Exemplo n.º 1
0
void UndoManagerTest::testUndoRedoCount()
{
  TestDocument doc;
  KateUndoManager *undoManager = doc.undoManager();

  // no undo/redo items at the beginning
  QCOMPARE(undoManager->undoCount(), 0u);
  QCOMPARE(undoManager->redoCount(), 0u);

  doc.insertText(Cursor(0, 0), "a");

  // create one insert-group
  QCOMPARE(undoManager->undoCount(), 1u);
  QCOMPARE(undoManager->redoCount(), 0u);

  doc.undo();

  // move insert-group to redo items
  QCOMPARE(undoManager->undoCount(), 0u);
  QCOMPARE(undoManager->redoCount(), 1u);

  doc.redo();

  // move insert-group back to undo items
  QCOMPARE(undoManager->undoCount(), 1u);
  QCOMPARE(undoManager->redoCount(), 0u);

  doc.insertText(Cursor(0, 1), "b");

  // merge "b" into insert-group
  QCOMPARE(undoManager->undoCount(), 1u);
  QCOMPARE(undoManager->redoCount(), 0u);

  doc.removeText(Range(0, 1, 0, 2));

  // create an additional remove-group
  QCOMPARE(undoManager->undoCount(), 2u);
  QCOMPARE(undoManager->redoCount(), 0u);

  doc.undo();

  // move remove-group to redo items
  QCOMPARE(undoManager->undoCount(), 1u);
  QCOMPARE(undoManager->redoCount(), 1u);

  doc.insertText(Cursor(0, 1), "b");

  // merge "b" into insert-group
  // and remove remove-group
  QCOMPARE(undoManager->undoCount(), 1u);
  QCOMPARE(undoManager->redoCount(), 0u);
}
Exemplo n.º 2
0
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;
}
Exemplo n.º 3
0
void TestKoTextEditor::testRemoveSelectedText()
{
    TestDocument doc;

    KoTextEditor *editor = doc.textEditor();
    KoTextRangeManager *rangeManager = &doc.m_rangeManager;

    // enter some lorem ipsum
    editor->insertText(lorem);

    QTextCursor cur(doc.m_document);
    cur.setPosition(editor->position());
    KoBookmark *bookmark = new KoBookmark(cur);
    bookmark->setName("start!");
    bookmark->setPositionOnlyMode(false); // we want it to be several chars long
    rangeManager->insert(bookmark);

    editor->insertText(lorem);

    bookmark->setRangeEnd(editor->position());

    QCOMPARE(bookmark->rangeStart(), lorem.length());
    QCOMPARE(bookmark->rangeEnd(), lorem.length() * 2);
    Q_ASSERT(rangeManager->textRanges().length() == 1);

    // select all text
    editor->setPosition(0, QTextCursor::MoveAnchor);
    editor->movePosition(QTextCursor::End, QTextCursor::KeepAnchor);

    Q_ASSERT(editor->hasSelection());

    // remove the text + the bookmark from the document
    editor->deleteChar();

    // check whether the bookmark has gone.
    Q_ASSERT(rangeManager->textRanges().length() == 0);
}
Exemplo n.º 4
0
void TestKoTextEditor::testPaste()
{
    TestDocument *source = new TestDocument();
    TestDocument *destination = new TestDocument();

    Q_ASSERT(source->textEditor() != destination->textEditor());

    KoShapeController shapeController(0, destination);

    source->textEditor()->insertText("bla");

    destination->textEditor()->paste(source->textEditor(), &shapeController);

    Q_ASSERT(destination->m_document->toPlainText() == "bla");


}
Exemplo n.º 5
0
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;
}
Exemplo n.º 6
0
void UndoManagerTest::testSafePoint()
{
  TestDocument doc;
  KateUndoManager *undoManager = doc.undoManager();

  doc.insertText(Cursor(0, 0), "a");

  // create one undo group
  QCOMPARE(undoManager->undoCount(), 1u);
  QCOMPARE(undoManager->redoCount(), 0u);

  undoManager->undoSafePoint();
  doc.insertText(Cursor(0, 1), "b");

  // create a second undo group (don't merge)
  QCOMPARE(undoManager->undoCount(), 2u);

  doc.undo();

  // move second undo group to redo items
  QCOMPARE(undoManager->undoCount(), 1u);
  QCOMPARE(undoManager->redoCount(), 1u);

  doc.insertText(Cursor(0, 1), "b");

  // create a second undo group again, (don't merge)
  QCOMPARE(undoManager->undoCount(), 2u);
  QCOMPARE(undoManager->redoCount(), 0u);

  doc.editStart();
  doc.insertText(Cursor(0, 2), "c");
  undoManager->undoSafePoint();
  doc.insertText(Cursor(0, 3), "d");
  doc.editEnd();

  // merge both edits into second undo group
  QCOMPARE(undoManager->undoCount(), 2u);
  QCOMPARE(undoManager->redoCount(), 0u);

  doc.insertText(Cursor(0, 4), "e");

  // create a third undo group (don't merge)
  QCOMPARE(undoManager->undoCount(), 3u);
  QCOMPARE(undoManager->redoCount(), 0u);
}