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 = {} 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++) { for (let i = Math.min(prevLine, lineNumber); i < Math.max(prevLine, lineNumber) + 1; i++) {
newState[i] = selected[prevLine] newState[i] = selected[prevLine]
} }
} }
if (type === 'MULTILINE') { break
}
case '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
} }
} else { break
}
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) {
@ -408,6 +414,7 @@ function selectedLinesReducer(
} }
} }
} }
}
return { return {
selected: { ...selected, ...newState }, selected: { ...selected, ...newState },
@ -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