web search done right
Fix the byte/char index mixups identified in issue 77 (#78)
Mikkel Denkerd5624ee1b4d2
diff --git a/core/src/api/autosuggest.rs b/core/src/api/autosuggest.rsindex 01cfc97f..e6d4b2a4 100644--- a/core/src/api/autosuggest.rs+++ b/core/src/api/autosuggest.rs@@ -29,7 +29,7 @@ fn highlight(query: &str, suggestion: &str) -> String {.chars().zip(query.chars()).position(|(suggestion_char, query_char)| suggestion_char != query_char)- .unwrap_or(query.len());+ .unwrap_or(query.chars().count());let mut new_suggestion: String = suggestion.chars().take(idx).collect();new_suggestion += HIGHLIGHTED_PREFIX;diff --git a/core/src/search_prettifier/entity.rs b/core/src/search_prettifier/entity.rsindex 9f426d4d..424a0f73 100644--- a/core/src/search_prettifier/entity.rs+++ b/core/src/search_prettifier/entity.rs@@ -49,10 +49,8 @@ fn prepare_info(info: BTreeMap<String, Span>, searcher: &LocalSearcher) -> Vec<(.map(|(key, value)| {let mut value = entity_link_to_html(value, 150).replace('*', "•");- if value.starts_with('•') || value.starts_with("\n•") {- if let Some(first_bullet) = value.find('•') {- value = value.chars().skip(first_bullet + 1).collect();- }+ if let Some((_, rest)) = value.split_once('•') {+ value = rest.to_string();}let value = maybe_prettify_entity_date(value);diff --git a/core/src/search_prettifier/mod.rs b/core/src/search_prettifier/mod.rsindex 026630d9..f1785f87 100644--- a/core/src/search_prettifier/mod.rs+++ b/core/src/search_prettifier/mod.rs@@ -103,9 +103,7 @@ fn prettify_url(url: &Url) -> String {pretty_url = stripped.to_string();}- if pretty_url.ends_with('/') {- pretty_url = pretty_url.chars().take(pretty_url.len() - 1).collect();- }+ pretty_url = pretty_url.trim_end_matches('/').to_string();pretty_url = pretty_url.replace('/', " › ");pretty_url = scheme + "://" + pretty_url.as_str();diff --git a/core/src/spell/spell_checker.rs b/core/src/spell/spell_checker.rsindex 9fb523f2..8f86b646 100644--- a/core/src/spell/spell_checker.rs+++ b/core/src/spell/spell_checker.rs@@ -34,10 +34,8 @@ fn deletes_rec(delete_words: &mut HashSet<String>,) {let edit_distance = edit_distance + 1;- let word_len = word.chars().count();-- if word_len > 1 {- for i in 0..word_len {+ if !word.is_empty() {+ for (i, _) in word.char_indices() {let delete = word.char_indices().filter(|(j, _)| *j != i)