Skip to content

Commit 4d4cf41

Browse files
Enable wrap lines in code editor
1 parent a93771f commit 4d4cf41

File tree

2 files changed

+29
-49
lines changed

2 files changed

+29
-49
lines changed

css/main.css

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -120,13 +120,13 @@ a.dropdown-item {
120120
}
121121

122122
#codeEditor, #lineCounter {
123-
font-family: monospace;
124123
margin: 0;
125124
padding: 10px 0;
126125
height: 28vh;
127126
border-radius: 0;
128127
resize: none;
129-
font-size: .8em;
128+
font-size: 13.333333333px;
129+
font-family: "Courier New", Courier, monospace;
130130
tab-size: 2;
131131
-webkit-hyphens: none;
132132
-moz-hyphens: none;
@@ -140,11 +140,11 @@ a.dropdown-item {
140140
box-sizing: border-box;
141141
}
142142
#codeEditor {
143-
padding-left: calc(2.25rem + 5px);
143+
padding-left: calc(4.25rem + 5px);
144144
width: 100%;
145145
background-color: #fefefd;
146146
border: 1.5px solid rgba(28,205,188);
147-
color: rgb(8 152 138);
147+
color: rgba(8,152,138);
148148
white-space: pre-wrap;
149149
}
150150
#lineCounter {
@@ -156,8 +156,8 @@ a.dropdown-item {
156156
color: #707070;
157157
background-color: #d8d8d8;
158158
position: absolute;
159-
width: 2.25rem;
160-
background-color: rgb(28 205 188 / 25%);
159+
width: 4.25rem;
160+
background-color: rgba(28,205,188,.25);
161161
border-color: rgba(28,205,188);
162162
color: rgba(8,152,138);
163163
}

js/custom.js

Lines changed: 23 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -644,51 +644,31 @@ if (document.readyState === 'complete' || document.readyState !== 'loading' && !
644644
'\n FROM patient_diagnosis) A LEFT JOIN ' +
645645
'\n (SELECT icd9_code, icd9_description FROM icd9_mapping) B' +
646646
'\n ON A.diagnosis_code = B.icd9_code;';
647-
648-
var _buffer;
649-
function countLines(textarea) {
650-
if (_buffer == null) {
651-
_buffer = document.createElement('textarea');
652-
_buffer.style.border = 'none';
653-
_buffer.style.height = '0';
654-
_buffer.style.overflow = 'hidden';
655-
_buffer.style.padding = '0';
656-
_buffer.style.position = 'absolute';
657-
_buffer.style.left = '0';
658-
_buffer.style.top = '0';
659-
_buffer.style.zIndex = '-1';
660-
document.body.appendChild(_buffer);
661-
}
662-
let cs = window.getComputedStyle(textarea);
663-
let pl = parseInt(cs.paddingLeft);
664-
let pr = parseInt(cs.paddingRight);
665-
let lh = parseInt(cs.lineHeight);
666-
if (isNaN(lh)) lh = parseInt(cs.fontSize);
667-
_buffer.style.width = (textarea.clientWidth - pl - pr) + 'px';
668-
_buffer.style.font = cs.font;
669-
_buffer.style.letterSpacing = cs.letterSpacing;
670-
_buffer.style.whiteSpace = cs.whiteSpace;
671-
_buffer.style.wordBreak = cs.wordBreak;
672-
_buffer.style.wordSpacing = cs.wordSpacing;
673-
_buffer.style.wordWrap = cs.wordWrap;
674-
675-
_buffer.value = textarea.value;
676-
677-
let result = Math.floor(_buffer.scrollHeight / lh);
678-
if (result == 0) result = 1;
679-
return result;
680-
}
681-
var onFirstLoad = true;
682-
var lineCountCache = 0;
683-
var outArrCache = new Array();
684-
async function line_counter() {
685-
let lineCount = codeEditor.value.split('\n').length;
647+
/*
648+
SELECT patient_id,diagnosis_code,icd9_description
649+
FROM
650+
(SELECT patient_id, diagnosis_code FROM patient_diagnosis) A LEFT JOIN (SELECT icd9_code, icd9_description FROM icd9_mapping) B
651+
ON A.diagnosis_code = B.icd9_code;
652+
*/
653+
const codeEditorWidth=document.querySelector('#codeEditor').clientWidth;
654+
const lineCounterWidth=document.querySelector('#lineCounter').clientWidth;
655+
const codeEditorEditableWidth=codeEditorWidth-lineCounterWidth-5;
656+
657+
function line_counter() {
658+
let lines = codeEditor.value.split('\n');
659+
let lineCount = lines.length;
686660
let outarr = new Array();
687-
for (var x = 0; x < lineCount; x++) {
688-
outarr[x] = (x + 1) + '.';
661+
for (let x = 0; x < lineCount; x++) {
662+
if ((lines[x].length * 8) + 5 > codeEditorEditableWidth) {
663+
outarr.push(`${parseInt(x + 1)}.`);
664+
let nbWrap = Math.floor(((lines[x].length * 8) + 5) / codeEditorEditableWidth);
665+
for (let y = 0; y < nbWrap; y++) {
666+
outarr.push(' ');
667+
}
668+
} else {
669+
outarr.push(`${parseInt(x + 1)}.`);
670+
}
689671
}
690-
await Promise.resolve(outarr);
691-
lineCountCache = lineCount;
692672
lineCounter.value = outarr.join('\n');
693673
}
694674
codeEditor.addEventListener('scroll', () => {

0 commit comments

Comments
 (0)