How to use the ve-range-utils/normalizePositionByRangeLength function in ve-range-utils

To help you get started, we’ve selected a few ve-range-utils examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github TeselaGen / openVectorEditor / src / VectorEditor / VectorInteractionWrapper / index.js View on Github external
function handleNoSelectionLayerYet({caretPosition, selectionLayerUpdate, nearestCaretPos, sequenceLength}) {
    //no selection layer yet, so we'll start one if necessary
    // 0 1 2 3 4 5 6 7 8 9
    //    c 
    //        n 
    //
    var dragEnd = {
        start: caretPosition,
        end: normalizePositionByRangeLength(nearestCaretPos - 1, sequenceLength, true)
    }
    var dragStart = {
        start: nearestCaretPos,
        end: normalizePositionByRangeLength(caretPosition - 1, sequenceLength, true)
    }
    if (caretPosition === nearestCaretPos) {
        return // do nothing because nearestCaretPos === caretPosition
    } else if (getRangeLength(dragEnd, sequenceLength) < getRangeLength(dragStart, sequenceLength)) {
        draggingEnd = true; //the caret becomes the "selection end"
        selectionLayerUpdate(dragEnd)
    } else {
        draggingEnd = false; //the caret becomes the "selection end"
        selectionLayerUpdate(dragStart)
    }
}
function handleCaretDrag({caretPosition, selectionLayer, selectionLayerUpdate, nearestCaretPos, sequenceLength}) {
github TeselaGen / openVectorEditor / src / VectorEditor / VectorInteractionWrapper / index.js View on Github external
function handleSelectionEndGrabbed({caretPosition, selectionLayer, selectionLayerUpdate, nearestCaretPos, sequenceLength}) {
    if (selectionLayer.start < 0) {
        handleNoSelectionLayerYet({
            caretPosition,
            selectionLayerUpdate,
            nearestCaretPos,
            sequenceLength
        })
    } else {
        //there must be a selection layer                  
        //we need to move the selection layer
        var newEnd = normalizePositionByRangeLength(nearestCaretPos - 1, sequenceLength)
        selectionLayerUpdate({
            start: selectionLayer.start,
            end: newEnd
        })
    }
}
function handleNoSelectionLayerYet({caretPosition, selectionLayerUpdate, nearestCaretPos, sequenceLength}) {