diff --git a/js/ui/appDisplay.js b/js/ui/appDisplay.js index 79437e24a..7e9b558e5 100644 --- a/js/ui/appDisplay.js +++ b/js/ui/appDisplay.js @@ -1440,13 +1440,28 @@ var FolderView = class FolderView extends BaseAppView { acceptDrop(source, actor, x, y, time) { let [index, dragLocation] = this.canDropAt(x, y); - let sourceIndex = this._allItems.indexOf(source); let success = index != -1; source.undoScaleAndFade(); - if (success) - this.moveItem(source, index); + if (success) { + // If we're dragging from another folder, remove from the old folder + if (source.view != this && + (source instanceof AppIcon) && + (source.view instanceof FolderView)) { + source.view.removeApp(source.app); + } + + // If the new app icon is not in this folder yet, add it; otherwise, + // just move the icon to the new position + let folderApps = this._folder.get_strv('apps'); + if (!folderApps.includes(source.id)) { + folderApps.splice(index, 0, source.id); + this._folder.set_strv('apps', folderApps); + } else { + this.moveItem(source, index); + } + } this.removeNudges(); return success;