diff --git a/src/reducer/d2/toolReducer.js b/src/reducer/d2/toolReducer.js index 3839b3b..c7c8a6d 100644 --- a/src/reducer/d2/toolReducer.js +++ b/src/reducer/d2/toolReducer.js @@ -8,7 +8,7 @@ import starReducer from './tools/shapes/starReducer.js'; import triangleReducer from './tools/shapes/triangleReducer.js'; import bucketReducer from './tools/bucketReducer.js'; import penReducer from './tools/penReducer.js'; -import textReducer from './tools/textReducer.js'; +import textReducer, { removeEmptyText } from './tools/textReducer.js'; import photoGuideReducer from './tools/photoGuideReducer.js'; import { transformReducer } from './tools/transformReducer.js'; import eraserReducer from './tools/eraserReducer.js'; @@ -44,6 +44,7 @@ export default function toolReducer(state, action) { // change 2D tool after explicit tool change action or on some selection if (action.type === actions.D2_CHANGE_TOOL) { state = updateTool(state, action.tool); + state = removeEmptyText(state); } if (action.category === actions.CAT_SELECTION) { state = updateTool(state, tools.TRANSFORM); diff --git a/src/reducer/d2/tools/textReducer.js b/src/reducer/d2/tools/textReducer.js index b7cb8bb..077c3ac 100644 --- a/src/reducer/d2/tools/textReducer.js +++ b/src/reducer/d2/tools/textReducer.js @@ -8,10 +8,11 @@ const debug = createDebug('d3d:reducer:text'); export default function textReducer(state, action) { if (action.log !== false) debug(action.type); - const activeShape = state.d2.activeShape; switch (action.type) { case actions.D2_TEXT_INIT: { + state = removeEmptyText(state); + const { position, textId, screenMatrixZoom } = action; const screenPosition = (position && screenMatrixZoom) ? position.applyMatrix(screenMatrixZoom.inverseMatrix()) : @@ -29,6 +30,7 @@ export default function textReducer(state, action) { } case actions.D2_TEXT_INPUT_CHANGE: { const { text, family, style, weight, fill } = action; + const { activeShape } = state.d2; return update(state, { objectsById: { [activeShape]: { @@ -43,16 +45,16 @@ export default function textReducer(state, action) { } }); } - case actions.D2_TEXT_ADD: { - if (activeShape && state.objectsById[activeShape].text.text.length === 0) { - return setActive2D(removeObject(state, activeShape), null); - } else { - return setActive2D(state, null); - } - break; - } default: return state; } +} + +export function removeEmptyText(state) { + const { activeShape } = state.d2; + + if (activeShape && state.objectsById[activeShape].text.text === '') { + return setActive2D(removeObject(state, activeShape), null); + } return state; } diff --git a/src/reducer/index.js b/src/reducer/index.js index 9fe70a2..141a060 100644 --- a/src/reducer/index.js +++ b/src/reducer/index.js @@ -142,7 +142,6 @@ function sketcherReducer(state = initialState, action) { case actions.MULTITOUCH_TRANSFORM_END: case actions.D2_TEXT_INIT: case actions.D2_TEXT_INPUT_CHANGE: - case actions.D2_TEXT_ADD: case actions.MOVE_SELECTION: return d2ToolReducer(state, action); @@ -188,11 +187,11 @@ function sketcherReducer(state = initialState, action) { return d3ToolReducer(state, action); case actions.D2_CHANGE_TOOL: - state = setActive2D(state, null); state = selectionReducer(state, action); state = d2ToolReducer(state, action); // switch and initialize tool state = updateMenus(state, action); state = contextReducer(state, action); + state = setActive2D(state, null); return state; case actions.D3_CHANGE_TOOL: diff --git a/src/utils/undoFilter.js b/src/utils/undoFilter.js index 136b56f..0a348f5 100644 --- a/src/utils/undoFilter.js +++ b/src/utils/undoFilter.js @@ -14,7 +14,6 @@ const INCLUDE = [ actions.DESELECT_ALL, actions.STAMP, actions.SELECT, - actions.D2_TEXT_ADD, actions.CLEAR, actions.TWIST_END, actions.SCULPT_END,