adds Clean Copy Support
This commit is contained in:
@@ -10,6 +10,7 @@ final class HelderTerminalView: LocalProcessTerminalView, TerminalSessionHandle,
|
||||
var appliedSettings: HelderConfig.Terminal?
|
||||
var appliedScale = 1.0
|
||||
private var closeObserver: NSObjectProtocol?
|
||||
private var keyMonitor: Any?
|
||||
private lazy var pointerTracker = PointerTracker(view: self)
|
||||
private let events = ProcessEvents()
|
||||
|
||||
@@ -24,6 +25,7 @@ final class HelderTerminalView: LocalProcessTerminalView, TerminalSessionHandle,
|
||||
processDelegate = events
|
||||
appliedSettings = store.config.terminal
|
||||
TerminalAppearance.apply(store.config.terminal, to: self)
|
||||
syncMouseReporting()
|
||||
}
|
||||
|
||||
required init?(coder: NSCoder) {
|
||||
@@ -60,18 +62,28 @@ final class HelderTerminalView: LocalProcessTerminalView, TerminalSessionHandle,
|
||||
super.send(source: source, data: data)
|
||||
}
|
||||
|
||||
/// ⌥← and ⌥→ jump by word (ESC b / ESC f, as Terminal.app does) while Option is not the Meta key.
|
||||
override func interpretKeyEvents(_ events: [NSEvent]) {
|
||||
if !optionAsMetaKey, events.count == 1, let event = events.first, event.type == .keyDown,
|
||||
event.modifierFlags.intersection([.shift, .control, .option, .command]) == .option,
|
||||
let key = event.charactersIgnoringModifiers?.unicodeScalars.first.map({ Int($0.value) }) {
|
||||
switch key {
|
||||
case NSLeftArrowFunctionKey: return send(EscapeSequences.emacsBack)
|
||||
case NSRightArrowFunctionKey: return send(EscapeSequences.emacsForward)
|
||||
default: break
|
||||
}
|
||||
}
|
||||
super.interpretKeyEvents(events)
|
||||
/// ⌥← and ⌥→ jump by word (ESC b / ESC f, as Terminal.app does) while Option is not the Meta key;
|
||||
/// caught before SwiftTerm, whose kitty-keyboard path would drop the Option and whose `keyDown` is not open.
|
||||
private func handleWordJump(_ event: NSEvent) -> Bool {
|
||||
guard !optionAsMetaKey, let window, event.window === window, window.firstResponder === self,
|
||||
event.modifierFlags.intersection([.shift, .control, .option, .command]) == .option,
|
||||
let key = event.charactersIgnoringModifiers?.unicodeScalars.first.map({ Int($0.value) }),
|
||||
key == NSLeftArrowFunctionKey || key == NSRightArrowFunctionKey else { return false }
|
||||
selection.active = false
|
||||
send(key == NSLeftArrowFunctionKey ? EscapeSequences.emacsBack : EscapeSequences.emacsForward)
|
||||
return true
|
||||
}
|
||||
|
||||
/// Mouse reporting is on only while the program asked for it; SwiftTerm clears the selection on every output
|
||||
/// while it is on, so a redrawing program like Claude Code could never keep one.
|
||||
override func dataReceived(slice: ArraySlice<UInt8>) {
|
||||
syncMouseReporting()
|
||||
super.dataReceived(slice: slice)
|
||||
syncMouseReporting()
|
||||
}
|
||||
|
||||
private func syncMouseReporting() {
|
||||
allowMouseReporting = terminal.mouseMode != .off
|
||||
}
|
||||
|
||||
/// Selecting text copies it, in both panes.
|
||||
@@ -181,7 +193,12 @@ final class HelderTerminalView: LocalProcessTerminalView, TerminalSessionHandle,
|
||||
super.viewDidMoveToWindow()
|
||||
if let closeObserver { NotificationCenter.default.removeObserver(closeObserver) }
|
||||
closeObserver = nil
|
||||
if let keyMonitor { NSEvent.removeMonitor(keyMonitor) }
|
||||
keyMonitor = nil
|
||||
guard let window else { return }
|
||||
keyMonitor = NSEvent.addLocalMonitorForEvents(matching: .keyDown) { [weak self] event in
|
||||
MainActor.assumeIsolated { self?.handleWordJump(event) ?? false } ? nil : event
|
||||
}
|
||||
closeObserver = NotificationCenter.default.addObserver(
|
||||
forName: NSWindow.willCloseNotification, object: window, queue: .main
|
||||
) { [weak self] _ in
|
||||
|
||||
Reference in New Issue
Block a user