diff options
| author | Shulhan <ms@kilabit.info> | 2021-08-22 01:20:58 +0700 |
|---|---|---|
| committer | Shulhan <ms@kilabit.info> | 2021-08-22 01:20:58 +0700 |
| commit | 7c11c8e290ba149cb42a86d0c6b0109603c12539 (patch) | |
| tree | 4d88004c43f24af0650fda52256f47da570bbb7b /editor/editor.ts | |
| parent | 4912019d4e3df64fde43bcfd6a8f0519e15c8af3 (diff) | |
| download | pakakeh.ts-7c11c8e290ba149cb42a86d0c6b0109603c12539.tar.xz | |
editor: add method GetContent
The GetContent method return the concatenated statements with new-line.
While at it, set default range begin and end to -1 to fix issue where
user select only line number 1 (index 0).
Diffstat (limited to 'editor/editor.ts')
| -rw-r--r-- | editor/editor.ts | 29 |
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() { |
