@@ -62,52 +62,74 @@ function moveCursor(
6262 editor . revealRange ( new vscode . Range ( newPosition , newPosition ) ) ;
6363}
6464
65+ enum ParagraphJumpOperation {
66+ moveUp = 0 ,
67+ moveDown = 1 ,
68+ selectUp = 2 ,
69+ selectDown = 3 ,
70+ }
71+
72+ function performParagraphJumpOperation (
73+ editor : vscode . TextEditor ,
74+ op : ParagraphJumpOperation
75+ ) {
76+ switch ( op ) {
77+ case ParagraphJumpOperation . moveUp :
78+ case ParagraphJumpOperation . selectUp :
79+ {
80+ const targetLine = getNextLine ( editor , LineOperation . up ) ;
81+ const newPosition = new vscode . Position ( targetLine . lineNumber , 0 ) ;
82+ const moveOp =
83+ op === ParagraphJumpOperation . moveUp
84+ ? MoveOperation . move
85+ : MoveOperation . select ;
86+ moveCursor ( editor , newPosition , moveOp ) ;
87+ }
88+ break ;
89+ case ParagraphJumpOperation . moveDown :
90+ case ParagraphJumpOperation . selectDown :
91+ {
92+ const targetLine = getNextLine ( editor , LineOperation . down ) ;
93+ const newPosition = new vscode . Position (
94+ targetLine . lineNumber ,
95+ targetLine . text . length
96+ ) ;
97+ const moveOp =
98+ op === ParagraphJumpOperation . moveDown
99+ ? MoveOperation . move
100+ : MoveOperation . select ;
101+ moveCursor ( editor , newPosition , moveOp ) ;
102+ }
103+ break ;
104+ }
105+ }
106+
65107export function activate ( context : vscode . ExtensionContext ) {
66108 let paragraphJumpUp = vscode . commands . registerTextEditorCommand (
67109 "paragraphjump.up" ,
68110 ( editor : vscode . TextEditor ) => {
69- const targetLine : vscode . TextLine = getNextLine ( editor , LineOperation . up ) ;
70- const newPosition = new vscode . Position ( targetLine . lineNumber , 0 ) ;
71- moveCursor ( editor , newPosition , MoveOperation . move ) ;
111+ performParagraphJumpOperation ( editor , ParagraphJumpOperation . moveUp ) ;
72112 }
73113 ) ;
74114
75115 let paragraphJumpDown = vscode . commands . registerTextEditorCommand (
76116 "paragraphjump.down" ,
77117 ( editor : vscode . TextEditor ) => {
78- const targetLine : vscode . TextLine = getNextLine (
79- editor ,
80- LineOperation . down
81- ) ;
82- const newPosition = new vscode . Position (
83- targetLine . lineNumber ,
84- targetLine . text . length
85- ) ;
86- moveCursor ( editor , newPosition , MoveOperation . move ) ;
118+ performParagraphJumpOperation ( editor , ParagraphJumpOperation . moveDown ) ;
87119 }
88120 ) ;
89121
90122 let paragraphSelectUp = vscode . commands . registerTextEditorCommand (
91123 "paragraphjump.selectup" ,
92124 ( editor : vscode . TextEditor ) => {
93- const targetLine : vscode . TextLine = getNextLine ( editor , LineOperation . up ) ;
94- const newPosition = new vscode . Position ( targetLine . lineNumber , 0 ) ;
95- moveCursor ( editor , newPosition , MoveOperation . select ) ;
125+ performParagraphJumpOperation ( editor , ParagraphJumpOperation . selectUp ) ;
96126 }
97127 ) ;
98128
99129 let paragraphSelectDown = vscode . commands . registerTextEditorCommand (
100130 "paragraphjump.selectdown" ,
101131 ( editor : vscode . TextEditor ) => {
102- const targetLine : vscode . TextLine = getNextLine (
103- editor ,
104- LineOperation . down
105- ) ;
106- const newPosition = new vscode . Position (
107- targetLine . lineNumber ,
108- targetLine . text . length
109- ) ;
110- moveCursor ( editor , newPosition , MoveOperation . select ) ;
132+ performParagraphJumpOperation ( editor , ParagraphJumpOperation . selectDown ) ;
111133 }
112134 ) ;
113135
0 commit comments