Path: blob/master/src/packages/frontend/codemirror/extensions/find-in-line.ts
1496 views
/*1* This file is part of CoCalc: Copyright © 2020 Sagemath, Inc.2* License: MS-RSL – see LICENSE.md for details3*/45import * as CodeMirror from "codemirror";67/*8Find pos {line:line, ch:ch} of first line that contains the9string s, or returns undefined if no single line contains s.10Should be much faster than calling getLine or getValue.11*/1213CodeMirror.defineExtension("find_in_line", function (14s: string15): CodeMirror.Position | undefined {16// @ts-ignore17const cm: any = this;1819let line: number = -1;20let ch: number = 0;21let i = 0;22cm.eachLine(function (z) {23ch = z.text.indexOf(s);24if (ch !== -1) {25line = i;26return true; // undocumented - calling false stops iteration27}28i += 1;29return false;30});31if (line >= 0) {32return { line, ch };33}34});353637