Skip to content

Hoist helper functions from Selection into Cursor class. #196

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 1, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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