diff --git a/MultilineGreyText/MultilineGreyTextTagger.cs b/MultilineGreyText/MultilineGreyTextTagger.cs index 770b23e..f3d8db9 100644 --- a/MultilineGreyText/MultilineGreyTextTagger.cs +++ b/MultilineGreyText/MultilineGreyTextTagger.cs @@ -81,20 +81,26 @@ public void SetSuggestion(String newSuggestion, bool inline, int caretPoint){ String line = untrim.TrimStart(); int offset = untrim.Length - line.Length; - caretPoint = Math.Max(0, caretPoint - offset); - - String combineSuggestion = line + newSuggestion; + caretPoint = Math.Max(0, caretPoint - offset); + + String currentText = line.Substring(0, caretPoint); + String combineSuggestion = currentText + newSuggestion; + if (line.Length - caretPoint > 0){ - String currentText = line.Substring(0, caretPoint); - combineSuggestion = currentText + newSuggestion; - userEndingText = line.TrimEnd().Substring(caretPoint); - var userIndex = newSuggestion.IndexOf(userEndingText); - if(userIndex < 0){ - return; + + userEndingText = line.Substring(caretPoint).TrimEnd(); + if (String.IsNullOrEmpty(userEndingText)){ + + }else{ + var userIndex = newSuggestion.IndexOf(userEndingText); + if (userIndex < 0) + { + return; + } + userIndex += currentText.Length; + this.userIndex = userIndex; } - userIndex += currentText.Length; - this.userIndex = userIndex; isTextInsertion = true; insertionPoint = line.Length - caretPoint; }else{ @@ -455,15 +461,16 @@ public bool CompleteText(){ //replaces text in the editor void ReplaceText(string text, int lineN){ ClearSuggestion(); - SnapshotSpan span = this.snapshot.GetLineFromLineNumber(lineN).Extent; - ITextEdit edit = view.TextBuffer.CreateEdit(); - if(span.Length == 0){ - edit.Insert(span.Start.Position, text); - }else { - edit.Replace(span, text); - } - edit.Apply(); + ITextEdit edit = view.BufferGraph.TopBuffer.CreateEdit(); + var spanLength = span.Length; + edit.Replace(span, text); + var newSnapshot = edit.Apply(); + + if(spanLength == 0 && text.Length > 0){ + view.Caret.MoveToPreviousCaretPosition(); + view.Caret.MoveToNextCaretPosition(); + } } //sets up the suggestion for display diff --git a/MultilineGreyText/RefactLanguageClient.cs b/MultilineGreyText/RefactLanguageClient.cs index 38f0897..852a093 100644 --- a/MultilineGreyText/RefactLanguageClient.cs +++ b/MultilineGreyText/RefactLanguageClient.cs @@ -152,12 +152,12 @@ public async Task ActivateAsync(CancellationToken token){ info.CreateNoWindow = true; //starts the lsp process - Process process = new Process(); - process.StartInfo = info; + serverProcess = new Process(); + serverProcess.StartInfo = info; - if (process.Start()){ + if (serverProcess.Start()){ //returns the connection for future use - this.c = new Connection(process.StandardOutput.BaseStream, process.StandardInput.BaseStream); + this.c = new Connection(serverProcess.StandardOutput.BaseStream, serverProcess.StandardInput.BaseStream); return c; } @@ -185,7 +185,6 @@ public async Task OnLoadedAsync(){ if (StartAsync != null){ loaded = true; await StartAsync.InvokeAsync(this, EventArgs.Empty); - statusBar = new StatusBar(); } } @@ -298,24 +297,37 @@ public async Task RefactCompletion(PropertyCollection props, String file async void ShowDefaultStatusBar(){ await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(); + if (!statusBar.IsInitialized()){ + statusBar.InitStatusBar(); + } statusBar.ShowDefaultStatusBar(); } async void ShowStatusBarError(String error){ await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(); + if (!statusBar.IsInitialized()){ + statusBar.InitStatusBar(); + } statusBar.ShowStatusBarError(error); } async void ShowLoadingStatusBar(){ await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(); + if (!statusBar.IsInitialized()){ + statusBar.InitStatusBar(); + } statusBar.ShowLoadingSymbol(); } public void Dispose(){ if(serverProcess != null){ - serverProcess.Kill(); - serverProcess.WaitForExit(); - serverProcess.Dispose(); + try{ + serverProcess.Kill(); + serverProcess.WaitForExit(); + serverProcess.Dispose(); + }catch(Exception e){ + Debug.Write("Dispose" + e.ToString()); + } } } diff --git a/MultilineGreyText/StatusBar.cs b/MultilineGreyText/StatusBar.cs index 38ad2ff..053f6fb 100644 --- a/MultilineGreyText/StatusBar.cs +++ b/MultilineGreyText/StatusBar.cs @@ -15,19 +15,27 @@ internal class StatusBar{ Brush whiteBrush; Brush errorBrush; Brush transparentBrush; + bool isInitialized = false; public StatusBar(){ stack = new StackPanel(); stack.Width = 75.0; stack.Orientation = Orientation.Horizontal; + ShowDefaultStatusBar(); + } + + public bool IsInitialized(){ + return isInitialized; + } + + public void InitStatusBar(){ + isInitialized = true; panel = VisualTreeUtils.FindChild(Application.Current.MainWindow, childName: "StatusBarPanel") as Panel; whiteBrush = new SolidColorBrush(Colors.White); errorBrush = new SolidColorBrush(Colors.Red); transparentBrush = new SolidColorBrush(Colors.Transparent); - panel.Children.Add(stack); - ShowDefaultStatusBar(); + panel.Children.Insert(3, stack); } - public void ShowDefaultStatusBar(){ stack.Children.Clear(); stack.Background = transparentBrush;