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

guicursor! #337

Merged
merged 36 commits into from
Oct 5, 2021
Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
646a89d
Refactor showMode update
citizenmatt Jun 4, 2021
2be0f5c
Reset caret visual position after mode changes
citizenmatt Jun 4, 2021
b50281f
Extract caret shape methods to helper
citizenmatt Jun 4, 2021
6c4bd9c
Refactor caret shape functions
citizenmatt Jun 4, 2021
e859b1c
Remove resetCaret
citizenmatt Jun 4, 2021
9c71b44
Update caret visual attributes when mode changes
citizenmatt Jun 5, 2021
55dedb4
Remove resetShape method
citizenmatt Jun 10, 2021
dfbec1f
Rename "bound" options to "bounded"
citizenmatt Jun 10, 2021
287ba70
Simplify BoundedListOption
citizenmatt Jun 10, 2021
e93a619
Make ListOption generic + create StringListOption
citizenmatt Jun 10, 2021
9f46e19
Fix typo
citizenmatt Jun 10, 2021
43620c2
Add guicursor option
citizenmatt Jun 10, 2021
9cf0a1a
Report errors while parsing guicursor option
citizenmatt Jun 11, 2021
8a55199
Add guicursor to dictionary
citizenmatt Jun 11, 2021
ccd792b
Provide hook for resetting cached values
citizenmatt Jun 28, 2021
d19c776
Minor refactor
citizenmatt Jun 28, 2021
ad19dc0
Use guicursor options to draw caret
citizenmatt Jun 28, 2021
b4d40fa
Rename assert method
citizenmatt Jun 28, 2021
a6087dd
Use replace mode caret for change character action
citizenmatt Jun 28, 2021
2f73dac
Force the caret visible when updating attributes
citizenmatt Jun 28, 2021
f051231
Use guicursor instead of editor cursor settings
citizenmatt Jun 28, 2021
64be751
Use guicursor options to draw ex caret
citizenmatt Jun 29, 2021
1caf380
Improve caret painting in command line
citizenmatt Jun 29, 2021
fe7dc49
Make ExShortcutKeyAction dumb aware
citizenmatt Jun 30, 2021
0288a0f
Use insert caret for select mode
citizenmatt Jun 30, 2021
0d840b2
Merge branch 'master' into feature/guicursor
citizenmatt Jun 30, 2021
d6a99d4
Update to latest EAP
citizenmatt Jun 30, 2021
91585e1
Run linters
citizenmatt Jun 30, 2021
d63e3da
Merge branch 'master' into feature/guicursor
citizenmatt Jul 28, 2021
70a45f3
Treat use block caret option as caret override
citizenmatt Jul 29, 2021
6ab5380
Add tests for caret attributes in nested modes
citizenmatt Aug 10, 2021
ae21727
Merge branch 'master' into feature/guicursor
citizenmatt Sep 27, 2021
74b0e3b
Merge branch 'master' into feature/guicursor
AlexPl292 Sep 29, 2021
c268407
Merge branch 'master' into feature/guicursor
AlexPl292 Sep 29, 2021
3fae2fd
isBlockCursor method doesn't work for UI tests at the moment
AlexPl292 Sep 29, 2021
ee74367
Merge branch 'master' into feature/guicursor
AlexPl292 Oct 5, 2021
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
4 changes: 4 additions & 0 deletions resources/messages/IdeaVimBundle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,10 @@ e_patnotf2=Pattern not found: {0}
unkopt=Unknown option: {0}
e_invarg=Invalid argument: {0}
E475=E475: Invalid argument: {0}
E545=E545: Missing colon: {0}
E546=E546: Illegal mode: {0}
E548=E548: Digit expected: {0}
E549=E549: Illegal percentage: {0}
E774=E774: 'operatorfunc' is empty

