From 26dc3cc553e49ee889e5579c32ca022cc7126961 Mon Sep 17 00:00:00 2001 From: Kegan Dougal Date: Mon, 21 Dec 2015 10:59:10 +0000 Subject: [PATCH] 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. --- src/TabComplete.js | 16 ++++++++++++ src/components/structures/RoomView.js | 11 +++++++- src/components/views/rooms/MessageComposer.js | 25 +++++++++++-------- 3 files changed, 40 insertions(+), 12 deletions(-) diff --git a/src/TabComplete.js b/src/TabComplete.js index 5a6bfa8343..c49ef19e7f 100644 --- a/src/TabComplete.js +++ b/src/TabComplete.js @@ -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