Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion Sources/GhosttyTerminalView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5760,7 +5760,12 @@ class GhosttyNSView: NSView, NSUserInterfaceValidations {

private func shouldSendCommittedIMEConfirmKey(event: NSEvent, markedTextBefore: Bool) -> Bool {
guard markedTextBefore, markedText.length == 0 else { return false }
return event.keyCode == 36 || event.keyCode == 76
guard event.keyCode == 36 || event.keyCode == 76 else { return false }
// Korean IME: Enter commits the syllable AND executes the command (single step).
// Japanese/Chinese IME: Enter only confirms the conversion; a second Enter executes.
// Only send the extra Return key for Korean input sources.
guard let sourceId = KeyboardLayout.id else { return false }
return sourceId.range(of: "korean", options: .caseInsensitive) != nil
}

private func ghosttyKeyEvent(for event: NSEvent, surface: ghostty_surface_t) -> ghostty_input_key_s {
Expand Down
8 changes: 8 additions & 0 deletions Sources/KeyboardLayout.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,16 @@ import AppKit
import Carbon

class KeyboardLayout {
/// Test-only override for the current input source ID.
#if DEBUG
static var debugInputSourceIdOverride: String?
#endif

/// Return a string ID of the current keyboard input source.
static var id: String? {
#if DEBUG
if let override = debugInputSourceIdOverride { return override }
#endif
if let source = TISCopyCurrentKeyboardInputSource()?.takeRetainedValue(),
let sourceIdPointer = TISGetInputSourceProperty(source, kTISPropertyInputSourceID) {
let sourceId = Unmanaged<CFString>.fromOpaque(sourceIdPointer).takeUnretainedValue()
Expand Down
3 changes: 3 additions & 0 deletions cmuxTests/CJKIMEInputTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1038,13 +1038,16 @@ final class KoreanIMEReturnCommitRegressionTests: XCTestCase {

view.setMarkedText("한", selectedRange: NSRange(location: 0, length: 1), replacementRange: NSRange(location: NSNotFound, length: 0))

// Simulate Korean input source so shouldSendCommittedIMEConfirmKey fires
KeyboardLayout.debugInputSourceIdOverride = "com.apple.inputmethod.Korean.2SetKorean"
installCJKIMEInterpretKeyEventsSwizzle()
cjkIMEInterpretKeyEventsHook = { candidateView, _ in
guard candidateView === view else { return false }
candidateView.insertText("한", replacementRange: NSRange(location: NSNotFound, length: 0))
return true
}
defer {
KeyboardLayout.debugInputSourceIdOverride = nil
cjkIMEInterpretKeyEventsHook = nil
}

Expand Down