Ticket T1287229
Visible to All Users

Cursor/selection changes after inserting text with insertText method

created 12 days ago

Hi,

using insertText method to insert text on position that is before (lower numeric value) cursor position causes cursor to move to different place in text. Numeric value of cursor position does not change, but after inserting text it points to different place in text and looks like selection has been changed.

For example, lets say we have simple document with increasing numbers (selection is marked with bold):
123456789

If we select number 9 then selection interval will be: { start: 8, length: 1 }

Now after insertText(0, 'text') text will be changed to:
text123456789

But selection interval stays the same: { start: 8, length: 1 } and now it points to number 5, so from users perspective selection changes from number 9 to number 5.

I would expect that selection interval will be adjusted so the same text will remain selected after inserting text or alternatively cursor will be moved to end of inserted text.

Similar problem occurs when Undo is performed for text inserted by insertText, selection "moves" in opposite direction, closer to end of document.

Thank you

Answers approved by DevExpress Support

created 12 days ago

Hello,

Thank you for contacting us.

You can handle OnContentInserted and OnContentRemoved events to change the selection after content is changed. Use the setSelection method to modify RichEdit's selection in the event handlers.

JavaScript
var selectionLength = 0; function OnContentInserted(s, e){ if (e.interval.start <= s.selection.start){ var newInterval = new DevExpress.RichEdit.Interval(s.selection.start + e.interval.length, s.selection.end - s.selection.start); s.selection.setSelection(newInterval); } } function OnContentRemoved(s, e){ if (e.interval.start <= s.selection.start){ var newInterval = new DevExpress.RichEdit.Interval(s.selection.start - e.interval.length, selectionLength); s.selection.setSelection(newInterval); } } function OnSelectionChanged(s, e){ selectionLength = s.selection.end - s.selection.start; }

Please let me know if this solution meets your requirements.

    Disclaimer: The information provided on DevExpress.com and affiliated web properties (including the DevExpress Support Center) is provided "as is" without warranty of any kind. Developer Express Inc disclaims all warranties, either express or implied, including the warranties of merchantability and fitness for a particular purpose. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.

    Confidential Information: Developer Express Inc does not wish to receive, will not act to procure, nor will it solicit, confidential or proprietary materials and information from you through the DevExpress Support Center or its web properties. Any and all materials or information divulged during chats, email communications, online discussions, Support Center tickets, or made available to Developer Express Inc in any manner will be deemed NOT to be confidential by Developer Express Inc. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.