1
0
mirror of https://github.com/chylex/IntelliJ-IdeaVim.git synced 2025-02-25 02:46:01 +01:00

Fix multiple copy from unnamed clipboard

This commit is contained in:
Alex Plate 2021-09-17 16:44:12 +03:00
parent 1466ad9bef
commit 85c8968d75
No known key found for this signature in database
GPG Key ID: 0B97153C8FFEC09F
3 changed files with 40 additions and 2 deletions
CHANGES.md
src/com/maddyhome/idea/vim/group/copy
test/ui

View File

@ -24,9 +24,11 @@ Please note that the quality of EAP versions may at times be way below even
usual beta standards.
## To Be Released
### Fixes:
* [VIM-2400](https://youtrack.jetbrains.com/issue/VIM-2400) Fix vim script parser
* [VIM-2401](https://youtrack.jetbrains.com/issue/VIM-2401) Exceptions occurred during execution of `map<expr>` are now shown in status bar
* [VIM-2404](https://youtrack.jetbrains.com/issue/VIM-2404) Fix multiple pastes from unnamed clipboard
## 1.7.0, 2021-09-16

View File

@ -51,6 +51,7 @@ import com.maddyhome.idea.vim.helper.fileSize
import com.maddyhome.idea.vim.helper.moveToInlayAwareOffset
import com.maddyhome.idea.vim.option.ClipboardOptionsData
import com.maddyhome.idea.vim.option.OptionsManager
import java.awt.datatransfer.DataFlavor
import java.util.*
import kotlin.math.abs
import kotlin.math.max
@ -328,11 +329,12 @@ class PutGroup {
val origContent: TextBlockTransferable = setClipboardText(text.text, text.transferableData)
val allContentsAfter = CopyPasteManager.getInstance().allContents
val sizeAfterInsert = allContentsAfter.size
val firstItemAfter = allContentsAfter.firstOrNull()
try {
pasteProvider.performPaste(context)
} finally {
if (sizeBeforeInsert != sizeAfterInsert || firstItemBefore != firstItemAfter) {
val textOnTop =
((firstItemBefore as? TextBlockTransferable)?.getTransferData(DataFlavor.stringFlavor) as? String) != text.text
if (sizeBeforeInsert != sizeAfterInsert || textOnTop) {
// Sometimes inserted text replaces existing one. E.g. on insert with + or * register
(CopyPasteManager.getInstance() as? CopyPasteManagerEx)?.run { removeContent(origContent) }
}

View File

@ -92,6 +92,7 @@ class UiTests {
}
}
testUnnamedClipboard(editor)
testSelectAndRightClick(editor)
testSelectTextWithMouseInGutter(editor)
testSelectForthAndBack(editor)
@ -121,6 +122,39 @@ class UiTests {
}
}
private fun IdeaFrame.testUnnamedClipboard(editor: Editor) {
keyboard {
enterText(":set clipboard+=unnamed")
enter()
enterText("gg")
enterText("yy")
enterText("jyy")
enterText("jyy")
enterText("p")
enterText("p")
enterText("p")
}
assertEquals(
"""
One Two
Three Four
Five
Five
Five
Five
""".trimIndent(),
editor.text
)
keyboard {
enterText(":set clipboard-=unnamed")
enter()
}
}
private fun IdeaFrame.wrapWithIf(editor: Editor) {
editor.findText("System").click()
remoteRobot.invokeActionJs("SurroundWith")