Skip to content

Commit

Permalink
Make 'editor' Property Public
Browse files Browse the repository at this point in the history
  • Loading branch information
evanplaice committed Jun 10, 2020
1 parent a56ec2f commit 95a39fa
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ Try it on [WebComponents.dev](https://webcomponents.dev/edit/uQEePfQ92jOWOpupDzp

**Properties**

- `editor` - the CodeMirror editor instance
- `value` - get/set the editor's contents

*Note: The ID attribute is required when multiple editors instances are present*
Expand Down
14 changes: 7 additions & 7 deletions src/wc-codemirror.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export class WCCodeMirror extends HTMLElement {
this.setSrc();
}

get value () { return this.__editor.getValue(); }
get value () { return this.editor.getValue(); }
set value (value) {
this.setValue(value);
}
Expand All @@ -35,7 +35,7 @@ export class WCCodeMirror extends HTMLElement {
this.appendChild(template.content.cloneNode(true));
this.__initialized = false;
this.__element = null;
this.__editor = null;
this.editor = null;
}

async connectedCallback () {
Expand All @@ -58,7 +58,7 @@ export class WCCodeMirror extends HTMLElement {
viewportMargin = viewportMarginAttr === 'infinity' ? Infinity : parseInt(viewportMarginAttr);
}

this.__editor = CodeMirror.fromTextArea(this.__element, {
this.editor = CodeMirror.fromTextArea(this.__element, {
lineNumbers: true,
readOnly: false,
mode,
Expand All @@ -80,13 +80,13 @@ export class WCCodeMirror extends HTMLElement {
async setSrc () {
const src = this.getAttribute('src');
const contents = await this.fetchSrc(src);
this.__editor.swapDoc(CodeMirror.Doc(contents, this.getAttribute('mode')));
this.__editor.refresh();
this.editor.swapDoc(CodeMirror.Doc(contents, this.getAttribute('mode')));
this.editor.refresh();
}

async setValue (value) {
this.__editor.swapDoc(CodeMirror.Doc(value, this.getAttribute('mode')));
this.__editor.refresh();
this.editor.swapDoc(CodeMirror.Doc(value, this.getAttribute('mode')));
this.editor.refresh();
}

async fetchSrc (src) {
Expand Down

0 comments on commit 95a39fa

Please sign in to comment.