mirror of
https://github.com/chylex/IntelliJ-IdeaVim.git
synced 2025-03-01 13:46:02 +01:00
Introduce ExecutionContext - abstract context holder
This commit is contained in:
parent
3571595838
commit
ce99c26c03
src
main/java/com/maddyhome/idea/vim
test/java/org/jetbrains/plugins/ideavim
@ -52,7 +52,6 @@ import com.maddyhome.idea.vim.handler.ActionBeanClass
|
||||
import com.maddyhome.idea.vim.handler.EditorActionHandlerBase
|
||||
import com.maddyhome.idea.vim.helper.ActionExecutor
|
||||
import com.maddyhome.idea.vim.helper.DigraphResult
|
||||
import com.maddyhome.idea.vim.helper.EditorDataContext.Companion.init
|
||||
import com.maddyhome.idea.vim.helper.MessageHelper.message
|
||||
import com.maddyhome.idea.vim.helper.RunnableHelper.runReadCommand
|
||||
import com.maddyhome.idea.vim.helper.RunnableHelper.runWriteCommand
|
||||
@ -67,8 +66,10 @@ import com.maddyhome.idea.vim.key.CommandNode
|
||||
import com.maddyhome.idea.vim.key.CommandPartNode
|
||||
import com.maddyhome.idea.vim.key.KeyMapping
|
||||
import com.maddyhome.idea.vim.key.Node
|
||||
import com.maddyhome.idea.vim.newapi.ExecutionContext
|
||||
import com.maddyhome.idea.vim.newapi.IjVimEditor
|
||||
import com.maddyhome.idea.vim.newapi.VimEditor
|
||||
import com.maddyhome.idea.vim.newapi.ij
|
||||
import com.maddyhome.idea.vim.ui.ShowCmd.update
|
||||
import com.maddyhome.idea.vim.ui.ex.ExEntryPanel
|
||||
import com.maddyhome.idea.vim.vimscript.model.datatypes.VimInt
|
||||
@ -120,7 +121,7 @@ class KeyHandler {
|
||||
* @param key The keystroke typed by the user
|
||||
* @param context The data context
|
||||
*/
|
||||
fun handleKey(editor: Editor, key: KeyStroke, context: DataContext) {
|
||||
fun handleKey(editor: Editor, key: KeyStroke, context: ExecutionContext) {
|
||||
handleKey(IjVimEditor(editor), key, context, allowKeyMappings = true, mappingCompleted = false)
|
||||
}
|
||||
|
||||
@ -135,7 +136,7 @@ class KeyHandler {
|
||||
fun handleKey(
|
||||
editor: IjVimEditor,
|
||||
key: KeyStroke,
|
||||
context: DataContext,
|
||||
context: ExecutionContext,
|
||||
allowKeyMappings: Boolean,
|
||||
mappingCompleted: Boolean,
|
||||
) {
|
||||
@ -232,7 +233,7 @@ class KeyHandler {
|
||||
|
||||
fun finishedCommandPreparation(
|
||||
editor: IjVimEditor,
|
||||
context: DataContext,
|
||||
context: ExecutionContext,
|
||||
editorState: CommandState,
|
||||
commandBuilder: CommandBuilder,
|
||||
key: KeyStroke?,
|
||||
@ -277,7 +278,7 @@ class KeyHandler {
|
||||
private fun handleEditorReset(
|
||||
editor: IjVimEditor,
|
||||
key: KeyStroke,
|
||||
context: DataContext,
|
||||
context: ExecutionContext,
|
||||
editorState: CommandState,
|
||||
) {
|
||||
val commandBuilder = editorState.commandBuilder
|
||||
@ -292,7 +293,7 @@ class KeyHandler {
|
||||
val executed = Ref.create<Boolean>()
|
||||
CommandProcessor.getInstance()
|
||||
.executeCommand(editor.editor.project,
|
||||
{ executed.set(ActionExecutor.executeAction(IdeActions.ACTION_EDITOR_ESCAPE, context)) },
|
||||
{ executed.set(ActionExecutor.executeAction(IdeActions.ACTION_EDITOR_ESCAPE, context.ij)) },
|
||||
"", null)
|
||||
indicateError = !executed.get()
|
||||
}
|
||||
@ -307,7 +308,7 @@ class KeyHandler {
|
||||
private fun handleKeyMapping(
|
||||
editor: IjVimEditor,
|
||||
key: KeyStroke,
|
||||
context: DataContext,
|
||||
context: ExecutionContext,
|
||||
mappingCompleted: Boolean,
|
||||
): Boolean {
|
||||
LOG.debug("Start processing key mappings.")
|
||||
@ -334,7 +335,7 @@ class KeyHandler {
|
||||
// be processed as normal.
|
||||
val mappingProcessed =
|
||||
handleUnfinishedMappingSequence(editor, mappingState, mapping, mappingCompleted) ||
|
||||
handleCompleteMappingSequence(editor.editor, context, mappingState, mapping, key) ||
|
||||
handleCompleteMappingSequence(editor, context, mappingState, mapping, key) ||
|
||||
handleAbandonedMappingSequence(editor, mappingState, context)
|
||||
LOG.debug { "Finish mapping processing. Return $mappingProcessed" }
|
||||
|
||||
@ -351,7 +352,7 @@ class KeyHandler {
|
||||
}
|
||||
|
||||
private fun handleUnfinishedMappingSequence(
|
||||
editor: IjVimEditor,
|
||||
editor: VimEditor,
|
||||
mappingState: MappingState,
|
||||
mapping: KeyMapping,
|
||||
mappingCompleted: Boolean,
|
||||
@ -384,22 +385,23 @@ class KeyHandler {
|
||||
// but before invoke later is handled. This is a rare case, so I'll just add a check to isPluginMapping.
|
||||
// But this "unexpected behaviour" exists and it would be better not to relay on mutable state with delays.
|
||||
// https://youtrack.jetbrains.com/issue/VIM-2392
|
||||
val ijEditor = (editor as IjVimEditor).editor
|
||||
mappingState.startMappingTimer { actionEvent: ActionEvent? ->
|
||||
application.invokeLater(
|
||||
{
|
||||
LOG.debug("Delayed mapping timer call")
|
||||
val unhandledKeys = mappingState.detachKeys()
|
||||
if (editor.editor.isDisposed || isPluginMapping(unhandledKeys)) {
|
||||
if (ijEditor.isDisposed || isPluginMapping(unhandledKeys)) {
|
||||
LOG.debug("Abandon mapping timer")
|
||||
return@invokeLater
|
||||
}
|
||||
LOG.trace("Processing unhandled keys...")
|
||||
for (keyStroke in unhandledKeys) {
|
||||
handleKey(editor, keyStroke, init(editor.editor, null),
|
||||
handleKey(editor, keyStroke, ExecutionContext.onEditor(editor),
|
||||
allowKeyMappings = true,
|
||||
mappingCompleted = true)
|
||||
}
|
||||
}, ModalityState.stateForComponent(editor.editor.component))
|
||||
}, ModalityState.stateForComponent(ijEditor.component))
|
||||
}
|
||||
}
|
||||
LOG.trace("Unfinished mapping processing finished")
|
||||
@ -407,8 +409,8 @@ class KeyHandler {
|
||||
}
|
||||
|
||||
private fun handleCompleteMappingSequence(
|
||||
editor: Editor,
|
||||
context: DataContext,
|
||||
editor: IjVimEditor,
|
||||
context: ExecutionContext,
|
||||
mappingState: MappingState,
|
||||
mapping: KeyMapping,
|
||||
key: KeyStroke,
|
||||
@ -441,10 +443,10 @@ class KeyHandler {
|
||||
return false
|
||||
}
|
||||
mappingState.resetMappingSequence()
|
||||
val currentContext = init(editor, context)
|
||||
val currentContext = context.updateEditor(editor)
|
||||
LOG.trace("Executing mapping info")
|
||||
try {
|
||||
mappingInfo.execute(editor, context)
|
||||
mappingInfo.execute(editor.editor, context.ij)
|
||||
} catch (e: Exception) {
|
||||
VimPlugin.showMessage(e.message)
|
||||
VimPlugin.indicateError()
|
||||
@ -464,7 +466,7 @@ class KeyHandler {
|
||||
// If we've just evaluated the previous key sequence, make sure to also handle the current key
|
||||
if (mappingInfo !== currentMappingInfo) {
|
||||
LOG.trace("Evaluating the current key")
|
||||
handleKey(IjVimEditor(editor), key, currentContext, allowKeyMappings = true, false)
|
||||
handleKey(editor, key, currentContext, allowKeyMappings = true, false)
|
||||
}
|
||||
LOG.trace("Success processing of mapping")
|
||||
return true
|
||||
@ -473,7 +475,7 @@ class KeyHandler {
|
||||
private fun handleAbandonedMappingSequence(
|
||||
editor: IjVimEditor,
|
||||
mappingState: MappingState,
|
||||
context: DataContext,
|
||||
context: ExecutionContext,
|
||||
): Boolean {
|
||||
LOG.debug("Processing abandoned mapping sequence")
|
||||
// The user has terminated a mapping sequence with an unexpected key
|
||||
@ -608,7 +610,7 @@ class KeyHandler {
|
||||
private fun handleDigraph(
|
||||
editor: IjVimEditor,
|
||||
key: KeyStroke,
|
||||
context: DataContext,
|
||||
context: ExecutionContext,
|
||||
editorState: CommandState,
|
||||
): Boolean {
|
||||
LOG.debug("Handling digraph")
|
||||
@ -678,7 +680,7 @@ class KeyHandler {
|
||||
|
||||
private fun executeCommand(
|
||||
editor: IjVimEditor,
|
||||
context: DataContext,
|
||||
context: ExecutionContext,
|
||||
editorState: CommandState,
|
||||
) {
|
||||
LOG.trace("Command execution")
|
||||
@ -707,7 +709,7 @@ class KeyHandler {
|
||||
IdeEventQueue.getInstance().flushDelayedKeyEvents()
|
||||
}
|
||||
if (ApplicationManager.getApplication().isDispatchThread) {
|
||||
val action: Runnable = ActionRunner(editor.editor, context, command, operatorArguments)
|
||||
val action: Runnable = ActionRunner(editor.editor, context.ij, command, operatorArguments)
|
||||
val cmdAction = command.action
|
||||
val name = cmdAction.id
|
||||
if (type.isWrite) {
|
||||
@ -721,7 +723,8 @@ class KeyHandler {
|
||||
}
|
||||
|
||||
private fun handleCommandNode(
|
||||
editor: IjVimEditor, context: DataContext,
|
||||
editor: IjVimEditor,
|
||||
context: ExecutionContext,
|
||||
key: KeyStroke,
|
||||
node: CommandNode<ActionBeanClass>,
|
||||
editorState: CommandState,
|
||||
@ -780,7 +783,7 @@ class KeyHandler {
|
||||
|
||||
private fun startWaitingForArgument(
|
||||
editor: Editor,
|
||||
context: DataContext,
|
||||
context: ExecutionContext,
|
||||
key: Char,
|
||||
action: EditorActionHandlerBase,
|
||||
argument: Argument.Type,
|
||||
@ -808,7 +811,7 @@ class KeyHandler {
|
||||
Argument.Type.EX_STRING -> {
|
||||
// The current Command expects an EX_STRING argument. E.g. SearchEntry(Fwd|Rev)Action. This won't execute until
|
||||
// state hits READY. Start the ex input field, push CMD_LINE mode and wait for the argument.
|
||||
VimPlugin.getProcess().startSearchCommand(editor, context, commandBuilder.count, key)
|
||||
VimPlugin.getProcess().startSearchCommand(editor, context.ij, commandBuilder.count, key)
|
||||
commandBuilder.commandState = CurrentCommandState.NEW_COMMAND
|
||||
editorState.pushModes(CommandState.Mode.CMD_LINE, CommandState.SubMode.NONE)
|
||||
}
|
||||
|
@ -27,6 +27,7 @@ import com.intellij.openapi.progress.ProcessCanceledException
|
||||
import com.maddyhome.idea.vim.helper.EditorDataContext
|
||||
import com.maddyhome.idea.vim.helper.isIdeaVimDisabledHere
|
||||
import com.maddyhome.idea.vim.key.KeyHandlerKeeper
|
||||
import com.maddyhome.idea.vim.newapi.vim
|
||||
import com.maddyhome.idea.vim.vimscript.services.OptionConstants
|
||||
import com.maddyhome.idea.vim.vimscript.services.OptionService
|
||||
import java.awt.event.KeyAdapter
|
||||
@ -73,7 +74,7 @@ class VimTypedActionHandler(origHandler: TypedActionHandler) : TypedActionHandle
|
||||
val modifiers = if (charTyped == ' ' && VimKeyListener.isSpaceShift) KeyEvent.SHIFT_DOWN_MASK else 0
|
||||
val keyStroke = KeyStroke.getKeyStroke(charTyped, modifiers)
|
||||
val startTime = if (traceTime) System.currentTimeMillis() else null
|
||||
handler.handleKey(editor, keyStroke, EditorDataContext.init(editor, context))
|
||||
handler.handleKey(editor, keyStroke, EditorDataContext.init(editor, context).vim)
|
||||
if (startTime != null) {
|
||||
val duration = System.currentTimeMillis() - startTime
|
||||
LOG.info("VimTypedAction '$charTyped': $duration ms")
|
||||
|
@ -49,6 +49,7 @@ import com.maddyhome.idea.vim.key.ShortcutOwnerInfo
|
||||
import com.maddyhome.idea.vim.listener.AceJumpService
|
||||
import com.maddyhome.idea.vim.listener.AppCodeTemplates.appCodeTemplateCaptured
|
||||
import com.maddyhome.idea.vim.newapi.IjVimEditor
|
||||
import com.maddyhome.idea.vim.newapi.vim
|
||||
import com.maddyhome.idea.vim.vimscript.model.datatypes.VimDataType
|
||||
import com.maddyhome.idea.vim.vimscript.model.datatypes.VimString
|
||||
import com.maddyhome.idea.vim.vimscript.model.options.OptionChangeListener
|
||||
@ -79,7 +80,7 @@ class VimShortcutKeyAction : AnAction(), DumbAware/*, LightEditCompatible*/ {
|
||||
// Should we use HelperKt.getTopLevelEditor(editor) here, as we did in former EditorKeyHandler?
|
||||
try {
|
||||
val start = if (traceTime) System.currentTimeMillis() else null
|
||||
KeyHandler.getInstance().handleKey(editor, keyStroke, EditorDataContext.init(editor, e.dataContext))
|
||||
KeyHandler.getInstance().handleKey(editor, keyStroke, EditorDataContext.init(editor, e.dataContext).vim)
|
||||
if (start != null) {
|
||||
val duration = System.currentTimeMillis() - start
|
||||
LOG.info("VimShortcut update '$keyStroke': $duration ms")
|
||||
|
@ -25,6 +25,7 @@ import com.maddyhome.idea.vim.command.Argument
|
||||
import com.maddyhome.idea.vim.command.Command
|
||||
import com.maddyhome.idea.vim.command.OperatorArguments
|
||||
import com.maddyhome.idea.vim.handler.VimActionHandler
|
||||
import com.maddyhome.idea.vim.newapi.vim
|
||||
import javax.swing.KeyStroke
|
||||
|
||||
class InsertCompletedDigraphAction : VimActionHandler.SingleExecution() {
|
||||
@ -34,7 +35,7 @@ class InsertCompletedDigraphAction : VimActionHandler.SingleExecution() {
|
||||
override fun execute(editor: Editor, context: DataContext, cmd: Command, operatorArguments: OperatorArguments): Boolean {
|
||||
// The converted digraph character has been captured as an argument, push it back through key handler
|
||||
val keyStroke = KeyStroke.getKeyStroke(cmd.argument!!.character)
|
||||
KeyHandler.getInstance().handleKey(editor, keyStroke, context)
|
||||
KeyHandler.getInstance().handleKey(editor, keyStroke, context.vim)
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
@ -25,6 +25,7 @@ import com.maddyhome.idea.vim.command.Argument
|
||||
import com.maddyhome.idea.vim.command.Command
|
||||
import com.maddyhome.idea.vim.command.OperatorArguments
|
||||
import com.maddyhome.idea.vim.handler.VimActionHandler
|
||||
import com.maddyhome.idea.vim.newapi.vim
|
||||
import javax.swing.KeyStroke
|
||||
|
||||
class InsertCompletedLiteralAction : VimActionHandler.SingleExecution() {
|
||||
@ -34,7 +35,7 @@ class InsertCompletedLiteralAction : VimActionHandler.SingleExecution() {
|
||||
override fun execute(editor: Editor, context: DataContext, cmd: Command, operatorArguments: OperatorArguments): Boolean {
|
||||
// The converted literal character has been captured as an argument, push it back through key handler
|
||||
val keyStroke = KeyStroke.getKeyStroke(cmd.argument!!.character)
|
||||
KeyHandler.getInstance().handleKey(editor, keyStroke, context)
|
||||
KeyHandler.getInstance().handleKey(editor, keyStroke, context.vim)
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
@ -98,7 +98,7 @@ object VimExtensionFacade {
|
||||
@JvmStatic
|
||||
fun executeNormalWithoutMapping(keys: List<KeyStroke>, editor: Editor) {
|
||||
val context = EditorDataContext.init(editor)
|
||||
keys.forEach { KeyHandler.getInstance().handleKey(editor.vim, it, context, false, false) }
|
||||
keys.forEach { KeyHandler.getInstance().handleKey(editor.vim, it, context.vim, false, false) }
|
||||
}
|
||||
|
||||
/** Returns a single key stroke from the user input similar to 'getchar()'. */
|
||||
|
@ -64,9 +64,7 @@ import com.maddyhome.idea.vim.key.KeyHandlerKeeper;
|
||||
import com.maddyhome.idea.vim.listener.SelectionVimListenerSuppressor;
|
||||
import com.maddyhome.idea.vim.listener.VimInsertListener;
|
||||
import com.maddyhome.idea.vim.listener.VimListenerSuppressor;
|
||||
import com.maddyhome.idea.vim.newapi.ChangeGroupKt;
|
||||
import com.maddyhome.idea.vim.newapi.IjVimEditor;
|
||||
import com.maddyhome.idea.vim.newapi.VimEditor;
|
||||
import com.maddyhome.idea.vim.newapi.*;
|
||||
import com.maddyhome.idea.vim.option.StrictMode;
|
||||
import com.maddyhome.idea.vim.vimscript.model.datatypes.VimString;
|
||||
import com.maddyhome.idea.vim.vimscript.services.OptionConstants;
|
||||
@ -355,7 +353,7 @@ public class ChangeGroup {
|
||||
if (register != null) {
|
||||
final List<KeyStroke> keys = register.getKeys();
|
||||
for (KeyStroke k : keys) {
|
||||
processKey(new IjVimEditor(editor), context, k);
|
||||
processKey(new IjVimEditor(editor), new IjExecutionContext(context), k);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@ -900,7 +898,7 @@ public class ChangeGroup {
|
||||
* @return true if this was a regular character, false if not
|
||||
*/
|
||||
public boolean processKey(final @NotNull VimEditor editor,
|
||||
final @NotNull DataContext context,
|
||||
final @NotNull ExecutionContext context,
|
||||
final @NotNull KeyStroke key) {
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("processKey(" + key + ")");
|
||||
@ -921,17 +919,18 @@ public class ChangeGroup {
|
||||
return false;
|
||||
}
|
||||
|
||||
private void type(@NotNull VimEditor vimEditor, @NotNull DataContext context, char key) {
|
||||
private void type(@NotNull VimEditor vimEditor, @NotNull ExecutionContext context, char key) {
|
||||
Editor editor = ((IjVimEditor)vimEditor).getEditor();
|
||||
DataContext ijContext = ExecutionContextKt.getIj(context);
|
||||
final Document doc = editor.getDocument();
|
||||
CommandProcessor.getInstance().executeCommand(editor.getProject(), () -> ApplicationManager.getApplication()
|
||||
.runWriteAction(() -> KeyHandlerKeeper.getInstance().getOriginalHandler().execute(editor, key, context)), "", doc,
|
||||
.runWriteAction(() -> KeyHandlerKeeper.getInstance().getOriginalHandler().execute(editor, key, ijContext)), "", doc,
|
||||
UndoConfirmationPolicy.DEFAULT, doc);
|
||||
MotionGroup.scrollCaretIntoView(editor);
|
||||
}
|
||||
|
||||
public boolean processKeyInSelectMode(final @NotNull IjVimEditor editor,
|
||||
final @NotNull DataContext context,
|
||||
final @NotNull ExecutionContext context,
|
||||
final @NotNull KeyStroke key) {
|
||||
boolean res;
|
||||
try (VimListenerSuppressor.Locked ignored = SelectionVimListenerSuppressor.INSTANCE.lock()) {
|
||||
@ -941,7 +940,8 @@ public class ChangeGroup {
|
||||
KeyHandler.getInstance().reset(editor);
|
||||
|
||||
if (isPrintableChar(key.getKeyChar()) || activeTemplateWithLeftRightMotion(editor.getEditor(), key)) {
|
||||
VimPlugin.getChange().insertBeforeCursor(editor.getEditor(), context);
|
||||
DataContext ijContext = ExecutionContextKt.getIj(context);
|
||||
VimPlugin.getChange().insertBeforeCursor(editor.getEditor(), ijContext);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -32,6 +32,7 @@ import com.maddyhome.idea.vim.VimPlugin;
|
||||
import com.maddyhome.idea.vim.common.Register;
|
||||
import com.maddyhome.idea.vim.helper.MessageHelper;
|
||||
import com.maddyhome.idea.vim.helper.StringHelper;
|
||||
import com.maddyhome.idea.vim.newapi.IjExecutionContext;
|
||||
import com.maddyhome.idea.vim.vimscript.services.OptionConstants;
|
||||
import com.maddyhome.idea.vim.vimscript.services.OptionService;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@ -142,7 +143,7 @@ public class MacroGroup {
|
||||
logger.debug("processing key " + pos);
|
||||
}
|
||||
// Handle one keystroke then queue up the next key
|
||||
KeyHandler.getInstance().handleKey(editor, keys.get(pos), context);
|
||||
KeyHandler.getInstance().handleKey(editor, keys.get(pos), new IjExecutionContext(context));
|
||||
if (pos < keys.size() - 1) {
|
||||
playbackKeys(editor, context, project, keys, pos + 1, cnt, total);
|
||||
}
|
||||
@ -174,7 +175,7 @@ public class MacroGroup {
|
||||
return;
|
||||
}
|
||||
ProgressManager.getInstance().executeNonCancelableSection(() -> {
|
||||
KeyHandler.getInstance().handleKey(editor, key, context);
|
||||
KeyHandler.getInstance().handleKey(editor, key, new IjExecutionContext(context));
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -106,7 +106,7 @@ class ToKeysMappingInfo(
|
||||
for (keyStroke in toKeys) {
|
||||
val recursive = isRecursive && !(first && fromIsPrefix)
|
||||
val keyHandler = KeyHandler.getInstance()
|
||||
keyHandler.handleKey(editor.vim, keyStroke, editorDataContext, recursive, false)
|
||||
keyHandler.handleKey(editor.vim, keyStroke, editorDataContext.vim, recursive, false)
|
||||
first = false
|
||||
}
|
||||
}
|
||||
@ -134,7 +134,7 @@ class ToExpressionMappingInfo(
|
||||
for (keyStroke in toKeys) {
|
||||
val recursive = isRecursive && !(first && fromIsPrefix)
|
||||
val keyHandler = KeyHandler.getInstance()
|
||||
keyHandler.handleKey(editor.vim, keyStroke, editorDataContext, recursive, false)
|
||||
keyHandler.handleKey(editor.vim, keyStroke, editorDataContext.vim, recursive, false)
|
||||
first = false
|
||||
}
|
||||
}
|
||||
@ -182,7 +182,7 @@ class ToHandlerMappingInfo(
|
||||
invokeLater {
|
||||
KeyHandler.getInstance().finishedCommandPreparation(
|
||||
IjVimEditor(editor),
|
||||
context, CommandState.getInstance(editor), CommandState.getInstance(editor).commandBuilder, null, false)
|
||||
context.vim, CommandState.getInstance(editor), CommandState.getInstance(editor).commandBuilder, null, false)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,51 @@
|
||||
/*
|
||||
* IdeaVim - Vim emulator for IDEs based on the IntelliJ platform
|
||||
* Copyright (C) 2003-2022 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/>.
|
||||
*/
|
||||
|
||||
package com.maddyhome.idea.vim.newapi
|
||||
|
||||
import com.intellij.openapi.actionSystem.DataContext
|
||||
import com.maddyhome.idea.vim.helper.EditorDataContext
|
||||
|
||||
/**
|
||||
* This would be ideal if we could provide a typed solution, but sofar this is just a holder
|
||||
*/
|
||||
|
||||
interface ExecutionContext {
|
||||
val context: Any
|
||||
|
||||
// TODO: 10.02.2022 Not sure about this method
|
||||
fun updateEditor(editor: VimEditor): ExecutionContext
|
||||
|
||||
companion object {
|
||||
fun onEditor(editor: VimEditor): ExecutionContext {
|
||||
return IjExecutionContext(EditorDataContext.init((editor as IjVimEditor).editor, null))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
val ExecutionContext.ij: DataContext
|
||||
get() = (this as IjExecutionContext).context
|
||||
|
||||
class IjExecutionContext(override val context: DataContext) : ExecutionContext {
|
||||
override fun updateEditor(editor: VimEditor): ExecutionContext {
|
||||
return IjExecutionContext(EditorDataContext.init((editor as IjVimEditor).editor, context))
|
||||
}
|
||||
}
|
||||
|
||||
val DataContext.vim
|
||||
get() = IjExecutionContext(this)
|
@ -22,6 +22,7 @@ import com.intellij.openapi.diagnostic.logger
|
||||
import com.maddyhome.idea.vim.KeyHandler
|
||||
import com.maddyhome.idea.vim.VimPlugin
|
||||
import com.maddyhome.idea.vim.helper.SearchHelper
|
||||
import com.maddyhome.idea.vim.newapi.vim
|
||||
import java.awt.event.ActionEvent
|
||||
import java.awt.event.KeyEvent
|
||||
import javax.swing.Action
|
||||
@ -121,7 +122,7 @@ class CompleteEntryAction : TextAction(ExEditorKit.CompleteEntry) {
|
||||
// write action
|
||||
// * The key handler routines get the chance to clean up and reset state
|
||||
val entry = ExEntryPanel.getInstance().entry
|
||||
KeyHandler.getInstance().handleKey(entry.editor, stroke, entry.context)
|
||||
KeyHandler.getInstance().handleKey(entry.editor, stroke, entry.context.vim)
|
||||
}
|
||||
|
||||
companion object {
|
||||
|
@ -21,6 +21,7 @@ import com.intellij.openapi.diagnostic.debug
|
||||
import com.intellij.openapi.diagnostic.logger
|
||||
import com.maddyhome.idea.vim.KeyHandler
|
||||
import com.maddyhome.idea.vim.helper.EditorDataContext
|
||||
import com.maddyhome.idea.vim.newapi.vim
|
||||
import org.jetbrains.annotations.NonNls
|
||||
import java.awt.event.ActionEvent
|
||||
import java.awt.event.KeyEvent
|
||||
@ -134,7 +135,7 @@ object ExEditorKit : DefaultEditorKit() {
|
||||
if (target.useHandleKeyFromEx) {
|
||||
val entry = ExEntryPanel.getInstance().entry
|
||||
val editor = entry.editor
|
||||
KeyHandler.getInstance().handleKey(editor, key, EditorDataContext.init(editor, entry.context))
|
||||
KeyHandler.getInstance().handleKey(editor, key, EditorDataContext.init(editor, entry.context).vim)
|
||||
} else {
|
||||
val event = ActionEvent(e.source, e.id, c.toString(), e.getWhen(), e.modifiers)
|
||||
super.actionPerformed(event)
|
||||
|
@ -23,6 +23,7 @@ import com.intellij.openapi.actionSystem.KeyboardShortcut
|
||||
import com.intellij.openapi.project.DumbAwareAction
|
||||
import com.maddyhome.idea.vim.KeyHandler
|
||||
import com.maddyhome.idea.vim.helper.EditorDataContext
|
||||
import com.maddyhome.idea.vim.newapi.vim
|
||||
import java.awt.event.KeyEvent
|
||||
import javax.swing.KeyStroke
|
||||
|
||||
@ -44,7 +45,7 @@ class ExShortcutKeyAction(private val exEntryPanel: ExEntryPanel) : DumbAwareAct
|
||||
val keyStroke = getKeyStroke(e)
|
||||
if (keyStroke != null) {
|
||||
val editor = exEntryPanel.entry.editor
|
||||
KeyHandler.getInstance().handleKey(editor, keyStroke, EditorDataContext.init(editor, e.dataContext))
|
||||
KeyHandler.getInstance().handleKey(editor, keyStroke, EditorDataContext.init(editor, e.dataContext).vim)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -85,7 +85,7 @@ data class NormalCommand(val ranges: Ranges, val argument: String) : Command.Sin
|
||||
val keyHandler = KeyHandler.getInstance()
|
||||
keyHandler.reset(editor.vim)
|
||||
for (key in keys) {
|
||||
keyHandler.handleKey(editor.vim, key, context, useMappings, true)
|
||||
keyHandler.handleKey(editor.vim, key, context.vim, useMappings, true)
|
||||
}
|
||||
|
||||
// Exit if state leaves as insert or cmd_line
|
||||
|
@ -29,6 +29,7 @@ import com.maddyhome.idea.vim.group.visual.VimVisualTimer;
|
||||
import com.maddyhome.idea.vim.helper.EditorDataContext;
|
||||
import com.maddyhome.idea.vim.helper.RunnableHelper;
|
||||
import com.maddyhome.idea.vim.helper.TestInputModel;
|
||||
import com.maddyhome.idea.vim.newapi.IjExecutionContext;
|
||||
import com.maddyhome.idea.vim.newapi.IjVimEditor;
|
||||
import com.maddyhome.idea.vim.ui.ex.ExEntryPanel;
|
||||
import com.maddyhome.idea.vim.vimscript.services.OptionService;
|
||||
@ -99,7 +100,7 @@ public abstract class JavaVimTestCase extends JavaCodeInsightFixtureTestCase {
|
||||
exEntryPanel.handleKey(key);
|
||||
}
|
||||
else {
|
||||
keyHandler.handleKey(editor, key, dataContext);
|
||||
keyHandler.handleKey(editor, key, new IjExecutionContext(dataContext));
|
||||
}
|
||||
}
|
||||
}, null, null);
|
||||
|
@ -706,7 +706,7 @@ abstract class VimTestCase : UsefulTestCase() {
|
||||
val inputModel = TestInputModel.getInstance(editor)
|
||||
var key = inputModel.nextKeyStroke()
|
||||
while (key != null) {
|
||||
keyHandler.handleKey(editor, key, dataContext)
|
||||
keyHandler.handleKey(editor, key, dataContext.vim)
|
||||
key = inputModel.nextKeyStroke()
|
||||
}
|
||||
},
|
||||
|
Loading…
Reference in New Issue
Block a user