[evince] libview: Update the caret cursor after selecting text with the mouse
- From: Carlos Garcia Campos <carlosgc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [evince] libview: Update the caret cursor after selecting text with the mouse
- Date: Fri, 21 Jun 2013 13:13:00 +0000 (UTC)
commit 619c1001b380566616e760317454c5e380dfbacf
Author: Carlos Garcia Campos <carlosgc gnome org>
Date: Fri Jun 21 15:09:58 2013 +0200
libview: Update the caret cursor after selecting text with the mouse
If there's an active selection move the caret cursor to the location
where the mouse is released.
libview/ev-view.c | 50 ++++++++++++++++++++++++++++----------------------
1 files changed, 28 insertions(+), 22 deletions(-)
---
diff --git a/libview/ev-view.c b/libview/ev-view.c
index ab29010..3b78e33 100644
--- a/libview/ev-view.c
+++ b/libview/ev-view.c
@@ -4014,17 +4014,17 @@ start_selection_for_event (EvView *view,
}
static gboolean
-get_caret_cursor_offset_at_location (EvView *view,
- gdouble x,
- gdouble y,
- gint *page,
- gint *offset)
-{
- gint doc_x, doc_y;
- EvRectangle *areas;
+position_caret_cursor_at_location (EvView *view,
+ gdouble x,
+ gdouble y)
+{
+ EvRectangle *areas = NULL;
+ guint n_areas = 0;
+ gint page;
+ gint offset = -1 ;
+ gint doc_x, doc_y;
EvRectangle *rect;
- guint n_areas = 0;
- guint i;
+ guint i;
if (!view->caret_enabled || view->rotation != 0)
return FALSE;
@@ -4033,10 +4033,10 @@ get_caret_cursor_offset_at_location (EvView *view,
return FALSE;
/* Get the offset from the doc point */
- if (!get_doc_point_from_location (view, x, y, page, &doc_x, &doc_y))
+ if (!get_doc_point_from_location (view, x, y, &page, &doc_x, &doc_y))
return FALSE;
- ev_page_cache_get_text_layout (view->page_cache, *page, &areas, &n_areas);
+ ev_page_cache_get_text_layout (view->page_cache, page, &areas, &n_areas);
if (!areas)
return FALSE;
@@ -4047,14 +4047,24 @@ get_caret_cursor_offset_at_location (EvView *view,
/* Position the caret before or after the character, depending on whether
the point falls within the left or right half of the bounding box. */
if (doc_x <= rect->x1 + (rect->x2 - rect->x1) / 2)
- *offset = i;
+ offset = i;
else
- *offset = i + 1;
+ offset = i + 1;
- return TRUE;
+ break;
}
}
+ if (offset == -1)
+ return FALSE;
+
+ if (view->cursor_offset != offset || view->cursor_page != page) {
+ view->cursor_offset = offset;
+ view->cursor_page = page;
+
+ return TRUE;
+ }
+
return FALSE;
}
@@ -4124,8 +4134,6 @@ ev_view_button_press_event (GtkWidget *widget,
view->image_dnd_info.start.x = event->x + view->scroll_x;
view->image_dnd_info.start.y = event->y + view->scroll_y;
} else {
- gint page, offset;
-
ev_view_remove_all (view);
if (view->synctex_result) {
@@ -4140,11 +4148,7 @@ ev_view_button_press_event (GtkWidget *widget,
if (EV_IS_SELECTION (view->document))
start_selection_for_event (view, event);
- if (get_caret_cursor_offset_at_location (view, event->x, event->y, &page,
&offset) &&
- (view->cursor_offset != offset || view->cursor_page != page)) {
- view->cursor_offset = offset;
- view->cursor_page = page;
-
+ if (position_caret_cursor_at_location (view, event->x, event->y)) {
view->cursor_blink_time = 0;
ev_view_pend_cursor_blink (view);
@@ -4595,7 +4599,9 @@ ev_view_button_release_event (GtkWidget *widget,
if (view->selection_info.selections) {
clear_link_selected (view);
ev_view_update_primary_selection (view);
-
+
+ position_caret_cursor_at_location (view, event->x, event->y);
+
if (view->selection_info.in_drag) {
clear_selection (view);
gtk_widget_queue_draw (widget);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]