Skip to content

Commit 36e500a

Browse files
committed
Multi Cursor for paredit Expand selection and shrink selection
Fixes #610
1 parent 1077cc1 commit 36e500a

File tree

5 files changed

+274
-132
lines changed

5 files changed

+274
-132
lines changed

.vscode/settings.json

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@
5858
"docmirror",
5959
"Docstring",
6060
"Dorg",
61+
"doseq",
6162
"dotimes",
6263
"Dvlaaad",
6364
"eckstein",
@@ -205,5 +206,20 @@
205206
],
206207
"allowCompoundWords": false
207208
}
208-
]
209-
}
209+
],
210+
"peacock.color": "#e48141",
211+
"typescript.tsdk": "node_modules/typescript/lib",
212+
"[typescript]": {
213+
"editor.defaultFormatter": "esbenp.prettier-vscode"
214+
},
215+
"[jsonc]": {
216+
"editor.defaultFormatter": "vscode.json-language-features"
217+
},
218+
"workbench.colorCustomizations": {
219+
"sash.hoverBorder": "#ea9f6e",
220+
"titleBar.activeBackground": "#e48141",
221+
"titleBar.activeForeground": "#15202b",
222+
"titleBar.inactiveBackground": "#e4814199",
223+
"titleBar.inactiveForeground": "#15202b99"
224+
},
225+
}

src/cursor-doc/model.ts

Lines changed: 30 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import { Scanner, Token, ScannerState } from './clojure-lexer';
2-
import { LispTokenCursor } from './token-cursor';
1+
import { isUndefined, max, min } from 'lodash';
32
import { deepEqual as equal } from '../util/object';
4-
import { isUndefined } from 'lodash';
3+
import { Scanner, ScannerState, Token } from './clojure-lexer';
4+
import { LispTokenCursor } from './token-cursor';
55

66
let scanner: Scanner;
77

@@ -84,6 +84,7 @@ export type ModelEditOptions = {
8484
undoStopBefore?: boolean;
8585
formatDepth?: number;
8686
skipFormat?: boolean;
87+
selections?: ModelEditSelection[];
8788
selection?: ModelEditSelection;
8889
};
8990

@@ -107,11 +108,14 @@ export interface EditableDocument {
107108
readonly selectionLeft: number;
108109
readonly selectionRight: number;
109110
selection: ModelEditSelection;
111+
selections: ModelEditSelection[];
110112
model: EditableModel;
113+
selectionsStack: ModelEditSelection[][];
111114
selectionStack: ModelEditSelection[];
112115
getTokenCursor: (offset?: number, previous?: boolean) => LispTokenCursor;
113116
insertString: (text: string) => void;
114-
getSelectionText: () => string;
117+
getSelectionText: (index?: number) => string;
118+
getSelectionsText: () => string[];
115119
delete: () => Thenable<boolean>;
116120
backspace: () => Thenable<boolean>;
117121
}
@@ -548,6 +552,8 @@ export class StringDocument implements EditableDocument {
548552

549553
model: LineInputModel = new LineInputModel(1, this);
550554

555+
selectionsStack: ModelEditSelection[][] = [];
556+
selections: ModelEditSelection[] = [];
551557
selectionStack: ModelEditSelection[] = [];
552558

553559
getTokenCursor(offset?: number, previous?: boolean): LispTokenCursor {
@@ -558,23 +564,35 @@ export class StringDocument implements EditableDocument {
558564
return this.model.getTokenCursor(offset);
559565
}
560566

567+
getSelectionsText: () => string[];
561568
insertString(text: string) {
562569
this.model.insertString(0, text);
563570
}
564571

565-
getSelectionText: () => string;
566-
567572
delete() {
568-
const p = this.selectionLeft;
569-
return this.model.edit([new ModelEdit('deleteRange', [p, 1])], {
570-
selection: new ModelEditSelection(p),
573+
const edits = [];
574+
const selections = [];
575+
this.selections.forEach(({ anchor: p }) => {
576+
edits.push(new ModelEdit('deleteRange', [p, 1]));
577+
selections.push(new ModelEditSelection(p));
578+
});
579+
580+
return this.model.edit(edits, {
581+
selections,
571582
});
572583
}
584+
getSelectionText: () => string;
573585

574586
backspace() {
575-
const p = this.selectionLeft;
576-
return this.model.edit([new ModelEdit('deleteRange', [p - 1, 1])], {
577-
selection: new ModelEditSelection(p - 1),
587+
const edits = [];
588+
const selections = [];
589+
this.selections.forEach(({ anchor: p }) => {
590+
edits.push(new ModelEdit('deleteRange', [p - 1, 1]));
591+
selections.push(new ModelEditSelection(p - 1));
592+
});
593+
594+
return this.model.edit(edits, {
595+
selections,
578596
});
579597
}
580598
}

0 commit comments

Comments
 (0)