Make Browser root nodes use "_*" uniformly

This commit is contained in:
Henrik Giesel 2021-06-15 12:11:43 +02:00 committed by Damien Elmes
parent 51de0fdcd1
commit c5faf39d7c
3 changed files with 12 additions and 11 deletions

View file

@ -711,12 +711,12 @@ class SidebarTreeView(QTreeView):
collapse_key=Config.Bool.COLLAPSE_TAGS,
type=SidebarItemType.TAG_ROOT,
)
root.search_node = SearchNode(negated=SearchNode(tag="none"))
root.search_node = SearchNode(tag="_*")
root.add_simple(
name=tr.browsing_sidebar_untagged(),
icon=icon,
type=SidebarItemType.TAG_NONE,
search_node=SearchNode(tag="none"),
search_node=SearchNode(negated=SearchNode(tag="_*")),
)
render(root, tree.children)
@ -763,7 +763,7 @@ class SidebarTreeView(QTreeView):
collapse_key=Config.Bool.COLLAPSE_DECKS,
type=SidebarItemType.DECK_ROOT,
)
root.search_node = SearchNode(deck="*")
root.search_node = SearchNode(deck="_*")
current = root.add_simple(
name=tr.browsing_current_deck(),
icon=icon,
@ -786,6 +786,7 @@ class SidebarTreeView(QTreeView):
collapse_key=Config.Bool.COLLAPSE_NOTETYPES,
type=SidebarItemType.NOTETYPE_ROOT,
)
root.search_node = SearchNode(note="_*")
for nt in sorted(self.col.models.all(), key=lambda nt: nt["name"].lower()):
item = SidebarItem(

View file

@ -23,11 +23,7 @@ impl TryFrom<pb::SearchNode> for Node {
Ok(if let Some(filter) = msg.filter {
match filter {
Filter::Tag(s) => Node::Search(SearchNode::Tag(escape_anki_wildcards(&s))),
Filter::Deck(s) => Node::Search(SearchNode::Deck(if s == "*" {
s
} else {
escape_anki_wildcards(&s)
})),
Filter::Deck(s) => Node::Search(SearchNode::Deck(escape_anki_wildcards(&s))),
Filter::Note(s) => Node::Search(SearchNode::Notetype(escape_anki_wildcards(&s))),
Filter::Template(u) => {
Node::Search(SearchNode::CardTemplate(TemplateKind::Ordinal(u as u16)))

View file

@ -399,10 +399,14 @@ pub(crate) fn to_text(txt: &str) -> Cow<str> {
/// Escape Anki wildcards and the backslash for escaping them: \*_
pub(crate) fn escape_anki_wildcards(txt: &str) -> String {
lazy_static! {
static ref RE: Regex = Regex::new(r"[\\*_]").unwrap();
if txt == "_*" {
txt.to_string()
} else {
lazy_static! {
static ref RE: Regex = Regex::new(r"[\\*_]").unwrap();
}
RE.replace_all(&txt, r"\$0").into()
}
RE.replace_all(&txt, r"\$0").into()
}
/// Compare text with a possible glob, folding case.