OpenProject is the leading open source project management software.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 
openproject/frontend/app/helpers/selection-helpers.ts

21 lines
564 B

export namespace SelectionHelpers {
/**
* 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(getSelection().anchorNode);
return hasSelection && isWithin;
} catch (e) {
console.error('Failed to test whether in selection ' + e);
return false;
}
}
}