From 5c8c4bb06e332ed1105a59f7c5eb44a255bc758b Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Fri, 10 Nov 2023 17:30:14 -0800 Subject: [PATCH] renderer/opengl: handle wide preedit --- src/renderer/Metal.zig | 1 + src/renderer/OpenGL.zig | 21 +++++++++++++++------ 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/src/renderer/Metal.zig b/src/renderer/Metal.zig index 43ce4cd61..e3cf2ae9e 100644 --- a/src/renderer/Metal.zig +++ b/src/renderer/Metal.zig @@ -1215,6 +1215,7 @@ fn rebuildCells( var cell: mtl_shaders.Cell = cursor_cell orelse (real_cursor_cell orelse break :preedit).*; cell.color = .{ 0, 0, 0, 255 }; + cell.cell_width = if (preedit_v.wide) 2 else 1; // If preedit rendering succeeded then we don't want to // re-render the underlying cell fg diff --git a/src/renderer/OpenGL.zig b/src/renderer/OpenGL.zig index bc8982b37..c699572c9 100644 --- a/src/renderer/OpenGL.zig +++ b/src/renderer/OpenGL.zig @@ -817,7 +817,7 @@ pub fn rebuildCells( // a cursor cell then we invert the colors on that and add it in so // that we can always see it. if (cursor_style_) |cursor_style| { - const real_cursor_cell = self.addCursor(screen, cursor_style); + const real_cursor_cell = self.addCursor(screen, cursor_style, preedit); // If we have a preedit, we try to render the preedit text on top // of the cursor. @@ -832,6 +832,7 @@ pub fn rebuildCells( cell.fg_g = 0; cell.fg_b = 0; cell.fg_a = 255; + cell.grid_width = if (preedit_v.wide) 2 else 1; // If preedit rendering succeeded then we don't want to // re-render the underlying cell fg @@ -871,10 +872,18 @@ fn addCursor( self: *OpenGL, screen: *terminal.Screen, cursor_style: renderer.CursorStyle, + preedit: ?renderer.State.Preedit, ) ?*const GPUCell { // Add the cursor. We render the cursor over the wide character if // we're on the wide characer tail. - const cell, const x = cell: { + const wide, const x = cell: { + // If we have preedit text, our width is based on that. + if (preedit) |p| { + if (p.codepoint > 0) { + break :cell .{ p.wide, screen.cursor.x }; + } + } + // The cursor goes over the screen cursor position. const cell = screen.getCell( .active, @@ -882,7 +891,7 @@ fn addCursor( screen.cursor.x, ); if (!cell.attrs.wide_spacer_tail or screen.cursor.x == 0) - break :cell .{ cell, screen.cursor.x }; + break :cell .{ cell.attrs.wide, screen.cursor.x }; // If we're part of a wide character, we move the cursor back to // the actual character. @@ -890,7 +899,7 @@ fn addCursor( .active, screen.cursor.y, screen.cursor.x - 1, - ), screen.cursor.x - 1 }; + ).attrs.wide, screen.cursor.x - 1 }; }; const color = self.cursor_color orelse self.foreground_color; @@ -910,7 +919,7 @@ fn addCursor( self.alloc, font.sprite_index, @intFromEnum(sprite), - .{ .cell_width = if (cell.attrs.wide) 2 else 1 }, + .{ .cell_width = if (wide) 2 else 1 }, ) catch |err| { log.warn("error rendering cursor glyph err={}", .{err}); return null; @@ -920,7 +929,7 @@ fn addCursor( .mode = .fg, .grid_col = @intCast(x), .grid_row = @intCast(screen.cursor.y), - .grid_width = if (cell.attrs.wide) 2 else 1, + .grid_width = if (wide) 2 else 1, .fg_r = color.r, .fg_g = color.g, .fg_b = color.b,