1
0
mirror of https://github.com/chylex/IntelliJ-IdeaVim.git synced 2025-05-09 00:34:07 +02:00

Show additional Insert modes in showmode widget

This commit is contained in:
Matt Ellis 2024-12-27 10:27:08 +00:00 committed by Alex Pláte
parent eaad93903b
commit dc5ef487d2
2 changed files with 79 additions and 10 deletions
src/main/java/com/maddyhome/idea/vim/ui/widgets/mode
vim-engine/src/main/kotlin/com/maddyhome/idea/vim/state/mode

View File

@ -34,7 +34,11 @@ class VimModeWidget(val project: Project) : CustomStatusBarWidget, VimStatusBarW
private companion object {
private const val INSERT = "INSERT"
private const val NORMAL = "NORMAL"
private const val INSERT_NORMAL = "(insert)"
private const val INSERT_PENDING_PREFIX = "(insert) "
private const val REPLACE = "REPLACE"
private const val REPLACE_NORMAL = "(replace)"
private const val REPLACE_PENDING_PREFIX = "(replace) "
private const val COMMAND = "COMMAND"
private const val VISUAL = "VISUAL"
private const val VISUAL_LINE = "V-LINE"
@ -43,6 +47,7 @@ class VimModeWidget(val project: Project) : CustomStatusBarWidget, VimStatusBarW
private const val SELECT_LINE = "S-LINE"
private const val SELECT_BLOCK = "S-BLOCK"
}
private val label = JBLabelWiderThan(setOf(REPLACE)).apply { isOpaque = true }
init {
@ -96,7 +101,7 @@ class VimModeWidget(val project: Project) : CustomStatusBarWidget, VimStatusBarW
return when (mode) {
Mode.INSERT -> INSERT
Mode.REPLACE -> REPLACE
is Mode.NORMAL -> NORMAL
is Mode.NORMAL -> getNormalModeText(mode)
is Mode.CMD_LINE -> COMMAND
is Mode.VISUAL -> getVisualModeText(mode)
is Mode.SELECT -> getSelectModeText(mode)
@ -104,16 +109,36 @@ class VimModeWidget(val project: Project) : CustomStatusBarWidget, VimStatusBarW
}
}
private fun getVisualModeText(mode: Mode.VISUAL) = when (mode.selectionType) {
SelectionType.CHARACTER_WISE -> VISUAL
SelectionType.LINE_WISE -> VISUAL_LINE
SelectionType.BLOCK_WISE -> VISUAL_BLOCK
private fun getNormalModeText(mode: Mode.NORMAL) = when {
mode.isInsertPending -> INSERT_NORMAL
mode.isReplacePending -> REPLACE_NORMAL
else -> NORMAL
}
private fun getSelectModeText(mode: Mode.SELECT) = when (mode.selectionType) {
SelectionType.CHARACTER_WISE -> SELECT
SelectionType.LINE_WISE -> SELECT_LINE
SelectionType.BLOCK_WISE -> SELECT_BLOCK
private fun getVisualModeText(mode: Mode.VISUAL): String {
val prefix = when {
mode.isInsertPending -> INSERT_PENDING_PREFIX
mode.isReplacePending -> REPLACE_PENDING_PREFIX
else -> ""
}
return prefix + when (mode.selectionType) {
SelectionType.CHARACTER_WISE -> VISUAL
SelectionType.LINE_WISE -> VISUAL_LINE
SelectionType.BLOCK_WISE -> VISUAL_BLOCK
}
}
private fun getSelectModeText(mode: Mode.SELECT): String {
val prefix = when {
mode.isInsertPending -> INSERT_PENDING_PREFIX
mode.isReplacePending -> REPLACE_PENDING_PREFIX
else -> ""
}
return prefix + when (mode.selectionType) {
SelectionType.CHARACTER_WISE -> SELECT
SelectionType.LINE_WISE -> SELECT_LINE
SelectionType.BLOCK_WISE -> SELECT_BLOCK
}
}
private class JBLabelWiderThan(private val words: Collection<String>): JBLabel("", CENTER) {
@ -158,4 +183,4 @@ fun repaintModeWidget() {
}
}
}
}
}

View File

@ -57,6 +57,20 @@ sealed interface Mode {
data class NORMAL(private val originalMode: Mode? = null) : Mode {
override val returnTo: Mode
get() = originalMode ?: this
/**
* Returns true if Insert mode is pending, after the completion of the current Normal command. AKA "Insert Normal"
*
* When in Insert mode the `<C-O>` keystroke will temporarily switch to Normal for the duration of a single command.
*/
val isInsertPending = originalMode is INSERT
/**
* Returns true if Replace mode is pending, after the completion of the current Normal command.
*
* Like "Insert Normal", but with `<C-O>` used in Replace mode.
*/
val isReplacePending = originalMode is REPLACE
}
data class OP_PENDING(override val returnTo: Mode) : Mode {
@ -77,6 +91,21 @@ sealed interface Mode {
"VISUAL mode can be active only in NORMAL, INSERT or REPLACE modes, not ${returnTo.javaClass.simpleName}"
}
}
/**
* Returns true if Insert mode is pending, after the completion of the current Visual command. AKA "Insert Visual"
*
* Vim can enter Visual mode from Insert mode, either using shifted keys (based on `'keymodel'` and `'selectmode'`
* values) or via "Insert Normal" (`i<C-O>v`).
*/
val isInsertPending = returnTo is INSERT
/**
* Returns true if Replace mode is pending, after the completion of the current Visual command.
*
* Like "Insert Visual", but starting from (and returning to) Replace (`R<C-O>v`).
*/
val isReplacePending = returnTo is REPLACE
}
data class SELECT(val selectionType: SelectionType, override val returnTo: Mode = NORMAL()) : Mode {
@ -88,6 +117,21 @@ sealed interface Mode {
"SELECT mode can be active only in NORMAL, INSERT or REPLACE modes, not ${returnTo.javaClass.simpleName}"
}
}
/**
* Returns true if Insert mode is pending, after the completion of the current Visual command. AKA "Insert Visual"
*
* Vim can enter Select mode from Insert mode, either using shifted keys (based on `'keymodel'` and `'selectmode'`
* values) or via "Insert Normal" (`i<C-O>gh`).
*/
val isInsertPending = returnTo is INSERT
/**
* Returns true if Replace mode is pending, after the completion of the current Visual command.
*
* Like "Insert Select", but starting from (and returning to) Replace (e.g., `R<C-O>gh`).
*/
val isReplacePending = returnTo is REPLACE
}
object INSERT : Mode {