Skip to content

Commit

Permalink
Improved performance of visual block replace by a lot (#997)
Browse files Browse the repository at this point in the history
  • Loading branch information
xconverge authored and johnfn committed Oct 27, 2016
1 parent 88e9077 commit e473341
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 15 deletions.
22 changes: 8 additions & 14 deletions src/actions/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3920,24 +3920,18 @@ class ActionReplaceCharacterVisualBlock extends BaseCommand {

public async exec(position: Position, vimState: VimState): Promise<VimState> {
const toInsert = this.keysPressed[1];
let textAtPos = "";
let newText = "";
for (const { pos } of Position.IterateBlock(vimState.topLeft, vimState.bottomRight)) {

textAtPos = TextEditor.getText(new vscode.Range(pos, pos.getRight()));
newText = toInsert;
for (const { start, end } of Position.IterateLine(vimState)) {

// If no character at this position, do not replace with anything
if (textAtPos === "") {
newText = "";
if (end.isBeforeOrEqual(start)) {
continue;
}

vimState.recordedState.transformations.push({
type : "replaceText",
text : newText,
start : pos,
end : pos.getRight(),
manuallySetCursorPositions : true
type: "replaceText",
text: Array(end.character - start.character + 1).join(toInsert),
start: start,
end: end,
manuallySetCursorPositions: true
});
}

Expand Down
2 changes: 1 addition & 1 deletion src/motion/position.ts
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ export class Position extends vscode.Position {

for (let lineIndex = itrStart; reverse ? lineIndex >= itrEnd : lineIndex <= itrEnd; reverse ? lineIndex-- : lineIndex++) {
const line = TextEditor.getLineAt(new Position(lineIndex, 0)).text;
const endCharacter = runToLineEnd ? line.length + 1 : bottomRight.character + 1;
const endCharacter = runToLineEnd ? line.length + 1 : Math.min(line.length, bottomRight.character + 1);

yield {
line : line.substring(topLeft.character, endCharacter),
Expand Down

0 comments on commit e473341

Please sign in to comment.