Fix brackets mismatch (#2019)

This commit is contained in:
Piyush Mishra 2020-12-10 11:48:59 +05:30 committed by GitHub
parent 9b51bf9af2
commit 0e47c0a4c0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 5 deletions

View File

@ -8,6 +8,7 @@ export enum EditorModes {
JSON = "application/json",
JSON_WITH_BINDING = "json-js",
SQL_WITH_BINDING = "sql-js",
JAVASCRIPT = "javascript",
}
export enum EditorTheme {

View File

@ -22,6 +22,7 @@ import AnalyticsUtil from "utils/AnalyticsUtil";
import "components/editorComponents/CodeEditor/modes";
import {
EditorConfig,
EditorModes,
EditorSize,
EditorTheme,
EditorThemes,
@ -140,6 +141,7 @@ class CodeEditor extends Component<Props, State> {
this.editor.on("change", this.onChangeTigger);
this.editor.on("keyup", this.handleAutocompleteHide);
this.editor.on("focus", this.handleEditorFocus);
this.editor.on("cursorActivity", this.handleCursorMovement);
this.editor.on("focus", this.onFocusTrigger);
this.editor.on("blur", this.handleEditorBlur);
if (this.props.height) {
@ -216,17 +218,28 @@ class CodeEditor extends Component<Props, State> {
}
};
handleCursorMovement = (cm: CodeMirror.Editor) => {
// ignore if disabled
if (!this.props.input.onChange || this.props.disabled) {
return;
}
const mode = cm.getModeAt(cm.getCursor());
if (
mode &&
[EditorModes.JAVASCRIPT, EditorModes.JSON].includes(mode.name)
) {
this.editor.setOption("matchBrackets", true);
} else {
this.editor.setOption("matchBrackets", false);
}
};
handleEditorFocus = () => {
this.setState({ isFocused: true });
this.editor.refresh();
if (this.props.size === EditorSize.COMPACT) {
this.editor.setOption("lineWrapping", true);
}
// Highlight matching brackets only when focused and not in readonly mode
if (this.props.input.onChange && !this.props.disabled) {
this.editor.setOption("matchBrackets", true);
}
};
handleEditorBlur = () => {