diff --git a/src/JSONNode.scss b/src/JSONNode.scss index 4513996..2d4845f 100644 --- a/src/JSONNode.scss +++ b/src/JSONNode.scss @@ -32,6 +32,8 @@ right: $input-padding; height: $selector-height; box-sizing: border-box; + padding-left: $indentation-width; + z-index: 1; .selector { margin-top: $selector-height / 2; @@ -39,13 +41,13 @@ &:hover { .selector { - border: 1px dashed $selection-background; + border: 1px dashed $theme-color; } } &.selected { .selector { - border: 1px dashed $theme-color; + border: 1px dashed $gray; } } } @@ -54,8 +56,12 @@ top: -$selector-height/2 - 1px; } - .after-node-selector { + .append-node-selector { bottom: -$selector-height/2 - 1px; + + .selector { + margin-top: $selector-height / 2 - 2px; + } } .header { diff --git a/src/JSONNode.svelte b/src/JSONNode.svelte index 5c22d63..932b247 100644 --- a/src/JSONNode.svelte +++ b/src/JSONNode.svelte @@ -14,7 +14,10 @@ import { singleton } from './singleton.js' import { getPlainText, - isChildOfButton, isContentEditableDiv, + isAppendNodeSelector, + isBeforeNodeSelector, + isChildOfButton, + isContentEditableDiv, setPlainText } from './utils/domUtils.js' import Icon from 'svelte-awesome' @@ -218,7 +221,27 @@ } // check if the mouse down is not happening in the key or value input fields or on a button - if (!isContentEditableDiv(event.target) && !isChildOfButton(event.target)) { + if (isContentEditableDiv(event.target) || isChildOfButton(event.target)) { + return + } + + if (isBeforeNodeSelector(event.target)) { + singleton.mousedown = true + singleton.selectionAnchor = path + singleton.selectionFocus = null + + onSelect({ + beforePath: path + }) + } else if (isAppendNodeSelector(event.target)) { + singleton.mousedown = true + singleton.selectionAnchor = path + singleton.selectionFocus = null + + onSelect({ + appendPath: path + }) + } else { // initialize dragging a selection singleton.mousedown = true singleton.selectionAnchor = path @@ -228,17 +251,18 @@ anchorPath: singleton.selectionAnchor, focusPath: singleton.selectionFocus }) - - event.stopPropagation() } + event.stopPropagation() + event.preventDefault() + // we attache the mouse up event listener to the global document, // so we will not miss if the mouse up is happening outside of the editor document.addEventListener('mouseup', handleMouseUp) } function handleMouseMove (event) { - if (singleton.mousedown) { + if (singleton.mousedown) { // TODO: Remove the need for this, only create mousemove handle when mouse is down event.preventDefault() event.stopPropagation() @@ -314,10 +338,10 @@ on:mousemove={handleMouseMove} >