SF.net SVN: geany:[4195] trunk

ntrel at users.sourceforge.net ntrel at xxxxx
Wed Sep 16 12:13:50 UTC 2009


Revision: 4195
          http://geany.svn.sourceforge.net/geany/?rev=4195&view=rev
Author:   ntrel
Date:     2009-09-16 12:13:50 +0000 (Wed, 16 Sep 2009)

Log Message:
-----------
Make Goto Tag commands use the current selection if present (useful
for selecting part of a tag or for ReST section names with spaces
in).

Modified Paths:
--------------
    trunk/ChangeLog
    trunk/src/callbacks.c
    trunk/src/keybindings.c
    trunk/src/search.c

Modified: trunk/ChangeLog
===================================================================
--- trunk/ChangeLog	2009-09-16 11:54:44 UTC (rev 4194)
+++ trunk/ChangeLog	2009-09-16 12:13:50 UTC (rev 4195)
@@ -1,3 +1,11 @@
+2009-09-16  Nick Treleaven  <nick(dot)treleaven(at)btinternet(dot)com>
+
+ * src/keybindings.c, src/callbacks.c, src/search.c:
+   Make Goto Tag commands use the current selection if present (useful
+   for selecting part of a tag or for ReST section names with spaces
+   in).
+
+
 2009-09-15  Frank Lanitz  <frank(at)frank(dot)uvena(dot)de>
 
  * src/main.c:

Modified: trunk/src/callbacks.c
===================================================================
--- trunk/src/callbacks.c	2009-09-16 11:54:44 UTC (rev 4194)
+++ trunk/src/callbacks.c	2009-09-16 12:13:50 UTC (rev 4195)
@@ -1121,8 +1121,15 @@
 
 	g_return_if_fail(doc != NULL);
 
-	sci_set_current_position(doc->editor->sci, editor_info.click_pos, FALSE);
-	symbols_goto_tag(editor_info.current_word, definition);
+	/* update cursor pos for navigating back afterwards */
+	if (!sci_has_selection(doc->editor->sci))
+		sci_set_current_position(doc->editor->sci, editor_info.click_pos, FALSE);
+
+	/* use the keybinding callback as it checks for selections as well as current word */
+	if (definition)
+		keybindings_send_command(GEANY_KEY_GROUP_GOTO, GEANY_KEYS_GOTO_TAGDEFINITION);
+	else
+		keybindings_send_command(GEANY_KEY_GROUP_GOTO, GEANY_KEYS_GOTO_TAGDECLARATION);
 }
 
 

Modified: trunk/src/keybindings.c
===================================================================
--- trunk/src/keybindings.c	2009-09-16 11:54:44 UTC (rev 4194)
+++ trunk/src/keybindings.c	2009-09-16 12:13:50 UTC (rev 4195)
@@ -80,6 +80,7 @@
 
 static gboolean check_current_word(GeanyDocument *doc);
 static gboolean read_current_word(GeanyDocument *doc);
+static gchar *get_current_word_or_sel(GeanyDocument *doc);
 
 static void cb_func_file_action(guint key_id);
 static void cb_func_project_action(guint key_id);
@@ -1340,22 +1341,23 @@
 			on_find_document_usage1_activate(NULL, NULL);
 			break;
 		case GEANY_KEYS_SEARCH_MARKALL:
+		{
+			gchar *text = get_current_word_or_sel(doc);
+
 			if (sci_has_selection(sci))
-			{
-				gchar *text = sci_get_selection_contents(sci);
-
 				search_mark_all(doc, text, SCFIND_MATCHCASE);
-				g_free(text);
-			}
 			else
 			{
-				read_current_word(doc);
-				search_mark_all(doc, editor_info.current_word, SCFIND_MATCHCASE | SCFIND_WHOLEWORD);
+				/* clears markers if text is null */
+				search_mark_all(doc, text, SCFIND_MATCHCASE | SCFIND_WHOLEWORD);
 			}
+			g_free(text);
 			break;
+		}
 	}
 }
 
+
 static void cb_func_menu_opencolorchooser(G_GNUC_UNUSED guint key_id)
 {
 	on_show_color_chooser1_activate(NULL, NULL);
@@ -1481,6 +1483,17 @@
 }
 
 
+static gchar *get_current_word_or_sel(GeanyDocument *doc)
+{
+	ScintillaObject *sci = doc->editor->sci;
+
+	if (sci_has_selection(sci))
+		return sci_get_selection_contents(sci);
+
+	return read_current_word(doc) ? g_strdup(editor_info.current_word) : NULL;
+}
+
+
 static void focus_sidebar(void)
 {
 	if (ui_prefs.sidebar_visible)
@@ -1784,6 +1797,19 @@
 }
 
 
+static void goto_tag(GeanyDocument *doc, gboolean definition)
+{
+	gchar *text = get_current_word_or_sel(doc);
+
+	if (text)
+		symbols_goto_tag(text, definition);
+	else
+		utils_beep();
+
+	g_free(text);
+}
+
+
 /* Common function for goto keybindings, useful even when sci doesn't have focus. */
 static void cb_func_goto_action(guint key_id)
 {
@@ -1837,12 +1863,10 @@
 			return;
 		}
 		case GEANY_KEYS_GOTO_TAGDEFINITION:
-			if (check_current_word(doc))
-				symbols_goto_tag(editor_info.current_word, TRUE);
+			goto_tag(doc, TRUE);
 			return;
 		case GEANY_KEYS_GOTO_TAGDECLARATION:
-			if (check_current_word(doc))
-				symbols_goto_tag(editor_info.current_word, FALSE);
+			goto_tag(doc, FALSE);
 			return;
 	}
 	/* only check editor-sensitive keybindings when editor has focus */

Modified: trunk/src/search.c
===================================================================
--- trunk/src/search.c	2009-09-16 11:54:44 UTC (rev 4194)
+++ trunk/src/search.c	2009-09-16 12:13:50 UTC (rev 4195)
@@ -959,7 +959,8 @@
 }
 
 
-/* @return Number of matches marked. */
+/* Clears markers if text is null/empty.
+ * @return Number of matches marked. */
 gint search_mark_all(GeanyDocument *doc, const gchar *search_text, gint flags)
 {
 	gint pos, count = 0;


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.



More information about the Commits mailing list