ompchamber 2.0.0 → 2.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +12 -0
- package/dist/client/index.html +1 -1
- package/dist/client/static/js/async/{g.74ff36419f.js → g.cb81980498.js} +2 -2
- package/dist/client/static/js/async/{q.33d6779f98.js → q.22588845a9.js} +2 -2
- package/dist/client/static/js/async/{yx.af2936c368.js → xn1.83a7784fe1.js} +3 -3
- package/dist/client/static/js/{index.c05535dbde.js → index.1fd9e1c543.js} +2 -2
- package/package.json +1 -1
- package/src/client/components/workspace/diff-panel/SplitView.tsx +4 -1
- package/src/client/components/workspace/diff-panel/UnifiedView.tsx +70 -65
- package/src/client/components/workspace/diff-panel/index.tsx +8 -1
- package/src/client/components/workspace/editor/index.tsx +7 -0
- package/src/client/hooks/editor/save-file.ts +62 -0
- package/src/client/hooks/editor/use-file-editor.test.ts +61 -5
- package/src/client/hooks/editor/use-file-editor.ts +38 -29
- package/src/client/hooks/editor/use-file-transfer.ts +5 -2
- package/src/server/routes/fs/action.test.ts +64 -0
- package/src/server/routes/fs/action.ts +10 -1
- package/src/shared/lib/code/line-endings.test.ts +38 -0
- package/src/shared/lib/code/line-endings.ts +56 -0
- /package/dist/client/static/js/async/{g.74ff36419f.js.LICENSE.txt → g.cb81980498.js.LICENSE.txt} +0 -0
- /package/dist/client/static/js/async/{q.33d6779f98.js.LICENSE.txt → q.22588845a9.js.LICENSE.txt} +0 -0
- /package/dist/client/static/js/async/{yx.af2936c368.js.LICENSE.txt → xn1.83a7784fe1.js.LICENSE.txt} +0 -0
- /package/dist/client/static/js/{index.c05535dbde.js.LICENSE.txt → index.1fd9e1c543.js.LICENSE.txt} +0 -0
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Line-ending preservation for the file-editing surfaces.
|
|
8
|
+
*
|
|
9
|
+
* Two independent transports destroy the distinction, so the file's own ending
|
|
10
|
+
* has to be carried out of band rather than inferred from the buffer:
|
|
11
|
+
*
|
|
12
|
+
* - A `<textarea>` cannot hold a CRLF. The HTML spec defines its *API value* as
|
|
13
|
+
* the raw value with every carriage return removed, so the instant a CRLF file
|
|
14
|
+
* is placed in the editing surface the buffer is LF-only — verified in
|
|
15
|
+
* Chromium: `textarea.value = 'a\r\nb'` reads back `'a\nb'`.
|
|
16
|
+
* - `multipart/form-data` normalizes the other way: every bare LF in a field
|
|
17
|
+
* value becomes CRLF in transit (the HTML serializer on the way out, Bun's
|
|
18
|
+
* parser agreeing on the way in). A save payload therefore cannot say "LF" no
|
|
19
|
+
* matter what the buffer held.
|
|
20
|
+
*
|
|
21
|
+
* Saving the buffer as-is rewrote the whole file's line endings on a
|
|
22
|
+
* one-character edit — every line showed as changed in `git diff`. The ending is
|
|
23
|
+
* detected at read and travels as its own field; the server builds the bytes.
|
|
24
|
+
* An unedited save is then byte-identical and an edited save a one-line diff.
|
|
25
|
+
*
|
|
26
|
+
* Detection is by the FIRST terminator rather than a vote over all of them: a
|
|
27
|
+
* file is overwhelmingly uniform, and the first ending is the one the author's
|
|
28
|
+
* editor writes. A file with no terminator, or one using lone CR (classic Mac
|
|
29
|
+
* OS), reads as `lf`.
|
|
30
|
+
*/
|
|
31
|
+
|
|
32
|
+
export type LineEnding = 'lf' | 'crlf';
|
|
33
|
+
|
|
34
|
+
/** The ending the file uses, judged by its first terminator. */
|
|
35
|
+
export function detectLineEnding(text: string): LineEnding {
|
|
36
|
+
const index = text.indexOf('\n');
|
|
37
|
+
return index > 0 && text[index - 1] === '\r' ? 'crlf' : 'lf';
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* The buffer form: CRLF and lone CR collapsed to LF, matching what a textarea
|
|
42
|
+
* can actually hold. A string already free of CR is returned unchanged.
|
|
43
|
+
*/
|
|
44
|
+
export function toLf(text: string): string {
|
|
45
|
+
return text.includes('\r') ? text.replace(/\r\n?/g, '\n') : text;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* The disk form: `text` normalized — whatever mix of endings it carries, and
|
|
50
|
+
* whether or not it came back through a transport that rewrote them — and then
|
|
51
|
+
* written with `ending`.
|
|
52
|
+
*/
|
|
53
|
+
export function toDiskText(text: string, ending: LineEnding): string {
|
|
54
|
+
const lf = toLf(text);
|
|
55
|
+
return ending === 'crlf' ? lf.replace(/\n/g, '\r\n') : lf;
|
|
56
|
+
}
|
/package/dist/client/static/js/async/{g.74ff36419f.js.LICENSE.txt → g.cb81980498.js.LICENSE.txt}
RENAMED
|
File without changes
|
/package/dist/client/static/js/async/{q.33d6779f98.js.LICENSE.txt → q.22588845a9.js.LICENSE.txt}
RENAMED
|
File without changes
|
/package/dist/client/static/js/async/{yx.af2936c368.js.LICENSE.txt → xn1.83a7784fe1.js.LICENSE.txt}
RENAMED
|
File without changes
|
/package/dist/client/static/js/{index.c05535dbde.js.LICENSE.txt → index.1fd9e1c543.js.LICENSE.txt}
RENAMED
|
File without changes
|