diff options
author | Trygve Aaberge <trygveaa@gmail.com> | 2023-04-24 23:55:07 +0200 |
---|---|---|
committer | Trygve Aaberge <trygveaa@gmail.com> | 2023-04-25 00:11:26 +0200 |
commit | a401fbf217a9e299310266dbdd1743241d5ec161 (patch) | |
tree | 5992a9bd3b4959b11b650a0a959895d52fac8de3 /src/gui | |
parent | e00ec6710d2669032f115c4be0619a65033881b9 (diff) | |
download | weechat-a401fbf217a9e299310266dbdd1743241d5ec161.zip |
core: add _chat_focused_line variable to get the focused line
This contains the single line that you focused on, like _chat_word
contains the word that you focused on. This will be equal to
_chat_line_message if the chat line only contains a single line, but if
the chat line has multiple lines, _chat_line_message will contain all of
them, but _chat_focused_line will only contain the single line that was
focused.
Fixes part of #1913
Diffstat (limited to 'src/gui')
-rw-r--r-- | src/gui/gui-focus.c | 4 | ||||
-rw-r--r-- | src/gui/gui-focus.h | 1 | ||||
-rw-r--r-- | src/gui/gui-window.c | 41 | ||||
-rw-r--r-- | src/gui/gui-window.h | 1 |
4 files changed, 37 insertions, 10 deletions
diff --git a/src/gui/gui-focus.c b/src/gui/gui-focus.c index b3b8f96ea..85362a10c 100644 --- a/src/gui/gui-focus.c +++ b/src/gui/gui-focus.c @@ -71,6 +71,7 @@ gui_focus_get_info (int x, int y) &focus_info->chat_line, &focus_info->chat_line_x, &focus_info->chat_word, + &focus_info->chat_focused_line, &focus_info->chat_bol, &focus_info->chat_eol); @@ -99,6 +100,8 @@ gui_focus_free_info (struct t_gui_focus_info *focus_info) { if (focus_info->chat_word) free (focus_info->chat_word); + if (focus_info->chat_focused_line) + free (focus_info->chat_focused_line); if (focus_info->chat_bol) free (focus_info->chat_bol); if (focus_info->chat_eol) @@ -238,6 +241,7 @@ gui_focus_to_hashtable (struct t_gui_focus_info *focus_info, const char *key) HASHTABLE_SET_STR("_chat_line_message", ""); } HASHTABLE_SET_STR_NOT_NULL("_chat_word", focus_info->chat_word); + HASHTABLE_SET_STR_NOT_NULL("_chat_focused_line", focus_info->chat_focused_line); HASHTABLE_SET_STR_NOT_NULL("_chat_bol", focus_info->chat_bol); HASHTABLE_SET_STR_NOT_NULL("_chat_eol", focus_info->chat_eol); diff --git a/src/gui/gui-focus.h b/src/gui/gui-focus.h index 3f7fd76d2..ad0793ad9 100644 --- a/src/gui/gui-focus.h +++ b/src/gui/gui-focus.h @@ -31,6 +31,7 @@ struct t_gui_focus_info struct t_gui_line *chat_line; /* line in chat area */ int chat_line_x; /* x in line */ char *chat_word; /* word at (x,y) */ + char *chat_focused_line; /* line at (x,y) */ char *chat_bol; /* beginning of line until (x,y) */ char *chat_eol; /* (x,y) until end of line */ struct t_gui_bar_window *bar_window; /* bar window found */ diff --git a/src/gui/gui-window.c b/src/gui/gui-window.c index 8bd621cca..f8040fe27 100644 --- a/src/gui/gui-window.c +++ b/src/gui/gui-window.c @@ -136,17 +136,20 @@ gui_window_get_context_at_xy (struct t_gui_window *window, struct t_gui_line **line, int *line_x, char **word, + char **focused_line, char **beginning, char **end) { int win_x, win_y, coords_x_message; char *data_next_line, *str_temp; - const char *ptr_data, *word_start, *word_end, *last_whitespace; + const char *ptr_data, *line_start, *line_end, *word_start, *word_end; + const char *last_newline, *last_whitespace; *chat = 0; *line = NULL; *line_x = -1; *word = NULL; + *focused_line = NULL; *beginning = NULL; *end = NULL; @@ -227,8 +230,9 @@ gui_window_get_context_at_xy (struct t_gui_window *window, free (str_temp); } *end = gui_color_decode (ptr_data, NULL); - if (ptr_data[0] != ' ' && ptr_data[0] != '\n') + if (ptr_data[0] != '\n') { + last_newline = NULL; last_whitespace = NULL; word_start = (*line)->data->message; while (word_start && (word_start < ptr_data)) @@ -238,26 +242,34 @@ gui_window_get_context_at_xy (struct t_gui_window *window, 0, 0, 0); if (word_start) { + if (word_start[0] == '\n') + last_newline = word_start; if (word_start[0] == ' ' || word_start[0] == '\n') last_whitespace = word_start; word_start = utf8_next_char (word_start); } } + line_start = (last_newline) ? last_newline + 1 : (*line)->data->message; word_start = (last_whitespace) ? last_whitespace + 1 : (*line)->data->message; - word_end = ptr_data; - while (word_end && word_end[0]) + line_end = ptr_data; + word_end = NULL; + while (line_end && line_end[0]) { - word_end = (char *)gui_chat_string_next_char (NULL, NULL, - (unsigned char *)word_end, + line_end = (char *)gui_chat_string_next_char (NULL, NULL, + (unsigned char *)line_end, 0, 0, 0); - if (word_end) + if (line_end) { - if (word_end[0] == ' ' || word_end[0] == '\n') + if (!word_end && line_end[0] == ' ') + word_end = line_end; + if (line_end[0] == '\n') break; - word_end = utf8_next_char (word_end); + line_end = utf8_next_char (line_end); } } - if (word_start && word_end) + if (!word_end && line_end) + word_end = line_end; + if (ptr_data[0] != ' ' && word_start && word_end) { str_temp = string_strndup (word_start, word_end - word_start); if (str_temp) @@ -266,6 +278,15 @@ gui_window_get_context_at_xy (struct t_gui_window *window, free (str_temp); } } + if (line_start && line_end) + { + str_temp = string_strndup (line_start, line_end - line_start); + if (str_temp) + { + *focused_line = gui_color_decode (str_temp, NULL); + free (str_temp); + } + } } } } diff --git a/src/gui/gui-window.h b/src/gui/gui-window.h index 10e589c0d..3ef0700cd 100644 --- a/src/gui/gui-window.h +++ b/src/gui/gui-window.h @@ -138,6 +138,7 @@ extern void gui_window_get_context_at_xy (struct t_gui_window *window, struct t_gui_line **line, int *line_x, char **word, + char **focused_line, char **beginning, char **end); extern void gui_window_ask_refresh (int refresh); |