use SHIFT meta when clicking up down layer to move to top/bottom

This commit is contained in:
Julian Descottes 2017-05-20 17:50:08 +02:00
parent 4a9f7cc74b
commit 9fafa8b7a7
3 changed files with 39 additions and 19 deletions

View File

@ -17,7 +17,7 @@
this.rootEl.addEventListener('click', this.onClick_.bind(this));
this.toggleLayerPreviewEl.addEventListener('click', this.toggleLayerPreview_.bind(this));
this.initCreateLayerButton_();
this.createButtonTooltips_();
this.initToggleLayerPreview_();
this.renderLayerList_();
@ -46,12 +46,24 @@
}
};
ns.LayersListController.prototype.initCreateLayerButton_ = function () {
var tooltip = pskl.utils.TooltipFormatter.format('Create a layer', null, [
ns.LayersListController.prototype.createButtonTooltips_ = function () {
var addTooltip = pskl.utils.TooltipFormatter.format('Create a layer', null, [
{key : 'shift', description : 'Clone current layer'}
]);
var addButton = this.rootEl.querySelector('[data-action="add"]');
addButton.setAttribute('title', tooltip);
addButton.setAttribute('title', addTooltip);
var moveDownTooltip = pskl.utils.TooltipFormatter.format('Move layer down', null, [
{key : 'shift', description : 'Move to the bottom'}
]);
var moveDownButton = this.rootEl.querySelector('[data-action="down"]');
moveDownButton.setAttribute('title', moveDownTooltip);
var moveUpTooltip = pskl.utils.TooltipFormatter.format('Move layer up', null, [
{key : 'shift', description : 'Move to the top'}
]);
var moveUpButton = this.rootEl.querySelector('[data-action="up"]');
moveUpButton.setAttribute('title', moveUpTooltip);
};
ns.LayersListController.prototype.initToggleLayerPreview_ = function () {
@ -157,9 +169,9 @@
ns.LayersListController.prototype.onButtonClick_ = function (button, evt) {
var action = button.getAttribute('data-action');
if (action == 'up') {
this.piskelController.moveLayerUp();
this.piskelController.moveLayerUp(evt.shiftKey);
} else if (action == 'down') {
this.piskelController.moveLayerDown();
this.piskelController.moveLayerDown(evt.shiftKey);
} else if (action == 'add') {
if (evt.shiftKey) {
this.piskelController.duplicateCurrentLayer();

View File

@ -258,15 +258,15 @@
return this.piskel.getLayersByName(name).length > 0;
};
ns.PiskelController.prototype.moveLayerUp = function () {
ns.PiskelController.prototype.moveLayerUp = function (toTop) {
var layer = this.getCurrentLayer();
this.piskel.moveLayerUp(layer);
this.piskel.moveLayerUp(layer, toTop);
this.selectLayer(layer);
};
ns.PiskelController.prototype.moveLayerDown = function () {
ns.PiskelController.prototype.moveLayerDown = function (toBottom) {
var layer = this.getCurrentLayer();
this.piskel.moveLayerDown(layer);
this.piskel.moveLayerDown(layer, toBottom);
this.selectLayer(layer);
};

View File

@ -82,20 +82,28 @@
this.layers.splice(index, 0, layer);
};
ns.Piskel.prototype.moveLayerUp = function (layer) {
ns.Piskel.prototype.moveLayerUp = function (layer, toTop) {
var index = this.layers.indexOf(layer);
if (index > -1 && index < this.layers.length - 1) {
this.layers[index] = this.layers[index + 1];
this.layers[index + 1] = layer;
}
var toIndex = toTop ? this.layers.length - 1 : index + 1;
this.moveLayer_(index, toIndex);
};
ns.Piskel.prototype.moveLayerDown = function (layer) {
ns.Piskel.prototype.moveLayerDown = function (layer, toBottom) {
var index = this.layers.indexOf(layer);
if (index > 0) {
this.layers[index] = this.layers[index - 1];
this.layers[index - 1] = layer;
var toIndex = toBottom ? 0 : index - 1;
this.moveLayer_(index, toIndex);
};
/**
* Move the layer at the provided index to the provided toIndex.
*/
ns.Piskel.prototype.moveLayer_ = function (fromIndex, toIndex) {
if (fromIndex == -1 || toIndex == -1 || fromIndex == toIndex) {
return;
}
toIndex = pskl.utils.Math.minmax(toIndex, 0, this.layers.length - 1);
var layer = this.layers.splice(fromIndex, 1)[0];
this.layers.splice(toIndex, 0, layer);
};
ns.Piskel.prototype.removeLayer = function (layer) {