MCPcopy
hub / github.com/VSCodeVim/Vim / syncCursors

Method syncCursors

src/mode/modeHandler.ts:127–148  ·  view source on GitHub ↗

* Updates VSCodeVim's internal representation of cursors to match VSCode's selections. * This loses some information, so it should only be done when necessary.

()

Source from the content-addressed store, hash-verified

125 * This loses some information, so it should only be done when necessary.
126 */
127 public syncCursors() {
128 // TODO: getCursorsAfterSync() is basically this, but stupider
129 const { selections } = this.vimState.editor;
130 // TODO: this if block is a workaround for a problem described here https://github.com/VSCodeVim/Vim/pull/8426
131 if (
132 selections.length === 1 &&
133 selections[0].isEqual(new Range(new Position(0, 0), new Position(0, 0)))
134 ) {
135 return;
136 }
137
138 if (
139 !this.vimState.cursorStartPosition.isEqual(selections[0].anchor) ||
140 !this.vimState.cursorStopPosition.isEqual(selections[0].active)
141 ) {
142 this.vimState.desiredColumn = selections[0].active.character;
143 }
144
145 this.vimState.cursors = selections.map(({ active, anchor }) =>
146 active.isBefore(anchor) ? new Cursor(anchor.getLeft(), active) : new Cursor(anchor, active),
147 );
148 }
149
150 /**
151 * This is easily the worst function in VSCodeVim.

Callers 2

createMethod · 0.95
getAndUpdateModeHandlerFunction · 0.80

Calls 1

getLeftMethod · 0.80

Tested by

no test coverage detected