Disable rich test paste when Shift key is held while pasting
parent
0ebbe2e7f3
commit
c5c6cd3af0
|
@ -73,10 +73,23 @@ export const pasteLinkExtension = ViewPlugin.fromClass(
|
|||
);
|
||||
|
||||
export function attachmentExtension(editor: Editor) {
|
||||
let shiftDown = false;
|
||||
return EditorView.domEventHandlers({
|
||||
dragover: (event) => {
|
||||
event.preventDefault();
|
||||
},
|
||||
keydown: (event) => {
|
||||
if (event.key === "Shift") {
|
||||
shiftDown = true;
|
||||
}
|
||||
return false;
|
||||
},
|
||||
keyup: (event) => {
|
||||
if (event.key === "Shift") {
|
||||
shiftDown = false;
|
||||
}
|
||||
return false;
|
||||
},
|
||||
drop: (event: DragEvent) => {
|
||||
// TODO: This doesn't take into account the target cursor position,
|
||||
// it just drops the attachment wherever the cursor was last.
|
||||
|
@ -93,12 +106,12 @@ export function attachmentExtension(editor: Editor) {
|
|||
paste: (event: ClipboardEvent) => {
|
||||
const payload = [...event.clipboardData!.items];
|
||||
const richText = event.clipboardData?.getData("text/html");
|
||||
if (richText) {
|
||||
// Only do rich text paste if shift is NOT down
|
||||
if (richText && !shiftDown) {
|
||||
const markdown = striptHtmlComments(turndownService.turndown(richText))
|
||||
.trim();
|
||||
const view = editor.editorView!;
|
||||
const selection = view.state.selection.main;
|
||||
console.log("Rich text", markdown);
|
||||
view.dispatch({
|
||||
changes: [
|
||||
{
|
||||
|
|
|
@ -6,6 +6,7 @@ release.
|
|||
## 0.2.1
|
||||
|
||||
* New `Plugs: Add` command
|
||||
* When holding `Shift` while pasting, rich test paste will be disabled.
|
||||
|
||||
## 0.2.0
|
||||
* The editor is now in "live preview" mode where a lot of markdown is hidden unless the cursor is present. This will take some getting used to, but results in a much more distraction free look.
|
||||
|
|
Loading…
Reference in New Issue