MCPcopy Create free account
hub / github.com/ecomfe/tempad-dev / optimizeRuns

Function optimizeRuns

packages/extension/mcp/tools/code/text/segments.ts:104–193  ·  view source on GitHub ↗
(runs: TextRun[])

Source from the content-addressed store, hash-verified

102}
103
104function optimizeRuns(runs: TextRun[]): TextRun[] {
105 applyStickySpace(runs)
106
107 const result: TextRun[] = []
108
109 const cleanedRuns = runs.map((run) => {
110 if (/^[\s\u200B-\u200D\uFEFF]*$/.test(run.text)) {
111 const newAttrs = { ...run.attrs }
112 delete newAttrs['color']
113 delete newAttrs['text-decoration-color']
114 delete newAttrs['text-decoration-line']
115 delete newAttrs['background-color']
116 return { ...run, attrs: newAttrs }
117 }
118 return run
119 })
120
121 for (const run of cleanedRuns) {
122 if (result.length === 0) {
123 result.push(run)
124 continue
125 }
126
127 const prev = result[result.length - 1]
128 const isWhitespace = /^[\s\u200B-\u200D\uFEFF]*$/.test(run.text)
129
130 if (isWhitespace) {
131 if (prev.marks.size !== run.marks.size) {
132 result.push(run)
133 continue
134 }
135 let marksMatch = true
136 for (const m of prev.marks) {
137 if (!run.marks.has(m)) {
138 marksMatch = false
139 break
140 }
141 }
142
143 if (marksMatch && prev.link === run.link) {
144 prev.text += run.text
145 continue
146 }
147 }
148
149 if (prev.marks.size !== run.marks.size) {
150 result.push(run)
151 continue
152 }
153
154 let marksMatch = true
155 for (const m of prev.marks) {
156 if (!run.marks.has(m)) {
157 marksMatch = false
158 break
159 }
160 }
161 if (!marksMatch) {

Callers 1

splitIntoLinesFunction · 0.85

Calls 3

canonicalizeValueFunction · 0.90
applyStickySpaceFunction · 0.85
hasMethod · 0.80

Tested by

no test coverage detected