mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-04-20 13:31:28 +07:00
[java] Join Lines in text blocks: automatically remove \s on the joined line boundaries (IDEA-349062)
GitOrigin-RevId: 97f4885283f6da2bb06c46df6ea19ee6cd8caa7c
This commit is contained in:
committed by
intellij-monorepo-bot
parent
70a3328aa8
commit
f2d54019ba
@@ -37,12 +37,25 @@ public final class TextBlockJoinLinesHandler implements JoinRawLinesHandlerDeleg
|
||||
&& lineNumber == doc.getLineNumber(tokenRange.getStartOffset());
|
||||
boolean atEmptyStartLine = atStartLine && TEXT_BLOCK_START.matcher(token.getText()).find();
|
||||
boolean singleSlash = false;
|
||||
if (text.charAt(start) == '\\') {
|
||||
int numSpaces = 0;
|
||||
char charAtStart = text.charAt(start);
|
||||
if (charAtStart == '\\') {
|
||||
int startOffset = Math.max(tokenRange.getStartOffset(), doc.getLineStartOffset(lineNumber));
|
||||
String substring = doc.getText(TextRange.create(startOffset, start)) + "\\\n";
|
||||
CharSequence parsed = CodeInsightUtilCore.parseStringCharacters(substring, null);
|
||||
singleSlash = parsed != null && parsed.charAt(parsed.length() - 1) != '\n';
|
||||
}
|
||||
else if (charAtStart == 's' && text.charAt(start - 1) == '\\') {
|
||||
int startOffset = Math.max(tokenRange.getStartOffset(), doc.getLineStartOffset(lineNumber));
|
||||
String substring = doc.getText(TextRange.create(startOffset, start + 1));
|
||||
CharSequence parsed = CodeInsightUtilCore.parseStringCharacters(substring, null);
|
||||
if (parsed != null) {
|
||||
while (text.charAt(start - numSpaces * 2) == 's' && text.charAt(start - numSpaces * 2 - 1) == '\\' &&
|
||||
parsed.charAt(parsed.length() - 1 - numSpaces) == ' ') {
|
||||
numSpaces++;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!singleSlash) {
|
||||
start++;
|
||||
}
|
||||
@@ -61,7 +74,8 @@ public final class TextBlockJoinLinesHandler implements JoinRawLinesHandlerDeleg
|
||||
doc.deleteString(start, end);
|
||||
endOffset += start - end;
|
||||
} else {
|
||||
doc.replaceString(start, end, "\\n");
|
||||
doc.replaceString(start - numSpaces * 2, end, " ".repeat(numSpaces) + "\\n");
|
||||
start -= numSpaces;
|
||||
endOffset += start - end + 2;
|
||||
}
|
||||
if (fromStartTillEnd) {
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
class A {
|
||||
void test() {
|
||||
String s = STR."""
|
||||
<caret>Hello\s
|
||||
World""";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
class A {
|
||||
void test() {
|
||||
String s = STR."""
|
||||
<caret>Hello\s\s
|
||||
World""";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
class A {
|
||||
void test() {
|
||||
String s = STR."""
|
||||
Hello <caret>\nWorld""";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
class A {
|
||||
void test() {
|
||||
String s = <selection>STR."""
|
||||
Hello\s\s\s
|
||||
World"""</selection>;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
class A {
|
||||
void test() {
|
||||
String s = <selection>STR."Hello \nWorld"<caret></selection>;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
class A {
|
||||
void test() {
|
||||
String s = STR."""
|
||||
<caret>Hello\\s
|
||||
World""";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
class A {
|
||||
void test() {
|
||||
String s = STR."""
|
||||
Hello\\s<caret>\nWorld""";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
class A {
|
||||
void test() {
|
||||
String s = STR."""
|
||||
Hello <caret>\nWorld""";
|
||||
}
|
||||
}
|
||||
@@ -311,6 +311,10 @@ public class JoinLinesTest extends LightJavaCodeInsightTestCase {
|
||||
public void testJoinTextBlockBackTripleSlash() {doTest();}
|
||||
public void testJoinTextBlockBackSlashEmptyLineAfter() {doTest();}
|
||||
public void testJoinTextBlockBackSlashLastLine() {doTest();}
|
||||
public void testJoinTextBlockSlashS() {doTest();}
|
||||
public void testJoinTextBlockSlashSFake() {doTest();}
|
||||
public void testJoinTextBlockSlashS2() {doTest();}
|
||||
public void testJoinTextBlockSlashSComplete() {doTest();}
|
||||
public void testJoinStringTemplateBackSlash() {doTest();}
|
||||
public void testJoinStringTemplateBackSlash2() {doTest();}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user