Do not clear primary clipboard when text is deselected

This commit is contained in:
Yevgen Muntyan 2008-12-24 15:29:32 -06:00
parent 3be9c0cf09
commit bf110f2341
3 changed files with 26 additions and 12 deletions

View File

@ -195,6 +195,14 @@ text_view_reset_im_context (GtkTextView *text_view)
}
static void
copy_and_place_cursor (GtkTextView *text_view,
const GtkTextIter *where)
{
_moo_text_view_ensure_primary (text_view);
gtk_text_buffer_place_cursor (gtk_text_view_get_buffer (text_view), where);
}
static void
move_cursor_to (GtkTextView *text_view,
GtkTextIter *where,
@ -210,7 +218,7 @@ move_cursor_to (GtkTextView *text_view,
if (extend_selection)
gtk_text_buffer_move_mark (buffer, insert, where);
else
gtk_text_buffer_place_cursor (buffer, where);
copy_and_place_cursor (text_view, where);
gtk_text_view_scroll_mark_onscreen (text_view, insert);
}
@ -697,7 +705,7 @@ _moo_text_view_button_press_event (GtkWidget *widget,
}
else
{
gtk_text_buffer_place_cursor (buffer, &iter);
copy_and_place_cursor (text_view, &iter);
}
}
else
@ -754,7 +762,7 @@ _moo_text_view_button_press_event (GtkWidget *widget,
if (gtk_text_buffer_get_selection_bounds (buffer, NULL, NULL))
{
/* it may happen sometimes, if you click fast enough */
gtk_text_buffer_place_cursor (buffer, &iter);
copy_and_place_cursor (text_view, &iter);
}
view->priv->dnd.button = GDK_2BUTTON_PRESS;
@ -814,7 +822,7 @@ _moo_text_view_button_release_event (GtkWidget *widget,
g_return_val_if_reached (FALSE);
}
get_start_mark (view, &iter);
gtk_text_buffer_place_cursor (gtk_text_view_get_buffer (text_view), &iter);
copy_and_place_cursor (text_view, &iter);
break;
}
@ -906,7 +914,7 @@ _moo_text_view_motion_event (GtkWidget *widget,
if (extend_selection (view, t, &start, &iter))
select_range (buffer, &start, &iter);
else
gtk_text_buffer_place_cursor (buffer, &iter);
copy_and_place_cursor (text_view, &iter);
}
else
{
@ -1127,7 +1135,7 @@ drag_scroll_timeout_func (MooTextView *view)
if (extend_selection (view, t, &start, &iter))
select_range (buffer, &start, &iter);
else
gtk_text_buffer_place_cursor (buffer, &iter);
copy_and_place_cursor (text_view, &iter);
}
else
{
@ -1255,6 +1263,7 @@ _moo_text_view_key_press_event (GtkWidget *widget,
return TRUE;
view->priv->in_key_press = TRUE;
_moo_text_view_ensure_primary (text_view);
gtk_text_buffer_begin_user_action (buffer);
handled = GTK_WIDGET_CLASS (_moo_text_view_parent_class)->
key_press_event (widget, event);

View File

@ -35,6 +35,7 @@ void _moo_text_view_move_cursor (GtkTextView *text_view,
GtkMovementStep step,
gint count,
gboolean extend_selection);
void _moo_text_view_ensure_primary (GtkTextView *text_view);
#if !GTK_CHECK_VERSION(2,12,0)
void _moo_text_view_page_horizontally (GtkTextView *text_view,
int count,

View File

@ -1893,8 +1893,6 @@ selection_changed (MooTextView *view,
G_N_ELEMENTS (targets),
clipboard_get_selection,
NULL, G_OBJECT (view));
else
clear_primary (view);
}
@ -1956,7 +1954,8 @@ clear_clipboard (G_GNUC_UNUSED GtkClipboard *clipboard,
static void
moo_text_view_cut_or_copy (GtkTextView *text_view,
gboolean delete)
gboolean delete,
GdkAtom clipboard_type)
{
GtkTextBuffer *buffer;
GtkTextIter start, end;
@ -1970,7 +1969,7 @@ moo_text_view_cut_or_copy (GtkTextView *text_view,
return;
clipboard = gtk_widget_get_clipboard (GTK_WIDGET (text_view),
GDK_SELECTION_CLIPBOARD);
clipboard_type);
contents = moo_new0 (MooTextViewClipboard);
contents->text = gtk_text_buffer_get_slice (buffer, &start, &end, TRUE);
@ -1998,18 +1997,23 @@ moo_text_view_cut_or_copy (GtkTextView *text_view,
}
}
void
_moo_text_view_ensure_primary (GtkTextView *text_view)
{
moo_text_view_cut_or_copy (text_view, FALSE, GDK_SELECTION_PRIMARY);
}
static void
moo_text_view_copy_clipboard (GtkTextView *text_view)
{
moo_text_view_cut_or_copy (text_view, FALSE);
moo_text_view_cut_or_copy (text_view, FALSE, GDK_SELECTION_CLIPBOARD);
}
static void
moo_text_view_cut_clipboard (GtkTextView *text_view)
{
moo_text_view_cut_or_copy (text_view, TRUE);
moo_text_view_cut_or_copy (text_view, TRUE, GDK_SELECTION_CLIPBOARD);
}