Skip to content

Commit db4d3cb

Browse files
committed
Margin: Corrections for Go To Defninition.
In scenarios like sel1 > sel2 + sel3, the CSS parser attach `+` and `>` signs to the previous selector, while CSS source map count it with the current node (SimpleSelector; that is part of selector).
1 parent 5a826c7 commit db4d3cb

File tree

1 file changed

+19
-5
lines changed

1 file changed

+19
-5
lines changed

EditorExtensions/Shared/Margins/CssTextViewMargin.cs

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,13 +60,27 @@ private void GoToDefinitionCommandHandler()
6060
if (selector == null)
6161
return;
6262

63-
int start = selector.Start;
64-
int column = start - containingLine.Start;
63+
int column = Math.Max(0, selector.SimpleSelectors.Last().Start - containingLine.Start - 1);
6564

66-
var sourceInfo = _compilerResult.SourceMap.MapNodes.FirstOrDefault(s => s.GeneratedLine == line && s.GeneratedColumn == column);
65+
var sourceInfoCollection = _compilerResult.SourceMap.MapNodes.Where(s => s.GeneratedLine == line && s.GeneratedColumn == column);
6766

68-
if (sourceInfo == null)
69-
return;
67+
if (!sourceInfoCollection.Any())
68+
{
69+
if (selector.SimpleSelectors.Last().PreviousSibling == null)
70+
return;
71+
72+
// In case previous selector had > or + sign at the end,
73+
// LESS compiler does count it as well.
74+
var point = selector.SimpleSelectors.Last().PreviousSibling.AfterEnd - 1;
75+
76+
column = Math.Max(0, point - containingLine.Start - 1);
77+
sourceInfoCollection = _compilerResult.SourceMap.MapNodes.Where(s => s.GeneratedLine == line && s.GeneratedColumn == column);
78+
79+
if (!sourceInfoCollection.Any())
80+
return;
81+
}
82+
83+
var sourceInfo = sourceInfoCollection.First();
7084

7185
if (sourceInfo.SourceFilePath != Document.FilePath)
7286
FileHelpers.OpenFileInPreviewTab(sourceInfo.SourceFilePath);

0 commit comments

Comments
 (0)