public static string GetPreviousWordAtIndex(this AvaloniaEdit.TextEditor editor, int index) { var lastWordIndex = TextUtilities.GetNextCaretPosition(editor.Document, index, LogicalDirection.Backward, CaretPositioningMode.WordBorder); if (lastWordIndex >= 0 && editor.Document.GetLocation(lastWordIndex).Line == editor.Document.GetLocation(index).Line) { return(editor.GetWordAtIndex(lastWordIndex)); } else { return(editor.GetWordAtIndex(index)); } }
public static string GetWordAtIndex(this AvaloniaEdit.TextEditor editor, int index) { var result = string.Empty; if (index >= 0 && editor.Document.TextLength > index) { var start = index; var currentChar = editor.Document.GetCharAt(index); var prevChar = '\0'; if (index > 0) { prevChar = editor.Document.GetCharAt(index - 1); } var charClass = TextUtilities.GetCharacterClass(currentChar); if (charClass != CharacterClass.LineTerminator && prevChar != ' ' && TextUtilities.GetCharacterClass(prevChar) != CharacterClass.LineTerminator) { start = TextUtilities.GetNextCaretPosition(editor.Document, index, LogicalDirection.Backward, CaretPositioningMode.WordStart); } var end = TextUtilities.GetNextCaretPosition(editor.Document, start, LogicalDirection.Forward, CaretPositioningMode.WordBorder); if (start != -1 && end != -1) { var word = editor.Document.GetText(start, end - start).Trim(); if (word.IsSymbol()) { result = word; } } } return(result); }
private void InitializeControls() { Background = Brushes.Transparent; MaxWidth = 3000; ColumnDefinitions = new ColumnDefinitions("*"); RowDefinitions = new RowDefinitions("*"); HorizontalAlignment = HorizontalAlignment.Stretch; VerticalAlignment = VerticalAlignment.Stretch; TextEditor = new TabControlTextEditor() { IsReadOnly = true, HorizontalAlignment = HorizontalAlignment.Stretch, VerticalAlignment = VerticalAlignment.Top, MaxWidth = 3000, MaxHeight = 2000, Foreground = Theme.GridForeground, Background = Theme.GridBackground, // WordWrap = true, // Doesn't work yet // HorizontalScrollBarVisibility = ScrollBarVisibility.Disabled, // WordWrap requires Disabled HorizontalScrollBarVisibility = ScrollBarVisibility.Auto, VerticalScrollBarVisibility = ScrollBarVisibility.Auto, Padding = new Thickness(6), FontSize = 14, SyntaxHighlighting = HighlightingManager.Instance.GetDefinition("JavaScript"), // handles JSON too }; TextEditor.Options.AllowScrollBelowDocument = false; // Breaks top alignment Children.Add(TextEditor); //textEditor.TextArea.IndentationStrategy = new AvaloniaEdit.Indentation.CSharp.CSharpIndentationStrategy(); /*ShowLineNumbers = true; * SyntaxHighlighting = HighlightingManager.Instance.GetDefinition("C#");*/ }