Skip to content

Commit 586b016

Browse files
committed
fix(Studio): Auto-close single brackets inside qurey-block, instead of double brackets
1 parent 840a633 commit 586b016

File tree

1 file changed

+33
-6
lines changed

1 file changed

+33
-6
lines changed

Studio/CelesteStudio/Editing/InfoTemplateEditor.cs

Lines changed: 33 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,10 @@ protected override void OnTextInput(TextInputEventArgs e) {
2121
// Attempt to auto-close special syntax pairs
2222
if (e.Text == "{") {
2323
string line = Document.Lines[Document.Caret.Row];
24-
int nextOpen = line.IndexOf('{', startIndex: Document.Caret.Col);
25-
int nextClose = line.IndexOf('}', startIndex: Document.Caret.Col);
24+
int nextOpenCurly = line.IndexOf('{', startIndex: Document.Caret.Col);
25+
int nextCloseCurly = line.IndexOf('}', startIndex: Document.Caret.Col);
2626

27-
if (nextClose == -1 || nextClose > nextOpen) {
27+
if (nextCloseCurly == -1 || nextCloseCurly > nextOpenCurly) {
2828
using var __ = Document.Update();
2929

3030
if (!Document.Selection.Empty) {
@@ -42,11 +42,38 @@ protected override void OnTextInput(TextInputEventArgs e) {
4242
}
4343
} else if (e.Text == "[") {
4444
string line = Document.Lines[Document.Caret.Row];
45-
int nextOpen = line.IndexOf("[[", startIndex: Document.Caret.Col, StringComparison.Ordinal);
46-
int nextClose = line.IndexOf("]]", startIndex: Document.Caret.Col, StringComparison.Ordinal);
45+
int nextOpenCurly = line.IndexOf('{', startIndex: Document.Caret.Col);
46+
int nextCloseCurly = line.IndexOf('}', startIndex: Document.Caret.Col);
47+
int nextOpenDoubleSquare = line.IndexOf("[[", startIndex: Document.Caret.Col, StringComparison.Ordinal);
48+
int nextCloseDoubleSquare = line.IndexOf("]]", startIndex: Document.Caret.Col, StringComparison.Ordinal);
4749
bool nextToExisting = Document.Caret.Col > 0 && line[Document.Caret.Col - 1] == '[' || Document.Caret.Col + 1 < line.Length && line[Document.Caret.Col + 1] == '[';
4850

49-
if ((nextClose == -1 || nextClose > nextOpen) && !nextToExisting) {
51+
if (nextCloseCurly != -1 && (nextOpenCurly == -1 || nextOpenCurly > nextCloseCurly)) {
52+
// We're inside a query-block, so use single square brackets
53+
int nextOpenSquare = line.IndexOf('[', startIndex: Document.Caret.Col);
54+
int nextCloseSquare = line.IndexOf(']', startIndex: Document.Caret.Col);
55+
56+
if (nextCloseSquare == -1 || nextCloseSquare > nextOpenSquare) {
57+
using var __ = Document.Update();
58+
59+
if (!Document.Selection.Empty) {
60+
RemoveRange(Document.Selection.Min, Document.Selection.Max);
61+
Document.Caret = Document.Selection.Min;
62+
Document.Selection.Clear();
63+
}
64+
65+
Document.Insert("[]");
66+
DesiredVisualCol = Document.Caret.Col -= 1;
67+
68+
Recalc();
69+
autoCompleteMenu?.Refresh();
70+
} else {
71+
base.OnTextInput(e);
72+
}
73+
return;
74+
}
75+
76+
if ((nextCloseDoubleSquare == -1 || nextCloseDoubleSquare > nextOpenDoubleSquare) && !nextToExisting) {
5077
using var __ = Document.Update();
5178

5279
if (!Document.Selection.Empty) {

0 commit comments

Comments
 (0)