From ff4bae7ecd46987c63b10c8bd4332deab10f4cfa Mon Sep 17 00:00:00 2001 From: haven1433 Date: Tue, 28 Nov 2023 23:03:35 -0600 Subject: [PATCH] prevent caret-reset events --- src/HexManiac.Core/ViewModels/TextEditorViewModel.cs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/HexManiac.Core/ViewModels/TextEditorViewModel.cs b/src/HexManiac.Core/ViewModels/TextEditorViewModel.cs index 7a5482c3..2f8593e8 100644 --- a/src/HexManiac.Core/ViewModels/TextEditorViewModel.cs +++ b/src/HexManiac.Core/ViewModels/TextEditorViewModel.cs @@ -38,6 +38,7 @@ namespace HavenSoft.HexManiac.Core.ViewModels { SyntaxHighlighting = syntaxHighlighting; } + private bool contentChanging; private string content = string.Empty; public string Content { get => content; @@ -46,14 +47,17 @@ namespace HavenSoft.HexManiac.Core.ViewModels { var oldContent = content; content = value; UpdateLayers(); - NotifyPropertyChanged(oldContent, nameof(Content)); + using (Scope(ref contentChanging, true, back => contentChanging = back)) { + NotifyPropertyChanged(oldContent, nameof(Content)); + } } } - private int caretIndex, savedCaret = int.MinValue; + private int caretIndex; public int CaretIndex { get => caretIndex; set { + if (contentChanging) return; Set(ref caretIndex, value, old => RequestCaretMove.Raise(this)); } }