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

Method constructor

content_scripts/link_hints.js:361–410  ·  view source on GitHub ↗
(hintDescriptors, mode)

Source from the content-addressed store, hash-verified

359class LinkHintsMode {
360 // @mode: One of the enums listed at the top of this file.
361 constructor(hintDescriptors, mode) {
362 if (mode == null) mode = OPEN_IN_CURRENT_TAB;
363 this.mode = mode;
364 // We need documentElement to be ready in order to append links.
365 if (!document.documentElement) return;
366
367 this.containerEl = null;
368 // Function that does the appropriate action on the selected link.
369 this.linkActivator = undefined;
370 // The link-hints "mode" (in the key-handler, indicator sense).
371 this.hintMode = null;
372 // A count of the number of Tab presses since the last non-Tab keyboard event.
373 this.tabCount = 0;
374
375 if (hintDescriptors.length === 0) {
376 HUD.show("No links to select.", 2000);
377 return;
378 }
379
380 // This count is used to rank equal-scoring hints when sorting, thereby making JavaScript's sort
381 // stable.
382 this.stableSortCount = 0;
383 this.hintMarkers = hintDescriptors.map((desc) => this.createMarkerFor(desc));
384 this.markerMatcher = Settings.get("filterLinkHints") ? new FilterHints() : new AlphabetHints();
385 this.markerMatcher.fillInMarkers(this.hintMarkers);
386
387 this.hintMode = new Mode();
388 this.hintMode.init({
389 name: `hint/${this.mode.name}`,
390 indicator: false,
391 singleton: "link-hints-mode",
392 suppressAllKeyboardEvents: true,
393 suppressTrailingKeyEvents: true,
394 exitOnEscape: true,
395 exitOnClick: true,
396 keydown: this.onKeyDownInMode.bind(this),
397 });
398
399 this.hintMode.onExit((event) => {
400 const hintsWereCancelled = (event?.type === "click") ||
401 ((event?.type === "keydown") &&
402 (KeyboardUtils.isEscape(event) || KeyboardUtils.isBackspace(event)));
403 if (hintsWereCancelled) {
404 HintCoordinator.sendMessage("exit", { isSuccess: false });
405 }
406 });
407
408 this.renderHints();
409 this.setIndicator();
410 }
411
412 renderHints() {
413 if (this.containerEl == null) {

Callers

nothing calls this directly

Calls 8

createMarkerForMethod · 0.95
renderHintsMethod · 0.95
setIndicatorMethod · 0.95
getMethod · 0.80
onExitMethod · 0.80
showMethod · 0.45
fillInMarkersMethod · 0.45
initMethod · 0.45

Tested by

no test coverage detected