Skip to content

Commit

Permalink
PR Feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
marcarro committed Aug 21, 2024
1 parent 4bab4dd commit 4297e6f
Showing 1 changed file with 7 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -119,20 +119,15 @@ private static bool IsInsideProperHtmlContent(RazorCodeActionContext context, Ma
return null;
}

var endLocation = GetEndLocation(selectionEnd, context.CodeDocument);
if (!endLocation.HasValue)
{
return null;
}

var endOwner = syntaxTree.Root.FindInnermostNode(endLocation.Value.AbsoluteIndex, true);
var endAbsoluteIndex = context.SourceText.GetRequiredAbsoluteIndex(selectionEnd);
var endOwner = syntaxTree.Root.FindInnermostNode(endAbsoluteIndex, true);
if (endOwner is null)
{
return null;
}

// Correct selection to include the current node if the selection ends immediately after a closing tag.
if (endOwner is MarkupTextLiteralSyntax && string.IsNullOrWhiteSpace(endOwner.ToFullString()) && endOwner.TryGetPreviousSibling(out var previousSibling))
if (endOwner is MarkupTextLiteralSyntax && endOwner.ContainsOnlyWhitespace() && endOwner.TryGetPreviousSibling(out var previousSibling))
{
endOwner = previousSibling;
}
Expand Down Expand Up @@ -178,13 +173,14 @@ private static void ProcessSelection(MarkupElementSyntax startElementNode, Marku
// This conditional handles cases where the user's selection spans across different levels of the DOM.
// For example:
// <div>
// <span>
// Selected text starts here<p>Some text</p>
// {|result:<span>
// {|selection:<p>Some text</p>
// </span>
// <span>
// <p>More text</p>
// </span>
// Selected text ends here <span></span>
// <span>
// </span>|}|}
// </div>
// In this case, we need to find the smallest set of complete elements that covers the entire selection.

Expand All @@ -200,16 +196,6 @@ private static void ProcessSelection(MarkupElementSyntax startElementNode, Marku
// Note: If we don't find a valid pair, we keep the original extraction range
}

private static SourceLocation? GetEndLocation(Position selectionEnd, RazorCodeDocument codeDocument)
{
if (!codeDocument.Source.Text.TryGetSourceLocation(selectionEnd, out var location))
{
return null;
}

return location;
}

private static bool TryGetNamespace(RazorCodeDocument codeDocument, [NotNullWhen(returnValue: true)] out string? @namespace)
// If the compiler can't provide a computed namespace it will fallback to "__GeneratedComponent" or
// similar for the NamespaceNode. This would end up with extracting to a wrong namespace
Expand Down

0 comments on commit 4297e6f

Please sign in to comment.