Skip to content

Commit

Permalink
[8.17] [ES|QL] Fixes the multiple comments bug (elastic#203966) (elas…
Browse files Browse the repository at this point in the history
…tic#204001)

# Backport

This will backport the following commits from `main` to `8.17`:
- [[ES|QL] Fixes the multiple comments bug
(elastic#203966)](elastic#203966)

<!--- Backport version: 9.4.3 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sqren/backport)

<!--BACKPORT [{"author":{"name":"Stratoula
Kalafateli","email":"efstratia.kalafateli@elastic.co"},"sourceCommit":{"committedDate":"2024-12-12T11:08:29Z","message":"[ES|QL]
Fixes the multiple comments bug (elastic#203966)\n\n##
Summary\r\n\r\n\r\n![meow](https://github.com/user-attachments/assets/aea64a3c-97de-417a-bd67-5434e70cf22a)\r\n\r\nSometimes
commenting multiple lines doesnt work as expected.\r\n\r\nThis PR fixes
it. The problem was that we were (un)commenting line by\r\nline and this
apparently can be buggy. With this PR we gather the edits\r\nand apply
all of them in one `executeEdits
`","sha":"9edadfdc4637b2fccc925677f9977fde62849608","branchLabelMapping":{"^v9.0.0$":"main","^v8.18.0$":"8.x","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:fix","v9.0.0","Feature:ES|QL","Team:ESQL","backport:version","v8.17.0","v8.18.0"],"title":"[ES|QL]
Fixes the multiple comments
bug","number":203966,"url":"https://github.com/elastic/kibana/pull/203966","mergeCommit":{"message":"[ES|QL]
Fixes the multiple comments bug (elastic#203966)\n\n##
Summary\r\n\r\n\r\n![meow](https://github.com/user-attachments/assets/aea64a3c-97de-417a-bd67-5434e70cf22a)\r\n\r\nSometimes
commenting multiple lines doesnt work as expected.\r\n\r\nThis PR fixes
it. The problem was that we were (un)commenting line by\r\nline and this
apparently can be buggy. With this PR we gather the edits\r\nand apply
all of them in one `executeEdits
`","sha":"9edadfdc4637b2fccc925677f9977fde62849608"}},"sourceBranch":"main","suggestedTargetBranches":["8.17","8.x"],"targetPullRequestStates":[{"branch":"main","label":"v9.0.0","branchLabelMappingKey":"^v9.0.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/203966","number":203966,"mergeCommit":{"message":"[ES|QL]
Fixes the multiple comments bug (elastic#203966)\n\n##
Summary\r\n\r\n\r\n![meow](https://github.com/user-attachments/assets/aea64a3c-97de-417a-bd67-5434e70cf22a)\r\n\r\nSometimes
commenting multiple lines doesnt work as expected.\r\n\r\nThis PR fixes
it. The problem was that we were (un)commenting line by\r\nline and this
apparently can be buggy. With this PR we gather the edits\r\nand apply
all of them in one `executeEdits
`","sha":"9edadfdc4637b2fccc925677f9977fde62849608"}},{"branch":"8.17","label":"v8.17.0","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"8.x","label":"v8.18.0","branchLabelMappingKey":"^v8.18.0$","isSourceBranch":false,"state":"NOT_CREATED"}]}]
BACKPORT-->

Co-authored-by: Stratoula Kalafateli <efstratia.kalafateli@elastic.co>
  • Loading branch information
kibanamachine and stratoula authored Dec 12, 2024
1 parent ebdcdd1 commit 34c9ed8
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions packages/kbn-esql-editor/src/esql_editor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}, []);

Expand Down

0 comments on commit 34c9ed8

Please sign in to comment.