Skip to content

Commit cec412f

Browse files
committed
Merge branch 'develop' into issue/218-uploading-images
2 parents 5f4e56b + cde2466 commit cec412f

File tree

4 files changed

+32
-21
lines changed

4 files changed

+32
-21
lines changed

aztec/src/main/kotlin/org/wordpress/aztec/formatting/LineBlockFormatter.kt

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -275,14 +275,30 @@ class LineBlockFormatter(editor: AztecText, val headerStyle: LineBlockFormatter.
275275
val span = AztecMediaSpan(editor.context, drawable, attributes, onMediaTappedListener)
276276
val html = span.getHtml();
277277

278-
val mediaStartIndex = selectionStart
279-
val mediaEndIndex = selectionStart + html.length
278+
val isAddingMediaToEndOfBlockElement = editableText.getSpans(selectionStart, selectionEnd, AztecBlockSpan::class.java)
279+
.any {
280+
selectionStart == editableText.getSpanEnd(it)
281+
}
282+
283+
val spanAtStartOfWhichMediaIsAdded = editableText.getSpans(selectionStart, selectionEnd, AztecBlockSpan::class.java)
284+
.firstOrNull {
285+
selectionStart == editableText.getSpanStart(it)
286+
}
287+
288+
val modifier = if (isAddingMediaToEndOfBlockElement) 1 else 0
289+
290+
val mediaStartIndex = selectionStart - modifier
291+
val mediaEndIndex = selectionStart + html.length - modifier
292+
293+
if (!isAddingMediaToEndOfBlockElement)
294+
editor.disableTextChangedListener()
280295

281-
editor.disableTextChangedListener()
282296
editableText.replace(selectionStart, selectionEnd, html)
283297

284-
editor.removeBlockStylesFromRange(mediaStartIndex, mediaEndIndex, true)
285-
editor.removeHeadingStylesFromRange(mediaStartIndex, mediaEndIndex)
298+
if (spanAtStartOfWhichMediaIsAdded != null) {
299+
editableText.setSpan(spanAtStartOfWhichMediaIsAdded, mediaStartIndex, editableText.getSpanEnd(spanAtStartOfWhichMediaIsAdded), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE)
300+
}
301+
286302
editor.removeInlineStylesFromRange(mediaStartIndex, mediaEndIndex)
287303

288304
editableText.setSpan(

aztec/src/main/kotlin/org/wordpress/aztec/spans/AztecListSpan.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ abstract class AztecListSpan(val verticalPadding: Int) : LeadingMarginSpan.Stand
5151
val currentLineNumber = getIndexOfProcessedLine(text, end)
5252

5353
if (totalNumberOfLinesInList > 1 && currentLineNumber == 1) {
54-
adjustment = if (this is AztecOrderedListSpan) 0 else verticalPadding
54+
adjustment = 0
5555
} else if ((totalNumberOfLinesInList > 1 && totalNumberOfLinesInList == currentLineNumber) || totalNumberOfLinesInList == 1) {
5656
adjustment = -verticalPadding
5757
}

aztec/src/main/kotlin/org/wordpress/aztec/spans/AztecUnorderedListSpan.kt

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ package org.wordpress.aztec.spans
1919

2020
import android.graphics.Canvas
2121
import android.graphics.Paint
22-
import android.graphics.Path
2322
import android.text.Layout
2423
import android.text.Spanned
2524
import android.text.TextUtils
@@ -64,7 +63,6 @@ class AztecUnorderedListSpan : AztecListSpan {
6463
}
6564

6665

67-
6866
override fun getLeadingMargin(first: Boolean): Int {
6967
return bulletMargin + 2 * bulletWidth + bulletPadding
7068
}
@@ -86,24 +84,14 @@ class AztecUnorderedListSpan : AztecListSpan {
8684
p.color = bulletColor
8785
p.style = Paint.Style.FILL
8886

89-
if (c.isHardwareAccelerated) {
90-
bulletPath = Path()
91-
bulletPath!!.addCircle(0.0f, 0.0f + getIndicatorAdjustment(text, end) / 2, bulletWidth.toFloat(), Path.Direction.CW)
87+
val textToDraw = "\u2022"
9288

93-
c.save()
94-
c.translate((x + bulletMargin + dir * bulletWidth).toFloat(), ((top + bottom) / 2.0f))
95-
c.drawPath(bulletPath!!, p)
96-
c.restore()
97-
} else {
98-
c.drawCircle((x + bulletMargin + dir * bulletWidth).toFloat(), ((top + bottom) / 2.0f) + getIndicatorAdjustment(text, end) / 2, bulletWidth.toFloat(), p)
99-
}
89+
val width = p.measureText(textToDraw)
90+
c.drawText(textToDraw, (bulletMargin + x + dir - width) * dir, (bottom - p.descent()) - width / 2 + getIndicatorAdjustment(text, end), p)
10091

10192
p.color = oldColor
10293
p.style = style
10394

10495
}
10596

106-
companion object {
107-
private var bulletPath: Path? = null
108-
}
10997
}

aztec/src/main/kotlin/org/wordpress/aztec/toolbar/AztecToolbar.kt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,4 +234,11 @@ class AztecToolbar : FrameLayout, OnMenuItemClickListener {
234234
}
235235
}
236236

237+
fun enableFormatButtons(isEnabled: Boolean) {
238+
ToolbarAction.values().forEach { action ->
239+
if (action != ToolbarAction.HTML) {
240+
toggleButtonState(findViewById(action.buttonId), isEnabled)
241+
}
242+
}
243+
}
237244
}

0 commit comments

Comments
 (0)