Skip to content

Commit

Permalink
search combinator selectors when looking for a class [deploy]
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinhendricks committed Dec 11, 2023
1 parent 570d913 commit 88d1036
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 2 deletions.
2 changes: 2 additions & 0 deletions ChangeLog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ pre-2.x.x
- add ability to change keyboard focus using keyboard shortcuts or menus
to BookBrowser, Preview, CodeView, ClipsWindow, and TableOfContents Windows
- preserve Media Overlay Active Classes when deleting unused classes
- Goto Link Or Style (or Ctrl-Clicking on a class will now search selectors
with combinators if notthing found in normal css classes

Bug Fixes
- patch Qt6.5.3 to avoid transient child window resize bug on Windows
Expand Down
22 changes: 21 additions & 1 deletion src/MainUI/MainWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2224,7 +2224,27 @@ void MainWindow::GoToLinkedStyleDefinition(const QString &element_name, const QS
}
}
}

// if nothing found try one last time looking in selectors with combinators for a close match
if (!found_match) {
QString sel1 = element_name + "." + style_class_name + " ";
QString sel2 = "." + style_class_name + " ";
foreach(QString bookpath, stylesheets) {
Resource * resource = m_Book->GetFolderKeeper()->GetResourceByBookPath(bookpath);
CSSResource *css_resource = qobject_cast<CSSResource*>( resource );
if (css_resource) {
CSSInfo css_info(css_resource->GetText());
QList<CSSInfo::CSSSelector*> combinators = css_info.getAllSelectorsWithCombinators();
foreach(CSSInfo::CSSSelector* selector, combinators) {
QString asel = selector->text;
if (asel.startsWith(sel1) || asel.startsWith(sel2)) {
m_TabManager->OpenResource(css_resource, -1, selector->pos);
found_match = true;
break;
}
}
}
}
}
if (!found_match) {
QString display_name;

Expand Down
14 changes: 14 additions & 0 deletions src/Parsers/CSSInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,20 @@ CSSInfo::CSSSelector *CSSInfo::getCSSSelectorForElementClass(const QString &elem
}


QList<CSSInfo::CSSSelector *> CSSInfo::getAllSelectorsWithCombinators()
{
QList<CSSInfo::CSSSelector *> matches;
foreach(CSSInfo::CSSSelector * cssSelector, m_CSSSelectors) {
QString asel = cssSelector->text;
if (asel.contains(' ') || asel.contains('>') ||
asel.contains('~') || asel.contains('+')) {
matches.append(cssSelector);
}
}
return matches;
}


QList<CSSInfo::CSSSelector *> CSSInfo::getAllCSSSelectorsForElementClass(const QString &elementName, const QString &className)
{
QList<CSSInfo::CSSSelector *> matches;
Expand Down
4 changes: 3 additions & 1 deletion src/Parsers/CSSInfo.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/************************************************************************
**
** Copyright (C) 2016-2022 Kevin B. Hendricks, Stratford, ON, Canada
** Copyright (C) 2016-2023 Kevin B. Hendricks, Stratford, ON, Canada
** Copyright (C) 2012 John Schember <[email protected]>
** Copyright (C) 2012 Dave Heiland
** Copyright (C) 2012 Grant Drake
Expand Down Expand Up @@ -55,6 +55,8 @@ class CSSInfo : public QObject

QList<CSSSelector*> getAllSelectors();

QList<CSSSelector*> getAllSelectorsWithCombinators();

/**
* Return selectors subset for only class based CSS declarations.
*/
Expand Down

0 comments on commit 88d1036

Please sign in to comment.