Script editor now keeps same line indentation as previous line when ENTER is pressed

This commit is contained in:
codeimp 2009-02-11 14:20:07 +00:00
parent 66ef82efb9
commit 01ad6d9ec9

View file

@ -121,6 +121,7 @@ namespace CodeImp.DoomBuilder.Controls
scriptedit.IsViewEOL = false;
scriptedit.IsVScrollBar = true;
scriptedit.SetFoldFlags((int)ScriptFoldFlag.Box);
scriptedit.TabWidth = 4;
// Symbol margin
scriptedit.SetMarginTypeN(0, (int)ScriptMarginType.Symbol);
@ -229,6 +230,7 @@ namespace CodeImp.DoomBuilder.Controls
scriptedit.CaretPeriod = SystemInformation.CaretBlinkTime;
scriptedit.CaretFore = General.Colors.ScriptBackground.Inverse().ToColorRef();
scriptedit.StyleBits = 7;
scriptedit.TabWidth = 4;
// This applies the default style to all styles
scriptedit.StyleClearAll();
@ -615,6 +617,21 @@ namespace CodeImp.DoomBuilder.Controls
int highlightstart = 0;
int highlightend = 0;
// Enter pressed?
if((e.KeyCode == Keys.Enter) && (e.Modifiers == Keys.None))
{
// Get the current line index and heck if its not the first line
int curline = scriptedit.LineFromPosition(scriptedit.CurrentPos);
if(curline > 0)
{
// Apply identation of the previous line to this line
int ident = scriptedit.GetLineIndentation(curline - 1);
int tabs = ident / scriptedit.TabWidth;
scriptedit.SetLineIndentation(curline, ident);
scriptedit.SetSel(scriptedit.SelectionStart + tabs, scriptedit.SelectionStart + tabs);
}
}
UpdatePositionInfo();
// Call tip shown