Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
88 commits
Select commit Hold shift + click to select a range
9834b50
Started working on our own replacement for vscode types
AndreasArvidsson Nov 10, 2022
516b47c
remove unused imports
AndreasArvidsson Nov 10, 2022
313ac8c
More workl
AndreasArvidsson Nov 11, 2022
df9608b
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Nov 11, 2022
66d177c
more changes
AndreasArvidsson Nov 11, 2022
4f4c15a
Merge branch 'types' of github.com:cursorless-dev/cursorless into types
AndreasArvidsson Nov 11, 2022
ad3d964
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Nov 11, 2022
5a7a172
More stuff
AndreasArvidsson Nov 11, 2022
4752f9c
Merge branch 'types' of github.com:cursorless-dev/cursorless into types
AndreasArvidsson Nov 11, 2022
11f18b3
Stuff stuff
AndreasArvidsson Nov 11, 2022
680a549
Some super secret clean up stuff
AndreasArvidsson Nov 11, 2022
2463653
Additional changes beyond human comprehension
AndreasArvidsson Nov 13, 2022
76b06c5
clean up
AndreasArvidsson Nov 13, 2022
806f1e2
Trans dimensional super fixes
AndreasArvidsson Nov 13, 2022
d6c43f5
Mind boggling changes
AndreasArvidsson Nov 13, 2022
8f5cfa5
Hopefully done with this suffering
AndreasArvidsson Nov 13, 2022
2c84c0b
Fixed circular dependencies
AndreasArvidsson Nov 13, 2022
3054983
Updated fake ide
AndreasArvidsson Nov 13, 2022
7eed96c
Added test for position
AndreasArvidsson Nov 13, 2022
1e9a3b8
Added range test
AndreasArvidsson Nov 13, 2022
682ab6d
Added getter to vscode editable editor implementation
AndreasArvidsson Nov 13, 2022
f0fb525
Convert position
AndreasArvidsson Nov 13, 2022
b24a209
Added text line implementation
AndreasArvidsson Nov 13, 2022
cdc792c
Better handling of selections
AndreasArvidsson Nov 13, 2022
825491c
group document by uri
AndreasArvidsson Nov 13, 2022
88af316
Remove on use to vscode converter
AndreasArvidsson Nov 13, 2022
0a30f19
Clean up tests
AndreasArvidsson Nov 13, 2022
bc8658c
Make sure functions use arrow format
AndreasArvidsson Nov 13, 2022
f4e7460
Use weak map to keep track of text editors
AndreasArvidsson Nov 13, 2022
406cb09
cleanup
AndreasArvidsson Nov 13, 2022
9fd624f
empty
AndreasArvidsson Nov 14, 2022
a935f5a
use arrow functions
AndreasArvidsson Nov 14, 2022
132cad9
updated lock file
AndreasArvidsson Nov 14, 2022
fd8b413
restore normal methods for position and range
AndreasArvidsson Nov 14, 2022
9ff9912
Remove arrow expressions as method
AndreasArvidsson Nov 14, 2022
1b8899e
added is active on the text editor
AndreasArvidsson Nov 14, 2022
0ad551d
Error when trying to deselect all selections
AndreasArvidsson Nov 14, 2022
b9934a3
added types
AndreasArvidsson Nov 14, 2022
014c618
Make use of `@cursorless` imports
AndreasArvidsson Nov 14, 2022
7381718
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Nov 14, 2022
2ca6f88
Moved vscode utilities
AndreasArvidsson Nov 14, 2022
48f4b22
Merge branch 'types' of github.com:cursorless-dev/cursorless into types
AndreasArvidsson Nov 14, 2022
f9f5540
update
AndreasArvidsson Nov 14, 2022
2572664
Fixed stupid bug
AndreasArvidsson Nov 14, 2022
2794bb5
empty
AndreasArvidsson Nov 14, 2022
aa275b6
stuff
AndreasArvidsson Nov 15, 2022
501f7c9
stuff
AndreasArvidsson Nov 15, 2022
7bb38a4
Added to empty range on position
AndreasArvidsson Nov 15, 2022
836092d
cleaned up vscode edit
AndreasArvidsson Nov 15, 2022
ad779fa
clean up
AndreasArvidsson Nov 15, 2022
10ea6d2
clean up vscode focus editor
AndreasArvidsson Nov 15, 2022
e764692
move creation of text editors into ide
AndreasArvidsson Nov 15, 2022
9b6598b
cleanup
AndreasArvidsson Nov 15, 2022
4c2ec1c
moved get node at location into editor
AndreasArvidsson Nov 15, 2022
d829853
empty
AndreasArvidsson Nov 15, 2022
b9b78c7
remove spread
AndreasArvidsson Nov 15, 2022
fb2d25b
Add license reference
pokey Nov 15, 2022
3cb92b6
use full vscode implementation
AndreasArvidsson Nov 15, 2022
3392546
Revert "moved get node at location into editor"
AndreasArvidsson Nov 15, 2022
9e8d26d
remove location type
AndreasArvidsson Nov 15, 2022
22ab6de
Merge branch 'main' into types
AndreasArvidsson Nov 15, 2022
4c2a848
Switch `getNodeAtLocation` to use document
pokey Nov 15, 2022
9cc4496
Use editable editor for performing edits
pokey Nov 15, 2022
e3da4a5
Add `ide` reference to editable text editor
pokey Nov 15, 2022
73cf0e5
docs
pokey Nov 15, 2022
c138345
Tweak
pokey Nov 15, 2022
ae1e1ff
tweak
pokey Nov 15, 2022
c12d8b3
Fix bug with id / editor generation
pokey Nov 15, 2022
4aaa19c
Remove unnecessary functions
pokey Nov 15, 2022
49bf331
Tweak name
pokey Nov 15, 2022
a1066b2
merged vscode text editor implementations
AndreasArvidsson Nov 16, 2022
4a456eb
Add back comments about range adjustment
pokey Nov 16, 2022
cfdb2d1
Tweak docstrings
pokey Nov 16, 2022
9ba5d27
docs
pokey Nov 16, 2022
14d5f0e
add a couple tests
pokey Nov 16, 2022
1009155
Updated line behavior
AndreasArvidsson Nov 16, 2022
f0ec35d
Test tweaks
pokey Nov 16, 2022
9d86644
updated behavior
AndreasArvidsson Nov 16, 2022
a2299bb
added selection isEqual
AndreasArvidsson Nov 16, 2022
6738670
`isEqual` => `isRangeEqual`
pokey Nov 16, 2022
c8a5a72
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Nov 16, 2022
cff3b07
cleanup
AndreasArvidsson Nov 16, 2022
3209bf4
Capture more unit tests in launch config
pokey Nov 16, 2022
07797b5
move `openNewEditor`
pokey Nov 16, 2022
4f37f26
Basic `TextLine` test
pokey Nov 16, 2022
5cdfba5
Selection + more range tests
pokey Nov 16, 2022
62328ad
yarn.lock tweak
pokey Nov 16, 2022
dfa7cd2
more line tests
pokey Nov 16, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 1 addition & 7 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,7 @@
}
],
"no-throw-literal": "warn",
"semi": "off",
"no-restricted-properties": [
2,
{
"property": "activeTextEditor"
}
]
"semi": "off"
},
"ignorePatterns": ["**/vendor/**/*.ts", "**/vendor/**/*.js"]
}
6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -590,18 +590,20 @@
"@types/chai": "^4.3.3",
"@types/glob": "^7.1.3",
"@types/js-yaml": "^4.0.2",
"@types/lodash": "^4.14.168",
"@types/mocha": "^8.0.4",
"@types/node": "^16.11.3",
"@types/semver": "^7.3.9",
"@types/sinon": "^10.0.2",
"@types/uuid": "^8.3.4",
"@types/vscode": "~1.61.0",
"@typescript-eslint/eslint-plugin": "^5.20.0",
"@typescript-eslint/parser": "^5.20.0",
"@vscode/test-electron": "^2.1.3",
"chai": "^4.3.6",
"esbuild": "^0.11.12",
"eslint": "^8.13.0",
"eslint-config-prettier": "^8.5.0",
"eslint": "^8.13.0",
"fast-xml-parser": "^3.20.0",
"glob": "^7.1.7",
"js-yaml": "^4.1.0",
Expand All @@ -615,12 +617,12 @@
"typescript": "4.6.3"
},
"dependencies": {
"@types/lodash": "^4.14.168",
"immer": "^9.0.15",
"immutability-helper": "^3.1.1",
"itertools": "^1.7.1",
"lodash": "^4.17.21",
"node-html-parser": "^5.3.3",
"uuid": "^9.0.0",
"vscode-uri": "^3.0.6"
}
}
15 changes: 9 additions & 6 deletions src/actions/BringMoveSwap.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import { Selection, TextEditor } from "@cursorless/common";
import { flatten } from "lodash";
import { DecorationRangeBehavior, Selection, TextEditor } from "vscode";
import { DecorationRangeBehavior } from "vscode";
import {
getSelectionInfo,
performEditsAndUpdateFullSelectionInfos,
} from "../core/updateSelections/updateSelections";
import ide from "../libs/cursorless-engine/singletons/ide.singleton";
import { Target } from "../typings/target.types";
import { EditWithRangeUpdater, Graph } from "../typings/Types";
import { selectionFromRange } from "../util/selectionUtils";
import { setSelectionsWithoutFocusingEditor } from "../util/setSelectionsAndFocusEditor";
import { getContentRange, runForEachEditor } from "../util/targetUtils";
import { unifyRemovalTargets } from "../util/unifyRanges";
Expand Down Expand Up @@ -167,7 +168,7 @@ class BringMoveSwap implements Action {
({ edit: { range }, originalTarget }) =>
getSelectionInfo(
editor.document,
selectionFromRange(originalTarget.isReversed, range),
range.toSelection(originalTarget.isReversed),
DecorationRangeBehavior.OpenOpen,
),
);
Expand All @@ -180,26 +181,28 @@ class BringMoveSwap implements Action {
),
);

