Commit b995906c79

b995906c7937fdedc7e6fb3601851ca85555f89c

parent: e5b284ed19

Unregistered key

Ethan Reynolds <1653607+reynoldsme@users.noreply.github.com> · 2024-04-12 03:50 UTC
committer: <noreply@github.com>

Add `external_edit_file_suffix` to config (#253)

Layout: unified · split

config.example.toml +1
@@ -6,6 +6,7 @@ url = "https://matrix.org"
6 6
7[settings] 7[settings]
8default_room = "#iamb-users:0x.badd.cafe" 8default_room = "#iamb-users:0x.badd.cafe"
9external_edit_file_suffix = ".md"
9log_level = "warn" 10log_level = "warn"
10message_shortcode_display = false 11message_shortcode_display = false
11open_command = ["my-open", "--file"] 12open_command = ["my-open", "--file"]
docs/iamb.5 +3
@@ -125,6 +125,9 @@ key and can be overridden as described in
125.Sx PROFILES . 125.Sx PROFILES .
126.Bl -tag -width Ds 126.Bl -tag -width Ds
127 127
128.It Sy external_edit_file_suffix
129Suffix to append to temporary file names when using the :editor command. Defaults to .md.
130
128.It Sy default_room 131.It Sy default_room
129The room to show by default instead of the 132The room to show by default instead of the
130.Sy :welcome 133.Sy :welcome
src/config.rs +8
@@ -507,6 +507,7 @@ pub struct TunableValues {
507 pub notifications: Notifications, 507 pub notifications: Notifications,
508 pub image_preview: Option<ImagePreviewValues>, 508 pub image_preview: Option<ImagePreviewValues>,
509 pub user_gutter_width: usize, 509 pub user_gutter_width: usize,
510 pub external_edit_file_suffix: String,
510} 511}
511 512
512#[derive(Clone, Default, Deserialize)] 513#[derive(Clone, Default, Deserialize)]
@@ -530,6 +531,7 @@ pub struct Tunables {
530 pub notifications: Option<Notifications>, 531 pub notifications: Option<Notifications>,
531 pub image_preview: Option<ImagePreview>, 532 pub image_preview: Option<ImagePreview>,
532 pub user_gutter_width: Option<usize>, 533 pub user_gutter_width: Option<usize>,
534 pub external_edit_file_suffix: Option<String>,
533} 535}
534 536
535impl Tunables { 537impl Tunables {
@@ -557,6 +559,9 @@ impl Tunables {
557 notifications: self.notifications.or(other.notifications), 559 notifications: self.notifications.or(other.notifications),
558 image_preview: self.image_preview.or(other.image_preview), 560 image_preview: self.image_preview.or(other.image_preview),
559 user_gutter_width: self.user_gutter_width.or(other.user_gutter_width), 561 user_gutter_width: self.user_gutter_width.or(other.user_gutter_width),
562 external_edit_file_suffix: self
563 .external_edit_file_suffix
564 .or(other.external_edit_file_suffix),
560 } 565 }
561 } 566 }
562 567
@@ -580,6 +585,9 @@ impl Tunables {
580 notifications: self.notifications.unwrap_or_default(), 585 notifications: self.notifications.unwrap_or_default(),
581 image_preview: self.image_preview.map(ImagePreview::values), 586 image_preview: self.image_preview.map(ImagePreview::values),
582 user_gutter_width: self.user_gutter_width.unwrap_or(30), 587 user_gutter_width: self.user_gutter_width.unwrap_or(30),
588 external_edit_file_suffix: self
589 .external_edit_file_suffix
590 .unwrap_or_else(|| ".md".to_string()),
583 } 591 }
584 } 592 }
585} 593}
src/tests.rs +1
@@ -186,6 +186,7 @@ pub fn mock_tunables() -> TunableValues {
186 .into_iter() 186 .into_iter()
187 .collect::<HashMap<_, _>>(), 187 .collect::<HashMap<_, _>>(),
188 open_command: None, 188 open_command: None,
189 external_edit_file_suffix: String::from(".md"),
189 username_display: UserDisplayStyle::Username, 190 username_display: UserDisplayStyle::Username,
190 message_user_color: false, 191 message_user_color: false,
191 notifications: Notifications { 192 notifications: Notifications {
src/windows/room/chat.rs +5 −2
@@ -5,7 +5,8 @@ use std::fs;
5use std::ops::Deref; 5use std::ops::Deref;
6use std::path::{Path, PathBuf}; 6use std::path::{Path, PathBuf};
7 7
8use edit::edit as external_edit; 8use edit::edit_with_builder as external_edit;
9use edit::Builder;
9use modalkit::editing::store::RegisterError; 10use modalkit::editing::store::RegisterError;
10use std::process::Command; 11use std::process::Command;
11use tokio; 12use tokio;
@@ -481,7 +482,9 @@ impl ChatState {
481 let msg = self.tbox.get(); 482 let msg = self.tbox.get();
482 483
483 let msg = if let SendAction::SubmitFromEditor = act { 484 let msg = if let SendAction::SubmitFromEditor = act {
484 external_edit(msg.trim_end().to_string())? 485 let suffix =
486 store.application.settings.tunables.external_edit_file_suffix.as_str();
487 external_edit(msg.trim_end().to_string(), Builder::new().suffix(suffix))?
485 } else if msg.is_blank() { 488 } else if msg.is_blank() {
486 return Ok(None); 489 return Ok(None);
487 } else { 490 } else {