1
0
mirror of https://github.com/chylex/IntelliJ-IdeaVim.git synced 2025-03-03 18:32:54 +01:00

Merge branch 'master' into feature/guicursor

# Conflicts:
#	src/com/maddyhome/idea/vim/listener/VimListenerManager.kt
This commit is contained in:
Alex Plate 2021-09-29 12:32:32 +03:00
commit c268407ce3
No known key found for this signature in database
GPG Key ID: 0B97153C8FFEC09F
4 changed files with 51 additions and 4 deletions
src/com/maddyhome/idea/vim/listener
test/ui

View File

@ -68,10 +68,14 @@ sealed class VimListenerSuppressor {
// Please try not to use lock/unlock without scoping
// Prefer try-with-resources
private fun unlock() {
fun unlock() {
caretListenerSuppressor--
}
fun reset() {
caretListenerSuppressor = 0
}
val isNotLocked: Boolean
get() = caretListenerSuppressor == 0

View File

@ -356,12 +356,24 @@ object VimListenerManager {
return caret.offset == lineEnd && lineEnd != lineStart && caret.offset - 1 == caret.selectionStart && caret.offset == caret.selectionEnd
}
// Note that the MacBook's trackpad has a small delay before mouseReleased is received, presumably to allow
// repositioning fingers to continue a drag operation. This can cause confusion when observing some of the effects
// in this handler!
override fun mousePressed(event: EditorMouseEvent) {
if (event.editor.isIdeaVimDisabledHere) return
SelectionVimListenerSuppressor.reset()
SelectionVimListenerSuppressor.lock()
}
/**
* This method may not be called
* Known cases:
* - Click-hold and close editor (ctrl-w)
* - Click-hold and switch editor (ctrl-tab)
*/
override fun mouseReleased(event: EditorMouseEvent) {
if (event.editor.isIdeaVimDisabledHere) return
SelectionVimListenerSuppressor.unlock()
clearFirstSelectionEvents(event)
skipNDragEvents = skipEvents
if (mouseDragging) {

View File

@ -42,6 +42,7 @@ import ui.utils.invokeActionJs
import ui.utils.moveMouseForthAndBack
import ui.utils.moveMouseInGutterTo
import ui.utils.moveMouseTo
import ui.utils.moveMouseWithDelayTo
import ui.utils.tripleClickOnRight
import ui.utils.uiTest
import ui.utils.vimExit
@ -80,6 +81,7 @@ class UiTests {
}
}
testSelectTextWithDelay(editor)
testExtendSelection(editor)
testLargerDragSelection(editor)
testSelectLastCharacter(editor)
@ -325,6 +327,24 @@ class UiTests {
vimExit()
}
private fun ContainerFixture.testSelectTextWithDelay(editor: Editor) {
println("Run testSelectTextUsingMouse...")
val from = editor.findText("One")
val to = editor.findText("Four")
val caretIsBlockWhileDragging = from.moveMouseWithDelayTo(to, editor)
assertFalse(caretIsBlockWhileDragging)
Thread.sleep(1000)
assertEquals("One Two\nThree ", editor.selectedText)
keyboard { enterText("l") }
assertEquals("One Two\nThree F", editor.selectedText)
vimExit()
}
private fun ContainerFixture.testSelectLastCharacter(editor: Editor) {
println("Run testSelectLastCharacter...")

View File

@ -50,6 +50,17 @@ fun RemoteText.moveMouseTo(goal: RemoteText, editor: Editor): Boolean {
return caretDuringDragging
}
fun RemoteText.moveMouseWithDelayTo(goal: RemoteText, editor: Editor, delay: Long = 1000): Boolean {
this.moveMouse()
editor.runJs("robot.pressMouse(MouseButton.LEFT_BUTTON)")
goal.moveMouse()
Thread.sleep(delay)
val caretDuringDragging = editor.isBlockCursor
editor.runJs("robot.releaseMouse(MouseButton.LEFT_BUTTON)")
waitFor { editor.isBlockCursor }
return caretDuringDragging
}
fun RemoteText.moveMouseInGutterTo(goal: RemoteText, fixture: Fixture) {
this.moveMouse()
val goalPoint = goal.point