public void UnregisterSourceFile(AvaloniaEdit.TextEditor editor, ISourceFile file) { var association = GetAssociatedData(file); editor.TextInput -= association.TextInputHandler; association.Solution = null; dataAssociations.Remove(file); }
public void RegisterSourceFile(AvaloniaEdit.TextEditor editor, ISourceFile file, TextDocument doc) { CSharpDataAssociation association = null; if (dataAssociations.TryGetValue(file, out association)) { throw new Exception("Source file already registered with language service."); } IndentationStrategy = new CSharpIndentationStrategy(editor.Options); association = new CSharpDataAssociation(); association.Solution = file.Project.Solution as OmniSharpSolution; // CanHandle has checked this. dataAssociations.Add(file, association); association.TextInputHandler = (sender, e) => { if (editor.Document == doc) { editor.BeginChange(); OpenBracket(editor, editor.Document, e.Text); CloseBracket(editor, editor.Document, e.Text); switch (e.Text) { case "}": case ";": editor.CaretOffset = Format(editor.Document, 0, (uint)editor.Document.TextLength, editor.CaretOffset); break; case "{": var lineCount = editor.Document.LineCount; var offset = Format(editor.Document, 0, (uint)editor.Document.TextLength, editor.CaretOffset); // suggests clang format didnt do anything, so we can assume not moving to new line. if (lineCount != editor.Document.LineCount) { if (offset <= editor.Document.TextLength) { var newLine = editor.Document.GetLineByOffset(offset); editor.CaretOffset = newLine.PreviousLine.EndOffset; } } else { editor.CaretOffset = offset; } break; } editor.EndChange(); } }; editor.TextArea.TextEntered += association.TextInputHandler; }
protected override void OnAttached() { editor = AssociatedObject as AvaloniaEdit.TextEditor; if (editor != null) { editor.DataContextChanged += Editor_DataContextChanged; } base.OnAttached(); }
protected override void OnDetaching() { editorVm = null; if (editor != null) { editor.DataContextChanged -= Editor_DataContextChanged; editor = null; } base.OnDetaching(); }
public void UnregisterSourceFile(AvaloniaEdit.TextEditor editor, ISourceFile file) { var association = GetAssociatedData(file); editor.TextInput -= association.TextInputHandler; var tu = association.TranslationUnit; clangAccessJobRunner.InvokeAsync(() => { tu?.Dispose(); }); dataAssociations.Remove(file); }
public void RegisterSourceFile(AvaloniaEdit.TextEditor editor, ISourceFile file, TextDocument textDocument) { _typeScriptContext = _typeScriptContext ?? ((TypeScriptProject)file.Project).TypeScriptContext; _typeScriptContext.OpenFile(file.FilePath, File.ReadAllText(file.FilePath)); TypeScriptDataAssociation association = null; if (dataAssociations.TryGetValue(file, out association)) { throw new InvalidOperationException("Source file already registered with language service."); } association = new TypeScriptDataAssociation(); dataAssociations.Add(file, association); }
public MainWindow() { InitializeComponent(); _textEditor = this.FindControl <TextEditor>("Editor"); _textEditor.Background = Brushes.Transparent; _textEditor.ShowLineNumbers = true; _textEditor.SyntaxHighlighting = HighlightingManager.Instance.GetDefinition("C#"); _textEditor.TextArea.TextEntered += textEditor_TextArea_TextEntered; _textEditor.TextArea.TextEntering += textEditor_TextArea_TextEntering; _textEditor.TextArea.IndentationStrategy = new Indentation.CSharp.CSharpIndentationStrategy(); _outText = this.FindControl <TextBlock>("outText"); _executionStatus = this.FindControl <TextBlock>("executionStatus"); _console = this.FindControl <TextBox>("console"); _console.IsReadOnly = true; Interpreter.Printed.Subscribe(PrintToConsole); Interpreter.NewRuntimeException.Subscribe(PrintErrorToConsole); _openFileBtn = this.FindControl <Button>("openFileBtn"); _openFileBtn.Click += _openFileBtn_Click; _saveFileBtn = this.FindControl <Button>("saveFileBtn"); _saveFileBtn.Click += SaveFileBtnClick;; _runBtn = this.FindControl <Button>("runBtn"); _runBtn.Click += RunBtnClick;; _textEditor.TextArea.TextView.ElementGenerators.Add(_generator); this.AddHandler(PointerWheelChangedEvent, (o, i) => { if (i.KeyModifiers != KeyModifiers.Control) { return; } if (i.Delta.Y > 0) { _textEditor.FontSize++; } else { _textEditor.FontSize = _textEditor.FontSize > 1 ? _textEditor.FontSize - 1 : 1; } }, RoutingStrategies.Bubble, true); }
public IntellisenseManager(AvaloniaEdit.TextEditor editor, IIntellisenseControl intellisenseControl, ICompletionAssistant completionAssistant, ILanguageService languageService, ISourceFile file) { intellisenseJobRunner = new JobRunner(); intellisenseQueryRunner = new JobRunner(1); Task.Factory.StartNew(() => { intellisenseJobRunner.RunLoop(new CancellationToken()); }); Task.Factory.StartNew(() => { intellisenseQueryRunner.RunLoop(new CancellationToken()); }); this.intellisenseControl = intellisenseControl; this.completionAssistant = completionAssistant; this.languageService = languageService; this.file = file; this.editor = editor; this.editor.LostFocus += Editor_LostFocus; _hidden = true; }
/// <summary> /// Gets the word in front of the caret. /// </summary> public static string GetWordBeforeCaret(this AvaloniaEdit.TextEditor editor) { if (editor == null) { throw new ArgumentNullException("editor"); } int endOffset = editor.CaretOffset; int startOffset = FindPrevWordStart(editor.Document, endOffset); if (startOffset < 0) { return(string.Empty); } else { return(editor.Document.GetText(startOffset, endOffset - startOffset)); } }
private void OpenBracket(AvaloniaEdit.TextEditor editor, TextDocument document, string text) { if (text[0].IsOpenBracketChar() && editor.CaretOffset <= document.TextLength && editor.CaretOffset > 0) { var nextChar = ' '; if (editor.CaretOffset != document.TextLength) { document.GetCharAt(editor.CaretOffset); } if (char.IsWhiteSpace(nextChar) || nextChar.IsCloseBracketChar()) { document.Insert(editor.CaretOffset, text[0].GetCloseBracketChar().ToString()); } editor.CaretOffset--; } }
public IntellisenseManager(AvaloniaEdit.TextEditor editor, IIntellisenseControl intellisenseControl, ICompletionAssistant completionAssistant, ILanguageService languageService, ISourceFile file) { intellisenseJobRunner = new JobRunner(); intellisenseQueryRunner = new JobRunner(1); Task.Factory.StartNew(() => { intellisenseJobRunner.RunLoop(new CancellationToken()); }); Task.Factory.StartNew(() => { intellisenseQueryRunner.RunLoop(new CancellationToken()); }); this.intellisenseControl = intellisenseControl; this.completionAssistant = completionAssistant; this.languageService = languageService; this.file = file; this.editor = editor; this.editor.LostFocus += Editor_LostFocus; _hidden = true; _shell = IoC.Get <IShell>(); _console = IoC.Get <IConsole>(); var snippetManager = IoC.Get <SnippetManager>(); _snippets = snippetManager.GetSnippets(languageService, file.Project?.Solution, file.Project); }
private void CloseBracket(AvaloniaEdit.TextEditor editor, TextDocument document, string text) { if (text[0].IsCloseBracketChar() && editor.CaretOffset < document.TextLength && editor.CaretOffset > 0) { var offset = editor.CaretOffset; while (offset < document.TextLength) { var currentChar = document.GetCharAt(offset); if (currentChar == text[0]) { document.Replace(offset, 1, string.Empty); break; } else if (!currentChar.IsWhiteSpace()) { break; } offset++; } } }
public static void ClearSelection(this AvaloniaEdit.TextEditor editor) { editor.Select(editor.CaretOffset, 0); }
public void UnregisterSourceFile(AvaloniaEdit.TextEditor editor, ISourceFile file) { _typeScriptContext.RemoveFile(file.FilePath); dataAssociations.Remove(file); }
public void Dispose() { editor.LostFocus -= Editor_LostFocus; editor = null; }
public SelectedLineBackgroundRenderer(AvaloniaEdit.TextEditor textEditor) { _textEditor = textEditor; BorderPen = new Pen(BorderBrush); }
public STBLEditor() { AvaloniaXamlLoader.Load(this); AvaloniaEdit = this.FindControl <AvaloniaEdit.TextEditor>("PART_AvaloniaEdit"); }