From 1fa1c51f29dec13755f5ae40f504270f362f3afb Mon Sep 17 00:00:00 2001 From: Alexey Kudravtsev Date: Tue, 26 Jul 2016 15:43:05 +0300 Subject: [PATCH] encapsulate ImmutableText --- .../intellij/openapi/editor/impl/DocumentImpl.java | 11 ++--------- .../editor/ex/util/LexerEditorHighlighter.java | 14 +++++++++----- .../openapi/editor/impl/ImmediatePainter.java | 5 +---- 3 files changed, 12 insertions(+), 18 deletions(-) diff --git a/platform/core-impl/src/com/intellij/openapi/editor/impl/DocumentImpl.java b/platform/core-impl/src/com/intellij/openapi/editor/impl/DocumentImpl.java index 8c8fd78fc6bb..ed8630232770 100644 --- a/platform/core-impl/src/com/intellij/openapi/editor/impl/DocumentImpl.java +++ b/platform/core-impl/src/com/intellij/openapi/editor/impl/DocumentImpl.java @@ -848,13 +848,6 @@ public class DocumentImpl extends UserDataHolderBase implements DocumentEx { return myText; } - // Breaks encapsulation, yet required for current zero-latency typing implementation. - // TODO Should be removed when we implement typing without starting write actions. - @NotNull - public ImmutableText getImmutableText() { - return myText; - } - @Override public void addDocumentListener(@NotNull DocumentListener listener) { myCachedDocumentListeners.set(null); @@ -896,11 +889,11 @@ public class DocumentImpl extends UserDataHolderBase implements DocumentEx { doRemoveDocumentListener(listener, myCachedDocumentListeners, myDocumentListeners); } - public void addInternalBulkModeListener(@NotNull DocumentBulkUpdateListener listener) { + void addInternalBulkModeListener(@NotNull DocumentBulkUpdateListener listener) { myBulkDocumentInternalListeners.add(listener); } - public void removeInternalBulkModeListener(@NotNull DocumentBulkUpdateListener listener) { + void removeInternalBulkModeListener(@NotNull DocumentBulkUpdateListener listener) { myBulkDocumentInternalListeners.remove(listener); } diff --git a/platform/editor-ui-ex/src/com/intellij/openapi/editor/ex/util/LexerEditorHighlighter.java b/platform/editor-ui-ex/src/com/intellij/openapi/editor/ex/util/LexerEditorHighlighter.java index e47c898014ec..cdd2b3b57c24 100644 --- a/platform/editor-ui-ex/src/com/intellij/openapi/editor/ex/util/LexerEditorHighlighter.java +++ b/platform/editor-ui-ex/src/com/intellij/openapi/editor/ex/util/LexerEditorHighlighter.java @@ -27,7 +27,6 @@ import com.intellij.openapi.editor.ex.PrioritizedDocumentListener; import com.intellij.openapi.editor.highlighter.EditorHighlighter; import com.intellij.openapi.editor.highlighter.HighlighterClient; import com.intellij.openapi.editor.highlighter.HighlighterIterator; -import com.intellij.openapi.editor.impl.DocumentImpl; import com.intellij.openapi.editor.impl.EditorDocumentPriorities; import com.intellij.openapi.editor.markup.TextAttributes; import com.intellij.openapi.fileTypes.PlainSyntaxHighlighter; @@ -39,7 +38,8 @@ import com.intellij.openapi.util.Comparing; import com.intellij.psi.tree.IElementType; import com.intellij.util.ArrayUtil; import com.intellij.util.text.ImmutableCharSequence; -import com.intellij.util.text.ImmutableText; +import com.intellij.util.text.MergingCharSequence; +import com.intellij.util.text.SingleCharSequence; import com.intellij.util.ui.UIUtil; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -368,6 +368,7 @@ public class LexerEditorHighlighter implements EditorHighlighter, PrioritizedDoc return myHighlighter; } + @NotNull private TextAttributes getAttributes(IElementType tokenType) { TextAttributes attrs = myAttributesMap.get(tokenType); if (attrs == null) { @@ -380,7 +381,8 @@ public class LexerEditorHighlighter implements EditorHighlighter, PrioritizedDoc // Called to determine visual attributes of inserted character prior to starting a write action. // TODO Should be removed when we implement typing without starting write actions. - public TextAttributes getAttributes(DocumentImpl document, int offset, char c) { + @NotNull + public TextAttributes getAttributesForTypedChar(@NotNull Document document, int offset, char c) { int startOffset = 0; if (mySegments.getSegmentCount() > 0) { @@ -404,7 +406,8 @@ public class LexerEditorHighlighter implements EditorHighlighter, PrioritizedDoc startOffset = mySegments.getSegmentStart(startIndex); } - ImmutableText newText = document.getImmutableText().insert(offset, Character.toString(c)); + CharSequence text = document.getImmutableCharSequence(); + CharSequence newText = new MergingCharSequence(new MergingCharSequence(text.subSequence(0, offset), new SingleCharSequence(c)), text.subSequence(offset, text.length())); myLexer.start(newText, startOffset, newText.length(), myInitialState); @@ -420,7 +423,8 @@ public class LexerEditorHighlighter implements EditorHighlighter, PrioritizedDoc return getAttributes(tokenType); } - protected TextAttributes convertAttributes(@NotNull TextAttributesKey[] keys) { + @NotNull + TextAttributes convertAttributes(@NotNull TextAttributesKey[] keys) { TextAttributes attrs = new TextAttributes(); for (TextAttributesKey key : keys) { TextAttributes attrs2 = myScheme.getAttributes(key); diff --git a/platform/platform-impl/src/com/intellij/openapi/editor/impl/ImmediatePainter.java b/platform/platform-impl/src/com/intellij/openapi/editor/impl/ImmediatePainter.java index fa2ab69c2de3..436816218df2 100644 --- a/platform/platform-impl/src/com/intellij/openapi/editor/impl/ImmediatePainter.java +++ b/platform/platform-impl/src/com/intellij/openapi/editor/impl/ImmediatePainter.java @@ -17,9 +17,6 @@ package com.intellij.openapi.editor.impl; import com.intellij.ide.plugins.IdeaPluginDescriptor; import com.intellij.ide.plugins.PluginManager; -import com.intellij.notification.Notification; -import com.intellij.notification.NotificationGroup; -import com.intellij.notification.NotificationType; import com.intellij.openapi.actionSystem.ActionManager; import com.intellij.openapi.actionSystem.AnAction; import com.intellij.openapi.actionSystem.AnActionEvent; @@ -230,7 +227,7 @@ public class ImmediatePainter { private void paintImmediately(Graphics g, int offset, char c, boolean insert) { if (g == null) return; // editor component is currently not displayable - TextAttributes attributes = ((LexerEditorHighlighter)getHighlighter()).getAttributes((DocumentImpl)getDocument(), offset, c); + TextAttributes attributes = ((LexerEditorHighlighter)getHighlighter()).getAttributesForTypedChar(getDocument(), offset, c); int fontType = attributes.getFontType(); FontInfo fontInfo = EditorUtil.fontForChar(c, attributes.getFontType(), myEditor);