fix: incorrect delete selected block if is utf-8 text

add param byte_delete to edit_delete, if byte_delete = 1 then one byte only delete,
but not multibyte char.
This commit is contained in:
Ilia Maslakov 2009-04-21 22:32:30 +00:00
parent 990838a226
commit 945d2183ac
4 changed files with 19 additions and 18 deletions

View File

@ -1070,7 +1070,7 @@ void edit_insert_ahead (WEdit * edit, int c)
}
int edit_delete (WEdit * edit)
int edit_delete (WEdit * edit, const int byte_delete)
{
int p = 0;
int cw = 1;
@ -1083,7 +1083,8 @@ int edit_delete (WEdit * edit)
edit->last_get_rule -= (edit->last_get_rule > edit->curs1);
cw = 1;
if ( edit->utf8 ) {
/* if byte_delete = 1 then delete only one byte not multibyte char*/
if ( edit->utf8 && byte_delete == 0 ) {
edit_get_utf (edit, edit->curs1, &cw);
if ( cw < 1 )
cw = 1;
@ -1950,7 +1951,7 @@ static void edit_right_delete_word (WEdit * edit)
for (;;) {
if (edit->curs1 >= edit->last_byte)
break;
c1 = edit_delete (edit);
c1 = edit_delete (edit, 1);
c2 = edit_get_byte (edit, edit->curs1);
if ((isspace (c1) == 0) != (isspace (c2) == 0))
break;
@ -2000,7 +2001,7 @@ edit_do_undo (WEdit * edit)
edit_backspace (edit);
break;
case DELCHAR:
edit_delete (edit);
edit_delete (edit, 0);
break;
case COLUMN_ON:
column_highlighting = 1;
@ -2044,7 +2045,7 @@ static void edit_delete_to_line_end (WEdit * edit)
while (edit_get_byte (edit, edit->curs1) != '\n') {
if (!edit->curs2)
break;
edit_delete (edit);
edit_delete (edit, 1);
}
}
@ -2066,7 +2067,7 @@ edit_delete_line (WEdit *edit)
* beyond EOF.
*/
while (edit_get_byte (edit, edit->curs1) != '\n') {
(void) edit_delete (edit);
(void) edit_delete (edit, 1);
}
/*
@ -2074,7 +2075,7 @@ edit_delete_line (WEdit *edit)
* Note that edit_delete() will not corrupt anything if called while
* cursor position is EOF.
*/
(void) edit_delete (edit);
(void) edit_delete (edit, 1);
/*
* Delete left part of the line.
@ -2383,7 +2384,7 @@ edit_execute_cmd (WEdit *edit, int command, int char_for_insertion)
if (char_for_insertion >= 0) {
if (edit->overwrite) {
if (edit_get_byte (edit, edit->curs1) != '\n')
edit_delete (edit);
edit_delete (edit, 1);
}
#ifdef HAVE_CHARSET
if ( char_for_insertion > 255 && utf8_display == 0 ) {
@ -2501,11 +2502,11 @@ edit_execute_cmd (WEdit *edit, int command, int char_for_insertion)
int i;
if (is_in_indent (edit) && left_of_four_spaces (edit)) {
for (i = 1; i <= HALF_TAB_SIZE; i++)
edit_delete (edit);
edit_delete (edit, 1);
break;
}
}
edit_delete (edit);
edit_delete (edit, 0);
break;
case CK_Delete_Word_Left:
edit_left_delete_word (edit);

View File

@ -160,7 +160,7 @@ void edit_block_move_cmd (WEdit * edit);
int edit_block_delete_cmd (WEdit * edit);
void edit_delete_line (WEdit * edit);
int edit_delete (WEdit * edit);
int edit_delete (WEdit * edit, const int byte_delete);
void edit_insert (WEdit * edit, int c);
void edit_cursor_move (WEdit * edit, long increment);
void edit_push_action (WEdit * edit, long c, ...);

View File

@ -1142,7 +1142,7 @@ edit_block_move_cmd (WEdit *edit)
edit_scroll_screen_over_cursor (edit);
count = start_mark;
while (count < end_mark) {
copy_buf[end_mark - count - 1] = edit_delete (edit);
copy_buf[end_mark - count - 1] = edit_delete (edit, 1);
count++;
}
edit_scroll_screen_over_cursor (edit);
@ -1187,7 +1187,7 @@ edit_delete_column_of_text (WEdit * edit)
edit_cursor_move (edit, p - edit->curs1);
while (q > p) { /* delete line between margins */
if (edit_get_byte (edit, edit->curs1) != '\n')
edit_delete (edit);
edit_delete (edit, 1);
q--;
}
if (n) /* move to next line except on the last delete */
@ -1226,7 +1226,7 @@ edit_block_delete (WEdit *edit)
edit_delete_column_of_text (edit);
} else {
while (count < end_mark) {
edit_delete (edit);
edit_delete (edit, 1);
count++;
}
}
@ -2119,7 +2119,7 @@ edit_replace_cmd (WEdit *edit, int again)
times_replaced++;
i = editcmd_get_str_nlen(edit_get_byte_ptr(edit,edit->found_start), i);
while (i--)
edit_delete (edit);
edit_delete (edit, 1);
while (repl_str[++i])
edit_insert (edit, repl_str[i]);
} else {
@ -2132,7 +2132,7 @@ edit_replace_cmd (WEdit *edit, int again)
} else {
times_replaced++;
while (i--)
edit_delete (edit);
edit_delete (edit, 1);
while (input2[++i])
edit_insert (edit, input2[i]);
}

View File

@ -272,7 +272,7 @@ static void format_this (unsigned char *t, int size, int indent)
static void replace_at (WEdit * edit, long q, int c)
{
edit_cursor_move (edit, q - edit->curs1);
edit_delete (edit);
edit_delete (edit, 1);
edit_insert_ahead (edit, c);
}
@ -302,7 +302,7 @@ put_paragraph (WEdit * edit, unsigned char *t, long p, int indent, int size)
} else if (c == '\n') {
edit_cursor_move (edit, p - edit->curs1);
while (strchr ("\t ", edit_get_byte (edit, p))) {
edit_delete (edit);
edit_delete (edit, 1);
if (cursor > edit->curs1)
cursor--;
}