Skip to content

Commit 0b2fd7f

Browse files
Version 0.0.6
1 parent 09fb5f9 commit 0b2fd7f

File tree

2 files changed

+22
-5
lines changed

2 files changed

+22
-5
lines changed

src/Component/Component.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
<PropertyGroup>
1717
<!-- Basic Info -->
1818
<PackageId>JsonViewer.Blazor</PackageId>
19-
<Version>0.0.5-beta</Version>
19+
<Version>0.0.6-beta</Version>
2020
<Title>JSON Viewer for Blazor</Title>
2121
<Authors>Parsa Panahpoor</Authors>
2222
<Company>JsonViewer-Component</Company>

src/Component/Core/Features/JsonPathDisplay.razor

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
@using Component.Models
22
@using Microsoft.JSInterop
33
@using Component.Core.Shared
4+
@using System.Threading
45
@inject IJSRuntime JSRuntime
56
@implements IDisposable
67

@@ -105,6 +106,7 @@
105106

106107
private bool isCopied = false;
107108
private DotNetObjectReference<JsonPathDisplay>? dotNetHelper;
109+
private CancellationTokenSource? copyCancellationTokenSource;
108110

109111
protected override async Task OnAfterRenderAsync(bool firstRender)
110112
{
@@ -151,13 +153,25 @@
151153
{
152154
if (PathInfo == null) return;
153155

156+
// Cancel any existing copy operation
157+
copyCancellationTokenSource?.Cancel();
158+
copyCancellationTokenSource?.Dispose();
159+
copyCancellationTokenSource = new CancellationTokenSource();
160+
154161
await OnCopyPath.InvokeAsync(PathInfo.Path);
155162
isCopied = true;
156163
StateHasChanged();
157164

158-
await Task.Delay(2000);
159-
isCopied = false;
160-
StateHasChanged();
165+
try
166+
{
167+
await Task.Delay(2000, copyCancellationTokenSource.Token);
168+
isCopied = false;
169+
StateHasChanged();
170+
}
171+
catch (OperationCanceledException)
172+
{
173+
// Operation was cancelled, ignore
174+
}
161175
}
162176

163177
private string TruncateValue(string value, int maxLength = 200)
@@ -167,11 +181,14 @@
167181
if (value.Length <= maxLength)
168182
return value;
169183

170-
return value.Substring(0, maxLength) + "...";
184+
// Use modern string slicing (more efficient)
185+
return string.Concat(value.AsSpan(0, maxLength), "...");
171186
}
172187

173188
public void Dispose()
174189
{
190+
copyCancellationTokenSource?.Cancel();
191+
copyCancellationTokenSource?.Dispose();
175192
dotNetHelper?.Dispose();
176193
}
177194
}

0 commit comments

Comments
 (0)