mirror of
https://github.com/usebruno/bruno.git
synced 2025-06-24 22:11:38 +02:00
Fix Crashes and improve AutoComplete logic
Fix crash when autocomplete pops up and then is deleted. Fix autocomplete from appearing inside interpolation or strings. Fix JSON linting when its empty and not lint when mode is undefined (Code Generation). Improve tab to indent on full line or multiple lines selected.
This commit is contained in:
parent
af0d4d26bb
commit
8ed88d42c0
@ -76,12 +76,14 @@ if (!SERVER_RENDERED) {
|
|||||||
let result = jsHinter(editor) || { list: [] };
|
let result = jsHinter(editor) || { list: [] };
|
||||||
result.to = CodeMirror.Pos(cursor.line, end);
|
result.to = CodeMirror.Pos(cursor.line, end);
|
||||||
result.from = CodeMirror.Pos(cursor.line, start);
|
result.from = CodeMirror.Pos(cursor.line, start);
|
||||||
hintWords.forEach((h) => {
|
if (curWordBru) {
|
||||||
if (h.includes('.') == curWordBru.includes('.') && h.startsWith(curWordBru)) {
|
hintWords.forEach((h) => {
|
||||||
result.list.push(curWordBru.includes('.') ? h.split('.')[1] : h);
|
if (h.includes('.') == curWordBru.includes('.') && h.startsWith(curWordBru)) {
|
||||||
}
|
result.list.push(curWordBru.includes('.') ? h.split('.')[1] : h);
|
||||||
});
|
}
|
||||||
result.list = result.list?.sort();
|
});
|
||||||
|
result.list?.sort();
|
||||||
|
}
|
||||||
return result;
|
return result;
|
||||||
});
|
});
|
||||||
CodeMirror.commands.autocomplete = (cm, hint, options) => {
|
CodeMirror.commands.autocomplete = (cm, hint, options) => {
|
||||||
@ -113,9 +115,7 @@ export default class CodeEditor extends React.Component {
|
|||||||
showCursorWhenSelecting: true,
|
showCursorWhenSelecting: true,
|
||||||
foldGutter: true,
|
foldGutter: true,
|
||||||
gutters: ['CodeMirror-linenumbers', 'CodeMirror-foldgutter', 'CodeMirror-lint-markers'],
|
gutters: ['CodeMirror-linenumbers', 'CodeMirror-foldgutter', 'CodeMirror-lint-markers'],
|
||||||
lint: {
|
lint: { esversion: 11 },
|
||||||
esversion: 11
|
|
||||||
},
|
|
||||||
readOnly: this.props.readOnly,
|
readOnly: this.props.readOnly,
|
||||||
scrollbarStyle: 'overlay',
|
scrollbarStyle: 'overlay',
|
||||||
theme: this.props.theme === 'dark' ? 'monokai' : 'default',
|
theme: this.props.theme === 'dark' ? 'monokai' : 'default',
|
||||||
@ -144,8 +144,14 @@ export default class CodeEditor extends React.Component {
|
|||||||
'Ctrl-F': 'findPersistent',
|
'Ctrl-F': 'findPersistent',
|
||||||
'Cmd-H': 'replace',
|
'Cmd-H': 'replace',
|
||||||
'Ctrl-H': 'replace',
|
'Ctrl-H': 'replace',
|
||||||
Tab: 'indentMore',
|
Tab: function (cm) {
|
||||||
|
cm.getSelection().includes('\n') || editor.getLine(cm.getCursor().line) == cm.getSelection()
|
||||||
|
? cm.execCommand('indentMore')
|
||||||
|
: cm.replaceSelection(' ', 'end');
|
||||||
|
},
|
||||||
'Shift-Tab': 'indentLess',
|
'Shift-Tab': 'indentLess',
|
||||||
|
'Ctrl-Space': 'autocomplete',
|
||||||
|
'Cmd-Space': 'autocomplete',
|
||||||
'Ctrl-Y': 'foldAll',
|
'Ctrl-Y': 'foldAll',
|
||||||
'Cmd-Y': 'foldAll',
|
'Cmd-Y': 'foldAll',
|
||||||
'Ctrl-I': 'unfoldAll',
|
'Ctrl-I': 'unfoldAll',
|
||||||
@ -178,6 +184,7 @@ export default class CodeEditor extends React.Component {
|
|||||||
}
|
}
|
||||||
}));
|
}));
|
||||||
if (editor) {
|
if (editor) {
|
||||||
|
editor.setOption('lint', this.props.mode && editor.getValue().trim().length > 0 ? { esversion: 11 } : false);
|
||||||
editor.on('change', this._onEdit);
|
editor.on('change', this._onEdit);
|
||||||
this.addOverlay();
|
this.addOverlay();
|
||||||
}
|
}
|
||||||
@ -187,14 +194,15 @@ export default class CodeEditor extends React.Component {
|
|||||||
const currentLine = editor.getLine(cursor.line);
|
const currentLine = editor.getLine(cursor.line);
|
||||||
let start = cursor.ch;
|
let start = cursor.ch;
|
||||||
let end = start;
|
let end = start;
|
||||||
while (end < currentLine.length && /[\w\."'\/`]/.test(currentLine.charAt(end))) ++end;
|
while (end < currentLine.length && /[^{}();\s\[\]\,]/.test(currentLine.charAt(end))) ++end;
|
||||||
while (start && /[\w\."'\/`]/.test(currentLine.charAt(start - 1))) --start;
|
while (start && /[^{}();\s\[\]\,]/.test(currentLine.charAt(start - 1))) --start;
|
||||||
let curWord = start != end && currentLine.slice(start, end);
|
let curWord = start != end && currentLine.slice(start, end);
|
||||||
//Qualify if autocomplete will be shown
|
//Qualify if autocomplete will be shown
|
||||||
if (
|
if (
|
||||||
/^(?!Shift|Tab|Enter|ArrowUp|ArrowDown|ArrowLeft|ArrowRight|\s)\w*/.test(event.key) &&
|
/^(?!Shift|Tab|Enter|ArrowUp|ArrowDown|ArrowLeft|ArrowRight|\s)\w*/.test(event.key) &&
|
||||||
curWord.length > 1 &&
|
curWord.length > 0 &&
|
||||||
/^(?!"'\d`)[a-zA-Z\.]/.test(curWord)
|
!/\/\/|\/\*|.*{{|`[^$]*{|`[^{]*$/.test(currentLine.slice(0, end)) &&
|
||||||
|
/(?<!\d)[a-zA-Z\._]$/.test(curWord)
|
||||||
) {
|
) {
|
||||||
CodeMirror.commands.autocomplete(cm, CodeMirror.hint.brunoJS, { completeSingle: false });
|
CodeMirror.commands.autocomplete(cm, CodeMirror.hint.brunoJS, { completeSingle: false });
|
||||||
}
|
}
|
||||||
@ -266,6 +274,7 @@ export default class CodeEditor extends React.Component {
|
|||||||
|
|
||||||
_onEdit = () => {
|
_onEdit = () => {
|
||||||
if (!this.ignoreChangeEvent && this.editor) {
|
if (!this.ignoreChangeEvent && this.editor) {
|
||||||
|
this.editor.setOption('lint', this.editor.getValue().trim().length > 0 ? { esversion: 11 } : false);
|
||||||
this.cachedValue = this.editor.getValue();
|
this.cachedValue = this.editor.getValue();
|
||||||
if (this.props.onEdit) {
|
if (this.props.onEdit) {
|
||||||
this.props.onEdit(this.cachedValue);
|
this.props.onEdit(this.cachedValue);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user