-
-
Notifications
You must be signed in to change notification settings - Fork 5.2k
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
Desktop: Add toggling functionality for bold, italics and code in Editor Toolbar #2565
Conversation
@PackElend label me please. |
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've noticed 1 issue and 1 room for improvement:
When you have a code block and select the code block (plus the bacticks) and use the code shortcut, the code block is rendered to normal text again (which was the idea), but an empty line is appended. So this has to be fixed. You have to make sure that there's no extra empty line.
As a suggestion, please also check for the underscore character for the emphasized text.
e.g. I write my emphasized text like _bla_
, but when I select that and hit the I
button, it turns into *_bla_*
. see comment inline.
ElectronClient/gui/NoteText.jsx
Outdated
this.wrapSelectionWithStrings('*', '*', _('emphasized text')); | ||
const selection = this.textOffsetSelection(); | ||
let string = this.state.note.body.substr(selection.start, selection.end - selection.start); | ||
if (string.startsWith('*') && string.endsWith('*')) { |
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.
Please also check for underscore here.
if ((string.startsWith('*') && string.endsWith('*')) || (string.startsWith('_') && string.endsWith('_'))) {
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.
@tessus I've made the requested changes and updated the PR. Please review.
0ef11dc
to
acff52c
Compare
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.
Unfortunately the codeblock still leaves an extra empty line.
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.
use this in commandTextCode():
if (string.startsWith('```') && string.endsWith('```')) {
this.wrapSelectionWithStrings('', '', '', string.substr(4, selection.end - selection.start - 8
} else {
this.wrapSelectionWithStrings(`\`\`\`${match[0]}`, `${match[0]}\`\`\``);
}
This will fix the extra line appearing.
dcaf583
to
f2e7b8c
Compare
Thanks, @meyash |
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.
LGTM. Tested.
The four blocks of code you've added are all very similar. Could you refactor them into a single function please? |
I've shortened the code a bit without making it very complicated. |
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.
Looks good to me, you can improve this code by adding regexp for searching but this is fine too
Anything else that has to be done or can we merge? |
Looks good, thanks @rabeehrz! |
Did this feature ever worked? On the latest version if I select some text and click on bold it becomes |
Yes, but you have to select the text first. There's also a follow-up PR which I think does what you think it should do. |
Fixes issue #2560
This PR adds a toggling function for bold, italics and code elements in the Editor Toolbar.
As mentioned in the issue:
Improvements
Added italics toggling for wrapping using underscores
Before
After