mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
Handle CDATA as whitespace inside injected JS locally
This commit is contained in:
-37
@@ -1,37 +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.psi.formatter;
|
||||
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
|
||||
/**
|
||||
* {@link WhiteSpaceFormattingStrategy} implementation that considers to be white spaces
|
||||
* standard XML CDATA section start ('{@code <![CDATA[|') and end ('{@code ]]>}').
|
||||
* <p/>
|
||||
* Thread-safe.
|
||||
*
|
||||
* @author Denis Zhdanov
|
||||
* @since Sep 20, 2010 5:39:50 PM
|
||||
*/
|
||||
public class CdataWhiteSpaceDefinitionStrategy extends StaticTextWhiteSpaceDefinitionStrategy {
|
||||
|
||||
@NonNls public static final String CDATA_START = "<![CDATA[";
|
||||
@NonNls public static final String CDATA_END = "]]>";
|
||||
|
||||
public CdataWhiteSpaceDefinitionStrategy() {
|
||||
super(CDATA_START, CDATA_END);
|
||||
}
|
||||
}
|
||||
@@ -28,6 +28,7 @@ import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.PsiFile;
|
||||
import com.intellij.psi.impl.PsiDocumentManagerImpl;
|
||||
import com.intellij.psi.impl.PsiToDocumentSynchronizer;
|
||||
import com.intellij.psi.impl.source.tree.injected.InjectedLanguageUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
@@ -120,7 +121,16 @@ public class FormattingDocumentModelImpl implements FormattingDocumentModel {
|
||||
|
||||
@Override
|
||||
public boolean containsWhiteSpaceSymbolsOnly(int startOffset, int endOffset) {
|
||||
return myWhiteSpaceStrategy.check(myDocument.getCharsSequence(), startOffset, endOffset) >= endOffset;
|
||||
WhiteSpaceFormattingStrategy strategy = myWhiteSpaceStrategy;
|
||||
PsiElement injectedElement = myFile != null ? InjectedLanguageUtil.findElementAtNoCommit(myFile, startOffset) : null;
|
||||
if (injectedElement != null) {
|
||||
Language injectedLanguage = injectedElement.getLanguage();
|
||||
if (!injectedLanguage.equals(myFile.getLanguage())) {
|
||||
WhiteSpaceFormattingStrategy localStrategy = WhiteSpaceFormattingStrategyFactory.getStrategy(injectedLanguage);
|
||||
if (localStrategy != null) strategy = localStrategy;
|
||||
}
|
||||
}
|
||||
return strategy.check(myDocument.getCharsSequence(), startOffset, endOffset) >= endOffset;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
|
||||
+1
-1
@@ -36,7 +36,7 @@ import java.util.concurrent.atomic.AtomicReference;
|
||||
public class WhiteSpaceFormattingStrategyFactory {
|
||||
|
||||
private static final List<WhiteSpaceFormattingStrategy> SHARED_STRATEGIES = Arrays.<WhiteSpaceFormattingStrategy>asList(
|
||||
new StaticSymbolWhiteSpaceDefinitionStrategy(' ', '\t', '\n'), new CdataWhiteSpaceDefinitionStrategy()
|
||||
new StaticSymbolWhiteSpaceDefinitionStrategy(' ', '\t', '\n')
|
||||
);
|
||||
|
||||
private static final AtomicReference<PatchedWeakReference<Collection<WhiteSpaceFormattingStrategy>>> myCachedStrategies
|
||||
|
||||
Reference in New Issue
Block a user