summaryrefslogtreecommitdiff
path: root/src/core
diff options
context:
space:
mode:
authorTrygve Aaberge <trygveaa@gmail.com>2020-05-12 23:06:39 +0200
committerSébastien Helleu <flashcode@flashtux.org>2023-03-26 15:52:19 +0200
commit9ac30381faf07f298e88ee777cbc6748b68a5cab (patch)
tree342c6b2b1f11b4c56a35ecd34c48d55fab83d0b6 /src/core
parent20cea84917804baa379902e757cd1d71cc05d1a1 (diff)
downloadweechat-9ac30381faf07f298e88ee777cbc6748b68a5cab.zip
core: Implement commands for operating on a single input line
This changes the commands delete_beginning_of_line, delete_end_of_line, delete_line, move_beginning_of_line and move_end_of_line to operate on the current line instead of the whole input. The commands delete_beginning_of_input, delete_end_of_input, delete_input, move_beginning_of_input and move_end_of_input are added with the previous implementations that the line commands had. Additionally, the commands move_previous_line and move_next_line are added which moves the cursor to the previous/next line and keeps the horizontal position in the line. The meta-r key is changed from delete_line to delete_input to keep the behavior, and because you probably want to delete the whole input more often than the line. The meta-R key is added for delete_line. The home, end, ctrl-u and ctrl-k keys are kept to the same commands, which means that they change behaviour. This is because having them operate on the line is consistent with other applications (vim, zsh), and I also think it's more practical. These new bindings are added: shift-home: /input move_beginning_of_input shift-end: /input move_end_of_input shift-up: /input move_previous_line shift-down: /input move_next_line meta-R: /input delete_line meta-ctrl-u: /input delete_beginning_of_input meta-ctrl-k: /input delete_end_of_input Relates to #1498
Diffstat (limited to 'src/core')
-rw-r--r--src/core/wee-command.c32
-rw-r--r--src/core/wee-utf8.c42
-rw-r--r--src/core/wee-utf8.h3
3 files changed, 74 insertions, 3 deletions
diff --git a/src/core/wee-command.c b/src/core/wee-command.c
index 6f426c965..ab43e2c2f 100644
--- a/src/core/wee-command.c
+++ b/src/core/wee-command.c
@@ -3481,16 +3481,26 @@ COMMAND_CALLBACK(input)
gui_input_delete_next_word (buffer);
else if (string_strcmp (argv[1], "delete_beginning_of_line") == 0)
gui_input_delete_beginning_of_line (buffer);
+ else if (string_strcmp (argv[1], "delete_beginning_of_input") == 0)
+ gui_input_delete_beginning_of_input (buffer);
else if (string_strcmp (argv[1], "delete_end_of_line") == 0)
gui_input_delete_end_of_line (buffer);
+ else if (string_strcmp (argv[1], "delete_end_of_input") == 0)
+ gui_input_delete_end_of_input (buffer);
else if (string_strcmp (argv[1], "delete_line") == 0)
gui_input_delete_line (buffer);
+ else if (string_strcmp (argv[1], "delete_input") == 0)
+ gui_input_delete_input (buffer);
else if (string_strcmp (argv[1], "transpose_chars") == 0)
gui_input_transpose_chars (buffer);
else if (string_strcmp (argv[1], "move_beginning_of_line") == 0)
gui_input_move_beginning_of_line (buffer);
+ else if (string_strcmp (argv[1], "move_beginning_of_input") == 0)
+ gui_input_move_beginning_of_input (buffer);
else if (string_strcmp (argv[1], "move_end_of_line") == 0)
gui_input_move_end_of_line (buffer);
+ else if (string_strcmp (argv[1], "move_end_of_input") == 0)
+ gui_input_move_end_of_input (buffer);
else if (string_strcmp (argv[1], "move_previous_char") == 0)
gui_input_move_previous_char (buffer);
else if (string_strcmp (argv[1], "move_next_char") == 0)
@@ -3499,6 +3509,10 @@ COMMAND_CALLBACK(input)
gui_input_move_previous_word (buffer);
else if (string_strcmp (argv[1], "move_next_word") == 0)
gui_input_move_next_word (buffer);
+ else if (string_strcmp (argv[1], "move_previous_line") == 0)
+ gui_input_move_previous_line (buffer);
+ else if (string_strcmp (argv[1], "move_next_line") == 0)
+ gui_input_move_next_line (buffer);
else if (string_strcmp (argv[1], "history_previous") == 0)
gui_input_history_local_previous (buffer);
else if (string_strcmp (argv[1], "history_next") == 0)
@@ -8352,18 +8366,26 @@ command_init ()
" delete_next_word: delete next word\n"
" delete_beginning_of_line: delete from beginning of line until "
"cursor\n"
+ " delete_beginning_of_input: delete from beginning of input until "
" delete_end_of_line: delete from cursor until end of line\n"
+ "cursor\n"
+ " delete_end_of_input: delete from cursor until end of input\n"
" delete_line: delete entire line\n"
+ " delete_input: delete entire input\n"
" clipboard_paste: paste from the internal clipboard\n"
" transpose_chars: transpose two chars\n"
" undo: undo last command line action\n"
" redo: redo last command line action\n"
" move_beginning_of_line: move cursor to beginning of line\n"
+ " move_beginning_of_input: move cursor to beginning of input\n"
" move_end_of_line: move cursor to end of line\n"
+ " move_end_of_input: move cursor to end of input\n"
" move_previous_char: move cursor to previous char\n"
" move_next_char: move cursor to next char\n"
" move_previous_word: move cursor to previous word\n"
" move_next_word: move cursor to next word\n"
+ " move_previous_line: move cursor to previous line\n"
+ " move_next_line: move cursor to next line\n"
" history_previous: recall previous command in current buffer "
"history\n"
" history_next: recall next command in current buffer history\n"
@@ -8387,12 +8409,16 @@ command_init ()
"search_stop_here || search_stop || "
"delete_previous_char || delete_next_char || delete_previous_word || "
"delete_previous_word_whitespace || delete_next_word || "
- "delete_beginning_of_line || delete_end_of_line || delete_line || "
+ "delete_beginning_of_line || delete_beginning_of_input || "
+ "delete_end_of_line || delete_end_of_input || "
+ "delete_line || delete_input || "
"clipboard_paste || "
"transpose_chars || "
"undo || redo || "
- "move_beginning_of_line || move_end_of_line || move_previous_char || "
- "move_next_char || move_previous_word || move_next_word || "
+ "move_beginning_of_line || move_beginning_of_input || "
+ "move_end_of_line || move_end_of_input || "
+ "move_previous_char || move_next_char || move_previous_word || "
+ "move_next_word || move_previous_line || move_next_line || "
"history_previous || history_next || history_global_previous || "
"history_global_next || "
"grab_key || grab_raw_key || grab_raw_key_command || grab_key_command || "
diff --git a/src/core/wee-utf8.c b/src/core/wee-utf8.c
index b29870f3f..e8c30792c 100644
--- a/src/core/wee-utf8.c
+++ b/src/core/wee-utf8.c
@@ -271,6 +271,48 @@ utf8_next_char (const char *string)
}
/*
+ * Gets pointer to the beginning of the UTF-8 line in a string.
+ *
+ * Returns pointer to the beginning of the UTF-8 line, NULL if string was NULL.
+ */
+
+const char *
+utf8_beginning_of_line (const char *string_start, const char *string)
+{
+ if (string && string[0] == '\n')
+ string = (char *)utf8_prev_char (string_start, string);
+
+ while (string && string[0] != '\n')
+ {
+ string = (char *)utf8_prev_char (string_start, string);
+ }
+
+ if (string)
+ return (char *)utf8_next_char (string);
+
+ return string_start;
+}
+
+/*
+ * Gets pointer to the end of the UTF-8 line in a string.
+ *
+ * Returns pointer to the end of the UTF-8 line, NULL if string was NULL.
+ */
+
+const char *
+utf8_end_of_line (const char *string)
+{
+ if (!string)
+ return NULL;
+
+ while (string[0] && string[0] != '\n')
+ {
+ string = (char *)utf8_next_char (string);
+ }
+ return string;
+}
+
+/*
* Gets UTF-8 char as an integer.
*
* Returns the UTF-8 char as integer number.
diff --git a/src/core/wee-utf8.h b/src/core/wee-utf8.h
index b2dab3334..88e8badb8 100644
--- a/src/core/wee-utf8.h
+++ b/src/core/wee-utf8.h
@@ -35,6 +35,9 @@ extern void utf8_normalize (char *string, char replacement);
extern const char *utf8_prev_char (const char *string_start,
const char *string);
extern const char *utf8_next_char (const char *string);
+extern const char *utf8_beginning_of_line (const char *string_start,
+ const char *string);
+extern const char *utf8_end_of_line (const char *string);
extern int utf8_char_int (const char *string);
extern int utf8_int_string (unsigned int unicode_value, char *string);
extern int utf8_char_size (const char *string);