From fffc1657bcb71c5047c61548174a44a3e1e8b274 Mon Sep 17 00:00:00 2001 From: Sandeep Somavarapu Date: Fri, 19 Aug 2016 12:45:45 +0200 Subject: [PATCH] Implement revealLine and reveal cursor while scrolling --- vim-sample/src/mappings.ts | 6 +++++- vim-sample/src/motions.ts | 28 ++++++++++++++++++++++++++-- 2 files changed, 31 insertions(+), 3 deletions(-) diff --git a/vim-sample/src/mappings.ts b/vim-sample/src/mappings.ts index d2045fc7..1c194621 100644 --- a/vim-sample/src/mappings.ts +++ b/vim-sample/src/mappings.ts @@ -110,7 +110,11 @@ defineMotionCommand('d', Motions.ScrollDownByHalfPage, {ctrl: true}); defineMotionCommand('f', Motions.ScrollDownByPage, {ctrl: true}); defineMotionCommand('y', Motions.ScrollUpByLine, {ctrl: true}); defineMotionCommand('u', Motions.ScrollUpByHalfPage, {ctrl: true}); -defineMotionCommand('b', Motions.ScrollUpByPage, {ctrl: true}); +defineMotionCommand('b', Motions.ScrollUpByPage, { ctrl: true }); + +defineMotionCommand('zt', Motions.RevealCurrentLineAtTop); +defineMotionCommand('zz', Motions.RevealCurrentLineAtCenter); +defineMotionCommand('zb', Motions.RevealCurrentLineAtBottom); export interface IFoundOperator { runNormal(controller: IController, editor:TextEditor): boolean; diff --git a/vim-sample/src/motions.ts b/vim-sample/src/motions.ts index a328e4af..28e1f883 100644 --- a/vim-sample/src/motions.ts +++ b/vim-sample/src/motions.ts @@ -4,7 +4,7 @@ *--------------------------------------------------------------------------------------------*/ 'use strict'; -import {Position, TextDocument} from 'vscode'; +import {Position, TextDocument, window} from 'vscode'; import {Words, WordCharacters} from './words'; import {Command, AbstractCommandDescriptor} from './common'; @@ -275,6 +275,7 @@ class EditorScrollCommand extends AbstractCommandDescriptor { to: this.to, by: this.by, value: args.repeat || 1, + revealCursor: true } return { commandId: 'editorScroll', @@ -283,6 +284,25 @@ class EditorScrollCommand extends AbstractCommandDescriptor { } } +class RevealCurrentLineCommand extends AbstractCommandDescriptor { + + constructor(private at: string) { + super(); + } + + public createCommand(args?: any): Command { + const lineNumber = window.activeTextEditor.selection.start.line; + const revealLineArgs: any = { + lineNumber, + at: this.at + }; + return { + commandId: 'revealLine', + args: revealLineArgs + }; + } +} + class MoveActiveEditorCommandByPosition extends AbstractCommandDescriptor { constructor() { @@ -367,5 +387,9 @@ export const Motions = { ScrollDownByPage: new EditorScrollCommand('down', 'page'), ScrollUpByLine: new EditorScrollCommand('up', 'line'), ScrollUpByHalfPage: new EditorScrollCommand('up', 'halfPage'), - ScrollUpByPage: new EditorScrollCommand('up', 'page') + ScrollUpByPage: new EditorScrollCommand('up', 'page'), + + RevealCurrentLineAtTop: new RevealCurrentLineCommand('top'), + RevealCurrentLineAtCenter: new RevealCurrentLineCommand('center'), + RevealCurrentLineAtBottom: new RevealCurrentLineCommand('bottom') };