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

Fix Paste Override Not Pasting in File Preview Editor and Race Condition in YAML Timestamp Updates via User Edits #1221

Merged
merged 2 commits into from
Nov 14, 2024

Conversation

pjkaufman
Copy link
Collaborator

Fixes #1219

There was an issue reported where when a user tries to paste into a markdown file preview it was pasting in the current document instead. This was caused by not using the editor provided by the editor-paste event. Using that editor, fixed the issue. However it showed another issue.

Using the editor from an editor-paste event is not 100% reliable for the Linter since it only provides the content linked to by the internal link. That is fine if it links to a file. However if it links to a header, paragraph, or otherwise, it would insert the timestamp change at the start of the linked to text. So there needed to be branching logic in the Linter to handle when the editor was a whole file versus it being in a part of the file. This also showed another issue.

The Linter was occasionally logging a warning saying that it was trying to run a debounce function on a file that was no longer in the map. This was odd since the logic for adding to the map first checked if the value was present. Well, the issue was that between the first editor-change event and the second you could have a situation where the cached read of the file's contents had not yet completed. This resulted in two plus additions to the map instead of one. To fix this, the cached read was moved to after the value was added to the map. The reason it needed to move is that the editor-change event does not seem to handle waiting async callbacks to complete before starting the next editor-change event.

Changes Made:

  • Swapped to using the file path for the editor change file's key in the map since it is smaller and should be more restrictive
  • Updated the paste event handler to make sure it used the editor of the paste event
  • Updated the editor-change's debounced function to make sure it handled partial file editors vs full file editors properly
  • Moved cached read of the editor-changed file info to after the addition to the map to prevent race conditions where the same file got added to the map more than once causing warnings in the console

…ect file when a file preview is being edited and fixed an issue with editing a file preview while the lint on editor change/user change logic is enabled where it would update the wrong part of the file
@pjkaufman pjkaufman added bug Something isn't working obsidian Obsidian specific syntax issue or feature labels Nov 14, 2024
@pjkaufman pjkaufman self-assigned this Nov 14, 2024
@pjkaufman pjkaufman merged commit 53dff1f into platers:master Nov 14, 2024
1 check passed
@pjkaufman pjkaufman added the resolution/update-made A change has been made that should resolve this issue or request label Nov 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working obsidian Obsidian specific syntax issue or feature resolution/update-made A change has been made that should resolve this issue or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Bug: linter breaks pasting in editable embeded sections
1 participant