mirror of
https://github.com/anyproto/anytype-kotlin.git
synced 2025-06-10 01:51:05 +09:00
Add-markup corner-case algorithm issues (#809)
This commit is contained in:
parent
2a8e5a60ae
commit
0bb0023696
3 changed files with 240 additions and 2 deletions
|
@ -4,6 +4,7 @@
|
|||
|
||||
### Fixes & tech 🚒
|
||||
|
||||
* Inconsistent logic when adding markup in certain corner cases (#509)
|
||||
* If you change checkbox's text color and then check off this checkbox, its text color always becomes black whereas it should have the color that you've set before (#785)
|
||||
|
||||
## Version 0.0.46
|
||||
|
|
|
@ -62,12 +62,14 @@ fun Marks.toggle(target: Mark): Marks {
|
|||
)
|
||||
)
|
||||
}
|
||||
} else
|
||||
} else {
|
||||
result.add(
|
||||
mark.copy(
|
||||
range = target.range.last..mark.range.last
|
||||
)
|
||||
)
|
||||
del.add(target)
|
||||
}
|
||||
}
|
||||
Overlap.INNER_RIGHT -> {
|
||||
if (target.type == Mark.Type.TEXT_COLOR || target.type == Mark.Type.BACKGROUND_COLOR) {
|
||||
|
@ -81,12 +83,14 @@ fun Marks.toggle(target: Mark): Marks {
|
|||
)
|
||||
result.add(target)
|
||||
}
|
||||
} else
|
||||
} else {
|
||||
result.add(
|
||||
mark.copy(
|
||||
range = mark.range.first..target.range.first
|
||||
)
|
||||
)
|
||||
del.add(target)
|
||||
}
|
||||
}
|
||||
Overlap.INNER -> {
|
||||
if (target.type == Mark.Type.TEXT_COLOR || target.type == Mark.Type.BACKGROUND_COLOR) {
|
||||
|
@ -116,6 +120,7 @@ fun Marks.toggle(target: Mark): Marks {
|
|||
range = target.range.last..mark.range.last
|
||||
)
|
||||
)
|
||||
del.add(target)
|
||||
}
|
||||
}
|
||||
Overlap.LEFT -> {
|
||||
|
|
|
@ -1602,6 +1602,238 @@ class MarkupExtTest {
|
|||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `should remove bold from first word when having inner-left overlap`() {
|
||||
|
||||
val given = listOf(
|
||||
Mark(
|
||||
type = Mark.Type.BOLD,
|
||||
range = 17..40
|
||||
),
|
||||
Mark(
|
||||
type = Mark.Type.BOLD,
|
||||
range = 50..60
|
||||
)
|
||||
)
|
||||
|
||||
val new = Mark(
|
||||
type = Mark.Type.BOLD,
|
||||
range = 17..24
|
||||
)
|
||||
|
||||
val expected = listOf(
|
||||
Mark(
|
||||
type = Mark.Type.BOLD,
|
||||
range = 24..40
|
||||
),
|
||||
Mark(
|
||||
type = Mark.Type.BOLD,
|
||||
range = 50..60
|
||||
)
|
||||
)
|
||||
|
||||
val result = given.addMark(new)
|
||||
|
||||
assertEquals(
|
||||
expected = expected,
|
||||
actual = result
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `should remove bold from second word when having inner-left overlap`() {
|
||||
|
||||
val given = listOf(
|
||||
Mark(
|
||||
type = Mark.Type.BOLD,
|
||||
range = 5..10
|
||||
),
|
||||
Mark(
|
||||
type = Mark.Type.BOLD,
|
||||
range = 17..40
|
||||
),
|
||||
)
|
||||
|
||||
val new = Mark(
|
||||
type = Mark.Type.BOLD,
|
||||
range = 17..24
|
||||
)
|
||||
|
||||
val expected = listOf(
|
||||
Mark(
|
||||
type = Mark.Type.BOLD,
|
||||
range = 5..10
|
||||
),
|
||||
Mark(
|
||||
type = Mark.Type.BOLD,
|
||||
range = 24..40
|
||||
)
|
||||
)
|
||||
|
||||
val result = given.addMark(new)
|
||||
|
||||
assertEquals(
|
||||
expected = expected,
|
||||
actual = result
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `should remove bold from first word when having inner-right overlap`() {
|
||||
|
||||
val given = listOf(
|
||||
Mark(
|
||||
type = Mark.Type.BOLD,
|
||||
range = 17..40
|
||||
),
|
||||
Mark(
|
||||
type = Mark.Type.BOLD,
|
||||
range = 50..60
|
||||
)
|
||||
)
|
||||
|
||||
val new = Mark(
|
||||
type = Mark.Type.BOLD,
|
||||
range = 24..40
|
||||
)
|
||||
|
||||
val expected = listOf(
|
||||
Mark(
|
||||
type = Mark.Type.BOLD,
|
||||
range = 17..24
|
||||
),
|
||||
Mark(
|
||||
type = Mark.Type.BOLD,
|
||||
range = 50..60
|
||||
)
|
||||
)
|
||||
|
||||
val result = given.addMark(new)
|
||||
|
||||
assertEquals(
|
||||
expected = expected,
|
||||
actual = result
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `should remove bold from second word when having inner-right overlap`() {
|
||||
|
||||
val given = listOf(
|
||||
Mark(
|
||||
type = Mark.Type.BOLD,
|
||||
range = 5..10
|
||||
),
|
||||
Mark(
|
||||
type = Mark.Type.BOLD,
|
||||
range = 17..40
|
||||
),
|
||||
)
|
||||
|
||||
val new = Mark(
|
||||
type = Mark.Type.BOLD,
|
||||
range = 24..40
|
||||
)
|
||||
|
||||
val expected = listOf(
|
||||
Mark(
|
||||
type = Mark.Type.BOLD,
|
||||
range = 5..10
|
||||
),
|
||||
Mark(
|
||||
type = Mark.Type.BOLD,
|
||||
range = 17..24
|
||||
)
|
||||
)
|
||||
|
||||
val result = given.addMark(new)
|
||||
|
||||
assertEquals(
|
||||
expected = expected,
|
||||
actual = result
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `should remove bold from first word when having inner overlap`() {
|
||||
|
||||
val given = listOf(
|
||||
Mark(
|
||||
type = Mark.Type.BOLD,
|
||||
range = 0..10
|
||||
),
|
||||
Mark(
|
||||
type = Mark.Type.BOLD,
|
||||
range = 50..60
|
||||
)
|
||||
)
|
||||
|
||||
val new = Mark(
|
||||
type = Mark.Type.BOLD,
|
||||
range = 55..57
|
||||
)
|
||||
|
||||
val expected = listOf(
|
||||
Mark(
|
||||
type = Mark.Type.BOLD,
|
||||
range = 0..10
|
||||
),
|
||||
Mark(
|
||||
type = Mark.Type.BOLD,
|
||||
range = 50..55
|
||||
),
|
||||
Mark(
|
||||
type = Mark.Type.BOLD,
|
||||
range = 57..60
|
||||
)
|
||||
)
|
||||
|
||||
val result = given.addMark(new)
|
||||
|
||||
assertEquals(
|
||||
expected = expected,
|
||||
actual = result
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `should remove bold from second word when having inner overlap`() {
|
||||
|
||||
val given = listOf(
|
||||
Mark(
|
||||
type = Mark.Type.BOLD,
|
||||
range = 5..10
|
||||
),
|
||||
Mark(
|
||||
type = Mark.Type.BOLD,
|
||||
range = 17..40
|
||||
),
|
||||
)
|
||||
|
||||
val new = Mark(
|
||||
type = Mark.Type.BOLD,
|
||||
range = 24..40
|
||||
)
|
||||
|
||||
val expected = listOf(
|
||||
Mark(
|
||||
type = Mark.Type.BOLD,
|
||||
range = 5..10
|
||||
),
|
||||
Mark(
|
||||
type = Mark.Type.BOLD,
|
||||
range = 17..24
|
||||
)
|
||||
)
|
||||
|
||||
val result = given.addMark(new)
|
||||
|
||||
assertEquals(
|
||||
expected = expected,
|
||||
actual = result
|
||||
)
|
||||
}
|
||||
|
||||
private fun checkOverlap(pair: Pair<IntRange, IntRange>, expected: Overlap) {
|
||||
val (a, b) = pair
|
||||
val result = a.overlap(b)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue