diff options
author | Havoc Pennington <hp@pobox.com> | 2000-12-02 07:51:37 +0000 |
---|---|---|
committer | Havoc Pennington <hp@src.gnome.org> | 2000-12-02 07:51:37 +0000 |
commit | 35876710dc133b5cab14241174ba0e680ca854af (patch) | |
tree | cab3760bbea08fdcb20e9a9a9f10f6eff3c00b07 /gtk/gtktextbuffer.c | |
parent | fb14d1299e3b81a70938462f841f17ea1e217ded (diff) | |
download | gtk+-35876710dc133b5cab14241174ba0e680ca854af.tar.gz |
don't create dangling pointers to the appearance attributes from the line
2000-11-30 Havoc Pennington <hp@pobox.com>
* gtk/gtktextdisplay.c (gtk_text_layout_draw): don't create
dangling pointers to the appearance attributes from the
line display
* gdk/gdkdraw.c (gdk_drawable_get_image): allow negative
width/height to mean "full width/height of drawable"
* gtk/gtktextview.h, gtk/gtktextview.c: Implement double/triple
click to select word/line
* gtk/gtktextiter.c (test_log_attrs): include paragraph delimiters
when getting log attrs. Get a slice, so that pixmaps and stuff
are properly handled.
* gtk/gtktextbuffer.c (paste): Fix pasting to work properly if you
paste into the selection (replaces selection now, previously
crashed or added to selection). Reveals longstanding btree bug -
select multiple lines, middle-click on the selection, boom. This
isn't related to my changes though.
* gtk/gtkentry.c (gtk_entry_move_forward_word): Update to reflect
PangoLogAttrs changes
(gtk_entry_move_backward_word): ditto
* gtk/gtktextlayout.h, gtk/gtktextlayout.c: Make the iter motion
functions return bool whether the iter moved onto a
dereferenceable position.
* gtk/gtktextview.h, gtk/gtktextview.c: Add a bunch of public
functions for motion in terms of display lines.
* gtk/gtktextmark.c (gtk_text_mark_get_buffer): Add function to
get the buffer a mark is inside
Diffstat (limited to 'gtk/gtktextbuffer.c')
-rw-r--r-- | gtk/gtktextbuffer.c | 60 |
1 files changed, 54 insertions, 6 deletions
diff --git a/gtk/gtktextbuffer.c b/gtk/gtktextbuffer.c index 9cd8dbba9f..db770bab66 100644 --- a/gtk/gtktextbuffer.c +++ b/gtk/gtktextbuffer.c @@ -2172,24 +2172,40 @@ pre_paste_prep (ClipboardRequest *request_data, GtkTextIter *insert_point) { GtkTextBuffer *buffer = request_data->buffer; + + get_paste_point (buffer, insert_point, TRUE); + /* If we're going to replace the selection, we insert before it to + * avoid messing it up, then we delete the selection after inserting. + */ if (request_data->replace_selection) { GtkTextIter start, end; if (gtk_text_buffer_get_selection_bounds (buffer, &start, &end)) + *insert_point = start; + } +} + +static void +post_paste_cleanup (ClipboardRequest *request_data) +{ + if (request_data->replace_selection) + { + GtkTextIter start, end; + + if (gtk_text_buffer_get_selection_bounds (request_data->buffer, + &start, &end)) { if (request_data->interactive) - gtk_text_buffer_delete_interactive (buffer, + gtk_text_buffer_delete_interactive (request_data->buffer, &start, &end, request_data->default_editable); else - gtk_text_buffer_delete (buffer, &start, &end); + gtk_text_buffer_delete (request_data->buffer, &start, &end); } } - - get_paste_point (buffer, insert_point, TRUE); } /* Called when we request a paste and receive the text data @@ -2214,6 +2230,8 @@ clipboard_text_received (GtkClipboard *clipboard, else gtk_text_buffer_insert (buffer, &insert_point, str, -1); + + post_paste_cleanup (request_data); } g_object_unref (G_OBJECT (buffer)); @@ -2253,6 +2271,33 @@ selection_data_get_buffer (GtkSelectionData *selection_data, return src_buffer; } +#if 0 +/* These are pretty handy functions; maybe something like them + * should be in the public API. Also, there are other places in this + * file where they could be used. + */ +static gpointer +save_iter (const GtkTextIter *iter, + gboolean left_gravity) +{ + return gtk_text_buffer_create_mark (gtk_text_iter_get_buffer (iter), + NULL, + iter, + TRUE); +} + +static void +restore_iter (const GtkTextIter *iter, + gpointer save_id) +{ + gtk_text_buffer_get_iter_at_mark (gtk_text_mark_get_buffer (save_id), + (GtkTextIter*) iter, + save_id); + gtk_text_buffer_delete_mark (gtk_text_mark_get_buffer (save_id), + save_id); +} +#endif + static void paste_from_buffer (ClipboardRequest *request_data, GtkTextBuffer *src_buffer, @@ -2274,6 +2319,8 @@ paste_from_buffer (ClipboardRequest *request_data, end, request_data->interactive); } + + post_paste_cleanup (request_data); g_object_unref (G_OBJECT (src_buffer)); } @@ -2392,13 +2439,14 @@ paste (GtkTextBuffer *buffer, * replace the selection with the new text, otherwise, you * simply insert the new text at the point where the click * occured, unselecting any selected text. The replace_selection - * flag toggles this behavior. FIXME set the flag based on something. + * flag toggles this behavior. */ data->replace_selection = FALSE; get_paste_point (buffer, &paste_point, FALSE); if (gtk_text_buffer_get_selection_bounds (buffer, &start, &end) && - gtk_text_iter_in_range (&paste_point, &start, &end)) + (gtk_text_iter_in_range (&paste_point, &start, &end) || + gtk_text_iter_equal (&paste_point, &end))) data->replace_selection = TRUE; if (is_clipboard) |