MCPcopy Create free account
hub / github.com/KDE/kdevelop / patternFromSelection

Function patternFromSelection

plugins/grepview/grepviewplugin.cpp:41–67  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

39#include <utility>
40
41static QString patternFromSelection(const KDevelop::IDocument* doc)
42{
43 if (!doc)
44 return QString();
45
46 QString pattern;
47 KTextEditor::Range range = doc->textSelection();
48 if( range.isValid() )
49 {
50 pattern = doc->textDocument()->text( range );
51 }
52 if( pattern.isEmpty() )
53 {
54 pattern = doc->textWord();
55 }
56
57 // Before anything, this removes line feeds from the
58 // beginning and the end.
59 int len = pattern.length();
60 if (len > 0 && pattern[0] == QLatin1Char('\n')) {
61 pattern.remove(0, 1);
62 len--;
63 }
64 if (len > 0 && pattern[len-1] == QLatin1Char('\n'))
65 pattern.truncate(len-1);
66 return pattern;
67}
68
69GrepViewPlugin::GrepViewPlugin(QObject* parent, const KPluginMetaData& metaData, const QVariantList&)
70 : KDevelop::IPlugin(QStringLiteral("kdevgrepview"), parent, metaData)

Callers 1

showDialogMethod · 0.85

Calls 9

QStringClass · 0.50
textSelectionMethod · 0.45
isValidMethod · 0.45
textMethod · 0.45
textDocumentMethod · 0.45
isEmptyMethod · 0.45
textWordMethod · 0.45
lengthMethod · 0.45
removeMethod · 0.45

Tested by

no test coverage detected