mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-07-15 08:16:13 +03:00
Merge pull request #995 from mitchellh/macos-preedit-bs
macos: if a preedit state is cleared, don't send key event
This commit is contained in:
@ -781,14 +781,19 @@ extension Ghostty {
|
|||||||
) ?? event
|
) ?? event
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let action = event.isARepeat ? GHOSTTY_ACTION_REPEAT : GHOSTTY_ACTION_PRESS
|
||||||
|
|
||||||
// By setting this to non-nil, we note that we'rein a keyDown event. From here,
|
// By setting this to non-nil, we note that we'rein a keyDown event. From here,
|
||||||
// we call interpretKeyEvents so that we can handle complex input such as Korean
|
// we call interpretKeyEvents so that we can handle complex input such as Korean
|
||||||
// language.
|
// language.
|
||||||
keyTextAccumulator = []
|
keyTextAccumulator = []
|
||||||
defer { keyTextAccumulator = nil }
|
defer { keyTextAccumulator = nil }
|
||||||
self.interpretKeyEvents([translationEvent])
|
|
||||||
|
|
||||||
let action = event.isARepeat ? GHOSTTY_ACTION_REPEAT : GHOSTTY_ACTION_PRESS
|
// We need to know what the length of marked text was before this event to
|
||||||
|
// know if these events cleared it.
|
||||||
|
let markedTextBefore = markedText.length > 0
|
||||||
|
|
||||||
|
self.interpretKeyEvents([translationEvent])
|
||||||
|
|
||||||
// If we have text, then we've composed a character, send that down. We do this
|
// If we have text, then we've composed a character, send that down. We do this
|
||||||
// first because if we completed a preedit, the text will be available here
|
// first because if we completed a preedit, the text will be available here
|
||||||
@ -802,7 +807,10 @@ extension Ghostty {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// If we have marked text, we're in a preedit state. Send that down.
|
// If we have marked text, we're in a preedit state. Send that down.
|
||||||
if (markedText.length > 0) {
|
// If we don't have marked text but we had marked text before, then the preedit
|
||||||
|
// was cleared so we want to send down an empty string to ensure we've cleared
|
||||||
|
// the preedit.
|
||||||
|
if (markedText.length > 0 || markedTextBefore) {
|
||||||
handled = true
|
handled = true
|
||||||
keyAction(action, event: event, preedit: markedText.string)
|
keyAction(action, event: event, preedit: markedText.string)
|
||||||
}
|
}
|
||||||
|
@ -1085,6 +1085,8 @@ fn resize(self: *Surface, size: renderer.ScreenSize) !void {
|
|||||||
///
|
///
|
||||||
/// The preedit input must be UTF-8 encoded.
|
/// The preedit input must be UTF-8 encoded.
|
||||||
pub fn preeditCallback(self: *Surface, preedit_: ?[]const u8) !void {
|
pub fn preeditCallback(self: *Surface, preedit_: ?[]const u8) !void {
|
||||||
|
// log.debug("text preeditCallback value={any}", .{preedit_});
|
||||||
|
|
||||||
self.renderer_state.mutex.lock();
|
self.renderer_state.mutex.lock();
|
||||||
defer self.renderer_state.mutex.unlock();
|
defer self.renderer_state.mutex.unlock();
|
||||||
|
|
||||||
@ -1124,7 +1126,10 @@ pub fn preeditCallback(self: *Surface, preedit_: ?[]const u8) !void {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// If we have no codepoints, then we're done.
|
// If we have no codepoints, then we're done.
|
||||||
if (codepoints.items.len == 0) return;
|
if (codepoints.items.len == 0) {
|
||||||
|
try self.queueRender();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
self.renderer_state.preedit = .{
|
self.renderer_state.preedit = .{
|
||||||
.codepoints = try codepoints.toOwnedSlice(self.alloc),
|
.codepoints = try codepoints.toOwnedSlice(self.alloc),
|
||||||
|
Reference in New Issue
Block a user