Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
12/04/14 17:14:01 (9 years ago)
Author:
jkarder
Message:

#2262: applied some of the changes suggested by swagner in comment:17:ticket:2262

  • added highlighting of current line
  • added error markers and bookmarks
  • fixed <Ctrl> + <Backspace> bug
  • minor code changes
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.CodeEditor/3.3/CodeEditor.cs

    r11436 r11657  
    4646
    4747    #region Fields & Properties
     48    private static Color WarningColor = Color.Blue;
     49    private static Color ErrorColor = Color.Red;
    4850
    4951    internal Dom.ProjectContentRegistry projectContentRegistry;
     
    127129      }
    128130      set {
     131        if (Doc.TextContent == value) return;
    129132        Doc.Replace(prefix.Length, Doc.TextLength - suffix.Length - prefix.Length, value);
    130133        Doc.RequestUpdate(new TextAreaUpdate(TextAreaUpdateType.WholeTextArea));
     
    141144
    142145    public event EventHandler TextEditorValidated;
    143 
    144146    protected void OnTextEditorValidated() {
    145147      if (TextEditorValidated != null)
     
    148150
    149151    public event EventHandler TextEditorTextChanged;
    150 
    151152    protected void OnTextEditorTextChanged() {
    152153      if (TextEditorTextChanged != null)
     
    159160      textEditor.ActiveTextAreaControl.TextEditorProperties.SupportReadOnlySegments = true;
    160161
    161       textEditor.SetHighlighting("C#");
    162       textEditor.ShowEOLMarkers = false;
    163       textEditor.ShowInvalidLines = false;
     162      LoadHighlightingStrategy();
    164163      HostCallbackImplementation.Register(this);
    165164      CodeCompletionKeyHandler.Attach(this, textEditor);
     
    192191        return;
    193192
    194       textEditor.ActiveTextAreaControl.TextArea.KeyEventHandler += new ICSharpCode.TextEditor.KeyEventHandler(TextArea_KeyEventHandler);
    195       textEditor.ActiveTextAreaControl.TextArea.DoProcessDialogKey += new DialogKeyProcessor(TextArea_DoProcessDialogKey);
    196 
    197       parserThread = new Thread(ParserThread);
    198       parserThread.IsBackground = true;
     193      textEditor.ActiveTextAreaControl.TextArea.KeyEventHandler += TextArea_KeyEventHandler;
     194      textEditor.ActiveTextAreaControl.TextArea.DoProcessDialogKey += TextArea_DoProcessDialogKey;
     195
     196      parserThread = new Thread(ParserThread) { IsBackground = true };
    199197      parserThread.Start();
    200198
    201       textEditor.Validated += (s, a) => { OnTextEditorValidated(); };
    202       textEditor.TextChanged += (s, a) => { OnTextEditorTextChanged(); };
     199      textEditor.Validated += (s, a) => OnTextEditorValidated();
     200      textEditor.TextChanged += (s, a) => {
     201        Doc.MarkerStrategy.RemoveAll(m => errorMarkers.Contains(m)); errorMarkers.Clear();
     202        Doc.BookmarkManager.RemoveMarks(m => errorBookmarks.Contains(m)); errorBookmarks.Clear();
     203        Doc.RequestUpdate(new TextAreaUpdate(TextAreaUpdateType.WholeTextArea));
     204        Doc.CommitUpdate();
     205        OnTextEditorTextChanged();
     206      };
    203207      InitializeImageList();
     208    }
     209
     210    private void LoadHighlightingStrategy() {
     211      var strategy = (DefaultHighlightingStrategy)HighlightingManager.Manager.FindHighlighter("C#");
     212      strategy.SetColorFor("CaretMarker", new HighlightColor(Color.Beige, false, false));
     213      Doc.HighlightingStrategy = strategy;
    204214    }
    205215
     
    216226
    217227    #region keyboard handlers: filter input in read-only areas
    218 
    219228    bool TextArea_KeyEventHandler(char ch) {
    220229      int caret = textEditor.ActiveTextAreaControl.Caret.Offset;
     
    232241      return false;
    233242    }
    234 
    235243    #endregion
    236244
     
    240248    }
    241249
     250    public void ScrollToPosition(int line, int column) {
     251      var segment = GetSegmentAtOffset(line, column);
     252      var position = Doc.OffsetToPosition(segment.Offset + segment.Length);
     253      var caret = textEditor.ActiveTextAreaControl.Caret;
     254      caret.Position = position;
     255      textEditor.ActiveTextAreaControl.CenterViewOn(line, 0);
     256    }
     257
    242258    private List<TextMarker> errorMarkers = new List<TextMarker>();
    243259    private List<Bookmark> errorBookmarks = new List<Bookmark>();
    244260    public void ShowCompileErrors(CompilerErrorCollection compilerErrors, string filename) {
    245       Doc.MarkerStrategy.RemoveAll(m => errorMarkers.Contains(m));
    246       Doc.BookmarkManager.RemoveMarks(m => errorBookmarks.Contains(m));
    247       errorMarkers.Clear();
    248       errorBookmarks.Clear();
    249261      errorLabel.Text = "";
    250262      errorLabel.ToolTipText = null;
     
    273285    private void AddErrorMarker(CompilerError error) {
    274286      var segment = GetSegmentAtOffset(error.Line, error.Column);
    275       Color color = error.IsWarning ? Color.Blue : Color.Red;
     287      Color color = error.IsWarning ? WarningColor : ErrorColor;
    276288      var marker = new TextMarker(segment.Offset, segment.Length, TextMarkerType.WaveLine, color) {
    277289        ToolTip = error.ErrorText,
     
    282294
    283295    private void AddErrorBookmark(CompilerError error) {
    284       var bookmark = new ErrorBookmark(Doc, new TextLocation(error.Column, error.Line - 1));
     296      Color color = error.IsWarning ? WarningColor : ErrorColor;
     297      var bookmark = new ErrorBookmark(Doc, new TextLocation(error.Column, error.Line - 1), color);
    285298      errorBookmarks.Add(bookmark);
    286299      Doc.BookmarkManager.AddMark(bookmark);
     
    288301
    289302    private AbstractSegment GetSegmentAtOffset(int lineNr, int columnNr) {
    290       lineNr = Math.Max(Doc.OffsetToPosition(prefix.Length).Line, lineNr);
     303      lineNr = Math.Max(Doc.OffsetToPosition(prefix.Length).Line, lineNr - 1);
    291304      lineNr = Math.Min(Doc.OffsetToPosition(Doc.TextLength - suffix.Length).Line, lineNr);
    292       var line = Doc.GetLineSegment(lineNr - 1);
    293       columnNr = Math.Max(0, columnNr);
     305      var line = Doc.GetLineSegment(lineNr);
     306      columnNr = Math.Max(0, columnNr - 1);
    294307      columnNr = Math.Min(line.Length, columnNr);
    295308      var word = line.GetWord(columnNr);
     
    299312        segment.Length = word.Length;
    300313      } else {
    301         segment.Offset = line.Offset + columnNr - 1;
     314        segment.Offset = line.Offset + columnNr;
    302315        segment.Length = 1;
    303316      }
Note: See TracChangeset for help on using the changeset viewer.