From 028ecb30ea033ccfdf370f7444e62eb73c6d7233 Mon Sep 17 00:00:00 2001 From: Sandeep Somavarapu Date: Mon, 29 Aug 2016 19:37:16 +0200 Subject: [PATCH] Fold commands --- vim-sample/src/mappings.ts | 5 +++++ vim-sample/src/motions.ts | 40 +++++++++++++++++++++++++++++++++++++- 2 files changed, 44 insertions(+), 1 deletion(-) diff --git a/vim-sample/src/mappings.ts b/vim-sample/src/mappings.ts index 1c194621..00bca69e 100644 --- a/vim-sample/src/mappings.ts +++ b/vim-sample/src/mappings.ts @@ -116,6 +116,11 @@ defineMotionCommand('zt', Motions.RevealCurrentLineAtTop); defineMotionCommand('zz', Motions.RevealCurrentLineAtCenter); defineMotionCommand('zb', Motions.RevealCurrentLineAtBottom); +// Folding +defineMotionCommand('zc', Motions.FoldUnder); +defineMotionCommand('zo', Motions.UnfoldUnder); + + export interface IFoundOperator { runNormal(controller: IController, editor:TextEditor): boolean; runVisual(controller: IController, editor:TextEditor): boolean; diff --git a/vim-sample/src/motions.ts b/vim-sample/src/motions.ts index 28e1f883..07cc1596 100644 --- a/vim-sample/src/motions.ts +++ b/vim-sample/src/motions.ts @@ -338,6 +338,41 @@ class MoveActiveEditorCommand extends AbstractCommandDescriptor { }; } } +class FoldCommand extends AbstractCommandDescriptor { + + constructor() { + super(); + } + + public createCommand(args?: any): Command { + let foldEditorArgs: any = { + levels: args.repeat ? args.repeat : 1, + direction: 'up' + } + return { + commandId: 'editor.fold', + args: foldEditorArgs + }; + } +} + +class UnfoldCommand extends AbstractCommandDescriptor { + + constructor() { + super(); + } + + public createCommand(args?: any): Command { + let foldEditorArgs: any = { + levels: args.repeat ? args.repeat : 1, + direction: 'up' + } + return { + commandId: 'editor.unfold', + args: foldEditorArgs + }; + } +} export const Motions = { RightMotion: new RightMotion(), @@ -391,5 +426,8 @@ export const Motions = { RevealCurrentLineAtTop: new RevealCurrentLineCommand('top'), RevealCurrentLineAtCenter: new RevealCurrentLineCommand('center'), - RevealCurrentLineAtBottom: new RevealCurrentLineCommand('bottom') + RevealCurrentLineAtBottom: new RevealCurrentLineCommand('bottom'), + + FoldUnder: new FoldCommand(), + UnfoldUnder: new UnfoldCommand() };