const editableEditor = ide().getEditableTextEditor(editor);

const [updatedEditSelections, cursorSelections]: Selection[][] =
await performEditsAndUpdateFullSelectionInfos(
this.graph.rangeUpdater,
editor,
editableEditor,
filteredEdits.map(({ edit }) => edit),
[editSelectionInfos, cursorSelectionInfos],
);

// NB: We set the selections here because we don't trust vscode to
// properly move the cursor on a bring. Sometimes it will smear an
// empty selection
setSelectionsWithoutFocusingEditor(editor, cursorSelections);
setSelectionsWithoutFocusingEditor(editableEditor, cursorSelections);

return edits.map((edit, index): MarkEntry => {
const selection = updatedEditSelections[index];
const range = edit.edit.updateRange(selection);
const target = edit.originalTarget;
return {
editor,
selection: selectionFromRange(target.isReversed, range),
selection: range.toSelection(target.isReversed),
isSource: edit.isSource,
target,
};
Expand Down
3 changes: 2 additions & 1 deletion src/actions/Clear.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import ide from "../libs/cursorless-engine/singletons/ide.singleton";
import { PlainTarget } from "../processTargets/targets";
import { Target } from "../typings/target.types";
import { Graph } from "../typings/Types";
Expand Down Expand Up @@ -29,7 +30,7 @@ export default class Clear implements Action {

if (thatMark != null) {
await setSelectionsAndFocusEditor(
editor,
ide().getEditableTextEditor(editor),
thatMark.map(({ selection }) => selection),
);
}
Expand Down
20 changes: 13 additions & 7 deletions src/actions/CommandAction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ import { flatten } from "lodash";
import { commands } from "vscode";
import { selectionToThatTarget } from "../core/commandRunner/selectionToThatTarget";
import { callFunctionAndUpdateSelections } from "../core/updateSelections/updateSelections";
import ide from "../libs/cursorless-engine/singletons/ide.singleton";
import { Target } from "../typings/target.types";
import { Graph } from "../typings/Types";
import {
focusEditor,
setSelectionsAndFocusEditor,
setSelectionsWithoutFocusingEditor,
} from "../util/setSelectionsAndFocusEditor";
Expand All @@ -15,7 +15,6 @@ import {
runOnTargetsForEachEditor,
} from "../util/targetUtils";
import { Action, ActionReturnValue } from "./actions.types";
import { getActiveTextEditor } from "../ide/vscode/activeTextEditor";

export interface CommandOptions {
command?: string;
Expand Down Expand Up @@ -53,7 +52,11 @@ export default class CommandAction implements Action {
);

// For command to the work we have to have the correct editor focused
await setSelectionsAndFocusEditor(editor, targetSelections, false);
await setSelectionsAndFocusEditor(
ide().getEditableTextEditor(editor),
targetSelections,
false,
);

const [updatedOriginalSelections, updatedTargetSelections] =
await callFunctionAndUpdateSelections(
Expand All @@ -70,7 +73,10 @@ export default class CommandAction implements Action {
// very end. This code can run on multiple editors in the course of
// one command, so we want to avoid focusing the editor multiple
// times.
setSelectionsWithoutFocusingEditor(editor, updatedOriginalSelections);
setSelectionsWithoutFocusingEditor(
ide().getEditableTextEditor(editor),
updatedOriginalSelections,
);
}

// If the document hasn't changed then we just return the original targets
Expand Down Expand Up @@ -120,7 +126,7 @@ export default class CommandAction implements Action {
ensureSingleTarget(targets);
}

const originalEditor = getActiveTextEditor();
const originalEditor = ide().activeEditableTextEditor;

const thatTargets = await this.runCommandAndUpdateSelections(
targets,
Expand All @@ -131,12 +137,12 @@ export default class CommandAction implements Action {
if (
actualOptions.restoreSelection &&
originalEditor != null &&
originalEditor !== getActiveTextEditor()
!originalEditor.isActive
) {
// NB: We just do one editor focus at the end, instead of using
// setSelectionsAndFocusEditor because the command might operate on
// multiple editors, so we just do one focus at the end.
await focusEditor(originalEditor);
await originalEditor.focus();
}

return { thatTargets };
Expand Down
21 changes: 15 additions & 6 deletions src/actions/Deselect.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Selection } from "vscode";
import ide from "../libs/cursorless-engine/singletons/ide.singleton";
import { Target } from "../typings/target.types";
import { Graph } from "../typings/Types";
import { setSelectionsWithoutFocusingEditor } from "../util/setSelectionsAndFocusEditor";
Expand All @@ -20,12 +20,14 @@ export default class Deselect implements Action {
return intersection && (!intersection.isEmpty || selection.isEmpty);
}),
);
// The editor requires at least one selection. Keep "primary" selection active

if (newSelections.length === 0) {
throw new SelectionRequiredError();
}

setSelectionsWithoutFocusingEditor(
editor,
newSelections.length > 0
? newSelections
: [new Selection(editor.selection.active, editor.selection.active)],
ide().getEditableTextEditor(editor),
newSelections,
);
});

Expand All @@ -34,3 +36,10 @@ export default class Deselect implements Action {
};
}
}

