mirror of
https://github.com/excalidraw/excalidraw.git
synced 2025-05-03 10:00:07 -04:00
Improve pasting (#723)
* switch to selection tool on paste * align pasting via contextMenu with pasting from event * ensure only plaintext can be pasted * fix findShapeByKey regression * simplify wysiwyg pasting * improve wysiwyg blurriness
This commit is contained in:
parent
ba1a39c9f3
commit
88eacc9da7
5 changed files with 119 additions and 82 deletions
|
@ -53,8 +53,36 @@ export function textWysiwyg({
|
|||
outline: "1px solid transparent",
|
||||
whiteSpace: "nowrap",
|
||||
minHeight: "1em",
|
||||
backfaceVisibility: "hidden",
|
||||
});
|
||||
|
||||
editable.onpaste = ev => {
|
||||
try {
|
||||
const selection = window.getSelection();
|
||||
if (!selection?.rangeCount) {
|
||||
return;
|
||||
}
|
||||
selection.deleteFromDocument();
|
||||
|
||||
const text = ev.clipboardData!.getData("text").replace(/\r\n?/g, "\n");
|
||||
|
||||
const span = document.createElement("span");
|
||||
span.innerText = text;
|
||||
const range = selection.getRangeAt(0);
|
||||
range.insertNode(span);
|
||||
|
||||
// deselect
|
||||
window.getSelection()!.removeAllRanges();
|
||||
range.setStart(span, span.childNodes.length);
|
||||
range.setEnd(span, span.childNodes.length);
|
||||
selection.addRange(range);
|
||||
|
||||
ev.preventDefault();
|
||||
} catch (err) {
|
||||
console.error(err);
|
||||
}
|
||||
};
|
||||
|
||||
editable.onkeydown = ev => {
|
||||
if (ev.key === KEYS.ESCAPE) {
|
||||
ev.preventDefault();
|
||||
|
@ -92,6 +120,7 @@ export function textWysiwyg({
|
|||
function cleanup() {
|
||||
editable.onblur = null;
|
||||
editable.onkeydown = null;
|
||||
editable.onpaste = null;
|
||||
window.removeEventListener("wheel", stopEvent, true);
|
||||
document.body.removeChild(editable);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue