How to replace selected text of a selected rectangle?
I wrote a plugin that should format some selected text.
If the selection is a complete line I can use SCI_REPLACESEL to insert the modified text.
What do I have to do, if I want to replace the text of a selected rectangle?
Thanks in advance
You have to take a more manual approach to it using other (“lower-level”) SCI_ functions for getting selections and replacing text. If that isn’t enough of a help for you, post again requesting more details.
thanks for your answer, but unfortunately it doesn’t help me.
Before I posted my question here, I took a look at the Scintilla Documentation.
I wrote a plugin library that reads the selected text -> SCI_GETSELTEXT
This works fine, with all selection kinds.
If I select a rectagle, e. g. a column, I get a multiline text with linebreaks.
Now, my formatting function modifies this text.
After this modification I need to replace the selected text of the document.
I tried SCI_REPLACESEL, but this inserts the text with the linebreaks at the fist position of the selection.
So, not the selected rectangle will be replaced.
How can I replace the text of a selected rectangle?
I understand the desire for it to be simple for the rectangular column selection case, but it is important that you understand why it is not so, and thus why there is no simple 2-step get-selection and replace-selection for this.
Let me first ask you some questions about what you are doing:
- Does the initially selected rectangular block ever have any virtual space in it?
- Are all of the lines/rows in the rectangular block you are replacing with of the same length (same number of columns for each line; note that it is fine if this is different from the number of columns in the initial selection)?
- Does the rectangular block you are replacing with always have the same number of lines/rows as the initially selected rectangular block?
[Maybe these questions will get you thinking along the lines of why this can be a difficult thing to do…]
If the answers are “no”/“yes”/“yes” then the situation is “fairly” simple, and I can describes some possible ways to implement (but let’s have those answers first). We can of course discuss the cases where the answers aren’t “no”/“yes”/“yes”, but the complexity increases. :-)