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
x/playground: cannot restore code selected and deleted by pressing tab #41037
Comments
Interesting. If you select some code and delete it by pressing |
@ALTree I found the cause of that issue. The playground has a bug in a custom tab handle that erases selected code and replace it with "\t" programmatically in a way that doesn't support native undo feature. //playground.js
function insertTabs(n) {
// find the selection start and end
var start = code[0].selectionStart;
var end = code[0].selectionEnd;
// split the textarea content into two, and insert n tabs
var v = code[0].value;
var u = v.substr(0, start);
for (var i=0; i<n; i++) {
u += "\t";
}
u += v.substr(end);
// set revised content
code[0].value = u; <-- this is cause of the bug
// reset caret position after inserted tabs
code[0].selectionStart = start+n;
code[0].selectionEnd = start+n;
} I write solutions and it seems to work on Chrome and Firefox. field = code[0]
let document = field.ownerDocument;
if (!document.execCommand('insertText', false, u)) {
//firefox only
field.setRangeText(
u,
start || 0,
end || 0,
'end'
);
field.dispatchEvent(new InputEvent('input', {
data: u,
inputType: 'insertText',
isComposing: false
}));
} |
Feel free to send a PR. |
@ALTree I made a pull-request golang/website#13 |
The playground suffer from a bug that on tab click replace selected code with "\t" programmatically in a way that doesn't support native undo feature. For golang/go#41037.
Change https://golang.org/cl/255157 mentions this issue: |
Change https://golang.org/cl/252377 mentions this issue: |
Update go.mod will pick up newer version containing fix golang/tools#251 For golang/go#41037
Change https://golang.org/cl/255177 mentions this issue: |
Just ran into this and lost some work, super obnoxious bug. Any progress on fixing this? |
Use this goplay.tools I fixed that issue, unfortunately it hasn't been merged because I've used execCommand which is described as obsolete in Mozilla documentation. I didn't find any other solutions to fix that on others browsers Blink/Webkit based without reimplementing code editor. The case here is to invoke native edit event to maintain textbook capabilities like undo, redo etc. |
Bumping, just ran into this myself. very annoying |
Change https://golang.org/cl/366535 mentions this issue: |
People often highlight a selection and type tab, hoping to indent it. Instead, the editor replaces it with a tab. That's fine - some editors work that way. But the old implementation did not push that edit onto the undo stack, so that there was no way to get the deleted selection back. Fix that. Fixes golang/go#41037. Change-Id: I9f2aa94ac389a3905d07411b0a156dbc66a7ec8a Reviewed-on: https://go-review.googlesource.com/c/website/+/366535 Trust: Russ Cox <rsc@golang.org> Run-TryBot: Russ Cox <rsc@golang.org> TryBot-Result: Go Bot <gobot@golang.org> Website-Publish: Russ Cox <rsc@golang.org> Reviewed-by: Jamal Carvalho <jamal@golang.org>
What version of Go are you using (
go version
)?The playground uses the latest stable release of Go.
The current version is go1.14.7.
Web browser and operating system
The latest Chrome, Windows 10
What operating system and processor architecture are you using (
go env
)?That running on https://play.golang.org/.
How to reproduce a bug?
Select any part of text and click Tab key. Code disappear, cannot undo changes.
What did you expect to do?
Got my code back.
What did you see instead?
Nothing 😅
The text was updated successfully, but these errors were encountered: