Skip to content

Commit c185471

Browse files
committed
Put formatting on undo stack
1 parent d027f0b commit c185471

File tree

3 files changed

+4
-2
lines changed

3 files changed

+4
-2
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@
7272
var afterMarker = content[selectionRange.End..];
7373
var shift = selectionRange.Start + fencedContent.IndexOf(CursorMarker, StringComparison.Ordinal);
7474
var removedCursor = fencedContent.Replace(CursorMarker, string.Empty);
75-
await jsRuntime.InvokeVoidAsync("setSelectionFromElement", elementId, shift);
75+
await jsRuntime.InvokeVoidAsync("setSelectionFromElement", elementId, shift, removedCursor);
7676
return beforeMarker + removedCursor + afterMarker;
7777
}
7878
}

src/LinkDotNet.Blog.Web/wwwroot/components/selection.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@ window.getSelectionFromElement = function (id) {
55
return { start, end }
66
}
77

8-
window.setSelectionFromElement = function (id, cursor) {
8+
window.setSelectionFromElement = function (id, cursor, newText) {
99
const elem = document.getElementById(id)
10+
document.execCommand("insertText", false, newText)
1011
elem.selectionStart = cursor
1112
elem.selectionEnd = cursor
1213
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,5 +52,6 @@ public void ShouldSetCursorPosition()
5252
var setSelection = JSInterop.Invocations.SingleOrDefault(s => s.Identifier == "setSelectionFromElement");
5353
setSelection.Arguments.Should().Contain(element);
5454
setSelection.Arguments.Should().Contain(9);
55+
setSelection.Arguments.Should().Contain("**llo**");
5556
}
5657
}

0 commit comments

Comments
 (0)