Skip to content
This repository has been archived by the owner on Jan 20, 2022. It is now read-only.

fix: Full selection plus arrow keys should lose selection #260

Merged
merged 1 commit into from
Sep 2, 2020
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
15 changes: 14 additions & 1 deletion src/plugins/Keys.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Plugin } from "prosemirror-state";
import { Plugin, Selection, AllSelection } from "prosemirror-state";
import Extension from "../lib/Extension";

export default class Keys extends Extension {
Expand All @@ -13,6 +13,19 @@ export default class Keys extends Extension {
// we can't use the keys bindings for this as we want to preventDefault
// on the original keyboard event when handled
handleKeyDown: (view, event) => {
if (view.state.selection instanceof AllSelection) {
if (event.key === "ArrowUp") {
const selection = Selection.atStart(view.state.doc);
view.dispatch(view.state.tr.setSelection(selection));
return true;
}
if (event.key === "ArrowDown") {
const selection = Selection.atEnd(view.state.doc);
view.dispatch(view.state.tr.setSelection(selection));
return true;
}
}

if (!event.metaKey) return false;
if (event.key === "s") {
event.preventDefault();
Expand Down