Commit 420e2f22 authored by jan.koester's avatar jan.koester
Browse files

test

parent 2e112c9b
Loading
Loading
Loading
Loading
+36 −14
Changes for editor/src/webedit_api.cpp: 36 added lines, 14 removed lines.
Original line number Diff line number Diff line
@@ -1805,16 +1805,33 @@ std::string buildCanvasScript(const std::string &metaJson) {
        "}"
        "var nearTop=ev.clientY-rect.top<10;"
        "var nearBottom=rect.bottom-ev.clientY<10;"
        "if(!nearTop&&!nearBottom){insertBtn.style.display='none';marginBtn.style.display='none';return;}"
        "var pos=nearTop?'before':'after';"
        "insertCtx={targetUuid:we.uuid,position:pos};"
        "if(nearTop||nearBottom){"
        "var vpos=nearTop?'before':'after';"
        "insertCtx={targetUuid:we.uuid,position:vpos};"
        "insertBtn.style.display='block';"
        "insertBtn.style.left=(rect.left+window.scrollX)+'px';"
        "insertBtn.style.top=((nearTop?rect.top:rect.bottom)+window.scrollY-11)+'px';"
        "marginCtx={uuid:we.uuid,el:we.el,position:pos};"
        "marginCtx={uuid:we.uuid,el:we.el,axis:'v',position:vpos};"
        "marginBtn.style.display='block';"
        "marginBtn.style.cursor='ns-resize';"
        "marginBtn.textContent='\\u2195';"
        "marginBtn.style.left=(rect.left+28+window.scrollX)+'px';"
        "marginBtn.style.top=insertBtn.style.top;"
        "return;"
        "}"
        // Left/right edges only get the margin handle — horizontal insertion
        // between siblings isn't a thing in this block-stacked layout.
        "insertBtn.style.display='none';"
        "var nearLeft=ev.clientX-rect.left<10;"
        "var nearRight=rect.right-ev.clientX<10;"
        "if(!nearLeft&&!nearRight){marginBtn.style.display='none';return;}"
        "var hpos=nearLeft?'left':'right';"
        "marginCtx={uuid:we.uuid,el:we.el,axis:'h',position:hpos};"
        "marginBtn.style.display='block';"
        "marginBtn.style.cursor='ew-resize';"
        "marginBtn.textContent='\\u2194';"
        "marginBtn.style.top=(rect.top+rect.height/2-11+window.scrollY)+'px';"
        "marginBtn.style.left=((hpos==='left'?rect.left:rect.right)+window.scrollX-11)+'px';"
        "});"
        "insertBtn.addEventListener('click',function(ev){"
        "ev.stopPropagation();"
@@ -1827,28 +1844,33 @@ std::string buildCanvasScript(const std::string &metaJson) {
        "},'*');"
        "});"

        // Dragging the margin handle changes margin-top (handle sits on the
        // block's top edge) or margin-bottom (bottom edge) live; the resulting
        // 4-value shorthand is only sent to the parent on release.
        // Dragging the margin handle changes whichever side it sits on
        // (margin-top/bottom on the block's horizontal edges, margin-left/
        // right on its vertical edges) live; the resulting 4-value shorthand
        // is only sent to the parent on release.
        "marginBtn.addEventListener('mousedown',function(ev){"
        "ev.preventDefault();"
        "ev.stopPropagation();"
        "if(!marginCtx)return;"
        "var prop=marginCtx.position==='before'?'marginTop':'marginBottom';"
        "var axis=marginCtx.axis;"
        "var prop=axis==='v'?(marginCtx.position==='before'?'marginTop':'marginBottom')"
        ":(marginCtx.position==='left'?'marginLeft':'marginRight');"
        "var start=parseFloat(getComputedStyle(marginCtx.el)[prop])||0;"
        "marginDrag={el:marginCtx.el,uuid:marginCtx.uuid,pos:marginCtx.position,prop:prop,"
        "startY:ev.clientY,startVal:start,currentVal:start};"
        "marginDrag={el:marginCtx.el,uuid:marginCtx.uuid,axis:axis,pos:marginCtx.position,prop:prop,"
        "startX:ev.clientX,startY:ev.clientY,startVal:start,currentVal:start};"
        "});"
        "document.addEventListener('mousemove',function(ev){"
        "if(!marginDrag)return;"
        "if(ev.buttons===0){marginDrag=null;marginBtn.style.display='none';return;}"
        "var d=marginDrag;"
        "var delta=ev.clientY-d.startY;"
        "var signed=d.pos==='before'?-delta:delta;"
        "var val=Math.max(0,Math.round(d.startVal+signed));"
        "var delta;"
        "if(d.axis==='v'){delta=ev.clientY-d.startY;if(d.pos==='before')delta=-delta;}"
        "else{delta=ev.clientX-d.startX;if(d.pos==='left')delta=-delta;}"
        "var val=Math.max(0,Math.round(d.startVal+delta));"
        "d.el.style[d.prop]=val+'px';"
        "d.currentVal=val;"
        "marginBtn.style.top=(ev.clientY+window.scrollY-11)+'px';"
        "if(d.axis==='v')marginBtn.style.top=(ev.clientY+window.scrollY-11)+'px';"
        "else marginBtn.style.left=(ev.clientX+window.scrollX-11)+'px';"
        "});"
        "document.addEventListener('mouseup',function(){"
        "if(!marginDrag)return;"