Interest in SyntaxEditor Multiple Caret/Selection Features?

by Avatar Bill Henning (Actipro) - 9 comments
Tuesday, February 20, 2018 at 4:02pm

BlogPostBanner-SyntaxEditor-DevNotes

As mentioned in a previous post, we have been working on refactoring the core internal implementation of our SyntaxEditor code editor control on the WPF, UWP, and WinForms platforms.  This effort is being made to bring all three platforms onto the same codebase for easier updating moving forward, and to enhance features wherever possible.

As we continue development of SyntaxEditor vNext, we are getting into porting in the caret/selection feature area.  We've seen a couple newer editors support the concept of multiple carets/selections and would like to get some feedback on if this is a desired feature by our customers.  This is different than the rectangular box selection feature we currently already support.

Rectangular Box Selection

Rectangular box selection is already supported in SyntaxEditor and looks like this:

SyntaxEditorBoxSelection

When this selection is active, you can type and it will enter text at the same column on each line.  You can also copy box-selected text and when it's pasted, it will retain the box layout.  This is a very handy and powerful feature.

Multiple Carets/Selections

Now what happens if you want to make multiple updates but not necessarily in the same column.  Let's take a look at a scenario:

SyntaxEditorMultiScenario

In the screenshot above, the caret is next to a Write method call.  Let's say we want to update all the Write method calls to be WriteLine instead.  We could change it once and copy/paste it to the other locations.  But if we had multiple caret support, you could throw a caret at the end of each of the four Write method calls (in various columns) and simply type Line to update all of them.

One implementation of this I saw used Alt+Click to add carets.  I don't personally like this because Alt is used as a system menu accelerator and causes issues like underlines to appear in menus if you Alt+Click

Another implementation of this used Ctrl+Click to add carets.  That seems better since it won't run into the system menu accelerator issue.  The downside is that Ctrl+Click is currently used in SyntaxEditor (and Visual Studio's code editor) to do quick word selection.  Thus we'd need to rework some of our existing keyboard shortcuts to accommodate new features.

Both these implementations also use Ctrl+U as a way to undo the last selection change, whereas SyntaxEditor and VS currently tie that keyboard shortcut to making selected text lowercase.

Summary

Let's hear from you… is the multiple caret/selection feature something you'd like to see?  How would you prefer to see the keyboard shortcuts adjusted to accommodate new features?

Actipro's WPF Controls

Over 100 UI controls for building beautiful Windows Presentation Foundation desktop apps.

Learn More

Over 100 UI controls for building beautiful Windows Presentation Foundation desktop apps.

Includes editors, docking windows, MDI, property grids, charts, tree controls, ribbons, gauges, themes, and much more.

Learn More Download Free Trial

Comments (9)

Posted 1 year ago by James Sconfitto - Exele Information Systems, Inc.
Avatar
I'm a big fan of multiple selections and carets after learning them from VsVim and then the Atom/VSCode editors. Multiple carets combined with edits and delete-(next/previous) word can save a lot of time! Ctrl+Click makes the most sense to me, though I didn't know that's what VS does. What about double-clicking a word to highlight it instead? Is that already bound somewhere else?
Posted 1 year ago by Bill Henning (Actipro) - Actipro Software LLC
Avatar
Good point, the double-click to select a word is the same as Ctrl+Click, so we could effectively lose current Ctrl+Click functionality and change that sequence to toggling extra carets. BTW, since writing the above, I also noticed that VS Code has an option that switches Alt+Click to Ctrl+Click instead. It seems that Alt+Click ran into problems on certain platforms.
Posted 1 year ago by Malcolm Stockham
Avatar
I'm not a big user of multiple carets, but I can see how they might be useful from time to time. I would like to comment that Ctrl+Click is quite commonly used to "Navigate to definition" (also on F12 in VS/vscode). This always used to be a VS PowerTools (or ReSharper) feature but has recently made it into the Visual Studio as standard (Options -> Text Editor -> General -> Enable mouse click to perform Go To definition). Where applicable, it seems to override the Ctrl+Click to select word feature that I wasn't previously aware of! I have this enabled almost everywhere I can (I think I first encountered it in the Delphi IDE) - and far more so than multiple caret editing. One similar (and handy) feature that the Delphi IDE did have that I've not really seen elsewhere is one where you could make a selection, invoke a "synchronized edit" mode and change all instances of a particular identifier simultaneously - a bit like a automatic find and replace. I've just found a better description in the docs here: http://docwiki.embarcadero.com/RADStudio/Tokyo/en/SyncEdit_(IDE_Tutorial).
Posted 1 year ago by Erel Uziel
Avatar
In our implementation we are using Ctrl + Click to "navigate to definition". This is the standard in many editors and it is very convenient. BTW, we also support identifier renaming: https://www.b4x.com/android/forum/attachments/rename-gif.53634/ Personally I never used a feature similar to the one you describe. I'm not sure whether we will enable such feature as there are many cases in our code where we assume that there is exactly one caret in the editor.
Posted 1 year ago by Mike Dempsey - Sr. Developer, Teradata Corp
Avatar
I don't see any real need for multiple carats. In your scenario you could simply select the block containing all the Write methods and use Replace All to do what you did just as quickly. I can see there might be other cases with a better use case but I think this is a very low frequency requirement. I also support Erel's point - there are many cases in our code where we use the 'current' position of the carat. If there were multiple 'current' positions that could cause problems.
Posted 1 year ago by Bill Henning (Actipro) - Actipro Software LLC
Avatar
Thanks for the feedback everyone, this is helpful... keep it coming! From what we are gathering from here and around the web on forums for other editor apps, people either love it or never use the multiple caret feature. There are also a lot of people very passionate about the block (box) selection feature we already support. It seems like if we added multiple carets, we'd need to allow the modifier key for adding them to be configurable (so as to not conflict if you set up Ctrl+Click with something navigate to definition), and would need to make sure the selection API still clearly indicated the normal properties for the primary selection for use in the status bar, etc. Any additional selections would be accessible via new API.
Posted 1 year ago by (Anonymous)
Avatar
I was reallly looking forward to a "rename all instances" feature similar to VS editor. You select a word, press F2 and type the new word and it automatically renames all instances as you type. This works on pretty much everything not only method calls. But sadly it seems your editor does not support something like that out of the box. Is this the same then your multiple carets or something different?
Posted 1 year ago by Bill Henning (Actipro) - Actipro Software LLC
Avatar
F2 to rename in VS is typically a refactoring feature that is a lot more complex than basic word renaming, because it also considers the scope of whatever the identifier is within the document. Meaning if you rename a variable, it only affects the current method and not other instances in the same document. If we added the multiple caret/selection feature and added the ability to select all instances of the current word under the caret, then it would allow for a "renaming all instances" kind of functionality, but wouldn't be scope-dependent.
Posted 1 year ago by JesperTreetop
Avatar
The "renaming all instances" functionality would also need to be able to be intercepted, since it could be of an identifier or function visible from other files and you would want to rename those things too (or the file name itself). I'm still hoping for Roslyn support. It would mean you could hook into the full ecosystem of refactorings and continually be up-to-date with the evolving language standards. SyntaxEditor would still be a really good enlightened text editor component.

Add Comment

Please log in to a validated account to post comments.