[gedit] Move to LINE:NUM in the popup goto line.
- From: Ignacio Casal Quinteiro <icq src gnome org>
- To: svn-commits-list gnome org
- Subject: [gedit] Move to LINE:NUM in the popup goto line.
- Date: Sat, 16 May 2009 18:07:52 -0400 (EDT)
commit 2100d5beccb9f6ddc2f0cdab2138d6491721bfbf
Author: Ignacio Casal Quinteiro <icq gnome org>
Date: Sun May 17 00:06:42 2009 +0200
Move to LINE:NUM in the popup goto line.
Been able to move to a line and a character number. E.g. 39:30 (Fixes bug #582060).
---
gedit/gedit-document.c | 32 +++++++++++++++++++++++++
gedit/gedit-document.h | 4 +++
gedit/gedit-view.c | 60 +++++++++++++++++++++++++++++++++++++++--------
3 files changed, 85 insertions(+), 11 deletions(-)
diff --git a/gedit/gedit-document.c b/gedit/gedit-document.c
index 3c48526..8a52bec 100644
--- a/gedit/gedit-document.c
+++ b/gedit/gedit-document.c
@@ -1427,6 +1427,38 @@ gedit_document_goto_line (GeditDocument *doc,
return ret;
}
+gboolean
+gedit_document_goto_line_offset (GeditDocument *doc,
+ gint line,
+ gint line_offset)
+{
+ gboolean ret = TRUE;
+ guint offset_count;
+ GtkTextIter iter;
+
+ g_return_val_if_fail (GEDIT_IS_DOCUMENT (doc), FALSE);
+ g_return_val_if_fail (line >= -1, FALSE);
+ g_return_val_if_fail (line_offset >= -1, FALSE);
+
+ gtk_text_buffer_get_iter_at_line (GTK_TEXT_BUFFER (doc),
+ &iter,
+ line);
+
+ offset_count = gtk_text_iter_get_chars_in_line (&iter);
+ if (line_offset > offset_count)
+ {
+ ret = FALSE;
+ }
+ else
+ {
+ gtk_text_iter_set_line_offset (&iter, line_offset);
+ }
+
+ gtk_text_buffer_place_cursor (GTK_TEXT_BUFFER (doc), &iter);
+
+ return ret;
+}
+
static gint
compute_num_of_lines (const gchar *text)
{
diff --git a/gedit/gedit-document.h b/gedit/gedit-document.h
index c0a9d79..7928601 100644
--- a/gedit/gedit-document.h
+++ b/gedit/gedit-document.h
@@ -200,6 +200,10 @@ gboolean gedit_document_get_deleted (GeditDocument *doc);
gboolean gedit_document_goto_line (GeditDocument *doc,
gint line);
+gboolean gedit_document_goto_line_offset(GeditDocument *doc,
+ gint line,
+ gint line_offset);
+
void gedit_document_set_search_text (GeditDocument *doc,
const gchar *text,
guint flags);
diff --git a/gedit/gedit-view.c b/gedit/gedit-view.c
index 729be4f..1db2818 100644
--- a/gedit/gedit-view.c
+++ b/gedit/gedit-view.c
@@ -1297,10 +1297,24 @@ search_entry_insert_text (GtkEditable *editable,
c = g_utf8_get_char (p);
- if ((c == '-' || c == '+') && *position == 0)
+ if (((c == '-' || c == '+') && *position == 0) ||
+ (c == ':' && *position != 0))
{
- next = g_utf8_next_char (p);
- p = next;
+ gchar *s = NULL;
+
+ if (c == ':')
+ {
+ s = gtk_editable_get_chars (editable, 0, -1);
+ s = g_utf8_strchr (s, -1, ':');
+ }
+
+ if (s == NULL || s == p)
+ {
+ next = g_utf8_next_char (p);
+ p = next;
+ }
+
+ g_free (s);
}
while (p != end)
@@ -1723,16 +1737,30 @@ search_init (GtkWidget *entry,
{
if (*entry_text != '\0')
{
- gboolean moved;
+ gboolean moved, moved_offset;
gint line;
gint offset_line = 0;
+ gint line_offset = 0;
+ gchar **split_text = NULL;
+ const gchar *text;
- if (*entry_text == '-')
+ split_text = g_strsplit (entry_text, ":", -1);
+
+ if (g_strv_length (split_text) > 1)
+ {
+ text = split_text[0];
+ }
+ else
+ {
+ text = entry_text;
+ }
+
+ if (*text == '-')
{
gint cur_line = gtk_text_iter_get_line (&view->priv->start_search_iter);
- if (*(entry_text + 1) != '\0')
- offset_line = MAX (atoi (entry_text + 1), 0);
+ if (*(text + 1) != '\0')
+ offset_line = MAX (atoi (text + 1), 0);
line = MAX (cur_line - offset_line, 0);
}
@@ -1740,20 +1768,30 @@ search_init (GtkWidget *entry,
{
gint cur_line = gtk_text_iter_get_line (&view->priv->start_search_iter);
- if (*(entry_text + 1) != '\0')
- offset_line = MAX (atoi (entry_text + 1), 0);
+ if (*(text + 1) != '\0')
+ offset_line = MAX (atoi (text + 1), 0);
line = cur_line + offset_line;
}
else
{
- line = MAX (atoi (entry_text) - 1, 0);
+ line = MAX (atoi (text) - 1, 0);
}
+ if (split_text[1] != NULL)
+ {
+ line_offset = atoi (split_text[1]);
+ }
+
+ g_strfreev (split_text);
+
moved = gedit_document_goto_line (doc, line);
+ moved_offset = gedit_document_goto_line_offset (doc, line,
+ line_offset);
+
gedit_view_scroll_to_cursor (view);
- if (!moved)
+ if (!moved || !moved_offset)
set_entry_background (view->priv->search_entry,
GEDIT_SEARCH_ENTRY_NOT_FOUND);
else
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]