@@ -8,6 +8,10 @@ import appContext from "../components/app_context.js";
88import type FNote from "../entities/fnote.js" ;
99import { t } from "./i18n.js" ;
1010
11+ // Track all elements that open tooltips
12+ let openTooltipElements : JQuery < HTMLElement > [ ] = [ ] ;
13+ let dismissTimer : ReturnType < typeof setTimeout > ;
14+
1115function setupGlobalTooltip ( ) {
1216 $ ( document ) . on ( "mouseenter" , "a" , mouseEnterHandler ) ;
1317
@@ -23,7 +27,12 @@ function setupGlobalTooltip() {
2327}
2428
2529function dismissAllTooltips ( ) {
26- $ ( ".note-tooltip" ) . remove ( ) ;
30+ clearTimeout ( dismissTimer ) ;
31+ openTooltipElements . forEach ( $el => {
32+ $el . tooltip ( "dispose" ) ;
33+ $el . removeAttr ( "aria-describedby" ) ;
34+ } ) ;
35+ openTooltipElements = [ ] ;
2736}
2837
2938function setupElementTooltip ( $el : JQuery < HTMLElement > ) {
@@ -86,8 +95,8 @@ async function mouseEnterHandler(this: HTMLElement) {
8695 // we need to check if we're still hovering over the element
8796 // since the operation to get tooltip content was async, it is possible that
8897 // we now create tooltip which won't close because it won't receive mouseleave event
89- if ( $ ( this ) . filter ( ":hover" ) . length > 0 ) {
90- $ ( this ) . tooltip ( {
98+ if ( $link . filter ( ":hover" ) . length > 0 ) {
99+ $link . tooltip ( {
91100 container : "body" ,
92101 // https://github.com/zadam/trilium/issues/2794 https://github.com/zadam/trilium/issues/2988
93102 // with bottom this flickering happens a bit less
@@ -103,7 +112,9 @@ async function mouseEnterHandler(this: HTMLElement) {
103112 } ) ;
104113
105114 dismissAllTooltips ( ) ;
106- $ ( this ) . tooltip ( "show" ) ;
115+ $link . tooltip ( "show" ) ;
116+
117+ openTooltipElements . push ( $link ) ;
107118
108119 // Dismiss the tooltip immediately if a link was clicked inside the tooltip.
109120 $ ( `.${ tooltipClass } a` ) . on ( "click" , ( e ) => {
@@ -115,15 +126,16 @@ async function mouseEnterHandler(this: HTMLElement) {
115126 // click on links within tooltip etc. without tooltip disappearing
116127 // - once the user moves the cursor away from both link and the tooltip, hide the tooltip
117128 const checkTooltip = ( ) => {
118- if ( ! $ ( this ) . filter ( ":hover" ) . length && ! $ ( `.${ linkId } :hover` ) . length ) {
129+
130+ if ( ! $link . filter ( ":hover" ) . length && ! $ ( `.${ linkId } :hover` ) . length ) {
119131 // cursor is neither over the link nor over the tooltip, user likely is not interested
120132 dismissAllTooltips ( ) ;
121133 } else {
122- setTimeout ( checkTooltip , 1000 ) ;
134+ dismissTimer = setTimeout ( checkTooltip , 1000 ) ;
123135 }
124136 } ;
125137
126- setTimeout ( checkTooltip , 1000 ) ;
138+ dismissTimer = setTimeout ( checkTooltip , 1000 ) ;
127139 }
128140}
129141
@@ -176,7 +188,25 @@ function renderFootnote($link: JQuery<HTMLElement>, url: string) {
176188 . closest ( ".footnote-item" ) // find the parent container of the footnote
177189 . find ( ".footnote-content" ) ; // find the actual text content of the footnote
178190
179- return $footnoteContent . html ( ) || "" ;
191+ const isEditable = $link . closest ( ".ck-content" ) . hasClass ( "note-detail-editable-text-editor" ) ;
192+ if ( isEditable ) {
193+ /* Remove widget buttons for tables, formulas, and images in editable notes. */
194+ $footnoteContent . find ( '.ck-widget__selection-handle' ) . remove ( ) ;
195+ $footnoteContent . find ( '.ck-widget__type-around' ) . remove ( ) ;
196+ $footnoteContent . find ( '.ck-widget__resizer' ) . remove ( ) ;
197+
198+ /* Handling in-line math formulas */
199+ $footnoteContent . find ( '.ck-math-tex.ck-math-tex-inline.ck-widget' ) . each ( function ( ) {
200+ const $katex = $ ( this ) . find ( '.katex' ) . first ( ) ;
201+ if ( $katex . length ) {
202+ $ ( this ) . replaceWith ( $ ( '<span class="math-tex"></span>' ) . append ( $ ( '<span></span>' ) . append ( $katex . clone ( ) ) ) ) ;
203+ }
204+ } ) ;
205+ }
206+
207+ let footnoteContent = $footnoteContent . html ( ) ;
208+ footnoteContent = `<div class="ck-content">${ footnoteContent } </div>`
209+ return footnoteContent || "" ;
180210}
181211
182212export default {
0 commit comments