mirror of
https://github.com/microsoft/vscode-extension-samples.git
synced 2026-04-27 16:55:44 +08:00
Implement revealLine and reveal cursor while scrolling
This commit is contained in:
@ -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;
|
||||
|
||||
@ -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')
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user