Upon opening a new Document, there is always a valid tool selected

This commit is contained in:
Igor Zinken
2021-01-10 20:12:04 +01:00
parent 1980c992ef
commit a92c387ac3
3 changed files with 10 additions and 1 deletions

View File

@@ -131,6 +131,9 @@ export default {
flushBitmapCache();
layerPool.clear();
this.calcIdealDimensions();
this.$nextTick(() => {
this.setActiveTool({ tool: this.activeTool || ToolTypes.MOVE, layer: this.activeLayer });
});
}
}
},
@@ -204,6 +207,7 @@ export default {
...mapMutations([
"setZCanvasBaseDimensions",
"setPanMode",
"setActiveTool",
]),
...mapActions([
"requestDocumentClose",

View File

@@ -61,7 +61,8 @@ export default {
addNewDocument( state, nameOrDocument ) {
const document = typeof nameOrDocument === "object" ? nameOrDocument : DocumentFactory.create({ name: nameOrDocument });
state.documents.push( document );
state.activeIndex = state.documents.length - 1;
state.activeIndex = state.documents.length - 1;
state.activeLayerIndex = document.layers.length - 1;
},
closeActiveDocument( state ) {
const document = state.documents[ state.activeIndex ];

View File

@@ -151,10 +151,14 @@ describe( "Vuex document module", () => {
it( "should be able to add a new Document to the list", () => {
const state = {
documents: [ { name: "foo" } ],
activeIndex: 0,
activeLayerIndex: 2,
};
mutations.addNewDocument( state, "bar" );
expect( state.documents ).toHaveLength( 2 );
expect( state.documents[ 1 ].name ).toEqual( "bar" );
expect( state.activeIndex ).toEqual( 1 );
expect( state.activeLayerIndex ).toEqual( 0 );
});
it( "should be able to close the active Document", () => {