Skip to content

Commit

Permalink
fix: fix hide popup when no hovering item
Browse files Browse the repository at this point in the history
  • Loading branch information
azu committed Apr 17, 2021
1 parent 0a6153e commit d4cbea6
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 9 deletions.

This file was deleted.

15 changes: 8 additions & 7 deletions packages/textchecker-element/src/attach-to-text-area.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,12 +75,15 @@ export const attachToTextArea = ({
}
const textChecker = new TextCheckerElement({
targetElement: textAreaElement,
hoverPadding: 10
hoverPadding: 20
});
textAreaElement.before(textChecker);
const hoverMap = new Map<TextCheckerElementRectItem, boolean>();
const textCheckerPopup = createTextCheckerPopupElement({
onLeave() {
textCheckerPopup.dismissCards();
if (!textCheckerPopup.isHovering && hoverMap.size === 0) {
textCheckerPopup.dismissCards();
}
}
});
const compositionHandler = createCompositionHandler();
Expand Down Expand Up @@ -113,13 +116,12 @@ export const attachToTextArea = ({
fixable: Boolean(message.fix)
};
const abortSignalMap = new WeakMap<TextCheckerElementRectItem, AbortController>();
let isMouseEnter = false;
return {
id: `${message.ruleId}::${message.line}:${message.column}`,
start: message.index,
end: message.index + 1,
onMouseEnter: ({ rectItem }: { rectItem: TextCheckerElementRectItem }) => {
isMouseEnter = true;
hoverMap.set(rectItem, true);
const controller = abortSignalMap.get(rectItem);
debug("enter", controller);
if (controller) {
Expand Down Expand Up @@ -186,13 +188,13 @@ export const attachToTextArea = ({
},
async onMouseLeave({ rectItem }: { rectItem: TextCheckerElementRectItem }) {
try {
isMouseEnter = false;
hoverMap.delete(rectItem);
const controller = abortSignalMap.get(rectItem);
debug("leave", controller);
await delay(500, {
signal: controller?.signal
});
if (textCheckerPopup.isHovering || isMouseEnter) {
if (textCheckerPopup.isHovering || hoverMap.get(rectItem)) {
return;
}
textCheckerPopup.dismissCard(card);
Expand All @@ -216,7 +218,6 @@ export const attachToTextArea = ({
textAreaElement.addEventListener("focusout", hideAnnotations);
update();
// when resize element, update annotation
// @ts-expect-error
const resizeObserver = new ResizeObserver(() => {
debug("textarea resize");
textCheckerPopup.dismissCards();
Expand Down
2 changes: 1 addition & 1 deletion packages/textchecker-element/src/text-checker-element.ts
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ export class TextCheckerElement extends HTMLElement {
};
return (
rect.left - hoverPadding <= point.x &&
point.x <= rect.left + hoverPadding + rect.width &&
point.x <= rect.left + rect.width + hoverPadding &&
rect.top - hoverPadding <= point.y &&
point.y <= rect.top + rect.height + hoverPadding
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,7 @@ export class TextCheckerPopupElement extends HTMLElement {
}

public dismissCards() {
console.trace("test");
this.store.removeAllCard();
}

Expand Down

0 comments on commit d4cbea6

Please sign in to comment.