Skip to content

Fix: respect fileclass fields order when inserting missing fields#784

Open
roccojiang wants to merge 1 commit into
mdelobelle:masterfrom
roccojiang:fields-order-fix
Open

Fix: respect fileclass fields order when inserting missing fields#784
roccojiang wants to merge 1 commit into
mdelobelle:masterfrom
roccojiang:fields-order-fix

Conversation

@roccojiang

Copy link
Copy Markdown

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() populates filesFields from the frontmatter fields array, which is populated in creation order. The ordering of fileclass fields is saved separately in fieldsOrder, 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 fieldsOrder during FieldIndex.getFilesFields(), before they are stored in filesFields.

As a result, all consumers of filesFields now receive fields in the expected order:

  • Missing-field insertion respects the user-configured FileClass ordering
  • Additionally, this also improves the InsertFieldSuggestModal displayed 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

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.

1 participant