From 07ebd88c3ada636ed1a9382cce9c433686b5dcfd Mon Sep 17 00:00:00 2001 From: Simon Tatham Date: Tue, 26 Feb 2019 18:32:44 +0000 Subject: [PATCH] Fix selection and cursor handling for bidi + wide chars. Commit fec93d5e0 missed a piece: when we hand wcTo to term_bidi_cache_store and it uses it to set up the mapping between physical and logical character positions for cursor and selection handling, it will assume wcTo has as many entries as there are columns in the terminal. But in fact now wcTo may be shorter than that, so term_bidi_cache_store also needs to pay attention to the nchars field. --- terminal.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/terminal.c b/terminal.c index e977fd6b..929e1ec8 100644 --- a/terminal.c +++ b/terminal.c @@ -4869,10 +4869,10 @@ static void term_bidi_cache_store(Terminal *term, int line, termchar *lbefore, termchar *lafter, bidi_char *wcTo, int width, int size) { - int i; + int i, j; if (!term->pre_bidi_cache || term->bidi_cache_size <= line) { - int j = term->bidi_cache_size; + j = term->bidi_cache_size; term->bidi_cache_size = line+1; term->pre_bidi_cache = sresize(term->pre_bidi_cache, term->bidi_cache_size, @@ -4910,13 +4910,15 @@ static void term_bidi_cache_store(Terminal *term, int line, termchar *lbefore, memset(term->post_bidi_cache[line].forward, 0, width * sizeof(int)); memset(term->post_bidi_cache[line].backward, 0, width * sizeof(int)); - for (i = 0; i < width; i++) { + for (i = j = 0; j < width; j += wcTo[i].nchars, i++) { int p = wcTo[i].index; assert(0 <= p && p < width); - term->post_bidi_cache[line].backward[i] = p; - term->post_bidi_cache[line].forward[p] = i; + for (int x = 0; x < wcTo[i].nchars; x++) { + term->post_bidi_cache[line].backward[j+x] = p+x; + term->post_bidi_cache[line].forward[p+x] = j+x; + } } }