-
-
Notifications
You must be signed in to change notification settings - Fork 581
Support rearranging layers with hotkeys #271
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
8acfa93
to
8deb530
Compare
Oh, and in general, feel free to add new commits instead of just amending them, everything will be squashed in the end anyway, it just makes it easier for us to keep track of the changes. (even tough I fully empathize with not wanting to write commit messages) |
This is why I force pushed before, I think I messed up the rebase 🤦♂️ |
ca42b4d
to
83c1e64
Compare
Thanks for the merge help @TrueDoctor |
Yeah, that code will change imminently though since I'm adding support for moving multiple layers now anyway |
83e932c
to
af426f6
Compare
Looks good, thanks for making the changes. Is this ready for a final review or do you need to handle more edge cases or add features or tests or something? Let me know if you need any help completing it. |
I hadn't considered testing, that's not a bad idea though, I've added a few. Let me know if they're sufficient. I think it's ready for a final review now, it's working as I'd expect it to. |
|
core/document/src/layers/folder.rs
Outdated
let target_pos = self.layer_ids.iter().position(|x| *x == target_id).ok_or(DocumentError::LayerNotFound)?; | ||
|
||
let mut last_pos = source_pos; | ||
for layer_id in &source_ids[1..source_ids.len()] { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you do something like source_ids.take(source_ids.len())
? might be a bit more ideomatic
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That isn't equivalent code, the slice excludes the first element intentionally. If there's a better way of doing that I'm all ears.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suppose you could call skip(1)
but at that point it might get longer than your current code.
Oh, wait, you are indexing source ids with source ids, in that case it should either be source_ids.skip(1)
or &source_ids[1..]
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The nice thing about the skip is, that it does not panic if the list is empty but that depends on what you want the code to do
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah I see. The caller definitely shouldn't be passing in an empty list (moving a list of zero layers makes no sense).
I think &source_ids[1..]
is probably the best solution here.
Yep, that's totally fair, I agree it wasn't the clearest. |
Fix formatting
5e8a693
to
1462e23
Compare
* Support moving single layers * Fix "Move layer to top/bottom" keybinds * Rename things named "move" to "reorder" Fix formatting * Combine sorted layer helper functions * Use integer consts for moving layers to front/back * Fix merge mistake * Fix some clippy lints * Fix panic * Remove "get" prefix from functions * Bring layer menu items out to sub-menu * Support moving multiple layers at a time * Add comment explaining odd keybinding * Add reordering tests * Add negative test * Add new error type * Add layer position helper, clean up tests * Make position helper return Result * Clean up slice iteration * Simplify source_layer_ids computation Co-authored-by: Dennis Kobert <[email protected]>
* Support moving single layers * Fix "Move layer to top/bottom" keybinds * Rename things named "move" to "reorder" Fix formatting * Combine sorted layer helper functions * Use integer consts for moving layers to front/back * Fix merge mistake * Fix some clippy lints * Fix panic * Remove "get" prefix from functions * Bring layer menu items out to sub-menu * Support moving multiple layers at a time * Add comment explaining odd keybinding * Add reordering tests * Add negative test * Add new error type * Add layer position helper, clean up tests * Make position helper return Result * Clean up slice iteration * Simplify source_layer_ids computation Co-authored-by: Dennis Kobert <[email protected]>
Closes #238
This change is