diff --git a/src/Libraries/ICSharpCode.TextEditor/Project/Src/Gui/Caret.cs b/src/Libraries/ICSharpCode.TextEditor/Project/Src/Gui/Caret.cs index 6e96d46b3d..48c43f29c1 100644 --- a/src/Libraries/ICSharpCode.TextEditor/Project/Src/Gui/Caret.cs +++ b/src/Libraries/ICSharpCode.TextEditor/Project/Src/Gui/Caret.cs @@ -285,8 +285,26 @@ namespace ICSharpCode.TextEditor static extern bool HideCaret(IntPtr hWnd); #endregion + bool firePositionChangedAfterUpdateEnd; + + void FirePositionChangedAfterUpdateEnd(object sender, EventArgs e) + { + OnPositionChanged(EventArgs.Empty); + } + protected virtual void OnPositionChanged(EventArgs e) { + if (this.textArea.MotherTextEditorControl.IsInUpdate) { + if (firePositionChangedAfterUpdateEnd == false) { + firePositionChangedAfterUpdateEnd = true; + this.textArea.Document.UpdateCommited += FirePositionChangedAfterUpdateEnd; + } + return; + } else if (firePositionChangedAfterUpdateEnd) { + this.textArea.Document.UpdateCommited -= FirePositionChangedAfterUpdateEnd; + firePositionChangedAfterUpdateEnd = false; + } + List foldings = textArea.Document.FoldingManager.GetFoldingsFromPosition(line, column); bool shouldUpdate = false; foreach (FoldMarker foldMarker in foldings) { diff --git a/src/Libraries/ICSharpCode.TextEditor/Project/Src/Gui/TextArea.cs b/src/Libraries/ICSharpCode.TextEditor/Project/Src/Gui/TextArea.cs index a0e3c54dd6..9c0f97f8a8 100644 --- a/src/Libraries/ICSharpCode.TextEditor/Project/Src/Gui/TextArea.cs +++ b/src/Libraries/ICSharpCode.TextEditor/Project/Src/Gui/TextArea.cs @@ -506,7 +506,7 @@ namespace ICSharpCode.TextEditor } if (adjustScrollBars) { - this.motherTextAreaControl.AdjustScrollBars(null, null); + this.motherTextAreaControl.AdjustScrollBars(); } Caret.UpdateCaretPosition(); @@ -516,7 +516,7 @@ namespace ICSharpCode.TextEditor void DocumentFoldingsChanged(object sender, EventArgs e) { Invalidate(); - this.motherTextAreaControl.AdjustScrollBars(null, null); + this.motherTextAreaControl.AdjustScrollBars(); } #region keyboard handling methods diff --git a/src/Libraries/ICSharpCode.TextEditor/Project/Src/Gui/TextAreaControl.cs b/src/Libraries/ICSharpCode.TextEditor/Project/Src/Gui/TextAreaControl.cs index c2e2d2216c..5419970efa 100644 --- a/src/Libraries/ICSharpCode.TextEditor/Project/Src/Gui/TextAreaControl.cs +++ b/src/Libraries/ICSharpCode.TextEditor/Project/Src/Gui/TextAreaControl.cs @@ -111,7 +111,8 @@ namespace ICSharpCode.TextEditor Controls.Add(this.hScrollBar); ResizeRedraw = true; - Document.DocumentChanged += new DocumentEventHandler(AdjustScrollBars); + Document.DocumentChanged += AdjustScrollBarsOnDocumentChange; + Document.UpdateCommited += AdjustScrollBarsOnCommittedUpdate; } protected override void Dispose(bool disposing) @@ -119,7 +120,8 @@ namespace ICSharpCode.TextEditor if (disposing) { if (!disposed) { disposed = true; - Document.DocumentChanged -= new DocumentEventHandler(AdjustScrollBars); + Document.DocumentChanged -= AdjustScrollBarsOnDocumentChange; + Document.UpdateCommited -= AdjustScrollBarsOnCommittedUpdate; motherTextEditorControl = null; if (vScrollBar != null) { vScrollBar.Dispose(); @@ -172,7 +174,33 @@ namespace ICSharpCode.TextEditor Width - SystemInformation.HorizontalScrollBarArrowWidth, SystemInformation.VerticalScrollBarArrowHeight); } - public void AdjustScrollBars(object sender, DocumentEventArgs e) + + bool adjustScrollBarsOnNextUpdate; + Point scrollToPosOnNextUpdate; + + void AdjustScrollBarsOnDocumentChange(object sender, DocumentEventArgs e) + { + if (motherTextEditorControl.IsInUpdate == false) { + AdjustScrollBars(); + } else { + adjustScrollBarsOnNextUpdate = true; + } + } + + void AdjustScrollBarsOnCommittedUpdate(object sender, EventArgs e) + { + if (motherTextEditorControl.IsInUpdate == false) { + if (adjustScrollBarsOnNextUpdate) { + adjustScrollBarsOnNextUpdate = false; + AdjustScrollBars(); + } + if (!scrollToPosOnNextUpdate.IsEmpty) { + ScrollTo(scrollToPosOnNextUpdate.Y, scrollToPosOnNextUpdate.X); + } + } + } + + public void AdjustScrollBars() { vScrollBar.Minimum = 0; // number of visible lines in document (folding!) @@ -213,7 +241,7 @@ namespace ICSharpCode.TextEditor } } - AdjustScrollBars(null, null); + AdjustScrollBars(); } void VScrollBarValueChanged(object sender, EventArgs e) @@ -265,11 +293,19 @@ namespace ICSharpCode.TextEditor public void ScrollToCaret() { + ScrollTo(textArea.Caret.Line, textArea.Caret.Column); + } + + public void ScrollTo(int line, int column) + { + if (motherTextEditorControl.IsInUpdate) { + scrollToPosOnNextUpdate = new Point(column, line); + return; + } int curCharMin = (int)(this.hScrollBar.Value - this.hScrollBar.Minimum); int curCharMax = curCharMin + textArea.TextView.VisibleColumnCount; - int pos = textArea.TextView.GetVisualColumn(textArea.Caret.Line, - textArea.Caret.Column); + int pos = textArea.TextView.GetVisualColumn(line, column); if (textArea.TextView.VisibleColumnCount < 0) { hScrollBar.Value = 0; @@ -282,7 +318,7 @@ namespace ICSharpCode.TextEditor } } } - ScrollTo(textArea.Caret.Line); + ScrollTo(line); } int scrollMarginHeight = 3; diff --git a/src/Libraries/ICSharpCode.TextEditor/Project/Src/Gui/TextAreaMouseHandler.cs b/src/Libraries/ICSharpCode.TextEditor/Project/Src/Gui/TextAreaMouseHandler.cs index e815e1b5e4..27c3911717 100644 --- a/src/Libraries/ICSharpCode.TextEditor/Project/Src/Gui/TextAreaMouseHandler.cs +++ b/src/Libraries/ICSharpCode.TextEditor/Project/Src/Gui/TextAreaMouseHandler.cs @@ -217,7 +217,7 @@ namespace ICSharpCode.TextEditor mousepos.Y - textArea.TextView.DrawingPosition.Y); if (marker != null && marker.IsFolded) { marker.IsFolded = false; - textArea.MotherTextAreaControl.AdjustScrollBars(null, null); + textArea.MotherTextAreaControl.AdjustScrollBars(); } if (textArea.Caret.Offset < textArea.Document.TextLength) { switch (textArea.Document.GetCharAt(textArea.Caret.Offset)) { diff --git a/src/Main/Base/Project/Src/Gui/AbstractViewContent.cs b/src/Main/Base/Project/Src/Gui/AbstractViewContent.cs index c2f8d5ed3a..8cc41cf19e 100644 --- a/src/Main/Base/Project/Src/Gui/AbstractViewContent.cs +++ b/src/Main/Base/Project/Src/Gui/AbstractViewContent.cs @@ -185,8 +185,10 @@ namespace ICSharpCode.SharpDevelop.Gui return isDirty; } set { - isDirty = value; - OnDirtyChanged(EventArgs.Empty); + if (isDirty != value) { + isDirty = value; + OnDirtyChanged(EventArgs.Empty); + } } } bool isDirty = false; diff --git a/src/Main/Base/Project/Src/TextEditor/SearchAndReplace/Engine/SearchReplaceManager.cs b/src/Main/Base/Project/Src/TextEditor/SearchAndReplace/Engine/SearchReplaceManager.cs index 9aa2a76a23..220b34878b 100644 --- a/src/Main/Base/Project/Src/TextEditor/SearchAndReplace/Engine/SearchReplaceManager.cs +++ b/src/Main/Base/Project/Src/TextEditor/SearchAndReplace/Engine/SearchReplaceManager.cs @@ -201,28 +201,33 @@ namespace SearchAndReplace return; List textAreas = new List(); + TextEditorControl textArea = null; for (int count = 0;; count++) { SearchResult result = SearchReplaceManager.find.FindNext(); if (result == null) { if (count != 0) { - foreach (TextEditorControl textArea in textAreas) { - textArea.EndUpdate(); - textArea.Refresh(); + foreach (TextEditorControl ta in textAreas) { + ta.EndUpdate(); + ta.Refresh(); } } ShowReplaceDoneMessage(count); find.Reset(); return; } else { - TextEditorControl textArea = OpenTextArea(result.FileName); - if (textArea != null) { - if (!textAreas.Contains(textArea)) { - textArea.BeginUpdate(); - textArea.ActiveTextAreaControl.TextArea.SelectionManager.SelectionCollection.Clear(); - textAreas.Add(textArea); + if (textArea == null || textArea.FileName != result.FileName) { + // we need to open another text area + textArea = OpenTextArea(result.FileName); + if (textArea != null) { + if (!textAreas.Contains(textArea)) { + textArea.BeginUpdate(); + textArea.ActiveTextAreaControl.TextArea.SelectionManager.SelectionCollection.Clear(); + textAreas.Add(textArea); + } } - + } + if (textArea != null) { string transformedPattern = result.TransformReplacePattern(SearchOptions.ReplacePattern); find.Replace(result.Offset, result.Length, transformedPattern); if (find.CurrentDocumentInformation.Document == null) { diff --git a/src/Main/Base/Project/Src/TextEditor/SearchAndReplace/Engine/SearchStrategy/WildcardSearchStrategy.cs b/src/Main/Base/Project/Src/TextEditor/SearchAndReplace/Engine/SearchStrategy/WildcardSearchStrategy.cs index 0c6602043a..ef2e0ccdce 100644 --- a/src/Main/Base/Project/Src/TextEditor/SearchAndReplace/Engine/SearchStrategy/WildcardSearchStrategy.cs +++ b/src/Main/Base/Project/Src/TextEditor/SearchAndReplace/Engine/SearchStrategy/WildcardSearchStrategy.cs @@ -114,7 +114,7 @@ namespace SearchAndReplace case CommandType.AnySingle: break; case CommandType.AnyDigit: - if (!Char.IsDigit(ch)) { + if (!Char.IsDigit(ch) && ch != '#') { return false; } break;