aboutsummaryrefslogtreecommitdiff
path: root/editor/editor.ts
diff options
context:
space:
mode:
Diffstat (limited to 'editor/editor.ts')
-rw-r--r--editor/editor.ts29
1 files changed, 17 insertions, 12 deletions
diff --git a/editor/editor.ts b/editor/editor.ts
index 9e1e301..843027e 100644
--- a/editor/editor.ts
+++ b/editor/editor.ts
@@ -21,8 +21,8 @@ export class Editor {
private el: HTMLElement | null
private activeFile: IVfsNode | null = null
private activeText: HTMLElement | null = null
- private rangeBegin: number = 0
- private rangeEnd: number = 0
+ private rangeBegin: number = -1
+ private rangeEnd: number = -1
private rawLines: string[] = []
private lines: EditorLine[] = []
private sel: Selection | null = null
@@ -48,6 +48,18 @@ export class Editor {
this.range = document.createRange()
}
+ // GetContent return content of file.
+ GetContent(): string {
+ let content = ""
+ for (let x = 0; x < this.lines.length; x++) {
+ if (x > 0) {
+ content += "\n"
+ }
+ content += this.lines[x].elText.innerText
+ }
+ return content
+ }
+
GetFile(): IVfsNode {
let node: IVfsNode = {
name: "",
@@ -56,16 +68,9 @@ export class Editor {
if (!this.activeFile) {
return node
}
- let content = ""
- for (let x = 0; x < this.lines.length; x++) {
- if (x > 0) {
- content += "\n"
- }
- content += this.lines[x].elText.innerText
- }
node.name = this.activeFile.name
node.path = this.activeFile.path
- node.content = content
+ node.content = this.GetContent()
return node
}
@@ -124,8 +129,8 @@ export class Editor {
for (let x = this.rangeBegin; x <= this.rangeEnd; x++) {
this.el.children[x].setAttribute("style", "")
}
- this.rangeBegin = 0
- this.rangeEnd = 0
+ this.rangeBegin = -1
+ this.rangeEnd = -1
}
initStyle() {