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 = {} const newState = {}
if (type === 'GROUP' && prevLine) { switch (type) {
for (let i = Math.min(prevLine, lineNumber); i < Math.max(prevLine, lineNumber) + 1; i++) { case 'GROUP': {
newState[i] = selected[prevLine] if (prevLine) {
for (let i = Math.min(prevLine, lineNumber); i < Math.max(prevLine, lineNumber) + 1; i++) {
newState[i] = selected[prevLine]
}
}
break
} }
} case 'MULTILINE': {
if (type === 'MULTILINE') { for (let i = 0; i < selectedLines.length; i++) {
for (let i = 0; i < selectedLines.length; i++) { newState[selectedLines[i] - 1] = true
newState[selectedLines[i] - 1] = true }
break
} }
} else { default: {
for (let i = 0; i < numLines; i++) { for (let i = 0; i < numLines; i++) {
if (i != lineNumber) { if (i != lineNumber) {
if (prevLine == null) { if (prevLine == null) {
newState[i] = false 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) { return React.useCallback(function onGutterClick(editor, lineNumber, gutter, e) {
const numLines = editor.display.view.length const numLines = editor.display.view.length
if (e.shiftKey) { const type = e.shiftKey ? 'GROUP' : 'LINE'
dispatch({ type: 'GROUP', lineNumber, numLines }) dispatch({ type, lineNumber, numLines })
} else {
dispatch({ type: 'LINE', lineNumber, numLines })
}
}, []) }, [])
} }

Loading…
Cancel
Save