Skip to content

Commit 12f2d20

Browse files
committed
Fix #736: "Move to Resource" does not work at the end of the string literal
1 parent 57e6e3b commit 12f2d20

4 files changed

Lines changed: 29 additions & 66 deletions

File tree

src/ResXManager.Model/ResourceManager.cs

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
/// </summary>
2323
[Shared]
2424
[Export]
25-
public sealed class ResourceManager : INotifyPropertyChanged
25+
public sealed partial class ResourceManager : INotifyPropertyChanged
2626
{
2727
private string? _snapshot;
2828

@@ -310,11 +310,4 @@ public string CreateSnapshot()
310310
{
311311
return _snapshot = ResourceEntities.CreateSnapshot();
312312
}
313-
314-
public event PropertyChangedEventHandler? PropertyChanged;
315-
316-
private void OnPropertyChanged(string propertyName)
317-
{
318-
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
319-
}
320313
}

src/ResXManager.VSIX.Compatibility.Shared/DteExtensions.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -77,14 +77,14 @@ public static ICollection<VSITEMSELECTION> GetSelectedProjectItems(this IVsMonit
7777
if ((hierarchyPtr == IntPtr.Zero) || (itemId == VSConstants.VSITEMID_ROOT))
7878
return Array.Empty<VSITEMSELECTION>();
7979

80-
return new[]
81-
{
80+
return
81+
[
8282
new VSITEMSELECTION
8383
{
8484
pHier = Marshal.GetObjectForIUnknown(hierarchyPtr) as IVsHierarchy,
8585
itemid = itemId
8686
}
87-
};
87+
];
8888
}
8989
finally
9090
{
@@ -144,12 +144,12 @@ public static ICollection<VSITEMSELECTION> GetSelectedProjectItems(this IVsMonit
144144

145145
public static IEnumerable<EnvDTE.ProjectItem> Children(this EnvDTE.ProjectItem? projectItem)
146146
{
147-
return projectItem?.TryGetProjectItems() ?? Enumerable.Empty<EnvDTE.ProjectItem>();
147+
return projectItem?.TryGetProjectItems() ?? [];
148148
}
149149

150150
public static IEnumerable<EnvDTE.ProjectItem> Descendants(this EnvDTE.ProjectItem? projectItem)
151151
{
152-
return projectItem?.TryGetProjectItems()?.SelectMany(p => p.DescendantsAndSelf()) ?? Enumerable.Empty<EnvDTE.ProjectItem>();
152+
return projectItem?.TryGetProjectItems()?.SelectMany(p => p.DescendantsAndSelf()) ?? [];
153153
}
154154

155155
public static IEnumerable<EnvDTE.ProjectItem> DescendantsAndSelf(this EnvDTE.ProjectItem? projectItem)
@@ -167,7 +167,7 @@ public static ICollection<VSITEMSELECTION> GetSelectedProjectItems(this IVsMonit
167167

168168
public static IEnumerable<SolutionItem> Descendants(this SolutionItem? projectItem)
169169
{
170-
return projectItem?.Children.SelectMany(p => p.DescendantsAndSelf()) ?? Enumerable.Empty<SolutionItem>();
170+
return projectItem?.Children.SelectMany(p => p.DescendantsAndSelf()) ?? [];
171171
}
172172

173173
public static IEnumerable<SolutionItem> DescendantsAndSelf(this SolutionItem? projectItem)
@@ -327,4 +327,4 @@ public static void SetFontSize(this EnvDTE80.DTE2 dte, DependencyObject view)
327327
return null;
328328
}
329329
}
330-
}
330+
}

src/ResXManager.VSIX.Compatibility.Shared/Refactorings.cs

Lines changed: 18 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ public bool CanMoveToResource()
136136
var projectResources = new HashSet<ResourceEntity>(GetResourceEntriesFromProject(document, entities));
137137

138138
// put resources from the same project on top
139-
entities.RemoveAll(entity => projectResources.Contains(entity));
139+
entities.RemoveAll(projectResources.Contains);
140140
entities.InsertRange(0, projectResources);
141141

142142
// put the last used entry on top, if it's in the same project, or the last access was cross-project.
@@ -197,7 +197,7 @@ private static IEnumerable<ResourceEntity> GetResourceEntriesFromProject(Documen
197197
}
198198
catch (Exception)
199199
{
200-
return Enumerable.Empty<ResourceEntity>();
200+
return [];
201201
}
202202
}
203203

