From b2204e1d77743914360463fbcafb57585544d60b Mon Sep 17 00:00:00 2001 From: Jan Prochazka Date: Wed, 28 Sep 2022 13:21:21 +0200 Subject: [PATCH] using gutte3r decorations for active query part --- packages/web/src/query/AceEditor.svelte | 37 +++++++++++++------------ 1 file changed, 19 insertions(+), 18 deletions(-) diff --git a/packages/web/src/query/AceEditor.svelte b/packages/web/src/query/AceEditor.svelte index c3e8af8a..b094ab8a 100644 --- a/packages/web/src/query/AceEditor.svelte +++ b/packages/web/src/query/AceEditor.svelte @@ -307,18 +307,14 @@ if (!mode?.includes('sql')) return; editor?.session?.setAnnotations([ - ...currentPartLines.map(row => ({ - row, - className: 'ace-gutter-current-part', - })), ...(queryParts || []) - .filter(part => !(errorMessages || []).find(err => err.line == part.trimStart?.line)) + .filter(part => !(errorMessages || []).find(err => err.line == part.trimStart.line)) .map(part => ({ row: part.trimStart.line, text: part.text, className: currentPartLines.includes(part.trimStart.line) ? 'ace-gutter-sql-run ace-gutter-current-part' - : 'ace-gutter-sql-run', + : 'ace-gutter-sql-run', // className: 'ace-gutter-sql-run', })), ...(errorMessages || []).map(error => ({ row: error.line, @@ -369,10 +365,10 @@ } function changedCurrentQueryPart() { - // if (queryParts.length <= 1) { - // removeCurrentPartMarker(); - // return; - // } + if (queryParts.length <= 1) { + removeCurrentPartMarker(); + return; + } const selectionRange = editor.getSelectionRange(); @@ -393,15 +389,20 @@ ); if (part?.text != currentPart?.text || part?.start?.position != currentPart?.start?.position) { - // removeCurrentPartMarker(); + removeCurrentPartMarker(); currentPart = part; - currentPartLines = []; if (currentPart) { const start = currentPart.trimStart || currentPart.start; const end = currentPart.trimEnd || currentPart.end; if (start && end) { currentPartLines = _.range(start.line, end.line + 1); + for (const row of currentPartLines) { + if ((queryParts || []).find(part => part.trimStart.line == row)) { + continue; + } + editor.getSession().addGutterDecoration(row, 'ace-gutter-current-part'); + } } // currentPartMarker = editor // .getSession() @@ -411,12 +412,12 @@ } } - // function removeCurrentPartMarker() { - // if (currentPartMarker != null) { - // editor.getSession().removeMarker(currentPartMarker); - // currentPartMarker = null; - // } - // } + function removeCurrentPartMarker() { + for (const row of currentPartLines) { + editor.getSession().removeGutterDecoration(row, 'ace-gutter-current-part'); + } + currentPartLines = []; + } onMount(() => { editor = ace.edit(EDITOR_ID);