1
0
mirror of https://github.com/weechat/weechat.git synced 2026-07-02 15:53:12 +02:00

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
This commit is contained in:
Trygve Aaberge
2023-04-24 23:55:07 +02:00
parent e00ec6710d
commit a401fbf217
4 changed files with 37 additions and 10 deletions
+4
View File
@@ -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);
+1
View File
@@ -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 */
+31 -10
View File
@@ -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);
}
}
}
}
}
+1
View File
@@ -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);