Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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}) {
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}) {