Skip to content

Commit 74db885

Browse files
jenstroegermarcbachmann
authored andcommitted
feat(selection): Remove nodes based on tag name and class.
1 parent 7c23958 commit 74db885

File tree

2 files changed

+9
-6
lines changed

2 files changed

+9
-6
lines changed

src/content.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -303,18 +303,19 @@ export function removeFormattingElem (host, range, elem) {
303303
})
304304
}
305305

306-
export function removeFormatting (host, range, tagName) {
306+
export function removeFormatting (host, range, tagName, className) {
307307
return restoreRange(host, range, () => {
308-
nuke(host, range, tagName)
308+
nuke(host, range, tagName, className)
309309
})
310310
}
311311

312312
// Unwrap all tags this range is affected by.
313313
// Can also affect content outside of the range.
314-
export function nuke (host, range, tagName) {
314+
export function nuke (host, range, tagName, className) {
315315
getTags(host, range).forEach((elem) => {
316316
if (elem.nodeName.toUpperCase() !== 'BR' &&
317-
(!tagName || elem.nodeName.toUpperCase() === tagName.toUpperCase())) {
317+
(!tagName || (elem.nodeName.toUpperCase() === tagName.toUpperCase() &&
318+
(!className || elem.classList.contains(className))))) {
318319
unwrap(elem)
319320
}
320321
})

src/selection.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -204,8 +204,10 @@ export default class Selection extends Cursor {
204204
}
205205

206206
// @param {String} tagName. E.g. 'a' to remove all links; if undefined, remove all.
207-
removeFormatting (tagName) {
208-
this.range = content.removeFormatting(this.host, this.range, tagName)
207+
// @param {String} className. E.g. 'foo' to remove all links 'a.foo'; if undefined,
208+
// disregard the className.
209+
removeFormatting (tagName, className) {
210+
this.range = content.removeFormatting(this.host, this.range, tagName, className)
209211
this.setSelection()
210212
}
211213

0 commit comments

Comments
 (0)