Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature] WIP: Keybindings added to navigate between tabs. #817

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions packages/app/src/app/store/modules/editor/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -370,3 +370,24 @@ export function setPreviewBounds({ props, state }) {
state.set(`editor.previewWindow.height`, props.height);
}
}

export function switchToTab({ state, props }) {
const tabs = state.get('editor.tabs');

const currentModuleShortid = state.get(`editor.currentModuleShortid`);
const currentTabIndex = tabs.findIndex(
t => t.moduleShortid === currentModuleShortid
);

const switchToTabIndex = (tabLength, currentIdx) => {
if (props.shouldSwitchNext) {
return currentIdx >= tabLength ? 0 : currentIdx + 1;
}
return currentIdx <= 0 ? tabs.length - 1 : currentIdx - 1;
};

const index = switchToTabIndex(tabs.length - 1, currentTabIndex);
const moduleShortid = state.get(`editor.tabs.${index}.moduleShortid`);

state.set('editor.currentModuleShortid', moduleShortid);
}
1 change: 1 addition & 0 deletions packages/app/src/app/store/modules/editor/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,5 +85,6 @@ export default Module({
quickActionsClosed: sequences.closeQuickActions,
setPreviewBounds: sequences.setPreviewBounds,
setPreviewContent: sequences.setPreviewContent,
switchTab: sequences.switchTab,
},
});
8 changes: 8 additions & 0 deletions packages/app/src/app/store/modules/editor/sequences.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,14 @@ export const closeTab = [
},
];

export const switchTab = [
hasEnoughTabs,
{
false: [],
true: [actions.switchToTab],
},
];

export const clearErrors = [
set(state`editor.errors`, []),
set(state`editor.corrections`, []),
Expand Down
16 changes: 16 additions & 0 deletions packages/common/utils/keybindings.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,22 @@ export const KEYBINDINGS = {
}),
},

'editor.switch-next-tab': {
title: 'Switch To Next Tab',
type: 'View',
bindings: [['Control', 'S']],
signal: 'editor.switchTab',
payload: () => ({ shouldSwitchNext: true }),
},

'editor.switch-previous-tab': {
title: 'Switch To Previous Tab',
type: 'View',
bindings: [['Control', 'Z']],
signal: 'editor.switchTab',
payload: () => ({ shouldSwitchNext: false }),
},

'editor.zen-mode': {
title: 'Toggle Zen Mode',
type: 'View',
Expand Down