mirror of
https://github.com/chylex/IntelliJ-IdeaVim.git
synced 2025-08-17 16:31:45 +02:00
Compare commits
3 Commits
0.61.1-EAP
...
0.61.2-EAP
Author | SHA1 | Date | |
---|---|---|---|
![]() |
4926d2554e | ||
![]() |
eae135acba | ||
![]() |
8ce3801b87 |
@@ -319,7 +319,7 @@ public class KeyHandler {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
reset(editor);
|
reset(editor);
|
||||||
ChangeGroup.resetCaret(editor, VimPlugin.getEditor().isBarCursor());
|
ChangeGroup.resetCaret(editor, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean handleKeyMapping(final @NotNull Editor editor,
|
private boolean handleKeyMapping(final @NotNull Editor editor,
|
||||||
|
@@ -204,10 +204,6 @@ public class EditorGroup implements PersistentStateComponent<Element> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isBarCursor() {
|
|
||||||
return !isBlockCursor;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void editorCreated(@NotNull Editor editor) {
|
public void editorCreated(@NotNull Editor editor) {
|
||||||
isBlockCursor = editor.getSettings().isBlockCursor();
|
isBlockCursor = editor.getSettings().isBlockCursor();
|
||||||
isRefrainFromScrolling = editor.getSettings().isRefrainFromScrolling();
|
isRefrainFromScrolling = editor.getSettings().isRefrainFromScrolling();
|
||||||
@@ -222,7 +218,7 @@ public class EditorGroup implements PersistentStateComponent<Element> {
|
|||||||
VimPlugin.getChange().insertBeforeCursor(editor, new EditorDataContext(editor, null));
|
VimPlugin.getChange().insertBeforeCursor(editor, new EditorDataContext(editor, null));
|
||||||
KeyHandler.getInstance().reset(editor);
|
KeyHandler.getInstance().reset(editor);
|
||||||
}
|
}
|
||||||
editor.getSettings().setBlockCursor(!CommandStateHelper.inInsertMode(editor) || isBlockCursor);
|
editor.getSettings().setBlockCursor(!CommandStateHelper.inInsertMode(editor));
|
||||||
editor.getSettings().setRefrainFromScrolling(REFRAIN_FROM_SCROLLING_VIM_VALUE);
|
editor.getSettings().setRefrainFromScrolling(REFRAIN_FROM_SCROLLING_VIM_VALUE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -41,6 +41,7 @@ import com.maddyhome.idea.vim.group.visual.VisualGroupKt;
|
|||||||
import com.maddyhome.idea.vim.handler.MotionActionHandler;
|
import com.maddyhome.idea.vim.handler.MotionActionHandler;
|
||||||
import com.maddyhome.idea.vim.handler.TextObjectActionHandler;
|
import com.maddyhome.idea.vim.handler.TextObjectActionHandler;
|
||||||
import com.maddyhome.idea.vim.helper.*;
|
import com.maddyhome.idea.vim.helper.*;
|
||||||
|
import com.maddyhome.idea.vim.listener.IdeaSpecifics;
|
||||||
import com.maddyhome.idea.vim.option.NumberOption;
|
import com.maddyhome.idea.vim.option.NumberOption;
|
||||||
import com.maddyhome.idea.vim.option.OptionChangeListener;
|
import com.maddyhome.idea.vim.option.OptionChangeListener;
|
||||||
import com.maddyhome.idea.vim.option.OptionsManager;
|
import com.maddyhome.idea.vim.option.OptionsManager;
|
||||||
@@ -318,6 +319,8 @@ public class MotionGroup {
|
|||||||
else {
|
else {
|
||||||
ModeHelper.exitVisualMode(editor);
|
ModeHelper.exitVisualMode(editor);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
IdeaSpecifics.AppCodeTemplates.onMovement(editor, caret, oldOffset < offset);
|
||||||
}
|
}
|
||||||
|
|
||||||
private @Nullable Editor selectEditor(@NotNull Editor editor, @NotNull Mark mark) {
|
private @Nullable Editor selectEditor(@NotNull Editor editor, @NotNull Mark mark) {
|
||||||
|
@@ -163,7 +163,7 @@ fun updateCaretState(editor: Editor) {
|
|||||||
|
|
||||||
fun CommandState.Mode.resetShape(editor: Editor) = when (this) {
|
fun CommandState.Mode.resetShape(editor: Editor) = when (this) {
|
||||||
CommandState.Mode.COMMAND, CommandState.Mode.VISUAL, CommandState.Mode.REPLACE -> ChangeGroup.resetCaret(editor, false)
|
CommandState.Mode.COMMAND, CommandState.Mode.VISUAL, CommandState.Mode.REPLACE -> ChangeGroup.resetCaret(editor, false)
|
||||||
CommandState.Mode.SELECT, CommandState.Mode.INSERT -> ChangeGroup.resetCaret(editor, VimPlugin.getEditor().isBarCursor)
|
CommandState.Mode.SELECT, CommandState.Mode.INSERT -> ChangeGroup.resetCaret(editor, true)
|
||||||
CommandState.Mode.CMD_LINE, CommandState.Mode.OP_PENDING -> Unit
|
CommandState.Mode.CMD_LINE, CommandState.Mode.OP_PENDING -> Unit
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -32,12 +32,14 @@ import com.intellij.openapi.actionSystem.CommonDataKeys
|
|||||||
import com.intellij.openapi.actionSystem.DataContext
|
import com.intellij.openapi.actionSystem.DataContext
|
||||||
import com.intellij.openapi.actionSystem.IdeActions
|
import com.intellij.openapi.actionSystem.IdeActions
|
||||||
import com.intellij.openapi.actionSystem.ex.AnActionListener
|
import com.intellij.openapi.actionSystem.ex.AnActionListener
|
||||||
|
import com.intellij.openapi.editor.Caret
|
||||||
import com.intellij.openapi.editor.Editor
|
import com.intellij.openapi.editor.Editor
|
||||||
import com.intellij.openapi.editor.actionSystem.EditorActionManager
|
import com.intellij.openapi.editor.actionSystem.EditorActionManager
|
||||||
import com.intellij.openapi.editor.event.CaretEvent
|
import com.intellij.openapi.editor.event.CaretEvent
|
||||||
import com.intellij.openapi.editor.event.CaretListener
|
import com.intellij.openapi.editor.event.CaretListener
|
||||||
import com.intellij.openapi.project.DumbAwareToggleAction
|
import com.intellij.openapi.project.DumbAwareToggleAction
|
||||||
import com.intellij.openapi.project.Project
|
import com.intellij.openapi.project.Project
|
||||||
|
import com.intellij.openapi.util.Key
|
||||||
import com.intellij.util.PlatformUtils
|
import com.intellij.util.PlatformUtils
|
||||||
import com.maddyhome.idea.vim.EventFacade
|
import com.maddyhome.idea.vim.EventFacade
|
||||||
import com.maddyhome.idea.vim.KeyHandler
|
import com.maddyhome.idea.vim.KeyHandler
|
||||||
@@ -47,10 +49,12 @@ import com.maddyhome.idea.vim.group.visual.IdeaSelectionControl
|
|||||||
import com.maddyhome.idea.vim.group.visual.moveCaretOneCharLeftFromSelectionEnd
|
import com.maddyhome.idea.vim.group.visual.moveCaretOneCharLeftFromSelectionEnd
|
||||||
import com.maddyhome.idea.vim.helper.EditorDataContext
|
import com.maddyhome.idea.vim.helper.EditorDataContext
|
||||||
import com.maddyhome.idea.vim.helper.commandState
|
import com.maddyhome.idea.vim.helper.commandState
|
||||||
|
import com.maddyhome.idea.vim.helper.fileSize
|
||||||
import com.maddyhome.idea.vim.helper.getTopLevelEditor
|
import com.maddyhome.idea.vim.helper.getTopLevelEditor
|
||||||
import com.maddyhome.idea.vim.helper.inNormalMode
|
import com.maddyhome.idea.vim.helper.inNormalMode
|
||||||
import com.maddyhome.idea.vim.option.IdeaRefactorMode
|
import com.maddyhome.idea.vim.option.IdeaRefactorMode
|
||||||
import org.jetbrains.annotations.NonNls
|
import org.jetbrains.annotations.NonNls
|
||||||
|
import org.jetbrains.annotations.NotNull
|
||||||
import java.beans.PropertyChangeEvent
|
import java.beans.PropertyChangeEvent
|
||||||
import java.beans.PropertyChangeListener
|
import java.beans.PropertyChangeListener
|
||||||
|
|
||||||
@@ -191,6 +195,87 @@ object IdeaSpecifics {
|
|||||||
.javaClass.name.startsWith("org.acejump.")
|
.javaClass.name.startsWith("org.acejump.")
|
||||||
}
|
}
|
||||||
//endregion
|
//endregion
|
||||||
|
|
||||||
|
//region AppCode templates
|
||||||
|
/**
|
||||||
|
* A collection of hacks to improve the interaction with fancy AppCode templates
|
||||||
|
*/
|
||||||
|
object AppCodeTemplates {
|
||||||
|
private val facedAppCodeTemplate = Key.create<IntRange>("FacedAppCodeTemplate")
|
||||||
|
|
||||||
|
private const val TEMPLATE_START = "<#T##"
|
||||||
|
private const val TEMPLATE_END = "#>"
|
||||||
|
|
||||||
|
@JvmStatic
|
||||||
|
fun onMovement(
|
||||||
|
editor: @NotNull Editor,
|
||||||
|
caret: @NotNull Caret,
|
||||||
|
toRight: Boolean
|
||||||
|
) {
|
||||||
|
if (!PlatformUtils.isAppCode()) return
|
||||||
|
|
||||||
|
val offset = caret.offset
|
||||||
|
val offsetRightEnd = offset + TEMPLATE_START.length
|
||||||
|
val offsetLeftEnd = offset - 1
|
||||||
|
val templateRange = caret.getUserData(facedAppCodeTemplate)
|
||||||
|
if (templateRange == null) {
|
||||||
|
if (offsetRightEnd < editor.fileSize
|
||||||
|
&& editor.document.charsSequence.subSequence(offset, offsetRightEnd).toString() == TEMPLATE_START) {
|
||||||
|
caret.shake()
|
||||||
|
|
||||||
|
val templateEnd = editor.findTemplateEnd(offset) ?: return
|
||||||
|
|
||||||
|
caret.putUserData(facedAppCodeTemplate, offset..templateEnd)
|
||||||
|
}
|
||||||
|
if (offsetLeftEnd >= 0
|
||||||
|
&& editor.document.charsSequence.subSequence(offsetLeftEnd, offset + 1).toString() == TEMPLATE_END) {
|
||||||
|
caret.shake()
|
||||||
|
|
||||||
|
val templateStart = editor.findTemplateStart(offsetLeftEnd) ?: return
|
||||||
|
|
||||||
|
caret.putUserData(facedAppCodeTemplate, templateStart..offset)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (offset in templateRange) {
|
||||||
|
if (toRight) {
|
||||||
|
caret.moveToOffset(templateRange.last + 1)
|
||||||
|
} else {
|
||||||
|
caret.moveToOffset(templateRange.first)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
caret.putUserData(facedAppCodeTemplate, null)
|
||||||
|
caret.shake()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun Caret.shake() {
|
||||||
|
moveCaretRelatively(1, 0, false, false)
|
||||||
|
moveCaretRelatively(-1, 0, false, false)
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun Editor.findTemplateEnd(start: Int): Int? {
|
||||||
|
val charSequence = this.document.charsSequence
|
||||||
|
val length = charSequence.length
|
||||||
|
for (i in start until length - 1) {
|
||||||
|
if (charSequence[i] == TEMPLATE_END[0] && charSequence[i+1] == TEMPLATE_END[1]) {
|
||||||
|
return i + 1
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun Editor.findTemplateStart(start: Int): Int? {
|
||||||
|
val charSequence = this.document.charsSequence
|
||||||
|
val templateLastIndex = TEMPLATE_START.length
|
||||||
|
for (i in start downTo templateLastIndex) {
|
||||||
|
if (charSequence.subSequence(i - templateLastIndex, i + 1).toString() == TEMPLATE_START) {
|
||||||
|
return i - templateLastIndex
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//endregion
|
||||||
}
|
}
|
||||||
|
|
||||||
//region Find action ID
|
//region Find action ID
|
||||||
|
@@ -253,11 +253,11 @@ object VimListenerManager {
|
|||||||
if (onLineEnd(caret)) {
|
if (onLineEnd(caret)) {
|
||||||
// UX protection for case when user performs a small dragging while putting caret on line end
|
// UX protection for case when user performs a small dragging while putting caret on line end
|
||||||
caret.removeSelection()
|
caret.removeSelection()
|
||||||
ChangeGroup.resetCaret(e.editor, VimPlugin.getEditor().isBarCursor)
|
ChangeGroup.resetCaret(e.editor, true)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (mouseDragging && e.editor.caretModel.primaryCaret.hasSelection()) {
|
if (mouseDragging && e.editor.caretModel.primaryCaret.hasSelection()) {
|
||||||
ChangeGroup.resetCaret(e.editor, VimPlugin.getEditor().isBarCursor)
|
ChangeGroup.resetCaret(e.editor, true)
|
||||||
|
|
||||||
if (!cutOffFixed && ComponentMouseListener.cutOffEnd) {
|
if (!cutOffFixed && ComponentMouseListener.cutOffEnd) {
|
||||||
cutOffFixed = true
|
cutOffFixed = true
|
||||||
|
Reference in New Issue
Block a user