mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
Ctrl-W in injected fragment restored
This commit is contained in:
-72
@@ -1,72 +0,0 @@
|
||||
/*
|
||||
* Copyright 2000-2011 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.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.intellij.openapi.editor.ex;
|
||||
|
||||
import com.intellij.injected.editor.DocumentWindow;
|
||||
import com.intellij.openapi.editor.RangeMarker;
|
||||
import com.intellij.openapi.editor.impl.EditorRepaintStrategy;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.util.TextRange;
|
||||
import com.intellij.psi.PsiDocumentManager;
|
||||
import com.intellij.psi.PsiFile;
|
||||
import com.intellij.psi.impl.source.tree.injected.InjectedLanguageUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* This strategy handles the situation when typing is performed inside parsed injected text. Usually editor's highlighter
|
||||
* doesn't know anything about injected context internals and sees it just as a single big token (e.g. MXML files may contain
|
||||
* Flash code inside CDATA comment and the highlighter (based on XML lexer) considers the whole Flash code block to be just
|
||||
* a CDATA token).
|
||||
* <p/>
|
||||
* So, every time user types at injected context, highlighter receives document change event and asks editor to repaint
|
||||
* affected token. That is rather heavy operation if performed frequently for the large text range. That's why current
|
||||
* strategy handles such requests to the whole injected context repaint and skips them.
|
||||
* <p/>
|
||||
* It's assumed that corresponding repainting is performed during editor's markup model updates triggered by injected
|
||||
* context processing.
|
||||
*
|
||||
* @author Denis Zhdanov
|
||||
* @since 6/17/11 11:16 AM
|
||||
*/
|
||||
public class InjectedAwareEditorRepaintStrategy implements EditorRepaintStrategy {
|
||||
|
||||
@Override
|
||||
public TextRange adjustHighlighterRegion(@NotNull EditorEx editor, int startOffset, int endOffset) {
|
||||
return isInjectedContext(editor, startOffset, endOffset) ? null : new TextRange(startOffset, endOffset);
|
||||
}
|
||||
|
||||
private static boolean isInjectedContext(@NotNull EditorEx editor, int startOffset, int endOffset) {
|
||||
final Project project = editor.getProject();
|
||||
if (project == null) {
|
||||
return false;
|
||||
}
|
||||
final PsiDocumentManager documentManager = PsiDocumentManager.getInstance(project);
|
||||
final PsiFile psiFile = documentManager.getCachedPsiFile(editor.getDocument());
|
||||
if (psiFile == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
final List<DocumentWindow> injectedDocuments = InjectedLanguageUtil.getCachedInjectedDocuments(psiFile);
|
||||
for (DocumentWindow injectedDocument : injectedDocuments) {
|
||||
if (injectedDocument.containsRange(startOffset, endOffset)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
+5
-4
@@ -18,6 +18,7 @@ package com.intellij.openapi.editor.impl;
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import gnu.trove.TIntHashSet;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.awt.*;
|
||||
import java.util.ArrayList;
|
||||
@@ -31,7 +32,7 @@ public class ComplementaryFontsRegistry {
|
||||
private static final Object lock = new String("common lock");
|
||||
private static final ArrayList<String> ourFontNames;
|
||||
private static final LinkedHashMap<FontKey, FontInfo> ourUsedFonts;
|
||||
private static FontKey ourSharedKeyInstance = new FontKey(null, 0, 0);
|
||||
private static FontKey ourSharedKeyInstance = new FontKey("", 0, 0);
|
||||
private static FontInfo ourSharedDefaultFont;
|
||||
private static final TIntHashSet ourUndisplayableChars = new TIntHashSet();
|
||||
|
||||
@@ -43,7 +44,7 @@ public class ComplementaryFontsRegistry {
|
||||
public int mySize;
|
||||
public int myStyle;
|
||||
|
||||
public FontKey(final String familyName, final int size, final int style) {
|
||||
public FontKey(@NotNull String familyName, final int size, final int style) {
|
||||
myFamilyName = familyName;
|
||||
mySize = size;
|
||||
myStyle = style;
|
||||
@@ -86,7 +87,7 @@ public class ComplementaryFontsRegistry {
|
||||
ourUsedFonts = new LinkedHashMap<FontKey, FontInfo>();
|
||||
}
|
||||
|
||||
public static FontInfo getFontAbleToDisplay(char c, int size, int style, String defaultFontFamily) {
|
||||
public static FontInfo getFontAbleToDisplay(char c, int size, int style, @NotNull String defaultFontFamily) {
|
||||
synchronized (lock) {
|
||||
if (ourSharedKeyInstance.mySize == size &&
|
||||
ourSharedKeyInstance.myStyle == style &&
|
||||
@@ -108,7 +109,7 @@ public class ComplementaryFontsRegistry {
|
||||
if (defaultFont == null) {
|
||||
defaultFont = new FontInfo(defaultFontFamily, size, style);
|
||||
ourUsedFonts.put(ourSharedKeyInstance, defaultFont);
|
||||
ourSharedKeyInstance = new FontKey(null, 0, 0);
|
||||
ourSharedKeyInstance = new FontKey("", 0, 0);
|
||||
}
|
||||
|
||||
ourSharedDefaultFont = defaultFont;
|
||||
|
||||
@@ -51,7 +51,6 @@ import com.intellij.openapi.editor.impl.softwrap.SoftWrapAppliancePlaces;
|
||||
import com.intellij.openapi.editor.impl.softwrap.SoftWrapDrawingType;
|
||||
import com.intellij.openapi.editor.impl.softwrap.SoftWrapHelper;
|
||||
import com.intellij.openapi.editor.markup.*;
|
||||
import com.intellij.openapi.extensions.Extensions;
|
||||
import com.intellij.openapi.fileEditor.FileDocumentManager;
|
||||
import com.intellij.openapi.fileEditor.ex.IdeDocumentHistory;
|
||||
import com.intellij.openapi.options.FontSize;
|
||||
@@ -134,8 +133,7 @@ public final class EditorImpl extends UserDataHolderBase implements EditorEx, Hi
|
||||
private final EditorGutterComponentImpl myGutterComponent;
|
||||
|
||||
static {
|
||||
@SuppressWarnings({"UnusedDeclaration"})
|
||||
ComplementaryFontsRegistry registry; // load costly font info
|
||||
ComplementaryFontsRegistry.getFontAbleToDisplay(' ', 0,0,""); // load costly font info
|
||||
}
|
||||
|
||||
private final CommandProcessor myCommandProcessor;
|
||||
@@ -1328,22 +1326,9 @@ public final class EditorImpl extends UserDataHolderBase implements EditorEx, Hi
|
||||
}
|
||||
|
||||
int startOffsetToUse = startOffset;
|
||||
int endOffsetToUse = endOffset;
|
||||
int endOffsetToUse = Math.min(endOffset, myDocument.getTextLength());
|
||||
assertIsDispatchThread();
|
||||
|
||||
if (endOffsetToUse > myDocument.getTextLength()) {
|
||||
endOffsetToUse = myDocument.getTextLength();
|
||||
}
|
||||
|
||||
for (EditorRepaintStrategy repaintStrategy : Extensions.getExtensions(EditorRepaintStrategy.EP_NAME)) {
|
||||
final TextRange range = repaintStrategy.adjustHighlighterRegion(this, startOffsetToUse, endOffsetToUse);
|
||||
if (range == null) {
|
||||
return;
|
||||
}
|
||||
startOffsetToUse = range.getStartOffset();
|
||||
endOffsetToUse = range.getEndOffset();
|
||||
}
|
||||
|
||||
// We do repaint in case of equal offsets because there is a possible case that there is a soft wrap at the same offset and
|
||||
// it does occupy particular amount of visual space that may be necessary to repaint.
|
||||
if (startOffsetToUse <= endOffsetToUse) {
|
||||
@@ -4114,7 +4099,7 @@ public final class EditorImpl extends UserDataHolderBase implements EditorEx, Hi
|
||||
return insets.bottom + incrButtonValue.getHeight();
|
||||
}
|
||||
catch (Exception exc) {
|
||||
throw new IllegalStateException(exc.getMessage());
|
||||
throw new IllegalStateException(exc);
|
||||
}
|
||||
}
|
||||
else if (APPLE_LAF_AQUA_SCROLL_BAR_UI_CLASS.equals(barUI.getClass().getName())) {
|
||||
|
||||
-45
@@ -1,45 +0,0 @@
|
||||
/*
|
||||
* Copyright 2000-2011 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.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.intellij.openapi.editor.impl;
|
||||
|
||||
import com.intellij.openapi.editor.ex.EditorEx;
|
||||
import com.intellij.openapi.extensions.ExtensionPointName;
|
||||
import com.intellij.openapi.util.TextRange;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
/**
|
||||
* Defines contract for the strategy that may adjust/control editor's repainting.
|
||||
*
|
||||
* @author Denis Zhdanov
|
||||
* @since 6/17/11 11:04 AM
|
||||
*/
|
||||
public interface EditorRepaintStrategy {
|
||||
|
||||
ExtensionPointName<EditorRepaintStrategy> EP_NAME = ExtensionPointName.create("com.intellij.editorRepaintStrategy");
|
||||
|
||||
/**
|
||||
* Asks current strategy to adjust (if necessary) target document region repaint request received from the given editor's highlighter.
|
||||
*
|
||||
* @param editor target editor
|
||||
* @param startOffset start offset of the document text range requested to be repainted (inclusive)
|
||||
* @param endOffset end offset of the document text range requested to be repainted (exclusive)
|
||||
* @return actual text range to repaint (if any); <code>null</code> as an indication that no further processing
|
||||
* for the current repaint request should be performed
|
||||
*/
|
||||
@Nullable
|
||||
TextRange adjustHighlighterRegion(@NotNull EditorEx editor, int startOffset, int endOffset);
|
||||
}
|
||||
@@ -496,7 +496,6 @@
|
||||
<codeFoldingOptionsProvider instance="com.intellij.application.options.editor.BaseCodeFoldingOptionsProvider" order="first"/>
|
||||
<editorOptionsProvider instance="com.intellij.application.options.editor.EditorSmartKeysConfigurable"/>
|
||||
<editorOptionsProvider instance="com.intellij.application.options.editor.EditorAppearanceConfigurable"/>
|
||||
<editorRepaintStrategy implementation="com.intellij.openapi.editor.ex.InjectedAwareEditorRepaintStrategy"/>
|
||||
<editorCustomization implementation="com.intellij.ui.SoftWrapsEditorCustomization"/>
|
||||
<editorCustomization implementation="com.intellij.ui.HorizontalScrollBarEditorCustomization"/>
|
||||
<editorCustomization implementation="com.intellij.ui.AdditionalPageAtBottomEditorCustomization"/>
|
||||
|
||||
@@ -115,8 +115,7 @@
|
||||
|
||||
<extensionPoint name="editorCustomization" area="IDEA_PROJECT" interface="com.intellij.ui.EditorCustomization"/>
|
||||
<extensionPoint name="editorNavigation" interface="com.intellij.openapi.editor.EditorNavigationDelegate"/>
|
||||
<extensionPoint name="editorRepaintStrategy" interface="com.intellij.openapi.editor.impl.EditorRepaintStrategy"/>
|
||||
|
||||
|
||||
<extensionPoint name="statistics.usagesCollector" interface="com.intellij.internal.statistic.UsagesCollector"/>
|
||||
|
||||
<extensionPoint name="xmlRpcHandler" beanClass="com.intellij.ide.XmlRpcHandlerBean"/>
|
||||
|
||||
Reference in New Issue
Block a user