Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 36 additions & 1 deletion src/editor/dtextedit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3815,7 +3815,7 @@ void TextEdit::undo_()
m_pUndoStack->undo();
qCDebug(appLog) << "Undo operation executed, new stack index:" << m_pUndoStack->index();

const bool needUpdate = refreshUndoRedoColumnStatus();
const bool needUpdate = refreshUndoRedoColumnStatusAfterUndo();
if (needUpdate) {
renderAllSelections();
update();
Expand Down Expand Up @@ -9224,6 +9224,41 @@ bool TextEdit::refreshUndoRedoColumnStatus()
return false;
}

/**
@brief Call this function after undo, refresh column edit status.
After undo(), index() has decremented, so command(index()) points to the
just-undone (redo-pending) command. To determine the current edit mode,
check command(index()-1) — the current top of the applied stack.
@return True if need update selection status.
*/
bool TextEdit::refreshUndoRedoColumnStatusAfterUndo()
{
if (const QUndoCommand *cmd = m_pUndoStack->command(m_pUndoStack->index() - 1)) {
const int id = cmd->id();
const bool columnEdit = (id != Utils::IdDefault) && (Utils::IdColumnEdit & id);
if (columnEdit != m_bIsAltMod) {
// update selection
m_bIsAltMod = columnEdit;
if (!m_bIsAltMod) {
m_altModSelections.clear();
}

return true;
}

// in column editing, update every time.
if (columnEdit) {
return true;
}
} else {
// No commands applied after undo — leave column edit mode state
// unchanged; column mode entry/exit is driven by user actions,
// orthogonal to the undo stack state.
}

return false;
}

/**
* @brief 文档内容变更时触发
* 当前用于记录中键更新前后的动作并压入撤销栈,需要注意鼠标中键不会移除字符仅会插入选中的字符。
Expand Down
1 change: 1 addition & 0 deletions src/editor/dtextedit.h
Original file line number Diff line number Diff line change
Expand Up @@ -628,6 +628,7 @@ public slots:
bool findFoldBlock(int line, QTextBlock &beginBlock, QTextBlock &endBlock, QTextBlock &curBlock);

bool refreshUndoRedoColumnStatus();
bool refreshUndoRedoColumnStatusAfterUndo();

private slots:
// 文档内容变更时触发
Expand Down
Loading