Skip to content

Instantly share code, notes, and snippets.

@nuxodin
Last active July 1, 2022 20:02
Show Gist options
  • Save nuxodin/72d7141f79a51d08a8914c8c883719f1 to your computer and use it in GitHub Desktop.
Save nuxodin/72d7141f79a51d08a8914c8c883719f1 to your computer and use it in GitHub Desktop.

Revisions

  1. nuxodin revised this gist Jul 1, 2022. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion keyboard word event.js
    Original file line number Diff line number Diff line change
    @@ -21,11 +21,11 @@ addEventListener('keyup', e=>{
    word += e.key;
    }

    e.target.dispatchEvent(new CustomEvent('u1-key-word', {bubbles: true, detail: word}));

    clearTimeout(wordClearTimeout);
    wordClearTimeout = setTimeout(()=>{

    e.target.dispatchEvent(new CustomEvent('u1-key-word', {bubbles: true, detail: word}));
    // dispatch here?
    word = '';
    }, 800);
  2. nuxodin revised this gist Jul 1, 2022. 1 changed file with 2 additions and 0 deletions.
    2 changes: 2 additions & 0 deletions keyboard word event.js
    Original file line number Diff line number Diff line change
    @@ -25,6 +25,8 @@ addEventListener('keyup', e=>{

    clearTimeout(wordClearTimeout);
    wordClearTimeout = setTimeout(()=>{

    // dispatch here?
    word = '';
    }, 800);
    });
  3. nuxodin revised this gist Jul 1, 2022. 1 changed file with 2 additions and 4 deletions.
    6 changes: 2 additions & 4 deletions keyboard word event.js
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,5 @@
    /*
    // track words using a delay to clean
    // better an WordObserver that can better handle chanching targets?

    // better a "WordObserver" that can better handle chanching targets?
    let word = '';
    let wordClearTimeout = null;
    let wordTarget = null;
    @@ -29,4 +28,3 @@ addEventListener('keyup', e=>{
    word = '';
    }, 800);
    });
    */
  4. nuxodin created this gist Jul 1, 2022.
    32 changes: 32 additions & 0 deletions keyboard word event.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,32 @@
    /*
    // track words using a delay to clean
    // better an WordObserver that can better handle chanching targets?
    let word = '';
    let wordClearTimeout = null;
    let wordTarget = null;
    addEventListener('keyup', e=>{
    const isChar = /^.$/u.test(e.key);
    // if (wordTarget !== e.target) { // clear if target changes
    // word = '';
    // wordTarget = e.target;
    // }
    if (e.key === 'Backspace') {
    word = word.slice(0, -1);
    } else if (!isChar) {
    word = '';
    return;
    } else {
    word += e.key;
    }
    e.target.dispatchEvent(new CustomEvent('u1-key-word', {bubbles: true, detail: word}));
    clearTimeout(wordClearTimeout);
    wordClearTimeout = setTimeout(()=>{
    word = '';
    }, 800);
    });
    */