Working with Smart Indent

Topics: User Forum
Nov 1, 2009 at 10:22 AM

Hello,

If I make a fresh project and add this callback

private void scintilla1_CharAdded(object sender, ScintillaNet.CharAddedEventArgs e)
        {
            if (e.Ch == '\r')
            {
                scintilla1.InsertText("       ");
            }
        }

 

everytime I press enter it adds some spaces. That's good, that's what I'm after!

Enabling

this.scintilla1.Indentation.SmartIndentType = ScintillaNet.SmartIndent.Simple;

Stops the above callback from working, no text is inserted.

 

However change the callback to

private void scintilla1_CharAdded(object sender, ScintillaNet.CharAddedEventArgs e)
        {
            if (e.Ch == '\r')
            {
                scintilla1.InsertText("_____");
            }
        }

 

And it works fine in both.

 

I would like to be able to use smart indent, and now again insert some spacing information. What's the best way to go about this?

Thanks!

-Dan

Coordinator
Nov 2, 2009 at 7:10 PM

In ScintillaNet Inside Indentation.cs line 214

Change

Line curLine = Scintilla.Lines.Current;
curLine.Indentation = curLine.Previous.Indentation;
Scintilla.CurrentPos = curLine.IndentPosition;

to

Line curLine = Scintilla.Lines.Current;
if (!string.IsNullOrEmpty(curLine.Text))
    return;
curLine.Indentation = curLine.Previous.Indentation;
Scintilla.CurrentPos = curLine.IndentPosition;

Or you can set the indentation type to none and integrate the above lines into your event handler.

Nov 4, 2009 at 8:46 PM

Thanks Chris, that works great!