Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Scintilla.NET.TestApp/FormMain.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 5 additions & 2 deletions Scintilla.NET.TestApp/FormMain.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion Scintilla.NET/Scintilla.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
10 changes: 10 additions & 0 deletions Scintilla.NET/UpdateChange.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,14 @@ public enum UpdateChange : uint
/// May have scrolled horizontally.
/// </summary>
HScroll = SciApi.SC_UPDATE_H_SCROLL,

/// <summary>
/// Contents may have changed.
/// </summary>
Text = SciApi.SC_UPDATE_TEXT,

/// <summary>
/// Number of lines may have changed.
/// </summary>
LineCount = SciApi.SC_UPDATE_LINE_COUNT,
}
30 changes: 30 additions & 0 deletions Scintilla.NET/UpdateUIEventArgs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ namespace ScintillaNET;
/// </summary>
public class UpdateUIEventArgs : EventArgs
{
private readonly Scintilla scintilla;
private readonly int bytePosition;
private int? position;

#region Properties

/// <summary>
Expand All @@ -15,6 +19,25 @@ public class UpdateUIEventArgs : EventArgs
/// <returns>A bitwise combination of <see cref="UpdateChange" /> values specifying the UI update that occurred.</returns>
public UpdateChange Change { get; private set; }

/// <summary>
/// Gets the zero-based document start position where the Text was changed.
/// </summary>
/// <returns>The zero-based document start position where the Text was changed.</returns>
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
Expand All @@ -24,7 +47,14 @@ public class UpdateUIEventArgs : EventArgs
/// </summary>
/// <param name="change">A bitwise combination of <see cref="UpdateChange" /> values specifying the reason to update the UI.</param>
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;
}

Expand Down
Loading