From 4a90f262c65ce104b7ef32dfb9d3c3c6be2b304c Mon Sep 17 00:00:00 2001 From: Matthew Hodgson Date: Thu, 17 Mar 2016 15:34:40 +0000 Subject: [PATCH 01/18] fix zero length tab complete behaviour --- src/TabComplete.js | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/TabComplete.js b/src/TabComplete.js index 3005411e13..c82d8e4644 100644 --- a/src/TabComplete.js +++ b/src/TabComplete.js @@ -83,10 +83,10 @@ class TabComplete { this._notifyStateChange(); } - startTabCompleting() { + startTabCompleting(passive) { this.completing = true; this.currentIndex = 0; - this._calculateCompletions(); + this._calculateCompletions(passive); } /** @@ -137,7 +137,7 @@ class TabComplete { this.inPassiveMode = passive; if (!this.completing) { - this.startTabCompleting(); + this.startTabCompleting(passive); } if (shiftKey) { @@ -270,7 +270,7 @@ class TabComplete { }); } - _calculateCompletions() { + _calculateCompletions(passive) { this.originalText = this.textArea.value; // cache starting text // grab the partial word from the text which we'll be tab-completing @@ -283,6 +283,11 @@ class TabComplete { var [ , boundaryGroup, partialGroup] = res; this.isFirstWord = partialGroup.length === this.originalText.length; + if (partialGroup.length === 0 && passive) { + this.stopTabCompleting(); + return; + } + this.matchedList = [ new Entry(partialGroup) // first entry is always the original partial ]; From c7ffb5937423de31d88224c00262fe70e640bb9f Mon Sep 17 00:00:00 2001 From: Matthew Hodgson Date: Thu, 17 Mar 2016 15:35:23 +0000 Subject: [PATCH 02/18] click on nicks to insert them into the MessageComposer --- src/components/views/rooms/EventTile.js | 15 +++++++++++---- src/components/views/rooms/MessageComposer.js | 9 +++++++++ 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/src/components/views/rooms/EventTile.js b/src/components/views/rooms/EventTile.js index cfff797e7d..9d5a17b3d2 100644 --- a/src/components/views/rooms/EventTile.js +++ b/src/components/views/rooms/EventTile.js @@ -268,10 +268,17 @@ module.exports = React.createClass({ this.readAvatarNode = ReactDom.findDOMNode(node); }, - onMemberAvatarClicked: function(sender) { + onMemberAvatarClick: function(event) { dispatcher.dispatch({ action: 'view_user', - member: sender + member: this.props.mxEvent.sender, + }); + }, + + onSenderProfileClick: function(event) { + dispatcher.dispatch({ + action: 'insert_displayname', + displayname: this.props.mxEvent.sender.name, }); }, @@ -318,12 +325,12 @@ module.exports = React.createClass({ avatar = (
+ onClick={ this.onMemberAvatarClick } />
); } if (EventTileType.needsSenderProfile()) { - sender = ; + sender = ; } } return ( diff --git a/src/components/views/rooms/MessageComposer.js b/src/components/views/rooms/MessageComposer.js index 6744de5d14..2cb2acb470 100644 --- a/src/components/views/rooms/MessageComposer.js +++ b/src/components/views/rooms/MessageComposer.js @@ -196,6 +196,15 @@ module.exports = React.createClass({ case 'focus_composer': this.refs.textarea.focus(); break; + case 'insert_displayname': + if (this.refs.textarea.value) { + this.refs.textarea.value = + this.refs.textarea.value.replace(/( ?)$/, " " + payload.displayname); + } + else { + this.refs.textarea.value = payload.displayname + ": "; + } + break; } }, From a64ad04a0e92d5227c6aae5a2519e1a4c12fd946 Mon Sep 17 00:00:00 2001 From: Matthew Hodgson Date: Thu, 17 Mar 2016 16:29:37 +0000 Subject: [PATCH 03/18] handle focus nicely when inserting displaynames and let them be inserted in the middle of in-progress messages --- src/components/views/rooms/MessageComposer.js | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/src/components/views/rooms/MessageComposer.js b/src/components/views/rooms/MessageComposer.js index 2cb2acb470..53253376c9 100644 --- a/src/components/views/rooms/MessageComposer.js +++ b/src/components/views/rooms/MessageComposer.js @@ -192,17 +192,28 @@ module.exports = React.createClass({ }, onAction: function(payload) { + var textarea = this.refs.textarea; switch (payload.action) { case 'focus_composer': - this.refs.textarea.focus(); + textarea.focus(); break; case 'insert_displayname': - if (this.refs.textarea.value) { - this.refs.textarea.value = - this.refs.textarea.value.replace(/( ?)$/, " " + payload.displayname); + if (textarea.value) { + var left = textarea.value.substring(0, textarea.selectionStart); + var right = textarea.value.substring(textarea.selectionEnd); + if (right && right.length) { + left += payload.displayname; + } + else { + left = left.replace(/( ?)$/, " " + payload.displayname); + } + textarea.value = left + right; + textarea.focus(); + textarea.setSelectionRange(left.length, left.length); } else { this.refs.textarea.value = payload.displayname + ": "; + this.refs.textarea.focus(); } break; } From 42479cf011b9566b8a91017a805aad535b0f4401 Mon Sep 17 00:00:00 2001 From: Matthew Hodgson Date: Thu, 17 Mar 2016 16:46:54 +0000 Subject: [PATCH 04/18] PR feedback --- src/TabComplete.js | 63 ++++++++++++++++++++++------------------------ 1 file changed, 30 insertions(+), 33 deletions(-) diff --git a/src/TabComplete.js b/src/TabComplete.js index c82d8e4644..0cf6e1948a 100644 --- a/src/TabComplete.js +++ b/src/TabComplete.js @@ -84,9 +84,38 @@ class TabComplete { } startTabCompleting(passive) { + this.originalText = this.textArea.value; // cache starting text + + // grab the partial word from the text which we'll be tab-completing + var res = MATCH_REGEX.exec(this.originalText); + if (!res) { + this.matchedList = []; + return; + } + // ES6 destructuring; ignore first element (the complete match) + var [ , boundaryGroup, partialGroup] = res; + + if (partialGroup.length === 0 && passive) { + return; + } + + this.isFirstWord = partialGroup.length === this.originalText.length; + this.completing = true; this.currentIndex = 0; - this._calculateCompletions(passive); + + this.matchedList = [ + new Entry(partialGroup) // first entry is always the original partial + ]; + + // find matching entries in the set of entries given to us + this.list.forEach((entry) => { + if (entry.text.toLowerCase().indexOf(partialGroup.toLowerCase()) === 0) { + this.matchedList.push(entry); + } + }); + + // console.log("calculated completions => %s", JSON.stringify(this.matchedList)); } /** @@ -270,38 +299,6 @@ class TabComplete { }); } - _calculateCompletions(passive) { - this.originalText = this.textArea.value; // cache starting text - - // grab the partial word from the text which we'll be tab-completing - var res = MATCH_REGEX.exec(this.originalText); - if (!res) { - this.matchedList = []; - return; - } - // ES6 destructuring; ignore first element (the complete match) - var [ , boundaryGroup, partialGroup] = res; - this.isFirstWord = partialGroup.length === this.originalText.length; - - if (partialGroup.length === 0 && passive) { - this.stopTabCompleting(); - return; - } - - this.matchedList = [ - new Entry(partialGroup) // first entry is always the original partial - ]; - - // find matching entries in the set of entries given to us - this.list.forEach((entry) => { - if (entry.text.toLowerCase().indexOf(partialGroup.toLowerCase()) === 0) { - this.matchedList.push(entry); - } - }); - - // console.log("_calculateCompletions => %s", JSON.stringify(this.matchedList)); - } - _notifyStateChange() { if (this.opts.onStateChange) { this.opts.onStateChange(this.completing); From 1b4c5224fd2b45a8fd61130cf4d3b3c7fe1d3c14 Mon Sep 17 00:00:00 2001 From: Matthew Hodgson Date: Thu, 17 Mar 2016 16:52:12 +0000 Subject: [PATCH 05/18] missed some s/this.refs.// --- src/components/views/rooms/MessageComposer.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/components/views/rooms/MessageComposer.js b/src/components/views/rooms/MessageComposer.js index 53253376c9..059cafd311 100644 --- a/src/components/views/rooms/MessageComposer.js +++ b/src/components/views/rooms/MessageComposer.js @@ -212,8 +212,8 @@ module.exports = React.createClass({ textarea.setSelectionRange(left.length, left.length); } else { - this.refs.textarea.value = payload.displayname + ": "; - this.refs.textarea.focus(); + textarea.value = payload.displayname + ": "; + textarea.focus(); } break; } From 76d4e8a7887376231b820c7fbbf4235adc521324 Mon Sep 17 00:00:00 2001 From: Matthew Hodgson Date: Thu, 17 Mar 2016 16:54:54 +0000 Subject: [PATCH 06/18] check length of textarea, not its trueiness --- src/components/views/rooms/MessageComposer.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/views/rooms/MessageComposer.js b/src/components/views/rooms/MessageComposer.js index 059cafd311..94058ae6d0 100644 --- a/src/components/views/rooms/MessageComposer.js +++ b/src/components/views/rooms/MessageComposer.js @@ -198,7 +198,7 @@ module.exports = React.createClass({ textarea.focus(); break; case 'insert_displayname': - if (textarea.value) { + if (textarea.value.length) { var left = textarea.value.substring(0, textarea.selectionStart); var right = textarea.value.substring(textarea.selectionEnd); if (right && right.length) { From fd4e70970583e8b13fb6bf12169c79cd2ee8d6fe Mon Sep 17 00:00:00 2001 From: Matthew Hodgson Date: Thu, 17 Mar 2016 16:56:16 +0000 Subject: [PATCH 07/18] don't need null guard --- src/components/views/rooms/MessageComposer.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/views/rooms/MessageComposer.js b/src/components/views/rooms/MessageComposer.js index 94058ae6d0..89633f18f8 100644 --- a/src/components/views/rooms/MessageComposer.js +++ b/src/components/views/rooms/MessageComposer.js @@ -201,7 +201,7 @@ module.exports = React.createClass({ if (textarea.value.length) { var left = textarea.value.substring(0, textarea.selectionStart); var right = textarea.value.substring(textarea.selectionEnd); - if (right && right.length) { + if (right.length) { left += payload.displayname; } else { From 092c416a89e90c901443c614d7dc1a8860fd8f03 Mon Sep 17 00:00:00 2001 From: Matthew Hodgson Date: Thu, 17 Mar 2016 17:25:48 +0000 Subject: [PATCH 08/18] ugh, get rid of accidental debugging --- src/Notifier.js | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Notifier.js b/src/Notifier.js index 08322e91bc..65a222c730 100644 --- a/src/Notifier.js +++ b/src/Notifier.js @@ -205,7 +205,6 @@ var Notifier = { }, onSyncStateChange: function(state) { - console.log("sync state change: " + state); if (state === "PREPARED" || state === "SYNCING") { this.isPrepared = true; } From 57ffc2d2e26f5f060277c2272b220d85cf096348 Mon Sep 17 00:00:00 2001 From: Matthew Hodgson Date: Thu, 17 Mar 2016 17:29:48 +0000 Subject: [PATCH 09/18] add autoFocus to MessageComposer's textarea, which generally makes the world a better place. We could probably kill all the focus_composer dispatches too, but haven't got time to check that right now --- src/components/views/rooms/MessageComposer.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/views/rooms/MessageComposer.js b/src/components/views/rooms/MessageComposer.js index 89633f18f8..c3e02975e0 100644 --- a/src/components/views/rooms/MessageComposer.js +++ b/src/components/views/rooms/MessageComposer.js @@ -517,7 +517,7 @@ module.exports = React.createClass({
-