-
-
Notifications
You must be signed in to change notification settings - Fork 831
Allow arrow keys navigation in autocomplete list #2966
Allow arrow keys navigation in autocomplete list #2966
Conversation
Hi, thank you for your PR! We've recently introduced a new composer for editing messages (currently under a labs flag, in Will report back here when that's done. Thanks for your patience. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Apart from needing a few further changes, looking good already!
// selectionOffset 0 means autocomplete inactive, while 1 means 0th item selected, hence the -1/+1 | ||
let index = this.state.selectionOffset - 1; | ||
index = (index + delta + completionCount) % completionCount; | ||
this.setSelection(index + 1); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Won't this prevent from ever going back selectionOffset=0 again? E.g. you'll just be able to cycle through pills without having the step with just the text you typed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're right, good catch, I see the point behind the %(completionCount+1)
now!
I've updated the above to:
// Note: selectionOffset 0 represents the unsubstituted text, while 1 means first pill selected
const index = (this.state.selectionOffset + delta + completionCount + 1) % (completionCount + 1);
this.setSelection(index);
a33afa1
to
ed64275
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the changes! Apart from left/right arrow comments, looks good! Still need to test it locally as well, but almost there :)
src/editor/autocomplete.js
Outdated
this._getAutocompleterComponent().moveSelection(+1); | ||
} | ||
|
||
onLeftArrow() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No need to add left/right arrow keys for the new composer yet, I need to test if it doesn't interfere with caret navigation. Let's just do enough here so it isn't broken.
@@ -116,6 +116,10 @@ export default class MessageEditor extends React.Component { | |||
autoComplete.onUpArrow(event); break; | |||
case "ArrowDown": | |||
autoComplete.onDownArrow(event); break; | |||
case "ArrowLeft": |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No need to add left/right arrow keys for the new composer yet, I need to test if it doesn't interfere with caret navigation. Let's just do enough here so it isn't broken.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Roger that, removed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tried it locally, works well! Sorry it took so long. This looks good to merge now.
(Referencing element-hq/element-web#4737)
This allows left/right arrow keys to navigate backwards/forwards in the autocomplete list (on top of the up/down arrow keys which already did that).
The first commit is the minimal code change for that, while the rest are follow-up cleanup/refactor (now that names like
onVerticalArrow
,onUpArrow
andonDownArrow
make less sense).Misc notes
this.direction = ''
needs to be at the top before the bunch ofautocomplete.moveSelection
, as the latter callssetState
, which triggersonChange
, which looks atthis.direction
, somewhere in the middle. It would be at the lastkeyDown
event's value if it wasn't reset here first, which is incorrect.keyDown
event, as this isn't supposed to be textual navigation, but instead is supposed to be "swallowed up" by the autocomplete list. This is why the rest of the// skip void nodes
block is after theautocomplete.moveSelection
s, so that it only happens if the latter didn't match and didn'treturn true
first.this.moveAutocompleteSelection -> this.autocomplete.onUpArrow
indirection step as it didn't really add anything.Signed-off-by: Pierre Boyer <pierre.s.boyer@gmail.com>