Skip to content

Commit f8b348f

Browse files
committed
Add option to clear query after running actions
1 parent 197753f commit f8b348f

6 files changed

Lines changed: 55 additions & 7 deletions

File tree

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ value as shown below:
110110
"history_limit": 100,
111111
"clipboard_limit": 20,
112112
"preserve_command": false,
113+
"clear_query_after_run": false,
113114
"follow_mouse": true,
114115
"static_location_enabled": false,
115116
"static_pos": [0, 0],
@@ -158,6 +159,7 @@ Example: typing `test` will only list entries containing `test`. If an alias mat
158159
`history_limit` defines how many entries the history plugin keeps.
159160
`clipboard_limit` sets how many clipboard entries are persisted for the clipboard plugin.
160161
`preserve_command` keeps the typed command prefix (like `bm add` or `f add`) in the search field after running an action.
162+
`clear_query_after_run` removes the search text after a successful action whenever you prefer starting with a blank box.
161163
`enabled_capabilities` maps plugin names to capability identifiers so features can be toggled individually. The folders plugin, for example, exposes `show_full_path`.
162164
`screenshot_dir` sets the directory used when saving screenshots. If omitted, screenshots are stored in a `MultiLauncher_Screenshots` folder in the current working directory.
163165
`screenshot_save_file` determines whether screenshots copied to the clipboard are also written to disk. The default is `true`.

settings.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
"timer_refresh": 1.0,
4242
"disable_timer_updates": false,
4343
"preserve_command": false,
44+
"clear_query_after_run": false,
4445
"net_refresh": 1.0,
4546
"net_unit": "auto",
4647
"screenshot_dir": null,

src/gui/mod.rs

Lines changed: 33 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,7 @@ 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,
40-
build_wezterm_command,
41-
extract_links,
42-
show_wiki_link,
43-
spawn_external,
39+
build_nvim_command, build_wezterm_command, extract_links, show_wiki_link, spawn_external,
4440
NotePanel,
4541
};
4642
pub use notes_dialog::NotesDialog;
@@ -385,6 +381,7 @@ pub struct LauncherApp {
385381
pub timer_refresh: f32,
386382
pub disable_timer_updates: bool,
387383
pub preserve_command: bool,
384+
pub clear_query_after_run: bool,
388385
pub query_autocomplete: bool,
389386
pub net_refresh: f32,
390387
pub net_unit: crate::settings::NetUnit,
@@ -501,6 +498,7 @@ impl LauncherApp {
501498
static_pos: Option<(i32, i32)>,
502499
static_size: Option<(i32, i32)>,
503500
hide_after_run: Option<bool>,
501+
clear_query_after_run: Option<bool>,
504502
timer_refresh: Option<f32>,
505503
disable_timer_updates: Option<bool>,
506504
preserve_command: Option<bool>,
@@ -556,6 +554,9 @@ impl LauncherApp {
556554
if let Some(v) = hide_after_run {
557555
self.hide_after_run = v;
558556
}
557+
if let Some(v) = clear_query_after_run {
558+
self.clear_query_after_run = v;
559+
}
559560
if let Some(v) = timer_refresh {
560561
self.timer_refresh = v;
561562
}
@@ -884,6 +885,7 @@ impl LauncherApp {
884885
timer_refresh: settings.timer_refresh,
885886
disable_timer_updates: settings.disable_timer_updates,
886887
preserve_command: settings.preserve_command,
888+
clear_query_after_run: settings.clear_query_after_run,
887889
query_autocomplete: settings.query_autocomplete,
888890
net_refresh: settings.net_refresh,
889891
net_unit: settings.net_unit,
@@ -2207,6 +2209,7 @@ impl eframe::App for LauncherApp {
22072209
let current = self.query.clone();
22082210
let mut refresh = false;
22092211
let mut set_focus = false;
2212+
let mut command_changed_query = false;
22102213
if let Some(new_q) = a.action.strip_prefix("query:") {
22112214
tracing::debug!("query action via Enter: {new_q}");
22122215
self.query = new_q.to_string();
@@ -2397,6 +2400,7 @@ impl eframe::App for LauncherApp {
23972400
} else {
23982401
self.query.clear();
23992402
}
2403+
command_changed_query = true;
24002404
refresh = true;
24012405
set_focus = true;
24022406
} else if a.action.starts_with("bookmark:remove:") {
@@ -2408,6 +2412,7 @@ impl eframe::App for LauncherApp {
24082412
} else {
24092413
self.query.clear();
24102414
}
2415+
command_changed_query = true;
24112416
refresh = true;
24122417
set_focus = true;
24132418
} else if a.action.starts_with("folder:remove:") {
@@ -2425,6 +2430,7 @@ impl eframe::App for LauncherApp {
24252430
} else {
24262431
self.query.clear();
24272432
}
2433+
command_changed_query = true;
24282434
refresh = true;
24292435
set_focus = true;
24302436
if self.enable_toasts {
@@ -2445,6 +2451,7 @@ impl eframe::App for LauncherApp {
24452451
set_focus = true;
24462452
if current.starts_with("note list") {
24472453
self.pending_query = Some(current.clone());
2454+
command_changed_query = true;
24482455
}
24492456
if self.enable_toasts {
24502457
let label =
@@ -2461,6 +2468,7 @@ impl eframe::App for LauncherApp {
24612468
// Re-run the current query so the todo list reflects the
24622469
// updated completion state immediately.
24632470
self.pending_query = Some(current.clone());
2471+
command_changed_query = true;
24642472
if self.enable_toasts {
24652473
let label = a
24662474
.label
@@ -2526,6 +2534,7 @@ impl eframe::App for LauncherApp {
25262534
} else {
25272535
self.query.clear();
25282536
}
2537+
command_changed_query = true;
25292538
set_focus = true;
25302539
} else if a.action.starts_with("timer:cancel:")
25312540
&& current.starts_with("timer rm")
@@ -2550,6 +2559,12 @@ impl eframe::App for LauncherApp {
25502559
} else {
25512560
self.query.clear();
25522561
}
2562+
command_changed_query = true;
2563+
set_focus = true;
2564+
}
2565+
if self.clear_query_after_run && !command_changed_query {
2566+
self.query.clear();
2567+
refresh = true;
25532568
set_focus = true;
25542569
}
25552570
if self.hide_after_run
@@ -2973,9 +2988,11 @@ impl eframe::App for LauncherApp {
29732988
}
29742989
if resp.clicked() {
29752990
let current = self.query.clone();
2991+
let mut command_changed_query = false;
29762992
if let Some(new_q) = a.action.strip_prefix("query:") {
29772993
tracing::debug!("query action via click: {new_q}");
29782994
clicked_query = Some(new_q.to_string());
2995+
command_changed_query = true;
29792996
set_focus = true;
29802997
tracing::debug!("move_cursor_end set via mouse click");
29812998
self.move_cursor_end = true;
@@ -3119,6 +3136,7 @@ impl eframe::App for LauncherApp {
31193136
} else {
31203137
self.query.clear();
31213138
}
3139+
command_changed_query = true;
31223140
refresh = true;
31233141
set_focus = true;
31243142
} else if a.action.starts_with("bookmark:remove:") {
@@ -3130,6 +3148,7 @@ impl eframe::App for LauncherApp {
31303148
} else {
31313149
self.query.clear();
31323150
}
3151+
command_changed_query = true;
31333152
refresh = true;
31343153
set_focus = true;
31353154
} else if a.action.starts_with("folder:remove:") {
@@ -3147,6 +3166,7 @@ impl eframe::App for LauncherApp {
31473166
} else {
31483167
self.query.clear();
31493168
}
3169+
command_changed_query = true;
31503170
refresh = true;
31513171
set_focus = true;
31523172
if self.enable_toasts {
@@ -3167,6 +3187,7 @@ impl eframe::App for LauncherApp {
31673187
set_focus = true;
31683188
if current.starts_with("note list") {
31693189
clicked_query = Some(current.clone());
3190+
command_changed_query = true;
31703191
}
31713192
if self.enable_toasts {
31723193
let label = a
@@ -3186,6 +3207,7 @@ impl eframe::App for LauncherApp {
31863207
// Re-run the current query so the visible list refreshes
31873208
// with the toggled completion state.
31883209
clicked_query = Some(current.clone());
3210+
command_changed_query = true;
31893211
if self.enable_toasts {
31903212
let label = a
31913213
.label
@@ -3254,6 +3276,12 @@ impl eframe::App for LauncherApp {
32543276
} else {
32553277
self.query.clear();
32563278
}
3279+
command_changed_query = true;
3280+
set_focus = true;
3281+
}
3282+
if self.clear_query_after_run && !command_changed_query {
3283+
self.query.clear();
3284+
refresh = true;
32573285
set_focus = true;
32583286
}
32593287
if self.hide_after_run

src/plugin_editor.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ impl PluginEditor {
116116
s.static_pos,
117117
s.static_size,
118118
Some(s.hide_after_run),
119+
Some(s.clear_query_after_run),
119120
Some(s.timer_refresh),
120121
Some(s.disable_timer_updates),
121122
Some(s.preserve_command),

src/settings.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,9 @@ pub struct Settings {
149149
/// Keep the command prefix in the query after running an action.
150150
#[serde(default)]
151151
pub preserve_command: bool,
152+
/// Clear the search query after successfully running an action.
153+
#[serde(default)]
154+
pub clear_query_after_run: bool,
152155
#[serde(default = "default_net_refresh")]
153156
pub net_refresh: f32,
154157
#[serde(default)]
@@ -294,6 +297,7 @@ impl Default for Settings {
294297
net_unit: NetUnit::Auto,
295298
disable_timer_updates: false,
296299
preserve_command: false,
300+
clear_query_after_run: false,
297301
show_examples: false,
298302
screenshot_dir: Some(
299303
std::env::current_dir()

src/settings_editor.rs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ pub struct SettingsEditor {
5151
timer_refresh: f32,
5252
disable_timer_updates: bool,
5353
preserve_command: bool,
54+
clear_query_after_run: bool,
5455
query_autocomplete: bool,
5556
net_refresh: f32,
5657
net_unit: crate::settings::NetUnit,
@@ -140,6 +141,7 @@ impl SettingsEditor {
140141
timer_refresh: settings.timer_refresh,
141142
disable_timer_updates: settings.disable_timer_updates,
142143
preserve_command: settings.preserve_command,
144+
clear_query_after_run: settings.clear_query_after_run,
143145
query_autocomplete: settings.query_autocomplete,
144146
net_refresh: settings.net_refresh,
145147
net_unit: settings.net_unit,
@@ -252,6 +254,7 @@ impl SettingsEditor {
252254
timer_refresh: self.timer_refresh,
253255
disable_timer_updates: self.disable_timer_updates,
254256
preserve_command: self.preserve_command,
257+
clear_query_after_run: self.clear_query_after_run,
255258
query_autocomplete: self.query_autocomplete,
256259
net_refresh: self.net_refresh,
257260
net_unit: self.net_unit,
@@ -357,9 +360,15 @@ impl SettingsEditor {
357360
);
358361
});
359362
}
360-
ui.checkbox(&mut self.hide_after_run, "Hide window after running action");
363+
ui.horizontal_wrapped(|ui| {
364+
ui.checkbox(
365+
&mut self.hide_after_run,
366+
"Hide window after running action",
367+
);
368+
ui.checkbox(&mut self.preserve_command, "Preserve command after run");
369+
ui.checkbox(&mut self.clear_query_after_run, "Clear query after run");
370+
});
361371
ui.checkbox(&mut self.always_on_top, "Always on top");
362-
ui.checkbox(&mut self.preserve_command, "Preserve command after run");
363372
ui.checkbox(&mut self.query_autocomplete, "Enable query autocomplete");
364373
ui.checkbox(
365374
&mut self.disable_timer_updates,
@@ -642,6 +651,7 @@ impl SettingsEditor {
642651
new_settings.static_pos,
643652
new_settings.static_size,
644653
Some(new_settings.hide_after_run),
654+
Some(new_settings.clear_query_after_run),
645655
Some(new_settings.timer_refresh),
646656
Some(new_settings.disable_timer_updates),
647657
Some(new_settings.preserve_command),
@@ -680,6 +690,8 @@ impl SettingsEditor {
680690
app.clipboard_limit = new_settings.clipboard_limit;
681691
app.page_jump = new_settings.page_jump;
682692
app.preserve_command = new_settings.preserve_command;
693+
app.clear_query_after_run =
694+
new_settings.clear_query_after_run;
683695
app.query_autocomplete =
684696
new_settings.query_autocomplete;
685697
app.net_refresh = new_settings.net_refresh;

0 commit comments

Comments
 (0)