Skip to content

Commit

Permalink
Add new commands and they relative keymaps for easy navigate through …
Browse files Browse the repository at this point in the history
…the structure:

* `core:component-prev` (w)
* `core:component-next` (s)
* `core:component-enter` (d)
* `core:component-exit` (a)
  • Loading branch information
artf committed Jun 5, 2018
1 parent 4a7264b commit f4f7343
Show file tree
Hide file tree
Showing 7 changed files with 87 additions and 3 deletions.
12 changes: 12 additions & 0 deletions src/commands/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,18 @@ module.exports = () => {
defaultCommands['core:redo'] = e => e.UndoManager.redo();
defaultCommands['core:copy'] = require('./view/CopyComponent').run;
defaultCommands['core:paste'] = require('./view/PasteComponent').run;
defaultCommands[
'core:component-next'
] = require('./view/ComponentNext').run;
defaultCommands[
'core:component-prev'
] = require('./view/ComponentPrev').run;
defaultCommands[
'core:component-enter'
] = require('./view/ComponentEnter').run;
defaultCommands[
'core:component-exit'
] = require('./view/ComponentExit').run;
defaultCommands['core:canvas-clear'] = e => {
e.DomComponents.clear();
e.CssComposer.clear();
Expand Down
13 changes: 13 additions & 0 deletions src/commands/view/ComponentEnter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
module.exports = {
run(ed) {
const toSelect = [];

ed.getSelectedAll().forEach(component => {
const coll = component.components();
const next = coll && coll.at(0);
next && toSelect.push(next);
});

toSelect.length && ed.select(toSelect);
}
};
12 changes: 12 additions & 0 deletions src/commands/view/ComponentExit.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
module.exports = {
run(ed) {
const toSelect = [];

ed.getSelectedAll().forEach(component => {
const next = component.parent();
next && toSelect.push(next);
});

toSelect.length && ed.select(toSelect);
}
};
14 changes: 14 additions & 0 deletions src/commands/view/ComponentNext.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
module.exports = {
run(ed) {
const toSelect = [];

ed.getSelectedAll().forEach(component => {
const coll = component.collection;
const at = coll.indexOf(component);
const next = coll.at(at + 1);
toSelect.push(next || component);
});

toSelect.length && ed.select(toSelect);
}
};
14 changes: 14 additions & 0 deletions src/commands/view/ComponentPrev.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
module.exports = {
run(ed) {
const toSelect = [];

ed.getSelectedAll().forEach(component => {
const coll = component.collection;
const at = coll.indexOf(component);
const next = coll.at(at - 1);
toSelect.push(next && at - 1 >= 0 ? next : component);
});

toSelect.length && ed.select(toSelect);
}
};
9 changes: 6 additions & 3 deletions src/dom_components/model/Component.js
Original file line number Diff line number Diff line change
Expand Up @@ -460,10 +460,10 @@ const Component = Backbone.Model.extend(Styleable).extend(
* @param {Object} [opts={}] Options, same as in `model.add()`(from backbone)
* @return {Array} Array of appended components
* @example
* someModel.get('components').lenght // -> 0
* someModel.get('components').length // -> 0
* const videoComponent = someModel.append('<video></video><div></div>')[0];
* // This will add 2 components (`video` and `div`) to your `someModel`
* someModel.get('components').lenght // -> 2
* someModel.get('components').length // -> 2
* // You can pass components directly
* otherModel.append(otherModel2);
* otherModel.append([otherModel3, otherModel4]);
Expand Down Expand Up @@ -652,7 +652,10 @@ const Component = Backbone.Model.extend(Styleable).extend(
attr.style = style;
}

return new this.constructor(attr, opts);
return new this.constructor(
attr,
opts
);
},

/**
Expand Down
16 changes: 16 additions & 0 deletions src/keymaps/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,22 @@ module.exports = () => {
'core:paste': {
keys: '⌘+v, ctrl+v',
handler: 'core:paste'
},
'core:component-next': {
keys: 's',
handler: 'core:component-next'
},
'core:component-prev': {
keys: 'w',
handler: 'core:component-prev'
},
'core:component-enter': {
keys: 'd',
handler: 'core:component-enter'
},
'core:component-exit': {
keys: 'a',
handler: 'core:component-exit'
}
}
};
Expand Down

0 comments on commit f4f7343

Please sign in to comment.