@@ -11782,19 +11782,37 @@
1178211782 if (gdownloadFile.tag == 'viewer') {
1178311783 // View the file in the dialog box
1178411784 setDialogMode(4, EscapeHtml(gdownloadFile.file), 3, p13editSaveBack, null, gdownloadFile.file);
11785- if (isWindowsNode(currentNode)){
11786- d4EditLineBreakVal = 0; // Windows (CR LF)
11787- } else if (isMacNode(currentNode)) {
11788- d4EditLineBreakVal = 2; // Mac (CR)
11789- } else {
11790- d4EditLineBreakVal = 1; // Linux (LF)
11791- }
1179211785 d4ToggleLineBreak(true);
1179311786 QV('d4EncodingButton', true);
1179411787 QV('d4LineBreakButton', true);
1179511788 QS('dialog').width = 'auto';
1179611789 QS('dialog').bottom = '80px';
1179711790 QS('dialog').top = QS('dialog').left = QS('dialog').right = '100px';
11791+ const crlf = (gdownloadFile.data.match(/\r\n/g) || []).length;
11792+ const cr = (gdownloadFile.data.match(/\r(?!\n)/g) || []).length;
11793+ const lf = (gdownloadFile.data.match(/(?<!\r)\n/g) || []).length;
11794+ let type;
11795+ if (crlf > 0 && cr === 0 && lf === 0) {
11796+ type = 'crlf';
11797+ } else if (lf > 0 && crlf === 0 && cr === 0) {
11798+ type = 'lf';
11799+ } else if (cr > 0 && crlf === 0 && lf === 0) {
11800+ type = 'cr';
11801+ } else {
11802+ // Mixed - pick dominant
11803+ const dominant = Math.max(crlf, cr, lf);
11804+ if (dominant === crlf) type = 'crlf';
11805+ else if (dominant === lf) type = 'lf';
11806+ else type = 'cr';
11807+ }
11808+ if (type === 'crlf') {
11809+ d4EditLineBreakVal = 0; // Windows (CR LF)
11810+ } else if (type === 'lf') {
11811+ d4EditLineBreakVal = 1; // Linux (LF)
11812+ } else {
11813+ d4EditLineBreakVal = 2; // Mac (CR)
11814+ }
11815+ d4ToggleLineBreak(true);
1179811816 if (d4EditEncodingVal == 1) {
1179911817 Q('d4editorarea').value = decode_utf8(gdownloadFile.data); // UTF8 Encoding
1180011818 } else {
0 commit comments