Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function updateMode() {
var language = $scope.language && typeof $scope.language === 'string' ? $scope.language : defaultLanguage;
if (language) {
var info = CodeMirror.findModeByName(language);
// Set proper editor mode
doc.setOption('mode', info.mime);
CodeMirror.autoLoadMode(doc, info.mode);
// Set proper Lint mode
doc.setOption('lint', getLintOption(info.name));
}
}
applyEditorStyleSingleFile (props) {
const { config, snippet } = props || this.props
const {
theme,
showLineNumber,
fontFamily,
fontSize,
tabSize,
indentUsingTab,
highlightCurrentLine
} = config.editor
// only update codemirror mode if new props is passed
if (props) {
const snippetMode = CodeMirror.findModeByName(snippet.lang).mode
if (snippetMode && snippetMode !== 'null') {
require(`codemirror/mode/${snippetMode}/${snippetMode}`)
}
}
const gutters = showLineNumber
? ['CodeMirror-linenumbers', 'CodeMirror-foldgutter']
: []
this.editor.getWrapperElement().style.fontSize = `${fontSize}px`
this.editor.setOption('lineNumbers', showLineNumber)
this.editor.setOption('foldGutter', showLineNumber)
this.editor.setOption('theme', theme)
this.editor.setOption('gutters', gutters)
this.editor.setOption('indentUnit', tabSize)
this.editor.setOption('tabSize', tabSize)
this.editor.setOption('indentWithTabs', indentUsingTab)
const descripChanged = snippet.description !== description.value
if (
valueChanged ||
langChanged ||
nameChanged ||
tagChanged ||
descripChanged
) {
const newSnippet = _.clone(snippet)
newSnippet.value = editor.getValue()
newSnippet.lang = lang.value
newSnippet.name = name.value
newSnippet.tags = newTags
newSnippet.description = description.value
if (langChanged) {
const snippetMode = CodeMirror.findModeByName(newSnippet.lang).mode
require(`codemirror/mode/${snippetMode}/${snippetMode}`)
editor.setOption('mode', snippetMode)
}
store.updateSnippet(newSnippet)
}
this.setState({ isEditing: false }, () => {
eventEmitter.emit('snippet-detail:edit-end')
})
editor.setOption('readOnly', true)
}
setMode (mode) {
let syntax = CodeMirror.findModeByName(convertModeName(mode))
if (syntax == null) syntax = CodeMirror.findModeByName('Plain Text')
this.editor.setOption('mode', syntax.mime)
CodeMirror.autoLoadMode(this.editor, syntax.mode)
}
setMode (mode) {
let syntax = CodeMirror.findModeByName(pass(mode))
if (syntax == null) syntax = CodeMirror.findModeByName('Plain Text')
this.editor.setOption('mode', syntax.mime)
CodeMirror.autoLoadMode(this.editor, syntax.mode)
}
setSyntaxMode (mode) {
let syntax = CodeMirror.findModeByName(mode)
if (syntax == null) syntax = CodeMirror.findModeByName('Plain Text')
this.codemirror.setOption('mode', syntax.mime)
CodeMirror.autoLoadMode(this.codemirror, syntax.mode)
}
setMode (mode) {
let syntax = CodeMirror.findModeByName(pass(mode))
if (syntax == null) syntax = CodeMirror.findModeByName('Plain Text')
this.editor.setOption('mode', syntax.mime)
CodeMirror.autoLoadMode(this.editor, syntax.mode)
}
const viewList = note.snippets.map((snippet, index) => {
const isActive = this.state.snippetIndex === index
let syntax = CodeMirror.findModeByName(pass(snippet.mode))
if (syntax == null) syntax = CodeMirror.findModeByName('Plain Text')
return <div style="{{zIndex:">
{snippet.mode === 'markdown'
?
: </div>
setSyntaxMode (mode) {
let syntax = CodeMirror.findModeByName(mode)
if (syntax == null) syntax = CodeMirror.findModeByName('Plain Text')
this.codemirror.setOption('mode', syntax.mime)
CodeMirror.autoLoadMode(this.codemirror, syntax.mode)
}