1
0
mirror of https://github.com/weechat/weechat.git synced 2026-06-29 22:36:38 +02:00

core: fix highlight on action messages: skip the nick at beginning to prevent highlight on it (bug #40516)

This commit is contained in:
Sebastien Helleu
2013-11-08 18:22:36 +01:00
parent 5ce1a3e867
commit e2605cf77b
2 changed files with 38 additions and 7 deletions
+2
View File
@@ -11,6 +11,8 @@ http://weechat.org/files/releasenotes/ReleaseNotes-devel.html[release notes]
== Version 0.4.3 (under dev)
* core: fix highlight on action messages: skip the nick at beginning to prevent
highlight on it (bug #40516)
* core: add default keys `meta2-1;3H` / `meta2-1;3F` (alt+home/end) and
`meta2-23;3~` / `meta2-24;3~` (alt+F11/F12) for xterm
* core: add support of italic text (requires ncurses >= 5.9 patch 20130831)
+36 -7
View File
@@ -648,8 +648,9 @@ gui_line_get_nick_tag (struct t_gui_line *line)
int
gui_line_has_highlight (struct t_gui_line *line)
{
int rc, i, j, no_highlight;
char *msg_no_color, *highlight_words;
int rc, i, j, no_highlight, action, length;
char *msg_no_color, *ptr_msg_no_color, *highlight_words;
const char *ptr_nick;
/*
* highlights are disabled on this buffer? (special value "-" means that
@@ -661,9 +662,13 @@ gui_line_has_highlight (struct t_gui_line *line)
/*
* check if highlight is forced by a tag (with option highlight_tags) or
* disabled for line
* disabled for line; also check if the line is an action message (for
* example tag "irc_action") and get pointer on the nick (tag "nick_xxx"),
* these info will be used later (see below)
*/
no_highlight = 0;
action = 0;
ptr_nick = NULL;
for (i = 0; i < line->data->tags_count; i++)
{
if (config_highlight_tags)
@@ -677,6 +682,17 @@ gui_line_has_highlight (struct t_gui_line *line)
}
if (strcmp (line->data->tags_array[i], GUI_CHAT_TAG_NO_HIGHLIGHT) == 0)
no_highlight = 1;
else if (strncmp (line->data->tags_array[i], "nick_", 5) == 0)
ptr_nick = line->data->tags_array[i] + 5;
else
{
length = strlen (line->data->tags_array[i]);
if ((length >= 7)
&& (strcmp (line->data->tags_array[i] + length - 7, "_action") == 0))
{
action = 1;
}
}
}
if (no_highlight)
return 0;
@@ -697,6 +713,19 @@ gui_line_has_highlight (struct t_gui_line *line)
msg_no_color = gui_color_decode (line->data->message, NULL);
if (!msg_no_color)
return 0;
ptr_msg_no_color = msg_no_color;
/*
* if the line is an action message and that we know the nick, we skip
* the nick if it is at beginning of message (to not highlight an action
* from another user if his nick is in our highlight settings)
*/
if (action && ptr_nick)
{
length = strlen (ptr_nick);
if (strncmp (ptr_msg_no_color, ptr_nick, length) == 0)
ptr_msg_no_color += length;
}
/*
* there is highlight on line if one of buffer highlight words matches line
@@ -704,7 +733,7 @@ gui_line_has_highlight (struct t_gui_line *line)
*/
highlight_words = gui_buffer_string_replace_local_var (line->data->buffer,
line->data->buffer->highlight_words);
rc = string_has_highlight (msg_no_color,
rc = string_has_highlight (ptr_msg_no_color,
(highlight_words) ?
highlight_words : line->data->buffer->highlight_words);
if (highlight_words)
@@ -714,7 +743,7 @@ gui_line_has_highlight (struct t_gui_line *line)
{
highlight_words = gui_buffer_string_replace_local_var (line->data->buffer,
CONFIG_STRING(config_look_highlight));
rc = string_has_highlight (msg_no_color,
rc = string_has_highlight (ptr_msg_no_color,
(highlight_words) ?
highlight_words : CONFIG_STRING(config_look_highlight));
if (highlight_words)
@@ -723,13 +752,13 @@ gui_line_has_highlight (struct t_gui_line *line)
if (!rc && config_highlight_regex)
{
rc = string_has_highlight_regex_compiled (msg_no_color,
rc = string_has_highlight_regex_compiled (ptr_msg_no_color,
config_highlight_regex);
}
if (!rc && line->data->buffer->highlight_regex_compiled)
{
rc = string_has_highlight_regex_compiled (msg_no_color,
rc = string_has_highlight_regex_compiled (ptr_msg_no_color,
line->data->buffer->highlight_regex_compiled);
}