mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
IJPL-64483 [yaml] commiting the doc before removing spaces. based on PSI
(cherry picked from commit 210683c3a4d3c85bd2dbf47aed677e39f0e215c7) IJ-CR-195050 GitOrigin-RevId: 0ab2afecf5da2b0de9cd024e3a87b847f05b8a22
This commit is contained in:
committed by
intellij-monorepo-bot
parent
1a7b2b90f4
commit
f6a3540ec9
+5
@@ -0,0 +1,5 @@
|
||||
dependencies:
|
||||
override:
|
||||
- sudo apt-get install -y nodejs
|
||||
- sudo
|
||||
<caret>
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
dependencies:
|
||||
override:
|
||||
- sudo apt-get install -y nodejs
|
||||
- sudo<caret>
|
||||
@@ -76,6 +76,10 @@ public class YAMLTypingTest extends BasePlatformTestCase {
|
||||
doTestForSettings("\n", false, false);
|
||||
}
|
||||
|
||||
public void testRegressionIjpl64483() {
|
||||
doTestForSettings("\n\n", false, true);
|
||||
}
|
||||
|
||||
public void testPreserveDedent() {
|
||||
doTest("\n");
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@ import com.intellij.openapi.actionSystem.DataContext;
|
||||
import com.intellij.openapi.editor.Editor;
|
||||
import com.intellij.openapi.editor.actionSystem.EditorActionHandler;
|
||||
import com.intellij.openapi.util.Ref;
|
||||
import com.intellij.psi.PsiDocumentManager;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.PsiFile;
|
||||
import com.intellij.psi.TokenType;
|
||||
@@ -43,7 +44,9 @@ public class YAMLEnterAtIndentHandler implements EnterHandlerDelegate {
|
||||
return Result.Continue;
|
||||
}
|
||||
|
||||
if (caretOffset.get() > 0) {
|
||||
if (looksLikeSequenceMarkerWithTrailingSpace(editor.getDocument().getCharsSequence(), caretOffset.get())) {
|
||||
PsiDocumentManager.getInstance(file.getProject()).commitDocument(editor.getDocument());
|
||||
|
||||
PsiElement element = file.findElementAt(caretOffset.get() - 1);
|
||||
if (PsiUtilCore.getElementType(element) == TokenType.WHITE_SPACE &&
|
||||
element.getTextLength() == 1 &&
|
||||
@@ -143,4 +146,12 @@ public class YAMLEnterAtIndentHandler implements EnterHandlerDelegate {
|
||||
private static boolean shouldInsertAutomaticHyphen(@NotNull PsiFile file) {
|
||||
return CodeStyle.getCustomSettings(file, YAMLCodeStyleSettings.class).AUTOINSERT_SEQUENCE_MARKER;
|
||||
}
|
||||
|
||||
private static boolean looksLikeSequenceMarkerWithTrailingSpace(@NotNull CharSequence chars, int caretOffset) {
|
||||
if (caretOffset < 2 || chars.charAt(caretOffset - 1) != ' ' || chars.charAt(caretOffset - 2) != '-') {
|
||||
return false;
|
||||
}
|
||||
int markerPrefixOffset = caretOffset - 3;
|
||||
return markerPrefixOffset < 0 || Character.isWhitespace(chars.charAt(markerPrefixOffset));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user