-
-
Notifications
You must be signed in to change notification settings - Fork 5k
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
Multiple selections #1656
Multiple selections #1656
Conversation
Not everything is perfect yet, but it works quite well. Todo: - testing on a mac - block selecting across the edges doesn't scroll the editor - multiple block selections (alt+drag, release, ctrl+alt+drag) - smarter copy & paste - keyboard shortcuts - autocomplete - clearer styling of adjacent selections (with a border or rounded corners), although showCursorWhenSelecting also helps - the new code in adjustPos is probably wrong (the second branch, which adjacent selections need, breaks the vim and emacs modes, but I don't know vim or emacs so I'm not sure when or why. with a single selection everything is fine though)
Hey, I just wanted to acknowledge this for now. I've seen it, and on the whole, it looks good. I'd prefer if you factored some of the functions that become much larger with your changes into smaller functions, but my original code was also guilty of huge functions, so it's not an important point, use your judgement. The way cursors are drawn and maintained is probably cleaner if you just put them all in a single I'll give some more though on how the existing API should interact with the presence of multiple selections. Backward compatibility is a must, of course, but it'd be nice if it were easy for addon writers to just do the simple thing and still have their code work in a multi-selection situation. I will review the code more closely soon. |
Thanks, that's good to hear! I'll do those things. |
Like Sublime Text: - Selections are copied separated by newlines - If the amount of pasted lines matches the amount of selections, each line is pasted into one selection
Great progress. Is there a reason selections aren't kept in sorted order all the time? That'd save some of the copying and re-sorting. By the way, github doesn't notify me of new commits pushed to a pull request. So when you think this is ready to merge, or want me to review something, add a comment. |
Attempt to make adjacent selections more visible. Might still need tweaking, for example for selections spanning exactly two lines.
Not really, I changed it. The copying still happens though, because I don't want to merge the selections while selecting. I'll let you know. |
This eliminates the need for merging the selections when drawing, and also fixes doing things to the selections while selecting
This also changes bidi behaviour on windows
Whoo! @twiss - thank you SOOO much for working on this! I have really been looking forward to seeing this feature added to CodeMirror. |
I find the concept of setting How about this:
That requires a bit more changes to existing code to properly conform to the multi-selection API, but gives more control, and is easier to reason about. What is |
Yes, that's fine too. See 46f44b8 and 800ff17.
Without it, when an addon handles a character and selectively returns CodeMirror.Pass to |
Operations may nest (inner ones become part of the outer one) and
|
Well, that's a possibility but it wouldn't change much by itself since the operation should end after the timeout in |
We want to merge selections while still selecting to be able to draw them correctly, e.g. when you add a selection around a cursor, that cursor should disappear. (Also so that in the edge case that some text is typed while selecting something reasonable happens.) However, when you move your mouse back to where you started, the merging should be undone. That's
Well, you can ctrl-click, ctrl-drag or call addSelection to add one selection, and (ctrl-)alt-drag or (but not on linux) (ctrl-)middle-drag to add a "block" selection, i.e. either selections around all text in the selected area, or a vertical line of cursors. In the current version of
Assuming the selections array is always sorted, all pairs or triples of selections that need to be merged will be "in a row", which is what |
I've pushed a version of your code, merged onto the current master branch, to the I'll start reviewing the code in detail and pushing patches when I encounter things I want to do differently. Please, if you do more work on this, work from my merged branch. |
Sure! Should I open a new pull request or should I rebase this branch to be the same as yours? Sorry, I'm not very familiar with git. In the matchtags addon, do you still want the jump-to-matching-tag command to work for all selections? It seems bad to just throw selections away. |
Rebasing this branch should work. I'm having some second thoughts about the API I proposed, as well as about some decisions in your code, so maybe it's best if you just let me run with it for a bit, rather than doing conflicting work. |
Alright, go ahead :) |
Okay, I'm currently at " aaaaargh! Will continue thinking about this, but as it stands I'm not sure how to proceed. A big problem is that you'll often want to somehow first compute a changeset from the set of selections, and then apply that atomically. This makes for much more awkward code, for example for Also, the way of adjusting the selection(s) for a change needs to be deeply rethought. The |
Well, what about this: commands are passed |
Any more thoughts here? |
Awesome. Thanks for the heads up. :) |
My implementation (tracked under #778) is now available. It's a full rewrite, since I wanted a fundamentally more robust model. Feedback welcome (I think I got all the features that are present in this code, except for the rounded corners on the selection, but I'm not entirely sure). |
See Issue #778. Not everything is perfect yet, but it works quite well.
Todo: