Skip to content

Commit

Permalink
feat(ngx-codejar): add all API functions provided by CodeJar
Browse files Browse the repository at this point in the history
  • Loading branch information
julianpoemp committed Jul 7, 2023
1 parent 03379ac commit 3a5b29f
Showing 1 changed file with 55 additions and 1 deletion.
56 changes: 55 additions & 1 deletion libs/ngx-codejar/src/lib/ngx-code-jar.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
EventEmitter,
Input,
OnChanges,
OnDestroy,
OnInit,
Output,
Renderer2,
Expand Down Expand Up @@ -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<string>();
}
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 3a5b29f

Please sign in to comment.