clean up selected lines reducer

main
Mike Fix 5 years ago
parent cc09b7f0a4
commit 625bbd4773
No known key found for this signature in database
GPG Key ID: 1D85E862314CA79F

@ -388,16 +388,22 @@ function selectedLinesReducer(
) {
const newState = {}
if (type === 'GROUP' && prevLine) {
switch (type) {
case 'GROUP': {
if (prevLine) {
for (let i = Math.min(prevLine, lineNumber); i < Math.max(prevLine, lineNumber) + 1; i++) {
newState[i] = selected[prevLine]
}
}
if (type === 'MULTILINE') {
break
}
case 'MULTILINE': {
for (let i = 0; i < selectedLines.length; i++) {
newState[selectedLines[i] - 1] = true
}
} else {
break
}
default: {
for (let i = 0; i < numLines; i++) {
if (i != lineNumber) {
if (prevLine == null) {
@ -408,6 +414,7 @@ function selectedLinesReducer(
}
}
}
}
return {
selected: { ...selected, ...newState },
@ -441,11 +448,8 @@ function useSelectedLines(props, editorRef) {
return React.useCallback(function onGutterClick(editor, lineNumber, gutter, e) {
const numLines = editor.display.view.length
if (e.shiftKey) {
dispatch({ type: 'GROUP', lineNumber, numLines })
} else {
dispatch({ type: 'LINE', lineNumber, numLines })
}
const type = e.shiftKey ? 'GROUP' : 'LINE'
dispatch({ type, lineNumber, numLines })
}, [])
}

Loading…
Cancel
Save