Pricing Blog

Context Menu - how to read the underlying text

  • rscott-1214270496447795320

    Bishop

    1 year ago

    https://www.youtube.com/watch?v=YUfa43NXSGY&ab_channel=toddle
    This tutorial is helpful but if we put a context menu on a contenteditable div, for example, how can we know what text was selected when they right clicked?
  • lucasg-1214272592282918922

    Lucas G

    1 year ago

    You can use a custom action to get the selected text
  • function getSelection(event, ctx) {
    const userSelection = window.getSelection();
    const selectedText = userSelection.toString();
    ctx.triggerActionEvent('selectedText', selectedText);
    }
  • rscott-1214275530480951378

    Bishop

    1 year ago

    Was just thinking that. 🙂
  • Thanks Lucas.
  • rscott-1214275895188000848

    Bishop

    1 year ago

    So its an action instead of a formula because the assumption is they will select the text and then the context menu will pop up without them having to right click?
  • rscott-1214276185148760134

    Bishop

    1 year ago

    i only want this to pop up for a certain field
  • rscott-1214279990447833120

    Bishop

    1 year ago

    Seems like it is more of an event on my contexteditable div
  • because I want them to just select the text and that triggers the pop up to show. then i use your action to get the text that was selected.

    How do I get it to trigger the menu when they do a selection
  • rscott-1214281034754035712

    Bishop

    1 year ago

    oh i think i get it i use mouseup event to detect selection happened then use your action
  • d.mcpaul-1219287053074825257

    Devin McPaul

    1 year ago

    This is GOLD!

    Going to start using this for my app.