@@ -14,8 +14,11 @@ import {
1414 filterCommandPaletteGroups ,
1515 findHighlightedCommandPaletteItem ,
1616 reduceCommandPaletteUiState ,
17+ createCommandPaletteSearchState ,
18+ reduceCommandPaletteSearchState ,
1719 type CommandPaletteActionItem ,
1820 type CommandPaletteGroup ,
21+ type CommandPaletteUiState ,
1922} from "./CommandPalette.logic" ;
2023
2124describe ( "linked pull request thread navigation" , ( ) => {
@@ -894,3 +897,104 @@ describe("virtualized command palette rows", () => {
894897 expect ( findHighlightedCommandPaletteItem ( groups , null ) ) . toBeNull ( ) ;
895898 } ) ;
896899} ) ;
900+
901+ describe ( "command palette search return" , ( ) => {
902+ const picker = { addonIcon : null , groups : [ ] } ;
903+
904+ it ( "restores each parent query when backing out of nested pickers" , ( ) => {
905+ let state = createCommandPaletteSearchState ( ">new thread" ) ;
906+ state = reduceCommandPaletteSearchState ( state , { type : "push" , view : picker } ) ;
907+ expect ( state . query ) . toBe ( "" ) ;
908+ state = reduceCommandPaletteSearchState ( state , { type : "query" , query : "remote project" } ) ;
909+ state = reduceCommandPaletteSearchState ( state , {
910+ type : "push" ,
911+ view : { ...picker , initialQuery : "~/" } ,
912+ } ) ;
913+ expect ( state . query ) . toBe ( "~/" ) ;
914+
915+ state = reduceCommandPaletteSearchState ( state , { type : "query" , query : "" } ) ;
916+ state = reduceCommandPaletteSearchState ( state , { type : "back" } ) ;
917+ expect ( state . query ) . toBe ( "remote project" ) ;
918+ expect ( state . views ) . toHaveLength ( 1 ) ;
919+ state = reduceCommandPaletteSearchState ( state , { type : "back" } ) ;
920+ expect ( state . query ) . toBe ( ">new thread" ) ;
921+ expect ( state . views ) . toHaveLength ( 0 ) ;
922+ } ) ;
923+
924+ it ( "cannot return to an old picker after a new search replaces it" , ( ) => {
925+ let state = reduceCommandPaletteSearchState ( createCommandPaletteSearchState ( "old" ) , {
926+ type : "push" ,
927+ view : picker ,
928+ } ) ;
929+ state = reduceCommandPaletteSearchState ( state , { type : "reset" , query : "fresh" } ) ;
930+ state = reduceCommandPaletteSearchState ( state , { type : "back" } ) ;
931+ expect ( state . query ) . toBe ( "fresh" ) ;
932+ expect ( state . views ) . toHaveLength ( 0 ) ;
933+ } ) ;
934+ } ) ;
935+
936+ describe ( "returning from file and content search" , ( ) => {
937+ const root : CommandPaletteUiState = { open : true , mode : "command" , openIntent : null } ;
938+ const query = "https://github.com/acme/web/pull/7" ;
939+ const context = {
940+ query,
941+ linkedThreadSearch : {
942+ kind : "search" as const ,
943+ query,
944+ linkedThreads : {
945+ environmentId : EnvironmentId . make ( "remote" ) ,
946+ threads : [
947+ {
948+ id : ThreadId . make ( "linked-thread" ) ,
949+ projectId : ProjectId . make ( "project" ) ,
950+ title : "Completed work" ,
951+ archivedAt : "2026-09-01T00:00:00.000Z" ,
952+ } ,
953+ ] ,
954+ } ,
955+ } ,
956+ } ;
957+
958+ it . each ( [ "files" , "content" ] as const ) (
959+ "Escape from %s restores the query and linked-thread results" ,
960+ ( mode ) => {
961+ const child = reduceCommandPaletteUiState ( root , { _tag : "OpenChildSearch" , mode, context } ) ;
962+ expect ( child . mode ) . toBe ( mode ) ;
963+ const returned = reduceCommandPaletteUiState ( child , { _tag : "BackToCommand" } ) ;
964+ expect ( returned ) . toEqual ( { ...root , restoredSearch : context } ) ;
965+ expect ( reduceCommandPaletteUiState ( returned , { _tag : "BackToCommand" } ) ) . toEqual ( returned ) ;
966+ } ,
967+ ) ;
968+
969+ it ( "closing a child search discards its return context before reopening" , ( ) => {
970+ const child : CommandPaletteUiState = { ...root , mode : "files" , parentSearch : context } ;
971+ const closed = reduceCommandPaletteUiState ( child , { _tag : "SetOpen" , open : false } ) ;
972+ expect ( closed ) . toEqual ( { open : false , mode : "files" , openIntent : null } ) ;
973+ expect ( reduceCommandPaletteUiState ( closed , { _tag : "BackToCommand" } ) ) . toEqual ( closed ) ;
974+ expect ( reduceCommandPaletteUiState ( closed , { _tag : "SetOpen" , open : true } ) ) . toEqual ( root ) ;
975+ } ) ;
976+
977+ it ( "a fresh overlay shortcut has no parent search to return to" , ( ) => {
978+ const child = reduceCommandPaletteUiState ( root , {
979+ _tag : "OpenChildSearch" ,
980+ mode : "files" ,
981+ context,
982+ } ) ;
983+ const fresh = reduceCommandPaletteUiState ( child , { _tag : "ToggleMode" , mode : "content" } ) ;
984+ expect ( fresh ) . toEqual ( { open : true , mode : "content" , openIntent : null } ) ;
985+ expect ( reduceCommandPaletteUiState ( fresh , { _tag : "BackToCommand" } ) ) . toEqual ( root ) ;
986+ } ) ;
987+
988+ it ( "a direct search intent replaces restored query and linked-thread context" , ( ) => {
989+ const child = reduceCommandPaletteUiState ( root , {
990+ _tag : "OpenChildSearch" ,
991+ mode : "content" ,
992+ context,
993+ } ) ;
994+ const returned = reduceCommandPaletteUiState ( child , { _tag : "BackToCommand" } ) ;
995+ expect ( reduceCommandPaletteUiState ( returned , { _tag : "OpenSearch" , query : "fresh" } ) ) . toEqual ( {
996+ ...root ,
997+ openIntent : { kind : "search" , query : "fresh" } ,
998+ } ) ;
999+ } ) ;
1000+ } ) ;
0 commit comments