MCPcopy Create free account
hub / github.com/anomalyco/opencode / offsetsToSelection

Function offsetsToSelection

packages/tui/src/editor-zed.ts:245–266  ·  view source on GitHub ↗
(text: string, startOffset: number, endOffset: number)

Source from the content-addressed store, hash-verified

243}
244
245function offsetsToSelection(text: string, startOffset: number, endOffset: number) {
246 const start = Math.max(0, Math.min(startOffset, text.length))
247 const end = Math.max(0, Math.min(endOffset, text.length))
248 let line = 1
249 let lineStart = 0
250 let startPosition = position(line, lineStart, start)
251 let endPosition = position(line, lineStart, end)
252
253 for (let index = 0; index <= end; index++) {
254 if (index === start) startPosition = position(line, lineStart, index)
255 if (index === end) {
256 endPosition = position(line, lineStart, index)
257 break
258 }
259 if (text[index] === "\n") {
260 line += 1
261 lineStart = index + 1
262 }
263 }
264
265 return { start: startPosition, end: endPosition }
266}
267
268function position(line: number, lineStart: number, offset: number) {
269 return {

Callers 2

resolveZedSelectionFunction · 0.85
offsetToPositionFunction · 0.85

Calls 1

positionFunction · 0.85

Tested by

no test coverage detected