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

Fix replace in visual, visual line, and visual block mode #953

Merged
merged 8 commits into from
Oct 25, 2016
Merged

Fix replace in visual, visual line, and visual block mode #953

merged 8 commits into from
Oct 25, 2016

Conversation

xconverge
Copy link
Member

@xconverge xconverge commented Oct 20, 2016

Any feedback on better ways of doing any of this?

  1. Visual block mode returns correctly after running "r" instead of having a few cursors left around
  2. Replace does not replace unless there is a character, this applies to line, block, and regular visual
  3. Replace added to visual and visual line with an IterateSelection position function selective replace transforms in chunks

@@ -192,6 +192,41 @@ export class Position extends vscode.Position {
}

/**
* Iterate over every position in the selection defined by the two positions passed in.
*/
public static *IterateSelection(topLeft: Position, bottomRight: Position): Iterable<{ line: string, char: string, pos: Position }> {
Copy link
Member Author

Choose a reason for hiding this comment

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

I have a feeling this exists somehow already?

Copy link
Member Author

Choose a reason for hiding this comment

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

I am not using it anymore but I will leave it since it seems handy

@@ -1366,6 +1366,9 @@ export class ModeHandler implements vscode.Disposable {
Position.EarlierOf(start, stop).getLineBegin(),
Position.LaterOf(start, stop).getLineEnd()
) ];
vimState.cursorStartPosition = selections[0].start as Position;
Copy link
Member Author

@xconverge xconverge Oct 20, 2016

Choose a reason for hiding this comment

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

This is updating cursor positions correctly for visual line mode

@xconverge xconverge changed the title [WIP] Fix replace in visual, visual line, and visual block mode Fix replace in visual, visual line, and visual block mode Oct 20, 2016
canBeRepeatedWithDot = true;

public async exec(position: Position, vimState: VimState): Promise<VimState> {
const toInsert = this.keysPressed[1];
Copy link
Member

Choose a reason for hiding this comment

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

redundant spaces.

Copy link
Member Author

Choose a reason for hiding this comment

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

fixed

let end = vimState.cursorPosition;

// If selection is reversed, reorganize it so that the text replace logic always works
if (start.line > end.line || ((start.line === end.line)
Copy link
Member

Choose a reason for hiding this comment

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

I think we have start.isBeforeOrEqual(end)

Copy link
Member Author

Choose a reason for hiding this comment

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

fixed

// If selection is reversed, reorganize it so that the text replace logic always works
if (start.line > end.line || ((start.line === end.line)
&& (start.character > end.character))) {
let tmp = start;
Copy link
Member

Choose a reason for hiding this comment

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

you may like the syntax sugar [start, end] = [end, start]

Copy link
Member Author

Choose a reason for hiding this comment

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

Ah dang, @johnfn guided me to this within the past month... will do

Copy link
Member Author

Choose a reason for hiding this comment

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

fixed

jpoon and others added 3 commits October 25, 2016 11:36
Fix test for visual line with typo
Pull request feedback incorporated.
@xconverge
Copy link
Member Author

Should be good to go now

thanks for the EOL find @Platzer

@rebornix rebornix merged commit 60e7ea1 into VSCodeVim:master Oct 25, 2016
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.

3 participants