mirror of
https://github.com/elastic/kibana.git
synced 2025-04-23 17:28:26 -04:00
[ES|QL] Allows to comment out the current line with the keyboard (#184637)
## Summary
Closes https://github.com/elastic/kibana/issues/184521
It allows the users to comment out the current line by typing `CMD + /`,
bringing it closer to what a developer would expect.

This commit is contained in:
parent
1b8236375a
commit
5193d45698
1 changed files with 29 additions and 0 deletions
|
@ -237,6 +237,28 @@ export const TextBasedLanguagesEditor = memo(function TextBasedLanguagesEditor({
|
|||
}
|
||||
}, [language, onTextLangQuerySubmit, abortController, isQueryLoading, allowQueryCancellation]);
|
||||
|
||||
const onCommentLine = useCallback(() => {
|
||||
const currentPosition = editor1.current?.getPosition();
|
||||
const lineNumber = currentPosition?.lineNumber;
|
||||
if (lineNumber) {
|
||||
const lineContent = editorModel.current?.getLineContent(lineNumber) ?? '';
|
||||
const hasComment = lineContent?.startsWith('//');
|
||||
const commentedLine = hasComment ? lineContent?.replace('//', '') : `//${lineContent}`;
|
||||
// executeEdits allows to keep edit in history
|
||||
editor1.current?.executeEdits('comment', [
|
||||
{
|
||||
range: {
|
||||
startLineNumber: lineNumber,
|
||||
startColumn: 0,
|
||||
endLineNumber: lineNumber,
|
||||
endColumn: (lineContent?.length ?? 0) + 1,
|
||||
},
|
||||
text: commentedLine,
|
||||
},
|
||||
]);
|
||||
}
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
if (!isLoading) setIsQueryLoading(false);
|
||||
}, [isLoading]);
|
||||
|
@ -903,6 +925,13 @@ export const TextBasedLanguagesEditor = memo(function TextBasedLanguagesEditor({
|
|||
onQuerySubmit
|
||||
);
|
||||
|
||||
// on CMD/CTRL + / comment out the entire line
|
||||
editor.addCommand(
|
||||
// eslint-disable-next-line no-bitwise
|
||||
monaco.KeyMod.CtrlCmd | monaco.KeyCode.Slash,
|
||||
onCommentLine
|
||||
);
|
||||
|
||||
setMeasuredEditorWidth(editor.getLayoutInfo().width);
|
||||
setMeasuredContentWidth(editor.getContentWidth());
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue