mirror of
https://gitee.com/vnotex/vnote.git
synced 2025-07-05 13:59:52 +08:00
bug-fix: do not cancel auto-indentation if cursor is not at block end
This commit is contained in:
parent
d955dedcb7
commit
04fa3654a4
@ -670,3 +670,22 @@ int VEditUtils::findNextEmptyBlock(const QTextCursor &p_cursor,
|
||||
|
||||
return p_repeat > 0 ? -1 : res;
|
||||
}
|
||||
|
||||
bool VEditUtils::needToCancelAutoIndent(int p_autoIndentPos, const QTextCursor &p_cursor)
|
||||
{
|
||||
// Cancel the auto indent/list if the pos is the same and cursor is at
|
||||
// the end of a block.
|
||||
QTextBlock block = p_cursor.block();
|
||||
if (p_cursor.position() == p_autoIndentPos
|
||||
&& !p_cursor.hasSelection()
|
||||
&& p_cursor.atBlockEnd()) {
|
||||
if (isListBlock(block)) {
|
||||
return true;
|
||||
} else if (isSpaceToBlockStart(block,
|
||||
p_cursor.positionInBlock())) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
@ -130,6 +130,10 @@ public:
|
||||
bool p_forward,
|
||||
int p_repeat);
|
||||
|
||||
// Check if we need to cancel auto indent.
|
||||
// @p_autoIndentPos: the position of the cursor after auto indent.
|
||||
static bool needToCancelAutoIndent(int p_autoIndentPos, const QTextCursor &p_cursor);
|
||||
|
||||
private:
|
||||
VEditUtils() {}
|
||||
};
|
||||
|
@ -518,7 +518,7 @@ bool VVim::handleKeyPressEvent(int key, int modifiers, int *p_autoIndentPos)
|
||||
bool resetPositionInBlock = true;
|
||||
Key keyInfo(key, modifiers);
|
||||
bool unindent = false;
|
||||
int autoIndentPos = -1;
|
||||
int autoIndentPos = p_autoIndentPos ? *p_autoIndentPos : -1;
|
||||
|
||||
// Handle Insert mode key press.
|
||||
if (VimMode::Insert == m_mode) {
|
||||
@ -527,20 +527,8 @@ bool VVim::handleKeyPressEvent(int key, int modifiers, int *p_autoIndentPos)
|
||||
// See if we need to cancel auto indent.
|
||||
bool cancelAutoIndent = false;
|
||||
if (p_autoIndentPos && *p_autoIndentPos > -1) {
|
||||
// Cancel the auto indent/list if the pos is the same and cursor is at
|
||||
// the end of a block.
|
||||
QTextCursor cursor = m_editor->textCursor();
|
||||
QTextBlock block = cursor.block();
|
||||
if (cursor.position() == *p_autoIndentPos && !cursor.hasSelection()) {
|
||||
if (VEditUtils::isListBlock(block)) {
|
||||
if (cursor.atBlockEnd()) {
|
||||
cancelAutoIndent = true;
|
||||
}
|
||||
} else if (VEditUtils::isSpaceToBlockStart(block,
|
||||
cursor.positionInBlock())) {
|
||||
cancelAutoIndent = true;
|
||||
}
|
||||
}
|
||||
cancelAutoIndent = VEditUtils::needToCancelAutoIndent(*p_autoIndentPos, cursor);
|
||||
|
||||
if (cancelAutoIndent) {
|
||||
autoIndentPos = -1;
|
||||
|
@ -553,20 +553,8 @@ bool VMdEditOperations::handleKeyReturn(QKeyEvent *p_event)
|
||||
if (m_autoIndentPos > -1) {
|
||||
// Cancel the auto indent/list if the pos is the same and cursor is at
|
||||
// the end of a block.
|
||||
bool cancelAutoIndent = false;
|
||||
QTextCursor cursor = m_editor->textCursor();
|
||||
QTextBlock block = cursor.block();
|
||||
if (cursor.position() == m_autoIndentPos && !cursor.hasSelection()) {
|
||||
if (VEditUtils::isListBlock(block)) {
|
||||
if (cursor.atBlockEnd()) {
|
||||
cancelAutoIndent = true;
|
||||
}
|
||||
} else if (VEditUtils::isSpaceToBlockStart(block,
|
||||
cursor.positionInBlock())) {
|
||||
cancelAutoIndent = true;
|
||||
}
|
||||
}
|
||||
if (cancelAutoIndent) {
|
||||
if (VEditUtils::needToCancelAutoIndent(m_autoIndentPos, cursor)) {
|
||||
m_autoIndentPos = -1;
|
||||
VEditUtils::deleteIndentAndListMark(cursor);
|
||||
m_editor->setTextCursor(cursor);
|
||||
|
Loading…
x
Reference in New Issue
Block a user