mirror of
https://github.com/netsurf-browser/netsurf
synced 2024-12-23 12:36:51 +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
|
* 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) {
|
} else if (tree->search.active == true) {
|
||||||
switch (key) {
|
switch (key) {
|
||||||
case NS_KEY_ESCAPE:
|
case NS_KEY_ESCAPE:
|
||||||
textarea_set_text(tree->search.textarea, "");
|
treeview__search_cancel(tree, false);
|
||||||
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);
|
|
||||||
return true;
|
return true;
|
||||||
case NS_KEY_NL:
|
case NS_KEY_NL:
|
||||||
case NS_KEY_CR:
|
case NS_KEY_CR:
|
||||||
|
Loading…
Reference in New Issue
Block a user