From 4406a3fb0e6ef03a5d52fbde4719f2afbfd472ed Mon Sep 17 00:00:00 2001 From: Horace He Date: Sat, 22 Apr 2017 23:36:13 -0400 Subject: [PATCH 1/5] Added potential strategy for foldfix --- src/actions/motion.ts | 162 +++++++++++++++++++++++++++++------------- 1 file changed, 114 insertions(+), 48 deletions(-) diff --git a/src/actions/motion.ts b/src/actions/motion.ts index ecc8865b68e..949a5e24cc9 100644 --- a/src/actions/motion.ts +++ b/src/actions/motion.ts @@ -140,6 +140,114 @@ export abstract class BaseMovement extends BaseAction { } } +abstract class MoveByScreenLineMaintainDesiredColumn extends MoveByScreenLine { + doesntChangeDesiredColumn = true; + public async execAction(position: Position, vimState: VimState): Promise < Position | IMovement > { + let prevDesiredColumn = vimState.desiredColumn; + let prevLine = vimState.editor.selection.active.line; + + await vscode.commands.executeCommand("cursorMove", { + to: this.movementType, + select: vimState.currentMode !== ModeName.Normal, + by: this.by, + value: this.value + }); + + if (vimState.currentMode === ModeName.Normal) { + let returnedPos = Position.FromVSCodePosition(vimState.editor.selection.active); + if (prevLine !== returnedPos.line) { + returnedPos = returnedPos.setLocation(returnedPos.line, prevDesiredColumn); + } + return returnedPos; + } else { + /** + * cursorMove command is handling the selection for us. + * So we are not following our design principal (do no real movement inside an action) here. + */ + + let start = Position.FromVSCodePosition(vimState.editor.selection.start); + let stop = Position.FromVSCodePosition(vimState.editor.selection.end); + + // We want to swap the cursor start stop positions based on which direction we are moving, up or down + if (start.line < position.line) { + [start, stop] = [stop, start]; + } + if (prevLine !== start.line) { + start = start.setLocation(start.line, prevDesiredColumn); + } + + return { start, stop }; + } + } +} + + + @RegisterAction +class MoveDown extends MoveByScreenLineMaintainDesiredColumn { + modes = [ModeName.Insert, ModeName.Normal, ModeName.Visual, ModeName.VisualLine]; + keys = [["j"]]; + movementType: CursorMovePosition = "down"; + by: CursorMoveByUnit = "line"; + value = 1; + doesntChangeDesiredColumn = true; + + public async execAction(position: Position, vimState: VimState): Promise < Position | IMovement > { + let t: Position; + let count = 0; + do { + t = (await new MoveDownByScreenLine().execAction(position, vimState)); + count= 1; + } while (t.line === position.line); + if (t.line > position.line) { + return t; + } + while (count > 0) { + await new MoveUpByScreenLine().execAction(position, vimState); + count--; + } + return await super.execAction(position, vimState); + } +} + + @RegisterAction +class MoveDownArrow extends MoveDown { + modes = [ModeName.Normal, ModeName.Visual, ModeName.VisualLine, ModeName.VisualBlock]; + keys = [[""]]; +} + + @RegisterAction +class MoveUp extends MoveByScreenLineMaintainDesiredColumn { + modes = [ModeName.Insert, ModeName.Normal, ModeName.Visual, ModeName.VisualLine]; + keys = [["k"]]; + movementType: CursorMovePosition = "up"; + by: CursorMoveByUnit = "line"; + value = 1; + doesntChangeDesiredColumn = true; + + public async execAction(position: Position, vimState: VimState): Promise < Position | IMovement > { + let t: Position; + + let count = 0; + do { + t = (await new MoveUpByScreenLine().execAction(position, vimState)); + count= 1; + } while (t.line === position.line); + if (t.line < position.line) { + return t; + } + while (count > 0) { + await new MoveDownByScreenLine().execAction(position, vimState); + count--; + } + return await super.execAction(position, vimState); + } +} + + @RegisterAction +class MoveUpArrow extends MoveDown { + modes = [ModeName.Normal, ModeName.Visual, ModeName.VisualLine, ModeName.VisualBlock]; + keys = [[""]]; +} @RegisterAction class ArrowsInReplaceMode extends BaseMovement { @@ -156,10 +264,10 @@ class ArrowsInReplaceMode extends BaseMovement { switch (this.keysPressed[0]) { case "": - newPosition = await new MoveUpArrow().execAction(position, vimState); + newPosition = (await new MoveUpArrow().execAction(position, vimState)); break; case "": - newPosition = await new MoveDownArrow().execAction(position, vimState); + newPosition = (await new MoveDownArrow().execAction(position, vimState)); break; case "": newPosition = await new MoveLeftArrow().execAction(position, vimState); @@ -288,48 +396,6 @@ class BackSpaceInNormalMode extends BaseMovement { } } -@RegisterAction -class MoveUp extends BaseMovement { - keys = ["k"]; - doesntChangeDesiredColumn = true; - - public async execAction(position: Position, vimState: VimState): Promise { - return position.getUp(vimState.desiredColumn); - } - - public async execActionForOperator(position: Position, vimState: VimState): Promise { - vimState.currentRegisterMode = RegisterMode.LineWise; - return position.getUp(position.getLineEnd().character); - } -} - -@RegisterAction -class MoveUpArrow extends MoveUp { - modes = [ModeName.Normal, ModeName.Visual, ModeName.VisualLine, ModeName.VisualBlock]; - keys = [""]; -} - -@RegisterAction -class MoveDown extends BaseMovement { - keys = ["j"]; - doesntChangeDesiredColumn = true; - - public async execAction(position: Position, vimState: VimState): Promise { - return position.getDown(vimState.desiredColumn); - } - - public async execActionForOperator(position: Position, vimState: VimState): Promise { - vimState.currentRegisterMode = RegisterMode.LineWise; - return position.getDown(position.getLineEnd().character); - } -} - -@RegisterAction -class MoveDownArrow extends MoveDown { - modes = [ModeName.Normal, ModeName.Visual, ModeName.VisualLine, ModeName.VisualBlock]; - keys = [""]; -} - @RegisterAction class MoveRight extends BaseMovement { keys = ["l"]; @@ -668,7 +734,7 @@ class MoveScreenLineCenter extends MoveByScreenLine { } @RegisterAction -class MoveUpByScreenLine extends MoveByScreenLine { +class MoveUpByScreenLine extends MoveByScreenLineMaintainDesiredColumn { modes = [ModeName.Insert, ModeName.Normal, ModeName.Visual]; keys = [["g", "k"], ["g", ""]]; @@ -678,7 +744,7 @@ class MoveUpByScreenLine extends MoveByScreenLine { } @RegisterAction -class MoveDownByScreenLine extends MoveByScreenLine { +class MoveDownByScreenLine extends MoveByScreenLineMaintainDesiredColumn { modes = [ModeName.Insert, ModeName.Normal, ModeName.Visual]; keys = [["g", "j"], ["g", ""]]; @@ -1703,10 +1769,10 @@ export class ArrowsInInsertMode extends BaseMovement { switch (this.keys[0]) { case "": - newPosition = await new MoveUpArrow().execAction(position, vimState); + newPosition = (await new MoveUpArrow().execAction(position, vimState)); break; case "": - newPosition = await new MoveDownArrow().execAction(position, vimState); + newPosition = (await new MoveDownArrow().execAction(position, vimState)); break; case "": newPosition = await new MoveLeftArrow().execAction(position, vimState); From 5a9f2f04d8d4f51a0bcccfaf9883234e6dfb3c57 Mon Sep 17 00:00:00 2001 From: Horace He Date: Mon, 15 May 2017 20:33:38 -0400 Subject: [PATCH 2/5] Added foldfix as option --- package.json | 5 + src/actions/base.ts | 6 +- src/actions/motion.ts | 362 ++++++++++++++++------------- src/configuration/configuration.ts | 5 + 4 files changed, 220 insertions(+), 158 deletions(-) diff --git a/package.json b/package.json index 8546e2c9937..ccdee9ff35a 100644 --- a/package.json +++ b/package.json @@ -475,6 +475,11 @@ "type": "boolean", "description": "In visual mode, start a search with * or # using the current selection", "default": false + }, + "vim.foldfix": { + "type": "boolean", + "description": "Uses a hack to move around folds properly", + "default": true } } } diff --git a/src/actions/base.ts b/src/actions/base.ts index ef91f1f5ae8..786c3847691 100644 --- a/src/actions/base.ts +++ b/src/actions/base.ts @@ -139,12 +139,16 @@ export class Actions { * * If no action could ever match, returns false. */ - public static getRelevantAction(keysPressed: string[], vimState: VimState): BaseAction | KeypressState { + public static getRelevantAction(keysPressed: string[], vimState: VimState): BaseAction |KeypressState { let couldPotentiallyHaveMatch = false; for (const thing of Actions.allActions) { const { type, action } = thing!; + // It's an action that can't be called directly. + if (action.keys === undefined) { + continue; + } if (action.doesActionApply(vimState, keysPressed)) { const result = new type(); diff --git a/src/actions/motion.ts b/src/actions/motion.ts index 949a5e24cc9..da8cda1dcab 100644 --- a/src/actions/motion.ts +++ b/src/actions/motion.ts @@ -1,6 +1,7 @@ import * as vscode from 'vscode'; import { ModeName } from './../mode/mode'; import { Position, PositionDiff } from './../common/motion/position'; +import { Configuration } from './../configuration/configuration'; import { TextEditor, CursorMovePosition, CursorMoveByUnit } from './../textEditor'; import { VimState } from './../mode/modeHandler'; import { RegisterMode } from './../register/register'; @@ -14,7 +15,7 @@ import { BaseAction } from './base'; export function isIMovement(o: IMovement | Position): o is IMovement { return (o as IMovement).start !== undefined && - (o as IMovement).stop !== undefined; + (o as IMovement).stop !== undefined; } /** @@ -42,10 +43,10 @@ export interface IMovement { */ export abstract class BaseMovement extends BaseAction { modes = [ - ModeName.Normal, - ModeName.Visual, - ModeName.VisualLine, - ModeName.VisualBlock, + ModeName.Normal, + ModeName.Visual, + ModeName.VisualLine, + ModeName.VisualBlock, ]; isMotion = true; @@ -107,8 +108,8 @@ export abstract class BaseMovement extends BaseAction { const firstIteration = (i === 0); const lastIteration = (i === count - 1); const temporaryResult = (recordedState.operator && lastIteration) ? - await this.execActionForOperator(position, vimState) : - await this.execAction(position, vimState); + await this.execActionForOperator(position, vimState) : + await this.execAction(position, vimState); if (temporaryResult instanceof Position) { result = temporaryResult; @@ -140,123 +141,220 @@ export abstract class BaseMovement extends BaseAction { } } +abstract class MoveByScreenLine extends BaseMovement { + modes = [ModeName.Normal, ModeName.Visual, ModeName.VisualLine]; + movementType: CursorMovePosition; + by: CursorMoveByUnit; + value: number = 1; + + public async execAction(position: Position, vimState: VimState): Promise { + await vscode.commands.executeCommand("cursorMove", { + to: this.movementType, + select: vimState.currentMode !== ModeName.Normal, + by: this.by, + value: this.value + }); + + if (vimState.currentMode === ModeName.Normal) { + return Position.FromVSCodePosition(vimState.editor.selection.active); + } else { + /** + * cursorMove command is handling the selection for us. + * So we are not following our design principal (do no real movement inside an action) here. + */ + let start = Position.FromVSCodePosition(vimState.editor.selection.start); + let stop = Position.FromVSCodePosition(vimState.editor.selection.end); + let curPos = Position.FromVSCodePosition(vimState.editor.selection.active); + + // We want to swap the cursor start stop positions based on which direction we are moving, up or down + if (start.isEqual(curPos)) { + position = start; + [start, stop] = [stop, start]; + start = start.getLeft(); + } + + return { start, stop }; + } + } + + public async execActionForOperator(position: Position, vimState: VimState): Promise { + await vscode.commands.executeCommand("cursorMove", { + to: this.movementType, + select: true, + by: this.by, + value: this.value + }); + + return { + start: Position.FromVSCodePosition(vimState.editor.selection.start), + stop: Position.FromVSCodePosition(vimState.editor.selection.end) + }; + } +} + abstract class MoveByScreenLineMaintainDesiredColumn extends MoveByScreenLine { doesntChangeDesiredColumn = true; public async execAction(position: Position, vimState: VimState): Promise < Position | IMovement > { let prevDesiredColumn = vimState.desiredColumn; let prevLine = vimState.editor.selection.active.line; - await vscode.commands.executeCommand("cursorMove", { + await vscode.commands.executeCommand("cursorMove", { to: this.movementType, - select: vimState.currentMode !== ModeName.Normal, - by: this.by, - value: this.value - }); - - if (vimState.currentMode === ModeName.Normal) { - let returnedPos = Position.FromVSCodePosition(vimState.editor.selection.active); - if (prevLine !== returnedPos.line) { - returnedPos = returnedPos.setLocation(returnedPos.line, prevDesiredColumn); - } - return returnedPos; - } else { - /** + select: vimState.currentMode !== ModeName.Normal, + by: this.by, + value: this.value + }); + + if (vimState.currentMode === ModeName.Normal) { + let returnedPos = Position.FromVSCodePosition(vimState.editor.selection.active); + if (prevLine !== returnedPos.line) { + returnedPos = returnedPos.setLocation(returnedPos.line, prevDesiredColumn); + } + return returnedPos; + } else { + /** * cursorMove command is handling the selection for us. * So we are not following our design principal (do no real movement inside an action) here. */ + let start = Position.FromVSCodePosition(vimState.editor.selection.start); + let stop = Position.FromVSCodePosition(vimState.editor.selection.end); + let curPos = Position.FromVSCodePosition(vimState.editor.selection.active); - let start = Position.FromVSCodePosition(vimState.editor.selection.start); - let stop = Position.FromVSCodePosition(vimState.editor.selection.end); + // We want to swap the cursor start stop positions based on which direction we are moving, up or down + if (start.isEqual(curPos)) { + position = start; + [start, stop] = [stop, start]; + start = start.getLeft(); + } - // We want to swap the cursor start stop positions based on which direction we are moving, up or down - if (start.line < position.line) { - [start, stop] = [stop, start]; - } - if (prevLine !== start.line) { - start = start.setLocation(start.line, prevDesiredColumn); - } + return { start, stop }; - return { start, stop }; - } + } } } +class MoveDownByScreenLineMaintainDesiredColumn extends MoveByScreenLineMaintainDesiredColumn { + movementType: CursorMovePosition = "down"; + by: CursorMoveByUnit = "wrappedLine"; + value = 1; +} - @RegisterAction -class MoveDown extends MoveByScreenLineMaintainDesiredColumn { - modes = [ModeName.Insert, ModeName.Normal, ModeName.Visual, ModeName.VisualLine]; - keys = [["j"]]; +class MoveDownFoldFix extends MoveByScreenLineMaintainDesiredColumn { movementType: CursorMovePosition = "down"; by: CursorMoveByUnit = "line"; value = 1; - doesntChangeDesiredColumn = true; - public async execAction(position: Position, vimState: VimState): Promise < Position | IMovement > { + public async execAction(position: Position, vimState: VimState): Promise < Position | IMovement > { + if (position.line === TextEditor.getLineCount() - 1) { + return position; + } let t: Position; let count = 0; do { - t = (await new MoveDownByScreenLine().execAction(position, vimState)); - count= 1; - } while (t.line === position.line); - if (t.line > position.line) { - return t; - } + t = (await new MoveDownByScreenLineMaintainDesiredColumn().execAction(position, vimState)); + count = 1; + } while (t.line === position.line); + if (t.line > position.line + 1) { + return t; + } while (count > 0) { - await new MoveUpByScreenLine().execAction(position, vimState); - count--; - } + await new MoveUpByScreenLine().execAction(position, vimState); + count--; + } return await super.execAction(position, vimState); } } - @RegisterAction +@RegisterAction +class MoveDown extends BaseMovement { + keys = ["j"]; + doesntChangeDesiredColumn = true; + + + public async execAction(position: Position, vimState: VimState): Promise { + if (Configuration.foldfix && vimState.currentMode !== ModeName.VisualBlock) { + return new MoveDownFoldFix().execAction(position, vimState); + } + return position.getDown(vimState.desiredColumn); + } + + public async execActionForOperator(position: Position, vimState: VimState): Promise { + vimState.currentRegisterMode = RegisterMode.LineWise; + return position.getDown(position.getLineEnd().character); + } + +} + +@RegisterAction class MoveDownArrow extends MoveDown { - modes = [ModeName.Normal, ModeName.Visual, ModeName.VisualLine, ModeName.VisualBlock]; - keys = [[""]]; + keys = [""]; } - @RegisterAction -class MoveUp extends MoveByScreenLineMaintainDesiredColumn { - modes = [ModeName.Insert, ModeName.Normal, ModeName.Visual, ModeName.VisualLine]; - keys = [["k"]]; +class MoveUpByScreenLineMaintainDesiredColumn extends MoveByScreenLineMaintainDesiredColumn { movementType: CursorMovePosition = "up"; - by: CursorMoveByUnit = "line"; + by: CursorMoveByUnit = "wrappedLine"; value = 1; +} + +@RegisterAction +class MoveUp extends BaseMovement { + keys = ["k"]; doesntChangeDesiredColumn = true; - public async execAction(position: Position, vimState: VimState): Promise < Position | IMovement > { + public async execAction(position: Position, vimState: VimState): Promise { + if (Configuration.foldfix && vimState.currentMode !== ModeName.VisualBlock) { + return new MoveUpFoldFix().execAction(position, vimState); + } + return position.getUp(vimState.desiredColumn); + } + + public async execActionForOperator(position: Position, vimState: VimState): Promise { + vimState.currentRegisterMode = RegisterMode.LineWise; + return position.getUp(position.getLineEnd().character); + } +} + +@RegisterAction +class MoveUpFoldFix extends MoveByScreenLineMaintainDesiredColumn { + movementType: CursorMovePosition = "up"; + by: CursorMoveByUnit = "line"; + value = 1; + + public async execAction(position: Position, vimState: VimState): Promise < Position | IMovement > { + if (position.line === 0) { + return position; + } let t: Position; - let count = 0; + let count = 0; do { - t = (await new MoveUpByScreenLine().execAction(position, vimState)); - count= 1; - } while (t.line === position.line); - if (t.line < position.line) { - return t; - } + t = (await new MoveUpByScreenLineMaintainDesiredColumn().execAction(position, vimState)); + count = 1; + } while (t.line === position.line); + if (t.line < position.line - 1) { + return t; + } while (count > 0) { - await new MoveDownByScreenLine().execAction(position, vimState); - count--; - } + await new MoveDownByScreenLine().execAction(position, vimState); + count--; + } return await super.execAction(position, vimState); } } - @RegisterAction -class MoveUpArrow extends MoveDown { - modes = [ModeName.Normal, ModeName.Visual, ModeName.VisualLine, ModeName.VisualBlock]; - keys = [[""]]; +@RegisterAction +class MoveUpArrow extends MoveUp { + keys = [""]; } @RegisterAction class ArrowsInReplaceMode extends BaseMovement { modes = [ModeName.Replace]; keys = [ - [""], - [""], - [""], - [""], + [""], + [""], + [""], + [""], ]; public async execAction(position: Position, vimState: VimState): Promise { @@ -264,19 +362,19 @@ class ArrowsInReplaceMode extends BaseMovement { switch (this.keysPressed[0]) { case "": - newPosition = (await new MoveUpArrow().execAction(position, vimState)); - break; + newPosition = (await new MoveUpArrow().execAction(position, vimState)); + break; case "": - newPosition = (await new MoveDownArrow().execAction(position, vimState)); - break; + newPosition = (await new MoveDownArrow().execAction(position, vimState)); + break; case "": - newPosition = await new MoveLeftArrow().execAction(position, vimState); - break; + newPosition = await new MoveLeftArrow().execAction(position, vimState); + break; case "": - newPosition = await new MoveRightArrow().execAction(position, vimState); - break; + newPosition = await new MoveRightArrow().execAction(position, vimState); + break; default: - break; + break; } vimState.replaceState = new ReplaceState(newPosition); return newPosition; @@ -427,7 +525,7 @@ class MoveDownNonBlank extends BaseMovement { public async execActionWithCount(position: Position, vimState: VimState, count: number): Promise { return position.getDownByCount(Math.max(count, 1)) - .getFirstLineNonBlankChar(); + .getFirstLineNonBlankChar(); } } @@ -437,7 +535,7 @@ class MoveUpNonBlank extends BaseMovement { public async execActionWithCount(position: Position, vimState: VimState, count: number): Promise { return position.getUpByCount(Math.max(count, 1)) - .getFirstLineNonBlankChar(); + .getFirstLineNonBlankChar(); } } @@ -447,7 +545,7 @@ class MoveDownUnderscore extends BaseMovement { public async execActionWithCount(position: Position, vimState: VimState, count: number): Promise { return position.getDownByCount(Math.max(count - 1, 0)) - .getFirstLineNonBlankChar(); + .getFirstLineNonBlankChar(); } } @@ -579,10 +677,10 @@ class MoveRepeat extends BaseMovement { class MoveRepeatReversed extends BaseMovement { keys = [","]; static reverseMotionMapping: Map BaseMovement> = new Map([ - [MoveFindForward, () => new MoveFindBackward()], - [MoveFindBackward, () => new MoveFindForward()], - [MoveTilForward, () => new MoveTilBackward()], - [MoveTilBackward, () => new MoveTilForward()] + [MoveFindForward, () => new MoveFindBackward()], + [MoveFindBackward, () => new MoveFindForward()], + [MoveTilForward, () => new MoveTilBackward()], + [MoveTilBackward, () => new MoveTilForward()] ]); public async execActionWithCount(position: Position, vimState: VimState, count: number): Promise { @@ -605,9 +703,9 @@ class MoveRepeatReversed extends BaseMovement { @RegisterAction class MoveLineEnd extends BaseMovement { keys = [ - ["$"], - [""], - [""]]; + ["$"], + [""], + [""]]; setsDesiredColumnToEOL = true; public async execAction(position: Position, vimState: VimState): Promise { @@ -627,65 +725,15 @@ class MoveLineBegin extends BaseMovement { public doesActionApply(vimState: VimState, keysPressed: string[]): boolean { return super.doesActionApply(vimState, keysPressed) && - vimState.recordedState.count === 0; + vimState.recordedState.count === 0; } public couldActionApply(vimState: VimState, keysPressed: string[]): boolean { return super.couldActionApply(vimState, keysPressed) && - vimState.recordedState.count === 0; + vimState.recordedState.count === 0; } } -abstract class MoveByScreenLine extends BaseMovement { - modes = [ModeName.Normal, ModeName.Visual, ModeName.VisualLine]; - movementType: CursorMovePosition; - by: CursorMoveByUnit; - value: number = 1; - - public async execAction(position: Position, vimState: VimState): Promise { - await vscode.commands.executeCommand("cursorMove", { - to: this.movementType, - select: vimState.currentMode !== ModeName.Normal, - by: this.by, - value: this.value - }); - - if (vimState.currentMode === ModeName.Normal) { - return Position.FromVSCodePosition(vimState.editor.selection.active); - } else { - /** - * cursorMove command is handling the selection for us. - * So we are not following our design principal (do no real movement inside an action) here. - */ - let start = Position.FromVSCodePosition(vimState.editor.selection.start); - let stop = Position.FromVSCodePosition(vimState.editor.selection.end); - let curPos = Position.FromVSCodePosition(vimState.editor.selection.active); - - // We want to swap the cursor start stop positions based on which direction we are moving, up or down - if (start.isEqual(curPos)) { - position = start; - [start, stop] = [stop, start]; - start = start.getLeft(); - } - - return { start, stop }; - } - } - - public async execActionForOperator(position: Position, vimState: VimState): Promise { - await vscode.commands.executeCommand("cursorMove", { - to: this.movementType, - select: true, - by: this.by, - value: this.value - }); - - return { - start: Position.FromVSCodePosition(vimState.editor.selection.start), - stop: Position.FromVSCodePosition(vimState.editor.selection.end) - }; - } -} @RegisterAction class MoveScreenLineBegin extends MoveByScreenLine { @@ -734,7 +782,7 @@ class MoveScreenLineCenter extends MoveByScreenLine { } @RegisterAction -class MoveUpByScreenLine extends MoveByScreenLineMaintainDesiredColumn { +class MoveUpByScreenLine extends MoveByScreenLine { modes = [ModeName.Insert, ModeName.Normal, ModeName.Visual]; keys = [["g", "k"], ["g", ""]]; @@ -744,7 +792,7 @@ class MoveUpByScreenLine extends MoveByScreenLineMaintainDesiredColumn { } @RegisterAction -class MoveDownByScreenLine extends MoveByScreenLineMaintainDesiredColumn { +class MoveDownByScreenLine extends MoveByScreenLine { modes = [ModeName.Insert, ModeName.Normal, ModeName.Visual]; keys = [["g", "j"], ["g", ""]]; @@ -957,7 +1005,7 @@ export class MoveWordBegin extends BaseMovement { } if (result.isLineEnd()) { - return new Position(result.line, result.character + 1); + return new Position(result.line, result.character + 1); } return result; @@ -1769,19 +1817,19 @@ export class ArrowsInInsertMode extends BaseMovement { switch (this.keys[0]) { case "": - newPosition = (await new MoveUpArrow().execAction(position, vimState)); - break; + newPosition = (await new MoveUpArrow().execAction(position, vimState)); + break; case "": - newPosition = (await new MoveDownArrow().execAction(position, vimState)); - break; + newPosition = (await new MoveDownArrow().execAction(position, vimState)); + break; case "": - newPosition = await new MoveLeftArrow().execAction(position, vimState); - break; + newPosition = await new MoveLeftArrow().execAction(position, vimState); + break; case "": - newPosition = await new MoveRightArrow().execAction(position, vimState); - break; + newPosition = await new MoveRightArrow().execAction(position, vimState); + break; default: - break; + break; } vimState.replaceState = new ReplaceState(newPosition); return newPosition; diff --git a/src/configuration/configuration.ts b/src/configuration/configuration.ts index 2d9b7803548..04b2ed34364 100644 --- a/src/configuration/configuration.ts +++ b/src/configuration/configuration.ts @@ -288,6 +288,11 @@ class ConfigurationClass { * In visual mode, start a search with * or # using the current selection */ visualstar = false; + + /** + * Uses a hack to fix moving around folds. + */ + foldfix = true; } function overlapSetting(args: { codeName: string, default: OptionValue, codeValueMapping?: ValueMapping }) { From 17b7708fedfc28bbc1fa6569fa3b19519b5daff3 Mon Sep 17 00:00:00 2001 From: Horace He Date: Tue, 16 May 2017 03:44:42 -0400 Subject: [PATCH 3/5] made small optimization hopefully this doesn't break tests --- src/actions/motion.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/actions/motion.ts b/src/actions/motion.ts index da8cda1dcab..b7913c81d86 100644 --- a/src/actions/motion.ts +++ b/src/actions/motion.ts @@ -254,7 +254,7 @@ class MoveDownFoldFix extends MoveByScreenLineMaintainDesiredColumn { t = (await new MoveDownByScreenLineMaintainDesiredColumn().execAction(position, vimState)); count = 1; } while (t.line === position.line); - if (t.line > position.line + 1) { + if (t.line > position.line) { return t; } while (count > 0) { @@ -331,7 +331,7 @@ class MoveUpFoldFix extends MoveByScreenLineMaintainDesiredColumn { t = (await new MoveUpByScreenLineMaintainDesiredColumn().execAction(position, vimState)); count = 1; } while (t.line === position.line); - if (t.line < position.line - 1) { + if (t.line < position.line) { return t; } while (count > 0) { From 90456624e45d5e7e897cfdc3c377399c54f9185a Mon Sep 17 00:00:00 2001 From: Horace He Date: Thu, 18 May 2017 23:19:33 -0400 Subject: [PATCH 4/5] made default for foldfix false --- package.json | 2 +- src/configuration/configuration.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 51572c09d77..af9bb98e637 100644 --- a/package.json +++ b/package.json @@ -479,7 +479,7 @@ "vim.foldfix": { "type": "boolean", "description": "Uses a hack to move around folds properly", - "default": true + "default": false } } } diff --git a/src/configuration/configuration.ts b/src/configuration/configuration.ts index 04b2ed34364..5662e862ea3 100644 --- a/src/configuration/configuration.ts +++ b/src/configuration/configuration.ts @@ -292,7 +292,7 @@ class ConfigurationClass { /** * Uses a hack to fix moving around folds. */ - foldfix = true; + foldfix = false; } function overlapSetting(args: { codeName: string, default: OptionValue, codeValueMapping?: ValueMapping }) { From efbcac2188bda5eb23550997c191065bc5d3f283 Mon Sep 17 00:00:00 2001 From: Horace He Date: Sat, 20 May 2017 19:06:00 -0400 Subject: [PATCH 5/5] fixed a dumb bug --- src/actions/motion.ts | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/src/actions/motion.ts b/src/actions/motion.ts index e14f1ddea8c..61bea693151 100644 --- a/src/actions/motion.ts +++ b/src/actions/motion.ts @@ -252,18 +252,20 @@ class MoveDownFoldFix extends MoveByScreenLineMaintainDesiredColumn { } let t: Position; let count = 0; + const prevDesiredColumn = vimState.desiredColumn; do { - t = (await new MoveDownByScreenLineMaintainDesiredColumn().execAction(position, vimState)); - count = 1; + t = (await new MoveDownByScreenLine().execAction(position, vimState)); + count += 1; } while (t.line === position.line); - if (t.line > position.line) { + if (t.line > position.line + 1) { return t; } while (count > 0) { - await new MoveUpByScreenLine().execAction(position, vimState); + t = await new MoveUpByScreenLine().execAction(position, vimState); count--; } - return await super.execAction(position, vimState); + vimState.desiredColumn = prevDesiredColumn; + return await position.getDown(vimState.desiredColumn); } } @@ -327,20 +329,23 @@ class MoveUpFoldFix extends MoveByScreenLineMaintainDesiredColumn { return position; } let t: Position; - + const prevDesiredColumn = vimState.desiredColumn; let count = 0; + do { t = (await new MoveUpByScreenLineMaintainDesiredColumn().execAction(position, vimState)); - count = 1; + count += 1; } while (t.line === position.line); - if (t.line < position.line) { + vimState.desiredColumn = prevDesiredColumn; + if (t.line < position.line - 1) { return t; } while (count > 0) { - await new MoveDownByScreenLine().execAction(position, vimState); + t = await new MoveDownByScreenLine().execAction(position, vimState); count--; } - return await super.execAction(position, vimState); + vimState.desiredColumn = prevDesiredColumn; + return await position.getUp(vimState.desiredColumn); } }