Skip to content

Fix toolbar back arrow discarding unsaved changes in File Editor#421

Open
faraz152 wants to merge 1 commit intoFossifyOrg:mainfrom
faraz152:fix/362-file-editor-back-button
Open

Fix toolbar back arrow discarding unsaved changes in File Editor#421
faraz152 wants to merge 1 commit intoFossifyOrg:mainfrom
faraz152:fix/362-file-editor-back-button

Conversation

@faraz152
Copy link
Copy Markdown

@faraz152 faraz152 commented Apr 8, 2026

Summary

  • Fixes back button always discards changes in File Editor #362 — The toolbar back arrow in the File Editor (ReadTextActivity) was calling finish() directly via setupTopAppBar, bypassing the unsaved changes dialog shown by onBackPressedCompat()
  • Override the navigation click listener after setupTopAppBar to route through onBackPressedDispatcher.onBackPressed(), ensuring the save/discard prompt appears for both the system back gesture and the toolbar arrow

Changes

  • ReadTextActivity.kt — Added setNavigationOnClickListener after setupTopAppBar in onResume() to delegate to onBackPressedDispatcher

How it works

onBackPressedCompat() already handles:

  1. Closing search if active
  2. Showing "Save / Discard" dialog if there are unsaved changes
  3. Falling through to default back behavior otherwise

Previously, only the system back button/gesture triggered this flow. The toolbar arrow called finish() directly (set by setupTopAppBar in fossify-commons), so edits were silently discarded.

Now both paths go through onBackPressedDispatcher.onBackPressed()onBackPressedCompat().

Test plan

  • Open a text file in the File Editor
  • Make changes to the text
  • Tap the toolbar back arrow → Save/Discard dialog should appear
  • System back gesture → Save/Discard dialog should appear (existing behavior, unchanged)
  • No changes made → both back methods exit immediately (no dialog)
  • Build compiles successfully (compileFossDebugKotlin)

🤖 Generated with Claude Code

The toolbar navigation arrow (set by setupTopAppBar) was calling finish()
directly, bypassing onBackPressedCompat() which contains the unsaved
changes dialog. Now the navigation click listener routes through
onBackPressedDispatcher so the save/discard prompt is shown consistently
for both the system back gesture and the toolbar arrow.

Fixes FossifyOrg#362

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@faraz152 faraz152 requested a review from naveensingh as a code owner April 8, 2026 11:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

back button always discards changes in File Editor

1 participant