mirror of
https://git.tartarus.org/simon/putty.git
synced 2025-04-27 07:42:09 -05:00
Use a little termline to store pre-edit text
I think supporting combining characters in pre-edit text will be simpler if I can use add_cc, which operated on termlines. Also we have code for resizing termlines, which means I might not need to count the width of the pre-edit string accurately before allocating it.
This commit is contained in:
parent
3bbde58c09
commit
4776885767
@ -2160,7 +2160,7 @@ void term_free(Terminal *term)
|
|||||||
if (term->userpass_state)
|
if (term->userpass_state)
|
||||||
term_userpass_state_free(term->userpass_state);
|
term_userpass_state_free(term->userpass_state);
|
||||||
|
|
||||||
sfree(term->preedit_termchars);
|
freetermline(term->preedit_termline);
|
||||||
|
|
||||||
sfree(term);
|
sfree(term);
|
||||||
}
|
}
|
||||||
@ -6121,13 +6121,13 @@ static void do_paint(Terminal *term)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Work out if and where to display pre-edit text. */
|
/* Work out if and where to display pre-edit text. */
|
||||||
if (i == our_curs_y && term->preedit_termchars != NULL) {
|
if (i == our_curs_y && term->preedit_termline != NULL) {
|
||||||
debug("preedit_width = %d\n", term->preedit_width);
|
debug("preedit_width = %d\n", term->preedit_termline->cols);
|
||||||
preedit_start = our_curs_x;
|
preedit_start = our_curs_x;
|
||||||
preedit_end = preedit_start + term->preedit_width;
|
preedit_end = preedit_start + term->preedit_termline->cols;
|
||||||
if (preedit_end > term->cols) {
|
if (preedit_end > term->cols) {
|
||||||
preedit_end = term->cols;
|
preedit_end = term->cols;
|
||||||
preedit_start = preedit_end - term->preedit_width;
|
preedit_start = preedit_end - term->preedit_termline->cols;
|
||||||
}
|
}
|
||||||
our_curs_x = preedit_start;
|
our_curs_x = preedit_start;
|
||||||
}
|
}
|
||||||
@ -6143,7 +6143,7 @@ static void do_paint(Terminal *term)
|
|||||||
scrpos.x = backward ? backward[j] : j;
|
scrpos.x = backward ? backward[j] : j;
|
||||||
|
|
||||||
if (in_preedit)
|
if (in_preedit)
|
||||||
d = term->preedit_termchars + j - preedit_start;
|
d = term->preedit_termline->chars + j - preedit_start;
|
||||||
|
|
||||||
tchar = d->chr;
|
tchar = d->chr;
|
||||||
tattr = d->attr;
|
tattr = d->attr;
|
||||||
@ -6282,7 +6282,7 @@ static void do_paint(Terminal *term)
|
|||||||
bool in_preedit = j >= preedit_start && j < preedit_end;
|
bool in_preedit = j >= preedit_start && j < preedit_end;
|
||||||
|
|
||||||
if (in_preedit)
|
if (in_preedit)
|
||||||
d = term->preedit_termchars + j - preedit_start;
|
d = term->preedit_termline->chars + j - preedit_start;
|
||||||
|
|
||||||
tattr = newline[j].attr;
|
tattr = newline[j].attr;
|
||||||
tchar = newline[j].chr;
|
tchar = newline[j].chr;
|
||||||
@ -8138,29 +8138,25 @@ void term_notify_window_size_pixels(Terminal *term, int x, int y)
|
|||||||
*/
|
*/
|
||||||
void term_set_preedit_text(Terminal *term, char *preedit_text)
|
void term_set_preedit_text(Terminal *term, char *preedit_text)
|
||||||
{
|
{
|
||||||
sfree(term->preedit_termchars);
|
freetermline(term->preedit_termline);
|
||||||
term->preedit_termchars = NULL;
|
term->preedit_termline = NULL;
|
||||||
term->preedit_width = 0;
|
|
||||||
if (preedit_text != NULL) {
|
if (preedit_text != NULL) {
|
||||||
BinarySource src[1];
|
BinarySource src[1];
|
||||||
int i;
|
int width = 0, i;
|
||||||
|
|
||||||
debug("Pre-edit:");
|
debug("Pre-edit:");
|
||||||
BinarySource_BARE_INIT(src, preedit_text, strlen(preedit_text));
|
BinarySource_BARE_INIT(src, preedit_text, strlen(preedit_text));
|
||||||
while (get_avail(src))
|
while (get_avail(src))
|
||||||
term->preedit_width +=
|
width += term_char_width(term, decode_utf8(src, NULL));
|
||||||
term_char_width(term, decode_utf8(src, NULL));
|
term->preedit_termline = newtermline(term, width, false);
|
||||||
term->preedit_termchars = snewn(term->preedit_width, termchar);
|
|
||||||
BinarySource_REWIND(src);
|
BinarySource_REWIND(src);
|
||||||
for (i = 0; i < term->preedit_width; i++) {
|
for (i = 0; i < width; i++) {
|
||||||
unsigned int c = decode_utf8(src, NULL);
|
unsigned int c = decode_utf8(src, NULL);
|
||||||
debug(" U+%04X", c);
|
debug(" U+%04X", c);
|
||||||
if (term_char_width(term, c) >= 1) {
|
if (term_char_width(term, c) >= 1) {
|
||||||
term->preedit_termchars[i] = term->basic_erase_char;
|
term->preedit_termline->chars[i].chr = c;
|
||||||
term->preedit_termchars[i].chr = c;
|
|
||||||
if (term_char_width(term, c) >= 2) {
|
if (term_char_width(term, c) >= 2) {
|
||||||
term->preedit_termchars[i+1] = term->basic_erase_char;
|
term->preedit_termline->chars[i+1].chr = UCSWIDE;
|
||||||
term->preedit_termchars[i+1].chr = UCSWIDE;
|
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -444,8 +444,7 @@ struct terminal_tag {
|
|||||||
bool userpass_utf8_override;
|
bool userpass_utf8_override;
|
||||||
|
|
||||||
/* Input method state. */
|
/* Input method state. */
|
||||||
termchar *preedit_termchars;
|
termline *preedit_termline;
|
||||||
int preedit_width;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
static inline bool in_utf(Terminal *term)
|
static inline bool in_utf(Terminal *term)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user