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,23 +388,30 @@ function selectedLinesReducer(
) {
const newState = {}
if (type === 'GROUP' && prevLine) {
for (let i = Math.min(prevLine, lineNumber); i < Math.max(prevLine, lineNumber) + 1; i++) {
newState[i] = selected[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]
}
}
break
}
}
if (type === 'MULTILINE') {
for (let i = 0; i < selectedLines.length; i++) {
newState[selectedLines[i] - 1] = true
case 'MULTILINE': {
for (let i = 0; i < selectedLines.length; i++) {
newState[selectedLines[i] - 1] = true
}
break
}
} else {
for (let i = 0; i < numLines; i++) {
if (i != lineNumber) {
if (prevLine == null) {
newState[i] = false
default: {
for (let i = 0; i < numLines; i++) {
if (i != lineNumber) {
if (prevLine == null) {
newState[i] = false
}
} else {
newState[lineNumber] = selected[lineNumber] === true ? false : true
}
} else {
newState[lineNumber] = selected[lineNumber] === true ? false : true
}
}
}
@ -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