Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

slash command dropdown position inside editor #17715

Open
Rithwinsai2 opened this issue Jan 6, 2025 · 0 comments
Open

slash command dropdown position inside editor #17715

Rithwinsai2 opened this issue Jan 6, 2025 · 0 comments
Labels
type:question This issue asks a question (how to...).

Comments

@Rithwinsai2
Copy link

📝 Ask a question

Move dropdown position above and below inside editor.
Image

_getBalloonPosition() {
const editor = this.editor;
const view = editor.editing.view;
const viewDocument = view.document;
const viewportHeight = window.innerHeight;
const editorRect = editor.ui.view.editable.element.getBoundingClientRect();
const editorBottom = editorRect.bottom;

    const target = () => {
        const range = view.domConverter.viewRangeToDom(viewDocument.selection.getFirstRange());
        const rect = range.getBoundingClientRect(); 

        if (rect.top === 0 && rect.left === 0 && rect.height === 0 && rect.width === 0) {
            return this._getEditorPosition(editorRect, viewportHeight);
        }

        let top = rect.top + rect.height + 10;

        if (top + 100 > editorBottom) { 
            top = rect.top - 100 - 10; 
        }
        if (top + 100 > viewportHeight) { 
            top = viewportHeight - 100 - 10;
        }

        if (top < 100) {
            top = 100; 
        }

        const left = Math.max(rect.left, editorRect.left);  
        const right = Math.min(rect.right, editorRect.right); 

        return { top, left, right };
    };

    return { target };
}

_getEditorPosition(editorRect, viewportHeight) {
    let top = editorRect.top + editorRect.height + 10; 

    if (top + 100 > viewportHeight) {
        top = viewportHeight - 100 - 10; 
    }
    const left = editorRect.left;
    const right = editorRect.right;

    return {left, right };
}

actual outpt:
![Image](https://github.com/user-attachments/assets/2c525eea-66![Image](https://github.com/user-attachments/assets/54491f98-8d48-40df-adc5-c2173d6b0a29)
7f-4b83-8e0a-343670cdd0cf)

expected output:
Image

@Rithwinsai2 Rithwinsai2 added the type:question This issue asks a question (how to...). label Jan 6, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type:question This issue asks a question (how to...).
Projects
None yet
Development

No branches or pull requests

1 participant