Tests::
+ * gui: add tests on input functions
* scripts: add tests on config functions
Build::
{
if (!paste || !undo_done)
gui_buffer_undo_snap (gui_current_window->buffer);
- gui_input_insert_string (gui_current_window->buffer,
- key_str, -1);
+ gui_input_insert_string (gui_current_window->buffer, key_str);
gui_input_text_changed_modifier_and_signal (gui_current_window->buffer,
(!paste || !undo_done) ? 1 : 0,
1); /* stop completion */
snprintf (mouse_key_input, sizeof (mouse_key_input),
"%s", mouse_key);
}
- gui_input_insert_string (gui_current_window->buffer,
- mouse_key_input, -1);
+ gui_input_insert_string (gui_current_window->buffer, mouse_key_input);
gui_input_text_changed_modifier_and_signal (gui_current_window->buffer,
1, /* save undo */
1); /* stop completion */
(ptr_prefix && ptr_prefix[0] && is_nick) ? CONFIG_STRING(config_look_quote_nick_suffix) : "",
(ptr_prefix && ptr_prefix[0]) ? " " : "",
message);
- gui_input_insert_string (gui_current_window->buffer, str, -1);
+ gui_input_insert_string (gui_current_window->buffer, str);
gui_input_text_changed_modifier_and_signal (gui_current_window->buffer,
1, /* save undo */
1); /* stop completion */
focus_info->chat,
focus_info->chat_word);
gui_input_delete_line (gui_current_window->buffer);
- gui_input_insert_string (gui_current_window->buffer, str_info, -1);
+ gui_input_insert_string (gui_current_window->buffer, str_info);
gui_focus_free_info (focus_info);
}
}
}
/*
- * Inserts a string into the input buffer.
- *
- * If pos == -1, string is inserted at cursor position.
+ * Inserts a string into the input buffer at cursor position.
*/
void
-gui_input_insert_string (struct t_gui_buffer *buffer, const char *string,
- int pos)
+gui_input_insert_string (struct t_gui_buffer *buffer, const char *string)
{
int size, length;
char *string_utf8, *ptr_start;
- if (!buffer->input)
+ if (!buffer->input || !string)
return;
string_utf8 = strdup (string);
if (!string_utf8)
return;
- if (pos == -1)
- pos = buffer->input_buffer_pos;
-
utf8_normalize (string_utf8, '?');
size = strlen (string_utf8);
buffer->input_buffer[buffer->input_buffer_size] = '\0';
/* move end of string to the right */
- ptr_start = (char *)utf8_add_offset (buffer->input_buffer, pos);
+ ptr_start = (char *)utf8_add_offset (buffer->input_buffer, buffer->input_buffer_pos);
memmove (ptr_start + size, ptr_start, strlen (ptr_start));
/* insert new string */
- ptr_start = (char *)utf8_add_offset (buffer->input_buffer, pos);
memcpy (ptr_start, string_utf8, size);
buffer->input_buffer_pos += length;
if (buffer->input && gui_input_clipboard)
{
gui_buffer_undo_snap (buffer);
- gui_input_insert_string (buffer,
- gui_input_clipboard, -1);
+ gui_input_insert_string (buffer, gui_input_clipboard);
gui_input_text_changed_modifier_and_signal (buffer,
1, /* save undo */
1); /* stop completion */
if (buffer->input_buffer[utf8_real_pos (buffer->input_buffer,
buffer->input_buffer_pos)] != ' ')
{
- gui_input_insert_string (buffer, " ",
- buffer->input_buffer_pos);
+ gui_input_insert_string (buffer, " ");
}
else
buffer->input_buffer_pos++;
gui_buffer_undo_snap (buffer);
args2 = string_convert_escaped_chars (args);
- gui_input_insert_string (buffer, (args2) ? args2 : args, -1);
+ gui_input_insert_string (buffer, (args2) ? args2 : args);
gui_input_text_changed_modifier_and_signal (buffer,
1, /* save undo */
1); /* stop completion */
int stop_completion);
extern void gui_input_set_pos (struct t_gui_buffer *buffer, int pos);
extern void gui_input_insert_string (struct t_gui_buffer *buffer,
- const char *string, int pos);
+ const char *string);
extern void gui_input_move_to_buffer (struct t_gui_buffer *from_buffer,
struct t_gui_buffer *to_buffer);
extern void gui_input_clipboard_paste (struct t_gui_buffer *buffer);
/* add expanded key to input buffer */
if (gui_current_window->buffer->input)
{
- gui_input_insert_string (gui_current_window->buffer, expanded_key, -1);
+ gui_input_insert_string (gui_current_window->buffer, expanded_key);
if (gui_key_grab_command)
{
/* add command bound to key (if found) */
gui_key_combo_buffer);
if (ptr_key)
{
- gui_input_insert_string (gui_current_window->buffer, " ", -1);
- gui_input_insert_string (gui_current_window->buffer, ptr_key->command, -1);
+ gui_input_insert_string (gui_current_window->buffer, " ");
+ gui_input_insert_string (gui_current_window->buffer, ptr_key->command);
}
}
gui_input_text_changed_modifier_and_signal (gui_current_window->buffer,
if (window->buffer->text_search_input)
{
gui_input_insert_string (window->buffer,
- window->buffer->text_search_input, -1);
+ window->buffer->text_search_input);
gui_input_text_changed_modifier_and_signal (window->buffer,
0, /* save undo */
1); /* stop completion */
TEST(GuiInput, InsertString)
{
- /* TODO: write tests */
+ gui_input_replace_input (gui_buffers, "");
+ LONGS_EQUAL(0, gui_buffers->input_buffer_pos);
+ STRCMP_EQUAL("", gui_buffers->input_buffer);
+
+ gui_input_insert_string (gui_buffers, NULL);
+ LONGS_EQUAL(0, gui_buffers->input_buffer_pos);
+ STRCMP_EQUAL("", gui_buffers->input_buffer);
+
+ gui_input_insert_string (gui_buffers, "");
+ STRCMP_EQUAL("", gui_buffers->input_buffer);
+ LONGS_EQUAL(0, gui_buffers->input_buffer_size);
+ LONGS_EQUAL(0, gui_buffers->input_buffer_length);
+ LONGS_EQUAL(0, gui_buffers->input_buffer_pos);
+
+ gui_input_insert_string (gui_buffers, "noël");
+ STRCMP_EQUAL("noël", gui_buffers->input_buffer);
+ LONGS_EQUAL(5, gui_buffers->input_buffer_size);
+ LONGS_EQUAL(4, gui_buffers->input_buffer_length);
+ LONGS_EQUAL(4, gui_buffers->input_buffer_pos);
+
+ gui_input_set_pos (gui_buffers, 3);
+ LONGS_EQUAL(5, gui_buffers->input_buffer_size);
+ LONGS_EQUAL(4, gui_buffers->input_buffer_length);
+ LONGS_EQUAL(3, gui_buffers->input_buffer_pos);
+
+ gui_input_insert_string (gui_buffers, "ï");
+ STRCMP_EQUAL("noëïl", gui_buffers->input_buffer);
+ LONGS_EQUAL(7, gui_buffers->input_buffer_size);
+ LONGS_EQUAL(5, gui_buffers->input_buffer_length);
+ LONGS_EQUAL(4, gui_buffers->input_buffer_pos);
}
/*