Skip to content

Commit 13830e4

Browse files
authored
Set scroll option with <C-u> and <C-d> (#8985)
Fixes #8984
1 parent 1bd4642 commit 13830e4

File tree

3 files changed

+43
-21
lines changed

3 files changed

+43
-21
lines changed

src/actions/commands/scroll.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,8 @@ abstract class CommandScrollAndMoveCursor extends BaseCommand {
7474
modes = [Mode.Normal, Mode.Visual, Mode.VisualLine, Mode.VisualBlock];
7575
override runsOnceForEachCountPrefix = false;
7676
abstract to: EditorScrollDirection;
77+
/** if true, set scroll option instead of repeating command */
78+
setScroll = false;
7779

7880
/**
7981
* @returns the number of lines this command should move the cursor
@@ -90,7 +92,9 @@ abstract class CommandScrollAndMoveCursor extends BaseCommand {
9092
.getConfiguration('editor')
9193
.get<boolean>('smoothScrolling', false);
9294

93-
const timesToRepeat = vimState.recordedState.count || 1;
95+
if (this.setScroll && vimState.recordedState.count)
96+
configuration.scroll = vimState.recordedState.count;
97+
const timesToRepeat = (!this.setScroll && vimState.recordedState.count) || 1;
9498
const moveLines = timesToRepeat * this.getNumLines(visibleRanges);
9599

96100
let scrollLines = moveLines;
@@ -153,19 +157,21 @@ class CommandMoveFullPageDown extends CommandScrollAndMoveCursor {
153157
}
154158

155159
@RegisterAction
156-
class CommandMoveHalfPageDown extends CommandScrollAndMoveCursor {
160+
class CommandCtrlD extends CommandScrollAndMoveCursor {
157161
keys = ['<C-d>'];
158162
to: EditorScrollDirection = 'down';
163+
override setScroll = true;
159164

160165
protected getNumLines(visibleRanges: vscode.Range[]) {
161166
return configuration.getScrollLines(visibleRanges);
162167
}
163168
}
164169

165170
@RegisterAction
166-
class CommandMoveHalfPageUp extends CommandScrollAndMoveCursor {
171+
class CommandCtrlU extends CommandScrollAndMoveCursor {
167172
keys = ['<C-u>'];
168173
to: EditorScrollDirection = 'up';
174+
override setScroll = true;
169175

170176
protected getNumLines(visibleRanges: vscode.Range[]) {
171177
return configuration.getScrollLines(visibleRanges);

test/mode/modeNormal.test.ts

Lines changed: 33 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2737,25 +2737,41 @@ suite('Mode Normal', () => {
27372737
endMode: Mode.Normal,
27382738
});
27392739

2740-
newTest({
2741-
title: 'can handle <C-u> when first line is visible and starting column is at the beginning',
2742-
start: ['\t hello world', 'hello', 'hi hello', '|foo'],
2743-
keysPressed: '<C-u>',
2744-
end: ['\t |hello world', 'hello', 'hi hello', 'foo'],
2745-
});
2740+
suite('<C-u> / <C-d>', () => {
2741+
newTest({
2742+
title: 'can handle <C-u> when first line is visible and starting column is at the beginning',
2743+
start: ['\t hello world', 'hello', 'hi hello', '|foo'],
2744+
keysPressed: '<C-u>',
2745+
end: ['\t |hello world', 'hello', 'hi hello', 'foo'],
2746+
});
27462747

2747-
newTest({
2748-
title: 'can handle <C-u> when first line is visible and starting column is at the end',
2749-
start: ['\t hello world', 'hello', 'hi hello', 'very long line at the bottom|'],
2750-
keysPressed: '<C-u>',
2751-
end: ['\t |hello world', 'hello', 'hi hello', 'very long line at the bottom'],
2752-
});
2748+
newTest({
2749+
title: 'can handle <C-u> when first line is visible and starting column is at the end',
2750+
start: ['\t hello world', 'hello', 'hi hello', 'very long line at the bottom|'],
2751+
keysPressed: '<C-u>',
2752+
end: ['\t |hello world', 'hello', 'hi hello', 'very long line at the bottom'],
2753+
});
27532754

2754-
newTest({
2755-
title: 'can handle <C-u> when first line is visible and starting column is in the middle',
2756-
start: ['\t hello world', 'hello', 'hi hello', 'very long line |at the bottom'],
2757-
keysPressed: '<C-u>',
2758-
end: ['\t |hello world', 'hello', 'hi hello', 'very long line at the bottom'],
2755+
newTest({
2756+
title: 'can handle <C-u> when first line is visible and starting column is in the middle',
2757+
start: ['\t hello world', 'hello', 'hi hello', 'very long line |at the bottom'],
2758+
keysPressed: '<C-u>',
2759+
end: ['\t |hello world', 'hello', 'hi hello', 'very long line at the bottom'],
2760+
});
2761+
2762+
newTest({
2763+
title: '[count]<C-u> sets and adheres to scroll option',
2764+
start: ['abc', 'def', 'ghi', 'jkl', 'mno', 'pqr', 'st|u'],
2765+
keysPressed: '2<C-u><C-u>',
2766+
end: ['abc', 'def', '|ghi', 'jkl', 'mno', 'pqr', 'stu'],
2767+
});
2768+
2769+
newTest({
2770+
title: '[count]<C-d> sets and adheres to scroll option',
2771+
start: ['ab|c', 'def', 'ghi', 'jkl', 'mno', 'pqr', 'stu'],
2772+
keysPressed: '2<C-d><C-d>',
2773+
end: ['abc', 'def', 'ghi', 'jkl', '|mno', 'pqr', 'stu'],
2774+
});
27592775
});
27602776

27612777
suite('<C-g>', () => {

test/testSimplifier.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ class DocState {
149149
}
150150

151151
/**
152-
* Tokenize a string like "abc<Esc>d<C-c>" into ["a", "b", "c", "<Esc>", "d", "<C-c>"]
152+
* Tokenize a string like `"abc<Esc>d<C-c>"` into `["a", "b", "c", "<Esc>", "d", "<C-c>"]`
153153
*/
154154
function tokenizeKeySequence(sequence: string): string[] {
155155
let isBracketedKey = false;

0 commit comments

Comments
 (0)