forked from usebruno/bruno
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added Keybindings tab. (usebruno#3204)
* Added Keybindings tab. * Minor Refactoring
- Loading branch information
Showing
5 changed files
with
179 additions
and
17 deletions.
There are no files selected for viewing
46 changes: 46 additions & 0 deletions
46
packages/bruno-app/src/components/Preferences/Keybindings/StyledWrapper.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import styled from 'styled-components'; | ||
|
||
const StyledWrapper = styled.div` | ||
table { | ||
width: 100%; | ||
border-collapse: collapse; | ||
thead, | ||
td { | ||
border: 2px solid ${(props) => props.theme.table.border}; | ||
} | ||
thead { | ||
color: ${(props) => props.theme.table.thead.color}; | ||
font-size: 1rem; | ||
user-select: none; | ||
} | ||
td { | ||
padding: 4px 8px; | ||
} | ||
thead th { | ||
font-weight: 600; | ||
padding: 10px; | ||
text-align: left; | ||
} | ||
} | ||
.table-container { | ||
max-height: 400px; | ||
overflow-y: scroll; | ||
} | ||
.key-button { | ||
display: inline-block; | ||
color: ${(props) => props.theme.colors.text.white}; | ||
border-radius: 4px; | ||
padding: 1px 5px; | ||
font-family: monospace; | ||
margin-right: 8px; | ||
border: 1px solid #ccc; | ||
} | ||
`; | ||
|
||
export default StyledWrapper; |
45 changes: 45 additions & 0 deletions
45
packages/bruno-app/src/components/Preferences/Keybindings/index.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import StyledWrapper from './StyledWrapper'; | ||
import React from 'react'; | ||
import { getKeyBindingsForOS } from 'providers/Hotkeys/keyMappings'; | ||
import { isMacOS } from 'utils/common/platform'; | ||
|
||
const Keybindings = ({ close }) => { | ||
const keyMapping = getKeyBindingsForOS(isMacOS() ? 'mac' : 'windows'); | ||
|
||
return ( | ||
<StyledWrapper className="w-full"> | ||
<div className="table-container"> | ||
<table> | ||
<thead> | ||
<tr> | ||
<th>Command</th> | ||
<th>Keybinding</th> | ||
</tr> | ||
</thead> | ||
<tbody> | ||
{keyMapping ? ( | ||
Object.entries(keyMapping).map(([action, { name, keys }], index) => ( | ||
<tr key={index}> | ||
<td>{name}</td> | ||
<td> | ||
{keys.split('+').map((key, i) => ( | ||
<div className="key-button" key={i}> | ||
{key} | ||
</div> | ||
))} | ||
</td> | ||
</tr> | ||
)) | ||
) : ( | ||
<tr> | ||
<td colSpan="2">No key bindings available</td> | ||
</tr> | ||
)} | ||
</tbody> | ||
</table> | ||
</div> | ||
</StyledWrapper> | ||
); | ||
}; | ||
|
||
export default Keybindings; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
const KeyMapping = { | ||
save: { mac: 'command+s', windows: 'ctrl+s', name: 'Save' }, | ||
sendRequest: { mac: 'command+enter', windows: 'ctrl+enter', name: 'Send Request' }, | ||
editEnvironment: { mac: 'command+e', windows: 'ctrl+e', name: 'Edit Environment' }, | ||
newRequest: { mac: 'command+b', windows: 'ctrl+b', name: 'New Request' }, | ||
closeTab: { mac: 'command+w', windows: 'ctrl+w', name: 'Close Tab' }, | ||
openPreferences: { mac: 'command+,', windows: 'ctrl+,', name: 'Open Preferences' }, | ||
minimizeWindow: { | ||
mac: 'command+Shift+Q', | ||
windows: 'control+Shift+Q', | ||
name: 'Minimize Window' | ||
}, | ||
switchToPreviousTab: { | ||
mac: 'command+pageup', | ||
windows: 'ctrl+pageup', | ||
name: 'Switch to Previous Tab' | ||
}, | ||
switchToNextTab: { | ||
mac: 'command+pagedown', | ||
windows: 'ctrl+pagedown', | ||
name: 'Switch to Next Tab' | ||
}, | ||
closeAllTabs: { mac: 'command+shift+w', windows: 'ctrl+shift+w', name: 'Close All Tabs' } | ||
}; | ||
|
||
/** | ||
* Retrieves the key bindings for a specific operating system. | ||
* | ||
* @param {string} os - The operating system (e.g., 'mac', 'windows'). | ||
* @returns {Object} An object containing the key bindings for the specified OS. | ||
*/ | ||
export const getKeyBindingsForOS = (os) => { | ||
const keyBindings = {}; | ||
for (const [action, { name, ...keys }] of Object.entries(KeyMapping)) { | ||
if (keys[os]) { | ||
keyBindings[action] = { | ||
keys: keys[os], | ||
name | ||
}; | ||
} | ||
} | ||
return keyBindings; | ||
}; | ||
|
||
/** | ||
* Retrieves the key bindings for a specific action across all operating systems. | ||
* | ||
* @param {string} action - The action for which to retrieve key bindings. | ||
* @returns {Object|null} An object containing the key bindings for macOS, Windows, or null if the action is not found. | ||
*/ | ||
export const getKeyBindingsForActionAllOS = (action) => { | ||
const actionBindings = KeyMapping[action]; | ||
|
||
if (!actionBindings) { | ||
console.warn(`Action "${action}" not found in KeyMapping.`); | ||
return null; | ||
} | ||
|
||
return [actionBindings.mac, actionBindings.windows]; | ||
}; |