diff options
Diffstat (limited to 'platform/platform-impl/src/com/intellij/openapi/editor')
22 files changed, 181 insertions, 141 deletions
diff --git a/platform/platform-impl/src/com/intellij/openapi/editor/actions/EditorActionUtil.java b/platform/platform-impl/src/com/intellij/openapi/editor/actions/EditorActionUtil.java index 8b7791086014..a0355cf71222 100644 --- a/platform/platform-impl/src/com/intellij/openapi/editor/actions/EditorActionUtil.java +++ b/platform/platform-impl/src/com/intellij/openapi/editor/actions/EditorActionUtil.java @@ -601,7 +601,9 @@ public class EditorActionUtil { } } caretModel.moveToOffset(newOffset); - editor.getScrollingModel().scrollToCaret(ScrollType.RELATIVE); + if (editor.getCaretModel().getCurrentCaret() == editor.getCaretModel().getPrimaryCaret()) { + editor.getScrollingModel().scrollToCaret(ScrollType.RELATIVE); + } setupSelection(editor, isWithSelection, selectionStart, blockSelectionStart); } @@ -673,7 +675,9 @@ public class EditorActionUtil { if (isWordStart(text, newOffset, camel)) break; } editor.getCaretModel().moveToOffset(newOffset); - editor.getScrollingModel().scrollToCaret(ScrollType.RELATIVE); + if (editor.getCaretModel().getCurrentCaret() == editor.getCaretModel().getPrimaryCaret()) { + editor.getScrollingModel().scrollToCaret(ScrollType.RELATIVE); + } setupSelection(editor, isWithSelection, selectionStart, blockSelectionStart); } diff --git a/platform/platform-impl/src/com/intellij/openapi/editor/ex/SoftWrapModelEx.java b/platform/platform-impl/src/com/intellij/openapi/editor/ex/SoftWrapModelEx.java index 48d43bcce8bd..e3c03c2fbbd4 100644 --- a/platform/platform-impl/src/com/intellij/openapi/editor/ex/SoftWrapModelEx.java +++ b/platform/platform-impl/src/com/intellij/openapi/editor/ex/SoftWrapModelEx.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2011 JetBrains s.r.o. + * Copyright 2000-2014 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,6 +16,7 @@ package com.intellij.openapi.editor.ex; import com.intellij.openapi.editor.*; +import com.intellij.openapi.editor.impl.EditorTextRepresentationHelper; import com.intellij.openapi.editor.impl.softwrap.SoftWrapDrawingType; import org.jetbrains.annotations.NotNull; @@ -149,4 +150,6 @@ public interface SoftWrapModelEx extends SoftWrapModel { * Allows to instruct current model to always return <code>'true'</code> from {@link #isRespectAdditionalColumns()}. */ void forceAdditionalColumnsUsage(); + + EditorTextRepresentationHelper getEditorTextRepresentationHelper(); } diff --git a/platform/platform-impl/src/com/intellij/openapi/editor/impl/BorderEffect.java b/platform/platform-impl/src/com/intellij/openapi/editor/impl/BorderEffect.java index cc1a23f6f8e5..2872699c8012 100644 --- a/platform/platform-impl/src/com/intellij/openapi/editor/impl/BorderEffect.java +++ b/platform/platform-impl/src/com/intellij/openapi/editor/impl/BorderEffect.java @@ -86,6 +86,8 @@ public class BorderEffect { markupModel.processRangeHighlightersOverlappingWith(myStartOffset, myEndOffset, new Processor<RangeHighlighterEx>() { @Override public boolean process(RangeHighlighterEx rangeHighlighter) { + if (!rangeHighlighter.getEditorFilter().avaliableIn(myEditor)) return true; + TextAttributes textAttributes = rangeHighlighter.getTextAttributes(); if (isBorder(textAttributes) && intersectsRange(rangeHighlighter)) { paintBorder(rangeHighlighter, textAttributes); diff --git a/platform/platform-impl/src/com/intellij/openapi/editor/impl/CaretImpl.java b/platform/platform-impl/src/com/intellij/openapi/editor/impl/CaretImpl.java index 068f25e16565..cfd039a5d504 100644 --- a/platform/platform-impl/src/com/intellij/openapi/editor/impl/CaretImpl.java +++ b/platform/platform-impl/src/com/intellij/openapi/editor/impl/CaretImpl.java @@ -1453,10 +1453,17 @@ public class CaretImpl extends UserDataHolderBase implements Caret { return marker != null && marker.isValid() && isVirtualSelectionEnabled() && myEndVirtualOffset > myStartVirtualOffset; } + @Override + @NotNull public EditorImpl getEditor() { return myEditor; } + @Override + public String toString() { + return "Caret at " + myVisibleCaret + (mySelectionMarker == null ? "" : (", selection marker: " + mySelectionMarker.toString())); + } + /** * Encapsulates information about target vertical range info - its <code>'y'</code> coordinate and height in pixels. */ diff --git a/platform/platform-impl/src/com/intellij/openapi/editor/impl/CaretModelImpl.java b/platform/platform-impl/src/com/intellij/openapi/editor/impl/CaretModelImpl.java index a18d45472454..8d6608e63dd9 100644 --- a/platform/platform-impl/src/com/intellij/openapi/editor/impl/CaretModelImpl.java +++ b/platform/platform-impl/src/com/intellij/openapi/editor/impl/CaretModelImpl.java @@ -282,11 +282,9 @@ public class CaretModelImpl implements CaretModel, PrioritizedDocumentListener, } } - boolean addCaret(CaretImpl caretToAdd) { + boolean addCaret(@NotNull CaretImpl caretToAdd) { for (CaretImpl caret : myCarets) { - VisualPosition newVisualPosition = caretToAdd.getVisualPosition(); - int newOffset = myEditor.logicalPositionToOffset(myEditor.visualToLogicalPosition(newVisualPosition)); - if (caret.getVisualPosition().equals(newVisualPosition) || newOffset >= caret.getSelectionStart() && newOffset <= caret.getSelectionEnd()) { + if (caretsOverlap(caret, caretToAdd)) { return false; } } @@ -384,8 +382,7 @@ public class CaretModelImpl implements CaretModel, PrioritizedDocumentListener, it.next(); } CaretImpl currCaret = it.next(); - if (prevCaret != null && (currCaret.getVisualPosition().equals(prevCaret.getVisualPosition()) - || selectionsIntersect(currCaret, prevCaret))) { + if (prevCaret != null && caretsOverlap(currCaret, prevCaret)) { int newSelectionStart = Math.min(currCaret.getSelectionStart(), prevCaret.getSelectionStart()); int newSelectionEnd = Math.max(currCaret.getSelectionEnd(), prevCaret.getSelectionEnd()); CaretImpl toRetain, toRemove; @@ -410,7 +407,10 @@ public class CaretModelImpl implements CaretModel, PrioritizedDocumentListener, } } - private static boolean selectionsIntersect(CaretImpl firstCaret, CaretImpl secondCaret) { + private static boolean caretsOverlap(@NotNull CaretImpl firstCaret, @NotNull CaretImpl secondCaret) { + if (firstCaret.getVisualPosition().equals(secondCaret.getVisualPosition())) { + return true; + } int firstStart = firstCaret.getSelectionStart(); int secondStart = secondCaret.getSelectionStart(); int firstEnd = firstCaret.getSelectionEnd(); diff --git a/platform/platform-impl/src/com/intellij/openapi/editor/impl/DefaultEditorTextRepresentationHelper.java b/platform/platform-impl/src/com/intellij/openapi/editor/impl/DefaultEditorTextRepresentationHelper.java index 9b2e473a0da5..61415eb90ce4 100644 --- a/platform/platform-impl/src/com/intellij/openapi/editor/impl/DefaultEditorTextRepresentationHelper.java +++ b/platform/platform-impl/src/com/intellij/openapi/editor/impl/DefaultEditorTextRepresentationHelper.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2012 JetBrains s.r.o. + * Copyright 2000-2014 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,14 +16,14 @@ package com.intellij.openapi.editor.impl; import com.intellij.openapi.editor.Editor; -import com.intellij.openapi.editor.colors.EditorColorsScheme; import com.intellij.openapi.editor.ex.util.EditorUtil; import gnu.trove.TObjectIntHashMap; import org.intellij.lang.annotations.JdkConstants; import org.jetbrains.annotations.NotNull; /** - * Not thread-safe. + * Not thread-safe. Performs caching of char widths, so cache reset must be invoked (via {@link #clearSymbolWidthCache()} method) when + * font settings are changed in editor. * * @author Denis Zhdanov * @since Jul 27, 2010 4:06:27 PM @@ -60,9 +60,6 @@ public class DefaultEditorTextRepresentationHelper implements EditorTextRepresen public int charWidth(char c, int fontType) { // Symbol width retrieval is detected to be a bottleneck, hence, we perform a caching here in assumption that every representation // helper is editor-bound and cache size is not too big. - EditorColorsScheme colorsScheme = myEditor.getColorsScheme(); - mySharedKey.fontName = colorsScheme.getEditorFontName(); - mySharedKey.fontSize = colorsScheme.getEditorFontSize(); mySharedKey.fontType = fontType; mySharedKey.c = c; @@ -83,9 +80,6 @@ public class DefaultEditorTextRepresentationHelper implements EditorTextRepresen // Symbol width retrieval is detected to be a bottleneck, hence, we perform a caching here in assumption that every representation // helper is editor-bound and cache size is not too big. - EditorColorsScheme colorsScheme = myEditor.getColorsScheme(); - mySharedKey.fontName = colorsScheme.getEditorFontName(); - mySharedKey.fontSize = colorsScheme.getEditorFontSize(); mySharedKey.fontType = fontType; for (int i = startToUse; i < end; i++) { @@ -107,7 +101,7 @@ public class DefaultEditorTextRepresentationHelper implements EditorTextRepresen return result; } Key key = mySharedKey.clone(); - FontInfo font = ComplementaryFontsRegistry.getFontAbleToDisplay(c, key.fontSize, key.fontType, key.fontName); + FontInfo font = ComplementaryFontsRegistry.getFontAbleToDisplay(c, key.fontType, myEditor.getColorsScheme().getFontPreferences()); result = font.charWidth(c); if (mySymbolWidthCache.size() >= MAX_SYMBOLS_WIDTHS_CACHE_SIZE) { // Don't expect to be here. @@ -117,33 +111,31 @@ public class DefaultEditorTextRepresentationHelper implements EditorTextRepresen return result; } + public void clearSymbolWidthCache() { + mySymbolWidthCache.clear(); + } + private static class Key { - public String fontName; - private int fontSize; @JdkConstants.FontStyle private int fontType; private char c; private Key() { - this(null, 0, 0, ' '); + this(0, ' '); } - Key(String fontName, int fontSize, @JdkConstants.FontStyle int fontType, char c) { - this.fontName = fontName; - this.fontSize = fontSize; + Key(@JdkConstants.FontStyle int fontType, char c) { this.fontType = fontType; this.c = c; } @Override protected Key clone() { - return new Key(fontName, fontSize, fontType, c); + return new Key(fontType, c); } @Override public int hashCode() { - int result = fontName != null ? fontName.hashCode() : 0; - result = 31 * result + fontSize; - result = 31 * result + fontType; + int result = fontType; result = 31 * result + c; return result; } @@ -155,10 +147,8 @@ public class DefaultEditorTextRepresentationHelper implements EditorTextRepresen Key key = (Key)o; - if (fontSize != key.fontSize) return false; if (fontType != key.fontType) return false; if (c != key.c) return false; - if (fontName != null ? !fontName.equals(key.fontName) : key.fontName != null) return false; return true; } diff --git a/platform/platform-impl/src/com/intellij/openapi/editor/impl/EditorImpl.java b/platform/platform-impl/src/com/intellij/openapi/editor/impl/EditorImpl.java index e37ad8f968ad..b708f38a9190 100644 --- a/platform/platform-impl/src/com/intellij/openapi/editor/impl/EditorImpl.java +++ b/platform/platform-impl/src/com/intellij/openapi/editor/impl/EditorImpl.java @@ -66,6 +66,8 @@ import com.intellij.openapi.util.text.StringUtil; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.openapi.wm.IdeFocusManager; import com.intellij.openapi.wm.IdeGlassPane; +import com.intellij.openapi.wm.ToolWindowAnchor; +import com.intellij.openapi.wm.ex.ToolWindowManagerEx; import com.intellij.psi.PsiDocumentManager; import com.intellij.psi.PsiFile; import com.intellij.ui.*; @@ -320,7 +322,7 @@ public final class EditorImpl extends UserDataHolderBase implements EditorEx, Hi myScheme = createBoundColorSchemeDelegate(null); initTabPainter(); myIsViewer = viewer; - mySettings = new SettingsImpl(this); + mySettings = new SettingsImpl(this, project); mySelectionModel = new SelectionModelImpl(this); myMarkupModel = new EditorMarkupModelImpl(this); @@ -1979,6 +1981,8 @@ public final class EditorImpl extends UserDataHolderBase implements EditorEx, Hi myMarkupModel.processRangeHighlightersOverlappingWith(clipStartOffset, clipEndOffset, new Processor<RangeHighlighterEx>() { @Override public boolean process(@NotNull RangeHighlighterEx highlighter) { + if (!highlighter.getEditorFilter().avaliableIn(EditorImpl.this)) return true; + final CustomHighlighterRenderer customRenderer = highlighter.getCustomRenderer(); if (customRenderer != null && clipStartOffset < highlighter.getEndOffset() && highlighter.getStartOffset() < clipEndOffset) { customRenderer.paint(EditorImpl.this, highlighter, g); @@ -2124,6 +2128,8 @@ public final class EditorImpl extends UserDataHolderBase implements EditorEx, Hi Processor<RangeHighlighterEx> paintProcessor = new Processor<RangeHighlighterEx>() { @Override public boolean process(@NotNull RangeHighlighterEx highlighter) { + if (!highlighter.getEditorFilter().avaliableIn(EditorImpl.this)) return true; + paintSegmentHighlighterAfterEndOfLine(g, highlighter, startLine, endLine); return true; } @@ -2978,6 +2984,8 @@ public final class EditorImpl extends UserDataHolderBase implements EditorEx, Hi markupModel.processRangeHighlightersOverlappingWith(clipStartOffset, clipEndOffset, new Processor<RangeHighlighterEx>() { @Override public boolean process(@NotNull RangeHighlighterEx lineMarker) { + if (!lineMarker.getEditorFilter().avaliableIn(EditorImpl.this)) return true; + paintLineMarkerSeparator(lineMarker, clip, g); return true; } @@ -6735,7 +6743,7 @@ public final class EditorImpl extends UserDataHolderBase implements EditorEx, Hi } } - private static class TablessBorder extends SideBorder { + private class TablessBorder extends SideBorder { private TablessBorder() { super(UIUtil.getBorderColor(), SideBorder.ALL); } @@ -6760,7 +6768,9 @@ public final class EditorImpl extends UserDataHolderBase implements EditorEx, Hi @Override public Insets getBorderInsets(Component c) { Container splitters = SwingUtilities.getAncestorOfClass(EditorsSplitters.class, c); - return splitters == null ? super.getBorderInsets(c) : new Insets(1, 0, 0, 0); + boolean thereIsSomethingAbove = !SystemInfo.isMac || UISettings.getInstance().SHOW_MAIN_TOOLBAR || UISettings.getInstance().SHOW_NAVIGATION_BAR || + EditorImpl.this.myProject != null && !ToolWindowManagerEx.getInstanceEx(EditorImpl.this.myProject).getIdsOn(ToolWindowAnchor.TOP).isEmpty(); + return splitters == null ? super.getBorderInsets(c) : new Insets(thereIsSomethingAbove ? 1 : 0, 0, 0, 0); } @Override diff --git a/platform/platform-impl/src/com/intellij/openapi/editor/impl/EditorMarkupModelImpl.java b/platform/platform-impl/src/com/intellij/openapi/editor/impl/EditorMarkupModelImpl.java index c721a5a5873b..a2f45fe33857 100644 --- a/platform/platform-impl/src/com/intellij/openapi/editor/impl/EditorMarkupModelImpl.java +++ b/platform/platform-impl/src/com/intellij/openapi/editor/impl/EditorMarkupModelImpl.java @@ -45,6 +45,7 @@ import com.intellij.openapi.ui.MessageType; import com.intellij.openapi.ui.popup.Balloon; import com.intellij.openapi.util.Disposer; import com.intellij.openapi.util.ProperTextRange; +import com.intellij.openapi.util.SystemInfo; import com.intellij.openapi.wm.ToolWindowAnchor; import com.intellij.openapi.wm.ex.ToolWindowManagerEx; import com.intellij.ui.*; @@ -229,6 +230,8 @@ public class EditorMarkupModelImpl extends MarkupModelImpl implements EditorMark markupModel.processRangeHighlightersOverlappingWith(startOffset, endOffset, new Processor<RangeHighlighterEx>() { @Override public boolean process(RangeHighlighterEx highlighter) { + if (!highlighter.getEditorFilter().avaliableIn(myEditor)) return true; + if (highlighter.getErrorStripeMarkColor() != null) { if (highlighter.getStartOffset() < endOffset && highlighter.getEndOffset() > startOffset) { highlighters.add(highlighter); @@ -266,6 +269,8 @@ public class EditorMarkupModelImpl extends MarkupModelImpl implements EditorMark markupModel.processRangeHighlightersOverlappingWith(startOffset, endOffset, new Processor<RangeHighlighterEx>() { @Override public boolean process(RangeHighlighterEx highlighter) { + if (!highlighter.getEditorFilter().avaliableIn(myEditor)) return true; + if (highlighter.getErrorStripeMarkColor() != null) { ProperTextRange range = offsetsToYPositions(highlighter.getStartOffset(), highlighter.getEndOffset()); if (scrollBarY >= range.getStartOffset() - myMinMarkHeight * 2 && @@ -432,7 +437,7 @@ public class EditorMarkupModelImpl extends MarkupModelImpl implements EditorMark errorIconBounds.y = bounds.height / 2 - errorIconBounds.height / 2; try { - if (UISettings.getInstance().PRESENTATION_MODE) { + if (UISettings.getInstance().PRESENTATION_MODE || SystemInfo.isMac) { g.setColor(getEditor().getColorsScheme().getDefaultBackground()); g.fillRect(0, 0, bounds.width, bounds.height); @@ -523,7 +528,7 @@ public class EditorMarkupModelImpl extends MarkupModelImpl implements EditorMark @Override protected void paintThumb(Graphics g, JComponent c, Rectangle thumbBounds) { - if (UISettings.getInstance().PRESENTATION_MODE) { + if (UISettings.getInstance().PRESENTATION_MODE || SystemInfo.isMac) { super.paintThumb(g, c, thumbBounds); return; } @@ -560,16 +565,16 @@ public class EditorMarkupModelImpl extends MarkupModelImpl implements EditorMark @Override protected int getThickness() { - if (UISettings.getInstance().PRESENTATION_MODE) return super.getThickness(); + if (UISettings.getInstance().PRESENTATION_MODE || SystemInfo.isMac) return super.getThickness(); return super.getThickness() + (isMacOverlayScrollbar() ? 2 : 7); } @Override protected void doPaintTrack(Graphics g, JComponent c, Rectangle bounds) { - if (UISettings.getInstance().PRESENTATION_MODE) { + if (UISettings.getInstance().PRESENTATION_MODE || SystemInfo.isMac) { g.setColor(getEditor().getColorsScheme().getDefaultBackground()); g.fillRect(bounds.x, bounds.y, bounds.width, bounds.height); - return; + //return; } Rectangle clip = g.getClipBounds().intersection(bounds); if (clip.height == 0) return; @@ -604,7 +609,7 @@ public class EditorMarkupModelImpl extends MarkupModelImpl implements EditorMark } private void paintTrackBasement(Graphics g, Rectangle bounds) { - if (UISettings.getInstance().PRESENTATION_MODE) { + if (UISettings.getInstance().PRESENTATION_MODE || SystemInfo.isMac) { return; } @@ -661,6 +666,8 @@ public class EditorMarkupModelImpl extends MarkupModelImpl implements EditorMark markup.processRangeHighlightersOverlappingWith(startOffset, endOffset, new Processor<RangeHighlighterEx>() { @Override public boolean process(RangeHighlighterEx highlighter) { + if (!highlighter.getEditorFilter().avaliableIn(myEditor)) return true; + Color color = highlighter.getErrorStripeMarkColor(); if (color == null) return true; boolean isThin = highlighter.isThinErrorStripeMark(); diff --git a/platform/platform-impl/src/com/intellij/openapi/editor/impl/FoldingModelImpl.java b/platform/platform-impl/src/com/intellij/openapi/editor/impl/FoldingModelImpl.java index 694bc75a5751..b92970425e99 100644 --- a/platform/platform-impl/src/com/intellij/openapi/editor/impl/FoldingModelImpl.java +++ b/platform/platform-impl/src/com/intellij/openapi/editor/impl/FoldingModelImpl.java @@ -265,9 +265,6 @@ public class FoldingModelImpl implements FoldingModelEx, PrioritizedDocumentList if (line >= myEditor.getDocument().getLineCount()) return null; - //leftmost folded block position - if (myEditor.xyToVisualPosition(p).equals(myEditor.logicalToVisualPosition(pos))) return null; - int offset = myEditor.logicalPositionToOffset(pos); return myFoldTree.fetchOutermost(offset); diff --git a/platform/platform-impl/src/com/intellij/openapi/editor/impl/SelectionModelImpl.java b/platform/platform-impl/src/com/intellij/openapi/editor/impl/SelectionModelImpl.java index 263ea77c286f..2f5a81153579 100644 --- a/platform/platform-impl/src/com/intellij/openapi/editor/impl/SelectionModelImpl.java +++ b/platform/platform-impl/src/com/intellij/openapi/editor/impl/SelectionModelImpl.java @@ -36,16 +36,13 @@ import com.intellij.openapi.editor.ex.DocumentEx; import com.intellij.openapi.editor.ex.PrioritizedDocumentListener; import com.intellij.openapi.editor.ex.util.EditorUtil; import com.intellij.openapi.editor.markup.TextAttributes; -import com.intellij.openapi.ide.CopyPasteManager; import com.intellij.openapi.util.Pair; -import com.intellij.openapi.util.text.StringUtil; import com.intellij.util.ArrayUtil; import com.intellij.util.containers.ContainerUtil; import gnu.trove.TIntArrayList; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -import java.awt.datatransfer.StringSelection; import java.util.Collection; import java.util.Iterator; import java.util.LinkedList; @@ -570,13 +567,7 @@ public class SelectionModelImpl implements SelectionModel, PrioritizedDocumentLi @Override public void copySelectionToClipboard() { - validateContext(true); - String s = getSelectedText(true); - if (s == null) return; - - s = StringUtil.convertLineSeparators(s); - StringSelection contents = new StringSelection(s); - CopyPasteManager.getInstance().setContents(contents); + CopyPasteSupport.copySelectionToClipboard(myEditor); } @Override diff --git a/platform/platform-impl/src/com/intellij/openapi/editor/impl/SettingsImpl.java b/platform/platform-impl/src/com/intellij/openapi/editor/impl/SettingsImpl.java index dabf5e9d2a2f..f2dbc6756ef5 100644 --- a/platform/platform-impl/src/com/intellij/openapi/editor/impl/SettingsImpl.java +++ b/platform/platform-impl/src/com/intellij/openapi/editor/impl/SettingsImpl.java @@ -25,6 +25,8 @@ package com.intellij.openapi.editor.impl; import com.intellij.codeStyle.CodeStyleFacade; +import com.intellij.lang.Language; +import com.intellij.openapi.editor.Document; import com.intellij.openapi.editor.EditorSettings; import com.intellij.openapi.editor.ex.EditorEx; import com.intellij.openapi.editor.ex.EditorSettingsExternalizable; @@ -32,10 +34,14 @@ import com.intellij.openapi.editor.impl.softwrap.SoftWrapAppliancePlaces; import com.intellij.openapi.fileTypes.FileType; import com.intellij.openapi.project.Project; import com.intellij.openapi.vfs.VirtualFile; +import com.intellij.psi.PsiDocumentManager; +import com.intellij.psi.PsiFile; +import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; public class SettingsImpl implements EditorSettings { @Nullable private final EditorEx myEditor; + @Nullable private final Language myLanguage; private Boolean myIsCamelWords; // This group of settings does not have UI @@ -78,9 +84,14 @@ public class SettingsImpl implements EditorSettings { private Boolean myRenamePreselect = null; private Boolean myWrapWhenTypingReachesRightMargin = null; private Boolean myShowIntentionBulb = null; + + public SettingsImpl() { + this(null, null); + } - public SettingsImpl(@Nullable EditorEx editor) { + public SettingsImpl(@Nullable EditorEx editor, @Nullable Project project) { myEditor = editor; + myLanguage = editor != null && project != null ? getDocumentLanguage(project, editor.getDocument()) : null; } @Override @@ -144,7 +155,17 @@ public class SettingsImpl implements EditorSettings { @Override public int getRightMargin(Project project) { return myRightMargin != null ? myRightMargin.intValue() : - CodeStyleFacade.getInstance(project).getRightMargin(); + CodeStyleFacade.getInstance(project).getRightMargin(myLanguage); + } + + @Nullable + private static Language getDocumentLanguage(@Nullable Project project, @NotNull Document document) { + if (project != null) { + PsiDocumentManager documentManager = PsiDocumentManager.getInstance(project); + PsiFile file = documentManager.getPsiFile(document); + if (file != null) return file.getLanguage(); + } + return null; } @Override diff --git a/platform/platform-impl/src/com/intellij/openapi/editor/impl/SoftWrapModelImpl.java b/platform/platform-impl/src/com/intellij/openapi/editor/impl/SoftWrapModelImpl.java index cccf86c5f98e..6f1b9820132b 100644 --- a/platform/platform-impl/src/com/intellij/openapi/editor/impl/SoftWrapModelImpl.java +++ b/platform/platform-impl/src/com/intellij/openapi/editor/impl/SoftWrapModelImpl.java @@ -21,6 +21,7 @@ import com.intellij.openapi.application.Application; import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.editor.*; +import com.intellij.openapi.editor.colors.FontPreferences; import com.intellij.openapi.editor.event.DocumentEvent; import com.intellij.openapi.editor.event.DocumentListener; import com.intellij.openapi.editor.ex.*; @@ -89,9 +90,10 @@ public class SoftWrapModelImpl implements SoftWrapModelEx, PrioritizedDocumentLi private SoftWrapPainter myPainter; private final SoftWrapApplianceManager myApplianceManager; private final SoftWrapAwareVisualSizeManager myVisualSizeManager; + private EditorTextRepresentationHelper myEditorTextRepresentationHelper; private final EditorEx myEditor; - + /** * We don't want to use soft wraps-aware processing from non-EDT and profiling shows that 'is EDT' check that is called too * often is rather expensive. Hence, we use caching here for performance improvement. @@ -101,6 +103,8 @@ public class SoftWrapModelImpl implements SoftWrapModelEx, PrioritizedDocumentLi private int myActive; private boolean myUseSoftWraps; private int myTabWidth = -1; + @NotNull + private FontPreferences myFontPreferences; /** * Soft wraps need to be kept up-to-date on all editor modification (changing text, adding/removing/expanding/collapsing fold @@ -132,9 +136,9 @@ public class SoftWrapModelImpl implements SoftWrapModelEx, PrioritizedDocumentLi myEditor = editor; myStorage = new SoftWrapsStorage(); myPainter = new CompositeSoftWrapPainter(editor); - DefaultEditorTextRepresentationHelper representationHelper = new DefaultEditorTextRepresentationHelper(editor); - myDataMapper = new CachingSoftWrapDataMapper(editor, myStorage, representationHelper); - myApplianceManager = new SoftWrapApplianceManager(myStorage, editor, myPainter, representationHelper, myDataMapper); + myEditorTextRepresentationHelper = new DefaultEditorTextRepresentationHelper(editor); + myDataMapper = new CachingSoftWrapDataMapper(editor, myStorage); + myApplianceManager = new SoftWrapApplianceManager(myStorage, editor, myPainter, myDataMapper); myFoldBasedApplianceStrategy = new SoftWrapFoldBasedApplianceStrategy(editor); myVisualSizeManager = new SoftWrapAwareVisualSizeManager(myPainter); @@ -150,6 +154,7 @@ public class SoftWrapModelImpl implements SoftWrapModelEx, PrioritizedDocumentLi }); EditorSettings settings = myEditor.getSettings(); myUseSoftWraps = settings.isUseSoftWraps(); + myFontPreferences = myEditor.getColorsScheme().getFontPreferences(); editor.addPropertyChangeListener(this); @@ -168,8 +173,16 @@ public class SoftWrapModelImpl implements SoftWrapModelEx, PrioritizedDocumentLi int tabWidthBefore = myTabWidth; myTabWidth = getCurrentTabWidth(); + + boolean fontsChanged = false; + if (!myFontPreferences.equals(myEditor.getColorsScheme().getFontPreferences()) + && myEditorTextRepresentationHelper instanceof DefaultEditorTextRepresentationHelper) { + fontsChanged = true; + myFontPreferences = myEditor.getColorsScheme().getFontPreferences(); + ((DefaultEditorTextRepresentationHelper)myEditorTextRepresentationHelper).clearSymbolWidthCache(); + } - if ((myUseSoftWraps ^ softWrapsUsedBefore) || (tabWidthBefore >= 0 && myTabWidth != tabWidthBefore)) { + if ((myUseSoftWraps ^ softWrapsUsedBefore) || (tabWidthBefore >= 0 && myTabWidth != tabWidthBefore) || fontsChanged) { myApplianceManager.reset(); myDeferredFoldRegions.clear(); myEditor.getScrollingModel().scrollToCaret(ScrollType.CENTER); @@ -705,6 +718,20 @@ public class SoftWrapModelImpl implements SoftWrapModelEx, PrioritizedDocumentLi myVisualSizeManager.setSoftWrapPainter(painter); } + public static EditorTextRepresentationHelper getEditorTextRepresentationHelper(@NotNull Editor editor) { + return ((SoftWrapModelEx)editor.getSoftWrapModel()).getEditorTextRepresentationHelper(); + } + + public EditorTextRepresentationHelper getEditorTextRepresentationHelper() { + return myEditorTextRepresentationHelper; + } + + @TestOnly + public void setEditorTextRepresentationHelper(EditorTextRepresentationHelper editorTextRepresentationHelper) { + myEditorTextRepresentationHelper = editorTextRepresentationHelper; + myApplianceManager.reset(); + } + @NotNull @Override public String dumpState() { diff --git a/platform/platform-impl/src/com/intellij/openapi/editor/impl/softwrap/mapping/AbstractMappingStrategy.java b/platform/platform-impl/src/com/intellij/openapi/editor/impl/softwrap/mapping/AbstractMappingStrategy.java index 26c8086beb72..bccdf4c59336 100644 --- a/platform/platform-impl/src/com/intellij/openapi/editor/impl/softwrap/mapping/AbstractMappingStrategy.java +++ b/platform/platform-impl/src/com/intellij/openapi/editor/impl/softwrap/mapping/AbstractMappingStrategy.java @@ -15,12 +15,10 @@ */ package com.intellij.openapi.editor.impl.softwrap.mapping; -import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.editor.Document; import com.intellij.openapi.editor.Editor; import com.intellij.openapi.editor.FoldRegion; import com.intellij.openapi.editor.LogicalPosition; -import com.intellij.openapi.editor.impl.EditorTextRepresentationHelper; import com.intellij.openapi.editor.impl.softwrap.SoftWrapsStorage; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -39,10 +37,7 @@ import java.util.List; */ abstract class AbstractMappingStrategy<T> implements MappingStrategy<T> { - private static final Logger LOG = Logger.getInstance("#" + AbstractMappingStrategy.class.getName()); - protected final Editor myEditor; - protected final EditorTextRepresentationHelper myRepresentationHelper; protected final SoftWrapsStorage myStorage; protected final List<CacheEntry> myCache; @@ -53,13 +48,11 @@ abstract class AbstractMappingStrategy<T> implements MappingStrategy<T> { AbstractMappingStrategy(@NotNull Editor editor, @NotNull SoftWrapsStorage storage, - @NotNull List<CacheEntry> cache, - @NotNull EditorTextRepresentationHelper representationHelper) + @NotNull List<CacheEntry> cache) { myEditor = editor; myStorage = storage; myCache = cache; - myRepresentationHelper = representationHelper; } @Nullable @@ -73,7 +66,7 @@ abstract class AbstractMappingStrategy<T> implements MappingStrategy<T> { } protected void setFirstInitialPosition() { - myInitialPosition = new EditorPosition(new LogicalPosition(0, 0), 0, myEditor, myRepresentationHelper); + myInitialPosition = new EditorPosition(new LogicalPosition(0, 0), 0, myEditor); } @Nullable diff --git a/platform/platform-impl/src/com/intellij/openapi/editor/impl/softwrap/mapping/CacheEntry.java b/platform/platform-impl/src/com/intellij/openapi/editor/impl/softwrap/mapping/CacheEntry.java index 57ef56c178e9..27362b52527a 100644 --- a/platform/platform-impl/src/com/intellij/openapi/editor/impl/softwrap/mapping/CacheEntry.java +++ b/platform/platform-impl/src/com/intellij/openapi/editor/impl/softwrap/mapping/CacheEntry.java @@ -17,7 +17,6 @@ package com.intellij.openapi.editor.impl.softwrap.mapping; import com.intellij.openapi.editor.Editor; import com.intellij.openapi.editor.FoldRegion; -import com.intellij.openapi.editor.impl.EditorTextRepresentationHelper; import com.intellij.openapi.util.Ref; import gnu.trove.TIntObjectHashMap; import gnu.trove.TIntObjectProcedure; @@ -25,7 +24,10 @@ import gnu.trove.TObjectProcedure; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -import java.util.*; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; /** * Encapsulates information to cache for the single visual line. @@ -59,7 +61,6 @@ class CacheEntry implements Comparable<CacheEntry>, Cloneable { public boolean locked; private final Editor myEditor; - private final EditorTextRepresentationHelper myRepresentationHelper; /** Holds positions for the tabulation symbols on a target visual line sorted by offset in ascending order. */ private List<TabData> myTabPositions = Collections.EMPTY_LIST; @@ -67,10 +68,9 @@ class CacheEntry implements Comparable<CacheEntry>, Cloneable { /** Holds information about single line fold regions representation data. */ private TIntObjectHashMap<FoldingData> myFoldingData = DUMMY; - CacheEntry(int visualLine, @NotNull Editor editor, @NotNull EditorTextRepresentationHelper representationHelper) { + CacheEntry(int visualLine, @NotNull Editor editor) { this.visualLine = visualLine; myEditor = editor; - myRepresentationHelper = representationHelper; } public void setLineStartPosition(@NotNull EditorPosition context) { @@ -99,7 +99,7 @@ class CacheEntry implements Comparable<CacheEntry>, Cloneable { } public EditorPosition buildStartLinePosition() { - EditorPosition result = new EditorPosition(myEditor, myRepresentationHelper); + EditorPosition result = new EditorPosition(myEditor); result.logicalLine = startLogicalLine; result.logicalColumn = startLogicalColumn; result.offset = startOffset; @@ -114,7 +114,7 @@ class CacheEntry implements Comparable<CacheEntry>, Cloneable { } public EditorPosition buildEndLinePosition() { - EditorPosition result = new EditorPosition(myEditor, myRepresentationHelper); + EditorPosition result = new EditorPosition(myEditor); result.logicalLine = endLogicalLine; result.logicalColumn = endLogicalColumn; result.offset = endOffset; @@ -246,7 +246,7 @@ class CacheEntry implements Comparable<CacheEntry>, Cloneable { @Override protected CacheEntry clone() { - final CacheEntry result = new CacheEntry(visualLine, myEditor, myRepresentationHelper); + final CacheEntry result = new CacheEntry(visualLine, myEditor); result.startLogicalLine = startLogicalLine; result.startLogicalColumn = startLogicalColumn; diff --git a/platform/platform-impl/src/com/intellij/openapi/editor/impl/softwrap/mapping/CachingSoftWrapDataMapper.java b/platform/platform-impl/src/com/intellij/openapi/editor/impl/softwrap/mapping/CachingSoftWrapDataMapper.java index 08bf0211dbc8..2f21b0319af2 100644 --- a/platform/platform-impl/src/com/intellij/openapi/editor/impl/softwrap/mapping/CachingSoftWrapDataMapper.java +++ b/platform/platform-impl/src/com/intellij/openapi/editor/impl/softwrap/mapping/CachingSoftWrapDataMapper.java @@ -21,7 +21,7 @@ import com.intellij.openapi.editor.*; import com.intellij.openapi.editor.ex.EditorEx; import com.intellij.openapi.editor.ex.FoldingModelEx; import com.intellij.openapi.editor.impl.EditorImpl; -import com.intellij.openapi.editor.impl.EditorTextRepresentationHelper; +import com.intellij.openapi.editor.impl.SoftWrapModelImpl; import com.intellij.openapi.editor.impl.softwrap.SoftWrapDataMapper; import com.intellij.openapi.editor.impl.softwrap.SoftWrapImpl; import com.intellij.openapi.editor.impl.softwrap.SoftWrapsStorage; @@ -71,19 +71,16 @@ public class CachingSoftWrapDataMapper implements SoftWrapDataMapper, SoftWrapAw private final VisualToLogicalCalculationStrategy myVisualToLogicalStrategy; private final EditorEx myEditor; private final SoftWrapsStorage myStorage; - private final EditorTextRepresentationHelper myRepresentationHelper; private final CacheEntry mySearchKey; - public CachingSoftWrapDataMapper(@NotNull EditorEx editor, @NotNull SoftWrapsStorage storage, - @NotNull EditorTextRepresentationHelper representationHelper) + public CachingSoftWrapDataMapper(@NotNull EditorEx editor, @NotNull SoftWrapsStorage storage) { myEditor = editor; myStorage = storage; - myRepresentationHelper = representationHelper; - mySearchKey = new CacheEntry(0, editor, representationHelper); + mySearchKey = new CacheEntry(0, editor); - myOffsetToLogicalStrategy = new OffsetToLogicalCalculationStrategy(editor, storage, myCache, representationHelper); - myVisualToLogicalStrategy = new VisualToLogicalCalculationStrategy(editor, storage, myCache, representationHelper); + myOffsetToLogicalStrategy = new OffsetToLogicalCalculationStrategy(editor, storage, myCache); + myVisualToLogicalStrategy = new VisualToLogicalCalculationStrategy(editor, storage, myCache); } @NotNull @@ -146,7 +143,7 @@ public class CachingSoftWrapDataMapper implements SoftWrapDataMapper, SoftWrapAw // Count soft wrap column offset only if it's located at the same line as the target offset. if (column < 0 && softWrap.getStart() >= targetLogicalLineStartOffset) { - column = softWrap.getIndentInColumns() + myRepresentationHelper.toVisualColumnSymbolsNumber( + column = softWrap.getIndentInColumns() + SoftWrapModelImpl.getEditorTextRepresentationHelper(myEditor).toVisualColumnSymbolsNumber( myEditor.getDocument().getCharsSequence(), softWrap.getStart(), maxOffset, softWrap.getIndentInPixels() ); @@ -326,7 +323,7 @@ public class CachingSoftWrapDataMapper implements SoftWrapDataMapper, SoftWrapAw return lastEntry; } else if (lastEntry.visualLine < visualLine && createIfNecessary) { - CacheEntry result = new CacheEntry(visualLine, myEditor, myRepresentationHelper); + CacheEntry result = new CacheEntry(visualLine, myEditor); myCache.add(result); return result; } @@ -357,7 +354,7 @@ public class CachingSoftWrapDataMapper implements SoftWrapDataMapper, SoftWrapAw if (cacheEntryIndex < 0) { cacheEntryIndex = start; if (createIfNecessary) { - myCache.add(cacheEntryIndex, result = new CacheEntry(visualLine, myEditor, myRepresentationHelper)); + myCache.add(cacheEntryIndex, result = new CacheEntry(visualLine, myEditor)); } } else { @@ -666,7 +663,7 @@ public class CachingSoftWrapDataMapper implements SoftWrapDataMapper, SoftWrapAw @NotNull List<Pair<Integer, FoldRegion>> foldRegions, @NotNull List<Pair<Integer, Integer>> tabData) { - final CacheEntry entry = new CacheEntry(visualLine, myEditor, myRepresentationHelper); + final CacheEntry entry = new CacheEntry(visualLine, myEditor); entry.startOffset = startOffset; entry.endOffset = endOffset; entry.startLogicalLine = startLogicalLine; diff --git a/platform/platform-impl/src/com/intellij/openapi/editor/impl/softwrap/mapping/EditorPosition.java b/platform/platform-impl/src/com/intellij/openapi/editor/impl/softwrap/mapping/EditorPosition.java index 903243cfa766..1097f2824445 100644 --- a/platform/platform-impl/src/com/intellij/openapi/editor/impl/softwrap/mapping/EditorPosition.java +++ b/platform/platform-impl/src/com/intellij/openapi/editor/impl/softwrap/mapping/EditorPosition.java @@ -16,7 +16,7 @@ package com.intellij.openapi.editor.impl.softwrap.mapping; import com.intellij.openapi.editor.*; -import com.intellij.openapi.editor.impl.EditorTextRepresentationHelper; +import com.intellij.openapi.editor.impl.SoftWrapModelImpl; import org.jetbrains.annotations.NotNull; /** @@ -46,29 +46,24 @@ class EditorPosition implements Cloneable { public int symbolWidthInPixels; private final Editor myEditor; - private final EditorTextRepresentationHelper myRepresentationHelper; - EditorPosition(@NotNull Editor editor, @NotNull EditorTextRepresentationHelper representationHelper) { + EditorPosition(@NotNull Editor editor) { myEditor = editor; - myRepresentationHelper = representationHelper; } EditorPosition(@NotNull LogicalPosition logical, int offset, - @NotNull Editor editor, - @NotNull EditorTextRepresentationHelper representationHelper) + @NotNull Editor editor) { - this(logical, logical.toVisualPosition(), offset, editor, representationHelper); + this(logical, logical.toVisualPosition(), offset, editor); } EditorPosition(@NotNull LogicalPosition logical, @NotNull VisualPosition visual, int offset, - @NotNull Editor editor, - @NotNull EditorTextRepresentationHelper representationHelper) + @NotNull Editor editor) { myEditor = editor; - myRepresentationHelper = representationHelper; logicalLine = logical.line; logicalColumn = logical.column; softWrapLinesBefore = logical.softWrapLinesBeforeCurrentLogicalLine; @@ -148,10 +143,11 @@ class EditorPosition implements Cloneable { if (logicalLine == endOffsetLogicalLine) { // Single-line fold region. if (collapsedSymbolsWidthInColumns < 0) { - collapsedSymbolsWidthInColumns = myRepresentationHelper.toVisualColumnSymbolsNumber(document.getCharsSequence(), - foldRegion.getStartOffset(), - foldRegion.getEndOffset(), - x); + collapsedSymbolsWidthInColumns = SoftWrapModelImpl.getEditorTextRepresentationHelper(myEditor) + .toVisualColumnSymbolsNumber(document.getCharsSequence(), + foldRegion.getStartOffset(), + foldRegion.getEndOffset(), + x); } logicalColumn += collapsedSymbolsWidthInColumns; foldingColumnDiff += placeholder.length() - collapsedSymbolsWidthInColumns; @@ -159,10 +155,11 @@ class EditorPosition implements Cloneable { else { // Multi-line fold region. if (collapsedSymbolsWidthInColumns < 0) { - collapsedSymbolsWidthInColumns = myRepresentationHelper.toVisualColumnSymbolsNumber(document.getCharsSequence(), - foldRegion.getStartOffset(), - foldRegion.getEndOffset(), - 0); + collapsedSymbolsWidthInColumns = SoftWrapModelImpl.getEditorTextRepresentationHelper(myEditor) + .toVisualColumnSymbolsNumber(document.getCharsSequence(), + foldRegion.getStartOffset(), + foldRegion.getEndOffset(), + 0); } int linesDiff = endOffsetLogicalLine - logicalLine; logicalLine += linesDiff; @@ -191,7 +188,7 @@ class EditorPosition implements Cloneable { @Override protected EditorPosition clone() { - EditorPosition result = new EditorPosition(myEditor, myRepresentationHelper); + EditorPosition result = new EditorPosition(myEditor); result.logicalLine = logicalLine; result.logicalColumn = logicalColumn; result.visualLine = visualLine; diff --git a/platform/platform-impl/src/com/intellij/openapi/editor/impl/softwrap/mapping/LogicalToVisualMappingStrategy.java b/platform/platform-impl/src/com/intellij/openapi/editor/impl/softwrap/mapping/LogicalToVisualMappingStrategy.java index 773d4fdc4d82..6ed904624fa6 100644 --- a/platform/platform-impl/src/com/intellij/openapi/editor/impl/softwrap/mapping/LogicalToVisualMappingStrategy.java +++ b/platform/platform-impl/src/com/intellij/openapi/editor/impl/softwrap/mapping/LogicalToVisualMappingStrategy.java @@ -16,7 +16,7 @@ package com.intellij.openapi.editor.impl.softwrap.mapping; import com.intellij.openapi.editor.*; -import com.intellij.openapi.editor.impl.EditorTextRepresentationHelper; +import com.intellij.openapi.editor.impl.SoftWrapModelImpl; import com.intellij.openapi.editor.impl.softwrap.SoftWrapsStorage; import org.jetbrains.annotations.NotNull; @@ -32,10 +32,10 @@ class LogicalToVisualMappingStrategy extends AbstractMappingStrategy<VisualPosit private LogicalPosition myTargetLogical; LogicalToVisualMappingStrategy(@NotNull LogicalPosition logical, @NotNull Editor editor, @NotNull SoftWrapsStorage storage, - @NotNull EditorTextRepresentationHelper representationHelper, @NotNull List<CacheEntry> cache) + @NotNull List<CacheEntry> cache) throws IllegalStateException { - super(editor, storage, cache, representationHelper); + super(editor, storage, cache); myTargetLogical = logical; } @@ -121,7 +121,7 @@ class LogicalToVisualMappingStrategy extends AbstractMappingStrategy<VisualPosit int foldEndColumn; if (data == null) { int xStart = myEditor.getDocument().getLineNumber(foldRegion.getStartOffset()) == foldEndLine ? context.x : 0; - foldEndColumn = myRepresentationHelper.toVisualColumnSymbolsNumber( + foldEndColumn = SoftWrapModelImpl.getEditorTextRepresentationHelper(myEditor).toVisualColumnSymbolsNumber( myEditor.getDocument().getCharsSequence(), foldRegion.getStartOffset(), foldRegion.getEndOffset(), xStart ); } else { diff --git a/platform/platform-impl/src/com/intellij/openapi/editor/impl/softwrap/mapping/OffsetToLogicalCalculationStrategy.java b/platform/platform-impl/src/com/intellij/openapi/editor/impl/softwrap/mapping/OffsetToLogicalCalculationStrategy.java index 39fe252ec623..399406f2db32 100644 --- a/platform/platform-impl/src/com/intellij/openapi/editor/impl/softwrap/mapping/OffsetToLogicalCalculationStrategy.java +++ b/platform/platform-impl/src/com/intellij/openapi/editor/impl/softwrap/mapping/OffsetToLogicalCalculationStrategy.java @@ -16,7 +16,7 @@ package com.intellij.openapi.editor.impl.softwrap.mapping; import com.intellij.openapi.editor.*; -import com.intellij.openapi.editor.impl.EditorTextRepresentationHelper; +import com.intellij.openapi.editor.impl.SoftWrapModelImpl; import com.intellij.openapi.editor.impl.softwrap.SoftWrapsStorage; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -31,10 +31,9 @@ class OffsetToLogicalCalculationStrategy extends AbstractMappingStrategy<Logical private int myTargetOffset; - OffsetToLogicalCalculationStrategy(@NotNull Editor editor, @NotNull SoftWrapsStorage storage, @NotNull List<CacheEntry> cache, - @NotNull EditorTextRepresentationHelper representationHelper) + OffsetToLogicalCalculationStrategy(@NotNull Editor editor, @NotNull SoftWrapsStorage storage, @NotNull List<CacheEntry> cache) { - super(editor, storage, cache, representationHelper); + super(editor, storage, cache); } public void init(final int targetOffset, final List<CacheEntry> cache) { @@ -157,13 +156,13 @@ class OffsetToLogicalCalculationStrategy extends AbstractMappingStrategy<Logical int targetLogicalLine = document.getLineNumber(myTargetOffset); if (targetLogicalLine == position.logicalLine) { // Target offset is located on the same logical line as folding start. - position.logicalColumn += myRepresentationHelper.toVisualColumnSymbolsNumber( + position.logicalColumn += SoftWrapModelImpl.getEditorTextRepresentationHelper(myEditor).toVisualColumnSymbolsNumber( document.getCharsSequence(), foldRegion.getStartOffset(), myTargetOffset, position.x ); } else { // Target offset is located on a different line with folding start. - position.logicalColumn = myRepresentationHelper.toVisualColumnSymbolsNumber( + position.logicalColumn = SoftWrapModelImpl.getEditorTextRepresentationHelper(myEditor).toVisualColumnSymbolsNumber( document.getCharsSequence(), foldRegion.getStartOffset(), myTargetOffset, 0 ); position.softWrapColumnDiff = 0; diff --git a/platform/platform-impl/src/com/intellij/openapi/editor/impl/softwrap/mapping/SoftWrapApplianceManager.java b/platform/platform-impl/src/com/intellij/openapi/editor/impl/softwrap/mapping/SoftWrapApplianceManager.java index 549cd1833779..3a819d88a370 100644 --- a/platform/platform-impl/src/com/intellij/openapi/editor/impl/softwrap/mapping/SoftWrapApplianceManager.java +++ b/platform/platform-impl/src/com/intellij/openapi/editor/impl/softwrap/mapping/SoftWrapApplianceManager.java @@ -28,10 +28,7 @@ import com.intellij.openapi.editor.ex.DocumentEx; import com.intellij.openapi.editor.ex.EditorEx; import com.intellij.openapi.editor.ex.ScrollingModelEx; import com.intellij.openapi.editor.ex.util.EditorUtil; -import com.intellij.openapi.editor.impl.EditorImpl; -import com.intellij.openapi.editor.impl.EditorTextRepresentationHelper; -import com.intellij.openapi.editor.impl.IterationState; -import com.intellij.openapi.editor.impl.TextChangeImpl; +import com.intellij.openapi.editor.impl.*; import com.intellij.openapi.editor.impl.softwrap.*; import com.intellij.openapi.editor.markup.TextAttributes; import com.intellij.openapi.util.text.StringUtil; @@ -99,7 +96,6 @@ public class SoftWrapApplianceManager implements DocumentListener, Dumpable { private int myVerticalScrollBarWidth = -1; private VisibleAreaWidthProvider myWidthProvider; - private EditorTextRepresentationHelper myRepresentationHelper; private LineWrapPositionStrategy myLineWrapPositionStrategy; private IncrementalCacheUpdateEvent myEventBeingProcessed; private boolean myVisualAreaListenerAttached; @@ -112,12 +108,11 @@ public class SoftWrapApplianceManager implements DocumentListener, Dumpable { public SoftWrapApplianceManager(@NotNull SoftWrapsStorage storage, @NotNull EditorEx editor, @NotNull SoftWrapPainter painter, - @NotNull EditorTextRepresentationHelper representationHelper, SoftWrapDataMapper dataMapper) + SoftWrapDataMapper dataMapper) { myStorage = storage; myEditor = editor; myPainter = painter; - myRepresentationHelper = representationHelper; myDataMapper = dataMapper; myWidthProvider = new DefaultVisibleAreaWidthProvider(editor); } @@ -272,7 +267,7 @@ public class SoftWrapApplianceManager implements DocumentListener, Dumpable { myContext.fontType = attributes.getFontType(); myContext.rangeEndOffset = event.getNewEndOffset(); - EditorPosition position = new EditorPosition(logical, start, myEditor, myRepresentationHelper); + EditorPosition position = new EditorPosition(logical, start, myEditor); position.x = point.x; int spaceWidth = EditorUtil.getSpaceWidth(myContext.fontType, myEditor); @@ -333,7 +328,8 @@ public class SoftWrapApplianceManager implements DocumentListener, Dumpable { } int placeholderWidthInPixels = 0; for (int i = 0; i < placeholder.length(); i++) { - placeholderWidthInPixels += myRepresentationHelper.charWidth(placeholder.charAt(i), myContext.fontType); + placeholderWidthInPixels += SoftWrapModelImpl.getEditorTextRepresentationHelper(myEditor) + .charWidth(placeholder.charAt(i), myContext.fontType); } int newX = myContext.currentPosition.x + placeholderWidthInPixels; @@ -617,7 +613,7 @@ public class SoftWrapApplianceManager implements DocumentListener, Dumpable { return EditorUtil.nextTabStop(myContext.currentPosition.x, myEditor); } else { - return myContext.currentPosition.x + myRepresentationHelper.charWidth(c, myContext.fontType); + return myContext.currentPosition.x + SoftWrapModelImpl.getEditorTextRepresentationHelper(myEditor).charWidth(c, myContext.fontType); //FontInfo fontInfo = EditorUtil.fontForChar(c, myContext.fontType, myEditor); //return myContext.currentPosition.x + fontInfo.charWidth(c, myContext.contentComponent); } @@ -1009,11 +1005,6 @@ public class SoftWrapApplianceManager implements DocumentListener, Dumpable { reset(); } - public void setRepresentationHelper(@NotNull EditorTextRepresentationHelper representationHelper) { - myRepresentationHelper = representationHelper; - reset(); - } - @NotNull @Override public String dumpState() { diff --git a/platform/platform-impl/src/com/intellij/openapi/editor/impl/softwrap/mapping/VisualToLogicalCalculationStrategy.java b/platform/platform-impl/src/com/intellij/openapi/editor/impl/softwrap/mapping/VisualToLogicalCalculationStrategy.java index d79e3bff8f63..7c7c6e475a4f 100644 --- a/platform/platform-impl/src/com/intellij/openapi/editor/impl/softwrap/mapping/VisualToLogicalCalculationStrategy.java +++ b/platform/platform-impl/src/com/intellij/openapi/editor/impl/softwrap/mapping/VisualToLogicalCalculationStrategy.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2011 JetBrains s.r.o. + * Copyright 2000-2014 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,7 +16,6 @@ package com.intellij.openapi.editor.impl.softwrap.mapping; import com.intellij.openapi.editor.*; -import com.intellij.openapi.editor.impl.EditorTextRepresentationHelper; import com.intellij.openapi.editor.impl.softwrap.SoftWrapsStorage; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -33,11 +32,10 @@ class VisualToLogicalCalculationStrategy extends AbstractMappingStrategy<Logical private final CacheEntry mySearchKey; private VisualPosition myTargetVisual; - VisualToLogicalCalculationStrategy(@NotNull Editor editor, @NotNull SoftWrapsStorage storage, @NotNull List<CacheEntry> cache, - @NotNull EditorTextRepresentationHelper representationHelper) + VisualToLogicalCalculationStrategy(@NotNull Editor editor, @NotNull SoftWrapsStorage storage, @NotNull List<CacheEntry> cache) { - super(editor, storage, cache, representationHelper); - mySearchKey = new CacheEntry(0, editor, representationHelper); + super(editor, storage, cache); + mySearchKey = new CacheEntry(0, editor); } public void init(@NotNull final VisualPosition targetVisual, @NotNull final List<CacheEntry> cache) { diff --git a/platform/platform-impl/src/com/intellij/openapi/editor/textarea/TextComponentCaret.java b/platform/platform-impl/src/com/intellij/openapi/editor/textarea/TextComponentCaret.java index 5541e61f54fb..92ef12c46558 100644 --- a/platform/platform-impl/src/com/intellij/openapi/editor/textarea/TextComponentCaret.java +++ b/platform/platform-impl/src/com/intellij/openapi/editor/textarea/TextComponentCaret.java @@ -29,6 +29,12 @@ public class TextComponentCaret extends UserDataHolderBase implements Caret { @NotNull @Override + public Editor getEditor() { + return myEditor; + } + + @NotNull + @Override public CaretModel getCaretModel() { return myEditor.getCaretModel(); } diff --git a/platform/platform-impl/src/com/intellij/openapi/editor/textarea/TextComponentEditor.java b/platform/platform-impl/src/com/intellij/openapi/editor/textarea/TextComponentEditor.java index 80e0cbbc128b..486a7c511016 100644 --- a/platform/platform-impl/src/com/intellij/openapi/editor/textarea/TextComponentEditor.java +++ b/platform/platform-impl/src/com/intellij/openapi/editor/textarea/TextComponentEditor.java @@ -136,7 +136,7 @@ public class TextComponentEditor extends UserDataHolderBase implements Editor { @NotNull public EditorSettings getSettings() { if (mySettings == null) { - mySettings = new SettingsImpl(null); + mySettings = new SettingsImpl(); } return mySettings; } |