Skip to content

Commit

Permalink
Merge pull request #193 from bobnik/feature/insert-layer
Browse files Browse the repository at this point in the history
when adding a new layer, insert after current one (vs at end)
  • Loading branch information
jeffeb3 authored Jan 11, 2021
2 parents 2b992d3 + 3e4bf30 commit 0e1ca70
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/features/layers/layersSlice.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,10 @@ const layersSlice = createSlice({
layer.id = uniqueId('layer-')
layer.name = layer.name || state.newLayerName
state.byId[layer.id] = layer
state.allIds.push(layer.id)

const index = state.allIds.findIndex(id => id === state.current) + 1
state.allIds.splice(index, 0, layer.id)

state.current = layer.id
state.selected = layer.id
state.newLayerNameOverride = false
Expand All @@ -46,7 +49,10 @@ const layersSlice = createSlice({
const layer = { ...source, name: state.copyLayerName }
layer.id = uniqueId('layer-')
state.byId[layer.id] = layer
state.allIds.push(layer.id)

const index = state.allIds.findIndex(id => id === state.current) + 1
state.allIds.splice(index, 0, layer.id)

state.current = layer.id
state.selected = layer.id
},
Expand Down
1 change: 1 addition & 0 deletions src/features/layers/layersSlice.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ describe('layers reducer', () => {
}
},
allIds: ['layer-1'],
current: 'layer-1',
copyLayerName: 'foo'
},
copyLayer('layer-1'))
Expand Down

0 comments on commit 0e1ca70

Please sign in to comment.