Skip to content

Commit

Permalink
feat(cursor): Hoist helper functions from Selection class.
Browse files Browse the repository at this point in the history
  • Loading branch information
jenstroeger authored and peyerluk committed Jul 1, 2021
1 parent bd0d445 commit 8e42af7
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 29 deletions.
29 changes: 29 additions & 0 deletions src/cursor.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,35 @@ export default class Cursor {
this.isCursor = true
}

// Get all tags that affect the current selection. Optionally pass a
// method to filter the returned elements.
//
// @param {Function filter(node)} [Optional] Method to filter the returned
// DOM Nodes.
// @return {Array of DOM Nodes}
getTags (filterFunc) {
return content.getTags(this.host, this.range, filterFunc)
}

// Get the names of all tags that affect the current selection. Optionally
// pass a method to filter the returned elements.
//
// @param {Function filter(node)} [Optional] Method to filter the DOM
// Nodes whose names are returned.
// @return {Array<String> of tag names}
getTagNames (filterFunc) {
return content.getTagNames(this.getTags(filterFunc))
}

// Get all tags of the specified type that affect the current selection.
//
// @method getTagsByName
// @param {String} tagName. E.g. 'a' to get all links.
// @return {Array of DOM Nodes}
getTagsByName (tagName) {
return content.getTagsByName(this.host, this.range, tagName)
}

isAtEnd () {
return parser.isEndOfHost(
this.host,
Expand Down
29 changes: 0 additions & 29 deletions src/selection.js
Original file line number Diff line number Diff line change
Expand Up @@ -249,35 +249,6 @@ export default class Selection extends Cursor {
this.setSelection()
}

// Get all tags that affect the current selection. Optionally pass a
// method to filter the returned elements.
//
// @param {Function filter(node)} [Optional] Method to filter the returned
// DOM Nodes.
// @return {Array of DOM Nodes}
getTags (filterFunc) {
return content.getTags(this.host, this.range, filterFunc)
}

// Get the names of all tags that affect the current selection. Optionally
// pass a method to filter the returned elements.
//
// @param {Function filter(node)} [Optional] Method to filter the DOM
// Nodes whose names are returned.
// @return {Array<String> of tag names}
getTagNames (filterFunc) {
return content.getTagNames(this.getTags(filterFunc))
}

// Get all tags of the specified type that affect the current selection.
//
// @method getTagsByName
// @param {String} tagName. E.g. 'a' to get all links.
// @return {Array of DOM Nodes}
getTagsByName (tagName) {
return content.getTagsByName(this.host, this.range, tagName)
}

// Check if the selection is the same as the elements contents.
//
// @method isExactSelection
Expand Down

0 comments on commit 8e42af7

Please sign in to comment.