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