<commit_before>"use strict";
var VFindMode = {
  isActive: false,
  query: "",
  parsedQuery: "",
  historyIndex: 0,
  isRegex: false,
  ignoreCase: false,
  hasNoIgnoreCaseFlag: false,
  hasResults: false,
  matchCount: 0,
  scrollX: 0,
  scrollY: 0,
  initialRange: null,
  activeRegexIndex: 0,
  regexMatches: null,
  box: null,
  input: null,
  countEl: null,
  styleIn: null,
  returnToViewport: false,
  A0Re: /\xa0/g,
  cssSel: "::selection{background:#ff9632;}",
  cssOut: ".vimiumFindMode body{-webkit-user-select:auto !important;user-select:auto !important;}\n.vimiumFindMode ",
  cssIFrame: '*{font:12px/14px "Helvetica Neue",Helvetica,Arial,sans-serif !important;\
height:14px;margin:0;overflow:hidden;vertical-align:top;white-space:nowrap;cursor:default;}\
body{cursor:text;display:inline-block;padding:0 3px 0 1px;min-width:7px;}body *{cursor:text;display:inline;}body br{display:none;}\
html > span{float:right;}',
  activate: function(options) {
    if (!document.body) { return false; }
    options = Object.setPrototypeOf(options || {}, null);
    var query = options.query, zoom;
    !this.isActive && query !== this.query && VMarks.setPreviousPosition();
    if (query != null) {
      return this.findAndFocus(this.query || query, options);
    }
    this.getCurrentRange();
    if (options.returnToViewport) {
      this.returnToViewport = true;
      this.scrollX = window.scrollX;
      this.scrollY = window.scrollY;
    }
    if (this.isActive) {
      this.box.contentWindow.focus();
      this.input.focus();
      this.box.contentDocument.execCommand("selectAll", false);
      return;
    }

    zoom = VDom.UI.getZoom();
    this.parsedQuery = this.query = "";
    this.regexMatches = null;
    this.activeRegexIndex = 0;
    this.init && this.init();

    var el = this.box = VDom.createElement("iframe");
    el.className = "R HUD Find LS";
    el.style.width = "0px";
    zoom !== 1 && (el.style.zoom = 1 / zoom);
    el.onload = function() { VFindMode.onLoad(this); };
    if (VDom.UI.InitInner && document.webkitIsFullScreen) { VHUD.show(""); VHUD.hide(); }
    VDom.UI.adjust();
    VHUD.box ? VDom.UI.root.insertBefore(el, VHUD.box) : VDom.UI.addElement(el);
  },
  onLoad: function(el) {
    var wnd = el.contentWindow, doc = wnd.document, zoom;
    el.onload = null;
    wnd.onmousedown = el.onmousedown = this.OnMousedown;
    wnd.onkeydown = this.onKeydown.bind(this);
    wnd.onfocus = VEventMode.OnWndFocus();
    zoom = wnd.devicePixelRatio;
    zoom < 1 && (doc.documentElement.style.zoom = 1 / zoom);
    el = VDom.UI.createStyle(this.cssIFrame, doc);
    doc.head.appendChild(el);
    el = this.input = doc.body;
    doc.documentElement.insertBefore(doc.createTextNode("/"), el);
    el.contentEditable = "plaintext-only";
    el.oninput = this.onInput.bind(this);
    el = this.countEl = doc.createElement("span");
    el.appendChild(doc.createTextNode(""));
    doc.documentElement.appendChild(el);
    VDom.UI.focus(this.input);
    this.isActive = true;
  },
  init: function() {
    var ref = this.postMode, UI = VDom.UI;
    ref.exit = ref.exit.bind(ref);
    this.styleIn = UI.createStyle(this.cssSel);
    UI.init && UI.init(false);
    UI.box.appendChild(UI.createStyle(this.cssOut + this.cssSel));
    this.init = null;
  },
  findAndFocus: function(query, options) {
    if (query !== this.query) {
      this.updateQuery(query);
      if (this.isActive) {
        this.input.textContent = query.replace(/^ /, '\xa0');
        this.showCount();
      }
    }
    this.init && this.init();
    var style = this.isActive || VHUD.opacity !== 1 ? null : VHUD.box.style;
    style && (style.visibility = "hidden");
    this.execute(null, options);
    style && (style.visibility = "");
    if (!this.hasResults) {
      this.isActive || VHUD.showForDuration("No matches for '" + this.query + "'", 1000);
      return;
    }
    this.focusFoundLink(window.getSelection().anchorNode);
    this.postMode.activate();
  },
  deactivate: function() { // need keep @hasResults
    this.checkReturnToViewPort();
    window.focus();
    var el = VDom.getSelectionFocusElement();
    el && el.focus();
    this.box.remove();
    if (this.box === VDom.lastHovered) { VDom.lastHovered = null; }
    this.box = this.input = this.countEl = null;
    this.styleIn.remove();
    this.parsedQuery = this.query = "";
    this.initialRange = this.regexMatches = null;
    this.historyIndex = this.matchCount = this.scrollY = this.scrollX = 0;
    this.isActive = this.returnToViewport = this._small = false;
    return el;
  },
  OnMousedown: function(event) { if (event.target !== VFindMode.input) { event.preventDefault(); VFindMode.input.focus(); } },
  onKeydown: function(event) {
    var i = event.keyCode, n = i, el, el2;
    i = event.altKey || event.metaKey ? 0 : i === VKeyCodes.enter ? (this.saveQuery(), 2)
      : (i === VKeyCodes.backspace || i === VKeyCodes.deleteKey) ? +!this.query.length
      : 0;
    if (!i) {
      if (VKeyboard.isEscape(event)) { i = 3; }
      else if (i = VKeyboard.getKeyStat(event)) {
        if (i !== 2 || n < 74 || n > 75) { return; }
        this.execute(null, { dir: 74 - n });
        i = 0;
      }
      else if (n === VKeyCodes.f1) { this.box.contentDocument.execCommand("delete"); }
      else if (n === VKeyCodes.f1 + 1) { window.focus(); VEventMode.suppress(n); }
      else if (n === VKeyCodes.esc) { i = 3; }
      else if (n === VKeyCodes.up || n === VKeyCodes.down) { this.nextQuery(n === VKeyCodes.up ? 1 : -1); }
      else { return; }
    }
    VUtils.Prevent(event);
    if (!i) { return; }
    var hasStyle = !!this.styleIn.parentNode;
    el = this.deactivate();
    VEventMode.suppress(n);
    if ((i === 3 || !this.hasResults || VVisualMode.mode) && hasStyle) {
      this.toggleStyle("remove");
      this.restoreSelection(true);
    }<commit_msg>VFindMode: exit if fullscreen status changes because iframe will be unloaded<commit_after>"use strict";
var VFindMode = {
  isActive: false,
  query: "",
  parsedQuery: "",
  historyIndex: 0,
  isRegex: false,
  ignoreCase: false,
  hasNoIgnoreCaseFlag: false,
  hasResults: false,
  matchCount: 0,
  scrollX: 0,
  scrollY: 0,
  initialRange: null,
  activeRegexIndex: 0,
  regexMatches: null,
  box: null,
  input: null,
  countEl: null,
  styleIn: null,
  returnToViewport: false,
  A0Re: /\xa0/g,
  cssSel: "::selection{background:#ff9632;}",
  cssOut: ".vimiumFindMode body{-webkit-user-select:auto !important;user-select:auto !important;}\n.vimiumFindMode ",
  cssIFrame: '*{font:12px/14px "Helvetica Neue",Helvetica,Arial,sans-serif !important;\
height:14px;margin:0;overflow:hidden;vertical-align:top;white-space:nowrap;cursor:default;}\
body{cursor:text;display:inline-block;padding:0 3px 0 1px;min-width:7px;}body *{cursor:text;display:inline;}body br{display:none;}\
html > span{float:right;}',
  activate: function(options) {
    if (!document.body) { return false; }
    options = Object.setPrototypeOf(options || {}, null);
    var query = options.query, zoom;
    !this.isActive && query !== this.query && VMarks.setPreviousPosition();
    if (query != null) {
      return this.findAndFocus(this.query || query, options);
    }
    this.getCurrentRange();
    if (options.returnToViewport) {
      this.returnToViewport = true;
      this.scrollX = window.scrollX;
      this.scrollY = window.scrollY;
    }
    if (this.isActive) {
      this.box.contentWindow.focus();
      this.input.focus();
      this.box.contentDocument.execCommand("selectAll", false);
      return;
    }

    zoom = VDom.UI.getZoom();
    this.parsedQuery = this.query = "";
    this.regexMatches = null;
    this.activeRegexIndex = 0;
    this.init && this.init();

    var el = this.box = VDom.createElement("iframe");
    el.className = "R HUD Find LS";
    el.style.width = "0px";
    zoom !== 1 && (el.style.zoom = 1 / zoom);
    el.onload = function() { VFindMode.onLoad(this); };
    if (VDom.UI.InitInner && document.webkitIsFullScreen) { VHUD.show(""); VHUD.hide(); }
    VDom.UI.adjust();
    VHUD.box ? VDom.UI.root.insertBefore(el, VHUD.box) : VDom.UI.addElement(el);
  },
  onLoad: function(el) {
    var wnd = el.contentWindow, doc = wnd.document, zoom;
    el.onload = null;
    wnd.onmousedown = el.onmousedown = this.OnMousedown;
    wnd.onkeydown = this.onKeydown.bind(this);
    wnd.onfocus = VEventMode.OnWndFocus();
    wnd.onunload = this.OnUnload;
    zoom = wnd.devicePixelRatio;
    zoom < 1 && (doc.documentElement.style.zoom = 1 / zoom);
    el = VDom.UI.createStyle(this.cssIFrame, doc);
    doc.head.appendChild(el);
    el = this.input = doc.body;
    doc.documentElement.insertBefore(doc.createTextNode("/"), el);
    el.contentEditable = "plaintext-only";
    el.oninput = this.onInput.bind(this);
    el = this.countEl = doc.createElement("span");
    el.appendChild(doc.createTextNode(""));
    doc.documentElement.appendChild(el);
    VDom.UI.focus(this.input);
    this.isActive = true;
  },
  init: function() {
    var ref = this.postMode, UI = VDom.UI;
    ref.exit = ref.exit.bind(ref);
    this.styleIn = UI.createStyle(this.cssSel);
    UI.init && UI.init(false);
    UI.box.appendChild(UI.createStyle(this.cssOut + this.cssSel));
    this.init = null;
  },
  findAndFocus: function(query, options) {
    if (query !== this.query) {
      this.updateQuery(query);
      if (this.isActive) {
        this.input.textContent = query.replace(/^ /, '\xa0');
        this.showCount();
      }
    }
    this.init && this.init();
    var style = this.isActive || VHUD.opacity !== 1 ? null : VHUD.box.style;
    style && (style.visibility = "hidden");
    this.execute(null, options);
    style && (style.visibility = "");
    if (!this.hasResults) {
      this.isActive || VHUD.showForDuration("No matches for '" + this.query + "'", 1000);
      return;
    }
    this.focusFoundLink(window.getSelection().anchorNode);
    this.postMode.activate();
  },
  deactivate: function(unexpectly) { // need keep @hasResults
    this.checkReturnToViewPort();
    this.isActive = this.returnToViewport = this._small = false;
    if (unexpectly) {
      console.log("Vimium++: the find box was unloaded unexpectly.");
    } else {
      window.focus();
      var el = VDom.getSelectionFocusElement();
      el && el.focus();
    }
    this.box.remove();
    if (this.box === VDom.lastHovered) { VDom.lastHovered = null; }
    this.box = this.input = this.countEl = null;
    this.styleIn.remove();
    this.parsedQuery = this.query = "";
    this.initialRange = this.regexMatches = null;
    this.historyIndex = this.matchCount = this.scrollY = this.scrollX = 0;
    return el;
  },
  OnUnload: function(e) { var f = VFindMode; f && f.isActive && f.deactivate(true); },
  OnMousedown: function(event) { if (event.target !== VFindMode.input) { event.preventDefault(); VFindMode.input.focus(); } },
  onKeydown: function(event) {
    var i = event.keyCode, n = i, el, el2;
    i = event.altKey || event.metaKey ? 0 : i === VKeyCodes.enter ? (this.saveQuery(), 2)
      : (i === VKeyCodes.backspace || i === VKeyCodes.deleteKey) ? +!this.query.length
      : 0;
    if (!i) {
      if (VKeyboard.isEscape(event)) { i = 3; }
      else if (i = VKeyboard.getKeyStat(event)) {
        if (i !== 2 || n < 74 || n > 75) { return; }
        this.execute(null, { dir: 74 - n });
        i = 0;
      }
      else if (n === VKeyCodes.f1) { this.box.contentDocument.execCommand("delete"); }
      else if (n === VKeyCodes.f1 + 1) { window.focus(); VEventMode.suppress(n); }
      else if (n === VKeyCodes.esc) { i = 3; }
      else if (n === VKeyCodes.up || n === VKeyCodes.down) { this.nextQuery(n === VKeyCodes.up ? 1 : -1); }
      else { return; }
    }
    VUtils.Prevent(event);
    if (!i) { return; }
    var hasStyle = !!this.styleIn.parentNode;
    el = this.deactivate();
    VEventMode.suppress(n);
    if ((i === 3 || !this.hasResults || VVisualMode.mode) && hasStyle) {
      this.toggleStyle("remove");
      this.restoreSelection(true);
    }
{'fraction_non_alphanumeric': 0.16615333388828768, 'fraction_numerical': 0.009323233164072254, 'mean_word_length': 3.149913644214162, 'pattern_counts': {'":': 2, '<': 7, '<?xml version=': 0, '>': 7, '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': '1029205', 'n_tokens_mistral': 4259, 'n_tokens_neox': 4173, 'n_words': 800}