Skip to content

Commit

Permalink
Added early return in ProcessMultiPointSelection
Browse files Browse the repository at this point in the history
  • Loading branch information
marcarro committed Aug 21, 2024
1 parent 7d3c78a commit 842b162
Showing 1 changed file with 12 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -171,9 +171,10 @@ private static void ProcessMultiPointSelection(MarkupElementSyntax startElementN
var startNodeContainsEndNode = endElementNode.Ancestors().Any(node => node == startElementNode);

// If the start element is an ancestor, keep the original end; otherwise, use the end of the end element
if (!startNodeContainsEndNode)
if (startNodeContainsEndNode)
{
actionParams.ExtractEnd = endElementNode.Span.End;
actionParams.ExtractEnd = startElementNode.Span.End;
return;
}

// If the start element is not an ancestor of the end element, we need to find a common parent
Expand All @@ -189,19 +190,17 @@ private static void ProcessMultiPointSelection(MarkupElementSyntax startElementN
// Selected text ends here <span></span>
// </div>
// In this case, we need to find the smallest set of complete elements that covers the entire selection.
if (!startNodeContainsEndNode)
{
// Find the closest containing sibling pair that encompasses both the start and end elements
var (extractStart, extractEnd) = FindContainingSiblingPair(startElementNode, endElementNode);

// Find the closest containing sibling pair that encompasses both the start and end elements
var (extractStart, extractEnd) = FindContainingSiblingPair(startElementNode, endElementNode);

// If we found a valid containing pair, update the extraction range
if (extractStart is not null && extractEnd is not null)
{
actionParams.ExtractStart = extractStart.Span.Start;
actionParams.ExtractEnd = extractEnd.Span.End;
}
// Note: If we don't find a valid pair, we keep the original extraction range
// If we found a valid containing pair, update the extraction range
if (extractStart is not null && extractEnd is not null)
{
actionParams.ExtractStart = extractStart.Span.Start;
actionParams.ExtractEnd = extractEnd.Span.End;
}
// Note: If we don't find a valid pair, we keep the original extraction range
}

private static bool IsMultiPointSelection(Range range) => range.Start != range.End;
Expand Down

0 comments on commit 842b162

Please sign in to comment.