burhanrashid52 / PhotoEditor

A Photo Editor library with simple, easy support for image editing using paints,text,filters,emoji and Sticker like stories.
MIT License
4.14k stars 991 forks source link

Wrong return value of undo() method #460

Closed VardanTitan closed 2 years ago

VardanTitan commented 2 years ago

Describe the bug In some cases undo() method returns wrong result.

To Reproduce Steps to reproduce the behavior:

  1. Add a text.
  2. Add a brush drawing
  3. Call undo()
  4. undo() returns a false although there is a text drawing that can be undone.

Expected behavior undo() call returns true so text also can be removed.

Additional context While looking into code I found this:

    fun undoView(): Boolean {
        if (mViewState.addedViewsCount > 0) {
            val removeView = mViewState.getAddedView(
                mViewState.addedViewsCount - 1
            )
            if (removeView is DrawingView) {
                return removeView.undo()
            } else {
                mViewState.removeAddedView(mViewState.addedViewsCount - 1)
                mViewGroup.removeView(removeView)
                mViewState.pushRedoView(removeView)
            }
            when (val viewTag = removeView.tag) {
                is ViewType -> onPhotoEditorListener?.onRemoveViewListener(
                    viewTag,
                    mViewState.addedViewsCount
                )
            }
        }
        return mViewState.addedViewsCount != 0
    }

I think return removeView.undo() causes the issue as it doesn't count added views before DrawingView.

burhanrashid52 commented 2 years ago

Thanks. Can you push the fix with the PR?

github-actions[bot] commented 2 years ago

This issue is stale because it has been open 20 days with no activity. Remove stale label or comment or this will be closed in 4 days.

github-actions[bot] commented 2 years ago

This issue was closed because it has been stalled for 5 days with no activity.