Skip to content

Commit d3b6938

Browse files
authored
Merge pull request lukeleppan#74 from bakuzan/master
Allow better word count to correctly reflect selection count when using shift+home
2 parents b2a43d9 + 9cdab1d commit d3b6938

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

src/editor/EditorPlugin.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { Transaction } from "@codemirror/state";
12
import {
23
ViewUpdate,
34
PluginValue,
@@ -22,9 +23,19 @@ class EditorPlugin implements PluginValue {
2223
}
2324

2425
const tr = update.transactions[0];
25-
if (!tr) return;
26+
27+
if (!tr) {
28+
return;
29+
}
30+
31+
// When selecting text with Shift+Home the userEventType is undefined.
32+
// This is probably a bug in codemirror, for the time being doing an explict check
33+
// for the type allows us to update the stats for the selection.
34+
const userEventTypeUndefined =
35+
tr.annotation(Transaction.userEvent) === undefined;
36+
2637
if (
27-
tr.isUserEvent("select") &&
38+
(tr.isUserEvent("select") || userEventTypeUndefined) &&
2839
tr.newSelection.ranges[0].from !== tr.newSelection.ranges[0].to
2940
) {
3041
let text = "";

0 commit comments

Comments
 (0)