From 0f7ec0d6fed6eecd58847e7e4a2b260e6a7431ad Mon Sep 17 00:00:00 2001 From: Alexey Yakovlev Date: Sun, 11 Mar 2012 00:50:47 +0400 Subject: [PATCH] Improved LoadSourceFile() method: added cleaning undo buffer and resetting visible range. --- .../Highlighter/FastColoredTextBoxHighlighter.cs | 3 +-- Irony.GrammarExplorer/fmGrammarExplorer.cs | 13 +++++++++++-- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/Irony.GrammarExplorer/Highlighter/FastColoredTextBoxHighlighter.cs b/Irony.GrammarExplorer/Highlighter/FastColoredTextBoxHighlighter.cs index 0d9fcb7..406721b 100644 --- a/Irony.GrammarExplorer/Highlighter/FastColoredTextBoxHighlighter.cs +++ b/Irony.GrammarExplorer/Highlighter/FastColoredTextBoxHighlighter.cs @@ -217,7 +217,7 @@ public void LockTextBox() { //SendMessage(TextBox.Handle, WM_SETREDRAW, 0, IntPtr.Zero); // Stop sending of events: _savedEventMask = SendMessage(TextBox.Handle, EM_GETEVENTMASK, 0, IntPtr.Zero); - //SendMessage(TextBox.Handle, EM_SETEVENTMASK, 0, IntPtr.Zero); + SendMessage(TextBox.Handle, EM_SETEVENTMASK, 0, IntPtr.Zero); } public void UnlockTextBox() { @@ -239,7 +239,6 @@ void Adapter_ColorizeTokens(object sender, ColorizeEventArgs args) { var tokenRange = TextBox.GetRange(tkn.Location.Position, tkn.Location.Position + tkn.Length); var tokenStyle = GetTokenStyle(tkn); tokenRange.SetStyle(tokenStyle); - } } finally { TextBox.EndUpdate(); diff --git a/Irony.GrammarExplorer/fmGrammarExplorer.cs b/Irony.GrammarExplorer/fmGrammarExplorer.cs index 2488c12..e3f86cd 100644 --- a/Irony.GrammarExplorer/fmGrammarExplorer.cs +++ b/Irony.GrammarExplorer/fmGrammarExplorer.cs @@ -405,9 +405,11 @@ private void LoadSourceFile(string path) { try { reader = new StreamReader(path); txtSource.Text = null; //to clear any old formatting + txtSource.ClearUndo(); + txtSource.ClearStylesBuffer(); txtSource.Text = reader.ReadToEnd(); - txtSource.SelectionStart = 0; - txtSource.SelectionLength = 0; + txtSource.SetVisibleState(0, FastColoredTextBoxNS.VisibleState.Visible); + txtSource.Selection = txtSource.GetRange(0, 0); } catch (Exception e) { MessageBox.Show(e.Message); } finally { @@ -433,9 +435,16 @@ private void StopHighlighter() { ClearHighlighting(); } private void ClearHighlighting() { + var selectedRange = txtSource.Selection; + var visibleRange = txtSource.VisibleRange; + var firstVisibleLine = Math.Min(visibleRange.Start.iLine, visibleRange.End.iLine); + var txt = txtSource.Text; txtSource.Clear(); txtSource.Text = txt; //remove all old highlighting + + txtSource.SetVisibleState(firstVisibleLine, FastColoredTextBoxNS.VisibleState.Visible); + txtSource.Selection = selectedRange; } private void EnableHighlighter(bool enable) { if (_highlighter != null)