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