@@ -119,20 +119,15 @@ private static bool IsInsideProperHtmlContent(RazorCodeActionContext context, Ma
119
119
return null ;
120
120
}
121
121
122
- var endLocation = GetEndLocation ( selectionEnd , context . CodeDocument ) ;
123
- if ( ! endLocation . HasValue )
124
- {
125
- return null ;
126
- }
127
-
128
- var endOwner = syntaxTree . Root . FindInnermostNode ( endLocation . Value . AbsoluteIndex , true ) ;
122
+ var endAbsoluteIndex = context . SourceText . GetRequiredAbsoluteIndex ( selectionEnd ) ;
123
+ var endOwner = syntaxTree . Root . FindInnermostNode ( endAbsoluteIndex , true ) ;
129
124
if ( endOwner is null )
130
125
{
131
126
return null ;
132
127
}
133
128
134
129
// Correct selection to include the current node if the selection ends immediately after a closing tag.
135
- if ( endOwner is MarkupTextLiteralSyntax && string . IsNullOrWhiteSpace ( endOwner . ToFullString ( ) ) && endOwner . TryGetPreviousSibling ( out var previousSibling ) )
130
+ if ( endOwner is MarkupTextLiteralSyntax && endOwner . ContainsOnlyWhitespace ( ) && endOwner . TryGetPreviousSibling ( out var previousSibling ) )
136
131
{
137
132
endOwner = previousSibling ;
138
133
}
@@ -178,13 +173,14 @@ private static void ProcessSelection(MarkupElementSyntax startElementNode, Marku
178
173
// This conditional handles cases where the user's selection spans across different levels of the DOM.
179
174
// For example:
180
175
// <div>
181
- // <span>
182
- // Selected text starts here <p>Some text</p>
176
+ // {|result: <span>
177
+ // {|selection: <p>Some text</p>
183
178
// </span>
184
179
// <span>
185
180
// <p>More text</p>
186
181
// </span>
187
- // Selected text ends here <span></span>
182
+ // <span>
183
+ // </span>|}|}
188
184
// </div>
189
185
// In this case, we need to find the smallest set of complete elements that covers the entire selection.
190
186
@@ -200,16 +196,6 @@ private static void ProcessSelection(MarkupElementSyntax startElementNode, Marku
200
196
// Note: If we don't find a valid pair, we keep the original extraction range
201
197
}
202
198
203
- private static SourceLocation ? GetEndLocation ( Position selectionEnd , RazorCodeDocument codeDocument )
204
- {
205
- if ( ! codeDocument . Source . Text . TryGetSourceLocation ( selectionEnd , out var location ) )
206
- {
207
- return null ;
208
- }
209
-
210
- return location ;
211
- }
212
-
213
199
private static bool TryGetNamespace ( RazorCodeDocument codeDocument , [ NotNullWhen ( returnValue : true ) ] out string ? @namespace )
214
200
// If the compiler can't provide a computed namespace it will fallback to "__GeneratedComponent" or
215
201
// similar for the NamespaceNode. This would end up with extracting to a wrong namespace
0 commit comments