Skip to content

OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub

487 B
Raw Blame
/**
 * Test whether we currently have a selection within.
 * @param {HTMLElement} target
 * @return {boolean}
 */
export function hasSelectionWithin(target:Element):boolean {
  try {
    const selection = window.getSelection()!;
    const hasSelection = selection.toString().length > 0;
    const isWithin = target.contains(selection.anchorNode);

    return hasSelection && isWithin;
  } catch (e) {
    console.error('Failed to test whether in selection ', e);
    return false;
  }
}