[terminal] IJPL-251692 Remove selection from all carets on typing, escape and mouse-reported scrolling

Default `removeSelection()` is removing selection only from the main editor caret.

(cherry picked from commit 8d5a176b32e668ca26f98188b8a13d60d8034a32)

IJ-CR-218081

GitOrigin-RevId: e1805677ca39a716751ec4ff312ebe43a9aba91d
This commit is contained in:
Konstantin Hudyakov
2026-08-14 15:57:11 +00:00
committed by intellij-monorepo-bot
parent 6f853914b3
commit b3a4728e3a
4 changed files with 6 additions and 6 deletions
@@ -27,7 +27,7 @@ internal class CancelSelection : TerminalEscapeHandler {
override fun isEnabled(e: AnActionEvent): Boolean = e.terminalEditor?.selectionModel?.hasSelection() == true
override fun execute(e: AnActionEvent) {
e.terminalEditor?.selectionModel?.removeSelection()
e.terminalEditor?.selectionModel?.removeSelection(true)
}
}
@@ -50,7 +50,7 @@ internal class TerminalMouseEventsHandlerImpl(
// Editor selection can be active at this moment only if the user holds Shift.
// Support the case of removing the selection here, because editor logic won't be able to do it
// (we consume the event).
editor.selectionModel.removeSelection()
editor.selectionModel.removeSelection(true)
// Consume the mouse event to avoid double processing:
// by the terminal process and the editor logic (for example, text selection).
@@ -136,7 +136,7 @@ internal class TerminalMouseEventsHandlerImpl(
if (event.isConsumed) return
if (settings.enableMouseReporting() && terminalState.mouseMode != MouseMode.MOUSE_REPORTING_NONE && !event.isShiftDown) {
editor.selectionModel.removeSelection()
editor.selectionModel.removeSelection(true)
// mousePressed() handles mouse wheel using SCROLLDOWN and SCROLLUP buttons
mousePressed(x, y, event)
}
@@ -48,7 +48,7 @@ internal class TerminalTextSelectionModelImpl(
val end = newSelection.endOffset - outputModel.startOffset
editorSelectionModel.setSelection(start.toInt(), end.toInt())
}
else editorSelectionModel.removeSelection()
else editorSelectionModel.removeSelection(true)
}
private fun getCurrentSelection(): TerminalTextSelection? {
@@ -581,8 +581,8 @@ class TerminalViewImpl(
coroutineScope.launch(Dispatchers.UI + CoroutineName("Key events listener")) {
keyEventsFlow.collect { e ->
if (e.awtEvent.id == KeyEvent.KEY_TYPED) {
outputEditor.selectionModel.let { if (it.hasSelection()) it.removeSelection() }
alternateBufferEditor.selectionModel.let { if (it.hasSelection()) it.removeSelection() }
outputEditor.selectionModel.let { if (it.hasSelection()) it.removeSelection(true) }
alternateBufferEditor.selectionModel.let { if (it.hasSelection()) it.removeSelection(true) }
}
}
}