Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

editor: Override default ctrl+a browser behavior #456

Merged
merged 1 commit into from
Nov 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion frontend/css/root.css
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
--alert-important: hsl(266deg 100% 86%);
--alert-warning: hsl(27deg 100% 74%);
--alert-caution: hsl(359deg 100% 75%);
--selection-highlight: hsl(0deg 0% 100% / 15%);
--selection-highlight: hsl(0deg 0% 100% / 25%);

color-scheme: dark;

Expand Down
6 changes: 6 additions & 0 deletions frontend/module/editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,12 @@ export default class Editor {
this.textarea.addEventListener("keydown", this.handleKeydown)
}

selectAll() {
this.textarea.selectionStart = 0
this.textarea.selectionEnd = this.textarea.value.length - 1
this.textarea.focus()
}

update(textareaProps) {
const { value, selectionStart, selectionEnd, errorLines } = textareaProps
// should be before updating selection otherwise selection will be lost
Expand Down
4 changes: 4 additions & 0 deletions frontend/play/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -443,6 +443,10 @@ function ctrlEnterListener(e) {
document.querySelector(".editor textarea").blur()
handleRun()
}
if ((e.metaKey || e.ctrlKey) && e.key === "a") {
e.preventDefault()
editor?.selectAll()
}
}

function escListener(e) {
Expand Down