How do you delete text in a ScintillaNET?

Topics: Developer Forum, User Forum
Mar 31, 2014 at 4:51 AM
I tried using the recommended method:

scintilla.GetRange(0, nTrimLength).Text = "";

But it doesn't seem to do anything. How do I delete?
Mar 31, 2014 at 8:45 PM
Edited Mar 31, 2014 at 8:46 PM
Ok I figured this one out too. Combination of weird behavior and a bug.

scintilla.GetRange(0, nTrimLength).Text = ""; does delete the text, but NOT if the ReadOnly attribute is true.

BUT, when you call ReplaceTarget, even though no text is replaced, it still returns the "number of characters replaced" as the number of characters you wanted to replace. So it makes you think it worked, but it didn't. This is just odd and I would consider this to be a bug.

So to handle it I just wrote up a DeleteRange method that removes the readonly attribute and re-adds it if necessary. This really shouldn't be necessary though imo.
Apr 2, 2014 at 3:16 AM
Actually, everything you just described is working "as designed".

The ReadOnly property will prevent any updates to the document--even programmatic updates. In that respect it is a bit different from say the TextBox.ReadOnly property because that only prevents user updates, not programmatic ones.

The ReplaceTarget method is a fairly thin wrapper around the native SCI_REPLACETARGET Scintilla function. Quoting from the Scintilla documentation:
After replacement, the target range refers to the replacement text. The return value is the length of the replacement string. Note that the recommended way to delete text in the document is to set the target to the text to be removed, and to perform a replace target with an empty string.
Thus, if you think the behavior should be different you can take it up with the native Scintilla component developers. :)

Apr 2, 2014 at 10:54 AM
Ok, yeah that's strange... I would think you'd want to see the text replaced, not the length of the text you wanted to use to replace... I mean you have that already because it got passed into the function right? Haha... but I see your point about the native Scintilla intended functionality... thanks!