MCPcopy
hub / github.com/philc/vimium / establishInitialSelectionAnchor

Method establishInitialSelectionAnchor

content_scripts/mode_visual.js:592–611  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

590 // TODO(smblott). It might be better to do something similar to Clearly or Readability; that is,
591 // try to find the start of the page's main textual content.
592 establishInitialSelectionAnchor() {
593 let node;
594 const nodes = document.createTreeWalker(document.body, NodeFilter.SHOW_TEXT);
595 while ((node = nodes.nextNode())) {
596 // Don't choose short text nodes; they're likely to be part of a banner.
597 if ((node.nodeType === 3) && (50 <= node.data.trim().length)) {
598 const element = node.parentElement;
599 if (DomUtils.getVisibleClientRect(element) && !DomUtils.isEditable(element)) {
600 // Start at the offset of the first non-whitespace character.
601 const offset = node.data.length - node.data.replace(/^\s+/, "").length;
602 const range = document.createRange();
603 range.setStart(node, offset);
604 range.setEnd(node, offset);
605 this.movement.setSelectionRange(range);
606 return true;
607 }
608 }
609 }
610 return false;
611 }
612}
613
614globalThis.VisualMode = VisualMode;

Callers 1

initMethod · 0.95

Calls 1

setSelectionRangeMethod · 0.80

Tested by

no test coverage detected