Skip to content
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

Closed
wants to merge 5 commits into from

Conversation

domgee
Copy link
Contributor

@domgee domgee commented Sep 7, 2016

Named registers should be case insensitive, with lower case denoting replace register contents, and upper case denoting append to register contents.

Vim documentation, Named Registers

if (typeof existingText === 'string') {
content = existingText + (existingText.endsWith('\n') ? '' : '\n') + content;
} else {
content = existingText.join('\n') + '\n' + content;
Copy link
Member

@johnfn johnfn Sep 8, 2016

Choose a reason for hiding this comment

The 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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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[]?

@johnfn
Copy link
Member

johnfn commented Sep 8, 2016

Thanks for the PR, @dominic31! Looks good to me, just a few concerns about how we handle visual block mode copy/paste.

@domgee
Copy link
Contributor Author

domgee commented Sep 12, 2016

@johnfn Thanks for the comments! I've pushed some changes, hopefully it looks better now.

@johnfn
Copy link
Member

johnfn commented Sep 15, 2016

Ergh.

After investigating registers a little more, I believe that I have actually implemented registers incorrectly in the case of visual block mode! It seems like when you copy in visual block mode, you simply copy each line separated by a newline. This is different than what we are doing, where if you copy in visual block mode, you actually copy an array of each line.

I would encourage you to go ahead and fix this, but actually I am anticipating some annoying merge conflicts with a branch I have been working on for a while #587 which adds yet another register case type.

If you really want to, you could first copy my register changes into here from my PR, and then work on top of them to replace the string[] case with string. If that sounds too complicated, I don't blame you; I'd just wait until I merge my PR in (optimistically) a few days.

@domgee
Copy link
Contributor Author

domgee commented Sep 17, 2016

It seems like when you copy in visual block mode, you simply copy each line separated by a newline.

Where does this happen? When appending to registers in visual block mode, I concatenate the arrays,

@Platzer Platzer mentioned this pull request Oct 6, 2016
6 tasks
@jpoon
Copy link
Member

jpoon commented Oct 19, 2016

Closing this PR as there haven't been any movement in the last month. Fee free to re-open the PR and let us know when it's ready for review.

@jpoon jpoon closed this Oct 19, 2016
@domgee
Copy link
Contributor Author

domgee commented Oct 20, 2016

@jpoon I was waiting for a reply to my last comment, else it is as far as I can see ready.

@jpoon jpoon reopened this Oct 20, 2016
@jpoon
Copy link
Member

jpoon commented Oct 20, 2016

@dominic31 My bad. Some of this logic changed since your last rebase, can you fix the conflicts then we can give it a quick review and merge?

@@ -52,6 +52,27 @@ export class Register {
clipboard.copy(content);
}

// Upper-case register name denotes append.
if (/^[A-Z]$/.test(register)) {
Copy link
Member

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 to isValidRegister?

@johnfn
Copy link
Member

johnfn commented Oct 20, 2016

I'm really sorry I didn't respond to that comment! I'm getting spammed with notifications from Github constantly and it makes it really difficult to find the stuff that matters. :(

Anywho, if you can make this work for the new register type I alluded to, we should be good here.

@jpoon
Copy link
Member

jpoon commented Oct 25, 2016

@Platzer submitted #974 which incompases these same changes. I'm closing this PR in favor of @Platzer mainly as there hasn't been any movement on this in the last week.

@jpoon jpoon closed this Oct 25, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants