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

Index fixes #1190

Merged
merged 9 commits into from
Mar 11, 2017
21 changes: 20 additions & 1 deletion src/actions/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1465,12 +1465,25 @@ class CommandInsertInSearchMode extends BaseCommand {
return vimState;
} else if (key === "<up>") {
const prevSearchList = vimState.globalState.searchStatePrevious!;

// Preincrement if on boundary to prevent seeing the same search index twice
if (vimState.globalState.searchStateIndex === vimState.globalState.searchStatePrevious.length - 1
&& searchState.searchString !== "") {
vimState.globalState.searchStateIndex -= 1;
}

if (prevSearchList[vimState.globalState.searchStateIndex] !== undefined) {
searchState.searchString = prevSearchList[vimState.globalState.searchStateIndex].searchString;
vimState.globalState.searchStateIndex -= 1;
}
} else if (key === "<down>") {
const prevSearchList = vimState.globalState.searchStatePrevious!;

// Preincrement if on boundary to prevent seeing the same search index twice
if (vimState.globalState.searchStateIndex === 0) {
Copy link
Member

Choose a reason for hiding this comment

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

How come we increment twice when we start at 0? I don't quite follow.

Copy link
Member Author

Choose a reason for hiding this comment

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

Otherwise index is 0 and you can press up and down alternating and never see a different result

vimState.globalState.searchStateIndex += 1;
}

if (prevSearchList[vimState.globalState.searchStateIndex] !== undefined) {
searchState.searchString = prevSearchList[vimState.globalState.searchStateIndex].searchString;
vimState.globalState.searchStateIndex += 1;
Expand Down Expand Up @@ -2917,7 +2930,13 @@ class CommandGoForwardInChangelist extends BaseCommand {
keys = ["g", ","];

public async exec(position: Position, vimState: VimState): Promise<VimState> {
const originalIndex = vimState.historyTracker.changelistIndex;
let originalIndex = vimState.historyTracker.changelistIndex;

// Preincrement if on boundary to prevent seeing the same index twice
if (originalIndex === 1) {
originalIndex += 1;
}

const nextPos = vimState.historyTracker.getChangePositionAtindex(originalIndex);

if (nextPos !== undefined) {
Expand Down
6 changes: 6 additions & 0 deletions src/history/historyTracker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import * as _ from "lodash";
import { Position } from './../motion/position';
import { TextEditor } from './../textEditor';
import { RecordedState } from './../mode/modeHandler';
import { Configuration } from './../configuration/configuration';

import DiffMatchPatch = require("diff-match-patch");

Expand Down Expand Up @@ -399,6 +400,11 @@ export class HistoryTracker {

this.currentHistoryStep.changes.push(change);

// Make sure history length does not exceed configuration option
if (this.currentHistoryStep.changes.length > Configuration.history) {
this.currentHistoryStep.changes.splice(0, 1);
}

if (change && this.currentHistoryStep.cursorStart === undefined) {
this.currentHistoryStep.cursorStart = cursorPosition;
}
Expand Down
5 changes: 5 additions & 0 deletions src/motion/position.ts
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,11 @@ export class Position extends vscode.Position {
return this.getLeft();
}

// First char on first line, can not go left any more
if (this.line === 0) {
return this;
}

return this.getUp(0).getLineEnd();
}

Expand Down