mirror of
https://gitee.com/vnotex/vnote.git
synced 2025-07-05 13:59:52 +08:00
enalbe Vim cmd line for searching in read mode
This commit is contained in:
parent
b927a525e2
commit
333be910cc
@ -155,6 +155,26 @@ public:
|
||||
Invalid
|
||||
};
|
||||
|
||||
// Search item including the searched text and options.
|
||||
struct SearchItem
|
||||
{
|
||||
SearchItem() : m_options(0), m_forward(true) {}
|
||||
|
||||
bool isEmpty() const
|
||||
{
|
||||
return m_text.isEmpty();
|
||||
}
|
||||
|
||||
// The user raw input.
|
||||
QString m_rawStr;
|
||||
|
||||
// The string used to search.
|
||||
QString m_text;
|
||||
|
||||
uint m_options;
|
||||
bool m_forward;
|
||||
};
|
||||
|
||||
// Handle key press event.
|
||||
// @p_autoIndentPos: the cursor position of last auto indent.
|
||||
// Returns true if the event is consumed and need no more handling.
|
||||
@ -205,6 +225,12 @@ public:
|
||||
// Returns empty string if it is not a valid register.
|
||||
QString readRegister(int p_key, int p_modifiers);
|
||||
|
||||
// Fetch the searched string and options from @p_type and @p_cmd.
|
||||
// \C for case-sensitive;
|
||||
// Case-insensitive by default.
|
||||
// Regular-expression by default.
|
||||
static VVim::SearchItem fetchSearchItem(VVim::CommandLineType p_type, const QString &p_cmd);
|
||||
|
||||
signals:
|
||||
// Emit when current mode has been changed.
|
||||
void modeChanged(VimMode p_mode);
|
||||
@ -284,21 +310,6 @@ private:
|
||||
}
|
||||
};
|
||||
|
||||
// Search item including the searched text and options.
|
||||
struct SearchItem
|
||||
{
|
||||
SearchItem() : m_options(0), m_forward(true) {}
|
||||
|
||||
// The user raw input.
|
||||
QString m_rawStr;
|
||||
|
||||
// The string used to search.
|
||||
QString m_text;
|
||||
|
||||
uint m_options;
|
||||
bool m_forward;
|
||||
};
|
||||
|
||||
class SearchHistory
|
||||
{
|
||||
public:
|
||||
@ -800,12 +811,6 @@ private:
|
||||
// [[, ]], [], ][, [{, ]}.
|
||||
void processTitleJump(const QList<Token> &p_tokens, bool p_forward, int p_relativeLevel);
|
||||
|
||||
// Fetch the searched string and options from @p_type and @p_cmd.
|
||||
// \C for case-sensitive;
|
||||
// Case-insensitive by default.
|
||||
// Regular-expression by default.
|
||||
VVim::SearchItem fetchSearchItem(VVim::CommandLineType p_type, const QString &p_cmd);
|
||||
|
||||
// Clear search highlight.
|
||||
void clearSearchHighlight();
|
||||
|
||||
|
@ -645,7 +645,7 @@ void VMdTab::clearSearchedWordHighlight()
|
||||
}
|
||||
}
|
||||
|
||||
void VMdTab::handleWebKeyPressed(int p_key, bool p_ctrl, bool /* p_shift */)
|
||||
void VMdTab::handleWebKeyPressed(int p_key, bool p_ctrl, bool p_shift)
|
||||
{
|
||||
V_ASSERT(m_webViewer);
|
||||
|
||||
@ -661,6 +661,7 @@ void VMdTab::handleWebKeyPressed(int p_key, bool p_ctrl, bool /* p_shift */)
|
||||
// Zoom out.
|
||||
zoomWebPage(false);
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
// Equal
|
||||
@ -669,6 +670,7 @@ void VMdTab::handleWebKeyPressed(int p_key, bool p_ctrl, bool /* p_shift */)
|
||||
// Zoom in.
|
||||
zoomWebPage(true);
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
// 0
|
||||
@ -677,6 +679,35 @@ void VMdTab::handleWebKeyPressed(int p_key, bool p_ctrl, bool /* p_shift */)
|
||||
// Recover zoom.
|
||||
m_webViewer->setZoomFactor(1);
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
// / or ?
|
||||
case 191:
|
||||
if (!p_ctrl) {
|
||||
VVim::CommandLineType type = VVim::CommandLineType::SearchForward;
|
||||
if (p_shift) {
|
||||
// ?, search backward.
|
||||
type = VVim::CommandLineType::SearchBackward;
|
||||
}
|
||||
|
||||
emit triggerVimCmd(type);
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
// n or N
|
||||
case 78:
|
||||
if (!p_ctrl) {
|
||||
if (!m_lastSearchItem.isEmpty()) {
|
||||
bool forward = !p_shift;
|
||||
findTextInWebView(m_lastSearchItem.m_text,
|
||||
m_lastSearchItem.m_options,
|
||||
false,
|
||||
forward ? m_lastSearchItem.m_forward : !m_lastSearchItem.m_forward);
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
default:
|
||||
@ -1047,6 +1078,8 @@ void VMdTab::handleVimCmdCommandCancelled()
|
||||
if (vim) {
|
||||
vim->processCommandLineCancelled();
|
||||
}
|
||||
} else {
|
||||
m_webViewer->findText("");
|
||||
}
|
||||
}
|
||||
|
||||
@ -1057,6 +1090,14 @@ void VMdTab::handleVimCmdCommandFinished(VVim::CommandLineType p_type, const QSt
|
||||
if (vim) {
|
||||
vim->processCommandLine(p_type, p_cmd);
|
||||
}
|
||||
} else {
|
||||
Q_ASSERT(p_type == VVim::CommandLineType::SearchForward
|
||||
|| p_type == VVim::CommandLineType::SearchBackward);
|
||||
m_lastSearchItem = VVim::fetchSearchItem(p_type, p_cmd);
|
||||
findTextInWebView(m_lastSearchItem.m_text,
|
||||
m_lastSearchItem.m_options,
|
||||
false,
|
||||
m_lastSearchItem.m_forward);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1069,6 +1110,11 @@ void VMdTab::handleVimCmdCommandChanged(VVim::CommandLineType p_type, const QStr
|
||||
if (vim) {
|
||||
vim->processCommandLineChanged(p_type, p_cmd);
|
||||
}
|
||||
} else {
|
||||
Q_ASSERT(p_type == VVim::CommandLineType::SearchForward
|
||||
|| p_type == VVim::CommandLineType::SearchBackward);
|
||||
VVim::SearchItem item = VVim::fetchSearchItem(p_type, p_cmd);
|
||||
findTextInWebView(item.m_text, item.m_options, true, item.m_forward);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -215,6 +215,8 @@ private:
|
||||
|
||||
// Used to scroll to the header of edit mode in read mode.
|
||||
VHeaderPointer m_headerFromEditMode;
|
||||
|
||||
VVim::SearchItem m_lastSearchItem;
|
||||
};
|
||||
|
||||
inline VMdEditor *VMdTab::getEditor()
|
||||
|
Loading…
x
Reference in New Issue
Block a user