KTextEditor

searcher.h
1/*
2 SPDX-FileCopyrightText: KDE Developers
3
4 SPDX-License-Identifier: LGPL-2.0-or-later
5*/
6
7#ifndef KATEVI_SEARCHER_H
8#define KATEVI_SEARCHER_H
9
10#include "ktexteditor/attribute.h"
11#include "ktexteditor/range.h"
12#include <vimode/range.h>
13
14#include <QString>
15
16namespace KTextEditor
17{
18class Cursor;
19class ViewPrivate;
20class MovingRange;
21}
22
23namespace KateVi
24{
25class InputModeManager;
26
27class Searcher
28{
29public:
30 explicit Searcher(InputModeManager *viInputModeManager);
31 ~Searcher();
32
33 /** Command part **/
34 void findNext();
35 void findPrevious();
36
37 /** Simple searchers **/
38 Range motionFindNext(int count = 1);
39 Range motionFindPrev(int count = 1);
40 Range findWordForMotion(const QString &pattern, bool backwards, const KTextEditor::Cursor startFrom, int count);
41
42 /** Extended searcher for Emulated Command Bar. **/
43 struct SearchParams {
44 QString pattern;
45 bool isBackwards = false;
46 bool isCaseSensitive = false;
47 bool shouldPlaceCursorAtEndOfMatch = false;
48 };
49 KTextEditor::Range findPattern(const SearchParams &searchParams, const KTextEditor::Cursor startFrom, int count, bool addToSearchHistory = true);
50
51 const QString getLastSearchPattern() const;
52 bool lastSearchWrapped() const;
53 void setLastSearchParams(const SearchParams &searchParams);
54
55 void enableHighlightSearch(bool enable);
56 bool isHighlightSearchEnabled() const;
57 void hideCurrentHighlight();
58 void updateHighlightColors();
59 void clearHighlights();
60 void patternDone(bool wasAborted);
61
62private:
63 Range findPatternForMotion(const SearchParams &searchParams, const KTextEditor::Cursor startFrom, int count = 1);
64 KTextEditor::Range findPatternWorker(const SearchParams &searchParams, const KTextEditor::Cursor startFrom, int count);
65
66 void highlightVisibleResults(const SearchParams &searchParams, bool force = false);
67 void disconnectSignals();
68 void connectSignals();
69
70private:
71 enum class HighlightMode {
72 Disable, /** vi :set nohls[earch] **/
73 Enable, /** vi :set hls[earch] **/
74 HideCurrent /** vi :noh[lsearch] - stop highlighting until next search **/
75 };
76
77 InputModeManager *m_viInputModeManager;
78 KTextEditor::ViewPrivate *m_view;
79
80 SearchParams m_lastSearchConfig;
81 bool m_lastSearchWrapped;
82
83 HighlightMode m_hlMode{HighlightMode::Enable};
85 SearchParams m_lastHlSearchConfig;
86 KTextEditor::Range m_lastHlSearchRange;
87 KTextEditor::Attribute::Ptr highlightMatchAttribute;
88 QMetaObject::Connection m_displayRangeChangedConnection;
89 QMetaObject::Connection m_textChangedConnection;
90 bool newPattern{true};
91};
92}
93
94#endif // KATEVI_SEARCHER_H
The Cursor represents a position in a Document.
Definition cursor.h:75
An object representing a section of text, from one Cursor to another.
The KTextEditor namespace contains all the public API that is required to use the KTextEditor compone...
Extended searcher for Emulated Command Bar.
Definition searcher.h:43
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Tue Mar 26 2024 11:15:44 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.