summaryrefslogtreecommitdiff
path: root/src/gui/gui-input.c
diff options
context:
space:
mode:
authorSébastien Helleu <flashcode@flashtux.org>2022-09-18 23:26:49 +0200
committerSébastien Helleu <flashcode@flashtux.org>2022-09-18 23:26:49 +0200
commit01cf98e8fbd8411464fcedd97d7400d961f7e1f5 (patch)
treee806dd11db677e788e4991383fedc4c0c1ee02bc /src/gui/gui-input.c
parentd7c0e896b2d00e215cf3616edc16afeaeb60196f (diff)
downloadweechat-01cf98e8fbd8411464fcedd97d7400d961f7e1f5.zip
core: add key alt+backspace, change behavior of key ctrl+w (closes #559)
The key ctrl+w now deletes one word until whitespace. The new key alt+backspace deletes one word (same behavior as ctrl+w in previous releases).
Diffstat (limited to 'src/gui/gui-input.c')
-rw-r--r--src/gui/gui-input.c84
1 files changed, 68 insertions, 16 deletions
diff --git a/src/gui/gui-input.c b/src/gui/gui-input.c
index e8b6f5593..04b6a3fca 100644
--- a/src/gui/gui-input.c
+++ b/src/gui/gui-input.c
@@ -95,7 +95,7 @@ gui_input_replace_input (struct t_gui_buffer *buffer, const char *new_input)
int size, length;
char *input_utf8;
- input_utf8 = strdup (new_input);
+ input_utf8 = strdup ((new_input) ? new_input : "");
if (input_utf8)
{
utf8_normalize (input_utf8, '?');
@@ -838,13 +838,44 @@ gui_input_delete_next_char (struct t_gui_buffer *buffer)
}
/*
- * Deletes previous word (default key: ctrl-W).
+ * Delete the range between two positions and copy the content to the
+ * clipboard.
+ */
+
+void
+gui_input_delete_range (struct t_gui_buffer *buffer,
+ char *start,
+ char *end)
+{
+ int size_deleted, length_deleted;
+
+ size_deleted = utf8_next_char (end) - start;
+ length_deleted = utf8_strnlen (start, size_deleted);
+
+ gui_input_clipboard_copy (start, size_deleted);
+
+ memmove (start, start + size_deleted, strlen (start + size_deleted));
+
+ if (gui_input_optimize_size (
+ buffer,
+ buffer->input_buffer_size - size_deleted,
+ buffer->input_buffer_length - length_deleted))
+ {
+ buffer->input_buffer[buffer->input_buffer_size] = '\0';
+ buffer->input_buffer_pos -= length_deleted;
+ }
+ gui_input_text_changed_modifier_and_signal (buffer,
+ 1, /* save undo */
+ 1); /* stop completion */
+}
+
+/*
+ * Deletes previous word (default key: alt-backspace).
*/
void
gui_input_delete_previous_word (struct t_gui_buffer *buffer)
{
- int length_deleted, size_deleted;
char *start, *string;
if (buffer->input && (buffer->input_buffer_pos > 0))
@@ -872,24 +903,45 @@ gui_input_delete_previous_word (struct t_gui_buffer *buffer)
else
string = buffer->input_buffer;
- size_deleted = utf8_next_char (start) - string;
- length_deleted = utf8_strnlen (string, size_deleted);
+ gui_input_delete_range (buffer, string, start);
+ }
+}
- gui_input_clipboard_copy (string, size_deleted);
+/*
+ * Deletes previous word until whitespace (default key: ctrl-W).
+ */
- memmove (string, string + size_deleted, strlen (string + size_deleted));
+void
+gui_input_delete_previous_word_whitespace (struct t_gui_buffer *buffer)
+{
+ char *start, *string;
- if (gui_input_optimize_size (
- buffer,
- buffer->input_buffer_size - size_deleted,
- buffer->input_buffer_length - length_deleted))
+ if (buffer->input && (buffer->input_buffer_pos > 0))
+ {
+ gui_buffer_undo_snap (buffer);
+ start = (char *)utf8_add_offset (buffer->input_buffer,
+ buffer->input_buffer_pos - 1);
+ string = start;
+ /* move to the left, skipping whitespace */
+ while (string && string_is_whitespace_char (string))
{
- buffer->input_buffer[buffer->input_buffer_size] = '\0';
- buffer->input_buffer_pos -= length_deleted;
+ string = (char *)utf8_prev_char (buffer->input_buffer, string);
}
- gui_input_text_changed_modifier_and_signal (buffer,
- 1, /* save undo */
- 1); /* stop completion */
+ /* move to the left until we reach a char which is not whitespace */
+ if (string)
+ {
+ while (string && !string_is_whitespace_char (string))
+ {
+ string = (char *)utf8_prev_char (buffer->input_buffer, string);
+ }
+ }
+
+ if (string)
+ string = (char *)utf8_next_char (string);
+ else
+ string = buffer->input_buffer;
+
+ gui_input_delete_range (buffer, string, start);
}
}