Skip to content

Commit

Permalink
Improved LoadSourceFile() method: added cleaning undo buffer and rese…
Browse files Browse the repository at this point in the history
…tting visible range.
  • Loading branch information
yallie committed Mar 10, 2012
1 parent 1b8d103 commit 0f7ec0d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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();
Expand Down
13 changes: 11 additions & 2 deletions Irony.GrammarExplorer/fmGrammarExplorer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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)
Expand Down

0 comments on commit 0f7ec0d

Please sign in to comment.