From 08fea2a2d77b9094139c77b24bf65c0efb1701ed Mon Sep 17 00:00:00 2001 From: gohil-jay Date: Sat, 5 Mar 2022 11:45:57 +0530 Subject: [PATCH] Added cursor tracking, tabs visuals; variable focus popup, highlighting and replacement --- frontend/src/components/ShuffleCodeEditor.jsx | 27 ++++++++++++++----- frontend/src/index.css | 5 ++++ 2 files changed, 25 insertions(+), 7 deletions(-) diff --git a/frontend/src/components/ShuffleCodeEditor.jsx b/frontend/src/components/ShuffleCodeEditor.jsx index b52d88be..4a5e21f9 100644 --- a/frontend/src/components/ShuffleCodeEditor.jsx +++ b/frontend/src/components/ShuffleCodeEditor.jsx @@ -228,12 +228,20 @@ const CodeEditor = (props) => { // return "" // } - function replaceVariables(index, str){ - var updatedCode = localcodedata.slice(0,index) + "$" + str + localcodedata.slice(index+currentVariable.length+1,) - setlocalcodedata(updatedCode) - setEditorPopupOpen(false) - setCurrentLocation(0) + function replaceVariables(swapVariable){ + // var updatedCode = localcodedata.slice(0,index) + "$" + str + localcodedata.slice(index+currentVariable.length+1,) + // setlocalcodedata(updatedCode) + // setEditorPopupOpen(false) + // setCurrentLocation(0) // console.log(index) + // console.log(currentLocation) + + var code_lines = localcodedata.split('\n') + code_lines[currentLine] = code_lines[currentLine].slice(0,currentLocation[1]) + "$" + swapVariable + code_lines[currentLine].slice(currentLocation[1]+currentVariable.length,) + // console.log(code_lines) + var updatedCode = code_lines.join('\n') + // console.log(updatedCode) + setlocalcodedata(updatedCode) } function expectedOutput(input) { @@ -342,6 +350,7 @@ const CodeEditor = (props) => { // console.log(value.getCursor()) setCurrentCharacter(value.getCursor().ch) setCurrentLine(value.getCursor().line) + // console.log(value.getCursor().ch, value.getCursor().line) findIndex(value.getCursor().line, value.getCursor().ch) highlight_variables(value) }} @@ -382,6 +391,7 @@ const CodeEditor = (props) => { {editorPopupOpen ? { }} >