Skip to content

Commit a8fd98e

Browse files
committed
Add NVim workspace support and fix highlighting issues
Introduces NVim workspace integration, including new plugin command and related view model logic. Fixes highlighting issues caused by trimming result spaces, resolves replace functionality in flat mode, and addresses result recycling for whole word matches. Updates version to 1.0.25 and documents changes in the changelog.
1 parent 9be2fab commit a8fd98e

File tree

9 files changed

+94
-22
lines changed

9 files changed

+94
-22
lines changed

src/Blitz.Avalonia.Controls/MatchHighlighter.cs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
namespace Blitz.Avalonia.Controls;
1111

12-
public class MatchHighlighter(CharState?[] states, List<BlitzMatch> matches, string lineText, bool isForReplacement)
12+
public class MatchHighlighter(CharState?[] states, List<BlitzMatch> matches, string lineText, bool isForReplacement, int offsetForSpaceRemoval = 0)
1313
{
1414
public InlineCollection GetInlines()
1515
{
@@ -22,21 +22,22 @@ public InlineCollection GetInlines()
2222

2323
foreach (var match in matches)
2424
{
25+
int offsetMathIndex = match.MatchIndex - offsetForSpaceRemoval;
2526

26-
int target = match.MatchIndex + match.MatchLength;
27+
int target = offsetMathIndex + match.MatchLength;
2728

2829

2930
if (match.Replacement is { Length: 0 })
3031
{
31-
states[match.MatchIndex] ??= new CharState();
32-
states[match.MatchIndex]!.InsertedText = lineText.Substring(match.MatchIndex, match.MatchLength);
32+
states[offsetMathIndex] ??= new CharState();
33+
states[offsetMathIndex]!.InsertedText = lineText.Substring(offsetMathIndex, match.MatchLength);
3334
}
3435
// matches are from whole line, which can be truncated for displaytext.
3536

36-
for (int i = match.MatchIndex; i < target && i < states.Length; i++)
37+
for (int i = offsetMathIndex; i < target && i < states.Length; i++)
3738
{
3839
states[i] ??= new CharState();
39-
if (i == match.MatchIndex && match.Replacement is { Length: > 0 } )
40+
if (i == offsetMathIndex && match.Replacement is { Length: > 0 } )
4041
{
4142
states[i]!.ReplacedFrom = match.Replacement;
4243
int offset = match.MatchLength - match.Replacement.Length;

src/Blitz.Avalonia.Controls/PluginCommands.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ public class PluginCommands
2525
public const string SetThemeLight = "SET_THEME_LIGHT";
2626
public const string VisualStudioCodeWorkspaceUpdate = "WORKSPACE_UPDATE";
2727
public const string SublimeTextWorkspaceUpdate = "SUBLIME_TEXT_WORKSPACE";
28+
public const string NVimUpdateWorkspace = "NVIM_SET_WORKSPACE";
2829
public const string UpdateVisualStudioProject = "VS_PROJECT";
2930
public const string UpdateVisualStudioActiveFiles = "VS_ACTIVE_FILES";
3031
public static string SimpleFolderSearch = "SIMPLE_FOLDER_SEARCH";

src/Blitz.Avalonia.Controls/ViewModels/ContentResultViewModel.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,25 +31,25 @@ public InlineCollection ContentWithHighlights
3131
//this can over-burden things. (huge performance hitch and horizontal scrolling). simply truncate here
3232
const int maxLineDisplayChars = 1024; //Make this optional? -> https://github.com/Natestah/BlitzSearch/issues/84
3333

34-
3534
if (!string.IsNullOrEmpty(fileContentResultResult.ReplacedContents))
3635
{
3736
renderedContents = fileContentResultResult.ReplacedContents;
3837
}
3938

39+
int offsetForSpaceRemoval = renderedContents.Length;
4040
renderedContents = renderedContents.TrimStart();
41+
offsetForSpaceRemoval -= renderedContents.Length;
4142

4243
bool largeLine = renderedContents.Length > maxLineDisplayChars;
4344

44-
4545
string displayContents = largeLine ? renderedContents.Substring(0, maxLineDisplayChars): renderedContents;
4646

4747
// given the lines contents and the filename.. come up with some highlights.
4848
InlineCollection inlineCollection = MainWindowViewModel.ResultsHighlighting.GetInlinesFromTextMateSharp(displayContents, fileNameResult.FileName);
4949

5050
var states = MainWindowViewModel.ResultsHighlighting.GetCharStatesFromInlines(inlineCollection, displayContents);
5151

52-
var matchHighlighter = new MatchHighlighter(states,fileContentResultResult.BlitzMatches, displayContents, replacing);
52+
var matchHighlighter = new MatchHighlighter(states,fileContentResultResult.BlitzMatches, displayContents, replacing, offsetForSpaceRemoval);
5353

5454
return matchHighlighter.GetInlines();
5555
}

src/Blitz.Avalonia.Controls/ViewModels/MainWindowViewModel.cs

Lines changed: 41 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -371,6 +371,9 @@ public void UpdateScopeSelectionForEditor()
371371
case CodeExecuteNames.Windsurf:
372372
RecallVisualStudioCodeWorkspacesVisited();
373373
break;
374+
case CodeExecuteNames.NVim:
375+
RecallNVimWorkspacesVisited();
376+
break;
374377
case CodeExecuteNames.SublimeText:
375378
//Sublime Text always updates a single summary of it's Windows and workspaces.
376379
ExternalPluginInteractions.Commander.ExecuteNamedAction(PluginCommands.SublimeTextWorkspaceUpdate);
@@ -1869,18 +1872,12 @@ public void UpdateActiveFiles(ActiveFilesList? list)
18691872

18701873
}
18711874

1872-
public void RecallVisualStudioCodeWorkspacesVisited()
1875+
private void RecallWorkSPaceVisited(string fromPluginExport)
18731876
{
1874-
if (SelectedEditorViewModel is not { IsVsCode: true } and not { IsCursor: true } and not
1875-
{ IsWindsurf: true })
1876-
{
1877-
return;
1878-
}
1879-
18801877
WorkspaceScopeViewModels.Clear();
18811878
int max = 20;
18821879
int count = 0;
1883-
foreach (var solutionId in ExternalPluginInteractions.Commander.GetSolutionIDsForCommands(PluginCommands.VisualStudioCodeWorkspaceUpdate))
1880+
foreach (var solutionId in ExternalPluginInteractions.Commander.GetSolutionIDsForCommands(fromPluginExport))
18841881
{
18851882
var workspaceScopeViewModel = new WorkspaceScopeViewModel(this, solutionId);
18861883
WorkspaceScopeViewModels.Add(workspaceScopeViewModel);
@@ -1905,6 +1902,25 @@ public void RecallVisualStudioCodeWorkspacesVisited()
19051902
}
19061903
}
19071904

1905+
public void RecallNVimWorkspacesVisited()
1906+
{
1907+
if (SelectedEditorViewModel is not { IsNeoVim: true })
1908+
{
1909+
return;
1910+
}
1911+
RecallWorkSPaceVisited(PluginCommands.NVimUpdateWorkspace);
1912+
}
1913+
public void RecallVisualStudioCodeWorkspacesVisited()
1914+
{
1915+
if (SelectedEditorViewModel is not { IsVsCode: true } and not { IsCursor: true } and not
1916+
{ IsWindsurf: true })
1917+
{
1918+
return;
1919+
}
1920+
1921+
RecallWorkSPaceVisited(PluginCommands.VisualStudioCodeWorkspaceUpdate);
1922+
}
1923+
19081924
private string GetNameFromSublimeTextWorkspace(FolderWorkspace workspace)
19091925
{
19101926
if (!string.IsNullOrEmpty(workspace.ProjectName))
@@ -1956,6 +1972,23 @@ private string GetNameFromSublimeTextWorkspace(FolderWorkspace workspace)
19561972
builder.Append(')');
19571973
return builder.ToString();
19581974
}
1975+
1976+
public void ApplyNVimWorkSpace(FolderWorkspace workspace)
1977+
{
1978+
SolutionViewModel = null;
1979+
WorkspaceScopeViewModels.Clear();
1980+
1981+
if (string.IsNullOrEmpty(workspace.Name))
1982+
{
1983+
workspace.Name = GetNameFromSublimeTextWorkspace(workspace);
1984+
}
1985+
var solutionId = SolutionID.CreateFromSolutionPath(workspace.Name);
1986+
var workspaceScopeViewModel = new WorkspaceScopeViewModel(this, solutionId,true)
1987+
{
1988+
WorkspaceExport = workspace
1989+
};
1990+
WorkspaceScopeViewModels.Insert(0, workspaceScopeViewModel);
1991+
}
19591992

19601993
public void ApplySublimeTextListOfWorkspaces(List<FolderWorkspace> workspaces)
19611994
{

src/Blitz.Avalonia.Controls/Views/BlitzMainPanel.axaml.cs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -265,10 +265,17 @@ private async void AcceptChangesClick(object? sender, RoutedEventArgs e)
265265
mainWindowViewModel.StopRespondingToCurrentQuery();
266266

267267
List<FileNameResult> items = [];
268-
foreach (var change in mainWindowViewModel.ResultBoxItems.OfType<FileNameResultViewModel>())
268+
HashSet<string> files = new HashSet<string>();
269+
foreach (var change in mainWindowViewModel.ResultBoxItems.OfType<ContentResultViewModel>())
269270
{
270-
items.Add(change.FileNameResult);
271+
if (files.Add(change.FileNameResult.FileName))
272+
{
273+
items.Add(change.FileNameResult);
274+
}
271275
}
276+
277+
278+
272279
mainWindowViewModel.ResultBoxItems.Clear();
273280
var summary = new StringBuilder();
274281
int total = items.Count;

src/Blitz.Avalonia.Controls/Views/ExternalPluginInteractions.cs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ private void RegisterCommands()
4242
_commander.RegisterAction(PluginCommands.UpdateVisualStudioProject, UpdateVisualStudioSelectedProject);
4343
_commander.RegisterAction(PluginCommands.UpdateVisualStudioActiveFiles, UpdateVisualStudioActiveFilesList);
4444
_commander.RegisterAction(PluginCommands.SublimeTextWorkspaceUpdate, UpdateSublimeTextWorkspace);
45+
_commander.RegisterAction(PluginCommands.NVimUpdateWorkspace, UpdateNVimWorkspace);
4546
_commander.RegisterAction(PluginCommands.SimpleFolderSearch, SetSimpleFolderSearch);
4647
_commander.ExecuteWithin(DateTime.UtcNow, TimeSpan.FromSeconds(2));
4748
}
@@ -423,6 +424,28 @@ private void UpdateVisualStudioSelectedProject(string text)
423424
}
424425

425426

427+
private void UpdateNVimWorkspace(string text)
428+
{
429+
if (string.IsNullOrEmpty(text))
430+
{
431+
return;
432+
}
433+
434+
Dispatcher.UIThread.Post(() =>
435+
{
436+
if (_viewModel is not { SelectedEditorViewModel.IsSublimeText: true })
437+
{
438+
return;
439+
}
440+
var workspace = JsonSerializer.Deserialize(text, JsonContext.Default.FolderWorkspace);
441+
if (workspace is null)
442+
{
443+
return;
444+
}
445+
_viewModel.ApplyNVimWorkSpace(workspace);
446+
});
447+
}
448+
426449

427450
private void UpdateSublimeTextWorkspace(string text)
428451
{

src/Blitz.Search/Searching.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -415,6 +415,10 @@ private static bool IsOldQueryRecyclable(IBlitzMatchingQuery oldSubQuery, IBlitz
415415
{
416416
return false;
417417
}
418+
else if (oldWordInQuery.SearchWord != newWordQuery.SearchWord)
419+
{
420+
return false;
421+
}
418422
if (oldWordInQuery.CaseSensitive != newWordQuery.CaseSensitive)
419423
{
420424
return false;

src/Blitz/Blitz.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414
<PackageIcon>Assets\BlitzIcon.ico</PackageIcon>
1515
<RepositoryUrl>https://github.com/Natestah/BlitzSearch</RepositoryUrl>
1616
<ApplicationIcon>Assets\BlitzIcon.ico</ApplicationIcon>
17-
<AssemblyVersion>1.0.24</AssemblyVersion>
18-
<FileVersion>1.0.24</FileVersion>
17+
<AssemblyVersion>1.0.25</AssemblyVersion>
18+
<FileVersion>1.0.25</FileVersion>
1919
<AssemblyOriginatorKeyFile>BlitzSign.snk</AssemblyOriginatorKeyFile>
2020
<PublicSign>false</PublicSign>
2121
</PropertyGroup>

src/Blitz/Documentation/Change_Log.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
# Change Log
22

33
#### Come join me on.. [Discord](https://discord.com/invite/UYPwQY9ngm) and give feedback!
4-
4+
### Version 1.0.25
5+
* Fix Highlighting issue introduced with trimming result spaces
6+
* Fixed Replace being broken with new flat mode
7+
* Fixed a result recycling issue with whole word matches.
58
### Version 1.0.24
69
* Don't dim Line Numbers
710
* Trim leading Spaces from results to pull in those far tabbed code results.

0 commit comments

Comments
 (0)