File tree Expand file tree Collapse file tree 2 files changed +40
-2
lines changed
src/Microsoft.CodeAnalysis.Razor.Workspaces/CodeActions/Razor
test/Microsoft.VisualStudio.LanguageServices.Razor.Test/Cohost/CodeActions Expand file tree Collapse file tree 2 files changed +40
-2
lines changed Original file line number Diff line number Diff line change @@ -46,9 +46,10 @@ public Task<ImmutableArray<RazorVSInternalCodeAction>> ProvideAsync(RazorCodeAct
46
46
return SpecializedTasks . EmptyImmutableArray < RazorVSInternalCodeAction > ( ) ;
47
47
}
48
48
49
- if ( owner is MarkupTextLiteralSyntax { Parent : MarkupStartTagSyntax } )
49
+ // If we're inside an element, move to the start tag so the following checks work as expected
50
+ if ( owner is MarkupTextLiteralSyntax { Parent : MarkupElementSyntax { StartTag : { } startTag } } )
50
51
{
51
- owner = owner . Parent ;
52
+ owner = startTag ;
52
53
}
53
54
54
55
// We have to be in a style tag (or inside it, but we'll have moved to the parent if so, above)
Original file line number Diff line number Diff line change @@ -262,6 +262,43 @@ await VerifyCodeActionAsync(
262
262
""" ) ] ) ;
263
263
}
264
264
265
+ [ Fact ]
266
+ public async Task ExtractToCss_FromInside ( )
267
+ {
268
+ await VerifyCodeActionAsync (
269
+ input : """
270
+ <div></div>
271
+
272
+ <style>
273
+ body {
274
+ back[||]ground-color: red;
275
+ }
276
+ </style>
277
+
278
+ @code
279
+ {
280
+ private int x = 1;
281
+ }
282
+ """ ,
283
+ expected : """
284
+ <div></div>
285
+
286
+
287
+
288
+ @code
289
+ {
290
+ private int x = 1;
291
+ }
292
+ """ ,
293
+ codeActionName : LanguageServerConstants . CodeActions . ExtractToCssAction ,
294
+ additionalExpectedFiles : [
295
+ ( FileUri ( "File1.razor.css" ) , $$$ """
296
+ body {
297
+ background-color: red;
298
+ }
299
+ """ ) ] ) ;
300
+ }
301
+
265
302
[ Fact ]
266
303
public void GetLastLineNumberAndLength ( )
267
304
{
You can’t perform that action at this time.
0 commit comments