Skip to content

Commit

Permalink
Merge pull request #581 from davidjonesma/copyLine
Browse files Browse the repository at this point in the history
Copy line
  • Loading branch information
jf-kelly authored Aug 31, 2022
2 parents b64b53b + fa7325f commit 206c4cf
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 7 deletions.
65 changes: 58 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
"bootstrap": "^5.1.3",
"browserslist": "^4.6.2",
"cannon": "^0.6.2",
"copy-to-clipboard": "^3.3.1",
"create-react-app": "^4.0.1",
"esdoc-ecmascript-proposal-plugin": "^1.0.0",
"esdoc-jsx-plugin": "^1.0.0",
Expand Down
12 changes: 12 additions & 0 deletions src/components/editor/Editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import customCompleter from "./customCompleter.js";
import KeyboardShortcut from "./KeyboardShortcut.js";
import { browserType } from "../../utils/browserType";
import FontSize from "./FontSize.js";
import copy from "copy-to-clipboard";

/**
* Editor is a React Component that create the Ace Editor in the DOM.
Expand Down Expand Up @@ -101,6 +102,17 @@ class Editor extends Component {
// eslint-disable-next-line
ref="aceEditor"
theme="github"
commands={[{
name: "copyLine",
bindKey: {win: "Ctrl-L", mac: "Command-L"},
exec: () => {let line = window.ace.edit("ace-editor").selection.getCursor().row;
let copyText = window.ace.edit("ace-editor").session.getTextRange({start: {row: line, column: 0}, end: {row: line + 1, column: 0}});
if (copyText.charAt(-1) === "\n") {
copyText = copyText.slice(0, -1);
}
copy(copyText);
}
}]}
fontSize = {this.props.settings.fontSize}
value={this.props.text}
width="100%"
Expand Down
4 changes: 4 additions & 0 deletions src/components/editor/KeyboardShortcut.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ const editor = [
{
shortcut: ["Alt/⌘", "D"],
description: "Delete current line of code"
},
{
shortcut: ["Ctrl/⌘", "L"],
description: "Copy current line of code"
}
];

Expand Down

0 comments on commit 206c4cf

Please sign in to comment.