Skip to content
This repository has been archived by the owner on Sep 11, 2024. It is now read-only.

Commit

Permalink
clean up onVerticalArrow
Browse files Browse the repository at this point in the history
Signed-off-by: Michael Telatynski <[email protected]>
  • Loading branch information
t3chguy committed Jun 15, 2019
1 parent 6a10f00 commit 03c3782
Showing 1 changed file with 14 additions and 14 deletions.
28 changes: 14 additions & 14 deletions src/components/views/rooms/MessageComposerInput.js
Original file line number Diff line number Diff line change
Expand Up @@ -1206,15 +1206,22 @@ export default class MessageComposerInput extends React.Component {
onVerticalArrow = (e, up) => {
if (e.ctrlKey || e.shiftKey || e.metaKey) return;

// Select history
const selection = this.state.editorState.selection;
if (e.altKey) {
// Try select composer history
const selected = this.selectHistory(up);
if (selected) {
// We're selecting history, so prevent the key event from doing anything else
e.preventDefault();
}
} else if (!e.altKey && up) {
// Try edit the latest message
const selection = this.state.editorState.selection;

// selection must be collapsed
if (!selection.isCollapsed) return;
const document = this.state.editorState.document;
// selection must be collapsed
if (!selection.isCollapsed) return;
const document = this.state.editorState.document;

// and we must be at the edge of the document (up=start, down=end)
if (up) {
// and we must be at the edge of the document (up=start, down=end)
if (!selection.anchor.isAtStartOfNode(document)) return;

if (!e.altKey) {
Expand All @@ -1227,15 +1234,8 @@ export default class MessageComposerInput extends React.Component {
event: editEvent,
});
}
return;
}
}

const selected = this.selectHistory(up);
if (selected) {
// We're selecting history, so prevent the key event from doing anything else
e.preventDefault();
}
};

selectHistory = async (up) => {
Expand Down

0 comments on commit 03c3782

Please sign in to comment.