action.VimPluginToggle.text=Vim Emulator
Expand Down
5 changes: 0 additions & 5 deletions src/com/maddyhome/idea/vim/KeyHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,7 @@
import com.maddyhome.idea.vim.action.change.insert.InsertCompletedLiteralAction;
import com.maddyhome.idea.vim.action.macro.ToggleRecordingAction;
import com.maddyhome.idea.vim.command.*;
import com.maddyhome.idea.vim.group.ChangeGroup;
import com.maddyhome.idea.vim.group.RegisterGroup;
import com.maddyhome.idea.vim.group.visual.VisualGroupKt;
import com.maddyhome.idea.vim.handler.ActionBeanClass;
import com.maddyhome.idea.vim.handler.EditorActionHandlerBase;
import com.maddyhome.idea.vim.helper.*;
Expand Down Expand Up @@ -357,7 +355,6 @@ private void handleEditorReset(@NotNull Editor editor, @NotNull KeyStroke key, f
}
}
reset(editor);
ChangeGroup.resetCaret(editor, false);
}

private boolean handleKeyMapping(final @NotNull Editor editor,
Expand Down Expand Up @@ -883,7 +880,6 @@ public void fullReset(@NotNull Editor editor) {
if (registerGroup != null) {
registerGroup.resetRegister();
}
VisualGroupKt.updateCaretState(editor);
editor.getSelectionModel().removeSelection();
}

Expand Down Expand Up @@ -978,7 +974,6 @@ public void run() {
if (editorState.getSubMode() == CommandState.SubMode.SINGLE_COMMAND &&
(!cmd.getFlags().contains(CommandFlags.FLAG_EXPECT_MORE))) {
editorState.popModes();
VisualGroupKt.resetShape(CommandStateHelper.getMode(editor), editor);
}

if (editorState.getCommandBuilder().isDone()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import com.intellij.openapi.editor.Editor
import com.maddyhome.idea.vim.VimPlugin
import com.maddyhome.idea.vim.command.Command
import com.maddyhome.idea.vim.command.CommandState
import com.maddyhome.idea.vim.group.visual.updateCaretState
import com.maddyhome.idea.vim.handler.VimActionHandler
import com.maddyhome.idea.vim.helper.commandState
import com.maddyhome.idea.vim.helper.moveToInlayAwareOffset
Expand Down Expand Up @@ -60,7 +59,6 @@ class SelectToggleVisualMode : VimActionHandler.SingleExecution() {
}
}
}
updateCaretState(editor)
return true
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@ import com.maddyhome.idea.vim.VimPlugin
import com.maddyhome.idea.vim.command.Command
import com.maddyhome.idea.vim.command.CommandState
import com.maddyhome.idea.vim.handler.VimActionHandler
import com.maddyhome.idea.vim.option.ListOption
import com.maddyhome.idea.vim.option.OptionsManager.selectmode
import com.maddyhome.idea.vim.option.StringListOption

class VisualToggleBlockModeAction : VimActionHandler.SingleExecution() {
override val type: Command.Type = Command.Type.OTHER_READONLY

override fun execute(editor: Editor, context: DataContext, cmd: Command): Boolean {
val listOption: ListOption = selectmode
val listOption: StringListOption = selectmode
return if (listOption.contains("cmd")) {
VimPlugin.getVisualMotion().enterSelectMode(editor, CommandState.SubMode.VISUAL_BLOCK)
} else VimPlugin.getVisualMotion()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@ import com.maddyhome.idea.vim.VimPlugin
import com.maddyhome.idea.vim.command.Command
import com.maddyhome.idea.vim.command.CommandState
import com.maddyhome.idea.vim.handler.VimActionHandler
import com.maddyhome.idea.vim.option.ListOption
import com.maddyhome.idea.vim.option.OptionsManager.selectmode
import com.maddyhome.idea.vim.option.StringListOption

class VisualToggleCharacterModeAction : VimActionHandler.SingleExecution() {
override val type: Command.Type = Command.Type.OTHER_READONLY

override fun execute(editor: Editor, context: DataContext, cmd: Command): Boolean {
val listOption: ListOption = selectmode
val listOption: StringListOption = selectmode
return if (listOption.contains("cmd")) {
VimPlugin.getVisualMotion().enterSelectMode(editor, CommandState.SubMode.VISUAL_CHARACTER)
} else VimPlugin.getVisualMotion()
Expand Down
40 changes: 27 additions & 13 deletions src/com/maddyhome/idea/vim/command/CommandState.kt
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ import com.maddyhome.idea.vim.helper.DigraphSequence
import com.maddyhome.idea.vim.helper.MessageHelper
import com.maddyhome.idea.vim.helper.VimNlsSafe
import com.maddyhome.idea.vim.helper.noneOfEnum
import com.maddyhome.idea.vim.helper.updateCaretsVisualAttributes
import com.maddyhome.idea.vim.helper.updateCaretsVisualPosition
import com.maddyhome.idea.vim.helper.vimCommandState
import com.maddyhome.idea.vim.key.CommandPartNode
import com.maddyhome.idea.vim.option.OptionsManager.showmode
Expand All @@ -35,17 +37,17 @@ import java.util.*
import javax.swing.KeyStroke

/**
* Used to maintain state while entering a Vim command (operator, motion, text object, etc.)
* Used to maintain state before and while entering a Vim command (operator, motion, text object, etc.)
*/
class CommandState private constructor() {
class CommandState private constructor(private val editor: Editor) {
val commandBuilder = CommandBuilder(getKeyRootNode(MappingMode.NORMAL))
private val modeStates = Stack<ModeState>()
val mappingState = MappingState()
private val digraphSequence = DigraphSequence()
var isRecording = false
set(value) {
field = value
updateStatus()
doShowMode()
}
var isDotRepeatInProgress = false

Expand Down Expand Up @@ -78,17 +80,26 @@ class CommandState private constructor() {

fun pushModes(mode: Mode, submode: SubMode) {
val newModeState = ModeState(mode, submode)

logger.debug("Push new mode state: ${newModeState.toSimpleString()}")
logger.debug { "Stack of mode states before push: ${toSimpleString()}" }

val previousMode = currentModeState()
modeStates.push(newModeState)
setMappingMode()
updateStatus()

if (previousMode.mode != newModeState.mode) {
onModeChanged()
}
}

fun popModes() {
val popped = modeStates.pop()
setMappingMode()
updateStatus()
if (popped.mode != mode) {
onModeChanged()
}

logger.debug("Popped mode state: ${popped.toSimpleString()}")
logger.debug { "Stack of mode states after pop: ${toSimpleString()}" }
}
Expand All @@ -107,13 +118,18 @@ class CommandState private constructor() {

private fun resetModes() {
modeStates.clear()
onModeChanged()
setMappingMode()
}

private fun onModeChanged() {
AlexPl292 marked this conversation as resolved.
Show resolved Hide resolved
editor.updateCaretsVisualAttributes()
editor.updateCaretsVisualPosition()
doShowMode()
}

private fun setMappingMode() {
val modeState = currentModeState()
val newMappingMode = if (modeState.mode == Mode.OP_PENDING) MappingMode.OP_PENDING else modeToMappingMode(mode)
mappingState.mappingMode = newMappingMode
mappingState.mappingMode = modeToMappingMode(mode)
}

@Contract(pure = true)
Expand All @@ -124,7 +140,7 @@ class CommandState private constructor() {
Mode.VISUAL -> MappingMode.VISUAL
Mode.SELECT -> MappingMode.SELECT
Mode.CMD_LINE -> MappingMode.CMD_LINE
else -> error("Unexpected mode: $mode")
Mode.OP_PENDING -> MappingMode.OP_PENDING
}
}

Expand All @@ -137,7 +153,6 @@ class CommandState private constructor() {
val modeState = currentModeState()
popModes()
pushModes(modeState.mode, submode)
updateStatus()
}

fun startDigraphSequence() {
Expand Down Expand Up @@ -183,7 +198,6 @@ class CommandState private constructor() {
resetModes()
commandBuilder.resetInProgressCommandPart(getKeyRootNode(mappingState.mappingMode))
digraphSequence.reset()
updateStatus()
}

fun toSimpleString(): String = modeStates.joinToString { it.toSimpleString() }
Expand Down Expand Up @@ -262,7 +276,7 @@ class CommandState private constructor() {
return if (modeStates.size > 0) modeStates.peek() else defaultModeState
}

private fun updateStatus() {
private fun doShowMode() {
val msg = StringBuilder()
if (showmode.isSet) {
msg.append(getStatusString(modeStates.size - 1))
Expand Down Expand Up @@ -334,7 +348,7 @@ class CommandState private constructor() {
fun getInstance(editor: Editor): CommandState {
var res = editor.vimCommandState
if (res == null) {
res = CommandState()
res = CommandState(editor)
editor.vimCommandState = res
}
return res
Expand Down
13 changes: 12 additions & 1 deletion src/com/maddyhome/idea/vim/ex/ExExceptions.kt
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,18 @@
*/
package com.maddyhome.idea.vim.ex

open class ExException(s: String? = null) : Exception(s)
import com.maddyhome.idea.vim.helper.MessageHelper
import org.jetbrains.annotations.PropertyKey

open class ExException(s: String? = null) : Exception(s) {
var code: String? = null
private set

companion object {
fun message(@PropertyKey(resourceBundle = MessageHelper.BUNDLE) code: String, vararg params: Any) =
ExException(MessageHelper.message(code, *params)).apply { this.code = code }
}
}

class InvalidCommandException(message: String, cmd: String?) : ExException(message + if (cmd != null) " | $cmd" else "")

Expand Down
15 changes: 3 additions & 12 deletions src/com/maddyhome/idea/vim/group/ChangeGroup.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,15 +56,14 @@
import com.maddyhome.idea.vim.common.TextRange;
import com.maddyhome.idea.vim.ex.ranges.LineRange;
import com.maddyhome.idea.vim.group.visual.VimSelection;
import com.maddyhome.idea.vim.group.visual.VisualGroupKt;
import com.maddyhome.idea.vim.group.visual.VisualModeHelperKt;
import com.maddyhome.idea.vim.handler.EditorActionHandlerBase;
import com.maddyhome.idea.vim.handler.Motion;
import com.maddyhome.idea.vim.helper.*;
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.option.BoundListOption;
import com.maddyhome.idea.vim.option.BoundedStringListOption;
import com.maddyhome.idea.vim.option.OptionsManager;
import com.maddyhome.idea.vim.option.StrictMode;
import kotlin.Pair;
Expand Down Expand Up @@ -446,8 +445,6 @@ private void initInsert(@NotNull Editor editor, @NotNull DataContext context, @N
oldOffset = editor.getCaretModel().getOffset();
setInsertEditorState(editor, mode == CommandState.Mode.INSERT);
state.pushModes(mode, CommandState.SubMode.NONE);

VisualGroupKt.updateCaretState(editor);
}

notifyListeners(editor);
Expand Down Expand Up @@ -550,8 +547,6 @@ public void processEscape(@NotNull Editor editor, @Nullable DataContext context)

CommandState.getInstance(editor).popModes();
exitAllSingleCommandInsertModes(editor);

VisualGroupKt.updateCaretState(editor);
}

/**
Expand Down Expand Up @@ -1829,10 +1824,6 @@ private boolean deleteText(final @NotNull Editor editor,
return false;
}

public static void resetCaret(@NotNull Editor editor, boolean insert) {
editor.getSettings().setBlockCursor(!insert);
}

/**
* Sort range of text with a given comparator
*
Expand Down Expand Up @@ -1893,7 +1884,7 @@ public boolean changeNumberVisualMode(final @NotNull Editor editor,
@NotNull TextRange selectedRange,
final int count,
boolean avalanche) {
BoundListOption nf = OptionsManager.INSTANCE.getNrformats();
BoundedStringListOption nf = OptionsManager.INSTANCE.getNrformats();
boolean alpha = nf.contains("alpha");
boolean hex = nf.contains("hex");
boolean octal = nf.contains("octal");
Expand Down Expand Up @@ -1935,7 +1926,7 @@ private void exitAllSingleCommandInsertModes(@NotNull Editor editor) {
private @Nullable List<Object> lastStrokes;

public boolean changeNumber(final @NotNull Editor editor, @NotNull Caret caret, final int count) {
final BoundListOption nf = OptionsManager.INSTANCE.getNrformats();
final BoundedStringListOption nf = OptionsManager.INSTANCE.getNrformats();
final boolean alpha = nf.contains("alpha");
final boolean hex = nf.contains("hex");
final boolean octal = nf.contains("octal");
Expand Down
10 changes: 7 additions & 3 deletions src/com/maddyhome/idea/vim/group/EditorGroup.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,17 @@
import com.intellij.openapi.components.PersistentStateComponent;
import com.intellij.openapi.components.State;
import com.intellij.openapi.components.Storage;
import com.intellij.openapi.editor.*;
import com.intellij.openapi.editor.Editor;
import com.intellij.openapi.editor.EditorGutter;
import com.intellij.openapi.editor.EditorSettings;
import com.intellij.openapi.editor.LineNumberConverter;
import com.intellij.openapi.editor.event.CaretEvent;
import com.intellij.openapi.editor.event.CaretListener;
import com.intellij.openapi.editor.ex.EditorGutterComponentEx;
import com.intellij.openapi.editor.ex.EditorSettingsExternalizable;
import com.intellij.openapi.project.Project;
import com.maddyhome.idea.vim.KeyHandler;
import com.maddyhome.idea.vim.VimPlugin;
import com.maddyhome.idea.vim.group.visual.VisualGroupKt;
import com.maddyhome.idea.vim.helper.*;
import com.maddyhome.idea.vim.option.OptionChangeListener;
import com.maddyhome.idea.vim.option.OptionsManager;
Expand All @@ -41,6 +43,8 @@
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import static com.maddyhome.idea.vim.helper.CaretVisualAttributesHelperKt.updateCaretsVisualAttributes;

/**
* @author vlan
*/
Expand Down Expand Up @@ -224,7 +228,7 @@ public void editorCreated(@NotNull Editor editor) {
VimPlugin.getChange().insertBeforeCursor(editor, EditorDataContext.init(editor, null));
KeyHandler.getInstance().reset(editor);
}
VisualGroupKt.resetShape(CommandStateHelper.getMode(editor), editor);
updateCaretsVisualAttributes(editor);
editor.getSettings().setRefrainFromScrolling(REFRAIN_FROM_SCROLLING_VIM_VALUE);
}

Expand Down
4 changes: 2 additions & 2 deletions src/com/maddyhome/idea/vim/group/RegisterGroup.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@
import com.maddyhome.idea.vim.handler.EditorActionHandlerBase;
import com.maddyhome.idea.vim.helper.EditorHelper;
import com.maddyhome.idea.vim.helper.StringHelper;
import com.maddyhome.idea.vim.option.ListOption;
import com.maddyhome.idea.vim.option.OptionsManager;
import com.maddyhome.idea.vim.option.StringListOption;
import com.maddyhome.idea.vim.ui.ClipboardHandler;
import kotlin.Pair;
import org.jdom.Element;
Expand Down Expand Up @@ -111,7 +111,7 @@ public class RegisterGroup implements PersistentStateComponent<Element> {
private @Nullable List<KeyStroke> recordList = null;

public RegisterGroup() {
final ListOption clipboardOption = OptionsManager.INSTANCE.getClipboard();
final StringListOption clipboardOption = OptionsManager.INSTANCE.getClipboard();
clipboardOption.addOptionChangeListenerAndExecute((oldValue, newValue) -> {
if (clipboardOption.contains("unnamed")) {
defaultRegister = '*';
Expand Down
4 changes: 2 additions & 2 deletions src/com/maddyhome/idea/vim/group/SearchGroup.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@
import com.maddyhome.idea.vim.common.TextRange;
import com.maddyhome.idea.vim.ex.ranges.LineRange;
import com.maddyhome.idea.vim.helper.*;
import com.maddyhome.idea.vim.option.ListOption;
import com.maddyhome.idea.vim.option.OptionChangeListener;
import com.maddyhome.idea.vim.option.OptionsManager;
import com.maddyhome.idea.vim.option.StringListOption;
import com.maddyhome.idea.vim.regexp.CharPointer;
import com.maddyhome.idea.vim.regexp.CharacterClasses;
import com.maddyhome.idea.vim.regexp.RegExp;
Expand Down Expand Up @@ -1273,7 +1273,7 @@ public void readData(@NotNull Element element) {
}

Element show = search.getChild("show-last");
final ListOption vimInfo = OptionsManager.INSTANCE.getViminfo();
final StringListOption vimInfo = OptionsManager.INSTANCE.getViminfo();
final boolean disableHighlight = vimInfo.contains("h");
showSearchHighlight = !disableHighlight && Boolean.parseBoolean(show.getText());
if (logger.isDebugEnabled()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@ object IdeaSelectionControl {
}

KeyHandler.getInstance().reset(editor)
updateCaretState(editor)
logger.debug("${editor.mode} is enabled")
}
}
Expand Down
Loading