mirror of
https://github.com/irssi/irssi.git
synced 2026-08-10 12:23:37 +02:00
BIG5 fixes by vanilla@FreeBSD.org(?)
git-svn-id: http://svn.irssi.org/repos/irssi/trunk@3134 dbcabf3a-b0e7-0310-adc4-f8d773084564
This commit is contained in:
parent
6122035f2f
commit
7eb2fc70e3
6 changed files with 94 additions and 11 deletions
|
|
@ -68,6 +68,27 @@ void gui_entry_destroy(GUI_ENTRY_REC *entry)
|
|||
g_free(entry);
|
||||
}
|
||||
|
||||
/* Fixes the cursor position if it at big5_lo .
|
||||
Direct: -1 , left shift 1 byte.
|
||||
Direct: 0, +1 , right shift 1 byte.
|
||||
*/
|
||||
static int _fix_big5_pos(unichar *p, int pos, int direct)
|
||||
{
|
||||
int newpos;
|
||||
|
||||
for (newpos = 0; newpos < pos && p[newpos] != 0; ) {
|
||||
if (is_big5(p[newpos], p[newpos+1]))
|
||||
newpos += 2;
|
||||
else
|
||||
newpos++;
|
||||
}
|
||||
|
||||
if (newpos != pos)
|
||||
pos += direct > 0 ? 1 : -1;
|
||||
|
||||
return pos;
|
||||
}
|
||||
|
||||
/* Fixes the cursor position in screen */
|
||||
static void gui_entry_fix_cursor(GUI_ENTRY_REC *entry)
|
||||
{
|
||||
|
|
@ -85,6 +106,8 @@ static void gui_entry_fix_cursor(GUI_ENTRY_REC *entry)
|
|||
entry->scrstart = entry->pos - entry->scrpos;
|
||||
}
|
||||
|
||||
entry->scrstart = _fix_big5_pos(entry->text, entry->scrstart, -1);
|
||||
|
||||
if (old_scrstart != entry->scrstart)
|
||||
entry->redraw_needed_from = 0;
|
||||
}
|
||||
|
|
@ -341,13 +364,31 @@ char *gui_entry_get_cutbuffer(GUI_ENTRY_REC *entry)
|
|||
return buf;
|
||||
}
|
||||
|
||||
void gui_entry_erase_to(GUI_ENTRY_REC *entry, int pos, int update_cutbuffer)
|
||||
{
|
||||
int newpos, size = 0;
|
||||
|
||||
g_return_if_fail(entry != NULL);
|
||||
|
||||
for (newpos = gui_entry_get_pos(entry); newpos > pos; size++)
|
||||
newpos = _fix_big5_pos(entry->text, newpos - 1, -1);
|
||||
gui_entry_erase(entry, size, update_cutbuffer);
|
||||
}
|
||||
|
||||
void gui_entry_erase(GUI_ENTRY_REC *entry, int size, int update_cutbuffer)
|
||||
{
|
||||
int newpos;
|
||||
|
||||
g_return_if_fail(entry != NULL);
|
||||
|
||||
if (entry->pos < size)
|
||||
return;
|
||||
|
||||
/* recount the erase size with big5 charsets */
|
||||
for (newpos = entry->pos; newpos > 0 && size > 0; size--)
|
||||
newpos = _fix_big5_pos(entry->text, newpos-1, -1);
|
||||
size = entry->pos - newpos;
|
||||
|
||||
if (update_cutbuffer) {
|
||||
/* put erased text to cutbuffer */
|
||||
if (entry->cutbuffer == NULL || entry->cutbuffer_len < size) {
|
||||
|
|
@ -471,10 +512,24 @@ void gui_entry_set_pos(GUI_ENTRY_REC *entry, int pos)
|
|||
|
||||
void gui_entry_move_pos(GUI_ENTRY_REC *entry, int pos)
|
||||
{
|
||||
int newpos;
|
||||
|
||||
g_return_if_fail(entry != NULL);
|
||||
|
||||
if (entry->pos+pos >= 0 && entry->pos+pos <= entry->text_len)
|
||||
entry->pos += pos;
|
||||
/* move cursor with big5 charset */
|
||||
newpos = _fix_big5_pos(entry->text, entry->pos, -1);
|
||||
if (pos > 0) {
|
||||
while (pos > 0 && newpos < entry->text_len) {
|
||||
newpos = _fix_big5_pos(entry->text, newpos+1, 1);
|
||||
pos--;
|
||||
}
|
||||
} else {
|
||||
while (pos < 0 && newpos > 0) {
|
||||
newpos = _fix_big5_pos(entry->text, newpos-1, -1);
|
||||
pos++;
|
||||
}
|
||||
}
|
||||
entry->pos = newpos;
|
||||
|
||||
gui_entry_fix_cursor(entry);
|
||||
gui_entry_draw(entry);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue