From f375070b7a7229cf3457f02ad0784f6487da0b15 Mon Sep 17 00:00:00 2001 From: James Brownlee Date: Fri, 19 Jan 2024 14:10:57 -0500 Subject: [PATCH] fixed spacing issue --- MultilineGreyText/MultilineGreyTextTagger.cs | 64 +++++++++----------- 1 file changed, 29 insertions(+), 35 deletions(-) diff --git a/MultilineGreyText/MultilineGreyTextTagger.cs b/MultilineGreyText/MultilineGreyTextTagger.cs index f3d8db9..fadb70f 100644 --- a/MultilineGreyText/MultilineGreyTextTagger.cs +++ b/MultilineGreyText/MultilineGreyTextTagger.cs @@ -70,45 +70,39 @@ private InlineGreyTextTagger GetTagger(){ } public void SetSuggestion(String newSuggestion, bool inline, int caretPoint){ - ClearSuggestion(); - inlineSuggestion = inline; - - int lineN = GetCurrentTextLine(); - - if (lineN < 0) return; - - String untrim = buffer.CurrentSnapshot.GetLineFromLineNumber(lineN).GetText(); - String line = untrim.TrimStart(); - int offset = untrim.Length - line.Length; - + ClearSuggestion(); + inlineSuggestion = inline; + + int lineN = GetCurrentTextLine(); + + if (lineN < 0) return; + + String untrim = buffer.CurrentSnapshot.GetLineFromLineNumber(lineN).GetText(); + String line = untrim.TrimStart(); + int offset = untrim.Length - line.Length; + caretPoint = Math.Max(0, caretPoint - offset); - String currentText = line.Substring(0, caretPoint); - String combineSuggestion = currentText + newSuggestion; + String combineSuggestion = line + newSuggestion; + if (line.Length - caretPoint > 0){ + String currentText = line.Substring(0, caretPoint); + combineSuggestion = currentText + newSuggestion; + userEndingText = line.Substring(caretPoint).TrimEnd(); + var userIndex = newSuggestion.IndexOf(userEndingText); + if (userIndex < 0){ + return; + } + userIndex += currentText.Length; - if (line.Length - caretPoint > 0){ - - userEndingText = line.Substring(caretPoint).TrimEnd(); - if (String.IsNullOrEmpty(userEndingText)){ + this.userIndex = userIndex; + isTextInsertion = true; + insertionPoint = line.Length - caretPoint; + }else{ + isTextInsertion = false; + } - }else{ - var userIndex = newSuggestion.IndexOf(userEndingText); - if (userIndex < 0) - { - return; - } - userIndex += currentText.Length; - this.userIndex = userIndex; - } - - isTextInsertion = true; - insertionPoint = line.Length - caretPoint; - }else{ - isTextInsertion = false; - } - - suggestion = new Tuple(combineSuggestion, combineSuggestion.Split('\n')); - Update(); + suggestion = new Tuple(combineSuggestion, combineSuggestion.Split('\n')); + Update(); } private void CaretUpdate(object sender, CaretPositionChangedEventArgs e){