我有麻烦。这里我的代码是:
void TextEditor::moveToLineUp()
{
QTextCursor cur = textCursor();
if(cur.hasSelection()) {
int start = cur.selectionStart();
int end = cur.selectionEnd();
QTextBlock startBlock = document()->findBlock(start);
QTextBlock endBlock = document()->findBlock(end);
cur.setPosition(startBlock.position());
cur.setPosition(endBlock.position()+endBlock.length(), QTextCursor::KeepAnchor);
} else {
// I'll fill it later
}
// ??? I don't know how not to write remove action in undo stack
QString text = cur.selectedText();
cur.removeSelectedText();
QTextCursor ncur(cur.block().previous());
ncur.insertText(text);
}
当用户选择一些文本并单击“排队”按钮时,将调用此函数。有选择的每一行都应该移动到一行。但在那之后撤消堆栈必须执行以下步骤:删除文本并粘贴文本。我应该怎么办?我想一步一步让它变得简单。