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

Commit

Permalink
fix: Full selection plus arrow keys should lose selection (#260)
Browse files Browse the repository at this point in the history
closes #259
  • Loading branch information
tommoor authored Sep 2, 2020
1 parent 36e739f commit 4a7772f
Showing 1 changed file with 14 additions and 1 deletion.
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

0 comments on commit 4a7772f

Please sign in to comment.