[fractal/fractal-next] content: Enable syntax highlighting when markdown is enabled
- From: Julian Sparber <jsparber src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [fractal/fractal-next] content: Enable syntax highlighting when markdown is enabled
- Date: Tue, 18 May 2021 16:49:19 +0000 (UTC)
commit c614df37242990cc57ebe6c3ef9694516561e14e
Author: Kévin Commaille <zecakeh tedomum fr>
Date: Tue May 18 18:03:03 2021 +0200
content: Enable syntax highlighting when markdown is enabled
src/session/content/content.rs | 25 +++++++++++++++++++------
1 file changed, 19 insertions(+), 6 deletions(-)
---
diff --git a/src/session/content/content.rs b/src/session/content/content.rs
index 0a60d149..5e1ec760 100644
--- a/src/session/content/content.rs
+++ b/src/session/content/content.rs
@@ -4,6 +4,7 @@ use gtk::{
gdk, glib, glib::clone, glib::signal::Inhibit, prelude::*, subclass::prelude::*,
CompositeTemplate,
};
+use sourceview::prelude::*;
mod imp {
use super::*;
@@ -150,16 +151,28 @@ mod imp {
Inhibit(false)
}
}));
- self.message_entry
+
+ let buffer = self
+ .message_entry
.buffer()
- .connect_text_notify(clone!(@weak obj => move |buffer| {
- let (start_iter, end_iter) = buffer.bounds();
- obj.action_set_enabled("content.send-text-message", start_iter != end_iter);
- }));
+ .downcast::<sourceview::Buffer>()
+ .unwrap();
+
+ buffer.connect_text_notify(clone!(@weak obj => move |buffer| {
+ let (start_iter, end_iter) = buffer.bounds();
+ obj.action_set_enabled("content.send-text-message", start_iter != end_iter);
+ }));
- let (start_iter, end_iter) = self.message_entry.buffer().bounds();
+ let (start_iter, end_iter) = buffer.bounds();
obj.action_set_enabled("content.send-text-message", start_iter != end_iter);
+ let md_lang =
+ sourceview::LanguageManager::default().and_then(|lm| lm.language("markdown"));
+ buffer.set_language(md_lang.as_ref());
+ obj.bind_property("markdown-enabled", &buffer, "highlight-syntax")
+ .flags(glib::BindingFlags::SYNC_CREATE)
+ .build();
+
let settings = Application::default().settings();
settings
.bind("markdown-enabled", obj, "markdown-enabled")
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]