Skip to content

Commit 609a7c2

Browse files
authored
Merge pull request #617 from multiplex55/codex/drop-note_external_editor-setting-and-update-commands
Drop note external editor setting
2 parents 9bd2aad + 82f69bf commit 609a7c2

9 files changed

Lines changed: 101 additions & 68 deletions

File tree

settings.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
"note_save_on_close": false,
2121
"note_always_overwrite": false,
2222
"note_images_as_links": false,
23-
"note_external_editor": "wezterm",
2423
"note_more_limit": 5,
2524
"enable_toasts": true,
2625
"toast_duration": 3.0,

src/gui/mod.rs

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@ pub use fav_dialog::FavDialog;
3636
pub use image_panel::ImagePanel;
3737
pub use macro_dialog::MacroDialog;
3838
pub use note_panel::{
39-
build_nvim_command, build_wezterm_command, extract_links, show_wiki_link, NotePanel,
39+
build_nvim_command, build_wezterm_command, extract_links, show_wiki_link, spawn_external,
40+
NotePanel,
4041
};
4142
pub use notes_dialog::NotesDialog;
4243
pub use screenshot_editor::ScreenshotEditor;
@@ -368,7 +369,6 @@ pub struct LauncherApp {
368369
pub note_save_on_close: bool,
369370
pub note_always_overwrite: bool,
370371
pub note_images_as_links: bool,
371-
pub note_external_editor: Option<String>,
372372
pub note_external_open: NoteExternalOpen,
373373
pub note_font_size: f32,
374374
pub note_more_limit: usize,
@@ -514,7 +514,6 @@ impl LauncherApp {
514514
note_always_overwrite: Option<bool>,
515515
note_images_as_links: Option<bool>,
516516
note_more_limit: Option<usize>,
517-
note_external_editor: Option<String>,
518517
) {
519518
self.plugin_dirs = plugin_dirs;
520519
self.index_paths = index_paths;
@@ -609,9 +608,6 @@ impl LauncherApp {
609608
if let Some(v) = note_more_limit {
610609
self.note_more_limit = v;
611610
}
612-
if note_external_editor.is_some() {
613-
self.note_external_editor = note_external_editor;
614-
}
615611
}
616612

617613
pub fn new(
@@ -872,7 +868,6 @@ impl LauncherApp {
872868
note_save_on_close: settings.note_save_on_close,
873869
note_always_overwrite: settings.note_always_overwrite,
874870
note_images_as_links: settings.note_images_as_links,
875-
note_external_editor: settings.note_external_editor.clone(),
876871
note_external_open,
877872
note_font_size: 16.0,
878873
note_more_limit: settings.note_more_limit,
@@ -2901,10 +2896,7 @@ impl eframe::App for LauncherApp {
29012896
if self.open_note_in_neovim(
29022897
&slug,
29032898
crate::plugins::note::load_notes,
2904-
|path| {
2905-
let (mut cmd, _cmd_str) = build_nvim_command(path);
2906-
cmd.spawn().map(|_| ())
2907-
},
2899+
|path| spawn_external(path, NoteExternalOpen::Wezterm),
29082900
) {
29092901
ui.close_menu();
29102902
}

src/gui/note_panel.rs

Lines changed: 25 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ use once_cell::sync::Lazy;
1616
use regex::Regex;
1717
use rfd::FileDialog;
1818
use std::collections::HashMap;
19-
use std::process::Command;
2019
#[cfg(windows)]
2120
use std::os::windows::process::CommandExt;
21+
use std::process::Command;
2222
use std::{
2323
env,
2424
path::{Path, PathBuf},
@@ -965,25 +965,33 @@ impl NotePanel {
965965

966966
fn open_external(&self, app: &mut LauncherApp, choice: NoteExternalOpen) {
967967
let path = self.note.path.clone();
968-
let result = match choice {
969-
NoteExternalOpen::Powershell => {
970-
let (mut cmd, _cmd_str) = build_nvim_command(&path);
971-
cmd.spawn()
972-
}
973-
NoteExternalOpen::Wezterm => {
974-
let editor = app.note_external_editor.as_deref().unwrap_or("nvim");
975-
let (mut cmd, _cmd_str) = build_wezterm_command(&path, editor);
976-
cmd.spawn()
977-
}
978-
NoteExternalOpen::Notepad => Command::new("notepad.exe").arg(&path).spawn(),
979-
NoteExternalOpen::Neither => return,
980-
};
981-
if let Err(e) = result {
968+
if let Err(e) = spawn_external(&path, choice) {
982969
app.set_error(format!("Failed to open note externally: {e}"));
983970
}
984971
}
985972
}
986973

974+
pub fn spawn_external(path: &Path, choice: NoteExternalOpen) -> std::io::Result<()> {
975+
match choice {
976+
NoteExternalOpen::Powershell => {
977+
let (mut cmd, _cmd_str) = build_nvim_command(path);
978+
cmd.spawn().map(|_| ())
979+
}
980+
NoteExternalOpen::Wezterm => {
981+
let (mut cmd, _cmd_str) = build_wezterm_command(path);
982+
match cmd.spawn() {
983+
Ok(_) => Ok(()),
984+
Err(_) => {
985+
let (mut cmd, _cmd_str) = build_nvim_command(path);
986+
cmd.spawn().map(|_| ())
987+
}
988+
}
989+
}
990+
NoteExternalOpen::Notepad => Command::new("notepad.exe").arg(path).spawn().map(|_| ()),
991+
NoteExternalOpen::Neither => Ok(()),
992+
}
993+
}
994+
987995
pub fn show_wiki_link(ui: &mut egui::Ui, app: &mut LauncherApp, l: &str) -> egui::Response {
988996
// Display wiki style links with brackets and allow clicking to
989997
// navigate to the referenced note. Missing targets are colored red.
@@ -1086,9 +1094,9 @@ pub fn build_nvim_command(note_path: &Path) -> (Command, String) {
10861094
(cmd, cmd_str)
10871095
}
10881096

1089-
pub fn build_wezterm_command(note_path: &Path, editor: &str) -> (Command, String) {
1097+
pub fn build_wezterm_command(note_path: &Path) -> (Command, String) {
10901098
let mut cmd = Command::new("wezterm");
1091-
cmd.arg("start").arg("--").arg(editor).arg(note_path);
1099+
cmd.arg("start").arg("--").arg("nvim").arg(note_path);
10921100
#[cfg(windows)]
10931101
{
10941102
cmd.creation_flags(0x08000000); // CREATE_NO_WINDOW

src/plugin_editor.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,6 @@ impl PluginEditor {
133133
Some(s.note_always_overwrite),
134134
Some(s.note_images_as_links),
135135
Some(s.note_more_limit),
136-
s.note_external_editor.clone(),
137136
);
138137
let dirs = s.plugin_dirs.clone().unwrap_or_default();
139138
let actions_arc = Arc::clone(&app.actions);

src/settings.rs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -84,10 +84,6 @@ pub struct Settings {
8484
/// textures directly in the preview.
8585
#[serde(default)]
8686
pub note_images_as_links: bool,
87-
/// External editor command used to open notes. If `None`, a platform
88-
/// specific fallback is used.
89-
#[serde(default)]
90-
pub note_external_editor: Option<String>,
9187
/// Number of tags or links shown before an expandable "... (more)" control
9288
/// appears in the note panel.
9389
#[serde(default = "default_note_more_limit")]
@@ -276,7 +272,6 @@ impl Default for Settings {
276272
note_save_on_close: default_note_save_on_close(),
277273
note_always_overwrite: false,
278274
note_images_as_links: false,
279-
note_external_editor: Some("wezterm".to_string()),
280275
note_more_limit: default_note_more_limit(),
281276
enable_toasts: true,
282277
toast_duration: default_toast_duration(),

src/settings_editor.rs

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ use crate::plugins::screenshot::ScreenshotPluginSettings;
55
use crate::settings::Settings;
66
use eframe::egui;
77
use egui_toast::{Toast, ToastKind, ToastOptions};
8-
use rfd::FileDialog;
98
use std::sync::Arc;
109

1110
#[derive(Default)]
@@ -34,7 +33,6 @@ pub struct SettingsEditor {
3433
note_always_overwrite: bool,
3534
note_images_as_links: bool,
3635
note_more_limit: usize,
37-
note_external_editor: String,
3836
query_scale: f32,
3937
list_scale: f32,
4038
history_limit: usize,
@@ -124,7 +122,6 @@ impl SettingsEditor {
124122
note_always_overwrite: settings.note_always_overwrite,
125123
note_images_as_links: settings.note_images_as_links,
126124
note_more_limit: settings.note_more_limit,
127-
note_external_editor: settings.note_external_editor.clone().unwrap_or_default(),
128125
query_scale: settings.query_scale.unwrap_or(1.0),
129126
list_scale: settings.list_scale.unwrap_or(1.0),
130127
history_limit: settings.history_limit,
@@ -239,11 +236,6 @@ impl SettingsEditor {
239236
note_always_overwrite: self.note_always_overwrite,
240237
note_images_as_links: self.note_images_as_links,
241238
note_more_limit: self.note_more_limit,
242-
note_external_editor: if self.note_external_editor.trim().is_empty() {
243-
None
244-
} else {
245-
Some(self.note_external_editor.clone())
246-
},
247239
query_scale: Some(self.query_scale),
248240
list_scale: Some(self.list_scale),
249241
history_limit: self.history_limit,
@@ -535,15 +527,6 @@ impl SettingsEditor {
535527
.clamp_range(1..=usize::MAX),
536528
);
537529
});
538-
ui.horizontal(|ui| {
539-
ui.label("External editor");
540-
ui.text_edit_singleline(&mut self.note_external_editor);
541-
if ui.button("Browse").clicked() {
542-
if let Some(file) = FileDialog::new().pick_file() {
543-
self.note_external_editor = file.display().to_string();
544-
}
545-
}
546-
});
547530
let mut cfg = self
548531
.plugin_settings
549532
.get("note")
@@ -676,7 +659,6 @@ impl SettingsEditor {
676659
Some(new_settings.note_always_overwrite),
677660
Some(new_settings.note_images_as_links),
678661
Some(new_settings.note_more_limit),
679-
new_settings.note_external_editor.clone(),
680662
);
681663
ctx.send_viewport_cmd(
682664
egui::ViewportCommand::WindowLevel(

tests/hide_after_run.rs

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,37 @@ fn run_action(action: &str) -> bool {
4747
}];
4848
let (mut app, flag) = new_app_with_settings(&ctx, actions, Settings::default());
4949
app.update_paths(
50-
None, None, None, None, None, None, None, None, None, None, None, None,
51-
None, Some(true), None, None, None, None, None, None, None, None, None,
52-
None, None, None, None, None, None, None, None, None,
50+
None,
51+
None,
52+
None,
53+
None,
54+
None,
55+
None,
56+
None,
57+
None,
58+
None,
59+
None,
60+
None,
61+
None,
62+
None,
63+
Some(true),
64+
None,
65+
None,
66+
None,
67+
None,
68+
None,
69+
None,
70+
None,
71+
None,
72+
None,
73+
None,
74+
None,
75+
None,
76+
None,
77+
None,
78+
None,
79+
None,
80+
None,
5381
);
5482
flag.store(true, Ordering::SeqCst);
5583
let a = app.results[0].clone();

tests/note_panel_shell.rs

Lines changed: 40 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#![cfg(windows)]
2-
use multi_launcher::gui::build_nvim_command;
2+
use multi_launcher::gui::{build_nvim_command, build_wezterm_command};
33
use once_cell::sync::Lazy;
44
use std::env;
55
use std::fs;
@@ -25,10 +25,7 @@ fn prefers_powershell7_then_powershell_then_cmd() {
2525
env::set_var("PATH", "");
2626
}
2727
let (cmd, _) = build_nvim_command(note);
28-
assert!(cmd
29-
.get_program()
30-
.to_string_lossy()
31-
.ends_with("pwsh.exe"));
28+
assert!(cmd.get_program().to_string_lossy().ends_with("pwsh.exe"));
3229
let args: Vec<_> = cmd
3330
.get_args()
3431
.map(|a| a.to_string_lossy().into_owned())
@@ -51,12 +48,11 @@ fn prefers_powershell7_then_powershell_then_cmd() {
5148
.ends_with("powershell.exe"));
5249

5350
// Fallback to cmd.exe
54-
unsafe { env::set_var("PATH", ""); }
51+
unsafe {
52+
env::set_var("PATH", "");
53+
}
5554
let (cmd, _) = build_nvim_command(note);
56-
assert!(cmd
57-
.get_program()
58-
.to_string_lossy()
59-
.ends_with("cmd.exe"));
55+
assert!(cmd.get_program().to_string_lossy().ends_with("cmd.exe"));
6056
let args: Vec<_> = cmd
6157
.get_args()
6258
.map(|a| a.to_string_lossy().into_owned())
@@ -74,3 +70,37 @@ fn prefers_powershell7_then_powershell_then_cmd() {
7470
}
7571
}
7672
}
73+
74+
#[test]
75+
fn wezterm_fallbacks_to_powershell_when_missing() {
76+
let _lock = TEST_MUTEX.lock().unwrap();
77+
let note = Path::new("note.txt");
78+
let orig_ps7 = env::var_os("ML_PWSH7_PATH");
79+
let orig_path = env::var_os("PATH");
80+
81+
let dir = tempdir().unwrap();
82+
let pwsh = dir.path().join("pwsh.exe");
83+
fs::write(&pwsh, "").unwrap();
84+
unsafe {
85+
env::set_var("ML_PWSH7_PATH", &pwsh);
86+
env::set_var("PATH", "");
87+
}
88+
89+
let (mut cmd, _) = build_wezterm_command(note);
90+
let res = cmd.spawn();
91+
assert!(res.is_err());
92+
93+
let (cmd, _) = build_nvim_command(note);
94+
assert!(cmd.get_program().to_string_lossy().ends_with("pwsh.exe"));
95+
96+
unsafe {
97+
match orig_ps7 {
98+
Some(v) => env::set_var("ML_PWSH7_PATH", v),
99+
None => env::remove_var("ML_PWSH7_PATH"),
100+
}
101+
match orig_path {
102+
Some(v) => env::set_var("PATH", v),
103+
None => env::remove_var("PATH"),
104+
}
105+
}
106+
}

tests/wezterm_command.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@ use std::path::Path;
44
#[test]
55
fn builds_wezterm_command() {
66
let note = Path::new("note.txt");
7-
let (cmd, _cmd_str) = build_wezterm_command(note, "wezterm");
7+
let (cmd, _cmd_str) = build_wezterm_command(note);
88
assert_eq!(cmd.get_program().to_string_lossy(), "wezterm");
99
let args: Vec<_> = cmd
1010
.get_args()
1111
.map(|a| a.to_string_lossy().into_owned())
1212
.collect();
13-
assert_eq!(args, ["start", "--", "wezterm", "note.txt"]);
13+
assert_eq!(args, ["start", "--", "nvim", "note.txt"]);
1414
}

0 commit comments

Comments
 (0)