1
0
Fork 0
mirror of https://github.com/anyproto/anytype-kotlin.git synced 2025-06-12 02:30:25 +09:00

Block merge | Carriage position issues (#383)

This commit is contained in:
Evgenii Kozlov 2020-04-21 21:55:47 +02:00 committed by GitHub
parent 0a6b8a407b
commit 0d0d04e130
Signed by: github
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 20 additions and 122 deletions

View file

@ -617,7 +617,7 @@ class PageViewModel(
fun onNonEmptyBlockBackspaceClicked(id: String) {
val page = blocks.first { it.id == context }
val index = page.children.indexOf(id)
if (index > 1) {
if (index > 0) {
val previous = page.children[index.dec()]
proceedWithMergingBlocks(
previous = previous,
@ -644,22 +644,23 @@ class PageViewModel(
}
fun onSplitLineEnterClicked(
id: String,
target: String,
index: Int
) {
splitBlock.invoke(
scope = viewModelScope,
params = SplitBlock.Params(
context = context,
target = id,
target = target,
index = index
)
) { result ->
result.either(
fnL = { Timber.e(it, "Error while splitting the target block with id: $id") },
fnR = { id -> updateFocus(id) }
)
}
),
onResult = { result ->
result.either(
fnL = { Timber.e(it, "Error while splitting block with id: $target") },
fnR = { updateFocus(target) }
)
}
)
}
fun onEndLineEnterTitleClicked() {

View file

@ -2185,58 +2185,6 @@ class PageViewModelTest {
)
}
@Test
fun `should not proceed with merging page title with the first paragraph on non-empty-block-backspace-pressed event`() {
val root = MockDataFactory.randomUuid()
val firstChild = MockDataFactory.randomUuid()
val secondChild = MockDataFactory.randomUuid()
val page = MockBlockFactory.makeOnePageWithTwoTextBlocks(
root = root,
firstChild = firstChild,
secondChild = secondChild,
firstChildStyle = Block.Content.Text.Style.TITLE,
secondChildStyle = Block.Content.Text.Style.P
)
val flow: Flow<List<Event.Command>> = flow {
delay(100)
emit(
listOf(
Event.Command.ShowBlock(
root = root,
blocks = page,
context = root
)
)
)
}
stubObserveEvents(flow)
stubOpenPage()
buildViewModel()
vm.open(root)
coroutineTestRule.advanceTime(100)
vm.onBlockFocusChanged(
id = secondChild,
hasFocus = true
)
vm.onNonEmptyBlockBackspaceClicked(
id = secondChild
)
verify(mergeBlocks, never()).invoke(
scope = any(),
params = any(),
onResult = any()
)
}
@Test
fun `should proceed with merging the first paragraph with the second on non-empty-block-backspace-pressed event`() {
@ -2461,7 +2409,7 @@ class PageViewModelTest {
val index = MockDataFactory.randomInt()
vm.onSplitLineEnterClicked(
id = child,
target = child,
index = index
)