fix edit_delete, edit_backspace now work with utf-8

This commit is contained in:
Ilia Maslakov 2009-04-14 06:07:35 +00:00
parent 4411af46bb
commit 21c88729a4

View File

@ -1059,6 +1059,8 @@ void edit_insert_ahead (WEdit * edit, int c)
int edit_delete (WEdit * edit) int edit_delete (WEdit * edit)
{ {
int p; int p;
int cw = 1;
if (!edit->curs2) if (!edit->curs2)
return 0; return 0;
@ -1066,6 +1068,13 @@ int edit_delete (WEdit * edit)
edit->mark2 -= (edit->mark2 > edit->curs1); edit->mark2 -= (edit->mark2 > edit->curs1);
edit->last_get_rule -= (edit->last_get_rule > edit->curs1); edit->last_get_rule -= (edit->last_get_rule > edit->curs1);
cw = 1;
if ( edit->utf8 ) {
edit_get_utf (edit, edit->curs1, &cw);
if ( cw < 1 )
cw = 1;
}
for ( int i = 1; i<= cw; i++ ) {
p = edit->buffers2[(edit->curs2 - 1) >> S_EDIT_BUF_SIZE][EDIT_BUF_SIZE - ((edit->curs2 - 1) & M_EDIT_BUF_SIZE) - 1]; p = edit->buffers2[(edit->curs2 - 1) >> S_EDIT_BUF_SIZE][EDIT_BUF_SIZE - ((edit->curs2 - 1) & M_EDIT_BUF_SIZE) - 1];
if (!(edit->curs2 & M_EDIT_BUF_SIZE)) { if (!(edit->curs2 & M_EDIT_BUF_SIZE)) {
@ -1074,6 +1083,7 @@ int edit_delete (WEdit * edit)
} }
edit->last_byte--; edit->last_byte--;
edit->curs2--; edit->curs2--;
}
edit_modification (edit); edit_modification (edit);
if (p == '\n') { if (p == '\n') {
@ -1097,6 +1107,8 @@ static int
edit_backspace (WEdit * edit) edit_backspace (WEdit * edit)
{ {
int p; int p;
int cw = 1;
if (!edit->curs1) if (!edit->curs1)
return 0; return 0;
@ -1104,6 +1116,13 @@ edit_backspace (WEdit * edit)
edit->mark2 -= (edit->mark2 >= edit->curs1); edit->mark2 -= (edit->mark2 >= edit->curs1);
edit->last_get_rule -= (edit->last_get_rule >= edit->curs1); edit->last_get_rule -= (edit->last_get_rule >= edit->curs1);
cw = 1;
if ( edit->utf8 ) {
edit_get_prev_utf (edit, edit->curs1, &cw);
if ( cw < 1 )
cw = 1;
}
for ( int i = 1; i<= cw; i++ ) {
p = *(edit->buffers1[(edit->curs1 - 1) >> S_EDIT_BUF_SIZE] + ((edit->curs1 - 1) & M_EDIT_BUF_SIZE)); p = *(edit->buffers1[(edit->curs1 - 1) >> S_EDIT_BUF_SIZE] + ((edit->curs1 - 1) & M_EDIT_BUF_SIZE));
if (!((edit->curs1 - 1) & M_EDIT_BUF_SIZE)) { if (!((edit->curs1 - 1) & M_EDIT_BUF_SIZE)) {
g_free (edit->buffers1[edit->curs1 >> S_EDIT_BUF_SIZE]); g_free (edit->buffers1[edit->curs1 >> S_EDIT_BUF_SIZE]);
@ -1111,7 +1130,7 @@ edit_backspace (WEdit * edit)
} }
edit->last_byte--; edit->last_byte--;
edit->curs1--; edit->curs1--;
}
edit_modification (edit); edit_modification (edit);
if (p == '\n') { if (p == '\n') {
if (edit->book_mark) if (edit->book_mark)