mirror of
				https://github.com/chylex/IntelliJ-IdeaVim.git
				synced 2025-11-04 01:40:12 +01:00 
			
		
		
		
	Compare commits
	
		
			21 Commits
		
	
	
		
			0937234558
			...
			f33589fbce
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| 
						
						
							
						
						f33589fbce
	
				 | 
					
					
						|||
| 
						
						
							
						
						35445cb730
	
				 | 
					
					
						|||
| 
						
						
							
						
						9cba953bf7
	
				 | 
					
					
						|||
| 
						
						
							
						
						eb7c1953ae
	
				 | 
					
					
						|||
| 
						
						
							
						
						8d4a1cd7d5
	
				 | 
					
					
						|||
| 
						
						
							
						
						fd33e4254b
	
				 | 
					
					
						|||
| 
						
						
							
						
						f242cf18d7
	
				 | 
					
					
						|||
| 
						
						
							
						
						ac46a45f26
	
				 | 
					
					
						|||
| 
						
						
							
						
						9d1e29d4bc
	
				 | 
					
					
						|||
| 
						
						
							
						
						8c30f802ca
	
				 | 
					
					
						|||
| 
						
						
							
						
						766f3f498d
	
				 | 
					
					
						|||
| 
						
						
							
						
						60d9c59a3e
	
				 | 
					
					
						|||
| 
						
						
							
						
						025bfe5aba
	
				 | 
					
					
						|||
| 
						
						
							
						
						2edb650830
	
				 | 
					
					
						|||
| 
						
						
							
						
						3d75e14dc4
	
				 | 
					
					
						|||
| 
						
						
							
						
						db0290d218
	
				 | 
					
					
						|||
| 
						
						
							
						
						36716fe849
	
				 | 
					
					
						|||
| 
						
						
							
						
						7cfe42688b
	
				 | 
					
					
						|||
| 
						
						
							
						
						1d9fb7f6a7
	
				 | 
					
					
						|||
| 
						
						
							
						
						8c4828a6fd
	
				 | 
					
					
						|||
| 
						
						
							
						
						86f11a9554
	
				 | 
					
					
						
							
								
								
									
										1
									
								
								.gitattributes
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										1
									
								
								.gitattributes
									
									
									
									
										vendored
									
									
										Normal file
									
								
							@@ -0,0 +1 @@
 | 
			
		||||
* text=auto eol=lf
 | 
			
		||||
