core: clear selection whenever preedit is changed

This commit is contained in:
Mitchell Hashimoto
2025-01-11 13:59:38 -08:00
parent af5e423ea5
commit 6c5c5b2ec0
5 changed files with 10 additions and 11 deletions

View File

@ -748,7 +748,6 @@ void ghostty_surface_complete_clipboard_request(ghostty_surface_t,
bool);
bool ghostty_surface_has_selection(ghostty_surface_t);
uintptr_t ghostty_surface_selection(ghostty_surface_t, char*, uintptr_t);
void ghostty_surface_clear_selection(ghostty_surface_t);
#ifdef __APPLE__
void ghostty_surface_set_display_id(ghostty_surface_t, uint32_t);

View File

@ -1293,11 +1293,6 @@ extension Ghostty.SurfaceView: NSTextInputClient {
}
func setMarkedText(_ string: Any, selectedRange: NSRange, replacementRange: NSRange) {
// Clear selection when IME input starts
if let surface = self.surface, ghostty_surface_has_selection(surface) {
ghostty_surface_clear_selection(surface)
}
switch string {
case let v as NSAttributedString:
self.markedText = NSMutableAttributedString(attributedString: v)

View File

@ -18,6 +18,7 @@ extension NSPasteboard {
return path
}
}
return self.string(forType: .string)
}

View File

@ -1591,6 +1591,15 @@ pub fn preeditCallback(self: *Surface, preedit_: ?[]const u8) !void {
self.renderer_state.mutex.lock();
defer self.renderer_state.mutex.unlock();
// We clear our selection when ANY OF:
// 1. We have an existing preedit
// 2. We have preedit text
if (self.renderer_state.preedit != null or
preedit_ != null)
{
self.setSelection(null) catch {};
}
// We always clear our prior preedit
if (self.renderer_state.preedit) |p| {
self.alloc.free(p.codepoints);

View File

@ -1550,11 +1550,6 @@ pub const CAPI = struct {
return selection.len;
}
/// Clear the current selection in the surface.
export fn ghostty_surface_clear_selection(surface: *Surface) void {
surface.core_surface.io.terminal.screen.clearSelection();
}
/// Tell the surface that it needs to schedule a render
export fn ghostty_surface_refresh(surface: *Surface) void {
surface.refresh();