From 7258f0b354460a1daff7de1a2fc6822634261c54 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Garc=C3=ADa=20Moreno?= Date: Sat, 7 Apr 2018 14:39:50 +0200 Subject: [PATCH] Fix autocompletion crash See #166 --- Cargo.lock | 3 ++- fractal-gtk/Cargo.toml | 1 + fractal-gtk/src/app.rs | 11 ++++++++--- 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 51557f7c..a05fad87 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -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)", ] diff --git a/fractal-gtk/Cargo.toml b/fractal-gtk/Cargo.toml index bd1a9814..ab577fcc 100644 --- a/fractal-gtk/Cargo.toml +++ b/fractal-gtk/Cargo.toml @@ -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"] diff --git a/fractal-gtk/src/app.rs b/fractal-gtk/src/app.rs index cd8c4bc4..8c6622e0 100644 --- a/fractal-gtk/src/app.rs +++ b/fractal-gtk/src/app.rs @@ -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::>(); + 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); }