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

Method rotateHints

content_scripts/link_hints.js:625–691  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

623
624 // Rotate the hints' z-index values so that hidden hints become visible.
625 rotateHints() {
626 // Partitions array into two arrays, based on the bool return value of predicate.
627 function partition(array, predicate) {
628 const a = [];
629 const b = [];
630 for (const item of array) {
631 const target = predicate(item) ? a : b;
632 target.push(item);
633 }
634 return [a, b];
635 }
636
637 // Get local, visible hint markers.
638 const [localMarkers, otherMarkers] = partition(
639 this.hintMarkers,
640 (m) => m.isLocalMarker() && (m.element.style.display !== "none"),
641 );
642
643 // Fill in the markers' rects, if necessary.
644 for (const m of localMarkers) {
645 if (m.markerRect == null) {
646 m.markerRect = m.element.getClientRects()[0];
647 }
648 }
649
650 // Calculate the overlapping groups of hints. We call each group a "stack". This is O(n^2).
651 let stacks = [];
652 for (const m of localMarkers) {
653 let stackForThisMarker = null;
654 const results = [];
655 for (const stack of stacks) {
656 const markerOverlapsThisStack = this.markerOverlapsStack(m, stack);
657 if (markerOverlapsThisStack && (stackForThisMarker == null)) {
658 // We've found an existing stack for this marker.
659 stack.push(m);
660 stackForThisMarker = stack;
661 results.push(stack);
662 } else if (markerOverlapsThisStack && (stackForThisMarker != null)) {
663 // This marker overlaps a second (or subsequent) stack; merge that stack into
664 // stackForThisMarker and discard it.
665 stackForThisMarker.push(...stack);
666 continue; // Discard this stack.
667 } else {
668 stack; // Keep this stack.
669 results.push(stack);
670 }
671 }
672 stacks = results;
673
674 if (stackForThisMarker == null) {
675 stacks.push([m]);
676 }
677 }
678
679 let newMarkers = [];
680 for (let stack of stacks) {
681 if (stack.length > 1) {
682 // Push the last element to the beginning.

Callers 1

rotateHintsFunction · 0.80

Calls 4

markerOverlapsStackMethod · 0.95
renderHintsMethod · 0.95
isLocalMarkerMethod · 0.80
pushMethod · 0.45

Tested by

no test coverage detected