Changeset View
Changeset View
Standalone View
Standalone View
src/completion/katecompletionmodel.cpp
Show First 20 Lines • Show All 1851 Lines • ▼ Show 20 Line(s) | |||||
1852 | bool KateCompletionModel::shouldMatchHideCompletionList() const | 1852 | bool KateCompletionModel::shouldMatchHideCompletionList() const | ||
1853 | { | 1853 | { | ||
1854 | 1854 | | |||
1855 | // @todo Make this faster | 1855 | // @todo Make this faster | ||
1856 | 1856 | | |||
1857 | bool doHide = false; | 1857 | bool doHide = false; | ||
1858 | CodeCompletionModel *hideModel = nullptr; | 1858 | CodeCompletionModel *hideModel = nullptr; | ||
1859 | 1859 | | |||
1860 | foreach (Group *group, m_rowTable) | 1860 | for (const Group *group : qAsConst(m_rowTable)) { | ||
1861 | foreach (const Item &item, group->filtered) | 1861 | for (const Item &item : qAsConst(group->filtered)) { | ||
1862 | if (item.haveExactMatch()) { | 1862 | if (item.haveExactMatch() || item.haveContainsMatch()) { | ||
1863 | KTextEditor::CodeCompletionModelControllerInterface *iface3 = dynamic_cast<KTextEditor::CodeCompletionModelControllerInterface *>(item.sourceRow().first); | 1863 | KTextEditor::CodeCompletionModelControllerInterface *iface3 = dynamic_cast<KTextEditor::CodeCompletionModelControllerInterface *>(item.sourceRow().first); | ||
1864 | bool hide = false; | 1864 | bool hide = false; | ||
1865 | if (!iface3) { | 1865 | if (!iface3) { | ||
1866 | hide = true; | 1866 | hide = true; | ||
1867 | } | 1867 | } | ||
1868 | if (iface3 && iface3->matchingItem(item.sourceRow().second) == KTextEditor::CodeCompletionModelControllerInterface::HideListIfAutomaticInvocation) { | 1868 | if (iface3 && iface3->matchingItem(item.sourceRow().second) == KTextEditor::CodeCompletionModelControllerInterface::HideListIfAutomaticInvocation) { | ||
1869 | hide = true; | 1869 | hide = true; | ||
1870 | } | 1870 | } | ||
1871 | if (hide) { | 1871 | if (hide) { | ||
1872 | doHide = true; | 1872 | doHide = true; | ||
1873 | hideModel = item.sourceRow().first; | 1873 | hideModel = item.sourceRow().first; | ||
1874 | } | 1874 | } | ||
1875 | } | 1875 | } | ||
1876 | } | ||||
1877 | } | ||||
1876 | 1878 | | |||
1877 | if (doHide) { | 1879 | if (doHide) { | ||
1878 | // Check if all other visible items are from the same model | 1880 | // Check if all other visible items are from the same model | ||
1879 | foreach (Group *group, m_rowTable) | 1881 | for (const Group *group : qAsConst(m_rowTable)) { | ||
1880 | foreach (const Item &item, group->filtered) | 1882 | for (const Item &item : qAsConst(group->filtered)) { | ||
1881 | if (item.sourceRow().first != hideModel) { | 1883 | if (item.sourceRow().first != hideModel) { | ||
1882 | return false; | 1884 | return false; | ||
1883 | } | 1885 | } | ||
1884 | } | 1886 | } | ||
1887 | } | ||||
1888 | } | ||||
1885 | 1889 | | |||
1886 | return doHide; | 1890 | return doHide; | ||
1887 | } | 1891 | } | ||
1888 | 1892 | | |||
1889 | static inline QChar toLowerIfInsensitive(QChar c, Qt::CaseSensitivity caseSensitive) | 1893 | static inline QChar toLowerIfInsensitive(QChar c, Qt::CaseSensitivity caseSensitive) | ||
1890 | { | 1894 | { | ||
1891 | return (caseSensitive == Qt::CaseInsensitive) ? c.toLower() : c; | 1895 | return (caseSensitive == Qt::CaseInsensitive) ? c.toLower() : c; | ||
1892 | } | 1896 | } | ||
▲ Show 20 Lines • Show All 99 Lines • ▼ Show 20 Line(s) | 1982 | { | |||
1992 | return false; | 1996 | return false; | ||
1993 | } | 1997 | } | ||
1994 | 1998 | | |||
1995 | KateCompletionModel::Item::MatchType KateCompletionModel::Item::match() | 1999 | KateCompletionModel::Item::MatchType KateCompletionModel::Item::match() | ||
1996 | { | 2000 | { | ||
1997 | QString match = model->currentCompletion(m_sourceRow.first); | 2001 | QString match = model->currentCompletion(m_sourceRow.first); | ||
1998 | 2002 | | |||
1999 | m_haveExactMatch = false; | 2003 | m_haveExactMatch = false; | ||
2004 | m_haveContainsMatch = false; | ||||
2000 | 2005 | | |||
2001 | // Hehe, everything matches nothing! (ie. everything matches a blank string) | 2006 | // Hehe, everything matches nothing! (ie. everything matches a blank string) | ||
2002 | if (match.isEmpty()) { | 2007 | if (match.isEmpty()) { | ||
2003 | return PerfectMatch; | 2008 | return PerfectMatch; | ||
2004 | } | 2009 | } | ||
2005 | if (m_nameColumn.isEmpty()) { | 2010 | if (m_nameColumn.isEmpty()) { | ||
2006 | return NoMatch; | 2011 | return NoMatch; | ||
2007 | } | 2012 | } | ||
2008 | 2013 | | |||
2009 | matchCompletion = (m_nameColumn.startsWith(match, model->matchCaseSensitivity()) ? StartsWithMatch : NoMatch); | 2014 | matchCompletion = (m_nameColumn.startsWith(match, model->matchCaseSensitivity()) ? StartsWithMatch : NoMatch); | ||
2010 | if (matchCompletion == NoMatch) { | 2015 | if (matchCompletion == NoMatch) { | ||
2011 | // if no match, try for "contains" | 2016 | // if no match, try for "contains" | ||
2012 | // Only match when the occurrence is at a "word" beginning, marked by | 2017 | // Only match when the occurrence is at a "word" beginning, marked by | ||
2013 | // an underscore or a capital. So Foo matches BarFoo and Bar_Foo, but not barfoo. | 2018 | // an underscore or a capital. So Foo matches BarFoo and Bar_Foo, but not barfoo. | ||
2014 | // Starting at 1 saves looking at the beginning of the word, that was already checked above. | 2019 | // Starting at 1 saves looking at the beginning of the word, that was already checked above. | ||
2015 | if (containsAtWordBeginning(m_nameColumn, match, model->matchCaseSensitivity())) { | 2020 | if (containsAtWordBeginning(m_nameColumn, match, model->matchCaseSensitivity())) { | ||
2016 | matchCompletion = ContainsMatch; | 2021 | matchCompletion = ContainsMatch; | ||
2022 | m_haveContainsMatch = true; | ||||
2017 | } | 2023 | } | ||
2018 | } | 2024 | } | ||
2019 | 2025 | | |||
2020 | if (matchCompletion == NoMatch && !m_nameColumn.isEmpty() && !match.isEmpty()) { | 2026 | if (matchCompletion == NoMatch && !m_nameColumn.isEmpty() && !match.isEmpty()) { | ||
2021 | // if still no match, try abbreviation matching | 2027 | // if still no match, try abbreviation matching | ||
2022 | if (matchesAbbreviation(m_nameColumn, match, model->matchCaseSensitivity())) { | 2028 | if (matchesAbbreviation(m_nameColumn, match, model->matchCaseSensitivity())) { | ||
2023 | matchCompletion = AbbreviationMatch; | 2029 | matchCompletion = AbbreviationMatch; | ||
brauch: Maybe you want to set the flag here too? | |||||
brauch: Actually no, probably not. ;) | |||||
2024 | } | 2030 | } | ||
2025 | } | 2031 | } | ||
2026 | 2032 | | |||
2027 | if (matchCompletion && match.length() == m_nameColumn.length()) { | 2033 | if (matchCompletion && match.length() == m_nameColumn.length()) { | ||
2028 | if (model->matchCaseSensitivity() == Qt::CaseInsensitive && | 2034 | if (model->matchCaseSensitivity() == Qt::CaseInsensitive && | ||
2029 | model->exactMatchCaseSensitivity() == Qt::CaseSensitive && | 2035 | model->exactMatchCaseSensitivity() == Qt::CaseSensitive && | ||
2030 | !m_nameColumn.startsWith(match, Qt::CaseSensitive)) { | 2036 | !m_nameColumn.startsWith(match, Qt::CaseSensitive)) { | ||
2031 | return matchCompletion; | 2037 | return matchCompletion; | ||
▲ Show 20 Lines • Show All 401 Lines • Show Last 20 Lines |
Maybe you want to set the flag here too?