"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = InjectSearch;
var _codeEditorSearch = require("./code-editor-search");
require("codemirror/addon/scroll/annotatescrollbar");
function InjectSearch(CodeMirrorModule, getSearchQuery) {
  const {
    doSearch,
    clearSearch
  } = (0, _codeEditorSearch.enableSearch)(CodeMirrorModule);
  const setSearchQuery = cm => {
    cm.state.search = new _codeEditorSearch.SearchState();
    cm.state.search.lastQuery = getSearchQuery();
  };
  const find = (cm, rev) => {
    clearSearch(cm);
    setSearchQuery(cm);
    doSearch(cm, rev);
  };

  // eslint-disable-next-line @typescript-eslint/ban-ts-comment
  // @ts-ignore
  CodeMirrorModule.commands.findNext = cm => find(cm, false);
  // eslint-disable-next-line @typescript-eslint/ban-ts-comment
  // @ts-ignore
  CodeMirrorModule.commands.findPrev = cm => find(cm, true);
  // eslint-disable-next-line @typescript-eslint/ban-ts-comment
  // @ts-ignore
  CodeMirrorModule.commands.clearSearch = clearSearch;
}