Fix autocompletion crash

See #166
This commit is contained in:
Daniel García Moreno 2018-04-07 14:39:50 +02:00
parent dd6a28b2f4
commit 7258f0b354
3 changed files with 11 additions and 4 deletions

3
Cargo.lock generated
View file

@ -330,7 +330,7 @@ dependencies = [
[[package]]
name = "fractal-gtk"
version = "0.1.22"
version = "0.1.23"
dependencies = [
"cairo-rs 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)",
"chrono 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
@ -350,6 +350,7 @@ dependencies = [
"serde 1.0.33 (registry+https://github.com/rust-lang/crates.io-index)",
"serde_derive 1.0.33 (registry+https://github.com/rust-lang/crates.io-index)",
"serde_json 1.0.13 (registry+https://github.com/rust-lang/crates.io-index)",
"unicode-segmentation 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
"url 1.7.0 (registry+https://github.com/rust-lang/crates.io-index)",
]

View file

@ -21,6 +21,7 @@ serde_json = "1.0.13"
url = "1.7.0"
rand = "0.4.2"
html2pango = { git = "https://gitlab.gnome.org/World/html2pango" }
unicode-segmentation = "1.2.0"
[dependencies.cairo-rs]
features = ["png"]

View file

@ -6,6 +6,9 @@ extern crate chrono;
extern crate gdk;
extern crate notify_rust;
extern crate rand;
extern crate unicode_segmentation;
use self::unicode_segmentation::UnicodeSegmentation;
use self::notify_rust::Notification;
@ -3451,7 +3454,7 @@ impl App {
return Inhibit(false);
}
}
/* allow popover opening with tab
/* allow popover opening with tab
* don't update popover when the input didn't change */
if !is_tab {
if let Some(ref text) = text {
@ -3469,9 +3472,11 @@ impl App {
op.lock().unwrap().popover_search = text.clone();
let pos = e.get_position();
if let Some(text) = text.clone() {
let (first, _) = text.split_at(pos as usize);
let graphs = UnicodeSegmentation::graphemes(text.as_str(), true).collect::<Vec<&str>>();
let (p1, _) = graphs.split_at(pos as usize);
let first = p1.join("");
if op.lock().unwrap().popover_position.is_none() {
if !is_tab {
if !is_tab {
if let Some(at_pos) = first.rfind("@") {
op.lock().unwrap().popover_position = Some(at_pos as i32);
}