Skip to content

Commit 68c5861

Browse files
committed
edit button now reads the file to get newline breaks instead! #7647
Signed-off-by: si458 <simonsmith5521@gmail.com>
1 parent c5a2e7a commit 68c5861

File tree

2 files changed

+46
-11
lines changed

2 files changed

+46
-11
lines changed

views/default.handlebars

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -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 {

views/default3.handlebars

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12827,12 +12827,29 @@
1282712827
setModalContent('xxAddAgent', EscapeHtml(gdownloadFile.file), 4, 'extra-large');
1282812828
var file = gdownloadFile.file;
1282912829
showModal('xxAddAgentModal', 'idx_dlgOkButton', () => p13editSaveBack(3, file));
12830-
if (isWindowsNode(currentNode)){
12831-
d4EditLineBreakVal = 0; // Windows (CR LF)
12832-
} else if (isMacNode(currentNode)) {
12833-
d4EditLineBreakVal = 2; // Mac (CR)
12830+
const crlf = (gdownloadFile.data.match(/\r\n/g) || []).length;
12831+
const cr = (gdownloadFile.data.match(/\r(?!\n)/g) || []).length;
12832+
const lf = (gdownloadFile.data.match(/(?<!\r)\n/g) || []).length;
12833+
let type;
12834+
if (crlf > 0 && cr === 0 && lf === 0) {
12835+
type = 'crlf';
12836+
} else if (lf > 0 && crlf === 0 && cr === 0) {
12837+
type = 'lf';
12838+
} else if (cr > 0 && crlf === 0 && lf === 0) {
12839+
type = 'cr';
1283412840
} else {
12841+
// Mixed - pick dominant
12842+
const dominant = Math.max(crlf, cr, lf);
12843+
if (dominant === crlf) type = 'crlf';
12844+
else if (dominant === lf) type = 'lf';
12845+
else type = 'cr';
12846+
}
12847+
if (type === 'crlf') {
12848+
d4EditLineBreakVal = 0; // Windows (CR LF)
12849+
} else if (type === 'lf') {
1283512850
d4EditLineBreakVal = 1; // Linux (LF)
12851+
} else {
12852+
d4EditLineBreakVal = 2; // Mac (CR)
1283612853
}
1283712854
d4ToggleLineBreak(true);
1283812855
QV('d4EncodingButton', true);

0 commit comments

Comments
 (0)