[project @ 2006-02-06 00:07:18 by adrianl]

Drag-saving of text without pressing Ctrl

svn path=/import/netsurf/; revision=2058
This commit is contained in:
Adrian Lees 2006-02-06 00:07:18 +00:00
parent 9a35230e88
commit c176e276e2
2 changed files with 38 additions and 6 deletions

View File

@ -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);
}
}

View File

@ -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