Skip to content

Commit 1a2482e

Browse files
committed
fix highlighting for multiline contexts, added ellipsis when truncated.
1 parent 6f026a8 commit 1a2482e

File tree

2 files changed

+42
-5
lines changed

2 files changed

+42
-5
lines changed

Rubberduck.Parsing/Symbols/ArgumentReference.cs

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,35 @@ internal ArgumentReference(
5252

5353
public override (string context, Selection highlight) HighligthSelection(ICodeModule module)
5454
{
55+
const int maxLength = 255;
56+
5557
var lines = module.GetLines(Selection.StartLine, Selection.LineCount).Split('\n');
5658

57-
var line = lines[0]; // TODO think of something that makes sense for multiline
58-
var indent = line.TakeWhile((c, i) => c.Equals(' ') && i < Selection.StartColumn).Count();
59-
return (line.Trim(), new Selection(1, Math.Max(Selection.StartColumn - indent - 1, 1), 1, Math.Max(Selection.EndColumn - indent,1)).ToZeroBased());
59+
var line = lines[0];
60+
var indent = line.TakeWhile(c => c.Equals(' ')).Count();
61+
62+
var highlight = new Selection(
63+
1, Math.Max(Selection.StartColumn - indent, 1),
64+
1, Math.Max(Selection.EndColumn - indent, 1))
65+
.ToZeroBased();
66+
67+
var trimmed = line.Trim();
68+
if (trimmed.Length > maxLength || lines.Length > 1)
69+
{
70+
trimmed = trimmed.Substring(0, Math.Min(trimmed.Length, maxLength)) + "...";
71+
highlight = new Selection(1, highlight.StartColumn, 1, trimmed.Length);
72+
}
73+
74+
if (highlight.IsSingleCharacter && highlight.StartColumn == 0)
75+
{
76+
trimmed = " " + trimmed;
77+
highlight = new Selection(0, 0, 0, 1);
78+
}
79+
else if (highlight.IsSingleCharacter)
80+
{
81+
highlight = new Selection(0, Selection.StartColumn-1 - indent - 1, 0, Selection.StartColumn-1 - indent);
82+
}
83+
return (trimmed, highlight);
6084
}
6185

6286
}

Rubberduck.Parsing/Symbols/IdentifierReference.cs

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,11 +135,24 @@ public bool IsSelected(QualifiedSelection selection)
135135

136136
public virtual (string context, Selection highlight) HighligthSelection(ICodeModule module)
137137
{
138+
const int maxLength = 255;
139+
138140
var lines = module.GetLines(Selection.StartLine, Selection.LineCount).Split('\n');
139141

140-
var line = lines[0]; // TODO think of something that makes sense for multiline
142+
var line = lines[0];
141143
var indent = line.TakeWhile(c => c.Equals(' ')).Count();
142-
return (line.Trim(), new Selection(1, Math.Max(Selection.StartColumn - indent,1), 1, Math.Max(Selection.EndColumn - indent,1)).ToZeroBased());
144+
145+
var highlight = new Selection(
146+
1, Math.Max(Selection.StartColumn - indent, 1),
147+
1, Math.Max(Selection.EndColumn - indent, 1))
148+
.ToZeroBased();
149+
150+
var trimmed = line.Trim();
151+
if (trimmed.Length > maxLength || lines.Length > 1)
152+
{
153+
trimmed = trimmed.Substring(0, maxLength) + "...";
154+
}
155+
return (trimmed, highlight);
143156
}
144157

145158
public bool Equals(IdentifierReference other)

0 commit comments

Comments
 (0)