milkdown icon indicating copy to clipboard operation
milkdown copied to clipboard

[Feature] Is it possible to make the slash or tooltip, calc the position rely a specified dom

Open 4-1-1 opened this issue 2 years ago • 3 comments

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

4-1-1 avatar Jul 26 '22 08:07 4-1-1

Can you please provide more information about the solution you mentioned above? I'm not quite understand that.

Saul-Mirone avatar Jul 26 '22 16:07 Saul-Mirone

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

4-1-1 avatar Jul 27 '22 04:07 4-1-1

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.

Saul-Mirone avatar Jul 28 '22 02:07 Saul-Mirone

rootDOMCtx has been added.

Saul-Mirone avatar Aug 23 '22 16:08 Saul-Mirone