Link to archived email:

https://lists.gnu.org/archive/html/bug-texinfo/2022-11/msg00239.html

On Wed, Nov 30, 2022 at 05:37:43PM -0800, Per Bothner wrote:
> On 11/30/22 06:44, Gavin Smith wrote:
> > There are a couple of other less important problems.  You can see
> > them at https://www.gnu.org/software/texinfo/manual/texinfo-html/index.html:
> > 
> > * A tooltip pops up saying "General Index (GNU Texinfo 7.0.1)" at the
> >    table of contents.
> > * The page title (displayed in a browser tab or the window title bar) at
> >    the Top node is "General Index (GNU Texinfo 7.0.1)".  However, go to
> >    either of the index nodes and the title becomes "Top (GNU Texinfo 
> > 7.0.1)".

We hardly ever touch info.js but I thought I would have a go at fixing
these old problems, after updating info.js for a change in the HTML
index output.  (I find these kinds of problems aren't insoluble, they
just take a large amount of time to work out, and there isn't necessarily
enough time for all such problems - this took me about three and a half
hours, even though the resulting patch is quite small.)

> 
> ...
>
> The actual problem seems to be that state.current points to
> the Top page when we loading the indexes.  Thus we are trying to set the 
> "title"
> attributes of the Top node when it should be one of the Index nodes.
> 
> The logic depends on the "current" node -but that isn't always correct when 
> dealing
> with messages from sub-windows. Specifically, the sub-page (iframe) sends a 
> "window-title"
> message to the parent window. The title should be set on the node 
> corresponding to
> the sending sub-window. This is not necsssarily the same as the "current" 
> window.
> We can modify state.current before loading the sub-window, and it will 
> *probably*
> work correctly, but selecting the affected node from the sub-window seems more
> correct than assuming the "current" node.
>
 
Your (Per's) analysis was correct.  I have attempted a fix, which relied
on the fact that we could get the name of the node from within the iframe,
then we pass this name in a message to the controlling window.  It's
possible then to update the title on the correct <div> element.

> I find the "state machine" logic of info.js quite hard to deal with,
> and I confess I don't understand what problem it is intended to solve.
> I don't think it's the right logic for dealing with "window-title" messages.

I didn't understand it either - the code jumps about all over the place
with multiple levels of indirection.  There is the "updater" which
updates the state, but much of the real work is done on "listeners"
which respond to changes in the state.  It is possible that the "updater"
and "listeners" could be folded together.

Here's the diff:

commit a2cf8f87b8cd5a894f4ee19ef0eac4b738799d56
Author: Gavin Smith <gavinsmith0...@gmail.com>
Date:   2025-07-29 03:24:35 +0100

    Remove annoying tooltip for Top node with info.js
    
    (updater): Add new action type "window-title-of-linkid".
    Not much is done in this function.
    (Pages.prototype.render): This called indirectly and is where a
    lot of the real processing is done after the main "store"
    receives an action.  Handle "window-title-of-linkid" action.
    
    (init_iframe) <on_load>: Initiate "window-title-of-linkid"
    action.  This contains the ID of the node as well as the new
    title to use, leading the "title" to be updated on the correct
    <div>.  We get the ID from the window location.  This is more
    reliable than the "window-title" action as that seemed to try
    to use whichever node was currently being displayed, which was
    wrong when the index nodes were read in at start up.  This lead
    to a "title" attribute being set incorrectly on some element in
    the Top node, which would lead to a tool-tip appearing with the
    title of whichever Index node was read in last.
    
    (actions) (window_title_of_linkid): Add for "window-title-of-linkid"
    message.

diff --git a/ChangeLog b/ChangeLog
index b85ef8c814..71c5100a84 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,27 @@
+2025-07-28  Gavin Smith <gavinsmith0...@gmail.com>
+
+       Remove annoying tooltip for Top node with info.js
+       
+       (updater): Add new action type "window-title-of-linkid".
+       Not much is done in this function.
+       (Pages.prototype.render): This called indirectly and is where a
+       lot of the real processing is done after the main "store"
+       receives an action.  Handle "window-title-of-linkid" action.
+       
+       (init_iframe) <on_load>: Initiate "window-title-of-linkid"
+       action.  This contains the ID of the node as well as the new
+       title to use, leading the "title" to be updated on the correct
+       <div>.  We get the ID from the window location.  This is more
+       reliable than the "window-title" action as that seemed to try
+       to use whichever node was currently being displayed, which was
+       wrong when the index nodes were read in at start up.  This lead
+       to a "title" attribute being set incorrectly on some element in
+       the Top node, which would lead to a tool-tip appearing with the
+       title of whichever Index node was read in last.
+
+       (actions) (window_title_of_linkid): Add for "window-title-of-linkid"
+       message.
+
 2025-07-28  Gavin Smith <gavinsmith0...@gmail.com>
 
        * info.js (init_sidebar) <add_header>:
diff --git a/js/info.js b/js/info.js
index 076ce0db43..391180e147 100644
--- a/js/info.js
+++ b/js/info.js
@@ -205,6 +205,10 @@ var actions = {
     return { type: "window-title", title: title };
   },
 
+  window_title_of_linkid: function (title, linkid) {
+    return { type: "window-title-of-linkid", title: title, linkid: linkid };
+  },
+
   /** Search EXP in the whole manual.
       @arg {RegExp|string} exp*/
   search: function (exp) {
@@ -470,6 +474,10 @@ updater (state, action)
         result.window_title = action.title;
         return result;
       }
+    case "window-title-of-linkid":
+      {
+        return result;
+      }
     case "warning":
       {
         result.warning = action.msg;
@@ -932,12 +940,19 @@ init_index_page ()
         this.prev_id = state.current;
         this.prev_div = div;
       }
-      if (state.action.type === "window-title") {
-          div.setAttribute("title", state.action.title);
+    if (state.action.type === "window-title")
+      {
+        div.setAttribute("title", state.action.title);
+      }
+    else if (state.action.type === "window-title-of-linkid")
+      {
+        var update_div =  document.getElementById (state.action.linkid);
+        if (update_div)
+          update_div.setAttribute("title", state.action.title);
       }
-      let title = div.getAttribute("title") || this.main_title;
-      if (title && document.title !== title)
-          document.title = title;
+    let title = div.getAttribute("title") || this.main_title;
+    if (title && document.title !== title)
+        document.title = title;
 
     if (state.search
         && (this.prev_search !== state.search)
@@ -1492,7 +1507,7 @@ init_iframe ()
     links[linkid] = navigation_links (document);
     store.dispatch (actions.cache_links (links));
     if (document.title)
-       store.dispatch (actions.window_title (document.title));
+      store.dispatch (actions.window_title_of_linkid (document.title, linkid));
 
     if (linkid_contains_index (linkid))
       {


Reply via email to