mirror of
https://github.com/ankitects/anki.git
synced 2025-09-18 14:02:21 -04:00
Cap tag suggestions at 500
This commit is contained in:
parent
1fd7fe4391
commit
e85c93f3e7
4 changed files with 12 additions and 8 deletions
|
@ -63,6 +63,7 @@ message FindAndReplaceTagRequest {
|
||||||
message CompleteTagRequest {
|
message CompleteTagRequest {
|
||||||
// a partial tag, optionally delimited with ::
|
// a partial tag, optionally delimited with ::
|
||||||
string input = 1;
|
string input = 1;
|
||||||
|
uint32 amount = 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
message CompleteTagResponse {
|
message CompleteTagResponse {
|
||||||
|
|
|
@ -91,7 +91,7 @@ impl TagsService for Backend {
|
||||||
|
|
||||||
fn complete_tag(&self, input: pb::CompleteTagRequest) -> Result<pb::CompleteTagResponse> {
|
fn complete_tag(&self, input: pb::CompleteTagRequest) -> Result<pb::CompleteTagResponse> {
|
||||||
self.with_col(|col| {
|
self.with_col(|col| {
|
||||||
let tags = col.complete_tag(&input.input)?;
|
let tags = col.complete_tag(&input.input, input.amount)?;
|
||||||
Ok(pb::CompleteTagResponse { tags })
|
Ok(pb::CompleteTagResponse { tags })
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,18 +2,19 @@
|
||||||
// License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
// License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||||
|
|
||||||
use regex::Regex;
|
use regex::Regex;
|
||||||
|
use std::convert::TryInto;
|
||||||
|
|
||||||
use crate::prelude::*;
|
use crate::prelude::*;
|
||||||
|
|
||||||
impl Collection {
|
impl Collection {
|
||||||
pub fn complete_tag(&self, input: &str) -> Result<Vec<String>> {
|
pub fn complete_tag(&self, input: &str, amount: u32) -> Result<Vec<String>> {
|
||||||
let filters: Vec<_> = input
|
let filters: Vec<_> = input
|
||||||
.split("::")
|
.split("::")
|
||||||
.map(component_to_regex)
|
.map(component_to_regex)
|
||||||
.collect::<Result<_, _>>()?;
|
.collect::<Result<_, _>>()?;
|
||||||
let mut tags = vec![];
|
let mut tags = vec![];
|
||||||
self.storage.get_tags_by_predicate(|tag| {
|
self.storage.get_tags_by_predicate(|tag| {
|
||||||
if filters_match(&filters, tag) {
|
if tags.len() <= amount.try_into().unwrap() && filters_match(&filters, tag) {
|
||||||
tags.push(tag.to_string());
|
tags.push(tag.to_string());
|
||||||
}
|
}
|
||||||
// we only need the tag name
|
// 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(
|
const data = await postRequest(
|
||||||
"/_anki/completeTag",
|
"/_anki/completeTag",
|
||||||
Tags.CompleteTagRequest.encode(
|
Tags.CompleteTagRequest.encode(
|
||||||
Tags.CompleteTagRequest.create({ input: replaceWithColons(input) })
|
Tags.CompleteTagRequest.create({ input, amount: 500 })
|
||||||
).finish()
|
).finish()
|
||||||
);
|
);
|
||||||
const response = Tags.CompleteTagResponse.decode(data);
|
const response = Tags.CompleteTagResponse.decode(data);
|
||||||
|
@ -72,10 +72,12 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||||
autocompleteDisabled = activeName.length === 0;
|
autocompleteDisabled = activeName.length === 0;
|
||||||
suggestionsPromise = autocompleteDisabled
|
suggestionsPromise = autocompleteDisabled
|
||||||
? noSuggestions
|
? noSuggestions
|
||||||
: fetchSuggestions(activeTag.name).then((names: string[]): string[] => {
|
: fetchSuggestions(replaceWithColons(activeTag.name)).then(
|
||||||
autocompleteDisabled = names.length === 0;
|
(names: string[]): string[] => {
|
||||||
return names.map(replaceWithUnicodeSeparator);
|
autocompleteDisabled = names.length === 0;
|
||||||
});
|
return names.map(replaceWithUnicodeSeparator);
|
||||||
|
}
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function onAutocomplete(selected: string): void {
|
function onAutocomplete(selected: string): void {
|
||||||
|
|
Loading…
Reference in a new issue