SF.net SVN: geany:[5895] trunk
colombanw at users.sourceforge.net
colombanw at xxxxx
Sun Aug 21 17:15:20 UTC 2011
Revision: 5895
http://geany.svn.sourceforge.net/geany/?rev=5895&view=rev
Author: colombanw
Date: 2011-08-21 17:15:19 +0000 (Sun, 21 Aug 2011)
Log Message:
-----------
Fix search for the current word if it isn't composed of only GEANY_WORDCHARS
Use Scintilla's definition of a "word" when fetching the current word
to perform a search. This is needed when we perform a whole-word
search for Scintilla to find the matches.
Closes #3386129.
Modified Paths:
--------------
trunk/ChangeLog
trunk/src/callbacks.c
trunk/src/editor.c
trunk/src/editor.h
trunk/src/keybindings.c
Modified: trunk/ChangeLog
===================================================================
--- trunk/ChangeLog 2011-08-19 22:15:59 UTC (rev 5894)
+++ trunk/ChangeLog 2011-08-21 17:15:19 UTC (rev 5895)
@@ -1,3 +1,10 @@
+2011-08-21 Colomban Wendling <colomban(at)geany(dot)org>
+
+ * src/callbacks.c, src/editor.c, src/editor.h, src/keybindings.c:
+ Fix search for the current word if it isn't composed of only
+ GEANY_WORDCHARS (closes #3386129).
+
+
2011-08-20 Colomban Wendling <colomban(at)geany(dot)org>
* tagmanager/haskell.c:
Modified: trunk/src/callbacks.c
===================================================================
--- trunk/src/callbacks.c 2011-08-19 22:15:59 UTC (rev 5894)
+++ trunk/src/callbacks.c 2011-08-21 17:15:19 UTC (rev 5895)
@@ -917,8 +917,8 @@
}
else
{
- editor_find_current_word(doc->editor, -1,
- editor_info.current_word, GEANY_MAX_WORD_LENGTH, NULL);
+ editor_find_current_word_sciwc(doc->editor, -1,
+ editor_info.current_word, GEANY_MAX_WORD_LENGTH);
search_text = g_strdup(editor_info.current_word);
flags = SCFIND_MATCHCASE | SCFIND_WHOLEWORD;
}
Modified: trunk/src/editor.c
===================================================================
--- trunk/src/editor.c 2011-08-19 22:15:59 UTC (rev 5894)
+++ trunk/src/editor.c 2011-08-21 17:15:19 UTC (rev 5895)
@@ -1664,6 +1664,32 @@
}
+/* Same as editor_find_current_word() but uses editor's word boundaries to decide what the word
+ * is. This should be used e.g. to get the word to search for */
+void editor_find_current_word_sciwc(GeanyEditor *editor, gint pos, gchar *word, gsize wordlen)
+{
+ gint start;
+ gint end;
+
+ g_return_if_fail(editor != NULL);
+
+ if (pos == -1)
+ pos = sci_get_current_position(editor->sci);
+
+ start = SSM(editor->sci, SCI_WORDSTARTPOSITION, pos, TRUE);
+ end = SSM(editor->sci, SCI_WORDENDPOSITION, pos, TRUE);
+
+ if (start == end) /* caret in whitespaces sequence */
+ *word = 0;
+ else
+ {
+ if ((guint)(end - start) >= wordlen)
+ end = start + (wordlen - 1);
+ sci_get_text_range(editor->sci, start, end, word);
+ }
+}
+
+
/**
* Finds the word at the position specified by @a pos. If any word is found, it is returned.
* Otherwise NULL is returned.
@@ -3959,7 +3985,10 @@
/* wordchars: NULL or a string containing characters to match a word.
- * Returns: the current selection or the current word. */
+ * Returns: the current selection or the current word.
+ *
+ * Passing NULL as wordchars is NOT the same as passing GEANY_WORDCHARS: NULL means
+ * using Scintillas's word boundaries. */
gchar *editor_get_default_selection(GeanyEditor *editor, gboolean use_current_word,
const gchar *wordchars)
{
@@ -3968,17 +3997,16 @@
g_return_val_if_fail(editor != NULL, NULL);
if (sci_get_lines_selected(editor->sci) == 1)
- {
- gint len = sci_get_selected_text_length(editor->sci);
-
- s = g_malloc(len + 1);
- sci_get_selected_text(editor->sci, s);
- }
+ s = sci_get_selection_contents(editor->sci);
else if (sci_get_lines_selected(editor->sci) == 0 && use_current_word)
{ /* use the word at current cursor position */
gchar word[GEANY_MAX_WORD_LENGTH];
- editor_find_current_word(editor, -1, word, sizeof(word), wordchars);
+ if (wordchars != NULL)
+ editor_find_current_word(editor, -1, word, sizeof(word), wordchars);
+ else
+ editor_find_current_word_sciwc(editor, -1, word, sizeof(word));
+
if (word[0] != '\0')
s = g_strdup(word);
}
Modified: trunk/src/editor.h
===================================================================
--- trunk/src/editor.h 2011-08-19 22:15:59 UTC (rev 5894)
+++ trunk/src/editor.h 2011-08-21 17:15:19 UTC (rev 5895)
@@ -240,6 +240,8 @@
void editor_find_current_word(GeanyEditor *editor, gint pos, gchar *word, size_t wordlen,
const gchar *wc);
+void editor_find_current_word_sciwc(GeanyEditor *editor, gint pos, gchar *word, gsize wordlen);
+
gchar *editor_get_word_at_pos(GeanyEditor *editor, gint pos, const gchar *wordchars);
gchar *editor_get_default_selection(GeanyEditor *editor, gboolean use_current_word, const gchar *wordchars);
Modified: trunk/src/keybindings.c
===================================================================
--- trunk/src/keybindings.c 2011-08-19 22:15:59 UTC (rev 5894)
+++ trunk/src/keybindings.c 2011-08-21 17:15:19 UTC (rev 5895)
@@ -86,9 +86,9 @@
static gboolean on_key_press_event(GtkWidget *widget, GdkEventKey *event, gpointer user_data);
static gboolean on_key_release_event(GtkWidget *widget, GdkEventKey *event, gpointer user_data);
-static gboolean check_current_word(GeanyDocument *doc);
-static gboolean read_current_word(GeanyDocument *doc);
-static gchar *get_current_word_or_sel(GeanyDocument *doc);
+static gboolean check_current_word(GeanyDocument *doc, gboolean sci_word);
+static gboolean read_current_word(GeanyDocument *doc, gboolean sci_word);
+static gchar *get_current_word_or_sel(GeanyDocument *doc, gboolean sci_word);
static gboolean cb_func_file_action(guint key_id);
static gboolean cb_func_project_action(guint key_id);
@@ -1415,16 +1415,12 @@
case GEANY_KEYS_SEARCH_PREVIOUSMESSAGE:
on_previous_message1_activate(NULL, NULL); break;
case GEANY_KEYS_SEARCH_FINDUSAGE:
- read_current_word(doc);
- on_find_usage1_activate(NULL, NULL);
- break;
+ on_find_usage1_activate(NULL, NULL); break;
case GEANY_KEYS_SEARCH_FINDDOCUMENTUSAGE:
- read_current_word(doc);
- on_find_document_usage1_activate(NULL, NULL);
- break;
+ on_find_document_usage1_activate(NULL, NULL); break;
case GEANY_KEYS_SEARCH_MARKALL:
{
- gchar *text = get_current_word_or_sel(doc);
+ gchar *text = get_current_word_or_sel(doc, TRUE);
if (sci_has_selection(sci))
search_mark_all(doc, text, SCFIND_MATCHCASE);
@@ -1546,25 +1542,29 @@
}
-static gboolean read_current_word(GeanyDocument *doc)
+static gboolean read_current_word(GeanyDocument *doc, gboolean sci_word)
{
- gint pos;
-
if (doc == NULL)
return FALSE;
- pos = sci_get_current_position(doc->editor->sci);
+ if (sci_word)
+ {
+ editor_find_current_word_sciwc(doc->editor, -1,
+ editor_info.current_word, GEANY_MAX_WORD_LENGTH);
+ }
+ else
+ {
+ editor_find_current_word(doc->editor, -1,
+ editor_info.current_word, GEANY_MAX_WORD_LENGTH, NULL);
+ }
- editor_find_current_word(doc->editor, pos,
- editor_info.current_word, GEANY_MAX_WORD_LENGTH, NULL);
-
return (*editor_info.current_word != 0);
}
-static gboolean check_current_word(GeanyDocument *doc)
+static gboolean check_current_word(GeanyDocument *doc, gboolean sci_word)
{
- if (!read_current_word(doc))
+ if (! read_current_word(doc, sci_word))
{
utils_beep();
return FALSE;
@@ -1573,14 +1573,14 @@
}
-static gchar *get_current_word_or_sel(GeanyDocument *doc)
+static gchar *get_current_word_or_sel(GeanyDocument *doc, gboolean sci_word)
{
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;
+ return read_current_word(doc, sci_word) ? g_strdup(editor_info.current_word) : NULL;
}
@@ -1934,7 +1934,7 @@
static void goto_tag(GeanyDocument *doc, gboolean definition)
{
- gchar *text = get_current_word_or_sel(doc);
+ gchar *text = get_current_word_or_sel(doc, FALSE);
if (text)
symbols_goto_tag(text, definition);
@@ -2148,7 +2148,7 @@
editor_show_macro_list(doc->editor);
break;
case GEANY_KEYS_EDITOR_CONTEXTACTION:
- if (check_current_word(doc))
+ if (check_current_word(doc, FALSE))
on_context_action1_activate(GTK_MENU_ITEM(ui_lookup_widget(main_widgets.editor_menu,
"context_action1")), NULL);
break;
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