Page MenuHome

Multi-Cursor Text Editing
Needs ReviewPublic

Authored by Marcelo Mutzbauer (1xundoredo) on Aug 31 2015, 4:19 PM.



Users of Sublime Text might already be familiar with this concept.

NOTE: When talking about cursors, I'm referring to text cursors(not mouse cursors).

Multiple cursors allow actions to be done in multiple places at once. These include insertion, deletion and replacement of characters or text.
As is well known, a cursor can be set by clicking onto the desired position in the text. Dragging the mouse while holding the mouse-button pressed results in a selection being made from the initial clicking point to the final position when the button is released. With this patch, a new cursor or selection can be added by holding CTRL while doing the operation. Same has been implemented for double-clicking(select word).
Selections and cursors can also be removed. This is done by CTRL-clicking the selection or cursor to get rid off. (Not sure how other editors like Sublime do this, but this seems good enough for an initial implementation)

Diff Detail

rB Blender

Event Timeline

Marcelo Mutzbauer (1xundoredo) retitled this revision from to Multi-Cursor Text Editing.Aug 31 2015, 4:19 PM
Marcelo Mutzbauer (1xundoredo) updated this object.
Marcelo Mutzbauer (1xundoredo) set the repository for this revision to rB Blender.
Marcelo Mutzbauer (1xundoredo) updated this object.
Marcelo Mutzbauer (1xundoredo) updated this revision to Diff 4984.

Hi @Marcelo Mutzbauer (1xundoredo), this patch is obviously quite some effort to support this feature.

However with the current maintainers we have, I'm wary or having to support too many features here.
Just having a simple fixed with text editor work with unicode, IME & syntax highlighting... has already been a bit of work to maintain (from time to time).

On the other hand. If your writing this feature and willing to maintain it, fix bugs etc.
Then its not necessarily giving us more work to do either.

Would like some feedback from other devs here... but my sense is this is making the text editor code over-complicated, beyond what we can reasonably maintain - longer term.

Taking a step back, it may be better to rewrite the editor component (probably drawing can remain the same...), So we can add more advanced features, without getting ourselves into a mess with overly complicated code all over the place.

Tested the patch, it crashes on adding template text, see Text -> Templates -> Python -> UI Menu.

Attached asan output.

Also crashes when typing with 2x cursors on the same line (entering text and backspacing).

Marcelo Mutzbauer (1xundoredo) updated this revision to Diff 4986.
  • Fixed backspace with 2 cursors on the same line(forgot to update columns of cursors right to a deleting cursor)
  • Fixed template loading crash(typo; freed Text instead of the TextSelection array)
  • Fixed crash when setting a single cursor with multiple cursor already placed(Freed TextSelection array before reallocing it)

Checked again, its much more stable now. Though its crashing for me when selections overlap (Its possible to get 2+ cursors occupying the same space when pressing Delete).

@Campbell Barton (campbellbarton) Sorry, can't reproduce. Maybe this only happens when the selections are in a certain position . . . Could you attach a screenshot before the crash happens?
Also, intersecting selections should be unified when the operator finishes(in txt_merge_sels(text)), so that might be a bug too(haven't discovered any problems when testing though)

@Marcelo Mutzbauer (1xundoredo), it wasn't hard to redo, just add a lot of cursors and start removing text, they will overlap at some point. You can tell they overlap since when you start typing again - many characters are added from the one place.

While its good to show that this can be done (by fixing issues with the patch), I'm still wary of over-complicating our text editor, especially when we don't have active maintainers there.

Also - for more serious development, many users run an external editor anyway. So I'm not convinced its best use of our time to attempt to compete with some of the more advanced, dedicated text editors.

Okay, fixed it(problem with cursor column updating). Will update patch soon.
As for maintenance, I do agree that supporting this is a bit overkill and time is much better spent in other areas. Not sure how to proceed.

Marcelo Mutzbauer (1xundoredo) updated this revision to Diff 4990.
  • Fix cursor column updating when deleting text

It could be worth having integrated, its an editor engine which supports multiple drawing front-ends (and has multiple selection).

This has been worked on T37714, but the patch was just doing the full Blender -> Scintilla conversion for every redraw.

I feel quite mixed about accepting patches to the Text Editor in Blender. Reasoning behind this is that we don't have strong maintainer in that are to help with all possible issues in it (and there are issues in there). And on another hand i don't mind if Blender's editor gets improved.

So think reasonable statement here will be: if you're gonna to be around after this patch is landed to master to further keep improving or fixing text editor then i feel positive about accepting this patch.

Hi @Marcelo Mutzbauer (1xundoredo), how about this?

Since we don't have so much time to maintain the text editor, we propose you to become the new maintainer.

You can have a branch for this work, to finish the patch, but there is also some added responsibility to make some fixes to other areas (bugs are reported every so often).

Once the patch is done we can do some final review, and it can go into master. But we would expect some continued work in this area (again, not a lot, just to make sure its working well).

If this doesn't work out, or you don't end up having time, then we may revert this patch... though thats a decision to be made later, if at all.

Looking at Scintilla, though I think it might be a useful thing, if the text editor is planned to be rewritten it might be a bad idea to do the thing twice. Took a look at the github repo, it seems like Scintilla is implemented in C++ and there is a wrapper to interface with the C code and do the drawing? I'm not sure about this, but making Scintilla work with Blender's DNA/RNA structure and C architecture might be more of hassle than just rewriting the entire thing from scratch. Plus, we might then have less trouble keeping everything in sync with their additions/fixes/improvements or providing more functionality on our own. I don't know. (Then again, Scintilla looks really powerful and we might not even have to do that)
When it comes to maintenance, I don't know if I'm familiar/experienced enough with Blender's codebase.
As it currently stands, the text editor is not really likely to be used by a developer. Working with file and especially directory structures is just a HUGE mess. As long as that problem is not addressed, developers probably won't consider writing their scripts in Blender itself. So functionality like this one might not really be interesting to anyone.
With the branch, does that mean that I should also make other improvements in the branch or should I be adding them after the merge?

Regarding the branch, I was suggesting this patch could be finished in a feature-branch. Which is a bit nicer then updating this patch (longer running projects. The merge with master would happen later, once the branch was reviewed and accepted.

  • Forgot calling selection unification code in word selection operator
  • Cleaned up selection unification code(txt_merge_sels(text))

Where would communication take place(In this differential? Somewhere else?)
Should fixes unrelated to this feature(e.g. weird scrollbar behavior) be done in the branch?

  • Patch can be applied to latest master again

Where would communication take place(In this differential? Somewhere else?)

You could mail bf-funboard & bf-python.

Should fixes unrelated to this feature(e.g. weird scrollbar behavior) be done in the branch?

No, for that just have another branch (mixing different developments in branches is generally problematic and makes it harder to review work).

Are you interested to have commit access to work on the text editor?

Marcelo Mutzbauer (1xundoredo) updated this revision to Diff 5256.
  • Update for latest master
  • Fix crash when reading in old files containing Texts
  • Fix crash when reading in new files created with patched build
  • Minor cleanup
  • Call txt_merge_sels in delete operator
  • Code-Style:
    • rename text->n_sels to text->nsels
    • post-increment in for loop