-
-
Notifications
You must be signed in to change notification settings - Fork 728
Improve ToC drag and drop new line handling #5871
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
2d0a6a5
to
3da3e90
Compare
I'm not entirely sure I properly saw that edge case. That being said, I believe there is a good way to ensure the command works as expected, and that is adding a test case for it. You could then also move the So, do you think it would be possible to add the following two things:
|
I can definitely move it. Regarding the edge case, I'm not so certain whether it should be, or can be, sanitized, but I'll see about creating a test for it. I don't think it would result in the |
Ahh, I see, the move section command didn't insert a new line when you exchanged the sections, I see it now. Well, as long as the sections don't turn unusable (as it was before), I think it's fine for now. We can still see whether we find the cause and improve that (because I personally like that users are being shown how to properly space out headings; I never liked seeing headings without proper spacing, but that's a personal pet peeve of mine)! |
It looks like there already is a separate function with tests, do you remember if this was intended to replace the editor method? https://github.com/search?q=repo%3AZettlr%2FZettlr%20move-section&type=code |
Oh boy, my memory is a sieve … (but thank you for discovering this!). So, I just checked the git blame, and that function hasn't been touched in five years. So it's safe to say that that was the original function, which is now dead code. (I confirmed that the now-used function is the one on the editor instance; while the unit tests use the now-defunct utility function that is not used in production.) So what I would suggest is to just extract the … … the more I think about the fact that I just completely forgot a relatively large and important utility function tells you enough about what a Swiss cheese my brain is. |
e775aa8
to
8c64f7c
Compare
I know we talked about tests, but I don't think there are currently any tests for editor commands. The current implementation relies on the editor state/view. I was able to move the function to a separate file in utils, but otherwise, I'm not sure where to go with restructuring this. It might require a larger refactor than anticipated. |
Ah, looks better. Regarding tests: I believe someone recently already did some test harnessing for EditorViews to test commands; so you might be able to plug into that. Otherwise: If it works for you, we might also postpone re-implementing the tests if that takes too long and deliver them sometime during the beta. But again, have a look in the test folder, I believe there's utilities for testing Editor Commands. |
Found them! Thank you for confirming that. I'll get something drafted before we merge this |
0a007d3
to
8dfc540
Compare
@nathanlesage I've done a little more refactoring and added some tests. If you could take a look at them when you get the chance, this should be good to merge once you're comfortable! |
1608a06
to
2c55b4a
Compare
059e8d4
to
53dd9cc
Compare
Hey @nathanlesage, sorry to bug you again, but do you think this can get merged before the beta? |
* previously, moving selections could result * in an extra blank line
* if we are at the end of the document, we need Text.to, * else we swallow the text on the final line.
53dd9cc
to
00a2d3e
Compare
Gnarl, forgot about this PR again 🙄 Merging now! There will be plenty of additional betas in any case … Sorry! |
No problem! I just wanted to make sure this got in since its pretty user-facing |
Description
This PR improves ToC drag and drop new line handling. It sanitizes new lines in ToC sections to ensure appropriate spacing when moving them.
Changes
the
moveSection
function was refactored to sanitize the section to ensure new lines are handled correctly.Previously, moving sections would result in an additional new line above the moved section. This was because the section selection extended from the beginning of the section to the end of the last line, but this results in a blank line. By extending the selection to the beginning of the next section, we remove this additional line.
Secondly, moving sections could result in them being appended to the end of the last line of the previous section, if they were not spaced correctly.
There is one edge case which I cannot seem to figure out, and it can be seen in the video below at about the 20 second mark. But if a section is moved above the previous section, but there is no new line between them, then the previous section will have no new line between it and the next section once it's moved.
Additional information
Previous behavior:
ToCPrev-1.mov
PR behavior:
ToC-1.mov
Tested on: macOS 15.6