Skip to content

Commit 44dfcb9

Browse files
committed
Work around for undefined user event type. Fixes lukeleppan#69.
1 parent 566f853 commit 44dfcb9

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

src/editor/EditorPlugin.ts

Lines changed: 14 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 = "";
@@ -42,6 +53,7 @@ class EditorPlugin implements PluginValue {
4253
tr.isUserEvent("redo") ||
4354
tr.isUserEvent("select")
4455
) {
56+
console.log("OTHER EVENTS");
4557
const textIter = tr.newDoc.iter();
4658
let text = "";
4759
while (!textIter.done) {

0 commit comments

Comments
 (0)