mirror of
https://github.com/weechat/weechat.git
synced 2026-06-12 14:14:48 +02:00
core: remove unused argument "pos" from function gui_input_insert_string, add tests on function
This commit is contained in:
@@ -43,6 +43,7 @@ Bug fixes::
|
||||
|
||||
Tests::
|
||||
|
||||
* gui: add tests on input functions
|
||||
* scripts: add tests on config functions
|
||||
|
||||
Build::
|
||||
|
||||
@@ -441,8 +441,7 @@ gui_key_flush (int paste)
|
||||
{
|
||||
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 */
|
||||
|
||||
@@ -203,8 +203,7 @@ gui_mouse_grab_end (const char *mouse_key)
|
||||
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 */
|
||||
|
||||
+1
-1
@@ -1108,7 +1108,7 @@ gui_chat_hsignal_quote_line_cb (const void *pointer, void *data,
|
||||
(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 */
|
||||
|
||||
@@ -143,7 +143,7 @@ gui_cursor_display_debug_info ()
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
+7
-16
@@ -236,28 +236,22 @@ gui_input_set_pos (struct t_gui_buffer *buffer, int pos)
|
||||
}
|
||||
|
||||
/*
|
||||
* 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);
|
||||
@@ -270,11 +264,10 @@ gui_input_insert_string (struct t_gui_buffer *buffer, const char *string,
|
||||
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;
|
||||
@@ -384,8 +377,7 @@ gui_input_clipboard_paste (struct t_gui_buffer *buffer)
|
||||
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 */
|
||||
@@ -508,8 +500,7 @@ gui_input_complete (struct t_gui_buffer *buffer)
|
||||
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++;
|
||||
@@ -1893,7 +1884,7 @@ gui_input_insert (struct t_gui_buffer *buffer, const char *args)
|
||||
|
||||
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 */
|
||||
|
||||
+1
-1
@@ -36,7 +36,7 @@ extern void gui_input_text_changed_modifier_and_signal (struct t_gui_buffer *buf
|
||||
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);
|
||||
|
||||
+3
-3
@@ -234,7 +234,7 @@ gui_key_grab_end_timer_cb (const void *pointer, void *data,
|
||||
/* 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) */
|
||||
@@ -242,8 +242,8 @@ gui_key_grab_end_timer_cb (const void *pointer, void *data,
|
||||
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,
|
||||
|
||||
@@ -1734,7 +1734,7 @@ gui_window_search_end (struct t_gui_window *window)
|
||||
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 */
|
||||
|
||||
@@ -116,7 +116,36 @@ TEST(GuiInput, SearchSignal)
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
Reference in New Issue
Block a user