Skip to content

Commit 0362dcd

Browse files
authored
🖊 editor: Override default ctrl+a browser behavior (#456)
Override default ctrl+a browser behavior in lab and playground to select all editor contents only and not the entire web page. While at it, make editor highlight a little bit more easily visible. Fixes: evylang/todo#108 Pull-request: #456
1 parent caeed5c commit 0362dcd

File tree

3 files changed

+11
-1
lines changed

3 files changed

+11
-1
lines changed

frontend/css/root.css

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
--alert-important: hsl(266deg 100% 86%);
4444
--alert-warning: hsl(27deg 100% 74%);
4545
--alert-caution: hsl(359deg 100% 75%);
46-
--selection-highlight: hsl(0deg 0% 100% / 15%);
46+
--selection-highlight: hsl(0deg 0% 100% / 25%);
4747

4848
color-scheme: dark;
4949

frontend/module/editor.js

+6
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,12 @@ export default class Editor {
6565
this.textarea.addEventListener("keydown", this.handleKeydown)
6666
}
6767

68+
selectAll() {
69+
this.textarea.selectionStart = 0
70+
this.textarea.selectionEnd = this.textarea.value.length - 1
71+
this.textarea.focus()
72+
}
73+
6874
update(textareaProps) {
6975
const { value, selectionStart, selectionEnd, errorLines } = textareaProps
7076
// should be before updating selection otherwise selection will be lost

frontend/play/index.js

+4
Original file line numberDiff line numberDiff line change
@@ -443,6 +443,10 @@ function ctrlEnterListener(e) {
443443
document.querySelector(".editor textarea").blur()
444444
handleRun()
445445
}
446+
if ((e.metaKey || e.ctrlKey) && e.key === "a") {
447+
e.preventDefault()
448+
editor?.selectAll()
449+
}
446450
}
447451

448452
function escListener(e) {

0 commit comments

Comments
 (0)