mirror of
https://github.com/anyproto/anytype-kotlin.git
synced 2025-06-10 10:00:44 +09:00
DROID-747 Editor | Fix | Simple tables, mention widget close (#2803)
* DROID-747 setup cell view holder * DROID-747 on mention stop, cell case * DROID-747 test * DROID-747 fix
This commit is contained in:
parent
db15e9e8d1
commit
67878e3bc4
5 changed files with 106 additions and 1 deletions
|
@ -110,7 +110,14 @@ class TableEditableCellsAdapter(
|
|||
onEmptyBlockBackspaceClicked = {},
|
||||
onSplitLineEnterClicked = { _, _, _ -> },
|
||||
onNonEmptyBlockBackspaceClicked = { _, _ -> },
|
||||
onMentionEvent = onMentionEvent,
|
||||
onMentionEvent = { mentionEvent ->
|
||||
onMentionEvent(
|
||||
when (mentionEvent) {
|
||||
MentionEvent.MentionSuggestStop -> MentionEvent.MentionSuggestStopCell
|
||||
else -> mentionEvent
|
||||
}
|
||||
)
|
||||
},
|
||||
onSlashEvent = {},
|
||||
onBackPressedCallback = null
|
||||
)
|
||||
|
|
|
@ -218,6 +218,7 @@ sealed class ControlPanelMachine {
|
|||
|
||||
object OnMentionClicked : Mentions()
|
||||
object OnStop : Mentions()
|
||||
object OnStopCell : Mentions()
|
||||
}
|
||||
|
||||
sealed class Slash : Event() {
|
||||
|
@ -788,6 +789,20 @@ sealed class ControlPanelMachine {
|
|||
),
|
||||
mainToolbar = Toolbar.Main(isVisible = true)
|
||||
)
|
||||
is Event.Mentions.OnStopCell -> state.copy(
|
||||
mentionToolbar = state.mentionToolbar.copy(
|
||||
isVisible = false,
|
||||
cursorCoordinate = null,
|
||||
updateList = false,
|
||||
mentionFrom = null,
|
||||
mentionFilter = null,
|
||||
mentions = emptyList()
|
||||
),
|
||||
mainToolbar = state.mainToolbar.copy(
|
||||
isVisible = true,
|
||||
targetBlockType = Toolbar.Main.TargetBlockType.Cell
|
||||
)
|
||||
)
|
||||
is Event.Mentions.OnResult -> state.copy(
|
||||
mentionToolbar = state.mentionToolbar.copy(
|
||||
mentions = event.mentions,
|
||||
|
|
|
@ -5476,6 +5476,12 @@ class EditorViewModel(
|
|||
mentionFilter.value = ""
|
||||
controlPanelInteractor.onEvent(ControlPanelMachine.Event.Mentions.OnStop)
|
||||
}
|
||||
MentionEvent.MentionSuggestStopCell -> {
|
||||
mentionFrom = -1
|
||||
jobMentionFilter?.cancel()
|
||||
mentionFilter.value = ""
|
||||
controlPanelInteractor.onEvent(ControlPanelMachine.Event.Mentions.OnStopCell)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -4,4 +4,5 @@ sealed class MentionEvent {
|
|||
data class MentionSuggestText(val text: CharSequence) : MentionEvent()
|
||||
data class MentionSuggestStart(val cursorCoordinate : Int, val mentionStart: Int) : MentionEvent()
|
||||
object MentionSuggestStop : MentionEvent()
|
||||
object MentionSuggestStopCell : MentionEvent()
|
||||
}
|
|
@ -16,6 +16,7 @@ import com.anytypeio.anytype.presentation.editor.Editor
|
|||
import com.anytypeio.anytype.presentation.editor.editor.EditorPresentationTestSetup
|
||||
import com.anytypeio.anytype.presentation.editor.editor.control.ControlPanelState
|
||||
import com.anytypeio.anytype.presentation.editor.editor.listener.ListenerType
|
||||
import com.anytypeio.anytype.presentation.editor.editor.mention.MentionEvent
|
||||
import com.anytypeio.anytype.presentation.editor.editor.model.BlockView
|
||||
import com.anytypeio.anytype.presentation.util.CoroutinesTestRule
|
||||
import com.anytypeio.anytype.test_utils.MockDataFactory
|
||||
|
@ -1338,6 +1339,81 @@ class EditorTableBlockTest : EditorPresentationTestSetup() {
|
|||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `when mention widget is closed with mention stop event , should be main menu for cells is visible`() {
|
||||
|
||||
//SETUP
|
||||
val columns = StubTableColumns(size = 2)
|
||||
val rows = StubTableRows(size = 1)
|
||||
val cells = StubTableCells(columns = columns, rows = rows)
|
||||
val columnLayout = StubLayoutColumns(children = columns.map { it.id })
|
||||
val rowLayout = StubLayoutRows(children = rows.map { it.id })
|
||||
val table = StubTable(id = tableId, children = listOf(columnLayout.id, rowLayout.id))
|
||||
val title = StubTitle()
|
||||
val header = StubHeader(children = listOf(title.id))
|
||||
val page = StubSmartBlock(id = root, children = listOf(header.id, table.id))
|
||||
val document =
|
||||
listOf(page, header, title, table, columnLayout, rowLayout) + columns + rows + cells
|
||||
stubInterceptEvents()
|
||||
stubOpenDocument(document)
|
||||
stubUpdateText()
|
||||
|
||||
//TESTING Focus Cell[0] - Add @ - Mention widget is visible - delete @
|
||||
// - main toolbar for cells is visible
|
||||
val vm = buildViewModel()
|
||||
vm.apply {
|
||||
onStart(root)
|
||||
|
||||
onBlockFocusChanged(
|
||||
id = cells[0].id,
|
||||
hasFocus = true
|
||||
)
|
||||
|
||||
onMentionEvent(
|
||||
mentionEvent = MentionEvent.MentionSuggestStart(
|
||||
cursorCoordinate = 0,
|
||||
mentionStart = 0
|
||||
)
|
||||
)
|
||||
|
||||
onMentionEvent(
|
||||
mentionEvent = MentionEvent.MentionSuggestText(
|
||||
text = "@"
|
||||
)
|
||||
)
|
||||
|
||||
val blockView = BlockView.Text.Paragraph(id = cells[0].id, text = "@")
|
||||
onTextBlockTextChanged(
|
||||
view = blockView
|
||||
)
|
||||
|
||||
onSelectionChanged(
|
||||
id = blockView.id,
|
||||
selection = IntRange(1, 1)
|
||||
)
|
||||
|
||||
onMentionEvent(mentionEvent = MentionEvent.MentionSuggestStopCell)
|
||||
}
|
||||
|
||||
//EXPECTED
|
||||
val expectedMode = Editor.Mode.Edit
|
||||
|
||||
val expectedMainToolbar = ControlPanelState.Toolbar.Main(
|
||||
isVisible = true,
|
||||
targetBlockType = ControlPanelState.Toolbar.Main.TargetBlockType.Cell
|
||||
)
|
||||
|
||||
//ASSERT
|
||||
assertEquals(
|
||||
expected = expectedMode,
|
||||
actual = vm.mode as Editor.Mode.Edit
|
||||
)
|
||||
assertEquals(
|
||||
expected = expectedMainToolbar,
|
||||
actual = vm.controlPanelViewState.value?.mainToolbar
|
||||
)
|
||||
}
|
||||
|
||||
private fun mapToViewCell(
|
||||
cell: Block,
|
||||
row: Block,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue