-
Notifications
You must be signed in to change notification settings - Fork 481
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(client): restore keyboard shortcuts overlay
Closes #1040
- Loading branch information
Niklas Kiefer
committed
Jan 22, 2019
1 parent
5fcab5a
commit a2ddfea
Showing
9 changed files
with
239 additions
and
4 deletions.
There are no files selected for viewing
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
34 changes: 34 additions & 0 deletions
34
client/src/app/modals/keyboard-shortcuts/KeyboardShortcutsModal.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,34 @@ | ||
import React, { PureComponent } from 'react'; | ||
|
||
import View from './View'; | ||
|
||
import getShortcuts from './getShortcuts'; | ||
|
||
class KeyboardShortcutsModal extends PureComponent { | ||
constructor(props) { | ||
super(props); | ||
|
||
this.state = {}; | ||
} | ||
|
||
render() { | ||
|
||
const { | ||
isMac, | ||
onClose, | ||
} = this.props; | ||
|
||
let modifierKey = 'Control'; | ||
|
||
if (isMac) { | ||
modifierKey = 'Command'; | ||
} | ||
|
||
return <View | ||
shortcuts={ getShortcuts(modifierKey) } | ||
onClose={ onClose } | ||
/>; | ||
} | ||
} | ||
|
||
export default KeyboardShortcutsModal; |
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,51 @@ | ||
import React, { PureComponent } from 'react'; | ||
|
||
import { | ||
ModalWrapper | ||
} from '../../primitives'; | ||
|
||
import css from './View.less'; | ||
|
||
|
||
class View extends PureComponent { | ||
|
||
constructor(props) { | ||
super(props); | ||
|
||
this.state = {}; | ||
} | ||
|
||
render() { | ||
const { | ||
shortcuts, | ||
onClose | ||
} = this.props; | ||
|
||
return ( | ||
<ModalWrapper className={ css.View } onClose={ onClose }> | ||
<h2>Keyboard Shortcuts</h2> | ||
<p> | ||
The following special shortcuts can be used on opened diagrams. | ||
</p> | ||
<table> | ||
<tbody className="keyboard-shortcuts"> | ||
{ | ||
(shortcuts || []).map(s => { | ||
return <tr key={ s.id }> | ||
<td>{ s.label }</td> | ||
<td className="binding"><code>{ s.binding }</code></td> | ||
</tr>; | ||
}) | ||
} | ||
</tbody> | ||
</table> | ||
<p> | ||
Find additional shortcuts on individual items in the application menu. | ||
</p> | ||
</ModalWrapper> | ||
); | ||
} | ||
|
||
} | ||
|
||
export default View; |
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,10 @@ | ||
:local(.View) { | ||
user-select: none; | ||
|
||
font-size: 1.2em; | ||
|
||
.binding { | ||
padding: 5px 10px; | ||
font-family: monospace; | ||
} | ||
} |
97 changes: 97 additions & 0 deletions
97
client/src/app/modals/keyboard-shortcuts/__tests__/KeyboardShortcutsModalSpec.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,97 @@ | ||
import React from 'react'; | ||
|
||
import { | ||
mount, | ||
shallow | ||
} from 'enzyme'; | ||
|
||
import { KeyboardShortcutsModal } from '..'; | ||
import View from '../View'; | ||
import getShortcuts from '../getShortcuts'; | ||
|
||
describe('<KeyboardShortcutsModal>', function() { | ||
|
||
it('should render', function() { | ||
shallow(<KeyboardShortcutsModal />); | ||
}); | ||
|
||
describe('keyboard shortcuts', function() { | ||
|
||
const macModifierKey = 'Command', | ||
otherModifierKey = 'Control'; | ||
|
||
it('should render shortcuts', function() { | ||
|
||
// given | ||
const isMac = true; | ||
|
||
// when | ||
const wrapper = mount(<KeyboardShortcutsModal | ||
isMac={ isMac } | ||
/>); | ||
|
||
const shortcuts = getShortcuts(macModifierKey); | ||
|
||
const keyboardShortcuts = wrapper.find('.keyboard-shortcuts').first(); | ||
|
||
// then | ||
expect(keyboardShortcuts).to.exist; | ||
expect(keyboardShortcuts.children()).to.have.lengthOf(shortcuts.length); | ||
|
||
wrapper.unmount(); | ||
|
||
}); | ||
|
||
|
||
it('should render with mac modifier key', function() { | ||
|
||
// given | ||
const isMac = true; | ||
|
||
// when | ||
const wrapper = mount(<KeyboardShortcutsModal | ||
isMac={ isMac } | ||
/>); | ||
|
||
const keyboardShortcuts = wrapper.find('.keyboard-shortcuts').first(); | ||
|
||
// then | ||
expect(keyboardShortcuts.text()).to.contain(macModifierKey); | ||
expect(keyboardShortcuts.text()).not.to.contain(otherModifierKey); | ||
|
||
wrapper.unmount(); | ||
}); | ||
|
||
|
||
|
||
it('should NOT render with mac modifier key', function() { | ||
|
||
// given | ||
const isMac = false; | ||
|
||
// when | ||
const wrapper = mount(<KeyboardShortcutsModal | ||
isMac={ isMac } | ||
/>); | ||
|
||
const keyboardShortcuts = wrapper.find('.keyboard-shortcuts').first(); | ||
|
||
// then | ||
expect(keyboardShortcuts.text()).not.to.contain(macModifierKey); | ||
expect(keyboardShortcuts.text()).to.contain(otherModifierKey); | ||
|
||
wrapper.unmount(); | ||
|
||
}); | ||
}); | ||
|
||
|
||
describe('<View>', function() { | ||
|
||
it('should render', function() { | ||
shallow(<View />); | ||
}); | ||
|
||
}); | ||
|
||
}); |
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,39 @@ | ||
const keyboardBinding = (binding, modifierKey) => { | ||
if (modifierKey) { | ||
binding = `${modifierKey} + ${binding}`; | ||
} | ||
|
||
return binding; | ||
}; | ||
|
||
export default function(modifierKey) { | ||
|
||
return [ | ||
{ | ||
id: 'addLineFeed', | ||
label: 'Add Line Feed (in text box)', | ||
binding: keyboardBinding('Shift + Enter') | ||
}, | ||
{ | ||
id: 'scrollVertical', | ||
label: 'Scrolling (Vertical)', | ||
binding: keyboardBinding('Mouse Wheel') | ||
}, | ||
{ | ||
id: 'scrollHorizontal', | ||
label: 'Scrolling (Horizontal)', | ||
binding: keyboardBinding('Shift + Mouse Wheel') | ||
}, | ||
{ | ||
id: 'addElementToSelection', | ||
label: 'Add element to selection', | ||
binding: keyboardBinding('Mouse Click', modifierKey) | ||
}, | ||
{ | ||
id: 'selectMultipleElements', | ||
label: 'Select multiple elements (Lasso Tool)', | ||
binding: keyboardBinding('Shift + Mouse Drag') | ||
} | ||
]; | ||
|
||
} |
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 @@ | ||
export { default as KeyboardShortcutsModal } from './KeyboardShortcutsModal'; |
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 |
---|---|---|
|
@@ -32,6 +32,7 @@ const globals = { | |
config, | ||
dialog, | ||
fileSystem, | ||
isMac, | ||
workspace | ||
}; | ||
|
||
|