Skip to content

Commit 806fbdb

Browse files
committed
fix line-overflow bug
1 parent 15336f0 commit 806fbdb

File tree

5 files changed

+56
-34
lines changed

5 files changed

+56
-34
lines changed

css/caret.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
position: absolute;
33
height: 2.6vh;
44
left: 1px;
5-
border-right: 1px solid black;
5+
border-right: 1px solid white;
66

77
transition: 0.07s;
88
z-index: 3;

css/custom.css

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,31 @@
11
#code_editor {
2-
background-color: gainsboro;
3-
width: 240px;
4-
height: 800px;
2+
background-color: rgb(39, 39, 39);
3+
width: 800px;
4+
height: 400px;
5+
overflow: auto;
56
}
67
.line {
7-
height: auto;
8+
}
9+
.linenum {
10+
color: whitesmoke;
11+
}
12+
.code {
13+
/* background-color: blanchedalmond; */
14+
color: white;
815
}
916

1017
.curLine {
11-
background-color: azure;
18+
background-color: rgb(78, 78, 78);
19+
}
20+
.keyword {
21+
color: rgb(20, 181, 255);
22+
display: inline-block;
23+
}
24+
.value {
25+
color: rgb(253, 2, 136);
26+
display: inline-block;
27+
}
28+
.comment {
29+
color: green;
30+
display: inline-block;
1231
}

css/index.css

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,7 @@ body {
1111
top: 0px;
1212
left: 0px;
1313
width: calc(100% - 10px);
14-
min-height: 2vh;
1514
height: 2vh;
16-
max-height: 2vh;
1715

1816
font-size: 2vh;
1917
padding: 2px 5px;
@@ -22,11 +20,16 @@ body {
2220
.line .linenum {
2321
display: inline-block;
2422
min-height: 2vh;
23+
text-align: center;
24+
vertical-align: middle;
2525
}
2626
.line .code {
27+
position: absolute;
28+
top: 0px;
2729
display: inline-block;
28-
margin: 0px 5px;
30+
margin: 1px 5px;
2931
min-height: 2vh;
32+
z-index: 0;
3033
}
3134

3235
.character {
@@ -36,15 +39,3 @@ body {
3639
margin: 0;
3740
}
3841

39-
.keyword {
40-
color: blue;
41-
display: inline-block;
42-
}
43-
.value {
44-
color: red;
45-
display: inline-block;
46-
}
47-
.comment {
48-
color: green;
49-
display: inline-block;
50-
}

js/caret.js

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -25,28 +25,34 @@ Caret.prototype = {
2525
let top, left;
2626
if(this.row == 1) top = 0;
2727
else top = $(`#${this.page.getId()} .line:nth-child(${this.row})`).position().top;
28+
2829
if(this.col == 1 || el == undefined) left = $(`#${this.page.getId()} .line:nth-child(${this.row}) .linenum`).width() + 10;
29-
else left = $(el).position().left + $(el).width();
30+
else left = $(el).position().left + $(el).width() + 16;
31+
if(this.col !==1 && el !== undefined)
32+
console.log('>>>'+this.row + ' ' + top + ' '+left);
3033

31-
// caretElement = $(caretElement)[0];
3234
$(caretElement).css('top', `${top}px`);
3335
$(caretElement).css('left', `${left}px`);
3436

35-
// toggle style
37+
// toggle current line background color
3638
let lineEl = $(".curLine");
3739
$(lineEl).removeClass("curLine");
3840
lineEl = $(`.line:nth-child(${this.row})`);
3941
$(lineEl).addClass("curLine");
4042

41-
/* TODO fix line height expand on char-overflow
42-
if ($(lineEl)[0].scrollWidth > $(lineEl).innerWidth()) {
43-
console.log('overflow: '+this.row)
44-
let charCount = this.page.getLineRef(this.row).getCode().length
45-
let charWidth = $('.character:nth-child(1)').width()
46-
let charPerLine = this.page.width / charWidth
47-
console.log(charPerLine)
48-
}
49-
*/
43+
// detect text overflow
44+
// TODO Enable word-wrap
45+
// lineEl = $(`#${this.page.getId()} .line:nth-child(${this.row})`)
46+
// let linenumEl = $(`#${this.page.getId()} .line:nth-child(${this.row}) .linenum`);
47+
// let linecodeEl = $(`#${this.page.getId()} .line:nth-child(${this.row}) .code`);
48+
49+
// if($(lineEl).width() < $(linenumEl).width() + $(linecodeEl).width()) {
50+
// console.log('OVERFLOW')
51+
52+
53+
// } else {
54+
// console.log('NO OVERFLOW');
55+
// }
5056
},
5157

5258
getCharacterElementBefore: function() {

js/var.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,10 @@ const charMap = {
1414
'[': ']',
1515
"'": "'",
1616
'"': '"'
17-
}
17+
};
18+
19+
var config = {
20+
lineHeight: 13,
21+
linenumHeight: 14,
22+
linecodeHeight: 15,
23+
};

0 commit comments

Comments
 (0)