From d407058a18d0f0a3df97ca287ca1be9b56e871ea Mon Sep 17 00:00:00 2001 From: Fabien Benetou Date: Thu, 25 May 2023 07:03:59 +0200 Subject: [PATCH] horizontal split with new editors, split full lines and vertical positioning --- index.html | 64 ++++++++++++++++++++++++++++++++++++------------------ 1 file changed, 43 insertions(+), 21 deletions(-) diff --git a/index.html b/index.html index 615c5e6..fb4dbf6 100644 --- a/index.html +++ b/index.html @@ -2209,7 +2209,6 @@ document.body.addEventListener( "highlighterready", (e) => { let pl = src.length/parts for (let n=0; n nextLineCodeEditor(codeEditor, ), 100) +function startScrollCodeEditor(codeEditor){ + if (!codeEditor.scrollInterval) codeEditor.scrollInterval = setInterval( _ => nextLineCodeEditor(codeEditor), 100) } function highlightAllOccurences(codeEditor, keyword="function"){ @@ -2355,22 +2352,22 @@ function highlightUnderChar(codeEditor, pos=0, name=null){ c.position.z= .01 } -function moveCaretToNextVisibleChar(codeEditor, ){ +function moveCaretToNextVisibleChar(codeEditor){ addCaretToCodeEditor( ++codeEditor.caret ) // might be able to reach non visible one by remove an offset } function addCaretToCodeEditor(codeEditor, pos=0){ - if (codeEditor.caret) removeCaretFromCodeEditor(codeEditor, ) + if (codeEditor.caret) removeCaretFromCodeEditor(codeEditor) highlightUnderChar(codeEditor, pos, "caret") codeEditor.caret = pos } -function removeCaretFromCodeEditor(codeEditor, ){ +function removeCaretFromCodeEditor(codeEditor){ codeEditor.element.object3D.getObjectByName("caret").removeFromParent() } -function clearCodeEditorContent(codeEditor, ){ +function clearCodeEditorContent(codeEditor){ updateCodeEditorWithContent( "" ) } @@ -2386,7 +2383,7 @@ function updateCodeEditorWithContent(codeEditor, content){ if (!codeEditor.element) return codeEditor.currentlyDisplayedText=content codeEditor.element.setAttribute("troika-text", {value: content}) - if (codeEditor.language) codeEditor.element.setAttribute("troika-text", {colorRanges: highlight(content, language='javascript')}) + if (codeEditor.language) codeEditor.element.setAttribute("troika-text", {colorRanges: highlight(content, codeEditor.language)}) } function addBackdropToTroikaElement( codeEditor ){ @@ -2459,8 +2456,8 @@ function addGuttersToTroikaElement( codeEditor ){ var rightGutter = document.createElement("a-cylinder") // height proportional to the visible content to the terminal size - let scrollBarHeight = codeEditor.lengthWindowRange/getNumberOfLinesFromCodeEditor(codeEditor, ) * h - let scrollBarVerticalOffset = codeEditor.line/getNumberOfLinesFromCodeEditor(codeEditor, ) * h + let scrollBarHeight = codeEditor.lengthWindowRange/getNumberOfLinesFromCodeEditor(codeEditor) * h + let scrollBarVerticalOffset = codeEditor.line/getNumberOfLinesFromCodeEditor(codeEditor) * h if (scrollBarHeight < .1) scrollBarHeight = .1 rightGutter.setAttribute("height", scrollBarHeight ) rightGutter.setAttribute("radius", .01 ) @@ -2521,7 +2518,7 @@ function addGuttersToTroikaElement( codeEditor ){ }) } -function getNumberOfLinesFromCodeEditor(codeEditor, ){ +function getNumberOfLinesFromCodeEditor(codeEditor){ let newLines = codeEditor.page.match(/\n/g) if (!newLines) return 1 // undefined or 0 return newLines.length @@ -2544,7 +2541,6 @@ function addCodeEditor(page="jxr console.log('hello world')", language="javascri language: null, } // could also add empty but with column and row for sizing - // for now supporting only 1 scode editor, despite the name parameter let forcedLines = '' const width = 50 @@ -2554,7 +2550,7 @@ function addCodeEditor(page="jxr console.log('hello world')", language="javascri let parts = page.split(' ') let n = 0 - if (!language.length){ + if (!language?.length){ while ( pos < page.length ){ while ( line.length < width && parts[n]){ line += parts[n++] + ' ' @@ -2571,7 +2567,7 @@ function addCodeEditor(page="jxr console.log('hello world')", language="javascri codeEditor.page = page } codeEditor.line = codeEditor.startWindowRange - let numberOfLines = getNumberOfLinesFromCodeEditor(codeEditor, ) + let numberOfLines = getNumberOfLinesFromCodeEditor(codeEditor) if (numberOfLines