From 400aa4492f28ac6556727aac225bba51decc82b5 Mon Sep 17 00:00:00 2001 From: Bakkeby Date: Thu, 7 Mar 2024 21:43:24 +0100 Subject: [PATCH] Fix cursor move with wide glyphs st would always move back 1 column, even with wide glyhps (using more than a single column). The glyph rune is set on its first column, and the other ones are to 0, so loop until we detect the start of the previous glyph. ref. https://git.suckless.org/st/commit/7473a8d1a57e5f9aba41b953f4e498c35e1c9dc5.html --- st.c | 6 +++++- st.h | 4 ++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/st.c b/st.c index 0ef00db..b7bddf3 100644 --- a/st.c +++ b/st.c @@ -3079,12 +3079,16 @@ tstrsequence(uchar c) void tcontrolcode(uchar ascii) { + size_t i; + switch (ascii) { case '\t': /* HT */ tputtab(1); return; case '\b': /* BS */ - tmoveto(term.c.x-1, term.c.y); + for (i = 1; term.c.x && term.line[term.c.y][term.c.x - i].u == 0; ++i) + ; + tmoveto(term.c.x - i, term.c.y); return; case '\r': /* CR */ tmoveto(0, term.c.y); diff --git a/st.h b/st.h index 9dfd7dc..8d8ffa9 100644 --- a/st.h +++ b/st.h @@ -155,8 +155,8 @@ typedef struct { typedef struct { Glyph attr; /* current char attributes */ - int x; - int y; + int x; /* terminal column */ + int y; /* terminal row */ char state; } TCursor;