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

Multiline yank writes to 0 register; fixes #1214 #3087

Merged
merged 6 commits into from
Oct 6, 2018

Conversation

jkillian
Copy link
Contributor

@jkillian jkillian commented Oct 2, 2018

What this PR does / why we need it:
Makes sure that multiline yank commands (5yy, 5Y, V%y) write to the 0 register. (They don't currently)

Which issue(s) this PR fixes
fixes #1214, fixes #2554, fixes #3065

Special notes for your reviewer:
See inline comment below for more explanation of this change

@@ -302,9 +302,7 @@ export class Register {
*/
private static processNumberedRegister(content: RegisterContent, vimState: VimState): void {
// Find the BaseOperator of the current actions
const baseOperator = vimState.recordedState.actionsRun.find(value => {
return value instanceof BaseOperator || value instanceof BaseCommand;
});
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Previously, this code was initializing baseOperator to be CommandNumber in some cases. For example, 5Y is [CommandNumber, CommandYankFullLine], and because CommandNumber inherits from BaseCommand and comes first, baseOperator would be set to that.

Then, the blocks below specifically to handle yanks wouldn't be hit.

export class CommandNumber extends BaseCommand {

@@ -126,7 +126,7 @@ export class RecordedState {
* The command (e.g. i, ., R, /) the user wants to run, if there is one.
*/
public get command(): BaseCommand {
const list = _.filter(this.actionsRun, a => a instanceof BaseCommand);
const list = _.filter(this.actionsRun, a => a instanceof BaseCommand).reverse();
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As far as I could tell, this get command() isn't actually being used anywhere yet, so this should be a safe change.

However, the comment below brought me pause:

// TODO - disregard , then assert this is of length 1.

If there is only supposed to be one BaseCommand, how come 5Y is two commands? Not familiar with the VSCode Vim codebase, but just wanted to mention this in case it matters.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, what are your thoughts on handling this in the processNumberedRegister call instead? Changing this seems a little bit of a workaround since the get() is currently returning the stack the way it was executed (which seems OK to me)

Not too sure on the TODO comment :/

Copy link
Contributor Author

@jkillian jkillian Oct 5, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, since nobody else seems to be calling get command(), I guess we can define it however we wish. To me, returning the last command seems to make more sense - for example if I ran 5@q I'd expect .command to refer to the macro execution, CommandExecuteMacro as opposed to CommandNumber. Or for something like "aD, I'd expect the D command, CommandDeleteToLineEnd, instead of the register command,CommandRegister.

That said, you know the code better than I do, so happy to do it either way in the end! Both ways will accomplish the same purpose and get this working better which is what matters 😃

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting looks like the getter for operator is reversed, lets just go with this!

@xconverge
Copy link
Member

Thanks! This one actually bugs me a lot!

@xconverge xconverge merged commit 047362c into VSCodeVim:master Oct 6, 2018
@TravisBuddy
Copy link

Hey @jkillian,
Something went wrong with the build.

TravisCI finished with status errored, which means the build failed because of something unrelated to the tests, such as a problem with a dependency or the build process itself.

View build log

TravisBuddy Request Identifier: 9bb6a060-c994-11e8-a6c9-11724a02104f

@jkillian
Copy link
Contributor Author

jkillian commented Oct 6, 2018

Thanks @xconverge! As a sidenote, I found this codebase really easy to jump into and start working on, so big 👍 for the simple code and organization! (And also for TypeScript which helps so much haha)

@xconverge
Copy link
Member

👍 ignore that travisbuddy warning, I merged in the middle of a build

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants