From 13830e49b0b14808100539d90002ded17a5edba6 Mon Sep 17 00:00:00 2001 From: Anton Jeppsson Date: Thu, 2 May 2024 03:10:33 +0200 Subject: [PATCH] Set scroll option with `` and `` (#8985) Fixes #8984 --- src/actions/commands/scroll.ts | 12 ++++++-- test/mode/modeNormal.test.ts | 50 ++++++++++++++++++++++------------ test/testSimplifier.ts | 2 +- 3 files changed, 43 insertions(+), 21 deletions(-) diff --git a/src/actions/commands/scroll.ts b/src/actions/commands/scroll.ts index df7a9c2ad..f91d6ded1 100644 --- a/src/actions/commands/scroll.ts +++ b/src/actions/commands/scroll.ts @@ -74,6 +74,8 @@ abstract class CommandScrollAndMoveCursor extends BaseCommand { modes = [Mode.Normal, Mode.Visual, Mode.VisualLine, Mode.VisualBlock]; override runsOnceForEachCountPrefix = false; abstract to: EditorScrollDirection; + /** if true, set scroll option instead of repeating command */ + setScroll = false; /** * @returns the number of lines this command should move the cursor @@ -90,7 +92,9 @@ abstract class CommandScrollAndMoveCursor extends BaseCommand { .getConfiguration('editor') .get('smoothScrolling', false); - const timesToRepeat = vimState.recordedState.count || 1; + if (this.setScroll && vimState.recordedState.count) + configuration.scroll = vimState.recordedState.count; + const timesToRepeat = (!this.setScroll && vimState.recordedState.count) || 1; const moveLines = timesToRepeat * this.getNumLines(visibleRanges); let scrollLines = moveLines; @@ -153,9 +157,10 @@ class CommandMoveFullPageDown extends CommandScrollAndMoveCursor { } @RegisterAction -class CommandMoveHalfPageDown extends CommandScrollAndMoveCursor { +class CommandCtrlD extends CommandScrollAndMoveCursor { keys = ['']; to: EditorScrollDirection = 'down'; + override setScroll = true; protected getNumLines(visibleRanges: vscode.Range[]) { return configuration.getScrollLines(visibleRanges); @@ -163,9 +168,10 @@ class CommandMoveHalfPageDown extends CommandScrollAndMoveCursor { } @RegisterAction -class CommandMoveHalfPageUp extends CommandScrollAndMoveCursor { +class CommandCtrlU extends CommandScrollAndMoveCursor { keys = ['']; to: EditorScrollDirection = 'up'; + override setScroll = true; protected getNumLines(visibleRanges: vscode.Range[]) { return configuration.getScrollLines(visibleRanges); diff --git a/test/mode/modeNormal.test.ts b/test/mode/modeNormal.test.ts index 486b159f1..89239809f 100755 --- a/test/mode/modeNormal.test.ts +++ b/test/mode/modeNormal.test.ts @@ -2737,25 +2737,41 @@ suite('Mode Normal', () => { endMode: Mode.Normal, }); - newTest({ - title: 'can handle when first line is visible and starting column is at the beginning', - start: ['\t hello world', 'hello', 'hi hello', '|foo'], - keysPressed: '', - end: ['\t |hello world', 'hello', 'hi hello', 'foo'], - }); + suite(' / ', () => { + newTest({ + title: 'can handle when first line is visible and starting column is at the beginning', + start: ['\t hello world', 'hello', 'hi hello', '|foo'], + keysPressed: '', + end: ['\t |hello world', 'hello', 'hi hello', 'foo'], + }); - newTest({ - title: 'can handle when first line is visible and starting column is at the end', - start: ['\t hello world', 'hello', 'hi hello', 'very long line at the bottom|'], - keysPressed: '', - end: ['\t |hello world', 'hello', 'hi hello', 'very long line at the bottom'], - }); + newTest({ + title: 'can handle when first line is visible and starting column is at the end', + start: ['\t hello world', 'hello', 'hi hello', 'very long line at the bottom|'], + keysPressed: '', + end: ['\t |hello world', 'hello', 'hi hello', 'very long line at the bottom'], + }); - newTest({ - title: 'can handle when first line is visible and starting column is in the middle', - start: ['\t hello world', 'hello', 'hi hello', 'very long line |at the bottom'], - keysPressed: '', - end: ['\t |hello world', 'hello', 'hi hello', 'very long line at the bottom'], + newTest({ + title: 'can handle when first line is visible and starting column is in the middle', + start: ['\t hello world', 'hello', 'hi hello', 'very long line |at the bottom'], + keysPressed: '', + end: ['\t |hello world', 'hello', 'hi hello', 'very long line at the bottom'], + }); + + newTest({ + title: '[count] sets and adheres to scroll option', + start: ['abc', 'def', 'ghi', 'jkl', 'mno', 'pqr', 'st|u'], + keysPressed: '2', + end: ['abc', 'def', '|ghi', 'jkl', 'mno', 'pqr', 'stu'], + }); + + newTest({ + title: '[count] sets and adheres to scroll option', + start: ['ab|c', 'def', 'ghi', 'jkl', 'mno', 'pqr', 'stu'], + keysPressed: '2', + end: ['abc', 'def', 'ghi', 'jkl', '|mno', 'pqr', 'stu'], + }); }); suite('', () => { diff --git a/test/testSimplifier.ts b/test/testSimplifier.ts index 8a79bbfcd..3d88a9f6b 100644 --- a/test/testSimplifier.ts +++ b/test/testSimplifier.ts @@ -149,7 +149,7 @@ class DocState { } /** - * Tokenize a string like "abcd" into ["a", "b", "c", "", "d", ""] + * Tokenize a string like `"abcd"` into `["a", "b", "c", "", "d", ""]` */ function tokenizeKeySequence(sequence: string): string[] { let isBracketedKey = false;