mirror of
https://github.com/chylex/IntelliJ-IdeaVim.git
synced 2025-08-17 16:31:45 +02:00
Compare commits
60 Commits
Author | SHA1 | Date | |
---|---|---|---|
![]() |
60caac5139 | ||
![]() |
307e438a1e | ||
![]() |
89489f7c7f | ||
![]() |
923a4706a0 | ||
![]() |
2594c7179e | ||
![]() |
0e2289caa6 | ||
![]() |
be26968237 | ||
![]() |
022f1ededc | ||
![]() |
70a19dd95d | ||
![]() |
00b3f5b9f5 | ||
![]() |
8b0bb413d8 | ||
![]() |
bd5e7d94fe | ||
![]() |
d43b2364a0 | ||
![]() |
610e73d9e3 | ||
![]() |
6f2a454d46 | ||
![]() |
4edce29d53 | ||
![]() |
ed2b8dd129 | ||
![]() |
42cdb36a51 | ||
![]() |
159c22ac21 | ||
![]() |
75b6833245 | ||
![]() |
b567717c75 | ||
![]() |
b2af829e2e | ||
![]() |
6e81714937 | ||
![]() |
cb9474d8d0 | ||
![]() |
be47e4c050 | ||
![]() |
c301898147 | ||
![]() |
8324561022 | ||
![]() |
834d630ef7 | ||
![]() |
c6259adad1 | ||
![]() |
9d1be34958 | ||
![]() |
ce4e64ec40 | ||
![]() |
b017466270 | ||
![]() |
568d2304ea | ||
![]() |
5dc1b245d0 | ||
![]() |
978d95b351 | ||
![]() |
90079c9dfe | ||
![]() |
57dec7e211 | ||
![]() |
fa75c853a7 | ||
![]() |
0887a57e29 | ||
![]() |
18901dcd44 | ||
![]() |
caecbe5b63 | ||
![]() |
077cab656b | ||
![]() |
95d7a7e860 | ||
![]() |
77a77c34b8 | ||
![]() |
fa78cc2a9f | ||
![]() |
03f18af66f | ||
![]() |
4e21145808 | ||
![]() |
258557ee5d | ||
![]() |
88ad420716 | ||
![]() |
4828e40f0d | ||
![]() |
5be29f5a07 | ||
![]() |
48ac99a29b | ||
![]() |
2c4f2139dd | ||
![]() |
47236c1e6c | ||
![]() |
5d8996dc38 | ||
![]() |
9feff84125 | ||
![]() |
c0fc62a1d6 | ||
![]() |
6b06d58759 | ||
![]() |
d06f2a2d18 | ||
![]() |
36c4596a08 |
@@ -73,6 +73,7 @@ Contributors:
|
||||
* [Pierce Corcoran](mailto:pierce@plasticcow.com)
|
||||
* [Jonatan Tierno](mailto:jonatantierno@gmail.com)
|
||||
* [Brendan Annable](mailto:brendan@annable.me)
|
||||
* [Naveen Kumar Molleti](mailto:nerd.naveen@gmail.com)
|
||||
|
||||
If you are a contributor and your name is not listed here, feel free to
|
||||
contact the maintainer.
|
||||
|
15
CHANGES.md
15
CHANGES.md
@@ -16,10 +16,23 @@ It is important to distinguish EAP from traditional pre-release software.
|
||||
Please note that the quality of EAP versions may at times be way below even
|
||||
usual beta standards.
|
||||
|
||||
0.53, 2019-08-07
|
||||
--------------
|
||||
* [VIM-1711](https://youtrack.jetbrains.com/issue/VIM-1711) Search is not triggered during surround action
|
||||
* [VIM-1712](https://youtrack.jetbrains.com/issue/VIM-1712) Fix `Y` command for visual mode
|
||||
* [VIM-1713](https://youtrack.jetbrains.com/issue/VIM-1713) Surround in visual mode put caret in correct position
|
||||
* [VIM-1732](https://youtrack.jetbrains.com/issue/VIM-1732) Fix SO after enabling vim mode
|
||||
* [VIM-1710](https://youtrack.jetbrains.com/issue/VIM-1710) Fix opening empty file with "relative number" enabled
|
||||
* [VIM-1725](https://youtrack.jetbrains.com/issue/VIM-1725) Fix problems with Japanese language
|
||||
* [VIM-1648](https://youtrack.jetbrains.com/issue/VIM-1648) Fix exception while substitute with conformation
|
||||
* [VIM-1736](https://youtrack.jetbrains.com/issue/VIM-1736) Fix `` for ex panel
|
||||
* [VIM-1739](https://youtrack.jetbrains.com/issue/VIM-1739) Fix full-width characters for ex panel
|
||||
|
||||
|
||||
0.52, 2019-07-23
|
||||
--------------
|
||||
|
||||
* Introduce [Select Mode](https://vimhelp.org/visual.txt.html#Select-mode).
|
||||
* Introduce [Select Mode](https://github.com/JetBrains/ideavim/wiki/Select-mode).
|
||||
|
||||
|
||||
* Fixed `:only` command
|
||||
|
@@ -76,7 +76,7 @@ The following `:set` commands can appear in `~/.ideavimrc` or be set manually in
|
||||
`ideajoin` `ideajoin` Boolean (default false) - IdeaVim ONLY
|
||||
|
||||
If true, join command will be performed via IDE
|
||||
See ideajoin-examples.md
|
||||
See wiki/`ideajoin` examples
|
||||
|
||||
'sidescroll' 'ss' minimum number of columns to scroll horizontally
|
||||
'sidescrolloff' 'siso' min. number of columns to left and right of cursor
|
||||
|
@@ -3,7 +3,7 @@ downloadIdeaSources=true
|
||||
instrumentPluginCode=true
|
||||
version=SNAPSHOT
|
||||
javaVersion=1.8
|
||||
kotlinVersion=1.3.40
|
||||
kotlinVersion=1.3.41
|
||||
publishUsername=username
|
||||
publishToken=token
|
||||
publishChannels=eap
|
||||
|
@@ -68,12 +68,9 @@ public class EventFacade {
|
||||
|
||||
public void setupTypedActionHandler(@NotNull VimTypedActionHandler handler) {
|
||||
final TypedAction typedAction = getTypedAction();
|
||||
final TypedActionHandler rawHandler = typedAction.getRawHandler();
|
||||
if (!(rawHandler instanceof VimTypedActionHandler)) {
|
||||
// Actually this if should always be true, but just as protection
|
||||
myOriginalTypedActionHandler = rawHandler;
|
||||
typedAction.setupRawHandler(handler);
|
||||
}
|
||||
myOriginalTypedActionHandler = typedAction.getRawHandler();
|
||||
|
||||
typedAction.setupRawHandler(handler);
|
||||
}
|
||||
|
||||
public void restoreTypedActionHandler() {
|
||||
|
@@ -54,6 +54,7 @@ import com.maddyhome.idea.vim.helper.DocumentManager;
|
||||
import com.maddyhome.idea.vim.helper.MacKeyRepeat;
|
||||
import com.maddyhome.idea.vim.listener.VimListenerManager;
|
||||
import com.maddyhome.idea.vim.option.OptionsManager;
|
||||
import com.maddyhome.idea.vim.ui.ExEntryPanel;
|
||||
import com.maddyhome.idea.vim.ui.VimEmulationConfigurable;
|
||||
import org.jdom.Element;
|
||||
import org.jdom.JDOMException;
|
||||
@@ -342,7 +343,9 @@ public class VimPlugin implements BaseComponent, PersistentStateComponent<Elemen
|
||||
|
||||
ApplicationManager.getApplication().invokeLater(this::updateState);
|
||||
|
||||
VimListenerManager.GlobalListeners.enable();
|
||||
getEditor().turnOn();
|
||||
getSearch().turnOn();
|
||||
VimListenerManager.INSTANCE.turnOn();
|
||||
|
||||
// Register vim actions in command mode
|
||||
RegisterActions.registerActions();
|
||||
@@ -447,12 +450,15 @@ public class VimPlugin implements BaseComponent, PersistentStateComponent<Elemen
|
||||
}
|
||||
|
||||
private void turnOnPlugin() {
|
||||
initializePlugin();
|
||||
KeyHandler.getInstance().fullReset(null);
|
||||
if (initialized) {
|
||||
KeyHandler.getInstance().fullReset(null);
|
||||
|
||||
getEditor().turnOn();
|
||||
getSearch().turnOn();
|
||||
VimListenerManager.INSTANCE.turnOn();
|
||||
getEditor().turnOn();
|
||||
getSearch().turnOn();
|
||||
VimListenerManager.INSTANCE.turnOn();
|
||||
} else {
|
||||
initializePlugin();
|
||||
}
|
||||
}
|
||||
|
||||
private void turnOffPlugin() {
|
||||
@@ -461,6 +467,7 @@ public class VimPlugin implements BaseComponent, PersistentStateComponent<Elemen
|
||||
getEditor().turnOff();
|
||||
getSearch().turnOff();
|
||||
VimListenerManager.INSTANCE.turnOff();
|
||||
ExEntryPanel.fullReset();
|
||||
}
|
||||
|
||||
private void updateState() {
|
||||
|
@@ -1,26 +1,23 @@
|
||||
package com.maddyhome.idea.vim
|
||||
|
||||
import org.jdom.Element
|
||||
import kotlin.properties.ReadWriteProperty
|
||||
import kotlin.reflect.KProperty
|
||||
|
||||
/**
|
||||
* @author Alex Plate
|
||||
*/
|
||||
class VimState {
|
||||
var isIdeaJoinNotified = false
|
||||
var isIdeaPutNotified = false
|
||||
var isTemplateInSelectModeNotified = false
|
||||
var isIdeaJoinNotified by StateProperty("idea-join")
|
||||
var isIdeaPutNotified by StateProperty("idea-put")
|
||||
var isTemplateInSelectModeNotified by StateProperty("template-selectmode")
|
||||
|
||||
fun readData(element: Element) {
|
||||
val notifications: Element? = element.getChild("notifications")
|
||||
|
||||
notifications?.getChild("idea-join")?.getAttributeValue("enabled")?.let {
|
||||
isIdeaJoinNotified = it.toBoolean()
|
||||
}
|
||||
notifications?.getChild("idea-put")?.getAttributeValue("enabled")?.let {
|
||||
isIdeaPutNotified = it.toBoolean()
|
||||
}
|
||||
notifications?.getChild("template-selectmode")?.getAttributeValue("enabled")?.let {
|
||||
isIdeaPutNotified = it.toBoolean()
|
||||
val notifications = element.getChild("notifications")
|
||||
map.keys.forEach { name ->
|
||||
notifications?.getChild(name)?.getAttributeValue("enabled")?.let {
|
||||
map[name] = it.toBoolean()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,16 +25,25 @@ class VimState {
|
||||
val notifications = Element("notifications")
|
||||
element.addContent(notifications)
|
||||
|
||||
val ideaJoin = Element("idea-join")
|
||||
ideaJoin.setAttribute("enabled", isIdeaJoinNotified.toString())
|
||||
notifications.addContent(ideaJoin)
|
||||
|
||||
val ideaPut = Element("idea-put")
|
||||
ideaPut.setAttribute("enabled", isIdeaPutNotified.toString())
|
||||
notifications.addContent(ideaPut)
|
||||
|
||||
val templateKeyModel = Element("template-selectmode")
|
||||
templateKeyModel.setAttribute("enabled", isTemplateInSelectModeNotified.toString())
|
||||
notifications.addContent(templateKeyModel)
|
||||
map.forEach { (name, value) ->
|
||||
val child = Element(name)
|
||||
child.setAttribute("enabled", value.toString())
|
||||
notifications.addContent(child)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
val map by lazy { mutableMapOf<String, Boolean>() }
|
||||
|
||||
private class StateProperty(val xmlName: String) : ReadWriteProperty<VimState, Boolean> {
|
||||
|
||||
init {
|
||||
map[xmlName] = false
|
||||
}
|
||||
|
||||
override fun getValue(thisRef: VimState, property: KProperty<*>): Boolean = map.getOrPut(xmlName) { false }
|
||||
|
||||
override fun setValue(thisRef: VimState, property: KProperty<*>, value: Boolean) {
|
||||
map[xmlName] = value
|
||||
}
|
||||
}
|
@@ -47,7 +47,7 @@ public class ExEntryAction extends VimCommandAction {
|
||||
@NotNull
|
||||
@Override
|
||||
public Command.Type getType() {
|
||||
return Command.Type.OTHER_READ_WRITE;
|
||||
return Command.Type.OTHER_READONLY;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
|
@@ -25,6 +25,7 @@ import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.editor.Editor;
|
||||
import com.intellij.openapi.editor.ex.util.EditorUtil;
|
||||
import com.intellij.openapi.fileEditor.ex.FileEditorManagerEx;
|
||||
import com.intellij.openapi.progress.ProcessCanceledException;
|
||||
import com.intellij.openapi.project.DumbAware;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.util.Key;
|
||||
@@ -38,17 +39,13 @@ import com.maddyhome.idea.vim.helper.EditorHelper;
|
||||
import com.maddyhome.idea.vim.key.ShortcutOwner;
|
||||
import com.maddyhome.idea.vim.option.ListOption;
|
||||
import com.maddyhome.idea.vim.option.OptionsManager;
|
||||
import one.util.streamex.StreamEx;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.event.InputEvent;
|
||||
import java.awt.event.KeyEvent;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.*;
|
||||
|
||||
import static java.awt.event.KeyEvent.*;
|
||||
|
||||
@@ -101,6 +98,10 @@ public class VimShortcutKeyAction extends AnAction implements DumbAware {
|
||||
try {
|
||||
KeyHandler.getInstance().handleKey(editor, keyStroke, new EditorDataContext(editor));
|
||||
}
|
||||
catch (ProcessCanceledException ignored) {
|
||||
// Control-flow exceptions (like ProcessCanceledException) should never be logged
|
||||
// See {@link com.intellij.openapi.diagnostic.Logger.checkException}
|
||||
}
|
||||
catch (Throwable throwable) {
|
||||
ourLogger.error(throwable);
|
||||
}
|
||||
@@ -195,7 +196,8 @@ public class VimShortcutKeyAction extends AnAction implements DumbAware {
|
||||
final Project project = editor.getProject();
|
||||
if (project == null) return false;
|
||||
final FileEditorManagerEx fileEditorManager = FileEditorManagerEx.getInstanceEx(project);
|
||||
return StreamEx.of(fileEditorManager.getAllEditors())
|
||||
if (fileEditorManager == null) return false;
|
||||
return Arrays.stream(fileEditorManager.getAllEditors())
|
||||
.anyMatch(fileEditor -> editor.equals(EditorUtil.getEditorEx(fileEditor)));
|
||||
}
|
||||
|
||||
|
@@ -49,7 +49,7 @@ public class RepeatExCommandAction extends VimCommandAction {
|
||||
@NotNull
|
||||
@Override
|
||||
public Command.Type getType() {
|
||||
return Command.Type.OTHER_WRITABLE;
|
||||
return Command.Type.OTHER_SELF_SYNCHRONIZED;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
|
@@ -53,7 +53,7 @@ public class ChangeLastGlobalSearchReplaceAction extends VimCommandAction {
|
||||
@NotNull
|
||||
@Override
|
||||
public Command.Type getType() {
|
||||
return Command.Type.OTHER_WRITABLE;
|
||||
return Command.Type.OTHER_SELF_SYNCHRONIZED;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
|
@@ -53,7 +53,7 @@ public class ChangeLastSearchReplaceAction extends VimCommandAction {
|
||||
@NotNull
|
||||
@Override
|
||||
public Command.Type getType() {
|
||||
return Command.Type.OTHER_WRITABLE;
|
||||
return Command.Type.OTHER_SELF_SYNCHRONIZED;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
|
@@ -65,7 +65,7 @@ public class ProcessExEntryAction extends VimCommandAction {
|
||||
@NotNull
|
||||
@Override
|
||||
public Command.Type getType() {
|
||||
return Command.Type.OTHER_READ_WRITE;
|
||||
return Command.Type.OTHER_SELF_SYNCHRONIZED;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
|
@@ -87,7 +87,6 @@ data class Command(
|
||||
SELECT_REGISTER,
|
||||
OTHER_READONLY,
|
||||
OTHER_WRITABLE,
|
||||
OTHER_READ_WRITE,
|
||||
/**
|
||||
* Represent commands that don't require an outer read or write action for synchronization.
|
||||
*/
|
||||
@@ -96,13 +95,13 @@ data class Command(
|
||||
|
||||
val isRead: Boolean
|
||||
get() = when (this) {
|
||||
MOTION, COPY, SELECT_REGISTER, OTHER_READONLY, OTHER_READ_WRITE, COMPLETION -> true
|
||||
MOTION, COPY, SELECT_REGISTER, OTHER_READONLY, COMPLETION -> true
|
||||
else -> false
|
||||
}
|
||||
|
||||
val isWrite: Boolean
|
||||
get() = when (this) {
|
||||
INSERT, DELETE, CHANGE, PASTE, RESET, OTHER_WRITABLE, OTHER_READ_WRITE -> true
|
||||
INSERT, DELETE, CHANGE, PASTE, RESET, OTHER_WRITABLE -> true
|
||||
else -> false
|
||||
}
|
||||
}
|
||||
|
@@ -25,7 +25,11 @@ fun commands(vararg commands: String) = commands.map { command ->
|
||||
?: throw RuntimeException("$command is invalid!")
|
||||
}.toTypedArray()
|
||||
|
||||
fun flags(rangeFlag: CommandHandler.RangeFlag, argumentFlag: CommandHandler.ArgumentFlag, vararg flags: CommandHandler.Flag) =
|
||||
CommandHandlerFlags(rangeFlag, argumentFlag, flags.toSet())
|
||||
fun flags(
|
||||
rangeFlag: CommandHandler.RangeFlag,
|
||||
argumentFlag: CommandHandler.ArgumentFlag,
|
||||
access: CommandHandler.Access,
|
||||
vararg flags: CommandHandler.Flag
|
||||
) = CommandHandlerFlags(rangeFlag, argumentFlag, access, flags.toSet())
|
||||
|
||||
private val commandPattern: Regex = "^([^\\[]+)(?:\\[([^]]+)])?\$".toRegex()
|
||||
|
@@ -87,9 +87,7 @@ sealed class CommandHandler {
|
||||
ARGUMENT_FORBIDDEN
|
||||
}
|
||||
|
||||
enum class Flag {
|
||||
DONT_REOPEN,
|
||||
|
||||
enum class Access {
|
||||
/**
|
||||
* Indicates that this is a command that modifies the editor
|
||||
*/
|
||||
@@ -98,6 +96,13 @@ sealed class CommandHandler {
|
||||
* Indicates that this command does not modify the editor
|
||||
*/
|
||||
READ_ONLY,
|
||||
/**
|
||||
* Indicates that this command handles writability by itself
|
||||
*/
|
||||
SELF_SYNCHRONIZED
|
||||
}
|
||||
|
||||
enum class Flag {
|
||||
DONT_SAVE_LAST,
|
||||
|
||||
/**
|
||||
@@ -182,4 +187,9 @@ sealed class CommandHandler {
|
||||
}
|
||||
}
|
||||
|
||||
data class CommandHandlerFlags(val rangeFlag: CommandHandler.RangeFlag, val argumentFlag: CommandHandler.ArgumentFlag, val flags: Set<CommandHandler.Flag>)
|
||||
data class CommandHandlerFlags(
|
||||
val rangeFlag: CommandHandler.RangeFlag,
|
||||
val argumentFlag: CommandHandler.ArgumentFlag,
|
||||
val access: CommandHandler.Access,
|
||||
val flags: Set<CommandHandler.Flag>
|
||||
)
|
||||
|
@@ -18,8 +18,10 @@
|
||||
package com.maddyhome.idea.vim.ex;
|
||||
|
||||
import com.intellij.openapi.actionSystem.DataContext;
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.editor.Editor;
|
||||
import com.intellij.openapi.util.ThrowableComputable;
|
||||
import com.maddyhome.idea.vim.VimPlugin;
|
||||
import com.maddyhome.idea.vim.command.SelectionType;
|
||||
import com.maddyhome.idea.vim.common.Register;
|
||||
@@ -41,11 +43,7 @@ import java.util.regex.Pattern;
|
||||
*/
|
||||
public class CommandParser {
|
||||
private static final int MAX_RECURSION = 100;
|
||||
public static final int RES_EMPTY = 1;
|
||||
public static final int RES_ERROR = 1;
|
||||
public static final int RES_READONLY = 1;
|
||||
public static final int RES_DONT_REOPEN = 4;
|
||||
public static final Pattern TRIM_WHITESPACE = Pattern.compile("[ \\t]*(.*)[ \\t\\n\\r]+", Pattern.DOTALL);
|
||||
private static final Pattern TRIM_WHITESPACE = Pattern.compile("[ \\t]*(.*)[ \\t\\n\\r]+", Pattern.DOTALL);
|
||||
private final CommandHandler[] myHandlers = new CommandHandler[] {
|
||||
new ActionListHandler(),
|
||||
new AsciiHandler(),
|
||||
@@ -169,31 +167,20 @@ public class CommandParser {
|
||||
* @param context The data context
|
||||
* @param cmd The text entered by the user
|
||||
* @param count The count entered before the colon
|
||||
* @return A bitwise collection of flags, if any, from the result of running the command.
|
||||
* @throws ExException if any part of the command is invalid or unknown
|
||||
*/
|
||||
public int processCommand(@NotNull Editor editor, @NotNull DataContext context, @NotNull String cmd,
|
||||
public void processCommand(@NotNull Editor editor, @NotNull DataContext context, @NotNull String cmd,
|
||||
int count) throws ExException {
|
||||
return processCommand(editor, context, cmd, count, MAX_RECURSION);
|
||||
processCommand(editor, context, cmd, count, MAX_RECURSION);
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse and execute an Ex command entered by the user
|
||||
*
|
||||
* @param editor The editor to run the command in
|
||||
* @param context The data context
|
||||
* @param cmd The text entered by the user
|
||||
* @param count The count entered before the colon
|
||||
* @param aliasCountdown A countdown for the depth of alias recursion that is allowed
|
||||
* @return A bitwise collection of flags, if any, from the result of running the command.
|
||||
* @throws ExException if any part of the command is invalid or unknown
|
||||
*/
|
||||
private int processCommand(@NotNull Editor editor, @NotNull DataContext context, @NotNull String cmd,
|
||||
private void processCommand(@NotNull Editor editor, @NotNull DataContext context, @NotNull String cmd,
|
||||
int count, int aliasCountdown) throws ExException {
|
||||
// Nothing entered
|
||||
int result = 0;
|
||||
if (cmd.length() == 0) {
|
||||
return result | RES_EMPTY;
|
||||
logger.warn("CMD is empty");
|
||||
return;
|
||||
}
|
||||
|
||||
// Only save the command to the history if it is at the top of the stack.
|
||||
@@ -210,14 +197,16 @@ public class CommandParser {
|
||||
if (aliasCountdown > 0) {
|
||||
String commandAlias = VimPlugin.getCommand().getAliasCommand(cmd, count);
|
||||
if (commandAlias.isEmpty()) {
|
||||
return result |= RES_ERROR;
|
||||
logger.warn("Command alias is empty");
|
||||
return;
|
||||
}
|
||||
return processCommand(editor, context, commandAlias, count, aliasCountdown - 1);
|
||||
processCommand(editor, context, commandAlias, count, aliasCountdown - 1);
|
||||
} else {
|
||||
VimPlugin.showMessage("Recursion detected, maximum alias depth reached.");
|
||||
VimPlugin.indicateError();
|
||||
return result |= RES_ERROR;
|
||||
logger.warn("Recursion detected, maximum alias depth reached. ");
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
// Parse the command
|
||||
@@ -229,23 +218,33 @@ public class CommandParser {
|
||||
throw new InvalidCommandException(message, cmd);
|
||||
}
|
||||
|
||||
if (handler.getArgFlags().getFlags().contains(CommandHandler.Flag.WRITABLE) && !editor.getDocument().isWritable()) {
|
||||
if (handler.getArgFlags().getAccess() == CommandHandler.Access.WRITABLE && !editor.getDocument().isWritable()) {
|
||||
VimPlugin.indicateError();
|
||||
return result | RES_READONLY;
|
||||
logger.info("Trying to modify readonly document");
|
||||
return;
|
||||
}
|
||||
|
||||
// Run the command
|
||||
boolean ok = handler.process(editor, context, command, count);
|
||||
if (ok && !handler.getArgFlags().getFlags().contains(CommandHandler.Flag.DONT_SAVE_LAST)) {
|
||||
VimPlugin.getRegister().storeTextInternal(editor, new TextRange(-1, -1), cmd,
|
||||
SelectionType.CHARACTER_WISE, ':', false);
|
||||
}
|
||||
|
||||
if (handler.getArgFlags().getFlags().contains(CommandHandler.Flag.DONT_REOPEN)) {
|
||||
result |= RES_DONT_REOPEN;
|
||||
}
|
||||
ThrowableComputable<Object, ExException> runCommand = () -> {
|
||||
boolean ok = handler.process(editor, context, command, count);
|
||||
if (ok && !handler.getArgFlags().getFlags().contains(CommandHandler.Flag.DONT_SAVE_LAST)) {
|
||||
VimPlugin.getRegister().storeTextInternal(editor, new TextRange(-1, -1), cmd,
|
||||
SelectionType.CHARACTER_WISE, ':', false);
|
||||
}
|
||||
return null;
|
||||
};
|
||||
|
||||
return result;
|
||||
switch (handler.getArgFlags().getAccess()) {
|
||||
case WRITABLE:
|
||||
ApplicationManager.getApplication().runWriteAction(runCommand);
|
||||
break;
|
||||
case READ_ONLY:
|
||||
ApplicationManager.getApplication().runReadAction(runCommand);
|
||||
break;
|
||||
case SELF_SYNCHRONIZED:
|
||||
runCommand.compute();
|
||||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
|
@@ -26,7 +26,6 @@ import com.intellij.openapi.editor.Editor
|
||||
import com.maddyhome.idea.vim.KeyHandler
|
||||
import com.maddyhome.idea.vim.VimPlugin
|
||||
import com.maddyhome.idea.vim.ex.*
|
||||
import com.maddyhome.idea.vim.ex.CommandHandler.Flag.DONT_REOPEN
|
||||
import com.maddyhome.idea.vim.ex.CommandHandler.Flag.SAVE_VISUAL
|
||||
import com.maddyhome.idea.vim.helper.runAfterGotFocus
|
||||
|
||||
@@ -36,7 +35,7 @@ import com.maddyhome.idea.vim.helper.runAfterGotFocus
|
||||
class ActionHandler : CommandHandler.SingleExecution() {
|
||||
|
||||
override val names = commands("action")
|
||||
override val argFlags: CommandHandlerFlags = flags(RangeFlag.RANGE_OPTIONAL, ArgumentFlag.ARGUMENT_OPTIONAL, DONT_REOPEN, SAVE_VISUAL)
|
||||
override val argFlags: CommandHandlerFlags = flags(RangeFlag.RANGE_OPTIONAL, ArgumentFlag.ARGUMENT_OPTIONAL, Access.READ_ONLY, SAVE_VISUAL)
|
||||
|
||||
override fun execute(editor: Editor, context: DataContext, cmd: ExCommand): Boolean {
|
||||
val actionName = cmd.argument.trim()
|
||||
|
@@ -22,14 +22,7 @@ import com.intellij.openapi.actionSystem.ActionManager
|
||||
import com.intellij.openapi.actionSystem.DataContext
|
||||
import com.intellij.openapi.actionSystem.KeyboardShortcut
|
||||
import com.intellij.openapi.editor.Editor
|
||||
import com.maddyhome.idea.vim.ex.CommandHandler
|
||||
import com.maddyhome.idea.vim.ex.CommandHandler.Flag.DONT_REOPEN
|
||||
import com.maddyhome.idea.vim.ex.CommandHandlerFlags
|
||||
import com.maddyhome.idea.vim.ex.CommandName
|
||||
import com.maddyhome.idea.vim.ex.ExCommand
|
||||
import com.maddyhome.idea.vim.ex.ExOutputModel
|
||||
import com.maddyhome.idea.vim.ex.commands
|
||||
import com.maddyhome.idea.vim.ex.flags
|
||||
import com.maddyhome.idea.vim.ex.*
|
||||
import com.maddyhome.idea.vim.helper.StringHelper
|
||||
|
||||
/**
|
||||
@@ -37,7 +30,7 @@ import com.maddyhome.idea.vim.helper.StringHelper
|
||||
*/
|
||||
class ActionListHandler : CommandHandler.SingleExecution() {
|
||||
override val names: Array<CommandName> = commands("actionlist")
|
||||
override val argFlags: CommandHandlerFlags = flags(RangeFlag.RANGE_FORBIDDEN, ArgumentFlag.ARGUMENT_OPTIONAL, DONT_REOPEN)
|
||||
override val argFlags: CommandHandlerFlags = flags(RangeFlag.RANGE_FORBIDDEN, ArgumentFlag.ARGUMENT_OPTIONAL, Access.READ_ONLY)
|
||||
|
||||
override fun execute(editor: Editor, context: DataContext, cmd: ExCommand): Boolean {
|
||||
val lineSeparator = "\n"
|
||||
|
@@ -21,16 +21,11 @@ package com.maddyhome.idea.vim.ex.handler
|
||||
import com.intellij.openapi.actionSystem.DataContext
|
||||
import com.intellij.openapi.editor.Editor
|
||||
import com.maddyhome.idea.vim.VimPlugin
|
||||
import com.maddyhome.idea.vim.ex.CommandHandler
|
||||
import com.maddyhome.idea.vim.ex.CommandHandlerFlags
|
||||
import com.maddyhome.idea.vim.ex.CommandName
|
||||
import com.maddyhome.idea.vim.ex.ExCommand
|
||||
import com.maddyhome.idea.vim.ex.commands
|
||||
import com.maddyhome.idea.vim.ex.flags
|
||||
import com.maddyhome.idea.vim.ex.*
|
||||
|
||||
class AsciiHandler : CommandHandler.SingleExecution() {
|
||||
override val names: Array<CommandName> = commands("as[cii]")
|
||||
override val argFlags: CommandHandlerFlags = flags(RangeFlag.RANGE_FORBIDDEN, ArgumentFlag.ARGUMENT_FORBIDDEN)
|
||||
override val argFlags: CommandHandlerFlags = flags(RangeFlag.RANGE_FORBIDDEN, ArgumentFlag.ARGUMENT_FORBIDDEN, Access.READ_ONLY)
|
||||
|
||||
override fun execute(editor: Editor, context: DataContext, cmd: ExCommand): Boolean {
|
||||
VimPlugin.getFile().displayAsciiInfo(editor)
|
||||
|
@@ -21,16 +21,11 @@ package com.maddyhome.idea.vim.ex.handler
|
||||
import com.intellij.openapi.actionSystem.DataContext
|
||||
import com.intellij.openapi.editor.Editor
|
||||
import com.maddyhome.idea.vim.VimPlugin
|
||||
import com.maddyhome.idea.vim.ex.CommandHandler
|
||||
import com.maddyhome.idea.vim.ex.CommandHandlerFlags
|
||||
import com.maddyhome.idea.vim.ex.CommandName
|
||||
import com.maddyhome.idea.vim.ex.ExCommand
|
||||
import com.maddyhome.idea.vim.ex.commands
|
||||
import com.maddyhome.idea.vim.ex.flags
|
||||
import com.maddyhome.idea.vim.ex.*
|
||||
|
||||
class CmdClearHandler : CommandHandler.SingleExecution() {
|
||||
override val names: Array<CommandName> = commands("comc[lear]")
|
||||
override val argFlags: CommandHandlerFlags = flags(RangeFlag.RANGE_FORBIDDEN, ArgumentFlag.ARGUMENT_FORBIDDEN)
|
||||
override val argFlags: CommandHandlerFlags = flags(RangeFlag.RANGE_FORBIDDEN, ArgumentFlag.ARGUMENT_FORBIDDEN, Access.READ_ONLY)
|
||||
|
||||
override fun execute(editor: Editor, context: DataContext, cmd: ExCommand): Boolean {
|
||||
VimPlugin.getCommand().resetAliases()
|
||||
|
@@ -22,20 +22,14 @@ import com.intellij.openapi.actionSystem.DataContext
|
||||
import com.intellij.openapi.diagnostic.Logger
|
||||
import com.intellij.openapi.editor.Editor
|
||||
import com.maddyhome.idea.vim.VimPlugin
|
||||
import com.maddyhome.idea.vim.ex.CommandHandler
|
||||
import com.maddyhome.idea.vim.ex.CommandHandler.Flag.WRITABLE
|
||||
import com.maddyhome.idea.vim.ex.ExCommand
|
||||
import com.maddyhome.idea.vim.ex.ExException
|
||||
import com.maddyhome.idea.vim.ex.ExOutputModel
|
||||
import com.maddyhome.idea.vim.ex.commands
|
||||
import com.maddyhome.idea.vim.ex.flags
|
||||
import com.maddyhome.idea.vim.ex.*
|
||||
import com.maddyhome.idea.vim.helper.MessageHelper
|
||||
import com.maddyhome.idea.vim.helper.Msg
|
||||
import java.io.IOException
|
||||
|
||||
class CmdFilterHandler : CommandHandler.SingleExecution() {
|
||||
override val names = commands("!")
|
||||
override val argFlags = flags(RangeFlag.RANGE_OPTIONAL, ArgumentFlag.ARGUMENT_OPTIONAL, WRITABLE)
|
||||
override val argFlags = flags(RangeFlag.RANGE_OPTIONAL, ArgumentFlag.ARGUMENT_OPTIONAL, Access.WRITABLE)
|
||||
override fun execute(editor: Editor, context: DataContext, cmd: ExCommand): Boolean {
|
||||
logger.info("execute")
|
||||
|
||||
|
@@ -22,13 +22,7 @@ import com.intellij.openapi.actionSystem.DataContext
|
||||
import com.intellij.openapi.editor.Editor
|
||||
import com.maddyhome.idea.vim.VimPlugin
|
||||
import com.maddyhome.idea.vim.common.Alias
|
||||
import com.maddyhome.idea.vim.ex.CommandHandler
|
||||
import com.maddyhome.idea.vim.ex.CommandHandlerFlags
|
||||
import com.maddyhome.idea.vim.ex.CommandName
|
||||
import com.maddyhome.idea.vim.ex.ExCommand
|
||||
import com.maddyhome.idea.vim.ex.ExOutputModel
|
||||
import com.maddyhome.idea.vim.ex.commands
|
||||
import com.maddyhome.idea.vim.ex.flags
|
||||
import com.maddyhome.idea.vim.ex.*
|
||||
import com.maddyhome.idea.vim.ex.vimscript.VimScriptCommandHandler
|
||||
import com.maddyhome.idea.vim.group.CommandGroup.Companion.BLACKLISTED_ALIASES
|
||||
|
||||
@@ -37,7 +31,7 @@ import com.maddyhome.idea.vim.group.CommandGroup.Companion.BLACKLISTED_ALIASES
|
||||
*/
|
||||
class CmdHandler : CommandHandler.SingleExecution(), VimScriptCommandHandler {
|
||||
override val names: Array<CommandName> = commands("com[mand]")
|
||||
override val argFlags: CommandHandlerFlags = flags(RangeFlag.RANGE_FORBIDDEN, ArgumentFlag.ARGUMENT_OPTIONAL, Flag.DONT_REOPEN)
|
||||
override val argFlags: CommandHandlerFlags = flags(RangeFlag.RANGE_FORBIDDEN, ArgumentFlag.ARGUMENT_OPTIONAL, Access.READ_ONLY)
|
||||
|
||||
// Static definitions needed for aliases.
|
||||
private companion object {
|
||||
|
@@ -22,18 +22,13 @@ import com.intellij.openapi.actionSystem.DataContext
|
||||
import com.intellij.openapi.editor.Editor
|
||||
import com.maddyhome.idea.vim.VimPlugin
|
||||
import com.maddyhome.idea.vim.command.SelectionType
|
||||
import com.maddyhome.idea.vim.ex.CommandHandler
|
||||
import com.maddyhome.idea.vim.ex.CommandHandler.Flag.WRITABLE
|
||||
import com.maddyhome.idea.vim.ex.CommandParser
|
||||
import com.maddyhome.idea.vim.ex.ExCommand
|
||||
import com.maddyhome.idea.vim.ex.commands
|
||||
import com.maddyhome.idea.vim.ex.flags
|
||||
import com.maddyhome.idea.vim.ex.*
|
||||
import com.maddyhome.idea.vim.group.copy.PutData
|
||||
import com.maddyhome.idea.vim.helper.EditorHelper
|
||||
|
||||
class CopyTextHandler : CommandHandler.SingleExecution() {
|
||||
override val names = commands("co[py]", "t")
|
||||
override val argFlags = flags(RangeFlag.RANGE_OPTIONAL, ArgumentFlag.ARGUMENT_REQUIRED, WRITABLE)
|
||||
override val argFlags = flags(RangeFlag.RANGE_OPTIONAL, ArgumentFlag.ARGUMENT_REQUIRED, Access.WRITABLE)
|
||||
override fun execute(editor: Editor, context: DataContext, cmd: ExCommand): Boolean {
|
||||
val carets = EditorHelper.getOrderedCaretsList(editor)
|
||||
for (caret in carets) {
|
||||
|
@@ -28,7 +28,7 @@ import com.maddyhome.idea.vim.ex.flags
|
||||
|
||||
class DelCmdHandler : CommandHandler.SingleExecution() {
|
||||
override val names = commands("delc[ommand]")
|
||||
override val argFlags = flags(RangeFlag.RANGE_FORBIDDEN, ArgumentFlag.ARGUMENT_REQUIRED)
|
||||
override val argFlags = flags(RangeFlag.RANGE_FORBIDDEN, ArgumentFlag.ARGUMENT_REQUIRED, Access.READ_ONLY)
|
||||
override fun execute(editor: Editor, context: DataContext, cmd: ExCommand): Boolean {
|
||||
if (!VimPlugin.getCommand().hasAlias(cmd.argument)) {
|
||||
VimPlugin.showMessage("E184: No such user-defined command: ${cmd.argument}")
|
||||
|
@@ -23,17 +23,11 @@ import com.intellij.openapi.editor.Caret
|
||||
import com.intellij.openapi.editor.Editor
|
||||
import com.maddyhome.idea.vim.VimPlugin
|
||||
import com.maddyhome.idea.vim.command.SelectionType
|
||||
import com.maddyhome.idea.vim.ex.CommandHandler
|
||||
import com.maddyhome.idea.vim.ex.CommandHandler.Flag.WRITABLE
|
||||
import com.maddyhome.idea.vim.ex.CommandHandlerFlags
|
||||
import com.maddyhome.idea.vim.ex.CommandName
|
||||
import com.maddyhome.idea.vim.ex.ExCommand
|
||||
import com.maddyhome.idea.vim.ex.commands
|
||||
import com.maddyhome.idea.vim.ex.flags
|
||||
import com.maddyhome.idea.vim.ex.*
|
||||
|
||||
class DeleteLinesHandler : CommandHandler.ForEachCaret() {
|
||||
override val names: Array<CommandName> = commands("d[elete]")
|
||||
override val argFlags: CommandHandlerFlags = flags(RangeFlag.RANGE_OPTIONAL, ArgumentFlag.ARGUMENT_OPTIONAL, WRITABLE)
|
||||
override val argFlags: CommandHandlerFlags = flags(RangeFlag.RANGE_OPTIONAL, ArgumentFlag.ARGUMENT_OPTIONAL, Access.WRITABLE)
|
||||
|
||||
override fun execute(editor: Editor, caret: Caret, context: DataContext,
|
||||
cmd: ExCommand): Boolean {
|
||||
|
@@ -29,7 +29,7 @@ import com.maddyhome.idea.vim.ex.flags
|
||||
|
||||
class DigraphHandler : CommandHandler.SingleExecution() {
|
||||
override val names = commands("dig[raphs]")
|
||||
override val argFlags = flags(RangeFlag.RANGE_OPTIONAL, ArgumentFlag.ARGUMENT_OPTIONAL)
|
||||
override val argFlags = flags(RangeFlag.RANGE_OPTIONAL, ArgumentFlag.ARGUMENT_OPTIONAL, Access.READ_ONLY)
|
||||
|
||||
override fun execute(editor: Editor, context: DataContext, cmd: ExCommand): Boolean {
|
||||
val arg = cmd.argument
|
||||
|
@@ -28,7 +28,7 @@ import com.maddyhome.idea.vim.ex.flags
|
||||
|
||||
class DumpLineHandler : CommandHandler.SingleExecution() {
|
||||
override val names = commands("dump[line]")
|
||||
override val argFlags = flags(RangeFlag.RANGE_OPTIONAL, ArgumentFlag.ARGUMENT_OPTIONAL)
|
||||
override val argFlags = flags(RangeFlag.RANGE_OPTIONAL, ArgumentFlag.ARGUMENT_OPTIONAL, Access.READ_ONLY)
|
||||
override fun execute(editor: Editor, context: DataContext, cmd: ExCommand): Boolean {
|
||||
if (!logger.isDebugEnabled) return false
|
||||
|
||||
|
@@ -20,11 +20,7 @@ package com.maddyhome.idea.vim.ex.handler
|
||||
|
||||
import com.intellij.openapi.actionSystem.DataContext
|
||||
import com.intellij.openapi.editor.Editor
|
||||
import com.maddyhome.idea.vim.ex.CommandHandler
|
||||
import com.maddyhome.idea.vim.ex.ExCommand
|
||||
import com.maddyhome.idea.vim.ex.ExOutputModel
|
||||
import com.maddyhome.idea.vim.ex.commands
|
||||
import com.maddyhome.idea.vim.ex.flags
|
||||
import com.maddyhome.idea.vim.ex.*
|
||||
import com.maddyhome.idea.vim.ex.vimscript.VimScriptGlobalEnvironment
|
||||
import com.maddyhome.idea.vim.ex.vimscript.VimScriptParser
|
||||
|
||||
@@ -33,7 +29,7 @@ import com.maddyhome.idea.vim.ex.vimscript.VimScriptParser
|
||||
*/
|
||||
class EchoHandler : CommandHandler.SingleExecution() {
|
||||
override val names = commands("ec[ho]")
|
||||
override val argFlags = flags(RangeFlag.RANGE_FORBIDDEN, ArgumentFlag.ARGUMENT_OPTIONAL)
|
||||
override val argFlags = flags(RangeFlag.RANGE_FORBIDDEN, ArgumentFlag.ARGUMENT_OPTIONAL, Access.READ_ONLY)
|
||||
|
||||
override fun execute(editor: Editor, context: DataContext, cmd: ExCommand): Boolean {
|
||||
val env = VimScriptGlobalEnvironment.getInstance()
|
||||
|
@@ -24,7 +24,6 @@ import com.intellij.openapi.editor.Editor
|
||||
import com.maddyhome.idea.vim.KeyHandler
|
||||
import com.maddyhome.idea.vim.VimPlugin
|
||||
import com.maddyhome.idea.vim.ex.CommandHandler
|
||||
import com.maddyhome.idea.vim.ex.CommandHandler.Flag.DONT_REOPEN
|
||||
import com.maddyhome.idea.vim.ex.ExCommand
|
||||
import com.maddyhome.idea.vim.ex.commands
|
||||
import com.maddyhome.idea.vim.ex.flags
|
||||
@@ -32,7 +31,7 @@ import com.maddyhome.idea.vim.helper.EditorDataContext
|
||||
|
||||
class EditFileHandler : CommandHandler.SingleExecution() {
|
||||
override val names = commands("bro[wse]", "e[dit]")
|
||||
override val argFlags = flags(RangeFlag.RANGE_FORBIDDEN, ArgumentFlag.ARGUMENT_OPTIONAL, DONT_REOPEN)
|
||||
override val argFlags = flags(RangeFlag.RANGE_FORBIDDEN, ArgumentFlag.ARGUMENT_OPTIONAL, Access.READ_ONLY)
|
||||
override fun execute(editor: Editor, context: DataContext, cmd: ExCommand): Boolean {
|
||||
val arg = cmd.argument
|
||||
if (arg == "#") {
|
||||
|
@@ -22,14 +22,13 @@ import com.intellij.openapi.actionSystem.DataContext
|
||||
import com.intellij.openapi.editor.Editor
|
||||
import com.maddyhome.idea.vim.VimPlugin
|
||||
import com.maddyhome.idea.vim.ex.CommandHandler
|
||||
import com.maddyhome.idea.vim.ex.CommandHandler.Flag.DONT_REOPEN
|
||||
import com.maddyhome.idea.vim.ex.ExCommand
|
||||
import com.maddyhome.idea.vim.ex.commands
|
||||
import com.maddyhome.idea.vim.ex.flags
|
||||
|
||||
class ExitHandler : CommandHandler.SingleExecution() {
|
||||
override val names = commands("qa[ll]", "quita[ll]", "wqa[ll]", "xa[ll]")
|
||||
override val argFlags = flags(RangeFlag.RANGE_OPTIONAL, ArgumentFlag.ARGUMENT_OPTIONAL, DONT_REOPEN)
|
||||
override val argFlags = flags(RangeFlag.RANGE_OPTIONAL, ArgumentFlag.ARGUMENT_OPTIONAL, Access.READ_ONLY)
|
||||
|
||||
override fun execute(editor: Editor, context: DataContext, cmd: ExCommand): Boolean {
|
||||
VimPlugin.getWindow().closeAll(context)
|
||||
|
@@ -29,7 +29,7 @@ import com.maddyhome.idea.vim.ex.flags
|
||||
|
||||
class FileHandler : CommandHandler.SingleExecution() {
|
||||
override val names = commands("f[ile]")
|
||||
override val argFlags = flags(RangeFlag.RANGE_IS_COUNT, ARGUMENT_FORBIDDEN)
|
||||
override val argFlags = flags(RangeFlag.RANGE_IS_COUNT, ARGUMENT_FORBIDDEN, Access.READ_ONLY)
|
||||
override fun execute(editor: Editor, context: DataContext, cmd: ExCommand): Boolean {
|
||||
val count = cmd.getCount(editor, context, 0, false)
|
||||
VimPlugin.getFile().displayFileInfo(editor, count > 0)
|
||||
|
@@ -24,14 +24,13 @@ import com.intellij.openapi.editor.Editor
|
||||
import com.maddyhome.idea.vim.KeyHandler
|
||||
import com.maddyhome.idea.vim.VimPlugin
|
||||
import com.maddyhome.idea.vim.ex.CommandHandler
|
||||
import com.maddyhome.idea.vim.ex.CommandHandler.Flag.DONT_REOPEN
|
||||
import com.maddyhome.idea.vim.ex.ExCommand
|
||||
import com.maddyhome.idea.vim.ex.commands
|
||||
import com.maddyhome.idea.vim.ex.flags
|
||||
|
||||
class FindClassHandler : CommandHandler.SingleExecution() {
|
||||
override val names = commands("cla[ss]")
|
||||
override val argFlags = flags(RangeFlag.RANGE_FORBIDDEN, ArgumentFlag.ARGUMENT_OPTIONAL, DONT_REOPEN)
|
||||
override val argFlags = flags(RangeFlag.RANGE_FORBIDDEN, ArgumentFlag.ARGUMENT_OPTIONAL, Access.READ_ONLY)
|
||||
override fun execute(editor: Editor, context: DataContext, cmd: ExCommand): Boolean {
|
||||
val arg = cmd.argument
|
||||
if (arg.isNotEmpty()) {
|
||||
|
@@ -24,14 +24,13 @@ import com.intellij.openapi.editor.Editor
|
||||
import com.maddyhome.idea.vim.KeyHandler
|
||||
import com.maddyhome.idea.vim.VimPlugin
|
||||
import com.maddyhome.idea.vim.ex.CommandHandler
|
||||
import com.maddyhome.idea.vim.ex.CommandHandler.Flag.DONT_REOPEN
|
||||
import com.maddyhome.idea.vim.ex.ExCommand
|
||||
import com.maddyhome.idea.vim.ex.commands
|
||||
import com.maddyhome.idea.vim.ex.flags
|
||||
|
||||
class FindFileHandler : CommandHandler.SingleExecution() {
|
||||
override val names = commands("fin[d]")
|
||||
override val argFlags = flags(RangeFlag.RANGE_FORBIDDEN, ArgumentFlag.ARGUMENT_OPTIONAL, DONT_REOPEN)
|
||||
override val argFlags = flags(RangeFlag.RANGE_FORBIDDEN, ArgumentFlag.ARGUMENT_OPTIONAL, Access.READ_ONLY)
|
||||
override fun execute(editor: Editor, context: DataContext, cmd: ExCommand): Boolean {
|
||||
val arg = cmd.argument
|
||||
if (arg.isNotEmpty()) {
|
||||
|
@@ -23,14 +23,13 @@ import com.intellij.openapi.application.ApplicationManager
|
||||
import com.intellij.openapi.editor.Editor
|
||||
import com.maddyhome.idea.vim.KeyHandler
|
||||
import com.maddyhome.idea.vim.ex.CommandHandler
|
||||
import com.maddyhome.idea.vim.ex.CommandHandler.Flag.DONT_REOPEN
|
||||
import com.maddyhome.idea.vim.ex.ExCommand
|
||||
import com.maddyhome.idea.vim.ex.commands
|
||||
import com.maddyhome.idea.vim.ex.flags
|
||||
|
||||
class FindSymbolHandler : CommandHandler.SingleExecution() {
|
||||
override val names = commands("sym[bol]")
|
||||
override val argFlags = flags(RangeFlag.RANGE_FORBIDDEN, ArgumentFlag.ARGUMENT_OPTIONAL, DONT_REOPEN)
|
||||
override val argFlags = flags(RangeFlag.RANGE_FORBIDDEN, ArgumentFlag.ARGUMENT_OPTIONAL, Access.READ_ONLY)
|
||||
override fun execute(editor: Editor, context: DataContext, cmd: ExCommand): Boolean {
|
||||
// TODO: Check the command argument and jump to a specific symbol
|
||||
ApplicationManager.getApplication().invokeLater { KeyHandler.executeAction("GotoSymbol", context) }
|
||||
|
@@ -23,19 +23,14 @@ import com.intellij.openapi.editor.Caret
|
||||
import com.intellij.openapi.editor.Editor
|
||||
import com.maddyhome.idea.vim.VimPlugin
|
||||
import com.maddyhome.idea.vim.command.CommandFlags
|
||||
import com.maddyhome.idea.vim.ex.CommandHandler
|
||||
import com.maddyhome.idea.vim.ex.CommandHandlerFlags
|
||||
import com.maddyhome.idea.vim.ex.CommandName
|
||||
import com.maddyhome.idea.vim.ex.ExCommand
|
||||
import com.maddyhome.idea.vim.ex.commands
|
||||
import com.maddyhome.idea.vim.ex.flags
|
||||
import com.maddyhome.idea.vim.ex.*
|
||||
import com.maddyhome.idea.vim.group.MotionGroup
|
||||
import com.maddyhome.idea.vim.helper.enumSetOf
|
||||
import java.util.*
|
||||
|
||||
class GotoCharacterHandler : CommandHandler.ForEachCaret() {
|
||||
override val names: Array<CommandName> = commands("go[to]")
|
||||
override val argFlags: CommandHandlerFlags = flags(RangeFlag.RANGE_IS_COUNT, ArgumentFlag.ARGUMENT_OPTIONAL)
|
||||
override val argFlags: CommandHandlerFlags = flags(RangeFlag.RANGE_IS_COUNT, ArgumentFlag.ARGUMENT_OPTIONAL, Access.READ_ONLY)
|
||||
override val optFlags: EnumSet<CommandFlags> = enumSetOf(CommandFlags.FLAG_MOT_EXCLUSIVE)
|
||||
|
||||
override fun execute(editor: Editor, caret: Caret, context: DataContext, cmd: ExCommand): Boolean {
|
||||
|
@@ -36,7 +36,7 @@ import kotlin.math.min
|
||||
*/
|
||||
class GotoLineHandler : CommandHandler.ForEachCaret() {
|
||||
override val names: Array<CommandName> = arrayOf()
|
||||
override val argFlags: CommandHandlerFlags = flags(RangeFlag.RANGE_REQUIRED, ArgumentFlag.ARGUMENT_OPTIONAL)
|
||||
override val argFlags: CommandHandlerFlags = flags(RangeFlag.RANGE_REQUIRED, ArgumentFlag.ARGUMENT_OPTIONAL, Access.READ_ONLY)
|
||||
override val optFlags: EnumSet<CommandFlags> = enumSetOf(CommandFlags.FLAG_MOT_EXCLUSIVE)
|
||||
|
||||
/**
|
||||
|
@@ -33,7 +33,7 @@ import java.net.URLEncoder
|
||||
*/
|
||||
class HelpHandler : CommandHandler.SingleExecution() {
|
||||
override val names = commands("h[elp]")
|
||||
override val argFlags = flags(RangeFlag.RANGE_OPTIONAL, ArgumentFlag.ARGUMENT_OPTIONAL)
|
||||
override val argFlags = flags(RangeFlag.RANGE_OPTIONAL, ArgumentFlag.ARGUMENT_OPTIONAL, Access.READ_ONLY)
|
||||
override fun execute(editor: Editor, context: DataContext, cmd: ExCommand): Boolean {
|
||||
BrowserUtil.browse(helpTopicUrl(cmd.argument))
|
||||
return true
|
||||
|
@@ -22,19 +22,12 @@ import com.intellij.openapi.actionSystem.DataContext
|
||||
import com.intellij.openapi.diagnostic.Logger
|
||||
import com.intellij.openapi.editor.Editor
|
||||
import com.maddyhome.idea.vim.VimPlugin
|
||||
import com.maddyhome.idea.vim.ex.CommandHandler
|
||||
import com.maddyhome.idea.vim.ex.ExCommand
|
||||
import com.maddyhome.idea.vim.ex.ExOutputModel
|
||||
import com.maddyhome.idea.vim.ex.commands
|
||||
import com.maddyhome.idea.vim.ex.flags
|
||||
import com.maddyhome.idea.vim.group.HistoryGroup.COMMAND
|
||||
import com.maddyhome.idea.vim.group.HistoryGroup.EXPRESSION
|
||||
import com.maddyhome.idea.vim.group.HistoryGroup.INPUT
|
||||
import com.maddyhome.idea.vim.group.HistoryGroup.SEARCH
|
||||
import com.maddyhome.idea.vim.ex.*
|
||||
import com.maddyhome.idea.vim.group.HistoryGroup.*
|
||||
|
||||
class HistoryHandler : CommandHandler.SingleExecution() {
|
||||
override val names = commands("his[tory]")
|
||||
override val argFlags = flags(RangeFlag.RANGE_FORBIDDEN, ArgumentFlag.ARGUMENT_OPTIONAL)
|
||||
override val argFlags = flags(RangeFlag.RANGE_FORBIDDEN, ArgumentFlag.ARGUMENT_OPTIONAL, Access.READ_ONLY)
|
||||
override fun execute(editor: Editor, context: DataContext, cmd: ExCommand): Boolean {
|
||||
logger.debug("execute")
|
||||
|
||||
|
@@ -23,17 +23,11 @@ import com.intellij.openapi.editor.Caret
|
||||
import com.intellij.openapi.editor.Editor
|
||||
import com.maddyhome.idea.vim.VimPlugin
|
||||
import com.maddyhome.idea.vim.common.TextRange
|
||||
import com.maddyhome.idea.vim.ex.CommandHandler
|
||||
import com.maddyhome.idea.vim.ex.CommandHandler.Flag.WRITABLE
|
||||
import com.maddyhome.idea.vim.ex.CommandHandlerFlags
|
||||
import com.maddyhome.idea.vim.ex.CommandName
|
||||
import com.maddyhome.idea.vim.ex.ExCommand
|
||||
import com.maddyhome.idea.vim.ex.commands
|
||||
import com.maddyhome.idea.vim.ex.flags
|
||||
import com.maddyhome.idea.vim.ex.*
|
||||
|
||||
class JoinLinesHandler : CommandHandler.ForEachCaret() {
|
||||
override val names: Array<CommandName> = commands("j[oin]")
|
||||
override val argFlags: CommandHandlerFlags = flags(RangeFlag.RANGE_OPTIONAL, ArgumentFlag.ARGUMENT_OPTIONAL, WRITABLE)
|
||||
override val argFlags: CommandHandlerFlags = flags(RangeFlag.RANGE_OPTIONAL, ArgumentFlag.ARGUMENT_OPTIONAL, Access.WRITABLE)
|
||||
|
||||
override fun execute(editor: Editor, caret: Caret, context: DataContext, cmd: ExCommand): Boolean {
|
||||
val arg = cmd.argument
|
||||
|
@@ -21,11 +21,7 @@ package com.maddyhome.idea.vim.ex.handler
|
||||
import com.intellij.openapi.actionSystem.DataContext
|
||||
import com.intellij.openapi.editor.Editor
|
||||
import com.maddyhome.idea.vim.VimPlugin
|
||||
import com.maddyhome.idea.vim.ex.CommandHandler
|
||||
import com.maddyhome.idea.vim.ex.ExCommand
|
||||
import com.maddyhome.idea.vim.ex.ExOutputModel
|
||||
import com.maddyhome.idea.vim.ex.commands
|
||||
import com.maddyhome.idea.vim.ex.flags
|
||||
import com.maddyhome.idea.vim.ex.*
|
||||
import com.maddyhome.idea.vim.helper.EditorHelper
|
||||
import com.maddyhome.idea.vim.helper.StringHelper.stringToKeys
|
||||
import com.maddyhome.idea.vim.helper.StringHelper.toKeyNotation
|
||||
@@ -33,7 +29,7 @@ import kotlin.math.absoluteValue
|
||||
|
||||
class JumpsHandler : CommandHandler.SingleExecution() {
|
||||
override val names = commands("ju[mps]")
|
||||
override val argFlags = flags(RangeFlag.RANGE_OPTIONAL, ArgumentFlag.ARGUMENT_FORBIDDEN)
|
||||
override val argFlags = flags(RangeFlag.RANGE_OPTIONAL, ArgumentFlag.ARGUMENT_FORBIDDEN, Access.READ_ONLY)
|
||||
override fun execute(editor: Editor, context: DataContext, cmd: ExCommand): Boolean {
|
||||
val jumps = VimPlugin.getMark().jumps
|
||||
val spot = VimPlugin.getMark().jumpSpot
|
||||
|
@@ -20,11 +20,7 @@ package com.maddyhome.idea.vim.ex.handler
|
||||
|
||||
import com.intellij.openapi.actionSystem.DataContext
|
||||
import com.intellij.openapi.editor.Editor
|
||||
import com.maddyhome.idea.vim.ex.CommandHandler
|
||||
import com.maddyhome.idea.vim.ex.ExCommand
|
||||
import com.maddyhome.idea.vim.ex.ExException
|
||||
import com.maddyhome.idea.vim.ex.commands
|
||||
import com.maddyhome.idea.vim.ex.flags
|
||||
import com.maddyhome.idea.vim.ex.*
|
||||
import com.maddyhome.idea.vim.ex.vimscript.VimScriptCommandHandler
|
||||
import com.maddyhome.idea.vim.ex.vimscript.VimScriptGlobalEnvironment
|
||||
import com.maddyhome.idea.vim.ex.vimscript.VimScriptParser
|
||||
@@ -35,7 +31,7 @@ import java.util.regex.Pattern
|
||||
*/
|
||||
class LetHandler : CommandHandler.SingleExecution(), VimScriptCommandHandler {
|
||||
override val names = commands("let")
|
||||
override val argFlags = flags(RangeFlag.RANGE_FORBIDDEN, ArgumentFlag.ARGUMENT_OPTIONAL)
|
||||
override val argFlags = flags(RangeFlag.RANGE_FORBIDDEN, ArgumentFlag.ARGUMENT_OPTIONAL, Access.READ_ONLY)
|
||||
|
||||
@Throws(ExException::class)
|
||||
override fun execute(editor: Editor, context: DataContext, cmd: ExCommand): Boolean {
|
||||
|
@@ -22,13 +22,7 @@ import com.intellij.openapi.actionSystem.DataContext
|
||||
import com.intellij.openapi.editor.Editor
|
||||
import com.maddyhome.idea.vim.VimPlugin
|
||||
import com.maddyhome.idea.vim.command.MappingMode
|
||||
import com.maddyhome.idea.vim.ex.CommandHandler
|
||||
import com.maddyhome.idea.vim.ex.CommandHandlerFlags
|
||||
import com.maddyhome.idea.vim.ex.CommandName
|
||||
import com.maddyhome.idea.vim.ex.ExCommand
|
||||
import com.maddyhome.idea.vim.ex.ExException
|
||||
import com.maddyhome.idea.vim.ex.commands
|
||||
import com.maddyhome.idea.vim.ex.flags
|
||||
import com.maddyhome.idea.vim.ex.*
|
||||
import com.maddyhome.idea.vim.ex.handler.MapHandler.SpecialArgument.EXPR
|
||||
import com.maddyhome.idea.vim.ex.handler.MapHandler.SpecialArgument.SCRIPT
|
||||
import com.maddyhome.idea.vim.ex.vimscript.VimScriptCommandHandler
|
||||
@@ -41,7 +35,7 @@ import javax.swing.KeyStroke
|
||||
*/
|
||||
class MapHandler : CommandHandler.SingleExecution(), VimScriptCommandHandler {
|
||||
override val names: Array<CommandName> = COMMAND_NAMES
|
||||
override val argFlags: CommandHandlerFlags = flags(RangeFlag.RANGE_FORBIDDEN, ArgumentFlag.ARGUMENT_OPTIONAL)
|
||||
override val argFlags: CommandHandlerFlags = flags(RangeFlag.RANGE_FORBIDDEN, ArgumentFlag.ARGUMENT_OPTIONAL, Access.READ_ONLY)
|
||||
|
||||
@Throws(ExException::class)
|
||||
override fun execute(editor: Editor, context: DataContext, cmd: ExCommand): Boolean {
|
||||
|
@@ -31,7 +31,7 @@ import com.maddyhome.idea.vim.helper.Msg
|
||||
|
||||
class MarkHandler : CommandHandler.SingleExecution() {
|
||||
override val names = commands("ma[rk]", "k")
|
||||
override val argFlags = flags(RangeFlag.RANGE_OPTIONAL, ArgumentFlag.ARGUMENT_REQUIRED)
|
||||
override val argFlags = flags(RangeFlag.RANGE_OPTIONAL, ArgumentFlag.ARGUMENT_REQUIRED, Access.READ_ONLY)
|
||||
|
||||
override fun execute(editor: Editor, context: DataContext, cmd: ExCommand): Boolean {
|
||||
val mark = cmd.argument[0]
|
||||
|
@@ -21,20 +21,14 @@ package com.maddyhome.idea.vim.ex.handler
|
||||
import com.intellij.openapi.actionSystem.DataContext
|
||||
import com.intellij.openapi.editor.Editor
|
||||
import com.maddyhome.idea.vim.VimPlugin
|
||||
import com.maddyhome.idea.vim.ex.CommandHandler
|
||||
import com.maddyhome.idea.vim.ex.CommandHandlerFlags
|
||||
import com.maddyhome.idea.vim.ex.CommandName
|
||||
import com.maddyhome.idea.vim.ex.ExCommand
|
||||
import com.maddyhome.idea.vim.ex.ExOutputModel
|
||||
import com.maddyhome.idea.vim.ex.commands
|
||||
import com.maddyhome.idea.vim.ex.flags
|
||||
import com.maddyhome.idea.vim.ex.*
|
||||
import com.maddyhome.idea.vim.helper.EditorHelper
|
||||
import com.maddyhome.idea.vim.helper.StringHelper.stringToKeys
|
||||
import com.maddyhome.idea.vim.helper.StringHelper.toKeyNotation
|
||||
|
||||
class MarksHandler : CommandHandler.SingleExecution() {
|
||||
override val names: Array<CommandName> = commands("marks")
|
||||
override val argFlags: CommandHandlerFlags = flags(RangeFlag.RANGE_OPTIONAL, ArgumentFlag.ARGUMENT_OPTIONAL)
|
||||
override val argFlags: CommandHandlerFlags = flags(RangeFlag.RANGE_OPTIONAL, ArgumentFlag.ARGUMENT_OPTIONAL, Access.READ_ONLY)
|
||||
|
||||
override fun execute(editor: Editor, context: DataContext, cmd: ExCommand): Boolean {
|
||||
|
||||
|
@@ -25,7 +25,6 @@ import com.maddyhome.idea.vim.VimPlugin
|
||||
import com.maddyhome.idea.vim.command.SelectionType
|
||||
import com.maddyhome.idea.vim.common.TextRange
|
||||
import com.maddyhome.idea.vim.ex.*
|
||||
import com.maddyhome.idea.vim.ex.CommandHandler.Flag.WRITABLE
|
||||
import com.maddyhome.idea.vim.group.copy.PutData
|
||||
import com.maddyhome.idea.vim.helper.EditorHelper
|
||||
import com.maddyhome.idea.vim.helper.MessageHelper
|
||||
@@ -35,7 +34,7 @@ import kotlin.math.min
|
||||
|
||||
class MoveTextHandler : CommandHandler.SingleExecution() {
|
||||
override val names = commands("m[ove]")
|
||||
override val argFlags = flags(RangeFlag.RANGE_OPTIONAL, ArgumentFlag.ARGUMENT_REQUIRED, WRITABLE)
|
||||
override val argFlags = flags(RangeFlag.RANGE_OPTIONAL, ArgumentFlag.ARGUMENT_REQUIRED, Access.WRITABLE)
|
||||
@Throws(ExException::class)
|
||||
override fun execute(editor: Editor, context: DataContext, cmd: ExCommand): Boolean {
|
||||
val carets = EditorHelper.getOrderedCaretsList(editor)
|
||||
|
@@ -22,14 +22,13 @@ import com.intellij.openapi.actionSystem.DataContext
|
||||
import com.intellij.openapi.editor.Editor
|
||||
import com.maddyhome.idea.vim.VimPlugin
|
||||
import com.maddyhome.idea.vim.ex.CommandHandler
|
||||
import com.maddyhome.idea.vim.ex.CommandHandler.Flag.DONT_REOPEN
|
||||
import com.maddyhome.idea.vim.ex.ExCommand
|
||||
import com.maddyhome.idea.vim.ex.commands
|
||||
import com.maddyhome.idea.vim.ex.flags
|
||||
|
||||
class NextFileHandler : CommandHandler.SingleExecution() {
|
||||
override val names = commands("n[ext]")
|
||||
override val argFlags = flags(RangeFlag.RANGE_IS_COUNT, ArgumentFlag.ARGUMENT_OPTIONAL, DONT_REOPEN)
|
||||
override val argFlags = flags(RangeFlag.RANGE_IS_COUNT, ArgumentFlag.ARGUMENT_OPTIONAL, Access.READ_ONLY)
|
||||
|
||||
override fun execute(editor: Editor, context: DataContext, cmd: ExCommand): Boolean {
|
||||
val count = cmd.getCount(editor, context, 1, true)
|
||||
|
@@ -28,7 +28,7 @@ import com.maddyhome.idea.vim.ex.flags
|
||||
|
||||
class NextTabHandler : CommandHandler.SingleExecution() {
|
||||
override val names = commands("tabn[ext]")
|
||||
override val argFlags = flags(RangeFlag.RANGE_FORBIDDEN, ArgumentFlag.ARGUMENT_OPTIONAL)
|
||||
override val argFlags = flags(RangeFlag.RANGE_FORBIDDEN, ArgumentFlag.ARGUMENT_OPTIONAL, Access.READ_ONLY)
|
||||
override fun execute(editor: Editor, context: DataContext, cmd: ExCommand): Boolean {
|
||||
VimPlugin.getMotion().moveCaretGotoNextTab(editor, context, cmd.argument.toIntOrNull() ?: 0)
|
||||
return true
|
||||
|
@@ -27,7 +27,7 @@ import com.maddyhome.idea.vim.ex.flags
|
||||
|
||||
class NoHLSearchHandler : CommandHandler.SingleExecution() {
|
||||
override val names = commands("noh[lsearch]")
|
||||
override val argFlags = flags(RangeFlag.RANGE_FORBIDDEN, ArgumentFlag.ARGUMENT_FORBIDDEN)
|
||||
override val argFlags = flags(RangeFlag.RANGE_FORBIDDEN, ArgumentFlag.ARGUMENT_FORBIDDEN, Access.READ_ONLY)
|
||||
override fun execute(editor: Editor, context: DataContext, cmd: ExCommand): Boolean {
|
||||
VimPlugin.getSearch().clearSearchHighlight()
|
||||
return true
|
||||
|
@@ -21,16 +21,11 @@ package com.maddyhome.idea.vim.ex.handler
|
||||
import com.intellij.openapi.actionSystem.DataContext
|
||||
import com.intellij.openapi.editor.Editor
|
||||
import com.maddyhome.idea.vim.VimPlugin
|
||||
import com.maddyhome.idea.vim.ex.CommandHandler
|
||||
import com.maddyhome.idea.vim.ex.CommandHandlerFlags
|
||||
import com.maddyhome.idea.vim.ex.CommandName
|
||||
import com.maddyhome.idea.vim.ex.ExCommand
|
||||
import com.maddyhome.idea.vim.ex.commands
|
||||
import com.maddyhome.idea.vim.ex.flags
|
||||
import com.maddyhome.idea.vim.ex.*
|
||||
|
||||
class OnlyHandler : CommandHandler.SingleExecution() {
|
||||
override val names: Array<CommandName> = commands("on[ly]")
|
||||
override val argFlags: CommandHandlerFlags = flags(RangeFlag.RANGE_OPTIONAL, ArgumentFlag.ARGUMENT_OPTIONAL)
|
||||
override val argFlags: CommandHandlerFlags = flags(RangeFlag.RANGE_OPTIONAL, ArgumentFlag.ARGUMENT_OPTIONAL, Access.READ_ONLY)
|
||||
|
||||
override fun execute(editor: Editor, context: DataContext, cmd: ExCommand): Boolean {
|
||||
VimPlugin.getWindow().closeAllExceptCurrent(context)
|
||||
|
@@ -22,14 +22,13 @@ import com.intellij.openapi.actionSystem.DataContext
|
||||
import com.intellij.openapi.editor.Editor
|
||||
import com.maddyhome.idea.vim.VimPlugin
|
||||
import com.maddyhome.idea.vim.ex.CommandHandler
|
||||
import com.maddyhome.idea.vim.ex.CommandHandler.Flag.DONT_REOPEN
|
||||
import com.maddyhome.idea.vim.ex.ExCommand
|
||||
import com.maddyhome.idea.vim.ex.commands
|
||||
import com.maddyhome.idea.vim.ex.flags
|
||||
|
||||
class PreviousFileHandler : CommandHandler.SingleExecution() {
|
||||
override val names = commands("N[ext]", "prev[ious]")
|
||||
override val argFlags = flags(RangeFlag.RANGE_IS_COUNT, ArgumentFlag.ARGUMENT_OPTIONAL, DONT_REOPEN)
|
||||
override val argFlags = flags(RangeFlag.RANGE_IS_COUNT, ArgumentFlag.ARGUMENT_OPTIONAL, Access.READ_ONLY)
|
||||
override fun execute(editor: Editor, context: DataContext, cmd: ExCommand): Boolean {
|
||||
val count = cmd.getCount(editor, context, 1, true)
|
||||
|
||||
|
@@ -28,7 +28,7 @@ import com.maddyhome.idea.vim.ex.flags
|
||||
|
||||
class PreviousTabHandler : CommandHandler.SingleExecution() {
|
||||
override val names = commands("tabp[revious]", "tabN[ext]")
|
||||
override val argFlags = flags(RangeFlag.RANGE_FORBIDDEN, ArgumentFlag.ARGUMENT_OPTIONAL)
|
||||
override val argFlags = flags(RangeFlag.RANGE_FORBIDDEN, ArgumentFlag.ARGUMENT_OPTIONAL, Access.READ_ONLY)
|
||||
override fun execute(editor: Editor, context: DataContext, cmd: ExCommand): Boolean {
|
||||
VimPlugin.getMotion().moveCaretGotoPreviousTab(editor, context, cmd.argument.toIntOrNull() ?: 0)
|
||||
return true
|
||||
|
@@ -28,7 +28,7 @@ import com.maddyhome.idea.vim.ex.flags
|
||||
|
||||
class PromptFindHandler : CommandHandler.SingleExecution() {
|
||||
override val names = commands("pro[mptfind]")
|
||||
override val argFlags = flags(RangeFlag.RANGE_FORBIDDEN, ArgumentFlag.ARGUMENT_OPTIONAL)
|
||||
override val argFlags = flags(RangeFlag.RANGE_FORBIDDEN, ArgumentFlag.ARGUMENT_OPTIONAL, Access.READ_ONLY)
|
||||
override fun execute(editor: Editor, context: DataContext, cmd: ExCommand) =
|
||||
KeyHandler.executeAction("Find", context)
|
||||
}
|
||||
|
@@ -28,7 +28,7 @@ import com.maddyhome.idea.vim.ex.flags
|
||||
|
||||
class PromptReplaceHandler : CommandHandler.SingleExecution() {
|
||||
override val names = commands("promptr[epl]")
|
||||
override val argFlags = flags(RangeFlag.RANGE_FORBIDDEN, ArgumentFlag.ARGUMENT_OPTIONAL)
|
||||
override val argFlags = flags(RangeFlag.RANGE_FORBIDDEN, ArgumentFlag.ARGUMENT_OPTIONAL, Access.READ_ONLY)
|
||||
override fun execute(editor: Editor, context: DataContext, cmd: ExCommand) =
|
||||
KeyHandler.executeAction("Replace", context)
|
||||
}
|
||||
|
@@ -30,7 +30,7 @@ import com.maddyhome.idea.vim.group.copy.PutData
|
||||
|
||||
class PutLinesHandler : CommandHandler.SingleExecution() {
|
||||
override val names = commands("pu[t]")
|
||||
override val argFlags = flags(RangeFlag.RANGE_OPTIONAL, ArgumentFlag.ARGUMENT_OPTIONAL)
|
||||
override val argFlags = flags(RangeFlag.RANGE_OPTIONAL, ArgumentFlag.ARGUMENT_OPTIONAL, Access.READ_ONLY)
|
||||
|
||||
override fun execute(editor: Editor, context: DataContext, cmd: ExCommand): Boolean {
|
||||
if (editor.isOneLineMode) return false
|
||||
|
@@ -22,14 +22,13 @@ import com.intellij.openapi.actionSystem.DataContext
|
||||
import com.intellij.openapi.editor.Editor
|
||||
import com.maddyhome.idea.vim.VimPlugin
|
||||
import com.maddyhome.idea.vim.ex.CommandHandler
|
||||
import com.maddyhome.idea.vim.ex.CommandHandler.Flag.DONT_REOPEN
|
||||
import com.maddyhome.idea.vim.ex.ExCommand
|
||||
import com.maddyhome.idea.vim.ex.commands
|
||||
import com.maddyhome.idea.vim.ex.flags
|
||||
|
||||
class QuitHandler : CommandHandler.SingleExecution() {
|
||||
override val names = commands("q[uit]", "clo[se]", "hid[e]")
|
||||
override val argFlags = flags(RangeFlag.RANGE_OPTIONAL, ArgumentFlag.ARGUMENT_OPTIONAL, DONT_REOPEN)
|
||||
override val argFlags = flags(RangeFlag.RANGE_OPTIONAL, ArgumentFlag.ARGUMENT_OPTIONAL, Access.READ_ONLY)
|
||||
override fun execute(editor: Editor, context: DataContext, cmd: ExCommand): Boolean {
|
||||
VimPlugin.getFile().closeFile(editor, context)
|
||||
return true
|
||||
|
@@ -21,7 +21,6 @@ package com.maddyhome.idea.vim.ex.handler
|
||||
import com.intellij.openapi.actionSystem.DataContext
|
||||
import com.intellij.openapi.editor.Editor
|
||||
import com.maddyhome.idea.vim.ex.CommandHandler
|
||||
import com.maddyhome.idea.vim.ex.CommandHandler.Flag.WRITABLE
|
||||
import com.maddyhome.idea.vim.ex.ExCommand
|
||||
import com.maddyhome.idea.vim.ex.commands
|
||||
import com.maddyhome.idea.vim.ex.flags
|
||||
@@ -29,6 +28,6 @@ import com.maddyhome.idea.vim.helper.UndoRedoHelper
|
||||
|
||||
class RedoHandler : CommandHandler.SingleExecution() {
|
||||
override val names = commands("red[o]")
|
||||
override val argFlags = flags(RangeFlag.RANGE_FORBIDDEN, ArgumentFlag.ARGUMENT_FORBIDDEN, WRITABLE)
|
||||
override val argFlags = flags(RangeFlag.RANGE_FORBIDDEN, ArgumentFlag.ARGUMENT_FORBIDDEN, Access.WRITABLE)
|
||||
override fun execute(editor: Editor, context: DataContext, cmd: ExCommand) = UndoRedoHelper.redo(context)
|
||||
}
|
||||
|
@@ -21,16 +21,12 @@ package com.maddyhome.idea.vim.ex.handler
|
||||
import com.intellij.openapi.actionSystem.DataContext
|
||||
import com.intellij.openapi.editor.Editor
|
||||
import com.maddyhome.idea.vim.VimPlugin
|
||||
import com.maddyhome.idea.vim.ex.CommandHandler
|
||||
import com.maddyhome.idea.vim.ex.ExCommand
|
||||
import com.maddyhome.idea.vim.ex.ExOutputModel
|
||||
import com.maddyhome.idea.vim.ex.commands
|
||||
import com.maddyhome.idea.vim.ex.flags
|
||||
import com.maddyhome.idea.vim.ex.*
|
||||
import com.maddyhome.idea.vim.helper.StringHelper
|
||||
|
||||
class RegistersHandler : CommandHandler.SingleExecution() {
|
||||
override val names = commands("di[splay]", "reg[isters]")
|
||||
override val argFlags = flags(RangeFlag.RANGE_OPTIONAL, ArgumentFlag.ARGUMENT_OPTIONAL)
|
||||
override val argFlags = flags(RangeFlag.RANGE_OPTIONAL, ArgumentFlag.ARGUMENT_OPTIONAL, Access.READ_ONLY)
|
||||
override fun execute(editor: Editor, context: DataContext, cmd: ExCommand): Boolean {
|
||||
val regs = VimPlugin.getRegister().registers.joinToString("\n", prefix = "--- Registers ---\n") { reg ->
|
||||
""""${reg.name} ${StringHelper.toKeyNotation(reg.keys)}"""
|
||||
|
@@ -22,20 +22,13 @@ import com.intellij.openapi.actionSystem.DataContext
|
||||
import com.intellij.openapi.editor.Caret
|
||||
import com.intellij.openapi.editor.Editor
|
||||
import com.maddyhome.idea.vim.VimPlugin
|
||||
import com.maddyhome.idea.vim.ex.CommandHandler
|
||||
import com.maddyhome.idea.vim.ex.*
|
||||
import com.maddyhome.idea.vim.ex.CommandHandler.Flag.DONT_SAVE_LAST
|
||||
import com.maddyhome.idea.vim.ex.CommandHandlerFlags
|
||||
import com.maddyhome.idea.vim.ex.CommandName
|
||||
import com.maddyhome.idea.vim.ex.CommandParser
|
||||
import com.maddyhome.idea.vim.ex.ExCommand
|
||||
import com.maddyhome.idea.vim.ex.ExException
|
||||
import com.maddyhome.idea.vim.ex.commands
|
||||
import com.maddyhome.idea.vim.ex.flags
|
||||
import com.maddyhome.idea.vim.group.MotionGroup
|
||||
|
||||
class RepeatHandler : CommandHandler.ForEachCaret() {
|
||||
override val names: Array<CommandName> = commands("@")
|
||||
override val argFlags: CommandHandlerFlags = flags(RangeFlag.RANGE_OPTIONAL, ArgumentFlag.ARGUMENT_REQUIRED, DONT_SAVE_LAST)
|
||||
override val argFlags: CommandHandlerFlags = flags(RangeFlag.RANGE_OPTIONAL, ArgumentFlag.ARGUMENT_REQUIRED, Access.SELF_SYNCHRONIZED, DONT_SAVE_LAST)
|
||||
|
||||
private var lastArg = ':'
|
||||
|
||||
|
@@ -22,14 +22,13 @@ import com.intellij.openapi.actionSystem.DataContext
|
||||
import com.intellij.openapi.editor.Editor
|
||||
import com.maddyhome.idea.vim.VimPlugin
|
||||
import com.maddyhome.idea.vim.ex.CommandHandler
|
||||
import com.maddyhome.idea.vim.ex.CommandHandler.Flag.DONT_REOPEN
|
||||
import com.maddyhome.idea.vim.ex.ExCommand
|
||||
import com.maddyhome.idea.vim.ex.commands
|
||||
import com.maddyhome.idea.vim.ex.flags
|
||||
|
||||
class SelectFileHandler : CommandHandler.SingleExecution() {
|
||||
override val names = commands("argu[ment]")
|
||||
override val argFlags = flags(RangeFlag.RANGE_IS_COUNT, ArgumentFlag.ARGUMENT_OPTIONAL, DONT_REOPEN)
|
||||
override val argFlags = flags(RangeFlag.RANGE_IS_COUNT, ArgumentFlag.ARGUMENT_OPTIONAL, Access.READ_ONLY)
|
||||
|
||||
override fun execute(editor: Editor, context: DataContext, cmd: ExCommand): Boolean {
|
||||
val count = cmd.getCount(editor, context, 0, true)
|
||||
|
@@ -23,14 +23,13 @@ import com.intellij.openapi.editor.Editor
|
||||
import com.maddyhome.idea.vim.VimPlugin
|
||||
import com.maddyhome.idea.vim.ex.CommandHandler
|
||||
import com.maddyhome.idea.vim.ex.CommandHandler.ArgumentFlag.ARGUMENT_OPTIONAL
|
||||
import com.maddyhome.idea.vim.ex.CommandHandler.Flag.DONT_REOPEN
|
||||
import com.maddyhome.idea.vim.ex.ExCommand
|
||||
import com.maddyhome.idea.vim.ex.commands
|
||||
import com.maddyhome.idea.vim.ex.flags
|
||||
|
||||
class SelectFirstFileHandler : CommandHandler.SingleExecution() {
|
||||
override val names = commands("fir[st]", "rew[ind]")
|
||||
override val argFlags = flags(RangeFlag.RANGE_OPTIONAL, ARGUMENT_OPTIONAL, DONT_REOPEN)
|
||||
override val argFlags = flags(RangeFlag.RANGE_OPTIONAL, ARGUMENT_OPTIONAL, Access.READ_ONLY)
|
||||
override fun execute(editor: Editor, context: DataContext, cmd: ExCommand): Boolean {
|
||||
val res = VimPlugin.getFile().selectFile(0, context)
|
||||
if (res) {
|
||||
|
@@ -22,14 +22,13 @@ import com.intellij.openapi.actionSystem.DataContext
|
||||
import com.intellij.openapi.editor.Editor
|
||||
import com.maddyhome.idea.vim.VimPlugin
|
||||
import com.maddyhome.idea.vim.ex.CommandHandler
|
||||
import com.maddyhome.idea.vim.ex.CommandHandler.Flag.DONT_REOPEN
|
||||
import com.maddyhome.idea.vim.ex.ExCommand
|
||||
import com.maddyhome.idea.vim.ex.commands
|
||||
import com.maddyhome.idea.vim.ex.flags
|
||||
|
||||
class SelectLastFileHandler : CommandHandler.SingleExecution() {
|
||||
override val names = commands("la[st]")
|
||||
override val argFlags = flags(RangeFlag.RANGE_OPTIONAL, ArgumentFlag.ARGUMENT_OPTIONAL, DONT_REOPEN)
|
||||
override val argFlags = flags(RangeFlag.RANGE_OPTIONAL, ArgumentFlag.ARGUMENT_OPTIONAL, Access.READ_ONLY)
|
||||
override fun execute(editor: Editor, context: DataContext, cmd: ExCommand): Boolean {
|
||||
val res = VimPlugin.getFile().selectFile(999, context)
|
||||
if (res) {
|
||||
|
@@ -29,7 +29,7 @@ import com.maddyhome.idea.vim.option.OptionsManager
|
||||
|
||||
class SetHandler : CommandHandler.SingleExecution(), VimScriptCommandHandler {
|
||||
override val names = commands("se[t]")
|
||||
override val argFlags = flags(RangeFlag.RANGE_OPTIONAL, ArgumentFlag.ARGUMENT_OPTIONAL)
|
||||
override val argFlags = flags(RangeFlag.RANGE_OPTIONAL, ArgumentFlag.ARGUMENT_OPTIONAL, Access.READ_ONLY)
|
||||
|
||||
override fun execute(editor: Editor, context: DataContext, cmd: ExCommand) =
|
||||
parseOptionLine(editor, cmd, true)
|
||||
|
@@ -30,7 +30,7 @@ import com.maddyhome.idea.vim.ex.flags
|
||||
*/
|
||||
class ShellHandler : CommandHandler.SingleExecution() {
|
||||
override val names = commands("sh[ell]")
|
||||
override val argFlags = flags(RangeFlag.RANGE_FORBIDDEN, ArgumentFlag.ARGUMENT_FORBIDDEN)
|
||||
override val argFlags = flags(RangeFlag.RANGE_FORBIDDEN, ArgumentFlag.ARGUMENT_FORBIDDEN, Access.READ_ONLY)
|
||||
override fun execute(editor: Editor, context: DataContext, cmd: ExCommand) =
|
||||
KeyHandler.executeAction("ActivateTerminalToolWindow", context)
|
||||
}
|
||||
|
@@ -23,17 +23,11 @@ import com.intellij.openapi.editor.Caret
|
||||
import com.intellij.openapi.editor.Editor
|
||||
import com.maddyhome.idea.vim.VimPlugin
|
||||
import com.maddyhome.idea.vim.common.TextRange
|
||||
import com.maddyhome.idea.vim.ex.CommandHandler
|
||||
import com.maddyhome.idea.vim.ex.CommandHandler.Flag.WRITABLE
|
||||
import com.maddyhome.idea.vim.ex.CommandHandlerFlags
|
||||
import com.maddyhome.idea.vim.ex.CommandName
|
||||
import com.maddyhome.idea.vim.ex.ExCommand
|
||||
import com.maddyhome.idea.vim.ex.commands
|
||||
import com.maddyhome.idea.vim.ex.flags
|
||||
import com.maddyhome.idea.vim.ex.*
|
||||
|
||||
class ShiftLeftHandler : CommandHandler.ForEachCaret() {
|
||||
override val names: Array<CommandName> = commands("<[${"<".repeat(31)}]")
|
||||
override val argFlags: CommandHandlerFlags = flags(RangeFlag.RANGE_OPTIONAL, ArgumentFlag.ARGUMENT_OPTIONAL, WRITABLE)
|
||||
override val argFlags: CommandHandlerFlags = flags(RangeFlag.RANGE_OPTIONAL, ArgumentFlag.ARGUMENT_OPTIONAL, Access.WRITABLE)
|
||||
|
||||
override fun execute(editor: Editor, caret: Caret, context: DataContext, cmd: ExCommand): Boolean {
|
||||
val range = cmd.getTextRange(editor, caret, context, true)
|
||||
|
@@ -23,17 +23,11 @@ import com.intellij.openapi.editor.Caret
|
||||
import com.intellij.openapi.editor.Editor
|
||||
import com.maddyhome.idea.vim.VimPlugin
|
||||
import com.maddyhome.idea.vim.common.TextRange
|
||||
import com.maddyhome.idea.vim.ex.CommandHandler
|
||||
import com.maddyhome.idea.vim.ex.CommandHandler.Flag.WRITABLE
|
||||
import com.maddyhome.idea.vim.ex.CommandHandlerFlags
|
||||
import com.maddyhome.idea.vim.ex.CommandName
|
||||
import com.maddyhome.idea.vim.ex.ExCommand
|
||||
import com.maddyhome.idea.vim.ex.commands
|
||||
import com.maddyhome.idea.vim.ex.flags
|
||||
import com.maddyhome.idea.vim.ex.*
|
||||
|
||||
class ShiftRightHandler : CommandHandler.ForEachCaret() {
|
||||
override val names: Array<CommandName> = commands(">[${">".repeat(31)}]")
|
||||
override val argFlags: CommandHandlerFlags = flags(RangeFlag.RANGE_OPTIONAL, ArgumentFlag.ARGUMENT_OPTIONAL, WRITABLE)
|
||||
override val argFlags: CommandHandlerFlags = flags(RangeFlag.RANGE_OPTIONAL, ArgumentFlag.ARGUMENT_OPTIONAL, Access.WRITABLE)
|
||||
|
||||
override fun execute(editor: Editor, caret: Caret, context: DataContext, cmd: ExCommand): Boolean {
|
||||
val range = cmd.getTextRange(editor, caret, context, true)
|
||||
|
@@ -23,13 +23,7 @@ import com.intellij.openapi.editor.Caret
|
||||
import com.intellij.openapi.editor.Editor
|
||||
import com.intellij.openapi.util.text.StringUtil
|
||||
import com.maddyhome.idea.vim.VimPlugin
|
||||
import com.maddyhome.idea.vim.ex.CommandHandler
|
||||
import com.maddyhome.idea.vim.ex.CommandHandler.Flag.WRITABLE
|
||||
import com.maddyhome.idea.vim.ex.ExCommand
|
||||
import com.maddyhome.idea.vim.ex.ExException
|
||||
import com.maddyhome.idea.vim.ex.LineRange
|
||||
import com.maddyhome.idea.vim.ex.commands
|
||||
import com.maddyhome.idea.vim.ex.flags
|
||||
import com.maddyhome.idea.vim.ex.*
|
||||
import com.maddyhome.idea.vim.helper.inBlockSubMode
|
||||
import java.util.*
|
||||
|
||||
@@ -38,7 +32,7 @@ import java.util.*
|
||||
*/
|
||||
class SortHandler : CommandHandler.SingleExecution() {
|
||||
override val names = commands("sor[t]")
|
||||
override val argFlags = flags(RangeFlag.RANGE_OPTIONAL, ArgumentFlag.ARGUMENT_OPTIONAL, WRITABLE)
|
||||
override val argFlags = flags(RangeFlag.RANGE_OPTIONAL, ArgumentFlag.ARGUMENT_OPTIONAL, Access.WRITABLE)
|
||||
|
||||
@Throws(ExException::class)
|
||||
override fun execute(editor: Editor, context: DataContext, cmd: ExCommand): Boolean {
|
||||
|
@@ -33,7 +33,7 @@ import java.io.File
|
||||
*/
|
||||
class SourceHandler : CommandHandler.SingleExecution(), VimScriptCommandHandler {
|
||||
override val names = commands("so[urce]")
|
||||
override val argFlags = flags(RangeFlag.RANGE_FORBIDDEN, ArgumentFlag.ARGUMENT_REQUIRED)
|
||||
override val argFlags = flags(RangeFlag.RANGE_FORBIDDEN, ArgumentFlag.ARGUMENT_REQUIRED, Access.READ_ONLY)
|
||||
override fun execute(editor: Editor, context: DataContext, cmd: ExCommand): Boolean {
|
||||
execute(cmd)
|
||||
return true
|
||||
|
@@ -22,14 +22,13 @@ import com.intellij.openapi.actionSystem.DataContext
|
||||
import com.intellij.openapi.editor.Editor
|
||||
import com.maddyhome.idea.vim.VimPlugin
|
||||
import com.maddyhome.idea.vim.ex.CommandHandler
|
||||
import com.maddyhome.idea.vim.ex.CommandHandler.Flag.DONT_REOPEN
|
||||
import com.maddyhome.idea.vim.ex.ExCommand
|
||||
import com.maddyhome.idea.vim.ex.commands
|
||||
import com.maddyhome.idea.vim.ex.flags
|
||||
|
||||
class SplitHandler : CommandHandler.SingleExecution() {
|
||||
override val names = commands("vs[plit]", "sp[lit]")
|
||||
override val argFlags = flags(RangeFlag.RANGE_FORBIDDEN, ArgumentFlag.ARGUMENT_OPTIONAL, DONT_REOPEN)
|
||||
override val argFlags = flags(RangeFlag.RANGE_FORBIDDEN, ArgumentFlag.ARGUMENT_OPTIONAL, Access.READ_ONLY)
|
||||
override fun execute(editor: Editor, context: DataContext, cmd: ExCommand): Boolean {
|
||||
if (cmd.command.startsWith("v")) {
|
||||
VimPlugin.getWindow().splitWindowVertical(context, cmd.argument)
|
||||
|
@@ -22,14 +22,13 @@ import com.intellij.openapi.actionSystem.DataContext
|
||||
import com.intellij.openapi.editor.Editor
|
||||
import com.maddyhome.idea.vim.VimPlugin
|
||||
import com.maddyhome.idea.vim.ex.CommandHandler
|
||||
import com.maddyhome.idea.vim.ex.CommandHandler.Flag.WRITABLE
|
||||
import com.maddyhome.idea.vim.ex.ExCommand
|
||||
import com.maddyhome.idea.vim.ex.commands
|
||||
import com.maddyhome.idea.vim.ex.flags
|
||||
|
||||
class SubstituteHandler : CommandHandler.SingleExecution() {
|
||||
override val names = commands("s[ubstitute]", "&", "~")
|
||||
override val argFlags = flags(RangeFlag.RANGE_OPTIONAL, ArgumentFlag.ARGUMENT_OPTIONAL, WRITABLE)
|
||||
override val argFlags = flags(RangeFlag.RANGE_OPTIONAL, ArgumentFlag.ARGUMENT_OPTIONAL, Access.SELF_SYNCHRONIZED)
|
||||
override fun execute(editor: Editor, context: DataContext, cmd: ExCommand): Boolean {
|
||||
var result = true
|
||||
for (caret in editor.caretModel.allCarets) {
|
||||
|
@@ -28,7 +28,7 @@ import com.maddyhome.idea.vim.ex.flags
|
||||
|
||||
class TabOnlyHandler : CommandHandler.SingleExecution() {
|
||||
override val names = commands("tabo[nly]")
|
||||
override val argFlags = flags(RangeFlag.RANGE_IS_COUNT, ArgumentFlag.ARGUMENT_FORBIDDEN)
|
||||
override val argFlags = flags(RangeFlag.RANGE_IS_COUNT, ArgumentFlag.ARGUMENT_FORBIDDEN, Access.READ_ONLY)
|
||||
override fun execute(editor: Editor, context: DataContext, cmd: ExCommand): Boolean {
|
||||
VimPlugin.getWindow().closeAllExceptCurrentTab(context)
|
||||
return true
|
||||
|
@@ -21,7 +21,6 @@ package com.maddyhome.idea.vim.ex.handler
|
||||
import com.intellij.openapi.actionSystem.DataContext
|
||||
import com.intellij.openapi.editor.Editor
|
||||
import com.maddyhome.idea.vim.ex.CommandHandler
|
||||
import com.maddyhome.idea.vim.ex.CommandHandler.Flag.WRITABLE
|
||||
import com.maddyhome.idea.vim.ex.ExCommand
|
||||
import com.maddyhome.idea.vim.ex.commands
|
||||
import com.maddyhome.idea.vim.ex.flags
|
||||
@@ -29,6 +28,6 @@ import com.maddyhome.idea.vim.helper.UndoRedoHelper
|
||||
|
||||
class UndoHandler : CommandHandler.SingleExecution() {
|
||||
override val names = commands("u[ndo]")
|
||||
override val argFlags = flags(RangeFlag.RANGE_FORBIDDEN, ArgumentFlag.ARGUMENT_FORBIDDEN, WRITABLE)
|
||||
override val argFlags = flags(RangeFlag.RANGE_FORBIDDEN, ArgumentFlag.ARGUMENT_FORBIDDEN, Access.WRITABLE)
|
||||
override fun execute(editor: Editor, context: DataContext, cmd: ExCommand) = UndoRedoHelper.undo(context)
|
||||
}
|
||||
|
@@ -28,7 +28,7 @@ import com.maddyhome.idea.vim.ex.flags
|
||||
|
||||
class WriteAllHandler : CommandHandler.SingleExecution() {
|
||||
override val names = commands("wa[ll]")
|
||||
override val argFlags = flags(RangeFlag.RANGE_OPTIONAL, ArgumentFlag.ARGUMENT_OPTIONAL)
|
||||
override val argFlags = flags(RangeFlag.RANGE_OPTIONAL, ArgumentFlag.ARGUMENT_OPTIONAL, Access.READ_ONLY)
|
||||
override fun execute(editor: Editor, context: DataContext, cmd: ExCommand): Boolean {
|
||||
VimPlugin.getFile().saveFiles(context)
|
||||
return true
|
||||
|
@@ -28,7 +28,7 @@ import com.maddyhome.idea.vim.ex.flags
|
||||
|
||||
class WriteHandler : CommandHandler.SingleExecution() {
|
||||
override val names = commands("w[rite]")
|
||||
override val argFlags = flags(RangeFlag.RANGE_OPTIONAL, ArgumentFlag.ARGUMENT_OPTIONAL)
|
||||
override val argFlags = flags(RangeFlag.RANGE_OPTIONAL, ArgumentFlag.ARGUMENT_OPTIONAL, Access.READ_ONLY)
|
||||
override fun execute(editor: Editor, context: DataContext, cmd: ExCommand): Boolean {
|
||||
VimPlugin.getFile().saveFile(context)
|
||||
return true
|
||||
|
@@ -28,7 +28,7 @@ import com.maddyhome.idea.vim.ex.flags
|
||||
|
||||
class WriteNextFileHandler : CommandHandler.SingleExecution() {
|
||||
override val names = commands("wn[ext]")
|
||||
override val argFlags = flags(RangeFlag.RANGE_IS_COUNT, ArgumentFlag.ARGUMENT_OPTIONAL)
|
||||
override val argFlags = flags(RangeFlag.RANGE_IS_COUNT, ArgumentFlag.ARGUMENT_OPTIONAL, Access.READ_ONLY)
|
||||
override fun execute(editor: Editor, context: DataContext, cmd: ExCommand): Boolean {
|
||||
val count = cmd.getCount(editor, context, 1, true)
|
||||
|
||||
|
@@ -28,7 +28,7 @@ import com.maddyhome.idea.vim.ex.flags
|
||||
|
||||
class WritePreviousFileHandler : CommandHandler.SingleExecution() {
|
||||
override val names = commands("wN[ext]", "wp[revious]")
|
||||
override val argFlags = flags(RangeFlag.RANGE_OPTIONAL, ArgumentFlag.ARGUMENT_OPTIONAL)
|
||||
override val argFlags = flags(RangeFlag.RANGE_OPTIONAL, ArgumentFlag.ARGUMENT_OPTIONAL, Access.READ_ONLY)
|
||||
override fun execute(editor: Editor, context: DataContext, cmd: ExCommand): Boolean {
|
||||
val count = cmd.getCount(editor, context, 1, true)
|
||||
|
||||
|
@@ -22,14 +22,13 @@ import com.intellij.openapi.actionSystem.DataContext
|
||||
import com.intellij.openapi.editor.Editor
|
||||
import com.maddyhome.idea.vim.VimPlugin
|
||||
import com.maddyhome.idea.vim.ex.CommandHandler
|
||||
import com.maddyhome.idea.vim.ex.CommandHandler.Flag.DONT_REOPEN
|
||||
import com.maddyhome.idea.vim.ex.ExCommand
|
||||
import com.maddyhome.idea.vim.ex.commands
|
||||
import com.maddyhome.idea.vim.ex.flags
|
||||
|
||||
class WriteQuitHandler : CommandHandler.SingleExecution() {
|
||||
override val names = commands("wq", "exi[t]", "x[it]")
|
||||
override val argFlags = flags(RangeFlag.RANGE_OPTIONAL, ArgumentFlag.ARGUMENT_OPTIONAL, DONT_REOPEN)
|
||||
override val argFlags = flags(RangeFlag.RANGE_OPTIONAL, ArgumentFlag.ARGUMENT_OPTIONAL, Access.READ_ONLY)
|
||||
override fun execute(editor: Editor, context: DataContext, cmd: ExCommand): Boolean {
|
||||
VimPlugin.getFile().saveFile(context)
|
||||
VimPlugin.getFile().closeFile(editor, context)
|
||||
|
@@ -23,15 +23,11 @@ import com.intellij.openapi.editor.Editor
|
||||
import com.maddyhome.idea.vim.VimPlugin
|
||||
import com.maddyhome.idea.vim.command.SelectionType
|
||||
import com.maddyhome.idea.vim.common.TextRange
|
||||
import com.maddyhome.idea.vim.ex.CommandHandler
|
||||
import com.maddyhome.idea.vim.ex.ExCommand
|
||||
import com.maddyhome.idea.vim.ex.ExException
|
||||
import com.maddyhome.idea.vim.ex.commands
|
||||
import com.maddyhome.idea.vim.ex.flags
|
||||
import com.maddyhome.idea.vim.ex.*
|
||||
|
||||
class YankLinesHandler : CommandHandler.SingleExecution() {
|
||||
override val names = commands("y[ank]")
|
||||
override val argFlags = flags(RangeFlag.RANGE_OPTIONAL, ArgumentFlag.ARGUMENT_OPTIONAL)
|
||||
override val argFlags = flags(RangeFlag.RANGE_OPTIONAL, ArgumentFlag.ARGUMENT_OPTIONAL, Access.READ_ONLY)
|
||||
|
||||
@Throws(ExException::class)
|
||||
override fun execute(editor: Editor, context: DataContext, cmd: ExCommand): Boolean {
|
||||
|
@@ -127,7 +127,7 @@ public class VimExtensionFacade {
|
||||
else {
|
||||
final Ref<String> text = Ref.create("");
|
||||
// XXX: The Ex entry panel is used only for UI here, its logic might be inappropriate for input()
|
||||
final ExEntryPanel exEntryPanel = ExEntryPanel.getInstance();
|
||||
final ExEntryPanel exEntryPanel = ExEntryPanel.getInstanceWithoutShortcuts();
|
||||
exEntryPanel.activate(editor, new EditorDataContext(editor), prompt.isEmpty() ? " " : prompt, "", 1);
|
||||
ModalEntry.activate(key -> {
|
||||
if (StringHelper.isCloseKeyStroke(key)) {
|
||||
|
@@ -36,8 +36,6 @@ import com.maddyhome.idea.vim.group.ChangeGroup;
|
||||
import com.maddyhome.idea.vim.helper.EditorHelper;
|
||||
import com.maddyhome.idea.vim.key.OperatorFunction;
|
||||
import com.maddyhome.idea.vim.option.ClipboardOptionsData;
|
||||
import com.maddyhome.idea.vim.option.ListOption;
|
||||
import com.maddyhome.idea.vim.option.OptionsManager;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
@@ -197,6 +195,8 @@ public class VimSurroundExtension extends VimNonDisposableExtension {
|
||||
List<KeyStroke> innerValue = getRegister(REGISTER);
|
||||
if (innerValue == null) {
|
||||
innerValue = new ArrayList<>();
|
||||
} else {
|
||||
innerValue = new ArrayList<>(innerValue);
|
||||
}
|
||||
|
||||
// Delete the surrounding
|
||||
@@ -222,11 +222,9 @@ public class VimSurroundExtension extends VimNonDisposableExtension {
|
||||
}
|
||||
|
||||
private static void perform(@NotNull String sequence, @NotNull Editor editor) {
|
||||
ListOption options = OptionsManager.INSTANCE.getClipboard();
|
||||
final boolean containedBefore = options.contains(ClipboardOptionsData.ideaput);
|
||||
options.remove(ClipboardOptionsData.ideaput);
|
||||
executeNormal(parseKeys("\"" + REGISTER + sequence), editor);
|
||||
if (containedBefore) options.append(ClipboardOptionsData.ideaput);
|
||||
try (ClipboardOptionsData.IdeaputDisabler ignored = new ClipboardOptionsData.IdeaputDisabler()) {
|
||||
executeNormal(parseKeys("\"" + REGISTER + sequence), editor);
|
||||
}
|
||||
}
|
||||
|
||||
private static void pasteSurround(@NotNull List<KeyStroke> innerValue, @NotNull Editor editor) {
|
||||
|
@@ -575,10 +575,13 @@ public class ChangeGroup {
|
||||
int len = EditorHelper.getLineLength(editor, EditorHelper.visualLineToLogicalLine(editor, vp.line));
|
||||
if (vp.column < len) {
|
||||
int offset = EditorHelper.visualPositionToOffset(editor, vp);
|
||||
char ch = editor.getDocument().getCharsSequence().charAt(offset);
|
||||
editor.getDocument().insertString(caret.getOffset(), Character.toString(ch));
|
||||
MotionGroup.moveCaret(editor, caret, VimPlugin.getMotion().moveCaretHorizontal(editor, caret, 1, true));
|
||||
res = true;
|
||||
CharSequence charsSequence = editor.getDocument().getCharsSequence();
|
||||
if (offset < charsSequence.length()) {
|
||||
char ch = charsSequence.charAt(offset);
|
||||
editor.getDocument().insertString(caret.getOffset(), Character.toString(ch));
|
||||
MotionGroup.moveCaret(editor, caret, VimPlugin.getMotion().moveCaretHorizontal(editor, caret, 1, true));
|
||||
res = true;
|
||||
}
|
||||
}
|
||||
|
||||
return res;
|
||||
|
@@ -258,7 +258,10 @@ public class EditorGroup {
|
||||
if (VimPlugin.isEnabled() && EditorHelper.isFileEditor(editor)) {
|
||||
final boolean relativeLineNumber = OptionsManager.INSTANCE.getRelativenumber().isSet();
|
||||
final boolean lineNumber = OptionsManager.INSTANCE.getNumber().isSet();
|
||||
if (relativeLineNumber && lineNumber && isCaretLine(line, editor)) {
|
||||
if (editor.getDocument().getLineCount() == 0) {
|
||||
return null;
|
||||
}
|
||||
else if (relativeLineNumber && lineNumber && isCaretLine(line, editor)) {
|
||||
return lineNumberToString(getLineNumber(line), editor);
|
||||
}
|
||||
else if (relativeLineNumber) {
|
||||
|
@@ -154,7 +154,7 @@ public class FileGroup {
|
||||
final EditorWindow window = fileEditorManager.getCurrentWindow();
|
||||
final VirtualFile virtualFile = EditorHelper.getVirtualFile(editor);
|
||||
|
||||
if (virtualFile != null) {
|
||||
if (virtualFile != null && window != null) {
|
||||
window.closeFile(virtualFile);
|
||||
}
|
||||
}
|
||||
@@ -220,7 +220,7 @@ public class FileGroup {
|
||||
if (project == null) return;
|
||||
FileEditorManager fem = FileEditorManager.getInstance(project); // API change - don't merge
|
||||
VirtualFile vf = lastSelections.get(fem);
|
||||
if (vf != null) {
|
||||
if (vf != null && vf.isValid()) {
|
||||
fem.openFile(vf, true);
|
||||
}
|
||||
else {
|
||||
@@ -234,7 +234,10 @@ public class FileGroup {
|
||||
FileEditor[] feditors = fMgr.openFile(file, true);
|
||||
if (feditors.length > 0) {
|
||||
if (feditors[0] instanceof TextEditor) {
|
||||
return ((TextEditor)feditors[0]).getEditor();
|
||||
Editor editor = ((TextEditor) feditors[0]).getEditor();
|
||||
if (!editor.isDisposed()) {
|
||||
return editor;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -243,7 +246,9 @@ public class FileGroup {
|
||||
|
||||
public void displayAsciiInfo(@NotNull Editor editor) {
|
||||
int offset = editor.getCaretModel().getOffset();
|
||||
char ch = editor.getDocument().getCharsSequence().charAt(offset);
|
||||
CharSequence charsSequence = editor.getDocument().getCharsSequence();
|
||||
if (charsSequence.length() == 0 || offset >= charsSequence.length()) return;
|
||||
char ch = charsSequence.charAt(offset);
|
||||
|
||||
VimPlugin.showMessage("<" +
|
||||
StringHelper.toKeyNotation(KeyStroke.getKeyStroke(ch)) +
|
||||
|
@@ -1301,9 +1301,7 @@ public class MotionGroup {
|
||||
}
|
||||
|
||||
public static void fileEditorManagerSelectionChangedCallback(@NotNull FileEditorManagerEvent event) {
|
||||
if (ExEntryPanel.getInstance().isActive()) {
|
||||
ExEntryPanel.getInstance().deactivate(false);
|
||||
}
|
||||
ExEntryPanel.deactivateAll();
|
||||
final FileEditor fileEditor = event.getOldEditor();
|
||||
if (fileEditor instanceof TextEditor) {
|
||||
final Editor editor = ((TextEditor)fileEditor).getEditor();
|
||||
|
@@ -188,7 +188,7 @@ class NotificationService(private val project: Project?) {
|
||||
const val IDEAVIM_STICKY_NOTIFICATION_ID = "ideavim-sticky"
|
||||
const val IDEAVIM_NOTIFICATION_ID = "ideavim"
|
||||
const val IDEAVIM_NOTIFICATION_TITLE = "IdeaVim"
|
||||
const val ideajoinExamplesUrl = "https://github.com/JetBrains/ideavim/blob/master/doc/ideajoin-examples.md"
|
||||
const val ideajoinExamplesUrl = "https://github.com/JetBrains/ideavim/wiki/%60ideajoin%60-examples"
|
||||
const val selectModeUrl = "https://vimhelp.org/visual.txt.html#Select-mode"
|
||||
}
|
||||
}
|
@@ -71,10 +71,8 @@ public class ProcessGroup {
|
||||
}
|
||||
|
||||
public void startExCommand(@NotNull Editor editor, DataContext context, @NotNull Command cmd) {
|
||||
if (editor.isOneLineMode()) // Don't allow ex commands in one line editors
|
||||
{
|
||||
return;
|
||||
}
|
||||
// Don't allow ex commands in one line editors
|
||||
if (editor.isOneLineMode()) return;
|
||||
|
||||
String initText = getRange(editor, cmd);
|
||||
CommandState.getInstance(editor).pushState(CommandState.Mode.EX_ENTRY, CommandState.SubMode.NONE, MappingMode.CMD_LINE);
|
||||
@@ -104,7 +102,6 @@ public class ProcessGroup {
|
||||
ExEntryPanel panel = ExEntryPanel.getInstance();
|
||||
panel.deactivate(true);
|
||||
boolean res = true;
|
||||
int flags;
|
||||
try {
|
||||
CommandState.getInstance(editor).popState();
|
||||
logger.debug("processing command");
|
||||
@@ -112,8 +109,7 @@ public class ProcessGroup {
|
||||
record(editor, text);
|
||||
if (logger.isDebugEnabled()) logger.debug("swing=" + SwingUtilities.isEventDispatchThread());
|
||||
if (panel.getLabel().equals(":")) {
|
||||
flags = CommandParser.getInstance().processCommand(editor, context, text, 1);
|
||||
if (logger.isDebugEnabled()) logger.debug("flags=" + flags);
|
||||
CommandParser.getInstance().processCommand(editor, context, text, 1);
|
||||
}
|
||||
else {
|
||||
int pos = VimPlugin.getSearch().search(editor, text, panel.getCount(),
|
||||
|
@@ -18,6 +18,7 @@
|
||||
package com.maddyhome.idea.vim.group;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.editor.*;
|
||||
import com.intellij.openapi.editor.colors.EditorColors;
|
||||
@@ -31,7 +32,6 @@ import com.intellij.openapi.project.ProjectManager;
|
||||
import com.intellij.openapi.util.Ref;
|
||||
import com.maddyhome.idea.vim.VimPlugin;
|
||||
import com.maddyhome.idea.vim.command.CommandFlags;
|
||||
import com.maddyhome.idea.vim.command.CommandState;
|
||||
import com.maddyhome.idea.vim.command.SelectionType;
|
||||
import com.maddyhome.idea.vim.common.CharacterPosition;
|
||||
import com.maddyhome.idea.vim.common.TextRange;
|
||||
@@ -40,13 +40,13 @@ 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.regexp.CharHelper;
|
||||
import com.maddyhome.idea.vim.regexp.CharPointer;
|
||||
import com.maddyhome.idea.vim.regexp.CharacterClasses;
|
||||
import com.maddyhome.idea.vim.regexp.RegExp;
|
||||
import com.maddyhome.idea.vim.ui.ExEntryPanel;
|
||||
import com.maddyhome.idea.vim.ui.ModalEntry;
|
||||
import org.jdom.Element;
|
||||
import org.jetbrains.annotations.Contract;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
@@ -164,7 +164,7 @@ public class SearchGroup {
|
||||
private static ReplaceConfirmationChoice confirmChoice(@NotNull Editor editor, @NotNull String match) {
|
||||
final Ref<ReplaceConfirmationChoice> result = Ref.create(ReplaceConfirmationChoice.QUIT);
|
||||
// XXX: The Ex entry panel is used only for UI here, its logic might be inappropriate for this method
|
||||
final ExEntryPanel exEntryPanel = ExEntryPanel.getInstance();
|
||||
final ExEntryPanel exEntryPanel = ExEntryPanel.getInstanceWithoutShortcuts();
|
||||
exEntryPanel.activate(editor, new EditorDataContext(editor), "Replace with " + match + " (y/n/a/q/l)?", "", 1);
|
||||
ModalEntry.activate(key -> {
|
||||
final ReplaceConfirmationChoice choice;
|
||||
@@ -217,7 +217,7 @@ public class SearchGroup {
|
||||
return res;
|
||||
}
|
||||
|
||||
public int search(@NotNull Editor editor, @NotNull String command, int startOffset, int count, EnumSet<CommandFlags> flags) {
|
||||
public int search(@NotNull Editor editor, @NotNull String command, int startOffset, int count, @NotNull EnumSet<CommandFlags> flags) {
|
||||
int dir = DIR_FORWARDS;
|
||||
char type = '/';
|
||||
String pattern = lastSearch;
|
||||
@@ -348,7 +348,7 @@ public class SearchGroup {
|
||||
updateSearchHighlights(lastSearch, lastIgnoreSmartCase, showSearchHighlight, true);
|
||||
}
|
||||
|
||||
public void updateIncsearchHighlights(Editor editor, String pattern, boolean forwards, int caretOffset, @Nullable LineRange searchRange) {
|
||||
public void updateIncsearchHighlights(@NotNull Editor editor, @NotNull String pattern, boolean forwards, int caretOffset, @Nullable LineRange searchRange) {
|
||||
// searchStartOffset is used to find the closest match. caretOffset is used to reset the caret if there is no match.
|
||||
// If searching based on e.g. :%s/... then these values are not going to be the same
|
||||
final int searchStartOffset = searchRange != null ? EditorHelper.getLineStartOffset(editor, searchRange.getStartLine()) : caretOffset;
|
||||
@@ -400,7 +400,7 @@ public class SearchGroup {
|
||||
final boolean wrap = OptionsManager.INSTANCE.getWrapscan().isSet();
|
||||
final TextRange result = findIt(editor, pattern, initialOffset, 1,
|
||||
forwards ? DIR_FORWARDS : DIR_BACKWARDS, shouldIgnoreSmartCase, wrap, false, true);
|
||||
if (result != null) {
|
||||
if (result != null && pattern != null) {
|
||||
currentMatchOffset = result.getStartOffset();
|
||||
final List<TextRange> results = Collections.singletonList(result);
|
||||
highlightSearchResults(editor, pattern, results, currentMatchOffset);
|
||||
@@ -415,6 +415,7 @@ public class SearchGroup {
|
||||
/**
|
||||
* Remove current search highlights if hlSearch is false, or if the pattern is changed
|
||||
*/
|
||||
@Contract("_, _, false -> true; _, null, true -> false")
|
||||
private boolean shouldRemoveSearchHighlight(@NotNull Editor editor, String newPattern, boolean hlSearch) {
|
||||
return !hlSearch || (newPattern != null && !newPattern.equals(UserDataManager.getVimLastSearch(editor)));
|
||||
}
|
||||
@@ -422,6 +423,7 @@ public class SearchGroup {
|
||||
/**
|
||||
* Add search highlights if hlSearch is true and the pattern is changed
|
||||
*/
|
||||
@Contract("_, _, false -> false; _, null, true -> false")
|
||||
private boolean shouldAddSearchHighlight(@NotNull Editor editor, @Nullable String newPattern, boolean hlSearch) {
|
||||
return hlSearch && newPattern != null && !newPattern.equals(UserDataManager.getVimLastSearch(editor)) && !Objects.equals(newPattern, "");
|
||||
}
|
||||
@@ -433,7 +435,7 @@ public class SearchGroup {
|
||||
}
|
||||
}
|
||||
|
||||
private int findClosestMatch(@NotNull Editor editor, List<TextRange> results, int initialOffset, boolean forwards) {
|
||||
private int findClosestMatch(@NotNull Editor editor, @NotNull List<TextRange> results, int initialOffset, boolean forwards) {
|
||||
if (results.isEmpty() || initialOffset == -1) {
|
||||
return -1;
|
||||
}
|
||||
@@ -895,19 +897,18 @@ public class SearchGroup {
|
||||
}
|
||||
}
|
||||
|
||||
@RWLockLabel.SelfSynchronized
|
||||
public boolean searchAndReplace(@NotNull Editor editor, @NotNull Caret caret, @NotNull LineRange range,
|
||||
@NotNull String excmd, String exarg) {
|
||||
// Explicitly exit visual mode here, so that visual mode marks don't change when we move the cursor to a match.
|
||||
if (CommandState.getInstance(editor).getMode() == CommandState.Mode.VISUAL) {
|
||||
if (CommandStateHelper.inVisualMode(editor)) {
|
||||
VimPlugin.getVisualMotion().exitVisual(editor);
|
||||
}
|
||||
|
||||
CharPointer cmd = new CharPointer(new StringBuffer(exarg));
|
||||
//sub_nsubs = 0;
|
||||
//sub_nlines = 0;
|
||||
|
||||
int which_pat;
|
||||
if (excmd.equals("~")) {
|
||||
if ("~".equals(excmd)) {
|
||||
which_pat = RE_LAST; /* use last used regexp */
|
||||
}
|
||||
else {
|
||||
@@ -943,7 +944,8 @@ public class SearchGroup {
|
||||
delimiter = cmd.charAt(); /* remember delimiter character */
|
||||
cmd.inc();
|
||||
}
|
||||
else /* find the end of the regexp */ {
|
||||
else {
|
||||
/* find the end of the regexp */
|
||||
which_pat = RE_LAST; /* use last used regexp */
|
||||
delimiter = cmd.charAt(); /* remember delimiter character */
|
||||
cmd.inc();
|
||||
@@ -971,8 +973,10 @@ public class SearchGroup {
|
||||
cmd.inc();
|
||||
}
|
||||
}
|
||||
else /* use previous pattern and substitution */ {
|
||||
if (lastReplace == null) /* there is no previous command */ {
|
||||
else {
|
||||
/* use previous pattern and substitution */
|
||||
if (lastReplace == null) {
|
||||
/* there is no previous command */
|
||||
VimPlugin.showMessage(MessageHelper.message(Msg.e_nopresub));
|
||||
return false;
|
||||
}
|
||||
@@ -990,7 +994,6 @@ public class SearchGroup {
|
||||
do_all = OptionsManager.INSTANCE.getGdefault().isSet();
|
||||
do_ask = false;
|
||||
do_error = true;
|
||||
//do_print = false;
|
||||
do_ic = 0;
|
||||
}
|
||||
while (!cmd.isNul()) {
|
||||
@@ -1007,13 +1010,16 @@ public class SearchGroup {
|
||||
else if (cmd.charAt() == 'e') {
|
||||
do_error = !do_error;
|
||||
}
|
||||
else if (cmd.charAt() == 'r') /* use last used regexp */ {
|
||||
else if (cmd.charAt() == 'r') {
|
||||
/* use last used regexp */
|
||||
which_pat = RE_LAST;
|
||||
}
|
||||
else if (cmd.charAt() == 'i') /* ignore case */ {
|
||||
else if (cmd.charAt() == 'i') {
|
||||
/* ignore case */
|
||||
do_ic = 'i';
|
||||
}
|
||||
else if (cmd.charAt() == 'I') /* don't ignore case */ {
|
||||
else if (cmd.charAt() == 'I') {
|
||||
/* don't ignore case */
|
||||
do_ic = 'I';
|
||||
}
|
||||
else if (cmd.charAt() != 'p') {
|
||||
@@ -1032,9 +1038,9 @@ public class SearchGroup {
|
||||
/*
|
||||
* check for a trailing count
|
||||
*/
|
||||
CharHelper.skipwhite(cmd);
|
||||
if (CharacterClasses.isDigit(cmd.charAt())) {
|
||||
int i = CharHelper.getdigits(cmd);
|
||||
cmd.skipWhitespaces();
|
||||
if (Character.isDigit(cmd.charAt())) {
|
||||
int i = cmd.getDigits();
|
||||
if (i <= 0 && do_error) {
|
||||
VimPlugin.showMessage(MessageHelper.message(Msg.e_zerocount));
|
||||
return false;
|
||||
@@ -1046,8 +1052,9 @@ public class SearchGroup {
|
||||
/*
|
||||
* check for trailing command or garbage
|
||||
*/
|
||||
CharHelper.skipwhite(cmd);
|
||||
if (!cmd.isNul() && cmd.charAt() != '"') /* if not end-of-line or comment */ {
|
||||
cmd.skipWhitespaces();
|
||||
if (!cmd.isNul() && cmd.charAt() != '"') {
|
||||
/* if not end-of-line or comment */
|
||||
VimPlugin.showMessage(MessageHelper.message(Msg.e_trailing));
|
||||
return false;
|
||||
}
|
||||
@@ -1076,8 +1083,6 @@ public class SearchGroup {
|
||||
setLastPattern(editor, pattern);
|
||||
}
|
||||
|
||||
//int start = editor.logicalPositionToOffset(new LogicalPosition(line1, 0));
|
||||
//int end = editor.logicalPositionToOffset(new LogicalPosition(line2, EditorHelper.getLineLength(editor, line2)));
|
||||
int start = editor.getDocument().getLineStartOffset(line1);
|
||||
int end = editor.getDocument().getLineEndOffset(line2);
|
||||
|
||||
@@ -1147,7 +1152,6 @@ public class SearchGroup {
|
||||
if (match == null) {
|
||||
return false;
|
||||
}
|
||||
//logger.debug("found match[" + spos + "," + epos + "] - replace " + match);
|
||||
|
||||
int line = lnum + regmatch.startpos[0].lnum;
|
||||
CharacterPosition startpos = new CharacterPosition(lnum + regmatch.startpos[0].lnum, regmatch.startpos[0].col);
|
||||
@@ -1187,7 +1191,7 @@ public class SearchGroup {
|
||||
}
|
||||
|
||||
if (doReplace) {
|
||||
editor.getDocument().replaceString(startoff, endoff, match);
|
||||
ApplicationManager.getApplication().runWriteAction(() -> editor.getDocument().replaceString(startoff, endoff, match));
|
||||
lastMatch = startoff;
|
||||
newpos = CharacterPosition.Companion.fromOffset(editor, newend);
|
||||
|
||||
@@ -1352,6 +1356,7 @@ public class SearchGroup {
|
||||
|
||||
public static DocumentSearchListener INSTANCE = new DocumentSearchListener();
|
||||
|
||||
@Contract(pure = true)
|
||||
private DocumentSearchListener () {
|
||||
}
|
||||
|
||||
|
@@ -457,7 +457,9 @@ class PutGroup {
|
||||
}
|
||||
|
||||
private fun notifyAboutIdeaPut(project: Project?) {
|
||||
if (VimPlugin.getVimState().isIdeaPutNotified || ClipboardOptionsData.ideaput in OptionsManager.clipboard) return
|
||||
if (VimPlugin.getVimState().isIdeaPutNotified
|
||||
|| ClipboardOptionsData.ideaput in OptionsManager.clipboard
|
||||
|| ClipboardOptionsData.ideaputDisabled) return
|
||||
|
||||
VimPlugin.getVimState().isIdeaPutNotified = true
|
||||
|
||||
|
@@ -46,6 +46,8 @@ class YankGroup {
|
||||
val motion = argument.motion ?: return false
|
||||
|
||||
val caretModel = editor.caretModel
|
||||
if (caretModel.caretCount <= 0) return false
|
||||
|
||||
val ranges = ArrayList<Pair<Int, Int>>(caretModel.caretCount)
|
||||
val startOffsets = HashMap<Caret, Int>(caretModel.caretCount)
|
||||
for (caret in caretModel.allCarets) {
|
||||
@@ -100,6 +102,17 @@ class YankGroup {
|
||||
|
||||
val selectionType = if (type == SelectionType.CHARACTER_WISE && range.isMultiple) SelectionType.BLOCK_WISE else type
|
||||
|
||||
if (type == SelectionType.LINE_WISE) {
|
||||
for (i in 0 until range.size()) {
|
||||
if (editor.offsetToLogicalPosition(range.startOffsets[i]).column != 0) {
|
||||
range.startOffsets[i] = EditorHelper.getLineStartForOffset(editor, range.startOffsets[i])
|
||||
}
|
||||
if (editor.offsetToLogicalPosition(range.endOffsets[i]).column != 0) {
|
||||
range.endOffsets[i] = (EditorHelper.getLineEndForOffset(editor, range.endOffsets[i]) + 1).coerceAtMost(EditorHelper.getFileSize(editor))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
val caretModel = editor.caretModel
|
||||
val rangeStartOffsets = range.startOffsets
|
||||
val rangeEndOffsets = range.endOffsets
|
||||
|
68
src/com/maddyhome/idea/vim/group/visual/VimVisualTimer.kt
Normal file
68
src/com/maddyhome/idea/vim/group/visual/VimVisualTimer.kt
Normal file
@@ -0,0 +1,68 @@
|
||||
package com.maddyhome.idea.vim.group.visual
|
||||
|
||||
import com.maddyhome.idea.vim.command.CommandState
|
||||
import com.maddyhome.idea.vim.group.visual.VimVisualTimer.mode
|
||||
import com.maddyhome.idea.vim.group.visual.VimVisualTimer.singleTask
|
||||
import com.maddyhome.idea.vim.helper.hasVisualSelection
|
||||
import com.maddyhome.idea.vim.option.OptionsManager
|
||||
import javax.swing.Timer
|
||||
|
||||
/**
|
||||
* Timer to control non-vim visual selection adjustment.
|
||||
*
|
||||
* Some actions in IJ use selection as a helper to reach desired behavior. E.g. backspace in python or yaml uses
|
||||
* selection to remove indent on the empty line. It selects indent and after that performs "remove selection" action.
|
||||
* If IdeaVim had reacted to this selection immediately, its listeners were called twice: after selection set and
|
||||
* after selection removing. After there both operations vim would get normal mode, what is inconvenient because user
|
||||
* expects vim to stay in insert mode.
|
||||
* Same approach is used in some accented characters on MacOs and for Romaji layout in Japanese language (VIM-1725).
|
||||
*
|
||||
* Because of this IdeaVim doesn't react to selection change immediately. After selection was changed, vim waits some
|
||||
* time (100 ms by default) and enables visual mode (or any another) if selection was not changed during this time.
|
||||
*
|
||||
* If during timer sleep another selection change was performed, the old timer get's disabled and
|
||||
* replaced with a new one.
|
||||
*
|
||||
* So, how does IdeaVim recognize that it should stay in insert mode?
|
||||
* Timer also gets an information about the current mode and whenever editor has selection.
|
||||
* [mode] property stores information about mode of *the first timer call*. So, if there were several calls
|
||||
* to timer, the first mode state will be stored in [mode] property. When the last timer acts, it compares state
|
||||
* of selection before first call and expected selection state after current call. Selection adjustment gets
|
||||
* performed only if there are changes in selection.
|
||||
*
|
||||
* Examples:
|
||||
* 1) User performs "extend selection" action from normal mode
|
||||
*
|
||||
* There will be only one call to [singleTask]. [mode] is command, editorHasSelection is true. So, selection adjustment
|
||||
* is called, IdeaVim starts visual (or select) mode.
|
||||
*
|
||||
* 2) Some action performs "extend selection" and "shrink selection" actions sequentially from insert mode.
|
||||
*
|
||||
* First call to [singleTask]. [mode] is insert, editorHasSelection is true. Timer starts.
|
||||
* Second call to [singleTask]. First timer gets interrupted. [mode] stays insert because it's not null.
|
||||
* editorHasSelection is false. Insert mode ([mode]) has no selection and editor also has no selection, so
|
||||
* no adjustment gets performed and IdeaVim stays in insert mode.
|
||||
*/
|
||||
object VimVisualTimer {
|
||||
|
||||
var swingTimer: Timer? = null
|
||||
var mode: CommandState.Mode? = null
|
||||
|
||||
inline fun singleTask(editorHasSelection: Boolean, currentMode: CommandState.Mode, crossinline task: () -> Unit) {
|
||||
swingTimer?.stop()
|
||||
|
||||
if (mode == null) mode = currentMode
|
||||
|
||||
// Default delay - 100 ms
|
||||
val timer = Timer(OptionsManager.visualEnterDelay.value()) {
|
||||
if (mode?.hasVisualSelection == true || editorHasSelection) {
|
||||
task()
|
||||
}
|
||||
swingTimer = null
|
||||
mode = null
|
||||
}
|
||||
timer.isRepeats = false
|
||||
timer.start()
|
||||
swingTimer = timer
|
||||
}
|
||||
}
|
@@ -18,26 +18,13 @@
|
||||
|
||||
package com.maddyhome.idea.vim.group.visual
|
||||
|
||||
import com.intellij.openapi.editor.Caret
|
||||
import com.intellij.openapi.editor.CaretVisualAttributes
|
||||
import com.intellij.openapi.editor.Editor
|
||||
import com.intellij.openapi.editor.LogicalPosition
|
||||
import com.intellij.openapi.editor.VisualPosition
|
||||
import com.intellij.openapi.editor.*
|
||||
import com.intellij.openapi.editor.colors.EditorColors
|
||||
import com.maddyhome.idea.vim.VimPlugin
|
||||
import com.maddyhome.idea.vim.command.CommandState
|
||||
import com.maddyhome.idea.vim.group.ChangeGroup
|
||||
import com.maddyhome.idea.vim.group.MotionGroup
|
||||
import com.maddyhome.idea.vim.helper.EditorHelper
|
||||
import com.maddyhome.idea.vim.helper.inBlockSubMode
|
||||
import com.maddyhome.idea.vim.helper.inSelectMode
|
||||
import com.maddyhome.idea.vim.helper.inVisualMode
|
||||
import com.maddyhome.idea.vim.helper.isEndAllowed
|
||||
import com.maddyhome.idea.vim.helper.mode
|
||||
import com.maddyhome.idea.vim.helper.sort
|
||||
import com.maddyhome.idea.vim.helper.subMode
|
||||
import com.maddyhome.idea.vim.helper.vimLastColumn
|
||||
import com.maddyhome.idea.vim.helper.vimSelectionStart
|
||||
import com.maddyhome.idea.vim.helper.*
|
||||
|
||||
/**
|
||||
* @author Alex Plate
|
||||
@@ -201,9 +188,9 @@ fun toNativeSelection(editor: Editor, start: Int, end: Int, mode: CommandState.M
|
||||
else -> sort(start, end)
|
||||
}
|
||||
|
||||
fun moveCaretOneCharLeftFromSelectionEnd(editor: Editor) {
|
||||
if (!editor.inVisualMode) {
|
||||
if (!editor.mode.isEndAllowed) {
|
||||
fun moveCaretOneCharLeftFromSelectionEnd(editor: Editor, predictedMode: CommandState.Mode) {
|
||||
if (predictedMode != CommandState.Mode.VISUAL) {
|
||||
if (!predictedMode.isEndAllowed) {
|
||||
editor.caretModel.allCarets.forEach { caret ->
|
||||
val lineEnd = EditorHelper.getLineEndForOffset(editor, caret.offset)
|
||||
val lineStart = EditorHelper.getLineStartForOffset(editor, caret.offset)
|
||||
|
@@ -41,8 +41,7 @@ import com.maddyhome.idea.vim.option.SelectModeOptionData
|
||||
*/
|
||||
class VisualMotionGroup {
|
||||
companion object {
|
||||
var modeBeforeEnteringNonVimVisual: CommandState.Mode? = null
|
||||
val logger = Logger.getInstance(VisualMotionGroup.javaClass)
|
||||
val logger = Logger.getInstance(VisualMotionGroup::class.java)
|
||||
}
|
||||
|
||||
fun selectPreviousVisualMode(editor: Editor): Boolean {
|
||||
@@ -107,56 +106,84 @@ class VisualMotionGroup {
|
||||
}
|
||||
|
||||
fun controlNonVimSelectionChange(editor: Editor, selectionSource: VimListenerManager.SelectionSource = VimListenerManager.SelectionSource.OTHER) {
|
||||
logger.info("Adjust non-vim selection. Source: $selectionSource")
|
||||
if (editor.caretModel.allCarets.any(Caret::hasSelection)) {
|
||||
val commandState = CommandState.getInstance(editor)
|
||||
logger.info("Some carets have selection. State before adjustment: ${commandState.toSimpleString()}")
|
||||
modeBeforeEnteringNonVimVisual = commandState.mode
|
||||
logger.info("Mode before entering non-vim visual: $modeBeforeEnteringNonVimVisual")
|
||||
while (commandState.mode != CommandState.Mode.COMMAND) {
|
||||
commandState.popState()
|
||||
VimVisualTimer.singleTask(editor.caretModel.allCarets.any(Caret::hasSelection), editor.mode) {
|
||||
logger.info("Adjust non-vim selection. Source: $selectionSource")
|
||||
if (editor.caretModel.allCarets.any(Caret::hasSelection)) {
|
||||
val commandState = CommandState.getInstance(editor)
|
||||
logger.info("Some carets have selection. State before adjustment: ${commandState.toSimpleString()}")
|
||||
while (commandState.mode != CommandState.Mode.COMMAND) {
|
||||
commandState.popState()
|
||||
}
|
||||
val autodetectedMode = autodetectVisualMode(editor)
|
||||
val selectMode = OptionsManager.selectmode
|
||||
when {
|
||||
editor.isOneLineMode -> {
|
||||
logger.info("Enter select mode. Reason: one line mode")
|
||||
enterSelectMode(editor, autodetectedMode)
|
||||
}
|
||||
selectionSource == VimListenerManager.SelectionSource.MOUSE && SelectModeOptionData.mouse in selectMode -> {
|
||||
logger.info("Enter select mode. Selection source is mouse and selectMode option has mouse")
|
||||
enterSelectMode(editor, autodetectedMode)
|
||||
}
|
||||
editor.isTemplateActive() && SelectModeOptionData.template in selectMode -> {
|
||||
logger.info("Enter select mode. Template is active and selectMode has template")
|
||||
enterSelectMode(editor, autodetectedMode)
|
||||
}
|
||||
selectionSource == VimListenerManager.SelectionSource.OTHER && SelectModeOptionData.refactoring in selectMode -> {
|
||||
logger.info("Enter select mode. Selection source is OTHER and selectMode has refactoring")
|
||||
enterSelectMode(editor, autodetectedMode)
|
||||
}
|
||||
else -> {
|
||||
logger.info("Enter visual mode")
|
||||
enterVisualMode(editor, autodetectedMode)
|
||||
}
|
||||
}
|
||||
KeyHandler.getInstance().reset(editor)
|
||||
} else {
|
||||
val commandState = CommandState.getInstance(editor)
|
||||
logger.info("None of carets have selection. State before adjustment: ${commandState.toSimpleString()}")
|
||||
exitVisual(editor)
|
||||
exitSelectModeAndResetKeyHandler(editor, true)
|
||||
|
||||
val templateActive = editor.isTemplateActive()
|
||||
if (templateActive && editor.mode == CommandState.Mode.COMMAND) {
|
||||
VimPlugin.getChange().insertBeforeCursor(editor, EditorDataContext(editor))
|
||||
}
|
||||
updateCaretState(editor)
|
||||
KeyHandler.getInstance().reset(editor)
|
||||
}
|
||||
val autodetectedMode = autodetectVisualMode(editor)
|
||||
val project = editor.project
|
||||
logger.info("${editor.mode} is enabled")
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: 2019-07-30 This method should be used for [controlNonVimSelectionChange]
|
||||
fun predictMode(editor: Editor, selectionSource: VimListenerManager.SelectionSource): CommandState.Mode {
|
||||
if (editor.caretModel.allCarets.any(Caret::hasSelection)) {
|
||||
val selectMode = OptionsManager.selectmode
|
||||
when {
|
||||
return when {
|
||||
editor.isOneLineMode -> {
|
||||
logger.info("Enter select mode. Reason: one line mode")
|
||||
enterSelectMode(editor, autodetectedMode)
|
||||
CommandState.Mode.SELECT
|
||||
}
|
||||
selectionSource == VimListenerManager.SelectionSource.MOUSE && SelectModeOptionData.mouse in selectMode -> {
|
||||
logger.info("Enter select mode. Selection source is mouse and selectMode option has mouse")
|
||||
enterSelectMode(editor, autodetectedMode)
|
||||
CommandState.Mode.SELECT
|
||||
}
|
||||
editor.isTemplateActive() && SelectModeOptionData.template in selectMode -> {
|
||||
logger.info("Enter select mode. Template is active and selectMode has template")
|
||||
enterSelectMode(editor, autodetectedMode)
|
||||
CommandState.Mode.SELECT
|
||||
}
|
||||
selectionSource == VimListenerManager.SelectionSource.OTHER && SelectModeOptionData.refactoring in selectMode -> {
|
||||
logger.info("Enter select mode. Selection source is OTHER and selectMode has refactoring")
|
||||
enterSelectMode(editor, autodetectedMode)
|
||||
CommandState.Mode.SELECT
|
||||
}
|
||||
else -> {
|
||||
logger.info("Enter visual mode")
|
||||
enterVisualMode(editor, autodetectedMode)
|
||||
CommandState.Mode.VISUAL
|
||||
}
|
||||
}
|
||||
KeyHandler.getInstance().reset(editor)
|
||||
} else {
|
||||
val commandState = CommandState.getInstance(editor)
|
||||
logger.info("None of carets have selection. State before adjustment: ${commandState.toSimpleString()}")
|
||||
exitVisual(editor)
|
||||
exitSelectModeAndResetKeyHandler(editor, true)
|
||||
|
||||
val templateActive = editor.isTemplateActive()
|
||||
if ((templateActive || modeBeforeEnteringNonVimVisual == CommandState.Mode.INSERT) && editor.mode == CommandState.Mode.COMMAND) {
|
||||
logger.info("Enter insert mode because ${if (templateActive) "template is active" else "mode before entering non vim visual: $modeBeforeEnteringNonVimVisual"}")
|
||||
VimPlugin.getChange().insertBeforeCursor(editor, EditorDataContext(editor))
|
||||
if (templateActive && editor.mode == CommandState.Mode.COMMAND || editor.mode == CommandState.Mode.INSERT) {
|
||||
return CommandState.Mode.INSERT
|
||||
}
|
||||
updateCaretState(editor)
|
||||
KeyHandler.getInstance().reset(editor)
|
||||
return CommandState.Mode.COMMAND
|
||||
}
|
||||
logger.info("${editor.mode} is enabled")
|
||||
}
|
||||
|
||||
//=============================== ENTER VISUAL and SELECT MODE ==============================================
|
||||
@@ -383,6 +410,7 @@ class VisualMotionGroup {
|
||||
}
|
||||
}
|
||||
|
||||
@RWLockLabel.NoLockRequired
|
||||
fun exitVisual(editor: Editor) {
|
||||
resetVisual(editor)
|
||||
if (editor.inVisualMode) {
|
||||
|
@@ -26,7 +26,6 @@ import com.intellij.openapi.editor.actionSystem.EditorActionHandler
|
||||
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.VisualMotionGroup
|
||||
import com.maddyhome.idea.vim.helper.getTopLevelEditor
|
||||
|
||||
/**
|
||||
@@ -101,7 +100,6 @@ sealed class EditorActionHandlerBase(myRunForEachCaret: Boolean) : EditorActionH
|
||||
public final override fun doExecute(_editor: Editor, caret: Caret?, context: DataContext) {
|
||||
if (!VimPlugin.isEnabled()) return
|
||||
|
||||
preAction()
|
||||
val editor = _editor.getTopLevelEditor()
|
||||
logger.debug("Execute command with handler: " + this.javaClass.name)
|
||||
|
||||
@@ -114,10 +112,6 @@ sealed class EditorActionHandlerBase(myRunForEachCaret: Boolean) : EditorActionH
|
||||
if (!baseExecute(editor, caret, context, cmd)) VimPlugin.indicateError()
|
||||
}
|
||||
|
||||
private fun preAction() {
|
||||
VisualMotionGroup.modeBeforeEnteringNonVimVisual = null
|
||||
}
|
||||
|
||||
open fun process(cmd: Command) {
|
||||
// No-op
|
||||
}
|
||||
|
@@ -5,13 +5,17 @@ package com.maddyhome.idea.vim.helper
|
||||
import com.intellij.openapi.editor.Editor
|
||||
import com.maddyhome.idea.vim.command.CommandState
|
||||
|
||||
/**
|
||||
* @author Alex Plate
|
||||
*/
|
||||
|
||||
private val modesWithEndAllowed = setOf(CommandState.Mode.INSERT, CommandState.Mode.REPEAT, CommandState.Mode.VISUAL, CommandState.Mode.SELECT)
|
||||
val CommandState.Mode.isEndAllowed
|
||||
get() = this in modesWithEndAllowed
|
||||
get() = when (this) {
|
||||
CommandState.Mode.INSERT, CommandState.Mode.REPEAT, CommandState.Mode.VISUAL, CommandState.Mode.SELECT -> true
|
||||
CommandState.Mode.COMMAND, CommandState.Mode.EX_ENTRY, CommandState.Mode.REPLACE -> false
|
||||
}
|
||||
|
||||
val CommandState.Mode.hasVisualSelection
|
||||
get() = when (this) {
|
||||
CommandState.Mode.VISUAL, CommandState.Mode.SELECT -> true
|
||||
CommandState.Mode.REPLACE, CommandState.Mode.EX_ENTRY, CommandState.Mode.COMMAND, CommandState.Mode.INSERT, CommandState.Mode.REPEAT -> false
|
||||
}
|
||||
|
||||
val Editor.mode
|
||||
get() = CommandState.getInstance(this).mode
|
||||
|
@@ -543,6 +543,7 @@ public class EditorHelper {
|
||||
|
||||
public static boolean isLineEmpty(@NotNull final Editor editor, final int line, final boolean allowBlanks) {
|
||||
CharSequence chars = editor.getDocument().getCharsSequence();
|
||||
if (chars.length() == 0) return true;
|
||||
int offset = getLineStartOffset(editor, line);
|
||||
if (offset >= chars.length() || chars.charAt(offset) == '\n') {
|
||||
return true;
|
||||
|
@@ -106,3 +106,38 @@ fun Editor.isTemplateActive(): Boolean {
|
||||
val project = this.project ?: return false
|
||||
return TemplateManager.getInstance(project).getActiveTemplate(this) != null
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* This annotations marks if annotated function required read or write lock
|
||||
*/
|
||||
@Target
|
||||
annotation class RWLockLabel {
|
||||
/**
|
||||
* [Readonly] annotation means that annotated function should be called from read action
|
||||
* This annotation is only a marker and doesn't enable r/w lock automatically
|
||||
*/
|
||||
@Target(AnnotationTarget.FUNCTION)
|
||||
annotation class Readonly
|
||||
|
||||
/**
|
||||
* [Writable] annotation means that annotated function should be called from write action
|
||||
* This annotation is only a marker and doesn't enable r/w lock automatically
|
||||
*/
|
||||
@Target(AnnotationTarget.FUNCTION)
|
||||
annotation class Writable
|
||||
|
||||
/**
|
||||
* [SelfSynchronized] annotation means that annotated function handles read/write lock by itself
|
||||
* This annotation is only a marker and doesn't enable r/w lock automatically
|
||||
*/
|
||||
@Target(AnnotationTarget.FUNCTION)
|
||||
annotation class SelfSynchronized
|
||||
|
||||
/**
|
||||
* [NoLockRequired] annotation means that annotated function doesn't require any lock
|
||||
* This annotation is only a marker and doesn't enable r/w lock automatically
|
||||
*/
|
||||
@Target(AnnotationTarget.FUNCTION)
|
||||
annotation class NoLockRequired
|
||||
}
|
||||
|
@@ -623,7 +623,7 @@ public class SearchHelper {
|
||||
boolean isOuter) {
|
||||
final CharSequence chars = editor.getDocument().getCharsSequence();
|
||||
final int pos = caret.getOffset();
|
||||
if (chars.charAt(pos) == '\n') {
|
||||
if (pos >= chars.length() || chars.charAt(pos) == '\n') {
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -662,6 +662,7 @@ public class SearchHelper {
|
||||
}
|
||||
|
||||
private static boolean checkInString(@NotNull CharSequence chars, int pos, boolean str) {
|
||||
if (chars.length() == 0) return false;
|
||||
int offset = pos;
|
||||
while (offset > 0 && chars.charAt(offset) != '\n') {
|
||||
offset--;
|
||||
@@ -1110,6 +1111,9 @@ public class SearchHelper {
|
||||
int stop = EditorHelper.getLineEndOffset(editor, caret.getLogicalPosition().line, true);
|
||||
|
||||
int pos = caret.getOffset();
|
||||
// Technically the first condition is covered by the second one, but let it be
|
||||
if (chars.length() == 0 || chars.length() <= pos) return null;
|
||||
|
||||
int start = pos;
|
||||
CharacterHelper.CharacterType[] types = new CharacterHelper.CharacterType[]{CharacterHelper.CharacterType.KEYWORD,
|
||||
CharacterHelper.CharacterType.PUNCTUATION};
|
||||
@@ -1174,6 +1178,8 @@ public class SearchHelper {
|
||||
}
|
||||
|
||||
int pos = caret.getOffset();
|
||||
if (chars.length() <= pos) return new TextRange(chars.length() - 1, chars.length() - 1);
|
||||
|
||||
boolean startSpace = CharacterHelper.charType(chars.charAt(pos), isBig) == CharacterHelper.CharacterType.WHITESPACE;
|
||||
// Find word start
|
||||
boolean onWordStart = pos == min ||
|
||||
@@ -1328,16 +1334,6 @@ public class SearchHelper {
|
||||
boolean found = false;
|
||||
// For forward searches, skip any current whitespace so we start at the start of a word
|
||||
if (step > 0 && pos < size - 1) {
|
||||
/*
|
||||
if (CharacterHelper.charType(chars[pos + step], false) == CharacterHelper.WHITESPACE)
|
||||
{
|
||||
if (!stayEnd)
|
||||
{
|
||||
pos += step;
|
||||
}
|
||||
pos = skipSpace(chars, pos, step, size);
|
||||
}
|
||||
*/
|
||||
if (CharacterHelper.charType(chars.charAt(pos + 1), bigWord) == CharacterHelper.CharacterType.WHITESPACE &&
|
||||
!spaceWords) {
|
||||
pos = skipSpace(chars, pos + 1, step, size) - 1;
|
||||
@@ -1379,11 +1375,11 @@ public class SearchHelper {
|
||||
}
|
||||
|
||||
if (found) {
|
||||
if (res < 0) //(pos <= 0)
|
||||
if (res < 0)
|
||||
{
|
||||
res = 0;
|
||||
}
|
||||
else if (res >= size) //(pos >= size)
|
||||
else if (res >= size)
|
||||
{
|
||||
res = size - 1;
|
||||
}
|
||||
@@ -1406,7 +1402,7 @@ public class SearchHelper {
|
||||
* @param size The size of the document
|
||||
* @return The new position. This will be the first non-whitespace character found or an empty line
|
||||
*/
|
||||
public static int skipSpace(@NotNull CharSequence chars, int offset, int step, int size) {
|
||||
private static int skipSpace(@NotNull CharSequence chars, int offset, int step, int size) {
|
||||
char prev = 0;
|
||||
while (offset >= 0 && offset < size) {
|
||||
final char c = chars.charAt(offset);
|
||||
@@ -1420,7 +1416,7 @@ public class SearchHelper {
|
||||
offset += step;
|
||||
}
|
||||
|
||||
return offset;
|
||||
return offset < size ? offset : size - 1;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1875,7 +1871,7 @@ public class SearchHelper {
|
||||
}
|
||||
|
||||
if (res < 0 || count > 0) {
|
||||
res = dir > 0 ? max - 1 : 0;
|
||||
res = dir > 0 ? (max > 0 ? max - 1 : 0) : 0;
|
||||
}
|
||||
else if (isOuter && ((dir < 0 && findend) || (dir > 0 && !findend))) {
|
||||
if (res != 0 && res != max - 1) {
|
||||
@@ -1893,6 +1889,7 @@ public class SearchHelper {
|
||||
@NotNull
|
||||
public static TextRange findSentenceRange(@NotNull Editor editor, @NotNull Caret caret, int count, boolean isOuter) {
|
||||
CharSequence chars = editor.getDocument().getCharsSequence();
|
||||
if (chars.length() == 0) return new TextRange(0, 0);
|
||||
int max = EditorHelper.getFileSize(editor);
|
||||
int offset = caret.getOffset();
|
||||
int ssel = caret.getSelectionStart();
|
||||
|
@@ -72,7 +72,8 @@ object IdeaSpecifics {
|
||||
// Rider moves caret to the end of selection
|
||||
editor?.caretModel?.addCaretListener(object : CaretListener {
|
||||
override fun caretPositionChanged(event: CaretEvent) {
|
||||
moveCaretOneCharLeftFromSelectionEnd(event.editor)
|
||||
val predictedMode = VimPlugin.getVisualMotion().predictMode(event.editor, VimListenerManager.SelectionSource.OTHER)
|
||||
moveCaretOneCharLeftFromSelectionEnd(event.editor, predictedMode)
|
||||
event.editor.caretModel.removeCaretListener(this)
|
||||
}
|
||||
})
|
||||
|
@@ -37,7 +37,6 @@ import com.maddyhome.idea.vim.VimTypedActionHandler
|
||||
import com.maddyhome.idea.vim.command.CommandState
|
||||
import com.maddyhome.idea.vim.ex.ExOutputModel
|
||||
import com.maddyhome.idea.vim.group.*
|
||||
import com.maddyhome.idea.vim.group.visual.VisualMotionGroup
|
||||
import com.maddyhome.idea.vim.group.visual.moveCaretOneCharLeftFromSelectionEnd
|
||||
import com.maddyhome.idea.vim.group.visual.vimSetSystemSelectionSilently
|
||||
import com.maddyhome.idea.vim.helper.*
|
||||
@@ -131,7 +130,10 @@ object VimListenerManager {
|
||||
@JvmStatic
|
||||
fun enable() {
|
||||
val typedAction = EditorActionManager.getInstance().typedAction
|
||||
EventFacade.getInstance().setupTypedActionHandler(VimTypedActionHandler(typedAction.rawHandler))
|
||||
if (typedAction.rawHandler !is VimTypedActionHandler) {
|
||||
// Actually this if should always be true, but just as protection
|
||||
EventFacade.getInstance().setupTypedActionHandler(VimTypedActionHandler(typedAction.rawHandler))
|
||||
}
|
||||
|
||||
OptionsManager.number.addOptionChangeListener(EditorGroup.NumberChangeListener.INSTANCE)
|
||||
OptionsManager.relativenumber.addOptionChangeListener(EditorGroup.NumberChangeListener.INSTANCE)
|
||||
@@ -295,14 +297,14 @@ object VimListenerManager {
|
||||
}
|
||||
|
||||
override fun mouseReleased(event: EditorMouseEvent) {
|
||||
VisualMotionGroup.modeBeforeEnteringNonVimVisual = null
|
||||
if (mouseDragging) {
|
||||
logger.debug("Release mouse after dragging")
|
||||
val editor = event.editor
|
||||
val caret = editor.caretModel.primaryCaret
|
||||
SelectionVimListenerSuppressor.use {
|
||||
val predictedMode = VimPlugin.getVisualMotion().predictMode(editor, VimListenerManager.SelectionSource.MOUSE)
|
||||
VimPlugin.getVisualMotion().controlNonVimSelectionChange(editor, VimListenerManager.SelectionSource.MOUSE)
|
||||
moveCaretOneCharLeftFromSelectionEnd(editor)
|
||||
moveCaretOneCharLeftFromSelectionEnd(editor, predictedMode)
|
||||
caret.vimLastColumn = editor.caretModel.visualPosition.column
|
||||
}
|
||||
|
||||
@@ -352,9 +354,10 @@ object VimListenerManager {
|
||||
private object ComponentMouseListener : MouseAdapter() {
|
||||
override fun mousePressed(e: MouseEvent?) {
|
||||
val editor = (e?.component as? EditorComponentImpl)?.editor ?: return
|
||||
val predictedMode = VimPlugin.getVisualMotion().predictMode(editor, VimListenerManager.SelectionSource.MOUSE)
|
||||
when (e.clickCount) {
|
||||
1 -> {
|
||||
if (!editor.inInsertMode) {
|
||||
if (!predictedMode.isEndAllowed) {
|
||||
editor.caretModel.runForEachCaret { caret ->
|
||||
val lineEnd = EditorHelper.getLineEndForOffset(editor, caret.offset)
|
||||
val lineStart = EditorHelper.getLineStartForOffset(editor, caret.offset)
|
||||
@@ -364,7 +367,7 @@ object VimListenerManager {
|
||||
}
|
||||
}
|
||||
}
|
||||
2 -> moveCaretOneCharLeftFromSelectionEnd(editor)
|
||||
2 -> moveCaretOneCharLeftFromSelectionEnd(editor, predictedMode)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -70,6 +70,7 @@ object OptionsManager {
|
||||
val viminfo = addOption(ListOption("viminfo", "vi", arrayOf("'100", "<50", "s10", "h"), null))
|
||||
val visualbell = addOption(ToggleOption("visualbell", "vb", false))
|
||||
val wrapscan = addOption(ToggleOption("wrapscan", "ws", true))
|
||||
val visualEnterDelay = addOption(NumberOption("visualdelay", "visualdelay", 100, 0, Int.MAX_VALUE))
|
||||
|
||||
init {
|
||||
registerExtensionOptions()
|
||||
@@ -407,6 +408,27 @@ object ClipboardOptionsData {
|
||||
const val abbr = "cb"
|
||||
|
||||
const val ideaput = "ideaput"
|
||||
var ideaputDisabled = false
|
||||
private set
|
||||
|
||||
/**
|
||||
* This autocloseable class allows temporary disable ideaput option
|
||||
* [ClipboardOptionsData.ideaputDisabled] property indicates if ideaput was disabled
|
||||
*/
|
||||
class IdeaputDisabler : AutoCloseable {
|
||||
private val containedBefore: Boolean
|
||||
override fun close() {
|
||||
if (containedBefore) OptionsManager.clipboard.append(ideaput)
|
||||
ideaputDisabled = false
|
||||
}
|
||||
|
||||
init {
|
||||
val options = OptionsManager.clipboard
|
||||
containedBefore = options.contains(ideaput)
|
||||
options.remove(ideaput)
|
||||
ideaputDisabled = true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
object IdeaJoinOptionsData {
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user