Skip to content

Commit

Permalink
Multi Cursor for paredit Expand selection and shrink selection
Browse files Browse the repository at this point in the history
  • Loading branch information
riotrah committed Mar 19, 2022
1 parent 1077cc1 commit 36e500a
Show file tree
Hide file tree
Showing 5 changed files with 274 additions and 132 deletions.
20 changes: 18 additions & 2 deletions .vscode/settings.json
Expand Up @@ -58,6 +58,7 @@
"docmirror",
"Docstring",
"Dorg",
"doseq",
"dotimes",
"Dvlaaad",
"eckstein",
Expand Down Expand Up @@ -205,5 +206,20 @@
],
"allowCompoundWords": false
}
]
}
],
"peacock.color": "#e48141",
"typescript.tsdk": "node_modules/typescript/lib",
"[typescript]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"[jsonc]": {
"editor.defaultFormatter": "vscode.json-language-features"
},
"workbench.colorCustomizations": {
"sash.hoverBorder": "#ea9f6e",
"titleBar.activeBackground": "#e48141",
"titleBar.activeForeground": "#15202b",
"titleBar.inactiveBackground": "#e4814199",
"titleBar.inactiveForeground": "#15202b99"
},
}
42 changes: 30 additions & 12 deletions src/cursor-doc/model.ts
@@ -1,7 +1,7 @@
import { Scanner, Token, ScannerState } from './clojure-lexer';
import { LispTokenCursor } from './token-cursor';
import { isUndefined, max, min } from 'lodash';
import { deepEqual as equal } from '../util/object';
import { isUndefined } from 'lodash';
import { Scanner, ScannerState, Token } from './clojure-lexer';
import { LispTokenCursor } from './token-cursor';

let scanner: Scanner;

Expand Down Expand Up @@ -84,6 +84,7 @@ export type ModelEditOptions = {
undoStopBefore?: boolean;
formatDepth?: number;
skipFormat?: boolean;
selections?: ModelEditSelection[];
selection?: ModelEditSelection;
};

Expand All @@ -107,11 +108,14 @@ export interface EditableDocument {
readonly selectionLeft: number;
readonly selectionRight: number;
selection: ModelEditSelection;
selections: ModelEditSelection[];
model: EditableModel;
selectionsStack: ModelEditSelection[][];
selectionStack: ModelEditSelection[];
getTokenCursor: (offset?: number, previous?: boolean) => LispTokenCursor;
insertString: (text: string) => void;
getSelectionText: () => string;
getSelectionText: (index?: number) => string;
getSelectionsText: () => string[];
delete: () => Thenable<boolean>;
backspace: () => Thenable<boolean>;
}
Expand Down Expand Up @@ -548,6 +552,8 @@ export class StringDocument implements EditableDocument {

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

selectionsStack: ModelEditSelection[][] = [];
selections: ModelEditSelection[] = [];
selectionStack: ModelEditSelection[] = [];

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

getSelectionsText: () => string[];
insertString(text: string) {
this.model.insertString(0, text);
}

getSelectionText: () => string;

delete() {
const p = this.selectionLeft;
return this.model.edit([new ModelEdit('deleteRange', [p, 1])], {
selection: new ModelEditSelection(p),
const edits = [];
const selections = [];
this.selections.forEach(({ anchor: p }) => {
edits.push(new ModelEdit('deleteRange', [p, 1]));
selections.push(new ModelEditSelection(p));
});

return this.model.edit(edits, {
selections,
});
}
getSelectionText: () => string;

backspace() {
const p = this.selectionLeft;
return this.model.edit([new ModelEdit('deleteRange', [p - 1, 1])], {
selection: new ModelEditSelection(p - 1),
const edits = [];
const selections = [];
this.selections.forEach(({ anchor: p }) => {
edits.push(new ModelEdit('deleteRange', [p - 1, 1]));
selections.push(new ModelEditSelection(p - 1));
});

return this.model.edit(edits, {
selections,
});
}
}

0 comments on commit 36e500a

Please sign in to comment.