3

問題があります。ここに私のコードは次のとおりです。

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);
}

ユーザーがテキストを選択し、「整列」ボタンをクリックすると、この関数が呼び出されます。選択されているすべての行は、1 行上に移動する必要があります。ただし、その後、スタックを元に戻すには、次の手順を実行する必要があります。テキストを削除してテキストを貼り付けます。私は何をすべきか?ワンステップで簡単操作にしたい。

4

0 に答える 0