@@ -1161,6 +1161,7 @@ async fn test_adding_directory_via_file(cx: &mut gpui::TestAppContext) {
11611161#[ gpui:: test]
11621162async fn test_copy_paste ( cx : & mut gpui:: TestAppContext ) {
11631163 init_test ( cx) ;
1164+ set_auto_open_settings ( cx, true , true , true ) ;
11641165
11651166 let fs = FakeFs :: new ( cx. executor ( ) ) ;
11661167 fs. insert_tree (
@@ -1257,6 +1258,140 @@ async fn test_copy_paste(cx: &mut gpui::TestAppContext) {
12571258 } ) ;
12581259}
12591260
1261+ #[ gpui:: test]
1262+ async fn test_paste_with_auto_open_disabled ( cx : & mut gpui:: TestAppContext ) {
1263+ init_test ( cx) ;
1264+ set_auto_open_settings ( cx, true , false , true ) ;
1265+
1266+ let fs = FakeFs :: new ( cx. executor ( ) ) ;
1267+ fs. insert_tree (
1268+ "/root1" ,
1269+ json ! ( {
1270+ "test.txt" : "content"
1271+ } ) ,
1272+ )
1273+ . await ;
1274+
1275+ let project = Project :: test ( fs. clone ( ) , [ "/root1" . as_ref ( ) ] , cx) . await ;
1276+ let workspace = cx. add_window ( |window, cx| Workspace :: test_new ( project. clone ( ) , window, cx) ) ;
1277+ let cx = & mut VisualTestContext :: from_window ( * workspace, cx) ;
1278+ let panel = workspace. update ( cx, ProjectPanel :: new) . unwrap ( ) ;
1279+ cx. run_until_parked ( ) ;
1280+
1281+ panel. update_in ( cx, |panel, window, cx| {
1282+ panel. select_next ( & Default :: default ( ) , window, cx) ;
1283+ } ) ;
1284+
1285+ panel. update_in ( cx, |panel, window, cx| {
1286+ panel. copy ( & Default :: default ( ) , window, cx) ;
1287+ panel. paste ( & Default :: default ( ) , window, cx) ;
1288+ } ) ;
1289+ cx. executor ( ) . run_until_parked ( ) ;
1290+
1291+ // File should be pasted but not opened (no EDITOR marker)
1292+ assert_eq ! (
1293+ visible_entries_as_strings( & panel, 0 ..50 , cx) ,
1294+ & [
1295+ "v root1" ,
1296+ " test.txt" ,
1297+ " [EDITOR: 'test copy.txt'] <== selected <== marked" ,
1298+ ]
1299+ ) ;
1300+
1301+ // Rename editor appears for disambiguation, confirm it
1302+ panel. update_in ( cx, |panel, window, cx| {
1303+ assert ! ( panel. confirm_edit( window, cx) . is_none( ) )
1304+ } ) ;
1305+ cx. executor ( ) . run_until_parked ( ) ;
1306+
1307+ // After confirming rename, file should exist but still not be opened as a separate editor
1308+ let entries = visible_entries_as_strings ( & panel, 0 ..50 , cx) ;
1309+ assert ! ( entries. contains( & " test copy.txt" . to_string( ) ) ) ;
1310+ assert ! ( entries. contains( & " test.txt" . to_string( ) ) ) ;
1311+ }
1312+
1313+ #[ gpui:: test]
1314+ async fn test_paste_with_auto_open_enabled ( cx : & mut gpui:: TestAppContext ) {
1315+ init_test ( cx) ;
1316+ set_auto_open_settings ( cx, true , true , true ) ;
1317+
1318+ let fs = FakeFs :: new ( cx. executor ( ) ) ;
1319+ fs. insert_tree (
1320+ "/root1" ,
1321+ json ! ( {
1322+ "test.txt" : "content"
1323+ } ) ,
1324+ )
1325+ . await ;
1326+
1327+ let project = Project :: test ( fs. clone ( ) , [ "/root1" . as_ref ( ) ] , cx) . await ;
1328+ let workspace = cx. add_window ( |window, cx| Workspace :: test_new ( project. clone ( ) , window, cx) ) ;
1329+ let cx = & mut VisualTestContext :: from_window ( * workspace, cx) ;
1330+ let panel = workspace. update ( cx, ProjectPanel :: new) . unwrap ( ) ;
1331+ cx. run_until_parked ( ) ;
1332+
1333+ panel. update_in ( cx, |panel, window, cx| {
1334+ panel. select_next ( & Default :: default ( ) , window, cx) ;
1335+ } ) ;
1336+
1337+ panel. update_in ( cx, |panel, window, cx| {
1338+ panel. copy ( & Default :: default ( ) , window, cx) ;
1339+ panel. paste ( & Default :: default ( ) , window, cx) ;
1340+ } ) ;
1341+ cx. executor ( ) . run_until_parked ( ) ;
1342+
1343+ // File should be pasted AND opened (EDITOR marker present)
1344+ assert_eq ! (
1345+ visible_entries_as_strings( & panel, 0 ..50 , cx) ,
1346+ & [
1347+ "v root1" ,
1348+ " test.txt" ,
1349+ " [EDITOR: 'test copy.txt'] <== selected <== marked" ,
1350+ ]
1351+ ) ;
1352+ }
1353+
1354+ #[ gpui:: test]
1355+ async fn test_duplicate_respects_auto_open_setting ( cx : & mut gpui:: TestAppContext ) {
1356+ init_test ( cx) ;
1357+ set_auto_open_settings ( cx, true , false , true ) ;
1358+
1359+ let fs = FakeFs :: new ( cx. executor ( ) ) ;
1360+ fs. insert_tree (
1361+ "/root1" ,
1362+ json ! ( {
1363+ "test.txt" : "content"
1364+ } ) ,
1365+ )
1366+ . await ;
1367+
1368+ let project = Project :: test ( fs. clone ( ) , [ "/root1" . as_ref ( ) ] , cx) . await ;
1369+ let workspace = cx. add_window ( |window, cx| Workspace :: test_new ( project. clone ( ) , window, cx) ) ;
1370+ let cx = & mut VisualTestContext :: from_window ( * workspace, cx) ;
1371+ let panel = workspace. update ( cx, ProjectPanel :: new) . unwrap ( ) ;
1372+ cx. run_until_parked ( ) ;
1373+
1374+ panel. update_in ( cx, |panel, window, cx| {
1375+ panel. select_next ( & Default :: default ( ) , window, cx) ;
1376+ } ) ;
1377+
1378+ // Duplicate uses paste internally, so it should respect on_paste setting
1379+ panel. update_in ( cx, |panel, window, cx| {
1380+ panel. duplicate ( & Duplicate , window, cx) ;
1381+ } ) ;
1382+ cx. executor ( ) . run_until_parked ( ) ;
1383+
1384+ // File should be duplicated but not opened (no additional EDITOR marker beyond rename)
1385+ assert_eq ! (
1386+ visible_entries_as_strings( & panel, 0 ..50 , cx) ,
1387+ & [
1388+ "v root1" ,
1389+ " test.txt" ,
1390+ " [EDITOR: 'test copy.txt'] <== selected <== marked" ,
1391+ ]
1392+ ) ;
1393+ }
1394+
12601395#[ gpui:: test]
12611396async fn test_cut_paste ( cx : & mut gpui:: TestAppContext ) {
12621397 init_test ( cx) ;
@@ -6987,6 +7122,21 @@ fn init_test_with_editor(cx: &mut TestAppContext) {
69877122 } ) ;
69887123}
69897124
7125+ fn set_auto_open_settings ( cx : & mut TestAppContext , on_create : bool , on_paste : bool , on_drop : bool ) {
7126+ cx. update ( |cx| {
7127+ cx. update_global :: < SettingsStore , _ > ( |store, cx| {
7128+ store. update_user_settings ( cx, |settings| {
7129+ settings. project_panel . get_or_insert_default ( ) . auto_open =
7130+ Some ( settings:: ProjectPanelAutoOpenSettings {
7131+ on_create : Some ( on_create) ,
7132+ on_paste : Some ( on_paste) ,
7133+ on_drop : Some ( on_drop) ,
7134+ } ) ;
7135+ } ) ;
7136+ } )
7137+ } ) ;
7138+ }
7139+
69907140fn ensure_single_file_is_opened (
69917141 window : & WindowHandle < Workspace > ,
69927142 expected_path : & str ,
0 commit comments