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

Feature Request - multi selection #778

Closed
0i0 opened this issue Aug 31, 2012 · 42 comments
Closed

Feature Request - multi selection #778

0i0 opened this issue Aug 31, 2012 · 42 comments
Milestone

Comments

@0i0
Copy link

0i0 commented Aug 31, 2012

I know that this might be a big one to get your head around. but its totally worth it.

after i have moved to sublime text 2 for my development. its really hard going back to editors that don't have the multi select feature

it is a killer one and it saves tons of time

if you don't know what it is watch this movie first http://www.youtube.com/watch?v=i2SVJa2EGIw

it takes some time to get to use to the idea that your pointing power was multiplied many-folds. than you really start to invent new ways to work with this

WATCH OUT - if you'll get use to work with multi selection it will be very hard to go back

@peterkroon
Copy link
Contributor

Awesome!

@mattpass
Copy link
Contributor

Agreed. Seems to be a part of all modern editors now.

@peterkroon
Copy link
Contributor

I think this shouldn't be too hard to create.
Also look at the Match Highllighter demo

@marijnh
Copy link
Member

marijnh commented Sep 3, 2012

Is this also useful for code that's not ridiculously repetitive?

This is cute, but it's not a priority for me.

@0i0
Copy link
Author

0i0 commented Sep 3, 2012

it is ridiculously productive to any kind of coding. the thing is, it takes a little time to understand the power of this.

we are used to think in a single coding dimension... and the jump to multiple dimensions is to understand there are many many things you can do in different ways

a great example will be if you use search and replace on something..
and you want to replace only most of the matches
traditionally you would go over ALL of them one by one.
with multi select you can just put cursors on all matches (single action), than directly remove the ONLY ones you don't want to change

for example if you want to replace 21 out of 27 matches this will be 7 actions vs 28 actions
(not to mention on each action you have to check yourself if it is a one you want to replace or not)

another example is if you want to add (,) at the end of a block of code at every line

you really have to try it to understand it more

I have been working with it for about a year now with JS HTML C# and python and I still find new ways of using this that amazes me

@jankeromnes
Copy link
Contributor

I think this feature has a lot of hype around it. It was brought by Sublime Text, and it is now implemented by ACE and people seem to love it. I don't use it yet, so I'm not sure about usefulness, but it is cute and I wouldn't mind this being in CodeMirror. Furthermore, I know a lot of people are making (irrational?) decisions about editors based on these kind of innovative features (multiple carrets and selection, block selection...), so if enough people are interested, maybe it's worth a crowd-funding effort? If there was a campaign for that I'd back it.

@marijnh
Copy link
Member

marijnh commented Sep 25, 2012

I think this wouldn't even be that hard to do. But unless it gets funded somehow, or someone else submits a good, clean patch, I don't have time to spend on it.

@pablokvitca
Copy link

I think it is a great feature with tons of usefulness and, once you get used to it, very indispensable. It's like using for a while just a computer to write and then going back to use pen and paper, it's AWFUL.

Also I think this feature will bring many more users and costumers to any service using CodeMirror, so I believe it a great feature to spend time, and work on.

I even found this on the CodeMirror Forum at Google Grupos: "...All cursor and selection display is
done through DOM nodes, so you could extend the code to display more
than one." I thought of doing it (a patch or something as marijnh said on a comment, two before this one.) but I'm a student and don't have much time, and also I'm not very experienced on this so even is I manage do it, I think it would be full of bugs and things like that.

@jankeromnes
Copy link
Contributor

As @siefkenj hints in issue #1032, there can be no Ctrl-V selection in vim mode unless there is block selection support in CodeMirror. I guess there can be no block selection without multi selection / multi cursor. To try it out, click on Edit in any file on github.com and use the Alt key.

Anyone up for crowd-funding the effort to implement this? I use Ctrl-V very often in Vim, and block selection with Alt-Click could do really nice in the default keymap.

