From 5fa0a983827a9ce173d4eef613dbd65154e3360f Mon Sep 17 00:00:00 2001 From: Pokey Rule Date: Wed, 1 Sep 2021 12:40:24 +0100 Subject: [PATCH 1/2] Fix copy when focus is not on editor --- src/actions/CommandAction.ts | 17 ++++++++--------- src/util/setSelectionsAndFocusEditor.ts | 8 ++++++-- 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/src/actions/CommandAction.ts b/src/actions/CommandAction.ts index 5961b7354c..3d625434ad 100644 --- a/src/actions/CommandAction.ts +++ b/src/actions/CommandAction.ts @@ -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"; @@ -32,18 +35,14 @@ export default class CommandAction implements Action { await runOnTargetsForEachEditor( 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); + + const originalSelections = editor.selections; const [updatedOriginalSelections, updatedTargetSelections] = await callFunctionAndUpdateSelections( diff --git a/src/util/setSelectionsAndFocusEditor.ts b/src/util/setSelectionsAndFocusEditor.ts index 016b00cd9b..dd8e2424b0 100644 --- a/src/util/setSelectionsAndFocusEditor.ts +++ b/src/util/setSelectionsAndFocusEditor.ts @@ -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 From a6b0257c4dbe20d57390785b227e5bb39e3ee970 Mon Sep 17 00:00:00 2001 From: Pokey Rule Date: Wed, 1 Sep 2021 12:44:54 +0100 Subject: [PATCH 2/2] Fix bug --- src/actions/CommandAction.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/actions/CommandAction.ts b/src/actions/CommandAction.ts index 3d625434ad..39cbc5793d 100644 --- a/src/actions/CommandAction.ts +++ b/src/actions/CommandAction.ts @@ -35,6 +35,8 @@ export default class CommandAction implements Action { await runOnTargetsForEachEditor( targets, async (editor, targets) => { + const originalSelections = editor.selections; + const targetSelections = targets.map( (target) => target.selection.selection ); @@ -42,8 +44,6 @@ export default class CommandAction implements Action { // For command to the work we have to have the correct editor focused await setSelectionsAndFocusEditor(editor, targetSelections, false); - const originalSelections = editor.selections; - const [updatedOriginalSelections, updatedTargetSelections] = await callFunctionAndUpdateSelections( () => commands.executeCommand(this.command),