public ScriptEditDialog(string text) : base("Script edit", "cde.ico", SizeToContent.Manual, ResizeMode.CanResize) { InitializeComponent(); Extensions.SetMinimalSize(this); AvalonLoader.Load(_textEditor); AvalonLoader.SetSyntax(_textEditor, "Script"); string script = ItemParser.Format(text, 0); _textEditor.Text = script; _textEditor.TextArea.TextEntered += new TextCompositionEventHandler(_textArea_TextEntered); _textEditor.TextArea.TextEntering += new TextCompositionEventHandler(_textArea_TextEntering); _completionWindow = new CompletionWindow(_textEditor.TextArea); _li = _completionWindow.CompletionList; ListView lv = _li.ListBox; lv.SelectionMode = SelectionMode.Single; //Image Extensions.GenerateListViewTemplate(lv, new ListViewDataTemplateHelper.GeneralColumnInfo[] { new ListViewDataTemplateHelper.ImageColumnInfo { Header = "", DisplayExpression = "Image", TextAlignment = TextAlignment.Center, FixedWidth = 22, MaxHeight = 22, SearchGetAccessor = "Commands" }, new ListViewDataTemplateHelper.GeneralColumnInfo { Header = "Commands", DisplayExpression = "Text", TextAlignment = TextAlignment.Left, IsFill = true, ToolTipBinding = "Description" } }, null, new string[] { }, "generateHeader", "false"); _completionWindow.Content = null; _completionWindow = null; WindowStartupLocation = WindowStartupLocation.CenterOwner; }
public void Complete(TextArea textArea, ISegment completionSegment, EventArgs insertionRequestEventArgs) { ISegment seg = AvalonLoader.GetWholeWordSegment(textArea.Document, _editor); textArea.Document.Replace(seg, Text); }
public ConvertItemIdsDialog() : base("Convert item IDs in text", "convert.png", SizeToContent.Manual, ResizeMode.CanResize) { InitializeComponent(); ShowInTaskbar = true; _tbSource.TextChanged += (e, a) => _updateDestination(); _tbSource.PreviewKeyUp += _onCloseKey; _tbDest.PreviewKeyUp += _onCloseKey; AvalonLoader.Load(_tbSource); AvalonLoader.SetSyntax(_tbSource, "Script"); AvalonLoader.Load(_tbDest); AvalonLoader.SetSyntax(_tbDest, "Script"); _tbSource.Text = Clipboard.GetText(); try { _citemsDb = SdeEditor.Instance.ProjectDatabase.GetMetaTable <int>(ServerDbs.CItems); } catch { _citemsDb = null; } }
private void _update() { if (!SdeAppConfiguration.IronPythonAutocomplete) { if (_completionWindow != null) { _completionWindow.Close(); } return; } // Open code completion after the user has pressed dot: if (_completionWindow == null || !_completionWindow.IsVisible) { if (_li.Parent != null) { ((CompletionWindow)_li.Parent).Content = null; } _completionWindow = new CompletionWindow(_textEditor.TextArea, _li); _completionWindow.Changed += new EventHandler(_completionWindow_Changed); _completionWindow.Closed += delegate { if (_completionWindow != null) { _completionWindow.Content = null; } _completionWindow = null; }; } RangeObservableCollectionX <ICompletionData> data = (RangeObservableCollectionX <ICompletionData>)_li.CompletionData; data.Clear(); string word = AvalonLoader.GetWholeWordAdv(_textEditor.TextArea.Document, _textEditor); List <string> words = PythonEditorList.Tables.Where(p => p.IndexOf(word, StringComparison.OrdinalIgnoreCase) != -1).OrderBy(p => p).ToList(); List <string> constants = PythonEditorList.Constants.Where(p => p.IndexOf(word, StringComparison.OrdinalIgnoreCase) != -1).OrderBy(p => p).ToList(); List <string> flags = FlagsManager.GetFlagNames().Where(p => p.IndexOf(word, StringComparison.OrdinalIgnoreCase) != -1).OrderBy(p => p).ToList(); if (words.Count == 0 && constants.Count == 0 && flags.Count == 0) { _completionWindow.Close(); return; } IEnumerable <ICompletionData> results = words.Select(p => (ICompletionData) new MyCompletionData(p, _textEditor, DataType.Function)). Concat(constants.Select(p => (ICompletionData) new MyCompletionData(p, _textEditor, DataType.Constant))). Concat(flags.Select(p => (ICompletionData) new MyCompletionData(p, _textEditor, DataType.Constant))); data.AddRange(results); _completionWindow.CompletionList.ListBox.ItemsSource = data; _completionWindow.Show(); _completionWindow.CompletionList.SelectedItem = _completionWindow.CompletionList.CompletionData.FirstOrDefault(p => String.Compare(p.Text, word, StringComparison.OrdinalIgnoreCase) >= 0); _completionWindow.CompletionList.ListBox.ScrollToCenterOfView(_completionWindow.CompletionList.SelectedItem); }
private void _update() { // Open code completion after the user has pressed dot: if (_completionWindow == null || !_completionWindow.IsVisible) { if (_li.Parent != null) { ((CompletionWindow)_li.Parent).Content = null; } _completionWindow = new CompletionWindow(_textEditor.TextArea, _li); _completionWindow.Changed += new EventHandler(_completionWindow_Changed); _completionWindow.Closed += delegate { if (_completionWindow != null) { _completionWindow.Content = null; } _completionWindow = null; }; } RangeObservableCollectionX <ICompletionData> data = (RangeObservableCollectionX <ICompletionData>)_li.CompletionData; data.Clear(); if (_skills == null) { _skills = new List <string>(); _skill_db = SdeEditor.Instance.ProjectDatabase.GetMetaTable <int>(ServerDbs.Skills); _skill_db.FastItems.ForEach(p => _skills.Add(p.GetStringValue(ServerSkillAttributes.Name.Index))); } string word = AvalonLoader.GetWholeWord(_textEditor.TextArea.Document, _textEditor); List <string> words = ScriptEditorList.Words.Where(p => p.IndexOf(word, StringComparison.OrdinalIgnoreCase) != -1).OrderBy(p => p).ToList(); List <string> constants = ScriptEditorList.Constants.Where(p => p.IndexOf(word, StringComparison.OrdinalIgnoreCase) != -1).OrderBy(p => p).ToList(); List <string> skills = _skills.Where(p => p.IndexOf(word, StringComparison.OrdinalIgnoreCase) != -1).OrderBy(p => p).ToList(); if (words.Count == 0 && constants.Count == 0 && skills.Count == 0) { _completionWindow.Close(); return; } IEnumerable <ICompletionData> results = words.Select(p => (ICompletionData) new MyCompletionData(p, _textEditor, DataType.Function)). Concat(constants.Select(p => (ICompletionData) new MyCompletionData(p, _textEditor, DataType.Constant))). Concat(skills.Select(p => (ICompletionData) new MyCompletionData(p, _textEditor, DataType.Skill))); data.AddRange(results); _completionWindow.CompletionList.ListBox.ItemsSource = data; _completionWindow.Show(); _completionWindow.CompletionList.SelectedItem = _completionWindow.CompletionList.CompletionData.FirstOrDefault(p => String.Compare(p.Text, word, StringComparison.OrdinalIgnoreCase) >= 0); TokeiLibrary.WPF.Extensions.ScrollToCenterOfView(_completionWindow.CompletionList.ListBox, _completionWindow.CompletionList.SelectedItem); }
private void _initBox(TextEditor box) { box.ShowLineNumbers = true; box.FontFamily = new FontFamily("Consolas"); AvalonLoader.Load(box); box.WordWrap = true; _realBox.AcceptsReturn = true; _realBox.AcceptsTab = true; }
public DbDebugDialog(SdeEditor editor) : base("Debug tables...", "warning16.png", SizeToContent.Manual, ResizeMode.CanResize) { InitializeComponent(); WindowStartupLocation = WindowStartupLocation.CenterOwner; Owner = WpfUtilities.TopWindow; AvalonLoader.Load(_textEditor); AvalonLoader.SetSyntax(_textEditor, "DebugDb"); Log = "Database: Debugger Started..."; DbDebugHelper.Cleared += delegate(object sender, ServerDbs primaryTable, string subFile, BaseDb db) { Log = String.Format("Table: {0}, Message: Table data cleared.", primaryTable); }; DbDebugHelper.ExceptionThrown += delegate(object sender, ServerDbs primaryTable, string subFile, BaseDb db) { Log = String.Format("Table: {0}, File: {1}, Message: An exception occured while reading the table, continuing.", primaryTable, _getPath(subFile)); }; DbDebugHelper.Loaded += delegate(object sender, ServerDbs primaryTable, string subFile, BaseDb db) { Log = String.Format("Table: {0}, File: {1}, Message: Table loaded.", primaryTable, _getPath(subFile)); }; DbDebugHelper.Saved += delegate(object sender, ServerDbs primaryTable, string subFile, BaseDb db) { Log = String.Format("Table: {0}, File: {1}, Message: Table saved.", primaryTable, _getPath(subFile)); }; DbDebugHelper.Update += delegate(object sender, string message) { Log = String.Format("Database: {0}", message ?? ""); }; DbDebugHelper.SftpUpdate += delegate(object sender, string message) { Log = String.Format("Sftp: {0}", message ?? ""); }; DbDebugHelper.Update2 += delegate(object sender, ServerDbs primaryTable, string subFile, BaseDb db, string message) { Log = String.Format("Table: {0}, File: {1}, Message: {2}", primaryTable, _getPath(subFile), message ?? ""); }; DbDebugHelper.WriteStatusUpdate += delegate(object sender, ServerDbs primaryTable, string subFile, BaseDb db, string message) { Log = String.Format("Table: {0}, File: {1}, Message: {2}", primaryTable, _getPath(subFile), message ?? ""); }; DbDebugHelper.StoppedLoading += delegate(object sender, ServerDbs primaryTable, string subFile, BaseDb db) { Log = String.Format("Table: {0}, File: {1}, Message: Table loading has been stopped due to too many errors.", primaryTable, _getPath(subFile)); }; }
public ScriptEditDialog(string text) : base("Script edit", "cde.ico", SizeToContent.Manual, ResizeMode.CanResize) { InitializeComponent(); AvalonLoader.Load(_textEditor); AvalonLoader.SetSyntax(_textEditor, "Script"); string script = DbIOFormatting.ScriptFormat(text, 0); _textEditor.Text = script; _textEditor.TextArea.TextEntered += new TextCompositionEventHandler(_textArea_TextEntered); _textEditor.TextArea.TextEntering += new TextCompositionEventHandler(_textArea_TextEntering); _textEditor.TextChanged += (e, a) => OnValueChanged(); //_textEditor.TextArea.IndentationStrategy = new CSharpIndentationStrategy(); _completionWindow = new CompletionWindow(_textEditor.TextArea); _completionWindow.Background = Application.Current.Resources["TabItemBackground"] as Brush; _li = _completionWindow.CompletionList; ListView lv = _li.ListBox; lv.SelectionMode = SelectionMode.Single; lv.Background = Application.Current.Resources["TabItemBackground"] as Brush; //Image ListViewDataTemplateHelper.GenerateListViewTemplateNew(lv, new ListViewDataTemplateHelper.GeneralColumnInfo[] { new ListViewDataTemplateHelper.ImageColumnInfo { Header = "", DisplayExpression = "Image", TextAlignment = TextAlignment.Center, FixedWidth = 22, MaxHeight = 22, SearchGetAccessor = "Commands" }, new ListViewDataTemplateHelper.GeneralColumnInfo { Header = "Commands", DisplayExpression = "Text", TextAlignment = TextAlignment.Left, IsFill = true, ToolTipBinding = "Description" } }, null, new string[] { }, "generateHeader", "false"); _completionWindow.Content = null; _completionWindow = null; WindowStartupLocation = WindowStartupLocation.CenterOwner; _textEditor.Loaded += delegate { _textEditor.Focus(); }; }
private void _loadUi() { _rcm = new WpfRecentFiles(SdeAppConfiguration.ConfigAsker, 6, _miLoadRecent, "Server database editor - IronPython recent files"); _rcm.FileClicked += new RecentFilesManager.RFMFileClickedEventHandler(_rcm_FileClicked); Binder.Bind(_textEditor, () => SdeAppConfiguration.IronPythonScript); Binder.Bind(_miAutocomplete, () => SdeAppConfiguration.IronPythonAutocomplete); AvalonLoader.Load(_textEditor); AvalonLoader.SetSyntax(_textEditor, "Python"); _textEditor.TextArea.TextEntered += new TextCompositionEventHandler(_textArea_TextEntered); _textEditor.TextArea.TextEntering += new TextCompositionEventHandler(_textArea_TextEntering); this.PreviewKeyDown += new KeyEventHandler(_ironPythonDialog_PreviewKeyDown); _completionWindow = new CompletionWindow(_textEditor.TextArea); _completionWindow.Background = Application.Current.Resources["TabItemBackground"] as Brush; _li = _completionWindow.CompletionList; ListView lv = _li.ListBox; lv.SelectionMode = SelectionMode.Single; lv.Background = Application.Current.Resources["TabItemBackground"] as Brush; //Image ListViewDataTemplateHelper.GenerateListViewTemplateNew(lv, new ListViewDataTemplateHelper.GeneralColumnInfo[] { new ListViewDataTemplateHelper.ImageColumnInfo { Header = "", DisplayExpression = "Image", TextAlignment = TextAlignment.Center, FixedWidth = 22, MaxHeight = 22, SearchGetAccessor = "Commands" }, new ListViewDataTemplateHelper.GeneralColumnInfo { Header = "Commands", DisplayExpression = "Text", TextAlignment = TextAlignment.Left, IsFill = true, ToolTipBinding = "Description" } }, null, new string[] { }, "generateHeader", "false"); _completionWindow.Content = null; _completionWindow = null; _rowConsole.Height = new GridLength(0); _buttonCloseConsole.Margin = new Thickness(0, 5, SystemParameters.HorizontalScrollBarButtonWidth + 2, 0); _textEditor.Drop += new DragEventHandler(_textEditor_Drop); }
private void _textArea_TextEntering(object sender, TextCompositionEventArgs e) { if (e.Text.Length > 0 && _completionWindow != null) { if (!char.IsLetterOrDigit(e.Text[0]) && e.Text[0] != '_') { if (e.Text[0] != '\t') { // The match must be exact string word = AvalonLoader.GetWholeWord(_textEditor.TextArea.Document, _textEditor); if (_li.SelectedItem == null || !_li.SelectedItem.ToString().StartsWith(word ?? "", StringComparison.OrdinalIgnoreCase)) { _completionWindow.Close(); return; } } _completionWindow.CompletionList.RequestInsertion(e); } } //if (e.Text.Length > 0 && _completionWindow == null) { // if (e.Text[0] == '}') { // int curLine = _textEditor.TextArea.Caret.Line; // var text = _getText(curLine); // int tabCount = _findIndex(curLine, '}'); // // if (tabCount > 0) { // if (tabCount == block.OuterIndent.Length + 1) { // // remove one! // doc.Text = block.OuterIndent + line.Substring(tabCount); // } // } // } //} }
public ShopSimulatorDialog() : base("Shop simulator", "editor.png", SizeToContent.Height, ResizeMode.NoResize) { InitializeComponent(); WindowStartupLocation = WindowStartupLocation.CenterOwner; Owner = WpfUtilities.TopWindow; _shopItems = new RangeObservableCollection <ShopItem>(); _lvItems.ItemsSource = _shopItems; Binder.Bind(_cbColorZeny, () => SdeAppConfiguration.UseZenyColors, () => _shopItems.ToList().ForEach(p => p.Update())); Binder.Bind(_cbDiscount, () => SdeAppConfiguration.UseDiscount, () => _shopItems.ToList().ForEach(p => p.Update())); Binder.Bind(_cbUseViewId, () => SdeAppConfiguration.AlwaysUseViewId, () => { if (!_enableEvents || _primaryShop == null) { return; } try { _enableEvents = false; string viewId = _primaryShop.NpcViewId; int ival; if (SdeAppConfiguration.AlwaysUseViewId) { if (!Int32.TryParse(viewId, out ival)) { var constDb = SdeEditor.Instance.ProjectDatabase.GetDb <string>(ServerDbs.Constants); var tuple = constDb.Table.TryGetTuple(viewId); if (tuple != null) { ival = tuple.GetValue <int>(ServerConstantsAttributes.Value); } else { ival = -1; } _primaryShop.NpcViewId = ival.ToString(CultureInfo.InvariantCulture); _tbNpcViewId.Text = _primaryShop.NpcViewId; _primaryShop.Reload(); } } else { if (Int32.TryParse(viewId, out ival)) { viewId = _viewIdToString(ival); if (!String.IsNullOrEmpty(viewId)) { if (viewId.IsExtension(".act", ".spr")) { _primaryShop.NpcViewId = Path.GetFileNameWithoutExtension(viewId.ToUpper()); } else { _primaryShop.NpcViewId = Path.GetFileName(viewId); } _tbNpcViewId.Text = _primaryShop.NpcViewId; _primaryShop.Reload(); } } } } catch (Exception err) { ErrorHandler.HandleException(err); } finally { _enableEvents = true; } }); _shop.TextChanged += new EventHandler(_shop_TextChanged); AvalonLoader.Load(_shop); WpfUtils.AddMouseInOutEffectsBox(_cbColorZeny, _cbDiscount, _cbUseViewId); _helper = new PreviewHelper(new RangeListView(), SdeEditor.Instance.ProjectDatabase.GetDb <int>(ServerDbs.Items), null, null, null, null); FrameViewerSettings settings = new FrameViewerSettings(); settings.Act = () => _act; settings.SelectedAction = () => _actIndexSelected.SelectedAction; settings.SelectedFrame = () => _actIndexSelected.SelectedFrame; _frameViewer.InitComponent(settings); _actIndexSelected.Init(_frameViewer); _actIndexSelected.Load(_act); _actIndexSelected.FrameChanged += (s, p) => _frameViewer.Update(); _actIndexSelected.ActionChanged += (s, p) => { _frameViewer.Update(); if (!_enableEvents || _primaryShop == null) { return; } try { _enableEvents = false; var elements = _tbNpcPosition.Text.Split(','); var dir = _convertAction(_actIndexSelected.SelectedAction); if (elements.Length == 4) { elements[3] = dir.ToString(CultureInfo.InvariantCulture); _primaryShop.ShopLocation = string.Join(",", elements); _primaryShop.Reload(); } else { _primaryShop.ShopLocation = "prontera,150,150," + dir.ToString(CultureInfo.InvariantCulture); _primaryShop.Reload(); } _tbNpcPosition.Text = _primaryShop.ShopLocation; } catch (Exception err) { ErrorHandler.HandleException(err); } finally { _enableEvents = true; } }; _actIndexSelected.SpecialFrameChanged += (s, p) => _frameViewer.Update(); _lvItems.MouseRightButtonUp += new MouseButtonEventHandler(_lvItems_MouseRightButtonUp); _lvItems.SelectionChanged += new SelectionChangedEventHandler(_lvItems_SelectionChanged); _tbItemId.TextChanged += new TextChangedEventHandler(_tbItemId_TextChanged); _tbPrice.TextChanged += new TextChangedEventHandler(_tbPrice_TextChanged); _tbNpcViewId.TextChanged += new TextChangedEventHandler(_tbNpcViewId_TextChanged); _tbNpcPosition.TextChanged += new TextChangedEventHandler(_tbNpcPosition_TextChanged); _tbNpcDisplayName.TextChanged += new TextChangedEventHandler(_tbNpcDisplayName_TextChanged); _tbNpcShopCurrency.TextChanged += new TextChangedEventHandler(_tbNpcShopCurrency_TextChanged); _comboBoxShopType.SelectionChanged += new SelectionChangedEventHandler(_comboBoxShopType_SelectionChanged); _buttonResetPrice.Click += delegate { _tbPrice.Text = "-1"; }; _buttonCurItemQuery.Click += delegate { try { Table <int, ReadableTuple <int> > btable = SdeEditor.Instance.ProjectDatabase.GetMetaTable <int>(ServerDbs.Items); SelectFromDialog select = new SelectFromDialog(btable, ServerDbs.Items, _tbNpcShopCurrency.Text); select.Owner = WpfUtilities.TopWindow; if (select.ShowDialog() == true) { _tbNpcShopCurrency.Text = select.Id; } } catch (Exception err) { ErrorHandler.HandleException(err); } }; _buttonViewIdQuery.Click += delegate { try { MultiGrfExplorer dialog = new MultiGrfExplorer(SdeEditor.Instance.ProjectDatabase.MetaGrf, "data\\sprite\\npc", "", _viewIdToString(FormatConverters.IntOrHexConverter(_primaryShop.NpcViewId ?? ""))); if (dialog.ShowDialog() == true) { var path = dialog.SelectedPath.GetFullPath(); string result; if (path.IsExtension(".act", ".spr")) { result = Path.GetFileNameWithoutExtension(path.ToUpper()); } else { result = Path.GetFileName(path); } if (SdeAppConfiguration.AlwaysUseViewId) { var constDb = SdeEditor.Instance.ProjectDatabase.GetDb <string>(ServerDbs.Constants); var tuple = constDb.Table.TryGetTuple(result); int ival; if (tuple != null) { ival = tuple.GetValue <int>(ServerConstantsAttributes.Value); } else { _tbNpcViewId.Text = result; return; } if (!_enableEvents || _primaryShop == null) { return; } try { _enableEvents = false; _primaryShop.NpcViewId = ival.ToString(CultureInfo.InvariantCulture); _tbNpcViewId.Text = _primaryShop.NpcViewId; _updateViewShop(); _primaryShop.Reload(); } catch (Exception err) { ErrorHandler.HandleException(err); } finally { _enableEvents = true; } } else { _tbNpcViewId.Text = result; } } } catch (Exception err) { ErrorHandler.HandleException(err); } }; _buttonQueryItem.Click += delegate { try { Table <int, ReadableTuple <int> > btable = SdeEditor.Instance.ProjectDatabase.GetMetaTable <int>(ServerDbs.Items); SelectFromDialog select = new SelectFromDialog(btable, ServerDbs.Items, _tbItemId.Text); select.Owner = WpfUtilities.TopWindow; if (select.ShowDialog() == true) { _tbItemId.Text = select.Id; } } catch (Exception err) { ErrorHandler.HandleException(err); } }; _gridColumnPrimary.Width = new GridLength(230 + SystemParameters.VerticalScrollBarWidth + 7); this.Loaded += delegate { this.MinHeight = this.ActualHeight + 10; this.MinWidth = this.ActualWidth; this.ResizeMode = ResizeMode.CanResize; SizeToContent = SizeToContent.Manual; }; ApplicationShortcut.Link(ApplicationShortcut.Delete, () => _buttonDelete_Click(null, null), _lvItems); ApplicationShortcut.Link(ApplicationShortcut.New, () => _buttonNew_Click(null, null), this); ApplicationShortcut.Link(ApplicationShortcut.FromString("Ctrl-Up", "MoveUp"), () => _buttonUp_Click(null, null), _lvItems); ApplicationShortcut.Link(ApplicationShortcut.FromString("Ctrl-Down", "MoveDown"), () => _buttonDown_Click(null, null), _lvItems); ApplicationShortcut.Link(ApplicationShortcut.Undo, () => _undo(), this); ApplicationShortcut.Link(ApplicationShortcut.Redo, () => _redo(), this); //_shop.Text = "alberta_in,182,97,0 shop Tool Dealer#alb2 73,1750:-1,611:-1,501:-1,502:-1,503:-1,504:-1,506:-1,645:-1,656:-1,601:-1,602:-1,2243:-1"; }
private void _textArea_TextEntering(object sender, TextCompositionEventArgs e) { try { if (e.Text.Length > 0 && _completionWindow != null) { if (!char.IsLetterOrDigit(e.Text[0]) && e.Text[0] != '_' && e.Text[0] != ' ') { string word = AvalonLoader.GetWholeWordAdv(_textEditor.TextArea.Document, _textEditor); var strategy = new RegexSearchStrategy(new Regex(word), true); if ((e.Text[0] != '\t' || e.Text[0] != '\n') && strategy.FindAll(_textEditor.Document, 0, _textEditor.Document.TextLength).Count() > 1) { _completionWindow.Close(); return; } string line = _getText(_textEditor.TextArea.Caret.Line); if (line.IndexOf('#') > -1) { _completionWindow.Close(); return; } _completionWindow.CompletionList.RequestInsertion(e); } else if (e.Text[0] == ' ') { _completionWindow.Close(); } } if (e.Text.Length > 0 && _completionWindow == null) { if (e.Text[0] == '\n') { int currentLine = _textEditor.TextArea.Caret.Line; DocumentLine docLine = _getLine(currentLine); string line = _getText(currentLine); int currentIndent = LineHelper.GetIndent(line); if (line.EndsWith(":") && _textEditor.CaretOffset >= docLine.EndOffset) { currentIndent++; } if (_textEditor.LineCount == currentLine) { _textEditor.Document.Insert(_textEditor.Document.TextLength, "\n" + LineHelper.GenerateIndent(currentIndent)); _textEditor.CaretOffset = _textEditor.Text.Length; } else { var position = _textEditor.CaretOffset; _textEditor.Document.Insert(_textEditor.CaretOffset, "\n" + LineHelper.GenerateIndent(currentIndent)); _textEditor.CaretOffset = position + ("\n" + LineHelper.GenerateIndent(currentIndent)).Length; } _textEditor.TextArea.Caret.BringCaretToView(); e.Handled = true; } } } catch { } }