@marijnh
Copy link
Member

marijnh commented Dec 2, 2012

Do these two problems (rectangular selection in vim and sublime text style multi selection) really map to the same implementation? It sounds like rectangular selection is a single selection that happens to not be a single range, whereas sublime text selections are actually multiple selections (if you replace them, all are replaced individually).

@jankeromnes
Copy link
Contributor

In Ace, block selections are composed of multiple single-range selections, with as many new cursors, and I guess Sublime's block selections work similarly.

In Vim, block selections appear to be single selections with a single cursor but multiple ranges. However, if you block select, then hit S (substitute: delete the selection and go to insert mode), you're going to be inserting text in the first line of the block selection, but as soon as you leave insert mode, all your inserted text is replicated on subsequent lines of the block selection. So I'll argue that Vim's implementation will also work with multiple selections and multiple cursors.

EDIT: Maybe I'm not making much sense, but my point is: I think block selection can and should be implemented with multiple single-range selections. No need for single selections that span multiple ranges, since replacing a block selection will always replace each range individually.

@mightyguava
Copy link
Contributor

I would think any operations on selections would operate on all ranges in all selections, individually. What exactly is the benefit of multiple single range selections over a single multi-range selection?

vim.js's internals are probably (I am too inept in C++ to verify) completely different from Vim's implementation. There wouldn't be much difference to vim.js whether we use multiple single range selections or one multi-range selection.

@jankeromnes
Copy link
Contributor

