Skip to content

Commit 842b162

Browse files
committed
Added early return in ProcessMultiPointSelection
1 parent 7d3c78a commit 842b162

File tree

1 file changed

+12
-13
lines changed

1 file changed

+12
-13
lines changed

src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/Razor/ExtractToNewComponentCodeActionProvider.cs

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -171,9 +171,10 @@ private static void ProcessMultiPointSelection(MarkupElementSyntax startElementN
171171
var startNodeContainsEndNode = endElementNode.Ancestors().Any(node => node == startElementNode);
172172

173173
// If the start element is an ancestor, keep the original end; otherwise, use the end of the end element
174-
if (!startNodeContainsEndNode)
174+
if (startNodeContainsEndNode)
175175
{
176-
actionParams.ExtractEnd = endElementNode.Span.End;
176+
actionParams.ExtractEnd = startElementNode.Span.End;
177+
return;
177178
}
178179

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

197-
// If we found a valid containing pair, update the extraction range
198-
if (extractStart is not null && extractEnd is not null)
199-
{
200-
actionParams.ExtractStart = extractStart.Span.Start;
201-
actionParams.ExtractEnd = extractEnd.Span.End;
202-
}
203-
// Note: If we don't find a valid pair, we keep the original extraction range
197+
// If we found a valid containing pair, update the extraction range
198+
if (extractStart is not null && extractEnd is not null)
199+
{
200+
actionParams.ExtractStart = extractStart.Span.Start;
201+
actionParams.ExtractEnd = extractEnd.Span.End;
204202
}
203+
// Note: If we don't find a valid pair, we keep the original extraction range
205204
}
206205

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

0 commit comments

Comments
 (0)