pass index to split/join to keep position

This commit is contained in:
j 2015-10-04 16:09:51 +01:00
parent b20a655fa8
commit 9eae0a0762
2 changed files with 30 additions and 10 deletions

View file

@ -215,8 +215,9 @@ pandora.ui.editPanel = function(isEmbed) {
});
},
join: function(data) {
var clips = [serializeClips(data.ids), serializeClips(data.join)];
pandora.doHistory('join', clips, ui.edit, function(result) {
var clips = [serializeClips(data.ids), serializeClips(data.join)],
index = pandora.$ui.editPanel.getPasteIndex() - 1;
pandora.doHistory('join', clips, ui.edit, index, function(result) {
edit.clips = edit.clips.filter(function(clip) {
return !Ox.contains(data.ids, clip.id);
}).concat(result.data.clips);
@ -314,11 +315,25 @@ pandora.ui.editPanel = function(isEmbed) {
sortClips(updateClips);
},
split: function(data) {
var clips = [serializeClips(data.ids), serializeClips(data.split)];
pandora.doHistory('split', clips, ui.edit, function(result) {
var clips = [serializeClips(data.ids), serializeClips(data.split)],
index = pandora.$ui.editPanel.getPasteIndex() - 1;
pandora.doHistory('split', clips, ui.edit, index, function(result) {
updateClips(edit.clips.filter(function(clip) {
return !Ox.contains(data.ids, clip.id);
}).map(function(clip) {
if (clip.index >= result.data.clips[0].index) {
clip.index += result.data.clips.length
}
return clip;
}).concat(result.data.clips));
//fixme: what resets the position here?
var position = that.options('position');
that.options({
selected: result.data.clips.map(function(clip) { return clip.id}),
});
setTimeout(function() {
that.options('position', position);
}, 500);
});
},
subtitles: function(data) {

View file

@ -353,9 +353,10 @@ pandora.createLinks = function($element) {
(function() {
pandora.doHistory = function(action, items, targets, callback) {
pandora.doHistory = function(action, items, targets, index, callback) {
items = Ox.makeArray(items);
targets = Ox.makeArray(targets);
callback = Ox.last(arguments);
if (action == 'copy' || action == 'paste') {
addItems(items, targets[0], addToHistory);
} else if (action == 'cut' || action == 'delete') {
@ -364,7 +365,7 @@ pandora.createLinks = function($element) {
editItem(items[1], addToHistory);
} else if (action == 'join' || action == 'split') {
removeItems(items[0], targets[0], function() {
addItems(items[1], targets[0], addToHistory);
addItems(items[1], targets[0], index, addToHistory);
});
} else if (action == 'move') {
removeItems(items, targets[0], function() {
@ -456,8 +457,14 @@ pandora.createLinks = function($element) {
}
};
function addItems(items, target, callback) {
function addItems(items, target, index, callback) {
var clips, type = getType(items);
if (Ox.isUndefined(callback)) {
callback = index;
index = pandora.$ui.editPanel
? pandora.$ui.editPanel.getPasteIndex()
: void 0;
}
if (type == 'item') {
pandora.api.find({
query: {
@ -485,9 +492,7 @@ pandora.createLinks = function($element) {
pandora.api.addClips({
clips: pandora.getClipData(items),
edit: target,
index: pandora.$ui.editPanel
? pandora.$ui.editPanel.getPasteIndex()
: void 0
index: index
}, function(result) {
// adding clips creates new ids, so mutate items in history
items.splice.apply(items, [0, items.length].concat(