mirror of
https://codeberg.org/dnkl/foot.git
synced 2026-03-30 11:10:23 -04:00
ime: don’t underline characters inside the cursor-box
This commit is contained in:
parent
fc2bcf9bc0
commit
a6ed9a9773
1 changed files with 131 additions and 125 deletions
36
ime.c
36
ime.c
|
|
@ -151,7 +151,11 @@ done(void *data, struct zwp_text_input_v3 *zwp_text_input_v3,
|
||||||
? mbstowcs(NULL, seat->ime.preedit.pending.text, 0)
|
? mbstowcs(NULL, seat->ime.preedit.pending.text, 0)
|
||||||
: 0;
|
: 0;
|
||||||
|
|
||||||
if (wchars > 0) {
|
if (wchars == 0 || wchars == (size_t)-1) {
|
||||||
|
ime_reset_preedit(seat);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
/* First, convert to unicode */
|
/* First, convert to unicode */
|
||||||
term->ime.preedit.text = xmalloc((wchars + 1) * sizeof(wchar_t));
|
term->ime.preedit.text = xmalloc((wchars + 1) * sizeof(wchar_t));
|
||||||
mbstowcs(term->ime.preedit.text, seat->ime.preedit.pending.text, wchars);
|
mbstowcs(term->ime.preedit.text, seat->ime.preedit.pending.text, wchars);
|
||||||
|
|
@ -179,7 +183,7 @@ done(void *data, struct zwp_text_input_v3 *zwp_text_input_v3,
|
||||||
int width = widths[i];
|
int width = widths[i];
|
||||||
|
|
||||||
cell->wc = term->ime.preedit.text[i];
|
cell->wc = term->ime.preedit.text[i];
|
||||||
cell->attrs = (struct attributes){.clean = 0, .underline = 1};
|
cell->attrs = (struct attributes){.clean = 0};
|
||||||
|
|
||||||
for (int j = 1; j < width; j++) {
|
for (int j = 1; j < width; j++) {
|
||||||
cell = &term->ime.preedit.cells[cell_idx + j];
|
cell = &term->ime.preedit.cells[cell_idx + j];
|
||||||
|
|
@ -232,7 +236,7 @@ done(void *data, struct zwp_text_input_v3 *zwp_text_input_v3,
|
||||||
wc_idx < wchars &&
|
wc_idx < wchars &&
|
||||||
cell_idx < cell_count &&
|
cell_idx < cell_count &&
|
||||||
(cell_begin < 0 || cell_end < 0);
|
(cell_begin < 0 || cell_end < 0);
|
||||||
)
|
cell_idx += widths[wc_idx], wc_idx++)
|
||||||
{
|
{
|
||||||
if (seat->ime.preedit.pending.cursor_begin == byte_idx)
|
if (seat->ime.preedit.pending.cursor_begin == byte_idx)
|
||||||
cell_begin = cell_idx;
|
cell_begin = cell_idx;
|
||||||
|
|
@ -247,8 +251,6 @@ done(void *data, struct zwp_text_input_v3 *zwp_text_input_v3,
|
||||||
break;
|
break;
|
||||||
|
|
||||||
byte_idx += wc_bytes;
|
byte_idx += wc_bytes;
|
||||||
cell_idx += max(wcwidth(term->ime.preedit.cells[cell_idx].wc), 1);
|
|
||||||
wc_idx++;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (seat->ime.preedit.pending.cursor_end >= byte_len)
|
if (seat->ime.preedit.pending.cursor_end >= byte_len)
|
||||||
|
|
@ -258,15 +260,8 @@ done(void *data, struct zwp_text_input_v3 *zwp_text_input_v3,
|
||||||
cell_begin = min(max(cell_begin, 0), cell_count - 1);
|
cell_begin = min(max(cell_begin, 0), cell_count - 1);
|
||||||
cell_end = min(max(cell_end, 0), cell_count);
|
cell_end = min(max(cell_end, 0), cell_count);
|
||||||
|
|
||||||
#if 1
|
|
||||||
if (cell_end < cell_begin)
|
if (cell_end < cell_begin)
|
||||||
cell_end = cell_begin;
|
cell_end = cell_begin;
|
||||||
#else
|
|
||||||
if (cell_end <= cell_begin) {
|
|
||||||
cell_end = cell_begin + max(
|
|
||||||
wcwidth(term->ime.preedit.cells[cell_begin].wc), 1);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* Expand cursor end to end of glyph */
|
/* Expand cursor end to end of glyph */
|
||||||
while (cell_end > cell_begin && cell_end < cell_count &&
|
while (cell_end > cell_begin && cell_end < cell_count &&
|
||||||
|
|
@ -288,13 +283,24 @@ done(void *data, struct zwp_text_input_v3 *zwp_text_input_v3,
|
||||||
term->ime.preedit.cursor.end = cell_end;
|
term->ime.preedit.cursor.end = cell_end;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Underline pre-edit string that is *not* covered by the cursor */
|
||||||
|
bool hidden = term->ime.preedit.cursor.hidden;
|
||||||
|
int start = term->ime.preedit.cursor.start;
|
||||||
|
int end = term->ime.preedit.cursor.end;
|
||||||
|
|
||||||
|
for (size_t i = 0, cell_idx = 0; i < wchars; cell_idx += widths[i], i++) {
|
||||||
|
if (hidden || start == end || cell_idx < start || cell_idx >= end) {
|
||||||
|
struct cell *cell = &term->ime.preedit.cells[cell_idx];
|
||||||
|
cell->attrs.underline = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ime_reset_preedit(seat);
|
||||||
|
|
||||||
if (term->is_searching)
|
if (term->is_searching)
|
||||||
render_refresh_search(term);
|
render_refresh_search(term);
|
||||||
else
|
else
|
||||||
render_refresh(term);
|
render_refresh(term);
|
||||||
}
|
|
||||||
|
|
||||||
ime_reset_preedit(seat);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue