Skip to content

Commit

Permalink
improve keycode handling, tab inserts slash
Browse files Browse the repository at this point in the history
  • Loading branch information
cblgh committed Oct 2, 2020
1 parent 4f0d1b2 commit b5851d6
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions monotome/scripts/indexer.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,22 @@ window.addEventListener("DOMContentLoaded", function () {

function handleKeypress (e) {
keypressed = true
if (isNavigation(e)) { return }
if (isFunction(e)) { return }
if (isModifier(e)) { return }
else if (e.key === "Tab") { addToBuffer(e, "/") }
else if (e.key === "Enter") { document.activeElement.blur(); processBuffer(buffer) }
else if (e.key === "Escape") { clearBuffer() }
else if (e.key === "Backspace") { e.preventDefault(); eraseFromBuffer() }
else if (e.key === "ArrowRight") { console.log("right arrow") }
else if (e.key === "ArrowLeft") { console.log("left arrow") }
else { addToBuffer(e, e.key) }
}

function isNavigation (e) {
return e.key === "ArrowUp" || e.key === "ArrowDown" || e.key === "PageDown" || e.key === "PageUp"
}

function isFunction (e) {
return e.keyCode == 0 || (e.keyCode >= 112 && e.keyCode <= 123);
}
Expand Down

0 comments on commit b5851d6

Please sign in to comment.