mirror of
https://github.com/chylex/IntelliJ-IdeaVim.git
synced 2025-07-28 04:59:03 +02:00
Extract vim mark constants into the separate file
This commit is contained in:
parent
c462af2d10
commit
f742e414e6
src/main/java/com/maddyhome/idea/vim
extension/exchange
group
newapi
vimscript/model/commands
vim-engine/src/main/kotlin/com/maddyhome/idea/vim
@ -42,7 +42,6 @@ import com.maddyhome.idea.vim.extension.VimExtensionFacade.putKeyMappingIfMissin
|
||||
import com.maddyhome.idea.vim.extension.VimExtensionFacade.setOperatorFunction
|
||||
import com.maddyhome.idea.vim.extension.VimExtensionFacade.setRegister
|
||||
import com.maddyhome.idea.vim.extension.VimExtensionHandler
|
||||
import com.maddyhome.idea.vim.group.MarkGroup
|
||||
import com.maddyhome.idea.vim.helper.EditorHelper
|
||||
import com.maddyhome.idea.vim.helper.StringHelper.parseKeys
|
||||
import com.maddyhome.idea.vim.helper.StringHelper.stringToKeys
|
||||
@ -51,6 +50,7 @@ import com.maddyhome.idea.vim.helper.moveToInlayAwareLogicalPosition
|
||||
import com.maddyhome.idea.vim.helper.moveToInlayAwareOffset
|
||||
import com.maddyhome.idea.vim.helper.subMode
|
||||
import com.maddyhome.idea.vim.key.OperatorFunction
|
||||
import com.maddyhome.idea.vim.mark.VimMarkConstants
|
||||
import com.maddyhome.idea.vim.newapi.vim
|
||||
import org.jetbrains.annotations.NonNls
|
||||
|
||||
@ -326,9 +326,9 @@ class VimExchangeExtension : VimExtension {
|
||||
fun getMarks(isVisual: Boolean): Pair<Mark, Mark> {
|
||||
val (startMark, endMark) =
|
||||
if (isVisual) {
|
||||
Pair(MarkGroup.MARK_VISUAL_START, MarkGroup.MARK_VISUAL_END)
|
||||
Pair(VimMarkConstants.MARK_VISUAL_START, VimMarkConstants.MARK_VISUAL_END)
|
||||
} else {
|
||||
Pair(MarkGroup.MARK_CHANGE_START, MarkGroup.MARK_CHANGE_END)
|
||||
Pair(VimMarkConstants.MARK_CHANGE_START, VimMarkConstants.MARK_CHANGE_END)
|
||||
}
|
||||
val marks = VimPlugin.getMark()
|
||||
return Pair(marks.getMark(editor, startMark)!!, marks.getMark(editor, endMark)!!)
|
||||
|
@ -78,6 +78,7 @@ import java.awt.event.KeyEvent;
|
||||
import java.math.BigInteger;
|
||||
import java.util.*;
|
||||
|
||||
import static com.maddyhome.idea.vim.mark.VimMarkConstants.*;
|
||||
import static com.maddyhome.idea.vim.register.RegisterConstants.LAST_INSERTED_TEXT_REGISTER;
|
||||
|
||||
/**
|
||||
@ -436,7 +437,7 @@ public class ChangeGroup implements VimChangeGroup {
|
||||
UserDataManager
|
||||
.setVimInsertStart(caret, editor.getDocument().createRangeMarker(caret.getOffset(), caret.getOffset()));
|
||||
if (caret == caretModel.getPrimaryCaret()) {
|
||||
VimPlugin.getMark().setMark(editor, MarkGroup.MARK_CHANGE_START, caret.getOffset());
|
||||
VimPlugin.getMark().setMark(editor, MARK_CHANGE_START, caret.getOffset());
|
||||
}
|
||||
}
|
||||
|
||||
@ -553,7 +554,7 @@ public class ChangeGroup implements VimChangeGroup {
|
||||
int offset = editor.getCaretModel().getPrimaryCaret().getOffset();
|
||||
final MarkGroup markGroup = VimPlugin.getMark();
|
||||
markGroup.setMark(editor, '^', offset);
|
||||
markGroup.setMark(editor, MarkGroup.MARK_CHANGE_END, offset);
|
||||
markGroup.setMark(editor, MARK_CHANGE_END, offset);
|
||||
|
||||
if (CommandState.getInstance(new IjVimEditor(editor)).getMode() == CommandState.Mode.REPLACE) {
|
||||
setInsertEditorState(editor, true);
|
||||
@ -581,7 +582,7 @@ public class ChangeGroup implements VimChangeGroup {
|
||||
|
||||
// The change pos '.' mark is the offset AFTER processing escape, and after switching to overtype
|
||||
offset = editor.getCaretModel().getPrimaryCaret().getOffset();
|
||||
markGroup.setMark(editor, MarkGroup.MARK_CHANGE_POS, offset);
|
||||
markGroup.setMark(editor, MARK_CHANGE_POS, offset);
|
||||
|
||||
CommandState.getInstance(new IjVimEditor(editor)).popModes();
|
||||
exitAllSingleCommandInsertModes(editor);
|
||||
@ -1715,7 +1716,7 @@ public class ChangeGroup implements VimChangeGroup {
|
||||
editor.getDocument().insertString(offset, str);
|
||||
InlayHelperKt.moveToInlayAwareOffset(caret, offset + str.length());
|
||||
|
||||
VimPlugin.getMark().setMark(editor, MarkGroup.MARK_CHANGE_POS, offset);
|
||||
VimPlugin.getMark().setMark(editor, MARK_CHANGE_POS, offset);
|
||||
}
|
||||
|
||||
public void insertText(@NotNull Editor editor, @NotNull Caret caret, @NotNull String str) {
|
||||
@ -1755,7 +1756,7 @@ public class ChangeGroup implements VimChangeGroup {
|
||||
|
||||
final int newEnd = start + str.length();
|
||||
VimPlugin.getMark().setChangeMarks(new IjVimEditor(editor), new TextRange(start, newEnd));
|
||||
VimPlugin.getMark().setMark(editor, MarkGroup.MARK_CHANGE_POS, newEnd);
|
||||
VimPlugin.getMark().setMark(editor, MARK_CHANGE_POS, newEnd);
|
||||
}
|
||||
|
||||
public void indentRange(@NotNull Editor editor,
|
||||
@ -1889,7 +1890,7 @@ public class ChangeGroup implements VimChangeGroup {
|
||||
|
||||
if (type != null) {
|
||||
final int start = updatedRange.getStartOffset();
|
||||
VimPlugin.getMark().setMark(editor, MarkGroup.MARK_CHANGE_POS, start);
|
||||
VimPlugin.getMark().setMark(editor, MARK_CHANGE_POS, start);
|
||||
VimPlugin.getMark().setChangeMarks(new IjVimEditor(editor), new TextRange(start, start + 1));
|
||||
}
|
||||
|
||||
|
@ -41,37 +41,32 @@ import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.openapi.vfs.VirtualFileManager;
|
||||
import com.maddyhome.idea.vim.VimPlugin;
|
||||
import com.maddyhome.idea.vim.api.VimEditor;
|
||||
import com.maddyhome.idea.vim.api.VimMarkGroup;
|
||||
import com.maddyhome.idea.vim.command.Command;
|
||||
import com.maddyhome.idea.vim.command.CommandState;
|
||||
import com.maddyhome.idea.vim.common.*;
|
||||
import com.maddyhome.idea.vim.helper.EditorHelper;
|
||||
import com.maddyhome.idea.vim.helper.HelperKt;
|
||||
import com.maddyhome.idea.vim.helper.SearchHelper;
|
||||
import com.maddyhome.idea.vim.mark.VimMarkGroupBase;
|
||||
import com.maddyhome.idea.vim.newapi.IjVimEditor;
|
||||
import com.maddyhome.idea.vim.options.OptionConstants;
|
||||
import com.maddyhome.idea.vim.options.OptionScope;
|
||||
import org.jdom.Element;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static com.maddyhome.idea.vim.mark.VimMarkConstants.*;
|
||||
|
||||
/**
|
||||
* This class contains all the mark related functionality
|
||||
*/
|
||||
@State(name = "VimMarksSettings", storages = {
|
||||
@Storage(value = "$APP_CONFIG$/vim_settings_local.xml", roamingType = RoamingType.DISABLED)
|
||||
})
|
||||
public class MarkGroup implements PersistentStateComponent<Element>, VimMarkGroup {
|
||||
public static final char MARK_VISUAL_START = '<';
|
||||
public static final char MARK_VISUAL_END = '>';
|
||||
public static final char MARK_CHANGE_START = '[';
|
||||
public static final char MARK_CHANGE_END = ']';
|
||||
public static final char MARK_CHANGE_POS = '.';
|
||||
|
||||
public class MarkGroup extends VimMarkGroupBase implements PersistentStateComponent<Element> {
|
||||
public void editorReleased(@NotNull EditorFactoryEvent event) {
|
||||
// Save off the last caret position of the file before it is closed
|
||||
Editor editor = event.getEditor();
|
||||
@ -802,39 +797,5 @@ public class MarkGroup implements PersistentStateComponent<Element>, VimMarkGrou
|
||||
private static final int SAVE_MARK_COUNT = 20;
|
||||
private static final int SAVE_JUMP_COUNT = 100;
|
||||
|
||||
public static final String WR_GLOBAL_MARKS = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
|
||||
public static final @NonNls String WR_REGULAR_FILE_MARKS = "abcdefghijklmnopqrstuvwxyz";
|
||||
/** Marks: abcdefghijklmnopqrstuvwxyz' */
|
||||
private static final String WR_FILE_MARKS = WR_REGULAR_FILE_MARKS + "'";
|
||||
|
||||
public static final String RO_GLOBAL_MARKS = "0123456789";
|
||||
private static final String RO_FILE_MARKS = ".[]<>^{}()";
|
||||
|
||||
private static final String DEL_CONTEXT_FILE_MARKS = ".^[]\"";
|
||||
/** Marks: .^[]"abcdefghijklmnopqrstuvwxyz */
|
||||
public static final String DEL_FILE_MARKS = DEL_CONTEXT_FILE_MARKS + WR_REGULAR_FILE_MARKS;
|
||||
/** Marks: 0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ*/
|
||||
private static final String DEL_GLOBAL_MARKS = RO_GLOBAL_MARKS + WR_GLOBAL_MARKS;
|
||||
/** Marks: .^[]"abcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ */
|
||||
public static final String DEL_MARKS = DEL_FILE_MARKS + DEL_GLOBAL_MARKS;
|
||||
|
||||
/** Marks: abcdefghijklmnopqrstuvwxyz'.^[]" */
|
||||
private static final String SAVE_FILE_MARKS = WR_FILE_MARKS + DEL_CONTEXT_FILE_MARKS;
|
||||
|
||||
/** Marks: ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789 */
|
||||
private static final String GLOBAL_MARKS = WR_GLOBAL_MARKS + RO_GLOBAL_MARKS;
|
||||
/** Marks: abcdefghijklmnopqrstuvwxyz'[]<>^{}() */
|
||||
private static final String FILE_MARKS = WR_FILE_MARKS + RO_FILE_MARKS;
|
||||
|
||||
/** Marks: ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz' */
|
||||
private static final String WRITE_MARKS = WR_GLOBAL_MARKS + WR_FILE_MARKS;
|
||||
/** Marks: 0123456789.[]<>^{}() */
|
||||
private static final String READONLY_MARKS = RO_GLOBAL_MARKS + RO_FILE_MARKS;
|
||||
|
||||
/** Marks: ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz' */
|
||||
private static final String VALID_SET_MARKS = WRITE_MARKS;
|
||||
/** Marks: ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'0123456789.[]<>^{}() */
|
||||
private static final String VALID_GET_MARKS = WRITE_MARKS + READONLY_MARKS;
|
||||
|
||||
private static final Logger logger = Logger.getInstance(MarkGroup.class.getName());
|
||||
}
|
||||
|
@ -41,13 +41,13 @@ import com.maddyhome.idea.vim.command.isBlock
|
||||
import com.maddyhome.idea.vim.command.isChar
|
||||
import com.maddyhome.idea.vim.command.isLine
|
||||
import com.maddyhome.idea.vim.common.TextRange
|
||||
import com.maddyhome.idea.vim.group.MarkGroup
|
||||
import com.maddyhome.idea.vim.group.MotionGroup
|
||||
import com.maddyhome.idea.vim.group.visual.VimSelection
|
||||
import com.maddyhome.idea.vim.helper.EditorHelper
|
||||
import com.maddyhome.idea.vim.helper.TestClipboardModel
|
||||
import com.maddyhome.idea.vim.helper.fileSize
|
||||
import com.maddyhome.idea.vim.helper.moveToInlayAwareOffset
|
||||
import com.maddyhome.idea.vim.mark.VimMarkConstants.MARK_CHANGE_POS
|
||||
import com.maddyhome.idea.vim.newapi.vim
|
||||
import com.maddyhome.idea.vim.options.OptionConstants
|
||||
import com.maddyhome.idea.vim.options.OptionScope
|
||||
@ -170,7 +170,7 @@ class PutGroup {
|
||||
var text = data.textData?.rawText ?: run {
|
||||
if (data.visualSelection != null) {
|
||||
val offset = editor.caretModel.primaryCaret.offset
|
||||
VimPlugin.getMark().setMark(editor, MarkGroup.MARK_CHANGE_POS, offset)
|
||||
VimPlugin.getMark().setMark(editor, MARK_CHANGE_POS, offset)
|
||||
VimPlugin.getMark().setChangeMarks(editor.vim, TextRange(offset, offset + 1))
|
||||
}
|
||||
return null
|
||||
@ -386,7 +386,7 @@ class PutGroup {
|
||||
startOffset + text.text.length
|
||||
) else startOffset + text.text.length
|
||||
VimPlugin.getMark().setChangeMarks(editor.vim, TextRange(startOffset, endOffset))
|
||||
VimPlugin.getMark().setMark(editor, MarkGroup.MARK_CHANGE_POS, startOffset)
|
||||
VimPlugin.getMark().setMark(editor, MARK_CHANGE_POS, startOffset)
|
||||
moveCaretToEndPosition(
|
||||
editor,
|
||||
caret,
|
||||
|
@ -16,7 +16,7 @@ import com.maddyhome.idea.vim.api.VimEditor
|
||||
import com.maddyhome.idea.vim.api.VimEnabler
|
||||
import com.maddyhome.idea.vim.api.VimInjector
|
||||
import com.maddyhome.idea.vim.api.VimKeyGroup
|
||||
import com.maddyhome.idea.vim.api.VimMarkGroup
|
||||
import com.maddyhome.idea.vim.mark.VimMarkGroup
|
||||
import com.maddyhome.idea.vim.api.VimMessages
|
||||
import com.maddyhome.idea.vim.api.VimProcessGroup
|
||||
import com.maddyhome.idea.vim.register.VimRegisterGroup
|
||||
|
@ -27,9 +27,9 @@ import com.maddyhome.idea.vim.common.OperatedRange
|
||||
import com.maddyhome.idea.vim.common.TextRange
|
||||
import com.maddyhome.idea.vim.common.VimMachine
|
||||
import com.maddyhome.idea.vim.common.VimRange
|
||||
import com.maddyhome.idea.vim.group.MarkGroup
|
||||
import com.maddyhome.idea.vim.helper.inlayAwareVisualColumn
|
||||
import com.maddyhome.idea.vim.helper.vimLastColumn
|
||||
import com.maddyhome.idea.vim.mark.VimMarkConstants.MARK_CHANGE_POS
|
||||
|
||||
@Service
|
||||
class VimMachineImpl : VimMachine {
|
||||
@ -56,7 +56,7 @@ class VimMachineImpl : VimMachine {
|
||||
editor.delete(range)
|
||||
|
||||
val start = normalizedRange.startOffset
|
||||
VimPlugin.getMark().setMark(editor.editor, MarkGroup.MARK_CHANGE_POS, start)
|
||||
VimPlugin.getMark().setMark(editor.editor, MARK_CHANGE_POS, start)
|
||||
VimPlugin.getMark().setChangeMarks(editor, TextRange(start, start + 1))
|
||||
|
||||
return operatedText
|
||||
|
@ -22,13 +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.ranges.Ranges
|
||||
import com.maddyhome.idea.vim.group.MarkGroup.DEL_FILE_MARKS
|
||||
import com.maddyhome.idea.vim.group.MarkGroup.DEL_MARKS
|
||||
import com.maddyhome.idea.vim.group.MarkGroup.RO_GLOBAL_MARKS
|
||||
import com.maddyhome.idea.vim.group.MarkGroup.WR_GLOBAL_MARKS
|
||||
import com.maddyhome.idea.vim.group.MarkGroup.WR_REGULAR_FILE_MARKS
|
||||
import com.maddyhome.idea.vim.helper.MessageHelper
|
||||
import com.maddyhome.idea.vim.helper.Msg
|
||||
import com.maddyhome.idea.vim.mark.VimMarkConstants.DEL_FILE_MARKS
|
||||
import com.maddyhome.idea.vim.mark.VimMarkConstants.DEL_MARKS
|
||||
import com.maddyhome.idea.vim.mark.VimMarkConstants.RO_GLOBAL_MARKS
|
||||
import com.maddyhome.idea.vim.mark.VimMarkConstants.WR_GLOBAL_MARKS
|
||||
import com.maddyhome.idea.vim.mark.VimMarkConstants.WR_REGULAR_FILE_MARKS
|
||||
import com.maddyhome.idea.vim.vimscript.model.ExecutionResult
|
||||
|
||||
private val VIML_COMMENT = Regex("(?<!\\\\)\".*")
|
||||
|
@ -3,6 +3,7 @@ package com.maddyhome.idea.vim.api
|
||||
import com.maddyhome.idea.vim.command.CommandState
|
||||
import com.maddyhome.idea.vim.common.VimMachine
|
||||
import com.maddyhome.idea.vim.diagnostic.VimLogger
|
||||
import com.maddyhome.idea.vim.mark.VimMarkGroup
|
||||
import com.maddyhome.idea.vim.options.OptionService
|
||||
import com.maddyhome.idea.vim.register.VimRegisterGroup
|
||||
|
||||
|
@ -0,0 +1,50 @@
|
||||
package com.maddyhome.idea.vim.mark
|
||||
|
||||
object VimMarkConstants {
|
||||
const val MARK_VISUAL_START = '<'
|
||||
const val MARK_VISUAL_END = '>'
|
||||
const val MARK_CHANGE_START = '['
|
||||
const val MARK_CHANGE_END = ']'
|
||||
const val MARK_CHANGE_POS = '.'
|
||||
|
||||
const val WR_GLOBAL_MARKS = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
|
||||
const val WR_REGULAR_FILE_MARKS = "abcdefghijklmnopqrstuvwxyz"
|
||||
|
||||
/** Marks: abcdefghijklmnopqrstuvwxyz' */
|
||||
const val WR_FILE_MARKS = "$WR_REGULAR_FILE_MARKS'"
|
||||
|
||||
const val RO_GLOBAL_MARKS = "0123456789"
|
||||
const val RO_FILE_MARKS = ".[]<>^{}()"
|
||||
|
||||
const val DEL_CONTEXT_FILE_MARKS = ".^[]\""
|
||||
|
||||
/** Marks: .^[]"abcdefghijklmnopqrstuvwxyz */
|
||||
const val DEL_FILE_MARKS = DEL_CONTEXT_FILE_MARKS + WR_REGULAR_FILE_MARKS
|
||||
|
||||
/** Marks: 0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ */
|
||||
const val DEL_GLOBAL_MARKS = RO_GLOBAL_MARKS + WR_GLOBAL_MARKS
|
||||
|
||||
/** Marks: .^[]"abcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ */
|
||||
const val DEL_MARKS = DEL_FILE_MARKS + DEL_GLOBAL_MARKS
|
||||
|
||||
/** Marks: abcdefghijklmnopqrstuvwxyz'.^[]" */
|
||||
const val SAVE_FILE_MARKS = WR_FILE_MARKS + DEL_CONTEXT_FILE_MARKS
|
||||
|
||||
/** Marks: ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789 */
|
||||
const val GLOBAL_MARKS = WR_GLOBAL_MARKS + RO_GLOBAL_MARKS
|
||||
|
||||
/** Marks: abcdefghijklmnopqrstuvwxyz'[]<>^{}() */
|
||||
const val FILE_MARKS = WR_FILE_MARKS + RO_FILE_MARKS
|
||||
|
||||
/** Marks: ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz' */
|
||||
const val WRITE_MARKS = WR_GLOBAL_MARKS + WR_FILE_MARKS
|
||||
|
||||
/** Marks: 0123456789.[]<>^{}() */
|
||||
const val READONLY_MARKS = RO_GLOBAL_MARKS + RO_FILE_MARKS
|
||||
|
||||
/** Marks: ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz' */
|
||||
const val VALID_SET_MARKS = WRITE_MARKS
|
||||
|
||||
/** Marks: ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'0123456789.[]<>^{}() */
|
||||
const val VALID_GET_MARKS = WRITE_MARKS + READONLY_MARKS
|
||||
}
|
@ -1,5 +1,6 @@
|
||||
package com.maddyhome.idea.vim.api
|
||||
package com.maddyhome.idea.vim.mark
|
||||
|
||||
import com.maddyhome.idea.vim.api.VimEditor
|
||||
import com.maddyhome.idea.vim.common.TextRange
|
||||
|
||||
interface VimMarkGroup {
|
@ -0,0 +1,4 @@
|
||||
package com.maddyhome.idea.vim.mark
|
||||
|
||||
abstract class VimMarkGroupBase : VimMarkGroup {
|
||||
}
|
Loading…
Reference in New Issue
Block a user