forked from qt-creator/qt-creator
Help: Add fallback word lookup for context help to base text editor
If we do not have a hover handler, or that did not produce any result, use the word under cursor and try with that. This adds at least some help fallback mechanism to all text editors, e.g. we get some context help (though a bit crude) for Pyside "for free". Change-Id: I1b6d91ad6f46bfd12e242b1aec9f4fcadae23403 Reviewed-by: Cristian Maureira-Fredes <cristian.maureira-fredes@qt.io> Reviewed-by: David Schulz <david.schulz@qt.io>
This commit is contained in:
@@ -8085,12 +8085,21 @@ void BaseTextEditor::setContextHelp(const HelpItem &item)
|
||||
|
||||
void TextEditorWidget::contextHelpItem(const IContext::HelpCallback &callback)
|
||||
{
|
||||
const QString fallbackWordUnderCursor = Text::wordUnderCursor(textCursor());
|
||||
if (d->m_contextHelpItem.isEmpty() && !d->m_hoverHandlers.isEmpty()) {
|
||||
d->m_hoverHandlers.first()->contextHelpId(this,
|
||||
Text::wordStartCursor(textCursor()).position(),
|
||||
callback);
|
||||
[fallbackWordUnderCursor, callback](const HelpItem &item) {
|
||||
if (item.isEmpty())
|
||||
callback(fallbackWordUnderCursor);
|
||||
else
|
||||
callback(item);
|
||||
});
|
||||
} else {
|
||||
callback(d->m_contextHelpItem);
|
||||
if (d->m_contextHelpItem.isEmpty())
|
||||
callback(fallbackWordUnderCursor);
|
||||
else
|
||||
callback(d->m_contextHelpItem);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user