Skip to content

Bug: View menu 'Sort by' has no effect when a folder is selected #1912

@gjouret

Description

@gjouret

Problem

The View → Sort by menu sets UserDefaultsManagement.sort (the global default), but when a folder with a per-folder sort override is selected, the sort does not change. The per-folder setting (set via right-click → Show Options → Sort by) always takes priority in buildSortBy() (Storage.swift:1475), and the View menu does not update it.

This means the View menu sort appears to "do nothing" for any folder that has an explicit per-folder sort set.

Root Cause

In ViewController.sortBy() (ViewController.swift:537), only UserDefaultsManagement.sort is updated. The per-folder project.settings.sortBy is not touched. Then buildSortBy() checks per-folder first and ignores the global:

public func buildSortBy() {
    if let project = self.searchQuery.projects.first, project.settings.sortBy != .none {
        self.sortByState = project.settings.sortBy  // per-folder wins, global ignored
        ...
        return
    }
    ...
    self.sortByState = UserDefaultsManagement.sort  // only reached if per-folder is .none
}

Expected Behavior

When a folder is selected and the user changes the sort via the View menu, the sort should take effect immediately on the visible note list. This means updating the per-folder project.settings.sortBy as well.

Suggested Fix

In ViewController.sortBy(), also update the currently selected folder's sort setting:

if let sidebarProjects = sidebarOutlineView.getSidebarProjects(), let project = sidebarProjects.first {
    if sortBy == project.settings.sortBy {
        project.settings.sortDirection = project.settings.sortDirection == .asc ? .desc : .asc
    }
    project.settings.sortBy = sortBy
    project.saveSettings()
}

Environment

  • FSNotes 7.1.1
  • macOS 15 Sequoia

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions