obsidian-text-format
obsidian-text-format copied to clipboard
Added the option to toggle the case of the selected text.
Hi.
Love your plugin but I was a bit frustrated having to map the keyboard shortcuts to uppercase and lower case. So I added the option just to toggle the case. The logic of choosing if the selected text is upper case or lower case is just to find the first character that does has a differing case character then covert the selected text the the opposite case of the character. This could be improved to be modern JavaScript but it gets the job done.
Hi, thank you for your PR.
Take an example, if we selected, say, "Obsidian plugin", what you expected is "obsidian plugin" if toggle once and "OBSIDIAN PLUGIN" if toggle twice. Is that right?
Yes that is correct.
I think using a regex to get the first letter (or any letter) is better than a for loop.
BTW, I am a bit curious about your use case. Do you only consider the uppercase
and lowercase
and no others like Capitalecase
? Will you use this command to a whole sentence? Like "Obsidian is an app", whose first letter is uppercase usually.
I was thinking the same thing but regexp would only cover the Latin alphabetical glyph [a-z|A-Z] excluding non Latin alphabetical glyphs. Understandably I don't know the whole Unicode code points (UTF-8) that have corresponding upper case or lower case equivalents, so I decided just to do a simple for loop checking the first glyph/codepoint that have a differing codepoint after converting the case.
For now, I only consider Latin and Cyrillic
"[\\w\\u0400-\\u04FF]"
The use case would be to select a range of characters, and then toggle the case of the selected range of characters. For example selecting [Obsidian is an app], I would want it to be toggled to lower case so it would be [obsidian is an app] and if I used the keyboard shortcut again it would toggle the case to [OBSIDIAN IS AN APP], and vis versa to [obsidian is an app].
For now, I only consider Latin and Cyrillic
"[\\w\\u0400-\\u04FF]"
I still think it is better to use regex to get the first letter, if regex fails to get, then use the for loop to search one. 🤔
Add a setting to configure the toggle sequence loop as users like.