mirror of
https://github.com/ankitects/anki.git
synced 2025-09-18 14:02:21 -04:00
bikeshedding: amount -> match_limit
+ convert from u32 in backend method
This commit is contained in:
parent
e85c93f3e7
commit
c9d3e5462e
4 changed files with 5 additions and 6 deletions
|
@ -63,7 +63,7 @@ message FindAndReplaceTagRequest {
|
|||
message CompleteTagRequest {
|
||||
// a partial tag, optionally delimited with ::
|
||||
string input = 1;
|
||||
uint32 amount = 2;
|
||||
uint32 match_limit = 2;
|
||||
}
|
||||
|
||||
message CompleteTagResponse {
|
||||
|
|
|
@ -91,7 +91,7 @@ impl TagsService for Backend {
|
|||
|
||||
fn complete_tag(&self, input: pb::CompleteTagRequest) -> Result<pb::CompleteTagResponse> {
|
||||
self.with_col(|col| {
|
||||
let tags = col.complete_tag(&input.input, input.amount)?;
|
||||
let tags = col.complete_tag(&input.input, input.match_limit as usize)?;
|
||||
Ok(pb::CompleteTagResponse { tags })
|
||||
})
|
||||
}
|
||||
|
|
|
@ -2,19 +2,18 @@
|
|||
// License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||
|
||||
use regex::Regex;
|
||||
use std::convert::TryInto;
|
||||
|
||||
use crate::prelude::*;
|
||||
|
||||
impl Collection {
|
||||
pub fn complete_tag(&self, input: &str, amount: u32) -> Result<Vec<String>> {
|
||||
pub fn complete_tag(&self, input: &str, limit: usize) -> Result<Vec<String>> {
|
||||
let filters: Vec<_> = input
|
||||
.split("::")
|
||||
.map(component_to_regex)
|
||||
.collect::<Result<_, _>>()?;
|
||||
let mut tags = vec![];
|
||||
self.storage.get_tags_by_predicate(|tag| {
|
||||
if tags.len() <= amount.try_into().unwrap() && filters_match(&filters, tag) {
|
||||
if tags.len() <= limit && filters_match(&filters, tag) {
|
||||
tags.push(tag.to_string());
|
||||
}
|
||||
// we only need the tag name
|
||||
|
|
|
@ -58,7 +58,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
|||
const data = await postRequest(
|
||||
"/_anki/completeTag",
|
||||
Tags.CompleteTagRequest.encode(
|
||||
Tags.CompleteTagRequest.create({ input, amount: 500 })
|
||||
Tags.CompleteTagRequest.create({ input, matchLimit: 500 })
|
||||
).finish()
|
||||
);
|
||||
const response = Tags.CompleteTagResponse.decode(data);
|
||||
|
|
Loading…
Reference in a new issue