Added cursor tracking, tabs visuals; variable focus popup, highlighting and replacement

This commit is contained in:
gohil-jay
2022-03-05 11:45:57 +05:30
parent e124012b74
commit 08fea2a2d7
2 changed files with 25 additions and 7 deletions
+20 -7
View File
@@ -228,12 +228,20 @@ const CodeEditor = (props) => {
// return "" // return ""
// } // }
function replaceVariables(index, str){ function replaceVariables(swapVariable){
var updatedCode = localcodedata.slice(0,index) + "$" + str + localcodedata.slice(index+currentVariable.length+1,) // var updatedCode = localcodedata.slice(0,index) + "$" + str + localcodedata.slice(index+currentVariable.length+1,)
setlocalcodedata(updatedCode) // setlocalcodedata(updatedCode)
setEditorPopupOpen(false) // setEditorPopupOpen(false)
setCurrentLocation(0) // setCurrentLocation(0)
// console.log(index) // 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) { function expectedOutput(input) {
@@ -342,6 +350,7 @@ const CodeEditor = (props) => {
// console.log(value.getCursor()) // console.log(value.getCursor())
setCurrentCharacter(value.getCursor().ch) setCurrentCharacter(value.getCursor().ch)
setCurrentLine(value.getCursor().line) setCurrentLine(value.getCursor().line)
// console.log(value.getCursor().ch, value.getCursor().line)
findIndex(value.getCursor().line, value.getCursor().ch) findIndex(value.getCursor().line, value.getCursor().ch)
highlight_variables(value) highlight_variables(value)
}} }}
@@ -382,6 +391,7 @@ const CodeEditor = (props) => {
{editorPopupOpen ? {editorPopupOpen ?
<Paper <Paper
style={{ style={{
margin: 10,
padding: 10, padding: 10,
width: 250, width: 250,
// textOverflow: 'ellipsis' // textOverflow: 'ellipsis'
@@ -396,7 +406,10 @@ const CodeEditor = (props) => {
}} }}
> >
<button <button
onClick={() => {replaceVariables(currentLocation, data.autocomplete)}} onClick={() => {
replaceVariables(data.autocomplete)
// console.log(currentCharacter, currentLine)
}}
style={{ style={{
backgroundColor: 'transparent', backgroundColor: 'transparent',
color: 'white', color: 'white',
@@ -425,7 +438,7 @@ const CodeEditor = (props) => {
color = 'textSecondary' color = 'textSecondary'
style={{ style={{
color: "white", color: "white",
paddingLeft: 360, paddingLeft: 340,
width: 50, width: 50,
display: 'inline', display: 'inline',
}} }}
+5
View File
@@ -12,3 +12,8 @@ code {
font-family: source-code-pro, Menlo, Monaco, Consolas, "Courier New", font-family: source-code-pro, Menlo, Monaco, Consolas, "Courier New",
monospace; monospace;
} }
.cm-tab::before{
content: "———";
margin-right: -13px;
}