mirror of
https://gitlab.gnome.org/GNOME/gtk.git
synced 2024-10-02 20:17:33 +00:00
Improve selection/arrow key behaviour in GtkTextView
This patch makes the text view behave more similar to entries. Patch by Michael Natterer, see bug 50942
This commit is contained in:
parent
87075b3b97
commit
a8fcc1c482
@ -337,6 +337,7 @@ static void gtk_text_view_paste_done_handler (GtkTextBuffer *buffer,
|
|||||||
static void gtk_text_view_get_cursor_location (GtkTextView *text_view,
|
static void gtk_text_view_get_cursor_location (GtkTextView *text_view,
|
||||||
GdkRectangle *pos);
|
GdkRectangle *pos);
|
||||||
static void gtk_text_view_get_virtual_cursor_pos (GtkTextView *text_view,
|
static void gtk_text_view_get_virtual_cursor_pos (GtkTextView *text_view,
|
||||||
|
GtkTextIter *cursor,
|
||||||
gint *x,
|
gint *x,
|
||||||
gint *y);
|
gint *y);
|
||||||
static void gtk_text_view_set_virtual_cursor_pos (GtkTextView *text_view,
|
static void gtk_text_view_set_virtual_cursor_pos (GtkTextView *text_view,
|
||||||
@ -5035,6 +5036,7 @@ gtk_text_view_move_cursor_internal (GtkTextView *text_view,
|
|||||||
{
|
{
|
||||||
GtkTextIter insert;
|
GtkTextIter insert;
|
||||||
GtkTextIter newplace;
|
GtkTextIter newplace;
|
||||||
|
gboolean cancel_selection = FALSE;
|
||||||
gint cursor_x_pos = 0;
|
gint cursor_x_pos = 0;
|
||||||
GtkDirectionType leave_direction = -1;
|
GtkDirectionType leave_direction = -1;
|
||||||
|
|
||||||
@ -5111,18 +5113,44 @@ gtk_text_view_move_cursor_internal (GtkTextView *text_view,
|
|||||||
|
|
||||||
gtk_text_buffer_get_iter_at_mark (get_buffer (text_view), &insert,
|
gtk_text_buffer_get_iter_at_mark (get_buffer (text_view), &insert,
|
||||||
gtk_text_buffer_get_insert (get_buffer (text_view)));
|
gtk_text_buffer_get_insert (get_buffer (text_view)));
|
||||||
|
|
||||||
|
if (! extend_selection)
|
||||||
|
{
|
||||||
|
GtkTextIter sel_bound;
|
||||||
|
|
||||||
|
gtk_text_buffer_get_iter_at_mark (get_buffer (text_view), &sel_bound,
|
||||||
|
gtk_text_buffer_get_selection_bound (get_buffer (text_view)));
|
||||||
|
|
||||||
|
/* if we move forward, assume the cursor is at the end of the selection;
|
||||||
|
* if we move backward, assume the cursor is at the start
|
||||||
|
*/
|
||||||
|
if (count > 0)
|
||||||
|
gtk_text_iter_order (&sel_bound, &insert);
|
||||||
|
else
|
||||||
|
gtk_text_iter_order (&insert, &sel_bound);
|
||||||
|
|
||||||
|
/* if we actually have a selection, just move *to* the beginning/end
|
||||||
|
* of the selection and not *from* there on LOGICAL_POSITIONS
|
||||||
|
* and VISUAL_POSITIONS movement
|
||||||
|
*/
|
||||||
|
if (! gtk_text_iter_equal (&sel_bound, &insert))
|
||||||
|
cancel_selection = TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
newplace = insert;
|
newplace = insert;
|
||||||
|
|
||||||
if (step == GTK_MOVEMENT_DISPLAY_LINES)
|
if (step == GTK_MOVEMENT_DISPLAY_LINES)
|
||||||
gtk_text_view_get_virtual_cursor_pos (text_view, &cursor_x_pos, NULL);
|
gtk_text_view_get_virtual_cursor_pos (text_view, &insert, &cursor_x_pos, NULL);
|
||||||
|
|
||||||
switch (step)
|
switch (step)
|
||||||
{
|
{
|
||||||
case GTK_MOVEMENT_LOGICAL_POSITIONS:
|
case GTK_MOVEMENT_LOGICAL_POSITIONS:
|
||||||
|
if (! cancel_selection)
|
||||||
gtk_text_iter_forward_visible_cursor_positions (&newplace, count);
|
gtk_text_iter_forward_visible_cursor_positions (&newplace, count);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case GTK_MOVEMENT_VISUAL_POSITIONS:
|
case GTK_MOVEMENT_VISUAL_POSITIONS:
|
||||||
|
if (! cancel_selection)
|
||||||
gtk_text_layout_move_iter_visually (text_view->layout,
|
gtk_text_layout_move_iter_visually (text_view->layout,
|
||||||
&newplace, count);
|
&newplace, count);
|
||||||
break;
|
break;
|
||||||
@ -5233,7 +5261,7 @@ gtk_text_view_move_cursor_internal (GtkTextView *text_view,
|
|||||||
g_signal_emit_by_name (text_view, "move-focus", leave_direction);
|
g_signal_emit_by_name (text_view, "move-focus", leave_direction);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else if (! cancel_selection)
|
||||||
{
|
{
|
||||||
gtk_widget_error_bell (GTK_WIDGET (text_view));
|
gtk_widget_error_bell (GTK_WIDGET (text_view));
|
||||||
}
|
}
|
||||||
@ -5386,7 +5414,7 @@ gtk_text_view_scroll_pages (GtkTextView *text_view,
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
gtk_text_view_get_virtual_cursor_pos (text_view, &cursor_x_pos, &cursor_y_pos);
|
gtk_text_view_get_virtual_cursor_pos (text_view, NULL, &cursor_x_pos, &cursor_y_pos);
|
||||||
|
|
||||||
oldval = adj->value;
|
oldval = adj->value;
|
||||||
newval = adj->value;
|
newval = adj->value;
|
||||||
@ -5467,7 +5495,7 @@ gtk_text_view_scroll_hpages (GtkTextView *text_view,
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
gtk_text_view_get_virtual_cursor_pos (text_view, &cursor_x_pos, &cursor_y_pos);
|
gtk_text_view_get_virtual_cursor_pos (text_view, NULL, &cursor_x_pos, &cursor_y_pos);
|
||||||
|
|
||||||
oldval = adj->value;
|
oldval = adj->value;
|
||||||
newval = adj->value;
|
newval = adj->value;
|
||||||
@ -7484,14 +7512,22 @@ gtk_text_view_get_cursor_location (GtkTextView *text_view,
|
|||||||
|
|
||||||
static void
|
static void
|
||||||
gtk_text_view_get_virtual_cursor_pos (GtkTextView *text_view,
|
gtk_text_view_get_virtual_cursor_pos (GtkTextView *text_view,
|
||||||
|
GtkTextIter *cursor,
|
||||||
gint *x,
|
gint *x,
|
||||||
gint *y)
|
gint *y)
|
||||||
{
|
{
|
||||||
|
GtkTextIter insert;
|
||||||
GdkRectangle pos;
|
GdkRectangle pos;
|
||||||
|
|
||||||
|
if (cursor)
|
||||||
|
insert = *cursor;
|
||||||
|
else
|
||||||
|
gtk_text_buffer_get_iter_at_mark (get_buffer (text_view), &insert,
|
||||||
|
gtk_text_buffer_get_insert (get_buffer (text_view)));
|
||||||
|
|
||||||
if ((x && text_view->virtual_cursor_x == -1) ||
|
if ((x && text_view->virtual_cursor_x == -1) ||
|
||||||
(y && text_view->virtual_cursor_y == -1))
|
(y && text_view->virtual_cursor_y == -1))
|
||||||
gtk_text_view_get_cursor_location (text_view, &pos);
|
gtk_text_layout_get_cursor_locations (text_view->layout, &insert, &pos, NULL);
|
||||||
|
|
||||||
if (x)
|
if (x)
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user