From 164e266ed02e9c794ced2600fc196a083d60db15 Mon Sep 17 00:00:00 2001 From: Alf Eaton Date: Fri, 4 Aug 2023 08:36:08 +0100 Subject: [PATCH] Improve collaborator cursor positioning (#14145) GitOrigin-RevId: c43f0877700381279c2f79699ea3963c3e9c12b3 --- .../source-editor/extensions/cursor-highlights.ts | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/services/web/frontend/js/features/source-editor/extensions/cursor-highlights.ts b/services/web/frontend/js/features/source-editor/extensions/cursor-highlights.ts index 6838535aef..7928e6dc31 100644 --- a/services/web/frontend/js/features/source-editor/extensions/cursor-highlights.ts +++ b/services/web/frontend/js/features/source-editor/extensions/cursor-highlights.ts @@ -1,8 +1,10 @@ import { + MapMode, RangeSet, RangeValue, StateEffect, StateField, + Transaction, TransactionSpec, } from '@codemirror/state' import { @@ -67,9 +69,15 @@ export const cursorHighlights = () => { } class HighlightRangeValue extends RangeValue { + mapMode = MapMode.Simple + constructor(public highlight: Highlight) { super() } + + eq(other: HighlightRangeValue) { + return other.highlight === this.highlight + } } const cursorHighlightsState = StateField.define>({ @@ -101,7 +109,7 @@ const cursorHighlightsState = StateField.define>({ } } - if (tr.docChanged) { + if (tr.docChanged && !tr.annotation(Transaction.remote)) { value = value.map(tr.changes) }