@@ -11,8 +11,11 @@ import {
1111 filterPinnedBrowseEntries ,
1212 filterCommandPaletteGroups ,
1313 reduceCommandPaletteUiState ,
14+ createCommandPaletteSearchState ,
15+ reduceCommandPaletteSearchState ,
1416 type CommandPaletteActionItem ,
1517 type CommandPaletteGroup ,
18+ type CommandPaletteUiState ,
1619} from "./CommandPalette.logic" ;
1720
1821describe ( "linked pull request thread navigation" , ( ) => {
@@ -803,3 +806,133 @@ describe("filterCommandPaletteGroups", () => {
803806 ] ) ;
804807 } ) ;
805808} ) ;
809+
810+ describe ( "command palette search return" , ( ) => {
811+ const projectPicker = { addonIcon : null , groups : [ ] } ;
812+
813+ it ( "restores distinct queries through multiple nested pickers" , ( ) => {
814+ let state = createCommandPaletteSearchState ( ">new thread" ) ;
815+ state = reduceCommandPaletteSearchState ( state , { type : "push" , view : projectPicker } ) ;
816+ expect ( state . query ) . toBe ( "" ) ;
817+ state = reduceCommandPaletteSearchState ( state , { type : "query" , query : "remote project" } ) ;
818+ state = reduceCommandPaletteSearchState ( state , {
819+ type : "push" ,
820+ view : { ...projectPicker , initialQuery : "~/" } ,
821+ } ) ;
822+ state = reduceCommandPaletteSearchState ( state , { type : "query" , query : "~/work" } ) ;
823+ state = reduceCommandPaletteSearchState ( state , { type : "back" } ) ;
824+ expect ( state . query ) . toBe ( "remote project" ) ;
825+ expect ( state . views ) . toHaveLength ( 1 ) ;
826+ state = reduceCommandPaletteSearchState ( state , { type : "back" } ) ;
827+ expect ( state ) . toEqual ( createCommandPaletteSearchState ( ">new thread" ) ) ;
828+ expect ( reduceCommandPaletteSearchState ( state , { type : "back" } ) ) . toBe ( state ) ;
829+ } ) ;
830+
831+ it ( "clearing a child prefix before Back does not erase the parent input" , ( ) => {
832+ let state = createCommandPaletteSearchState ( ">add project" ) ;
833+ state = reduceCommandPaletteSearchState ( state , {
834+ type : "push" ,
835+ view : { ...projectPicker , initialQuery : "~/" } ,
836+ } ) ;
837+ state = reduceCommandPaletteSearchState ( state , { type : "query" , query : "" } ) ;
838+ state = reduceCommandPaletteSearchState ( state , { type : "back" } ) ;
839+ expect ( state . query ) . toBe ( ">add project" ) ;
840+ state = reduceCommandPaletteSearchState ( state , { type : "query" , query : "" } ) ;
841+ expect ( state ) . toEqual ( createCommandPaletteSearchState ( ) ) ;
842+ } ) ;
843+
844+ it ( "new direct-open and fresh-open searches cannot return to old input" , ( ) => {
845+ const nested = reduceCommandPaletteSearchState ( createCommandPaletteSearchState ( "old search" ) , {
846+ type : "push" ,
847+ view : projectPicker ,
848+ } ) ;
849+ const newSearch = reduceCommandPaletteSearchState ( nested , {
850+ type : "reset" ,
851+ query : "linked thread" ,
852+ } ) ;
853+ expect ( reduceCommandPaletteSearchState ( newSearch , { type : "back" } ) ) . toEqual (
854+ createCommandPaletteSearchState ( "linked thread" ) ,
855+ ) ;
856+ const directPicker = reduceCommandPaletteSearchState (
857+ reduceCommandPaletteSearchState ( nested , { type : "reset" } ) ,
858+ { type : "push" , view : projectPicker } ,
859+ ) ;
860+ expect ( reduceCommandPaletteSearchState ( directPicker , { type : "back" } ) ) . toEqual (
861+ createCommandPaletteSearchState ( ) ,
862+ ) ;
863+ expect ( createCommandPaletteSearchState ( ) ) . toEqual ( { query : "" , views : [ ] } ) ;
864+ } ) ;
865+ } ) ;
866+
867+ describe ( "palette-origin search overlay return" , ( ) => {
868+ const root : CommandPaletteUiState = { open : true , mode : "command" , openIntent : null } ;
869+ const context = {
870+ query : ">find file" ,
871+ linkedThreadSearch : null ,
872+ } ;
873+
874+ it . each ( [ "files" , "content" ] as const ) (
875+ "returns from %s without importing the child query" ,
876+ ( mode ) => {
877+ const child = reduceCommandPaletteUiState ( root , {
878+ _tag : "OpenChildSearch" ,
879+ mode,
880+ context,
881+ } ) ;
882+ const returned = reduceCommandPaletteUiState ( child , { _tag : "BackToCommand" } ) ;
883+ expect ( returned . mode ) . toBe ( "command" ) ;
884+ expect ( returned . restoredSearch ) . toEqual ( context ) ;
885+ expect ( returned . parentSearch ) . toBeUndefined ( ) ;
886+ expect ( createCommandPaletteSearchState ( returned . restoredSearch ?. query ) ) . toEqual ( {
887+ query : ">find file" ,
888+ views : [ ] ,
889+ } ) ;
890+ } ,
891+ ) ;
892+
893+ it ( "retains linked-thread search data without carrying the old palette's views" , ( ) => {
894+ const linkedContext = {
895+ query : "https://github.com/acme/web/pull/7" ,
896+ linkedThreadSearch : {
897+ kind : "search" as const ,
898+ query : "https://github.com/acme/web/pull/7" ,
899+ linkedThreads : {
900+ environmentId : EnvironmentId . make ( "remote" ) ,
901+ threads : [ ] ,
902+ } ,
903+ } ,
904+ } ;
905+ const child = reduceCommandPaletteUiState ( root , {
906+ _tag : "OpenChildSearch" ,
907+ mode : "content" ,
908+ context : linkedContext ,
909+ } ) ;
910+ const returned = reduceCommandPaletteUiState ( child , { _tag : "BackToCommand" } ) ;
911+ expect ( returned . restoredSearch ) . toEqual ( linkedContext ) ;
912+ expect ( createCommandPaletteSearchState ( returned . restoredSearch ?. query ) . views ) . toEqual ( [ ] ) ;
913+ } ) ;
914+
915+ it ( "closing after a selection discards the return context and cannot reopen the parent" , ( ) => {
916+ const child = reduceCommandPaletteUiState ( root , {
917+ _tag : "OpenChildSearch" ,
918+ mode : "files" ,
919+ context,
920+ } ) ;
921+ const closed = reduceCommandPaletteUiState ( child , { _tag : "SetOpen" , open : false } ) ;
922+ expect ( reduceCommandPaletteUiState ( closed , { _tag : "BackToCommand" } ) ) . toBe ( closed ) ;
923+ expect ( reduceCommandPaletteUiState ( closed , { _tag : "SetOpen" , open : true } ) ) . toEqual ( root ) ;
924+ } ) ;
925+
926+ it ( "a fresh shortcut or direct intent discards a previous return context" , ( ) => {
927+ const child = reduceCommandPaletteUiState ( root , {
928+ _tag : "OpenChildSearch" ,
929+ mode : "files" ,
930+ context,
931+ } ) ;
932+ const fresh = reduceCommandPaletteUiState ( child , { _tag : "ToggleMode" , mode : "content" } ) ;
933+ expect ( reduceCommandPaletteUiState ( fresh , { _tag : "BackToCommand" } ) ) . toEqual ( root ) ;
934+ const direct = reduceCommandPaletteUiState ( child , { _tag : "OpenChangeTheme" } ) ;
935+ expect ( direct . parentSearch ) . toBeUndefined ( ) ;
936+ expect ( direct . restoredSearch ) . toBeUndefined ( ) ;
937+ } ) ;
938+ } ) ;
0 commit comments