mirror of
https://github.com/netsurf-browser/netsurf
synced 2024-12-23 04:26:50 +03:00
Treeview: Split out search cancel functionality.
This commit is contained in:
parent
d3493b138f
commit
798bfbf80f
@ -835,6 +835,37 @@ static nserror treeview__search(
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Cancel a treeview search, optionally droping focus from search widget.
|
||||
*
|
||||
* \param[in] tree Treeview to cancel search in.
|
||||
* \param[in] drop_focus Iff true, drop input focus from search widget.
|
||||
*/
|
||||
static void treeview__search_cancel(treeview *tree, bool drop_focus)
|
||||
{
|
||||
struct rect r = {
|
||||
.x0 = tree_g.window_padding + tree_g.icon_size,
|
||||
.x1 = 600,
|
||||
.y0 = 0,
|
||||
.y1 = tree_g.line_height,
|
||||
};
|
||||
|
||||
if (tree->search.active == false) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (drop_focus) {
|
||||
tree->search.active = false;
|
||||
textarea_set_caret(tree->search.textarea, -1);
|
||||
} else {
|
||||
textarea_set_caret(tree->search.textarea, 0);
|
||||
}
|
||||
|
||||
textarea_set_text(tree->search.textarea, "");
|
||||
treeview__cw_invalidate_area(tree, &r);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Callback for textarea_create, in desktop/treeview.h
|
||||
*
|
||||
@ -3850,13 +3881,7 @@ bool treeview_keypress(treeview *tree, uint32_t key)
|
||||
} else if (tree->search.active == true) {
|
||||
switch (key) {
|
||||
case NS_KEY_ESCAPE:
|
||||
textarea_set_text(tree->search.textarea, "");
|
||||
textarea_set_caret(tree->search.textarea, 0);
|
||||
r.x0 = tree_g.window_padding + tree_g.icon_size;
|
||||
r.x1 = 600;
|
||||
r.y0 = 0;
|
||||
r.y1 = tree_g.line_height;
|
||||
treeview__cw_invalidate_area(tree, &r);
|
||||
treeview__search_cancel(tree, false);
|
||||
return true;
|
||||
case NS_KEY_NL:
|
||||
case NS_KEY_CR:
|
||||
|
Loading…
Reference in New Issue
Block a user