From 8c2e731466f6590e2b205cf67aa3111e5aa293bc Mon Sep 17 00:00:00 2001 From: Robin Leber <rleber98@gmail.com> Date: Thu, 20 Jun 2024 15:45:07 +0200 Subject: [PATCH] pipe binding with multiple editor opening --- src/functions/pipeBinding.js | 33 +++++++++++++++++++++------------ 1 file changed, 21 insertions(+), 12 deletions(-) diff --git a/src/functions/pipeBinding.js b/src/functions/pipeBinding.js index 54fe253..fb352af 100644 --- a/src/functions/pipeBinding.js +++ b/src/functions/pipeBinding.js @@ -20,18 +20,27 @@ export const getPipesForFilter = () => { export const handlePipeBinding = (pipeMapping, editor) => { let lineNumber = 14; + let editorCodeText = editor.state.doc.toString(); pipeMapping.forEach((pipe) => { - let line = editor.state.doc.line(lineNumber); - let position = line.from; - let transaction = editor.state.update({ - changes: { - from: position, - insert: `\t\tconst ${pipe.pipeName.replace(/\s+/g, "")} = "${ - pipe.pipeName - }"\n`, - }, - }); - editor.dispatch(transaction); - lineNumber++; + if ( + editorCodeText.includes( + `const ${pipe.pipeName.replace(/\s+/g, "")} = "${pipe.pipeName}"` + ) + ) { + return; + } else { + let line = editor.state.doc.line(lineNumber); + let position = line.from; + let transaction = editor.state.update({ + changes: { + from: position, + insert: `\t\tconst ${pipe.pipeName.replace(/\s+/g, "")} = "${ + pipe.pipeName + }"\n`, + }, + }); + editor.dispatch(transaction); + lineNumber++; + } }); }; -- GitLab