summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorVika <vika@fireburn.ru>2025-03-11 14:14:06 +0300
committerVika <vika@fireburn.ru>2025-04-09 20:20:19 +0300
commit936ed2d5d00199c545a8cdac763909cc63be096b (patch)
treec171aafafe26fc648d64ea03481bfd3994bb4eb5 /src
parent2224f5557a3f2d522a82de27cee73234fa856298 (diff)
downloadbowl-936ed2d5d00199c545a8cdac763909cc63be096b.tar.zst
libspelling support
While libspelling is rather primitive (i.e. doesn't support mixing languages),
it's better than nothing to detect simple spelling mistakes. Let's use it.
Diffstat (limited to 'src')
-rw-r--r--src/components/post_editor.rs24
-rw-r--r--src/main.rs3
2 files changed, 23 insertions, 4 deletions
diff --git a/src/components/post_editor.rs b/src/components/post_editor.rs
index 863e515..d08685a 100644
--- a/src/components/post_editor.rs
+++ b/src/components/post_editor.rs
@@ -88,10 +88,12 @@ impl Post {
 pub(crate) struct PostEditor<E> {
     #[no_eq] smart_summary_busy_guard: Option<gtk::gio::ApplicationBusyGuard>,
     sending: bool,
+    #[do_not_track] #[allow(dead_code)] spell_checker: spelling::Checker,
+    #[do_not_track] spelling_adapter: spelling::TextBufferAdapter,
 
     #[do_not_track] name_buffer: gtk::EntryBuffer,
     #[do_not_track] summary_buffer: gtk::EntryBuffer,
-    #[do_not_track] content_buffer: gtk::TextBuffer,
+    #[do_not_track] content_buffer: sourceview5::Buffer,
 
     #[do_not_track] pending_tag_buffer: gtk::EntryBuffer,
     #[do_not_track] tags: relm4::factory::FactoryVecDeque<TagPill>,
@@ -241,6 +243,9 @@ impl<E: std::error::Error + std::fmt::Debug + Send + 'static> Component for Post
                             #[name = "content_textarea"]
                             gtk::TextView {
                                 set_buffer: Some(&model.content_buffer),
+                                set_extra_menu: Some(&model.spelling_adapter.menu_model()),
+                                insert_action_group: ("spelling", Some(&model.spelling_adapter)),
+
                                 set_hexpand: true,
                                 #[iterate]
                                 add_css_class: &["frame", "view"],
@@ -340,15 +345,25 @@ impl<E: std::error::Error + std::fmt::Debug + Send + 'static> Component for Post
         #[cfg(feature = "smart-summary")]
         let (http, init) = init;
 
+        let spell_checker = spelling::Checker::default();
+        let content_buffer = Default::default();
+
         let mut model = Self {
             smart_summary_busy_guard: None,
             sending: false,
 
+            spelling_adapter: spelling::TextBufferAdapter::new(
+                &content_buffer,
+                &spell_checker
+            ),
+            spell_checker,
+
             name_buffer: gtk::EntryBuffer::default(),
             summary_buffer: gtk::EntryBuffer::default(),
-            content_buffer: gtk::TextBuffer::default(),
-            pending_tag_buffer: gtk::EntryBuffer::default(),
+            content_buffer,
 
+
+            pending_tag_buffer: gtk::EntryBuffer::default(),
             tags: FactoryVecDeque::builder()
                 .launch({
                     let listbox = gtk::Box::default();
@@ -383,10 +398,11 @@ impl<E: std::error::Error + std::fmt::Debug + Send + 'static> Component for Post
         let visibility_model = adw::EnumListModel::new(Visibility::static_type());
 
         let widgets = view_output!();
-
         #[cfg(feature = "smart-summary")]
         widgets.summary_field.append(model.smart_summary.widget());
 
+        model.spelling_adapter.set_enabled(true);
+
         widgets.visibility_selector.set_expression(Some(
             gtk::ClosureExpression::new::<String>(
                 [] as [gtk::Expression; 0],
diff --git a/src/main.rs b/src/main.rs
index 9f531ea..989516a 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -16,6 +16,9 @@ fn main() {
 
     relm4_icons::initialize_icons(bowl::icons::GRESOURCE_BYTES, bowl::icons::RESOURCE_PREFIX);
 
+    sourceview5::init();
+    spelling::init();
+
     let app = relm4::RelmApp::new(bowl::APPLICATION_ID);
     relm4::set_global_css("/* CSS for Bowl */
 .tag-pill button {