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
13 changes: 6 additions & 7 deletions src/actions/CommandAction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@ import {
} from "../typings/Types";
import displayPendingEditDecorations from "../util/editDisplayUtils";
import { runOnTargetsForEachEditor } from "../util/targetUtils";
import { focusEditor } from "../util/setSelectionsAndFocusEditor";
import {
focusEditor,
setSelectionsAndFocusEditor,
} from "../util/setSelectionsAndFocusEditor";
import { flatten } from "lodash";
import { callFunctionAndUpdateSelections } from "../util/updateSelections";
import { ensureSingleEditor } from "../util/targetUtils";
Expand All @@ -32,18 +35,14 @@ export default class CommandAction implements Action {
await runOnTargetsForEachEditor<SelectionWithEditor[]>(
targets,
async (editor, targets) => {
// For command to the work we have to have the correct editor focused
if (editor !== window.activeTextEditor) {
await focusEditor(editor);
}

const originalSelections = editor.selections;

const targetSelections = targets.map(
(target) => target.selection.selection
);

editor.selections = targetSelections;
// For command to the work we have to have the correct editor focused
await setSelectionsAndFocusEditor(editor, targetSelections, false);
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When setting selections and focusing editor it is important to first set the selections and then focus the editor. This was fixed in the setSelectionsAndFocusEditor function but because it wasn't used here we didn't get that fix


const [updatedOriginalSelections, updatedTargetSelections] =
await callFunctionAndUpdateSelections(
Expand Down
8 changes: 6 additions & 2 deletions src/util/setSelectionsAndFocusEditor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,14 @@ const columnFocusCommands = {

export async function setSelectionsAndFocusEditor(
editor: TextEditor,
selections: Selection[]
selections: Selection[],
revealRange: boolean = true
) {
editor.selections = selections;
editor.revealRange(editor.selection);

if (revealRange) {
editor.revealRange(editor.selection);
}

// NB: We focus the editor after setting the selection because otherwise you see
// an intermediate state where the old selection persists
Expand Down