From a8677c0bf4d5bf1341f02ad1c14e96f6833237fa Mon Sep 17 00:00:00 2001 From: toehead2001 Date: Mon, 5 Oct 2026 00:25:01 -0700 Subject: [PATCH 1/2] Add Text and LineCount to UpdateUI --- Scintilla.NET/Scintilla.cs | 2 +- Scintilla.NET/UpdateChange.cs | 10 ++++++++++ Scintilla.NET/UpdateUIEventArgs.cs | 30 ++++++++++++++++++++++++++++++ 3 files changed, 41 insertions(+), 1 deletion(-) diff --git a/Scintilla.NET/Scintilla.cs b/Scintilla.NET/Scintilla.cs index a185d7f..54d7747 100644 --- a/Scintilla.NET/Scintilla.cs +++ b/Scintilla.NET/Scintilla.cs @@ -3367,7 +3367,7 @@ private void WmReflectNotify(ref Message m) break; case SciApi.SCN_UPDATEUI: - OnUpdateUI(new UpdateUIEventArgs((UpdateChange)scn.updated)); + OnUpdateUI(new UpdateUIEventArgs(this, (UpdateChange)scn.updated, scn.position.ToInt32())); break; case SciApi.SCN_CHARADDED: diff --git a/Scintilla.NET/UpdateChange.cs b/Scintilla.NET/UpdateChange.cs index c2fcad6..5e60c9b 100644 --- a/Scintilla.NET/UpdateChange.cs +++ b/Scintilla.NET/UpdateChange.cs @@ -33,4 +33,14 @@ public enum UpdateChange : uint /// May have scrolled horizontally. /// HScroll = SciApi.SC_UPDATE_H_SCROLL, + + /// + /// Contents may have changed. + /// + Text = SciApi.SC_UPDATE_TEXT, + + /// + /// Number of lines may have changed. + /// + LineCount = SciApi.SC_UPDATE_LINE_COUNT, } diff --git a/Scintilla.NET/UpdateUIEventArgs.cs b/Scintilla.NET/UpdateUIEventArgs.cs index f03b239..98c14ab 100644 --- a/Scintilla.NET/UpdateUIEventArgs.cs +++ b/Scintilla.NET/UpdateUIEventArgs.cs @@ -7,6 +7,10 @@ namespace ScintillaNET; /// public class UpdateUIEventArgs : EventArgs { + private readonly Scintilla scintilla; + private readonly int bytePosition; + private int? position; + #region Properties /// @@ -15,6 +19,25 @@ public class UpdateUIEventArgs : EventArgs /// A bitwise combination of values specifying the UI update that occurred. public UpdateChange Change { get; private set; } + /// + /// Gets the zero-based document start position where the Text was changed. + /// + /// The zero-based document start position where the Text was changed. + public int Position + { + get + { + if (this.bytePosition == Scintilla.InvalidPosition || this.scintilla is null) + { + return Scintilla.InvalidPosition; + } + + this.position ??= this.scintilla.Lines.ByteToCharPosition(this.bytePosition); + + return (int)this.position; + } + } + #endregion Properties #region Constructors @@ -24,7 +47,14 @@ public class UpdateUIEventArgs : EventArgs /// /// A bitwise combination of values specifying the reason to update the UI. public UpdateUIEventArgs(UpdateChange change) + : this(null, change, Scintilla.InvalidPosition) + { + } + + internal UpdateUIEventArgs(Scintilla scintilla, UpdateChange change, int bytePosition) { + this.scintilla = scintilla; + this.bytePosition = bytePosition; Change = change; } From 4d86a518ac916fa5c8c15f840c4e22c4fd5c96d2 Mon Sep 17 00:00:00 2001 From: toehead2001 Date: Mon, 5 Oct 2026 07:38:06 -0700 Subject: [PATCH 2/2] Update TestApp to use UpdateChange.LineCount --- Scintilla.NET.TestApp/FormMain.Designer.cs | 2 +- Scintilla.NET.TestApp/FormMain.cs | 7 +++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/Scintilla.NET.TestApp/FormMain.Designer.cs b/Scintilla.NET.TestApp/FormMain.Designer.cs index 67ab66a..222e884 100644 --- a/Scintilla.NET.TestApp/FormMain.Designer.cs +++ b/Scintilla.NET.TestApp/FormMain.Designer.cs @@ -73,7 +73,7 @@ private void InitializeComponent() this.scintilla.TabIndex = 2; this.scintilla.SavePointLeft += new System.EventHandler(this.scintilla_SavePointLeft); this.scintilla.SavePointReached += new System.EventHandler(this.scintilla_SavePointReached); - this.scintilla.TextChanged += new System.EventHandler(this.scintilla_TextChanged); + this.scintilla.UpdateUI += new System.EventHandler(this.scintilla_UpdateUI); // // toolStripStatusLabel // diff --git a/Scintilla.NET.TestApp/FormMain.cs b/Scintilla.NET.TestApp/FormMain.cs index 4dbc578..57d7b2e 100644 --- a/Scintilla.NET.TestApp/FormMain.cs +++ b/Scintilla.NET.TestApp/FormMain.cs @@ -223,9 +223,12 @@ private void describeKeywordSetsToolStripMenuItem_Click(object sender, EventArgs scintilla.ReplaceSelection(scintilla.DescribeKeywordSets()); } - private void scintilla_TextChanged(object sender, EventArgs e) + private void scintilla_UpdateUI(object sender, UpdateUIEventArgs e) { - AdjustLineNumberMargin(scintilla); + if (e.Change.HasFlag(UpdateChange.LineCount)) + { + AdjustLineNumberMargin(scintilla); + } } private void scintilla_SavePointLeft(object sender, EventArgs e)