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

DROID-284 Editor | Enhancement | Ignore html when copying Anytype content to third-party mobile apps (#2707)

This commit is contained in:
Evgenii Kozlov 2022-11-16 19:52:01 +03:00 committed by GitHub
parent 613fc45b18
commit 00dc75d62e
Signed by: github
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 43 additions and 8 deletions

View file

@ -13,10 +13,9 @@ class AnytypeClipboard(
private val cm: ClipboardManager
) : ClipboardDataStore.System {
override suspend fun put(text: String, html: String?) {
override suspend fun put(text: String, html: String?, ignoreHtml: Boolean) {
val uri = Uri.parse(ANYTYPE_CLIPBOARD_URI)
if (html != null)
if (!ignoreHtml && html != null)
cm.setPrimaryClip(
ClipData.newHtmlText(ANYTYPE_CLIPBOARD_LABEL, text, html).apply {
addItem(ClipData.Item(uri))

View file

@ -37,7 +37,8 @@ class AndroidClipboardTest {
runBlocking {
clipboard.put(
text = text,
html = null
html = null,
ignoreHtml = MockDataFactory.randomBoolean()
)
}
@ -50,6 +51,33 @@ class AndroidClipboardTest {
assertNotNull(cm.primaryClip?.getItemAt(1)?.uri)
}
@Test
fun `should put text, ignore html and put uri as second item`() {
val text = MockDataFactory.randomString()
val html = MockDataFactory.randomString()
runBlocking {
clipboard.put(
text = text,
html = html,
ignoreHtml = true
)
}
assertEquals(
expected = text,
actual = cm.primaryClip?.getItemAt(0)?.text
)
assertEquals(
expected = null,
actual = cm.primaryClip?.getItemAt(0)?.htmlText
)
assertNull(cm.primaryClip?.getItemAt(0)?.uri)
assertNotNull(cm.primaryClip?.getItemAt(1)?.uri)
}
@Test
fun `should put text, html as first item and uri as second item`() {
val text = MockDataFactory.randomString()
@ -58,7 +86,8 @@ class AndroidClipboardTest {
runBlocking {
clipboard.put(
text = text,
html = html
html = html,
ignoreHtml = false
)
}

View file

@ -14,7 +14,8 @@ class ClipboardDataRepository(
)
factory.system.put(
text = text,
html = html
html = html,
ignoreHtml = true
)
}

View file

@ -20,7 +20,7 @@ interface ClipboardDataStore {
/**
* Stores copied [text] and optionally a [html] representation on the systen clipboard.
*/
suspend fun put(text: String, html: String?)
suspend fun put(text: String, html: String?, ignoreHtml: Boolean)
/**
* @return current clip on the clipboard.

View file

@ -239,7 +239,13 @@ fun Block.Content.Text.Mark.toMiddlewareModel(): MBMark = when (type) {
param_ = param.orEmpty()
)
}
else -> throw IllegalStateException("Unsupported mark type: ${type.name}")
Block.Content.Text.Mark.Type.EMOJI -> {
MBMark(
range = range.range(),
type = MBMarkType.Emoji,
param_ = param.orEmpty()
)
}
}
fun IntRange.range(): Range = Range(from = first, to = last)