From c176e276e2de15a306872e3d4fa74193178eaadf Mon Sep 17 00:00:00 2001 From: Adrian Lees Date: Mon, 6 Feb 2006 00:07:18 +0000 Subject: [project @ 2006-02-06 00:07:18 by adrianl] Drag-saving of text without pressing Ctrl svn path=/import/netsurf/; revision=2058 --- desktop/selection.c | 29 +++++++++++++++++++++++++++-- desktop/selection.h | 15 +++++++++++---- 2 files changed, 38 insertions(+), 6 deletions(-) (limited to 'desktop') diff --git a/desktop/selection.c b/desktop/selection.c index be713d2d2..a33a2068a 100644 --- a/desktop/selection.c +++ b/desktop/selection.c @@ -242,7 +242,7 @@ bool selection_click(struct selection *s, struct box *box, } } - if (!pos && (mouse & BROWSER_MOUSE_MOD_2) && + if (!pos && (mouse & (BROWSER_MOUSE_DRAG_1 | BROWSER_MOUSE_DRAG_2))) { /* drag-saving selection */ assert(s->bw); @@ -279,7 +279,7 @@ bool selection_click(struct selection *s, struct box *box, } gui_start_selection(s->bw->window); } - else if (mouse & BROWSER_MOUSE_CLICK_1) { + else if (pos && (mouse & BROWSER_MOUSE_CLICK_1)) { /* clear selection */ selection_clear(s, true); @@ -901,3 +901,28 @@ bool selection_save_text(struct selection *s, const char *path) return false; } + + +/** + * Adjust the selection to reflect a change in the selected text, + * eg. editing in a text area/input field. + * + * \param s selection object + * \param byte_offset byte offset of insertion/removal point + * \param change byte size of change, +ve = insertion, -ve = removal + * \param redraw true iff the screen should be updated + */ + +void selection_update(struct selection *s, size_t byte_offset, + int change, bool redraw) +{ + if (selection_defined(s) && + byte_offset >= s->start_idx && + byte_offset < s->end_idx) + { + if (change > 0) + s->end_idx += change; + else + s->end_idx += max(change, byte_offset - s->end_idx); + } +} diff --git a/desktop/selection.h b/desktop/selection.h index eaaae4d83..c039e1c0f 100644 --- a/desktop/selection.h +++ b/desktop/selection.h @@ -44,7 +44,8 @@ struct selection }; -typedef bool (*seln_traverse_handler)(struct box *b, int offset, size_t length, void *handle); +typedef bool (*seln_traverse_handler)(struct box *b, int offset, + size_t length, void *handle); struct selection *selection_create(struct browser_window *bw); @@ -72,17 +73,23 @@ void selection_set_end(struct selection *s, struct box *box, int idx); struct box *selection_get_start(struct selection *s, int *pidx); struct box *selection_get_end(struct selection *s, int *pidx); -bool selection_click(struct selection *s, struct box *box, browser_mouse_state mouse, int dx, int dy); -void selection_track(struct selection *s, struct box *box, browser_mouse_state mouse, int dx, int dy); +bool selection_click(struct selection *s, struct box *box, browser_mouse_state mouse, + int dx, int dy); +void selection_track(struct selection *s, struct box *box, browser_mouse_state mouse, + int dx, int dy); void selection_drag_end(struct selection *s, struct box *box, browser_mouse_state mouse, int dx, int dy); -bool selection_traverse(struct selection *s, seln_traverse_handler handler, void *handle); +bool selection_traverse(struct selection *s, seln_traverse_handler handler, + void *handle); bool selection_highlighted(struct selection *s, struct box *box, unsigned *start_idx, unsigned *end_idx); bool selection_save_text(struct selection *s, const char *path); +void selection_update(struct selection *s, size_t byte_offset, int change, + bool redraw); + #endif -- cgit v1.2.3