Skip to content

Commit

Permalink
only activate background highlighter when needed (#1643)
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinushey committed Dec 6, 2017
1 parent 119d868 commit 30fd018
Showing 1 changed file with 22 additions and 4 deletions.
Expand Up @@ -35,6 +35,7 @@
import com.google.gwt.event.logical.shared.AttachEvent;
import com.google.gwt.event.logical.shared.ValueChangeEvent;
import com.google.gwt.event.logical.shared.ValueChangeHandler;
import com.google.gwt.event.shared.HandlerRegistration;
import com.google.gwt.user.client.Timer;
import com.google.inject.Inject;

Expand Down Expand Up @@ -173,7 +174,6 @@ public AceBackgroundHighlighter(AceEditor editor)
highlightPatterns_ = new ArrayList<HighlightPattern>();
handlers_ = new HandlerRegistrations(
editor.addEditorModeChangedHandler(this),
editor.addDocumentChangedHandler(this),
editor.addAttachHandler(this));

int n = editor.getRowCount();
Expand Down Expand Up @@ -224,7 +224,18 @@ public void onEditorModeChanged(EditorModeChangedEvent event)
clearMarkers();
clearRowState();
refreshHighlighters();
synchronizeFrom(0);

if (documentChangedHandler_ != null)
{
documentChangedHandler_.removeHandler();
documentChangedHandler_ = null;
}

if (!highlightPatterns_.isEmpty())
{
documentChangedHandler_ = editor_.addDocumentChangedHandler(this);
synchronizeFrom(0);
}
}

@Override
Expand Down Expand Up @@ -267,6 +278,11 @@ public void onAttachOrDetach(AttachEvent event)
if (!event.isAttached())
{
handlers_.removeHandler();
if (documentChangedHandler_ != null)
{
documentChangedHandler_.removeHandler();
documentChangedHandler_ = null;
}
}
}

Expand Down Expand Up @@ -442,11 +458,13 @@ private static final List<HighlightPattern> rMarkdownHighlightPatterns()

private final AceEditor editor_;
private final EditSession session_;
private final List<HighlightPattern> highlightPatterns_;
private final HandlerRegistrations handlers_;

private HighlightPattern activeHighlightPattern_;
private String activeModeId_;
private HandlerRegistration documentChangedHandler_;
private boolean enabled_;
private final List<HighlightPattern> highlightPatterns_;
private final HandlerRegistrations handlers_;

private final JsVectorInteger rowStates_;
private final JsVectorInteger markerIds_;
Expand Down

0 comments on commit 30fd018

Please sign in to comment.