mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 09:48:58 -04:00
[ES|QL] Fixes the multiple comments bug (#203966)
## Summary  Sometimes commenting multiple lines doesnt work as expected. This PR fixes it. The problem was that we were (un)commenting line by line and this apparently can be buggy. With this PR we gather the edits and apply all of them in one `executeEdits `
This commit is contained in:
parent
96573a40c1
commit
9edadfdc46
1 changed files with 11 additions and 11 deletions
|
@ -169,25 +169,25 @@ export const ESQLEditor = memo(function ESQLEditor({
|
|||
const currentSelection = editor1?.current?.getSelection();
|
||||
const startLineNumber = currentSelection?.startLineNumber;
|
||||
const endLineNumber = currentSelection?.endLineNumber;
|
||||
const edits = [];
|
||||
if (startLineNumber && endLineNumber) {
|
||||
for (let lineNumber = startLineNumber; lineNumber <= endLineNumber; 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,
|
||||
edits.push({
|
||||
range: {
|
||||
startLineNumber: lineNumber,
|
||||
startColumn: 0,
|
||||
endLineNumber: lineNumber,
|
||||
endColumn: (lineContent?.length ?? 0) + 1,
|
||||
},
|
||||
]);
|
||||
text: commentedLine,
|
||||
});
|
||||
}
|
||||
// executeEdits allows to keep edit in history
|
||||
editor1.current?.executeEdits('comment', edits);
|
||||
}
|
||||
}, []);
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue