Skip to content

Commit cc6ffa3

Browse files
jenstroegermarcbachmann
authored andcommitted
feat(selection): Add helper functions to select tags.
1 parent 4fd1f77 commit cc6ffa3

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

src/content.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,9 +161,14 @@ export function unwrapInternalNodes (sibling, keepUiElements) {
161161

162162
// Get all tags that start or end inside the range
163163
export function getTags (host, range, filterFunc) {
164-
const tags = getInnerTags(range, filterFunc)
164+
const innerTags = getInnerTags(range, filterFunc)
165+
const ancestorTags = getAncestorTags(host, range, filterFunc)
166+
return innerTags.concat(ancestorTags)
167+
}
165168

166-
// get all tags that surround the range
169+
// Get all ancestor tags that start or end inside the range
170+
export function getAncestorTags (host, range, filterFunc) {
171+
let tags = []
167172
let node = range.commonAncestorContainer
168173
while (node !== host) {
169174
if (!filterFunc || filterFunc(node)) tags.push(node)

src/cursor.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,16 @@ export default class Cursor {
6565
return content.getTagsByName(this.host, this.range, tagName)
6666
}
6767

68+
// Get all tags that are completely withing the current selection.
69+
getInnerTags (filterFunc) {
70+
return content.getInnerTags(this.range, filterFunc)
71+
}
72+
73+
// Get all tags that surround the current selection.
74+
getAncestorTags (filterFunc) {
75+
return content.getAncestorTags(this.host, this.range, filterFunc)
76+
}
77+
6878
isAtEnd () {
6979
return parser.isEndOfHost(
7080
this.host,

0 commit comments

Comments
 (0)