[evince] libview: Position the caret cursor at beginning/end of the line when clicking outside the line
- From: Carlos Garcia Campos <carlosgc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [evince] libview: Position the caret cursor at beginning/end of the line when clicking outside the line
- Date: Wed, 26 Jun 2013 13:08:56 +0000 (UTC)
commit 040a42db65ee9acb2df31476f40a6257c84f0d1b
Author: Carlos Garcia Campos <carlosgc gnome org>
Date: Wed Jun 26 12:58:28 2013 +0200
libview: Position the caret cursor at beginning/end of the line when clicking outside the line
Position the caret cursor also when not clicking over text if the line
contains text.
libview/ev-view.c | 48 +++++++++++++++++++++++++++++++++++++-----------
1 files changed, 37 insertions(+), 11 deletions(-)
---
diff --git a/libview/ev-view.c b/libview/ev-view.c
index a723623..aaf1833 100644
--- a/libview/ev-view.c
+++ b/libview/ev-view.c
@@ -4024,7 +4024,7 @@ position_caret_cursor_at_location (EvView *view,
gint offset = -1 ;
gint doc_x, doc_y;
EvRectangle *rect;
- guint i;
+ guint i, j;
if (!view->caret_enabled || view->rotation != 0)
return FALSE;
@@ -4040,24 +4040,50 @@ position_caret_cursor_at_location (EvView *view,
if (!areas)
return FALSE;
+ /* First look for the line of text at location */
for (i = 0; i < n_areas; i++) {
rect = areas + i;
- if (doc_x >= rect->x1 && doc_x <= rect->x2 &&
- doc_y >= rect->y1 && doc_y <= rect->y2) {
- /* 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;
- else
- offset = i + 1;
+ if (doc_y >= rect->y1 && doc_y <= rect->y2)
break;
- }
}
- if (offset == -1)
+ if (i == n_areas)
return FALSE;
+ if (doc_x <= rect->x1) {
+ /* Location is before the start of the line */
+ offset = i;
+ } else {
+ for (j = i; j < n_areas; j++) {
+ rect = areas + j;
+
+ if (doc_y < rect->y1) {
+ /* Location is after the end of the line */
+ offset = j;
+ break;
+ }
+
+ if (doc_x >= rect->x1 && doc_x <= rect->x2) {
+ /* Location is inside the line. 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 = j;
+ else
+ offset = j + 1;
+ break;
+ }
+
+ }
+ }
+
+ if (offset == -1) {
+ /* This is the last line and loocation is after the end of the line */
+ offset = n_areas;
+ }
+
if (view->cursor_offset != offset || view->cursor_page != page) {
view->cursor_offset = offset;
view->cursor_page = page;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]