void UndoManagerTest::testSelectionUndo() { TestDocument doc; KateView *view = static_cast<KateView*>(doc.createView(0)); doc.setText("aaaa bbbb cccc\n" "dddd eeee ffff"); view->setCursorPosition(KTextEditor::Cursor(1, 9)); KTextEditor::Range selectionRange(KTextEditor::Cursor(0, 5), KTextEditor::Cursor(1, 9)); view->setSelection(selectionRange); doc.typeChars(view, "eeee"); // cursor position: "aaaa eeee| ffff", no selection anymore QCOMPARE(view->cursorPosition(), KTextEditor::Cursor(0, 9)); QCOMPARE(view->selection(), false); // undo to remove "eeee" and add selection and text again doc.undo(); QCOMPARE(view->cursorPosition(), KTextEditor::Cursor(1, 9)); QCOMPARE(view->selection(), true); QCOMPARE(view->selectionRange(), selectionRange); // redo to insert "eeee" again and remove selection // cursor position: "aaaa eeee| ffff", no selection anymore doc.redo(); QCOMPARE(view->cursorPosition(), KTextEditor::Cursor(0, 9)); QCOMPARE(view->selection(), false); delete view; }
void UndoManagerTest::testCursorPosition() { TestDocument doc; KateView *view = static_cast<KateView*>(doc.createView(0)); doc.setText("aaaa bbbb cccc\n" "dddd ffff"); view->setCursorPosition(KTextEditor::Cursor(1, 5)); doc.typeChars(view, "eeee"); // cursor position: "dddd eeee| ffff" QCOMPARE(view->cursorPosition(), KTextEditor::Cursor(1, 9)); // undo once to remove "eeee", cursor position: "dddd | ffff" doc.undo(); QCOMPARE(view->cursorPosition(), KTextEditor::Cursor(1, 5)); // redo once to insert "eeee" again. cursor position: "dddd eeee| ffff" doc.redo(); QCOMPARE(view->cursorPosition(), KTextEditor::Cursor(1, 9)); delete view; }