Skip to content

A modern terminal with a built-in multiplexer: close it and your sessions keep running. Run shells and tons of AI agents across your machines, then pick them up from desktop, browser, TUI and more. Written in Rust with no UI framework: interface drawn straight on the GPU. No Electron, GPUI or webview.

fix(gui): stop dropping the last glyph of text sized to fit it

RoversXa8dcf9f5f9ba
diff --git a/wezterm-gui/src/settings_window.rs b/wezterm-gui/src/settings_window.rs
index 2b91a174..db50f705 100644
--- a/wezterm-gui/src/settings_window.rs
+++ b/wezterm-gui/src/settings_window.rs
@@ -17667,6 +17667,11 @@ impl SettingsWindow {
let right_edge = x + max_width;
for glyph in &shaped.glyphs {
+ // Fitted by advance, as the measurement and the ellipsis are; see
+ // `DrawContext::draw_text_on_layer`.
+ if pos_x + glyph.x_advance.get() as f32 > right_edge + 0.5 {
+ break;
+ }
if let Some(texture) = glyph.texture.as_ref() {
let glyph_x = (pos_x + (glyph.x_offset + glyph.bearing_x).get() as f32).round();
let glyph_y =
@@ -17674,10 +17679,6 @@ impl SettingsWindow {
let width = texture.coords.size.width as f32 * glyph.scale as f32;
let height = texture.coords.size.height as f32 * glyph.scale as f32;
- if glyph_x + width > right_edge {
- break;
- }
-
let mut quad = layers.allocate(layer_num)?;
quad.set_position(
glyph_x - left_offset,
diff --git a/wezterm-gui/src/ui/draw.rs b/wezterm-gui/src/ui/draw.rs
index a8004dd6..6833a65a 100644
--- a/wezterm-gui/src/ui/draw.rs
+++ b/wezterm-gui/src/ui/draw.rs
@@ -803,6 +803,14 @@ impl<'a> DrawContext<'a> {
for info in infos {
let glyph = glyph_cache.cached_glyph(&info, style, false, font, self.metrics, 1)?;
+ // Whether a glyph fits is a question for its advance, as it is
+ // for `measure_text_width` and the ellipsis. The ink a glyph
+ // draws past its advance -- rounding on a 1x screen, a heavier
+ // face -- is no reason to drop it, and a box sized to the
+ // measured text lost its last glyph to exactly that.
+ if pos_x + glyph.x_advance.get() as f32 > right_edge + 0.5 {
+ break;
+ }
if let Some(texture) = glyph.texture.as_ref() {
let glyph_x = (pos_x + (glyph.x_offset + glyph.bearing_x).get() as f32).round();
let glyph_y =
@@ -810,10 +818,6 @@ impl<'a> DrawContext<'a> {
let width = texture.coords.size.width as f32 * glyph.scale as f32;
let height = texture.coords.size.height as f32 * glyph.scale as f32;
- if glyph_x + width > right_edge {
- break;
- }
-
let mut quad = layers.allocate(layer_num)?;
quad.set_position(
glyph_x - left_offset,