Skip to content

Commit 4404d02

Browse files
committed
refactor: call init inside Editor class
Signed-off-by: Raccoon <raccoon@hackmd.io>
1 parent e72bcfe commit 4404d02

2 files changed

Lines changed: 45 additions & 45 deletions

File tree

‎public/js/index.js‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -307,8 +307,8 @@ if (!textit) {
307307
throw new Error('There was no textit area!')
308308
}
309309

310-
const editorInstance = new Editor()
311-
var editor = editorInstance.init(textit)
310+
const editorInstance = new Editor(textit)
311+
var editor = editorInstance.editor
312312

313313
// FIXME: global referncing in jquery-textcomplete patch
314314
window.editor = editor

‎public/js/lib/editor/index.js‎

Lines changed: 43 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ const viewportMargin = 20
1919
const jumpToAddressBarKeymapName = isMac ? 'Cmd-L' : 'Ctrl-L'
2020

2121
export default class Editor {
22-
constructor () {
22+
constructor (textareaElement) {
2323
this.editor = null
2424
this.jumpToAddressBarKeymapValue = null
2525
this.defaultExtraKeys = {
@@ -142,6 +142,48 @@ export default class Editor {
142142
CodeMirror.defineMode('vega', function (config, modeConfig) {
143143
return CodeMirror.overlayMode(CodeMirror.getMode(config, 'application/ld+json'), ignoreOverlay)
144144
})
145+
146+
this.init(textareaElement)
147+
}
148+
149+
init (textareaElement) {
150+
this.editor = CodeMirror.fromTextArea(textareaElement, {
151+
mode: defaultEditorMode,
152+
backdrop: defaultEditorMode,
153+
keyMap: 'sublime',
154+
viewportMargin: viewportMargin,
155+
styleActiveLine: true,
156+
lineNumbers: true,
157+
lineWrapping: true,
158+
showCursorWhenSelecting: true,
159+
highlightSelectionMatches: true,
160+
indentUnit: 4,
161+
continueComments: 'Enter',
162+
theme: 'one-dark',
163+
inputStyle: 'textarea',
164+
matchBrackets: true,
165+
autoCloseBrackets: true,
166+
matchTags: {
167+
bothTags: true
168+
},
169+
autoCloseTags: true,
170+
foldGutter: true,
171+
gutters: [
172+
'CodeMirror-linenumbers',
173+
'authorship-gutters',
174+
'CodeMirror-foldgutter'
175+
],
176+
extraKeys: this.defaultExtraKeys,
177+
flattenSpans: true,
178+
addModeClass: true,
179+
readOnly: true,
180+
autoRefresh: true,
181+
otherCursors: true,
182+
placeholder: "← Start by entering a title here\n===\nVisit /features if you don't know what to do.\nHappy hacking :)"
183+
})
184+
185+
this.spellchecker = new CodeMirrorSpellChecker(CodeMirror, this.getExistingSpellcheckLang(), this.editor)
186+
this.tableEditor = initTableEditor(this.editor)
145187
}
146188

147189
on (event, cb) {
@@ -740,48 +782,6 @@ export default class Editor {
740782
})
741783
}
742784

743-
init (textit) {
744-
this.editor = CodeMirror.fromTextArea(textit, {
745-
mode: defaultEditorMode,
746-
backdrop: defaultEditorMode,
747-
keyMap: 'sublime',
748-
viewportMargin: viewportMargin,
749-
styleActiveLine: true,
750-
lineNumbers: true,
751-
lineWrapping: true,
752-
showCursorWhenSelecting: true,
753-
highlightSelectionMatches: true,
754-
indentUnit: 4,
755-
continueComments: 'Enter',
756-
theme: 'one-dark',
757-
inputStyle: 'textarea',
758-
matchBrackets: true,
759-
autoCloseBrackets: true,
760-
matchTags: {
761-
bothTags: true
762-
},
763-
autoCloseTags: true,
764-
foldGutter: true,
765-
gutters: [
766-
'CodeMirror-linenumbers',
767-
'authorship-gutters',
768-
'CodeMirror-foldgutter'
769-
],
770-
extraKeys: this.defaultExtraKeys,
771-
flattenSpans: true,
772-
addModeClass: true,
773-
readOnly: true,
774-
autoRefresh: true,
775-
otherCursors: true,
776-
placeholder: "← Start by entering a title here\n===\nVisit /features if you don't know what to do.\nHappy hacking :)"
777-
})
778-
779-
this.spellchecker = new CodeMirrorSpellChecker(CodeMirror, this.getExistingSpellcheckLang(), this.editor)
780-
this.tableEditor = initTableEditor(this.editor)
781-
782-
return this.editor
783-
}
784-
785785
getEditor () {
786786
return this.editor
787787
}

0 commit comments

Comments
 (0)