mirror of
https://github.com/anomalyco/opencode.git
synced 2026-11-16 05:01:03 +03:00
fix(core): stop splitting an emoji when read truncates a long line (#62575)
This commit is contained in:
committed by
GitHub
Unverified
parent
3dc79ab657
commit
54de420baa
@@ -354,8 +354,12 @@ const textPage = (bytes: Uint8Array, eof: boolean, page: PageInput) => {
|
||||
return { entries, offset, next, consumed }
|
||||
}
|
||||
|
||||
const clampLine = (line: string) =>
|
||||
line.length > MAX_LINE_LENGTH ? line.slice(0, MAX_LINE_LENGTH) + MAX_LINE_SUFFIX : line
|
||||
const clampLine = (line: string) => {
|
||||
if (line.length <= MAX_LINE_LENGTH) return line
|
||||
const code = line.charCodeAt(MAX_LINE_LENGTH - 1)
|
||||
const end = code >= 0xd800 && code <= 0xdbff ? MAX_LINE_LENGTH - 1 : MAX_LINE_LENGTH
|
||||
return line.slice(0, end) + MAX_LINE_SUFFIX
|
||||
}
|
||||
|
||||
// A trailing newline ends the last line instead of starting an empty one.
|
||||
const lineCount = (newlines: number, last: number | undefined) => newlines + (last === undefined || last === 10 ? 0 : 1)
|
||||
|
||||
@@ -424,13 +424,13 @@ describe("ReadToolFileSystem", () => {
|
||||
Effect.gen(function* () {
|
||||
const { environment, files, directory } = yield* fixture
|
||||
const file = path.join(directory, "long.txt")
|
||||
yield* files.writeFileString(file, "a".repeat(2_001))
|
||||
yield* files.writeFileString(file, `${"a".repeat(1_999)}😀tail`)
|
||||
|
||||
const result = yield* ReadToolFileSystem.read(environment, absolute(file), "long.txt", { limit: 1 })
|
||||
|
||||
expect(result).toMatchObject({
|
||||
type: "text-page",
|
||||
content: `${"a".repeat(2_000)}... (line truncated to 2000 chars)`,
|
||||
content: `${"a".repeat(1_999)}... (line truncated to 2000 chars)`,
|
||||
truncated: false,
|
||||
})
|
||||
}),
|
||||
|
||||
Reference in New Issue
Block a user