|
|
a78d3a |
From d33ed342af50b66c7c49c2843d7495febfd663e9 Mon Sep 17 00:00:00 2001
|
|
|
a78d3a |
From: Christian Hergert <chergert@redhat.com>
|
|
|
a78d3a |
Date: Wed, 28 Jul 2021 17:49:40 -0700
|
|
|
a78d3a |
Subject: [PATCH 1/1] view: fix decrement of negative numbers
|
|
|
a78d3a |
|
|
|
a78d3a |
Fixes #117
|
|
|
a78d3a |
---
|
|
|
a78d3a |
gtksourceview/gtksourceview.c | 11 +++++++++++
|
|
|
a78d3a |
1 file changed, 11 insertions(+)
|
|
|
a78d3a |
|
|
|
a78d3a |
diff --git a/gtksourceview/gtksourceview.c b/gtksourceview/gtksourceview.c
|
|
|
a78d3a |
index e10584aa..377cdd8d 100644
|
|
|
a78d3a |
--- a/gtksourceview/gtksourceview.c
|
|
|
a78d3a |
+++ b/gtksourceview/gtksourceview.c
|
|
|
a78d3a |
@@ -360,61 +360,72 @@ gtk_source_view_move_to_matching_bracket (GtkSourceView *view,
|
|
|
a78d3a |
gtk_text_buffer_move_mark (buffer, insert_mark, &bracket_match);
|
|
|
a78d3a |
}
|
|
|
a78d3a |
else
|
|
|
a78d3a |
{
|
|
|
a78d3a |
gtk_text_buffer_place_cursor (buffer, &bracket_match);
|
|
|
a78d3a |
}
|
|
|
a78d3a |
|
|
|
a78d3a |
gtk_text_view_scroll_mark_onscreen (text_view, insert_mark);
|
|
|
a78d3a |
}
|
|
|
a78d3a |
}
|
|
|
a78d3a |
|
|
|
a78d3a |
static void
|
|
|
a78d3a |
gtk_source_view_change_number (GtkSourceView *view,
|
|
|
a78d3a |
gint count)
|
|
|
a78d3a |
{
|
|
|
a78d3a |
GtkTextView *text_view = GTK_TEXT_VIEW (view);
|
|
|
a78d3a |
GtkTextBuffer *buffer;
|
|
|
a78d3a |
GtkTextIter start, end;
|
|
|
a78d3a |
gchar *str;
|
|
|
a78d3a |
|
|
|
a78d3a |
buffer = gtk_text_view_get_buffer (text_view);
|
|
|
a78d3a |
if (!GTK_SOURCE_IS_BUFFER (buffer))
|
|
|
a78d3a |
{
|
|
|
a78d3a |
return;
|
|
|
a78d3a |
}
|
|
|
a78d3a |
|
|
|
a78d3a |
if (!gtk_text_buffer_get_selection_bounds (buffer, &start, &end))
|
|
|
a78d3a |
{
|
|
|
a78d3a |
if (!gtk_text_iter_starts_word (&start))
|
|
|
a78d3a |
{
|
|
|
a78d3a |
+ GtkTextIter prev;
|
|
|
a78d3a |
+
|
|
|
a78d3a |
gtk_text_iter_backward_word_start (&start;;
|
|
|
a78d3a |
+
|
|
|
a78d3a |
+ /* Include the negative sign if there is one.
|
|
|
a78d3a |
+ * https://gitlab.gnome.org/GNOME/gtksourceview/-/issues/117
|
|
|
a78d3a |
+ */
|
|
|
a78d3a |
+ prev = start;
|
|
|
a78d3a |
+ if (gtk_text_iter_backward_char (&prev) && gtk_text_iter_get_char (&prev) == '-')
|
|
|
a78d3a |
+ {
|
|
|
a78d3a |
+ start = prev;
|
|
|
a78d3a |
+ }
|
|
|
a78d3a |
}
|
|
|
a78d3a |
|
|
|
a78d3a |
if (!gtk_text_iter_ends_word (&end))
|
|
|
a78d3a |
{
|
|
|
a78d3a |
gtk_text_iter_forward_word_end (&end;;
|
|
|
a78d3a |
}
|
|
|
a78d3a |
}
|
|
|
a78d3a |
|
|
|
a78d3a |
str = gtk_text_buffer_get_text (buffer, &start, &end, FALSE);
|
|
|
a78d3a |
|
|
|
a78d3a |
if (str != NULL && *str != '\0')
|
|
|
a78d3a |
{
|
|
|
a78d3a |
gchar *p;
|
|
|
a78d3a |
gint64 n;
|
|
|
a78d3a |
glong len;
|
|
|
a78d3a |
|
|
|
a78d3a |
len = gtk_text_iter_get_offset (&end) - gtk_text_iter_get_offset (&start;;
|
|
|
a78d3a |
g_assert (len > 0);
|
|
|
a78d3a |
|
|
|
a78d3a |
n = g_ascii_strtoll (str, &p, 10);
|
|
|
a78d3a |
|
|
|
a78d3a |
/* do the action only if strtoll succeeds (p != str) and
|
|
|
a78d3a |
* the whole string is the number, e.g. not 123abc
|
|
|
a78d3a |
*/
|
|
|
a78d3a |
if ((p - str) == len)
|
|
|
a78d3a |
{
|
|
|
a78d3a |
gchar *newstr;
|
|
|
a78d3a |
|
|
|
a78d3a |
newstr = g_strdup_printf ("%"G_GINT64_FORMAT, (n + count));
|
|
|
a78d3a |
|
|
|
a78d3a |
--
|
|
|
a78d3a |
2.39.1
|
|
|
a78d3a |
|