Browse Source

Fixed change grouping when the document is changed inside event handlers for TextDocument.TextChanged.

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@5067 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
shortcuts
Daniel Grunwald 17 years ago
parent
commit
819bab8287
  1. 21
      src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Document/TextDocument.cs

21
src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Document/TextDocument.cs

@ -199,6 +199,7 @@ namespace ICSharpCode.AvalonEdit.Document
/// <list type="bullet"> /// <list type="bullet">
/// <item><description><b><see cref="BeginUpdate">BeginUpdate()</see></b></description> /// <item><description><b><see cref="BeginUpdate">BeginUpdate()</see></b></description>
/// <list type="bullet"> /// <list type="bullet">
/// <item><description>Start of change group (on undo stack)</description></item>
/// <item><description><see cref="UpdateStarted"/> event is raised</description></item> /// <item><description><see cref="UpdateStarted"/> event is raised</description></item>
/// </list></item> /// </list></item>
/// <item><description><b><see cref="Insert(int,string)">Insert()</see> / <see cref="Remove(int,int)">Remove()</see> / <see cref="Replace(int,int,string)">Replace()</see></b></description> /// <item><description><b><see cref="Insert(int,string)">Insert()</see> / <see cref="Remove(int,int)">Remove()</see> / <see cref="Replace(int,int,string)">Replace()</see></b></description>
@ -214,6 +215,7 @@ namespace ICSharpCode.AvalonEdit.Document
/// <item><description><see cref="TextChanged"/> event is raised</description></item> /// <item><description><see cref="TextChanged"/> event is raised</description></item>
/// <item><description><see cref="TextLengthChanged"/> event is raised</description></item> /// <item><description><see cref="TextLengthChanged"/> event is raised</description></item>
/// <item><description><see cref="LineCountChanged"/> event is raised</description></item> /// <item><description><see cref="LineCountChanged"/> event is raised</description></item>
/// <item><description>End of change group (on undo stack)</description></item>
/// <item><description><see cref="UpdateFinished"/> event is raised</description></item> /// <item><description><see cref="UpdateFinished"/> event is raised</description></item>
/// </list></item> /// </list></item>
/// </list> /// </list>
@ -355,11 +357,15 @@ namespace ICSharpCode.AvalonEdit.Document
throw new InvalidOperationException("Cannot end update within document change."); throw new InvalidOperationException("Cannot end update within document change.");
if (beginUpdateCount == 0) if (beginUpdateCount == 0)
throw new InvalidOperationException("No update is active."); throw new InvalidOperationException("No update is active.");
beginUpdateCount -= 1; if (beginUpdateCount == 1) {
if (beginUpdateCount == 0) { // fire change events inside the change group - event handlers might add additional
// document changes to the change group
FireChangeEvents(); FireChangeEvents();
beginUpdateCount = 0;
if (UpdateFinished != null) if (UpdateFinished != null)
UpdateFinished(this, EventArgs.Empty); UpdateFinished(this, EventArgs.Empty);
} else {
beginUpdateCount -= 1;
} }
} }
@ -382,18 +388,16 @@ namespace ICSharpCode.AvalonEdit.Document
bool fireTextChanged; bool fireTextChanged;
/// <summary> /// <summary>
/// Fires TextChanged, TextLengthChanged, TotalHeightChanged, LineCountChanged if required. /// Fires TextChanged, TextLengthChanged, LineCountChanged if required.
/// </summary> /// </summary>
internal void FireChangeEvents() internal void FireChangeEvents()
{ {
if (beginUpdateCount > 0) // it may be necessary to fire the event multiple times if the document is changed
return; // from inside the event handlers
while (fireTextChanged) {
if (fireTextChanged) {
fireTextChanged = false; fireTextChanged = false;
if (TextChanged != null) if (TextChanged != null)
TextChanged(this, EventArgs.Empty); TextChanged(this, EventArgs.Empty);
}
int textLength = rope.Length; int textLength = rope.Length;
if (textLength != oldTextLength) { if (textLength != oldTextLength) {
@ -408,6 +412,7 @@ namespace ICSharpCode.AvalonEdit.Document
LineCountChanged(this, EventArgs.Empty); LineCountChanged(this, EventArgs.Empty);
} }
} }
}
#endregion #endregion
#region Insert / Remove / Replace #region Insert / Remove / Replace

Loading…
Cancel
Save