diff --git a/Cargo.toml b/Cargo.toml index 04a4ee05..3629097b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -48,6 +48,9 @@ version = "0.9.1" [dependencies.plurify] version = "0.1.1" +[dependencies.libspelling] +version = "0.3.0" + # development [patch.crates-io] # ggemini = { git = "https://github.com/YGGverse/ggemini.git" } diff --git a/README.md b/README.md index 8bdb0f9d..2cc5994d 100644 --- a/README.md +++ b/README.md @@ -132,13 +132,14 @@ GTK 4 / Libadwaita client written in Rust * Glib `2.80` * Gtk `4.14` * GtkSourceView `5.14` -* Libadwaita `1.5` (Ubuntu 24.04+) +* libadwaita `1.5` (Ubuntu 24.04+) +* libspelling `0.1` #### Debian ``` bash sudo apt install git curl build-essential\ - libgtk-4-dev libgtksourceview-5-dev libadwaita-1-dev\ + libgtk-4-dev libgtksourceview-5-dev libadwaita-1-dev libspelling-1-dev\ libsqlite3-dev libssl-dev ``` @@ -146,7 +147,7 @@ sudo apt install git curl build-essential\ ``` bash sudo dnf install git curl gcc\ - gtk4-devel gtksourceview5-devel libadwaita-devel\ + gtk4-devel gtksourceview5-devel libadwaita-devel libspelling-devel\ sqlite-devel openssl-devel ``` diff --git a/src/app/browser/window/tab/item/page/input/response/form/widget.rs b/src/app/browser/window/tab/item/page/input/response/form/widget.rs index 072d77f3..e5be15b6 100644 --- a/src/app/browser/window/tab/item/page/input/response/form/widget.rs +++ b/src/app/browser/window/tab/item/page/input/response/form/widget.rs @@ -1,9 +1,11 @@ use gtk::{ gio::SimpleAction, glib::GString, - prelude::{ActionExt, TextBufferExt, TextViewExt}, + prelude::{ActionExt, TextBufferExt, TextViewExt, WidgetExt}, TextView, WrapMode, }; +use libspelling::{Checker, TextBufferAdapter}; +use sourceview::Buffer; const MARGIN: i32 = 8; @@ -14,15 +16,27 @@ pub struct Widget { impl Widget { // Construct pub fn new(action_update: SimpleAction) -> Self { + // Init [SourceView](https://gitlab.gnome.org/GNOME/gtksourceview) type buffer + let buffer = Buffer::builder().build(); + + // Init [libspelling](https://gitlab.gnome.org/GNOME/libspelling) + let checker = Checker::default(); + let adapter = TextBufferAdapter::new(&buffer, &checker); + adapter.set_enabled(true); + // Init main widget let text_view = TextView::builder() .bottom_margin(MARGIN) + .buffer(&buffer) + .extra_menu(&adapter.menu_model()) .left_margin(MARGIN) .right_margin(MARGIN) .top_margin(MARGIN) .wrap_mode(WrapMode::Word) .build(); + text_view.insert_action_group("spelling", Some(&adapter)); + // Init events text_view.buffer().connect_changed(move |_| { action_update.activate(None);