Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 2 additions & 2 deletions packages/cursorless-engine/src/actions/InsertCopy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ class InsertCopy implements SimpleAction {
const editableEditor = ide().getEditableTextEditor(editor);

const [
updatedEditorSelections,
updatedCursorSelections,
updatedContentSelections,
updatedEditSelections,
]: Selection[][] = await performEditsAndUpdateSelectionsWithBehavior(
Expand All @@ -86,7 +86,7 @@ class InsertCopy implements SimpleAction {
([edit, selection]) => edit!.updateRange(selection!),
);

setSelectionsWithoutFocusingEditor(editableEditor, updatedEditorSelections);
setSelectionsWithoutFocusingEditor(editableEditor, updatedCursorSelections);
const primarySelection = editor.selections[0];

if (
Expand Down
57 changes: 35 additions & 22 deletions packages/cursorless-engine/src/actions/Remove.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
import { FlashStyle } from "@cursorless/common";
import { FlashStyle, Selection, TextEditor } from "@cursorless/common";
import { flatten, zip } from "lodash";
import { RangeUpdater } from "../core/updateSelections/RangeUpdater";
import { performEditsAndUpdateRanges } from "../core/updateSelections/updateSelections";
import { performEditsAndUpdateSelections } from "../core/updateSelections/updateSelections";
import { RawSelectionTarget } from "../processTargets/targets";
import { ide } from "../singletons/ide.singleton";
import { Target } from "../typings/target.types";
import { flashTargets, runOnTargetsForEachEditor } from "../util/targetUtils";
import { unifyRemovalTargets } from "../util/unifyRanges";
import { SimpleAction, ActionReturnValue } from "./actions.types";
import { setSelectionsWithoutFocusingEditor } from "../util/setSelectionsAndFocusEditor";

export default class Delete implements SimpleAction {
constructor(private rangeUpdater: RangeUpdater) {
this.run = this.run.bind(this);
this.runForEditor = this.runForEditor.bind(this);
}

async run(
Expand All @@ -28,28 +30,39 @@ export default class Delete implements SimpleAction {
}

const thatTargets = flatten(
await runOnTargetsForEachEditor(targets, async (editor, targets) => {
const edits = targets.map((target) => target.constructRemovalEdit());
const ranges = edits.map((edit) => edit.range);

const [updatedRanges] = await performEditsAndUpdateRanges(
this.rangeUpdater,
ide().getEditableTextEditor(editor),
edits,
[ranges],
);

return zip(targets, updatedRanges).map(
([target, range]) =>
new RawSelectionTarget({
editor: target!.editor,
isReversed: target!.isReversed,
contentRange: range!,
}),
);
}),
await runOnTargetsForEachEditor(targets, this.runForEditor),
);

return { thatTargets };
}

private async runForEditor(editor: TextEditor, targets: Target[]) {
const edits = targets.map((target) => target.constructRemovalEdit());

const cursorSelections = editor.selections;
const editSelections = edits.map(({ range }) => range.toSelection(false));
const editableEditor = ide().getEditableTextEditor(editor);

const [updatedCursorSelections, updatedEditSelections]: Selection[][] =
await performEditsAndUpdateSelections(
this.rangeUpdater,
editableEditor,
edits,
[cursorSelections, editSelections],
);

await setSelectionsWithoutFocusingEditor(
editableEditor,
updatedCursorSelections,
);

return zip(targets, updatedEditSelections).map(
([target, range]) =>
new RawSelectionTarget({
editor: target!.editor,
isReversed: target!.isReversed,
contentRange: range!,
}),
);
}
}