Implement revealLine and reveal cursor while scrolling

This commit is contained in:
Sandeep Somavarapu
2016-08-19 12:45:45 +02:00
parent 134de4eff9
commit fffc1657bc
2 changed files with 31 additions and 3 deletions

View File

@ -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;

View File

@ -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')
};