(
position: Position,
vimState: VimState,
count: number,
)
| 67 | } |
| 68 | |
| 69 | public override async execActionWithCount( |
| 70 | position: Position, |
| 71 | vimState: VimState, |
| 72 | count: number, |
| 73 | ): Promise<Position | IMovement> { |
| 74 | const multicursorIndex = this.multicursorIndex ?? 0; |
| 75 | |
| 76 | if (multicursorIndex === 0) { |
| 77 | if (vimState.currentMode === Mode.Visual) { |
| 78 | // If we change the `vimState.editor.selections` directly with the forEach |
| 79 | // for some reason vscode doesn't update them. But doing it this way does |
| 80 | // update vscode's selections. |
| 81 | vimState.editor.selections = vimState.editor.selections.map((s, i) => { |
| 82 | if (s.active.isAfter(s.anchor)) { |
| 83 | // The selection is on the right side of the cursor, while our representation |
| 84 | // considers the cursor to be the left edge, so we need to move the selection |
| 85 | // to the right place before executing the 'cursorMove' command. |
| 86 | const active = s.active.getLeftThroughLineBreaks(); |
| 87 | return new vscode.Selection(s.anchor, active); |
| 88 | } else { |
| 89 | return s; |
| 90 | } |
| 91 | }); |
| 92 | } |
| 93 | |
| 94 | // When we have multicursors and run a 'cursorMove' command, vscode applies that command |
| 95 | // to all cursors at the same time. So we should only run it once. |
| 96 | await vscode.commands.executeCommand('cursorMove', { |
| 97 | to: this.movementType, |
| 98 | select: vimState.currentMode !== Mode.Normal, |
| 99 | // select: ![Mode.Normal, Mode.Insert].includes(vimState.currentMode), |
| 100 | by: this.by, |
| 101 | value: this.value * count, |
| 102 | }); |
| 103 | } |
| 104 | |
| 105 | /** |
| 106 | * HACK: |
| 107 | * The `cursorMove` command is handling the selection for us. |
| 108 | * So we are not following our design principal (do no real movement inside an action) here |
| 109 | */ |
| 110 | if (!vimState.editor.selections[multicursorIndex]) { |
| 111 | // VS Code selections no longer have the same amount of cursors as we do. This means that |
| 112 | // two or more selections combined into one. In this case we return these cursors as they |
| 113 | // were with the removed flag so that they can be removed. |
| 114 | // TODO: does this work in VisualBlock (where cursors are not 1 to 1 with selections)? |
| 115 | return { |
| 116 | start: vimState.cursorStartPosition, |
| 117 | stop: vimState.cursorStopPosition, |
| 118 | removed: true, |
| 119 | }; |
| 120 | } |
| 121 | |
| 122 | if (vimState.currentMode === Mode.Normal) { |
| 123 | return vimState.editor.selections[multicursorIndex].active; |
| 124 | } else { |
| 125 | let start = vimState.editor.selections[multicursorIndex].anchor; |
| 126 | const stop = vimState.editor.selections[multicursorIndex].active; |
nothing calls this directly
no test coverage detected