mirror of
https://github.com/anyproto/anytype-kotlin.git
synced 2025-06-08 05:47:05 +09:00
DROID-2691 Editor | Do not show the keyboard when clicking on mention markup. (#1964)
This commit is contained in:
parent
fe00ed3b52
commit
a6a9167b6f
3 changed files with 37 additions and 17 deletions
|
@ -16,6 +16,7 @@ import com.anytypeio.anytype.core_utils.ext.VALUE_ROUNDED
|
|||
import com.anytypeio.anytype.core_utils.ext.removeSpans
|
||||
import com.anytypeio.anytype.presentation.editor.editor.Markup
|
||||
import com.anytypeio.anytype.core_models.ThemeColor
|
||||
import com.anytypeio.anytype.core_ui.extensions.disable
|
||||
import timber.log.Timber
|
||||
|
||||
fun Markup.toSpannable(
|
||||
|
@ -498,8 +499,7 @@ fun Editable.proceedWithSettingMentionSpan(
|
|||
fun Editable.setClickableSpan(click: ((String) -> Unit)?, mark: Markup.Mark.Mention) {
|
||||
val clickableSpan = object : ClickableSpan() {
|
||||
override fun onClick(widget: View) {
|
||||
// TODO consider pausing text watchers. Otherwise, redundant text watcher events will be triggered.
|
||||
(widget as? TextInputWidget)?.enableReadMode()
|
||||
(widget as? TextInputWidget)?.disable()
|
||||
click?.invoke(mark.param)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,16 +1,9 @@
|
|||
package com.anytypeio.anytype.core_ui.extensions
|
||||
|
||||
import android.graphics.Point
|
||||
import com.anytypeio.anytype.core_ui.common.isLinksOrMentionsPresent
|
||||
import com.anytypeio.anytype.core_ui.widgets.text.TextInputWidget
|
||||
import com.anytypeio.anytype.presentation.editor.editor.Markup
|
||||
|
||||
fun TextInputWidget.preserveSelection(block: () -> Unit) = synchronized(this) {
|
||||
val selection = selectionStart..selectionEnd
|
||||
block()
|
||||
setSelection(selection.first, selection.last)
|
||||
}
|
||||
|
||||
fun TextInputWidget.applyMovementMethod(item: Markup) {
|
||||
if (item.marks.isNotEmpty() && item.marks.isLinksOrMentionsPresent()) {
|
||||
setLinksClickable()
|
||||
|
@ -19,12 +12,9 @@ fun TextInputWidget.applyMovementMethod(item: Markup) {
|
|||
}
|
||||
}
|
||||
|
||||
fun TextInputWidget.getSelectionCoords(): Point {
|
||||
val pos = selectionStart
|
||||
val line = layout.getLineForOffset(pos)
|
||||
val baseline = layout.getLineBaseline(line)
|
||||
val ascent = layout.getLineAscent(line)
|
||||
val x = layout.getPrimaryHorizontal(pos).toInt()
|
||||
val y = baseline + ascent
|
||||
return Point(x, y)
|
||||
fun TextInputWidget.disable() {
|
||||
isEnabled = false
|
||||
pauseTextWatchers {
|
||||
enableReadMode()
|
||||
}
|
||||
}
|
|
@ -4,10 +4,13 @@ import android.os.Build
|
|||
import android.os.Handler
|
||||
import android.os.Looper
|
||||
import android.os.SystemClock
|
||||
import android.text.Layout
|
||||
import android.text.style.ClickableSpan
|
||||
import android.view.HapticFeedbackConstants
|
||||
import android.view.MotionEvent
|
||||
import android.view.View
|
||||
import android.view.ViewConfiguration
|
||||
import com.anytypeio.anytype.core_ui.extensions.disable
|
||||
import com.anytypeio.anytype.core_ui.widgets.text.TextInputWidget
|
||||
import timber.log.Timber
|
||||
import kotlin.math.abs
|
||||
|
@ -84,6 +87,33 @@ class EditorTouchProcessor(
|
|||
moves.clear()
|
||||
Timber.d("ACTION UP")
|
||||
actionHandler.removeCallbacksAndMessages(null)
|
||||
|
||||
/**
|
||||
* When clicking on mention text, the code contains two separate logics
|
||||
* that handle clicks on this text: the EditorTouchProcessor,
|
||||
* which is responsible for triggering drag-and-drop or long-click mode,
|
||||
* and the ClickableSpan, which is applied to the mention text.
|
||||
* Since it is impossible to predict which listener will execute first,
|
||||
* the click on the mention is handled in two different places.
|
||||
* @see fun Editable.setClickableSpan(click: ((String) -> Unit)?, mark: Markup.Mark.Mention)
|
||||
*/
|
||||
if (v is TextInputWidget) {
|
||||
val x = (event.x - v.totalPaddingLeft + v.scrollX).toInt()
|
||||
val y = (event.y - v.totalPaddingTop + v.scrollY).toInt()
|
||||
|
||||
val layout: Layout = v.layout
|
||||
val line = layout.getLineForVertical(y)
|
||||
val offset = layout.getOffsetForHorizontal(line, x.toFloat())
|
||||
|
||||
val link =
|
||||
v.editableText.getSpans(offset, offset, ClickableSpan::class.java)
|
||||
if (link.isNotEmpty()) {
|
||||
v.disable()
|
||||
link[0].onClick(v)
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
return when (actionUpStartInMillis.untilNow()) {
|
||||
in LONG_PRESS_TIMEOUT..DND_TIMEOUT -> {
|
||||
onLongClick()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue