Corrected righy click options so shift+right click always works
This commit is contained in:
1 parent
1b73c313b2
commit
adac2b9a68
1 file changed
+202
-1
+202
-1
@@ -1936,6 +1936,9 @@ struct Moorly {
|
|||||||
close_to_tray_draft: bool,
|
close_to_tray_draft: bool,
|
||||||
minimize_to_tray: bool,
|
minimize_to_tray: bool,
|
||||||
minimize_to_tray_draft: bool,
|
minimize_to_tray_draft: bool,
|
||||||
|
right_click_behavior: RightClickBehavior,
|
||||||
|
right_click_behavior_draft: RightClickBehavior,
|
||||||
|
right_click_menu_open: bool,
|
||||||
/// Mirrors the OS autostart entry so the settings button knows which
|
/// Mirrors the OS autostart entry so the settings button knows which
|
||||||
/// action to offer.
|
/// action to offer.
|
||||||
autostart_at_login: bool,
|
autostart_at_login: bool,
|
||||||
@@ -2765,6 +2768,8 @@ struct GeneralConfig {
|
|||||||
/// Minimizing the main window hides it to the tray instead.
|
/// Minimizing the main window hides it to the tray instead.
|
||||||
#[serde(default)]
|
#[serde(default)]
|
||||||
minimize_to_tray: bool,
|
minimize_to_tray: bool,
|
||||||
|
#[serde(default)]
|
||||||
|
right_click_behavior: RightClickBehavior,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for GeneralConfig {
|
impl Default for GeneralConfig {
|
||||||
@@ -2773,10 +2778,47 @@ impl Default for GeneralConfig {
|
|||||||
fade_settings: true,
|
fade_settings: true,
|
||||||
close_to_tray: false,
|
close_to_tray: false,
|
||||||
minimize_to_tray: false,
|
minimize_to_tray: false,
|
||||||
|
right_click_behavior: RightClickBehavior::default(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// What a plain right-click does inside a terminal.
|
||||||
|
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default, Serialize, Deserialize)]
|
||||||
|
#[serde(rename_all = "snake_case")]
|
||||||
|
enum RightClickBehavior {
|
||||||
|
Disabled,
|
||||||
|
ContextMenu,
|
||||||
|
#[default]
|
||||||
|
CopyPaste,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl RightClickBehavior {
|
||||||
|
const ALL: [Self; 3] = [Self::Disabled, Self::ContextMenu, Self::CopyPaste];
|
||||||
|
|
||||||
|
fn label(self) -> &'static str {
|
||||||
|
match self {
|
||||||
|
Self::Disabled => "Disabled",
|
||||||
|
Self::ContextMenu => "Context menu",
|
||||||
|
Self::CopyPaste => "Copy / Paste",
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn description(self) -> &'static str {
|
||||||
|
match self {
|
||||||
|
Self::Disabled => "Right-click does nothing.",
|
||||||
|
Self::ContextMenu => "Always opens the context menu.",
|
||||||
|
Self::CopyPaste => "Copies selected text, otherwise pastes clipboard contents.",
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl std::fmt::Display for RightClickBehavior {
|
||||||
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||||
|
write!(f, "{} — {}", self.label(), self.description())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||||
struct StartupConfig {
|
struct StartupConfig {
|
||||||
#[serde(default = "default_true")]
|
#[serde(default = "default_true")]
|
||||||
@@ -4837,6 +4879,7 @@ fn apply_settings(state: &mut Moorly) {
|
|||||||
state.fade_settings = state.fade_settings_draft;
|
state.fade_settings = state.fade_settings_draft;
|
||||||
state.close_to_tray = state.close_to_tray_draft;
|
state.close_to_tray = state.close_to_tray_draft;
|
||||||
state.minimize_to_tray = state.minimize_to_tray_draft;
|
state.minimize_to_tray = state.minimize_to_tray_draft;
|
||||||
|
state.right_click_behavior = state.right_click_behavior_draft;
|
||||||
state.hide_tab_close = state.hide_tab_close_draft;
|
state.hide_tab_close = state.hide_tab_close_draft;
|
||||||
state.show_new_session_button = state.show_new_session_button_draft;
|
state.show_new_session_button = state.show_new_session_button_draft;
|
||||||
state.show_command_palette_description = state.show_command_palette_description_draft;
|
state.show_command_palette_description = state.show_command_palette_description_draft;
|
||||||
@@ -4879,6 +4922,7 @@ fn undo_settings(state: &mut Moorly) {
|
|||||||
state.fade_settings_draft = state.fade_settings;
|
state.fade_settings_draft = state.fade_settings;
|
||||||
state.close_to_tray_draft = state.close_to_tray;
|
state.close_to_tray_draft = state.close_to_tray;
|
||||||
state.minimize_to_tray_draft = state.minimize_to_tray;
|
state.minimize_to_tray_draft = state.minimize_to_tray;
|
||||||
|
state.right_click_behavior_draft = state.right_click_behavior;
|
||||||
state.hide_tab_close_draft = state.hide_tab_close;
|
state.hide_tab_close_draft = state.hide_tab_close;
|
||||||
state.show_new_session_button_draft = state.show_new_session_button;
|
state.show_new_session_button_draft = state.show_new_session_button;
|
||||||
state.show_command_palette_description_draft = state.show_command_palette_description;
|
state.show_command_palette_description_draft = state.show_command_palette_description;
|
||||||
@@ -4931,6 +4975,7 @@ fn config_file(state: &Moorly) -> ConfigFile {
|
|||||||
fade_settings: state.fade_settings,
|
fade_settings: state.fade_settings,
|
||||||
close_to_tray: state.close_to_tray,
|
close_to_tray: state.close_to_tray,
|
||||||
minimize_to_tray: state.minimize_to_tray,
|
minimize_to_tray: state.minimize_to_tray,
|
||||||
|
right_click_behavior: state.right_click_behavior,
|
||||||
},
|
},
|
||||||
startup: StartupConfig {
|
startup: StartupConfig {
|
||||||
show_start_tab: state.show_start_tab,
|
show_start_tab: state.show_start_tab,
|
||||||
@@ -5071,6 +5116,9 @@ impl Default for Moorly {
|
|||||||
close_to_tray_draft: close_to_tray,
|
close_to_tray_draft: close_to_tray,
|
||||||
minimize_to_tray,
|
minimize_to_tray,
|
||||||
minimize_to_tray_draft: minimize_to_tray,
|
minimize_to_tray_draft: minimize_to_tray,
|
||||||
|
right_click_behavior: config.general.right_click_behavior,
|
||||||
|
right_click_behavior_draft: config.general.right_click_behavior,
|
||||||
|
right_click_menu_open: false,
|
||||||
autostart_at_login: autostart::enabled(),
|
autostart_at_login: autostart::enabled(),
|
||||||
drag: None,
|
drag: None,
|
||||||
modifiers: keyboard::Modifiers::default(),
|
modifiers: keyboard::Modifiers::default(),
|
||||||
@@ -5225,6 +5273,8 @@ enum Message {
|
|||||||
SetFadeSettings(bool),
|
SetFadeSettings(bool),
|
||||||
SetCloseToTray(bool),
|
SetCloseToTray(bool),
|
||||||
SetMinimizeToTray(bool),
|
SetMinimizeToTray(bool),
|
||||||
|
SetRightClickBehavior(RightClickBehavior),
|
||||||
|
ToggleRightClickBehaviorMenu,
|
||||||
EnableAutostartAtLogin,
|
EnableAutostartAtLogin,
|
||||||
DisableAutostartAtLogin,
|
DisableAutostartAtLogin,
|
||||||
SetHideTabClose(bool),
|
SetHideTabClose(bool),
|
||||||
@@ -5506,7 +5556,11 @@ fn update(state: &mut Moorly, message: Message) -> Task<Message> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
Message::TerminalRightClick(window, id) => {
|
Message::TerminalRightClick(window, id) => {
|
||||||
if state.modifiers.shift() {
|
// Shift always opens the menu, whatever the plain right-click
|
||||||
|
// setting is. Otherwise the setting decides.
|
||||||
|
if state.modifiers.shift()
|
||||||
|
|| state.right_click_behavior == RightClickBehavior::ContextMenu
|
||||||
|
{
|
||||||
let pointer = state
|
let pointer = state
|
||||||
.windows
|
.windows
|
||||||
.get(&window)
|
.get(&window)
|
||||||
@@ -5522,6 +5576,10 @@ fn update(state: &mut Moorly, message: Message) -> Task<Message> {
|
|||||||
return Task::none();
|
return Task::none();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if state.right_click_behavior == RightClickBehavior::Disabled {
|
||||||
|
return Task::none();
|
||||||
|
}
|
||||||
|
|
||||||
state.terminal_menu = None;
|
state.terminal_menu = None;
|
||||||
let has_selection = state
|
let has_selection = state
|
||||||
.terminal_sessions
|
.terminal_sessions
|
||||||
@@ -6103,6 +6161,13 @@ fn update(state: &mut Moorly, message: Message) -> Task<Message> {
|
|||||||
Message::SetFadeSettings(value) => state.fade_settings_draft = value,
|
Message::SetFadeSettings(value) => state.fade_settings_draft = value,
|
||||||
Message::SetCloseToTray(value) => state.close_to_tray_draft = value,
|
Message::SetCloseToTray(value) => state.close_to_tray_draft = value,
|
||||||
Message::SetMinimizeToTray(value) => state.minimize_to_tray_draft = value,
|
Message::SetMinimizeToTray(value) => state.minimize_to_tray_draft = value,
|
||||||
|
Message::SetRightClickBehavior(behavior) => {
|
||||||
|
state.right_click_behavior_draft = behavior;
|
||||||
|
state.right_click_menu_open = false;
|
||||||
|
}
|
||||||
|
Message::ToggleRightClickBehaviorMenu => {
|
||||||
|
state.right_click_menu_open = !state.right_click_menu_open;
|
||||||
|
}
|
||||||
Message::EnableAutostartAtLogin => match autostart::enable() {
|
Message::EnableAutostartAtLogin => match autostart::enable() {
|
||||||
Ok(()) => state.autostart_at_login = true,
|
Ok(()) => state.autostart_at_login = true,
|
||||||
Err(error) => {
|
Err(error) => {
|
||||||
@@ -10358,6 +10423,14 @@ fn general_panel(state: &Moorly) -> Element<'_, Message> {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
panel = panel.push(
|
||||||
|
column![
|
||||||
|
styled_text(&state.typography.h2, "Right-click behavior"),
|
||||||
|
right_click_behavior_picker(state),
|
||||||
|
]
|
||||||
|
.spacing(8),
|
||||||
|
);
|
||||||
|
|
||||||
let login_action: Element<'_, Message> = if state.autostart_at_login {
|
let login_action: Element<'_, Message> = if state.autostart_at_login {
|
||||||
button("Remove autostart")
|
button("Remove autostart")
|
||||||
.on_press(Message::DisableAutostartAtLogin)
|
.on_press(Message::DisableAutostartAtLogin)
|
||||||
@@ -10391,6 +10464,63 @@ fn general_panel(state: &Moorly) -> Element<'_, Message> {
|
|||||||
panel.into()
|
panel.into()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Drop list with a label and description per right-click behavior.
|
||||||
|
fn right_click_behavior_picker(state: &Moorly) -> Element<'_, Message> {
|
||||||
|
let current = state.right_click_behavior_draft;
|
||||||
|
|
||||||
|
let field = button(
|
||||||
|
row![
|
||||||
|
column![
|
||||||
|
text(current.label()).size(14),
|
||||||
|
text(current.description()).size(11),
|
||||||
|
]
|
||||||
|
.spacing(2)
|
||||||
|
.width(Length::Fill),
|
||||||
|
text("▾").size(12),
|
||||||
|
]
|
||||||
|
.width(Length::Fill)
|
||||||
|
.align_y(Alignment::Center),
|
||||||
|
)
|
||||||
|
.on_press(Message::ToggleRightClickBehaviorMenu)
|
||||||
|
.width(Length::Fill)
|
||||||
|
.padding([6, 10])
|
||||||
|
.style(theme::outlined_option);
|
||||||
|
|
||||||
|
let mut picker = column![field].spacing(4).width(Length::Fill);
|
||||||
|
|
||||||
|
if state.right_click_menu_open {
|
||||||
|
let mut choices = column![].spacing(2).width(Length::Fill);
|
||||||
|
|
||||||
|
for behavior in RightClickBehavior::ALL {
|
||||||
|
let selected = behavior == current;
|
||||||
|
|
||||||
|
choices = choices.push(
|
||||||
|
button(
|
||||||
|
column![
|
||||||
|
text(behavior.label()).size(14),
|
||||||
|
text(behavior.description()).size(11),
|
||||||
|
]
|
||||||
|
.spacing(2)
|
||||||
|
.width(Length::Fill),
|
||||||
|
)
|
||||||
|
.on_press(Message::SetRightClickBehavior(behavior))
|
||||||
|
.width(Length::Fill)
|
||||||
|
.padding([5, 10])
|
||||||
|
.style(move |theme, status| theme::selectable_row(theme, status, selected)),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
picker = picker.push(
|
||||||
|
container(choices)
|
||||||
|
.padding(2)
|
||||||
|
.width(Length::Fill)
|
||||||
|
.style(theme::advanced_frame),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
picker.into()
|
||||||
|
}
|
||||||
|
|
||||||
/// Moves an autostart entry to `target`, shifting the ones in between.
|
/// Moves an autostart entry to `target`, shifting the ones in between.
|
||||||
fn move_autostart(state: &mut Moorly, index: usize, target: usize) {
|
fn move_autostart(state: &mut Moorly, index: usize, target: usize) {
|
||||||
if index <= target || index >= state.autostart_profiles_draft.len() {
|
if index <= target || index >= state.autostart_profiles_draft.len() {
|
||||||
@@ -10911,6 +11041,7 @@ fn settings_dirty(state: &Moorly) -> bool {
|
|||||||
|| state.command_palette_enabled_draft != state.command_palette_enabled
|
|| state.command_palette_enabled_draft != state.command_palette_enabled
|
||||||
|| state.close_to_tray_draft != state.close_to_tray
|
|| state.close_to_tray_draft != state.close_to_tray
|
||||||
|| state.minimize_to_tray_draft != state.minimize_to_tray
|
|| state.minimize_to_tray_draft != state.minimize_to_tray
|
||||||
|
|| state.right_click_behavior_draft != state.right_click_behavior
|
||||||
|| state.theme_choice != state.saved_theme_choice
|
|| state.theme_choice != state.saved_theme_choice
|
||||||
|| state.shortcuts != state.saved_shortcuts
|
|| state.shortcuts != state.saved_shortcuts
|
||||||
}
|
}
|
||||||
@@ -12524,6 +12655,9 @@ mod tests {
|
|||||||
close_to_tray_draft: false,
|
close_to_tray_draft: false,
|
||||||
minimize_to_tray: false,
|
minimize_to_tray: false,
|
||||||
minimize_to_tray_draft: false,
|
minimize_to_tray_draft: false,
|
||||||
|
right_click_behavior: super::RightClickBehavior::default(),
|
||||||
|
right_click_behavior_draft: super::RightClickBehavior::default(),
|
||||||
|
right_click_menu_open: false,
|
||||||
autostart_at_login: false,
|
autostart_at_login: false,
|
||||||
drag: None,
|
drag: None,
|
||||||
modifiers: keyboard::Modifiers::default(),
|
modifiers: keyboard::Modifiers::default(),
|
||||||
@@ -13282,6 +13416,10 @@ mod tests {
|
|||||||
assert!(text.contains("[shortcuts]"));
|
assert!(text.contains("[shortcuts]"));
|
||||||
assert!(text.contains("[command_palette]\nenabled = false"));
|
assert!(text.contains("[command_palette]\nenabled = false"));
|
||||||
assert_eq!(parsed["general"]["fade_settings"].as_bool(), Some(false));
|
assert_eq!(parsed["general"]["fade_settings"].as_bool(), Some(false));
|
||||||
|
assert_eq!(
|
||||||
|
parsed["general"]["right_click_behavior"].as_str(),
|
||||||
|
Some("copy_paste")
|
||||||
|
);
|
||||||
assert_eq!(parsed["appearance"]["theme"].as_str(), Some("dark"));
|
assert_eq!(parsed["appearance"]["theme"].as_str(), Some("dark"));
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
parsed["appearance"]["toast"]["enabled"].as_bool(),
|
parsed["appearance"]["toast"]["enabled"].as_bool(),
|
||||||
@@ -14498,6 +14636,69 @@ mod tests {
|
|||||||
assert!(state.terminal_sessions[&id].selection.is_none());
|
assert!(state.terminal_sessions[&id].selection.is_none());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn right_click_behavior_waits_for_save_or_undo() {
|
||||||
|
let mut state = state();
|
||||||
|
assert_eq!(
|
||||||
|
state.right_click_behavior,
|
||||||
|
super::RightClickBehavior::CopyPaste
|
||||||
|
);
|
||||||
|
|
||||||
|
let _ = update(
|
||||||
|
&mut state,
|
||||||
|
Message::SetRightClickBehavior(super::RightClickBehavior::ContextMenu),
|
||||||
|
);
|
||||||
|
assert_eq!(
|
||||||
|
state.right_click_behavior,
|
||||||
|
super::RightClickBehavior::CopyPaste
|
||||||
|
);
|
||||||
|
assert!(super::settings_dirty(&state));
|
||||||
|
|
||||||
|
let _ = update(&mut state, Message::UndoChanges);
|
||||||
|
assert_eq!(
|
||||||
|
state.right_click_behavior_draft,
|
||||||
|
state.right_click_behavior
|
||||||
|
);
|
||||||
|
|
||||||
|
let _ = update(
|
||||||
|
&mut state,
|
||||||
|
Message::SetRightClickBehavior(super::RightClickBehavior::ContextMenu),
|
||||||
|
);
|
||||||
|
let _ = update(&mut state, Message::SaveSettings);
|
||||||
|
assert_eq!(
|
||||||
|
state.right_click_behavior,
|
||||||
|
super::RightClickBehavior::ContextMenu
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn right_click_behavior_controls_the_terminal_action() {
|
||||||
|
let (mut state, _, id) = terminal_for_session_end(super::SessionEnd::Keep);
|
||||||
|
let selection = super::TerminalSelection {
|
||||||
|
anchor: (0, 0),
|
||||||
|
focus: (0, 2),
|
||||||
|
};
|
||||||
|
|
||||||
|
state.right_click_behavior = super::RightClickBehavior::Disabled;
|
||||||
|
state.terminal_sessions.get_mut(&id).unwrap().selection = Some(selection);
|
||||||
|
let _ = update(&mut state, Message::TerminalRightClick(test_window(), id));
|
||||||
|
assert!(state.terminal_menu.is_none());
|
||||||
|
assert!(state.terminal_sessions[&id].selection.is_some());
|
||||||
|
|
||||||
|
// Shift always opens the menu, even when plain right-click is disabled.
|
||||||
|
state.modifiers = keyboard::Modifiers::SHIFT;
|
||||||
|
let _ = update(&mut state, Message::TerminalRightClick(test_window(), id));
|
||||||
|
assert_eq!(state.terminal_menu.as_ref().unwrap().id, id);
|
||||||
|
assert!(state.terminal_sessions[&id].selection.is_some());
|
||||||
|
state.modifiers = keyboard::Modifiers::NONE;
|
||||||
|
|
||||||
|
state.right_click_behavior = super::RightClickBehavior::ContextMenu;
|
||||||
|
state.terminal_menu = None;
|
||||||
|
state.terminal_sessions.get_mut(&id).unwrap().selection = None;
|
||||||
|
let _ = update(&mut state, Message::TerminalRightClick(test_window(), id));
|
||||||
|
assert_eq!(state.terminal_menu.as_ref().unwrap().id, id);
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn quick_actions_have_default_shortcuts() {
|
fn quick_actions_have_default_shortcuts() {
|
||||||
let state = state();
|
let state = state();
|
||||||
|
|||||||
Reference in new issue
Block a user