summaryrefslogtreecommitdiff
path: root/libview
diff options
context:
space:
mode:
authorCarlos Garcia Campos <[email protected]>2013-06-26 12:58:28 +0200
committerraveit65 <[email protected]>2017-09-06 18:25:34 +0200
commit502b35b6de941c3aa6643a5bf9ef37f1b985ec01 (patch)
tree7540306c37bfbc644fb5595e66c7f94585993767 /libview
parent41f83255d87c342ff957c5159fc37331210083af (diff)
downloadatril-502b35b6de941c3aa6643a5bf9ef37f1b985ec01.tar.bz2
atril-502b35b6de941c3aa6643a5bf9ef37f1b985ec01.tar.xz
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. origin commit: https://git.gnome.org/browse/evince/commit/?h=gnome-3-10&id=040a42d
Diffstat (limited to 'libview')
-rw-r--r--libview/ev-view.c48
1 files changed, 37 insertions, 11 deletions
diff --git a/libview/ev-view.c b/libview/ev-view.c
index 3f90d610..118d51d3 100644
--- a/libview/ev-view.c
+++ b/libview/ev-view.c
@@ -4232,7 +4232,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;
@@ -4248,24 +4248,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;