appDisplay: Fix multi-page dragging behavior in folders

Folders reflow across pages because they don't set
allow_incomplete_pages to true. This means we want the nudging of items
to happen slightly differently when dragging an item across pages:

- When dragging from lower page index to a higher one, always reflow
towards the start of the grid (because there's now an empty slot on the
old page and items on the new page will force-reflow towards that)
- When dragging from a higher page index to a lower one, we can reflow to
the end as we usually do

To archive this, factor out the selection of "reflow direction" into a
separate variable that always defaults to "end" (because empty space is
always at the end of the grid). Set it to "start" when the item created an
empty slot on the current page or (and this is new:) on a previous page in
the folder case.

Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/2348>
This commit is contained in:
Jonas Dreßler 2022-06-24 15:17:51 +02:00 committed by Marge Bot
parent 4cf372b890
commit 245137ff35

View File

@ -1177,6 +1177,16 @@ var BaseAppView = GObject.registerClass({
const [sourcePage, sourcePosition] = this._grid.getItemPosition(source); const [sourcePage, sourcePosition] = this._grid.getItemPosition(source);
let [targetPage, targetPosition, dragLocation] = this._grid.getDropTarget(x, y); let [targetPage, targetPosition, dragLocation] = this._grid.getDropTarget(x, y);
let reflowDirection = Clutter.ActorAlign.END;
if (sourcePosition === targetPosition)
reflowDirection = -1;
if (sourcePage === targetPage && sourcePosition < targetPosition)
reflowDirection = Clutter.ActorAlign.START;
if (!this._grid.layout_manager.allow_incomplete_pages && sourcePage < targetPage)
reflowDirection = Clutter.ActorAlign.START;
// In case we're hovering over the edge of an item but the // In case we're hovering over the edge of an item but the
// reflow will happen in the opposite direction (the drag // reflow will happen in the opposite direction (the drag
// can't "naturally push the item away"), we instead set the // can't "naturally push the item away"), we instead set the
@ -1187,8 +1197,7 @@ var BaseAppView = GObject.registerClass({
// or last column though, in that case there is no adjacent // or last column though, in that case there is no adjacent
// icon we could push away. // icon we could push away.
if (dragLocation === IconGrid.DragLocation.START_EDGE && if (dragLocation === IconGrid.DragLocation.START_EDGE &&
targetPosition > sourcePosition && reflowDirection === Clutter.ActorAlign.START) {
targetPage === sourcePage) {
const nColumns = this._grid.layout_manager.columns_per_page; const nColumns = this._grid.layout_manager.columns_per_page;
const targetColumn = targetPosition % nColumns; const targetColumn = targetPosition % nColumns;
@ -1197,8 +1206,7 @@ var BaseAppView = GObject.registerClass({
dragLocation = IconGrid.DragLocation.END_EDGE; dragLocation = IconGrid.DragLocation.END_EDGE;
} }
} else if (dragLocation === IconGrid.DragLocation.END_EDGE && } else if (dragLocation === IconGrid.DragLocation.END_EDGE &&
(targetPosition < sourcePosition || reflowDirection === Clutter.ActorAlign.END) {
targetPage !== sourcePage)) {
const nColumns = this._grid.layout_manager.columns_per_page; const nColumns = this._grid.layout_manager.columns_per_page;
const targetColumn = targetPosition % nColumns; const targetColumn = targetPosition % nColumns;