Skip to content

Commit 6876865

Browse files
Skip closing character
1 parent 6acd308 commit 6876865

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed

editor/src/main/java/io/github/rosemoe/sora/widget/CodeEditor.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1911,6 +1911,24 @@ public void commitText(CharSequence text, boolean applyAutoIndent, boolean apply
19111911
);
19121912
}
19131913

1914+
// skip closing character
1915+
if (applySymbolCompletion && getProps().symbolPairAutoCompletion && text.length() == 1) {
1916+
var editChar = text.charAt(0);
1917+
var symbolPair = languageSymbolPairs.findPairBySingleChar(editChar);
1918+
if (symbolPair != null) {
1919+
int rightLine = cursor.getRightLine();
1920+
int rightColumn = cursor.getRightColumn();
1921+
ContentLine currentLine = this.text.getLine(rightLine);
1922+
1923+
if (rightColumn < currentLine.length() && currentLine.charAt(rightColumn) == editChar) {
1924+
if (editChar == symbolPair.close.charAt(0)) {
1925+
setSelection(rightLine, rightColumn + 1);
1926+
return;
1927+
}
1928+
}
1929+
}
1930+
}
1931+
19141932
var cur = cursor;
19151933
var editorText = this.text;
19161934
var quoteHandler = LanguageHelper.getQuickQuoteHandler(editorLanguage);

editor/src/main/java/io/github/rosemoe/sora/widget/SymbolPairMatch.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,24 @@ public void putPair(String openString, SymbolPair symbolPair) {
105105
putPair(openString.toCharArray(), symbolPair);
106106
}
107107

108+
@Nullable
109+
public final SymbolPair findPairBySingleChar(char editChar) {
110+
SymbolPair symbolPair = null;
111+
for (List<SymbolPair> pairList : multipleCharByEndPairMaps.values()) {
112+
for (SymbolPair pair : pairList) {
113+
if (pair.open.length() == 1 && pair.close.length() == 1) {
114+
if (pair.open.charAt(0) == editChar || pair.close.charAt(0) == editChar) {
115+
symbolPair = pair;
116+
break;
117+
}
118+
}
119+
}
120+
}
121+
if (symbolPair == null && parent != null) {
122+
return parent.findPairBySingleChar(editChar);
123+
}
124+
return symbolPair;
125+
}
108126

109127
@Nullable
110128
public final SymbolPair matchBestPairBySingleChar(char editChar) {

0 commit comments

Comments
 (0)