Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[8.17] [ES|QL] Fixes the multiple comments bug (#203966) #204001

Merged
merged 1 commit into from
Dec 12, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading