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

Word in visual mode #385

Merged
merged 13 commits into from
Jul 23, 2016
Merged

Word in visual mode #385

merged 13 commits into from
Jul 23, 2016

Conversation

rebornix
Copy link
Member

@rebornix rebornix commented Jul 4, 2016

  1. Enrich aw with executeWithOperator and executeWithCount
  2. Add aW
  3. Enrich iw
  4. Add iW
  5. Normal/Visual mode test cases.

@@ -5,9 +5,14 @@ import { ModeHandler } from '../../src/mode/modeHandler';
import { setupWorkspace, cleanUpWorkspace, assertEqualLines, assertEqual } from './../testUtils';
import { ModeName } from '../../src/mode/mode';
import { TextEditor } from '../../src/textEditor';
import { getTestingFunctions } from '../testSimplifier';
Copy link
Member

Choose a reason for hiding this comment

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

Thanks! I need to change the other tests at some point...

Copy link
Member Author

Choose a reason for hiding this comment

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

Oh we can do this step by step. Each time we add new test cases to old ones, we can do the tweaking at the same time.

@rebornix
Copy link
Member Author

rebornix commented Jul 5, 2016

Add logic for iw and iW.

Just like I mentioned above, selecting words, sentences, paragraphs, etc all share the same executeWithCount that we use in MovementAWordTextObject. It's different from BaseMovement#execActionWithCount.

In summary, BaseMovement#execActionWithCount is returning a movement, which tells us how cursor moves from old position to new position. While MovementAWordTextObject#executeWithCount is returning a selection, which tells us which range (start and stop) should we operate on. IMovement is not an ideal name for this situation IMHO.

@rebornix rebornix force-pushed the WordInVisualMode branch 2 times, most recently from 51c281d to 5b889b2 Compare July 5, 2016 13:08
@rebornix
Copy link
Member Author

rebornix commented Jul 5, 2016

Just realize that IMovement is for selection. The funny thing is the IMovement part of BaseMovement#execActionWithCount is never being called (actually I don't know what kind of movement will use original logic). So I just moved my execActionWithCount into it.

@rebornix
Copy link
Member Author

Update and fix conflicts

let result: Position | IMovement = new Position(0, 0); // bogus init to satisfy typechecker
=======
Copy link
Member

Choose a reason for hiding this comment

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

There are still some merge conflicts here.

@johnfn
Copy link
Member

johnfn commented Jul 12, 2016

Sorry, I've left this hanging for too long. Can you explain what you did? Just add counts for aw iw?

@rebornix
Copy link
Member Author

The first thing I did is fixing aw and iw with count and then add aW, iW, the Big Word feature.

@@ -171,7 +171,12 @@ export abstract class BaseMovement extends BaseAction {
*/
public async execActionWithCount(position: Position, vimState: VimState, count: number): Promise<Position | IMovement> {
let recordedState = vimState.recordedState;
let result: Position | IMovement = new Position(0, 0); // bogus init to satisfy typechecker
let resultPosition: Position = new Position(0, 0);
Copy link
Member

Choose a reason for hiding this comment

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

Isn't resultPosition the exact same thing as position?

@rebornix
Copy link
Member Author

Fix the comment by @johnfn , I was doing wrong with Union Type but now turned around.

if (lastIteration) {
(result as IMovement).stop = temporaryResult.stop;
} else {
position = temporaryResult.stop.getRightThroughLineBreaks();
Copy link
Member

Choose a reason for hiding this comment

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

This getRight concerns me. Why is it necessary?

Copy link
Member Author

Choose a reason for hiding this comment

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

yup, it's necessary for IMovment. This is also why the logic of IMovement and Position is totally different.

When we run a single movement without an operator, like w, we want to move cursor to the beginning of next word. While if we run a single movement with an operator, like aw, we want to move the end cursor to the end of current word (aka, the left-side character of the beginning of next word). Then we sucessfully get a selection of the whole word.

Above is about single movement w/ operator. Then if we run movements with an operator multple times, like 2aw, after running the first aw, the end of seletion or the cursor is at the end of first word. As we need to include next following word into the selection, we need to pass the position of the begining of next word to aw command, then we can get the correct end position of the second aw. Lastly, we combine the beginning of first word and the end of last word and return the result selection.

Like I mentioned before, Movement (contains a start and a stop) is likely a selection. When executing selection with numeric prefix, I think we always need to move cursor to next character of the end of current selection.

@johnfn
Copy link
Member

johnfn commented Jul 16, 2016

Just want to hear back on my 2 comments and we should be good to merge!

@rebornix rebornix mentioned this pull request Jul 17, 2016
7 tasks
@rebornix
Copy link
Member Author

@johnfn rebased code and replied to your comments :)

@rebornix
Copy link
Member Author

Rebase again to resolve conflicts.

@johnfn johnfn merged commit 6c25501 into VSCodeVim:master Jul 23, 2016
@johnfn
Copy link
Member

johnfn commented Jul 23, 2016

Woo finally! Sorry for taking so long, and thanks @rebornix!

@rebornix rebornix deleted the WordInVisualMode branch July 23, 2016 15:20
This pull request was closed.
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.

2 participants