7#include "interactivesedreplacemode.h"
12using namespace KateVi;
14InteractiveSedReplaceMode::InteractiveSedReplaceMode(
EmulatedCommandBar *emulatedCommandBar,
15 MatchHighlighter *matchHighlighter,
16 InputModeManager *viInputModeManager,
17 KTextEditor::ViewPrivate *view)
18 : ActiveMode(emulatedCommandBar, matchHighlighter, viInputModeManager, view)
21 m_interactiveSedReplaceLabel =
new QLabel();
22 m_interactiveSedReplaceLabel->setObjectName(QStringLiteral(
"interactivesedreplace"));
25void InteractiveSedReplaceMode::activate(std::shared_ptr<SedReplace::InteractiveSedReplacer> interactiveSedReplace)
27 Q_ASSERT_X(interactiveSedReplace->currentMatch().isValid(),
28 "startInteractiveSearchAndReplace",
29 "KateCommands shouldn't initiate an interactive sed replace with no initial match");
32 m_interactiveSedReplacer = interactiveSedReplace;
34 hideAllWidgetsExcept(m_interactiveSedReplaceLabel);
35 m_interactiveSedReplaceLabel->show();
36 updateInteractiveSedReplaceLabelText();
38 updateMatchHighlight(interactiveSedReplace->currentMatch());
39 moveCursorTo(interactiveSedReplace->currentMatch().start());
42bool InteractiveSedReplaceMode::handleKeyPress(
const QKeyEvent *keyEvent)
47 if (
keyEvent->text() == QLatin1String(
"y") ||
keyEvent->text() == QLatin1String(
"n")) {
48 const KTextEditor::Cursor cursorPosIfFinalMatch = m_interactiveSedReplacer->currentMatch().start();
49 if (
keyEvent->text() == QLatin1String(
"y")) {
50 m_interactiveSedReplacer->replaceCurrentMatch();
52 m_interactiveSedReplacer->skipCurrentMatch();
54 updateMatchHighlight(m_interactiveSedReplacer->currentMatch());
55 updateInteractiveSedReplaceLabelText();
56 moveCursorTo(m_interactiveSedReplacer->currentMatch().start());
58 if (!m_interactiveSedReplacer->currentMatch().isValid()) {
59 moveCursorTo(cursorPosIfFinalMatch);
60 finishInteractiveSedReplace();
63 }
else if (
keyEvent->text() == QLatin1String(
"l")) {
64 m_interactiveSedReplacer->replaceCurrentMatch();
65 finishInteractiveSedReplace();
67 }
else if (
keyEvent->text() == QLatin1String(
"q")) {
68 finishInteractiveSedReplace();
70 }
else if (
keyEvent->text() == QLatin1String(
"a")) {
71 m_interactiveSedReplacer->replaceAllRemaining();
72 finishInteractiveSedReplace();
78void InteractiveSedReplaceMode::deactivate(
bool wasAborted)
82 m_interactiveSedReplaceLabel->hide();
85QWidget *InteractiveSedReplaceMode::label()
87 return m_interactiveSedReplaceLabel;
90void InteractiveSedReplaceMode::updateInteractiveSedReplaceLabelText()
92 m_interactiveSedReplaceLabel->setText(m_interactiveSedReplacer->currentMatchReplacementConfirmationMessage() + QLatin1String(
" (y/n/a/q/l)"));
95void InteractiveSedReplaceMode::finishInteractiveSedReplace()
98 closeWithStatusMessage(m_interactiveSedReplacer->finalStatusReportMessage());
99 m_interactiveSedReplacer.reset();
A KateViewBarWidget that attempts to emulate some of the features of Vim's own command bar,...
void keyEvent(KeyAction action, QWidget *widget, Qt::Key key, Qt::KeyboardModifiers modifier, int delay)