mirror of
https://github.com/ankitects/anki.git
synced 2025-09-18 22:12:21 -04:00
Introduce "resched:n" instead of 0 and a flag for "rated"
This commit is contained in:
parent
7e58660aab
commit
cbfe14ef4f
2 changed files with 18 additions and 11 deletions
|
@ -122,7 +122,7 @@ pub enum TemplateKind<'a> {
|
|||
pub(super) enum EaseKind {
|
||||
Rated(u8),
|
||||
Reviewed,
|
||||
All,
|
||||
Manually,
|
||||
}
|
||||
|
||||
impl std::fmt::Display for EaseKind {
|
||||
|
@ -132,7 +132,7 @@ impl std::fmt::Display for EaseKind {
|
|||
match self {
|
||||
Rated(u) => write!(f, " and ease = {}", u),
|
||||
Reviewed => write!(f, " and ease in (1, 2, 3, 4)"),
|
||||
All => write!(f, ""),
|
||||
Manually => write!(f, " and ease = 0"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -305,6 +305,7 @@ fn search_node_for_text_with_argument<'a>(
|
|||
"is" => parse_state(val)?,
|
||||
"flag" => parse_flag(val)?,
|
||||
"rated" => parse_rated(val)?,
|
||||
"resched" => parse_resched(val)?,
|
||||
"dupe" => parse_dupes(val)?,
|
||||
"prop" => parse_prop(val)?,
|
||||
"re" => SearchNode::Regex(unescape_quotes(val)),
|
||||
|
@ -378,14 +379,11 @@ fn parse_rated(val: &str) -> ParseResult<SearchNode<'static>> {
|
|||
|
||||
let ease = match it.next() {
|
||||
Some(v) => {
|
||||
let c: char = v.parse().unwrap();
|
||||
match c {
|
||||
'0' | '1' | '2' | '3' | '4' => {
|
||||
let n = c.to_digit(10).unwrap() as u8;
|
||||
EaseKind::Rated(n)
|
||||
}
|
||||
'a' => EaseKind::All,
|
||||
_ => return Err(ParseError {}),
|
||||
let u: u8 = v.parse().unwrap();
|
||||
if (1..5).contains(&u) {
|
||||
EaseKind::Rated(u)
|
||||
} else {
|
||||
return Err(ParseError {})
|
||||
}
|
||||
}
|
||||
None => EaseKind::Reviewed,
|
||||
|
@ -394,6 +392,15 @@ fn parse_rated(val: &str) -> ParseResult<SearchNode<'static>> {
|
|||
Ok(SearchNode::Rated { days, ease })
|
||||
}
|
||||
|
||||
/// eg resched:3
|
||||
fn parse_resched(val: &str) -> ParseResult<SearchNode<'static>> {
|
||||
let mut it = val.splitn(1, ':');
|
||||
let days = it.next().unwrap().parse()?;
|
||||
let ease = EaseKind::Manually;
|
||||
|
||||
Ok(SearchNode::Rated { days, ease })
|
||||
}
|
||||
|
||||
/// eg dupes:1231,hello
|
||||
fn parse_dupes(val: &str) -> ParseResult<SearchNode> {
|
||||
let mut it = val.splitn(2, ',');
|
||||
|
|
|
@ -159,7 +159,7 @@ fn write_rated(days: &u32, ease: &EaseKind) -> String {
|
|||
match ease {
|
||||
Rated(n) => format!("\"rated:{}:{}\"", days, n),
|
||||
Reviewed => format!("\"rated:{}\"", days),
|
||||
All => format!("\"rated:{}:a\"", days),
|
||||
Manually => format!("\"resched:{}\"", days),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue