UNPKG

prism-code-editor

Version:

Lightweight, extensible code editor component for the web using Prism

53 lines (52 loc) 1.32 kB
import { c as m } from "./search-c8a7add4.js"; import "./utils-d80f188d.js"; import "./index-fa58cb3b.js"; import "./prismCore-5c7f03d0.js"; const g = (s, n) => ({ update(e) { this.update = () => { }; const o = m(e), c = o.container; c.style.zIndex = -1, c.className = s, e.addListener("selectionChange", n(e, o)); } }), $ = (s, n = 1, e = 200) => g("selection-matches", (o, c) => ([i, a], t) => { t = o.focused ? t.slice(i, a) : ""; let r = t.search(/\S/), h = (t = t.trim()).length; c.search( n > h || h > e ? "" : t, s, !1, !1, void 0, i + r ); }), L = (s, n) => Object.assign( g("word-matches", (e, o) => { let c = !1; return e.addListener("update", () => c = !0), ([i, a], t) => { if (i != a || !e.focused || c) o.search(""); else { let r = `[\\p{L}_$\\d${n && n(i) ? "-" : ""}]*`, h = t.slice(0, i).match(RegExp(r + "$", "u")), d = h.index, l = h[0] + t.slice(i).match(RegExp("^" + r, "u"))[0]; o.search( /^-*(\d|$)/.test(l) || s && !s(d, d + l.length) ? "" : l, !0, !0, !1, void 0, s ); } c = !1; }; }), { setFilter(e) { s = e; } } ); export { L as highlightCurrentWord, $ as highlightSelectionMatches };