diff --git a/CHANGELOG.md b/CHANGELOG.md index 6b9fa2d5f9..4c21516990 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,7 @@ * Should save the latest text input if you close the page quickly (#1067) * Keyboard won't show up in code snippet on Android 7 (#1024) +* Do not crash if document's title is broken after paste (#1108) ### Middleware ⚙ diff --git a/presentation/src/main/java/com/anytypeio/anytype/presentation/page/PageViewModel.kt b/presentation/src/main/java/com/anytypeio/anytype/presentation/page/PageViewModel.kt index c79ec3a5eb..a6364e72b6 100644 --- a/presentation/src/main/java/com/anytypeio/anytype/presentation/page/PageViewModel.kt +++ b/presentation/src/main/java/com/anytypeio/anytype/presentation/page/PageViewModel.kt @@ -544,14 +544,18 @@ class PageViewModel( val first = event.blocks.first { it.id == root.children.first() } val content = first.content if (content is Content.Layout && content.type == Content.Layout.Type.HEADER) { - val title = event.blocks.title() - val focus = Editor.Focus(id = title.id, cursor = Editor.Cursor.End) - viewModelScope.launch { orchestrator.stores.focus.update(focus) } - controlPanelInteractor.onEvent( - ControlPanelMachine.Event.OnFocusChanged( - id = title.id, style = Content.Text.Style.TITLE + try { + val title = event.blocks.title() + val focus = Editor.Focus(id = title.id, cursor = Editor.Cursor.End) + viewModelScope.launch { orchestrator.stores.focus.update(focus) } + controlPanelInteractor.onEvent( + ControlPanelMachine.Event.OnFocusChanged( + id = title.id, style = Content.Text.Style.TITLE + ) ) - ) + } catch (e: Throwable) { + Timber.e(e, "Error while initial focusing") + } } } else -> Timber.d("Skipping initial focusing, document is not empty.")