From d4cbea6f44b28ef325a0f7f9d96ef738fa280717 Mon Sep 17 00:00:00 2001 From: azu Date: Sat, 17 Apr 2021 16:15:03 +0900 Subject: [PATCH] fix: fix hide popup when no hovering item --- .../runtime-helper/src/textlint-apply-fix.ts | 1 - .../src/attach-to-text-area.ts | 15 ++++++++------- .../src/text-checker-element.ts | 2 +- .../src/text-checker-popup-element.ts | 1 + 4 files changed, 10 insertions(+), 9 deletions(-) delete mode 100644 packages/@textlint/runtime-helper/src/textlint-apply-fix.ts diff --git a/packages/@textlint/runtime-helper/src/textlint-apply-fix.ts b/packages/@textlint/runtime-helper/src/textlint-apply-fix.ts deleted file mode 100644 index 2bdcc22..0000000 --- a/packages/@textlint/runtime-helper/src/textlint-apply-fix.ts +++ /dev/null @@ -1 +0,0 @@ -import { TextlintKernel } from "@textlint/kernel"; diff --git a/packages/textchecker-element/src/attach-to-text-area.ts b/packages/textchecker-element/src/attach-to-text-area.ts index 6a25b28..ef7be38 100644 --- a/packages/textchecker-element/src/attach-to-text-area.ts +++ b/packages/textchecker-element/src/attach-to-text-area.ts @@ -75,12 +75,15 @@ export const attachToTextArea = ({ } const textChecker = new TextCheckerElement({ targetElement: textAreaElement, - hoverPadding: 10 + hoverPadding: 20 }); textAreaElement.before(textChecker); + const hoverMap = new Map(); const textCheckerPopup = createTextCheckerPopupElement({ onLeave() { - textCheckerPopup.dismissCards(); + if (!textCheckerPopup.isHovering && hoverMap.size === 0) { + textCheckerPopup.dismissCards(); + } } }); const compositionHandler = createCompositionHandler(); @@ -113,13 +116,12 @@ export const attachToTextArea = ({ fixable: Boolean(message.fix) }; const abortSignalMap = new WeakMap(); - 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) { @@ -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); @@ -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(); diff --git a/packages/textchecker-element/src/text-checker-element.ts b/packages/textchecker-element/src/text-checker-element.ts index bc1327b..57d25d4 100644 --- a/packages/textchecker-element/src/text-checker-element.ts +++ b/packages/textchecker-element/src/text-checker-element.ts @@ -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 ); diff --git a/packages/textchecker-element/src/text-checker-popup-element.ts b/packages/textchecker-element/src/text-checker-popup-element.ts index 10b0c02..260f5fa 100644 --- a/packages/textchecker-element/src/text-checker-popup-element.ts +++ b/packages/textchecker-element/src/text-checker-popup-element.ts @@ -206,6 +206,7 @@ export class TextCheckerPopupElement extends HTMLElement { } public dismissCards() { + console.trace("test"); this.store.removeAllCard(); }