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

Method appendToRegister

src/register/register.ts:147–188  ·  view source on GitHub ↗

* Appends the content at the specified index of the multicursor Register.

(
    vimState: VimState,
    register: string,
    content: RegisterContent,
    multicursorIndex: number,
  )

Source from the content-addressed store, hash-verified

145 * Appends the content at the specified index of the multicursor Register.
146 */
147 private static appendToRegister(
148 vimState: VimState,
149 register: string,
150 content: RegisterContent,
151 multicursorIndex: number,
152 ): void {
153 if (!Register.registers.has(register)) {
154 Register.registers.set(register, []);
155 }
156
157 const contentByCursor = Register.registers.get(register)!;
158 const oldContent = contentByCursor[multicursorIndex];
159 if (oldContent === undefined) {
160 contentByCursor[multicursorIndex] = {
161 registerMode: vimState.currentRegisterMode,
162 text: content,
163 };
164 } else {
165 // Line-wise trumps other RegisterModes
166 const registerMode =
167 vimState.currentRegisterMode === RegisterMode.LineWise
168 ? RegisterMode.LineWise
169 : oldContent.registerMode;
170 let newText: RegisterContent;
171 if (oldContent.text instanceof RecordedState || content instanceof RecordedState) {
172 newText = oldContent.text;
173 } else {
174 newText = oldContent.text + (registerMode === RegisterMode.LineWise ? '\n' : '') + content;
175 }
176 contentByCursor[multicursorIndex] = {
177 registerMode,
178 text: newText,
179 };
180 }
181
182 if (multicursorIndex === 0 && this.isClipboardRegister(register)) {
183 const newContent = contentByCursor[multicursorIndex].text;
184 if (!(newContent instanceof RecordedState)) {
185 void Clipboard.Copy(newContent);
186 }
187 }
188 }
189
190 /**
191 * Updates a readonly register's content. This is the only way to do so.

Callers 1

putMethod · 0.80

Calls 4

isClipboardRegisterMethod · 0.95
hasMethod · 0.80
CopyMethod · 0.80
getMethod · 0.65

Tested by

no test coverage detected