mirror of
https://github.com/chylex/IntelliJ-IdeaVim.git
synced 2025-03-05 06:32:51 +01:00
Add 'startofline' support for scrolling actions
This commit is contained in:
parent
1d3d6f0ea1
commit
39197df0c7
src/com/maddyhome/idea/vim
action/motion
scroll
MotionScrollHalfPageDownAction.ktMotionScrollHalfPageUpAction.ktMotionScrollPageDownAction.ktMotionScrollPageUpAction.kt
updown
group
test/org/jetbrains/plugins/ideavim/action/scroll
@ -32,6 +32,6 @@ class MotionScrollHalfPageDownAction : VimActionHandler.SingleExecution() {
|
||||
override val flags: EnumSet<CommandFlags> = enumSetOf(CommandFlags.FLAG_IGNORE_SCROLL_JUMP)
|
||||
|
||||
override fun execute(editor: Editor, context: DataContext, cmd: Command): Boolean {
|
||||
return VimPlugin.getMotion().scrollScreen(editor, cmd.rawCount, true)
|
||||
return VimPlugin.getMotion().scrollScreen(editor, editor.caretModel.primaryCaret, cmd.rawCount, true)
|
||||
}
|
||||
}
|
||||
|
@ -32,6 +32,6 @@ class MotionScrollHalfPageUpAction : VimActionHandler.SingleExecution() {
|
||||
override val flags: EnumSet<CommandFlags> = enumSetOf(CommandFlags.FLAG_IGNORE_SCROLL_JUMP)
|
||||
|
||||
override fun execute(editor: Editor, context: DataContext, cmd: Command): Boolean {
|
||||
return VimPlugin.getMotion().scrollScreen(editor, cmd.rawCount, false)
|
||||
return VimPlugin.getMotion().scrollScreen(editor, editor.caretModel.primaryCaret, cmd.rawCount, false)
|
||||
}
|
||||
}
|
||||
|
@ -39,7 +39,7 @@ class MotionScrollPageDownAction : VimActionHandler.SingleExecution() {
|
||||
override val flags: EnumSet<CommandFlags> = enumSetOf(FLAG_IGNORE_SCROLL_JUMP)
|
||||
|
||||
override fun execute(editor: Editor, context: DataContext, cmd: Command): Boolean {
|
||||
return VimPlugin.getMotion().scrollFullPage(editor, cmd.count)
|
||||
return VimPlugin.getMotion().scrollFullPage(editor, editor.caretModel.primaryCaret, cmd.count)
|
||||
}
|
||||
}
|
||||
|
||||
@ -54,6 +54,6 @@ class MotionScrollPageDownInsertModeAction : VimActionHandler.SingleExecution(),
|
||||
override val flags: EnumSet<CommandFlags> = enumSetOf(FLAG_IGNORE_SCROLL_JUMP, FLAG_CLEAR_STROKES)
|
||||
|
||||
override fun execute(editor: Editor, context: DataContext, cmd: Command): Boolean {
|
||||
return VimPlugin.getMotion().scrollFullPage(editor, cmd.count)
|
||||
return VimPlugin.getMotion().scrollFullPage(editor, editor.caretModel.primaryCaret, cmd.count)
|
||||
}
|
||||
}
|
||||
|
@ -39,7 +39,7 @@ class MotionScrollPageUpAction : VimActionHandler.SingleExecution() {
|
||||
override val flags: EnumSet<CommandFlags> = enumSetOf(FLAG_IGNORE_SCROLL_JUMP)
|
||||
|
||||
override fun execute(editor: Editor, context: DataContext, cmd: Command): Boolean {
|
||||
return VimPlugin.getMotion().scrollFullPage(editor, -cmd.count)
|
||||
return VimPlugin.getMotion().scrollFullPage(editor, editor.caretModel.primaryCaret, -cmd.count)
|
||||
}
|
||||
}
|
||||
|
||||
@ -54,6 +54,6 @@ class MotionScrollPageUpInsertModeAction : VimActionHandler.SingleExecution(), C
|
||||
override val flags: EnumSet<CommandFlags> = enumSetOf(FLAG_IGNORE_SCROLL_JUMP, FLAG_CLEAR_STROKES)
|
||||
|
||||
override fun execute(editor: Editor, context: DataContext, cmd: Command): Boolean {
|
||||
return VimPlugin.getMotion().scrollFullPage(editor, -cmd.count)
|
||||
return VimPlugin.getMotion().scrollFullPage(editor, editor.caretModel.primaryCaret, -cmd.count)
|
||||
}
|
||||
}
|
||||
|
@ -46,6 +46,6 @@ class MotionShiftDownAction : ShiftedArrowKeyHandler() {
|
||||
}
|
||||
|
||||
override fun motionWithoutKeyModel(editor: Editor, context: DataContext, cmd: Command) {
|
||||
VimPlugin.getMotion().scrollFullPage(editor, cmd.count)
|
||||
VimPlugin.getMotion().scrollFullPage(editor, editor.caretModel.primaryCaret, cmd.count)
|
||||
}
|
||||
}
|
||||
|
@ -46,6 +46,6 @@ class MotionShiftUpAction : ShiftedArrowKeyHandler() {
|
||||
}
|
||||
|
||||
override fun motionWithoutKeyModel(editor: Editor, context: DataContext, cmd: Command) {
|
||||
VimPlugin.getMotion().scrollFullPage(editor, -cmd.count)
|
||||
VimPlugin.getMotion().scrollFullPage(editor, editor.caretModel.primaryCaret, -cmd.count)
|
||||
}
|
||||
}
|
||||
|
@ -1075,7 +1075,7 @@ public class MotionGroup {
|
||||
}
|
||||
}
|
||||
|
||||
public boolean scrollFullPage(@NotNull Editor editor, int pages) {
|
||||
public boolean scrollFullPage(@NotNull Editor editor, @NotNull Caret caret, int pages) {
|
||||
int caretVisualLine = EditorHelper.scrollFullPage(editor, pages);
|
||||
if (caretVisualLine != -1) {
|
||||
final int scrollOffset = getNormalizedScrollOffset(editor);
|
||||
@ -1099,9 +1099,10 @@ public class MotionGroup {
|
||||
}
|
||||
}
|
||||
|
||||
int offset =
|
||||
moveCaretToLineStartSkipLeading(editor, visualLineToLogicalLine(editor, caretVisualLine));
|
||||
moveCaret(editor, editor.getCaretModel().getPrimaryCaret(), offset);
|
||||
int offset = moveCaretToLineWithStartOfLineOption(editor,
|
||||
visualLineToLogicalLine(editor, caretVisualLine),
|
||||
caret);
|
||||
moveCaret(editor, caret, offset);
|
||||
return success;
|
||||
}
|
||||
|
||||
@ -1134,7 +1135,7 @@ public class MotionGroup {
|
||||
}
|
||||
}
|
||||
|
||||
public boolean scrollScreen(final @NotNull Editor editor, int rawCount, boolean down) {
|
||||
public boolean scrollScreen(final @NotNull Editor editor, final @NotNull Caret caret, int rawCount, boolean down) {
|
||||
final CaretModel caretModel = editor.getCaretModel();
|
||||
final int currentLogicalLine = caretModel.getLogicalPosition().line;
|
||||
|
||||
@ -1178,8 +1179,8 @@ public class MotionGroup {
|
||||
}
|
||||
|
||||
int logicalLine = visualLineToLogicalLine(editor, targetCaretVisualLine);
|
||||
int caretOffset = moveCaretToLineStartSkipLeading(editor, logicalLine);
|
||||
moveCaret(editor, caretModel.getPrimaryCaret(), caretOffset);
|
||||
int caretOffset = moveCaretToLineWithStartOfLineOption(editor, logicalLine, caret);
|
||||
moveCaret(editor, caret, caretOffset);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -20,7 +20,6 @@ package org.jetbrains.plugins.ideavim.action.scroll
|
||||
|
||||
import com.maddyhome.idea.vim.VimPlugin
|
||||
import com.maddyhome.idea.vim.helper.StringHelper.parseKeys
|
||||
import com.maddyhome.idea.vim.helper.VimBehaviorDiffers
|
||||
import com.maddyhome.idea.vim.option.OptionsManager
|
||||
import org.jetbrains.plugins.ideavim.VimTestCase
|
||||
|
||||
@ -102,7 +101,6 @@ class ScrollHalfPageDownActionTest : VimTestCase() {
|
||||
assertVisibleArea(135, 169)
|
||||
}
|
||||
|
||||
@VimBehaviorDiffers(description = "IdeaVim does not support the 'startofline' options")
|
||||
fun `test scroll downwards puts cursor on first non-blank column`() {
|
||||
configureByLines(100, " I found it in a legendary land")
|
||||
setPositionAndScroll(20, 25, 14)
|
||||
@ -110,4 +108,13 @@ class ScrollHalfPageDownActionTest : VimTestCase() {
|
||||
assertPosition(42, 4)
|
||||
assertVisibleArea(37, 71)
|
||||
}
|
||||
|
||||
fun `test scroll downwards keeps same column with nostartofline`() {
|
||||
OptionsManager.startofline.reset()
|
||||
configureByLines(100, " I found it in a legendary land")
|
||||
setPositionAndScroll(20, 25, 14)
|
||||
typeText(parseKeys("<C-D>"))
|
||||
assertPosition(42, 14)
|
||||
assertVisibleArea(37, 71)
|
||||
}
|
||||
}
|
||||
|
@ -20,7 +20,6 @@ package org.jetbrains.plugins.ideavim.action.scroll
|
||||
|
||||
import com.maddyhome.idea.vim.VimPlugin
|
||||
import com.maddyhome.idea.vim.helper.StringHelper.parseKeys
|
||||
import com.maddyhome.idea.vim.helper.VimBehaviorDiffers
|
||||
import com.maddyhome.idea.vim.option.OptionsManager
|
||||
import org.jetbrains.plugins.ideavim.VimTestCase
|
||||
|
||||
@ -94,7 +93,6 @@ class ScrollHalfPageUpActionTest : VimTestCase() {
|
||||
assertVisibleArea(65, 99)
|
||||
}
|
||||
|
||||
@VimBehaviorDiffers(description = "IdeaVim does not support the 'startofline' options")
|
||||
fun `test scroll up puts cursor on first non-blank column`() {
|
||||
configureByLines(100, " I found it in a legendary land")
|
||||
setPositionAndScroll(50, 60, 14)
|
||||
@ -102,4 +100,13 @@ class ScrollHalfPageUpActionTest : VimTestCase() {
|
||||
assertPosition(43, 4)
|
||||
assertVisibleArea(33, 67)
|
||||
}
|
||||
|
||||
fun `test scroll upwards keeps same column with nostartofline`() {
|
||||
OptionsManager.startofline.reset()
|
||||
configureByLines(100, " I found it in a legendary land")
|
||||
setPositionAndScroll(50, 60, 14)
|
||||
typeText(parseKeys("<C-U>"))
|
||||
assertPosition(43, 14)
|
||||
assertVisibleArea(33, 67)
|
||||
}
|
||||
}
|
||||
|
@ -166,4 +166,21 @@ class ScrollPageDownActionTest : VimTestCase() {
|
||||
typeText(parseKeys("<C-F>"))
|
||||
assertTrue(VimPlugin.isError())
|
||||
}
|
||||
|
||||
fun `test scroll page down puts cursor on first non-blank column`() {
|
||||
configureByLines(100, " I found it in a legendary land")
|
||||
setPositionAndScroll(20, 25, 14)
|
||||
typeText(parseKeys("<C-F>"))
|
||||
assertPosition(53, 4)
|
||||
assertVisibleArea(53, 87)
|
||||
}
|
||||
|
||||
fun `test scroll page down keeps same column with nostartofline`() {
|
||||
OptionsManager.startofline.reset()
|
||||
configureByLines(100, " I found it in a legendary land")
|
||||
setPositionAndScroll(20, 25, 14)
|
||||
typeText(parseKeys("<C-F>"))
|
||||
assertPosition(53, 14)
|
||||
assertVisibleArea(53, 87)
|
||||
}
|
||||
}
|
||||
|
@ -164,4 +164,21 @@ class ScrollPageUpActionTest : VimTestCase() {
|
||||
assertPosition(11, 0)
|
||||
assertVisibleArea(0, 34)
|
||||
}
|
||||
|
||||
fun `test scroll page up puts cursor on first non-blank column`() {
|
||||
configureByLines(100, " I found it in a legendary land")
|
||||
setPositionAndScroll(50, 60, 14)
|
||||
typeText(parseKeys("<C-B>"))
|
||||
assertPosition(51, 4)
|
||||
assertVisibleArea(17, 51)
|
||||
}
|
||||
|
||||
fun `test scroll page up keeps same column with nostartofline`() {
|
||||
OptionsManager.startofline.reset()
|
||||
configureByLines(100, " I found it in a legendary land")
|
||||
setPositionAndScroll(50, 60, 14)
|
||||
typeText(parseKeys("<C-B>"))
|
||||
assertPosition(51, 14)
|
||||
assertVisibleArea(17, 51)
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user