enh: note selection edit support

This commit is contained in:
Timothy Jaeryang Baek
2025-07-19 16:35:03 +04:00
parent e35f7748f6
commit 3af2938efc
4 changed files with 102 additions and 16 deletions
+35 -1
View File
@@ -56,6 +56,7 @@
import { Fragment, DOMParser } from 'prosemirror-model';
import { EditorState, Plugin, PluginKey, TextSelection, Selection } from 'prosemirror-state';
import { Decoration, DecorationSet } from 'prosemirror-view';
import { Editor, Extension } from '@tiptap/core';
// Yjs imports
@@ -167,6 +168,8 @@
});
};
export let onSelectionUpdate = (e) => {};
export let id = '';
export let value = '';
export let html = '';
@@ -192,6 +195,8 @@
let jsonValue = '';
let mdValue = '';
let lastSelectionBookmark = null;
// Yjs setup
let ydoc = null;
let yXmlFragment = null;
@@ -827,6 +832,33 @@
}
};
const SelectionDecoration = Extension.create({
name: 'selectionDecoration',
addProseMirrorPlugins() {
return [
new Plugin({
key: new PluginKey('selection'),
props: {
decorations: (state) => {
const { selection } = state;
const { focused } = this.editor;
if (focused || selection.empty) {
return null;
}
return DecorationSet.create(state.doc, [
Decoration.inline(selection.from, selection.to, {
class: 'editor-selection'
})
]);
}
}
})
];
}
});
onMount(async () => {
content = value;
@@ -882,6 +914,7 @@
link: link
}),
Placeholder.configure({ placeholder }),
SelectionDecoration,
CodeBlockLowlight.configure({
lowlight
@@ -1168,7 +1201,8 @@
if (files) {
editor.storage.files = files;
}
}
},
onSelectionUpdate: onSelectionUpdate
});
if (messageInput) {