Don't scroll the editor view if it is unnecessary when using Find

Next/Previous, Find Selected and when searching from the search bar.


git-svn-id: https://geany.svn.sourceforge.net/svnroot/geany/trunk@2274 ea778897-0a13-0410-b9d1-a72fbfd435f5
This commit is contained in:
Nick Treleaven 2008-02-22 13:30:16 +00:00
parent 9163bf50d6
commit 3714cf498f
6 changed files with 70 additions and 20 deletions

View File

@ -3,6 +3,10 @@
* tagmanager/options.c:
Use extern for c_tags_ignore declaration to avoid allocating a
second copy of it (patch by Daniel Richard G., thanks).
* src/callbacks.c, src/search.c, src/document.c, src/editor.c,
src/editor.h:
Don't scroll the editor view if it is unnecessary when using Find
Next/Previous, Find Selected and when searching from the search bar.
2008-02-22 Enrico Tröger <enrico(dot)troeger(at)uvena(dot)de>

View File

@ -1125,39 +1125,42 @@ on_find1_activate (GtkMenuItem *menuitem,
}
void
on_find_next1_activate (GtkMenuItem *menuitem,
gpointer user_data)
static void find_again(gboolean change_direction)
{
gint idx = document_get_cur_idx();
g_return_if_fail(DOC_IDX_VALID(idx));
if (search_data.text)
{
gboolean forward = ! search_data.backwards;
gint result = document_find_text(idx, search_data.text, search_data.flags,
search_data.backwards, TRUE, NULL);
change_direction ? forward : !forward, FALSE, NULL);
if (result > -1)
editor_display_current_line(idx, 0.3F);
set_search_bar_background((result > -1) ? TRUE : FALSE);
}
}
void
on_find_next1_activate (GtkMenuItem *menuitem,
gpointer user_data)
{
find_again(FALSE);
}
void
on_find_previous1_activate (GtkMenuItem *menuitem,
gpointer user_data)
{
gint idx = document_get_cur_idx();
if (search_data.text == NULL) return;
if (search_data.flags & SCFIND_REGEXP)
utils_beep(); // Can't reverse search order for a regex (find next ignores search backwards)
else
{
gint result = document_find_text(idx, search_data.text, search_data.flags,
!search_data.backwards, TRUE, NULL);
set_search_bar_background((result > -1) ? TRUE : FALSE);
}
find_again(TRUE);
}

View File

@ -1475,16 +1475,20 @@ gboolean document_search_bar_find(gint idx, const gchar *text, gint flags, gbool
if (search_pos != -1)
{
gint line = sci_get_line_from_position(doc_list[idx].sci, ttf.chrgText.cpMin);
// unfold maybe folded results
sci_ensure_line_is_visible(doc_list[idx].sci,
sci_get_line_from_position(doc_list[idx].sci, ttf.chrgText.cpMin));
sci_ensure_line_is_visible(doc_list[idx].sci, line);
sci_set_selection_start(doc_list[idx].sci, ttf.chrgText.cpMin);
sci_set_selection_end(doc_list[idx].sci, ttf.chrgText.cpMax);
// we need to force scrolling in case the cursor is outside of the current visible area
// doc_list[].scroll_percent doesn't work because sci isn't always updated while searching
editor_scroll_to_line(doc_list[idx].sci, -1, 0.3F);
if (! editor_line_in_view(doc_list[idx].sci, line))
{
// we need to force scrolling in case the cursor is outside of the current visible area
// doc_list[].scroll_percent doesn't work because sci isn't always updated while searching
editor_scroll_to_line(doc_list[idx].sci, -1, 0.3F);
}
return TRUE;
}
else

View File

@ -2643,3 +2643,36 @@ gchar *editor_get_default_selection(gint idx, const gchar *wordchars)
}
return s;
}
/* Note: Usually the line should be made visible (not folded) before calling this.
* Returns: TRUE if line is/will be displayed to the user, or FALSE if it is
* outside the view. */
gboolean editor_line_in_view(ScintillaObject *sci, gint line)
{
gint vis1, los;
line = SSM(sci, SCI_VISIBLEFROMDOCLINE, line, 0); // convert to visible line number
vis1 = SSM(sci, SCI_GETFIRSTVISIBLELINE, 0, 0);
los = SSM(sci, SCI_LINESONSCREEN, 0, 0);
return (line >= vis1 && line < vis1 + los);
}
/* If the current line is outside the current view window, scroll the line
* so it appears at percent_of_view. */
void editor_display_current_line(gint idx, gfloat percent_of_view)
{
ScintillaObject *sci = doc_list[idx].sci;
gint line = sci_get_current_line(sci);
// unfold maybe folded results
sci_ensure_line_is_visible(doc_list[idx].sci, line);
// scroll the line if it's off screen
if (! editor_line_in_view(sci, line))
doc_list[idx].scroll_percent = percent_of_view;
}

View File

@ -131,8 +131,12 @@ void editor_auto_line_indentation(gint idx, gint pos);
void editor_indentation_by_one_space(gint idx, gint pos, gboolean decrease);
gboolean editor_line_in_view(ScintillaObject *sci, gint line);
void editor_scroll_to_line(ScintillaObject *sci, gint line, gfloat percent_of_view);
void editor_display_current_line(gint idx, gfloat percent_of_view);
void editor_finalize(void);

View File

@ -251,7 +251,9 @@ void search_find_selection(gint idx, gboolean search_backwards)
if (s)
{
setup_find_next(s); // allow find next/prev
document_find_text(idx, s, 0, search_backwards, TRUE, NULL);
if (document_find_text(idx, s, 0, search_backwards, FALSE, NULL) > -1)
editor_display_current_line(idx, 0.3F);
g_free(s);
}
}