Work around for undefined user event type. Fixes #69.
This commit is contained in:
parent
566f8531b5
commit
44dfcb9fe3
1 changed files with 14 additions and 2 deletions
|
@ -1,3 +1,4 @@
|
|||
import { Transaction } from "@codemirror/state";
|
||||
import {
|
||||
ViewUpdate,
|
||||
PluginValue,
|
||||
|
@ -22,9 +23,19 @@ class EditorPlugin implements PluginValue {
|
|||
}
|
||||
|
||||
const tr = update.transactions[0];
|
||||
if (!tr) return;
|
||||
|
||||
if (!tr) {
|
||||
return;
|
||||
}
|
||||
|
||||
// When selecting text with Shift+Home the userEventType is undefined.
|
||||
// This is probably a bug in codemirror, for the time being doing an explict check
|
||||
// for the type allows us to update the stats for the selection.
|
||||
const userEventTypeUndefined =
|
||||
tr.annotation(Transaction.userEvent) === undefined;
|
||||
|
||||
if (
|
||||
tr.isUserEvent("select") &&
|
||||
(tr.isUserEvent("select") || userEventTypeUndefined) &&
|
||||
tr.newSelection.ranges[0].from !== tr.newSelection.ranges[0].to
|
||||
) {
|
||||
let text = "";
|
||||
|
@ -42,6 +53,7 @@ class EditorPlugin implements PluginValue {
|
|||
tr.isUserEvent("redo") ||
|
||||
tr.isUserEvent("select")
|
||||
) {
|
||||
console.log("OTHER EVENTS");
|
||||
const textIter = tr.newDoc.iter();
|
||||
let text = "";
|
||||
while (!textIter.done) {
|
||||
|
|
Loading…
Reference in a new issue