Skip to content

Commit

Permalink
fix: paste text into empty block (close: #474)
Browse files Browse the repository at this point in the history
  • Loading branch information
Sohee Lee committed Apr 16, 2019
1 parent b17274d commit a8cf0fb
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 34 deletions.
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
"markdown-it": "^8.4.0",
"to-mark": "^1.1.5",
"tui-color-picker": "^2.2.1",
"squire-rte": "sohee-lee7/Squire#b1e0e1031fa18912d233c204cbe7c7fae4a42621",
"squire-rte": "sohee-lee7/Squire#e35304de663568a458a75f0d3c206fbddb8c0699",
"plantuml-encoder": "^1.2.5",
"tui-chart": "^2.13.0"
},
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@
"markdown-it": "^8.4.0",
"plantuml-encoder": "^1.2.5",
"resize-observer-polyfill": "^1.5.0",
"squire-rte": "github:sohee-lee7/Squire#b1e0e1031fa18912d233c204cbe7c7fae4a42621",
"squire-rte": "github:sohee-lee7/Squire#e35304de663568a458a75f0d3c206fbddb8c0699",
"to-mark": "^1.1.5",
"tui-chart": "^3.0.1",
"tui-code-snippet": "^1.5.0",
Expand Down
30 changes: 0 additions & 30 deletions src/js/wwClipboardManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,9 +133,6 @@ class WwClipboardManager {
pasteData.fragment.appendChild(element);
});

// @TODO Temporary code : paste to empty code block
this._pasteToEmptyCodeBlock(pasteData);

// once right after the squire insertHTML DOM.
const handler = () => {
this.wwe.getEditor().removeEventListener('input', handler);
Expand All @@ -145,33 +142,6 @@ class WwClipboardManager {
this.wwe.getEditor().addEventListener('input', handler);
}

// @TODO Temporary code : paste to empty code block
// Squire remove empty code block when paste.
// This code should remove after https://github.com/neilj/Squire/issues/349 would be resolved.
_pasteToEmptyCodeBlock(pasteData) {
const sq = this.wwe.getEditor();
const range = sq.getSelection().cloneRange();
const container = range.startContainer;
const wwCodeblockManager = this.wwe.componentManager.getManager('codeblock');
let shouldChangeSelection = false;
if (wwCodeblockManager.isInCodeBlock(range) && range.collapse &&
container.nodeName === 'PRE' && !container.textContent) {
const brNode = container.firstChild;
container.insertBefore(pasteData.fragment, brNode);
pasteData.defaultPrevented = true;
shouldChangeSelection = true;
}

const handler = () => {
this.wwe.getEditor().removeEventListener('input', handler);
if (shouldChangeSelection) {
range.setStart(container, 1);
sq.setSelection(range);
}
};
this.wwe.getEditor().addEventListener('input', handler);
}

_setClipboardData(clipboardEvent, htmlContent, textContent) {
if (util.browser.msie) {
clipboardEvent.squirePrevented = true;
Expand Down

0 comments on commit a8cf0fb

Please sign in to comment.