Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FR: save edit history in a different location and/or as a hidden file #2

Open
chrisgrieser opened this issue Aug 1, 2023 · 15 comments
Labels
enhancement New feature or request

Comments

@chrisgrieser
Copy link

Thanks for the plugin, this was actually sth, I've been looking for a while.

What I'd like to have is a method to keep the edit history files out of sight. Right now, they are saved in the same folder as the note, so when you switch to the file explorer, your folder is cluttered with files you are not going to actively work with.

So what I'd like to propose is one of two options which would accomplish that.

  1. Save the edit history file with a . prefix (e.g. .notename.md.edtz). At least on mac and Linux, this hides those files by default.
  2. save the edit history files in a parallel directory, mirroring the directory structure of your vault.
@antoniotejada
Copy link
Owner

@chrisgrieser Thanks!

There's an item for that in the README.md TODO section. I've actually been thinking a lot about that and the code supports it, but it has multiple issues described in the code itself:

        /* XXX Issues with allowing a user-configured history folder: 
            - any history folder will mimic the the structure of the note
              directory (alternatively history files could be on a flat
              directory with the name coming from a hash of the full path, but
              that makes renaming more involved, and fishing for history files
              less intuitive)

            - due to an Obsidian design decision, folders cannot start with "."
              so the user-defined history folder be visible in the file explorer
                - Note this limitation is not consistently enforced through the
                    API:
                    - Obsidian does allow createBinary on a path starting with a
                      dot and it successfully creates the file
                    - Unfortunately getAbstractFileFromPath on a path starting
                      with a dot fails so the file can be created (which only
                      requires the path) but not modified (which requires a
                      TAbstractFile)

            - because it's visible, the user can rename the edit history folder
              from the obsidian UI,
                - renaming the topmost directory could be supported since the
                  only thing needed would be to update the internal variable.
                  Obisidan API notifies of the top level rename and each
                  children, which can be ignored. This will need care depending
                  on the reporting order of root vs. children and the update of
                  the internal variable.
                - if the user renames a non-top level directory then all
                  children history files would go out of sync, so this is a
                  problem.

            - the Obsidian setting onChange gets called on every keystroke, so
               configuring the edit history folder in settings would cause a
               rename on each keystroke. There doesn't seem to be a final
               changed(), hide() is not called either
            
            - it's not clear whether the folder should be deleted if empty
            
            - it's not clear if it's safe to just copy all the files found with
              whatever extension new Setting(containerEl) .setName('Edits
              folder') .setDesc('Folder to store the edit history file. Empty to
              store the edit file in the same directory alongside the original
              file. Due to Obsidian limitations this must start with a character
              other than "."') .addText(text => text .setPlaceholder('Enter the
              folder name')
              .setValue(this.plugin.settings.editHistoryRootFolder)
              .onChange(async (value) => { logInfo("onChange");
              logInfo('Edits folder: ' + value); // Only allow top level
              folders

                    this.plugin.settings.editHistoryRootFolder = value;


            // XXX Can the folder just be renamed via the file explorer
            interface? // XXX Check no dir component starts with "." // XXX
            Delete edits? copy them to new folder? trash them? // XXX Ask the
            user to delete folder? // XXX Ask for confirmation? // XXX Use
            private apis to store in some hidden folder? await
            this.plugin.saveSettings();
                }));
*/

https://github.com/antoniotejada/obsidian-edit-history/blob/master/main.ts#L899

I will give it more thought, but the more I think about it and the more I use it the more I like the fact that the edit history files are alongside the notes.

Leaving this open.

@antoniotejada antoniotejada added the enhancement New feature or request label Aug 1, 2023
@antoniotejada
Copy link
Owner

antoniotejada commented Aug 1, 2023

Your suggestion of preceding the edit history file by "." looks the most doable, but I think it will need to use the adapter Obsidian API which is frown upon (that is for sure the case if you try to create folders starting with ".", will need to verify for files).

@chrisgrieser
Copy link
Author

I know that the pandoc reference list plugin creates files in a .pandoc folder in the vault, and it's from one of the Obsidian devs, so maybe they are using a good method?
https://obsidian.md/plugins?id=obsidian-pandoc-reference-list

@Aetherinox
Copy link

Aetherinox commented Aug 14, 2023

I like this addon, but the way it's storing the edited files is messing up my structure. If you can't hide or do something with the files visibly showing themselves, it would be nice to allow a subfolder to be specified.

Such as all edits being migrated to a folder at the bottom of the list called .history or something and not planted directly below the file that was changed. Then if I need to see the edits, I can just go to the specified folder and pick out what I need to view edits for.

qLYk3Rj

@antoniotejada
Copy link
Owner

antoniotejada commented Aug 14, 2023

@Aetherinox they don't show for me in the Obsididan file explorer, I guess you have enabled "detect all file extensions" under Obsidian Files & Links?

To me keeping the edit history file alongside the note is a feature, not a bug. It makes edit history file backup transparent and having its own folder only makes things more complicated as I describe above, so I'm not very motivated to do anything about it.

The most likely thing I may do is to put a settings toggle so the edit history filename starts with a dot, which should hide it in some operating systems, and from a cursory test also in the Obsidian file explorer even with "detect all file extensions" set.

@antoniotejada
Copy link
Owner

I know that the pandoc reference list plugin creates files in a .pandoc folder in the vault, and it's from one of the Obsidian devs, so maybe they are using a good method? https://obsidian.md/plugins?id=obsidian-pandoc-reference-list

For the record, pandoc plugin uses the bad api,

