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

[CLOSED] Toggling block comment extremely fast only uncomments partially #2231

Open
core-ai-bot opened this issue Aug 29, 2021 · 5 comments
Open

Comments

@core-ai-bot
Copy link
Member

Issue by peterflynn
Wednesday Dec 12, 2012 at 01:35 GMT
Originally opened as adobe/brackets#2335


  1. Select a range of code
  2. Hold down Ctrl+Shift, and press "/" twice as fast as you can

Result: often, the closing "/" is left in the code even though the opening "/" has been removed.

Expected: the uncomment command completely reverses the comment command -- i.e. the text is unchanged in net.

@core-ai-bot
Copy link
Member Author

Comment by peterflynn
Wednesday Dec 12, 2012 at 01:46 GMT


This bug occurs because block-comment relies on tokens in the file, and certain tokenization in CodeMirror occurs asynchronously. If you can run uncomment within 100 ms of running comment, it will get partially stale tokens and thus fail to interpret the text correctly.

In particular, CodeMirror only synchronously tokenizes the actual lines that were touched by an edit (or the first 500 of those lines, if there are more than that). Any other lines -- in this case, all the lines between the "/" and "/" -- won't be retokenized until 100 ms later. See startWorker() and the call to it in updateLinesNoUndo().

This bug could occur with any command that relies on tokens, but it's particularly easy to hit with block comment (and broke a bunch of unit tests I've been writing). It seems like the cleanest solution, that places the least burden on commands, would be to add a CodeMirror API that let us complete all pending retokenization synchronously -- e.g. editor.ensureTokensUpToDate().

@core-ai-bot
Copy link
Member Author

Comment by njx
Monday Dec 17, 2012 at 19:20 GMT


Reviewed. Seems like there's already an internal API in CodeMirror (v2) for highlighting a specified range of lines synchronously, so it could be easy to just expose that if Marijn is okay with it. (I think you'd want to be able to pick a range of lines to highlight to, rather than just completing all pending retokenization to the end of the file, because the file might be long. So you'd really want to just pick some chunksize, tokenize that far, and then see if you got out of the comment, and if not, iterate.)

@core-ai-bot
Copy link
Member Author

Comment by peterflynn
Friday Mar 29, 2013 at 20:00 GMT


Note: whenever this is fixed the workaround in EditorCommandHandlers-test.testToggleBlock() should be removed.

@core-ai-bot
Copy link
Member Author

Comment by njx
Thursday Jun 13, 2013 at 18:59 GMT


I have a proposal for fixing this at codemirror/codemirror5#1610 (which would also require us to pass true for the new precise parameter everywhere we care about this, which is probably everywhere :))

@core-ai-bot
Copy link
Member Author

Comment by gruehle
Friday Jun 14, 2013 at 21:07 GMT


Confirmed fixed. Closing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant