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

Function serialize

packages/app/src/addons/serialize.ts:193–224  ·  view source on GitHub ↗
(range: IBufferRange, excludeFinalCursorPosition?: boolean)

Source from the content-addressed store, hash-verified

191 constructor(protected readonly _buffer: IBuffer) {}
192
193 public serialize(range: IBufferRange, excludeFinalCursorPosition?: boolean): string {
194 let oldCell = this._buffer.getNullCell()
195
196 const startRow = range.start.y
197 const endRow = range.end.y
198 const startColumn = range.start.x
199 const endColumn = range.end.x
200
201 this._beforeSerialize(endRow - startRow + 1, startRow, endRow)
202
203 for (let row = startRow; row <= endRow; row++) {
204 const line = this._buffer.getLine(row)
205 if (line) {
206 const startLineColumn = row === range.start.y ? startColumn : 0
207 const endLineColumn = Math.min(endColumn, line.length)
208
209 for (let col = startLineColumn; col < endLineColumn; col++) {
210 const c = line.getCell(col)
211 if (!c) {
212 continue
213 }
214 this._nextCell(c, oldCell, row, col)
215 oldCell = c
216 }
217 }
218 this._rowEnd(row, row === endRow)
219 }
220
221 this._afterSerialize()
222
223 return this._serializeString(excludeFinalCursorPosition)
224 }
225
226 protected _nextCell(_cell: IBufferCell, _oldCell: IBufferCell, _row: number, _col: number): void {}
227 protected _rowEnd(_row: number, _isLastRow: boolean): void {}

Callers

nothing calls this directly

Calls 7

getNullCellMethod · 0.80
_beforeSerializeMethod · 0.80
getLineMethod · 0.80
getCellMethod · 0.80
_nextCellMethod · 0.80
_rowEndMethod · 0.80
_serializeStringMethod · 0.80

Tested by

no test coverage detected