Skip to content

Commit dd4aeb6

Browse files
committed
Allow shortcuts even when nothing is selected
1 parent cc02c9e commit dd4aeb6

File tree

2 files changed

+2
-5
lines changed

2 files changed

+2
-5
lines changed

src/LinkDotNet.Blog.Web/Shared/TextAreaWithShortcuts.razor

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,17 +61,14 @@
6161
string fence)
6262
{
6363
var selectionRange = await jsRuntime.InvokeAsync<SelectionRange>("getSelectionFromElement", elementId);
64-
if (selectionRange.Start == selectionRange.End)
65-
{
66-
return content;
67-
}
6864

6965
var beforeMarker = selectionRange.Start > 0 ? content[..selectionRange.Start] : string.Empty;
7066
var selectedContent = content[selectionRange.Start..selectionRange.End];
7167
var fencedContent = fence.Replace(SelectedMarker, selectedContent);
7268
var afterMarker = content[selectionRange.End..];
7369
var shift = selectionRange.Start + fencedContent.IndexOf(CursorMarker, StringComparison.Ordinal);
7470
var removedCursor = fencedContent.Replace(CursorMarker, string.Empty);
71+
7572
await jsRuntime.InvokeVoidAsync("setSelectionFromElement", elementId, shift, removedCursor);
7673
return beforeMarker + removedCursor + afterMarker;
7774
}

tests/LinkDotNet.Blog.UnitTests/Web/Shared/TextAreaWithShortcutsTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public class TextAreaWithShortcutsTests : TestContext
1515
[InlineData("h", 0, 1, true, "Test")]
1616
[InlineData("b", 0, 1, false, "Test")]
1717
[InlineData("f", 0, 4, false, "Test")]
18-
[InlineData("b", 0, 0, true, "Test")]
18+
[InlineData("b", 0, 0, true, "****Test")]
1919
public void ShouldSetMarkerOnKeyUp(string key, int start, int end, bool ctrlPressed, string expected)
2020
{
2121
const string id = "id";

0 commit comments

Comments
 (0)