Fix: respect fileclass fields order when inserting missing fields#784
Open
roccojiang wants to merge 1 commit into
Open
Fix: respect fileclass fields order when inserting missing fields#784roccojiang wants to merge 1 commit into
roccojiang wants to merge 1 commit into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes: #618, #731
Partially addresses: #491
Problem
The "insert missing fields" actions currently add fields in the order they were originally defined, rather than the order configured by the user in the FileClass settings UI. This contradicts the documented behaviour of inserting missing fields, and as reported in the linked issues, this behavior is unintuitive and inconvenient.
Root Cause
FieldIndex.getFilesFields()populatesfilesFieldsfrom the frontmatterfieldsarray, which is populated in creation order. The ordering of fileclass fields is saved separately infieldsOrder, however, this is never applied during field indexing, so downstream consumers operate on fields sorted in the unintuitive creation order.Solution
Fields now get sorted according to the fileclass-defined
fieldsOrderduringFieldIndex.getFilesFields(), before they are stored infilesFields.As a result, all consumers of
filesFieldsnow receive fields in the expected order:InsertFieldSuggestModaldisplayed when clicking the metadata button from a note's properties section – the modal will show fields in expected order, rather than the raw creation order