adobe / brackets

An open source code editor for the web, written in JavaScript, HTML and CSS.
http://brackets.io
MIT License
33.24k stars 7.62k forks source link

Toggle Block Comment doesn't work with multiple cursors in one comment #7510

Open njx opened 10 years ago

njx commented 10 years ago
  1. Open a JS file with a multiline block comment
  2. Create multiple cursors inside the block comment
  3. Edit > Toggle Block Comment

Result: Nothing happens. This is because we iterate over each selection independently, but both selections would try to generate the same edit (remove the outer block comment), and those overlapping edits get rejected by doMultipleEdits().

njx commented 10 years ago

There are quite likely other issues like this in the commenting code, because in general the code reaches outside each individual selection in order to figure out what to do. There are a few different approaches I could imagine taking to fix this:

The latter is probably easier and straightforward, but it wouldn't catch cases where, for example, the comment code wants to do two different things that overlap for nearby selections. I would think that that latter case should only occur for pathological combinations of selections where it's not obvious what the user wants anyway.

njx commented 10 years ago

Reviewed. Low pri to me.

peterflynn commented 10 years ago

@njx What about inflating the selections to cover the entire comment that they'll affect, and then coalescing selections that are overlapping? I assume the selection manipulation APIs would give us the coalescing for free in that case. (We'd want to do this on a clone of the original selections though I guess, since we want to roughly preserve the user's original selection state after the edits).

njx commented 10 years ago

Yup, something like that might work too, but I don't remember the commenting code well enough to know if that's easier than one of the other options.