milkdown
milkdown copied to clipboard
[Feature] Is it possible to make the slash or tooltip, calc the position rely a specified dom
Is your feature request related to a problem? Please describe. Sometimes , the editor container is too small . make the slash menu is hard to use.
Describe the solution you'd like move postion:relative style of "milkdown" and the parentNode could be specified by ctx
Describe alternatives you've considered
Additional context
Can you please provide more information about the solution you mentioned above? I'm not quite understand that.
const calculatePosition = (view: EditorView, dropdownElement: HTMLElement) => {
calculateNodePosition(view, dropdownElement, (selected, target, parent) => {
const $editor = dropdownElement.parentElement;// make it can be change . absolute dom's parent is the up nearest relative dom .Not just it's parentElement
if (!$editor) {
throw new Error();
}
let left = selected.left - parent.left;
let top = selected.bottom - parent.top + 14 + $editor.scrollTop;
if (left < 0) {
left = 0;
}
if (parent.height + parent.top - selected.bottom < target.height) {
const topOffset = selected.top - parent.top - target.height - 14 + $editor.scrollTop;
if (topOffset > 0) {
top = topOffset;
}
}
return [top, left];
});
};
have a look at the comment
I do have a plan to store the root as a standalone slice. So users can get it use ctx.get(rootDOMCtx)
. I may do it in next version.
rootDOMCtx
has been added.