Skip to content

Commit c384d69

Browse files
fix: pasting text that is surrounded by markup
If text is exactly surrounded by markup, delete the markup as well.
1 parent fd0647c commit c384d69

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

src/selection.js

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -245,11 +245,25 @@ export default class Selection extends Cursor {
245245
this.setSelection()
246246
}
247247

248-
// Delete the contents inside the range. After that the selection will be a
249-
// cursor.
248+
// Delete the farest ancestor that is an exact selection
249+
deleteExactSurroundingMarkups () {
250+
const markupTags = this.getAncestorTags(
251+
(elem) => ['STRONG', 'EM'].includes(elem.nodeName)
252+
).reverse()
253+
for (const markupTag of markupTags) {
254+
if (this.isExactSelection(markupTag)) {
255+
markupTag.remove()
256+
break
257+
}
258+
}
259+
}
260+
261+
// Delete the contents inside the range and exact surrounding markups.
262+
// After that the selection will be a cursor.
250263
//
251264
// @return Cursor instance
252265
deleteContent () {
266+
this.deleteExactSurroundingMarkups()
253267
this.range.deleteContents()
254268
return new Cursor(this.host, this.range)
255269
}

0 commit comments

Comments
 (0)