Skip to content

Commit

Permalink
fix some bugs when pasting
Browse files Browse the repository at this point in the history
  • Loading branch information
huynhsontung committed May 1, 2021
1 parent 57f3e2b commit 27307f5
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -75,16 +75,16 @@ private static void ForEachLinkInDocument(ITextDocument document, Action<ITextRa
linkRange.Expand(TextRangeUnit.Link);

// Adjacent links have the same index. Manually check each link with Collapse and Expand.
var previousText = linkRange.Text;
var previousStart = linkRange.StartPosition;
var hasAdjacentToken = true;
while (hasAdjacentToken)
{
action?.Invoke(linkRange);

linkRange.Collapse(false);
linkRange.Expand(TextRangeUnit.Link);
hasAdjacentToken = !string.IsNullOrEmpty(linkRange.Text) && linkRange.Text != previousText;
previousText = linkRange.Text;
hasAdjacentToken = !string.IsNullOrEmpty(linkRange.Link) && linkRange.StartPosition != previousStart;
previousStart = linkRange.StartPosition;
}

nextIndex = range.GetIndex(TextRangeUnit.Link);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,13 @@ private ITextRange CommitSuggestionIntoDocument(ITextRange range, string display
_ignoreChange = true;
TextDocument.BeginUndoGroup();

range.SetText(TextSetOptions.Unhide, displayText);
// We don't want to set text when the display text doesn't change since it may lead to unexpected caret move.
range.GetText(TextGetOptions.NoHidden, out var existingText);
if (existingText != displayText)
{
range.SetText(TextSetOptions.Unhide, displayText);
}

range.Link = $"\"{id}\"";

range.CharacterFormat.BackgroundColor = format.Background;
Expand Down

0 comments on commit 27307f5

Please sign in to comment.