mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
added common document/selectionchange watcher
Signed-off-by: Roman <ixrock@gmail.com>
This commit is contained in:
parent
ae68ea2d51
commit
e4e4d7efe1
@ -13,6 +13,15 @@ export interface BadgeProps extends React.HTMLAttributes<any>, TooltipDecoratorP
|
|||||||
isExpanded?: boolean; // always force state to this value
|
isExpanded?: boolean; // always force state to this value
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const badgeMeta = observable({
|
||||||
|
hasTextSelected: false,
|
||||||
|
});
|
||||||
|
|
||||||
|
// Common handler for all Badge instances
|
||||||
|
document.addEventListener("selectionchange", () => {
|
||||||
|
badgeMeta.hasTextSelected = window.getSelection().toString().trim().length > 0
|
||||||
|
});
|
||||||
|
|
||||||
@withTooltip
|
@withTooltip
|
||||||
@observer
|
@observer
|
||||||
export class Badge extends React.Component<BadgeProps> {
|
export class Badge extends React.Component<BadgeProps> {
|
||||||
@ -25,8 +34,7 @@ export class Badge extends React.Component<BadgeProps> {
|
|||||||
|
|
||||||
@autobind()
|
@autobind()
|
||||||
onMouseUp(evt: React.MouseEvent) {
|
onMouseUp(evt: React.MouseEvent) {
|
||||||
const isTextSelected = !!document.getSelection().toString().trim();
|
if (!this.isExpandable || badgeMeta.hasTextSelected) return; // no action required
|
||||||
if (!this.isExpandable || isTextSelected) return; // no action required
|
|
||||||
this.isExpanded = !this.isExpanded;
|
this.isExpanded = !this.isExpanded;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user