Skip to content

Commit

Permalink
web/app: fix key sequence timeout handling and reset behavior
Browse files Browse the repository at this point in the history
  • Loading branch information
alonswartz committed Oct 31, 2024
1 parent ba7d34e commit 0ee8a48
Showing 1 changed file with 16 additions and 8 deletions.
24 changes: 16 additions & 8 deletions web/app/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -365,12 +365,16 @@ export default {
handleKeyPress(event) {
if (event.target.tagName !== 'BODY') return

let timeoutId;
const leaderKey = 'Space'
if (event.code == leaderKey) {
if (this.keySequence.length == 0 && event.code == leaderKey) {
this.keySequence = [leaderKey];
event.preventDefault();
timeoutId = setTimeout(() => { this.keySequence = []; this.resetActiveFilename(); }, 2000);
setTimeout(() => {
if (this.keySequence.length > 0) {
this.keySequence = [];
this.resetActiveFilename();
}
}, 2000);
return;
}

Expand All @@ -380,37 +384,41 @@ export default {

switch(this.keySequence.join(' ')) {
case `${leaderKey} KeyN KeyL`:
this.keySequence = [];
this.openFinder('/api/raw/list?color=true&prefix=label&sort=alpha');
this.keySequence = []; clearTimeout(timeoutId);
break;
case `${leaderKey} KeyN KeyC`:
this.keySequence = [];
this.openFinder('/api/raw/list?color=true&prefix=ctime&sort=ctime');
this.keySequence = []; clearTimeout(timeoutId);
break;
case `${leaderKey} KeyN KeyM`:
this.keySequence = [];
this.openFinder('/api/raw/list?color=true&prefix=mtime&sort=mtime');
this.keySequence = []; clearTimeout(timeoutId);
break;
case `${leaderKey} KeyN KeyK`:
this.keySequence = [];
this.activeFilename
? this.openFinder('/api/raw/links?color=true&filename=' + this.activeFilename)
: this.openFinder('/api/raw/links?color=true');
this.keySequence = []; clearTimeout(timeoutId);
break;
case `${leaderKey} KeyN KeyS`:
this.keySequence = [];
this.openFinder('/api/raw/lines?color=true&prefix=title');
this.keySequence = []; clearTimeout(timeoutId);
break;
case `${leaderKey} KeyN KeyN`:
this.keySequence = [];
this.newNote();
break;
case `${leaderKey} KeyN KeyD`:
this.keySequence = [];
this.dailyNote();
break;
case `${leaderKey} KeyN KeyW`:
this.keySequence = [];
this.weeklyNote();
break;
case `${leaderKey} KeyN KeyG`:
this.keySequence = [];
this.showGraph = true;
break;
}
Expand Down

0 comments on commit 0ee8a48

Please sign in to comment.