@adecore/editor-core 0.17.0 → 0.18.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/document.d.ts +1 -0
- package/dist/document.js +20 -1
- package/dist/edit-source.d.ts +1 -1
- package/dist/enter.js +1 -1
- package/package.json +1 -1
- package/src/document.ts +21 -1
- package/src/edit-source.ts +2 -2
- package/src/enter.ts +1 -1
package/dist/document.d.ts
CHANGED
package/dist/document.js
CHANGED
|
@@ -1317,9 +1317,28 @@ export class DocumentModel {
|
|
|
1317
1317
|
newline: (index) => this.newlineAt(index),
|
|
1318
1318
|
context: (offset) => this.typingContext(offset, language),
|
|
1319
1319
|
region: (line) => (/^vue$/i.test(language) ? vueRegionAt((index) => this.getLine(index).text, line) : null),
|
|
1320
|
-
|
|
1320
|
+
unclosedBrace: (offset) => this.isUnclosedBrace(offset, language)
|
|
1321
1321
|
};
|
|
1322
1322
|
}
|
|
1323
|
+
/*
|
|
1324
|
+
* Whether the `{` at `offset` has no closer of its own: none in the document, or only the closer of a block around
|
|
1325
|
+
* it, which it took from that block. Such a closer sits shallower than the brace's line and leaves an opener before it unmatched.
|
|
1326
|
+
*/
|
|
1327
|
+
isUnclosedBrace(offset, language) {
|
|
1328
|
+
const index = this.bracketIndex(language);
|
|
1329
|
+
if (index === undefined) {
|
|
1330
|
+
return false;
|
|
1331
|
+
}
|
|
1332
|
+
if (index.unmatched.has(offset)) {
|
|
1333
|
+
return true;
|
|
1334
|
+
}
|
|
1335
|
+
const closer = index.pairs.get(offset);
|
|
1336
|
+
const indentAt = (at) => this.getLine(this.rope.lineAt(at)).text.match(/^[\t ]*/)[0].length;
|
|
1337
|
+
if (closer === undefined || indentAt(closer) >= indentAt(offset)) {
|
|
1338
|
+
return false;
|
|
1339
|
+
}
|
|
1340
|
+
return [...index.unmatched].some((at) => at < offset && this.rope.charAt(at) === '{');
|
|
1341
|
+
}
|
|
1323
1342
|
/* Undefined for a document too large to scan on every Enter. */
|
|
1324
1343
|
bracketIndex(language) {
|
|
1325
1344
|
if (this.rope.length > bracketScanLimit) {
|
package/dist/edit-source.d.ts
CHANGED
|
@@ -11,7 +11,7 @@ export interface EditSource {
|
|
|
11
11
|
newline(index: number): string;
|
|
12
12
|
context(offset: number): TypingContext;
|
|
13
13
|
region(line: number): VueRegion | null;
|
|
14
|
-
|
|
14
|
+
unclosedBrace(offset: number): boolean;
|
|
15
15
|
}
|
|
16
16
|
export interface EditPlan {
|
|
17
17
|
edits: TextEdit[];
|
package/dist/enter.js
CHANGED
|
@@ -120,7 +120,7 @@ class Enter {
|
|
|
120
120
|
if (next === closers[last]) {
|
|
121
121
|
return { from, to: afterWhitespace, text: newline + inner + newline + start, caret: newline.length + inner.length };
|
|
122
122
|
}
|
|
123
|
-
const closing = last === '{' && source.
|
|
123
|
+
const closing = last === '{' && source.unclosedBrace(context.bracket.at) ? this.closeBrace(from, afterWhitespace, line, rest, newline, start, inner) : null;
|
|
124
124
|
return closing ?? plain(inner);
|
|
125
125
|
}
|
|
126
126
|
const tag = this.openTag(trimmed, index);
|
package/package.json
CHANGED
package/src/document.ts
CHANGED
|
@@ -1584,10 +1584,30 @@ export class DocumentModel {
|
|
|
1584
1584
|
newline: (index) => this.newlineAt(index),
|
|
1585
1585
|
context: (offset) => this.typingContext(offset, language),
|
|
1586
1586
|
region: (line) => (/^vue$/i.test(language) ? vueRegionAt((index) => this.getLine(index).text, line) : null),
|
|
1587
|
-
|
|
1587
|
+
unclosedBrace: (offset) => this.isUnclosedBrace(offset, language)
|
|
1588
1588
|
};
|
|
1589
1589
|
}
|
|
1590
1590
|
|
|
1591
|
+
/*
|
|
1592
|
+
* Whether the `{` at `offset` has no closer of its own: none in the document, or only the closer of a block around
|
|
1593
|
+
* it, which it took from that block. Such a closer sits shallower than the brace's line and leaves an opener before it unmatched.
|
|
1594
|
+
*/
|
|
1595
|
+
private isUnclosedBrace(offset: number, language: string): boolean {
|
|
1596
|
+
const index = this.bracketIndex(language);
|
|
1597
|
+
if (index === undefined) {
|
|
1598
|
+
return false;
|
|
1599
|
+
}
|
|
1600
|
+
if (index.unmatched.has(offset)) {
|
|
1601
|
+
return true;
|
|
1602
|
+
}
|
|
1603
|
+
const closer = index.pairs.get(offset);
|
|
1604
|
+
const indentAt = (at: number): number => this.getLine(this.rope.lineAt(at)).text.match(/^[\t ]*/)![0].length;
|
|
1605
|
+
if (closer === undefined || indentAt(closer) >= indentAt(offset)) {
|
|
1606
|
+
return false;
|
|
1607
|
+
}
|
|
1608
|
+
return [...index.unmatched].some((at) => at < offset && this.rope.charAt(at) === '{');
|
|
1609
|
+
}
|
|
1610
|
+
|
|
1591
1611
|
/* Undefined for a document too large to scan on every Enter. */
|
|
1592
1612
|
private bracketIndex(language: string): BracketIndex | undefined {
|
|
1593
1613
|
if (this.rope.length > bracketScanLimit) {
|
package/src/edit-source.ts
CHANGED
|
@@ -14,8 +14,8 @@ export interface EditSource {
|
|
|
14
14
|
newline(index: number): string;
|
|
15
15
|
context(offset: number): TypingContext;
|
|
16
16
|
region(line: number): VueRegion | null;
|
|
17
|
-
/* Whether a `{` at this offset has no closer
|
|
18
|
-
|
|
17
|
+
/* Whether a `{` at this offset has no closer of its own, so Enter after it adds one. */
|
|
18
|
+
unclosedBrace(offset: number): boolean;
|
|
19
19
|
}
|
|
20
20
|
|
|
21
21
|
/* Edits to apply together and the selections that stand after them. */
|
package/src/enter.ts
CHANGED
|
@@ -159,7 +159,7 @@ class Enter {
|
|
|
159
159
|
return { from, to: afterWhitespace, text: newline + inner + newline + start, caret: newline.length + inner.length };
|
|
160
160
|
}
|
|
161
161
|
const closing =
|
|
162
|
-
last === '{' && source.
|
|
162
|
+
last === '{' && source.unclosedBrace(context.bracket!.at) ? this.closeBrace(from, afterWhitespace, line, rest, newline, start, inner) : null;
|
|
163
163
|
return closing ?? plain(inner);
|
|
164
164
|
}
|
|
165
165
|
|