1
0
mirror of https://github.com/chylex/IntelliJ-IdeaVim.git synced 2025-08-14 08:17:06 +02:00

Add Shift+Enter mapping to scroll page forward

Fixes VIM-2752
This commit is contained in:
Matt Ellis
2024-11-08 17:35:07 +00:00
committed by Alex Pláte
parent 5eb36ce428
commit a745da9761
3 changed files with 33 additions and 1 deletions
src/test/java/org/jetbrains/plugins/ideavim/action/scroll
vim-engine/src/main
kotlin
com
maddyhome
idea
vim
resources

@@ -56,6 +56,16 @@ class ScrollPageDownActionTest : VimTestCase() {
assertVisibleArea(33, 67)
}
@TestWithoutNeovim(SkipNeovimReason.SCROLL)
@Test
fun `test scroll single page down with S-Enter`() {
configureByPages(5)
setPositionAndScroll(0, 0)
typeText("<S-Enter>")
assertPosition(33, 0)
assertVisibleArea(33, 67)
}
@TestWithoutNeovim(SkipNeovimReason.SCROLL)
@Test
fun `test scroll page down in insert mode with S-Down`() {

@@ -22,7 +22,24 @@ import com.maddyhome.idea.vim.handler.VimActionHandler
import com.maddyhome.idea.vim.helper.enumSetOf
import java.util.*
@CommandOrMotion(keys = ["<C-F>", "<PageDown>"], modes = [Mode.NORMAL, Mode.VISUAL, Mode.OP_PENDING])
// The <S-Enter> mapping is interesting. Vim has multiple mappings to move the caret down: <Down>, obviously, but also
// <Enter>, <C-N>, `+` and `j`. While there are some differences (<Enter> and `+` have a flag that moves the caret to
// the start of the line), there is just one function to handle all of these keys and move the caret down.
// This function checks if Shift is held down, in which case it will scroll the page forward, because <S-Down> behaves
// the same as <C-F>. The side effect is that all shift+"down" shortcuts will now scroll forward, including <S-Enter>.
// However, Vim does not support shifted ctrl shortcuts because terminals only support simple ascii control characters.
// So <C-S-N> doesn't scroll forward. Shift+j becomes `J`, which joins multiple lines. And on a typical US/UK keyboard,
// `+` requires shift to type, so can only be typed with the numpad. Vim does not allow remapping <s-+>.
// (IdeaVim does not get shift+numpadPlus, only "typed +". We might get it for a keypress, but by the time it's
// converted to a typed char, we lose the modifier).
// The same logic holds for <Up> and shift - <C-P>, `k` and `-` should scroll backwards, but <C-S-P> isn't valid, `K` is
// a different action, and shift+numpadMinus works but can't be remapped (or handled by IdeaVim).
// Ironically, Vim registers separate functions for <S-Down> and <S-Up>, so the non-shifted functions don't actually
// need to check for shift. So this is all side effect...
// See https://github.com/vim/vim/issues/15107
// Note that IdeaVim handles <S-Down> separately because it behaves differently based on 'keymodel'
// TODO: Is there any way for IdeaVim to handle shift+numpadPlus?
@CommandOrMotion(keys = ["<C-F>", "<PageDown>", "<S-Enter>"], modes = [Mode.NORMAL, Mode.VISUAL, Mode.OP_PENDING])
class MotionScrollPageDownAction : VimActionHandler.SingleExecution() {
override val type: Command.Type = Command.Type.OTHER_READONLY

@@ -844,6 +844,11 @@
"class": "com.maddyhome.idea.vim.action.motion.leftright.MotionShiftEndAction",
"modes": "INXS"
},
{
"keys": "<S-Enter>",
"class": "com.maddyhome.idea.vim.action.motion.scroll.MotionScrollPageDownAction",
"modes": "NXO"
},
{
"keys": "<S-Home>",
"class": "com.maddyhome.idea.vim.action.motion.leftright.MotionShiftHomeAction",