@@ -37,6 +37,35 @@ export default class Cursor {
37
37
this . isCursor = true
38
38
}
39
39
40
+ // Get all tags that affect the current selection. Optionally pass a
41
+ // method to filter the returned elements.
42
+ //
43
+ // @param {Function filter(node) } [Optional] Method to filter the returned
44
+ // DOM Nodes.
45
+ // @return {Array of DOM Nodes }
46
+ getTags ( filterFunc ) {
47
+ return content . getTags ( this . host , this . range , filterFunc )
48
+ }
49
+
50
+ // Get the names of all tags that affect the current selection. Optionally
51
+ // pass a method to filter the returned elements.
52
+ //
53
+ // @param {Function filter(node) } [Optional] Method to filter the DOM
54
+ // Nodes whose names are returned.
55
+ // @return {Array<String> of tag names }
56
+ getTagNames ( filterFunc ) {
57
+ return content . getTagNames ( this . getTags ( filterFunc ) )
58
+ }
59
+
60
+ // Get all tags of the specified type that affect the current selection.
61
+ //
62
+ // @method getTagsByName
63
+ // @param {String } tagName. E.g. 'a' to get all links.
64
+ // @return {Array of DOM Nodes }
65
+ getTagsByName ( tagName ) {
66
+ return content . getTagsByName ( this . host , this . range , tagName )
67
+ }
68
+
40
69
isAtEnd ( ) {
41
70
return parser . isEndOfHost (
42
71
this . host ,
@@ -341,6 +370,24 @@ export default class Cursor {
341
370
return content . adoptElement ( node , this . win . document )
342
371
}
343
372
373
+ // Check whether the cursor's closest parent element node matches
374
+ // the given tagName (and optional className), and return that
375
+ // parent if it does or null if not.
376
+ getParentContainer ( tagName , className ) {
377
+ const tags = this . getTags ( )
378
+
379
+ let node = tags . shift ( )
380
+ if ( node . nodeType !== Node . TEXT_NODE ) return null
381
+
382
+ if ( tags . length === 0 ) return null
383
+
384
+ node = tags . shift ( )
385
+ if ( node . nodeName !== tagName ) return null
386
+ if ( className && ! node . classList . contains ( className ) ) return null
387
+
388
+ return node
389
+ }
390
+
344
391
// Currently we call triggerChange manually after format changes.
345
392
// This is to prevent excessive triggering of the change event during
346
393
// merge or split operations or other manipulations by scripts.
0 commit comments