class SelectionRequiredError extends Error {
constructor() {
super("Can't deselect every selection. At least one is required");
this.name = "SelectionRequiredError";
}
}
16 changes: 9 additions & 7 deletions src/actions/EditNew/EditNew.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import ide from "../../libs/cursorless-engine/singletons/ide.singleton";
import { containingLineIfUntypedStage } from "../../processTargets/modifiers/commonContainingScopeIfUntypedStages";
import PositionStage from "../../processTargets/modifiers/PositionStage";
import { ModifierStage } from "../../processTargets/PipelineStages.types";
import { Target } from "../../typings/target.types";
import { Graph } from "../../typings/Types";
import { selectionFromRange } from "../../util/selectionUtils";
import { setSelectionsAndFocusEditor } from "../../util/setSelectionsAndFocusEditor";
import { createThatMark, ensureSingleEditor } from "../../util/targetUtils";
import { Action, ActionReturnValue } from "../actions.types";
import { State } from "./EditNew.types";
import { runNotebookCellTargets } from "./runNotebookCellTargets";
import { runCommandTargets } from "./runCommandTargets";
import { runEditTargets } from "./runEditTargets";
import { runNotebookCellTargets } from "./runNotebookCellTargets";

export class EditNew implements Action {
getFinalStages(): ModifierStage[] {
Expand All @@ -29,7 +29,9 @@ export class EditNew implements Action {
return runNotebookCellTargets(this.graph, targets);
}

const editor = ensureSingleEditor(targets);
const editableEditor = ide().getEditableTextEditor(
ensureSingleEditor(targets),
);

/**
* Keeps track of the desired cursor positions and "that" marks as we
Expand All @@ -41,13 +43,13 @@ export class EditNew implements Action {
cursorRanges: new Array(targets.length).fill(undefined) as undefined[],
};

state = await runCommandTargets(this.graph, editor, state);
state = await runEditTargets(this.graph, editor, state);
state = await runCommandTargets(this.graph, editableEditor, state);
state = await runEditTargets(this.graph, editableEditor, state);

const newSelections = state.targets.map((target, index) =>
selectionFromRange(target.isReversed, state.cursorRanges[index]!),
state.cursorRanges[index]!.toSelection(target.isReversed),
);
await setSelectionsAndFocusEditor(editor, newSelections);
await setSelectionsAndFocusEditor(editableEditor, newSelections);

return {
thatSelections: createThatMark(state.targets, state.thatRanges),
Expand Down
4 changes: 2 additions & 2 deletions src/actions/EditNew/EditNew.types.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Range } from "vscode";
import { Target } from "../../typings/target.types";
import type { Range } from "@cursorless/common";
import type { Target } from "../../typings/target.types";

/**
* Internal type to be used for storing a reference to a target that will use a
Expand Down
5 changes: 3 additions & 2 deletions src/actions/EditNew/runCommandTargets.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { commands, TextEditor } from "vscode";
import { EditableTextEditor } from "@cursorless/common";
import { commands } from "vscode";
import { callFunctionAndUpdateRanges } from "../../core/updateSelections/updateSelections";
import { Graph } from "../../typings/Types";
import { CommandTarget, State } from "./EditNew.types";
Expand All @@ -16,7 +17,7 @@ import { CommandTarget, State } from "./EditNew.types";
*/
export async function runCommandTargets(
graph: Graph,
editor: TextEditor,
editor: EditableTextEditor,
state: State,
): Promise<State> {
const commandTargets: CommandTarget[] = state.targets
Expand Down
15 changes: 6 additions & 9 deletions src/actions/EditNew/runEditTargets.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Selection, EditableTextEditor } from "@cursorless/common";
import { zip } from "lodash";
import { DecorationRangeBehavior, Range, Selection, TextEditor } from "vscode";
import { DecorationRangeBehavior } from "vscode";
import { performEditsAndUpdateSelectionsWithBehavior } from "../../core/updateSelections/updateSelections";
import { Graph } from "../../typings/Types";
import { EditTarget, State } from "./EditNew.types";
Expand All @@ -19,7 +20,7 @@ import { EditTarget, State } from "./EditNew.types";
*/
export async function runEditTargets(
graph: Graph,
editor: TextEditor,
editor: EditableTextEditor,
state: State,
): Promise<State> {
const editTargets: EditTarget[] = state.targets
Expand All @@ -43,7 +44,7 @@ export async function runEditTargets(
);

const thatSelections = {
selections: state.thatRanges.map(toSelection),
selections: state.thatRanges.map((r) => r.toSelection(false)),
};

// We need to remove undefined cursor locations. Note that these undefined
Expand All @@ -57,11 +58,11 @@ export async function runEditTargets(
const cursorIndices = cursorInfos.map(({ index }) => index);

const cursorSelections = {
selections: cursorInfos.map(({ range }) => toSelection(range!)),
selections: cursorInfos.map(({ range }) => range!.toSelection(false)),
};

const editSelections = {
selections: edits.map((edit) => toSelection(edit.range)),
selections: edits.map((edit) => edit.range.toSelection(false)),
rangeBehavior: DecorationRangeBehavior.OpenOpen,
};

Expand Down Expand Up @@ -96,7 +97,3 @@ export async function runEditTargets(
cursorRanges: updatedCursorRanges,
};
}

function toSelection(range: Range) {
return new Selection(range.start, range.end);
}
7 changes: 4 additions & 3 deletions src/actions/EditNew/runNotebookCellTargets.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { commands, Selection } from "vscode";
import { Selection } from "@cursorless/common";
import { commands } from "vscode";
import { NotebookCellPositionTarget } from "../../processTargets/targets";
import { Target } from "../../typings/target.types";
import { Graph } from "../../typings/Types";
Expand All @@ -20,8 +21,8 @@ export async function runNotebookCellTargets(
// Inserting a new jupyter cell above pushes the previous one down two lines
if (command === "jupyter.insertCellAbove") {
thatMark[0].selection = new Selection(
thatMark[0].selection.anchor.translate({ lineDelta: 2 }),
thatMark[0].selection.active.translate({ lineDelta: 2 }),
thatMark[0].selection.anchor.translate(2, undefined),
thatMark[0].selection.active.translate(2, undefined),
);
}

Expand Down
Loading