exporting patch:
# HG changeset patch
# User Daniel J Sebald <daniel.sebald@ieee.org>
# Date 1522946158 18000
#      Thu Apr 05 11:35:58 2018 -0500
# Branch stable
# Node ID da9aa812c45199482d1fa6d5e4a2406723d42a96
# Parent  435645a627ddcde4780227ba1e308f8392245ed9
Add standard key bindings and actions to in-page Documentation find (bug #53006)

* documentation.cc (documentation::documentation): Connect m_doc_browser
  cursor position change signal to slot that records position.  Connect
  m_find_line_edit text-edited signal to find_forward_from_anchor() to provide
  search-while-type.  Replace QKeySequence "Ctrl+F" definition with Qt's
  pre-defined QKeySequence::Find.  Change the context of the key press from
  Qt::WidgetWithChildrenShortcut to the broader Qt::WindowShortcut and rename
  the sequence show_shortcut.  Connect show_shortcut object's activated()
  signal to parent widget's show() slot and to m_find_line_edit's selectAll()
  and setFocus() slots.  Create a hide_shortcut QShortcut with QKeySequence
  "Escape" and connect its activated() signal to parent widget's hide() slot
  and m_doc_browser's setFocus() slot.  Create a findnext_shortcut and connect
  its activated() signal to the documentation class's find_forward() slot.
  Create a findnext_shortcut and connect its activated() signal to the
  documentation class's find_backward() slot.  Set m_search_anchor_position to
  zero.
  (documentation::find_forward): After doing the find operation, record the
  current "anchor" position of the QTextEdit's cursor position.
  (documentation::find_backward): Ditto.
  (documentation::toggle_hidden_find): Removed.
  (documentation::find_forward_from_anchor): Added.  For search-while-type,
  set the QTextEdit's cursor position back to the anchor position before
  calling the find() routine and allow "undoing" the search-while-type.
  (documentation::record_anchor_position): Added.  Record the QTextEdit
  cursor's current position.
  (documentation::handle_cursor_position_change): Added.  Upon the QTextEdit's
  cursor change, call record_anchor_position() but only if that position change
  was due to user action within the window.

* documentation.h (documentation:public QSplitter): Add new integer member
  variable m_search_anchor_position.
  (documentation::find_forward_from_anchor): Added.  Slot declaration.
  (documentation::record_anchor_position): Ditto.
  (documentation::handle_cursor_position_change): Ditto.

diff --git a/libgui/src/documentation.cc b/libgui/src/documentation.cc
--- a/libgui/src/documentation.cc
+++ b/libgui/src/documentation.cc
@@ -98,12 +98,16 @@ namespace octave
     // The browser
     QWidget *browser_find = new QWidget (this);
     m_doc_browser = new documentation_browser (m_help_engine, browser_find);
+    connect (m_doc_browser, SIGNAL (cursorPositionChanged (void)),
+             this, SLOT(handle_cursor_position_change (void)));
 
     QWidget *find_footer = new QWidget (browser_find);
     QLabel *find_label = new QLabel (tr ("Find:"), find_footer);
     m_find_line_edit = new QLineEdit (find_footer);
     connect (m_find_line_edit, SIGNAL (returnPressed (void)),
              this, SLOT(find_forward (void)));
+    connect (m_find_line_edit, SIGNAL (textEdited (const QString&)),
+             this, SLOT(find_forward_from_anchor (const QString&)));
     QToolButton *forward_button = new QToolButton (find_footer);
     forward_button->setText (tr ("Search forward"));
     forward_button->setToolTip (tr ("Search forward"));
@@ -129,11 +133,30 @@ namespace octave
     v_box_browser_find->addWidget (find_footer);
     browser_find->setLayout (v_box_browser_find);
 
-    QShortcut *shortcut = new QShortcut(QKeySequence(tr("Ctrl+F")), browser_find);
-    shortcut->setContext(Qt::WidgetWithChildrenShortcut);
-    connect (shortcut, SIGNAL (activated (void)),
-             this, SLOT(toggle_hidden_find (void)));
+    QShortcut *show_shortcut = new QShortcut (QKeySequence (QKeySequence::Find), browser_find);
+    show_shortcut->setContext(Qt::WindowShortcut);
+    connect (show_shortcut, SIGNAL (activated (void)),
+             m_find_line_edit->parentWidget (), SLOT (show (void)));
+    connect (show_shortcut, SIGNAL (activated (void)),
+             m_find_line_edit, SLOT (selectAll (void)));
+    connect (show_shortcut, SIGNAL (activated (void)),
+             m_find_line_edit, SLOT (setFocus (void)));
+    QShortcut *hide_shortcut = new QShortcut (QKeySequence (tr ("Escape")), m_find_line_edit);
+    hide_shortcut->setContext(Qt::WindowShortcut);
+    connect (hide_shortcut, SIGNAL (activated (void)),
+             m_find_line_edit->parentWidget (), SLOT(hide (void)));
+    connect (hide_shortcut, SIGNAL (activated (void)),
+             m_doc_browser, SLOT (setFocus (void)));
+    QShortcut *findnext_shortcut = new QShortcut (QKeySequence (QKeySequence::FindNext), browser_find);
+    findnext_shortcut->setContext(Qt::WindowShortcut);
+    connect (findnext_shortcut, SIGNAL (activated (void)),
+             this, SLOT(find_forward (void)));
+    QShortcut *findprev_shortcut = new QShortcut (QKeySequence (QKeySequence::FindPrevious), browser_find);
+    findprev_shortcut->setContext(Qt::WindowShortcut);
+    connect (findprev_shortcut, SIGNAL (activated (void)),
+             this, SLOT(find_backward (void)));
     find_footer->hide ();
+    m_search_anchor_position = 0;
 
     // Layout contents, index and search
     QTabWidget *navi = new QTabWidget (this);
@@ -321,6 +344,7 @@ namespace octave
       return;
 
     m_doc_browser->find (m_find_line_edit->text ());
+    record_anchor_position ();
   }
 
   void documentation::find_backward (void)