The only difference between several single-range selections vs a single multi-range selection is that in the first case there are several cursors, implying that any operation is applied to all ranges. The multi-cursor aspect helps operating on all ranges (every selection's cursor inserts / deletes / replaces the same way), and this implementation has the nice effect of giving all at once multiple cloned cursors, multiple selections, and block selection (when those multiple selections happen to form a block).

@marijnh
Copy link
Member

marijnh commented Dec 3, 2012

In Emacs' rectangle-manipulation functions, it is possible to paste one rectangle (represented as a set of equal-length lines on the clipboard-equivalent) into a rectangular selection. That wouldn't naturally play well with a Subline Text / ACE style multi-selection. Not sure how it is in vim.

But, if the vim mode knows it is acting on a rectangle, and it can query the current multi-selection somehow, it would be easy for it to make some API calls that amount to the same effect -- replacing the individual ranges separately. So I guess that yes, having such multi-cursor selections would still be useful.

@jankeromnes
Copy link
Contributor

Vim is also able to paste rectangles anywhere (before inserting the new text, it deletes currently selected text if any, but the pasted section does not care about the shape of the selection it replaces). The behavior I see is, paste the first line of the clipboard as if it was pasted normally, and then paste all the other lines of the clipboard relatively to the first pasted line. For multi-selections that happen to be rectangular, it happens as follows in Vim:

copy this:
A B
C D

paste into this (with cursor on or just after "j"):
e f g h
i j k l
m n o p

result:
e f g h
i j A B k l
m n C D o p

edge case when you paste off limits:
e f g h
i j k l
m n o p A B
        C D
(new lines and white spaces are spanned as necessary)

I don't see why having a "multi-cusor-sublime-ace model" would cause trouble implementing rectangular pasting. The Emacs behavior you described sounds to me like:

  1. delete previously selected text
  2. insert all ranges in the clipboard relatively to the pasting position

Does Emacs fit the pasted rectangular text into selected rectangle if their dimensions are different? Maybe that would be a little more tricky.

@pablokvitca
Copy link

-----Original Message-----
From: Jan Keromnes notifications@github.com
Date: Mon, 03 Dec 2012 04:28:34
To: marijnh/CodeMirrorCodeMirror@noreply.github.com
Reply-To: marijnh/CodeMirror reply@reply.github.com
Cc: Paulpablokvitca@gmail.com
Subject: Re: [CodeMirror] Feature Request - multi selection (#778)

Vim is also able to paste rectangles anywhere (before inserting the new text, it deletes currently selected text if any, but the pasted section does not care about the shape of the selection it replaces). The behavior I see is, paste the first line of the clipboard as if it was pasted normally, and then paste all the other lines of the clipboard relatively to the first pasted line. For multi-selections that happen to be rectangular, it happens as follows in Vim:

copy this:
a b
c d

paste into this (with cursor on or just after J):
E F G H
I J K L
M N O P

result:
E F G H
I J a b K L
M N c d O P

edge case when you paste off limits:
E F G H
I J K L
M N O P a b
        c d
(new lines and white spaces are spanned as necessary)

I don't see why having a "multi-cusor-sublime-ace model" would cause trouble implementing rectangular pasting. The Emacs behavior you described sounds to me like:

  1. delete previously selected text
  2. insert all ranges in the clipboard relatively to the pasting position

Does Emacs fit the pasted rectangular text into selected rectangle if their dimensions are different? Maybe that would be a little more tricky.


Reply to this email directly or view it on GitHub:
#778 (comment)

@marijnh
Copy link
Member

marijnh commented Dec 3, 2012

I just meant that you won't be able to simply use .replaceSelection(...) to do the rectangle-pasting. Also, there'd be some trickiness handling native paste events. If you have the text to be pasted and you can find out the selection, it is of course possible to implement arbitrary models of replacement.

@iclanzan
Copy link

iclanzan commented Jun 8, 2013

Please implement multiple cursors/selections. I find it extremely useful.

@notslang
Copy link

+1 ... where can I go to throw money at this?

@twiss twiss mentioned this issue Jul 6, 2013
8 tasks
@samuela
Copy link
Contributor

samuela commented Aug 9, 2013

+1 I would also highly recommend implementing Sublime Text's Cmd-D shortcut which adds the next occurrence of the selected string to the multi-selection. For example, if my file looks something like

" foo bar foo "

and I select the first "foo",

" foo bar foo "

now, hitting Cmd-D, I can easily select the next "foo"

" foo bar foo "

One of my favorite features in any text editor ever and it shouldn't be too tricky to implement once multi-select is working.

@notslang
Copy link

notslang commented Aug 9, 2013

+1 for "next occurrence selection" ... I use that all the time

Also, sublime's Ctrl +Shift+L to break up a selection into multiple selection by lines is really useful.

marijnh added a commit that referenced this issue Jan 16, 2014
marijnh added a commit that referenced this issue Jan 16, 2014
And fix example code in demo.

Issue #778
marijnh added a commit that referenced this issue Jan 16, 2014
marijnh added a commit that referenced this issue Jan 16, 2014
marijnh added a commit that referenced this issue Jan 16, 2014
marijnh added a commit that referenced this issue Jan 23, 2014
marijnh added a commit that referenced this issue Jan 23, 2014
marijnh added a commit that referenced this issue Jan 23, 2014
marijnh added a commit that referenced this issue Jan 23, 2014
marijnh added a commit that referenced this issue Jan 23, 2014
marijnh added a commit that referenced this issue Jan 23, 2014
marijnh added a commit that referenced this issue Jan 23, 2014
And fix example code in demo.

Issue #778
marijnh added a commit that referenced this issue Jan 23, 2014
marijnh added a commit that referenced this issue Jan 23, 2014
marijnh added a commit that referenced this issue Jan 23, 2014
@marijnh
Copy link
Member

marijnh commented Feb 19, 2014

(Oh, oops, it seems repeatedly rebasing a branch with issue-tagged commits isn't handled very gracefully by github. That's a lot of noise.)

Anyway, this is stable, and certain to be part of 4.0 (most likely to be released next month). Closing.

@gingersoulrecords
Copy link

I'm not sure if anyone said 'thanks' to @marijnh for doing this all these years ago.

From someone who is benefiting from it now, thanks Marijn.

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