Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fleet #824

Merged
merged 46 commits into from
Feb 23, 2024
Merged

Fleet #824

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
355cfe0
Remove Editor from VimStateMachine
lippfi Feb 2, 2024
3738012
Listeners refactoring
lippfi Feb 2, 2024
363db05
Macro recording state is no longer per editor
lippfi Feb 3, 2024
6edfd8e
Remove deprecated showmode status bar text update that does not work …
lippfi Feb 3, 2024
5fc2f04
Remove mappingMode from MappingState
lippfi Feb 3, 2024
7966a6d
Create KeyHandlerState
lippfi Feb 3, 2024
31e7c49
Add equals & hashCode
lippfi Feb 4, 2024
282e581
Make state cloneable
lippfi Feb 4, 2024
02540eb
Pass KeyHandlerState as a method argument
lippfi Feb 4, 2024
00f5541
Add KeyProcessResult interface
lippfi Feb 5, 2024
15ae069
Make keyHandlerState argument not null
lippfi Feb 23, 2024
275c5d2
Add KeyProcessResultBuilder
lippfi Feb 23, 2024
19fa008
Use KeyProcessResultBuilder
lippfi Feb 23, 2024
f454d60
Add MutableBoolean to be able to pass and modify shouldRecord in methods
lippfi Feb 23, 2024
e3ec9c6
Add KeyConsumer
lippfi Feb 23, 2024
0ab32ca
Make MappingProcessor a KeyConsumer
lippfi Feb 23, 2024
4317506
Fix broken digraphSequence
lippfi Feb 23, 2024
9826f0a
Move some logic to CommandCountConsumer
lippfi Feb 23, 2024
46425a2
Move some logic to DeleteCommandConsumer
lippfi Feb 23, 2024
c501457
Move some logic to EditorResetConsumer
lippfi Feb 23, 2024
6741120
Move some logic to CharArgumentConsumer
lippfi Feb 23, 2024
1d9514a
Move some logic to RegisterConsumer
lippfi Feb 23, 2024
e033b08
Move some logic to DigraphConsumer
lippfi Feb 23, 2024
f801145
Update MappingInfo to match newer signature
lippfi Feb 23, 2024
eea3336
Move some logic to CommandConsumer
lippfi Feb 23, 2024
ddb1b80
Move some logic to CommandConsumer
lippfi Feb 23, 2024
74a8277
Move some logic to SelectRegisterConsumer
lippfi Feb 23, 2024
7842b15
Move some logic to ModeInputConsumer
lippfi Feb 23, 2024
e9bf066
Add synchronize blocks to minimize risk of concurrent key processing …
lippfi Feb 23, 2024
23fdadc
Fix test
lippfi Feb 23, 2024
ea62f22
Remove piece of code for handling bad commands
lippfi Feb 23, 2024
d3704d6
Cleanup after moving logic to other classes
lippfi Feb 23, 2024
2de933c
Make processKey public
lippfi Feb 7, 2024
db35c97
Move some editor methods to the base class
lippfi Feb 7, 2024
a7dfef6
Make LazyVimCommand open
lippfi Feb 7, 2024
924b741
Fix DigraphSequence cloning
lippfi Feb 8, 2024
c8113ee
Commit state after receiving unknown key
lippfi Feb 8, 2024
38bc914
Avoid using annotation-processors in vim-engine
lippfi Feb 9, 2024
795abd7
Add documentation
lippfi Feb 16, 2024
4aac113
Remove duplicate method
lippfi Feb 16, 2024
7523db1
Empty status bar message after each test
lippfi Feb 18, 2024
8eaa6df
Throw error instead of warning on state conflict
lippfi Feb 18, 2024
1a4333f
Move implementations to upper level
lippfi Feb 20, 2024
7d679e6
Merge branch 'refs/heads/master' into fleet
lippfi Feb 23, 2024
b737362
Update CaretVisualAttributesListener to use new Editor API
lippfi Feb 23, 2024
3c94091
Merge branch 'refs/heads/master' into fleet
lippfi Feb 23, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ publishChannels=eap

# Kotlinx serialization also uses some version of kotlin stdlib under the hood. However,
# we exclude this version from the dependency and use our own version of kotlin that is specified above
kotlinxSerializationVersion=1.5.1
kotlinxSerializationVersion=1.6.2

