1
0
Fork 0
mirror of https://github.com/anyproto/anytype-kotlin.git synced 2025-06-08 13:57:10 +09:00

Clicking on empty space before document is loaded should not crash application (#930)

This commit is contained in:
Evgenii Kozlov 2020-09-28 12:46:30 +03:00 committed by GitHub
parent 2a486cd541
commit ab722c8e49
Signed by: github
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 61 additions and 27 deletions

View file

@ -6,6 +6,10 @@
* Changed object names in add-block and turn-into panels (#752)
### Fixes & tech 🚒
* Clicking on empty space before document is loaded should not crash application (#930)
## Version 0.0.49
### Fixes & tech 🚒

View file

@ -1776,35 +1776,35 @@ class PageViewModel(
}
fun onOutsideClicked() {
blocks.first { it.id == context }.let { page ->
if (page.children.isNotEmpty()) {
val last = blocks.first { it.id == page.children.last() }
when (val content = last.content) {
is Content.Text -> {
when {
content.style == Content.Text.Style.TITLE -> addNewBlockAtTheEnd()
content.text.isNotEmpty() -> addNewBlockAtTheEnd()
else -> Timber.d("Outside-click has been ignored.")
}
}
is Content.Link -> {
addNewBlockAtTheEnd()
}
is Content.Bookmark -> {
addNewBlockAtTheEnd()
}
is Content.File -> {
addNewBlockAtTheEnd()
}
is Content.Divider -> {
addNewBlockAtTheEnd()
}
else -> {
Timber.d("Outside-click has been ignored.")
val root = blocks.find { it.id == context } ?: return
if (root.children.isEmpty()) {
addNewBlockAtTheEnd()
} else {
val last = blocks.first { it.id == root.children.last() }
when (val content = last.content) {
is Content.Text -> {
when {
content.style == Content.Text.Style.TITLE -> addNewBlockAtTheEnd()
content.text.isNotEmpty() -> addNewBlockAtTheEnd()
else -> Timber.d("Outside-click has been ignored.")
}
}
} else {
addNewBlockAtTheEnd()
is Content.Link -> {
addNewBlockAtTheEnd()
}
is Content.Bookmark -> {
addNewBlockAtTheEnd()
}
is Content.File -> {
addNewBlockAtTheEnd()
}
is Content.Divider -> {
addNewBlockAtTheEnd()
}
else -> {
Timber.d("Outside-click has been ignored.")
}
}
}
}

View file

@ -0,0 +1,30 @@
package com.anytypeio.anytype.presentation.page.editor
import androidx.arch.core.executor.testing.InstantTaskExecutorRule
import com.anytypeio.anytype.presentation.util.CoroutinesTestRule
import com.nhaarman.mockitokotlin2.verifyZeroInteractions
import org.junit.Before
import org.junit.Rule
import org.junit.Test
import org.mockito.MockitoAnnotations
class EditorEmptySpaceInteractionTest : EditorPresentationTestSetup() {
@get:Rule
val rule = InstantTaskExecutorRule()
@get:Rule
val coroutineTestRule = CoroutinesTestRule()
@Before
fun setup() {
MockitoAnnotations.initMocks(this)
}
@Test
fun `should ignore outside click if document isn't started yet`() {
val vm = buildViewModel()
vm.onOutsideClicked()
verifyZeroInteractions(createBlock)
}
}