Improves helder

This commit is contained in:
2026-10-05 09:24:25 +02:00
parent 8fafea4fc3
commit 336987d821
44 changed files with 3454 additions and 542 deletions
@@ -18,6 +18,7 @@ final class HelderTerminalView: LocalProcessTerminalView, TerminalSessionHandle
super.init(frame: NSRect(x: 0, y: 0, width: 480, height: 320),
font: TerminalAppearance.font(store.config.terminal),
options: TerminalAppearance.options(store.config.terminal))
Self.arrowCursorUpdate
events.owner = self
processDelegate = events
appliedSettings = store.config.terminal
@@ -58,6 +59,20 @@ 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)
}
/// Selecting text copies it, in both panes.
override func selectionChanged(source: Terminal) {
super.selectionChanged(source: source)
@@ -87,6 +102,23 @@ final class HelderTerminalView: LocalProcessTerminalView, TerminalSessionHandle
return nil
}
// MARK: Pointer
/// The terminal shows the arrow, so SwiftTerm's I-beam rect is dropped; its `resetCursorRects` is not open.
override func addCursorRect(_ rect: NSRect, cursor object: NSCursor) {
guard object != .iBeam else { return }
super.addCursorRect(rect, cursor: object)
}
/// Gives this class its own `cursorUpdate:` that sets the arrow; Swift cannot override SwiftTerm's I-beam one,
/// which runs when an update reaches the pane through a subview or a neighbour's tracking area.
private static let arrowCursorUpdate: Void = {
let block: @convention(block) (AnyObject, NSEvent) -> Void = { _, _ in NSCursor.arrow.set() }
let selector = #selector(NSResponder.cursorUpdate(with:))
let types = method_getTypeEncoding(class_getInstanceMethod(NSView.self, selector)!)
class_addMethod(HelderTerminalView.self, selector, imp_implementationWithBlock(block), types)
}()
// MARK: Lifetime
/// Closing the window kills the child; moving the view between containers does not.