[26194] Skip activation of edit field with active selection within (#5885)
https://community.openproject.com/wp/26194 [ci skip]pull/5889/head
parent
48f8589087
commit
f405d68f73
@ -0,0 +1,21 @@ |
||||
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; |
||||
} |
||||
} |
||||
} |
||||
|
Loading…
Reference in new issue