private void ExecuteAppendText(object sender, ExecutedRoutedEventArgs args) { string text = args.Parameter as string; if (text.Contains('\n')) { var lines = text.Split('\n'); int startRow = Pad.Cursor.Row + 1; foreach (string line in lines.Take(lines.Count() - 1)) { Pad.Cursor.Row += 1; Pad.InsertLine(Pad.Cursor.Row, line); } PushChange(new Remove(new Range(startRow) { EndRow = Pad.Cursor.Row, EndColumn = Pad.Lines[Pad.Cursor.Row].Text.Length, })); } else { int column = Pad.Cursor.Column < Pad.CurrentLine.Text.Length ? Pad.Cursor.Column + 1 : Pad.Cursor.Column; Pad.CurrentLine.Text = Pad.CurrentLine.Text.Insert( column, text); PushChange(new Remove(new Range(Pad.Cursor.Row) { StartColumn = column, EndColumn = column + text.Length })); Pad.Cursor.Column += text.Length; } }
private void ExecuteInsertNewline(object sender, ExecutedRoutedEventArgs args) { string nextLine = Pad.CurrentLine.Text.Substring(Pad.Cursor.Column); Pad.CurrentLine.Text = Pad.CurrentLine.Text.Substring(0, Pad.Cursor.Column); if (Pad.CurrentLine.Text.Contains(":")) { string maybeCommand = Pad.CurrentLine.Text.Split(':')[0]; int row = Pad.Cursor.Row + 1; bool addedParameters = false; if (Commands.IsCommand(maybeCommand)) { var parameters = Commands.GetParamaters(maybeCommand); foreach (var param in parameters) { Pad.InsertLine(row++, " " + param + ":"); addedParameters = true; } } if (!addedParameters || !String.IsNullOrWhiteSpace(nextLine)) { nextLine = " " + nextLine; Pad.InsertLine(row, nextLine); } } else { Pad.InsertLine(Pad.Cursor.Row + 1, nextLine); } Pad.Cursor.Row += 1; Pad.Cursor.Column = Pad.CurrentLine.Text.Length; }