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

Move history with alt up/down regardless of where selection is #3254

Merged
merged 1 commit into from
Jul 29, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 11 additions & 11 deletions src/components/views/rooms/MessageComposerInput.js
Original file line number Diff line number Diff line change
Expand Up @@ -1130,17 +1130,6 @@ export default class MessageComposerInput extends React.Component {
onVerticalArrow = (e, up) => {
if (e.ctrlKey || e.shiftKey || e.metaKey) return;

// selection must be collapsed
const selection = this.state.editorState.selection;
if (!selection.isCollapsed) return;
// and we must be at the edge of the document (up=start, down=end)
const document = this.state.editorState.document;
if (up) {
if (!selection.anchor.isAtStartOfNode(document)) return;
} else {
if (!selection.anchor.isAtEndOfNode(document)) return;
}

const shouldSelectHistory = e.altKey;
const shouldEditLastMessage = !e.altKey && up && !RoomViewStore.getQuotingEvent();

Expand All @@ -1152,6 +1141,17 @@ export default class MessageComposerInput extends React.Component {
e.preventDefault();
}
} else if (shouldEditLastMessage) {
// selection must be collapsed
const selection = this.state.editorState.selection;
if (!selection.isCollapsed) return;
// and we must be at the edge of the document (up=start, down=end)
const document = this.state.editorState.document;
if (up) {
if (!selection.anchor.isAtStartOfNode(document)) return;
} else {
if (!selection.anchor.isAtEndOfNode(document)) return;
}

const editEvent = findEditableEvent(this.props.room, false);
if (editEvent) {
// We're selecting history, so prevent the key event from doing anything else
Expand Down