-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support for appending to named registers #731
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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.join('\n') + '\n' + content; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Careful. The reason that existingText can be a string[] is because of yanking in visual block mode - you copy an entire block, and then paste the whole block later. (Same thing with content[].) I'm don't think that flattening down that array is the right thing to do here, because then you lose that block. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes I was unsure about this. The approach I took preserves the type of the new content, so string + string[] -> string[], string[] + string -> string. Are you saying that if either existingText or content is string[] then the result should be string[]? |
||
} | ||
} else { | ||
if (typeof existingText === 'string') { | ||
content = existingText.split('\n').concat(content); | ||
} else { | ||
content = existingText.concat(content); | ||
} | ||
} | ||
} | ||
} | ||
|
||
Register.registers[register] = { | ||
text : content, | ||
registerMode: vimState.effectiveRegisterMode(), | ||
|
@@ -63,12 +84,17 @@ export class Register { | |
* register ". | ||
*/ | ||
public static async get(vimState: VimState): Promise<IRegisterContent> { | ||
const register = vimState.recordedState.registerName; | ||
let register = vimState.recordedState.registerName; | ||
|
||
if (!Register.isValidRegister(register)) { | ||
throw new Error(`Invalid register ${register}`); | ||
} | ||
|
||
// Register names are case-insensitive. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This comment is a little bit misleading. Probably you want to say something like |
||
if (/^[A-Z]$/.test(register)) { | ||
register = register.toLowerCase(); | ||
} | ||
|
||
if (!Register.registers[register]) { | ||
Register.registers[register] = { text: "", registerMode: RegisterMode.CharacterWise }; | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you move this into it's own separate static function (
isNamedRegister
), similar toisValidRegister
?