Skip to content

Commit

Permalink
fix(bug): due to event listeners tendency to disrupt layouts
Browse files Browse the repository at this point in the history
Using event listeners were forsaken in favor of CSS-based techniques, due to their tendency to disrupt layouts and burden GPU of PC.
  • Loading branch information
YU000jp committed Aug 3, 2023
1 parent 44c59f6 commit a7c873a
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 25 deletions.
29 changes: 4 additions & 25 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import '@logseq/libs'; //https://plugins-doc.logseq.com/
import { LSPluginBaseInfo, PageEntity, SettingSchemaDesc } from '@logseq/libs/dist/LSPlugin.user';
//import { setup as l10nSetup, t } from "logseq-l10n"; //https://github.com/sethyuan/logseq-l10n
//import ja from "./translations/ja.json";
import fileTooltipCSS from "./tooltip.css?inline";
let restore: Boolean = false;


Expand All @@ -19,11 +20,7 @@ const main = () => {
// }
// })();


logseq.App.onRouteChanged(async () => {

});

logseq.provideStyle(fileTooltipCSS);

logseq.App.onSidebarVisibleChanged(async ({ visible }) => {
if (visible === true) {
Expand All @@ -34,7 +31,6 @@ const main = () => {

setTimeout(() => observerMainRight(), 500);


logseq.onSettingsChanged((newSet: LSPluginBaseInfo['settings'], oldSet: LSPluginBaseInfo['settings']) => {
//更新されたら
if (newSet !== oldSet) restoreAllNamespaces();
Expand All @@ -48,6 +44,7 @@ const main = () => {




const callback = () => {
//callback関数
observer.disconnect();
Expand Down Expand Up @@ -119,25 +116,7 @@ function abbreviateNamespace(namespaceRef: HTMLElement) {

namespaceRef.dataset.origText = text || "";
namespaceRef.textContent = abbreviatedText;
const enterHandler = () => {
if (restore === false) {
namespaceRef.textContent = namespaceRef.dataset.origText || "";
} else if (restore === true) {
//イベントリスナーを削除
namespaceRef.removeEventListener('mouseenter', enterHandler);
}
};
const leaveHandler = () => {
if (restore === false) {
namespaceRef.textContent = abbreviatedText;
} else if (restore === true) {
//イベントリスナーを削除
namespaceRef.removeEventListener('mouseleave', leaveHandler);
}
};
// Show entire string on hover
namespaceRef.addEventListener('mouseenter', enterHandler);
namespaceRef.addEventListener('mouseleave', leaveHandler);
namespaceRef.classList.add("shortNamespaceTooltip");//CSSでtooltipを表示する
}


Expand Down
29 changes: 29 additions & 0 deletions src/tooltip.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
div#root .shortNamespaceTooltip {
position: relative;
cursor: pointer
}
div#root div#main-content-container .shortNamespaceTooltip::before {
white-space: nowrap
}
div#root .shortNamespaceTooltip::before {
content: attr(data-orig-text);
display: block;
padding: 3px 13px;
background: var(--ls-secondary-background-color);
border-radius: 4px;
font-size: .94em;
top: 0;
left: 0;
z-index: var(--ls-z-index-level-3);
overflow: auto;
margin: -.4em auto
}
div#root .shortNamespaceTooltip:hover::before {
top: 0;
opacity: 1;
display: block;
}
div#root .shortNamespaceTooltip::before {
position: absolute;
display: none
}

0 comments on commit a7c873a

Please sign in to comment.