From 7dcc6c9a19a1ff8093b39d5c59c92640e6da13c4 Mon Sep 17 00:00:00 2001 From: Kalle Olavi Niemitalo Date: Mon, 31 Jul 2006 21:46:36 +0200 Subject: [PATCH] viewer UTF-8: Correctly position cursor for ACT_EDIT_LEFT in text input field. To reproduce the bug before this patch: Enable CONFIG_UTF_8, UTF-8 I/O, and UTF-8 charset. Go to www.google.com and type "abc" in the text input field. Then press Left. The cursor jumps to "a" when it should go to "c". --- src/viewer/text/form.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/viewer/text/form.c b/src/viewer/text/form.c index 29b981bc..867e0019 100644 --- a/src/viewer/text/form.c +++ b/src/viewer/text/form.c @@ -1312,15 +1312,17 @@ field_op(struct session *ses, struct document_view *doc_view, if (utf8) { int old_state = fs->state; unsigned char *new_value; + int cells; new_value = utf8_prevchar(fs->value + fs->state, 1, fs->value); fs->state = new_value - fs->value; if (old_state != fs->state) { if (fc->type == FC_PASSWORD) - fs->state_cell = int_max(fs->state_cell - 1, 0); + cells = 1; else - fs->state_cell = int_max(utf8_char2cells(new_value, NULL) - 1, 0); + cells = utf8_char2cells(new_value, NULL); + fs->state_cell = int_max(fs->state_cell - cells, 0); } } else #endif /* CONFIG_UTF_8 */