Add moving tabs left and right with key shortcuts
This commit is contained in:
parent
9129277bed
commit
003a9b3b06
4 changed files with 49 additions and 1 deletions
|
|
@ -132,6 +132,8 @@ zoom-reset = Default text size
|
||||||
zoom-out = Smaller text
|
zoom-out = Smaller text
|
||||||
next-tab = Next tab
|
next-tab = Next tab
|
||||||
previous-tab = Previous tab
|
previous-tab = Previous tab
|
||||||
|
move-tab-left = Move tab left
|
||||||
|
move-tab-right = Move tab right
|
||||||
split-horizontal = Split horizontal
|
split-horizontal = Split horizontal
|
||||||
split-vertical = Split vertical
|
split-vertical = Split vertical
|
||||||
pane-toggle-maximize = Maximize or restore pane
|
pane-toggle-maximize = Maximize or restore pane
|
||||||
|
|
|
||||||
35
src/main.rs
35
src/main.rs
|
|
@ -8,7 +8,7 @@ use cosmic::iced::keyboard::key::Physical;
|
||||||
use cosmic::widget::menu::action::MenuAction;
|
use cosmic::widget::menu::action::MenuAction;
|
||||||
use cosmic::widget::menu::key_bind::KeyBind;
|
use cosmic::widget::menu::key_bind::KeyBind;
|
||||||
use cosmic::widget::pane_grid::Pane;
|
use cosmic::widget::pane_grid::Pane;
|
||||||
use cosmic::widget::segmented_button::ReorderEvent;
|
use cosmic::widget::segmented_button::{InsertPosition, ReorderEvent};
|
||||||
use cosmic::{
|
use cosmic::{
|
||||||
Application, ApplicationExt, Element, action,
|
Application, ApplicationExt, Element, action,
|
||||||
app::{Core, Settings, Task, context_drawer},
|
app::{Core, Settings, Task, context_drawer},
|
||||||
|
|
@ -281,6 +281,8 @@ pub enum Action {
|
||||||
TabNewNoProfile,
|
TabNewNoProfile,
|
||||||
TabNext,
|
TabNext,
|
||||||
TabPrev,
|
TabPrev,
|
||||||
|
TabMoveLeft,
|
||||||
|
TabMoveRight,
|
||||||
ToggleFullscreen,
|
ToggleFullscreen,
|
||||||
WindowClose,
|
WindowClose,
|
||||||
WindowNew,
|
WindowNew,
|
||||||
|
|
@ -334,6 +336,8 @@ impl Action {
|
||||||
Self::TabNewNoProfile => Message::TabNewNoProfile,
|
Self::TabNewNoProfile => Message::TabNewNoProfile,
|
||||||
Self::TabNext => Message::TabNext,
|
Self::TabNext => Message::TabNext,
|
||||||
Self::TabPrev => Message::TabPrev,
|
Self::TabPrev => Message::TabPrev,
|
||||||
|
Self::TabMoveLeft => Message::TabMoveLeft,
|
||||||
|
Self::TabMoveRight => Message::TabMoveRight,
|
||||||
Self::ToggleFullscreen => Message::ToggleFullscreen,
|
Self::ToggleFullscreen => Message::ToggleFullscreen,
|
||||||
Self::WindowClose => Message::WindowClose,
|
Self::WindowClose => Message::WindowClose,
|
||||||
Self::WindowNew => Message::WindowNew,
|
Self::WindowNew => Message::WindowNew,
|
||||||
|
|
@ -442,6 +446,8 @@ pub enum Message {
|
||||||
TabNewNoProfile,
|
TabNewNoProfile,
|
||||||
TabNext,
|
TabNext,
|
||||||
TabPrev,
|
TabPrev,
|
||||||
|
TabMoveLeft,
|
||||||
|
TabMoveRight,
|
||||||
TermEvent(pane_grid::Pane, segmented_button::Entity, TermEvent),
|
TermEvent(pane_grid::Pane, segmented_button::Entity, TermEvent),
|
||||||
TermEventTx(mpsc::UnboundedSender<(pane_grid::Pane, segmented_button::Entity, TermEvent)>),
|
TermEventTx(mpsc::UnboundedSender<(pane_grid::Pane, segmented_button::Entity, TermEvent)>),
|
||||||
ToggleFullscreen,
|
ToggleFullscreen,
|
||||||
|
|
@ -2960,6 +2966,33 @@ impl Application for App {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Message::TabMoveLeft => {
|
||||||
|
if let Some(tab_model) = self.pane_model.active_mut() {
|
||||||
|
let pos: usize = tab_model
|
||||||
|
.position(tab_model.active())
|
||||||
|
.expect("at least one tab is always open")
|
||||||
|
.into();
|
||||||
|
if pos > 0 {
|
||||||
|
let dragged = tab_model.iter().nth(pos).expect("tab unavailable");
|
||||||
|
let target = tab_model.iter().nth(pos - 1).expect("previous tab missing");
|
||||||
|
tab_model.reorder(dragged, target, InsertPosition::Before);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Message::TabMoveRight => {
|
||||||
|
if let Some(tab_model) = self.pane_model.active_mut() {
|
||||||
|
let len = tab_model.iter().count();
|
||||||
|
let pos: usize = tab_model
|
||||||
|
.position(tab_model.active())
|
||||||
|
.expect("at least one tab is always open")
|
||||||
|
.into();
|
||||||
|
if pos < len - 1 && len > 1 {
|
||||||
|
let dragged = tab_model.iter().nth(pos).expect("tab unavailable");
|
||||||
|
let target = tab_model.iter().nth(pos + 1).expect("next tab missing");
|
||||||
|
tab_model.reorder(dragged, target, InsertPosition::After);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Message::TermEvent(pane, entity, event) => {
|
Message::TermEvent(pane, entity, event) => {
|
||||||
match event {
|
match event {
|
||||||
TermEvent::Bell => {
|
TermEvent::Bell => {
|
||||||
|
|
|
||||||
|
|
@ -195,6 +195,9 @@ pub fn menu_bar<'a>(
|
||||||
MenuItem::Button(fl!("next-tab"), None, Action::TabNext),
|
MenuItem::Button(fl!("next-tab"), None, Action::TabNext),
|
||||||
MenuItem::Button(fl!("previous-tab"), None, Action::TabPrev),
|
MenuItem::Button(fl!("previous-tab"), None, Action::TabPrev),
|
||||||
MenuItem::Divider,
|
MenuItem::Divider,
|
||||||
|
MenuItem::Button(fl!("move-tab-left"), None, Action::TabMoveLeft),
|
||||||
|
MenuItem::Button(fl!("move-tab-right"), None, Action::TabMoveRight),
|
||||||
|
MenuItem::Divider,
|
||||||
MenuItem::Button(
|
MenuItem::Button(
|
||||||
fl!("split-horizontal"),
|
fl!("split-horizontal"),
|
||||||
None,
|
None,
|
||||||
|
|
|
||||||
|
|
@ -87,6 +87,8 @@ pub enum KeyBindAction {
|
||||||
TabNew,
|
TabNew,
|
||||||
TabNext,
|
TabNext,
|
||||||
TabPrev,
|
TabPrev,
|
||||||
|
TabMoveLeft,
|
||||||
|
TabMoveRight,
|
||||||
ToggleFullscreen,
|
ToggleFullscreen,
|
||||||
WindowClose,
|
WindowClose,
|
||||||
WindowNew,
|
WindowNew,
|
||||||
|
|
@ -127,6 +129,8 @@ impl KeyBindAction {
|
||||||
Self::TabNew => Some(Action::TabNew),
|
Self::TabNew => Some(Action::TabNew),
|
||||||
Self::TabNext => Some(Action::TabNext),
|
Self::TabNext => Some(Action::TabNext),
|
||||||
Self::TabPrev => Some(Action::TabPrev),
|
Self::TabPrev => Some(Action::TabPrev),
|
||||||
|
Self::TabMoveLeft => Some(Action::TabMoveLeft),
|
||||||
|
Self::TabMoveRight => Some(Action::TabMoveRight),
|
||||||
Self::ToggleFullscreen => Some(Action::ToggleFullscreen),
|
Self::ToggleFullscreen => Some(Action::ToggleFullscreen),
|
||||||
Self::WindowClose => Some(Action::WindowClose),
|
Self::WindowClose => Some(Action::WindowClose),
|
||||||
Self::WindowNew => Some(Action::WindowNew),
|
Self::WindowNew => Some(Action::WindowNew),
|
||||||
|
|
@ -288,6 +292,8 @@ pub fn action_label(action: KeyBindAction) -> String {
|
||||||
KeyBindAction::TabNew => fl!("new-tab"),
|
KeyBindAction::TabNew => fl!("new-tab"),
|
||||||
KeyBindAction::TabNext => fl!("next-tab"),
|
KeyBindAction::TabNext => fl!("next-tab"),
|
||||||
KeyBindAction::TabPrev => fl!("previous-tab"),
|
KeyBindAction::TabPrev => fl!("previous-tab"),
|
||||||
|
KeyBindAction::TabMoveLeft => fl!("move-tab-left"),
|
||||||
|
KeyBindAction::TabMoveRight => fl!("move-tab-right"),
|
||||||
KeyBindAction::ToggleFullscreen => fl!("toggle-fullscreen"),
|
KeyBindAction::ToggleFullscreen => fl!("toggle-fullscreen"),
|
||||||
KeyBindAction::WindowClose => fl!("close-window"),
|
KeyBindAction::WindowClose => fl!("close-window"),
|
||||||
KeyBindAction::WindowNew => fl!("new-window"),
|
KeyBindAction::WindowNew => fl!("new-window"),
|
||||||
|
|
@ -470,6 +476,10 @@ fn fallback_shortcuts() -> Shortcuts {
|
||||||
bind!([Ctrl], "Tab", TabNext);
|
bind!([Ctrl], "Tab", TabNext);
|
||||||
bind!([Ctrl, Shift], "Tab", TabPrev);
|
bind!([Ctrl, Shift], "Tab", TabPrev);
|
||||||
|
|
||||||
|
// Ctrl+Shift+PageUp/Down move tabs left and right
|
||||||
|
bind!([Ctrl, Shift], "PageUp", TabMoveLeft);
|
||||||
|
bind!([Ctrl, Shift], "PageDown", TabMoveRight);
|
||||||
|
|
||||||
// Ctrl+Shift+# activates tabs by index
|
// Ctrl+Shift+# activates tabs by index
|
||||||
bind!([Ctrl, Shift], "1", TabActivate0);
|
bind!([Ctrl, Shift], "1", TabActivate0);
|
||||||
bind!([Ctrl, Shift], "2", TabActivate1);
|
bind!([Ctrl, Shift], "2", TabActivate1);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue