mirror of
https://github.com/element-hq/element-web
synced 2024-11-25 02:35:48 +03:00
Factor out handleTabPress and remove passive flag onKeyDown
This commit is contained in:
parent
b80015c69c
commit
82ff5c5e52
1 changed files with 30 additions and 31 deletions
|
@ -132,12 +132,38 @@ class TabComplete {
|
||||||
return peekList;
|
return peekList;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
handleTabPress(passive, shiftKey) {
|
||||||
|
var wasInPassiveMode = this.inPassiveMode && !passive;
|
||||||
|
console.log(
|
||||||
|
"handleTabPress passive=%s, shift=%s wasPassive=%s",
|
||||||
|
passive, shiftKey, wasInPassiveMode
|
||||||
|
);
|
||||||
|
this.inPassiveMode = passive;
|
||||||
|
|
||||||
|
if (!this.completing) {
|
||||||
|
this.startTabCompleting();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (shiftKey) {
|
||||||
|
this.nextMatchedEntry(-1);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
// if we were in passive mode we got out of sync by incrementing the
|
||||||
|
// index to show the peek view but not set the text area. Therefore,
|
||||||
|
// we want to set the *current* index rather than the *next* index.
|
||||||
|
this.nextMatchedEntry(wasInPassiveMode ? 0 : 1);
|
||||||
|
}
|
||||||
|
this._notifyStateChange();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {DOMEvent} e
|
* @param {DOMEvent} e
|
||||||
*/
|
*/
|
||||||
onKeyDown(ev) {
|
onKeyDown(ev) {
|
||||||
var wasInPassiveMode = this.inPassiveMode && !ev.passive;
|
if (!this.textArea) {
|
||||||
this.inPassiveMode = ev.passive;
|
console.error("onKeyDown called before a <textarea> was set!");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (ev.keyCode !== KEY_TAB) {
|
if (ev.keyCode !== KEY_TAB) {
|
||||||
// pressing any key (except shift, windows, cmd (OSX) and ctrl/alt combinations)
|
// pressing any key (except shift, windows, cmd (OSX) and ctrl/alt combinations)
|
||||||
|
@ -153,14 +179,7 @@ class TabComplete {
|
||||||
clearTimeout(this.enterTabCompleteTimerId);
|
clearTimeout(this.enterTabCompleteTimerId);
|
||||||
this.enterTabCompleteTimerId = setTimeout(() => {
|
this.enterTabCompleteTimerId = setTimeout(() => {
|
||||||
if (!this.completing) {
|
if (!this.completing) {
|
||||||
// inject a fake tab event so we use the same code paths
|
this.handleTabPress(true, false);
|
||||||
// as much as possible. Add a 'passive' flag to indicate
|
|
||||||
// that they didn't really hit this key.
|
|
||||||
this.onKeyDown({
|
|
||||||
keyCode: KEY_TAB,
|
|
||||||
passive: true,
|
|
||||||
preventDefault: function(){} // NOP
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
}, DELAY_TIME_MS);
|
}, DELAY_TIME_MS);
|
||||||
}
|
}
|
||||||
|
@ -169,30 +188,10 @@ class TabComplete {
|
||||||
}
|
}
|
||||||
|
|
||||||
// tab key has been pressed at this point
|
// tab key has been pressed at this point
|
||||||
|
this.handleTabPress(false, ev.shiftKey)
|
||||||
if (!this.textArea) {
|
|
||||||
console.error("onKeyDown called before a <textarea> was set!");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// init struct if necessary
|
|
||||||
if (!this.completing) {
|
|
||||||
this.startTabCompleting();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (ev.shiftKey) {
|
|
||||||
this.nextMatchedEntry(-1);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
// if we were in passive mode we got out of sync by incrementing the
|
|
||||||
// index to show the peek view but not set the text area. Therefore,
|
|
||||||
// we want to set the *current* index rather than the *next* index.
|
|
||||||
this.nextMatchedEntry(wasInPassiveMode ? 0 : 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
// prevent the default TAB operation (typically focus shifting)
|
// prevent the default TAB operation (typically focus shifting)
|
||||||
ev.preventDefault();
|
ev.preventDefault();
|
||||||
this._notifyStateChange();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in a new issue