Skip to content

Add "Match whole word" button in Search plugin

Glebs Ivanovskis requested to merge i-ky/kate:whole-word-search into master

When searching across source code it often helps to match case sensitively and restrict results that match whole words. There is already a toggle for case sensitivity, but to perform the whole word match one needs to enable regular expressions and manually wrapping search query with word boundary assertions. This seems too complicated, especially considering that sometimes search query needs escaping.

This merge request enhances Search plugin with functionality to match whole words. It is inspired by KTextEditor's Find & Replace form:

    // abuse regex for whole word plaintext search
    if (m_wholeWords) {
        // escape dot and friends
        const QString workPattern = QStringLiteral("\\b%1\\b").arg(QRegularExpression::escape(text));

Functionality is toggled with a button: image

P.S. This is my first contribution of a UI feature to Kate and I am not very experienced with Qt, so please take it with a grain of salt. I tried to mimic case sensitivity and regular expression toggles as much as I could, but it still may require some work. In particular, icon choice for the button.

Edited by Glebs Ivanovskis

Merge request reports