1
0
mirror of https://github.com/lensapp/lens.git synced 2025-05-20 05:10:56 +00:00

Not closing badge if user started to select text

Signed-off-by: Alex Andreev <alex.andreev.email@gmail.com>
This commit is contained in:
Alex Andreev 2021-07-13 16:16:52 +03:00
parent 4130c3ce91
commit 5ba5ed488f

View File

@ -36,13 +36,9 @@ export interface BadgeProps extends React.HTMLAttributes<any>, TooltipDecoratorP
disabled?: boolean;
}
const badgeMeta = observable({
hasTextSelected: false,
});
// Common handler for all Badge instances
document.addEventListener("selectionchange", () => {
badgeMeta.hasTextSelected = window.getSelection().toString().trim().length > 0;
Badge.badgeMeta.hasTextSelected ||= window.getSelection().toString().trim().length > 0;
});
@withTooltip
@ -52,6 +48,10 @@ export class Badge extends React.Component<BadgeProps> {
expandable: true
};
static badgeMeta = observable({
hasTextSelected: false
});
@observable.ref elem: HTMLElement;
@observable isExpanded = false;
@ -68,8 +68,11 @@ export class Badge extends React.Component<BadgeProps> {
@boundMethod
onMouseUp() {
if (!this.isExpandable || badgeMeta.hasTextSelected) return; // no action required
this.isExpanded = !this.isExpanded;
if (!this.isExpandable || Badge.badgeMeta.hasTextSelected) {
Badge.badgeMeta.hasTextSelected = false;
} else {
this.isExpanded = !this.isExpanded;
}
}
@boundMethod