MCPcopy
hub / github.com/marktext/marktext / replace

Method replace

packages/muya/src/search/index.ts:81–107  ·  view source on GitHub ↗
(replaceValue: string, opt = { isSingle: true, isRegexp: false })

Source from the content-addressed store, hash-verified

79 }
80
81 replace(replaceValue: string, opt = { isSingle: true, isRegexp: false }) {
82 const { isSingle, isRegexp, ...rest } = opt;
83 const options = Object.assign({}, DEFAULT_SEARCH_OPTIONS, rest);
84 const { matches, value, index } = this;
85
86 if (matches.length) {
87 if (isRegexp)
88 replaceValue = buildRegexValue(matches[index], replaceValue);
89
90 if (isSingle) {
91 // replace one
92 this._innerReplace([matches[index]], replaceValue);
93 }
94 else {
95 // replace all
96 this._innerReplace(matches, replaceValue);
97 }
98 const highlightIndex = index < matches.length - 1 ? index : index - 1;
99
100 this.search(value, {
101 ...options,
102 highlightIndex: isSingle ? highlightIndex : -1,
103 });
104 }
105
106 return this;
107 }
108
109 /**
110 * Find preview or next value, and highlight it.

Callers 15

snakeToCamelFunction · 0.45
escapeHTMLFunction · 0.45
unescapeHTMLFunction · 0.45
escapeInBlockHtmlFunction · 0.45
wordCountFunction · 0.45
generateGithubSlugFunction · 0.45
correctImageSrcFunction · 0.45
matchStringFunction · 0.45
buildRegexValueFunction · 0.45
normalizePastedHTMLFunction · 0.45
tokenizerFunction · 0.45
escapeAttrFunction · 0.45

Calls 3

_innerReplaceMethod · 0.95
searchMethod · 0.95
buildRegexValueFunction · 0.90

Tested by

no test coverage detected