vt: don’t reset utf8proc grapheme state when we’re not at a grapheme break

This commit is contained in:
Daniel Eklöf 2021-06-25 20:42:23 +02:00
parent d206697001
commit 0ff8f72a9d
No known key found for this signature in database
GPG key ID: 5BBD4992C116573F
2 changed files with 12 additions and 5 deletions

View file

@ -33,6 +33,10 @@
### Deprecated ### Deprecated
### Removed ### Removed
### Fixed ### Fixed
* Grapheme cluster state being reset between codepoints.
### Security ### Security
### Contributors ### Contributors

13
vt.c
View file

@ -639,10 +639,10 @@ action_utf8_print(struct terminal *term, wchar_t wc)
#if defined(FOOT_GRAPHEME_CLUSTERING) #if defined(FOOT_GRAPHEME_CLUSTERING)
if (grapheme_clustering) { if (grapheme_clustering) {
/* Check if we're on a grapheme cluster break */ /* Check if we're on a grapheme cluster break */
/* Note: utf8proc fails to ZWJ */ if (utf8proc_grapheme_break_stateful(
if (utf8proc_grapheme_break_stateful(last, wc, &term->vt.grapheme_state) && last, wc, &term->vt.grapheme_state))
last != 0x200d /* ZWJ */)
{ {
term_reset_grapheme_state(term);
goto out; goto out;
} }
} }
@ -682,6 +682,7 @@ action_utf8_print(struct terminal *term, wchar_t wc)
{ {
wc = precomposed; wc = precomposed;
width = precomposed_width; width = precomposed_width;
term_reset_grapheme_state(term);
goto out; goto out;
} }
} }
@ -746,6 +747,7 @@ action_utf8_print(struct terminal *term, wchar_t wc)
* character chains. Fall through here and print the * character chains. Fall through here and print the
* current zero-width character to the current cell */ * current zero-width character to the current cell */
LOG_WARN("maximum number of composed characters reached"); LOG_WARN("maximum number of composed characters reached");
term_reset_grapheme_state(term);
goto out; goto out;
} }
@ -780,10 +782,11 @@ action_utf8_print(struct terminal *term, wchar_t wc)
xassert(wc <= CELL_COMB_CHARS_HI); xassert(wc <= CELL_COMB_CHARS_HI);
goto out; goto out;
} }
} } else
term_reset_grapheme_state(term);
out: out:
term_reset_grapheme_state(term);
if (width > 0) if (width > 0)
term_print(term, wc, width); term_print(term, wc, width);
} }