From b3a4728e3ab02a70b08e824835db499edc758a95 Mon Sep 17 00:00:00 2001 From: Konstantin Hudyakov Date: Tue, 11 Aug 2026 09:34:16 +0300 Subject: [PATCH] [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 --- .../terminal/frontend/action/TerminalEscapeHandlers.kt | 2 +- .../frontend/view/impl/TerminalMouseEventsHandlerImpl.kt | 4 ++-- .../frontend/view/impl/TerminalTextSelectionModelImpl.kt | 2 +- .../intellij/terminal/frontend/view/impl/TerminalViewImpl.kt | 4 ++-- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/plugins/terminal/frontend/src/com/intellij/terminal/frontend/action/TerminalEscapeHandlers.kt b/plugins/terminal/frontend/src/com/intellij/terminal/frontend/action/TerminalEscapeHandlers.kt index dc0a4db8285c..f2eb7782fdd1 100644 --- a/plugins/terminal/frontend/src/com/intellij/terminal/frontend/action/TerminalEscapeHandlers.kt +++ b/plugins/terminal/frontend/src/com/intellij/terminal/frontend/action/TerminalEscapeHandlers.kt @@ -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) } } diff --git a/plugins/terminal/frontend/src/com/intellij/terminal/frontend/view/impl/TerminalMouseEventsHandlerImpl.kt b/plugins/terminal/frontend/src/com/intellij/terminal/frontend/view/impl/TerminalMouseEventsHandlerImpl.kt index 52a1c49d58dd..7c575f5e5255 100644 --- a/plugins/terminal/frontend/src/com/intellij/terminal/frontend/view/impl/TerminalMouseEventsHandlerImpl.kt +++ b/plugins/terminal/frontend/src/com/intellij/terminal/frontend/view/impl/TerminalMouseEventsHandlerImpl.kt @@ -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) } diff --git a/plugins/terminal/frontend/src/com/intellij/terminal/frontend/view/impl/TerminalTextSelectionModelImpl.kt b/plugins/terminal/frontend/src/com/intellij/terminal/frontend/view/impl/TerminalTextSelectionModelImpl.kt index 9f532adef659..0d723484dcf4 100644 --- a/plugins/terminal/frontend/src/com/intellij/terminal/frontend/view/impl/TerminalTextSelectionModelImpl.kt +++ b/plugins/terminal/frontend/src/com/intellij/terminal/frontend/view/impl/TerminalTextSelectionModelImpl.kt @@ -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? { diff --git a/plugins/terminal/frontend/src/com/intellij/terminal/frontend/view/impl/TerminalViewImpl.kt b/plugins/terminal/frontend/src/com/intellij/terminal/frontend/view/impl/TerminalViewImpl.kt index b07ae4c2995c..95ee6bfc7c62 100644 --- a/plugins/terminal/frontend/src/com/intellij/terminal/frontend/view/impl/TerminalViewImpl.kt +++ b/plugins/terminal/frontend/src/com/intellij/terminal/frontend/view/impl/TerminalViewImpl.kt @@ -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) } } } }