diff --git a/index.test.ts b/index.test.ts index 7cc2781..9c818be 100644 --- a/index.test.ts +++ b/index.test.ts @@ -121,6 +121,8 @@ for (const type of ['textarea', 'input', 'contenteditable'] as const) { const field = getField(type, 'W{O}A'); wrapFieldSelection(field, '[', ']'); t.equal(getState(field), 'W[{O}]A'); + wrapFieldSelection(field, '

', '

'); + t.equal(getState(field), 'W[

{O}

]A'); t.end(); }); diff --git a/index.ts b/index.ts index 5d64172..a45d41f 100644 --- a/index.ts +++ b/index.ts @@ -94,7 +94,7 @@ function wrapFieldSelectionNative( // Restore the selection around the previously-selected text field.selectionStart = selectionStart! + wrap.length; - field.selectionEnd = selectionEnd! + wrapEnd.length; + field.selectionEnd = selectionEnd! + wrap.length; } function collapseCursor(selection: Selection, range: Range, toStart: boolean) {