Merge branch 'wip/chergert/4575-fix-texthistory-selection' into 'main'

testsuite: ignore texthistory selection on delete/backspace

Closes #4575

See merge request GNOME/gtk!4287
This commit is contained in:
Matthias Clasen 2021-12-29 14:58:53 +00:00
commit dd0effe957
3 changed files with 29 additions and 11 deletions

View File

@ -981,11 +981,8 @@ gtk_text_history_selection_changed (GtkTextHistory *self,
return_if_applying (self);
return_if_irreversible (self);
if (self->in_user == 0 && self->irreversible == 0)
{
self->selection.insert = CLAMP (selection_insert, -1, G_MAXINT);
self->selection.bound = CLAMP (selection_bound, -1, G_MAXINT);
}
self->selection.insert = CLAMP (selection_insert, -1, G_MAXINT);
self->selection.bound = CLAMP (selection_bound, -1, G_MAXINT);
}
void

View File

@ -10101,7 +10101,11 @@ gtk_text_view_real_undo (GtkWidget *widget,
GtkTextView *text_view = GTK_TEXT_VIEW (widget);
if (gtk_text_view_get_editable (text_view))
gtk_text_buffer_undo (text_view->priv->buffer);
{
gtk_text_buffer_undo (text_view->priv->buffer);
gtk_text_view_scroll_mark_onscreen (text_view,
gtk_text_buffer_get_insert (text_view->priv->buffer));
}
}
static void
@ -10112,7 +10116,11 @@ gtk_text_view_real_redo (GtkWidget *widget,
GtkTextView *text_view = GTK_TEXT_VIEW (widget);
if (gtk_text_view_get_editable (text_view))
gtk_text_buffer_redo (text_view->priv->buffer);
{
gtk_text_buffer_redo (text_view->priv->buffer);
gtk_text_view_scroll_mark_onscreen (text_view,
gtk_text_buffer_get_insert (text_view->priv->buffer));
}
}
static void

View File

@ -251,8 +251,6 @@ run_test (const Command *commands,
set_selection (text, cmd->location, cmd->end_location);
else if (strlen (cmd->text) == 1)
set_selection (text, cmd->location, -1);
else
set_selection (text, -1, -1);
command_delete_key (cmd, text);
break;
@ -261,8 +259,6 @@ run_test (const Command *commands,
set_selection (text, cmd->location, cmd->end_location);
else if (strlen (cmd->text) == 1)
set_selection (text, cmd->end_location, -1);
else
set_selection (text, -1, -1);
command_delete_key (cmd, text);
break;
@ -623,6 +619,22 @@ test_issue_4276 (void)
run_test (commands, G_N_ELEMENTS (commands), 0);
}
static void
test_issue_4575 (void)
{
const Command commands[] = {
{ INSERT, 0, -1, "this is some text", "this is some text", SET, UNSET, UNSET },
{ SELECT, 5, 8, NULL, NULL, SET, UNSET, UNSET },
{ BEGIN_USER, -1, -1, NULL, NULL, UNSET, UNSET, UNSET },
{ DELETE_KEY, 5, 8, "is ", "this some text", UNSET, UNSET, UNSET, IGNORE_SELECT },
{ END_USER, -1, -1, NULL, NULL, SET, UNSET, UNSET },
{ UNDO, -1, -1, NULL, "this is some text", SET, SET, UNSET },
{ CHECK_SELECT, 5, 8, NULL, "this is some text", SET, SET, UNSET },
};
run_test (commands, G_N_ELEMENTS (commands), 0);
}
int
main (int argc,
char *argv[])
@ -644,6 +656,7 @@ main (int argc,
g_test_add_func ("/Gtk/TextHistory/test13", test13);
g_test_add_func ("/Gtk/TextHistory/test14", test14);
g_test_add_func ("/Gtk/TextHistory/issue_4276", test_issue_4276);
g_test_add_func ("/Gtk/TextHistory/issue_4575", test_issue_4575);
return g_test_run ();
}