Skip to content

feat: Add various text transforms #5701

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

Open
wants to merge 14 commits into
base: develop
Choose a base branch
from

Conversation

richdouglasevans
Copy link
Contributor

@richdouglasevans richdouglasevans commented Mar 30, 2025

Closes #4039
Closes #5675
Closes #5676
Closes #5677
Closes #5678
Closes #5679
Closes #5680
Closes #5681

Description

This adds a new Transform submenu to the editor which has numerous text transforms in it.

output.mp4

Pending Work

I have lumped the text transforms into the context menu without that much thought to ordering them.

We may want to put some thought into:

  • what transforms are present in the context menu
  • the order those transforms appear in the context menu
  • adding the transforms to the Edit menu too

Additional information

Tested on: Windows 11 Home.

Note that I have not updated the CHANGELOG per the PR template guideline 'cos I don't know when this'll be merged, if ever 🤷

@nathanlesage
Copy link
Member

I will need some more time to think about your style of coding because it is different from mine — not in a bad way, so this is not a criticism, but it's a bit more involved to think about this. A few things I already saw you may want to tackle in the meantime is:

  1. I feel your unit tests are extremely repetitive. When you test for various inputs for a single function, for example, it is much simpler and easier to create an array of test cases at the top of the file, and implement the tester function once. This way the file is more organized, and it will be simple to just add additional test cases in the future.
  2. I greatly appreciate your efforts to kickstart testing the codemirror related functionality. The main reason why we don't yet have such tests is literally just because I was too lazy to write those helper functions until now. What I would love to see is to have that a bit more generalized so that we can test more than just the transformation commands in the future. Please do not take this to completely over-engineer that; just start naming things "codemirror-test-utils" or something like that simply so that we know where to add additional functionality as the need arises and we start testing more things.
  3. Please don't write longer strings by concatenating them, this looks horribly ugly 🙈 The 80 character column limit is not enforced in cases where the description just takes longer, that is fine. If you really do need multi-line strings (but not in the tests please), you can use backtick-strings.
  4. I'll have to think if it's really adequate to have the transform commands implemented using a factory style, because it does add some complexity that is more difficult to disentangle in the future. My first intention was to literally just write command functions as-is (in the sense that they could be copied and pasted into different code bases and they work there, too). I do see the appeal of saving on some code, however, but I'm wondering what your thoughts are on my approach to the table editor commands (see PR feat: Rewrite TableEditor from Scratch #5243, specifically this folder: https://github.com/Zettlr/Zettlr/tree/table-editor/source/common/modules/markdown-editor/table-editor/commands)

I'll be back with a more thorough code review — also please feel free to remove the explanatory comments, because it makes focusing on the code more difficult than necessary. I appreciate the thoroughness, but it is easier to parse if you could transfer that information into your PR description and leave the files!

Thank you already for your help and work!

@richdouglasevans
Copy link
Contributor Author

richdouglasevans commented Apr 2, 2025

I feel your unit tests are extremely repetitive. When you test for various inputs for a single function, for example, it is much simpler and easier to create an array of test cases at the top of the file, and implement the tester function once. This way the file is more organized, and it will be simple to just add additional test cases in the future.

I have changed the test fixtures to conform to your preference.

What I would love to see is to have that a bit more generalized so that we can test more than just the transformation commands in the future.

I have moved the supporting code into a folder per your suggestion.

Please don't write longer strings by concatenating them.

Updated to conform to your preference in 9899d09

remove the explanatory comments

I have deleted all of them.

I'm wondering what your thoughts are on my approach to the table editor commands

Approach looks solid ✌️ In your case there are distinct differences between chunks of commands... while there is some repetition, it reads well enough.

I only refactored to the composition approach after writing the third text transform command because by then I noticed that I was repeating the same code in every command: in the specific case of these text transforms there's no difference to the CodeMirror algorithm piece... the composition allows the code that's distinct and relevant to just that transform to "pop."

It's easy enough for me to un-compose it.

@richdouglasevans richdouglasevans force-pushed the 5679-strip-duplicate-spaces branch 2 times, most recently from 04c2d13 to 62a1676 Compare April 21, 2025 13:50
@richdouglasevans richdouglasevans force-pushed the 5679-strip-duplicate-spaces branch from 62a1676 to 9138c37 Compare May 29, 2025 09:36
@richdouglasevans richdouglasevans force-pushed the 5679-strip-duplicate-spaces branch from 9138c37 to 8e0509e Compare July 14, 2025 20:28
@richdouglasevans richdouglasevans force-pushed the 5679-strip-duplicate-spaces branch from 8e0509e to dd9e5a0 Compare July 15, 2025 12:42
richdouglasevans added a commit to richdouglasevans/Zettlr that referenced this pull request Jul 15, 2025
This PR addresses half of Zettlr#5677: the code for doing the reverse transformation — quotes to italics — will follow in a distinct PR.

> ℹ️ Please note that this PR _merges into [another PR](Zettlr#5701 The code in this PR builds on code from that other PR.
>
> I understand that this is a bit funky: I'm only doing it this way because there is still some uncertainty about the approach. Ideally the uncertainty will be resolved in these two PRs and then we can get back to the usual workflow.

## Description

This adds another transform to the editor's new _Transform_ submenu which will change italicized text to quoted text.

In the video I am:

* selecting some italicized text
* clicking the command from the aforementioned submenu

After running the command the italicized text becomes instead quoted text.

## Additional information

Tested on: Windows 11 Home.

> Note that I have not updated the CHANGELOG per the PR template guideline 'cos I don't know when this'll be merged, if ever 🤷
@richdouglasevans richdouglasevans changed the title feat: Add transform to strip duplicate spaces feat: Add various text transforms Jul 15, 2025
@nathanlesage
Copy link
Member

Sooooooo, after way too long I've been able to give it a Quick Look. And it has proven once more that sometimes letting something sit can change one's perspective on it. I am now much more comfortable reading your code and seeing the benefits of your approach. While I do believe that a bit of the code might be too verbose, that honestly boils down to personal preference, so I don't want you to change anything. I just gave it a skim and will want to try it out myself but I really believe that the code looks good to merge!

So thanks for holding tight during the past four months -- once I'm back at my desktop, I'll give it a quick run and then we can merge it.

I currently think that we can pull this through in two PRs: one that implements the base functionality plus examples (I.e., this PR as it is), and then a second one that simply implements all other transforms you have been discussing!

If you want to, you can already open that second PR (you can close the individual ones), because I'm pretty sure you won't have to change anything! And then we're good to go!

Thank you again for all of this exemplary work!

This PR addresses half of Zettlr#5677: the code for doing the reverse transformation — quotes to italics — will follow in a distinct PR.

This adds another transform to the editor's new _Transform_ submenu which will change italicized text to quoted text.

In the video I am:

* selecting some italicized text
* clicking the command from the aforementioned submenu

After running the command the italicized text becomes instead quoted text.

Tested on: Windows 11 Home.

> Note that I have not updated the CHANGELOG per the PR template guideline 'cos I don't know when this'll be merged, if ever 🤷
@richdouglasevans richdouglasevans force-pushed the 5679-strip-duplicate-spaces branch from ea602c8 to 0f945c3 Compare July 18, 2025 10:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment