Skip to content

Commit

Permalink
fix: pasting text that is surrounded by markup
Browse files Browse the repository at this point in the history
If text is exactly surrounded by markup, delete the markup as well.
  • Loading branch information
Muhameti-centralsoft committed Aug 9, 2022
1 parent fd0647c commit c384d69
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions src/selection.js
Original file line number Diff line number Diff line change
Expand Up @@ -245,11 +245,25 @@ export default class Selection extends Cursor {
this.setSelection()
}

// Delete the contents inside the range. After that the selection will be a
// cursor.
// Delete the farest ancestor that is an exact selection
deleteExactSurroundingMarkups () {
const markupTags = this.getAncestorTags(
(elem) => ['STRONG', 'EM'].includes(elem.nodeName)
).reverse()
for (const markupTag of markupTags) {
if (this.isExactSelection(markupTag)) {
markupTag.remove()
break
}
}
}

// Delete the contents inside the range and exact surrounding markups.
// After that the selection will be a cursor.
//
// @return Cursor instance
deleteContent () {
this.deleteExactSurroundingMarkups()
this.range.deleteContents()
return new Cursor(this.host, this.range)
}
Expand Down

0 comments on commit c384d69

Please sign in to comment.