Skip to content

Commit ed95f12

Browse files
- finished fixing the undo/redo behavior for viewer settings
1 parent 0104ed4 commit ed95f12

File tree

4 files changed

+47
-24
lines changed

4 files changed

+47
-24
lines changed

js/components/preview/viewerControls/settingsControls.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import { setNglViewParams } from '../../../reducers/ngl/actions';
77
import { setNglBckGrndColor, setNglClipNear, setNglClipFar, setNglClipDist, setNglFogNear, setNglFogFar } from '../../../reducers/ngl/dispatchActions';
88
import { NglContext } from '../../nglView/nglProvider';
99
import { VIEWS } from '../../../constants/constants';
10-
import { throttle, debounce } from 'lodash';
1110

1211

1312
const useStyles = makeStyles(theme => ({
@@ -75,7 +74,7 @@ export const SettingControls = memo(({ open, onClose }) => {
7574
step={1}
7675
min={0}
7776
max={100}
78-
onChange={debounce((e, value) => dispatch(setNglClipNear(value, viewParams[NGL_PARAMS.clipNear], majorView)), 50)}
77+
onChange={(e, value) => dispatch(setNglClipNear(value, viewParams[NGL_PARAMS.clipNear], majorView))}
7978
/>
8079
</Grid>
8180
</Grid>

js/reducers/tracking/dispatchActions.js

+27-21
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ import {
125125
setInspirationMoleculeDataList
126126
} from '../../components/datasets/redux/actions';
127127
import { selectVectorAndResetCompounds } from '../../../js/reducers/selection/dispatchActions';
128+
import { ActionCreators as UndoActionCreators } from '../../undoredo/actions'
128129

129130
export const addCurrentActionsListToSnapshot = (snapshot, project, nglViewList) => async (dispatch, getState) => {
130131
let projectID = project && project.projectID;
@@ -2231,7 +2232,12 @@ export const appendAndSendTrackingActions = trackAction => async (dispatch, getS
22312232
if (isUndoRedoAction === false) {
22322233
const undoRedoActionList = state.trackingReducers.undo_redo_actions_list;
22332234
const mergedUndoRedoActionList = mergeActions(trackAction, [...undoRedoActionList]);
2234-
dispatch(setUndoRedoActionList(mergedUndoRedoActionList.list));
2235+
if (mergedActionList.merged) {
2236+
dispatch(setUndoRedoActionList(mergedUndoRedoActionList.list));
2237+
dispatch(UndoActionCreators.removeLastPast());
2238+
} else {
2239+
dispatch(setUndoRedoActionList(mergedUndoRedoActionList.list));
2240+
}
22352241
}
22362242
}
22372243
dispatch(setIsActionTracking(false));
@@ -2240,26 +2246,26 @@ export const appendAndSendTrackingActions = trackAction => async (dispatch, getS
22402246

22412247
export const mergeActions = (trackAction, list) => {
22422248
let merged = false;
2243-
// if (needsToBeMerged(trackAction)) {
2244-
// let newList = [];
2245-
// if (list.length > 0) {
2246-
// const lastEntry = list[list.length - 1];
2247-
// if (isSameTypeOfAction(trackAction, lastEntry) && isActionWithinTimeLimit(lastEntry, trackAction)) {
2248-
// trackAction.oldSetting = lastEntry.oldSetting;
2249-
// trackAction.text = trackAction.getText();
2250-
// newList = [...list.slice(0, list.length - 1), trackAction];
2251-
// merged = true;
2252-
// } else {
2253-
// newList = [...list, trackAction];
2254-
// }
2255-
// } else {
2256-
// newList.push(trackAction);
2257-
// }
2258-
// return {merged: merged, list: newList};
2259-
// } else {
2260-
// return {merged: merged, list: [...list, trackAction]};
2261-
// }
2262-
return {merged: merged, list: [...list, trackAction]};
2249+
if (needsToBeMerged(trackAction)) {
2250+
let newList = [];
2251+
if (list.length > 0) {
2252+
const lastEntry = list[list.length - 1];
2253+
if (isSameTypeOfAction(trackAction, lastEntry) && isActionWithinTimeLimit(lastEntry, trackAction)) {
2254+
trackAction.oldSetting = lastEntry.oldSetting;
2255+
trackAction.text = trackAction.getText();
2256+
newList = [...list.slice(0, list.length - 1), trackAction];
2257+
merged = true;
2258+
} else {
2259+
newList = [...list, trackAction];
2260+
}
2261+
} else {
2262+
newList.push(trackAction);
2263+
}
2264+
return {merged: merged, list: newList};
2265+
} else {
2266+
return {merged: merged, list: [...list, trackAction]};
2267+
}
2268+
// return {merged: merged, list: [...list, trackAction]};
22632269
};
22642270

22652271
const needsToBeMerged = trackAction => {

js/undoredo/actions.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ export const ActionTypes = {
44
JUMP_TO_FUTURE: '@@redux-undo/JUMP_TO_FUTURE',
55
JUMP_TO_PAST: '@@redux-undo/JUMP_TO_PAST',
66
JUMP: '@@redux-undo/JUMP',
7-
CLEAR_HISTORY: '@@redux-undo/CLEAR_HISTORY'
7+
CLEAR_HISTORY: '@@redux-undo/CLEAR_HISTORY',
8+
REMOVE_LAST_PAST: '@@redux-undo/REMOVE_LAST_PAST'
89
}
910

1011
export const ActionCreators = {
@@ -25,5 +26,8 @@ export const ActionCreators = {
2526
},
2627
clearHistory () {
2728
return { type: ActionTypes.CLEAR_HISTORY }
29+
},
30+
removeLastPast() {
31+
return {type: ActionTypes.REMOVE_LAST_PAST}
2832
}
2933
}

js/undoredo/reducer.js

+14
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,15 @@ function createHistory (state, ignoreInitialState) {
1414
return history
1515
}
1616

17+
function removeLastPast(history) {
18+
const { past, present, future } = history;
19+
20+
const newPast = [...past];
21+
newPast.pop();
22+
23+
return newHistory(newPast, present, future)
24+
}
25+
1726
// insert: insert `state` into history, which means adding the current state
1827
// into `past`, setting the new `state` as `present` and erasing
1928
// the `future`.
@@ -87,6 +96,7 @@ export function undoable (reducer, rawConfig = {}) {
8796
jumpToPastType: ActionTypes.JUMP_TO_PAST,
8897
jumpToFutureType: ActionTypes.JUMP_TO_FUTURE,
8998
jumpType: ActionTypes.JUMP,
99+
removeLastPast: ActionTypes.REMOVE_LAST_PAST,
90100
neverSkipReducer: false,
91101
ignoreInitialState: false,
92102
syncFilter: false,
@@ -185,6 +195,10 @@ export function undoable (reducer, rawConfig = {}) {
185195
debug.log(`perform jump to ${action.index}`)
186196
debug.end(res)
187197
return skipReducer(res, action, ...slices)
198+
199+
case config.removeLastPast:
200+
res = removeLastPast(history);
201+
return skipReducer(res, action, ...slices);
188202

189203
case actionTypeAmongClearHistoryType(action.type, config.clearHistoryType):
190204
res = createHistory(history.present, config.ignoreInitialState)

0 commit comments

Comments
 (0)