Recent

Author Topic: KMemo: How to Surround a selected text with curly braces?  (Read 914 times)

EganSolo

  • Sr. Member
  • ****
  • Posts: 395
KMemo: How to Surround a selected text with curly braces?
« on: April 21, 2023, 10:23:18 am »
Use case: the user selects some text inside a KMemo. The user clicks a button and the text which was selected is now surrounded by curly braces. If the selection is empty, then a pair of curly braces surrounding a single blank character is inserted at the cursor and the cart is moved between them.

To solve this I need
  • The Starting line and column and ending line and column of the selected text.
  • The ability to insert text before the starting column and after the ending column
  • The ability to deselect the text
  • The ability to move the caret either after the right curly brace or between the pair of braces.

From what I've read so far, there may be different ways of doing this, none of which is completely clear to me:
  • I could use SelectedText.Top to find the start of the selection but there does not seem to be an equivalent SelectedText.Bottom so how do I find the end of the selection?
  • There is a RealSelStart and RealSelEnd which are indices. But are they block indices? If not, what kind of indices they are? Also, how could I use them to insert text before the start of the selection and after its end?

As you can see, I'm not really clear on how to do this. If someone could point me in the right direction, and if there is enough viewing interest, I would write a small demo and post it back.

 

TinyPortal © 2005-2018