@@ -329,19 +353,35 @@ namespace octave
       return;
 
     m_doc_browser->find (m_find_line_edit->text (), QTextDocument::FindBackward);
+    record_anchor_position ();
   }
 
-  void documentation::toggle_hidden_find (void)
+  void documentation::find_forward_from_anchor (const QString& text)
   {
     if (! m_help_engine)
       return;
 
-    m_find_line_edit->parentWidget ()->
-        setHidden (! m_find_line_edit->parentWidget ()->isHidden ());
-    if (m_find_line_edit->parentWidget ()->isHidden ())
-      m_doc_browser->setFocus ();
-    else
-      m_find_line_edit->setFocus ();
+    QTextCursor textcur = m_doc_browser->textCursor ();
+    textcur.setPosition (m_search_anchor_position);
+    m_doc_browser->setTextCursor (textcur);
+    m_doc_browser->find (text);
+  }
+
+  void documentation::record_anchor_position (void)
+  {
+    if (! m_help_engine)
+      return;
+
+    m_search_anchor_position = m_doc_browser->textCursor ().position ();
+  }
+
+  void documentation::handle_cursor_position_change (void)
+  {
+    if (! m_help_engine)
+      return;
+
+    if (m_doc_browser->hasFocus ())
+      record_anchor_position ();
   }
 
   void documentation::registerDoc (const QString& qch)
diff --git a/libgui/src/documentation.h b/libgui/src/documentation.h
--- a/libgui/src/documentation.h
+++ b/libgui/src/documentation.h
@@ -88,13 +88,16 @@ namespace octave
     void filter_update_history (void);
     void find_forward (void);
     void find_backward (void);
-    void toggle_hidden_find (void);
+    void find_forward_from_anchor (const QString& text);
+    void record_anchor_position (void);
+    void handle_cursor_position_change (void);
 
   private:
 
     QHelpEngine *m_help_engine;
     documentation_browser *m_doc_browser;
     QLineEdit *m_find_line_edit;
+    int m_search_anchor_position;
     QComboBox *m_filter;
     QString m_collection;
 
