Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
cm.setValue(str);
expect(cm.getValue()).eql(str);
expect(cm.isClean()).not.ok;
// blur event
var i = 0;
cm.on('blur', function () {
i += 1;
expect(i === 1).ok;
});
cm.on('focus', function () {
i += 1;
expect(i === 2).ok;
done();
});
CodeMirror.signal(cm, 'blur');
CodeMirror.signal(cm, 'focus');
});
componentDidUpdate(prevProps) {
const CodeMirror = require('codemirror')
// Ensure the changes caused by this update are not interpretted as
// user-input changes which could otherwise result in an infinite
// event loop.
this.ignoreChangeEvent = true
if (this.props.schema !== prevProps.schema) {
this.editor.options.lint.schema = this.props.schema
this.editor.options.hintOptions.schema = this.props.schema
this.editor.options.info.schema = this.props.schema
this.editor.options.jump.schema = this.props.schema
CodeMirror.signal(this.editor, 'change', this.editor)
}
if (
this.props.value !== prevProps.value &&
this.props.value !== this.cachedValue
) {
this.cachedValue = this.props.value
this.editor.setValue(this.props.value)
}
this.ignoreChangeEvent = false
setTimeout(() => {
if (this.props.sessionId !== prevProps.sessionId) {
if (this.props.scrollTop) {
this.scrollTo(this.props.scrollTop)
}
}
CodeMirror.defineExtension('validate', function validate() {
const code = this.getValue();
let lineMatches;
try {
JSON.parse(code);
this.notify('SUCCESS', 'Valid JSON');
CodeMirror.signal(CodeMirror, 'validate', this);
} catch (_e) {
try {
jsonlint.parse(code);
this.notify('SUCCESS', 'Valid JSON');
CodeMirror.signal(CodeMirror, 'validate', this);
} catch (e) {
// retrieve line number from error
lineMatches = e.message.match(/line ([0-9]*)/);
if (lineMatches && lineMatches.length > 1) {
this.highlightErrorLine(+lineMatches[1] - 1);
}
this.notify('ERROR', e);
CodeMirror.signal(CodeMirror, 'errorvalidate', this);
value: function componentDidUpdate(prevProps) {
var CodeMirror = require("codemirror");
// Ensure the changes caused by this update are not interpretted as
// user-input changes which could otherwise result in an infinite
// event loop.
this.ignoreChangeEvent = true;
if (this.props.schema !== prevProps.schema) {
this.editor.options.lint.schema = this.props.schema;
this.editor.options.hintOptions.schema = this.props.schema;
this.editor.options.info.schema = this.props.schema;
this.editor.options.jump.schema = this.props.schema;
CodeMirror.signal(this.editor, "change", this.editor);
}
if (this.props.value !== prevProps.value && this.props.value !== this.cachedValue) {
this.cachedValue = this.props.value;
this.editor.setValue(this.props.value);
}
this.ignoreChangeEvent = false;
}
}, {
componentDidUpdate(prevProps) {
const CodeMirror = require('codemirror');
// Ensure the changes caused by this update are not interpretted as
// user-input changes which could otherwise result in an infinite
// event loop.
this.ignoreChangeEvent = true;
if (this.props.variableToType !== prevProps.variableToType) {
this.editor.options.lint.variableToType = this.props.variableToType;
this.editor.options.hintOptions.variableToType = this.props.variableToType;
CodeMirror.signal(this.editor, 'change', this.editor);
}
if (
this.props.value !== prevProps.value &&
this.props.value !== this.cachedValue
) {
const thisValue = this.props.value || '';
this.cachedValue = thisValue;
this.editor.setValue(thisValue);
}
this.ignoreChangeEvent = false;
}
componentDidUpdate(prevProps) {
const CodeMirror = require('codemirror');
// Ensure the changes caused by this update are not interpretted as
// user-input changes which could otherwise result in an infinite
// event loop.
this.ignoreChangeEvent = true;
if (this.props.autoCompleteData !== prevProps.autoCompleteData) {
// this.editor.options.lint.autoCompleteData = this.props.autoCompleteData;
this.editor.options.hintOptions.variableToType = getVariableToType(
this.props.autoCompleteData
);
CodeMirror.signal(this.editor, 'change', this.editor);
}
if (this.props.value !== prevProps.value && this.props.value !== this.cachedValue) {
const thisValue = this.props.value || '';
this.cachedValue = thisValue;
this.editor.setValue(thisValue);
}
this.ignoreChangeEvent = false;
}
goLineDownOrEmit(editor: Editor & Doc): void {
const cursor: Position = editor.getCursor();
const lastLineNumber: number = editor.lastLine();
const lastLine: string = editor.getLine(lastLineNumber);
if (
cursor.line === lastLineNumber &&
cursor.ch === lastLine.length &&
!editor.somethingSelected()
) {
CodeMirror.signal(editor, "bottomBoundary");
} else {
editor.execCommand("goLineDown");
}
}
private _diffAndApply(data: DocInfoLike) {
for (let k in data) {
if (!isEqual(data[k], this[k])) {
CodeMirror.signal(this.cm, "docInfoChange", k, data[k])
this[k] = data[k]
if (k === 'footnotes') {
let footnoteDict: this['footnoteDict'] = this.footnoteDict = {}
for (let node of data[k]) {
let name = node.name.toLowerCase()
if (name in footnoteDict) footnoteDict[name].push(node)
else footnoteDict[name] = [node]
}
}
}
}
}
}
window.addEventListener('load', function() {
CodeMirror.signal(editor, "change");
});
const initialScroll = this.editor.getScrollInfo()
this.cachedValue =
getSDL(
this.props.schema,
this.props.settings['schema.disableComments'],
) || ''
this.editor.setValue(
getSDL(
this.props.schema,
this.props.settings['schema.disableComments'],
),
)
if (this.props.isPollingSchema) {
this.editor.scrollTo(initialScroll.left, initialScroll.top)
}
CodeMirror.signal(this.editor, 'change', this.editor)
}
if (this.props.width !== prevProps.width) {
this.editor.refresh()
}
if (
this.props.settings['schema.disableComments'] !==
prevProps.settings['schema.disableComments']
) {
this.editor.refresh()
}
}