mirror of
https://github.com/chylex/IntelliJ-IdeaVim.git
synced 2025-01-05 01:42:49 +01:00
Remove unnecessary setting of vimLastColumn
This commit is contained in:
parent
0549f32d6e
commit
ff4ee06a1f
src/main/java/com/maddyhome/idea/vim
group
helper
listener
newapi
vim-engine/src/main/kotlin/com/maddyhome/idea/vim
@ -735,8 +735,6 @@ public class ChangeGroup extends VimChangeGroupBase {
|
||||
injector.getMotion().moveCaret(editor, caret, range.getStartOffset());
|
||||
}
|
||||
}
|
||||
|
||||
UserDataManager.setVimLastColumn(((IjVimCaret) caret).getCaret(), caret.getVisualPosition().getColumn());
|
||||
}
|
||||
|
||||
|
||||
|
@ -368,6 +368,12 @@ public class MotionGroup extends VimMotionGroupBase {
|
||||
moveCaret(((IjVimEditor) editor).getEditor(), ((IjVimCaret) caret).getCaret(), offset);
|
||||
}
|
||||
|
||||
/** Move the caret to the given offset
|
||||
* <p>
|
||||
* Note that <code>Caret.vimLastColumn</code> might be valid for visual block mode, if moving the primary caret after
|
||||
* using the end of line motion (<code>$</code>).
|
||||
* </p>
|
||||
*/
|
||||
public static void moveCaret(@NotNull Editor editor, @NotNull Caret caret, int offset) {
|
||||
if (offset < 0 || offset > editor.getDocument().getTextLength() || !caret.isValid()) return;
|
||||
|
||||
@ -377,9 +383,6 @@ public class MotionGroup extends VimMotionGroupBase {
|
||||
|
||||
// Note that this call replaces ALL carets, so any local caret instances will be invalid!
|
||||
VisualGroupKt.vimMoveBlockSelectionToOffset(editor, offset);
|
||||
|
||||
Caret primaryCaret = editor.getCaretModel().getPrimaryCaret();
|
||||
UserDataManager.setVimLastColumn(primaryCaret, primaryCaret.getVisualPosition().column);
|
||||
scrollCaretIntoView(editor);
|
||||
return;
|
||||
}
|
||||
|
@ -74,6 +74,9 @@ var Caret.vimLastColumn: Int
|
||||
_vimLastColumn = value
|
||||
_vimLastColumnPos = visualPosition
|
||||
}
|
||||
fun Caret.resetVimLastColumn() {
|
||||
_vimLastColumnPos = null
|
||||
}
|
||||
private var Caret._vimLastColumn: Int by userDataCaretToEditorOr { (this as Caret).inlayAwareVisualColumn }
|
||||
private var Caret._vimLastColumnPos: VisualPosition? by userDataCaretToEditor()
|
||||
|
||||
|
@ -398,7 +398,6 @@ object VimListenerManager {
|
||||
|
||||
// Reset caret after forceBarShape while dragging
|
||||
editor.updateCaretsVisualAttributes()
|
||||
caret.vimLastColumn = editor.caretModel.visualPosition.column
|
||||
}
|
||||
|
||||
mouseDragging = false
|
||||
@ -439,9 +438,6 @@ object VimListenerManager {
|
||||
KeyHandler.getInstance().reset(editor.vim)
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: 2019-03-22 Multi?
|
||||
caretModel.primaryCaret.vimLastColumn = caretModel.visualPosition.column
|
||||
} else if (event.area != EditorMouseEventArea.ANNOTATIONS_AREA &&
|
||||
event.area != EditorMouseEventArea.FOLDING_OUTLINE_AREA &&
|
||||
event.mouseEvent.button != MouseEvent.BUTTON3
|
||||
|
@ -33,7 +33,6 @@ import com.maddyhome.idea.vim.common.including
|
||||
import com.maddyhome.idea.vim.common.offset
|
||||
import com.maddyhome.idea.vim.group.MotionGroup
|
||||
import com.maddyhome.idea.vim.helper.EditorHelper
|
||||
import com.maddyhome.idea.vim.helper.inlayAwareVisualColumn
|
||||
import com.maddyhome.idea.vim.helper.vimChangeActionSwitchMode
|
||||
import com.maddyhome.idea.vim.helper.vimLastColumn
|
||||
|
||||
@ -107,7 +106,6 @@ fun deleteRange(
|
||||
): Boolean {
|
||||
val vimRange = toVimRange(range, type)
|
||||
|
||||
(caret as IjVimCaret).caret.vimLastColumn = caret.caret.inlayAwareVisualColumn
|
||||
val deletedInfo = injector.vimMachine.delete(vimRange, editor, caret)
|
||||
if (deletedInfo != null) {
|
||||
when (deletedInfo) {
|
||||
|
@ -31,6 +31,7 @@ import com.maddyhome.idea.vim.group.visual.vimUpdateEditorSelection
|
||||
import com.maddyhome.idea.vim.helper.inlayAwareVisualColumn
|
||||
import com.maddyhome.idea.vim.helper.moveToInlayAwareOffset
|
||||
import com.maddyhome.idea.vim.helper.registerStorage
|
||||
import com.maddyhome.idea.vim.helper.resetVimLastColumn
|
||||
import com.maddyhome.idea.vim.helper.vimInsertStart
|
||||
import com.maddyhome.idea.vim.helper.vimLastColumn
|
||||
import com.maddyhome.idea.vim.helper.vimLastVisualOperatorRange
|
||||
@ -56,6 +57,7 @@ class IjVimCaret(val caret: Caret) : VimCaretBase() {
|
||||
set(value) {
|
||||
caret.vimLastColumn = value
|
||||
}
|
||||
override fun resetLastColumn() = caret.resetVimLastColumn()
|
||||
override val inlayAwareVisualColumn: Int
|
||||
get() = caret.inlayAwareVisualColumn
|
||||
override val selectionStart: Int
|
||||
|
@ -43,7 +43,7 @@ class MotionShiftEndAction : ShiftedSpecialKeyHandler() {
|
||||
}
|
||||
|
||||
val newOffset = injector.motion.moveCaretToRelativeLineEnd(editor, caret, cmd.count - 1, allow)
|
||||
caret.vimLastColumn = VimMotionGroupBase.LAST_COLUMN
|
||||
|
||||
caret.moveToOffset(newOffset)
|
||||
caret.vimLastColumn = VimMotionGroupBase.LAST_COLUMN
|
||||
}
|
||||
|
@ -35,7 +35,6 @@ class SelectEnableBlockModeAction : VimActionHandler.SingleExecution() {
|
||||
editor.primaryCaret().run {
|
||||
vimSetSystemSelectionSilently(offset.point, (offset.point + 1).coerceAtMost(lineEnd))
|
||||
moveToInlayAwareOffset((offset.point + 1).coerceAtMost(lineEnd))
|
||||
vimLastColumn = getVisualPosition().column
|
||||
}
|
||||
return injector.visualMotionGroup.enterSelectMode(editor, VimStateMachine.SubMode.VISUAL_BLOCK)
|
||||
}
|
||||
|
@ -35,7 +35,6 @@ class SelectEnableCharacterModeAction : VimActionHandler.SingleExecution() {
|
||||
caret.run {
|
||||
vimSetSystemSelectionSilently(offset.point, (offset.point + 1).coerceAtMost(lineEnd))
|
||||
moveToInlayAwareOffset((offset.point + 1).coerceAtMost(lineEnd))
|
||||
vimLastColumn = getVisualPosition().column
|
||||
}
|
||||
}
|
||||
return injector.visualMotionGroup.enterSelectMode(editor, VimStateMachine.SubMode.VISUAL_CHARACTER)
|
||||
|
@ -35,6 +35,7 @@ interface VimCaret {
|
||||
val vimLine: Int
|
||||
|
||||
var vimLastColumn: Int
|
||||
fun resetLastColumn()
|
||||
val inlayAwareVisualColumn: Int
|
||||
|
||||
fun hasSelection(): Boolean
|
||||
|
@ -903,7 +903,8 @@ abstract class VimChangeGroupBase : VimChangeGroup {
|
||||
if (res) {
|
||||
var pos = injector.engineEditorHelper.normalizeOffset(editor, range.startOffset, isChange)
|
||||
if (type === SelectionType.LINE_WISE) {
|
||||
// Deleting text will move the caret, which invalidates the last column. Reset it before trying to use it
|
||||
// Reset the saved intended column cache, which has been invalidated by the caret moving due to deleted text.
|
||||
// This value will be used to reposition the caret if 'startofline' is false
|
||||
caret.vimLastColumn = intendedColumn
|
||||
pos = injector.motion
|
||||
.moveCaretToLineWithStartOfLineOption(
|
||||
@ -912,6 +913,10 @@ abstract class VimChangeGroupBase : VimChangeGroup {
|
||||
)
|
||||
}
|
||||
injector.motion.moveCaret(editor, caret, pos)
|
||||
|
||||
// Ensure the intended column cache is invalidated - it will only happen automatically if the caret actually moves
|
||||
// If 'startofline' is true and we've just deleted text, it's likely we haven't moved
|
||||
caret.resetLastColumn()
|
||||
}
|
||||
return res
|
||||
}
|
||||
|
@ -97,9 +97,6 @@ abstract class VimMachineBase : VimMachine {
|
||||
* - What caret?
|
||||
*/
|
||||
override fun delete(range: VimRange, editor: VimEditor, caret: VimCaret): OperatedRange? {
|
||||
// Update the last column before we delete, or we might be retrieving the data for a line that no longer exists
|
||||
caret.vimLastColumn = caret.inlayAwareVisualColumn
|
||||
|
||||
val operatedText = editor.deleteDryRun(range) ?: return null
|
||||
|
||||
val normalizedRange = operatedText.toNormalizedTextRange(editor)
|
||||
|
@ -144,7 +144,6 @@ sealed class ChangeEditorActionHandler : EditorActionHandlerBase(false) {
|
||||
if (worked[0]) {
|
||||
VimRepeater.saveLastChange(cmd)
|
||||
VimRepeater.repeatHandler = false
|
||||
editor.forEachNativeCaret({ it.vimLastColumn = it.getVisualPosition().column })
|
||||
}
|
||||
|
||||
val toSwitch = editor.vimChangeActionSwitchMode
|
||||
|
@ -268,7 +268,6 @@ sealed class VisualOperatorActionHandler : EditorActionHandlerBase(false) {
|
||||
caret.vimLastVisualOperatorRange = visualChange
|
||||
}
|
||||
}
|
||||
editor.forEachCaret({ it.vimLastColumn = it.getVisualPosition().column })
|
||||
}
|
||||
|
||||
editor.vimKeepingVisualOperatorAction = false
|
||||
|
Loading…
Reference in New Issue
Block a user