From 0b9701e8995fb93884a83b0924b98438ca7623a9 Mon Sep 17 00:00:00 2001
From: Michael Davis <mcarsondavis@gmail.com>
Date: Thu, 23 Jan 2025 18:12:15 -0500
Subject: [PATCH] tui buffer: Handle multi-width graphemes in
 set_string_anchored

We should skip zero-width graphemes and reset only long (more than
1-width) graphemes.

Connects #12036
---
 helix-tui/src/buffer.rs | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/helix-tui/src/buffer.rs b/helix-tui/src/buffer.rs
index 405a0acd..bfcf35ac 100644
--- a/helix-tui/src/buffer.rs
+++ b/helix-tui/src/buffer.rs
@@ -349,15 +349,20 @@ impl Buffer {
             if start_index > end_index {
                 break;
             }
+            let width = s.width();
+            if width == 0 {
+                continue;
+            }
 
             self.content[start_index].set_symbol(s);
             self.content[start_index].set_style(style(byte_offset));
 
-            for i in start_index + 1..end_index {
+            // Reset following cells if multi-width (they would be hidden by the grapheme):
+            for i in start_index + 1..start_index + width {
                 self.content[i].reset();
             }
 
-            start_index += s.width();
+            start_index += width;
         }
 
         (x, y)