+ var htmlElement = this.rootWrapper.find('.current-text-element')[0];
+ if(htmlElement) {
+ return this.getDocumentElement(htmlElement);
+ }
+ },
+
+ getPreviousTextElement: function(relativeToElement, includeInvisible) {
+ return this.getNearestTextElement('above', relativeToElement, includeInvisible);
+ },
+
+ getNextTextElement: function(relativeToElement, includeInvisible) {
+ return this.getNearestTextElement('below', relativeToElement, includeInvisible);
+ },
+
+ getNearestTextElement: function(direction, relativeToElement, includeInvisible) {
+ includeInvisible = includeInvisible !== undefined ? includeInvisible : false;
+ var selector = '[document-text-element]' + (includeInvisible ? '' : ':visible');
+ return this.getDocumentElement(utils.nearestInDocumentOrder(selector, direction, relativeToElement.dom[0]));
+ },
+
+ contains: function(element) {
+ return element && element.dom && element.dom.parents().index(this.rootWrapper) !== -1;
+ },
+
+ triggerSelectionChanged: function() {
+ var s = this.getSelection(),
+ f;
+ if(!s) {
+ return;
+ }
+ this.trigger('selectionChanged', s);
+ f = s.toDocumentFragment();
+
+ if(f && f instanceof f.RangeFragment) {
+ if(this.currentNodeElement) {
+ this.currentNodeElement.updateState({active: false});
+ this.currentNodeElement = null;
+ }
+ }
+ },
+
+ getSelection: function() {
+ return selection.fromNativeSelection(this);