Commits

Anonymous committed d37be6f

Changed sexp highlighter to update only on caret stop events.

  • Participants
  • Parent commits 0c5e04f

Comments (0)

Files changed (1)

org.lispdev.editor/src/org/lispdev/editor/SexpHighlighter.java

 package org.lispdev.editor;
 
 import org.eclipse.jface.text.ITextViewer;
-import org.eclipse.swt.custom.CaretEvent;
-import org.eclipse.swt.custom.CaretListener;
+import org.eclipse.swt.SWT;
 import org.eclipse.swt.custom.StyleRange;
 import org.eclipse.swt.custom.StyledText;
 import org.eclipse.swt.events.KeyEvent;
 import org.eclipse.swt.events.KeyListener;
+import org.eclipse.swt.events.MouseEvent;
+import org.eclipse.swt.events.MouseListener;
 import org.eclipse.swt.graphics.Color;
 import org.eclipse.swt.graphics.RGB;
 import org.lispdev.editor.preferences.Preference;
 import org.lispdev.preferences.PreferenceItem;
 
 public class SexpHighlighter
-implements KeyListener, CaretListener, ItemListener
+implements KeyListener, MouseListener, ItemListener
 {
 
   private ITextViewer textViewer;
 
   private Color outerColor;
 
-  public void install(ITextViewer viewer)
+  public void install(final ITextViewer viewer)
   {
     if( viewer == null ) return;
     if( textViewer == viewer )
       return;
     }
     viewer.getTextWidget().addKeyListener(this);
-    viewer.getTextWidget().addCaretListener(this);
+    viewer.getTextWidget().addMouseListener(this);
     textViewer = viewer;
     Preference.COLOR_INNER.item().addListener(
         EditorPlugin.get().getPreferences(), this);
   {
     if( textViewer == null ) return;
     textViewer.getTextWidget().removeKeyListener(this);
-    textViewer.getTextWidget().removeCaretListener(this);
+    textViewer.getTextWidget().removeMouseListener(this);
     Preference.COLOR_INNER.item().removeListener(this);
     Preference.COLOR_OUTER.item().removeListener(this);
   }
 
   @Override
   public void keyPressed(KeyEvent e)
-  {
-    updateHighlighting();
+  {// only need to update highlighting for key events that might move us into a
+   // different s-expression scope
+    switch(e.character)
+    {
+      case '(':
+      case ')':
+      case '\b':
+      case '\n':
+      case '\r':
+        updateHighlighting();
+        return;
+    }
   }
 
   @Override
   public void keyReleased(KeyEvent e)
   {
-  }
-
-  @Override
-  public void caretMoved(CaretEvent event)
-  {
-    updateHighlighting();
+    switch(e.keyCode)
+    {
+      case SWT.HOME:
+      case SWT.END:
+      case SWT.DEL:
+      case SWT.KEYPAD_CR:
+      case SWT.ARROW_RIGHT:
+      case SWT.ARROW_LEFT:
+      case SWT.ARROW_DOWN:
+      case SWT.ARROW_UP:
+      case SWT.PAGE_DOWN:
+      case SWT.PAGE_UP:
+        updateHighlighting();
+    }
   }
 
   @Override
     updateColors();
   }
 
+  @Override
+  public void mouseDoubleClick(MouseEvent e)
+  {}
+
+  @Override
+  public void mouseDown(MouseEvent e)
+  {
+    updateHighlighting();
+  }
+
+  @Override
+  public void mouseUp(MouseEvent e)
+  {}
+
 }