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.IsViewEOL = false;
scriptedit.IsVScrollBar = true; scriptedit.IsVScrollBar = true;
scriptedit.SetFoldFlags((int)ScriptFoldFlag.Box); scriptedit.SetFoldFlags((int)ScriptFoldFlag.Box);
scriptedit.TabWidth = 4;
// Symbol margin // Symbol margin
scriptedit.SetMarginTypeN(0, (int)ScriptMarginType.Symbol); scriptedit.SetMarginTypeN(0, (int)ScriptMarginType.Symbol);
@ -229,6 +230,7 @@ namespace CodeImp.DoomBuilder.Controls
scriptedit.CaretPeriod = SystemInformation.CaretBlinkTime; scriptedit.CaretPeriod = SystemInformation.CaretBlinkTime;
scriptedit.CaretFore = General.Colors.ScriptBackground.Inverse().ToColorRef(); scriptedit.CaretFore = General.Colors.ScriptBackground.Inverse().ToColorRef();
scriptedit.StyleBits = 7; scriptedit.StyleBits = 7;
scriptedit.TabWidth = 4;
// This applies the default style to all styles // This applies the default style to all styles
scriptedit.StyleClearAll(); scriptedit.StyleClearAll();
@ -550,7 +552,7 @@ namespace CodeImp.DoomBuilder.Controls
scriptpanel.Height = this.ClientSize.Height; scriptpanel.Height = this.ClientSize.Height;
} }
} }
// Key pressed down // Key pressed down
private void scriptedit_KeyDown(object sender, KeyEventArgs e) private void scriptedit_KeyDown(object sender, KeyEventArgs e)
{ {
@ -615,6 +617,21 @@ namespace CodeImp.DoomBuilder.Controls
int highlightstart = 0; int highlightstart = 0;
int highlightend = 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(); UpdatePositionInfo();
// Call tip shown // Call tip shown