-
Notifications
You must be signed in to change notification settings - Fork 767
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Partial implementation of virtualedit config
This does not support all config settings, but does add the 'onemore' option. This partly addresses https://youtrack.jetbrains.com/issue/VIM-844
- Loading branch information
Showing
7 changed files
with
335 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
87 changes: 87 additions & 0 deletions
87
src/com/maddyhome/idea/vim/helper/CommandStateExtensions.kt.orig
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
/* | ||
* IdeaVim - Vim emulator for IDEs based on the IntelliJ platform | ||
* Copyright (C) 2003-2020 The IdeaVim authors | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 2 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
@file:JvmName("CommandStateHelper") | ||
|
||
package com.maddyhome.idea.vim.helper | ||
|
||
import com.intellij.openapi.editor.Editor | ||
import com.maddyhome.idea.vim.command.CommandState | ||
import com.maddyhome.idea.vim.option.OptionsManager | ||
|
||
val CommandState.Mode.isEndAllowed | ||
get() = when (this) { | ||
CommandState.Mode.INSERT, CommandState.Mode.VISUAL, CommandState.Mode.SELECT -> true | ||
<<<<<<< HEAD | ||
CommandState.Mode.COMMAND, CommandState.Mode.CMD_LINE, CommandState.Mode.REPLACE, CommandState.Mode.OP_PENDING -> false | ||
======= | ||
CommandState.Mode.COMMAND, CommandState.Mode.CMD_LINE, CommandState.Mode.REPLACE -> OptionsManager.virtualedit.value == "onemore" | ||
>>>>>>> f7ff3089... Partial implementation of virtualedit config | ||
} | ||
|
||
val CommandState.Mode.isBlockCaret | ||
get() = when (this) { | ||
CommandState.Mode.VISUAL, CommandState.Mode.COMMAND, CommandState.Mode.OP_PENDING -> true | ||
CommandState.Mode.INSERT, CommandState.Mode.CMD_LINE, CommandState.Mode.REPLACE, CommandState.Mode.SELECT -> false | ||
} | ||
|
||
val CommandState.Mode.hasVisualSelection | ||
get() = when (this) { | ||
CommandState.Mode.VISUAL, CommandState.Mode.SELECT -> true | ||
CommandState.Mode.REPLACE, CommandState.Mode.CMD_LINE, CommandState.Mode.COMMAND, CommandState.Mode.INSERT, CommandState.Mode.OP_PENDING -> false | ||
} | ||
|
||
val Editor.mode | ||
get() = this.commandState.mode | ||
|
||
var Editor.subMode | ||
get() = this.commandState.subMode | ||
set(value) { | ||
this.commandState.subMode = value | ||
} | ||
|
||
@get:JvmName("inNormalMode") | ||
val Editor.inNormalMode | ||
get() = this.mode == CommandState.Mode.COMMAND | ||
|
||
@get:JvmName("inInsertMode") | ||
val Editor.inInsertMode | ||
get() = this.mode == CommandState.Mode.INSERT || this.mode == CommandState.Mode.REPLACE | ||
|
||
@get:JvmName("inRepeatMode") | ||
val Editor.inRepeatMode | ||
get() = this.commandState.isDotRepeatInProgress | ||
|
||
@get:JvmName("inVisualMode") | ||
val Editor.inVisualMode | ||
get() = this.mode == CommandState.Mode.VISUAL | ||
|
||
@get:JvmName("inSelectMode") | ||
val Editor.inSelectMode | ||
get() = this.mode == CommandState.Mode.SELECT | ||
|
||
@get:JvmName("inBlockSubMode") | ||
val Editor.inBlockSubMode | ||
get() = this.subMode == CommandState.SubMode.VISUAL_BLOCK | ||
|
||
@get:JvmName("inSingleCommandMode") | ||
val Editor.inSingleCommandMode | ||
get() = this.subMode == CommandState.SubMode.SINGLE_COMMAND && this.inNormalMode | ||
|
||
val Editor?.commandState | ||
get() = CommandState.getInstance(this) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
220 changes: 220 additions & 0 deletions
220
test/org/jetbrains/plugins/ideavim/action/motion/leftright/MotionRightActionTest.kt.orig
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,220 @@ | ||
/* | ||
* IdeaVim - Vim emulator for IDEs based on the IntelliJ platform | ||
* Copyright (C) 2003-2020 The IdeaVim authors | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 2 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
@file:Suppress("RemoveCurlyBracesFromTemplate") | ||
|
||
package org.jetbrains.plugins.ideavim.action.motion.leftright | ||
|
||
import com.maddyhome.idea.vim.command.CommandState | ||
<<<<<<< HEAD | ||
import org.jetbrains.plugins.ideavim.SkipNeovimReason | ||
import org.jetbrains.plugins.ideavim.TestWithoutNeovim | ||
======= | ||
import com.maddyhome.idea.vim.helper.StringHelper.parseKeys | ||
import com.maddyhome.idea.vim.option.OptionsManager | ||
>>>>>>> f7ff3089... Partial implementation of virtualedit config | ||
import org.jetbrains.plugins.ideavim.VimTestCase | ||
|
||
class MotionRightActionTest : VimTestCase() { | ||
fun `test simple motion`() { | ||
doTest("l", """ | ||
A Discovery | ||
|
||
I found ${c}it in a legendary land | ||
all rocks and lavender and tufted grass, | ||
where it was settled on some sodden sand | ||
hard by the torrent of a mountain pass. | ||
""".trimIndent(), """ | ||
A Discovery | ||
|
||
I found i${c}t in a legendary land | ||
all rocks and lavender and tufted grass, | ||
where it was settled on some sodden sand | ||
hard by the torrent of a mountain pass. | ||
""".trimIndent(), CommandState.Mode.COMMAND, CommandState.SubMode.NONE) | ||
} | ||
|
||
fun `test simple motion with repeat`() { | ||
doTest("3l", """ | ||
A Discovery | ||
|
||
I found ${c}it in a legendary land | ||
all rocks and lavender and tufted grass, | ||
where it was settled on some sodden sand | ||
hard by the torrent of a mountain pass. | ||
""".trimIndent(), """ | ||
A Discovery | ||
|
||
I found it ${c}in a legendary land | ||
all rocks and lavender and tufted grass, | ||
where it was settled on some sodden sand | ||
hard by the torrent of a mountain pass. | ||
""".trimIndent(), CommandState.Mode.COMMAND, CommandState.SubMode.NONE) | ||
} | ||
|
||
fun `test simple motion to the end`() { | ||
doTest("3l", """ | ||
A Discovery | ||
|
||
I found it in a legendary lan${c}d | ||
all rocks and lavender and tufted grass, | ||
where it was settled on some sodden sand | ||
hard by the torrent of a mountain pass. | ||
""".trimIndent(), """ | ||
A Discovery | ||
|
||
I found it in a legendary lan${c}d | ||
all rocks and lavender and tufted grass, | ||
where it was settled on some sodden sand | ||
hard by the torrent of a mountain pass. | ||
""".trimIndent(), CommandState.Mode.COMMAND, CommandState.SubMode.NONE) | ||
} | ||
|
||
<<<<<<< HEAD | ||
@TestWithoutNeovim(SkipNeovimReason.NON_ASCII) | ||
======= | ||
fun `test virtual edit motion to the end`() { | ||
OptionsManager.virtualedit.set("onemore") | ||
doTest(parseKeys("3l"), """ | ||
A Discovery | ||
|
||
I found it in a legendary lan${c}d | ||
all rocks and lavender and tufted grass, | ||
where it was settled on some sodden sand | ||
hard by the torrent of a mountain pass. | ||
""".trimIndent(), """ | ||
A Discovery | ||
|
||
I found it in a legendary land${c} | ||
all rocks and lavender and tufted grass, | ||
where it was settled on some sodden sand | ||
hard by the torrent of a mountain pass. | ||
""".trimIndent(), CommandState.Mode.COMMAND, CommandState.SubMode.NONE) | ||
} | ||
|
||
>>>>>>> f7ff3089... Partial implementation of virtualedit config | ||
fun `test simple motion non-ascii`() { | ||
doTest("l", """ | ||
A Discovery | ||
|
||
I found it in a legendar${c}𝛁 land | ||
all rocks and lavender and tufted grass, | ||
where it was settled on some sodden sand | ||
hard by the torrent of a mountain pass. | ||
""".trimIndent(), """ | ||
A Discovery | ||
|
||
I found it in a legendar𝛁${c} land | ||
all rocks and lavender and tufted grass, | ||
where it was settled on some sodden sand | ||
hard by the torrent of a mountain pass. | ||
""".trimIndent(), CommandState.Mode.COMMAND, CommandState.SubMode.NONE) | ||
} | ||
|
||
@TestWithoutNeovim(SkipNeovimReason.NON_ASCII) | ||
fun `test simple motion emoji`() { | ||
doTest("l", """ | ||
A Discovery | ||
|
||
I found it in a legendar${c}🐔 land | ||
all rocks and lavender and tufted grass, | ||
where it was settled on some sodden sand | ||
hard by the torrent of a mountain pass. | ||
""".trimIndent(), """ | ||
A Discovery | ||
|
||
I found it in a legendar🐔${c} land | ||
all rocks and lavender and tufted grass, | ||
where it was settled on some sodden sand | ||
hard by the torrent of a mountain pass. | ||
""".trimIndent(), CommandState.Mode.COMMAND, CommandState.SubMode.NONE) | ||
} | ||
|
||
@TestWithoutNeovim(SkipNeovimReason.NON_ASCII) | ||
fun `test simple motion czech`() { | ||
doTest("l", """ | ||
A Discovery | ||
|
||
I found it in a legendar${c}ž land | ||
all rocks and lavender and tufted grass, | ||
where it was settled on some sodden sand | ||
hard by the torrent of a mountain pass. | ||
""".trimIndent(), """ | ||
A Discovery | ||
|
||
I found it in a legendarž${c} land | ||
all rocks and lavender and tufted grass, | ||
where it was settled on some sodden sand | ||
hard by the torrent of a mountain pass. | ||
""".trimIndent(), CommandState.Mode.COMMAND, CommandState.SubMode.NONE) | ||
} | ||
|
||
fun `test simple motion tab`() { | ||
doTest("l", """ | ||
A Discovery | ||
|
||
I found it in a legendar${c}. land | ||
all rocks and lavender and tufted grass, | ||
where it was settled on some sodden sand | ||
hard by the torrent of a mountain pass | ||
""".trimIndent().dotToTab(), """ | ||
A Discovery | ||
|
||
I found it in a legendar.${c} land | ||
all rocks and lavender and tufted grass, | ||
where it was settled on some sodden sand | ||
hard by the torrent of a mountain pass | ||
""".trimIndent().dotToTab(), CommandState.Mode.COMMAND, CommandState.SubMode.NONE) | ||
} | ||
|
||
fun `test char visual mode`() { | ||
doTest(listOf("v", "ll"), """ | ||
A Discovery | ||
|
||
I found it in a legendary lan${c}d | ||
all rocks and lavender and tufted grass, | ||
where it was settled on some sodden sand | ||
hard by the torrent of a mountain pass. | ||
""".trimIndent(), """ | ||
A Discovery | ||
|
||
I found it in a legendary lan${s}d${c}${se} | ||
all rocks and lavender and tufted grass, | ||
where it was settled on some sodden sand | ||
hard by the torrent of a mountain pass. | ||
""".trimIndent(), CommandState.Mode.VISUAL, CommandState.SubMode.VISUAL_CHARACTER) | ||
} | ||
|
||
fun `test block visual mode`() { | ||
doTest(listOf("<C-V>", "ll"), """ | ||
A Discovery | ||
|
||
I found it in a legendary lan${c}d | ||
all rocks and lavender and tufted grass, | ||
where it was settled on some sodden sand | ||
hard by the torrent of a mountain pass. | ||
""".trimIndent(), """ | ||
A Discovery | ||
|
||
I found it in a legendary lan${s}d${c}${se} | ||
all rocks and lavender and tufted grass, | ||
where it was settled on some sodden sand | ||
hard by the torrent of a mountain pass. | ||
""".trimIndent(), CommandState.Mode.VISUAL, CommandState.SubMode.VISUAL_BLOCK) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters