SyntaxEditor vNext Multiple Selection Pasting

by Avatar Bill Henning (Actipro) - 2 comments
Thursday, August 2, 2018 at 3:34pm

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 (codenamed vNext) is being made to bring all three platforms onto the same codebase for easier updating moving forward, and to enhance features wherever possible.

As described in recent blog posts, we've been working on adding multiple caret/selection support to SyntaxEditor in vNext.  In this post, I'd like to show off a neat new feature related to copying/pasting text when there are multiple selections.

Pasting Demo

At the start of this animation, I do a line copy, which occurs when there is no selection and you press Ctrl+C.  Then I paste that line in three times.

Next I select the text "Actipro," then Ctrl+select the text "SyntaxEditor," and finally Ctrl+select the text "vNext."  The Ctrl+selections have allowed me to create three selections.  At this point I could type and it would replace each of those selections with what I typed.  Instead, I'm going to press Ctrl+C again to copy the selected text.

2018-08-02_11-15-36

When I copy multiple selections, each selection's text is appended together and delimited by a line terminator.  So if you would paste what I copied into Notepad, it would paste as:

Actipro
SyntaxEditor
vNext

In the animation, the next thing I do is put a caret in each of the three empty strings by Ctrl+clicking in them.  We just added some new vNext logic that will compare the number of selections with the number of lines in the pasted text.  When they are equal, as they are in this demo, each line in the pasted text will get pasted into the related selection.  The end result is you can see how each of the three selections I originally copied end up in a separate target selection.

Summary

Multiple caret/selection support touches many portions of the editor and we are continuing to work through updating all feature areas to support it.

Let us know what you think in the comments.

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 (2)

Posted 6 years ago by (Anonymous)
Avatar
Hi, this looks amazing, but I'm wondering about implementing this into existing solutions. Are there any possible code conflicts? For example does this changes the existing selected text property or caret position property? Or do you plan to have additional properties for the virtual caret?
Posted 6 years ago by Bill Henning (Actipro) - Actipro Software LLC
Avatar
Hello, We thought of that and basically kept all the view.Selection properties the same. All of them will only affect the "primary" selection, which is the last one added. We added a view.Selection.Ranges property that gets you access to all the selections (including additional ones beyond the primary one). The view.SelectedText property continues to only get the primary selection's text. Programmatic text changes (making an ITextChange) will only apply to the primary selection by default unless you specify a new option flag. Our edit actions (we are still porting them) will generally specify that flag so they are compatible with all selection ranges. Also our view.ReplaceSelectedText method will apply to all selections. We think the design above keeps selection logic compatible with old versions, while also introducing the new multiple selections in a reliable way.

Add Comment

Please log in to a validated account to post comments.