Kate
kateviemulatedcommandbar.cpp
Go to the documentation of this file.
113 // All curly brackets, except the closing curly bracket of a matching pair where the opening bracket is escaped,
123 if (qtRegexPattern[i] == '}' && lookingForMatchingCloseBracket && qtRegexPattern[i - 1] != '\\')
139 int previousNonMatchingClosedCurlyPos = 0; // i.e. the position of the last character which is either
144 QString chunkExcludingMatchingCurlyClosed = qtRegexPattern.mid(previousNonMatchingClosedCurlyPos, matchingClosedCurlyPos - previousNonMatchingClosedCurlyPos);
151 QString chunkAfterLastMatchingClosedCurly = qtRegexPattern.mid(matchingClosedCurlyBracketPositions.last() + 1);
161 // All square brackets, *except* for those that are a) unescaped; and b) form a matching pair, must be
168 if (qtRegexPattern[i] == '[' && !isCharEscaped(qtRegexPattern, i) && !lookingForMatchingCloseBracket)
173 if (qtRegexPattern[i] == ']' && lookingForMatchingCloseBracket && !isCharEscaped(qtRegexPattern, i))
189 // Ensure that every chunk of qtRegexPattern that does *not* contain one of the matching pairs of
192 int previousNonMatchingSquareBracketPos = 0; // i.e. the position of the last character which is
197 QString chunkExcludingMatchingSquareBrackets = qtRegexPattern.mid(previousNonMatchingSquareBracketPos, matchingSquareBracketPos - previousNonMatchingSquareBracketPos);
198 chunkExcludingMatchingSquareBrackets = ensuredCharEscaped(chunkExcludingMatchingSquareBrackets, '[');
199 chunkExcludingMatchingSquareBrackets = ensuredCharEscaped(chunkExcludingMatchingSquareBrackets, ']');
200 qtRegexPatternNonMatchingSquaresMadeLiteral += chunkExcludingMatchingSquareBrackets + qtRegexPattern[matchingSquareBracketPos];
203 QString chunkAfterLastMatchingSquareBracket = qtRegexPattern.mid(matchingSquareBracketPositions.last() + 1);
204 chunkAfterLastMatchingSquareBracket = ensuredCharEscaped(chunkAfterLastMatchingSquareBracket, '[');
205 chunkAfterLastMatchingSquareBracket = ensuredCharEscaped(chunkAfterLastMatchingSquareBracket, ']');
252 if (caseSensitivityMarkersStripped.at(pos) == 'C' && isCharEscaped(caseSensitivityMarkersStripped, pos))
296 if (searchText.length() > posOfSearchConfigMarker + 1 && searchText.at(posOfSearchConfigMarker + 1) == 'e')
304 QString withSearchConfigRemoved(const QString& originalSearchText, const bool isSearchBackwards)
306 const int posOfSearchConfigMarker = findPosOfSearchConfigMarker(originalSearchText, isSearchBackwards);
362 m_highlightedMatch = m_view->doc()->newMovingRange(Range::invalid(), Kate::TextRange::DoNotExpand);
388 // Make sure the timer is stopped when the user switches views. If not, focus will be given to the
389 // wrong view when KateViewBar::hideCurrentBarWidget() is called as a result of m_commandResponseMessageDisplayHide
391 connect(m_view, SIGNAL(focusOut(KTextEditor::View*)), m_commandResponseMessageDisplayHide, SLOT(stop()));
393 connect(m_view, SIGNAL(focusIn(KTextEditor::View*)), this, SLOT(startHideCommandResponseTimer()));
401 void KateViEmulatedCommandBar::init(KateViEmulatedCommandBar::Mode mode, const QString& initialText)
439 void KateViEmulatedCommandBar::setCommandResponseMessageTimeout(long int commandResponseMessageTimeOutMS)
464 const Qt::Key syntheticSearchCompletedKey = (m_wasAborted ? static_cast<Qt::Key>(0) : Qt::Key_Enter);
465 QKeyEvent syntheticSearchCompletedKeyPress(QEvent::KeyPress, syntheticSearchCompletedKey, Qt::NoModifier);
474 m_view->getViInputModeManager()->setLastSearchPlacesCursorAtEndOfMatch(m_currentSearchPlacesCursorAtEndOfMatch);
501 m_highlightMatchAttribute->setDynamicAttribute (KTextEditor::Attribute::ActivateMouseIn, mouseInAttribute);
502 m_highlightMatchAttribute->dynamicAttribute (KTextEditor::Attribute::ActivateMouseIn)->setBackground(matchColour);
512 void KateViEmulatedCommandBar::setBarBackground(KateViEmulatedCommandBar::BarBackgroundStatus status)
546 // Re-route this keypress through Vim's central keypress handling area, so that we can use the keypress in e.g.
581 if (charToTheLeftOfCursor.isLetterOrNumber() || charToTheLeftOfCursor == '_' || charToTheLeftOfCursor == ' ')
595 while (wordBeforeCursorBegin >= 0 && (m_edit->text()[wordBeforeCursorBegin].isLetterOrNumber() || m_edit->text()[wordBeforeCursorBegin] == '_'))
600 return m_edit->text().mid(wordBeforeCursorBegin, m_edit->cursorPosition() - wordBeforeCursorBegin);
606 const int cursorPositionWithoutRangeExpression = m_edit->cursorPosition() - rangeExpression().length();
608 while (commandBeforeCursorBegin >= 0 && (textWithoutRangeExpression[commandBeforeCursorBegin].isLetterOrNumber() || textWithoutRangeExpression[commandBeforeCursorBegin] == '_' || textWithoutRangeExpression[commandBeforeCursorBegin] == '-'))
613 return textWithoutRangeExpression.mid(commandBeforeCursorBegin, cursorPositionWithoutRangeExpression - commandBeforeCursorBegin);
620 const QString newText = m_edit->text().left(m_edit->cursorPosition() - wordBeforeCursor().length()) +
629 const QString newText = m_edit->text().left(m_edit->cursorPosition() - commandBeforeCursor().length()) +
639 m_completionModel->setStringList(reversed(KateGlobal::self()->viInputModeGlobal()->searchHistory()));
679 m_completionModel->setStringList(reversed(KateGlobal::self()->viInputModeGlobal()->commandHistory()));
689 m_completionModel->setStringList(reversed(KateGlobal::self()->viInputModeGlobal()->searchHistory()));
700 m_completionModel->setStringList(reversed(KateGlobal::self()->viInputModeGlobal()->replaceHistory()));
745 // Seem to need a call to complete() else the size of the popup box is not altered appropriately.
772 const int newCursorPosition = m_edit->cursorPosition() + (newCompletion.length() - commandBeforeCursor().length());
778 m_edit->setText(withSedFindTermReplacedWith(withCaseSensitivityMarkersStripped(withSedDelimiterEscaped(newCompletion))));
812 parsedSedExpression.parsedSuccessfully = KateCommands::SedReplace::parse(commandWithoutRangeExpression, delimiter, parsedSedExpression.findBeginPos, parsedSedExpression.findEndPos, parsedSedExpression.replaceBeginPos, parsedSedExpression.replaceEndPos);
820 // The replace term was empty, and a quirk of the regex used is that replaceBeginPos will be -1.
821 // It's actually the position after the first occurrence of the delimiter after the end of the find pos.
822 parsedSedExpression.replaceBeginPos = commandWithoutRangeExpression.indexOf(delimiter, parsedSedExpression.findEndPos) + 1;
827 // Both find and replace terms are empty; replace term is at the third occurrence of the delimiter.
831 parsedSedExpression.replaceBeginPos = commandWithoutRangeExpression.indexOf(delimiter, parsedSedExpression.replaceBeginPos + 1);
882 return command.mid(parsedSedExpression.findBeginPos, parsedSedExpression.findEndPos - parsedSedExpression.findBeginPos + 1);
890 return command.mid(parsedSedExpression.replaceBeginPos, parsedSedExpression.replaceEndPos - parsedSedExpression.replaceBeginPos + 1);
903 return parsedSedExpression.parsedSuccessfully && (m_edit->cursorPosition() >= parsedSedExpression.findBeginPos && m_edit->cursorPosition() <= parsedSedExpression.findEndPos + 1);
909 return parsedSedExpression.parsedSuccessfully && m_edit->cursorPosition() >= parsedSedExpression.replaceBeginPos && m_edit->cursorPosition() <= parsedSedExpression.replaceEndPos + 1;
929 if (keyEvent->modifiers() == Qt::ControlModifier && (keyEvent->key() == Qt::Key_C || keyEvent->key() == Qt::Key_BracketLeft) && !m_waitingForRegister)
943 // TODO - it would be better to use e.g. keyEvent->key() == Qt::Key_Y instead of keyEvent->text() == "y",
944 // but this would require some slightly dicey changes to the "feed key press" code in order to make it work
1089 else if ((keyEvent->modifiers() == Qt::ControlModifier && keyEvent->key() == Qt::Key_H) || keyEvent->key() == Qt::Key_Backspace)
1134 m_edit->setSelection(parsedSedExpression.findBeginPos, parsedSedExpression.findEndPos - parsedSedExpression.findBeginPos + 1);
1140 m_edit->setSelection(parsedSedExpression.replaceBeginPos, parsedSedExpression.replaceEndPos - parsedSedExpression.replaceBeginPos + 1);
1151 if (m_completer->popup()->isVisible() && m_currentCompletionType == KateViEmulatedCommandBar::WordFromDocument)
1164 qDebug() << "text:\n" << m_edit->text() << "\n is sed replace: " << parsedSedExpression.parsedSuccessfully;
1169 const QString commandWithSedSearchRegexConverted = withSedFindTermReplacedWith(convertedFindTerm);
1201 // Send the keypress back to the QLineEdit. Ideally, instead of doing this, we would simply return "false"
1202 // and let Qt re-dispatch the event itself; however, there is a corner case in that if the selection
1203 // changes (as a result of e.g. incremental searches during Visual Mode), and the keypress that causes it
1205 // (so KateViInputModeManager::isHandlingKeypress() returns false), we lose information about whether we are
1207 QKeyEvent keyEventCopy(keyEvent->type(), keyEvent->key(), keyEvent->modifiers(), keyEvent->text(), keyEvent->isAutoRepeat(), keyEvent->count());
1222 void KateViEmulatedCommandBar::startInteractiveSearchAndReplace(QSharedPointer< KateCommands::SedReplace::InteractiveSedReplacer > interactiveSedReplace)
1277 void KateViEmulatedCommandBar::switchToCommandResponseDisplay(const QString& commandResponseMessage)
1291 m_interactiveSedReplaceLabel->setText(m_interactiveSedReplacer->currentMatchReplacementConfirmationMessage() + " (y/n/a/q/l)");
1322 const bool placeCursorAtEndOfMatch = shouldPlaceCursorAtEndOfMatch(qtRegexPattern, searchBackwards);
1333 // Decide case-sensitivity via SmartCase (note: if the expression contains \C, the "case-sensitive" marker, then
1350 // The "count" for the current search is not shared between Visual & Normal mode, so we need to pick
1352 Range match = m_view->getViInputModeManager()->getCurrentViModeHandler()->findPattern(qtRegexPattern, searchBackwards, caseSensitive, m_startingCursorPos);
1360 realMatchEnd = Cursor(realMatchEnd.line() - 1, m_view->doc()->lineLength(realMatchEnd.line() - 1));
1382 if (m_mode == Command && m_currentCompletionType == None && !withoutRangeExpression().isEmpty())
1390 const bool commandBeforeCursorIsLeading = (m_edit->cursorPosition() - commandBeforeCursor().length() == rangeExpression().length());
1391 if (m_mode == Command && !commandBeforeCursorIsLeading && m_currentCompletionType == Commands && !m_isNextTextChangeDueToCompletionChange)
1398 if (!m_isNextTextChangeDueToCompletionChange && m_completer->popup()->currentIndex().row() != -1)
1411 if (m_commandResponseMessageDisplay->isVisible() && !m_commandResponseMessageDisplayHide->isActive())
QLayout * layout() const
void startInteractiveSearchAndReplace(QSharedPointer< KateCommands::SedReplace::InteractiveSedReplacer > interactiveSedReplace)
Definition: kateviemulatedcommandbar.cpp:1222
void setCaseSensitivity(Qt::CaseSensitivity caseSensitivity)
int indexOf(QChar ch, int from, Qt::CaseSensitivity cs) const
Qt::KeyboardModifiers modifiers() const
Type type() const
palette
virtual QModelIndex index(int row, int column, const QModelIndex &parent) const =0
virtual KTextEditor::MovingRange * newMovingRange(const KTextEditor::Range &range, KTextEditor::MovingRange::InsertBehaviors insertBehaviors=KTextEditor::MovingRange::DoNotExpand, KTextEditor::MovingRange::EmptyBehavior emptyBehavior=KTextEditor::MovingRange::AllowEmpty)
Create a new moving range for this document.
Definition: katedocument.cpp:4741
void setCurrentIndex(const QModelIndex &index)
void setCompletionPrefix(const QString &prefix)
void setText(const QString &)
bool hasPendingEvents()
int count() const
void setText(const QString &text, bool selected=true)
Definition: kateviewhelpers.cpp:839
void setWidget(QWidget *widget)
Definition: kateviinputmodemanager.h:51
void setLastSearchBackwards(bool b)
set search direction of last search.
Definition: kateviinputmodemanager.h:229
void setModel(QAbstractItemModel *model)
QString currentCompletion() const
virtual void setVisible(bool visible)
void setAlignment(QFlags< Qt::AlignmentFlag >)
bool isAutoRepeat() const
bool isSendingSyntheticSearchCompletedKeypress()
Definition: kateviemulatedcommandbar.cpp:1217
QString & remove(int position, int n)
const QChar KeyEventToQChar(const QKeyEvent &keyEvent)
Definition: katevikeyparser.cpp:674
bool setCursorPosition(KTextEditor::Cursor position)
Definition: kateview.cpp:2418
KateViInputModeManager * getViInputModeManager()
Definition: kateview.cpp:1587
static KTextEditor::Range parseRangeExpression(const QString &command, KateView *view, QString &destRangeExpression, QString &destTransformedCommand)
Attempt to parse any leading range expression (e.g.
Definition: katevicommandrangeexpressionparser.cpp:68
virtual void scrollTo(const QModelIndex &index, ScrollHint hint)=0
Definition: kateviewhelpers.h:294
void addWidget(QWidget *widget, int stretch, QFlags< Qt::AlignmentFlag > alignment)
const QString getLastSearchPattern() const
The current search pattern.
Definition: kateviinputmodemanager.cpp:422
void processEvents(QFlags< QEventLoop::ProcessEventsFlag > flags)
void append(const T &value)
void setLayout(QLayout *layout)
void installEventFilter(QObject *filterObj)
void setCommandResponseMessageTimeout(long commandResponseMessageTimeOutMS)
Definition: kateviemulatedcommandbar.cpp:439
void complete(const QRect &rect)
void setFocus()
bool isEmpty() const
void setObjectName(const QString &name)
bool isEmpty() const
int row() const
bool sendEvent(QObject *receiver, QEvent *event)
void hideMe()
QString text() const
void setLastSearchPlacesCursorAtEndOfMatch(bool b)
Definition: kateviinputmodemanager.h:233
KateViModeBase * getCurrentViModeHandler() const
Definition: kateviinputmodemanager.cpp:466
void init(Mode mode, const QString &initialText=QString())
Definition: kateviemulatedcommandbar.cpp:401
Range findPattern(const QString &pattern, bool backwards, bool caseSensitive, const Cursor &startFrom, int count=-1) const
Definition: katevimodebase.cpp:183
void setText(const QString &)
void hide()
void backspace()
Definition: kateview.h:77
iterator end()
QString toLower() const
int key() const
void insert(const QString &newText)
void stop()
QChar toLower() const
Definition: kateviinputmodemanager.h:52
QString & replace(int position, int n, QChar after)
bool handleKeyPress(const QKeyEvent *keyEvent)
Definition: kateviemulatedcommandbar.cpp:927
bool handleKeypress(const QKeyEvent *e)
feed key the given key press to the command parser
Definition: kateviinputmodemanager.cpp:113
QString mid(int position, int n) const
QString getWord(const KTextEditor::Cursor &cursor)
Definition: katedocument.cpp:3538
KateViEmulatedCommandBar(KateView *view, QWidget *parent=0)
Definition: kateviemulatedcommandbar.cpp:318
Definition: kateviewhelpers.h:432
const QChar at(int position) const
T & last()
QSet< T > fromList(const QList< T > &list)
const QColor & searchHighlightColor() const
Definition: kateconfig.cpp:2687
void setLastSearchPattern(const QString &p)
Set the current search pattern.
Definition: kateviinputmodemanager.cpp:434
int length() const
Definition: kateviinsertmode.h:39
void appendReplaceHistoryItem(const QString &replaceHistoryItem)
Definition: kateviglobal.cpp:282
void appendCommandHistoryItem(const QString &commandHistoryItem)
Definition: kateviglobal.cpp:272
QString left(int n) const
void start(int msec)
void show()
KateViVisualMode * getViVisualMode()
Definition: kateviinputmodemanager.cpp:556
int currentRow() const
QAbstractItemModel * model() const
cursorPosition
QModelIndex currentIndex() const
void appendSearchHistoryItem(const QString &searchHistoryItem)
Definition: kateviglobal.cpp:257
bool isActive() const
bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
QString getRegisterContent(const QChar ®) const
Definition: kateviglobal.cpp:121
virtual ~KateViEmulatedCommandBar()
Definition: kateviemulatedcommandbar.cpp:396
void setStringList(const QStringList &strings)
iterator begin()
QAbstractItemView * popup() const
static bool parse(const QString &sedReplaceString, QString &destDelim, int &destFindBeginPos, int &destFindEndPos, int &destReplaceBeginPos, int &destReplaceEndPos)
Parses sedReplaceString to see if it is a valid sed replace expression (e.g.
Definition: katecmds.cpp:999
bool setCurrentRow(int row)
bool isLetterOrNumber() const
void setLastSearchCaseSensitive(bool caseSensitive)
Definition: kateviinputmodemanager.h:231
int completionCount() const
void setSelection(int start, int length)
void setSingleShot(bool singleShot)
T findChild(const QString &name) const
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Sat May 9 2020 03:56:58 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006
Documentation copyright © 1996-2020 The KDE developers.
Generated on Sat May 9 2020 03:56:58 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006
KDE's Doxygen guidelines are available online.