@@ -256,7 +256,7 @@ private static bool IsInProject(ResourceEntity entity, Project? project)
256256
if (document is null)
257257
return null;
258258

259-
var textDocument = (TextDocument?)document.Object(@"TextDocument");
259+
var textDocument = (TextDocument?)document.Object("TextDocument");
260260
if (textDocument is null)
261261
return null;
262262

@@ -396,60 +396,46 @@ private sealed class GenericParser : IParser
396396
return locator.Locate(@"""") ?? locator.Locate("'") ?? locator.Locate("`");
397397
}
398398

399-
private sealed class Locator
399+
private sealed class Locator(string line, int column, Selection? selection)
400400
{
401-
private readonly string _line;
402-
private readonly int _column;
403-
private readonly Selection? _selection;
404-
405-
public Locator(string line, int column, Selection? selection)
406-
{
407-
_line = line;
408-
_column = column;
409-
_selection = selection;
410-
}
411-
412401
public string? Locate(string quote)
413402
{
414403
ThrowIfNotOnUIThread();
415404

416405
var secondQuote = -1;
417406

418-
while (secondQuote < _line.Length)
407+
while (secondQuote < line.Length)
419408
{
420-
var firstQuote = _line.IndexOf(quote, secondQuote + 1, StringComparison.Ordinal);
409+
var firstQuote = line.IndexOf(quote, secondQuote + 1, StringComparison.Ordinal);
421410
if (firstQuote == -1)
422411
return null;
423412

424-
if (_line.Length <= firstQuote + 1)
413+
var startIndex = firstQuote + 1;
414+
415+
if (line.Length <= startIndex)
425416
return null;
426417

427-
if (_column < firstQuote)
418+
if (column < firstQuote)
428419
return null;
429420

430-
secondQuote = _line.IndexOf(quote, firstQuote + 1, StringComparison.Ordinal);
421+
secondQuote = line.IndexOf(quote, startIndex, StringComparison.Ordinal);
431422
if (secondQuote == -1)
432423
return null;
433424

434-
if (_column >= secondQuote)
435-
continue;
425+
var endIndex = secondQuote + 2;
436426

437-
var startIndex = firstQuote + 1;
438-
var length = secondQuote - firstQuote - 1;
427+
if (column >= endIndex)
428+
continue;
439429

440-
if (_selection != null)
441-
{
442-
var startColumn = firstQuote + 1;
443-
var endColumn = secondQuote + 2;
430+
var length = secondQuote - startIndex;
444431

445-
_selection.MoveTo(startColumn, endColumn);
446-
}
432+
selection?.MoveTo(startIndex, endIndex);
447433

448-
return _line.Substring(startIndex, length);
434+
return line.Substring(startIndex, length);
449435
}
450436

451437
return null;
452438
}
453439
}
454440
}
455-
}
441+
}

src/ResXManager.VSIX/Visuals/MoveToResourceViewModel.cs

Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public MoveToResourceViewModel(IVsixCompatibility vsixCompatibility, ICollection
5757
Key = Keys.Skip(SelectedKeyIndex).FirstOrDefault() ?? Keys.FirstOrDefault();
5858
Value = text;
5959

60-
PropertyChanged += ((_, _) => Update());
60+
PropertyChanged += (_, _) => Update();
6161
}
6262

6363
private static string BaseFileName(string fileName)
@@ -197,28 +197,12 @@ private static bool IsCharValidForSymbolStart(char c)
197197
string? IDataErrorInfo.Error => null;
198198
}
199199

200-
public sealed class Replacement : INotifyPropertyChanged
200+
public sealed partial class Replacement(string pattern, Func<string, string> evaluator) : INotifyPropertyChanged
201201
{
202-
private readonly string _pattern;
203-
private readonly Func<string, string> _evaluator;
204-
205-
public Replacement(string pattern, Func<string, string> evaluator)
206-
{
207-
_pattern = pattern;
208-
_evaluator = evaluator;
209-
}
210-
211-
public string? Value => _evaluator(_pattern);
212-
213-
public event PropertyChangedEventHandler? PropertyChanged;
202+
public string? Value => evaluator(pattern);
214203

215204
public void Update()
216205
{
217206
OnPropertyChanged(nameof(Value));
218207
}
219-
220-
private void OnPropertyChanged(string propertyName)
221-
{
222-
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
223-
}
224208
}

0 commit comments

Comments
 (0)