From ac3f68e6cb7930b231ba32f850b004c48d09d281 Mon Sep 17 00:00:00 2001 From: Konstantin Ivanov <54908981+konstantiniiv@users.noreply.github.com> Date: Mon, 27 Dec 2021 12:35:58 +0200 Subject: [PATCH] Editor | Fix | Update mention names in headers (#2017) Co-authored-by: konstantiniiv --- .../features/editor/TextBlockHolder.kt | 3 + .../editor/render/DefaultBlockViewRenderer.kt | 117 +++++++++++------- 2 files changed, 72 insertions(+), 48 deletions(-) diff --git a/core-ui/src/main/java/com/anytypeio/anytype/core_ui/features/editor/TextBlockHolder.kt b/core-ui/src/main/java/com/anytypeio/anytype/core_ui/features/editor/TextBlockHolder.kt index f6e38ad5d1..b851253209 100644 --- a/core-ui/src/main/java/com/anytypeio/anytype/core_ui/features/editor/TextBlockHolder.kt +++ b/core-ui/src/main/java/com/anytypeio/anytype/core_ui/features/editor/TextBlockHolder.kt @@ -341,6 +341,9 @@ interface TextBlockHolder : TextHolder { content.pauseTextWatchers { enableEditMode() } + content.pauseTextWatchers { + content.applyMovementMethod(item) + } } else { enableReadMode() } diff --git a/presentation/src/main/java/com/anytypeio/anytype/presentation/editor/render/DefaultBlockViewRenderer.kt b/presentation/src/main/java/com/anytypeio/anytype/presentation/editor/render/DefaultBlockViewRenderer.kt index cb9ddeab3d..f1c51c70fb 100644 --- a/presentation/src/main/java/com/anytypeio/anytype/presentation/editor/render/DefaultBlockViewRenderer.kt +++ b/presentation/src/main/java/com/anytypeio/anytype/presentation/editor/render/DefaultBlockViewRenderer.kt @@ -571,23 +571,30 @@ class DefaultBlockViewRenderer( indent: Int, details: Block.Details, selection: Set - ): BlockView.Text.Header.Three = BlockView.Text.Header.Three( - mode = if (mode == EditorMode.Edit) BlockView.Mode.EDIT else BlockView.Mode.READ, - id = block.id, - text = content.text, - color = content.color, - isFocused = block.id == focus.id, - marks = content.marks(details = details, urlBuilder = urlBuilder), - backgroundColor = content.backgroundColor, - indent = indent, - alignment = content.align?.toView(), - cursor = if (block.id == focus.id) setCursor(focus, content) else null, - isSelected = checkIfSelected( - mode = mode, - block = block, - selection = selection + ): BlockView.Text.Header.Three { + val marks = content.marks(details = details, urlBuilder = urlBuilder) + val (normalizedText, normalizedMarks) = content.getTextAndMarks( + details = details, + marks = marks ) - ) + return BlockView.Text.Header.Three( + mode = if (mode == EditorMode.Edit) BlockView.Mode.EDIT else BlockView.Mode.READ, + id = block.id, + text = normalizedText, + color = content.color, + isFocused = block.id == focus.id, + marks = normalizedMarks, + backgroundColor = content.backgroundColor, + indent = indent, + alignment = content.align?.toView(), + cursor = if (block.id == focus.id) setCursor(focus, content) else null, + isSelected = checkIfSelected( + mode = mode, + block = block, + selection = selection + ) + ) + } private fun headerTwo( mode: EditorMode, @@ -597,23 +604,30 @@ class DefaultBlockViewRenderer( indent: Int, details: Block.Details, selection: Set - ): BlockView.Text.Header.Two = BlockView.Text.Header.Two( - mode = if (mode == EditorMode.Edit) BlockView.Mode.EDIT else BlockView.Mode.READ, - id = block.id, - text = content.text, - color = content.color, - isFocused = block.id == focus.id, - marks = content.marks(details = details, urlBuilder = urlBuilder), - backgroundColor = content.backgroundColor, - indent = indent, - alignment = content.align?.toView(), - cursor = if (block.id == focus.id) setCursor(focus, content) else null, - isSelected = checkIfSelected( - mode = mode, - block = block, - selection = selection + ): BlockView.Text.Header.Two { + val marks = content.marks(details = details, urlBuilder = urlBuilder) + val (normalizedText, normalizedMarks) = content.getTextAndMarks( + details = details, + marks = marks ) - ) + return BlockView.Text.Header.Two( + mode = if (mode == EditorMode.Edit) BlockView.Mode.EDIT else BlockView.Mode.READ, + id = block.id, + text = normalizedText, + color = content.color, + isFocused = block.id == focus.id, + marks = normalizedMarks, + backgroundColor = content.backgroundColor, + indent = indent, + alignment = content.align?.toView(), + cursor = if (block.id == focus.id) setCursor(focus, content) else null, + isSelected = checkIfSelected( + mode = mode, + block = block, + selection = selection + ) + ) + } private fun headerOne( mode: EditorMode, @@ -623,23 +637,30 @@ class DefaultBlockViewRenderer( indent: Int, details: Block.Details, selection: Set - ): BlockView.Text.Header.One = BlockView.Text.Header.One( - mode = if (mode == EditorMode.Edit) BlockView.Mode.EDIT else BlockView.Mode.READ, - id = block.id, - text = content.text, - color = content.color, - isFocused = block.id == focus.id, - marks = content.marks(details = details, urlBuilder = urlBuilder), - backgroundColor = content.backgroundColor, - indent = indent, - alignment = content.align?.toView(), - cursor = if (block.id == focus.id) setCursor(focus, content) else null, - isSelected = checkIfSelected( - mode = mode, - block = block, - selection = selection + ): BlockView.Text.Header.One { + val marks = content.marks(details = details, urlBuilder = urlBuilder) + val (normalizedText, normalizedMarks) = content.getTextAndMarks( + details = details, + marks = marks ) - ) + return BlockView.Text.Header.One( + mode = if (mode == EditorMode.Edit) BlockView.Mode.EDIT else BlockView.Mode.READ, + id = block.id, + text = normalizedText, + color = content.color, + isFocused = block.id == focus.id, + marks = normalizedMarks, + backgroundColor = content.backgroundColor, + indent = indent, + alignment = content.align?.toView(), + cursor = if (block.id == focus.id) setCursor(focus, content) else null, + isSelected = checkIfSelected( + mode = mode, + block = block, + selection = selection + ) + ) + } private fun checkbox( mode: EditorMode,