Commit f633da0d authored by Milian Wolff's avatar Milian Wolff

Fix up/down keyboard navigation for 'Show documentation' links

The navigation widget relies on a crude HTML "parser" which
counts "lines". Yes. Only '<br/>' is considered a newline, even
though due to line wrapping we can have obviously more lines. Well,
without rewriting all of that, also count '</p>' as introducing a
new line. This allows us to jump to the 'Show documentation' link
then.

To make this work reliably, we also fixup the generated HTML to be
valid and not nest '<p>' tags. Furthermore, we prevent the ugly
line indication marker '<->' being shown when we try to down past
the last paragraph.
parent 38e910ba
......@@ -88,10 +88,10 @@ QString AbstractDeclarationNavigationContext::html(bool shorten)
clear();
AbstractNavigationContext::html(shorten);
modifyHtml() += QLatin1String("<html><body><p>");
modifyHtml() += QLatin1String("<html><body>");
if (!d->m_declaration.data()) {
modifyHtml() += i18n("<br /> lost declaration <br />");
modifyHtml() += QLatin1String("<p>") + i18n("lost declaration") + QLatin1String("</p></body></html>");
return currentHtml();
}
......@@ -103,6 +103,8 @@ QString AbstractDeclarationNavigationContext::html(bool shorten)
QExplicitlySharedDataPointer<IDocumentation> doc;
modifyHtml() += QStringLiteral("<p>");
if (!shorten) {
doc = ICore::self()->documentationController()->documentationForDeclaration(d->m_declaration.data());
......@@ -318,12 +320,12 @@ QString AbstractDeclarationNavigationContext::html(bool shorten)
modifyHtml() += QStringLiteral(" "); //The action name _must_ stay "show_uses", since that is also used from outside
makeLink(i18n("Show uses"), QStringLiteral("show_uses"),
NavigationAction(d->m_declaration, NavigationAction::NavigateUses));
}
modifyHtml() += QStringLiteral("</p>");
QByteArray declarationComment = d->m_declaration->comment();
if (!shorten && (!declarationComment.isEmpty() || doc)) {
modifyHtml() += QStringLiteral("<p>");
if (doc) {
QString comment = doc->description();
connect(
......@@ -345,8 +347,7 @@ QString AbstractDeclarationNavigationContext::html(bool shorten)
comment = comment.toHtmlEscaped();
comment.replace(QLatin1Char('\n'), QLatin1String("<br />")); //Replicate newlines in html
}
modifyHtml() += commentHighlight(comment);
modifyHtml() += QStringLiteral("</p>");
modifyHtml() += QLatin1String("<p>") + commentHighlight(comment) + QLatin1String("</p>");
}
}
......@@ -361,9 +362,7 @@ QString AbstractDeclarationNavigationContext::html(bool shorten)
modifyHtml() += QStringLiteral("</p>");
}
//modifyHtml() += "<br />";
modifyHtml() += QLatin1String("</p></body></html>");
modifyHtml() += QLatin1String("</body></html>");
return currentHtml();
}
......
......@@ -281,6 +281,7 @@ void AbstractNavigationContext::down()
int fromLine = d->m_currentPositionLine;
// try to select the next link within our lineJump distance
if (d->m_selectedLink >= 0 && d->m_selectedLink < d->m_linkCount) {
if (fromLine == -1)
fromLine = d->m_linkLines[d->m_selectedLink];
......@@ -293,13 +294,18 @@ void AbstractNavigationContext::down()
}
}
}
if (fromLine == d->m_currentLine - 1) // nothing to do, we are at the end of the document
return;
// scroll down by applying the lineJump
if (fromLine == -1)
fromLine = 0;
d->m_currentPositionLine = fromLine + lineJump;
if (d->m_currentPositionLine > d->m_currentLine)
d->m_currentPositionLine = d->m_currentLine;
if (d->m_currentPositionLine >= d->m_currentLine)
d->m_currentPositionLine = d->m_currentLine - 1;
}
void AbstractNavigationContext::up()
......@@ -326,7 +332,7 @@ void AbstractNavigationContext::up()
}
if (fromLine == -1)
fromLine = d->m_currentLine;
fromLine = d->m_currentLine - 1;
d->m_currentPositionLine = fromLine - lineJump;
if (d->m_currentPositionLine < 0)
......@@ -484,7 +490,7 @@ static QStringList splitAndKeep(QString str, const QRegExp& regExp)
void AbstractNavigationContext::addHtml(const QString& html)
{
QRegExp newLineRegExp(QStringLiteral("<br>|<br */>"));
QRegExp newLineRegExp(QStringLiteral("<br>|<br */>|</p>"));
foreach (const QString& line, splitAndKeep(html, newLineRegExp)) {
d->m_currentText += line;
if (line.indexOf(newLineRegExp) != -1) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment