-
-
Notifications
You must be signed in to change notification settings - Fork 107
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
Support pasting markdown #17
Conversation
src/index.js
Outdated
if (INLINE_STYLE_CHARACTERS.indexOf(text[i]) >= 0) { | ||
newEditorState = addText(newEditorState, buffer.join('') + text[i]); | ||
newEditorState = _handleCharacter(newEditorState, text[i]); | ||
buffer.length = 0; |
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.
What does this line intended to?
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.
While typing Inline transformation were taking place we space is entered.
But in case on pasting text.
"_hello_ "
was transformed to hello.
But "_hello_"
was not being transformed. Thus while pasting INLINE_STYLE_CHARACTERS also checked.
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.
Thanks, that makes sense.
I meant I'm thinking assigning length
property to Array instance will affect nothing.
Can I ask what intended to do in this line 148?
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.
buffer.length = 0
will reset the array to empty without changing it's refrence thus it would work as const
. Otherwise we can do let buffer = []
and buffer = []
instead of buffer.length = 0
.
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.
Updated to let version I thought buffer.length
was faster. I was wrong.
https://jsperf.com/array-destroy
src/index.js
Outdated
@@ -1,3 +1,5 @@ | |||
/* eslint-disable no-underscore-dangle,no-plusplus */ |
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.
Can you please keep using current eslint rules?
@ngs |
@potato4d @nil1511 I'm awaiting for reply about #17 (comment) |
.eslintrc
Outdated
"class-methods-use-this": 0 | ||
"class-methods-use-this": 0, | ||
"no-plusplus":0, | ||
"no-underscore-dangle":0 |
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.
Can you please keep original?
Any updates on this? |
@ngs Can you check now? Sorry for the delay. |
@nil1511 Thank you. Test coverage became non-perfect with this PR. Could you cover non-covered lines/trees? |
src/__test__/utils-test.js
Outdated
let newEditorState = EditorState.createWithContent(Draft.convertFromRaw(newRawContentState)); | ||
const initialBlockSize = newEditorState.getCurrentContent().getBlockMap().size; | ||
const randomBlockSize = Math.floor((Math.random() * 50) + 1); // random number bettween 1 to 50 | ||
for (let i = 0; i < randomBlockSize; i++) { // eslint-disable-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.
Which lint rule did you disable?
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.
no-plusplus rule
src/index.js
Outdated
const editorState = getEditorState(); | ||
let newEditorState = editorState; | ||
let buffer = []; | ||
for (let i = 0; i < text.length; i++) { // eslint-disable-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.
@nil1511 here as well
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.
no-plusplus rule
@ngs Can you check the test? I have already updated the description on the first comment. |
src/index.js
Outdated
const INLINE_STYLE_CHARACTERS = [' ', '*', '_']; | ||
|
||
function checkCharacterForState(editorState, character) { | ||
if (INLINE_STYLE_CHARACTERS.indexOf(character) === -1) { return editorState; } |
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.
This line is not covered yet. ref
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.
Removed it. That check was redundant. currently, checkCharacterForState is only called with one of INLINE_STYLE_CHARACTERS. Now code coverage is 100%.
@nil1511 Thank you! |
* Support Pasting markdown * Fix single line paste * Reset buffer using assignment * Move eslint rules to eslintrc * Revert eslint config * Added Test case for utils * Specify disable rule * Added test case for handlePastedText * remove redundant check
Published as v0.1.0 https://www.npmjs.com/package/draft-js-markdown-shortcuts-plugin |
Added Support for pasting markdown.
How does it work?