Skip to content

Commit

Permalink
Merge pull request #2867 from xmbhasin/improve-foldfix
Browse files Browse the repository at this point in the history
Improve foldfix performance and potentially fix some bugs(#1855 #2163)
  • Loading branch information
xconverge authored Jul 23, 2018
2 parents 4e1865c + 71f5e4e commit 9cff13d
Showing 1 changed file with 30 additions and 29 deletions.
59 changes: 30 additions & 29 deletions src/actions/motion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -261,25 +261,33 @@ class MoveDownFoldFix extends MoveByScreenLineMaintainDesiredColumn {
value = 1;

public async execAction(position: Position, vimState: VimState): Promise<Position | IMovement> {
if (position.line === TextEditor.getLineCount() - 1) {
if (position.line >= TextEditor.getLineCount() - 1) {
return position;
}
let t: Position;
let count = 0;
let t: Position | IMovement;
let prevLine: number = position.line;
let prevChar: number = position.character;
const prevDesiredColumn = vimState.desiredColumn;
const moveDownByScreenLine = new MoveDownByScreenLine();
do {
t = <Position>await new MoveDownByScreenLine().execAction(position, vimState);
count += 1;
t = <Position | IMovement>await moveDownByScreenLine.execAction(position, vimState);
t = t instanceof Position ? t : t.stop;
const lineChanged = prevLine !== t.line;
// wrappedLine movement goes to eol character only when at the last line
// thus a column change on wrappedLine movement represents a visual last line
const colChanged = prevChar !== t.character;
if (lineChanged || !colChanged) {
break;
}
prevChar = t.character;
prevLine = t.line;
} while (t.line === position.line);
if (t.line > position.line + 1) {
return t;
}
while (count > 0) {
t = <Position>await new MoveUpByScreenLine().execAction(position, vimState);
count--;
// fix column change at last line caused by wrappedLine movement
// causes cursor lag and flicker if a large repeat prefix is given to movement
if (t.character !== prevDesiredColumn) {
t = new Position(t.line, prevDesiredColumn);
}
vimState.desiredColumn = prevDesiredColumn;
return await position.getDown(vimState.desiredColumn);
return t;
}
}

Expand Down Expand Up @@ -340,26 +348,19 @@ class MoveUpFoldFix extends MoveByScreenLineMaintainDesiredColumn {
if (position.line === 0) {
return position;
}
let t: Position;
let t: Position | IMovement;
const prevDesiredColumn = vimState.desiredColumn;
let count = 0;

const moveUpByScreenLine = new MoveUpByScreenLine();
do {
t = <Position>(
await new MoveUpByScreenLineMaintainDesiredColumn().execAction(position, vimState)
);
count += 1;
t = <Position | IMovement>await moveUpByScreenLine.execAction(position, vimState);
t = t instanceof Position ? t : t.stop;
} while (t.line === position.line);
vimState.desiredColumn = prevDesiredColumn;
if (t.line < position.line - 1) {
return t;
}
while (count > 0) {
t = <Position>await new MoveDownByScreenLine().execAction(position, vimState);
count--;
// fix column change at last line caused by wrappedLine movement
// causes cursor lag and flicker if a large repeat prefix is given to movement
if (t.character !== prevDesiredColumn) {
t = new Position(t.line, prevDesiredColumn);
}
vimState.desiredColumn = prevDesiredColumn;
return await position.getUp(vimState.desiredColumn);
return t;
}
}

Expand Down

0 comments on commit 9cff13d

Please sign in to comment.