Push up instantiation of TabComplete to RoomView

RoomView is the parent component which creates MessageComposer AND the status
bar. By making RoomView instantiate TabComplete we can scope instances
correctly rather than relying on singleton behaviour through dispatches. This
also makes communication between status bar and the MessageComposer infinitely
easier since they are now sharing the same TabComplete object.
This commit is contained in:
Kegan Dougal 2015-12-21 10:59:10 +00:00
parent c6d02b2c26
commit 26dc3cc553
3 changed files with 40 additions and 12 deletions

View file

@ -45,6 +45,10 @@ class TabComplete {
this.textArea = textArea;
}
isTabCompleting() {
return this.tabStruct.completing;
}
next() {
this.tabStruct.index++;
this.setCompletionOption();
@ -117,15 +121,27 @@ class TabComplete {
}
}
/**
* @param {DOMEvent} e
* @return {Boolean} True if the tab complete state changed as a result of
* this event.
*/
onKeyDown(ev) {
if (ev.keyCode !== KEY_TAB) {
if (ev.keyCode !== KEY_SHIFT && this.tabStruct.completing) {
// they're resuming typing; reset tab complete state vars.
this.tabStruct.completing = false;
this.tabStruct.index = 0;
return true;
}
return false;
}
if (!this.textArea) {
console.error("onKeyDown called before a <textarea> was set!");
return false;
}
// init struct if necessary
if (!this.tabStruct.completing) {
this.tabStruct.completing = true;