mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-10-16 14:56:10 +00:00
core: remove size limit on preedit length by heap allocating
Fixes #882 We previously had a hardcoded limit of 16 codepoints. In #882, a user pointed out that in Chinese, is reasonable for a preedit input to be longer than this. To avoid any future issues, this commit moves to a heap-allocated variant. Preedits aren't that common, they aren't high throughput, and they're generally pretty small, so using a heap allocation is fine. The memory is owned by the person who set it.
This commit is contained in:
@@ -697,6 +697,14 @@ pub fn updateFrame(
|
||||
cursor_blink_visible,
|
||||
);
|
||||
|
||||
// Get our preedit state
|
||||
const preedit: ?renderer.State.Preedit = preedit: {
|
||||
if (cursor_style == null) break :preedit null;
|
||||
const p = state.preedit orelse break :preedit null;
|
||||
break :preedit try p.clone(self.alloc);
|
||||
};
|
||||
errdefer if (preedit) |p| p.deinit(self.alloc);
|
||||
|
||||
// If we have Kitty graphics data, we enter a SLOW SLOW SLOW path.
|
||||
// We only do this if the Kitty image state is dirty meaning only if
|
||||
// it changes.
|
||||
@@ -709,11 +717,14 @@ pub fn updateFrame(
|
||||
.selection = selection,
|
||||
.screen = screen_copy,
|
||||
.mouse = state.mouse,
|
||||
.preedit = if (cursor_style != null) state.preedit else null,
|
||||
.preedit = preedit,
|
||||
.cursor_style = cursor_style,
|
||||
};
|
||||
};
|
||||
defer critical.screen.deinit();
|
||||
defer {
|
||||
critical.screen.deinit();
|
||||
if (critical.preedit) |p| p.deinit(self.alloc);
|
||||
}
|
||||
|
||||
// Grab our draw mutex if we have it and update our data
|
||||
{
|
||||
@@ -1083,7 +1094,7 @@ pub fn rebuildCells(
|
||||
if (preedit) |preedit_v| {
|
||||
const range = preedit_range.?;
|
||||
var x = range.x[0];
|
||||
for (preedit_v.codepoints[0..preedit_v.len]) |cp| {
|
||||
for (preedit_v.codepoints) |cp| {
|
||||
self.addPreeditCell(cp, x, range.y) catch |err| {
|
||||
log.warn("error building preedit cell, will be invalid x={} y={}, err={}", .{
|
||||
x,
|
||||
|
Reference in New Issue
Block a user