Skip to content

Add option to keep selection when clearing search#1371

Open
Ahelsamahy wants to merge 1 commit intop0deje:masterfrom
Ahelsamahy:preserve-selection-after-search-clear
Open

Add option to keep selection when clearing search#1371
Ahelsamahy wants to merge 1 commit intop0deje:masterfrom
Ahelsamahy:preserve-selection-after-search-clear

Conversation

@Ahelsamahy
Copy link
Copy Markdown

@Ahelsamahy Ahelsamahy commented Apr 6, 2026

Summary

Add option to keep selection when clearing search

Today, when search is cleared, Maccy always jumps selection back to the first unpinned item.
With this change, users can enable a setting to keep the previously selected item instead.

image

Problem

My common workflow is:

  1. I copy two items. A and B
  2. I forget what is item B but I still remember what is A.
  3. I Search for item A hoping that I find B
  4. I search for A in clipboard. I find it.
  5. Clear search to continue around that same position and find nearby item B.

Current behavior resets selection to the top.

Changes

  • Added new default key:
  • preserveSelectionAfterSearch (default: false)
  • Added new setting in General → Search:
  • Keep selected item when clearing search
  • Updated search-clear behavior in History.searchQuery.didSet:
  • If enabled and previous selection is still visible, keep that selection.
  • Otherwise fallback to existing behavior (select first unpinned item).
  • Added tests in HistoryTests for:
  • default behavior (jump to top)
  • enabled behavior (preserve selection)

Backward compatibility

  • Default value is false, so existing behavior is unchanged unless users enable it.

Testing

  • Build passes with:
  • xcodebuild build -project Maccy.xcodeproj -scheme Maccy -configuration Release -destination 'platform=macOS' CODE_SIGNING_ALLOWED=NO CODE_SIGNING_REQUIRED=NO
  • Added unit tests in HistoryTests for new behavior.

I couldn't find a way to know how to run the changes locally. I came up with these

  cd /Maccy

  # Build Release (unsigned)
  xcodebuild build \
    -project Maccy.xcodeproj \
    -scheme Maccy \
    -configuration Release \
    -destination 'platform=macOS' \
    CODE_SIGNING_ALLOWED=NO CODE_SIGNING_REQUIRED=NO

  # Find built app
  APP_PATH="$(find ~/Library/Developer/Xcode/DerivedData -path '*Maccy*/Build/Products/Release/Maccy.app' | tail -n 1)"
  echo "$APP_PATH"

  # Replace installed app
  pkill Maccy || true
  rm -rf /Applications/Maccy.app
  cp -R "$APP_PATH" /Applications/Maccy.app

  # Remove quarantine + launch
  xattr -dr com.apple.quarantine /Applications/Maccy.app
  open /Applications/Maccy.app

Notes

  • Only English settings strings were added in this PR for the new option label/tooltip.

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