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