billthefarmer / editor

Android simple text editor
https://billthefarmer.github.io/editor
GNU General Public License v3.0
474 stars 85 forks source link

Editing new file will reuse the file name of previously opened file #228

Open Vrihub opened 5 months ago

Vrihub commented 5 months ago

Steps to reproduce:

  1. Open an existing file. Don't enter edit mode.
  2. Tap on the "+" icon to open a new file. You get an empty buffer with the Untitled.txt filename
  3. Tap on the pencil icon to enter edit mode

Expected result: you should be editing the new Untitled.txt file.

Actual result: as soon as you enter edit mode, the current filename reverts to the name of the file you opened in step 1. above.

WARNING: potential data loss. If you don't realise this and click on the Save icon, the old file will be silently overwritten.

Suggestions:

  1. Fix this bug
  2. Add a confirmation prompt before overwriting existing files.
billthefarmer commented 5 months ago

Unable to reproduce. Tested on three different devices.

Vrihub commented 5 months ago

Interesting. I Get the bug if I open the file in step 1 in one of the following ways:

I can't reproduce the bug if I open the file in step 1 via Editor's "Open file" menu.

So the way the first file is opened seems to matter.

I'm running f-droid's latest editor package on Samsung android 11.

billthefarmer commented 5 months ago

See the README. File managers and other apps use a content URI to share files which may not be resolvable to a path to a real file and may be read-only. That is why I wrote the file picker, to get around the idiosyncrasies of file managers, other apps, and android making it difficult to access the file system.

Vrihub commented 5 months ago

So it seems the bug lies in this mechanism you devised to overcome android's limitations in saving files. It is a bit too over-zealous in the scenario I described, wrongly re-using the old filename and overwriting the old file when the user saves.

Once the user chooses to edit a new file, the past shouldn't matter and editor should stick to the default filename for new files.

(BTW I never had any problems with saving files, but maybe I was lucky with my android version)

Vrihub commented 5 months ago

This bug seems fixed in 1.96 thanks!!!

I've now noticed another couple of bugs while using the Save as... feature to overwrite an existing file.

Steps:

  1. Open a file and edit it.
  2. Choose Save as... and enter the name of an already existing file

Expected: get a warning message like "File FOO already exists. Do you want to overwrite it?"

Actual: the message says "This file has changed. Do you want to overwrite it?" The original file has obviously been changed, while the target file (about to be overwritten) has not been changed. This message only makes sense if one chooses Save as... and enters the same name of the original file.

But there's more. If you now choose to overwrite: the new file name will appear in the upper left corner, but the file is still saved to disk under the old filename, while the file chosen to be overwritten is left untouched. This keeps happening every time you hit the Save icon. Incidentally, pressing the android "Back" button to switch to another app, then switching back to the editor gets you back to the file and restores the old original filename in the upper left corner.

Expected: the original file should be left untouched, the chosen file should be overwritten with the current buffer content, and the new filename should appear permanently in the upper left corner (until the next Save as... action).