@@ -30,6 +30,7 @@ class T3ReviewDiffView(context: Context, appContext: AppContext) : ExpoView(cont
3030 private val onToggleFile by EventDispatcher ()
3131 private val onToggleViewedFile by EventDispatcher ()
3232 private val onPressHunk by EventDispatcher ()
33+ private val onPressFileAction by EventDispatcher ()
3334 private val onPressLine by EventDispatcher ()
3435 private val onSelectLineRange by EventDispatcher ()
3536 private val onToggleComment by EventDispatcher ()
@@ -391,12 +392,17 @@ class T3ReviewDiffView(context: Context, appContext: AppContext) : ExpoView(cont
391392
392393 private fun handleRowTap (row : DiffRow , gesture : String , target : RowTapTarget ) {
393394 when (row.kind) {
394- " hunk" -> if (gesture == " tap" && target == RowTapTarget .HUNK_ACTION && ! row.hunkActionDisabled) {
395- onPressHunk(mapOf (" rowId" to row.id))
395+ " hunk" -> if (gesture == " tap" ) {
396+ if (target == RowTapTarget .HUNK_REVERT && ! row.hunkRevertActionDisabled)
397+ onPressHunk(mapOf (" rowId" to row.id, " action" to " revert" ))
398+ else if (target == RowTapTarget .HUNK_ACTION && ! row.hunkActionDisabled)
399+ onPressHunk(mapOf (" rowId" to row.id, " action" to " stage" ))
396400 }
397401 " file" -> {
398402 if (gesture != " tap" ) return
399- if (target == RowTapTarget .VIEWED_CHECKBOX ) {
403+ if (target == RowTapTarget .FILE_ACTION ) {
404+ if (! row.fileActionDisabled) onPressFileAction(mapOf (" fileId" to row.resolvedFileId, " rowId" to row.id))
405+ } else if (target == RowTapTarget .VIEWED_CHECKBOX ) {
400406 onToggleViewedFile(mapOf (" fileId" to row.resolvedFileId))
401407 } else {
402408 onToggleFile(mapOf (" fileId" to row.resolvedFileId))
@@ -465,7 +471,9 @@ class T3ReviewDiffView(context: Context, appContext: AppContext) : ExpoView(cont
465471private enum class RowTapTarget {
466472 ROW ,
467473 VIEWED_CHECKBOX ,
468- HUNK_ACTION
474+ HUNK_ACTION ,
475+ HUNK_REVERT ,
476+ FILE_ACTION
469477}
470478
471479private enum class HorizontalPanKind {
@@ -500,7 +508,11 @@ internal data class DiffRow(
500508 val commentResolvedSummary : String? = null ,
501509 val renameSegments : List <DiffRenameSegment > = emptyList(),
502510 val hunkAction : String? = null ,
503- val hunkActionDisabled : Boolean = false
511+ val hunkActionDisabled : Boolean = false ,
512+ val hunkRevertAction : Boolean = false ,
513+ val hunkRevertActionDisabled : Boolean = false ,
514+ val fileAction : String? = null ,
515+ val fileActionDisabled : Boolean = false
504516) {
505517 val resolvedFileId: String get() = fileId.ifEmpty { id }
506518}
@@ -723,6 +735,10 @@ private class DiffCanvasView(context: Context) : View(context) {
723735 if (hit.row.kind == " line" ) clearNativeRange()
724736 val target = if (hit.row.kind == " hunk" && hit.row.hunkAction != null && event.x >= width - 112 * density) {
725737 RowTapTarget .HUNK_ACTION
738+ } else if (hit.row.kind == " hunk" && hit.row.hunkRevertAction && event.x >= width - 224 * density) {
739+ RowTapTarget .HUNK_REVERT
740+ } else if (hit.row.kind == " file" && hit.row.fileAction != null && event.x >= width - 100 * density) {
741+ RowTapTarget .FILE_ACTION
726742 } else if (
727743 showViewedCheckbox && hit.row.kind == " file" &&
728744 drawing.fileHeaderCheckboxRect(
@@ -1164,7 +1180,8 @@ private class DiffCanvasView(context: Context) : View(context) {
11641180 val addText = " +${row.additions} "
11651181 val addWidth = boldTextPaint.measureText(addText)
11661182 val countGap = 4f * density
1167- val countsRight = if (showViewedCheckbox) checkboxRect.left - 10f * density else width - 16f * density
1183+ val countsRight = if (row.fileAction != null ) width - 110f * density
1184+ else if (showViewedCheckbox) checkboxRect.left - 10f * density else width - 16f * density
11681185 val countsX = countsRight - deleteWidth - countGap - addWidth
11691186 val baseline = centeredBaseline(top, bottom, boldTextPaint)
11701187 canvas.drawText(deleteText, countsX, baseline, boldTextPaint)
@@ -1205,6 +1222,16 @@ private class DiffCanvasView(context: Context) : View(context) {
12051222 pathOffset,
12061223 maxPathOffset,
12071224 )
1225+ row.fileAction?.let { label ->
1226+ val rect = RectF (width - 96 * density, top + 7 * density, width - 10 * density, bottom - 7 * density)
1227+ backgroundPaint.color = theme.border
1228+ backgroundPaint.style = Paint .Style .STROKE
1229+ backgroundPaint.strokeWidth = density
1230+ canvas.drawRoundRect(rect, 6 * density, 6 * density, backgroundPaint)
1231+ backgroundPaint.style = Paint .Style .FILL
1232+ drawing.configureUiPaint(boldTextPaint, if (row.fileActionDisabled) theme.mutedText else theme.hunkText, 12 * density, " semibold" )
1233+ canvas.drawText(label, rect.centerX() - boldTextPaint.measureText(label) / 2 , centeredBaseline(top, bottom, boldTextPaint), boldTextPaint)
1234+ }
12081235 drawBottomBorder(canvas, bottom)
12091236 }
12101237
@@ -1247,7 +1274,8 @@ private class DiffCanvasView(context: Context) : View(context) {
12471274 size = style.fileHeaderMetaFontSizePx,
12481275 weight = style.fileHeaderMetaFontWeight,
12491276 )
1250- val countsRight = if (showViewedCheckbox) checkboxRect.left - 10f * density else width - 16f * density
1277+ val countsRight = if (row.fileAction != null ) width - 110f * density
1278+ else if (showViewedCheckbox) checkboxRect.left - 10f * density else width - 16f * density
12511279 val countsX = countsRight -
12521280 boldTextPaint.measureText(" -${row.deletions} " ) - 4f * density -
12531281 boldTextPaint.measureText(" +${row.additions} " )
@@ -1286,7 +1314,7 @@ private class DiffCanvasView(context: Context) : View(context) {
12861314 weight = style.hunkFontWeight,
12871315 )
12881316 canvas.save()
1289- if (row.hunkAction != null ) canvas.clipRect(0f , top.toFloat(), width - 112 * density, bottom.toFloat())
1317+ if (row.hunkAction != null ) canvas.clipRect(0f , top.toFloat(), width - ( if (row.hunkRevertAction) 224 else 112 ) * density, bottom.toFloat())
12901318 drawScrollableCode(canvas, top, bottom) { codeX ->
12911319 canvas.drawText(
12921320 row.text.ifEmpty { row.content },
@@ -1303,6 +1331,14 @@ private class DiffCanvasView(context: Context) : View(context) {
13031331 drawing.configureUiPaint(boldTextPaint, if (row.hunkActionDisabled) theme.mutedText else theme.hunkText, 13 * density, " semibold" )
13041332 canvas.drawText(label, rect.centerX() - boldTextPaint.measureText(label) / 2 , centeredBaseline(top, bottom, boldTextPaint), boldTextPaint)
13051333 }
1334+ if (row.hunkRevertAction) {
1335+ val rect = RectF (width - 218 * density, top + 6 * density, width - 118 * density, bottom - 6 * density)
1336+ backgroundPaint.color = theme.headerBackground
1337+ canvas.drawRoundRect(rect, 6 * density, 6 * density, backgroundPaint)
1338+ drawing.configureUiPaint(boldTextPaint, if (row.hunkRevertActionDisabled) theme.mutedText else theme.deleteText, 13 * density, " semibold" )
1339+ val label = " Revert hunk"
1340+ canvas.drawText(label, rect.centerX() - boldTextPaint.measureText(label) / 2 , centeredBaseline(top, bottom, boldTextPaint), boldTextPaint)
1341+ }
13061342 }
13071343
13081344 private fun drawNoticeRow (canvas : Canvas , row : DiffRow , top : Int , bottom : Int ) {
@@ -1599,6 +1635,10 @@ private fun parseRows(value: String): List<DiffRow> = try {
15991635 text = row.optString(" text" ),
16001636 hunkAction = row.optNullableString(" hunkAction" ),
16011637 hunkActionDisabled = row.optBoolean(" hunkActionDisabled" , false ),
1638+ hunkRevertAction = row.optBoolean(" hunkRevertAction" , false ),
1639+ hunkRevertActionDisabled = row.optBoolean(" hunkRevertActionDisabled" , false ),
1640+ fileAction = row.optNullableString(" fileAction" ),
1641+ fileActionDisabled = row.optBoolean(" fileActionDisabled" , false ),
16021642 content = row.optString(" content" ),
16031643 change = row.optString(" change" , " context" ),
16041644 oldLineNumber = row.optNullableInt(" oldLineNumber" ),
0 commit comments