[gtksourceview/wip/smart-backspace] view: bug fix and improvements of do_smart_backspace()
- From: Sébastien Wilmet <swilmet src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtksourceview/wip/smart-backspace] view: bug fix and improvements of do_smart_backspace()
- Date: Sun, 16 Aug 2015 15:44:02 +0000 (UTC)
commit 9910649c28a5a2fb011bd186c5c13aaae19546a9
Author: Sébastien Wilmet <swilmet gnome org>
Date: Sun Aug 16 16:31:12 2015 +0200
view: bug fix and improvements of do_smart_backspace()
Use insert_interactive() and delete_interactive().
gtksourceview/gtksourceview.c | 72 +++++++++++++++++++---------------------
1 files changed, 34 insertions(+), 38 deletions(-)
---
diff --git a/gtksourceview/gtksourceview.c b/gtksourceview/gtksourceview.c
index 1db25f3..536f00a 100644
--- a/gtksourceview/gtksourceview.c
+++ b/gtksourceview/gtksourceview.c
@@ -4069,14 +4069,15 @@ gtk_source_view_do_smart_backspace (GtkSourceView *view,
guint modifiers)
{
GtkTextBuffer *buffer;
+ gboolean default_editable;
GtkTextIter insert;
GtkTextIter end;
- GtkTextIter tmp;
+ GtkTextIter iter;
guint visual_column;
gint indent_width;
- gint tab_width;
buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (view));
+ default_editable = gtk_text_view_get_editable (GTK_TEXT_VIEW (view));
if (gtk_text_buffer_get_selection_bounds (buffer, &insert, &end))
{
@@ -4090,59 +4091,50 @@ gtk_source_view_do_smart_backspace (GtkSourceView *view,
* end of the previous line. Anything more than that is non-obvious because it requires
* looking in a position other than where the cursor is.
*/
- if ((gtk_text_iter_get_line_offset (&insert) == 0) && (gtk_text_iter_get_line (&insert) > 0))
+ if ((gtk_text_iter_get_line_offset (&insert) == 0) &&
+ (gtk_text_iter_get_line (&insert) > 0))
{
- gtk_text_buffer_begin_user_action (buffer);
- gtk_text_iter_backward_char (&insert);
- gtk_text_buffer_delete (buffer, &insert, &end);
- gtk_text_buffer_end_user_action (buffer);
-
+ gtk_text_iter_backward_cursor_position (&insert);
+ gtk_text_buffer_delete_interactive (buffer, &insert, &end, default_editable);
return TRUE;
}
}
- /* if the line isn't empty up to our cursor, ignore */
- tmp = insert;
- while (TRUE)
+ /* If the line isn't empty up to our cursor, ignore. */
+ iter = insert;
+ gtk_text_iter_set_line_offset (&iter, 0);
+ while (gtk_text_iter_compare (&iter, &insert) < 0)
{
- gunichar ch;
-
- ch = gtk_text_iter_get_char (&tmp);
+ gunichar ch = gtk_text_iter_get_char (&iter);
- if ((ch != 0) && !g_unichar_isspace (ch))
+ if (!g_unichar_isspace (ch))
{
return FALSE;
}
- if (gtk_text_iter_starts_line (&tmp))
- {
- break;
- }
-
- gtk_text_iter_backward_char (&tmp);
+ gtk_text_iter_forward_char (&iter);
}
- /*
- * If <Control>BackSpace was specified, delete up to the zero position.
- */
+ /* If <Control>BackSpace was specified, delete up to the zero position. */
if ((modifiers & GDK_CONTROL_MASK) != 0)
{
- gtk_text_buffer_begin_user_action (buffer);
gtk_text_iter_set_line_offset (&insert, 0);
- gtk_text_buffer_delete (buffer, &insert, &end);
- gtk_text_buffer_end_user_action (buffer);
-
+ gtk_text_buffer_delete_interactive (buffer, &insert, &end, default_editable);
return TRUE;
}
visual_column = gtk_source_view_get_visual_column (view, &insert);
- indent_width = gtk_source_view_get_indent_width (view);
- tab_width = gtk_source_view_get_tab_width (view);
+ indent_width = view->priv->indent_width;
if (indent_width <= 0)
{
- indent_width = tab_width;
+ indent_width = view->priv->tab_width;
}
+ g_return_val_if_fail (indent_width > 0, FALSE);
+
+ /* If the cursor is not at an indent_width boundary, it probably means
+ * that we want to adjust the spaces.
+ */
if ((gint)visual_column < indent_width)
{
return FALSE;
@@ -4150,14 +4142,15 @@ gtk_source_view_do_smart_backspace (GtkSourceView *view,
if ((visual_column % indent_width) == 0)
{
- gint target_column = visual_column - indent_width;
+ guint target_column;
gunichar ch;
- g_assert (target_column >= 0);
+ g_assert ((gint)visual_column >= indent_width);
+ target_column = visual_column - indent_width;
- while ((gint)gtk_source_view_get_visual_column (view, &insert) > target_column)
+ while (gtk_source_view_get_visual_column (view, &insert) > target_column)
{
- gtk_text_iter_backward_char (&insert);
+ gtk_text_iter_backward_cursor_position (&insert);
ch = gtk_text_iter_get_char (&insert);
if (!g_unichar_isspace (ch))
@@ -4173,10 +4166,13 @@ gtk_source_view_do_smart_backspace (GtkSourceView *view,
}
gtk_text_buffer_begin_user_action (buffer);
- gtk_text_buffer_delete (buffer, &insert, &end);
- while ((gint)gtk_source_view_get_visual_column (view, &insert) < target_column)
+ gtk_text_buffer_delete_interactive (buffer, &insert, &end, default_editable);
+ while (gtk_source_view_get_visual_column (view, &insert) < target_column)
{
- gtk_text_buffer_insert (buffer, &insert, " ", 1);
+ if (!gtk_text_buffer_insert_interactive (buffer, &insert, " ", 1, default_editable))
+ {
+ break;
+ }
}
gtk_text_buffer_end_user_action (buffer);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]