Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@
"modify_deck": true,
"modify_field": true,
"modify_flag": true,
"modify_flag__show_explanations": true,
"modify_is": true,
"modify_is__show_explanations": true,
"modify_note": true,
Expand Down
5 changes: 5 additions & 0 deletions src/config.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,11 @@
"default": true,
"description": ""
},
"modify_flag__show_explanations": {
"type": "boolean",
"default": true,
"description": ""
},
"modify_is": {
"type": "boolean",
"default": true,
Expand Down
4 changes: 4 additions & 0 deletions src/config_update.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@ def get_default_conf_for_this_addon(addon_folder_name):
"modify_deck": ["open filter dialog after typing these search operators", "modify_deck"],
"modify_field": ["open filter dialog after typing these search operators", "modify_field"],
"modify_flag": ["open filter dialog after typing these search operators", "modify_flag"],
"modify_flag__show_explanations": [
"open filter dialog after typing these search operators",
"modify_flag__show_explanations",
],
"modify_is": ["open filter dialog after typing these search operators", "modify_is"],
"modify_is__show_explanations": [
"open filter dialog after typing these search operators",
Expand Down
28 changes: 28 additions & 0 deletions src/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,34 @@ def is_values_with_explanations():
"is:learn -is:review (cards that are in learning for the first time)": "is:learn -is:review",
}

def flag_values():
return [
"flag:1",
"flag:2",
"flag:3",
"flag:4",
"flag:5",
"flag:6",
"flag:7",
"flag:0",
"-flag:0",
"-flag:1",
]


def flag_values_with_explanations():
return {
"red flag": "flag:1",
"orange flag": "flag:2",
"green flag": "flag:3",
"blue flag": "flag:4",
"pink flag": "flag:5",
"turquoise flag": "flag:6",
"purple flag": "flag:7",
"no flags": "flag:0",
"any flag": "-flag:0",
"no red flags": "-flag:1",
}

def props():
all_version_texts = {
Expand Down
26 changes: 14 additions & 12 deletions src/onTextChange.py
Original file line number Diff line number Diff line change
Expand Up @@ -637,20 +637,13 @@ def onSearchEditTextChange(
if matches_search_operator(before, "flag:") and (
gc(["open filter dialog after typing these search operators", "modify_flag"]) or from_button
):
expl = gc(["open filter dialog after typing these search operators", "modify_flag__show_explanations"])
prefixed_with_minus = True if minus_precedes_search_operator(before, "flag:") else False
vals = {
"remove_from_end_of_before": -1 if prefixed_with_minus else 0,
"remove_from_end_of_before": (0 if expl else -5) - (1 if prefixed_with_minus else 0),
"insert_space_at_pos_in_before": -5,
"dict_for_dialog": "flags",
"values_for_filter_dialog": {
"red": "1",
"orange": "2",
"green": "3",
"blue": "4",
"pink": "5",
"turquoise": "6",
"purple": "7",
},
"dict_for_dialog": "flags_with_explanations" if expl else False,
"values_for_filter_dialog": flag_values_with_explanations() if expl else flag_values(),
"surround_with_quotes": False,
"infotext": False,
"windowtitle": "Anki: Search by Flag",
Expand Down Expand Up @@ -893,7 +886,16 @@ def fieldnames_modelname_dict():
) # triggering a search makes no sense here: the user needs to fill in the search term for prop:

############ generate sel_list
if vals["dict_for_dialog"] == "flags":
if vals["dict_for_dialog"] == "flags_with_explanations":
already_in_line = befmod[:-5] # substract flag:
new_text = already_in_line + ("-" if is_exclusion else "") + d.sel_value_from_dict + after
new_pos = len(already_in_line + ("-" if is_exclusion else "") + d.sel_value_from_dict)
return (
new_text,
new_pos,
False,
) # triggering a search makes no sense here: the user needs to fill in the search term for is:
elif vals["dict_for_dialog"] == "flags":
sel_list = [d.sel_value_from_dict]

if just_returned_input_line_content:
Expand Down