Skip to content

Commit

Permalink
Add "autoUpdateContent" option
Browse files Browse the repository at this point in the history
  • Loading branch information
Francois-Xavier Montigny committed Aug 11, 2016
1 parent f7caaa6 commit 35b1659
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 11 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ import 'brace/mode/sql';
[theme]="'clouds'"
[options]="options"
[readOnly]="false"
[autoUpdateContent]="true" //change content when [text] change
(textChanged)="onChange($event)"
style="min-height: 200px; width:100%; overflow: auto;"></div>
`
Expand Down
2 changes: 2 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export declare class AceEditorDirective {
_readOnly: boolean;
_theme: string;
_mode: string;
_autoUpdateContent: boolean;
editor: any;
oldText: any;
constructor(elementRef: ElementRef);
Expand All @@ -18,4 +19,5 @@ export declare class AceEditorDirective {
theme: any;
mode: any;
text: any;
autoUpdateContent: any;
}
23 changes: 19 additions & 4 deletions index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion index.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ng2-ace-editor",
"version": "0.0.16",
"version": "0.0.17",
"description": "Ace editor integration with typescript for angular 2.",
"main": "index.js",
"scripts": {
Expand Down
17 changes: 12 additions & 5 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ declare var ace:any;

@Directive({
selector: '[ace-editor]',
inputs: ['text', 'mode', 'theme', 'readOnly', 'options'],
inputs: ['text', 'mode', 'theme', 'readOnly', 'options', 'autoUpdateContent'],
outputs: ['textChanged']
})
export class AceEditorDirective {
Expand All @@ -16,6 +16,7 @@ export class AceEditorDirective {
_readOnly:boolean = false;
_theme:string = "monokai";
_mode:string = "html";
_autoUpdateContent:boolean = true;
editor:any;
oldText:any;

Expand Down Expand Up @@ -66,10 +67,16 @@ export class AceEditorDirective {

@Input() set text(text) {
if(text == null)
text = "";
text = "";

this.editor.setValue(text);
this.editor.clearSelection();
this.editor.focus();
if(this._autoUpdateContent == true) {
this.editor.setValue(text);
this.editor.clearSelection();
this.editor.focus();
}
}

@Input() set autoUpdateContent(status) {
this._autoUpdateContent = status;
}
}

0 comments on commit 35b1659

Please sign in to comment.