Re: [scintilla] implementing auto-Indent in Scintilla ? ... .NET WinForms

509 views
Skip to first unread message
Message has been deleted

Lex Trotman

unread,
Aug 11, 2015, 3:27:54 AM8/11/15
to scintilla...@googlegroups.com
On 11 August 2015 at 14:51, BillWoo <therealu...@gmail.com> wrote:
> Hi, This is my first post about Scintilla, and I'd like to start by thanking
> the authors, and this community, for a remarkable resource !
>
> I've searched to see if anyone has implemented auto-indent-by-tabs, and the
> only thing I found was a reference to Scintilla as used in "Zeus" something
> or other; I couldn't locate any usable code, or relevant discussions.
>
> If you know of existing code to implement auto-indent, I'd appreciate a
> link.
>
> My initial experiments in implementing auto-indent:
>
> 1. verified that executing that run-time execution of the code:
>
> private char tab = '\t';
>
> private void button1_Click(object sender, EventArgs e)
> {
> scintilla1.InsertText(-1, Tab);

The documentation on INSERTCHECK says "Text is about to be inserted.
The handler may change the text being inserted by calling
SCI_CHANGEINSERTION. No other modifications may be made in this
handler." so you can't run this in the insert check.

> }
>
> in a Button Click EventHandler works as expected.
>
> 2. then I implemented a simple facility to keep track of the number of tabs
> on the previous line, and tried to use the Scintilla 'InsertCheck method to
> modify the text when a new line was entered so the correct number of tabs
> was prefixed to the new line:
>
> a. I observe an unusual behavior:
>
>
> 1. the first line entered would be prefixed with the correct number of tab
> characters, but the second, and each alternating line would be prefixed with
> twenty-one tab characters.
>
>
> 2. that, of course, suggests some form of recursion, but stepping through
> the code, there's no evidence of recursion.
>
>
> On request, I'll post the full code, but, perhaps, there is already a simple
> explanation for what I observe.
>
> thanks, Bill
>
> --
> You received this message because you are subscribed to the Google Groups
> "scintilla-interest" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to scintilla-inter...@googlegroups.com.
> To post to this group, send email to scintilla...@googlegroups.com.
> Visit this group at http://groups.google.com/group/scintilla-interest.
> For more options, visit https://groups.google.com/d/optout.
Message has been deleted

michael.s...@gmail.com

unread,
Aug 11, 2015, 9:25:08 AM8/11/15
to scintilla-interest
You can modify the text, but you must use SCI_CHANGEINSERTION. You can't use any other modification method. Pseudo-code for my auto-indent is as follows if it helps.

if (modificationCode = SCN_MODIFIED) and (modificationType = SC_INSERTCHECK) {
    if (textToInsert = carriageReturn) or (textToInsert = lineFeed) or (textToInsert = carriageReturnLineFeed) {
        Indent := GetLineAutoIndentation; // Calculate the auto indent this line requires based on the indent of previous lines
        ChangeInsertion(textToInsert + Indent);
    }
}

Michael


On Tuesday, August 11, 2015 at 3:51:46 AM UTC-4, BillWoo wrote:
Lex Trotman wrote: 

"The documentation on INSERTCHECK says "Text is about to be inserted. 
The handler may change the text being inserted by calling 
SCI_CHANGEINSERTION. No other modifications may be made in this 
handler." so you can't run this in the insert check."

Thanks, Lex, I based my use of InsertCheck on the .NET documentation here:


Which states: "Changes made by a user to the text can be observed, but not modified--with one exception. The InsertCheck event occurs before text is inserted (and earlier than the BeforeInsert event) and is provided for the express purpose of giving you an option to modify the text being inserted. This can be used to simply cancel/prevent unwanted user input. Or in more advanced situations, it could be used to replace user input."

My reading of that documentation suggests InsertCheck should be usable to modify text before it is appended to the Document.
Reply all
Reply to author
Forward
Message has been deleted
0 new messages