From 8b33f583301cd6c5c86ea37bc2ebc797424e85a0 Mon Sep 17 00:00:00 2001 From: Konstantin Ivanov <54908981+konstantiniiv@users.noreply.github.com> Date: Mon, 17 Jul 2023 18:50:57 +0200 Subject: [PATCH] DROID-1524 Editor | Fix | Mention for untitled objects isn't visible in block (#215) Co-authored-by: Evgenii Kozlov --- .../presentation/editor/EditorViewModel.kt | 2 +- .../editor/editor/EditorMentionTest.kt | 125 ++++++++++++++++++ 2 files changed, 126 insertions(+), 1 deletion(-) diff --git a/presentation/src/main/java/com/anytypeio/anytype/presentation/editor/EditorViewModel.kt b/presentation/src/main/java/com/anytypeio/anytype/presentation/editor/EditorViewModel.kt index ad88b6abd..56d1c9190 100644 --- a/presentation/src/main/java/com/anytypeio/anytype/presentation/editor/EditorViewModel.kt +++ b/presentation/src/main/java/com/anytypeio/anytype/presentation/editor/EditorViewModel.kt @@ -5722,7 +5722,7 @@ class EditorViewModel( val target = blocks.first { it.id == focus.value } val new = target.addMention( - mentionText = name, + mentionText = name.getMentionName(MENTION_TITLE_EMPTY), mentionId = id, from = mentionFrom, mentionTrigger = mentionTrigger diff --git a/presentation/src/test/java/com/anytypeio/anytype/presentation/editor/editor/EditorMentionTest.kt b/presentation/src/test/java/com/anytypeio/anytype/presentation/editor/editor/EditorMentionTest.kt index ad1d7e6b7..818080891 100644 --- a/presentation/src/test/java/com/anytypeio/anytype/presentation/editor/editor/EditorMentionTest.kt +++ b/presentation/src/test/java/com/anytypeio/anytype/presentation/editor/editor/EditorMentionTest.kt @@ -1083,6 +1083,131 @@ class EditorMentionTest : EditorPresentationTestSetup() { clearPendingCoroutines() } + @Test + fun `should update text as Untitled when mention text is empty`() { + + val title = Block( + id = MockDataFactory.randomUuid(), + content = Block.Content.Text( + text = MockDataFactory.randomString(), + style = Block.Content.Text.Style.TITLE, + marks = emptyList() + ), + children = emptyList(), + fields = Block.Fields.empty() + ) + + val header = Block( + id = MockDataFactory.randomUuid(), + content = Block.Content.Layout( + type = Block.Content.Layout.Type.HEADER + ), + fields = Block.Fields.empty(), + children = listOf(title.id) + ) + + val mentionTrigger = "@" + val from = 11 + val givenText = "page about $mentionTrigger music" + val mentionText = "" + val mentionHash = "ryew78yfhiuwehudc" + + val a = Block( + id = "dfhkshfjkhsdjhfjkhsjkd", + fields = Block.Fields.empty(), + children = emptyList(), + content = Block.Content.Text( + text = givenText, + marks = listOf(), + style = Block.Content.Text.Style.P + ) + ) + + val page = Block( + id = root, + fields = Block.Fields(emptyMap()), + content = Block.Content.Smart, + children = listOf(header.id, a.id) + ) + + val document = listOf(page, header, title, a) + + stubOpenDocument(document) + stubInterceptEvents() + + updateText.stub { + onBlocking { invoke(any()) } doReturn Either.Right(Unit) + } + + searchObjects.stub { + onBlocking { invoke(any()) } doReturn Either.Right(listOf()) + } + + val vm = buildViewModel() + + vm.onStart(root) + + vm.apply { + onBlockFocusChanged( + id = a.id, + hasFocus = true + ) + onSelectionChanged( + id = a.id, + selection = IntRange(12, 12) + ) + onMentionEvent( + MentionEvent.MentionSuggestStart( + cursorCoordinate = 500, + mentionStart = from + ) + ) + onCreateMentionInText( + id = mentionHash, + name = mentionText, + mentionTrigger = mentionTrigger + ) + } + + vm.state.test().apply { + assertValue( + ViewState.Success( + blocks = listOf( + BlockView.Title.Basic( + id = title.id, + isFocused = false, + text = title.content().text, + mode = BlockView.Mode.EDIT + ), + BlockView.Text.Paragraph( + id = a.id, + cursor = 12, + isSelected = false, + isFocused = true, + marks = listOf( + Markup.Mark.Mention.Loading( + from = from, + to = from + MENTION_TITLE_EMPTY.length, + param = mentionHash + ) + ), + indent = 0, + text = "page about $MENTION_TITLE_EMPTY music", + mode = BlockView.Mode.EDIT, + decorations = listOf( + BlockView.Decoration( + background = a.parseThemeBackgroundColor() + ) + ) + ) + ) + ) + ) + } + + clearPendingCoroutines() + } + private fun clearPendingCoroutines() { coroutineTestRule.advanceTime(EditorViewModel.TEXT_CHANGES_DEBOUNCE_DURATION) }