@@ -33,6 +33,23 @@ ContainmentItem {
3333 implicitWidth: useColumnLayout ? Panel .rootObject .dockSize : (Math .min (remainingSpacesForTaskManager, appContainer .implicitWidth ) + forceRelayoutWorkaround)
3434 implicitHeight: useColumnLayout ? (Math .min (remainingSpacesForTaskManager, appContainer .implicitHeight ) + forceRelayoutWorkaround) : Panel .rootObject .dockSize
3535
36+ // Find target index by position using ListView's built-in indexAt method instead of relying on fixed width
37+ function findTargetIndexByPosition (dragPosition ) {
38+ if (! appContainer || ! appContainer .model || appContainer .model .count === 0 ) {
39+ return 0
40+ }
41+
42+ // Use ListView's built-in indexAt method
43+ let targetIndex = appContainer .indexAt (dragPosition .x , dragPosition .y )
44+
45+ // If no valid index found, return end position
46+ if (targetIndex === - 1 ) {
47+ return appContainer .model .count
48+ }
49+
50+ return targetIndex
51+ }
52+
3653 OverflowContainer {
3754 id: appContainer
3855 anchors .fill : parent
@@ -103,7 +120,8 @@ ContainmentItem {
103120 implicitHeight: useColumnLayout ? visualModel .cellWidth : taskmanager .implicitHeight
104121
105122 onEntered : function (drag ) {
106- visualModel .items .move ((drag .source as AppItem).visualIndex , app .visualIndex )
123+ // TODO: this is actually unused, should change the delegateRoot type from DropArea to Item later.
124+ visualModel .items .move (drag .source .DelegateModel .itemsIndex , delegateRoot .DelegateModel .itemsIndex )
107125 }
108126
109127 property int visualIndex: DelegateModel .itemsIndex
@@ -156,21 +174,19 @@ ContainmentItem {
156174
157175 onPositionChanged : function (drag ) {
158176 if (launcherDndDesktopId === " " ) return
159- let curX = taskmanager .useColumnLayout ? drag .y : drag .x
160- let cellWidth = visualModel .cellWidth
161- let curCell = curX / cellWidth
177+ let dragPosition = Qt .point (drag .x , drag .y )
178+ let targetIndex = taskmanager .findTargetIndexByPosition (dragPosition)
162179 let appId = taskmanager .Applet .desktopIdToAppId (launcherDndDesktopId)
163- taskmanager .Applet .dataModel .moveTo (appId, curCell )
180+ taskmanager .Applet .dataModel .moveTo (appId, targetIndex )
164181 }
165182
166183 onDropped : function (drop ) {
167184 Panel .contextDragging = false
168185 if (launcherDndDesktopId === " " ) return
169- let curX = taskmanager .useColumnLayout ? drop .y : drop .x
170- let cellWidth = visualModel .cellWidth
171- let curCell = curX / cellWidth
186+ let dropPosition = Qt .point (drop .x , drop .y )
187+ let targetIndex = taskmanager .findTargetIndexByPosition (dropPosition)
172188 let appId = taskmanager .Applet .desktopIdToAppId (launcherDndDesktopId)
173- taskmanager .Applet .dataModel .moveTo (appId, curCell )
189+ taskmanager .Applet .dataModel .moveTo (appId, targetIndex )
174190 resetDndState ()
175191 }
176192
0 commit comments