summaryrefslogtreecommitdiff
path: root/src/gui
diff options
context:
space:
mode:
authorSébastien Helleu <flashcode@flashtux.org>2022-12-17 15:20:23 +0100
committerSébastien Helleu <flashcode@flashtux.org>2022-12-18 14:13:14 +0100
commitdd9ae79204b815187472f5c5ab03495435affa7c (patch)
treef0232f26e1ad2b0b94c2ed2aabe0de5aa36e0d0b /src/gui
parentf03384d12426228bf80acb1ce4e05ad2d4ff4865 (diff)
downloadweechat-dd9ae79204b815187472f5c5ab03495435affa7c.zip
core: remove unused argument "pos" from function gui_input_insert_string, add tests on function
Diffstat (limited to 'src/gui')
-rw-r--r--src/gui/curses/gui-curses-key.c3
-rw-r--r--src/gui/curses/gui-curses-mouse.c3
-rw-r--r--src/gui/gui-chat.c2
-rw-r--r--src/gui/gui-cursor.c2
-rw-r--r--src/gui/gui-input.c23
-rw-r--r--src/gui/gui-input.h2
-rw-r--r--src/gui/gui-key.c6
-rw-r--r--src/gui/gui-window.c2
8 files changed, 16 insertions, 27 deletions
diff --git a/src/gui/curses/gui-curses-key.c b/src/gui/curses/gui-curses-key.c
index 6ca0f48b6..218940305 100644
--- a/src/gui/curses/gui-curses-key.c
+++ b/src/gui/curses/gui-curses-key.c
@@ -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 */
diff --git a/src/gui/curses/gui-curses-mouse.c b/src/gui/curses/gui-curses-mouse.c
index e49482b62..3a6325e09 100644
--- a/src/gui/curses/gui-curses-mouse.c
+++ b/src/gui/curses/gui-curses-mouse.c
@@ -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 */
diff --git a/src/gui/gui-chat.c b/src/gui/gui-chat.c
index 26d82aaf3..7f63523d9 100644
--- a/src/gui/gui-chat.c
+++ b/src/gui/gui-chat.c
@@ -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 */
diff --git a/src/gui/gui-cursor.c b/src/gui/gui-cursor.c
index 07ffda7c4..29452db44 100644
--- a/src/gui/gui-cursor.c
+++ b/src/gui/gui-cursor.c
@@ -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);
}
}
diff --git a/src/gui/gui-input.c b/src/gui/gui-input.c
index c7784047a..6fb378575 100644
--- a/src/gui/gui-input.c
+++ b/src/gui/gui-input.c
@@ -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 */
diff --git a/src/gui/gui-input.h b/src/gui/gui-input.h
index 3fafb7357..9aedf0ea1 100644
--- a/src/gui/gui-input.h
+++ b/src/gui/gui-input.h
@@ -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);
diff --git a/src/gui/gui-key.c b/src/gui/gui-key.c
index c33b11b48..4d31716c7 100644
--- a/src/gui/gui-key.c
+++ b/src/gui/gui-key.c
@@ -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,
diff --git a/src/gui/gui-window.c b/src/gui/gui-window.c
index 2280e6fce..34fe35871 100644
--- a/src/gui/gui-window.c
+++ b/src/gui/gui-window.c
@@ -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 */