From eda7c0985965d7f004f685b1d9dfe69b78bd7340 Mon Sep 17 00:00:00 2001 From: Jens Troeger Date: Thu, 29 Oct 2020 16:11:28 +1000 Subject: [PATCH] feat(cursor): Hoist helper functions from Selection class. --- src/cursor.js | 29 +++++++++++++++++++++++++++++ src/selection.js | 29 ----------------------------- 2 files changed, 29 insertions(+), 29 deletions(-) diff --git a/src/cursor.js b/src/cursor.js index 69ffa82d..ca959cb0 100644 --- a/src/cursor.js +++ b/src/cursor.js @@ -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 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, diff --git a/src/selection.js b/src/selection.js index 7abc9e74..3c6bd681 100644 --- a/src/selection.js +++ b/src/selection.js @@ -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 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