UNPKG

1.53 kBJavaScriptView Raw
1import xhtml from '../xhtml';
2
3// 更新编辑器内容视图
4
5export function updateView() {
6
7 let template = "";
8
9 this.__formatData.forEach((line, index) => {
10
11 let bgcolor = "";
12 if (index == this.__lineNum) {
13 bgcolor = "background-color:" + this._colorEdit;
14 }
15
16 template += "<div style='min-width: fit-content;white-space: nowrap;line-height:21px;height:21px;" + bgcolor + "'>";
17
18 template += "<em style='color:" + this._colorNumber + ";user-select: none;display:inline-block;font-style:normal;width:35px;text-align:right;margin-right:5px;'>" + (index + 1) + "</em>";
19
20 line.forEach(text => {
21
22 let contentText = text.content;
23
24 // 提前对特殊字符进行处理
25 contentText = contentText.replace(/\&/g, "&amp;");/*[&]*/
26 contentText = contentText.replace(/</g, "&lt;"); contentText = contentText.replace(/>/g, "&gt;");/*[<,>]*/
27
28 template += "<span style='font-weight:" + this._fontWeight + ";white-space: pre;color:" + text.color + "'>" + contentText + "</span>";
29
30 });
31
32 template += "</div>";
33
34 });
35
36 this.__showDOM.innerHTML = template;
37
38};
39
40// 输入的时候更新光标位置
41
42export function updateCursorPosition(text) {
43
44 xhtml.css(this.__focusDOM, {
45 top: (this.__lineNum * 21 + 10) + "px",
46 left: (40 + this.$$textWidth(this._contentArray[this.__lineNum].substring(0, this.__leftNum))) + "px",
47 });
48
49};
50