--Boundary-00=_cBxWAy+g/ezBhJa Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Content-Disposition: inline Hi! I've made a little patch that implements type-ahead find in KHTML. I didn't want to put it in CVS right away as there are still some issues I would like some help and feedback with: - KHTML uses the H, J, K and L keys for scrolling, just like vi. Also the space key is used to scroll down. These keys will undoubtly interfere with type-ahead find. Right now you can disable type-ahead find by defining KHTML_NO_TYPE_AHEAD_FIND, but I guess some dynamic switch would be needed if the patch goes in for people who really like the vi keys. - Pressing F3 won't find the next occurrence of the string you're searching for. Now this is related to the functions findTextBegin() and the old findTextNext() I use. Can someone explain how I use the new API which (hopefully) gets the F3 key to work. (Btw, this problem affects my Google search bar as well) - Currently, the patch will search all text. However, the type-ahead find in Mozilla by default limits itself to links, which is a good idea I think. I'm afraid some extension to the search functions would be needed to support this. Any idea's? Thanks for your help. -- Arend van Beelen jr. http://www.liacs.nl/~dvbeelen Why wait for hell if you can grab it all today? -- Xynobite --Boundary-00=_cBxWAy+g/ezBhJa Content-Type: text/x-diff; charset="us-ascii"; name="type_ahead_find.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="type_ahead_find.patch" ? khtml.katefl ? type_ahead_find.patch ? ecma/xmlhttprequest.lut.h Index: khtmlview.cpp =================================================================== RCS file: /home/kde/kdelibs/khtml/khtmlview.cpp,v retrieving revision 1.622 diff -u -3 -p -u -r1.622 khtmlview.cpp --- khtmlview.cpp 18 Mar 2004 13:44:18 -0000 1.622 +++ khtmlview.cpp 19 Mar 2004 15:08:35 -0000 @@ -305,6 +305,10 @@ public: CaretViewContext *m_caretViewContext; EditorContext *m_editorContext; #endif // KHTML_NO_CARET +#ifndef KHTML_NO_TYPE_AHEAD_FIND + QString findString; + QTimer timer; +#endif // KHTML_NO_TYPE_AHEAD_FIND }; #ifndef QT_NO_TOOLTIP @@ -354,6 +358,10 @@ KHTMLView::KHTMLView( KHTMLPart *part, Q d->tooltip = new KHTMLToolTip( this, d ); #endif +#ifndef KHTML_NO_TYPE_AHEAD_FIND + connect(&d->timer, SIGNAL(timeout()), this, SLOT(findTimeout())); +#endif // KHTML_NO_TYPE_AHEAD_FIND + init(); viewport()->show(); @@ -1033,6 +1041,58 @@ void KHTMLView::keyPressEvent( QKeyEvent return; } +#ifndef KHTML_NO_TYPE_AHEAD_FIND + // type-ahead find aka find-as-you-type + if(_ke->key() >= Key_A && _ke->key() <= Key_Z || _ke->key() == Key_Space) + { + if(d->findString.isEmpty()) + { + m_part->findTextBegin(); + } + + QString newFindString = d->findString + QChar(_ke->key()); + if(m_part->findTextNext(newFindString, true, false, false)) + { + d->findString = newFindString; + m_part->setStatusBarText(i18n("Text found: %1.").arg(newFindString.lower()), KHTMLPart::BarDefaultText); + } + else + { + m_part->setStatusBarText(i18n("Text not found: %1.").arg(newFindString.lower()), KHTMLPart::BarDefaultText); + } + + d->timer.start(3000, true); + _ke->accept(); + return; + } + else if(_ke->key() == Key_BackSpace) + { + d->findString = d->findString.left(d->findString.length() - 1); + + m_part->findTextBegin(); + if(!d->findString.isEmpty()) + { + m_part->findTextNext(d->findString, true, false, false); + m_part->setStatusBarText(i18n("Text found: %1.").arg(d->findString.lower()), KHTMLPart::BarDefaultText); + } + else + { + findTimeout(); + } + + d->timer.start(3000, true); + _ke->accept(); + return; + } + else if(_ke->key() == Key_Escape) + { + findTimeout(); + + _ke->accept(); + return; + } +#endif // KHTML_NO_TYPE_AHEAD_FIND + int offs = (clipper()->height() < 30) ? clipper()->height() : 30; if (_ke->state() & Qt::ShiftButton) switch(_ke->key()) @@ -1179,9 +1239,20 @@ void KHTMLView::keyPressEvent( QKeyEvent _ke->ignore(); return; } + _ke->accept(); } +#ifndef KHTML_NO_TYPE_AHEAD_FIND + +void KHTMLView::findTimeout() +{ + d->findString = ""; + m_part->setStatusBarText(i18n("Find stopped."), KHTMLPart::BarDefaultText); +} + +#endif // KHTML_NO_TYPE_AHEAD_FIND + void KHTMLView::keyReleaseEvent(QKeyEvent *_ke) { if (d->m_caretViewContext && d->m_caretViewContext->keyReleasePending) { Index: khtmlview.h =================================================================== RCS file: /home/kde/kdelibs/khtml/khtmlview.h,v retrieving revision 1.201 diff -u -3 -p -u -r1.201 khtmlview.h --- khtmlview.h 18 Mar 2004 13:41:37 -0000 1.201 +++ khtmlview.h 19 Mar 2004 15:08:35 -0000 @@ -202,6 +202,9 @@ protected slots: private slots: void tripleClickTimeout(); +#ifndef KHTML_NO_TYPE_AHEAD_FIND + void findTimeout(); +#endif // KHTML_NO_TYPE_AHEAD_FIND private: void scheduleRelayout(khtml::RenderObject* clippedObj=0); --Boundary-00=_cBxWAy+g/ezBhJa--