fix: copy hotkey conflicts with ctrlc

This commit is contained in:
Srar
2025-12-10 14:54:49 +08:00
committed by hstyi
parent 1d596e18df
commit b499667cbb
2 changed files with 11 additions and 3 deletions

View File

@@ -20,6 +20,10 @@ class TerminalCopyAction : AnAction() {
override fun actionPerformed(evt: AnActionEvent) {
val terminalPanel = evt.getData(DataProviders.TerminalPanel) ?: return
val selectionModel = terminalPanel.terminal.getSelectionModel()
if (!selectionModel.hasSelection()) {
return
}
val text = terminalPanel.copy()
val systemClipboard = terminalPanel.toolkit.systemClipboard
@@ -53,4 +57,4 @@ class TerminalCopyAction : AnAction() {
}
}
}

View File

@@ -1,5 +1,6 @@
package app.termora.terminal.panel
import app.termora.actions.TerminalCopyAction
import app.termora.keymap.KeyShortcut
import app.termora.keymap.KeymapManager
import app.termora.terminal.ControlCharacters
@@ -69,6 +70,7 @@ class TerminalPanelKeyAdapter(
}
val keyStroke = KeyStroke.getKeyStrokeForEvent(e)
val keymapActions = activeKeymap.getActionIds(KeyShortcut(keyStroke))
for (action in terminalPanel.getTerminalActions()) {
if (action.test(keyStroke, e)) {
action.actionPerformed(e)
@@ -100,7 +102,9 @@ class TerminalPanelKeyAdapter(
}
// 如果命中了全局快捷键,那么不处理
if (keyStroke.modifiers != 0 && activeKeymap.getActionIds(KeyShortcut(keyStroke)).isNotEmpty()) {
val copyShortcutWithoutSelection =
keymapActions.contains(TerminalCopyAction.COPY) && terminal.getSelectionModel().hasSelection().not()
if (keyStroke.modifiers != 0 && keymapActions.isNotEmpty() && !copyShortcutWithoutSelection) {
return
}
@@ -155,4 +159,4 @@ class TerminalPanelKeyAdapter(
return Character.toLowerCase(e.keyCode.toChar())
}
}
}