summaryrefslogtreecommitdiff
path: root/src/main/kotlin/me/kyren223/trident/utils/Utils.kt
blob: e688dd8d05f99a034d5a0a1dba95bcb78f79dc2a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
package me.kyren223.trident.utils

import com.maddyhome.idea.vim.api.VimEditor
import com.maddyhome.idea.vim.api.injector
import com.maddyhome.idea.vim.command.MappingMode
import com.maddyhome.idea.vim.command.OperatorArguments
import com.maddyhome.idea.vim.key.MappingOwner
import com.maddyhome.idea.vim.state.mode.Mode

fun setEditorMode(editor: VimEditor, mode: Mode) {
    val context = injector.executionContextManager.onEditor(editor, null)
    val operatorArguments = OperatorArguments(false, 0, mode)
    editor.exitInsertMode(context, operatorArguments)
    editor.vimChangeActionSwitchMode = Mode.NORMAL()
}

fun injectEnterToSelectMapping() {
    injector.keyGroup.putKeyMapping(
        MappingMode.NV,
        injector.parser.parseKeys("<cr>"),
        MappingOwner.Plugin.get("Trident"),
        injector.parser.parseKeys(":action TridentListSelect<cr>"),
        false
    )
}