Skip to content

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

Merged
merged 20 commits into from
Jul 21, 2021

Conversation

ajweeks
Copy link
Contributor

@ajweeks ajweeks commented Jul 15, 2021

Closes #238


This change is Reviewable

@ajweeks ajweeks force-pushed the rearrange-layers branch from 8acfa93 to 8deb530 Compare July 16, 2021 07:48
@TrueDoctor
Copy link
Member

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)

@ajweeks
Copy link
Contributor Author

ajweeks commented Jul 16, 2021

This is why I force pushed before, I think I messed up the rebase 🤦‍♂️

@ajweeks
Copy link
Contributor Author

ajweeks commented Jul 17, 2021

Thanks for the merge help @TrueDoctor

@ajweeks
Copy link
Contributor Author

ajweeks commented Jul 17, 2021

Yeah, that code will change imminently though since I'm adding support for moving multiple layers now anyway

@ajweeks ajweeks marked this pull request as ready for review July 18, 2021 08:09
@Keavon
Copy link
Member

Keavon commented Jul 18, 2021

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.

@ajweeks
Copy link
Contributor Author

ajweeks commented Jul 18, 2021

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.

@TrueDoctor
Copy link
Member

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.
That's nice, will get right to reviewing

@Keavon Keavon requested a review from TrueDoctor July 18, 2021 10:19
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()] {
Copy link
Member

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

Copy link
Contributor Author

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.

Copy link
Member

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..]

Copy link
Member

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

Copy link
Contributor Author

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.

@ajweeks
Copy link
Contributor Author

ajweeks commented Jul 18, 2021

Looks great, thanks for adding the tests! (This is the kind of thing that can be trickier to get right so testing is indeed helpful). My only comment about the tests is just a nitpick about the comments: it took me about a minute of understand what you meant by '' until I realized that's the "same as above" indicator, my mind was thinking along the lines of single-quoted strings or anything else. If you get the chance, could you consider moving the comment to the line above the one it refers to (typically it's better stylistic practice for descriptive comments, rather than TODOs, to be on its own line) so the comment refers to the block of following lines, and the '' mark is therefore unnecessary? I really don't intend to be a stickler over comments or style like that, so please feel more than free to ignore this comment, it's truly a nitpick I'm totally happy to ignore.

Yep, that's totally fair, I agree it wasn't the clearest.

@TrueDoctor TrueDoctor merged commit a448b36 into GraphiteEditor:master Jul 21, 2021
Keavon pushed a commit that referenced this pull request Jun 16, 2022
* 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]>
Keavon pushed a commit that referenced this pull request Jul 30, 2023
* 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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Rearranging layers with hotkeys
3 participants