Revision: 2274 http://geany.svn.sourceforge.net/geany/?rev=2274&view=rev Author: ntrel Date: 2008-02-22 05:30:16 -0800 (Fri, 22 Feb 2008)
Log Message: ----------- Don't scroll the editor view if it is unnecessary when using Find Next/Previous, Find Selected and when searching from the search bar.
Modified Paths: -------------- trunk/ChangeLog trunk/src/callbacks.c trunk/src/document.c trunk/src/editor.c trunk/src/editor.h trunk/src/search.c
Modified: trunk/ChangeLog =================================================================== --- trunk/ChangeLog 2008-02-22 13:16:07 UTC (rev 2273) +++ trunk/ChangeLog 2008-02-22 13:30:16 UTC (rev 2274) @@ -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>
Modified: trunk/src/callbacks.c =================================================================== --- trunk/src/callbacks.c 2008-02-22 13:16:07 UTC (rev 2273) +++ trunk/src/callbacks.c 2008-02-22 13:30:16 UTC (rev 2274) @@ -1125,39 +1125,42 @@ }
-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_previous1_activate (GtkMenuItem *menuitem, +on_find_next1_activate (GtkMenuItem *menuitem, gpointer user_data) { - gint idx = document_get_cur_idx(); + find_again(FALSE); +}
- if (search_data.text == NULL) return;
+void +on_find_previous1_activate (GtkMenuItem *menuitem, + gpointer user_data) +{ 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); }
Modified: trunk/src/document.c =================================================================== --- trunk/src/document.c 2008-02-22 13:16:07 UTC (rev 2273) +++ trunk/src/document.c 2008-02-22 13:30:16 UTC (rev 2274) @@ -1475,16 +1475,20 @@
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
Modified: trunk/src/editor.c =================================================================== --- trunk/src/editor.c 2008-02-22 13:16:07 UTC (rev 2273) +++ trunk/src/editor.c 2008-02-22 13:30:16 UTC (rev 2274) @@ -2643,3 +2643,36 @@ } 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; +} + +
Modified: trunk/src/editor.h =================================================================== --- trunk/src/editor.h 2008-02-22 13:16:07 UTC (rev 2273) +++ trunk/src/editor.h 2008-02-22 13:30:16 UTC (rev 2274) @@ -131,8 +131,12 @@
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);
Modified: trunk/src/search.c =================================================================== --- trunk/src/search.c 2008-02-22 13:16:07 UTC (rev 2273) +++ trunk/src/search.c 2008-02-22 13:30:16 UTC (rev 2274) @@ -251,7 +251,9 @@ 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); } }
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.