Skip to content

Commit c42c4e9

Browse files
committed
Fix shaping of Arabic test when the region is extended
* src/xdisp.c (compute_stop_pos): Set the limit for searching for changes in text properties such that the limit is never in the middle of composable text. (Bug#28312)
1 parent c310057 commit c42c4e9

File tree

1 file changed

+39
-1
lines changed

1 file changed

+39
-1
lines changed

src/xdisp.c

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3632,7 +3632,45 @@ compute_stop_pos (struct it *it)
36323632
/* Set up variables for computing the stop position from text
36333633
property changes. */
36343634
XSETBUFFER (object, current_buffer);
3635-
limit = make_fixnum (IT_CHARPOS (*it) + TEXT_PROP_DISTANCE_LIMIT);
3635+
pos = charpos + TEXT_PROP_DISTANCE_LIMIT;
3636+
/* Make sure the above arbitrary limit position is not in the
3637+
middle of composable text, so we don't break compositions by
3638+
submitting the composable text to the shaper in separate
3639+
chunks. We play safe here by assuming that only SPC, TAB,
3640+
FF, and NL cannot be in some composition; in particular, most
3641+
ASCII punctuation characters could be composed into ligatures. */
3642+
if (!NILP (BVAR (current_buffer, enable_multibyte_characters))
3643+
&& !NILP (Vauto_composition_mode))
3644+
{
3645+
ptrdiff_t endpos = charpos + 10 * TEXT_PROP_DISTANCE_LIMIT;
3646+
bool found = false;
3647+
3648+
if (pos > ZV)
3649+
pos = ZV;
3650+
if (endpos > ZV)
3651+
endpos = ZV;
3652+
ptrdiff_t bpos = CHAR_TO_BYTE (pos);
3653+
while (pos < endpos)
3654+
{
3655+
int ch;
3656+
FETCH_CHAR_ADVANCE_NO_CHECK (ch, pos, bpos);
3657+
if (ch == ' ' || ch == '\t' || ch == '\n' || ch == '\f')
3658+
{
3659+
found = true;
3660+
break;
3661+
}
3662+
}
3663+
if (found)
3664+
pos--;
3665+
else if (it->stop_charpos < endpos)
3666+
pos = it->stop_charpos;
3667+
else
3668+
{
3669+
/* Give up and use the original arbitrary limit. */
3670+
pos = charpos + TEXT_PROP_DISTANCE_LIMIT;
3671+
}
3672+
}
3673+
limit = make_fixnum (pos);
36363674
}
36373675

36383676
/* Get the interval containing IT's position. Value is a null

0 commit comments

Comments
 (0)