Retrieves the common ancestor node of the first range and the last range.
@returns {CKEDITOR.dom.element} The common ancestor of the selection.
@example
var ancestor = editor.getSelection().<strong>getCommonAncestor()</strong>;
321604
function()
		{
			var ranges = this.getRanges(),
				startNode = ranges[ 0 ].startContainer,
				endNode = ranges[ ranges.length - 1 ].endContainer;
			return startNode.getCommonAncestor( endNode );
		}
293727
function() {
			var endContainer = this.endContainer,
				endOffset = this.endOffset;

			// [IE] Special handling for range end in text with a following NBSP,
			// we it to be isolated, for bogus check.
			if ( CKEDITOR.env.ie && endContainer.type == CKEDITOR.NODE_TEXT )
			{
				var textAfter = CKEDITOR.tools.rtrim( endContainer.substring( endOffset ) );
				if ( nbspRegExp.test( textAfter ) )
					this.trim( 1, 0 );
			}

			// Antecipate the trim() call here, so the walker will not make
			// changes to the DOM, which would not get reflected into this
			// range otherwise.
			this.trim();

			// We need to grab the block element holding the start boundary, so
			// let's use an element path for it.
			var path = new CKEDITOR.dom.elementPath( this.endContainer, this.root );

			// Creates a range starting at the block start until the range start.
			var walkerRange = this.clone();
			walkerRange.collapse( false );
			walkerRange.setEndAt( path.block || path.blockLimit, CKEDITOR.POSITION_BEFORE_END );

			var walker = new CKEDITOR.dom.walker( walkerRange );
			walker.evaluator = getCheckStartEndBlockEvalFunction();

			return walker.checkForward();
		}
1260346
private JComponent getEffectiveClippingAncestor() {
        JComponent clippingComponent = clippingAncestor;

        if ((clippingComponent == null) && (decoratedComponent != null)) {
            // No specific clipping ancestor specified by the programmer, so try to find one

            // Keep a reference to the best alternative candidate if no other proper ancestor can be found
            Container lastNonNullParent = decoratedComponent;

            // Look for the first viewport or layered pane in the component hierarchy tree
            Container parent = decoratedComponent.getParent();
            while ((parent != null) && (clippingComponent == null)) {
                lastNonNullParent = parent;
                if ((parent instanceof JViewport) || (parent instanceof JLayeredPane)) {
                    clippingComponent = (JComponent) parent;
                }
                parent = parent.getParent();
            }

            if (clippingComponent == null) {
                // This may be a normal case depending on the application logic to hide a panel (tabbed pane like)
                if (lastNonNullParent instanceof JComponent) {
                    clippingComponent = (JComponent) lastNonNullParent;
                }
            }
        }

        return clippingComponent;
    }
1351386
public ElemTemplateElement getLastChildElem()
  {

    ElemTemplateElement lastChild = null;

    for (ElemTemplateElement node = m_firstChild; node != null;
            node = node.m_nextSibling)
    {
      lastChild = node;
    }

    return lastChild;
  }
731934
function (node, pred) {
            var ancestors = listAncestor(node);
            return list.last(ancestors.filter(pred));
        }
671053
function getNodes(sel) {
	var range = getRange(sel);
	if (!range) { return []; }

	var node = range.startContainer;
	var endNode = range.endContainer;

	// Special case for a range that is contained within a single node
	if (node === endNode) { return [node]; }

	// Iterate nodes until we hit the end container
	var nodes = [];
	while (node && node !== endNode) {
		nodes.push(node = nextNode(node));
	}

	// Add partially selected nodes at the start of the range
	node = range.startContainer;
	while (node && node !== range.commonAncestorContainer) {
		nodes.unshift(node);
		node = node.parentNode;
	}

	return nodes;
}
234286
function (node, pred) {
            pred = pred || func.fail;

            var ancestors = [];
            ancestor(node, function (el) {
                if (!isEditable(el)) {
                    ancestors.push(el);
                }

                return pred(el);
            });
            return ancestors;
        }
