History travel hotkeys

This commit is contained in:
Val Erastov 2019-02-20 17:39:15 -08:00
parent bfe41aa5d2
commit 32174e1541
6 changed files with 58 additions and 5 deletions

View file

@ -142,5 +142,23 @@ export default [
ctx.services.viewer.requestRender();
}
},
{
id: 'StandardView3Way',
invoke: ctx => {
ctx.services.viewer.lookAt(ORIGIN, DIR_3_WAY_VIEW, AXIS.Y, ctx.services.viewer.sceneSetup.camera.position.length());
ctx.services.viewer.requestRender();
}
},
{
id: 'HistoryBackward',
invoke: ctx => ctx.services.craft.historyTravel.backward({
noWizardFocus: true
})
},
{
id: 'HistoryForward',
invoke: ctx => ctx.services.craft.historyTravel.forward({
noWizardFocus: true
})
},
]

View file

@ -79,7 +79,8 @@ export function activate({streams, services}) {
}
services.craft = {
modify, modifyInHistoryAndStep, reset, runRequest
modify, modifyInHistoryAndStep, reset, runRequest,
historyTravel: historyTravel(streams.craft.modifications)
};
streams.craft.modifications.pairwise().attach(([prev, curr]) => {
@ -129,3 +130,30 @@ function isAdditiveChange({history:oldHistory, pointer:oldPointer}, {history, po
}
return true;
}
function historyTravel(modifications$) {
return {
setPointer: function(pointer, hints) {
let mod = modifications$.value;
if (pointer >= mod.history.length || pointer < -1) {
return;
}
modifications$.update(({history}) => ({history, pointer, hints}));
},
begin: function(hints) {
this.setPointer(-1, hints);
},
end: function(hints) {
this.setPointer(modifications$.value.history.length - 1, hints);
},
forward: function(hints) {
this.setPointer(modifications$.value.pointer + 1, hints);
},
backward: function (hints) {
this.setPointer(modifications$.value.pointer - 1, hints);
},
}
}

View file

@ -90,6 +90,9 @@ export default class Wizard extends React.Component {
};
focusFirstInput = el => {
if (this.props.noFocus) {
return;
}
let toFocus = el.querySelector('input, select');
if (!toFocus) {
toFocus = el;

View file

@ -11,6 +11,7 @@ function WizardManager({wizardContext, type, cancel, cancelHistoryEdit, applyWor
}
return <Wizard key={wizardContext.ID}
context={wizardContext}
noFocus={wizardContext.noWizardFocus}
onCancel={wizardContext.changingHistory ? cancelHistoryEdit : cancel}
onOK={applyWorkingRequest} />
}

View file

@ -28,12 +28,13 @@ export function activate(ctx) {
}
});
function gotoEditHistoryModeIfNeeded({pointer, history}) {
function gotoEditHistoryModeIfNeeded({pointer, history, hints}) {
if (pointer !== history.length - 1) {
let {type, params} = history[pointer + 1];
streams.wizard.effectiveOperation.value = {
type,
params,
noWizardFocus: hints && hints.noWizardFocus,
changingHistory: true
};
} else {
@ -56,7 +57,7 @@ export function activate(ctx) {
let operation = ctx.services.operation.get(opRequest.type);
let params;
let changingHistory = opRequest.changingHistory;
let {changingHistory, noWizardFocus} = opRequest;
if (changingHistory) {
params = clone(opRequest.params)
} else {
@ -98,7 +99,7 @@ export function activate(ctx) {
const disposerList = createFunctionList();
wizCtx = {
workingRequest$, materializedWorkingRequest$, state$, updateParams, updateParam, updateState,
operation, changingHistory,
operation, changingHistory, noWizardFocus,
addDisposer: disposerList.add,
dispose: disposerList.call,
ID: ++REQUEST_COUNTER,

View file

@ -16,6 +16,8 @@ export default {
'StandardViewTop': '5',
'StandardViewBottom': '6',
'StandardView3Way': '7',
'HistoryBackward': ',',
'HistoryForward': '.',
'menu.craft': 'shift+c',
'menu.primitives': 'shift+a',
'menu.main': 'space',