From d8b4295af46a59c2223e9c6444b4e8d97389e0c1 Mon Sep 17 00:00:00 2001 From: Zef Hemel Date: Tue, 10 Sep 2024 14:54:15 +0200 Subject: [PATCH] Fix double page reloads --- web/editor_state.ts | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/web/editor_state.ts b/web/editor_state.ts index b9aea365..2cac3918 100644 --- a/web/editor_state.ts +++ b/web/editor_state.ts @@ -1,5 +1,10 @@ import customMarkdownStyle from "./style.ts"; -import { history, indentWithTab, standardKeymap } from "@codemirror/commands"; +import { + history, + indentWithTab, + isolateHistory, + standardKeymap, +} from "@codemirror/commands"; import { autocompletion, closeBrackets, @@ -247,6 +252,12 @@ export function createEditorState( class { update(update: ViewUpdate): void { if (update.docChanged) { + // Find if there's a history isolate in the transaction, if so it came from a local reload and we don't do anything + if ( + update.transactions.some((t) => t.annotation(isolateHistory)) + ) { + return; + } const changes: TextChange[] = []; update.changes.iterChanges((fromA, toA, fromB, toB, inserted) => changes.push({