Repository navigation
fix(canvas): let region auto-sort use any grid shape and clear place that fits - #187
Merged
Merged
Conversation
A region sort refused whenever the near-square grid did not fit the region or anything covered the region's center, even when the windows fit in another column count or beside the obstacle. Region sorting now keeps the near-square grid when it fits and otherwise tries the other column counts, nearest to the usual one first (fewer columns on a tie). The block goes to the region's center when that is clear, else to the clear place nearest the center (topmost, then leftmost). Candidate places are the region edges, the center and the obstacles' edges, which covers every free position. The task tree keeps its shape. Layouts that sorted before are unchanged.
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Follows up on Auto-sort (#163) and the 1.8.5 known limitation about conservative region sorting.
The 1.8.5 notes list region sorting as conservative: it can reject layouts that fit. This PR fixes the two causes I could reproduce. Layouts that sorted before land exactly where they did.
Failing scenarios (all on 1.8.5, snapping on, 700 x 430 windows)
2200 x 560at (3000, 0), so the content area is2160 x 480(20px edges, 60px title). Three windows, Grid. Sorting always builds the near-square 2 x 2 grid (880tall), which does not fit, so the sort is refused. One row (3 x 700 + 2 x 20 = 2140wide,430tall) fits: x = 3030 / 3750 / 4470, y = 90.The same happens with groups. By status, one
needs_approvaland threeworkingwindows in a1500 x 1500region (content1460 x 1420). The usual shape (1 column + 2 columns) is2160wide and is refused. One column per group is1440 x 1330and fits.3000 x 2400, two windows (block1420 x 430), a400 x 300note in the middle at (4300, 1050). The centered block covers the note, so the sort is refused, though the block fits 20px below the note at y = 1370 (or above it at y = 600). The same applies when a partly overlapping region covers the center. The code even had a comment about this: "reject an obstructed centered block; add bounded placement search only if requested".Root cause
centerInRegiontook the single arrangement fromarrangeCanvasAutoSort, which is always the near-square grid (ceil(sqrt(n))columns, per group for status/project). It tried one position, the rounded center, and returnednullif that position overflowed or touched any obstacle.Rule after the fix
For a region sort, in this order:
Candidate places are the region edges, the center, and each obstacle's edges plus the gap. Any free position can slide up and left until an edge or obstacle stops it, so this set contains a free place whenever one exists. The search is O(shapes x candidates^2 x obstacles), and only obstacles that overlap the region count.
Same input gives the same output. List order still does not matter, and sorting twice is a no-op. The canvas (non-region) sort is untouched:
arrangeCanvasAutoSortstill always uses the near-square grid and the right/down shift.What changes for existing layouts
docs/UI_CONTRACT(en/ru/zh-CN). No menu or i18n changes.Validation
tests/canvas-auto-sort.test.mjs, new or updated:canvasAutoSort.tsthe first three tests fail (3 fail / 28 pass). With this change, 32 / 32 pass.npm run build,npm run audit:secretsandtests/renderer-bundle-splitting.test.mjspass. The eager renderer entry is 1,198,508 bytes, unchanged (auto-sort is loaded on demand).node --test tests/*.test.mjs): 2654 tests, 2648 pass, 0 fail, 6 skipped.