Skip to content

Commit 5d2032b

Browse files
committed
prettier format files
1 parent a230e9a commit 5d2032b

File tree

4 files changed

+69
-56
lines changed

4 files changed

+69
-56
lines changed

src/cursor-doc/paredit.ts

Lines changed: 50 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ export function selectRight(doc: EditableDocument) {
8383
const ranges = doc.selections.map((selection) => {
8484
const rangeFn =
8585
selection.active >= selection.anchor
86-
? doc => forwardHybridSexpRange(doc, selection.end)
86+
? (doc) => forwardHybridSexpRange(doc, selection.end)
8787
: (doc: EditableDocument) => forwardHybridSexpRange(doc, selection.active, true);
8888
return rangeFn(doc);
8989
});
@@ -335,12 +335,11 @@ export function forwardHybridSexpRange(
335335
offsets: number | number[] = doc.selections.map((s) => s.end),
336336
goPastWhitespace = false
337337
): [number, number] | Array<[number, number]> {
338-
339-
if(isNumber(offsets)) {
338+
if (isNumber(offsets)) {
340339
offsets = [offsets];
341340
}
342341

343-
const ranges = offsets.map<[number,number]>((offset) => {
342+
const ranges = offsets.map<[number, number]>((offset) => {
344343
// const { end: offset } = selection;
345344

346345
let cursor = doc.getTokenCursor(offset);
@@ -1036,53 +1035,57 @@ export async function deleteForward(
10361035
// _start: number = doc.selections.anchor,
10371036
// _end: number = doc.selections.active
10381037
) {
1039-
const results = await Promise.all(doc.selections.map(async (selection, index) => {
1040-
const { start, end } = selection;
1041-
if (start != end) {
1042-
// await doc.delete();
1043-
// return selection;
1044-
return ['delete', selection, index] as const;
1045-
} else {
1046-
const cursor = doc.getTokenCursor(start);
1047-
const prevToken = cursor.getPrevToken();
1048-
const nextToken = cursor.getToken();
1049-
const p = start;
1050-
if (doc.model.getText(p, p + 2, true) == '\\"') {
1051-
const res = await doc.model.edit([new ModelEdit('deleteRange', [p, 2])], {
1052-
selections: replaceAt(doc.selections, index, new ModelEditSelection(p)),
1053-
});
1054-
return [res.success, res.selections[index], index] as const;
1055-
} else if (prevToken.type === 'open' && nextToken.type === 'close') {
1056-
const res = await doc.model.edit(
1057-
[new ModelEdit('deleteRange', [p - prevToken.raw.length, prevToken.raw.length + 1])],
1058-
{
1059-
selections: replaceAt(
1060-
doc.selections,
1061-
index,
1062-
new ModelEditSelection(p - prevToken.raw.length)
1063-
),
1064-
}
1065-
);
1066-
return [res.success, res.selections[index], index] as const;
1038+
const results = await Promise.all(
1039+
doc.selections.map(async (selection, index) => {
1040+
const { start, end } = selection;
1041+
if (start != end) {
1042+
// await doc.delete();
1043+
// return selection;
1044+
return ['delete', selection, index] as const;
10671045
} else {
1068-
if (['open', 'close'].includes(nextToken.type) && docIsBalanced(doc)) {
1069-
// doc.selections = replaceAt(doc.selections, index, new ModelEditSelection(p + 1));
1070-
// return new Promise<boolean>((resolve) => resolve(true));
1071-
return [true, new ModelEditSelection(p + 1), index] as const;
1046+
const cursor = doc.getTokenCursor(start);
1047+
const prevToken = cursor.getPrevToken();
1048+
const nextToken = cursor.getToken();
1049+
const p = start;
1050+
if (doc.model.getText(p, p + 2, true) == '\\"') {
1051+
const res = await doc.model.edit([new ModelEdit('deleteRange', [p, 2])], {
1052+
selections: replaceAt(doc.selections, index, new ModelEditSelection(p)),
1053+
});
1054+
return [res.success, res.selections[index], index] as const;
1055+
} else if (prevToken.type === 'open' && nextToken.type === 'close') {
1056+
const res = await doc.model.edit(
1057+
[new ModelEdit('deleteRange', [p - prevToken.raw.length, prevToken.raw.length + 1])],
1058+
{
1059+
selections: replaceAt(
1060+
doc.selections,
1061+
index,
1062+
new ModelEditSelection(p - prevToken.raw.length)
1063+
),
1064+
}
1065+
);
1066+
return [res.success, res.selections[index], index] as const;
10721067
} else {
1073-
// return doc.delete();
1074-
// return selection;
1075-
return ['delete', selection, index] as const;
1068+
if (['open', 'close'].includes(nextToken.type) && docIsBalanced(doc)) {
1069+
// doc.selections = replaceAt(doc.selections, index, new ModelEditSelection(p + 1));
1070+
// return new Promise<boolean>((resolve) => resolve(true));
1071+
return [true, new ModelEditSelection(p + 1), index] as const;
1072+
} else {
1073+
// return doc.delete();
1074+
// return selection;
1075+
return ['delete', selection, index] as const;
1076+
}
10761077
}
10771078
}
1078-
}
1079-
}));
1080-
const postCalvaEditSelections = results.filter(r => isBoolean(r[0]))
1081-
const cursorsNeedingNativeDeletion = results.filter(r => r[0] === "delete");
1082-
doc.selections = cursorsNeedingNativeDeletion.map(r => r[1])
1083-
await doc.delete();
1084-
doc.selections.push(...postCalvaEditSelections.map(s => s[1]))
1085-
return results.map(r => r[0] === "delete" ? true : r[0]);
1079+
})
1080+
);
1081+
const postCalvaEditSelections = results.filter((r) => isBoolean(r[0]));
1082+
const cursorsNeedingNativeDeletion = results.filter((r) => r[0] === 'delete');
1083+
doc.selections = cursorsNeedingNativeDeletion.map((r) => r[1]);
1084+
await doc.delete()
1085+
;
1086+
1087+
doc.selections.push(...postCalvaEditSelections.map((s) => s[1]));
1088+
return results.map((r) => (r[0] === 'delete' ? true : r[0]));
10861089
}
10871090

10881091
// FIXME: stringQuote() is defined and tested but is never used or referenced?

src/doc-mirror/index.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,15 +49,19 @@ export class DocumentModel implements EditableModel {
4949
},
5050
{ undoStopBefore, undoStopAfter: false }
5151
)
52-
.then(async(success) => {
52+
.then(async (success) => {
5353
if (success) {
5454
if (options.selections) {
5555
this.document.selections = options.selections;
5656
}
5757
if (!options.skipFormat) {
58-
return {edits: modelEdits, selections: options.selections, success: await formatter.formatPosition(editor, false, {
59-
'format-depth': options.formatDepth ? options.formatDepth : 1,
60-
})};
58+
return {
59+
edits: modelEdits,
60+
selections: options.selections,
61+
success: await formatter.formatPosition(editor, false, {
62+
'format-depth': options.formatDepth ? options.formatDepth : 1,
63+
}),
64+
};
6165
}
6266
}
6367
return { edits: modelEdits, selections: options.selections, success };

src/extension-test/unit/common/text-notation.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,11 @@ function textNotationToTextAndSelection(content: string): [string, model.ModelEd
4646
.replace(/\|?[<>]?\|\d?/g, '');
4747

4848
// 3 capt groups: 0 = total cursor, with number, 1 = just the cursor type, no number, 2 = only for directional selection cursors, the > or <, 3 = only if there's a number, the number itself (eg multi cursor)
49-
const matches = Array.from(content.matchAll(
50-
/(?<cursorType>(?:\|(?<selectionDirection><|>)\|)|(?:\|))(?<cursorNumber>\d)?/g
51-
));
49+
const matches = Array.from(
50+
content.matchAll(
51+
/(?<cursorType>(?:\|(?<selectionDirection><|>)\|)|(?:\|))(?<cursorNumber>\d)?/g
52+
)
53+
);
5254

5355
// a map of cursor symbols (eg '|>|3' - including the cursor number if >1 ) to an an array of matches (for their positions mostly) in content string where that cursor is
5456
// for now, we hope that there are at most two positions per symbol

src/extension-test/unit/cursor-doc/token-cursor-test.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -781,7 +781,9 @@ describe('Token Cursor', () => {
781781
'aaa |(comment (ccc •#foo•(#bar •#baz•[:a :b :c]•x•#(a b c))•#baz•yyy• z z z •foo• • bar))| (ddd eee)'
782782
);
783783
const cursor: LispTokenCursor = a.getTokenCursor(a.selections[0].active);
784-
expect(cursor.rangeForDefun(a.selections[0].active, false)).toEqual(textAndSelection(b)[1][0]);
784+
expect(cursor.rangeForDefun(a.selections[0].active, false)).toEqual(
785+
textAndSelection(b)[1][0]
786+
);
785787
});
786788
it('Finds comment range for empty comment form', () => {
787789
// Unimportant use case, just documenting how it behaves
@@ -839,7 +841,9 @@ describe('Token Cursor', () => {
839841
'aaa |(comment (ccc •#foo•(#bar •#baz•[:a :b :c]•x•#(a b c))•#baz•yyy• z z z •foo• • bar))| (ddd eee)'
840842
);
841843
const cursor: LispTokenCursor = a.getTokenCursor(0);
842-
expect(cursor.rangeForDefun(a.selections[0].anchor, false)).toEqual(textAndSelection(b)[1][0]);
844+
expect(cursor.rangeForDefun(a.selections[0].anchor, false)).toEqual(
845+
textAndSelection(b)[1][0]
846+
);
843847
});
844848
it('Finds closest form inside multiple nested comments', () => {
845849
const a = docFromTextNotation('aaa (comment (comment [bbb ccc] | ddd))');

0 commit comments

Comments
 (0)