Skip to content

Commit 582c49b

Browse files
committed
Merge branch '3078-refresh-on-copy' into develop
Issue #3078 PR #3199
2 parents c139362 + 9cbefbf commit 582c49b

File tree

2 files changed

+19
-3
lines changed

2 files changed

+19
-3
lines changed

monkey/monkey_island/cc/ui/src/components/pages/RunMonkeyPage/RunManually/LocalManualRunOptions.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ const getContents = (props) => {
8383
</Form>
8484
</div>
8585
</div>
86-
<CommandDisplay commands={commands}/>
86+
<CommandDisplay commands={commands} onCopy={getOtp} />
8787
<Col lg={{span:3, offset: 9}} md={{span:4, offset: 8}} sm={{span:4, offset: 8}} xs={12}>
8888
<Button style={{'float': 'right'}} title="Refresh OTP" onClick={getOtp}>Refresh OTP</Button>
8989
</Col>

monkey/monkey_island/cc/ui/src/components/pages/RunMonkeyPage/utils/CommandDisplay.js

+18-2
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,22 @@ export default function commandDisplay(props) {
2626
}
2727
}, [props.commands]);
2828

29+
function handleKeyDown(event) {
30+
let charCode = String.fromCharCode(event.which).toLowerCase();
31+
if ((event.ctrlKey || event.metaKey) && charCode === 'c') {
32+
props.onCopy();
33+
}
34+
if ((event.ctrlKey || event.metaKey) && charCode === 'a') {
35+
event.preventDefault();
36+
let codeElement = event.target.querySelector('code');
37+
let selection = window.getSelection();
38+
let range = document.createRange();
39+
range.selectNode(codeElement);
40+
selection.addRange(range);
41+
}
42+
console.log(charCode);
43+
}
44+
2945
function renderNav() {
3046
return (
3147
<Nav variant='tabs' activeKey={selectedCommand.type} onSelect={setSelectedCommandByName}>
@@ -42,9 +58,9 @@ export default function commandDisplay(props) {
4258
<div className={'command-display'}>
4359
{renderNav()}
4460
<Card>
45-
<div style={{'overflow': 'auto', 'padding': '0.5em'}}>
61+
<div style={{'overflow': 'auto', 'padding': '0.5em'}} onKeyDown={handleKeyDown} tabIndex={-1}>
4662
<CopyToClipboard text={selectedCommand.command} className="pull-right btn-sm">
47-
<Button style={{margin: '-0.5em'}} title="Copy to Clipboard">
63+
<Button style={{margin: '-0.5em'}} title="Copy to Clipboard" onClick={props.onCopy}>
4864
<FontAwesomeIcon icon={faClipboard}/>
4965
</Button>
5066
</CopyToClipboard>

0 commit comments

Comments
 (0)