-
Notifications
You must be signed in to change notification settings - Fork 101
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
feat(ui-markdown-editor): inline wysiwyg - #360 #361
base: main
Are you sure you want to change the base?
Conversation
Signed-off-by: Devesh <[email protected]>
Just an initial thought from watching the recording: I think it would be better to have the text formatted after the final character of the formatting text rather than the space after. So instead "bold" turning into "bold" when the cursor ( typing *bold* _ Have "bold" turn into "bold" when the cursor ( typing *bold*_ |
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.
Really great stuff here!
Some initial thoughts. After going through these, could you also format the code in the files (especially packages/ui-markdown-editor/src/utilities/matchCases.js
) so it's a bit easier to go through?
I likely have more thoughts, but I think with the formatting and my already made comments, it's getting a bit hectic so I'll add more after you address these comments.
@@ -4,6 +4,8 @@ const MISC_CONSTANTS = { | |||
DROPDOWN_NORMAL: 'Normal', | |||
}; | |||
|
|||
export const SPACE_BAR = " "; |
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.
Slightly nit-picky, but maybe this variable could be SPACE_CHARACTER
instead.
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 changed it to a SPACE_CHARACTER
. 👍
switch (ev.key) { | ||
case SPACE_BAR: | ||
matchCases(editor, currentLine); | ||
break; | ||
} | ||
} |
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.
Do you expect there to be other cases? If not, I think we could do this without a switch case to be more simple.
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 changed it to a simple if-else statement as I don't think there will be more cases for it right now.
|
||
const currentLine = currentNode.text | ||
|
||
onkeyup = (ev) => { |
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.
Could this be better handled in our onKeyDown
handler instead of in the withText
plugin?
/** | ||
* | ||
* @param {string} textToInsert The text that we want to format | ||
* @param {Object} textFormats This is the format style of the text (bold, italic, code) we want to apply or remove as the key in an object | ||
* and a boolean as the value. i.e. `{ bold: true }` | ||
* @param {Integer} markdownCharacters The number of markdown characters that the user has to type to trigger WYSIWYG | ||
*/ | ||
const insertFormattedInlineText = (textToInsert, textFormats, markdownCharacters) => { |
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.
Could insertFormattedInlineText
be defined outside of matchCases
?
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.
Should I put it outside the matchCases
function or outside the matchCases
file?
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 think outside the function, probably keep it in this file for now.
Signed-off-by: Devesh <[email protected]>
@irmerk The formatting was looking normal in VSCode but for some reason, it started to look weird after I pushed it here, so I ran it through prettier and now it looks normal. |
@irmerk I think the two ways of executing shortcuts that you mentioned above have very different implementations. I implemented the (1) one which seemed a bit easier for me. How it works here is:
This will happen before we even enter the second asterisk at the end. It will just take For it to behave how you mentioned (2), I think I'll probably have to scrap this method and implement it the other way. In this implementation, we will count the Let me know what you think about it or if you think there is some other way. 👍 |
Apologies for the delay in responding. This is interesting, I hadn't thought of that.
But we're working with CommonMark. I think I'd like a UX perspective here before proceeding in any direction, if you can look at this @Michael-Grover. |
@irmerk Yes, that'll be great. I'll wait for that before I update anything 👍 |
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.
Could this be moved to its own function - like withShortcuts
does in the Slate example?
https://github.com/ianstormtaylor/slate/blob/main/site/examples/markdown-shortcuts.tsx
I also notice that the Slate example covers more shortcuts than this does. They also hook into insertText
which I suspect means that the code will also work on copy/paste. Thoughts?
Yes, I think that it is a good idea. We can do that.
This PR just includes the shortcuts that are performed on inline text, will add more shortcuts once this gets approved.
These inline shortcuts also hook into the Would love to know what others think? |
I agree that we can iterate on more shortcuts after this gets merged in. I think a |
Thanks for the feedback. |
Signed-off-by: Devesh <[email protected]>
@irmerk @dselman I implemented it with the |
Closes #360
This PR will let people directly write formatted text with the help of markdown shortcuts.
It adds the following features:
code inline
Changes
Functions added:
matchCodeInline
=> Implements the markdown shortcuts forinline code
matchBoldAndItalic
=> Implements the markdown shortcuts for italic, bold and bold + italic text.insertFormattedInlineText
=> This function is used in both the above functions. It is used to format and insert the formatted text in the right place.Bugs and Improvements
editor
andcurrentLine
arguments from functions as those values are available in the whole file and can be fetched directly by those functions.Screenshots or Video
2021-12-21.20-40-30.mp4
Related Issues
Author Checklist
--signoff
option of git commit.master
fromfork:branchname