diff --git a/src/register/register.ts b/src/register/register.ts index 6255e6a233b..443493dd664 100644 --- a/src/register/register.ts +++ b/src/register/register.ts @@ -42,7 +42,7 @@ export class Register { * register ". */ public static put(content: string | string[], vimState: VimState): void { - const register = vimState.recordedState.registerName; + let register = vimState.recordedState.registerName; if (!Register.isValidRegister(register)) { throw new Error(`Invalid register ${register}`); @@ -52,6 +52,27 @@ export class Register { clipboard.copy(content); } + // Upper-case register name denotes append. + if (/^[A-Z]$/.test(register)) { + register = register.toLowerCase(); + let existingText = Register.registers[register] && Register.registers[register].text; + if (existingText) { + if (typeof content === 'string') { + if (typeof existingText === 'string') { + content = existingText + (existingText.endsWith('\n') ? '' : '\n') + content; + } else { + content = existingText.concat(content.split('\n')); + } + } else { + if (typeof existingText === 'string') { + content = existingText.split('\n').concat(content); + } else { + content = existingText.concat(content); + } + } + } + } + Register.registers[register] = { text : content, registerMode: vimState.effectiveRegisterMode(), @@ -72,6 +93,11 @@ export class Register { throw new Error(`Invalid register ${register}`); } + // Retrieving register content is case-insensitive + if (/^[A-Z]$/.test(register)) { + register = register.toLowerCase(); + } + if (!Register.registers[register]) { Register.registers[register] = { text: "", registerMode: RegisterMode.CharacterWise }; } diff --git a/test/register/register.test.ts b/test/register/register.test.ts index 6f67906566d..9ea4689cf24 100644 --- a/test/register/register.test.ts +++ b/test/register/register.test.ts @@ -48,4 +48,18 @@ suite("register", () => { end: ["one", "two", "one", "|two"], }); + newTest({ + title: "Can append content to register", + start: ['|one', "two"], + keysPressed: '"ayyj"Ayy$"ap', + end: ["one", "two", "|one", "two"], + }); + + newTest({ + title: "Can replace register contents after append", + start: ['|one', "two", "three"], + keysPressed: '"ayyj"Ayyj"ayy$"ap', + end: ["one", "two", "three", "|three"], + }); + }); \ No newline at end of file