Skip to content

Commit

Permalink
UP-23, UP-24 Added moving cursor after inserted character
Browse files Browse the repository at this point in the history
  • Loading branch information
tatyanakrivonogova committed May 28, 2024
1 parent 2dbf713 commit 71bd28e
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
3 changes: 3 additions & 0 deletions src/document/document.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@ void Document::updateCursor() {
void Document::Insert(Glyph::GlyphPtr& glyph) {
currentPage->Insert(glyph);
compositor->Compose();

selectedGlyph = glyph;
this->updateCursor();
// glyph->Draw();
}

Expand Down
20 changes: 19 additions & 1 deletion test/model/text_editor_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2067,7 +2067,25 @@ TEST(Document_Cursor1,
auto d = std::make_shared<Document>(std::make_shared<SimpleCompositor>());

Glyph::GlyphPtr selectedGlyph = d->GetSelectedGlyph();
std::cout << *selectedGlyph << std::endl;
Row::RowPtr selectedRow = std::dynamic_pointer_cast<Row>(selectedGlyph);
EXPECT_TRUE(selectedRow != nullptr);
EXPECT_TRUE(selectedRow ==
d->GetFirstPage()->GetFirstGlyph()->GetFirstGlyph());
std::cout << *selectedRow << std::endl;
}

TEST(Document_Cursor2,
DocumentCursorAfterInsertedChar_WhenCalles_ReturnGlyphNextToCursor) {
auto d = std::make_shared<Document>(std::make_shared<SimpleCompositor>());

Character c1 = Character(0, 0, 10, 10, 'A');
Glyph::GlyphPtr c1Ptr = std::make_shared<Character>(c1);
d->Insert(c1Ptr);

Glyph::GlyphPtr selectedGlyph = d->GetSelectedGlyph();
Character::CharPtr selectedChar =
std::dynamic_pointer_cast<Character>(selectedGlyph);
EXPECT_TRUE(selectedChar != nullptr);
EXPECT_TRUE(selectedChar == c1Ptr);
std::cout << *selectedChar << std::endl;
}

0 comments on commit 71bd28e

Please sign in to comment.