slackUrl=
youtrackToken=
Expand Down
16 changes: 8 additions & 8 deletions src/main/java/com/maddyhome/idea/vim/VimPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -211,22 +211,22 @@ public static boolean isNotEnabled() {
public static void setEnabled(final boolean enabled) {
if (isEnabled() == enabled) return;

if (!enabled) {
getInstance().turnOffPlugin(true);
}

getInstance().enabled = enabled;

if (enabled) {
getInstance().turnOnPlugin();
}

if (enabled) {
VimInjectorKt.getInjector().getListenersNotifier().notifyPluginTurnedOn();
} else {
VimInjectorKt.getInjector().getListenersNotifier().notifyPluginTurnedOff();
}

if (!enabled) {
getInstance().turnOffPlugin(true);
}

if (enabled) {
getInstance().turnOnPlugin();
}

StatusBarIconFactory.Util.INSTANCE.updateIcon();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public class VimTypedActionHandler(origHandler: TypedActionHandler) : TypedActio
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.vim, keyStroke, injector.executionContextManager.onEditor(editor.vim, context.vim))
handler.handleKey(editor.vim, keyStroke, injector.executionContextManager.onEditor(editor.vim, context.vim), handler.keyHandlerState)
if (startTime != null) {
val duration = System.currentTimeMillis() - startTime
LOG.info("VimTypedAction '$charTyped': $duration ms")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,12 @@ public class VimShortcutKeyAction : AnAction(), DumbAware, ActionRemoteBehaviorS
// 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(
val keyHandler = KeyHandler.getInstance()
keyHandler.handleKey(
editor.vim,
keyStroke,
injector.executionContextManager.onEditor(editor.vim, e.dataContext.vim),
keyHandler.keyHandlerState,
)
if (start != null) {
val duration = System.currentTimeMillis() - start
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import com.maddyhome.idea.vim.state.mode.SelectionType
public class CommandState(private val machine: VimStateMachine) {

public val isOperatorPending: Boolean
get() = machine.isOperatorPending
get() = machine.isOperatorPending(machine.mode)

public val mode: Mode
get() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,8 @@ public object VimExtensionFacade {
@JvmStatic
public fun executeNormalWithoutMapping(keys: List<KeyStroke>, editor: Editor) {
val context = injector.executionContextManager.onEditor(editor.vim)
keys.forEach { KeyHandler.getInstance().handleKey(editor.vim, it, context, false, false) }
val keyHandler = KeyHandler.getInstance()
keys.forEach { keyHandler.handleKey(editor.vim, it, context, false, false, keyHandler.keyHandlerState) }
}

/** Returns a single key stroke from the user input similar to 'getchar()'. */
Expand All @@ -159,7 +160,7 @@ public object VimExtensionFacade {
LOG.trace("Unit test mode is active")
val mappingStack = KeyHandler.getInstance().keyStack
mappingStack.feedSomeStroke() ?: TestInputModel.getInstance(editor).nextKeyStroke()?.also {
if (editor.vim.vimStateMachine.isRecording) {
if (injector.registerGroup.isRecording) {
KeyHandler.getInstance().modalEntryKeys += it
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ public void execute(@NotNull VimEditor editor, @NotNull ExecutionContext context

final ArgumentTextObjectHandler textObjectHandler = new ArgumentTextObjectHandler(isInner);
//noinspection DuplicatedCode
if (!vimStateMachine.isOperatorPending()) {
if (!vimStateMachine.isOperatorPending(editor.getMode())) {
editor.nativeCarets().forEach((VimCaret caret) -> {
final TextRange range = textObjectHandler.getRange(editor, caret, context, count, 0);
if (range != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ internal class Matchit : VimExtension {

// Normally we want to jump to the start of the matching pair. But when moving forward in operator
// pending mode, we want to include the entire match. isInOpPending makes that distinction.
val isInOpPending = commandState.isOperatorPending
val isInOpPending = commandState.isOperatorPending(editor.mode)

if (isInOpPending) {
val matchitAction = MatchitAction()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ import com.maddyhome.idea.vim.extension.VimExtensionFacade.putKeyMappingIfMissin
import com.maddyhome.idea.vim.extension.exportOperatorFunction
import com.maddyhome.idea.vim.group.visual.VimSelection
import com.maddyhome.idea.vim.helper.exitVisualMode
import com.maddyhome.idea.vim.state.mode.mode
import com.maddyhome.idea.vim.helper.vimStateMachine
import com.maddyhome.idea.vim.key.OperatorFunction
import com.maddyhome.idea.vim.newapi.IjVimEditor
Expand Down Expand Up @@ -163,13 +162,14 @@ internal class ReplaceWithRegister : VimExtension {
caretAfterInsertedText = false,
putToLine = -1,
)
val vimEditor = editor.vim
ClipboardOptionHelper.IdeaputDisabler().use {
VimPlugin.getPut().putText(
IjVimEditor(editor),
vimEditor,
injector.executionContextManager.onEditor(editor.vim),
putData,
operatorArguments = OperatorArguments(
editor.vimStateMachine?.isOperatorPending ?: false,
editor.vimStateMachine?.isOperatorPending(vimEditor.mode) ?: false,
0,
editor.vim.mode,
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ public void execute(@NotNull VimEditor editor, @NotNull ExecutionContext context

final EntireTextObjectHandler textObjectHandler = new EntireTextObjectHandler(ignoreLeadingAndTrailing);
//noinspection DuplicatedCode
if (!vimStateMachine.isOperatorPending()) {
if (!vimStateMachine.isOperatorPending(editor.getMode())) {
((IjVimEditor) editor).getEditor().getCaretModel().runForEachCaret((Caret caret) -> {
final TextRange range = textObjectHandler.getRange(editor, new IjVimCaret(caret), context, count, 0);
if (range != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ public void execute(@NotNull VimEditor editor, @NotNull ExecutionContext context

final IndentObjectHandler textObjectHandler = new IndentObjectHandler(includeAbove, includeBelow);

if (!vimStateMachine.isOperatorPending()) {
if (!vimStateMachine.isOperatorPending(editor.getMode())) {
((IjVimEditor)editor).getEditor().getCaretModel().runForEachCaret((Caret caret) -> {
final TextRange range = textObjectHandler.getRange(vimEditor, new IjVimCaret(caret), context, count, 0);
if (range != null) {
Expand Down
14 changes: 13 additions & 1 deletion src/main/java/com/maddyhome/idea/vim/group/EditorGroup.java
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ public void editorCreated(@NotNull Editor editor) {
switchToInsertMode.run();
}
});
updateCaretsVisualAttributes(editor);
updateCaretsVisualAttributes(new IjVimEditor(editor));
}

public void editorDeinit(@NotNull Editor editor, boolean isReleased) {
Expand Down Expand Up @@ -288,6 +288,18 @@ public void notifyIdeaJoin(@NotNull VimEditor editor) {
notifyIdeaJoin(((IjVimEditor) editor).getEditor().getProject(), editor);
}

@Override
public void updateCaretsVisualAttributes(@NotNull VimEditor editor) {
Editor ijEditor = ((IjVimEditor) editor).getEditor();
CaretVisualAttributesHelperKt.updateCaretsVisualAttributes(ijEditor);
}

@Override
public void updateCaretsVisualPosition(@NotNull VimEditor editor) {
Editor ijEditor = ((IjVimEditor) editor).getEditor();
CaretVisualAttributesHelperKt.updateCaretsVisualAttributes(ijEditor);
}

public static class NumberChangeListener implements EffectiveOptionValueChangeListener {
public static NumberChangeListener INSTANCE = new NumberChangeListener();

Expand Down
4 changes: 3 additions & 1 deletion src/main/java/com/maddyhome/idea/vim/group/MacroGroup.kt
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import com.intellij.openapi.diagnostic.logger
import com.intellij.openapi.progress.ProcessCanceledException
import com.intellij.openapi.progress.ProgressManager
import com.intellij.openapi.progress.util.PotemkinProgress
import com.maddyhome.idea.vim.KeyHandler
import com.maddyhome.idea.vim.KeyHandler.Companion.getInstance
import com.maddyhome.idea.vim.api.ExecutionContext
import com.maddyhome.idea.vim.api.VimEditor
Expand Down Expand Up @@ -77,11 +78,12 @@ internal class MacroGroup : VimMacroBase() {
} catch (e: ProcessCanceledException) {
return@runnable
}
val keyHandler = KeyHandler.getInstance()
ProgressManager.getInstance().executeNonCancelableSection {
// Prevent autocompletion during macros.
// See https://github.com/JetBrains/ideavim/pull/772 for details
CompletionServiceImpl.setCompletionPhase(CompletionPhase.NoCompletion)
getInstance().handleKey(editor, key, context)
keyHandler.handleKey(editor, key, context, keyHandler.keyHandlerState)
}
if (injector.messages.isError()) return@runnable
}
Expand Down
25 changes: 14 additions & 11 deletions src/main/java/com/maddyhome/idea/vim/group/ProcessGroup.kt
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import com.intellij.openapi.progress.ProgressManager
import com.intellij.util.execution.ParametersListUtil
import com.intellij.util.text.CharSequenceReader
import com.maddyhome.idea.vim.KeyHandler.Companion.getInstance
import com.maddyhome.idea.vim.KeyProcessResult
import com.maddyhome.idea.vim.VimPlugin
import com.maddyhome.idea.vim.api.ExecutionContext
import com.maddyhome.idea.vim.api.VimEditor
Expand All @@ -37,7 +38,6 @@ import com.maddyhome.idea.vim.state.mode.Mode
import com.maddyhome.idea.vim.state.mode.Mode.NORMAL
import com.maddyhome.idea.vim.state.mode.Mode.VISUAL
import com.maddyhome.idea.vim.state.mode.ReturnableFromCmd
import com.maddyhome.idea.vim.state.mode.mode
import com.maddyhome.idea.vim.ui.ex.ExEntryPanel
import com.maddyhome.idea.vim.vimscript.model.CommandLineVimLContext
import java.io.BufferedWriter
Expand Down Expand Up @@ -85,24 +85,27 @@ public class ProcessGroup : VimProcessGroupBase() {
modeBeforeCommandProcessing = currentMode
val initText = getRange(editor, cmd)
injector.markService.setVisualSelectionMarks(editor)
editor.vimStateMachine.mode = Mode.CMD_LINE(currentMode)
editor.mode = Mode.CMD_LINE(currentMode)
val panel = ExEntryPanel.getInstance()
panel.activate(editor.ij, context.ij, ":", initText, 1)
}

public override fun processExKey(editor: VimEditor, stroke: KeyStroke): Boolean {
public override fun processExKey(editor: VimEditor, stroke: KeyStroke, processResultBuilder: KeyProcessResult.KeyProcessResultBuilder): Boolean {
// This will only get called if somehow the key focus ended up in the editor while the ex entry window
// is open. So I'll put focus back in the editor and process the key.

val panel = ExEntryPanel.getInstance()
if (panel.isActive) {
requestFocus(panel.entry)
panel.handleKey(stroke)

processResultBuilder.addExecutionStep { _, _, _ ->
requestFocus(panel.entry)
panel.handleKey(stroke)
}
return true
} else {
getInstance(editor).mode = NORMAL()
getInstance().reset(editor)
processResultBuilder.addExecutionStep { _, lambdaEditor, _ ->
lambdaEditor.mode = NORMAL()
getInstance().reset(lambdaEditor)
}
return false
}
}
Expand All @@ -112,7 +115,7 @@ public class ProcessGroup : VimProcessGroupBase() {
panel.deactivate(true)
var res = true
try {
getInstance(editor).mode = NORMAL()
editor.mode = NORMAL()

logger.debug("processing command")

Expand Down Expand Up @@ -152,7 +155,7 @@ public class ProcessGroup : VimProcessGroupBase() {
}

public override fun cancelExEntry(editor: VimEditor, resetCaret: Boolean) {
editor.vimStateMachine.mode = NORMAL()
editor.mode = NORMAL()
getInstance().reset(editor)
val panel = ExEntryPanel.getInstance()
panel.deactivate(true, resetCaret)
Expand All @@ -162,7 +165,7 @@ public class ProcessGroup : VimProcessGroupBase() {
val initText = getRange(editor, cmd) + "!"
val currentMode = editor.mode
check(currentMode is ReturnableFromCmd) { "Cannot enable cmd mode from $currentMode" }
editor.vimStateMachine.mode = Mode.CMD_LINE(currentMode)
editor.mode = Mode.CMD_LINE(currentMode)
val panel = ExEntryPanel.getInstance()
panel.activate(editor.ij, context.ij, ":", initText, 1)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ internal object IdeaSelectionControl {

logger.debug("Some carets have selection. State before adjustment: ${editor.vim.mode}")

editor.vim.vimStateMachine.mode = Mode.NORMAL()
editor.vim.mode = Mode.NORMAL()

activateMode(editor, chooseSelectionMode(editor, selectionSource, true))
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,8 @@ internal abstract class VimKeyHandler(nextHandler: EditorActionHandler?) : Octop
override fun executeHandler(editor: Editor, caret: Caret?, dataContext: DataContext?) {
val enterKey = key(key)
val context = injector.executionContextManager.onEditor(editor.vim, dataContext?.vim)
KeyHandler.getInstance().handleKey(editor.vim, enterKey, context)
val keyHandler = KeyHandler.getInstance()
keyHandler.handleKey(editor.vim, enterKey, context, keyHandler.keyHandlerState)
}

override fun isHandlerEnabled(editor: Editor, dataContext: DataContext?): Boolean {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,17 @@ import com.maddyhome.idea.vim.VimPlugin
import com.maddyhome.idea.vim.api.VimEditor
import com.maddyhome.idea.vim.api.globalOptions
import com.maddyhome.idea.vim.api.injector
import com.maddyhome.idea.vim.common.IsReplaceCharListener
import com.maddyhome.idea.vim.common.ModeChangeListener
import com.maddyhome.idea.vim.newapi.IjVimEditor
import com.maddyhome.idea.vim.newapi.ij
import com.maddyhome.idea.vim.newapi.vim
import com.maddyhome.idea.vim.options.EffectiveOptionValueChangeListener
import com.maddyhome.idea.vim.options.helpers.GuiCursorMode
import com.maddyhome.idea.vim.options.helpers.GuiCursorOptionHelper
import com.maddyhome.idea.vim.options.helpers.GuiCursorType
import com.maddyhome.idea.vim.state.mode.Mode
import com.maddyhome.idea.vim.state.mode.inBlockSelection
import com.maddyhome.idea.vim.state.mode.mode
import org.jetbrains.annotations.TestOnly
import java.awt.Color

Expand Down Expand Up @@ -138,3 +141,31 @@ private object AttributesCache {

@TestOnly
internal fun getGuiCursorMode(editor: Editor) = editor.guicursorMode()

public class CaretVisualAttributesListener : IsReplaceCharListener, ModeChangeListener {
override fun isReplaceCharChanged(editor: VimEditor) {
updateCaretsVisual(editor)
}

override fun modeChanged(editor: VimEditor, oldMode: Mode) {
updateCaretsVisual(editor)
}

private fun updateCaretsVisual(editor: VimEditor) {
if (injector.globalOptions().ideaglobalmode) {
updateAllEditorsCaretsVisual()
} else {
val ijEditor = (editor as IjVimEditor).editor
ijEditor.updateCaretsVisualAttributes()
ijEditor.updateCaretsVisualPosition()
}
}

public fun updateAllEditorsCaretsVisual() {
injector.editorGroup.getEditors().forEach { editor ->
val ijEditor = (editor as IjVimEditor).editor
ijEditor.updateCaretsVisualAttributes()
ijEditor.updateCaretsVisualPosition()
}
}
}
12 changes: 6 additions & 6 deletions src/main/java/com/maddyhome/idea/vim/helper/ModeExtensions.kt
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,15 @@ internal fun Editor.exitSelectMode(adjustCaretPosition: Boolean) {
val returnTo = this.vim.vimStateMachine.mode.returnTo
when (returnTo) {
ReturnTo.INSERT -> {
this.vim.vimStateMachine.mode = Mode.INSERT
this.vim.mode = Mode.INSERT
}

ReturnTo.REPLACE -> {
this.vim.vimStateMachine.mode = Mode.REPLACE
this.vim.mode = Mode.REPLACE
}

null -> {
this.vim.vimStateMachine.mode = Mode.NORMAL()
this.vim.mode = Mode.NORMAL()
}
}
SelectionVimListenerSuppressor.lock().use {
Expand All @@ -67,15 +67,15 @@ internal fun VimEditor.exitSelectMode(adjustCaretPosition: Boolean) {
val returnTo = this.vimStateMachine.mode.returnTo
when (returnTo) {
ReturnTo.INSERT -> {
this.vimStateMachine.mode = Mode.INSERT
this.mode = Mode.INSERT
}

ReturnTo.REPLACE -> {
this.vimStateMachine.mode = Mode.REPLACE
this.mode = Mode.REPLACE
}

null -> {
this.vimStateMachine.mode = Mode.NORMAL()
this.mode = Mode.NORMAL()
}
}
SelectionVimListenerSuppressor.lock().use {
Expand Down
Loading
Loading