<commit_before>var VFind = {
  isActive_: false,
  query_: "",
  query0_: "",
  parsedQuery_: "",
  parsedRegexp_: null as RegExpG | null,
  historyIndex_: 0,
  notEmpty_: false,
  isQueryRichText_: true,
  isRegex_: null as boolean | null,
  ignoreCase_: null as boolean | null,
  wholeWord_: false,
  hasResults_: false,
  matchCount_: 0,
  coords_: null as null | MarksNS.ScrollInfo,
  initialRange_: null as Range | null,
  activeRegexIndex_: 0,
  regexMatches_: null as RegExpMatchArray | null,
  inShadow_: true,
  box_: null as never as HTMLIFrameElement & { contentDocument: Document },
  input_: null as never as SafeHTMLElement,
  countEl_: null as never as SafeHTMLElement,
  styleIn_: null as never as HTMLStyleElement,
  styleOut_: null as never as HTMLStyleElement,
  A0Re_: <RegExpG> /\xa0/g,
  tailRe_: <RegExpOne> /\n$/,
  css_: null as never as NonNullable<NonNullable<ContentWindowCore["VFind"]>["css_"]>,
  styleIframe_: null as HTMLStyleElement | null,
  activate_ (this: void, _0: number, options: CmdOptions[kFgCmd.findMode]): void {
    const a = VFind, dom = VDom, UI = VCui;
    a.css_ = options.f || a.css_;
    if (!dom.isHTML_()) { return; }
    let query: string = options.s ? UI.getSelectionText_() : "";
    (query.length > 99 || query.indexOf("\n") > 0) && (query = "");
    a.isQueryRichText_ = !query;
    query || (query = options.q);
    a.isActive_ || query === a.query_ && options.l || VMarks.setPreviousPosition_();
    dom.docSelectable_ = UI.getDocSelectable_();
    UI.ensureBorder_();
    if (options.l) {
      return a.findAndFocus_(query || a.query_, options);
    }
    a.isActive_ && UI.adjust_();
    if (!a.isActive_) {
      a.getCurrentRange_();
      if (options.r) {
        a.coords_ = [scrollX, scrollY];
      }
    }
    VHud.hide_(TimerType.noTimer);
    if (a.isActive_) {
      return a.setFirstQuery_(query);
    }

    a.parsedQuery_ = a.query_ = "";
    a.parsedRegexp_ = a.regexMatches_ = null;
    a.activeRegexIndex_ = 0;

    const el = a.box_ = dom.createElement_("iframe") as typeof VFind.box_, st = el.style;
    el.className = "R HUD UI" + VDom.cache_.d;
    st.display = "none"; st.width = "0";
    if (Build.BTypes & ~BrowserType.Firefox && dom.wdZoom_ !== 1) { st.zoom = "" + 1 / dom.wdZoom_; }
    el.onload = function (this: HTMLIFrameElement): void { VFind.notDisableScript_() && VFind.onLoad_(1); };
    VKey.pushHandler_(VKey.SuppressMost_, a);
    a.query_ || (a.query0_ = query);
    a.init_ && a.init_(AdjustType.NotAdjust);
    UI.toggleSelectStyle_(1);
    a.isActive_ = true;
    UI.add_(el, AdjustType.DEFAULT, VHud.box_);
  },
  notDisableScript_(): 1 | void {
    try {
      if (this.box_.contentWindow.document) { return 1; }
    } catch {}
    this.deactivate_(FindNS.Action.ExitUnexpectedly);
    let s = "Sorry, Vimium C can not open a HUD on this page", b = VVisual;
    b.mode_ ? b.prompt_(s, 2000) : VHud.tip_(s);
  },
  onLoad_ (later?: 1): void {
    const a = this, box: HTMLIFrameElement = a.box_,
    wnd = box.contentWindow, f = wnd.addEventListener.bind(wnd) as typeof addEventListener,
    onKey = a.onKeydown_.bind(a),
    now = Date.now(), s = VKey.Stop_, t = true;
    let tick = 0;
    f("mousedown", a.OnMousedown_, t);
    f("keydown", onKey, t);
    f("keyup", onKey, t);
    f("input", a.OnInput_, t);
    if (Build.BTypes & ~BrowserType.Chrome) {
      f("paste", a._OnPaste, t);
    }
    f("unload", a.OnUnload_, t);
    for (const i of ["keypress", "mouseup", "click", "contextmenu", "copy", "cut", "paste"]) {
      f(i, s, t);
    }
    f("blur", a._onUnexpectedBlur = function (this: Window, event): void {
      const b = VFind, delta = Date.now() - now, wnd1 = this;
      if (event && b && b.isActive_ && delta < 500 && delta > -99 && event.target === wnd1) {
        wnd1.closed || setTimeout(function (): void { VFind === b && b.isActive_ && b.focus_(); }, tick++ * 17);
      } else {
        wnd1.removeEventListener("blur", b._onUnexpectedBlur, true);
        b._onUnexpectedBlur = null;
      }
    }, t);
    f("focus", function (this: Window, event: Event): void {
      if (VFind._actived && event.target === this) {
        VEvent.OnWndFocus_();
      }
      Build.BTypes & BrowserType.Firefox
        && (!(Build.BTypes & ~BrowserType.Firefox) || VOther === BrowserType.Firefox)
        || VKey.Stop_(event);
    }, t);
    box.onload = later ? null as never : function (): void {
      this.onload = null as never; VFind.onLoad2_(this.contentWindow);
    };
    if (later) { a.onLoad2_(wnd); }
  },
  onLoad2_ (wnd: Window): void {
    const doc = wnd.document, docEl = doc.documentElement as HTMLHtmlElement,
    body = doc.body as HTMLBodyElement,
    a = VFind,
    zoom = wnd.devicePixelRatio, list = doc.createDocumentFragment(),
    addElement = function (tag: 0 | "div" | "style", id?: string | 0): SafeHTMLElement {
      const newEl = doc.createElement(tag || "span") as SafeHTMLElement;
      id && (newEl.id = id);
      id !== 0 && list.appendChild(newEl);
      return newEl;
    };
    addElement(0, "s").textContent = "/";
    const el = a.input_ = addElement(0, "i");
    addElement(0, "h");
    if (!(Build.BTypes & BrowserType.Firefox) && !Build.DetectAPIOnFirefox) {
      el.contentEditable = "true";
      wnd.removeEventListener("paste", VKey.Stop_, true);
    } else if (Build.BTypes & ~BrowserType.Chrome) {
      let plain = true;
      try {
        el.contentEditable = "plaintext-only";
      } catch {
        plain = false;
        el.contentEditable = "true";
      }
      wnd.removeEventListener("paste", plain ? a._OnPaste : VKey.Stop_, true);
    } else {
      el.contentEditable = "plaintext-only";
    }
    (a.countEl_ = addElement(0, "c")).textContent = " ";
    VCui.createStyle_(a.css_.i, a.styleIframe_ = addElement("style") as HTMLStyleElement);
    const root = VDom.createShadowRoot_(body), inShadow = a.inShadow_ = root !== body,
    root2 = inShadow ? addElement("div", 0) : body;
    root2.className = "r" + VDom.cache_.d;
    root2.spellcheck = false;
    root2.appendChild(list);
    if (inShadow) {
      // here can not use `body.contentEditable = "true"`, otherwise Backspace will break on Firefox, Win
      body.setAttribute("role", "textbox");
      root2.addEventListener("mousedown", a.OnMousedown_, true);
      root.appendChild(root2);
    }
    Build.BTypes & ~BrowserType.Firefox &&
    zoom < 1 && (docEl.style.zoom = "" + 1 / zoom);
    a.box_.style.display = "";
    VKey.removeHandler_(a);
    VKey.pushHandler_(a.onHostKeydown_, a);
    return a.setFirstQuery_(a.query0_);
  },
  _onUnexpectedBlur: null as ((event?: Event) => void) | null,
  focus_ (): void {
    this._actived = false;
    this.input_.focus();
    this._actived = true;
  },
  _actived: false,
  setFirstQuery_ (query: string): void {
    const a = this;
    a.focus_();
    a.query0_ = "";
    a.query_ || a.SetQuery_(query);
    a.isQueryRichText_ = true;
    a.notEmpty_ = !!a.query_;
    a.notEmpty_ && a.box_.contentDocument.execCommand("selectAll", false);
  },
  init_ (adjust: AdjustType): void {
    const ref = this.postMode_, UI = VCui,
    css = this.css_.c, sin = this.styleIn_ = UI.createStyle_(css);<commit_msg>fix a flicker on Firefox<commit_after>var VFind = {
  isActive_: false,
  query_: "",
  query0_: "",
  parsedQuery_: "",
  parsedRegexp_: null as RegExpG | null,
  historyIndex_: 0,
  notEmpty_: false,
  isQueryRichText_: true,
  isRegex_: null as boolean | null,
  ignoreCase_: null as boolean | null,
  wholeWord_: false,
  hasResults_: false,
  matchCount_: 0,
  coords_: null as null | MarksNS.ScrollInfo,
  initialRange_: null as Range | null,
  activeRegexIndex_: 0,
  regexMatches_: null as RegExpMatchArray | null,
  inShadow_: true,
  box_: null as never as HTMLIFrameElement & { contentDocument: Document },
  input_: null as never as SafeHTMLElement,
  countEl_: null as never as SafeHTMLElement,
  styleIn_: null as never as HTMLStyleElement,
  styleOut_: null as never as HTMLStyleElement,
  A0Re_: <RegExpG> /\xa0/g,
  tailRe_: <RegExpOne> /\n$/,
  css_: null as never as NonNullable<NonNullable<ContentWindowCore["VFind"]>["css_"]>,
  styleIframe_: null as HTMLStyleElement | null,
  activate_ (this: void, _0: number, options: CmdOptions[kFgCmd.findMode]): void {
    const a = VFind, dom = VDom, UI = VCui;
    a.css_ = options.f || a.css_;
    if (!dom.isHTML_()) { return; }
    let query: string = options.s ? UI.getSelectionText_() : "";
    (query.length > 99 || query.indexOf("\n") > 0) && (query = "");
    a.isQueryRichText_ = !query;
    query || (query = options.q);
    a.isActive_ || query === a.query_ && options.l || VMarks.setPreviousPosition_();
    dom.docSelectable_ = UI.getDocSelectable_();
    UI.ensureBorder_();
    if (options.l) {
      return a.findAndFocus_(query || a.query_, options);
    }
    a.isActive_ && UI.adjust_();
    if (!a.isActive_) {
      a.getCurrentRange_();
      if (options.r) {
        a.coords_ = [scrollX, scrollY];
      }
    }
    if (a.isActive_) {
      VHud.hide_(TimerType.noTimer);
      return a.setFirstQuery_(query);
    }

    a.parsedQuery_ = a.query_ = "";
    a.parsedRegexp_ = a.regexMatches_ = null;
    a.activeRegexIndex_ = 0;

    const el = a.box_ = dom.createElement_("iframe") as typeof VFind.box_, st = el.style;
    el.className = "R HUD UI" + VDom.cache_.d;
    st.display = "none"; st.width = "0";
    if (Build.BTypes & ~BrowserType.Firefox && dom.wdZoom_ !== 1) { st.zoom = "" + 1 / dom.wdZoom_; }
    el.onload = function (this: HTMLIFrameElement): void { VFind.notDisableScript_() && VFind.onLoad_(1); };
    VKey.pushHandler_(VKey.SuppressMost_, a);
    a.query_ || (a.query0_ = query);
    a.init_ && a.init_(AdjustType.NotAdjust);
    UI.toggleSelectStyle_(1);
    a.isActive_ = true;
    UI.add_(el, AdjustType.DEFAULT, VHud.box_);
  },
  notDisableScript_(): 1 | void {
    try {
      if (this.box_.contentWindow.document) { return 1; }
    } catch {}
    this.deactivate_(FindNS.Action.ExitUnexpectedly);
    let s = "Sorry, Vimium C can not open a HUD on this page", b = VVisual;
    b.mode_ ? b.prompt_(s, 2000) : VHud.tip_(s);
  },
  onLoad_ (later?: 1): void {
    const a = this, box: HTMLIFrameElement = a.box_,
    wnd = box.contentWindow, f = wnd.addEventListener.bind(wnd) as typeof addEventListener,
    onKey = a.onKeydown_.bind(a),
    now = Date.now(), s = VKey.Stop_, t = true;
    let tick = 0;
    f("mousedown", a.OnMousedown_, t);
    f("keydown", onKey, t);
    f("keyup", onKey, t);
    f("input", a.OnInput_, t);
    if (Build.BTypes & ~BrowserType.Chrome) {
      f("paste", a._OnPaste, t);
    }
    f("unload", a.OnUnload_, t);
    for (const i of ["keypress", "mouseup", "click", "contextmenu", "copy", "cut", "paste"]) {
      f(i, s, t);
    }
    f("blur", a._onUnexpectedBlur = function (this: Window, event): void {
      const b = VFind, delta = Date.now() - now, wnd1 = this;
      if (event && b && b.isActive_ && delta < 500 && delta > -99 && event.target === wnd1) {
        wnd1.closed || setTimeout(function (): void { VFind === b && b.isActive_ && b.focus_(); }, tick++ * 17);
      } else {
        wnd1.removeEventListener("blur", b._onUnexpectedBlur, true);
        b._onUnexpectedBlur = null;
      }
    }, t);
    f("focus", function (this: Window, event: Event): void {
      if (VFind._actived && event.target === this) {
        VEvent.OnWndFocus_();
      }
      Build.BTypes & BrowserType.Firefox
        && (!(Build.BTypes & ~BrowserType.Firefox) || VOther === BrowserType.Firefox)
        || VKey.Stop_(event);
    }, t);
    box.onload = later ? null as never : function (): void {
      this.onload = null as never; VFind.onLoad2_(this.contentWindow);
    };
    if (later) { a.onLoad2_(wnd); }
  },
  onLoad2_ (wnd: Window): void {
    const doc = wnd.document, docEl = doc.documentElement as HTMLHtmlElement,
    body = doc.body as HTMLBodyElement,
    a = VFind,
    zoom = wnd.devicePixelRatio, list = doc.createDocumentFragment(),
    addElement = function (tag: 0 | "div" | "style", id?: string | 0): SafeHTMLElement {
      const newEl = doc.createElement(tag || "span") as SafeHTMLElement;
      id && (newEl.id = id);
      id !== 0 && list.appendChild(newEl);
      return newEl;
    };
    addElement(0, "s").textContent = "/";
    const el = a.input_ = addElement(0, "i");
    addElement(0, "h");
    if (!(Build.BTypes & BrowserType.Firefox) && !Build.DetectAPIOnFirefox) {
      el.contentEditable = "true";
      wnd.removeEventListener("paste", VKey.Stop_, true);
    } else if (Build.BTypes & ~BrowserType.Chrome) {
      let plain = true;
      try {
        el.contentEditable = "plaintext-only";
      } catch {
        plain = false;
        el.contentEditable = "true";
      }
      wnd.removeEventListener("paste", plain ? a._OnPaste : VKey.Stop_, true);
    } else {
      el.contentEditable = "plaintext-only";
    }
    (a.countEl_ = addElement(0, "c")).textContent = " ";
    VCui.createStyle_(a.css_.i, a.styleIframe_ = addElement("style") as HTMLStyleElement);
    const root = VDom.createShadowRoot_(body), inShadow = a.inShadow_ = root !== body,
    root2 = inShadow ? addElement("div", 0) : body;
    root2.className = "r" + VDom.cache_.d;
    root2.spellcheck = false;
    root2.appendChild(list);
    if (inShadow) {
      // here can not use `body.contentEditable = "true"`, otherwise Backspace will break on Firefox, Win
      body.setAttribute("role", "textbox");
      root2.addEventListener("mousedown", a.OnMousedown_, true);
      root.appendChild(root2);
    }
    Build.BTypes & ~BrowserType.Firefox &&
    zoom < 1 && (docEl.style.zoom = "" + 1 / zoom);
    a.box_.style.display = "";
    VKey.removeHandler_(a);
    VKey.pushHandler_(a.onHostKeydown_, a);
    // delay VHud.hide_, so that avoid flicker on Firefox
    VHud.hide_(TimerType.noTimer);
    a.setFirstQuery_(a.query0_);
  },
  _onUnexpectedBlur: null as ((event?: Event) => void) | null,
  focus_ (): void {
    this._actived = false;
    this.input_.focus();
    this._actived = true;
  },
  _actived: false,
  setFirstQuery_ (query: string): void {
    const a = this;
    a.focus_();
    a.query0_ = "";
    a.query_ || a.SetQuery_(query);
    a.isQueryRichText_ = true;
    a.notEmpty_ = !!a.query_;
    a.notEmpty_ && a.box_.contentDocument.execCommand("selectAll", false);
  },
  init_ (adjust: AdjustType): void {
    const ref = this.postMode_, UI = VCui,
    css = this.css_.c, sin = this.styleIn_ = UI.createStyle_(css);
{'fraction_non_alphanumeric': 0.15663149182702255, 'fraction_numerical': 0.007862611214566521, 'mean_word_length': 3.0177334441673596, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '470022', 'n_tokens_mistral': 5188, 'n_tokens_neox': 5055, 'n_words': 1175}