426304
function selectionRangesForHTMLNode(node) {
	const ranges = [new Range(node.start, node.end)];
	if (node.close) {
		ranges.push(new Range(node.open.end, node.close.start));
	}

	return ranges;
}
7213
function findCommonOffsetParent(element1, element2) {
  // This check is needed to avoid errors in case one of the elements isn't defined for any reason
  if (!element1 || !element1.nodeType || !element2 || !element2.nodeType) {
    return document.documentElement;
  }

  // Here we make sure to give as "start" the element that comes first in the DOM
  const order = element1.compareDocumentPosition(element2) & Node.DOCUMENT_POSITION_FOLLOWING;
  const start = order ? element1 : element2;
  const end = order ? element2 : element1;

  // Get common ancestor container
  const range = document.createRange();
  range.setStart(start, 0);
  range.setEnd(end, 0);
  const { commonAncestorContainer } = range;

  // Both nodes are inside #document
  if (element1 !== commonAncestorContainer && element2 !== commonAncestorContainer || start.contains(end)) {
    if (isOffsetContainer(commonAncestorContainer)) {
      return commonAncestorContainer;
    }

    return getOffsetParent(commonAncestorContainer);
  }

  // one of the nodes is inside shadowDOM, find which one
  const element1root = getRoot(element1);
  if (element1root.host) {
    return findCommonOffsetParent(element1root.host, element2);
  } else {
    return findCommonOffsetParent(element1, getRoot(element2).host);
  }
}
769135
function () {
      var range = this.el.ownerDocument.getSelection().getRangeAt(0).cloneRange();
      var wrapperNode = range.endContainer.parentNode;
      var node = this.el.ownerDocument.createElement('span');
      range.insertNode(node);
      range.selectNodeContents(node);
      range.deleteContents();
      setTimeout(function() { wrapperNode.normalize(); }, 0);
      var $node = $(node);
      var position = $node.offset();
      position.left -= this.$el.offset().left;
      position.top += $node.height() - this.$el.offset().top;
      position.lineHeight = $node.height();
      
      // special positioning logic for iframes
      // this is typically used for contenteditables such as tinymce or ckeditor
      if (this.completer.$iframe) {
        var iframePosition = this.completer.$iframe.offset();
        position.top += iframePosition.top;
        position.left += iframePosition.left;
        // We need to get the scrollTop of the html-element inside the iframe and not of the body-element,
        // because on IE the scrollTop of the body-element (this.$el) is always zero.
        position.top -= $(this.completer.$iframe[0].contentWindow.document).scrollTop();
      }
      
      $node.remove();
      return position;
    }
117834
function getPreviousItemRange(model, anchor, getItemRanges) {
	// Find HTML node for next selection
	let node = nodeForPoint(model, anchor.start, 'previous');
	let range;

	// We might need to narrow down node context to find best token match
	while (node) {
		range = getPreviousRange(getItemRanges(node), anchor);
		if (range) {
			break;
		}
		node = previousSibling(node) || node.parent;
	}

	return range;
}
278656
function() {
					var range = self.getRanges()[ 0 ].clone(),
						enclosed, selected;

					// Check first any enclosed element, e.g. <ul>[<li><a href="#">item</a></li>]</ul>
					for ( var i = 2; i && !( ( enclosed = range.getEnclosedNode() ) && ( enclosed.type == CKEDITOR.NODE_ELEMENT ) && styleObjectElements[ enclosed.getName() ] && ( selected = enclosed ) ); i-- ) {
						// Then check any deep wrapped element, e.g. [<b><i><img /></i></b>]
						range.shrink( CKEDITOR.SHRINK_ELEMENT );
					}

					return selected && selected.$;
				}
937758
function() {
			var out = [];
			if (this.parent) {
				// add current range if it is not root node
				out.push(this.range);
			}

			this.children.forEach(function(child) {
				out = out.concat(child.allRanges());
			});

			return out;
		}
185139
public static org.w3c.dom.Element findAnchorElement(org.w3c.dom.Element e)
    {
        if ("a".equalsIgnoreCase(e.getTagName().trim()))
            return e;
        else if (e.getParentNode() != null && e.getParentNode().getNodeType() == Node.ELEMENT_NODE)
            return findAnchorElement((org.w3c.dom.Element) e.getParentNode());
        else
            return null;
    }
189544
function() {
        var doc,
            nodes = this._nodes,
            query = this._query,
            root = this._queryRoot;

        if (query) {
            if (!root) {
                if (nodes && nodes[0] && nodes[0].ownerDocument) {
                    root = nodes[0].ownerDocument;
                }
            }

            this._nodes = Y.Selector.query(query, root);
        }

        return this;
    }
3280
function getAllAncestors(el) {
  var ancestors = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
  var nextAncestor = el.parentNode;

  if (!nextAncestor) {
    return ancestors;
  }

  ancestors.push(nextAncestor);
  return getAllAncestors(nextAncestor, ancestors);
}
521135
public Node previousNode() {

		if (currentNode == null)
			return null;

		// get sibling
		Node result = getPreviousSibling(currentNode);
		if (result == null) {
			result = getParentNode(currentNode);
			if (result != null) {
				currentNode = result;
				return result;
			}
			return null;
		}

		// get the lastChild of result.
		Node lastChild = getLastChild(result);

		Node prev = lastChild;
		while (lastChild != null) {
			prev = lastChild;
			lastChild = getLastChild(prev);
		}

		lastChild = prev;

		// if there is a lastChild which passes filters return it.
		if (lastChild != null) {
			currentNode = lastChild;
			return lastChild;
		}

		// otherwise return the previous sibling.
		currentNode = result;
		return result;
	}