@@ -6,8 +6,8 @@ const targetLineIsEmptyOrWhitespace = (
66) => ! document . lineAt ( line ) . isEmptyOrWhitespace ;
77
88enum LineOperation {
9- up = 1 ,
10- down = 2 ,
9+ up = 0 ,
10+ down = 1 ,
1111}
1212
1313function getNextLine ( editor : vscode . TextEditor , op : LineOperation ) {
@@ -34,8 +34,30 @@ function getNextLine(editor: vscode.TextEditor, op: LineOperation) {
3434 return document . lineAt ( line ) ;
3535}
3636
37- function moveCursor ( editor : vscode . TextEditor , newPosition : vscode . Position ) {
38- let newCursorPosition = new vscode . Selection ( newPosition , newPosition ) ;
37+ enum MoveOperation {
38+ move = 0 ,
39+ select = 1 ,
40+ }
41+
42+ function moveCursor (
43+ editor : vscode . TextEditor ,
44+ newPosition : vscode . Position ,
45+ op : MoveOperation
46+ ) {
47+ let newCursorPosition : vscode . Selection ;
48+ switch ( op ) {
49+ case MoveOperation . move :
50+ {
51+ newCursorPosition = new vscode . Selection ( newPosition , newPosition ) ;
52+ }
53+ break ;
54+ case MoveOperation . select :
55+ {
56+ let anchor = editor . selection . anchor ;
57+ newCursorPosition = new vscode . Selection ( anchor , newPosition ) ;
58+ }
59+ break ;
60+ }
3961 editor . selection = newCursorPosition ;
4062 editor . revealRange ( new vscode . Range ( newPosition , newPosition ) ) ;
4163}
@@ -44,22 +66,57 @@ export function activate(context: vscode.ExtensionContext) {
4466 let paragraphJumpUp = vscode . commands . registerTextEditorCommand (
4567 "paragraphjump.up" ,
4668 ( editor : vscode . TextEditor ) => {
47- let targetLine : vscode . TextLine = getNextLine ( editor , LineOperation . up ) ;
69+ const targetLine : vscode . TextLine = getNextLine ( editor , LineOperation . up ) ;
4870 const newPosition = new vscode . Position ( targetLine . lineNumber , 0 ) ;
49- moveCursor ( editor , newPosition ) ;
71+ moveCursor ( editor , newPosition , MoveOperation . move ) ;
5072 }
5173 ) ;
5274
5375 let paragraphJumpDown = vscode . commands . registerTextEditorCommand (
5476 "paragraphjump.down" ,
5577 ( editor : vscode . TextEditor ) => {
56- let targetLine : vscode . TextLine = getNextLine ( editor , LineOperation . down ) ;
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 ) ;
87+ }
88+ ) ;
89+
90+ let paragraphSelectUp = vscode . commands . registerTextEditorCommand (
91+ "paragraphjump.selectup" ,
92+ ( editor : vscode . TextEditor ) => {
93+ const targetLine : vscode . TextLine = getNextLine ( editor , LineOperation . up ) ;
5794 const newPosition = new vscode . Position ( targetLine . lineNumber , 0 ) ;
58- moveCursor ( editor , newPosition ) ;
95+ moveCursor ( editor , newPosition , MoveOperation . select ) ;
5996 }
6097 ) ;
6198
62- context . subscriptions . push ( paragraphJumpUp , paragraphJumpDown ) ;
99+ let paragraphSelectDown = vscode . commands . registerTextEditorCommand (
100+ "paragraphjump.selectdown" ,
101+ ( 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 ) ;
111+ }
112+ ) ;
113+
114+ context . subscriptions . push (
115+ paragraphJumpUp ,
116+ paragraphJumpDown ,
117+ paragraphSelectUp ,
118+ paragraphSelectDown
119+ ) ;
63120}
64121
65122export function deactivate ( ) { }
0 commit comments