https://github.com/OliverBalfour/obsidian-pandoc/blob/68ff9e3733cc73055156455721fc736ad45c7d5e/renderer.ts#L166
https://github.com/OliverBalfour/obsidian-pandoc/blob/68ff9e3733cc73055156455721fc736ad45c7d5e/main.ts#L64

@Aetherinox
Copy link

Aetherinox commented Aug 14, 2023

Disabling detect all file extensions seems to address the issue of it showing, but do you know if there's a place where the recognized files are listed? Because I'm wondering why I turned that on now and must have had a reason. But with my vault being so massive, it's hard to track down where.

Adding the prefix of a period would be helpful on my linux system.

@antoniotejada
Copy link
Owner

@Aetherinox

Disabling detect all file extensions seems to address the issue of it showing, but do you know if there's a place where the recognized files are listed?

I'm not aware there's such a thing, but I just found out about detect all file extensions myself by poking around.

Looking at the sources, that setting corresponds to showUnsupportedFiles

t.prototype.isSupportedFile = function(e) {
    var t = this.app;
    return !!t.vault.getConfig("showUnsupportedFiles") || t.viewRegistry.isExtensionRegistered(e.extension)
}

So if the extension is registered then the file will be shown in the Obsidian file explorer (and available as file suggestion in the quick picker, etc). My guess is that they are regarded as registered if they have an associated core or plugin view.

Adding the prefix of a period would be helpful on my linux system.

Right, note would also hide it from the Obsidian file explorer even if you have "detect all file extensions".

@antoniotejada
Copy link
Owner

My guess is that they are regarded as registered if they have an associated core or plugin view.

@Aetherinox Boils down to calling registerExtensions
See
https://docs.obsidian.md/Reference/TypeScript+API/Plugin/registerExtensions
https://github.com/MeepTech/obsidian-custom-file-extensions-plugin

@gapmiss
Copy link

gapmiss commented Sep 12, 2023

This CSS snippet hides the edtz files from the file explorer.

.tree-item.nav-file:has(div[data-path$=edtz]) {
  display: none;
}

Obsidian v1.4.9

@antoniotejada
Copy link
Owner

@gapmiss

This CSS snippet hides the edtz files from the file explorer.

.tree-item.nav-file:has(div[data-path$=edtz]) {
  display: none;
}

Obsidian v1.4.9

That sounds like a great suggestion for the styles.css file, thanks!

@antoniotejada
Copy link
Owner

@alsab200
Copy link

Thanks for such a great plugin.
For hiding the file extension through "css" and some other setting helps but as a makeup only.
I personally do not want to potentially "double" the number of my files in my vault.. and perhaps want to avoid them being indexed too..
Also I don't want to see them in the file explorer as well.. Too many files..
So please reconsider to give us an option to store your "edtz" files in a dedicated folder..
Thank you..

@sigrunixia
Copy link

Files with double extensions can be problematic on some operating systems (particularly Android). I'd encourage the .md to be removed from the naming convention.

I also occasionally see this plugin as a contributor to Obsidian Sync issues reported to the support box, due to each device generating slightly different edit histories, and possibly the plugin not being configured to reload from Sync (See https://docs.obsidian.md/Reference/TypeScript+API/Plugin/onExternalSettingsChange).

From my perspective, the ability to put the .edtz files in a dedicated folder would be ideal, so that folder can be excluded from syncing services.

Having them be hidden files in the vault would also work towards this purpose.

@antoniotejada
Copy link
Owner

antoniotejada commented Nov 28, 2024

@sigrunixia

Files with double extensions can be problematic on some operating systems (particularly Android). I'd encourage the .md to be removed from the naming convention.

That's news to me, do you have specifics on what the problems are with multiple dots in the filename?

The original extension cannot be trivially removed because you may have two files with the same basename (eg. test.md and text.txt). You could do char replacement but then you need to also escape the replacement char, etc (without char replacement escaping, if you change "." to "_" so the edit file is test_md.edtz then it will collide with a theoretical test_md file).

I also occasionally see this plugin as a contributor to Obsidian Sync issues reported to the support box, due to each device generating slightly different edit histories, and possibly the plugin not being configured to reload from Sync (See https://docs.obsidian.md/Reference/TypeScript+API/Plugin/onExternalSettingsChange).

Will keep onExternalSettingsChange in mind, although looks like the failures from that should be different plugin settings on each device which doesn't look like a big deal.

From my perspective, the ability to put the .edtz files in a dedicated folder would be ideal, so that folder can be excluded from syncing services.

Using a different folder has issues as I've mentioned in previous replies (in addition, you have to replicate the whole vault folder structure elsewhere and do folder management deleting folders when no history files are found, renaming the whole folder structure when a folder is renamed in the vault, etc).

I have my own google drive sync plugin and I filter out .edtz files to be safe, although things should be safe as long as you don't edit both files at the same time, which is a sync conflict anyway and the user needs to pick which file to persist. I believe there's a corner case depending on the order the edtz and original files are sync'ed, since I think syncing the original file triggers onchange, which triggers the edtz update, but I can't remember how big of an issue it was.

Can't Sync be configured to filter out files by file extension?

Having them be hidden files in the vault would also work towards this purpose.

Right, that's my suggested solution too, disable "Detect all file extensions" in the vault.

Are you suggesting any other way of hiding files? I also noticed that using a dot at the beginning of the file will also hide the file from Obsidian (I believe in all OSs) but then you say that multiple extensions are problematic, so that would be problematic too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

6 participants