1
0
mirror of https://github.com/chylex/IntelliJ-IdeaVim.git synced 2025-05-29 19:34:09 +02:00

Remove unused range argument from yank motion

This commit is contained in:
Alex Plate 2025-03-07 09:40:27 +02:00
parent 156fbcd60d
commit 017b36673b
No known key found for this signature in database
GPG Key ID: 0B97153C8FFEC09F

View File

@ -16,15 +16,11 @@ import com.maddyhome.idea.vim.api.VimEditor
import com.maddyhome.idea.vim.api.anyNonWhitespace import com.maddyhome.idea.vim.api.anyNonWhitespace
import com.maddyhome.idea.vim.api.getLineEndForOffset import com.maddyhome.idea.vim.api.getLineEndForOffset
import com.maddyhome.idea.vim.api.getLineStartForOffset import com.maddyhome.idea.vim.api.getLineStartForOffset
import com.maddyhome.idea.vim.api.getText
import com.maddyhome.idea.vim.api.injector import com.maddyhome.idea.vim.api.injector
import com.maddyhome.idea.vim.api.normalizeColumn
import com.maddyhome.idea.vim.api.normalizeLine
import com.maddyhome.idea.vim.command.Argument import com.maddyhome.idea.vim.command.Argument
import com.maddyhome.idea.vim.command.MotionType import com.maddyhome.idea.vim.command.MotionType
import com.maddyhome.idea.vim.command.OperatorArguments import com.maddyhome.idea.vim.command.OperatorArguments
import com.maddyhome.idea.vim.common.TextRange import com.maddyhome.idea.vim.common.TextRange
import com.maddyhome.idea.vim.group.visual.vimLeadSelectionOffset
import com.maddyhome.idea.vim.handler.MotionActionHandler import com.maddyhome.idea.vim.handler.MotionActionHandler
import com.maddyhome.idea.vim.state.mode.SelectionType import com.maddyhome.idea.vim.state.mode.SelectionType
import org.jetbrains.annotations.Contract import org.jetbrains.annotations.Contract
@ -35,7 +31,6 @@ open class YankGroupBase : VimYankGroup {
editor: VimEditor, editor: VimEditor,
context: ExecutionContext, context: ExecutionContext,
caretToRange: Map<ImmutableVimCaret, TextRange>, caretToRange: Map<ImmutableVimCaret, TextRange>,
range: TextRange,
type: SelectionType, type: SelectionType,
startOffsets: Map<VimCaret, Int>?, startOffsets: Map<VimCaret, Int>?,
): Boolean { ): Boolean {
@ -95,7 +90,6 @@ open class YankGroupBase : VimYankGroup {
if (nativeCaretCount <= 0) return false if (nativeCaretCount <= 0) return false
val caretToRange = HashMap<ImmutableVimCaret, TextRange>(nativeCaretCount) val caretToRange = HashMap<ImmutableVimCaret, TextRange>(nativeCaretCount)
val ranges = ArrayList<Pair<Int, Int>>(nativeCaretCount)
// This logic is from original vim // This logic is from original vim
val startOffsets = val startOffsets =
@ -111,7 +105,6 @@ open class YankGroupBase : VimYankGroup {
?: continue ?: continue
assert(motionRange.size() == 1) assert(motionRange.size() == 1)
ranges.add(motionRange.startOffset to motionRange.endOffset)
startOffsets?.put(caret, motionRange.normalize().startOffset) startOffsets?.put(caret, motionRange.normalize().startOffset)
caretToRange[caret] = TextRange(motionRange.startOffset, motionRange.endOffset) caretToRange[caret] = TextRange(motionRange.startOffset, motionRange.endOffset)
@ -127,15 +120,12 @@ open class YankGroupBase : VimYankGroup {
} }
} }
val range = getTextRange(ranges, motionType) ?: return false if (caretToRange.isEmpty()) return false
if (range.size() == 0) return false
return yankRange( return yankRange(
editor, editor,
context, context,
caretToRange, caretToRange,
range,
motionType, motionType,
startOffsets, startOffsets,
) )
@ -156,7 +146,6 @@ open class YankGroupBase : VimYankGroup {
*/ */
override fun yankLine(editor: VimEditor, context: ExecutionContext, count: Int): Boolean { override fun yankLine(editor: VimEditor, context: ExecutionContext, count: Int): Boolean {
val caretCount = editor.nativeCarets().size val caretCount = editor.nativeCarets().size
val ranges = ArrayList<Pair<Int, Int>>(caretCount)
val caretToRange = HashMap<ImmutableVimCaret, TextRange>(caretCount) val caretToRange = HashMap<ImmutableVimCaret, TextRange>(caretCount)
for (caret in editor.nativeCarets()) { for (caret in editor.nativeCarets()) {
val start = injector.motion.moveCaretToCurrentLineStart(editor, caret) val start = injector.motion.moveCaretToCurrentLineStart(editor, caret)
@ -165,12 +154,10 @@ open class YankGroupBase : VimYankGroup {
if (end == -1) continue if (end == -1) continue
ranges.add(start to end)
caretToRange[caret] = TextRange(start, end) caretToRange[caret] = TextRange(start, end)
} }
val range = getTextRange(ranges, SelectionType.LINE_WISE) ?: return false return yankRange(editor, context, caretToRange, SelectionType.LINE_WISE, null)
return yankRange(editor, context, caretToRange, range, SelectionType.LINE_WISE, null)
} }
@Deprecated("Please use the same method, but with ExecutionContext") @Deprecated("Please use the same method, but with ExecutionContext")
@ -225,9 +212,9 @@ open class YankGroupBase : VimYankGroup {
} }
return if (moveCursor) { return if (moveCursor) {
yankRange(editor, context, caretToRange, range, type, startOffsets) yankRange(editor, context, caretToRange, type, startOffsets)
} else { } else {
yankRange(editor, context, caretToRange, range, type, null) yankRange(editor, context, caretToRange, type, null)
} }
} }
} }