Merge pull request #74 from bakuzan/master

Allow better word count to correctly reflect selection count when using shift+home
This commit is contained in:
Luke Leppan 2023-03-29 23:36:11 +02:00 committed by GitHub
commit d3b6938e48
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -1,3 +1,4 @@
import { Transaction } from "@codemirror/state";
import { import {
ViewUpdate, ViewUpdate,
PluginValue, PluginValue,
@ -22,9 +23,19 @@ class EditorPlugin implements PluginValue {
} }
const tr = update.transactions[0]; 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 ( if (
tr.isUserEvent("select") && (tr.isUserEvent("select") || userEventTypeUndefined) &&
tr.newSelection.ranges[0].from !== tr.newSelection.ranges[0].to tr.newSelection.ranges[0].from !== tr.newSelection.ranges[0].to
) { ) {
let text = ""; let text = "";