Skip to content

Commit

Permalink
Fix paste of content in mid-line
Browse files Browse the repository at this point in the history
  • Loading branch information
rdaum committed Jan 31, 2025
1 parent c9dada5 commit 6c87ec1
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions crates/web-host/src/client/narrative.ts
Original file line number Diff line number Diff line change
Expand Up @@ -418,13 +418,11 @@ const InputArea = (context: Context, player: State<Player>) => {
e.preventDefault();
const pastedData = e.clipboardData?.getData("text") || "";
if (pastedData) {
// Append to the input field with the pasted content as-is, not interpreted as
// key-strokes.
i.value += pastedData;
// Insert the pasted data at the current cursor position.
i.value = i.value.substring(0, i.selectionStart) + pastedData + i.value.substring(i.selectionEnd);

// Jump the selection to the end of the line
i.selectionStart = i.value.length;
i.selectionEnd = i.value.length;
// Jump the selection to the end of the pasted part
i.selectionStart = i.selectionEnd = i.selectionStart + pastedData.length;
}
});
i.addEventListener("keydown", e => {
Expand Down

0 comments on commit 6c87ec1

Please sign in to comment.