using free function
This commit is contained in:
@@ -17,7 +17,7 @@ export default class TheCodeArea extends StatefulVue {
|
|||||||
@Prop() private theme!: string;
|
@Prop() private theme!: string;
|
||||||
|
|
||||||
public async mounted() {
|
public async mounted() {
|
||||||
this.editor = this.initializeEditor();
|
this.editor = initializeEditor(this.theme, this.editorId);
|
||||||
const state = await this.getCurrentStateAsync();
|
const state = await this.getCurrentStateAsync();
|
||||||
this.updateCode(state.code.current);
|
this.updateCode(state.code.current);
|
||||||
state.code.changed.on((code) => this.updateCode(code));
|
state.code.changed.on((code) => this.updateCode(code));
|
||||||
@@ -26,20 +26,19 @@ export default class TheCodeArea extends StatefulVue {
|
|||||||
private updateCode(code: string) {
|
private updateCode(code: string) {
|
||||||
this.editor.setValue(code || 'Something is bad 😢', 1);
|
this.editor.setValue(code || 'Something is bad 😢', 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
private initializeEditor(): ace.Ace.Editor {
|
|
||||||
const lang = 'batchfile';
|
|
||||||
const theme = this.theme || 'github';
|
|
||||||
const editor = ace.edit(this.editorId);
|
|
||||||
editor.getSession().setMode(`ace/mode/${lang}`);
|
|
||||||
editor.setTheme(`ace/theme/${theme}`);
|
|
||||||
editor.setReadOnly(true);
|
|
||||||
editor.setAutoScrollEditorIntoView(true);
|
|
||||||
// this.editor.getSession().setUseWrapMode(true);
|
|
||||||
// this.editor.setOption("indentedSoftWrap", false);
|
|
||||||
return editor;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function initializeEditor(theme: string, editorId: string): ace.Ace.Editor {
|
||||||
|
const lang = 'batchfile';
|
||||||
|
theme = theme || 'github';
|
||||||
|
const editor = ace.edit(editorId);
|
||||||
|
editor.getSession().setMode(`ace/mode/${lang}`);
|
||||||
|
editor.setTheme(`ace/theme/${theme}`);
|
||||||
|
editor.setReadOnly(true);
|
||||||
|
editor.setAutoScrollEditorIntoView(true);
|
||||||
|
return editor;
|
||||||
|
}
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style scoped lang="scss">
|
<style scoped lang="scss">
|
||||||
|
|||||||
Reference in New Issue
Block a user