summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog.asciidoc1
-rw-r--r--src/gui/curses/gui-curses-chat.c28
-rw-r--r--src/gui/gui-input.c25
-rw-r--r--src/gui/gui-window.c41
4 files changed, 64 insertions, 31 deletions
diff --git a/ChangeLog.asciidoc b/ChangeLog.asciidoc
index b7ab1159c..eeb76e3a1 100644
--- a/ChangeLog.asciidoc
+++ b/ChangeLog.asciidoc
@@ -15,6 +15,7 @@ http://weechat.org/files/releasenotes/ReleaseNotes-devel.html[release notes]
== Version 0.4.4 (under dev)
+* core: add text search in buffers with free content (task #13051)
* core: add buffer property "clear"
* core: fix add of filter on OS X when regex for message is empty (filter regex
ending with "\t")
diff --git a/src/gui/curses/gui-curses-chat.c b/src/gui/curses/gui-curses-chat.c
index 2a4dd9e75..2d687b340 100644
--- a/src/gui/curses/gui-curses-chat.c
+++ b/src/gui/curses/gui-curses-chat.c
@@ -429,7 +429,8 @@ gui_chat_display_word_raw (struct t_gui_window *window, struct t_gui_line *line,
if (gui_window_current_emphasis)
{
gui_window_emphasize (GUI_WINDOW_OBJECTS(window)->win_chat,
- x, window->win_chat_cursor_y,
+ x - window->scroll->start_col,
+ window->win_chat_cursor_y,
size_on_screen);
}
}
@@ -1550,6 +1551,8 @@ void
gui_chat_display_line_y (struct t_gui_window *window, struct t_gui_line *line,
int y)
{
+ char *ptr_data, *message_with_search;
+
/* reset color & style for a new line */
gui_chat_reset_style (window, line, 0, 1,
GUI_COLOR_CHAT_INACTIVE_WINDOW,
@@ -1558,16 +1561,37 @@ gui_chat_display_line_y (struct t_gui_window *window, struct t_gui_line *line,
window->win_chat_cursor_x = 0;
window->win_chat_cursor_y = y;
+ gui_window_current_emphasis = 0;
gui_chat_clrtoeol (window);
- if (gui_chat_display_word_raw (window, line, line->data->message,
+ /* emphasize text (if searching text) */
+ ptr_data = line->data->message;
+ message_with_search = NULL;
+ if ((window->buffer->text_search != GUI_TEXT_SEARCH_DISABLED)
+ && (window->buffer->text_search_where & GUI_TEXT_SEARCH_IN_MESSAGE)
+ && (!window->buffer->text_search_regex
+ || window->buffer->text_search_regex_compiled))
+ {
+ message_with_search = gui_color_emphasize (ptr_data,
+ window->buffer->input_buffer,
+ window->buffer->text_search_exact,
+ window->buffer->text_search_regex_compiled);
+ if (message_with_search)
+ ptr_data = message_with_search;
+ }
+
+ /* display the line */
+ if (gui_chat_display_word_raw (window, line, ptr_data,
window->win_chat_width, 0,
CONFIG_BOOLEAN(config_look_color_inactive_message),
0) < window->win_chat_width)
{
gui_window_clrtoeol (GUI_WINDOW_OBJECTS(window)->win_chat);
}
+
+ if (message_with_search)
+ free (message_with_search);
}
/*
diff --git a/src/gui/gui-input.c b/src/gui/gui-input.c
index d34886be5..237548efc 100644
--- a/src/gui/gui-input.c
+++ b/src/gui/gui-input.c
@@ -580,8 +580,7 @@ gui_input_search_text (struct t_gui_buffer *buffer)
struct t_gui_window *window;
window = gui_window_search_with_buffer (buffer);
- if (window && (window->buffer->type == GUI_BUFFER_TYPE_FORMATTED)
- && (window->buffer->text_search == GUI_TEXT_SEARCH_DISABLED))
+ if (window && (window->buffer->text_search == GUI_TEXT_SEARCH_DISABLED))
{
gui_window_search_start (window);
gui_input_search_signal (buffer);
@@ -634,8 +633,7 @@ gui_input_search_switch_case (struct t_gui_buffer *buffer)
struct t_gui_window *window;
window = gui_window_search_with_buffer (buffer);
- if (window && (window->buffer->type == GUI_BUFFER_TYPE_FORMATTED)
- && (window->buffer->text_search != GUI_TEXT_SEARCH_DISABLED))
+ if (window && (window->buffer->text_search != GUI_TEXT_SEARCH_DISABLED))
{
window->buffer->text_search_exact ^= 1;
gui_window_search_restart (window);
@@ -654,8 +652,7 @@ gui_input_search_switch_regex (struct t_gui_buffer *buffer)
struct t_gui_window *window;
window = gui_window_search_with_buffer (buffer);
- if (window && (window->buffer->type == GUI_BUFFER_TYPE_FORMATTED)
- && (window->buffer->text_search != GUI_TEXT_SEARCH_DISABLED))
+ if (window && (window->buffer->text_search != GUI_TEXT_SEARCH_DISABLED))
{
window->buffer->text_search_regex ^= 1;
gui_window_search_restart (window);
@@ -673,9 +670,12 @@ gui_input_search_switch_where (struct t_gui_buffer *buffer)
struct t_gui_window *window;
window = gui_window_search_with_buffer (buffer);
- if (window && (window->buffer->type == GUI_BUFFER_TYPE_FORMATTED)
- && (window->buffer->text_search != GUI_TEXT_SEARCH_DISABLED))
+ if (window && (window->buffer->text_search != GUI_TEXT_SEARCH_DISABLED))
{
+ /* it's not possible to change that in a buffer with free content */
+ if (window->buffer->type == GUI_BUFFER_TYPE_FREE)
+ return;
+
if (window->buffer->text_search_where == GUI_TEXT_SEARCH_IN_MESSAGE)
window->buffer->text_search_where = GUI_TEXT_SEARCH_IN_PREFIX;
else if (window->buffer->text_search_where == GUI_TEXT_SEARCH_IN_PREFIX)
@@ -697,8 +697,7 @@ gui_input_search_previous (struct t_gui_buffer *buffer)
struct t_gui_window *window;
window = gui_window_search_with_buffer (buffer);
- if (window && (window->buffer->type == GUI_BUFFER_TYPE_FORMATTED)
- && (window->buffer->text_search != GUI_TEXT_SEARCH_DISABLED))
+ if (window && (window->buffer->text_search != GUI_TEXT_SEARCH_DISABLED))
{
window->buffer->text_search = GUI_TEXT_SEARCH_BACKWARD;
(void) gui_window_search_text (window);
@@ -715,8 +714,7 @@ gui_input_search_next (struct t_gui_buffer *buffer)
struct t_gui_window *window;
window = gui_window_search_with_buffer (buffer);
- if (window && (window->buffer->type == GUI_BUFFER_TYPE_FORMATTED)
- && (window->buffer->text_search != GUI_TEXT_SEARCH_DISABLED))
+ if (window && (window->buffer->text_search != GUI_TEXT_SEARCH_DISABLED))
{
window->buffer->text_search = GUI_TEXT_SEARCH_FORWARD;
(void) gui_window_search_text (window);
@@ -733,8 +731,7 @@ gui_input_search_stop (struct t_gui_buffer *buffer)
struct t_gui_window *window;
window = gui_window_search_with_buffer (buffer);
- if (window && (window->buffer->type == GUI_BUFFER_TYPE_FORMATTED)
- && (window->buffer->text_search != GUI_TEXT_SEARCH_DISABLED))
+ if (window && (window->buffer->text_search != GUI_TEXT_SEARCH_DISABLED))
{
gui_window_search_stop (window);
gui_input_search_signal (buffer);
diff --git a/src/gui/gui-window.c b/src/gui/gui-window.c
index edc4defd9..7345e669f 100644
--- a/src/gui/gui-window.c
+++ b/src/gui/gui-window.c
@@ -1571,29 +1571,38 @@ gui_window_search_text (struct t_gui_window *window)
void
gui_window_search_start (struct t_gui_window *window)
{
- window->buffer->text_search = GUI_TEXT_SEARCH_BACKWARD;
+ window->buffer->text_search =
+ (window->buffer->type == GUI_BUFFER_TYPE_FORMATTED) ?
+ GUI_TEXT_SEARCH_BACKWARD : GUI_TEXT_SEARCH_FORWARD;
+
if ((window->buffer->text_search_where == 0)
|| CONFIG_BOOLEAN(config_look_buffer_search_force_default))
{
/* set default search values */
window->buffer->text_search_exact = CONFIG_BOOLEAN(config_look_buffer_search_case_sensitive);
window->buffer->text_search_regex = CONFIG_BOOLEAN(config_look_buffer_search_regex);
- switch (CONFIG_INTEGER(config_look_buffer_search_where))
+ if (window->buffer->type == GUI_BUFFER_TYPE_FORMATTED)
{
- case CONFIG_LOOK_BUFFER_SEARCH_PREFIX:
- window->buffer->text_search_where = GUI_TEXT_SEARCH_IN_PREFIX;
- break;
- case CONFIG_LOOK_BUFFER_SEARCH_MESSAGE:
- window->buffer->text_search_where = GUI_TEXT_SEARCH_IN_MESSAGE;
- break;
- case CONFIG_LOOK_BUFFER_SEARCH_PREFIX_MESSAGE:
- window->buffer->text_search_where = GUI_TEXT_SEARCH_IN_PREFIX | GUI_TEXT_SEARCH_IN_MESSAGE;
- break;
- default:
- window->buffer->text_search_where = GUI_TEXT_SEARCH_IN_MESSAGE;
- break;
+ switch (CONFIG_INTEGER(config_look_buffer_search_where))
+ {
+ case CONFIG_LOOK_BUFFER_SEARCH_PREFIX:
+ window->buffer->text_search_where = GUI_TEXT_SEARCH_IN_PREFIX;
+ break;
+ case CONFIG_LOOK_BUFFER_SEARCH_MESSAGE:
+ window->buffer->text_search_where = GUI_TEXT_SEARCH_IN_MESSAGE;
+ break;
+ case CONFIG_LOOK_BUFFER_SEARCH_PREFIX_MESSAGE:
+ window->buffer->text_search_where = GUI_TEXT_SEARCH_IN_PREFIX | GUI_TEXT_SEARCH_IN_MESSAGE;
+ break;
+ default:
+ window->buffer->text_search_where = GUI_TEXT_SEARCH_IN_MESSAGE;
+ break;
+ }
}
+ else
+ window->buffer->text_search_where = GUI_TEXT_SEARCH_IN_MESSAGE;
}
+
window->buffer->text_search_found = 0;
gui_input_search_compile_regex (window->buffer);
if (window->buffer->text_search_input)
@@ -1616,7 +1625,9 @@ gui_window_search_restart (struct t_gui_window *window)
{
window->scroll->start_line = NULL;
window->scroll->start_line_pos = 0;
- window->buffer->text_search = GUI_TEXT_SEARCH_BACKWARD;
+ window->buffer->text_search =
+ (window->buffer->type == GUI_BUFFER_TYPE_FORMATTED) ?
+ GUI_TEXT_SEARCH_BACKWARD : GUI_TEXT_SEARCH_FORWARD;
window->buffer->text_search_found = 0;
gui_input_search_compile_regex (window->buffer);
if (gui_window_search_text (window))