mirror of
https://gitee.com/vnotex/vnote.git
synced 2025-07-05 13:59:52 +08:00
vim-mode: support canceling autoindent after o/O
This commit is contained in:
parent
78674efaa0
commit
2734b8407c
@ -340,9 +340,9 @@ static int percentageToBlockNumber(const QTextDocument *p_doc, int p_percent)
|
||||
return num >= 0 ? num : 0;
|
||||
}
|
||||
|
||||
bool VVim::handleKeyPressEvent(QKeyEvent *p_event)
|
||||
bool VVim::handleKeyPressEvent(QKeyEvent *p_event, bool *p_autoIndented)
|
||||
{
|
||||
bool ret = handleKeyPressEvent(p_event->key(), p_event->modifiers());
|
||||
bool ret = handleKeyPressEvent(p_event->key(), p_event->modifiers(), p_autoIndented);
|
||||
if (ret) {
|
||||
p_event->accept();
|
||||
}
|
||||
@ -350,13 +350,17 @@ bool VVim::handleKeyPressEvent(QKeyEvent *p_event)
|
||||
return ret;
|
||||
}
|
||||
|
||||
bool VVim::handleKeyPressEvent(int key, int modifiers)
|
||||
bool VVim::handleKeyPressEvent(int key, int modifiers, bool *p_autoIndented)
|
||||
{
|
||||
bool ret = false;
|
||||
bool resetPositionInBlock = true;
|
||||
Key keyInfo(key, modifiers);
|
||||
bool unindent = false;
|
||||
|
||||
if (p_autoIndented) {
|
||||
*p_autoIndented = false;
|
||||
}
|
||||
|
||||
// Handle Insert mode key press.
|
||||
if (VimMode::Insert == m_mode) {
|
||||
if (key == Qt::Key_Escape
|
||||
@ -739,16 +743,22 @@ bool VVim::handleKeyPressEvent(int key, int modifiers)
|
||||
1);
|
||||
}
|
||||
|
||||
bool textInserted = false;
|
||||
if (vconfig.getAutoIndent()) {
|
||||
VEditUtils::indentBlockAsPreviousBlock(cursor);
|
||||
textInserted = VEditUtils::indentBlockAsPreviousBlock(cursor);
|
||||
if (vconfig.getAutoList()) {
|
||||
VEditUtils::insertListMarkAsPreviousBlock(cursor);
|
||||
textInserted = VEditUtils::insertListMarkAsPreviousBlock(cursor)
|
||||
|| textInserted;
|
||||
}
|
||||
}
|
||||
|
||||
cursor.endEditBlock();
|
||||
m_editor->setTextCursor(cursor);
|
||||
|
||||
if (p_autoIndented && textInserted) {
|
||||
*p_autoIndented = true;
|
||||
}
|
||||
|
||||
setMode(VimMode::Insert);
|
||||
}
|
||||
|
||||
|
@ -148,7 +148,7 @@ public:
|
||||
|
||||
// Handle key press event.
|
||||
// Returns true if the event is consumed and need no more handling.
|
||||
bool handleKeyPressEvent(QKeyEvent *p_event);
|
||||
bool handleKeyPressEvent(QKeyEvent *p_event, bool *p_autoIndented = NULL);
|
||||
|
||||
// Return current mode.
|
||||
VimMode getMode() const;
|
||||
@ -449,7 +449,7 @@ private:
|
||||
};
|
||||
|
||||
// Returns true if the event is consumed and need no more handling.
|
||||
bool handleKeyPressEvent(int key, int modifiers);
|
||||
bool handleKeyPressEvent(int key, int modifiers, bool *p_autoIndented = NULL);
|
||||
|
||||
// Reset all key state info.
|
||||
void resetState();
|
||||
|
@ -193,8 +193,15 @@ bool VMdEditOperations::insertImage()
|
||||
|
||||
bool VMdEditOperations::handleKeyPressEvent(QKeyEvent *p_event)
|
||||
{
|
||||
if (m_editConfig->m_enableVimMode && m_vim->handleKeyPressEvent(p_event)) {
|
||||
m_autoIndentPos = -1;
|
||||
bool autoIndentedVim = false;
|
||||
if (m_editConfig->m_enableVimMode
|
||||
&& m_vim->handleKeyPressEvent(p_event, &autoIndentedVim)) {
|
||||
if (autoIndentedVim) {
|
||||
m_autoIndentPos = m_editor->textCursor().position();
|
||||
} else {
|
||||
m_autoIndentPos = -1;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user