Skip to content
This repository was archived by the owner on Oct 11, 2022. It is now read-only.

Commit 4cfa0e6

Browse files
authoredJul 2, 2018
Merge pull request #93 from withspectrum/remove-custom-paste-handling
Remove custom paste handling
2 parents 2460a7d + 8d8f4f5 commit 4cfa0e6

File tree

2 files changed

+0
-167
lines changed

2 files changed

+0
-167
lines changed
 

‎src/__test__/plugin.test.js

-109
Original file line numberDiff line numberDiff line change
@@ -660,115 +660,6 @@ describe("draft-js-markdown-plugin", () => {
660660
expect(store.setEditorState).toHaveBeenCalledWith(newEditorState);
661661
});
662662
});
663-
describe("handlePastedText", () => {
664-
let pastedText;
665-
let html;
666-
beforeEach(() => {
667-
pastedText = `_hello world_
668-
Hello`;
669-
html = undefined;
670-
subject = () =>
671-
plugin.handlePastedText(
672-
pastedText,
673-
html,
674-
store.getEditorState(),
675-
store
676-
);
677-
});
678-
[
679-
"replaceText",
680-
// TODO(@mxstbr): This broke when switching mocha->jest, fix it!
681-
// 'insertEmptyBlock',
682-
"handleBlockType",
683-
"handleImage",
684-
"handleLink",
685-
"handleInlineStyle",
686-
].forEach(modifier => {
687-
describe(modifier, () => {
688-
beforeEach(() => {
689-
createMarkdownPlugin.__Rewire__(modifier, modifierSpy); // eslint-disable-line no-underscore-dangle
690-
});
691-
it("returns handled", () => {
692-
expect(subject()).toBe("handled");
693-
expect(modifierSpy).toHaveBeenCalled();
694-
});
695-
});
696-
});
697-
describe("nothing in clipboard", () => {
698-
beforeEach(() => {
699-
pastedText = "";
700-
});
701-
it("returns not-handled", () => {
702-
expect(subject()).toBe("not-handled");
703-
});
704-
});
705-
describe("pasted just text", () => {
706-
beforeEach(() => {
707-
pastedText = "hello";
708-
createMarkdownPlugin.__Rewire__("replaceText", modifierSpy); // eslint-disable-line no-underscore-dangle
709-
});
710-
it("returns handled", () => {
711-
expect(subject()).toBe("handled");
712-
expect(modifierSpy).toHaveBeenCalledWith(
713-
currentEditorState,
714-
"hello"
715-
);
716-
});
717-
});
718-
describe("pasted just text with new line code", () => {
719-
beforeEach(() => {
720-
pastedText = "hello\nworld";
721-
const rawContentState = {
722-
entityMap: {},
723-
blocks: [
724-
{
725-
key: "item1",
726-
text: "",
727-
type: "unstyled",
728-
depth: 0,
729-
inlineStyleRanges: [],
730-
entityRanges: [],
731-
data: {},
732-
},
733-
],
734-
};
735-
const otherRawContentState = {
736-
entityMap: {},
737-
blocks: [
738-
{
739-
key: "item2",
740-
text: "H1",
741-
type: "header-one",
742-
depth: 0,
743-
inlineStyleRanges: [],
744-
entityRanges: [],
745-
data: {},
746-
},
747-
],
748-
};
749-
/* eslint-disable no-underscore-dangle */
750-
createMarkdownPlugin.__Rewire__("replaceText", () =>
751-
createEditorState(rawContentState, currentSelectionState)
752-
);
753-
createMarkdownPlugin.__Rewire__("checkReturnForState", () =>
754-
createEditorState(otherRawContentState, currentSelectionState)
755-
);
756-
/* eslint-enable no-underscore-dangle */
757-
});
758-
it("return handled", () => {
759-
expect(subject()).toBe("handled");
760-
});
761-
});
762-
describe("passed `html` argument", () => {
763-
beforeEach(() => {
764-
pastedText = "# hello";
765-
html = "<h1>hello</h1>";
766-
});
767-
it("returns not-handled", () => {
768-
expect(subject()).toBe("not-handled");
769-
});
770-
});
771-
});
772663
});
773664
});
774665
});

‎src/index.js

-58
Original file line numberDiff line numberDiff line change
@@ -415,64 +415,6 @@ const createMarkdownPlugin = (_config = {}) => {
415415
}
416416
}
417417
},
418-
handlePastedText(text, html, editorState, { setEditorState }) {
419-
let newEditorState = editorState;
420-
let buffer = [];
421-
422-
if (html) {
423-
return "not-handled";
424-
}
425-
426-
// If we're in a code block don't add markdown to it
427-
if (inCodeBlock(editorState)) {
428-
setEditorState(insertText(editorState, text));
429-
return "handled";
430-
}
431-
432-
for (let i = 0; i < text.length; i++) {
433-
// eslint-disable-line no-plusplus
434-
if (INLINE_STYLE_CHARACTERS.indexOf(text[i]) >= 0) {
435-
newEditorState = replaceText(
436-
newEditorState,
437-
buffer.join("") + text[i]
438-
);
439-
newEditorState = checkCharacterForState(
440-
config,
441-
newEditorState,
442-
text[i]
443-
);
444-
buffer = [];
445-
} else if (text[i].charCodeAt(0) === 10) {
446-
newEditorState = replaceText(newEditorState, buffer.join(""));
447-
const tmpEditorState = checkReturnForState(
448-
config,
449-
newEditorState,
450-
{}
451-
);
452-
if (newEditorState === tmpEditorState) {
453-
newEditorState = insertEmptyBlock(tmpEditorState);
454-
} else {
455-
newEditorState = tmpEditorState;
456-
}
457-
buffer = [];
458-
} else if (i === text.length - 1) {
459-
newEditorState = replaceText(
460-
newEditorState,
461-
buffer.join("") + text[i]
462-
);
463-
buffer = [];
464-
} else {
465-
buffer.push(text[i]);
466-
}
467-
}
468-
469-
if (editorState !== newEditorState) {
470-
setEditorState(newEditorState);
471-
return "handled";
472-
}
473-
474-
return "not-handled";
475-
},
476418
};
477419
};
478420

0 commit comments

Comments
 (0)
This repository has been archived.