From 3a5b29fd7f9826fd24429c492c21604d3d90d786 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julian=20P=C3=B6mp?= Date: Fri, 7 Jul 2023 09:43:12 +0200 Subject: [PATCH] feat(ngx-codejar): add all API functions provided by CodeJar --- .../src/lib/ngx-code-jar.component.ts | 56 ++++++++++++++++++- 1 file changed, 55 insertions(+), 1 deletion(-) diff --git a/libs/ngx-codejar/src/lib/ngx-code-jar.component.ts b/libs/ngx-codejar/src/lib/ngx-code-jar.component.ts index 71a198b..de6ca7b 100644 --- a/libs/ngx-codejar/src/lib/ngx-code-jar.component.ts +++ b/libs/ngx-codejar/src/lib/ngx-code-jar.component.ts @@ -5,6 +5,7 @@ import { EventEmitter, Input, OnChanges, + OnDestroy, OnInit, Output, Renderer2, @@ -57,7 +58,7 @@ import {withLineNumbers} from 'codejar/linenumbers.js'; } `] }) -export class NgxCodeJarComponent implements OnInit, AfterViewInit, OnChanges { +export class NgxCodeJarComponent implements OnInit, AfterViewInit, OnChanges, OnDestroy { constructor(private el: ElementRef, private renderer: Renderer2) { this.update = new EventEmitter(); } @@ -143,6 +144,59 @@ export class NgxCodeJarComponent implements OnInit, AfterViewInit, OnChanges { } } + /*** + * updates the options. + * @param options new options + */ + public updateOptions(options: CodeJarOptions) { + if (this.codeJar) { + this.options = options; + this.codeJar.updateOptions(options); + } + } + + /*** + * saves current cursor position. + */ + public save(): Position | undefined { + if (this.codeJar) { + return this.codeJar.save(); + } + return undefined; + } + + /*** + * restore cursor position. + * @param pos cursor position + */ + public restore(pos: Position): void { + if (this.codeJar) { + this.codeJar.restore(pos); + } + } + + /*** + * saves current editor state to history. + */ + public recordHistory(pos: Position): void { + if (this.codeJar) { + this.codeJar.recordHistory(); + } + } + + /*** + * removes all event listeners. It's automatically called when component is destroyed. + */ + public destroy(): void { + if (this.codeJar) { + this.codeJar.destroy(); + } + } + + ngOnDestroy() { + this.destroy(); + } + private applyCustomizations() { if (this.wrapper && this.editor) { const codejarWrap = (this.wrapper.nativeElement as HTMLElement).firstElementChild;