@@ -128,18 +128,7 @@ dependencies {
 | 
			
		||||
 | 
			
		||||
    // AceJump is an optional dependency. We use their SessionManager class to check if it's active
 | 
			
		||||
    plugin("AceJump", "3.8.19")
 | 
			
		||||
 | 
			
		||||
    // [VERSION UPDATE] 2024.3+
 | 
			
		||||
    // Dirty hack: in 2024.3+ the json plugin is extracted. So, the tests that use JSON don't work.
 | 
			
		||||
    // If the IdeaVim minimal version is bumped to 2024.3, leave only `bundledPlugins...` line
 | 
			
		||||
    // If we start to support a new version like 2024.2.2 or 2025.1.1, please add it to the correct branch of this when
 | 
			
		||||
    // This check intentionally has a pattern where we explicitly specify if to use the JSON plugin for each
 | 
			
		||||
    //   supported version or not to prevent developers from figuring out what happened with JSON.
 | 
			
		||||
    when (ideaVersion) {
 | 
			
		||||
      "2024.2.1" -> { /* Nothing */ }
 | 
			
		||||
      "LATEST-EAP-SNAPSHOT", "2024.3" -> bundledPlugins("com.intellij.modules.json")
 | 
			
		||||
      else -> error("Unsupported version: $ideaVersion")
 | 
			
		||||
    }
 | 
			
		||||
    plugin("com.intellij.classic.ui", "242.20224.159")
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  moduleSources(project(":vim-engine", "sourcesJarArtifacts"))
 | 
			
		||||
@@ -225,6 +214,8 @@ tasks {
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  compileTestKotlin {
 | 
			
		||||
    enabled = false
 | 
			
		||||
    
 | 
			
		||||
    kotlinOptions {
 | 
			
		||||
      jvmTarget = javaVersion
 | 
			
		||||
      apiVersion = "1.9"
 | 
			
		||||
 
 | 
			
		||||
@@ -16,11 +16,11 @@
 | 
			
		||||
# https://data.services.jetbrains.com/products?code=IC
 | 
			
		||||
# Maven releases are here: https://www.jetbrains.com/intellij-repository/releases
 | 
			
		||||
# And snapshots: https://www.jetbrains.com/intellij-repository/snapshots
 | 
			
		||||
ideaVersion=2024.2.1
 | 
			
		||||
ideaVersion=2024.2
 | 
			
		||||
# Values for type: https://plugins.jetbrains.com/docs/intellij/tools-gradle-intellij-plugin.html#intellij-extension-type
 | 
			
		||||
ideaType=IC
 | 
			
		||||
instrumentPluginCode=true
 | 
			
		||||
version=SNAPSHOT
 | 
			
		||||
version=chylex-42
 | 
			
		||||
javaVersion=17
 | 
			
		||||
remoteRobotVersion=0.11.23
 | 
			
		||||
antlrVersion=4.10.1
 | 
			
		||||
@@ -41,7 +41,6 @@ youtrackToken=
 | 
			
		||||
 | 
			
		||||
# Gradle settings
 | 
			
		||||
org.gradle.jvmargs='-Dfile.encoding=UTF-8'
 | 
			
		||||
org.gradle.configuration-cache=true
 | 
			
		||||
org.gradle.caching=true
 | 
			
		||||
 | 
			
		||||
# Disable warning from gradle-intellij-plugin. Kotlin stdlib is included as compileOnly, so the warning is unnecessary
 | 
			
		||||
 
 | 
			
		||||
@@ -0,0 +1,52 @@
 | 
			
		||||
package com.maddyhome.idea.vim.action
 | 
			
		||||
 | 
			
		||||
import com.intellij.openapi.actionSystem.ActionUpdateThread
 | 
			
		||||
import com.intellij.openapi.actionSystem.AnActionEvent
 | 
			
		||||
import com.intellij.openapi.command.UndoConfirmationPolicy
 | 
			
		||||
import com.intellij.openapi.command.WriteCommandAction
 | 
			
		||||
import com.intellij.openapi.fileEditor.TextEditor
 | 
			
		||||
import com.intellij.openapi.fileEditor.ex.FileEditorManagerEx
 | 
			
		||||
import com.intellij.openapi.project.DumbAwareAction
 | 
			
		||||
import com.maddyhome.idea.vim.KeyHandler
 | 
			
		||||
import com.maddyhome.idea.vim.api.injector
 | 
			
		||||
import com.maddyhome.idea.vim.newapi.IjEditorExecutionContext
 | 
			
		||||
import com.maddyhome.idea.vim.newapi.vim
 | 
			
		||||
import com.maddyhome.idea.vim.state.mode.Mode
 | 
			
		||||
 | 
			
		||||
class VimRunLastMacroInOpenFiles : DumbAwareAction() {
 | 
			
		||||
  override fun update(e: AnActionEvent) {
 | 
			
		||||
    val lastRegister = injector.macro.lastRegister
 | 
			
		||||
    val isEnabled = lastRegister != 0.toChar()
 | 
			
		||||
 | 
			
		||||
    e.presentation.isEnabled = isEnabled
 | 
			
		||||
    e.presentation.text = if (isEnabled) "Run Macro '${lastRegister}' in Open Files" else "Run Last Macro in Open Files"
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  override fun getActionUpdateThread(): ActionUpdateThread {
 | 
			
		||||
    return ActionUpdateThread.EDT
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  override fun actionPerformed(e: AnActionEvent) {
 | 
			
		||||
    val project = e.project ?: return
 | 
			
		||||
    val fileEditorManager = FileEditorManagerEx.getInstanceExIfCreated(project) ?: return
 | 
			
		||||
    val editors = fileEditorManager.allEditors.filterIsInstance<TextEditor>()
 | 
			
		||||
    
 | 
			
		||||
    WriteCommandAction.writeCommandAction(project)
 | 
			
		||||
      .withName(e.presentation.text)
 | 
			
		||||
      .withGlobalUndo()
 | 
			
		||||
      .withUndoConfirmationPolicy(UndoConfirmationPolicy.REQUEST_CONFIRMATION)
 | 
			
		||||
      .run<RuntimeException> {
 | 
			
		||||
        val reg = injector.macro.lastRegister
 | 
			
		||||
        
 | 
			
		||||
        for (editor in editors) {
 | 
			
		||||
          fileEditorManager.openFile(editor.file, true)
 | 
			
		||||
          
 | 
			
		||||
          val vimEditor = editor.editor.vim
 | 
			
		||||
          vimEditor.mode = Mode.NORMAL()
 | 
			
		||||
          KeyHandler.getInstance().reset(vimEditor)
 | 
			
		||||
          
 | 
			
		||||
          injector.macro.playbackRegister(vimEditor, IjEditorExecutionContext(e.dataContext), reg, 1)
 | 
			
		||||
        }
 | 
			
		||||
      }
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
@@ -285,4 +285,4 @@ fun VimExtensionFacade.exportOperatorFunction(name: String, function: OperatorFu
 | 
			
		||||
 | 
			
		||||
fun interface ScriptFunction {
 | 
			
		||||
  fun execute(editor: VimEditor, context: ExecutionContext, args: Map<String, VimDataType>): ExecutionResult
 | 
			
		||||
}
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -21,9 +21,7 @@ import com.intellij.openapi.editor.markup.TextAttributes
 | 
			
		||||
import com.intellij.openapi.util.Disposer
 | 
			
		||||
import com.intellij.util.Alarm
 | 
			
		||||
import com.intellij.util.Alarm.ThreadToUse
 | 
			
		||||
import com.jetbrains.rd.util.first
 | 
			
		||||
import com.maddyhome.idea.vim.VimPlugin
 | 
			
		||||
import com.maddyhome.idea.vim.api.ImmutableVimCaret
 | 
			
		||||
import com.maddyhome.idea.vim.api.VimEditor
 | 
			
		||||
import com.maddyhome.idea.vim.api.injector
 | 
			
		||||
import com.maddyhome.idea.vim.common.ModeChangeListener
 | 
			
		||||
@@ -123,9 +121,9 @@ internal class VimHighlightedYank : VimExtension, VimYankListener, ModeChangeLis
 | 
			
		||||
    initialised = false
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  override fun yankPerformed(caretToRange: Map<ImmutableVimCaret, TextRange>) {
 | 
			
		||||
  override fun yankPerformed(editor: VimEditor, range: TextRange) {
 | 
			
		||||
    ensureInitialised()
 | 
			
		||||
    highlightHandler.highlightYankRange(caretToRange)
 | 
			
		||||
    highlightHandler.highlightYankRange(editor.ij, range)
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  override fun modeChanged(editor: VimEditor, oldMode: Mode) {
 | 
			
		||||
@@ -146,25 +144,22 @@ internal class VimHighlightedYank : VimExtension, VimYankListener, ModeChangeLis
 | 
			
		||||
    private var lastEditor: Editor? = null
 | 
			
		||||
    private val highlighters = mutableSetOf<RangeHighlighter>()
 | 
			
		||||
 | 
			
		||||
    fun highlightYankRange(caretToRange: Map<ImmutableVimCaret, TextRange>) {
 | 
			
		||||
    fun highlightYankRange(editor: Editor, range: TextRange) {
 | 
			
		||||
      // from vim-highlightedyank docs: When a new text is yanked or user starts editing, the old highlighting would be deleted
 | 
			
		||||
      clearYankHighlighters()
 | 
			
		||||
 | 
			
		||||
      val editor = caretToRange.first().key.editor.ij
 | 
			
		||||
      lastEditor = editor
 | 
			
		||||
 | 
			
		||||
      val attributes = getHighlightTextAttributes(editor)
 | 
			
		||||
      for (range in caretToRange.values) {
 | 
			
		||||
        for (i in 0 until range.size()) {
 | 
			
		||||
          val highlighter = editor.markupModel.addRangeHighlighter(
 | 
			
		||||
            range.startOffsets[i],
 | 
			
		||||
            range.endOffsets[i],
 | 
			
		||||
            HighlighterLayer.SELECTION,
 | 
			
		||||
            attributes,
 | 
			
		||||
            HighlighterTargetArea.EXACT_RANGE,
 | 
			
		||||
          )
 | 
			
		||||
          highlighters.add(highlighter)
 | 
			
		||||
        }
 | 
			
		||||
      for (i in 0 until range.size()) {
 | 
			
		||||
        val highlighter = editor.markupModel.addRangeHighlighter(
 | 
			
		||||
          range.startOffsets[i],
 | 
			
		||||
          range.endOffsets[i],
 | 
			
		||||
          HighlighterLayer.SELECTION,
 | 
			
		||||
          attributes,
 | 
			
		||||
          HighlighterTargetArea.EXACT_RANGE,
 | 
			
		||||
        )
 | 
			
		||||
        highlighters.add(highlighter)
 | 
			
		||||
      }
 | 
			
		||||
 | 
			
		||||
      // from vim-highlightedyank docs: A negative number makes the highlight persistent.
 | 
			
		||||
@@ -282,4 +277,4 @@ internal class VimHighlightedYank : VimExtension, VimYankListener, ModeChangeLis
 | 
			
		||||
      return default
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -230,7 +230,7 @@ private object FileTypePatterns {
 | 
			
		||||
    } else if (fileTypeName == "CMakeLists.txt" || fileName == "CMakeLists") {
 | 
			
		||||
      this.cMakePatterns
 | 
			
		||||
    } else {
 | 
			
		||||
      return null
 | 
			
		||||
      this.htmlPatterns
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -29,7 +29,6 @@ import com.maddyhome.idea.vim.extension.exportOperatorFunction
 | 
			
		||||
import com.maddyhome.idea.vim.group.visual.VimSelection
 | 
			
		||||
import com.maddyhome.idea.vim.helper.exitVisualMode
 | 
			
		||||
import com.maddyhome.idea.vim.key.OperatorFunction
 | 
			
		||||
import com.maddyhome.idea.vim.newapi.IjVimCopiedText
 | 
			
		||||
import com.maddyhome.idea.vim.newapi.IjVimEditor
 | 
			
		||||
import com.maddyhome.idea.vim.newapi.ij
 | 
			
		||||
import com.maddyhome.idea.vim.newapi.vim
 | 
			
		||||
@@ -154,8 +153,7 @@ private fun doReplace(editor: Editor, context: DataContext, caret: ImmutableVimC
 | 
			
		||||
    usedType = SelectionType.CHARACTER_WISE
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  val copiedText = IjVimCopiedText(usedText, (savedRegister.copiedText as IjVimCopiedText).transferableData)
 | 
			
		||||
  val textData = PutData.TextData(savedRegister.name, copiedText, usedType)
 | 
			
		||||
  val textData = PutData.TextData(usedText, usedType, savedRegister.transferableData, savedRegister.name)
 | 
			
		||||
 | 
			
		||||
  val putData = PutData(
 | 
			
		||||
    textData,
 | 
			
		||||
 
 | 
			
		||||
@@ -0,0 +1,30 @@
 | 
			
		||||
package com.maddyhome.idea.vim.extension.surround
 | 
			
		||||
 | 
			
		||||
import com.intellij.util.text.CharSequenceSubSequence
 | 
			
		||||
 | 
			
		||||
internal data class RepeatedCharSequence(val text: CharSequence, val count: Int) : CharSequence {
 | 
			
		||||
  override val length = text.length * count
 | 
			
		||||
 | 
			
		||||
  override fun get(index: Int): Char {
 | 
			
		||||
    if (index < 0 || index >= length) throw IndexOutOfBoundsException()
 | 
			
		||||
    return text[index % text.length]
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  override fun subSequence(startIndex: Int, endIndex: Int): CharSequence {
 | 
			
		||||
    return CharSequenceSubSequence(this, startIndex, endIndex)
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  override fun toString(): String {
 | 
			
		||||
    return text.repeat(count)
 | 
			
		||||
  }
 | 
			
		||||
  
 | 
			
		||||
  companion object {
 | 
			
		||||
    fun of(text: CharSequence, count: Int): CharSequence {
 | 
			
		||||
      return when (count) {
 | 
			
		||||
        0 -> ""
 | 
			
		||||
        1 -> text
 | 
			
		||||
        else -> RepeatedCharSequence(text, count)
 | 
			
		||||
      }
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
@@ -14,6 +14,7 @@ import com.intellij.openapi.editor.Editor
 | 
			
		||||
import com.maddyhome.idea.vim.VimPlugin
 | 
			
		||||
import com.maddyhome.idea.vim.api.ExecutionContext
 | 
			
		||||
import com.maddyhome.idea.vim.api.VimCaret
 | 
			
		||||
import com.maddyhome.idea.vim.api.VimChangeGroup
 | 
			
		||||
import com.maddyhome.idea.vim.api.VimEditor
 | 
			
		||||
import com.maddyhome.idea.vim.api.endsWithNewLine
 | 
			
		||||
import com.maddyhome.idea.vim.api.getLeadingCharacterOffset
 | 
			
		||||
@@ -36,18 +37,21 @@ import com.maddyhome.idea.vim.extension.VimExtensionFacade.setRegisterForCaret
 | 
			
		||||
import com.maddyhome.idea.vim.extension.exportOperatorFunction
 | 
			
		||||
import com.maddyhome.idea.vim.group.findBlockRange
 | 
			
		||||
import com.maddyhome.idea.vim.helper.exitVisualMode
 | 
			
		||||
import com.maddyhome.idea.vim.helper.runWithEveryCaretAndRestore
 | 
			
		||||
import com.maddyhome.idea.vim.key.OperatorFunction
 | 
			
		||||
import com.maddyhome.idea.vim.newapi.IjVimCaret
 | 
			
		||||
import com.maddyhome.idea.vim.newapi.IjVimEditor
 | 
			
		||||
import com.maddyhome.idea.vim.newapi.ij
 | 
			
		||||
import com.maddyhome.idea.vim.newapi.vim
 | 
			
		||||
import com.maddyhome.idea.vim.options.helpers.ClipboardOptionHelper
 | 
			
		||||
import com.maddyhome.idea.vim.put.PutData
 | 
			
		||||
import com.maddyhome.idea.vim.state.mode.Mode
 | 
			
		||||
import com.maddyhome.idea.vim.state.mode.SelectionType
 | 
			
		||||
import com.maddyhome.idea.vim.state.mode.returnTo
 | 
			
		||||
import com.maddyhome.idea.vim.state.mode.selectionType
 | 
			
		||||
import org.jetbrains.annotations.NonNls
 | 
			
		||||
import java.awt.event.KeyEvent
 | 
			
		||||
import javax.swing.KeyStroke
 | 
			
		||||
import com.maddyhome.idea.vim.state.mode.returnTo
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Port of vim-surround.
 | 
			
		||||
@@ -80,7 +84,7 @@ internal class VimSurroundExtension : VimExtension {
 | 
			
		||||
      putKeyMappingIfMissing(MappingMode.XO, injector.parser.parseKeys("S"), owner, injector.parser.parseKeys("<Plug>VSurround"), true)
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    VimExtensionFacade.exportOperatorFunction(OPERATOR_FUNC, Operator())
 | 
			
		||||
    VimExtensionFacade.exportOperatorFunction(OPERATOR_FUNC, Operator(supportsMultipleCursors = false, count = 1)) // TODO
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  private class YSurroundHandler : ExtensionHandler {
 | 
			
		||||
@@ -108,7 +112,7 @@ internal class VimSurroundExtension : VimExtension {
 | 
			
		||||
        val lastNonWhiteSpaceOffset = getLastNonWhitespaceCharacterOffset(editor.text(), lineStartOffset, lineEndOffset)
 | 
			
		||||
        if (lastNonWhiteSpaceOffset != null) {
 | 
			
		||||
          val range = TextRange(lineStartOffset, lastNonWhiteSpaceOffset + 1)
 | 
			
		||||
          performSurround(pair, range, it)
 | 
			
		||||
          performSurround(pair, range, it, count = operatorArguments.count1)
 | 
			
		||||
        }
 | 
			
		||||
//        it.moveToOffset(lineStartOffset)
 | 
			
		||||
      }
 | 
			
		||||
@@ -131,15 +135,13 @@ internal class VimSurroundExtension : VimExtension {
 | 
			
		||||
 | 
			
		||||
  private class VSurroundHandler : ExtensionHandler {
 | 
			
		||||
    override fun execute(editor: VimEditor, context: ExecutionContext, operatorArguments: OperatorArguments) {
 | 
			
		||||
      val selectionStart = editor.ij.caretModel.primaryCaret.selectionStart
 | 
			
		||||
      // NB: Operator ignores SelectionType anyway
 | 
			
		||||
      if (!Operator().apply(editor, context, editor.mode.selectionType)) {
 | 
			
		||||
      if (!Operator(supportsMultipleCursors = true, count = operatorArguments.count1).apply(editor, context, editor.mode.selectionType)) {
 | 
			
		||||
        return
 | 
			
		||||
      }
 | 
			
		||||
      runWriteAction {
 | 
			
		||||
        // Leave visual mode
 | 
			
		||||
        editor.exitVisualMode()
 | 
			
		||||
        editor.ij.caretModel.moveToOffset(selectionStart)
 | 
			
		||||
      }
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
@@ -160,6 +162,10 @@ internal class VimSurroundExtension : VimExtension {
 | 
			
		||||
 | 
			
		||||
    companion object {
 | 
			
		||||
      fun change(editor: VimEditor, context: ExecutionContext, charFrom: Char, newSurround: SurroundPair?) {
 | 
			
		||||
        editor.ij.runWithEveryCaretAndRestore { changeAtCaret(editor, context, charFrom, newSurround) }
 | 
			
		||||
      }
 | 
			
		||||
      
 | 
			
		||||
      fun changeAtCaret(editor: VimEditor, context: ExecutionContext, charFrom: Char, newSurround: SurroundPair?) {
 | 
			
		||||
        // Save old register values for carets
 | 
			
		||||
        val surroundings = editor.sortedCarets()
 | 
			
		||||
          .map {
 | 
			
		||||
@@ -200,7 +206,7 @@ internal class VimSurroundExtension : VimExtension {
 | 
			
		||||
              val trimmedValue = if (newSurround.shouldTrim) innerValue.trim() else innerValue
 | 
			
		||||
              it.first + trimmedValue + it.second
 | 
			
		||||
            } ?: innerValue
 | 
			
		||||
            val textData = PutData.TextData(null, injector.clipboardManager.dumbCopiedText(text), SelectionType.CHARACTER_WISE)
 | 
			
		||||
            val textData = PutData.TextData(text, SelectionType.CHARACTER_WISE, emptyList(), null)
 | 
			
		||||
            val putData = PutData(textData, null, 1, insertTextBeforeCaret = true, rawIndent = true, caretAfterInsertedText = false)
 | 
			
		||||
 | 
			
		||||
            surrounding.caret to putData
 | 
			
		||||
@@ -271,20 +277,41 @@ internal class VimSurroundExtension : VimExtension {
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  private class Operator : OperatorFunction {
 | 
			
		||||
    override fun apply(editor: VimEditor, context: ExecutionContext, selectionType: SelectionType?): Boolean {
 | 
			
		||||
      val ijEditor = editor.ij
 | 
			
		||||
  private class Operator(private val supportsMultipleCursors: Boolean, private val count: Int) : OperatorFunction {
 | 
			
		||||
    override fun apply(vimEditor: VimEditor, context: ExecutionContext, selectionType: SelectionType?): Boolean {
 | 
			
		||||
      val ijEditor = vimEditor.ij
 | 
			
		||||
      val c = getChar(ijEditor)
 | 
			
		||||
      if (c.code == 0) return true
 | 
			
		||||
 | 
			
		||||
      val pair = getOrInputPair(c, ijEditor, context.ij) ?: return false
 | 
			
		||||
      // XXX: Will it work with line-wise or block-wise selections?
 | 
			
		||||
      val range = getSurroundRange(editor.currentCaret()) ?: return false
 | 
			
		||||
      performSurround(pair, range, editor.currentCaret(), selectionType == SelectionType.LINE_WISE)
 | 
			
		||||
      // Jump back to start
 | 
			
		||||
      executeNormalWithoutMapping(injector.parser.parseKeys("`["), ijEditor)
 | 
			
		||||
 | 
			
		||||
      runWriteAction {
 | 
			
		||||
        val change = VimPlugin.getChange()
 | 
			
		||||
        if (supportsMultipleCursors) {
 | 
			
		||||
          ijEditor.runWithEveryCaretAndRestore {
 | 
			
		||||
            applyOnce(ijEditor, change, pair, count)
 | 
			
		||||
          }
 | 
			
		||||
        }
 | 
			
		||||
        else {
 | 
			
		||||
          applyOnce(ijEditor, change, pair, count)
 | 
			
		||||
          // Jump back to start
 | 
			
		||||
          executeNormalWithoutMapping(injector.parser.parseKeys("`["), ijEditor)
 | 
			
		||||
        }
 | 
			
		||||
      }
 | 
			
		||||
      return true
 | 
			
		||||
    }
 | 
			
		||||
    
 | 
			
		||||
    private fun applyOnce(editor: Editor, change: VimChangeGroup, pair: SurroundPair, count: Int) {
 | 
			
		||||
      // XXX: Will it work with line-wise or block-wise selections?
 | 
			
		||||
      val primaryCaret = editor.caretModel.primaryCaret
 | 
			
		||||
      val range = getSurroundRange(primaryCaret.vim)
 | 
			
		||||
      if (range != null) {
 | 
			
		||||
        val start = RepeatedCharSequence.of(pair.first, count)
 | 
			
		||||
        val end = RepeatedCharSequence.of(pair.second, count)
 | 
			
		||||
        change.insertText(IjVimEditor(editor), IjVimCaret(primaryCaret), range.startOffset, start)
 | 
			
		||||
        change.insertText(IjVimEditor(editor), IjVimCaret(primaryCaret), range.endOffset + start.length, end)
 | 
			
		||||
      }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private fun getSurroundRange(caret: VimCaret): TextRange? {
 | 
			
		||||
      val editor = caret.editor
 | 
			
		||||
@@ -385,15 +412,15 @@ private fun getChar(editor: Editor): Char {
 | 
			
		||||
  return res
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
private fun performSurround(pair: SurroundPair, range: TextRange, caret: VimCaret, tagsOnNewLines: Boolean = false) {
 | 
			
		||||
private fun performSurround(pair: SurroundPair, range: TextRange, caret: VimCaret, count: Int, tagsOnNewLines: Boolean = false) {
 | 
			
		||||
  runWriteAction {
 | 
			
		||||
    val editor = caret.editor
 | 
			
		||||
    val change = VimPlugin.getChange()
 | 
			
		||||
    val leftSurround = pair.first + if (tagsOnNewLines) "\n" else ""
 | 
			
		||||
    val leftSurround = RepeatedCharSequence.of(pair.first + if (tagsOnNewLines) "\n" else "", count)
 | 
			
		||||
 | 
			
		||||
    val isEOF = range.endOffset == editor.text().length
 | 
			
		||||
    val hasNewLine = editor.endsWithNewLine()
 | 
			
		||||
    val rightSurround = if (tagsOnNewLines) {
 | 
			
		||||
    val rightSurround = (if (tagsOnNewLines) {
 | 
			
		||||
      if (isEOF && !hasNewLine) {
 | 
			
		||||
        "\n" + pair.second
 | 
			
		||||
      } else {
 | 
			
		||||
@@ -401,7 +428,7 @@ private fun performSurround(pair: SurroundPair, range: TextRange, caret: VimCare
 | 
			
		||||
      }
 | 
			
		||||
    } else {
 | 
			
		||||
      pair.second
 | 
			
		||||
    }
 | 
			
		||||
    }).let { RepeatedCharSequence.of(it, count) }
 | 
			
		||||
 | 
			
		||||
    change.insertText(editor, caret, range.startOffset, leftSurround)
 | 
			
		||||
    change.insertText(editor, caret, range.endOffset + leftSurround.length, rightSurround)
 | 
			
		||||
 
 | 
			
		||||
@@ -42,7 +42,6 @@ import com.maddyhome.idea.vim.newapi.ij
 | 
			
		||||
import com.maddyhome.idea.vim.state.mode.Mode
 | 
			
		||||
import com.maddyhome.idea.vim.undo.VimKeyBasedUndoService
 | 
			
		||||
import com.maddyhome.idea.vim.undo.VimTimestampBasedUndoService
 | 
			
		||||
import kotlin.math.min
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Provides all the insert/replace related functionality
 | 
			
		||||
@@ -139,6 +138,7 @@ class ChangeGroup : VimChangeGroupBase() {
 | 
			
		||||
    context: ExecutionContext,
 | 
			
		||||
    range: TextRange,
 | 
			
		||||
  ) {
 | 
			
		||||
    val startPos = editor.offsetToBufferPosition(caret.offset)
 | 
			
		||||
    val startOffset = editor.getLineStartForOffset(range.startOffset)
 | 
			
		||||
    val endOffset = editor.getLineEndForOffset(range.endOffset)
 | 
			
		||||
    val ijEditor = (editor as IjVimEditor).editor
 | 
			
		||||
@@ -163,11 +163,7 @@ class ChangeGroup : VimChangeGroupBase() {
 | 
			
		||||
      }
 | 
			
		||||
    }
 | 
			
		||||
    val afterAction = {
 | 
			
		||||
      val firstLine = editor.offsetToBufferPosition(
 | 
			
		||||
        min(startOffset.toDouble(), endOffset.toDouble()).toInt()
 | 
			
		||||
      ).line
 | 
			
		||||
      val newOffset = injector.motion.moveCaretToLineStartSkipLeading(editor, firstLine)
 | 
			
		||||
      caret.moveToOffset(newOffset)
 | 
			
		||||
      caret.moveToOffset(injector.motion.moveCaretToLineStartSkipLeading(editor, startPos.line))
 | 
			
		||||
      restoreCursor(editor, caret, (caret as IjVimCaret).caret.logicalPosition.line)
 | 
			
		||||
    }
 | 
			
		||||
    if (project != null) {
 | 
			
		||||
 
 | 
			
		||||
@@ -139,7 +139,7 @@ object IjOptions {
 | 
			
		||||
  // Temporary feature flags during development, not really intended for external use
 | 
			
		||||
  val closenotebooks: ToggleOption = addOption(ToggleOption("closenotebooks", GLOBAL, "closenotebooks", true, isHidden = true))
 | 
			
		||||
  val commandOrMotionAnnotation: ToggleOption = addOption(ToggleOption("commandormotionannotation", GLOBAL, "commandormotionannotation", true, isHidden = true))
 | 
			
		||||
  val oldundo: ToggleOption = addOption(ToggleOption("oldundo", GLOBAL, "oldundo", false, isHidden = true))
 | 
			
		||||
  val oldundo: ToggleOption = addOption(ToggleOption("oldundo", GLOBAL, "oldundo", true, isHidden = true))
 | 
			
		||||
  val unifyjumps: ToggleOption = addOption(ToggleOption("unifyjumps", GLOBAL, "unifyjumps", true, isHidden = true))
 | 
			
		||||
  val vimscriptFunctionAnnotation: ToggleOption = addOption(ToggleOption("vimscriptfunctionannotation", GLOBAL, "vimscriptfunctionannotation", true, isHidden = true))
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -0,0 +1,68 @@
 | 
			
		||||
package com.maddyhome.idea.vim.group
 | 
			
		||||
 | 
			
		||||
import com.intellij.codeInsight.daemon.ReferenceImporter
 | 
			
		||||
import com.intellij.openapi.actionSystem.CommonDataKeys
 | 
			
		||||
import com.intellij.openapi.actionSystem.DataContext
 | 
			
		||||
import com.intellij.openapi.application.ApplicationManager
 | 
			
		||||
import com.intellij.openapi.application.ReadAction
 | 
			
		||||
import com.intellij.openapi.command.WriteCommandAction
 | 
			
		||||
import com.intellij.openapi.editor.Editor
 | 
			
		||||
import com.intellij.openapi.fileEditor.FileDocumentManager
 | 
			
		||||
import com.intellij.openapi.progress.ProgressIndicator
 | 
			
		||||
import com.intellij.openapi.progress.ProgressManager
 | 
			
		||||
import com.intellij.openapi.progress.Task
 | 
			
		||||
import com.intellij.psi.PsiDocumentManager
 | 
			
		||||
import com.intellij.psi.PsiElement
 | 
			
		||||
import com.intellij.psi.PsiRecursiveElementWalkingVisitor
 | 
			
		||||
import java.util.function.BooleanSupplier
 | 
			
		||||
 | 
			
		||||
internal object MacroAutoImport {
 | 
			
		||||
  fun run(editor: Editor, dataContext: DataContext) {
 | 
			
		||||
    val project = CommonDataKeys.PROJECT.getData(dataContext) ?: return
 | 
			
		||||
    val file = PsiDocumentManager.getInstance(project).getPsiFile(editor.document) ?: return
 | 
			
		||||
 | 
			
		||||
    if (!FileDocumentManager.getInstance().requestWriting(editor.document, project)) {
 | 
			
		||||
      return
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    val importers = ReferenceImporter.EP_NAME.extensionList
 | 
			
		||||
    if (importers.isEmpty()) {
 | 
			
		||||
      return
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    ProgressManager.getInstance().run(object : Task.Backgroundable(project, "Auto import", true) {
 | 
			
		||||
      override fun run(indicator: ProgressIndicator) {
 | 
			
		||||
        val fixes = ReadAction.nonBlocking<List<BooleanSupplier>> {
 | 
			
		||||
          val fixes = mutableListOf<BooleanSupplier>()
 | 
			
		||||
 | 
			
		||||
          file.accept(object : PsiRecursiveElementWalkingVisitor() {
 | 
			
		||||
            override fun visitElement(element: PsiElement) {
 | 
			
		||||
              for (reference in element.references) {
 | 
			
		||||
                if (reference.resolve() != null) {
 | 
			
		||||
                  continue
 | 
			
		||||
                }
 | 
			
		||||
                for (importer in importers) {
 | 
			
		||||
                  importer.computeAutoImportAtOffset(editor, file, element.textRange.startOffset, true)
 | 
			
		||||
                    ?.let(fixes::add)
 | 
			
		||||
                }
 | 
			
		||||
              }
 | 
			
		||||
              super.visitElement(element)
 | 
			
		||||
            }
 | 
			
		||||
          })
 | 
			
		||||
 | 
			
		||||
          return@nonBlocking fixes
 | 
			
		||||
        }.executeSynchronously()
 | 
			
		||||
 | 
			
		||||
        ApplicationManager.getApplication().invokeAndWait {
 | 
			
		||||
          WriteCommandAction.writeCommandAction(project)
 | 
			
		||||
            .withName("Auto Import")
 | 
			
		||||
            .withGroupId("IdeaVimAutoImportAfterMacro")
 | 
			
		||||
            .shouldRecordActionForActiveDocument(true)
 | 
			
		||||
            .run<RuntimeException> {
 | 
			
		||||
              fixes.forEach { it.asBoolean }
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
      }
 | 
			
		||||
    })
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
@@ -22,6 +22,7 @@ import com.maddyhome.idea.vim.api.injector
 | 
			
		||||
import com.maddyhome.idea.vim.helper.MessageHelper.message
 | 
			
		||||
import com.maddyhome.idea.vim.macro.VimMacroBase
 | 
			
		||||
import com.maddyhome.idea.vim.newapi.IjVimEditor
 | 
			
		||||
import com.maddyhome.idea.vim.newapi.ij
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Used to handle playback of macros
 | 
			
		||||
@@ -93,6 +94,9 @@ internal class MacroGroup : VimMacroBase() {
 | 
			
		||||
        } finally {
 | 
			
		||||
          keyStack.removeFirst()
 | 
			
		||||
        }
 | 
			
		||||
        if (!isInternalMacro) {
 | 
			
		||||
          MacroAutoImport.run(editor.ij, context.ij)
 | 
			
		||||
        }
 | 
			
		||||
      }
 | 
			
		||||
 | 
			
		||||
      if (isInternalMacro) {
 | 
			
		||||
 
 | 
			
		||||
@@ -14,7 +14,6 @@ import com.intellij.openapi.components.State;
 | 
			
		||||
import com.intellij.openapi.components.Storage;
 | 
			
		||||
import com.intellij.openapi.diagnostic.Logger;
 | 
			
		||||
import com.maddyhome.idea.vim.VimPlugin;
 | 
			
		||||
import com.maddyhome.idea.vim.api.VimInjectorKt;
 | 
			
		||||
import com.maddyhome.idea.vim.newapi.IjVimInjectorKt;
 | 
			
		||||
import com.maddyhome.idea.vim.register.Register;
 | 
			
		||||
import com.maddyhome.idea.vim.register.VimRegisterGroupBase;
 | 
			
		||||
@@ -29,8 +28,6 @@ import java.util.ArrayList;
 | 
			
		||||
import java.util.Collections;
 | 
			
		||||
import java.util.List;
 | 
			
		||||
 | 
			
		||||
import static com.maddyhome.idea.vim.api.VimInjectorKt.injector;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * This group works with command associated with copying and pasting text
 | 
			
		||||
 */
 | 
			
		||||
@@ -131,7 +128,7 @@ public class RegisterGroup extends VimRegisterGroupBase implements PersistentSta
 | 
			
		||||
          final String text = VimPlugin.getXML().getSafeXmlText(textElement);
 | 
			
		||||
          if (text != null) {
 | 
			
		||||
            logger.trace("Register data parsed");
 | 
			
		||||
            register = new Register(key, injector.getClipboardManager().dumbCopiedText(text), type);
 | 
			
		||||
            register = new Register(key, type, text, Collections.emptyList());
 | 
			
		||||
          }
 | 
			
		||||
          else {
 | 
			
		||||
            logger.trace("Cannot parse register data");
 | 
			
		||||
 
 | 
			
		||||
@@ -36,7 +36,6 @@ import com.maddyhome.idea.vim.helper.moveToInlayAwareOffset
 | 
			
		||||
import com.maddyhome.idea.vim.ide.isClionNova
 | 
			
		||||
import com.maddyhome.idea.vim.mark.VimMarkConstants.MARK_CHANGE_POS
 | 
			
		||||
import com.maddyhome.idea.vim.newapi.IjVimCaret
 | 
			
		||||
import com.maddyhome.idea.vim.newapi.IjVimCopiedText
 | 
			
		||||
import com.maddyhome.idea.vim.newapi.IjVimEditor
 | 
			
		||||
import com.maddyhome.idea.vim.newapi.ij
 | 
			
		||||
import com.maddyhome.idea.vim.newapi.vim
 | 
			
		||||
@@ -127,7 +126,7 @@ internal class PutGroup : VimPutBase() {
 | 
			
		||||
      point.dispose()
 | 
			
		||||
      if (!caret.isValid) return@forEach
 | 
			
		||||
 | 
			
		||||
      val caretPossibleEndOffset = lastPastedRegion?.endOffset ?: (startOffset + text.copiedText.text.length)
 | 
			
		||||
      val caretPossibleEndOffset = lastPastedRegion?.endOffset ?: (startOffset + text.text.length)
 | 
			
		||||
      val endOffset = if (data.indent) {
 | 
			
		||||
        doIndent(
 | 
			
		||||
          vimEditor,
 | 
			
		||||
@@ -179,9 +178,11 @@ internal class PutGroup : VimPutBase() {
 | 
			
		||||
    val allContentsBefore = CopyPasteManager.getInstance().allContents
 | 
			
		||||
    val sizeBeforeInsert = allContentsBefore.size
 | 
			
		||||
    val firstItemBefore = allContentsBefore.firstOrNull()
 | 
			
		||||
    logger.debug { "Copied text: ${text.copiedText}" }
 | 
			
		||||
    val (textContent, transferableData) = text.copiedText as IjVimCopiedText
 | 
			
		||||
    val origContent: TextBlockTransferable = injector.clipboardManager.setClipboardText(textContent, textContent, transferableData) as TextBlockTransferable
 | 
			
		||||
    logger.debug { "Transferable classes: ${text.transferableData.joinToString { it.javaClass.name }}" }
 | 
			
		||||
    val origContent: TextBlockTransferable = injector.clipboardManager.setClipboardText(
 | 
			
		||||
      text.text,
 | 
			
		||||
      transferableData = text.transferableData,
 | 
			
		||||
    ) as TextBlockTransferable
 | 
			
		||||
    val allContentsAfter = CopyPasteManager.getInstance().allContents
 | 
			
		||||
    val sizeAfterInsert = allContentsAfter.size
 | 
			
		||||
    try {
 | 
			
		||||
@@ -189,7 +190,7 @@ internal class PutGroup : VimPutBase() {
 | 
			
		||||
    } finally {
 | 
			
		||||
      val textInClipboard = (firstItemBefore as? TextBlockTransferable)
 | 
			
		||||
        ?.getTransferData(DataFlavor.stringFlavor) as? String
 | 
			
		||||
      val textOnTop = textInClipboard != null && textInClipboard != text.copiedText.text
 | 
			
		||||
      val textOnTop = textInClipboard != null && textInClipboard != text.text
 | 
			
		||||
      if (sizeBeforeInsert != sizeAfterInsert || textOnTop) {
 | 
			
		||||
        // Sometimes an inserted text replaces an existing one. E.g. on insert with + or * register
 | 
			
		||||
        (CopyPasteManager.getInstance() as? CopyPasteManagerEx)?.run { removeContent(origContent) }
 | 
			
		||||
 
 | 
			
		||||
@@ -339,7 +339,7 @@ public class EditorHelper {
 | 
			
		||||
 | 
			
		||||
    final int offset = y - ((screenHeight - lineHeight) / lineHeight / 2 * lineHeight);
 | 
			
		||||
    final @NotNull VimEditor editor1 = new IjVimEditor(editor);
 | 
			
		||||
    final int lastVisualLine = EngineEditorHelperKt.getVisualLineCount(editor1) - 1;
 | 
			
		||||
    final int lastVisualLine = EngineEditorHelperKt.getVisualLineCount(editor1) + editor.getSettings().getAdditionalLinesCount();
 | 
			
		||||
    final int offsetForLastLineAtBottom = getOffsetToScrollVisualLineToBottomOfScreen(editor, lastVisualLine);
 | 
			
		||||
 | 
			
		||||
    // For `zz`, we want to use virtual space and move any line, including the last one, to the middle of the screen.
 | 
			
		||||
 
 | 
			
		||||
@@ -12,6 +12,7 @@ package com.maddyhome.idea.vim.helper
 | 
			
		||||
 | 
			
		||||
import com.intellij.codeWithMe.ClientId
 | 
			
		||||
import com.intellij.openapi.editor.Caret
 | 
			
		||||
import com.intellij.openapi.editor.CaretState
 | 
			
		||||
import com.intellij.openapi.editor.Editor
 | 
			
		||||
import com.intellij.openapi.editor.ex.util.EditorUtil
 | 
			
		||||
import com.intellij.openapi.fileEditor.ex.FileEditorManagerEx
 | 
			
		||||
@@ -20,6 +21,8 @@ import com.maddyhome.idea.vim.api.StringListOptionValue
 | 
			
		||||
import com.maddyhome.idea.vim.api.injector
 | 
			
		||||
import com.maddyhome.idea.vim.group.IjOptionConstants
 | 
			
		||||
import com.maddyhome.idea.vim.newapi.globalIjOptions
 | 
			
		||||
import com.maddyhome.idea.vim.newapi.vim
 | 
			
		||||
import com.maddyhome.idea.vim.state.mode.inBlockSelection
 | 
			
		||||
import java.awt.Component
 | 
			
		||||
import javax.swing.JComponent
 | 
			
		||||
import javax.swing.JTable
 | 
			
		||||
@@ -96,3 +99,41 @@ internal val Caret.vimLine: Int
 | 
			
		||||
 */
 | 
			
		||||
internal val Editor.vimLine: Int
 | 
			
		||||
  get() = this.caretModel.currentCaret.vimLine
 | 
			
		||||
 | 
			
		||||
internal inline fun Editor.runWithEveryCaretAndRestore(action: () -> Unit) {
 | 
			
		||||
  val caretModel = this.caretModel
 | 
			
		||||
  val carets = if (this.vim.inBlockSelection) null else caretModel.allCarets
 | 
			
		||||
  if (carets == null || carets.size == 1) {
 | 
			
		||||
    action()
 | 
			
		||||
  }
 | 
			
		||||
  else {
 | 
			
		||||
    var initialDocumentSize = this.document.textLength
 | 
			
		||||
    var documentSizeDifference = 0
 | 
			
		||||
 | 
			
		||||
    val caretOffsets = carets.map { it.selectionStart to it.selectionEnd }
 | 
			
		||||
    val restoredCarets = mutableListOf<CaretState>()
 | 
			
		||||
 | 
			
		||||
    caretModel.removeSecondaryCarets()
 | 
			
		||||
    
 | 
			
		||||
    for ((selectionStart, selectionEnd) in caretOffsets) {
 | 
			
		||||
      if (selectionStart == selectionEnd) {
 | 
			
		||||
        caretModel.primaryCaret.moveToOffset(selectionStart + documentSizeDifference)
 | 
			
		||||
      }
 | 
			
		||||
      else {
 | 
			
		||||
        caretModel.primaryCaret.setSelection(
 | 
			
		||||
          selectionStart + documentSizeDifference,
 | 
			
		||||
          selectionEnd + documentSizeDifference
 | 
			
		||||
        )
 | 
			
		||||
      }
 | 
			
		||||
      
 | 
			
		||||
      action()
 | 
			
		||||
      restoredCarets.add(caretModel.caretsAndSelections.single())
 | 
			
		||||
 | 
			
		||||
      val documentLength = this.document.textLength
 | 
			
		||||
      documentSizeDifference += documentLength - initialDocumentSize
 | 
			
		||||
      initialDocumentSize = documentLength
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    caretModel.caretsAndSelections = restoredCarets
 | 
			
		||||
  } 
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -20,6 +20,7 @@ import com.intellij.openapi.actionSystem.PlatformDataKeys
 | 
			
		||||
import com.intellij.openapi.actionSystem.ex.ActionUtil
 | 
			
		||||
import com.intellij.openapi.actionSystem.ex.ActionUtil.performDumbAwareWithCallbacks
 | 
			
		||||
import com.intellij.openapi.actionSystem.impl.ProxyShortcutSet
 | 
			
		||||
import com.intellij.openapi.actionSystem.impl.Utils
 | 
			
		||||
import com.intellij.openapi.application.ex.ApplicationManagerEx
 | 
			
		||||
import com.intellij.openapi.command.CommandProcessor
 | 
			
		||||
import com.intellij.openapi.command.UndoConfirmationPolicy
 | 
			
		||||
@@ -95,6 +96,7 @@ internal class IjActionExecutor : VimActionExecutor {
 | 
			
		||||
      ActionManager.getInstance(),
 | 
			
		||||
      0,
 | 
			
		||||
    )
 | 
			
		||||
    Utils.initUpdateSession(event)
 | 
			
		||||
    // beforeActionPerformedUpdate should be called to update the action. It fixes some rider-specific problems.
 | 
			
		||||
    //   because rider use async update method. See VIM-1819.
 | 
			
		||||
    // This method executes inside of lastUpdateAndCheckDumb
 | 
			
		||||
 
 | 
			
		||||
@@ -59,7 +59,7 @@ internal object ScrollViewHelper {
 | 
			
		||||
    // that this needs to be replaced as a more or less dumb line for line rewrite.
 | 
			
		||||
    val topLine = getVisualLineAtTopOfScreen(editor)
 | 
			
		||||
    val bottomLine = getVisualLineAtBottomOfScreen(editor)
 | 
			
		||||
    val lastLine = vimEditor.getVisualLineCount() - 1
 | 
			
		||||
    val lastLine = vimEditor.getVisualLineCount() + editor.settings.additionalLinesCount
 | 
			
		||||
 | 
			
		||||
    // We need the non-normalised value here, so we can handle cases such as so=999 to keep the current line centred
 | 
			
		||||
    val scrollOffset = injector.options(vimEditor).scrolloff
 | 
			
		||||
 
 | 
			
		||||
@@ -30,6 +30,8 @@ import com.maddyhome.idea.vim.common.InsertSequence
 | 
			
		||||
import com.maddyhome.idea.vim.newapi.IjVimCaret
 | 
			
		||||
import com.maddyhome.idea.vim.newapi.globalIjOptions
 | 
			
		||||
import com.maddyhome.idea.vim.newapi.ij
 | 
			
		||||
import com.maddyhome.idea.vim.state.mode.SelectionType
 | 
			
		||||
import com.maddyhome.idea.vim.state.mode.inVisualMode
 | 
			
		||||
import com.maddyhome.idea.vim.undo.VimTimestampBasedUndoService
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
@@ -77,15 +79,7 @@ internal class UndoRedoHelper : VimTimestampBasedUndoService {
 | 
			
		||||
      // TODO refactor me after VIM-308 when restoring selection and caret movement will be ignored by undo
 | 
			
		||||
      editor.runWithChangeTracking {
 | 
			
		||||
        undoManager.undo(fileEditor)
 | 
			
		||||
 | 
			
		||||
        // We execute undo one more time if the previous one just restored selection
 | 
			
		||||
        if (!hasChanges && hasSelection(editor) && undoManager.isUndoAvailable(fileEditor)) {
 | 
			
		||||
          undoManager.undo(fileEditor)
 | 
			
		||||
        }
 | 
			
		||||
      }
 | 
			
		||||
 | 
			
		||||
      CommandProcessor.getInstance().runUndoTransparentAction {
 | 
			
		||||
        removeSelections(editor)
 | 
			
		||||
        restoreVisualMode(editor)
 | 
			
		||||
      }
 | 
			
		||||
    } else {
 | 
			
		||||
      notifyAboutNewUndo(editor.ij.project)
 | 
			
		||||
@@ -119,7 +113,7 @@ internal class UndoRedoHelper : VimTimestampBasedUndoService {
 | 
			
		||||
  private fun hasSelection(editor: VimEditor): Boolean {
 | 
			
		||||
    return editor.primaryCaret().ij.hasSelection()
 | 
			
		||||
  }
 | 
			
		||||
  
 | 
			
		||||
 | 
			
		||||
  override fun redo(editor: VimEditor, context: ExecutionContext): Boolean {
 | 
			
		||||
    val ijContext = context.context as DataContext
 | 
			
		||||
    val project = PlatformDataKeys.PROJECT.getData(ijContext) ?: return false
 | 
			
		||||
@@ -240,4 +234,21 @@ internal class UndoRedoHelper : VimTimestampBasedUndoService {
 | 
			
		||||
    val hasChanges: Boolean
 | 
			
		||||
      get() = changeListener.hasChanged || initialPath != editor.getPath()
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  private fun restoreVisualMode(editor: VimEditor) {
 | 
			
		||||
    if (!editor.inVisualMode && editor.getSelectionModel().hasSelection()) {
 | 
			
		||||
      val detectedMode = VimPlugin.getVisualMotion().autodetectVisualSubmode(editor)
 | 
			
		||||
 | 
			
		||||
      // Visual block selection is restored into multiple carets, so multi-carets that form a block are always
 | 
			
		||||
      // identified as visual block mode, leading to false positives.
 | 
			
		||||
      // Since I use visual block mode much less often than multi-carets, this is a judgment call to never restore
 | 
			
		||||
      // visual block mode.
 | 
			
		||||
      val wantedMode = if (detectedMode == SelectionType.BLOCK_WISE)
 | 
			
		||||
        SelectionType.CHARACTER_WISE
 | 
			
		||||
      else
 | 
			
		||||
        detectedMode
 | 
			
		||||
 | 
			
		||||
      VimPlugin.getVisualMotion().enterVisualMode(editor, wantedMode)
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -18,7 +18,6 @@ import com.intellij.openapi.editor.VisualPosition
 | 
			
		||||
import com.intellij.openapi.editor.markup.RangeHighlighter
 | 
			
		||||
import com.intellij.openapi.util.Key
 | 
			
		||||
import com.intellij.openapi.util.UserDataHolder
 | 
			
		||||
import com.maddyhome.idea.vim.api.CaretRegisterStorageBase
 | 
			
		||||
import com.maddyhome.idea.vim.api.LocalMarkStorage
 | 
			
		||||
import com.maddyhome.idea.vim.api.SelectionInfo
 | 
			
		||||
import com.maddyhome.idea.vim.common.InsertSequence
 | 
			
		||||
@@ -96,7 +95,6 @@ internal var Caret.vimInsertStart: RangeMarker by userDataOr {
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// TODO: Data could be lost during visual block motion
 | 
			
		||||
internal var Caret.registerStorage: CaretRegisterStorageBase? by userDataCaretToEditor()
 | 
			
		||||
internal var Caret.markStorage: LocalMarkStorage? by userDataCaretToEditor()
 | 
			
		||||
internal var Caret.lastSelectionInfo: SelectionInfo? by userDataCaretToEditor()
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -1,32 +0,0 @@
 | 
			
		||||
/*
 | 
			
		||||
 * Copyright 2003-2023 The IdeaVim authors
 | 
			
		||||
 *
 | 
			
		||||
 * Use of this source code is governed by an MIT-style
 | 
			
		||||
 * license that can be found in the LICENSE.txt file or at
 | 
			
		||||
 * https://opensource.org/licenses/MIT.
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
package com.maddyhome.idea.vim.helper
 | 
			
		||||
 | 
			
		||||
import com.intellij.ide.plugins.StandalonePluginUpdateChecker
 | 
			
		||||
import com.intellij.openapi.components.Service
 | 
			
		||||
import com.intellij.openapi.components.service
 | 
			
		||||
import com.maddyhome.idea.vim.VimPlugin
 | 
			
		||||
import com.maddyhome.idea.vim.group.NotificationService
 | 
			
		||||
import com.maddyhome.idea.vim.icons.VimIcons
 | 
			
		||||
 | 
			
		||||
@Service(Service.Level.APP)
 | 
			
		||||
internal class VimStandalonePluginUpdateChecker : StandalonePluginUpdateChecker(
 | 
			
		||||
  VimPlugin.getPluginId(),
 | 
			
		||||
  updateTimestampProperty = PROPERTY_NAME,
 | 
			
		||||
  NotificationService.IDEAVIM_STICKY_GROUP,
 | 
			
		||||
  VimIcons.IDEAVIM,
 | 
			
		||||
) {
 | 
			
		||||
 | 
			
		||||
  override fun skipUpdateCheck(): Boolean = VimPlugin.isNotEnabled() || "dev" in VimPlugin.getVersion()
 | 
			
		||||
 | 
			
		||||
  companion object {
 | 
			
		||||
    private const val PROPERTY_NAME = "ideavim.statistics.timestamp"
 | 
			
		||||
    fun getInstance(): VimStandalonePluginUpdateChecker = service()
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
@@ -10,15 +10,12 @@ package com.maddyhome.idea.vim.listener
 | 
			
		||||
 | 
			
		||||
import com.intellij.execution.impl.ConsoleViewImpl
 | 
			
		||||
import com.intellij.openapi.application.ApplicationManager
 | 
			
		||||
import com.intellij.openapi.editor.Editor
 | 
			
		||||
import com.intellij.openapi.editor.EditorKind
 | 
			
		||||
import com.maddyhome.idea.vim.KeyHandler
 | 
			
		||||
import com.maddyhome.idea.vim.VimPlugin
 | 
			
		||||
import com.maddyhome.idea.vim.api.ExecutionContext
 | 
			
		||||
import com.maddyhome.idea.vim.api.VimEditor
 | 
			
		||||
import com.maddyhome.idea.vim.api.injector
 | 
			
		||||
import com.maddyhome.idea.vim.common.EditorListener
 | 
			
		||||
import com.maddyhome.idea.vim.helper.EditorHelper
 | 
			
		||||
import com.maddyhome.idea.vim.helper.inInsertMode
 | 
			
		||||
import com.maddyhome.idea.vim.newapi.ij
 | 
			
		||||
import com.maddyhome.idea.vim.state.mode.Mode
 | 
			
		||||
@@ -31,8 +28,8 @@ import com.maddyhome.idea.vim.state.mode.Mode
 | 
			
		||||
 */
 | 
			
		||||
class IJEditorFocusListener : EditorListener {
 | 
			
		||||
  override fun focusGained(editor: VimEditor) {
 | 
			
		||||
    val oldEditor = KeyHandler.getInstance().editorInFocus
 | 
			
		||||
    if (oldEditor != null && oldEditor.ij == editor.ij) return
 | 
			
		||||
    val editorInFocus = KeyHandler.getInstance().editorInFocus
 | 
			
		||||
    if (editorInFocus != null && editorInFocus.ij == editor.ij) return
 | 
			
		||||
 | 
			
		||||
    KeyHandler.getInstance().editorInFocus = editor
 | 
			
		||||
 | 
			
		||||
@@ -63,9 +60,7 @@ class IJEditorFocusListener : EditorListener {
 | 
			
		||||
      val context: ExecutionContext = injector.executionContextManager.getEditorExecutionContext(editor)
 | 
			
		||||
      VimPlugin.getChange().insertBeforeCursor(editor, context)
 | 
			
		||||
    }
 | 
			
		||||
    if (isTerminal(ijEditor) && !ijEditor.inInsertMode) {
 | 
			
		||||
      switchToInsertMode.run()
 | 
			
		||||
    } else if (ijEditor.isInsertMode && ((oldEditor != null && isTerminal(oldEditor.ij)) || !ijEditor.document.isWritable)) {
 | 
			
		||||
    if (!ijEditor.document.isWritable) {
 | 
			
		||||
      val context: ExecutionContext = injector.executionContextManager.getEditorExecutionContext(editor)
 | 
			
		||||
      val mode = injector.vimState.mode
 | 
			
		||||
      when (mode) {
 | 
			
		||||
@@ -82,12 +77,5 @@ class IJEditorFocusListener : EditorListener {
 | 
			
		||||
    }
 | 
			
		||||
    KeyHandler.getInstance().reset(editor)
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  // By "terminal" we refer to some editor that should switch to INSERT mode on focus
 | 
			
		||||
  private fun isTerminal(ijEditor: Editor): Boolean {
 | 
			
		||||
    return !ijEditor.isViewer &&
 | 
			
		||||
      !EditorHelper.isFileEditor(ijEditor) &&
 | 
			
		||||
      ijEditor.document.isWritable &&
 | 
			
		||||
      ijEditor.editorKind != EditorKind.DIFF
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -16,7 +16,9 @@ import com.intellij.codeInsight.lookup.impl.actions.ChooseItemAction
 | 
			
		||||
import com.intellij.codeInsight.template.Template
 | 
			
		||||
import com.intellij.codeInsight.template.TemplateEditingAdapter
 | 
			
		||||
import com.intellij.codeInsight.template.TemplateManagerListener
 | 
			
		||||
import com.intellij.codeInsight.template.impl.TemplateManagerImpl
 | 
			
		||||
import com.intellij.codeInsight.template.impl.TemplateState
 | 
			
		||||
import com.intellij.codeInsight.template.impl.actions.NextVariableAction
 | 
			
		||||
import com.intellij.find.FindModelListener
 | 
			
		||||
import com.intellij.openapi.actionSystem.ActionManager
 | 
			
		||||
import com.intellij.openapi.actionSystem.ActionUpdateThread
 | 
			
		||||
@@ -28,6 +30,7 @@ import com.intellij.openapi.actionSystem.CommonDataKeys
 | 
			
		||||
import com.intellij.openapi.actionSystem.ex.AnActionListener
 | 
			
		||||
import com.intellij.openapi.actionSystem.impl.ProxyShortcutSet
 | 
			
		||||
import com.intellij.openapi.editor.Editor
 | 
			
		||||
import com.intellij.openapi.editor.impl.ScrollingModelImpl
 | 
			
		||||
import com.intellij.openapi.keymap.KeymapManager
 | 
			
		||||
import com.intellij.openapi.project.DumbAwareToggleAction
 | 
			
		||||
import com.intellij.openapi.util.TextRange
 | 
			
		||||
@@ -58,6 +61,7 @@ internal object IdeaSpecifics {
 | 
			
		||||
    private val surrounderAction =
 | 
			
		||||
      "com.intellij.codeInsight.generation.surroundWith.SurroundWithHandler\$InvokeSurrounderAction"
 | 
			
		||||
    private var editor: Editor? = null
 | 
			
		||||
    private var caretOffset = -1
 | 
			
		||||
    private var completionPrevDocumentLength: Int? = null
 | 
			
		||||
    private var completionPrevDocumentOffset: Int? = null
 | 
			
		||||
 | 
			
		||||
@@ -67,6 +71,7 @@ internal object IdeaSpecifics {
 | 
			
		||||
      val hostEditor = event.dataContext.getData(CommonDataKeys.HOST_EDITOR)
 | 
			
		||||
      if (hostEditor != null) {
 | 
			
		||||
        editor = hostEditor
 | 
			
		||||
        caretOffset = hostEditor.caretModel.offset
 | 
			
		||||
      }
 | 
			
		||||
 | 
			
		||||
      val isVimAction = (action as? AnActionWrapper)?.delegate is VimShortcutKeyAction
 | 
			
		||||
@@ -115,42 +120,61 @@ internal object IdeaSpecifics {
 | 
			
		||||
      if (VimPlugin.isNotEnabled()) return
 | 
			
		||||
 | 
			
		||||
      val editor = editor
 | 
			
		||||
      if (editor != null && action is ChooseItemAction && injector.registerGroup.isRecording) {
 | 
			
		||||
        val prevDocumentLength = completionPrevDocumentLength
 | 
			
		||||
        val prevDocumentOffset = completionPrevDocumentOffset
 | 
			
		||||
      if (editor != null) {
 | 
			
		||||
        if (action is ChooseItemAction && injector.registerGroup.isRecording) {
 | 
			
		||||
          val prevDocumentLength = completionPrevDocumentLength
 | 
			
		||||
          val prevDocumentOffset = completionPrevDocumentOffset
 | 
			
		||||
 | 
			
		||||
        if (prevDocumentLength != null && prevDocumentOffset != null) {
 | 
			
		||||
          val register = VimPlugin.getRegister()
 | 
			
		||||
          val addedTextLength = editor.document.textLength - prevDocumentLength
 | 
			
		||||
          val caretShift = addedTextLength - (editor.caretModel.primaryCaret.offset - prevDocumentOffset)
 | 
			
		||||
          val leftArrow = KeyStroke.getKeyStroke(KeyEvent.VK_LEFT, 0)
 | 
			
		||||
          if (prevDocumentLength != null && prevDocumentOffset != null) {
 | 
			
		||||
            val register = VimPlugin.getRegister()
 | 
			
		||||
            val addedTextLength = editor.document.textLength - prevDocumentLength
 | 
			
		||||
            val caretShift = addedTextLength - (editor.caretModel.primaryCaret.offset - prevDocumentOffset)
 | 
			
		||||
            val leftArrow = KeyStroke.getKeyStroke(KeyEvent.VK_LEFT, 0)
 | 
			
		||||
 | 
			
		||||
          register.recordText(editor.document.getText(TextRange(prevDocumentOffset, prevDocumentOffset + addedTextLength)))
 | 
			
		||||
          repeat(caretShift.coerceAtLeast(0)) {
 | 
			
		||||
            register.recordKeyStroke(leftArrow)
 | 
			
		||||
            register.recordText(editor.document.getText(TextRange(prevDocumentOffset, prevDocumentOffset + addedTextLength)))
 | 
			
		||||
            repeat(caretShift.coerceAtLeast(0)) {
 | 
			
		||||
              register.recordKeyStroke(leftArrow)
 | 
			
		||||
            }
 | 
			
		||||
          }
 | 
			
		||||
 | 
			
		||||
          this.completionPrevDocumentLength = null
 | 
			
		||||
          this.completionPrevDocumentOffset = null
 | 
			
		||||
        }
 | 
			
		||||
        
 | 
			
		||||
        //region Enter insert mode after surround with if
 | 
			
		||||
        if (surrounderAction == action.javaClass.name && surrounderItems.any {
 | 
			
		||||
            action.templatePresentation.text.endsWith(
 | 
			
		||||
              it,
 | 
			
		||||
            )
 | 
			
		||||
          }
 | 
			
		||||
        ) {
 | 
			
		||||
          editor?.let {
 | 
			
		||||
            it.vim.mode = Mode.NORMAL()
 | 
			
		||||
            VimPlugin.getChange().insertBeforeCursor(it.vim, event.dataContext.vim)
 | 
			
		||||
            KeyHandler.getInstance().reset(it.vim)
 | 
			
		||||
          }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        this.completionPrevDocumentLength = null
 | 
			
		||||
        this.completionPrevDocumentOffset = null
 | 
			
		||||
      }
 | 
			
		||||
 | 
			
		||||
      //region Enter insert mode after surround with if
 | 
			
		||||
      if (surrounderAction == action.javaClass.name && surrounderItems.any {
 | 
			
		||||
          action.templatePresentation.text.endsWith(
 | 
			
		||||
            it,
 | 
			
		||||
          )
 | 
			
		||||
        else if (action is NextVariableAction && TemplateManagerImpl.getTemplateState(editor) == null) {
 | 
			
		||||
          editor.vim.exitInsertMode(event.dataContext.vim)
 | 
			
		||||
          KeyHandler.getInstance().reset(editor.vim)
 | 
			
		||||
        }
 | 
			
		||||
      ) {
 | 
			
		||||
        editor?.let {
 | 
			
		||||
          it.vim.mode = Mode.NORMAL()
 | 
			
		||||
          VimPlugin.getChange().insertBeforeCursor(it.vim, event.dataContext.vim)
 | 
			
		||||
          KeyHandler.getInstance().reset(it.vim)
 | 
			
		||||
        //endregion
 | 
			
		||||
 | 
			
		||||
        if (caretOffset != -1 && caretOffset != editor.caretModel.offset) {
 | 
			
		||||
          val scrollModel = editor.scrollingModel as ScrollingModelImpl
 | 
			
		||||
          if (scrollModel.isScrollingNow) {
 | 
			
		||||
            val v = scrollModel.verticalScrollOffset
 | 
			
		||||
            val h = scrollModel.horizontalScrollOffset
 | 
			
		||||
            scrollModel.finishAnimation()
 | 
			
		||||
            scrollModel.scroll(h, v)
 | 
			
		||||
            scrollModel.finishAnimation()
 | 
			
		||||
          }
 | 
			
		||||
          injector.scroll.scrollCaretIntoView(editor.vim)
 | 
			
		||||
        }
 | 
			
		||||
      }
 | 
			
		||||
      //endregion
 | 
			
		||||
 | 
			
		||||
      this.editor = null
 | 
			
		||||
      this.caretOffset = -1
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -81,7 +81,6 @@ import com.maddyhome.idea.vim.handler.keyCheckRequests
 | 
			
		||||
import com.maddyhome.idea.vim.helper.CaretVisualAttributesListener
 | 
			
		||||
import com.maddyhome.idea.vim.helper.GuicursorChangeListener
 | 
			
		||||
import com.maddyhome.idea.vim.helper.StrictMode
 | 
			
		||||
import com.maddyhome.idea.vim.helper.VimStandalonePluginUpdateChecker
 | 
			
		||||
import com.maddyhome.idea.vim.helper.exitSelectMode
 | 
			
		||||
import com.maddyhome.idea.vim.helper.exitVisualMode
 | 
			
		||||
import com.maddyhome.idea.vim.helper.forceBarCursor
 | 
			
		||||
@@ -97,6 +96,7 @@ import com.maddyhome.idea.vim.newapi.IjVimSearchGroup
 | 
			
		||||
import com.maddyhome.idea.vim.newapi.InsertTimeRecorder
 | 
			
		||||
import com.maddyhome.idea.vim.newapi.ij
 | 
			
		||||
import com.maddyhome.idea.vim.newapi.vim
 | 
			
		||||
import com.maddyhome.idea.vim.state.mode.Mode
 | 
			
		||||
import com.maddyhome.idea.vim.state.mode.inSelectMode
 | 
			
		||||
import com.maddyhome.idea.vim.state.mode.selectionType
 | 
			
		||||
import com.maddyhome.idea.vim.ui.ShowCmdOptionChangeListener
 | 
			
		||||
@@ -399,7 +399,18 @@ internal object VimListenerManager {
 | 
			
		||||
    override fun selectionChanged(event: FileEditorManagerEvent) {
 | 
			
		||||
      // We can't rely on being passed a non-null editor, so check for Code With Me scenarios explicitly
 | 
			
		||||
      if (VimPlugin.isNotEnabled() || !ClientId.isCurrentlyUnderLocalId) return
 | 
			
		||||
 | 
			
		||||
      
 | 
			
		||||
      val newEditor = event.newEditor
 | 
			
		||||
      if (newEditor is TextEditor) {
 | 
			
		||||
        val editor = newEditor.editor
 | 
			
		||||
        if (editor.isInsertMode) {
 | 
			
		||||
          editor.vim.mode = Mode.NORMAL()
 | 
			
		||||
          KeyHandler.getInstance().reset(editor.vim)
 | 
			
		||||
        }
 | 
			
		||||
        // Breaks relativenumber for some reason
 | 
			
		||||
//        injector.scroll.scrollCaretIntoView(editor.vim)
 | 
			
		||||
      }
 | 
			
		||||
      
 | 
			
		||||
      MotionGroup.fileEditorManagerSelectionChangedCallback(event)
 | 
			
		||||
      FileGroup.fileEditorManagerSelectionChangedCallback(event)
 | 
			
		||||
      VimPlugin.getSearch().fileEditorManagerSelectionChangedCallback(event)
 | 
			
		||||
@@ -471,8 +482,6 @@ internal object VimListenerManager {
 | 
			
		||||
 | 
			
		||||
        event.editor.putUserData(openingEditorKey, OpeningEditor(openingEditor, owningEditorWindow, isPreview, canBeReused))
 | 
			
		||||
      }
 | 
			
		||||
 | 
			
		||||
      VimStandalonePluginUpdateChecker.getInstance().pluginUsed()
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    override fun editorReleased(event: EditorFactoryEvent) {
 | 
			
		||||
 
 | 
			
		||||
@@ -12,8 +12,6 @@ import com.intellij.openapi.editor.Caret
 | 
			
		||||
import com.intellij.openapi.editor.LogicalPosition
 | 
			
		||||
import com.intellij.openapi.editor.VisualPosition
 | 
			
		||||
import com.maddyhome.idea.vim.api.BufferPosition
 | 
			
		||||
import com.maddyhome.idea.vim.api.CaretRegisterStorage
 | 
			
		||||
import com.maddyhome.idea.vim.api.CaretRegisterStorageBase
 | 
			
		||||
import com.maddyhome.idea.vim.api.ImmutableVimCaret
 | 
			
		||||
import com.maddyhome.idea.vim.api.LocalMarkStorage
 | 
			
		||||
import com.maddyhome.idea.vim.api.SelectionInfo
 | 
			
		||||
@@ -21,6 +19,7 @@ import com.maddyhome.idea.vim.api.VimCaret
 | 
			
		||||
import com.maddyhome.idea.vim.api.VimCaretBase
 | 
			
		||||
import com.maddyhome.idea.vim.api.VimEditor
 | 
			
		||||
import com.maddyhome.idea.vim.api.VimVisualPosition
 | 
			
		||||
import com.maddyhome.idea.vim.api.injector
 | 
			
		||||
import com.maddyhome.idea.vim.common.InsertSequence
 | 
			
		||||
import com.maddyhome.idea.vim.common.LiveRange
 | 
			
		||||
import com.maddyhome.idea.vim.group.visual.VisualChange
 | 
			
		||||
@@ -29,7 +28,6 @@ import com.maddyhome.idea.vim.helper.insertHistory
 | 
			
		||||
import com.maddyhome.idea.vim.helper.lastSelectionInfo
 | 
			
		||||
import com.maddyhome.idea.vim.helper.markStorage
 | 
			
		||||
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
 | 
			
		||||
@@ -37,22 +35,14 @@ import com.maddyhome.idea.vim.helper.vimLastVisualOperatorRange
 | 
			
		||||
import com.maddyhome.idea.vim.helper.vimLine
 | 
			
		||||
import com.maddyhome.idea.vim.helper.vimSelectionStart
 | 
			
		||||
import com.maddyhome.idea.vim.helper.vimSelectionStartClear
 | 
			
		||||
import com.maddyhome.idea.vim.register.VimRegisterGroup
 | 
			
		||||
import com.maddyhome.idea.vim.state.mode.SelectionType
 | 
			
		||||
 | 
			
		||||
internal class IjVimCaret(val caret: Caret) : VimCaretBase() {
 | 
			
		||||
 | 
			
		||||
  override val registerStorage: CaretRegisterStorage
 | 
			
		||||
    get() {
 | 
			
		||||
      var storage = this.caret.registerStorage
 | 
			
		||||
      if (storage == null) {
 | 
			
		||||
        initInjector() // To initialize injector used in CaretRegisterStorageBase
 | 
			
		||||
        storage = CaretRegisterStorageBase(this)
 | 
			
		||||
        this.caret.registerStorage = storage
 | 
			
		||||
      } else if (storage.caret != this) {
 | 
			
		||||
        storage.caret = this
 | 
			
		||||
      }
 | 
			
		||||
      return storage
 | 
			
		||||
    }
 | 
			
		||||
  override val registerStorage: VimRegisterGroup
 | 
			
		||||
    get() = injector.registerGroup
 | 
			
		||||
 
 | 
			
		||||
  override val markStorage: LocalMarkStorage
 | 
			
		||||
    get() {
 | 
			
		||||
      var storage = this.caret.markStorage
 | 
			
		||||
 
 | 
			
		||||
@@ -179,21 +179,38 @@ internal class IjVimEditor(editor: Editor) : MutableLinearEditor, VimEditorBase(
 | 
			
		||||
    return editor.caretModel.allCarets.map { IjVimCaret(it) }
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  override var isFirstCaret = true
 | 
			
		||||
  override var isReversingCarets = false
 | 
			
		||||
  
 | 
			
		||||
  @Suppress("ideavimRunForEachCaret")
 | 
			
		||||
  override fun forEachCaret(action: (VimCaret) -> Unit) {
 | 
			
		||||
    if (editor.vim.inBlockSelection) {
 | 
			
		||||
      action(IjVimCaret(editor.caretModel.primaryCaret))
 | 
			
		||||
    } else {
 | 
			
		||||
      editor.caretModel.runForEachCaret({
 | 
			
		||||
        if (it.isValid) {
 | 
			
		||||
          action(IjVimCaret(it))
 | 
			
		||||
        }
 | 
			
		||||
      }, false)
 | 
			
		||||
      try {
 | 
			
		||||
        editor.caretModel.runForEachCaret({
 | 
			
		||||
          if (it.isValid) {
 | 
			
		||||
            action(IjVimCaret(it))
 | 
			
		||||
            isFirstCaret = false
 | 
			
		||||
          }
 | 
			
		||||
        }, false)
 | 
			
		||||
      } finally {
 | 
			
		||||
        isFirstCaret = true
 | 
			
		||||
      }
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  override fun forEachNativeCaret(action: (VimCaret) -> Unit, reverse: Boolean) {
 | 
			
		||||
    editor.caretModel.runForEachCaret({ action(IjVimCaret(it)) }, reverse)
 | 
			
		||||
    isReversingCarets = reverse
 | 
			
		||||
    try {
 | 
			
		||||
      editor.caretModel.runForEachCaret({
 | 
			
		||||
        action(IjVimCaret(it))
 | 
			
		||||
        isFirstCaret = false
 | 
			
		||||
      }, reverse)
 | 
			
		||||
    } finally {
 | 
			
		||||
      isFirstCaret = true
 | 
			
		||||
      isReversingCarets = false
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  override fun isInForEachCaretScope(): Boolean {
 | 
			
		||||
 
 | 
			
		||||
@@ -23,7 +23,10 @@ import com.maddyhome.idea.vim.EventFacade;
 | 
			
		||||
import com.maddyhome.idea.vim.KeyHandler;
 | 
			
		||||
import com.maddyhome.idea.vim.VimPlugin;
 | 
			
		||||
import com.maddyhome.idea.vim.action.VimShortcutKeyAction;
 | 
			
		||||
import com.maddyhome.idea.vim.api.*;
 | 
			
		||||
import com.maddyhome.idea.vim.api.VimCommandLine;
 | 
			
		||||
import com.maddyhome.idea.vim.api.VimCommandLineCaret;
 | 
			
		||||
import com.maddyhome.idea.vim.api.VimEditor;
 | 
			
		||||
import com.maddyhome.idea.vim.api.VimKeyGroupBase;
 | 
			
		||||
import com.maddyhome.idea.vim.ex.ranges.LineRange;
 | 
			
		||||
import com.maddyhome.idea.vim.helper.SearchHighlightsHelper;
 | 
			
		||||
import com.maddyhome.idea.vim.helper.UiHelper;
 | 
			
		||||
@@ -348,7 +351,7 @@ public class ExEntryPanel extends JPanel implements VimCommandLine {
 | 
			
		||||
        int count1 = Math.max(1, KeyHandler.getInstance().getKeyHandlerState().getEditorCommandBuilder()
 | 
			
		||||
          .calculateCount0Snapshot());
 | 
			
		||||
 | 
			
		||||
        if (labelText.equals("/") || labelText.equals("?") || searchCommand) {
 | 
			
		||||
        if ((labelText.equals("/") || labelText.equals("?") || searchCommand) && !injector.getMacro().isExecutingMacro()) {
 | 
			
		||||
          final boolean forwards = !labelText.equals("?");  // :s, :g, :v are treated as forwards
 | 
			
		||||
          int pattenEnd = injector.getSearchGroup().findEndOfPattern(searchText, separator, 0);
 | 
			
		||||
          final String pattern = searchText.substring(0, pattenEnd);
 | 
			
		||||
 
 | 
			
		||||
@@ -1,12 +1,4 @@
 | 
			
		||||
<!--
 | 
			
		||||
  ~ Copyright 2003-2023 The IdeaVim authors
 | 
			
		||||
  ~
 | 
			
		||||
  ~ Use of this source code is governed by an MIT-style
 | 
			
		||||
  ~ license that can be found in the LICENSE.txt file or at
 | 
			
		||||
  ~ https://opensource.org/licenses/MIT.
 | 
			
		||||
  -->
 | 
			
		||||
 | 
			
		||||
<idea-plugin url="https://plugins.jetbrains.com/plugin/164" xmlns:xi="http://www.w3.org/2001/XInclude">
 | 
			
		||||
<idea-plugin xmlns:xi="http://www.w3.org/2001/XInclude">
 | 
			
		||||
  <name>IdeaVim</name>
 | 
			
		||||
  <id>IdeaVIM</id>
 | 
			
		||||
  <description><![CDATA[
 | 
			
		||||
@@ -21,7 +13,7 @@
 | 
			
		||||
        <li><a href="https://youtrack.jetbrains.com/issues/VIM">Issue tracker</a>: feature requests and bug reports</li>
 | 
			
		||||
      </ul>
 | 
			
		||||
    ]]></description>
 | 
			
		||||
  <version>SNAPSHOT</version>
 | 
			
		||||
  <version>chylex</version>
 | 
			
		||||
  <vendor>JetBrains</vendor>
 | 
			
		||||
 | 
			
		||||
  <!-- Mark the plugin as compatible with RubyMine and other products based on the IntelliJ platform (including CWM) -->
 | 
			
		||||
@@ -135,10 +127,12 @@
 | 
			
		||||
  <xi:include href="/META-INF/includes/VimListeners.xml" xpointer="xpointer(/idea-plugin/*)"/>
 | 
			
		||||
 | 
			
		||||
  <actions resource-bundle="messages.IdeaVimBundle">
 | 
			
		||||
    <action id="VimPluginToggle" class="com.maddyhome.idea.vim.action.VimPluginToggleAction">
 | 
			
		||||
    <group id="com.chylex.intellij.vim" text="Vim" popup="true">
 | 
			
		||||
      <add-to-group group-id="ToolsMenu" anchor="last"/>
 | 
			
		||||
    </action>
 | 
			
		||||
 | 
			
		||||
      <action id="VimPluginToggle" class="com.maddyhome.idea.vim.action.VimPluginToggleAction"/>
 | 
			
		||||
      <action id="VimRunLastMacroInOpenFiles" class="com.maddyhome.idea.vim.action.VimRunLastMacroInOpenFiles"/>
 | 
			
		||||
    </group>
 | 
			
		||||
    
 | 
			
		||||
    <!-- Internal -->
 | 
			
		||||
    <!--suppress PluginXmlI18n -->
 | 
			
		||||
    <action id="VimInternalAddBlockInlays" class="com.maddyhome.idea.vim.action.internal.AddBlockInlaysAction" text="Add Test Block Inlays | IdeaVim Internal" internal="true"/>
 | 
			
		||||
@@ -156,5 +150,6 @@
 | 
			
		||||
    </group>
 | 
			
		||||
 | 
			
		||||
    <action id="VimFindActionIdAction" class="com.maddyhome.idea.vim.listener.FindActionIdAction"/>
 | 
			
		||||
    <action id="VimJumpToSource" class="com.intellij.diff.actions.impl.OpenInEditorAction" />
 | 
			
		||||
  </actions>
 | 
			
		||||
</idea-plugin>
 | 
			
		||||
 
 | 
			
		||||
@@ -9,6 +9,7 @@
 | 
			
		||||
package org.jetbrains.plugins.ideavim.ex.implementation.variables
 | 
			
		||||
 | 
			
		||||
import com.maddyhome.idea.vim.api.injector
 | 
			
		||||
import com.maddyhome.idea.vim.newapi.vim
 | 
			
		||||
import org.jetbrains.plugins.ideavim.VimTestCase
 | 
			
		||||
import org.junit.jupiter.api.Test
 | 
			
		||||
import kotlin.test.assertEquals
 | 
			
		||||
@@ -43,10 +44,12 @@ class RegisterVariableTest : VimTestCase() {
 | 
			
		||||
    configureByText("abcd")
 | 
			
		||||
    enterCommand("""vnoremap <expr> y '"' . v:register . 'y'""")
 | 
			
		||||
    typeText("vl\"zy")
 | 
			
		||||
    val register = injector.registerGroup.getRegisters()
 | 
			
		||||
    val vimEditor = fixture.editor.vim
 | 
			
		||||
    val context = injector.executionContextManager.getEditorExecutionContext(vimEditor)
 | 
			
		||||
    val register = injector.registerGroup.getRegisters(vimEditor, context)
 | 
			
		||||
      .filter { reg -> reg.name == 'z' }
 | 
			
		||||
      .first()
 | 
			
		||||
    assertEquals("ab", register.text)
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -16,7 +16,7 @@ import com.maddyhome.idea.vim.command.Command
 | 
			
		||||
import com.maddyhome.idea.vim.command.OperatorArguments
 | 
			
		||||
import com.maddyhome.idea.vim.handler.VimActionHandler
 | 
			
		||||
 | 
			
		||||
@CommandOrMotion(keys = ["<C-R>"], modes = [Mode.NORMAL])
 | 
			
		||||
@CommandOrMotion(keys = ["U", "<C-R>"], modes = [Mode.NORMAL, Mode.VISUAL])
 | 
			
		||||
class RedoAction : VimActionHandler.SingleExecution() {
 | 
			
		||||
  override val type: Command.Type = Command.Type.OTHER_SELF_SYNCHRONIZED
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -16,7 +16,7 @@ import com.maddyhome.idea.vim.command.Command
 | 
			
		||||
import com.maddyhome.idea.vim.command.OperatorArguments
 | 
			
		||||
import com.maddyhome.idea.vim.handler.VimActionHandler
 | 
			
		||||
 | 
			
		||||
@CommandOrMotion(keys = ["u", "<Undo>"], modes = [Mode.NORMAL])
 | 
			
		||||
@CommandOrMotion(keys = ["u", "<Undo>"], modes = [Mode.NORMAL, Mode.VISUAL])
 | 
			
		||||
class UndoAction : VimActionHandler.SingleExecution() {
 | 
			
		||||
  override val type: Command.Type = Command.Type.OTHER_SELF_SYNCHRONIZED
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -8,7 +8,6 @@
 | 
			
		||||
package com.maddyhome.idea.vim.action.change.change
 | 
			
		||||
 | 
			
		||||
import com.intellij.vim.annotations.CommandOrMotion
 | 
			
		||||
import com.intellij.vim.annotations.Mode
 | 
			
		||||
import com.maddyhome.idea.vim.api.ExecutionContext
 | 
			
		||||
import com.maddyhome.idea.vim.api.VimCaret
 | 
			
		||||
import com.maddyhome.idea.vim.api.VimChangeGroup
 | 
			
		||||
@@ -22,7 +21,7 @@ import com.maddyhome.idea.vim.handler.VisualOperatorActionHandler
 | 
			
		||||
/**
 | 
			
		||||
 * @author vlan
 | 
			
		||||
 */
 | 
			
		||||
@CommandOrMotion(keys = ["u"], modes = [Mode.VISUAL])
 | 
			
		||||
@CommandOrMotion(keys = [], modes = [])
 | 
			
		||||
class ChangeCaseLowerVisualAction : VisualOperatorActionHandler.ForEachCaret() {
 | 
			
		||||
  override val type: Command.Type = Command.Type.CHANGE
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -8,7 +8,6 @@
 | 
			
		||||
package com.maddyhome.idea.vim.action.change.change
 | 
			
		||||
 | 
			
		||||
import com.intellij.vim.annotations.CommandOrMotion
 | 
			
		||||
import com.intellij.vim.annotations.Mode
 | 
			
		||||
import com.maddyhome.idea.vim.api.ExecutionContext
 | 
			
		||||
import com.maddyhome.idea.vim.api.VimCaret
 | 
			
		||||
import com.maddyhome.idea.vim.api.VimChangeGroup
 | 
			
		||||
@@ -22,7 +21,7 @@ import com.maddyhome.idea.vim.handler.VisualOperatorActionHandler
 | 
			
		||||
/**
 | 
			
		||||
 * @author vlan
 | 
			
		||||
 */
 | 
			
		||||
@CommandOrMotion(keys = ["U"], modes = [Mode.VISUAL])
 | 
			
		||||
@CommandOrMotion(keys = [], modes = [])
 | 
			
		||||
class ChangeCaseUpperVisualAction : VisualOperatorActionHandler.ForEachCaret() {
 | 
			
		||||
  override val type: Command.Type = Command.Type.CHANGE
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -68,9 +68,9 @@ class InsertRegisterAction : VimActionHandler.SingleExecution() {
 | 
			
		||||
 */
 | 
			
		||||
@RWLockLabel.SelfSynchronized
 | 
			
		||||
private fun insertRegister(editor: VimEditor, context: ExecutionContext, key: Char): Boolean {
 | 
			
		||||
  val register: Register? = injector.registerGroup.getRegister(editor, context, key)
 | 
			
		||||
  val register: Register? = injector.registerGroup.getRegister(key)
 | 
			
		||||
  if (register != null) {
 | 
			
		||||
    val textData = PutData.TextData(register.name, injector.clipboardManager.dumbCopiedText(register.text), SelectionType.CHARACTER_WISE)
 | 
			
		||||
    val textData = PutData.TextData(register.text, SelectionType.CHARACTER_WISE, emptyList(), register.name)
 | 
			
		||||
    val putData = PutData(textData, null, 1, insertTextBeforeCaret = true, rawIndent = true, caretAfterInsertedText = true)
 | 
			
		||||
    injector.put.putText(editor, context, putData)
 | 
			
		||||
    return true
 | 
			
		||||
 
 | 
			
		||||
@@ -10,7 +10,6 @@ package com.maddyhome.idea.vim.action.copy
 | 
			
		||||
import com.intellij.vim.annotations.CommandOrMotion
 | 
			
		||||
import com.intellij.vim.annotations.Mode
 | 
			
		||||
import com.maddyhome.idea.vim.api.ExecutionContext
 | 
			
		||||
import com.maddyhome.idea.vim.api.ImmutableVimCaret
 | 
			
		||||
import com.maddyhome.idea.vim.api.VimEditor
 | 
			
		||||
import com.maddyhome.idea.vim.api.injector
 | 
			
		||||
import com.maddyhome.idea.vim.command.Argument
 | 
			
		||||
@@ -36,7 +35,15 @@ sealed class PutTextBaseAction(
 | 
			
		||||
    val count = operatorArguments.count1
 | 
			
		||||
    val sortedCarets = editor.sortedCarets()
 | 
			
		||||
    return if (sortedCarets.size > 1) {
 | 
			
		||||
      val caretToPutData = sortedCarets.associateWith { getPutDataForCaret(editor, context, it, count) }
 | 
			
		||||
      val putData = getPutData(count)
 | 
			
		||||
 | 
			
		||||
      val splitText = putData.textData?.rawText?.split('\n')?.dropLastWhile(String::isEmpty)
 | 
			
		||||
      val caretToPutData = if (splitText != null && splitText.size == sortedCarets.size) {
 | 
			
		||||
        sortedCarets.mapIndexed { index, caret -> caret to putData.copy(textData = putData.textData.copy(rawText = splitText[splitText.lastIndex - index])) }.toMap()
 | 
			
		||||
      } else {
 | 
			
		||||
        sortedCarets.associateWith { putData }
 | 
			
		||||
      }
 | 
			
		||||
      
 | 
			
		||||
      var result = true
 | 
			
		||||
      injector.application.runWriteAction {
 | 
			
		||||
        caretToPutData.forEach {
 | 
			
		||||
@@ -45,21 +52,24 @@ sealed class PutTextBaseAction(
 | 
			
		||||
      }
 | 
			
		||||
      result
 | 
			
		||||
    } else {
 | 
			
		||||
      val putData = getPutDataForCaret(editor, context, sortedCarets.single(), count)
 | 
			
		||||
      injector.put.putText(editor, context, putData)
 | 
			
		||||
      injector.put.putText(editor, context, getPutData(count))
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  private fun getPutDataForCaret(editor: VimEditor, context: ExecutionContext, caret: ImmutableVimCaret, count: Int): PutData {
 | 
			
		||||
    val registerService = injector.registerGroup
 | 
			
		||||
    val registerChar = if (caret.editor.carets().size == 1) {
 | 
			
		||||
      registerService.currentRegister
 | 
			
		||||
    } else {
 | 
			
		||||
      registerService.getCurrentRegisterForMulticaret()
 | 
			
		||||
    }
 | 
			
		||||
    val register = caret.registerStorage.getRegister(editor, context, registerChar)
 | 
			
		||||
    val textData = register?.let { TextData(register) }
 | 
			
		||||
    return PutData(textData, null, count, insertTextBeforeCaret, indent, caretAfterInsertedText, -1)
 | 
			
		||||
  private fun getPutData(count: Int): PutData {
 | 
			
		||||
    return PutData(getRegisterTextData(), null, count, insertTextBeforeCaret, indent, caretAfterInsertedText, -1)
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
fun getRegisterTextData(): TextData? {
 | 
			
		||||
  val register = injector.registerGroup.getRegister(injector.registerGroup.currentRegister)
 | 
			
		||||
  return register?.let {
 | 
			
		||||
    TextData(
 | 
			
		||||
      register.text ?: injector.parser.toPrintableString(register.keys),
 | 
			
		||||
      register.type,
 | 
			
		||||
      register.transferableData,
 | 
			
		||||
      register.name,
 | 
			
		||||
    )
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -41,7 +41,21 @@ sealed class PutVisualTextBaseAction(
 | 
			
		||||
  ): Boolean {
 | 
			
		||||
    if (caretsAndSelections.isEmpty()) return false
 | 
			
		||||
    val count = cmd.count
 | 
			
		||||
    val caretToPutData = editor.sortedCarets().associateWith { getPutDataForCaret(editor, context, it, caretsAndSelections[it], count) }
 | 
			
		||||
    val sortedCarets = editor.sortedCarets()
 | 
			
		||||
 | 
			
		||||
    val textData = getRegisterTextData()
 | 
			
		||||
    val splitText = textData?.rawText?.split('\n')?.dropLastWhile(String::isEmpty)
 | 
			
		||||
 | 
			
		||||
    val caretToTextData = if (splitText != null && splitText.size == sortedCarets.size) {
 | 
			
		||||
      sortedCarets.mapIndexed { index, caret -> caret to textData.copy(rawText = splitText[splitText.lastIndex - index]) }.toMap()
 | 
			
		||||
    } else {
 | 
			
		||||
      sortedCarets.associateWith { textData }
 | 
			
		||||
    }
 | 
			
		||||
    
 | 
			
		||||
    val caretToPutData = caretToTextData.mapValues { (caret, textData) ->
 | 
			
		||||
      getPutDataForCaret(textData, caret, caretsAndSelections[caret], count)
 | 
			
		||||
    }
 | 
			
		||||
    
 | 
			
		||||
    injector.registerGroup.resetRegister()
 | 
			
		||||
    var result = true
 | 
			
		||||
    injector.application.runWriteAction {
 | 
			
		||||
@@ -51,11 +65,8 @@ sealed class PutVisualTextBaseAction(
 | 
			
		||||
    }
 | 
			
		||||
    return result
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  private fun getPutDataForCaret(editor: VimEditor, context: ExecutionContext, caret: VimCaret, selection: VimSelection?, count: Int): PutData {
 | 
			
		||||
    val lastRegisterChar = injector.registerGroup.lastRegisterChar
 | 
			
		||||
    val register = caret.registerStorage.getRegister(editor, context, lastRegisterChar)
 | 
			
		||||
    val textData = register?.let { PutData.TextData(register) }
 | 
			
		||||
  
 | 
			
		||||
  private fun getPutDataForCaret(textData: PutData.TextData?, caret: VimCaret, selection: VimSelection?, count: Int): PutData {
 | 
			
		||||
    val visualSelection = selection?.let { PutData.VisualSelection(mapOf(caret to it), it.type) }
 | 
			
		||||
    return PutData(textData, visualSelection, count, insertTextBeforeCaret, indent, caretAfterInsertedText)
 | 
			
		||||
  }
 | 
			
		||||
 
 | 
			
		||||
@@ -69,8 +69,7 @@ class ProcessSearchEntryAction(private val parentAction: ProcessExEntryAction) :
 | 
			
		||||
      '?' -> injector.searchGroup.processSearchCommand(editor, argument.string, caret.offset, operatorArguments.count1, Direction.BACKWARDS)
 | 
			
		||||
      else -> throw ExException("Unexpected search label ${argument.label}")
 | 
			
		||||
    }
 | 
			
		||||
    // Vim doesn't treat not finding something as an error, although it might report either an error or warning message
 | 
			
		||||
    if (offsetAndMotion == null) return Motion.NoMotion
 | 
			
		||||
    if (offsetAndMotion == null) return Motion.Error
 | 
			
		||||
    parentAction.motionType = offsetAndMotion.second
 | 
			
		||||
    return offsetAndMotion.first.toMotionOrError()
 | 
			
		||||
  }
 | 
			
		||||
 
 | 
			
		||||
@@ -76,6 +76,13 @@ sealed class TillCharacterMotion(
 | 
			
		||||
      )
 | 
			
		||||
    }
 | 
			
		||||
    injector.motion.setLastFTCmd(tillCharacterMotionType, argument.character)
 | 
			
		||||
    
 | 
			
		||||
    val offset = if (!finishBeforeCharacter) ""
 | 
			
		||||
    else if (direction == Direction.FORWARDS) "s-1"
 | 
			
		||||
    else "s+1"
 | 
			
		||||
    
 | 
			
		||||
    injector.searchGroup.setLastSearchState(argument.character.let { if (it == '.') "\\." else it.toString() }, offset, direction)
 | 
			
		||||
    
 | 
			
		||||
    return res.toMotionOrError()
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -9,7 +9,6 @@
 | 
			
		||||
package com.maddyhome.idea.vim.api
 | 
			
		||||
 | 
			
		||||
import com.maddyhome.idea.vim.common.LiveRange
 | 
			
		||||
import com.maddyhome.idea.vim.common.TextRange
 | 
			
		||||
import com.maddyhome.idea.vim.group.visual.VisualChange
 | 
			
		||||
import com.maddyhome.idea.vim.group.visual.vimMoveBlockSelectionToOffset
 | 
			
		||||
import com.maddyhome.idea.vim.group.visual.vimMoveSelectionToCaret
 | 
			
		||||
@@ -17,13 +16,11 @@ import com.maddyhome.idea.vim.handler.Motion
 | 
			
		||||
import com.maddyhome.idea.vim.helper.RWLockLabel
 | 
			
		||||
import com.maddyhome.idea.vim.helper.StrictMode
 | 
			
		||||
import com.maddyhome.idea.vim.helper.exitVisualMode
 | 
			
		||||
import com.maddyhome.idea.vim.register.Register
 | 
			
		||||
import com.maddyhome.idea.vim.state.mode.SelectionType
 | 
			
		||||
import com.maddyhome.idea.vim.register.VimRegisterGroup
 | 
			
		||||
import com.maddyhome.idea.vim.state.mode.inBlockSelection
 | 
			
		||||
import com.maddyhome.idea.vim.state.mode.inCommandLineMode
 | 
			
		||||
import com.maddyhome.idea.vim.state.mode.inSelectMode
 | 
			
		||||
import com.maddyhome.idea.vim.state.mode.inVisualMode
 | 
			
		||||
import javax.swing.KeyStroke
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Immutable interface of the caret. Immutable caret is an important concept of Fleet.
 | 
			
		||||
@@ -64,7 +61,7 @@ interface ImmutableVimCaret {
 | 
			
		||||
  fun hasSelection(): Boolean
 | 
			
		||||
 | 
			
		||||
  var lastSelectionInfo: SelectionInfo
 | 
			
		||||
  val registerStorage: CaretRegisterStorage
 | 
			
		||||
  val registerStorage: VimRegisterGroup
 | 
			
		||||
  val markStorage: LocalMarkStorage
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@@ -150,30 +147,3 @@ fun VimCaret.moveToMotion(motion: Motion): VimCaret {
 | 
			
		||||
    this
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
interface CaretRegisterStorage {
 | 
			
		||||
  val caret: ImmutableVimCaret
 | 
			
		||||
 | 
			
		||||
  /**
 | 
			
		||||
   * Stores text to caret's recordable (named/numbered/unnamed) register
 | 
			
		||||
   */
 | 
			
		||||
  @Deprecated("Please use the same method, but with ExecutionContext")
 | 
			
		||||
  fun storeText(editor: VimEditor, range: TextRange, type: SelectionType, isDelete: Boolean): Boolean
 | 
			
		||||
  fun storeText(editor: VimEditor, context: ExecutionContext, range: TextRange, type: SelectionType, isDelete: Boolean): Boolean
 | 
			
		||||
 | 
			
		||||
  /**
 | 
			
		||||
   * Gets text from caret's recordable register
 | 
			
		||||
   * If the register is not recordable - global text state will be returned
 | 
			
		||||
   */
 | 
			
		||||
  @Deprecated("Please use com.maddyhome.idea.vim.api.CaretRegisterStorage#getRegister(com.maddyhome.idea.vim.api.VimEditor, com.maddyhome.idea.vim.api.ExecutionContext, char)")
 | 
			
		||||
  fun getRegister(r: Char): Register?
 | 
			
		||||
  fun getRegister(editor: VimEditor, context: ExecutionContext, r: Char): Register?
 | 
			
		||||
 | 
			
		||||
  @Deprecated("Please use com.maddyhome.idea.vim.api.CaretRegisterStorage#setKeys(com.maddyhome.idea.vim.api.VimEditor, com.maddyhome.idea.vim.api.ExecutionContext, char, java.util.List<? extends javax.swing.KeyStroke>)")
 | 
			
		||||
  fun setKeys(register: Char, keys: List<KeyStroke>)
 | 
			
		||||
  fun setKeys(editor: VimEditor, context: ExecutionContext, register: Char, keys: List<KeyStroke>)
 | 
			
		||||
  
 | 
			
		||||
  @Deprecated("Please use com.maddyhome.idea.vim.api.CaretRegisterStorage#saveRegister(com.maddyhome.idea.vim.api.VimEditor, com.maddyhome.idea.vim.api.ExecutionContext, char, com.maddyhome.idea.vim.register.Register)")
 | 
			
		||||
  fun saveRegister(r: Char, register: Register)
 | 
			
		||||
  fun saveRegister(editor: VimEditor, context: ExecutionContext, r: Char, register: Register)
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -8,98 +8,4 @@
 | 
			
		||||
 | 
			
		||||
package com.maddyhome.idea.vim.api
 | 
			
		||||
 | 
			
		||||
import com.maddyhome.idea.vim.common.TextRange
 | 
			
		||||
import com.maddyhome.idea.vim.register.Register
 | 
			
		||||
import com.maddyhome.idea.vim.register.RegisterConstants
 | 
			
		||||
import com.maddyhome.idea.vim.register.VimRegisterGroupBase
 | 
			
		||||
import com.maddyhome.idea.vim.state.mode.SelectionType
 | 
			
		||||
import javax.swing.KeyStroke
 | 
			
		||||
 | 
			
		||||
abstract class VimCaretBase : VimCaret
 | 
			
		||||
 | 
			
		||||
open class CaretRegisterStorageBase(override var caret: ImmutableVimCaret) : CaretRegisterStorage, VimRegisterGroupBase() {
 | 
			
		||||
  companion object {
 | 
			
		||||
    private const val ALLOWED_TO_STORE_REGISTERS = RegisterConstants.RECORDABLE_REGISTERS +
 | 
			
		||||
      RegisterConstants.SMALL_DELETION_REGISTER +
 | 
			
		||||
      RegisterConstants.BLACK_HOLE_REGISTER +
 | 
			
		||||
      RegisterConstants.LAST_INSERTED_TEXT_REGISTER +
 | 
			
		||||
      RegisterConstants.LAST_SEARCH_REGISTER
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  override var lastRegisterChar: Char
 | 
			
		||||
    get() {
 | 
			
		||||
      return injector.registerGroup.lastRegisterChar
 | 
			
		||||
    }
 | 
			
		||||
    set(_) {}
 | 
			
		||||
 | 
			
		||||
  override var isRegisterSpecifiedExplicitly: Boolean
 | 
			
		||||
    get() {
 | 
			
		||||
      return injector.registerGroup.isRegisterSpecifiedExplicitly
 | 
			
		||||
    }
 | 
			
		||||
    set(_) {}
 | 
			
		||||
 | 
			
		||||
  @Deprecated("Please use the same method, but with ExecutionContext")
 | 
			
		||||
  override fun storeText(editor: VimEditor, range: TextRange, type: SelectionType, isDelete: Boolean): Boolean {
 | 
			
		||||
    val context = injector.executionContextManager.getEditorExecutionContext(editor)
 | 
			
		||||
    return storeText(editor, context, caret, range, type, isDelete)
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  override fun storeText(editor: VimEditor, context: ExecutionContext, range: TextRange, type: SelectionType, isDelete: Boolean): Boolean {
 | 
			
		||||
    val registerChar = if (caret.editor.carets().size == 1) currentRegister else getCurrentRegisterForMulticaret()
 | 
			
		||||
    if (caret.isPrimary) {
 | 
			
		||||
      val registerService = injector.registerGroup
 | 
			
		||||
      registerService.lastRegisterChar = registerChar
 | 
			
		||||
      return registerService.storeText(editor, context, caret, range, type, isDelete)
 | 
			
		||||
    } else {
 | 
			
		||||
      if (!ALLOWED_TO_STORE_REGISTERS.contains(registerChar)) {
 | 
			
		||||
        return false
 | 
			
		||||
      }
 | 
			
		||||
      val text = preprocessTextBeforeStoring(editor.getText(range), type)
 | 
			
		||||
      return storeTextInternal(editor, context, range, text, type, registerChar, isDelete)
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
  
 | 
			
		||||
  override fun getRegister(r: Char): Register? {
 | 
			
		||||
    val editorStub = injector.fallbackWindow
 | 
			
		||||
    val contextStub = injector.executionContextManager.getEditorExecutionContext(editorStub)
 | 
			
		||||
    return getRegister(editorStub, contextStub, r)
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  override fun getRegister(editor: VimEditor, context: ExecutionContext, r: Char): Register? {
 | 
			
		||||
    if (caret.isPrimary || !RegisterConstants.RECORDABLE_REGISTERS.contains(r)) {
 | 
			
		||||
      return injector.registerGroup.getRegister(editor, context, r)
 | 
			
		||||
    }
 | 
			
		||||
    return super.getRegister(editor, context, r) ?: injector.registerGroup.getRegister(editor, context, r)
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  override fun setKeys(register: Char, keys: List<KeyStroke>) {
 | 
			
		||||
    val editorStub = injector.fallbackWindow
 | 
			
		||||
    val contextStub = injector.executionContextManager.getEditorExecutionContext(editorStub)
 | 
			
		||||
    setKeys(editorStub, contextStub, register, keys)
 | 
			
		||||
  }
 | 
			
		||||
  
 | 
			
		||||
  override fun setKeys(editor: VimEditor, context: ExecutionContext, register: Char, keys: List<KeyStroke>) {
 | 
			
		||||
    if (caret.isPrimary) {
 | 
			
		||||
      injector.registerGroup.setKeys(register, keys)
 | 
			
		||||
    }
 | 
			
		||||
    if (!RegisterConstants.RECORDABLE_REGISTERS.contains(register)) {
 | 
			
		||||
      return
 | 
			
		||||
    }
 | 
			
		||||
    return super.setKeys(register, keys)
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  override fun saveRegister(r: Char, register: Register) {
 | 
			
		||||
    val editorStub = injector.fallbackWindow
 | 
			
		||||
    val contextStub = injector.executionContextManager.getEditorExecutionContext(editorStub)
 | 
			
		||||
    saveRegister(editorStub, contextStub, r, register)
 | 
			
		||||
  }
 | 
			
		||||
  override fun saveRegister(editor: VimEditor, context: ExecutionContext, r: Char, register: Register) {
 | 
			
		||||
    if (caret.isPrimary) {
 | 
			
		||||
      injector.registerGroup.saveRegister(editor, context, r, register)
 | 
			
		||||
    }
 | 
			
		||||
    if (!RegisterConstants.RECORDABLE_REGISTERS.contains(r)) {
 | 
			
		||||
      return
 | 
			
		||||
    }
 | 
			
		||||
    return super.saveRegister(editor, context, r, register)
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -175,7 +175,7 @@ interface VimChangeGroup {
 | 
			
		||||
    operatorArguments: OperatorArguments,
 | 
			
		||||
  )
 | 
			
		||||
 | 
			
		||||
  fun insertText(editor: VimEditor, caret: VimCaret, offset: Int, str: String): VimCaret
 | 
			
		||||
  fun insertText(editor: VimEditor, caret: VimCaret, offset: Int, str: CharSequence): VimCaret
 | 
			
		||||
 | 
			
		||||
  fun insertText(editor: VimEditor, caret: VimCaret, str: String): VimCaret
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -182,29 +182,39 @@ abstract class VimChangeGroupBase : VimChangeGroup {
 | 
			
		||||
        return false
 | 
			
		||||
      }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    val isInsertMode = editor.mode == Mode.INSERT || editor.mode == Mode.REPLACE
 | 
			
		||||
    val shouldYank = type != null && !isInsertMode && saveToRegister
 | 
			
		||||
    if (shouldYank && !caret.registerStorage.storeText(editor, context, updatedRange, type, isDelete = true)) {
 | 
			
		||||
      return false
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    val startOffsets = updatedRange.startOffsets
 | 
			
		||||
    val endOffsets = updatedRange.endOffsets
 | 
			
		||||
    for (i in updatedRange.size() - 1 downTo 0) {
 | 
			
		||||
      val (newRange, _) = editor.search(
 | 
			
		||||
        startOffsets[i] to endOffsets[i],
 | 
			
		||||
    val mode = editor.mode
 | 
			
		||||
    if (type == null ||
 | 
			
		||||
      (mode == Mode.INSERT || mode == Mode.REPLACE) ||
 | 
			
		||||
      !saveToRegister ||
 | 
			
		||||
      injector.registerGroup.storeText(
 | 
			
		||||
        editor,
 | 
			
		||||
        LineDeleteShift.NL_ON_END
 | 
			
		||||
      ) ?: continue
 | 
			
		||||
      editor.deleteString(TextRange(newRange.first, newRange.second))
 | 
			
		||||
        context,
 | 
			
		||||
        caret,
 | 
			
		||||
        updatedRange,
 | 
			
		||||
        type,
 | 
			
		||||
        true,
 | 
			
		||||
        !editor.isFirstCaret,
 | 
			
		||||
        editor.isReversingCarets
 | 
			
		||||
      )
 | 
			
		||||
    ) {
 | 
			
		||||
      val startOffsets = updatedRange.startOffsets
 | 
			
		||||
      val endOffsets = updatedRange.endOffsets
 | 
			
		||||
      for (i in updatedRange.size() - 1 downTo 0) {
 | 
			
		||||
        val (newRange, _) = editor.search(
 | 
			
		||||
          startOffsets[i] to endOffsets[i],
 | 
			
		||||
          editor,
 | 
			
		||||
          LineDeleteShift.NL_ON_END
 | 
			
		||||
        ) ?: continue
 | 
			
		||||
        editor.deleteString(TextRange(newRange.first, newRange.second))
 | 
			
		||||
      }
 | 
			
		||||
      if (type != null) {
 | 
			
		||||
        val start = updatedRange.startOffset
 | 
			
		||||
        injector.markService.setMark(caret, MARK_CHANGE_POS, start)
 | 
			
		||||
        injector.markService.setChangeMarks(caret, TextRange(start, start + 1))
 | 
			
		||||
      }
 | 
			
		||||
      return true
 | 
			
		||||
    }
 | 
			
		||||
    if (type != null) {
 | 
			
		||||
      val start = updatedRange.startOffset
 | 
			
		||||
      injector.markService.setMark(caret, MARK_CHANGE_POS, start)
 | 
			
		||||
      injector.markService.setChangeMarks(caret, TextRange(start, start + 1))
 | 
			
		||||
    }
 | 
			
		||||
    return true
 | 
			
		||||
    return false
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  /**
 | 
			
		||||
@@ -214,7 +224,7 @@ abstract class VimChangeGroupBase : VimChangeGroup {
 | 
			
		||||
   * @param caret  The caret to start insertion in
 | 
			
		||||
   * @param str    The text to insert
 | 
			
		||||
   */
 | 
			
		||||
  override fun insertText(editor: VimEditor, caret: VimCaret, offset: Int, str: String): VimCaret {
 | 
			
		||||
  override fun insertText(editor: VimEditor, caret: VimCaret, offset: Int, str: CharSequence): VimCaret {
 | 
			
		||||
    (editor as MutableVimEditor).insertText(caret, offset, str)
 | 
			
		||||
    val newCaret = caret.moveToInlayAwareOffset(offset + str.length)
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -172,7 +172,8 @@ interface VimEditor {
 | 
			
		||||
   * This method should perform caret merging after the operations. This is similar to IJ runForEachCaret
 | 
			
		||||
   * TODO review
 | 
			
		||||
   */
 | 
			
		||||
 | 
			
		||||
  val isFirstCaret: Boolean
 | 
			
		||||
  val isReversingCarets: Boolean
 | 
			
		||||
  fun forEachCaret(action: (VimCaret) -> Unit)
 | 
			
		||||
  fun forEachNativeCaret(action: (VimCaret) -> Unit, reverse: Boolean = false)
 | 
			
		||||
  fun isInForEachCaretScope(): Boolean
 | 
			
		||||
 
 | 
			
		||||
@@ -17,8 +17,6 @@ import com.maddyhome.idea.vim.common.VimListenersNotifier
 | 
			
		||||
import com.maddyhome.idea.vim.diagnostic.VimLogger
 | 
			
		||||
import com.maddyhome.idea.vim.diagnostic.vimLogger
 | 
			
		||||
import com.maddyhome.idea.vim.impl.state.VimStateMachineImpl
 | 
			
		||||
import com.maddyhome.idea.vim.register.VimRegisterGroup
 | 
			
		||||
import com.maddyhome.idea.vim.register.VimRegisterGroupBase
 | 
			
		||||
import com.maddyhome.idea.vim.state.VimStateMachine
 | 
			
		||||
import com.maddyhome.idea.vim.vimscript.services.VariableService
 | 
			
		||||
import com.maddyhome.idea.vim.vimscript.services.VimVariableServiceBase
 | 
			
		||||
@@ -28,7 +26,6 @@ import com.maddyhome.idea.vim.yank.YankGroupBase
 | 
			
		||||
abstract class VimInjectorBase : VimInjector {
 | 
			
		||||
  companion object {
 | 
			
		||||
    val logger: VimLogger by lazy { vimLogger<VimInjectorBase>() }
 | 
			
		||||
    val registerGroupStub: VimRegisterGroupBase by lazy { object : VimRegisterGroupBase() {} }
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  override val vimState: VimStateMachine = VimStateMachineImpl()
 | 
			
		||||
@@ -38,8 +35,6 @@ abstract class VimInjectorBase : VimInjector {
 | 
			
		||||
 | 
			
		||||
  override val variableService: VariableService by lazy { object : VimVariableServiceBase() {} }
 | 
			
		||||
 | 
			
		||||
  override val registerGroup: VimRegisterGroup by lazy { registerGroupStub }
 | 
			
		||||
  override val registerGroupIfCreated: VimRegisterGroup? by lazy { registerGroupStub }
 | 
			
		||||
  override val messages: VimMessages by lazy { VimMessagesStub() }
 | 
			
		||||
  override val processGroup: VimProcessGroup by lazy { VimProcessGroupStub() }
 | 
			
		||||
  override val application: VimApplication by lazy { VimApplicationStub() }
 | 
			
		||||
 
 | 
			
		||||
@@ -200,4 +200,17 @@ interface VimSearchGroup {
 | 
			
		||||
   * Returns true if any text is selected in the visible editors, false otherwise.
 | 
			
		||||
   */
 | 
			
		||||
  fun isSomeTextHighlighted(): Boolean
 | 
			
		||||
 | 
			
		||||
  /**
 | 
			
		||||
   * Sets the last search state purely for tests
 | 
			
		||||
   *
 | 
			
		||||
   * @param pattern         The pattern to save. This is the last search pattern, not the last substitute pattern
 | 
			
		||||
   * @param patternOffset   The pattern offset, e.g. `/{pattern}/{offset}`
 | 
			
		||||
   * @param direction       The direction to search
 | 
			
		||||
   */
 | 
			
		||||
  fun setLastSearchState(
 | 
			
		||||
    pattern: String,
 | 
			
		||||
    patternOffset: String,
 | 
			
		||||
    direction: Direction,
 | 
			
		||||
  )
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -1357,8 +1357,7 @@ abstract class VimSearchGroupBase : VimSearchGroup {
 | 
			
		||||
   * @param patternOffset   The pattern offset, e.g. `/{pattern}/{offset}`
 | 
			
		||||
   * @param direction       The direction to search
 | 
			
		||||
   */
 | 
			
		||||
  @TestOnly
 | 
			
		||||
  fun setLastSearchState(
 | 
			
		||||
  override fun setLastSearchState(
 | 
			
		||||
    pattern: String,
 | 
			
		||||
    patternOffset: String,
 | 
			
		||||
    direction: Direction,
 | 
			
		||||
 
 | 
			
		||||
@@ -8,7 +8,6 @@
 | 
			
		||||
 | 
			
		||||
package com.maddyhome.idea.vim.common
 | 
			
		||||
 | 
			
		||||
import com.maddyhome.idea.vim.api.ImmutableVimCaret
 | 
			
		||||
import com.maddyhome.idea.vim.api.VimEditor
 | 
			
		||||
import com.maddyhome.idea.vim.api.injector
 | 
			
		||||
import com.maddyhome.idea.vim.state.mode.Mode
 | 
			
		||||
@@ -72,9 +71,9 @@ class VimListenersNotifier {
 | 
			
		||||
    isReplaceCharListeners.forEach { it.isReplaceCharChanged(editor) }
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  fun notifyYankPerformed(caretToRange: Map<ImmutableVimCaret, TextRange>) {
 | 
			
		||||
  fun notifyYankPerformed(editor: VimEditor, range: TextRange) {
 | 
			
		||||
    if (!injector.enabler.isEnabled()) return // we remove all the listeners when turning the plugin off, but let's do it just in case
 | 
			
		||||
    yankListeners.forEach { it.yankPerformed(caretToRange) }
 | 
			
		||||
    yankListeners.forEach { it.yankPerformed(editor, range) }
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  fun reset() {
 | 
			
		||||
 
 | 
			
		||||
@@ -8,8 +8,8 @@
 | 
			
		||||
 | 
			
		||||
package com.maddyhome.idea.vim.common
 | 
			
		||||
 | 
			
		||||
import com.maddyhome.idea.vim.api.ImmutableVimCaret
 | 
			
		||||
import com.maddyhome.idea.vim.api.VimEditor
 | 
			
		||||
 | 
			
		||||
interface VimYankListener {
 | 
			
		||||
  fun yankPerformed(caretToRange: Map<ImmutableVimCaret, TextRange>)
 | 
			
		||||
}
 | 
			
		||||
  fun yankPerformed(editor: VimEditor, range: TextRange)
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -259,7 +259,11 @@ class ToActionMappingInfo(
 | 
			
		||||
 | 
			
		||||
  override fun execute(editor: VimEditor, context: ExecutionContext, keyState: KeyHandlerState) {
 | 
			
		||||
    LOG.debug("Executing 'ToAction' mapping...")
 | 
			
		||||
    injector.actionExecutor.executeAction(editor, name = action, context = context)
 | 
			
		||||
    val commandBuilder = KeyHandler.getInstance().keyHandlerState.commandBuilder
 | 
			
		||||
    for (i in 0 until commandBuilder.calculateCount0Snapshot().coerceAtLeast(1)) {
 | 
			
		||||
      injector.actionExecutor.executeAction(editor, name = action, context = context)
 | 
			
		||||
    }
 | 
			
		||||
    commandBuilder.resetCount()
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  companion object {
 | 
			
		||||
 
 | 
			
		||||
@@ -8,11 +8,11 @@
 | 
			
		||||
 | 
			
		||||
package com.maddyhome.idea.vim.put
 | 
			
		||||
 | 
			
		||||
import com.maddyhome.idea.vim.common.VimCopiedText
 | 
			
		||||
import com.maddyhome.idea.vim.state.mode.SelectionType
 | 
			
		||||
 | 
			
		||||
data class ProcessedTextData(
 | 
			
		||||
  val registerChar: Char?,
 | 
			
		||||
  val copiedText: VimCopiedText,
 | 
			
		||||
  val text: String,
 | 
			
		||||
  val typeInRegister: SelectionType,
 | 
			
		||||
  val transferableData: List<Any>,
 | 
			
		||||
  val registerChar: Char?,
 | 
			
		||||
)
 | 
			
		||||
 
 | 
			
		||||
@@ -9,10 +9,8 @@
 | 
			
		||||
package com.maddyhome.idea.vim.put
 | 
			
		||||
 | 
			
		||||
import com.maddyhome.idea.vim.api.VimCaret
 | 
			
		||||
import com.maddyhome.idea.vim.common.VimCopiedText
 | 
			
		||||
import com.maddyhome.idea.vim.state.mode.SelectionType
 | 
			
		||||
import com.maddyhome.idea.vim.group.visual.VimSelection
 | 
			
		||||
import com.maddyhome.idea.vim.register.Register
 | 
			
		||||
import com.maddyhome.idea.vim.state.mode.SelectionType
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * [putToLine] has affect only of [insertTextBeforeCaret] is false and [visualSelection] is null
 | 
			
		||||
@@ -35,12 +33,9 @@ data class PutData(
 | 
			
		||||
  )
 | 
			
		||||
 | 
			
		||||
  data class TextData(
 | 
			
		||||
    val registerChar: Char?,
 | 
			
		||||
    val copiedText: VimCopiedText,
 | 
			
		||||
    val rawText: String?,
 | 
			
		||||
    val typeInRegister: SelectionType,
 | 
			
		||||
  ) {
 | 
			
		||||
    constructor(register: Register): this(register.name, register.copiedText, register.type)
 | 
			
		||||
 | 
			
		||||
    val rawText = copiedText.text // TODO do not call it raw text...
 | 
			
		||||
  }
 | 
			
		||||
    val transferableData: List<Any>,
 | 
			
		||||
    val registerChar: Char?,
 | 
			
		||||
  )
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -135,7 +135,6 @@ abstract class VimPutBase : VimPut {
 | 
			
		||||
 | 
			
		||||
    if (data.visualSelection?.typeInEditor?.isLine == true && data.textData.typeInRegister.isChar) text += "\n"
 | 
			
		||||
 | 
			
		||||
    // TODO: shouldn't it be adjusted when we are storing the text?
 | 
			
		||||
    if (data.textData.typeInRegister.isLine && text.isNotEmpty() && text.last() != '\n') text += '\n'
 | 
			
		||||
 | 
			
		||||
    if (data.textData.typeInRegister.isChar && text.lastOrNull() == '\n' && data.visualSelection?.typeInEditor?.isLine == false) {
 | 
			
		||||
@@ -144,9 +143,10 @@ abstract class VimPutBase : VimPut {
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    return ProcessedTextData(
 | 
			
		||||
      data.textData.registerChar,
 | 
			
		||||
      data.textData.copiedText.updateText(text),
 | 
			
		||||
      text,
 | 
			
		||||
      data.textData.typeInRegister,
 | 
			
		||||
      data.textData.transferableData,
 | 
			
		||||
      data.textData.registerChar,
 | 
			
		||||
    )
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
@@ -493,7 +493,7 @@ abstract class VimPutBase : VimPut {
 | 
			
		||||
    startOffsets.forEach { startOffset ->
 | 
			
		||||
      val subMode = data.visualSelection?.typeInEditor ?: SelectionType.CHARACTER_WISE
 | 
			
		||||
      val (endOffset, updatedCaret) = putTextInternal(
 | 
			
		||||
        editor, updated, context, text.copiedText.text, text.typeInRegister, subMode,
 | 
			
		||||
        editor, updated, context, text.text, text.typeInRegister, subMode,
 | 
			
		||||
        startOffset, data.count, data.indent, data.caretAfterInsertedText,
 | 
			
		||||
      )
 | 
			
		||||
      updated = updatedCaret
 | 
			
		||||
 
 | 
			
		||||
@@ -625,7 +625,13 @@ class VimRegex(pattern: String) {
 | 
			
		||||
    override fun carets(): List<VimCaret> = emptyList()
 | 
			
		||||
 | 
			
		||||
    override fun nativeCarets(): List<VimCaret> = emptyList()
 | 
			
		||||
    
 | 
			
		||||
    override val isFirstCaret: Boolean
 | 
			
		||||
      get() = false
 | 
			
		||||
 | 
			
		||||
    override val isReversingCarets: Boolean
 | 
			
		||||
      get() = false
 | 
			
		||||
    
 | 
			
		||||
    override fun forEachCaret(action: (VimCaret) -> Unit) {}
 | 
			
		||||
 | 
			
		||||
    override fun forEachNativeCaret(action: (VimCaret) -> Unit, reverse: Boolean) {}
 | 
			
		||||
 
 | 
			
		||||
@@ -8,26 +8,86 @@
 | 
			
		||||
package com.maddyhome.idea.vim.register
 | 
			
		||||
 | 
			
		||||
import com.maddyhome.idea.vim.api.injector
 | 
			
		||||
import com.maddyhome.idea.vim.common.VimCopiedText
 | 
			
		||||
import com.maddyhome.idea.vim.helper.EngineStringHelper
 | 
			
		||||
import com.maddyhome.idea.vim.state.mode.SelectionType
 | 
			
		||||
import org.jetbrains.annotations.NonNls
 | 
			
		||||
import java.awt.event.KeyEvent
 | 
			
		||||
import javax.swing.KeyStroke
 | 
			
		||||
 | 
			
		||||
// TODO should we prefer keys over text, as they are more informative?
 | 
			
		||||
// TODO e.g.  could be both <Esc> and <C-[> after trying to restore original keys
 | 
			
		||||
data class Register(val name: Char,
 | 
			
		||||
                    val copiedText: VimCopiedText,
 | 
			
		||||
                    val type: SelectionType,
 | 
			
		||||
) {
 | 
			
		||||
  val text = copiedText.text
 | 
			
		||||
  val keys get() = injector.parser.stringToKeys(copiedText.text)
 | 
			
		||||
  val printableString: String = EngineStringHelper.toPrintableCharacters(keys) // should be the same as [text], but we can't render control notation properly
 | 
			
		||||
class Register {
 | 
			
		||||
  var name: Char
 | 
			
		||||
  val type: SelectionType
 | 
			
		||||
  val keys: MutableList<KeyStroke>
 | 
			
		||||
  val transferableData: MutableList<out Any>
 | 
			
		||||
  val rawText: String?
 | 
			
		||||
 | 
			
		||||
  constructor(name: Char, type: SelectionType, keys: MutableList<KeyStroke>) : this(name, injector.clipboardManager.dumbCopiedText(injector.parser.toPrintableString(keys)), type)
 | 
			
		||||
//  constructor(name: Char, type: SelectionType, text: String, transferableData: MutableList<out Any>) : this(name, text, type, transferableData)
 | 
			
		||||
  constructor(name: Char, type: SelectionType, keys: MutableList<KeyStroke>) {
 | 
			
		||||
    this.name = name
 | 
			
		||||
    this.type = type
 | 
			
		||||
    this.keys = keys
 | 
			
		||||
    this.transferableData = mutableListOf()
 | 
			
		||||
    this.rawText = text
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  override fun toString(): String = "@$name = $printableString"
 | 
			
		||||
  constructor(
 | 
			
		||||
    name: Char,
 | 
			
		||||
    type: SelectionType,
 | 
			
		||||
    text: String,
 | 
			
		||||
    transferableData: MutableList<out Any>,
 | 
			
		||||
  ) {
 | 
			
		||||
    this.name = name
 | 
			
		||||
    this.type = type
 | 
			
		||||
    this.keys = injector.parser.stringToKeys(text).toMutableList()
 | 
			
		||||
    this.transferableData = transferableData
 | 
			
		||||
    this.rawText = text
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  constructor(
 | 
			
		||||
    name: Char,
 | 
			
		||||
    type: SelectionType,
 | 
			
		||||
    text: String,
 | 
			
		||||
    transferableData: MutableList<out Any>,
 | 
			
		||||
    rawText: String,
 | 
			
		||||
  ) {
 | 
			
		||||
    this.name = name
 | 
			
		||||
    this.type = type
 | 
			
		||||
    this.keys = injector.parser.stringToKeys(text).toMutableList()
 | 
			
		||||
    this.transferableData = transferableData
 | 
			
		||||
    this.rawText = rawText
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  val text: String?
 | 
			
		||||
    get() {
 | 
			
		||||
      val builder = StringBuilder()
 | 
			
		||||
      for (key in keys) {
 | 
			
		||||
        val c = key.keyChar
 | 
			
		||||
        if (c == KeyEvent.CHAR_UNDEFINED) {
 | 
			
		||||
          return null
 | 
			
		||||
        }
 | 
			
		||||
        builder.append(c)
 | 
			
		||||
      }
 | 
			
		||||
      return builder.toString()
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
  val printableString: String
 | 
			
		||||
    get() = EngineStringHelper.toPrintableCharacters(keys) // should be the same as [text], but we can't render control notation properly
 | 
			
		||||
  
 | 
			
		||||
  /**
 | 
			
		||||
   * Append the supplied text to any existing text.
 | 
			
		||||
   */
 | 
			
		||||
  fun addTextAndResetTransferableData(text: String) {
 | 
			
		||||
    addKeys(injector.parser.stringToKeys(text))
 | 
			
		||||
    transferableData.clear()
 | 
			
		||||
  }
 | 
			
		||||
  
 | 
			
		||||
  fun prependTextAndResetTransferableData(text: String) {
 | 
			
		||||
    this.keys.addAll(0, injector.parser.stringToKeys(text))
 | 
			
		||||
    transferableData.clear()
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  fun addKeys(keys: List<KeyStroke>) {
 | 
			
		||||
    this.keys.addAll(keys)
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  object KeySorter : Comparator<Register> {
 | 
			
		||||
    @NonNls
 | 
			
		||||
@@ -38,27 +98,3 @@ data class Register(val name: Char,
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Imagine you yanked two lines and have the following content in your register a - foo\nbar\n (register type is line-wise)
 | 
			
		||||
 * Now, there are three different ways to append content, each with a different outcome:
 | 
			
		||||
 * - If you append a macro qAbazq, you'll get foo\nbarbaz\n in register `a` and it stays line-wise
 | 
			
		||||
 * - If you use Vim script and execute let @A = "baz", the result will be foo\nbar\nbaz and the register becomes character-wise
 | 
			
		||||
 * - If you copy "baz" to register A, it becomes foo\nbar\nbaz\n and stays line-wise
 | 
			
		||||
 *
 | 
			
		||||
 * At the moment, we will stick to the third option to not overcomplicate the plugin
 | 
			
		||||
 * (until there is a user who notices the difference)
 | 
			
		||||
 */
 | 
			
		||||
fun Register.addText(text: String): Register {
 | 
			
		||||
  return when (this.type) {
 | 
			
		||||
    SelectionType.CHARACTER_WISE -> {
 | 
			
		||||
      Register(this.name, injector.clipboardManager.dumbCopiedText(this.text + text), SelectionType.CHARACTER_WISE) // todo it's empty for historical reasons, but should we really clear transferable data?
 | 
			
		||||
    }
 | 
			
		||||
    SelectionType.LINE_WISE -> {
 | 
			
		||||
      Register(this.name, injector.clipboardManager.dumbCopiedText(this.text + text + (if (text.endsWith('\n')) "" else "\n")), SelectionType.LINE_WISE) // todo it's empty for historical reasons, but should we really clear transferable data?
 | 
			
		||||
    }
 | 
			
		||||
    SelectionType.BLOCK_WISE -> {
 | 
			
		||||
      Register(this.name, injector.clipboardManager.dumbCopiedText(this.text + "\n" + text), SelectionType.BLOCK_WISE) // todo it's empty for historical reasons, but should we really clear transferable data?
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -10,8 +10,8 @@ package com.maddyhome.idea.vim.register
 | 
			
		||||
import com.maddyhome.idea.vim.api.ExecutionContext
 | 
			
		||||
import com.maddyhome.idea.vim.api.ImmutableVimCaret
 | 
			
		||||
import com.maddyhome.idea.vim.api.VimEditor
 | 
			
		||||
import com.maddyhome.idea.vim.state.mode.SelectionType
 | 
			
		||||
import com.maddyhome.idea.vim.common.TextRange
 | 
			
		||||
import com.maddyhome.idea.vim.state.mode.SelectionType
 | 
			
		||||
import org.jetbrains.annotations.TestOnly
 | 
			
		||||
import javax.swing.KeyStroke
 | 
			
		||||
 | 
			
		||||
@@ -39,7 +39,6 @@ interface VimRegisterGroup {
 | 
			
		||||
  val isRegisterSpecifiedExplicitly: Boolean
 | 
			
		||||
  val defaultRegister: Char
 | 
			
		||||
 | 
			
		||||
  fun getLastRegister(editor: VimEditor, context: ExecutionContext): Register?
 | 
			
		||||
  fun isValid(reg: Char): Boolean
 | 
			
		||||
  fun selectRegister(reg: Char): Boolean
 | 
			
		||||
  fun resetRegister()
 | 
			
		||||
@@ -49,14 +48,6 @@ interface VimRegisterGroup {
 | 
			
		||||
  fun isRegisterWritable(reg: Char): Boolean
 | 
			
		||||
 | 
			
		||||
  /** Store text into the last register. */
 | 
			
		||||
  @Deprecated("Please use com.maddyhome.idea.vim.register.VimRegisterGroup#storeText(com.maddyhome.idea.vim.api.VimEditor, com.maddyhome.idea.vim.api.ExecutionContext, com.maddyhome.idea.vim.api.ImmutableVimCaret, com.maddyhome.idea.vim.common.TextRange, com.maddyhome.idea.vim.state.mode.SelectionType, boolean)")
 | 
			
		||||
  fun storeText(
 | 
			
		||||
    editor: VimEditor,
 | 
			
		||||
    caret: ImmutableVimCaret,
 | 
			
		||||
    range: TextRange,
 | 
			
		||||
    type: SelectionType,
 | 
			
		||||
    isDelete: Boolean,
 | 
			
		||||
  ): Boolean
 | 
			
		||||
  fun storeText(
 | 
			
		||||
    editor: VimEditor,
 | 
			
		||||
    context: ExecutionContext,
 | 
			
		||||
@@ -64,23 +55,19 @@ interface VimRegisterGroup {
 | 
			
		||||
    range: TextRange,
 | 
			
		||||
    type: SelectionType,
 | 
			
		||||
    isDelete: Boolean,
 | 
			
		||||
    forceAppend: Boolean = false,
 | 
			
		||||
    prependInsteadOfAppend: Boolean = false
 | 
			
		||||
  ): Boolean
 | 
			
		||||
 | 
			
		||||
  /**
 | 
			
		||||
   * Stores text to any writable register (used for the let command)
 | 
			
		||||
   */
 | 
			
		||||
  @Deprecated("Please use com.maddyhome.idea.vim.register.VimRegisterGroup#storeText(com.maddyhome.idea.vim.api.VimEditor, com.maddyhome.idea.vim.api.ExecutionContext, char, java.lang.String)")
 | 
			
		||||
  fun storeText(register: Char, text: String): Boolean
 | 
			
		||||
  fun storeText(editor: VimEditor, context: ExecutionContext, register: Char, text: String): Boolean
 | 
			
		||||
 | 
			
		||||
  /**
 | 
			
		||||
   * Stores text to any writable register (used for multicaret tests)
 | 
			
		||||
   */
 | 
			
		||||
  @TestOnly
 | 
			
		||||
  // todo better tests
 | 
			
		||||
  @Deprecated("Please use com.maddyhome.idea.vim.register.VimRegisterGroup#storeText(com.maddyhome.idea.vim.api.VimEditor, com.maddyhome.idea.vim.api.ExecutionContext, char, java.lang.String, com.maddyhome.idea.vim.state.mode.SelectionType)")
 | 
			
		||||
  fun storeText(register: Char, text: String, selectionType: SelectionType): Boolean
 | 
			
		||||
  @TestOnly
 | 
			
		||||
  fun storeText(editor: VimEditor, context: ExecutionContext, register: Char, text: String, selectionType: SelectionType): Boolean
 | 
			
		||||
 | 
			
		||||
  /**
 | 
			
		||||
@@ -100,22 +87,14 @@ interface VimRegisterGroup {
 | 
			
		||||
  @Deprecated("Please use com.maddyhome.idea.vim.register.VimRegisterGroup#getRegister(com.maddyhome.idea.vim.api.VimEditor, com.maddyhome.idea.vim.api.ExecutionContext, char)")
 | 
			
		||||
  fun getRegister(r: Char): Register?
 | 
			
		||||
  fun getRegister(editor: VimEditor, context: ExecutionContext, r: Char): Register?
 | 
			
		||||
  @Deprecated("Please use com.maddyhome.idea.vim.register.VimRegisterGroup#getRegisters(com.maddyhome.idea.vim.api.VimEditor, com.maddyhome.idea.vim.api.ExecutionContext)")
 | 
			
		||||
  fun getRegisters(): List<Register>
 | 
			
		||||
  fun getRegisters(editor: VimEditor, context: ExecutionContext): List<Register>
 | 
			
		||||
  @Deprecated("Please use com.maddyhome.idea.vim.register.VimRegisterGroup#saveRegister(com.maddyhome.idea.vim.api.VimEditor, com.maddyhome.idea.vim.api.ExecutionContext, char, com.maddyhome.idea.vim.register.Register)")
 | 
			
		||||
  fun saveRegister(r: Char, register: Register)
 | 
			
		||||
  fun saveRegister(editor: VimEditor, context: ExecutionContext, r: Char, register: Register)
 | 
			
		||||
  fun startRecording(register: Char): Boolean
 | 
			
		||||
 | 
			
		||||
  @Deprecated("Please use com.maddyhome.idea.vim.register.VimRegisterGroup#getPlaybackRegister(com.maddyhome.idea.vim.api.VimEditor, com.maddyhome.idea.vim.api.ExecutionContext, char)")
 | 
			
		||||
  fun getPlaybackRegister(r: Char): Register?
 | 
			
		||||
  fun getPlaybackRegister(editor: VimEditor, context: ExecutionContext, r: Char): Register?
 | 
			
		||||
  fun recordText(text: String)
 | 
			
		||||
  fun setKeys(register: Char, keys: List<KeyStroke>)
 | 
			
		||||
  fun setKeys(register: Char, keys: List<KeyStroke>, type: SelectionType)
 | 
			
		||||
  @Deprecated("Please use com.maddyhome.idea.vim.register.VimRegisterGroup#finishRecording(com.maddyhome.idea.vim.api.VimEditor, com.maddyhome.idea.vim.api.ExecutionContext)")
 | 
			
		||||
  fun finishRecording()
 | 
			
		||||
  fun finishRecording(editor: VimEditor, context: ExecutionContext)
 | 
			
		||||
  fun getCurrentRegisterForMulticaret(): Char // `set clipbaard+=unnamedplus` should not make system register the default one when working with multiple carets VIM-2804
 | 
			
		||||
  fun isSystemClipboard(register: Char): Boolean
 | 
			
		||||
 
 | 
			
		||||
@@ -17,7 +17,6 @@ import com.maddyhome.idea.vim.api.globalOptions
 | 
			
		||||
import com.maddyhome.idea.vim.api.injector
 | 
			
		||||
import com.maddyhome.idea.vim.command.Argument
 | 
			
		||||
import com.maddyhome.idea.vim.common.TextRange
 | 
			
		||||
import com.maddyhome.idea.vim.common.VimCopiedText
 | 
			
		||||
import com.maddyhome.idea.vim.diagnostic.VimLogger
 | 
			
		||||
import com.maddyhome.idea.vim.diagnostic.debug
 | 
			
		||||
import com.maddyhome.idea.vim.diagnostic.vimLogger
 | 
			
		||||
@@ -75,16 +74,11 @@ abstract class VimRegisterGroupBase : VimRegisterGroup {
 | 
			
		||||
  override val defaultRegister: Char
 | 
			
		||||
    get() = defaultRegisterChar
 | 
			
		||||
 | 
			
		||||
  override fun getLastRegister(editor: VimEditor, context: ExecutionContext): Register? {
 | 
			
		||||
    return getRegister(editor, context, lastRegisterChar)
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  /**
 | 
			
		||||
   * Get the last register selected by the user
 | 
			
		||||
   *
 | 
			
		||||
   * @return The register, null if no such register
 | 
			
		||||
   */
 | 
			
		||||
  @Deprecated("Please use com.maddyhome.idea.vim.register.VimRegisterGroup#getLastRegister(com.maddyhome.idea.vim.api.VimEditor, com.maddyhome.idea.vim.api.ExecutionContext)")
 | 
			
		||||
  override val lastRegister: Register?
 | 
			
		||||
    get() = getRegister(lastRegisterChar)
 | 
			
		||||
 | 
			
		||||
@@ -121,13 +115,20 @@ abstract class VimRegisterGroupBase : VimRegisterGroup {
 | 
			
		||||
    return if (isValid(reg)) {
 | 
			
		||||
      isRegisterSpecifiedExplicitly = true
 | 
			
		||||
      lastRegisterChar = reg
 | 
			
		||||
      logger.debug { "register selected: $lastRegisterChar" }
 | 
			
		||||
      logger.debug { "register selected: $lastRegister" }
 | 
			
		||||
 | 
			
		||||
      true
 | 
			
		||||
    } else {
 | 
			
		||||
      false
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  override fun getRegister(r: Char): Register? {
 | 
			
		||||
    val dummyEditor = injector.fallbackWindow
 | 
			
		||||
    val dummyContext = injector.executionContextManager.getEditorExecutionContext(dummyEditor)
 | 
			
		||||
    return getRegister(dummyEditor, dummyContext, r)
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  /**
 | 
			
		||||
   * Reset the selected register back to the default register.
 | 
			
		||||
   */
 | 
			
		||||
@@ -183,6 +184,8 @@ abstract class VimRegisterGroupBase : VimRegisterGroup {
 | 
			
		||||
    type: SelectionType,
 | 
			
		||||
    register: Char,
 | 
			
		||||
    isDelete: Boolean,
 | 
			
		||||
    forceAppend: Boolean,
 | 
			
		||||
    prependInsteadOfAppend: Boolean,
 | 
			
		||||
  ): Boolean {
 | 
			
		||||
    // Null register doesn't get saved, but acts like it was
 | 
			
		||||
    if (lastRegisterChar == BLACK_HOLE_REGISTER) return true
 | 
			
		||||
@@ -201,49 +204,62 @@ abstract class VimRegisterGroupBase : VimRegisterGroup {
 | 
			
		||||
      end = t
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    val copiedText = if (start != -1) { // FIXME: so, we had invalid ranges all the time?.. I've never handled such cases
 | 
			
		||||
      injector.clipboardManager.collectCopiedText(editor, context, range, text)
 | 
			
		||||
    } else {
 | 
			
		||||
      injector.clipboardManager.dumbCopiedText(text)
 | 
			
		||||
    }
 | 
			
		||||
    logger.debug { "Copy to '$lastRegisterChar' with copied text: $copiedText" }
 | 
			
		||||
    // If this is an uppercase register, we need to append the text to the corresponding lowercase register
 | 
			
		||||
    if (Character.isUpperCase(register)) {
 | 
			
		||||
    val transferableData: List<Any> =
 | 
			
		||||
      if (start != -1) injector.clipboardManager.getTransferableData(editor, range) else ArrayList()
 | 
			
		||||
    var processedText =
 | 
			
		||||
      if (start != -1) injector.clipboardManager.preprocessText(editor, range, text, transferableData) else text
 | 
			
		||||
    logger.debug {
 | 
			
		||||
      val transferableClasses = transferableData.joinToString(",") { it.javaClass.name }
 | 
			
		||||
      "Copy to '$lastRegister' with transferable data: $transferableClasses"
 | 
			
		||||
    }
 | 
			
		||||
    if (Character.isUpperCase(register) || forceAppend) {
 | 
			
		||||
      if (forceAppend && type == SelectionType.CHARACTER_WISE) {
 | 
			
		||||
        processedText = if (prependInsteadOfAppend)
 | 
			
		||||
          processedText + '\n'
 | 
			
		||||
        else
 | 
			
		||||
          '\n' + processedText
 | 
			
		||||
      }
 | 
			
		||||
      val lreg = Character.toLowerCase(register)
 | 
			
		||||
      val r = myRegisters[lreg]
 | 
			
		||||
      // Append the text if the lowercase register existed
 | 
			
		||||
      if (r != null) {
 | 
			
		||||
        myRegisters[lreg] = r.addText(copiedText.text)
 | 
			
		||||
        if (prependInsteadOfAppend) {
 | 
			
		||||
          r.prependTextAndResetTransferableData(processedText)
 | 
			
		||||
        }
 | 
			
		||||
        else {
 | 
			
		||||
          r.addTextAndResetTransferableData(processedText)
 | 
			
		||||
        }
 | 
			
		||||
      } else {
 | 
			
		||||
        myRegisters[lreg] = Register(lreg, copiedText, type)
 | 
			
		||||
        logger.debug { "register '$register' contains: \"$copiedText\"" }
 | 
			
		||||
        myRegisters[lreg] = Register(lreg, type, processedText, ArrayList(transferableData))
 | 
			
		||||
        logger.debug { "register '$register' contains: \"$processedText\"" }
 | 
			
		||||
      } // Set the text if the lowercase register didn't exist yet
 | 
			
		||||
    } else {
 | 
			
		||||
      myRegisters[register] = Register(register, copiedText, type)
 | 
			
		||||
      logger.debug { "register '$register' contains: \"$copiedText\"" }
 | 
			
		||||
      myRegisters[register] = Register(register, type, processedText, ArrayList(transferableData))
 | 
			
		||||
      logger.debug { "register '$register' contains: \"$processedText\"" }
 | 
			
		||||
    } // Put the text in the specified register
 | 
			
		||||
 | 
			
		||||
    if (register == CLIPBOARD_REGISTER) {
 | 
			
		||||
      injector.clipboardManager.setClipboardContent(editor, context, copiedText)
 | 
			
		||||
      injector.clipboardManager.setClipboardText(processedText, text, ArrayList(transferableData))
 | 
			
		||||
      if (!isRegisterSpecifiedExplicitly && !isDelete && isPrimaryRegisterSupported() && OptionConstants.clipboard_unnamedplus in injector.globalOptions().clipboard) {
 | 
			
		||||
        injector.clipboardManager.setPrimaryContent(editor, context, copiedText)
 | 
			
		||||
        injector.clipboardManager.setPrimaryText(processedText, text, ArrayList(transferableData))
 | 
			
		||||
      }
 | 
			
		||||
    }
 | 
			
		||||
    if (register == PRIMARY_REGISTER) {
 | 
			
		||||
      if (isPrimaryRegisterSupported()) {
 | 
			
		||||
        injector.clipboardManager.setPrimaryContent(editor, context, copiedText)
 | 
			
		||||
        injector.clipboardManager.setPrimaryText(processedText, text, ArrayList(transferableData))
 | 
			
		||||
        if (!isRegisterSpecifiedExplicitly && !isDelete && OptionConstants.clipboard_unnamed in injector.globalOptions().clipboard) {
 | 
			
		||||
          injector.clipboardManager.setClipboardContent(editor, context, copiedText)
 | 
			
		||||
          injector.clipboardManager.setClipboardText(processedText, text, ArrayList(transferableData))
 | 
			
		||||
        }
 | 
			
		||||
      } else {
 | 
			
		||||
        injector.clipboardManager.setClipboardContent(editor, context, copiedText)
 | 
			
		||||
        injector.clipboardManager.setClipboardText(processedText, text, ArrayList(transferableData))
 | 
			
		||||
      }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    // Also add it to the unnamed register if the default wasn't specified
 | 
			
		||||
    if (register != UNNAMED_REGISTER && ".:/".indexOf(register) == -1) {
 | 
			
		||||
      myRegisters[UNNAMED_REGISTER] = Register(UNNAMED_REGISTER, copiedText, type)
 | 
			
		||||
      logger.debug { "register '$UNNAMED_REGISTER' contains: \"$copiedText\"" }
 | 
			
		||||
      myRegisters[UNNAMED_REGISTER] = Register(UNNAMED_REGISTER, type, processedText, ArrayList(transferableData))
 | 
			
		||||
      logger.debug { "register '$UNNAMED_REGISTER' contains: \"$processedText\"" }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    if (isDelete) {
 | 
			
		||||
@@ -263,37 +279,26 @@ abstract class VimRegisterGroupBase : VimRegisterGroup {
 | 
			
		||||
        while (d >= '1') {
 | 
			
		||||
          val t = myRegisters[d]
 | 
			
		||||
          if (t != null) {
 | 
			
		||||
            val incName = (d.code + 1).toChar()
 | 
			
		||||
            myRegisters[incName] = Register(incName, t.copiedText, t.type)
 | 
			
		||||
            t.name = (d.code + 1).toChar()
 | 
			
		||||
            myRegisters[(d.code + 1).toChar()] = t
 | 
			
		||||
          }
 | 
			
		||||
          d--
 | 
			
		||||
        }
 | 
			
		||||
        myRegisters['1'] = Register('1', copiedText, type)
 | 
			
		||||
        myRegisters['1'] = Register('1', type, processedText, ArrayList(transferableData))
 | 
			
		||||
      }
 | 
			
		||||
 | 
			
		||||
      // Deletes smaller than one line and without specified register go the the "-" register
 | 
			
		||||
      if (smallInlineDeletion && register == defaultRegister) {
 | 
			
		||||
        myRegisters[SMALL_DELETION_REGISTER] =
 | 
			
		||||
          Register(SMALL_DELETION_REGISTER, copiedText, type)
 | 
			
		||||
          Register(SMALL_DELETION_REGISTER, type, processedText, ArrayList(transferableData))
 | 
			
		||||
      }
 | 
			
		||||
    } else if (register == defaultRegister) {
 | 
			
		||||
      myRegisters['0'] = Register('0', copiedText, type)
 | 
			
		||||
      logger.debug { "register '0' contains: \"$copiedText\"" }
 | 
			
		||||
      myRegisters['0'] = Register('0', type, processedText, ArrayList(transferableData))
 | 
			
		||||
      logger.debug { "register '0' contains: \"$processedText\"" }
 | 
			
		||||
    } // Yanks also go to register 0 if the default register was used
 | 
			
		||||
    return true
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  @Deprecated("Please use com.maddyhome.idea.vim.register.VimRegisterGroup#storeText(com.maddyhome.idea.vim.api.VimEditor, com.maddyhome.idea.vim.api.ExecutionContext, com.maddyhome.idea.vim.api.ImmutableVimCaret, com.maddyhome.idea.vim.common.TextRange, com.maddyhome.idea.vim.state.mode.SelectionType, boolean)")
 | 
			
		||||
  override fun storeText(
 | 
			
		||||
    editor: VimEditor,
 | 
			
		||||
    caret: ImmutableVimCaret,
 | 
			
		||||
    range: TextRange,
 | 
			
		||||
    type: SelectionType,
 | 
			
		||||
    isDelete: Boolean
 | 
			
		||||
  ): Boolean {
 | 
			
		||||
    return storeText(editor, injector.executionContextManager.getEditorExecutionContext(editor), caret, range, type, isDelete)
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  
 | 
			
		||||
  /**
 | 
			
		||||
   * Store text into the last register.
 | 
			
		||||
   *
 | 
			
		||||
@@ -310,10 +315,12 @@ abstract class VimRegisterGroupBase : VimRegisterGroup {
 | 
			
		||||
    range: TextRange,
 | 
			
		||||
    type: SelectionType,
 | 
			
		||||
    isDelete: Boolean,
 | 
			
		||||
    forceAppend: Boolean,
 | 
			
		||||
    prependInsteadOfAppend: Boolean
 | 
			
		||||
  ): Boolean {
 | 
			
		||||
    if (isRegisterWritable()) {
 | 
			
		||||
      val text = preprocessTextBeforeStoring(editor.getText(range), type)
 | 
			
		||||
      return storeTextInternal(editor, context, range, text, type, lastRegisterChar, isDelete)
 | 
			
		||||
      return storeTextInternal(editor, context, range, text, type, lastRegisterChar, isDelete, forceAppend, prependInsteadOfAppend)
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    return false
 | 
			
		||||
@@ -348,59 +355,32 @@ abstract class VimRegisterGroupBase : VimRegisterGroup {
 | 
			
		||||
    if (READONLY_REGISTERS.indexOf(register) == -1 && register != LAST_SEARCH_REGISTER && register != UNNAMED_REGISTER) {
 | 
			
		||||
      return false
 | 
			
		||||
    }
 | 
			
		||||
    myRegisters[register] = Register(register, injector.clipboardManager.dumbCopiedText(text), SelectionType.CHARACTER_WISE) // TODO why transferable data is not collected?
 | 
			
		||||
    myRegisters[register] = Register(register, SelectionType.CHARACTER_WISE, text, ArrayList())
 | 
			
		||||
    logger.debug { "register '$register' contains: \"$text\"" }
 | 
			
		||||
    return true
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  @Deprecated("Please use com.maddyhome.idea.vim.register.VimRegisterGroup#getRegister(com.maddyhome.idea.vim.api.VimEditor, com.maddyhome.idea.vim.api.ExecutionContext, char)")
 | 
			
		||||
  override fun getRegister(r: Char): Register? {
 | 
			
		||||
    val dummyEditor = injector.fallbackWindow
 | 
			
		||||
    val dummyContext = injector.executionContextManager.getEditorExecutionContext(dummyEditor)
 | 
			
		||||
    return getRegister(dummyEditor, dummyContext, r)
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  @Deprecated("Please use com.maddyhome.idea.vim.register.VimRegisterGroup#storeText(com.maddyhome.idea.vim.api.VimEditor, com.maddyhome.idea.vim.api.ExecutionContext, char, java.lang.String, com.maddyhome.idea.vim.state.mode.SelectionType)")
 | 
			
		||||
  override fun storeText(register: Char, text: String, selectionType: SelectionType): Boolean {
 | 
			
		||||
    val dummyEditor = injector.fallbackWindow
 | 
			
		||||
    val dummyContext = injector.executionContextManager.getEditorExecutionContext(dummyEditor)
 | 
			
		||||
    return storeText(dummyEditor, dummyContext, register, text, selectionType)
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  override fun storeText(
 | 
			
		||||
    editor: VimEditor,
 | 
			
		||||
    context: ExecutionContext,
 | 
			
		||||
    register: Char,
 | 
			
		||||
    text: String,
 | 
			
		||||
    selectionType: SelectionType
 | 
			
		||||
  ): Boolean {
 | 
			
		||||
    if (!WRITABLE_REGISTERS.contains(register)) {
 | 
			
		||||
      return false
 | 
			
		||||
    }
 | 
			
		||||
    logger.debug { "register '$register' contains: \"$text\"" }
 | 
			
		||||
    val oldRegister = getRegister(editor, context, register.lowercaseChar())
 | 
			
		||||
    val newRegister = if (register.isUpperCase() && oldRegister != null) {
 | 
			
		||||
      oldRegister.addText(text)
 | 
			
		||||
    } else {
 | 
			
		||||
      Register(register, injector.clipboardManager.dumbCopiedText(text), selectionType) // FIXME why don't we collect transferable data?
 | 
			
		||||
    }
 | 
			
		||||
    saveRegister(editor, context, register, newRegister)
 | 
			
		||||
    if (register == '/') {
 | 
			
		||||
      injector.searchGroup.lastSearchPattern = text // todo we should not have this field if we have the "/" register
 | 
			
		||||
    }
 | 
			
		||||
    return true
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  @Deprecated("Please use com.maddyhome.idea.vim.register.VimRegisterGroup#storeText(com.maddyhome.idea.vim.api.VimEditor, com.maddyhome.idea.vim.api.ExecutionContext, char, java.lang.String)")
 | 
			
		||||
  override fun storeText(register: Char, text: String): Boolean {
 | 
			
		||||
    val dummyEditor = injector.fallbackWindow
 | 
			
		||||
    val dummyContext = injector.executionContextManager.getEditorExecutionContext(dummyEditor)
 | 
			
		||||
    return storeText(dummyEditor, dummyContext, register, text)
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  override fun storeText(editor: VimEditor, context: ExecutionContext, register: Char, text: String): Boolean {
 | 
			
		||||
    return storeText(editor, context, register, text, SelectionType.CHARACTER_WISE)
 | 
			
		||||
  }
 | 
			
		||||
  
 | 
			
		||||
  override fun storeText(editor: VimEditor, context: ExecutionContext, register: Char, text: String, selectionType: SelectionType): Boolean {
 | 
			
		||||
    if (!WRITABLE_REGISTERS.contains(register)) {
 | 
			
		||||
      return false
 | 
			
		||||
    }
 | 
			
		||||
    logger.debug { "register '$register' contains: \"$text\"" }
 | 
			
		||||
    val textToStore = if (register.isUpperCase()) {
 | 
			
		||||
      (getRegister(register.lowercaseChar())?.rawText ?: "") + text
 | 
			
		||||
    } else {
 | 
			
		||||
      text
 | 
			
		||||
    }
 | 
			
		||||
    val reg = Register(register, selectionType, textToStore, ArrayList())
 | 
			
		||||
    saveRegister(editor, context, register, reg)
 | 
			
		||||
    if (register == '/') {
 | 
			
		||||
      injector.searchGroup.lastSearchPattern = text // todo we should not have this field if we have the "/" register
 | 
			
		||||
    }
 | 
			
		||||
    return true
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  private fun guessSelectionType(text: String): SelectionType {
 | 
			
		||||
    return if (text.endsWith("\n")) SelectionType.LINE_WISE else SelectionType.CHARACTER_WISE
 | 
			
		||||
@@ -413,10 +393,10 @@ abstract class VimRegisterGroupBase : VimRegisterGroup {
 | 
			
		||||
   * @param r - the register character corresponding to either the primary selection (*) or clipboard selection (+)
 | 
			
		||||
   * @return the content of the selection, if available, otherwise null
 | 
			
		||||
   */
 | 
			
		||||
  private fun refreshClipboardRegister(editor: VimEditor, context: ExecutionContext, r: Char): Register? {
 | 
			
		||||
  private fun refreshClipboardRegister(r: Char): Register? {
 | 
			
		||||
    return when (r) {
 | 
			
		||||
      PRIMARY_REGISTER -> refreshPrimaryRegister(editor, context)
 | 
			
		||||
      CLIPBOARD_REGISTER -> refreshClipboardRegister(editor, context)
 | 
			
		||||
      PRIMARY_REGISTER -> refreshPrimaryRegister()
 | 
			
		||||
      CLIPBOARD_REGISTER -> refreshClipboardRegister()
 | 
			
		||||
      else -> throw RuntimeException("Clipboard register expected, got $r")
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
@@ -425,56 +405,60 @@ abstract class VimRegisterGroupBase : VimRegisterGroup {
 | 
			
		||||
    return System.getenv("DISPLAY") != null && injector.systemInfoService.isXWindow
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  private fun setSystemPrimaryRegisterText(editor: VimEditor, context: ExecutionContext, copiedText: VimCopiedText) {
 | 
			
		||||
    logger.trace("Setting text: $copiedText to primary selection...")
 | 
			
		||||
  private fun setSystemPrimaryRegisterText(text: String, rawText: String, transferableData: List<Any>) {
 | 
			
		||||
    logger.trace("Setting text: $text to primary selection...")
 | 
			
		||||
    if (isPrimaryRegisterSupported()) {
 | 
			
		||||
      try {
 | 
			
		||||
        injector.clipboardManager.setPrimaryContent(editor, context, copiedText)
 | 
			
		||||
        injector.clipboardManager.setPrimaryText(text, rawText, transferableData)
 | 
			
		||||
      } catch (e: Exception) {
 | 
			
		||||
        logger.warn("False positive X11 primary selection support")
 | 
			
		||||
        logger.trace("Setting text to primary selection failed. Setting it to clipboard selection instead")
 | 
			
		||||
        setSystemClipboardRegisterText(editor, context, copiedText)
 | 
			
		||||
        setSystemClipboardRegisterText(text, rawText, transferableData)
 | 
			
		||||
      }
 | 
			
		||||
    } else {
 | 
			
		||||
      logger.trace("X11 primary selection is not supporting. Setting clipboard selection instead")
 | 
			
		||||
      setSystemClipboardRegisterText(editor, context, copiedText)
 | 
			
		||||
      setSystemClipboardRegisterText(text, rawText, transferableData)
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  private fun setSystemClipboardRegisterText(editor: VimEditor, context: ExecutionContext, copiedText: VimCopiedText) {
 | 
			
		||||
    injector.clipboardManager.setClipboardContent(editor, context, copiedText)
 | 
			
		||||
  private fun setSystemClipboardRegisterText(text: String, rawText: String, transferableData: List<Any>) {
 | 
			
		||||
    injector.clipboardManager.setClipboardText(text, rawText, transferableData)
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  private fun refreshPrimaryRegister(editor: VimEditor, context: ExecutionContext): Register? {
 | 
			
		||||
  private fun refreshPrimaryRegister(): Register? {
 | 
			
		||||
    logger.trace("Syncing cached primary selection value..")
 | 
			
		||||
    if (!isPrimaryRegisterSupported()) {
 | 
			
		||||
      logger.trace("X11 primary selection is not supported. Syncing clipboard selection..")
 | 
			
		||||
      return refreshClipboardRegister(editor, context)
 | 
			
		||||
      return refreshClipboardRegister()
 | 
			
		||||
    }
 | 
			
		||||
    try {
 | 
			
		||||
      val clipboardData = injector.clipboardManager.getPrimaryContent(editor, context) ?: return null
 | 
			
		||||
      val clipboardData = injector.clipboardManager.getPrimaryTextAndTransferableData() ?: return null
 | 
			
		||||
      val currentRegister = myRegisters[PRIMARY_REGISTER]
 | 
			
		||||
      if (currentRegister != null && clipboardData.text == currentRegister.text) {
 | 
			
		||||
      val text = clipboardData.first
 | 
			
		||||
      val transferableData = clipboardData.second?.toMutableList()
 | 
			
		||||
      if (currentRegister != null && text == currentRegister.text) {
 | 
			
		||||
        return currentRegister
 | 
			
		||||
      }
 | 
			
		||||
      return Register(PRIMARY_REGISTER, clipboardData, guessSelectionType(clipboardData.text))
 | 
			
		||||
      return transferableData?.let { Register(PRIMARY_REGISTER, guessSelectionType(text), text, it) }
 | 
			
		||||
    } catch (e: Exception) {
 | 
			
		||||
      logger.warn("False positive X11 primary selection support")
 | 
			
		||||
      logger.trace("Syncing primary selection failed. Syncing clipboard selection instead")
 | 
			
		||||
      return refreshClipboardRegister(editor, context)
 | 
			
		||||
      return refreshClipboardRegister()
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  private fun refreshClipboardRegister(editor: VimEditor, context: ExecutionContext): Register? {
 | 
			
		||||
  private fun refreshClipboardRegister(): Register? {
 | 
			
		||||
    // for some reason non-X systems use PRIMARY_REGISTER as a clipboard storage
 | 
			
		||||
    val systemAwareClipboardRegister = if (isPrimaryRegisterSupported()) CLIPBOARD_REGISTER else PRIMARY_REGISTER
 | 
			
		||||
 | 
			
		||||
    val clipboardData = injector.clipboardManager.getClipboardContent(editor, context) ?: return null
 | 
			
		||||
    val clipboardData = injector.clipboardManager.getClipboardTextAndTransferableData() ?: return null
 | 
			
		||||
    val currentRegister = myRegisters[systemAwareClipboardRegister]
 | 
			
		||||
    if (currentRegister != null && clipboardData.text == currentRegister.text) {
 | 
			
		||||
    val text = clipboardData.first
 | 
			
		||||
    val transferableData = clipboardData.second?.toMutableList()
 | 
			
		||||
    if (currentRegister != null && text == currentRegister.text) {
 | 
			
		||||
      return currentRegister
 | 
			
		||||
    }
 | 
			
		||||
    return Register(systemAwareClipboardRegister, clipboardData, guessSelectionType(clipboardData.text))
 | 
			
		||||
    return transferableData?.let { Register(systemAwareClipboardRegister, guessSelectionType(text), text, it) }
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  override fun getRegister(editor: VimEditor, context: ExecutionContext, r: Char): Register? {
 | 
			
		||||
@@ -483,46 +467,34 @@ abstract class VimRegisterGroupBase : VimRegisterGroup {
 | 
			
		||||
    if (Character.isUpperCase(myR)) {
 | 
			
		||||
      myR = Character.toLowerCase(myR)
 | 
			
		||||
    }
 | 
			
		||||
    return if (CLIPBOARD_REGISTERS.indexOf(myR) >= 0) refreshClipboardRegister(editor, context, myR) else myRegisters[myR]
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  @Deprecated("Please use com.maddyhome.idea.vim.register.VimRegisterGroup#getRegisters(com.maddyhome.idea.vim.api.VimEditor, com.maddyhome.idea.vim.api.ExecutionContext)")
 | 
			
		||||
  override fun getRegisters(): List<Register> {
 | 
			
		||||
    val dummyEditor = injector.fallbackWindow
 | 
			
		||||
    val dummyContext = injector.executionContextManager.getEditorExecutionContext(dummyEditor)
 | 
			
		||||
    return getRegisters(dummyEditor, dummyContext)
 | 
			
		||||
    return if (CLIPBOARD_REGISTERS.indexOf(myR) >= 0) refreshClipboardRegister(myR) else myRegisters[myR]
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  override fun getRegisters(editor: VimEditor, context: ExecutionContext): List<Register> {
 | 
			
		||||
    val filteredRegisters = myRegisters.values.filterNot { CLIPBOARD_REGISTERS.contains(it.name) }.toMutableList()
 | 
			
		||||
    val clipboardRegisters = CLIPBOARD_REGISTERS
 | 
			
		||||
      .filterNot { it == CLIPBOARD_REGISTER && !isPrimaryRegisterSupported() } // for some reason non-X systems use PRIMARY_REGISTER as a clipboard storage
 | 
			
		||||
      .mapNotNull { refreshClipboardRegister(editor, context, it) }
 | 
			
		||||
      .mapNotNull { refreshClipboardRegister(it) }
 | 
			
		||||
 | 
			
		||||
    return (filteredRegisters + clipboardRegisters).sortedWith(Register.KeySorter)
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  @Deprecated("Please use com.maddyhome.idea.vim.register.VimRegisterGroup#saveRegister(com.maddyhome.idea.vim.api.VimEditor, com.maddyhome.idea.vim.api.ExecutionContext, char, com.maddyhome.idea.vim.register.Register)")
 | 
			
		||||
  override fun saveRegister(r: Char, register: Register) {
 | 
			
		||||
    val dummyEditor = injector.fallbackWindow
 | 
			
		||||
    val dummyContext = injector.executionContextManager.getEditorExecutionContext(dummyEditor)
 | 
			
		||||
    saveRegister(dummyEditor, dummyContext, r, register)
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  override fun saveRegister(editor: VimEditor, context: ExecutionContext, r: Char, register: Register) {
 | 
			
		||||
    var myR = if (Character.isUpperCase(r)) Character.toLowerCase(r) else r
 | 
			
		||||
    val text = register.text
 | 
			
		||||
    val rawText = register.rawText
 | 
			
		||||
 | 
			
		||||
    if (CLIPBOARD_REGISTERS.indexOf(myR) >= 0) {
 | 
			
		||||
    if (CLIPBOARD_REGISTERS.indexOf(myR) >= 0 && text != null && rawText != null) {
 | 
			
		||||
      when (myR) {
 | 
			
		||||
        CLIPBOARD_REGISTER -> {
 | 
			
		||||
          if (!isPrimaryRegisterSupported()) {
 | 
			
		||||
            // it looks wrong, but for some reason non-X systems use the * register to store the clipboard content
 | 
			
		||||
            myR = PRIMARY_REGISTER
 | 
			
		||||
          }
 | 
			
		||||
          setSystemClipboardRegisterText(editor, context, register.copiedText)
 | 
			
		||||
          setSystemClipboardRegisterText(text, rawText, ArrayList(register.transferableData))
 | 
			
		||||
        }
 | 
			
		||||
        PRIMARY_REGISTER -> {
 | 
			
		||||
          setSystemPrimaryRegisterText(editor, context, register.copiedText)
 | 
			
		||||
          setSystemPrimaryRegisterText(text, rawText, ArrayList(register.transferableData))
 | 
			
		||||
        }
 | 
			
		||||
      }
 | 
			
		||||
    }
 | 
			
		||||
@@ -539,15 +511,8 @@ abstract class VimRegisterGroupBase : VimRegisterGroup {
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  @Deprecated("Please use com.maddyhome.idea.vim.register.VimRegisterGroup#getPlaybackRegister(com.maddyhome.idea.vim.api.VimEditor, com.maddyhome.idea.vim.api.ExecutionContext, char)")
 | 
			
		||||
  override fun getPlaybackRegister(r: Char): Register? {
 | 
			
		||||
    val dummyEditor = injector.fallbackWindow
 | 
			
		||||
    val dummyContext = injector.executionContextManager.getEditorExecutionContext(dummyEditor)
 | 
			
		||||
    return getPlaybackRegister(dummyEditor, dummyContext, r)
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  override fun getPlaybackRegister(editor: VimEditor, context: ExecutionContext, r: Char): Register? {
 | 
			
		||||
    return if (PLAYBACK_REGISTERS.indexOf(r) != 0) getRegister(editor, context, r) else null
 | 
			
		||||
    return if (PLAYBACK_REGISTERS.indexOf(r) != 0) getRegister(r) else null
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  override fun recordText(text: String) {
 | 
			
		||||
@@ -565,19 +530,12 @@ abstract class VimRegisterGroupBase : VimRegisterGroup {
 | 
			
		||||
    myRegisters[register] = Register(register, type, keys.toMutableList())
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  @Deprecated("Please use com.maddyhome.idea.vim.register.VimRegisterGroup#finishRecording(com.maddyhome.idea.vim.api.VimEditor, com.maddyhome.idea.vim.api.ExecutionContext)")
 | 
			
		||||
  override fun finishRecording() {
 | 
			
		||||
    val dummyEditor = injector.fallbackWindow
 | 
			
		||||
    val dummyContext = injector.executionContextManager.getEditorExecutionContext(dummyEditor)
 | 
			
		||||
    finishRecording(dummyEditor, dummyContext)
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  override fun finishRecording(editor: VimEditor, context: ExecutionContext) {
 | 
			
		||||
    val register = recordRegister
 | 
			
		||||
    if (register != null) {
 | 
			
		||||
      var reg: Register? = null
 | 
			
		||||
      if (Character.isUpperCase(register)) {
 | 
			
		||||
        reg = getRegister(editor, context, register)
 | 
			
		||||
        reg = getRegister(register)
 | 
			
		||||
      }
 | 
			
		||||
 | 
			
		||||
      val myRecordList = recordList
 | 
			
		||||
@@ -586,7 +544,7 @@ abstract class VimRegisterGroupBase : VimRegisterGroup {
 | 
			
		||||
          reg = Register(Character.toLowerCase(register), SelectionType.CHARACTER_WISE, myRecordList)
 | 
			
		||||
          myRegisters[Character.toLowerCase(register)] = reg
 | 
			
		||||
        } else {
 | 
			
		||||
          myRegisters[reg.name.lowercaseChar()] = reg.addText(injector.parser.toPrintableString(myRecordList))
 | 
			
		||||
          reg.addKeys(myRecordList)
 | 
			
		||||
        }
 | 
			
		||||
      }
 | 
			
		||||
    }
 | 
			
		||||
 
 | 
			
		||||
@@ -33,7 +33,7 @@ data class CopyTextCommand(val range: Range, val modifier: CommandModifier, val
 | 
			
		||||
    val carets = editor.sortedCarets()
 | 
			
		||||
    for (caret in carets) {
 | 
			
		||||
      val range = getLineRange(editor, caret).toTextRange(editor)
 | 
			
		||||
      val copiedText = injector.clipboardManager.collectCopiedText(editor, context, range)
 | 
			
		||||
      val text = editor.getText(range)
 | 
			
		||||
 | 
			
		||||
      // Copy is defined as:
 | 
			
		||||
      // :[range]co[py] {address}
 | 
			
		||||
@@ -42,7 +42,8 @@ data class CopyTextCommand(val range: Range, val modifier: CommandModifier, val
 | 
			
		||||
      // the line _before_ the first line (i.e., copy to above the first line).
 | 
			
		||||
      val address1 = getAddressFromArgument(editor)
 | 
			
		||||
 | 
			
		||||
      val textData = PutData.TextData(null, copiedText, SelectionType.LINE_WISE)
 | 
			
		||||
      val transferableData = injector.clipboardManager.getTransferableData(editor, range)
 | 
			
		||||
      val textData = PutData.TextData(text, SelectionType.LINE_WISE, transferableData, null)
 | 
			
		||||
      var mutableCaret = caret
 | 
			
		||||
      val putData = if (address1 == 0) {
 | 
			
		||||
        // TODO: This should maintain current column location
 | 
			
		||||
 
 | 
			
		||||
@@ -83,7 +83,7 @@ data class MoveTextCommand(val range: Range, val modifier: CommandModifier, val
 | 
			
		||||
    val selectionEndOffset = lastSelectionInfo.end?.let { editor.bufferPositionToOffset(it) }
 | 
			
		||||
 | 
			
		||||
    val text = editor.getText(range)
 | 
			
		||||
    val textData = PutData.TextData(null, injector.clipboardManager.dumbCopiedText(text), SelectionType.LINE_WISE)
 | 
			
		||||
    val textData = PutData.TextData(text, SelectionType.LINE_WISE, emptyList(), null)
 | 
			
		||||
 | 
			
		||||
    val dropNewLineInEnd = (line + linesMoved == editor.lineCount() - 1 && text.last() == '\n') ||
 | 
			
		||||
      (lineRange.endLine == editor.lineCount() - 1)
 | 
			
		||||
 
 | 
			
		||||
@@ -13,9 +13,9 @@ import com.maddyhome.idea.vim.api.ExecutionContext
 | 
			
		||||
import com.maddyhome.idea.vim.api.VimEditor
 | 
			
		||||
import com.maddyhome.idea.vim.api.injector
 | 
			
		||||
import com.maddyhome.idea.vim.command.OperatorArguments
 | 
			
		||||
import com.maddyhome.idea.vim.state.mode.SelectionType
 | 
			
		||||
import com.maddyhome.idea.vim.ex.ranges.Range
 | 
			
		||||
import com.maddyhome.idea.vim.put.PutData
 | 
			
		||||
import com.maddyhome.idea.vim.state.mode.SelectionType
 | 
			
		||||
import com.maddyhome.idea.vim.vimscript.model.ExecutionResult
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
@@ -42,7 +42,12 @@ data class PutLinesCommand(val range: Range, val modifier: CommandModifier, val
 | 
			
		||||
 | 
			
		||||
    val line = if (range.size() == 0) -1 else getLine(editor)
 | 
			
		||||
    val textData = registerGroup.getRegister(editor, context, registerGroup.lastRegisterChar)?.let {
 | 
			
		||||
      PutData.TextData(null, it.copiedText, SelectionType.LINE_WISE)
 | 
			
		||||
      PutData.TextData(
 | 
			
		||||
        it.text ?: injector.parser.toKeyNotation(it.keys),
 | 
			
		||||
        SelectionType.LINE_WISE,
 | 
			
		||||
        it.transferableData,
 | 
			
		||||
        null,
 | 
			
		||||
      )
 | 
			
		||||
    }
 | 
			
		||||
    val putData = PutData(
 | 
			
		||||
      textData,
 | 
			
		||||
 
 | 
			
		||||
@@ -13,8 +13,9 @@ import com.maddyhome.idea.vim.api.ExecutionContext
 | 
			
		||||
import com.maddyhome.idea.vim.api.VimEditor
 | 
			
		||||
import com.maddyhome.idea.vim.api.injector
 | 
			
		||||
import com.maddyhome.idea.vim.command.OperatorArguments
 | 
			
		||||
import com.maddyhome.idea.vim.state.mode.SelectionType
 | 
			
		||||
import com.maddyhome.idea.vim.ex.ranges.Range
 | 
			
		||||
import com.maddyhome.idea.vim.helper.EngineStringHelper
 | 
			
		||||
import com.maddyhome.idea.vim.state.mode.SelectionType
 | 
			
		||||
import com.maddyhome.idea.vim.vimscript.model.ExecutionResult
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
@@ -36,7 +37,8 @@ data class RegistersCommand(val range: Range, val modifier: CommandModifier, val
 | 
			
		||||
          SelectionType.CHARACTER_WISE -> "c"
 | 
			
		||||
          SelectionType.BLOCK_WISE -> "b"
 | 
			
		||||
        }
 | 
			
		||||
        "  $type  \"${reg.name}   ${reg.printableString.take(200)}"
 | 
			
		||||
        val text = reg.rawText?.let { injector.parser.parseKeys(it) } ?: reg.keys
 | 
			
		||||
        "  $type  \"${reg.name}   ${EngineStringHelper.toPrintableCharacters(text).take(200)}"
 | 
			
		||||
      }
 | 
			
		||||
 | 
			
		||||
    injector.outputPanel.output(editor, context, regs)
 | 
			
		||||
 
 | 
			
		||||
@@ -12,8 +12,8 @@ import com.maddyhome.idea.vim.api.ExecutionContext
 | 
			
		||||
import com.maddyhome.idea.vim.api.VimEditor
 | 
			
		||||
import com.maddyhome.idea.vim.command.Argument
 | 
			
		||||
import com.maddyhome.idea.vim.command.OperatorArguments
 | 
			
		||||
import com.maddyhome.idea.vim.state.mode.SelectionType
 | 
			
		||||
import com.maddyhome.idea.vim.common.TextRange
 | 
			
		||||
import com.maddyhome.idea.vim.state.mode.SelectionType
 | 
			
		||||
 | 
			
		||||
interface VimYankGroup {
 | 
			
		||||
  /**
 | 
			
		||||
@@ -38,8 +38,6 @@ interface VimYankGroup {
 | 
			
		||||
   * @param count  The number of lines to yank
 | 
			
		||||
   * @return true if able to yank the lines, false if not
 | 
			
		||||
   */
 | 
			
		||||
  @Deprecated("Please use the same method, but with ExecutionContext")
 | 
			
		||||
  fun yankLine(editor: VimEditor, count: Int): Boolean
 | 
			
		||||
  fun yankLine(editor: VimEditor, context: ExecutionContext, count: Int): Boolean
 | 
			
		||||
 | 
			
		||||
  /**
 | 
			
		||||
@@ -50,7 +48,5 @@ interface VimYankGroup {
 | 
			
		||||
   * @param type   The type of yank
 | 
			
		||||
   * @return true if able to yank the range, false if not
 | 
			
		||||
   */
 | 
			
		||||
  @Deprecated("Please use the same method, but with ExecutionContext")
 | 
			
		||||
  fun yankRange(editor: VimEditor, range: TextRange?, type: SelectionType, moveCursor: Boolean): Boolean
 | 
			
		||||
  fun yankRange(editor: VimEditor, context: ExecutionContext, range: TextRange?, type: SelectionType, moveCursor: Boolean): Boolean
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -10,7 +10,6 @@ package com.maddyhome.idea.vim.yank
 | 
			
		||||
 | 
			
		||||
import com.maddyhome.idea.vim.action.motion.updown.MotionDownLess1FirstNonSpaceAction
 | 
			
		||||
import com.maddyhome.idea.vim.api.ExecutionContext
 | 
			
		||||
import com.maddyhome.idea.vim.api.ImmutableVimCaret
 | 
			
		||||
import com.maddyhome.idea.vim.api.VimCaret
 | 
			
		||||
import com.maddyhome.idea.vim.api.VimEditor
 | 
			
		||||
import com.maddyhome.idea.vim.api.getLineEndForOffset
 | 
			
		||||
@@ -18,8 +17,8 @@ import com.maddyhome.idea.vim.api.getLineStartForOffset
 | 
			
		||||
import com.maddyhome.idea.vim.api.injector
 | 
			
		||||
import com.maddyhome.idea.vim.command.Argument
 | 
			
		||||
import com.maddyhome.idea.vim.command.OperatorArguments
 | 
			
		||||
import com.maddyhome.idea.vim.state.mode.SelectionType
 | 
			
		||||
import com.maddyhome.idea.vim.common.TextRange
 | 
			
		||||
import com.maddyhome.idea.vim.state.mode.SelectionType
 | 
			
		||||
import org.jetbrains.annotations.Contract
 | 
			
		||||
import kotlin.math.min
 | 
			
		||||
 | 
			
		||||
@@ -27,7 +26,6 @@ open class YankGroupBase : VimYankGroup {
 | 
			
		||||
  private fun yankRange(
 | 
			
		||||
    editor: VimEditor,
 | 
			
		||||
    context: ExecutionContext,
 | 
			
		||||
    caretToRange: Map<ImmutableVimCaret, TextRange>,
 | 
			
		||||
    range: TextRange,
 | 
			
		||||
    type: SelectionType,
 | 
			
		||||
    startOffsets: Map<VimCaret, Int>?,
 | 
			
		||||
@@ -36,13 +34,8 @@ open class YankGroupBase : VimYankGroup {
 | 
			
		||||
      caret.moveToOffset(offset)
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    injector.listenersNotifier.notifyYankPerformed(caretToRange)
 | 
			
		||||
 | 
			
		||||
    var result = true
 | 
			
		||||
    for ((caret, myRange) in caretToRange) {
 | 
			
		||||
      result = caret.registerStorage.storeText(editor, context, myRange, type, false) && result
 | 
			
		||||
    }
 | 
			
		||||
    return result
 | 
			
		||||
    injector.listenersNotifier.notifyYankPerformed(editor, range)
 | 
			
		||||
    return injector.registerGroup.storeText(editor, context, editor.primaryCaret(), range, type, false)
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  @Contract("_, _ -> new")
 | 
			
		||||
@@ -87,7 +80,6 @@ open class YankGroupBase : VimYankGroup {
 | 
			
		||||
    val nativeCaretCount = editor.nativeCarets().size
 | 
			
		||||
    if (nativeCaretCount <= 0) return false
 | 
			
		||||
 | 
			
		||||
    val caretToRange = HashMap<ImmutableVimCaret, TextRange>(nativeCaretCount)
 | 
			
		||||
    val ranges = ArrayList<Pair<Int, Int>>(nativeCaretCount)
 | 
			
		||||
 | 
			
		||||
    // This logic is from original vim
 | 
			
		||||
@@ -105,7 +97,6 @@ open class YankGroupBase : VimYankGroup {
 | 
			
		||||
      assert(motionRange.size() == 1)
 | 
			
		||||
      ranges.add(motionRange.startOffset to motionRange.endOffset)
 | 
			
		||||
      startOffsets?.put(caret, motionRange.normalize().startOffset)
 | 
			
		||||
      caretToRange[caret] = TextRange(motionRange.startOffset, motionRange.endOffset)
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    val range = getTextRange(ranges, motionType) ?: return false
 | 
			
		||||
@@ -115,19 +106,12 @@ open class YankGroupBase : VimYankGroup {
 | 
			
		||||
    return yankRange(
 | 
			
		||||
      editor,
 | 
			
		||||
      context,
 | 
			
		||||
      caretToRange,
 | 
			
		||||
      range,
 | 
			
		||||
      motionType,
 | 
			
		||||
      startOffsets,
 | 
			
		||||
    )
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  @Deprecated("Please use the same method, but with ExecutionContext")
 | 
			
		||||
  override fun yankLine(editor: VimEditor, count: Int): Boolean {
 | 
			
		||||
    val context = injector.executionContextManager.getEditorExecutionContext(editor)
 | 
			
		||||
    return yankLine(editor, context, count)
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  /**
 | 
			
		||||
   * This yanks count lines of text
 | 
			
		||||
   *
 | 
			
		||||
@@ -138,7 +122,6 @@ open class YankGroupBase : VimYankGroup {
 | 
			
		||||
  override fun yankLine(editor: VimEditor, context: ExecutionContext, count: Int): Boolean {
 | 
			
		||||
    val caretCount = editor.nativeCarets().size
 | 
			
		||||
    val ranges = ArrayList<Pair<Int, Int>>(caretCount)
 | 
			
		||||
    val caretToRange = HashMap<ImmutableVimCaret, TextRange>(caretCount)
 | 
			
		||||
    for (caret in editor.nativeCarets()) {
 | 
			
		||||
      val start = injector.motion.moveCaretToCurrentLineStart(editor, caret)
 | 
			
		||||
      val end = min(injector.motion.moveCaretToRelativeLineEnd(editor, caret, count - 1, true) + 1, editor.fileSize().toInt())
 | 
			
		||||
@@ -146,17 +129,10 @@ open class YankGroupBase : VimYankGroup {
 | 
			
		||||
      if (end == -1) continue
 | 
			
		||||
 | 
			
		||||
      ranges.add(start to end)
 | 
			
		||||
      caretToRange[caret] = TextRange(start, end)
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    val range = getTextRange(ranges, SelectionType.LINE_WISE) ?: return false
 | 
			
		||||
    return yankRange(editor, context, caretToRange, range, SelectionType.LINE_WISE, null)
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  @Deprecated("Please use the same method, but with ExecutionContext")
 | 
			
		||||
  override fun yankRange(editor: VimEditor, range: TextRange?, type: SelectionType, moveCursor: Boolean): Boolean {
 | 
			
		||||
    val context = injector.executionContextManager.getEditorExecutionContext(editor)
 | 
			
		||||
    return yankRange(editor, context, range, type, moveCursor)
 | 
			
		||||
    return yankRange(editor, context, range, SelectionType.LINE_WISE, null)
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  /**
 | 
			
		||||
@@ -169,7 +145,6 @@ open class YankGroupBase : VimYankGroup {
 | 
			
		||||
   */
 | 
			
		||||
  override fun yankRange(editor: VimEditor, context: ExecutionContext, range: TextRange?, type: SelectionType, moveCursor: Boolean): Boolean {
 | 
			
		||||
    range ?: return false
 | 
			
		||||
    val caretToRange = HashMap<ImmutableVimCaret, TextRange>()
 | 
			
		||||
 | 
			
		||||
    if (type == SelectionType.LINE_WISE) {
 | 
			
		||||
      for (i in 0 until range.size()) {
 | 
			
		||||
@@ -189,19 +164,17 @@ open class YankGroupBase : VimYankGroup {
 | 
			
		||||
    val startOffsets = HashMap<VimCaret, Int>(editor.nativeCarets().size)
 | 
			
		||||
    if (type == SelectionType.BLOCK_WISE) {
 | 
			
		||||
      startOffsets[editor.primaryCaret()] = range.normalize().startOffset
 | 
			
		||||
      caretToRange[editor.primaryCaret()] = range
 | 
			
		||||
    } else {
 | 
			
		||||
      for ((i, caret) in editor.nativeCarets().withIndex()) {
 | 
			
		||||
        val textRange = TextRange(rangeStartOffsets[i], rangeEndOffsets[i])
 | 
			
		||||
        startOffsets[caret] = textRange.normalize().startOffset
 | 
			
		||||
        caretToRange[caret] = textRange
 | 
			
		||||
      }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    return if (moveCursor) {
 | 
			
		||||
      yankRange(editor, context, caretToRange, range, type, startOffsets)
 | 
			
		||||
      yankRange(editor, context, range, type, startOffsets)
 | 
			
		||||
    } else {
 | 
			
		||||
      yankRange(editor, context, caretToRange, range, type, null)
 | 
			
		||||
      yankRange(editor, context, range, type, null)
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -387,7 +387,7 @@
 | 
			
		||||
    {
 | 
			
		||||
        "keys": "<C-R>",
 | 
			
		||||
        "class": "com.maddyhome.idea.vim.action.change.RedoAction",
 | 
			
		||||
        "modes": "N"
 | 
			
		||||
        "modes": "NX"
 | 
			
		||||
    },
 | 
			
		||||
    {
 | 
			
		||||
        "keys": "<C-R>",
 | 
			
		||||
@@ -922,7 +922,7 @@
 | 
			
		||||
    {
 | 
			
		||||
        "keys": "<Undo>",
 | 
			
		||||
        "class": "com.maddyhome.idea.vim.action.change.UndoAction",
 | 
			
		||||
        "modes": "N"
 | 
			
		||||
        "modes": "NX"
 | 
			
		||||
    },
 | 
			
		||||
    {
 | 
			
		||||
        "keys": "<Up>",
 | 
			
		||||
@@ -1141,8 +1141,8 @@
 | 
			
		||||
    },
 | 
			
		||||
    {
 | 
			
		||||
        "keys": "U",
 | 
			
		||||
        "class": "com.maddyhome.idea.vim.action.change.change.ChangeCaseUpperVisualAction",
 | 
			
		||||
        "modes": "X"
 | 
			
		||||
        "class": "com.maddyhome.idea.vim.action.change.RedoAction",
 | 
			
		||||
        "modes": "NX"
 | 
			
		||||
    },
 | 
			
		||||
    {
 | 
			
		||||
        "keys": "V",
 | 
			
		||||
@@ -1917,12 +1917,7 @@
 | 
			
		||||
    {
 | 
			
		||||
        "keys": "u",
 | 
			
		||||
        "class": "com.maddyhome.idea.vim.action.change.UndoAction",
 | 
			
		||||
        "modes": "N"
 | 
			
		||||
    },
 | 
			
		||||
    {
 | 
			
		||||
        "keys": "u",
 | 
			
		||||
        "class": "com.maddyhome.idea.vim.action.change.change.ChangeCaseLowerVisualAction",
 | 
			
		||||
        "modes": "X"
 | 
			
		||||
        "modes": "NX"
 | 
			
		||||
    },
 | 
			
		||||
    {
 | 
			
		||||
        "keys": "v",
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user