1
0
mirror of https://github.com/irssi/irssi.git synced 2024-10-13 05:03:45 -04:00

forward_word and backward_word now move only to next/prev non-alphanumeric character. added forward_to_space and backward_to_space. transpose_characters moves the cursor to right. patch by peder@linpro.no.

git-svn-id: http://svn.irssi.org/repos/irssi/trunk@1920 dbcabf3a-b0e7-0310-adc4-f8d773084564
This commit is contained in:
Timo Sirainen 2001-10-25 14:39:36 +00:00 committed by cras
parent d4178292e5
commit 39b66ab883
3 changed files with 46 additions and 16 deletions

View File

@ -348,46 +348,60 @@ void gui_entry_move_pos(GUI_ENTRY_REC *entry, int pos)
gui_entry_draw(entry);
}
static void gui_entry_move_words_left(GUI_ENTRY_REC *entry, int count)
static void gui_entry_move_words_left(GUI_ENTRY_REC *entry, int count, int to_space)
{
int pos;
pos = entry->pos;
while (count > 0 && pos > 0) {
while (pos > 0 && entry->text->str[pos-1] == ' ')
pos--;
while (pos > 0 && entry->text->str[pos-1] != ' ')
pos--;
if (to_space) {
while (pos > 0 && entry->text->str[pos-1] == ' ')
pos--;
while (pos > 0 && entry->text->str[pos-1] != ' ')
pos--;
} else {
while (pos > 0 && !isalnum(entry->text->str[pos-1]))
pos--;
while (pos > 0 && isalnum(entry->text->str[pos-1]))
pos--;
}
count--;
}
entry->pos = pos;
}
static void gui_entry_move_words_right(GUI_ENTRY_REC *entry, int count)
static void gui_entry_move_words_right(GUI_ENTRY_REC *entry, int count, int to_space)
{
int pos;
pos = entry->pos;
while (count > 0 && pos < entry->text->len) {
while (pos < entry->text->len && entry->text->str[pos] != ' ')
pos++;
while (pos < entry->text->len && entry->text->str[pos] == ' ')
pos++;
if (to_space) {
while (pos < entry->text->len && entry->text->str[pos] == ' ')
pos++;
while (pos < entry->text->len && entry->text->str[pos] != ' ')
pos++;
} else {
while (pos < entry->text->len && !isalnum(entry->text->str[pos]))
pos++;
while (pos < entry->text->len && isalnum(entry->text->str[pos]))
pos++;
}
count--;
}
entry->pos = pos;
}
void gui_entry_move_words(GUI_ENTRY_REC *entry, int count)
void gui_entry_move_words(GUI_ENTRY_REC *entry, int count, int to_space)
{
g_return_if_fail(entry != NULL);
if (count < 0)
gui_entry_move_words_left(entry, -count);
gui_entry_move_words_left(entry, -count, to_space);
else if (count > 0)
gui_entry_move_words_right(entry, count);
gui_entry_move_words_right(entry, count, to_space);
gui_entry_fix_cursor(entry);
gui_entry_draw(entry);

View File

@ -35,7 +35,7 @@ void gui_entry_erase_next_word(GUI_ENTRY_REC *entry, int to_space);
int gui_entry_get_pos(GUI_ENTRY_REC *entry);
void gui_entry_set_pos(GUI_ENTRY_REC *entry, int pos);
void gui_entry_move_pos(GUI_ENTRY_REC *entry, int pos);
void gui_entry_move_words(GUI_ENTRY_REC *entry, int count);
void gui_entry_move_words(GUI_ENTRY_REC *entry, int count, int to_space);
void gui_entry_redraw(GUI_ENTRY_REC *entry);

View File

@ -216,12 +216,22 @@ static void key_forward_character(void)
static void key_backward_word(void)
{
gui_entry_move_words(active_entry, -1);
gui_entry_move_words(active_entry, -1, FALSE);
}
static void key_forward_word(void)
{
gui_entry_move_words(active_entry, 1);
gui_entry_move_words(active_entry, 1, FALSE);
}
static void key_backward_to_space(void)
{
gui_entry_move_words(active_entry, -1, TRUE);
}
static void key_forward_to_space(void)
{
gui_entry_move_words(active_entry, 1, TRUE);
}
static void key_erase_line(void)
@ -278,6 +288,7 @@ static void key_transpose_characters(void)
gui_entry_move_pos(active_entry, -1);
gui_entry_insert_char(active_entry, c);
gui_entry_set_pos(active_entry, pos);
gui_entry_move_pos(active_entry, 1);
}
static void key_delete_character(void)
@ -550,6 +561,8 @@ void gui_readline_init(void)
key_bind("forward_character", "", "right", NULL, (SIGNAL_FUNC) key_forward_character);
key_bind("backward_word", "", "meta2-d", NULL, (SIGNAL_FUNC) key_backward_word);
key_bind("forward_word", "", "meta2-c", NULL, (SIGNAL_FUNC) key_forward_word);
key_bind("backward_to_space", "", NULL, NULL, (SIGNAL_FUNC) key_backward_to_space);
key_bind("forward_to_space", "", NULL, NULL, (SIGNAL_FUNC) key_forward_to_space);
key_bind("beginning_of_line", "", "home", NULL, (SIGNAL_FUNC) key_beginning_of_line);
key_bind("beginning_of_line", NULL, "^A", NULL, (SIGNAL_FUNC) key_beginning_of_line);
key_bind("end_of_line", "", "end", NULL, (SIGNAL_FUNC) key_end_of_line);
@ -628,6 +641,8 @@ void gui_readline_deinit(void)
key_unbind("forward_character", (SIGNAL_FUNC) key_forward_character);
key_unbind("backward_word", (SIGNAL_FUNC) key_backward_word);
key_unbind("forward_word", (SIGNAL_FUNC) key_forward_word);
key_unbind("backward_to_space", (SIGNAL_FUNC) key_backward_to_space);
key_unbind("forward_to_space", (SIGNAL_FUNC) key_forward_to_space);
key_unbind("beginning_of_line", (SIGNAL_FUNC) key_beginning_of_line);
key_unbind("end_of_line", (SIGNAL_FUNC) key_end_of_line);
@ -638,6 +653,7 @@ void gui_readline_deinit(void)
key_unbind("delete_character", (SIGNAL_FUNC) key_delete_character);
key_unbind("delete_next_word", (SIGNAL_FUNC) key_delete_next_word);
key_unbind("delete_previous_word", (SIGNAL_FUNC) key_delete_previous_word);
key_unbind("delete_to_next_space", (SIGNAL_FUNC) key_delete_to_next_space);
key_unbind("delete_to_previous_space", (SIGNAL_FUNC) key_delete_to_previous_space);
key_unbind("erase_line", (SIGNAL_FUNC) key_erase_line);
key_unbind("erase_to_beg_of_line", (SIGNAL_FUNC) key_erase_to_beg_of_line);