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

Add multi-cursor support [WIP] #83

Closed
wants to merge 4 commits into from

Conversation

bentranter
Copy link

Hey everyone, here is a functional but fairly limited PR to support multiple cursors in micro.

Short demo: asciicast

What's changed:

When Ctrl-N is typed outside of an active search (ie, a search started by using the Ctrl-F shortcut), the word under the cursor is selected. On every subsequent press of Ctrl-N, a new cursor will be added for every match, and each match will be highlighted. To leave multi-cursor mode, the user can just type escape, or can click anywhere inside the terminal.

What still needs work:

  1. Making sure the editor doesn't crash. There are some bugs to work out around making sure it's impossible to get an out-of-bounds error when using multiple cursors.
  2. Informing the user they're in multi-cursor mode. This could be done in two ways - either by displaying something that says "Multi-cursor mode active with x cursors, or by figuring out how to show each individual cursor. Tcell seems to only have support for one cursor, but it might be possible to fake it visually.
  3. Not adding duplicate cursors. Right now, for each every match, a new cursor will be added, even if that cursor has already been added. Shouldn't be too hard to figure out, I had a half-working solution earlier but I wanted to make this PR asap so I didn't finish that solution.

Since there are still kinks to work out, I added an option for multicursor defaulted to false, so users won't run into unexpected trouble. I just wanted to make this PR since it's very difficult to keep this branch in a state where there aren't merge conflicts (like there are now), since the changes to make Cursor become []Cursor are so widespread and seem to be the main source of conflicts.

Anyway, sorry for writing a novel - let me know what you think of this. I'll fix the conflicts if you're interested in having this merged at this point in time. Also, this will close #5 when merged.

@zyedidia
Copy link
Owner

Wow, this looks pretty good. I think that it needs to be rebound from CtrlN because now the next functionality is gone. Perhaps CtrlD is better because that's what Sublime Text uses. I realize that CtrlD is already bound, but half page down can easily be bound to another key.

Undo seems to work very nicely with the multiple cursors.

I think the main issue is selecting the same words multiple times which creates multiple ursors in the same place. I noticed this causes the editor to crash sometimes when inserting text.

Also it should be very easy to fake visual cursors by just rendering a default style column at the cursor location.

For example, replace cursor.go:367 with

screen.SetContent(c.GetVisualX()+c.v.lineNumOffset-c.v.leftCol, c.y-c.v.topline, c.RuneUnder(c.x), nil, tcell.StyleDefault.Reverse(true))

You also have to make sure to loop over the cursors in the view's display function and display each cursor, but it looked pretty good when I tried it.

@bentranter
Copy link
Author

👍 thanks for the feedback! Remapping this to CtrlD sounds good since most users will probably expect that. I'll keep working on this over the next few days to address the issues you mentioned, and I'll ping you in this PR once that's done.

@zyedidia
Copy link
Owner

This PR hasn't had any activity in quite a while, and there are so many merge conflicts at this point (this branch is 345 commits behind master) that I think it's best to close the PR. Multiple cursors will be a feature I try to implement soon anyway, if nobody else makes a new PR first.

@zyedidia zyedidia closed this Aug 29, 2016
@CamilleScholtz
Copy link
Contributor

rip :^(

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

Successfully merging this pull request may close these issues.

Multiple cursor support
3 participants