mirror of
https://github.com/TermoraDev/termora.git
synced 2026-01-16 02:12:58 +08:00
fix: Escape key (#482)
This commit is contained in:
@@ -42,7 +42,6 @@ class BackgroundManager private constructor() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun getBackgroundImage(): BufferedImage? {
|
fun getBackgroundImage(): BufferedImage? {
|
||||||
assertEventDispatchThread()
|
|
||||||
val bg = doGetBackgroundImage()
|
val bg = doGetBackgroundImage()
|
||||||
if (bg == null) {
|
if (bg == null) {
|
||||||
if (JPopupMenu.getDefaultLightWeightPopupEnabled()) {
|
if (JPopupMenu.getDefaultLightWeightPopupEnabled()) {
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package app.termora.terminal.panel
|
|||||||
|
|
||||||
import app.termora.keymap.KeyShortcut
|
import app.termora.keymap.KeyShortcut
|
||||||
import app.termora.keymap.KeymapManager
|
import app.termora.keymap.KeymapManager
|
||||||
|
import app.termora.terminal.ControlCharacters
|
||||||
import app.termora.terminal.Terminal
|
import app.termora.terminal.Terminal
|
||||||
import com.formdev.flatlaf.util.SystemInfo
|
import com.formdev.flatlaf.util.SystemInfo
|
||||||
import org.slf4j.LoggerFactory
|
import org.slf4j.LoggerFactory
|
||||||
@@ -99,11 +100,12 @@ class TerminalPanelKeyAdapter(
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Character.isISOControl(e.keyChar)) {
|
val keyChar = mapKeyChar(e)
|
||||||
|
if (Character.isISOControl(keyChar)) {
|
||||||
terminal.getSelectionModel().clearSelection()
|
terminal.getSelectionModel().clearSelection()
|
||||||
// 如果不为空表示已经发送过了,所以这里为空的时候再发送
|
// 如果不为空表示已经发送过了,所以这里为空的时候再发送
|
||||||
if (encode.isEmpty()) {
|
if (encode.isEmpty()) {
|
||||||
writer.write(TerminalWriter.WriteRequest.fromBytes("${e.keyChar}".toByteArray(writer.getCharset())))
|
writer.write(TerminalWriter.WriteRequest.fromBytes("$keyChar".toByteArray(writer.getCharset())))
|
||||||
e.consume()
|
e.consume()
|
||||||
}
|
}
|
||||||
terminal.getScrollingModel().scrollTo(Int.MAX_VALUE)
|
terminal.getScrollingModel().scrollTo(Int.MAX_VALUE)
|
||||||
@@ -111,6 +113,21 @@ class TerminalPanelKeyAdapter(
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun mapKeyChar(e: KeyEvent): Char {
|
||||||
|
if (Character.isISOControl(e.keyChar)) {
|
||||||
|
return e.keyChar
|
||||||
|
}
|
||||||
|
|
||||||
|
val isCtrlPressedOnly = isCtrlPressedOnly(e)
|
||||||
|
|
||||||
|
// https://github.com/TermoraDev/termora/issues/478
|
||||||
|
if (isCtrlPressedOnly && e.keyCode == KeyEvent.VK_OPEN_BRACKET) {
|
||||||
|
return ControlCharacters.ESC
|
||||||
|
}
|
||||||
|
|
||||||
|
return e.keyChar
|
||||||
|
}
|
||||||
|
|
||||||
private fun isCtrlPressedOnly(e: KeyEvent): Boolean {
|
private fun isCtrlPressedOnly(e: KeyEvent): Boolean {
|
||||||
val modifiersEx = e.modifiersEx
|
val modifiersEx = e.modifiersEx
|
||||||
return (modifiersEx and InputEvent.ALT_DOWN_MASK) == 0
|
return (modifiersEx and InputEvent.ALT_DOWN_MASK) == 0
|
||||||
|
|||||||
Reference in New Issue
Block a user