-
-
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
Fix replace in visual, visual line, and visual block mode #953
Conversation
@@ -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 }> { |
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.
I have a feeling this exists somehow already?
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.
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; |
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.
This is updating cursor positions correctly for visual line mode
…le iterating over every character, it was very slow.
canBeRepeatedWithDot = true; | ||
|
||
public async exec(position: Position, vimState: VimState): Promise<VimState> { | ||
const toInsert = this.keysPressed[1]; |
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.
redundant spaces.
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.
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) |
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.
I think we have start.isBeforeOrEqual(end)
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.
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; |
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.
you may like the syntax sugar [start, end] = [end, start]
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.
Ah dang, @johnfn guided me to this within the past month... will do
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.
fixed
Fix test for visual line with typo Pull request feedback incorporated.
Should be good to go now thanks for the EOL find @Platzer |
Any feedback on better ways of doing any of this?
an IterateSelection position functionselective replace transforms in chunks