1
0
mirror of https://github.com/rkd77/elinks.git synced 2024-12-04 14:46:47 -05:00

UTF-8: Don't update form_state.state_cell if it is not used.

FC_TEXT, FC_PASSWORD, and FC_FILE do not use state_cell.
FC_TEXTAREA does use it.
This commit is contained in:
Kalle Olavi Niemitalo 2006-09-02 23:16:32 +03:00 committed by Kalle Olavi Niemitalo
parent 8d77387f6f
commit cc6939b9f8
2 changed files with 8 additions and 73 deletions

View File

@ -164,10 +164,6 @@ init_form_state(struct form_control *fc, struct form_state *fs)
fs->value = stracpy(fc->default_value); fs->value = stracpy(fc->default_value);
fs->state = strlen(fc->default_value); fs->state = strlen(fc->default_value);
#ifdef CONFIG_UTF_8 #ifdef CONFIG_UTF_8
if (fc->type == FC_TEXT)
fs->state_cell = utf8_ptr2cells(fs->value, NULL);
if (fc->type == FC_PASSWORD)
fs->state_cell = utf8_ptr2chars(fs->value, NULL);
if (fc->type == FC_TEXTAREA) if (fc->type == FC_TEXTAREA)
fs->state_cell = 0; fs->state_cell = 0;
#endif /* CONFIG_UTF_8 */ #endif /* CONFIG_UTF_8 */
@ -176,9 +172,6 @@ init_form_state(struct form_control *fc, struct form_state *fs)
case FC_FILE: case FC_FILE:
fs->value = stracpy(""); fs->value = stracpy("");
fs->state = 0; fs->state = 0;
#ifdef CONFIG_UTF_8
fs->state_cell = 0;
#endif /* CONFIG_UTF_8 */
fs->vpos = 0; fs->vpos = 0;
break; break;
case FC_SELECT: case FC_SELECT:
@ -1391,20 +1384,10 @@ field_op(struct session *ses, struct document_view *doc_view,
break; break;
} }
if (utf8) { if (utf8) {
int old_state = fs->state;
unsigned char *new_value; unsigned char *new_value;
int cells;
new_value = utf8_prevchar(fs->value + fs->state, 1, fs->value); new_value = utf8_prevchar(fs->value + fs->state, 1, fs->value);
fs->state = new_value - fs->value; fs->state = new_value - fs->value;
if (old_state != fs->state) {
if (fc->type == FC_PASSWORD)
cells = 1;
else
cells = utf8_char2cells(new_value, NULL);
fs->state_cell = int_max(fs->state_cell - cells, 0);
}
} else } else
#endif /* CONFIG_UTF_8 */ #endif /* CONFIG_UTF_8 */
fs->state = int_max(fs->state - 1, 0); fs->state = int_max(fs->state - 1, 0);
@ -1418,17 +1401,9 @@ field_op(struct session *ses, struct document_view *doc_view,
if (utf8) { if (utf8) {
unsigned char *text = fs->value + fs->state; unsigned char *text = fs->value + fs->state;
unsigned char *end = strchr(text, '\0'); unsigned char *end = strchr(text, '\0');
int old_state = fs->state;
unicode_val_T data = utf_8_to_unicode(&text, end);
utf_8_to_unicode(&text, end);
fs->state = (int)(text - fs->value); fs->state = (int)(text - fs->value);
if (old_state != fs->state) {
if (fc->type == FC_PASSWORD)
fs->state_cell = int_min(fs->state_cell + 1,
utf8_ptr2cells(fs->value, NULL));
else
fs->state_cell += unicode_to_cell(data);
}
} else } else
#endif /* CONFIG_UTF_8 */ #endif /* CONFIG_UTF_8 */
fs->state = int_min(fs->state + 1, strlen(fs->value)); fs->state = int_min(fs->state + 1, strlen(fs->value));
@ -1439,7 +1414,6 @@ field_op(struct session *ses, struct document_view *doc_view,
status = textarea_op_home(fs, fc, utf8); status = textarea_op_home(fs, fc, utf8);
} else { } else {
fs->state = 0; fs->state = 0;
fs->state_cell = 0;
} }
#else #else
if (fc->type == FC_TEXTAREA) { if (fc->type == FC_TEXTAREA) {
@ -1479,29 +1453,19 @@ field_op(struct session *ses, struct document_view *doc_view,
#endif /* CONFIG_UTF_8 */ #endif /* CONFIG_UTF_8 */
} else { } else {
fs->state = strlen(fs->value); fs->state = strlen(fs->value);
#ifdef CONFIG_UTF_8
if (utf8 && fc->type != FC_PASSWORD)
fs->state_cell = utf8_ptr2cells(fs->value,
fs->value + fs->state);
else if(utf8)
fs->state_cell = utf8_ptr2chars(fs->value,
fs->value + fs->state);
#endif /* CONFIG_UTF_8 */
} }
break; break;
case ACT_EDIT_BEGINNING_OF_BUFFER: case ACT_EDIT_BEGINNING_OF_BUFFER:
if (fc->type == FC_TEXTAREA) { if (fc->type == FC_TEXTAREA) {
#ifdef CONFIG_UTF_8 #ifdef CONFIG_UTF_8
status = textarea_op_bob(fs, fc, utf8); status = textarea_op_bob(fs, fc, utf8);
fs->state_cell = 0;
#else #else
status = textarea_op_bob(fs, fc); status = textarea_op_bob(fs, fc);
#endif /* CONFIG_UTF_8 */ #endif /* CONFIG_UTF_8 */
} else { } else {
fs->state = 0; fs->state = 0;
} }
#ifdef CONFIG_UTF_8
fs->state_cell = 0;
#endif /* CONFIG_UTF_8 */
break; break;
case ACT_EDIT_END_OF_BUFFER: case ACT_EDIT_END_OF_BUFFER:
if (fc->type == FC_TEXTAREA) { if (fc->type == FC_TEXTAREA) {
@ -1512,15 +1476,6 @@ field_op(struct session *ses, struct document_view *doc_view,
#endif /* CONFIG_UTF_8 */ #endif /* CONFIG_UTF_8 */
} else { } else {
fs->state = strlen(fs->value); fs->state = strlen(fs->value);
#ifdef CONFIG_UTF_8
if (utf8 && fc->type != FC_PASSWORD)
fs->state_cell = utf8_ptr2cells(fs->value,
fs->value + fs->state);
else if(utf8)
fs->state_cell = utf8_ptr2chars(fs->value,
fs->value + fs->state);
#endif /* CONFIG_UTF_8 */
} }
break; break;
case ACT_EDIT_OPEN_EXTERNAL: case ACT_EDIT_OPEN_EXTERNAL:
@ -1539,7 +1494,8 @@ field_op(struct session *ses, struct document_view *doc_view,
fs->value[0] = 0; fs->value[0] = 0;
fs->state = 0; fs->state = 0;
#ifdef CONFIG_UTF_8 #ifdef CONFIG_UTF_8
fs->state_cell = 0; if (fc->type == FC_TEXTAREA)
fs->state_cell = 0;
#endif /* CONFIG_UTF_8 */ #endif /* CONFIG_UTF_8 */
break; break;
case ACT_EDIT_PASTE_CLIPBOARD: case ACT_EDIT_PASTE_CLIPBOARD:
@ -1557,14 +1513,8 @@ field_op(struct session *ses, struct document_view *doc_view,
memmove(v, text, length + 1); memmove(v, text, length + 1);
fs->state = strlen(fs->value); fs->state = strlen(fs->value);
#ifdef CONFIG_UTF_8 #ifdef CONFIG_UTF_8
if(utf8 && fc->type == FC_PASSWORD) if (utf8 && fc->type == FC_TEXTAREA)
fs->state_cell = utf8_ptr2chars(fs->value,
fs->value + fs->state);
else if (utf8 && fc->type == FC_TEXTAREA)
fs->state_cell = 0; fs->state_cell = 0;
else if (utf8)
fs->state_cell = utf8_ptr2cells(fs->value,
fs->value + fs->state);
#endif /* CONFIG_UTF_8 */ #endif /* CONFIG_UTF_8 */
} }
} }
@ -1612,10 +1562,6 @@ field_op(struct session *ses, struct document_view *doc_view,
if (old_state != fs->state) { if (old_state != fs->state) {
if (fc->type == FC_TEXTAREA) if (fc->type == FC_TEXTAREA)
fs->state_cell = 0; fs->state_cell = 0;
else if (fc->type == FC_PASSWORD)
fs->state_cell = int_max(fs->state_cell - 1, 0);
else
fs->state_cell -= utf8_char2cells(new_value, NULL);
length = strlen(fs->value + old_state) + 1; length = strlen(fs->value + old_state) + 1;
memmove(new_value, fs->value + old_state, length); memmove(new_value, fs->value + old_state, length);
} }
@ -1685,14 +1631,8 @@ field_op(struct session *ses, struct document_view *doc_view,
fs->state = (int) (text - fs->value); fs->state = (int) (text - fs->value);
#ifdef CONFIG_UTF_8 #ifdef CONFIG_UTF_8
if (utf8) { if (utf8) {
if(fc->type == FC_PASSWORD) if (fc->type == FC_TEXTAREA)
fs->state_cell = utf8_ptr2cells(fs->value,
fs->value + fs->state);
else if (fc->type == FC_TEXTAREA)
fs->state_cell = 0; fs->state_cell = 0;
else
fs->state_cell = utf8_ptr2cells(fs->value,
fs->value + fs->state);
} }
#endif /* CONFIG_UTF_8 */ #endif /* CONFIG_UTF_8 */
break; break;
@ -1821,12 +1761,8 @@ field_op(struct session *ses, struct document_view *doc_view,
} }
fs->state += length; fs->state += length;
if (fc->type == FC_PASSWORD) if (fc->type == FC_TEXTAREA)
fs->state_cell += (is_cp_utf8(cp) ? 1 : length);
else if (fc->type == FC_TEXTAREA)
fs->state_cell = 0; fs->state_cell = 0;
else
fs->state_cell += (is_cp_utf8(cp) ? unicode_to_cell(get_kbd_key(ev)) : length);
} }
#else #else
fs->value[fs->state++] = get_kbd_key(ev); fs->value[fs->state++] = get_kbd_key(ev);

View File

@ -53,8 +53,7 @@ struct form_state {
int state; int state;
#ifdef CONFIG_UTF_8 #ifdef CONFIG_UTF_8
/* For FC_TEXT, FC_PASSWORD, and FC_FILE, @state_cell is not /* For FC_TEXT, FC_PASSWORD, and FC_FILE, @state_cell is not
* used. There is still code that updates it; such code * used. */
* should be removed. */
int state_cell; int state_cell;
#endif /* CONFIG_UTF_8 */ #endif /* CONFIG_UTF_8 */
/* For FC_TEXT, FC_PASSWORD, and FC_FILE, @vpos is the index /* For FC_TEXT, FC_PASSWORD, and FC_FILE, @vpos is the index