Closes https://github.com/zed-industries/community/issues/1789#issuecomment-1646061712 <img width="196" alt="Screenshot 2023-07-21 at 23 23 47" src="https://github.com/zed-industries/zed/assets/2690773/f5c7025b-6dc8-4f0c-81e5-3cc98a3a9c8b"> <img width="197" alt="Screenshot 2023-07-21 at 23 23 52" src="https://github.com/zed-industries/zed/assets/2690773/596f8ab0-15e0-4285-be34-ce4c276b686f"> When renaming in project panel, select file names without extensions. Release Notes: - Improved project panel rename by selecting file names without extensions
Unified · Split
| @@ -4,7 +4,7 @@ mod project_panel_settings; · 3 unmodified lines | ||
| 4 | 4 | use context_menu::{ContextMenu, ContextMenuItem}; |
| 5 | 5 | use db::kvp::KEY_VALUE_STORE; |
| 6 | 6 | use drag_and_drop::{DragAndDrop, Draggable}; |
| 7 | −use editor::{Cancel, Editor}; | |
| 7 | +use editor::{scroll::autoscroll::Autoscroll, Cancel, Editor}; | |
| 8 | 8 | use file_associations::FileAssociations; |
| 9 | 9 | |
| 10 | 10 | use futures::stream::StreamExt; |
| @@ -741,13 +741,20 @@ impl ProjectPanel { · 730 unmodified lines | ||
| 741 | 741 | is_dir: entry.is_dir(), |
| 742 | 742 | processing_filename: None, |
| 743 | 743 | }); |
| 744 | − let filename = entry | |
| 744 | + let file_name = entry | |
| 745 | 745 | .path |
| 746 | 746 | .file_name() |
| 747 | − .map_or(String::new(), |s| s.to_string_lossy().to_string()); | |
| 747 | + .map(|s| s.to_string_lossy()) | |
| 748 | + .unwrap_or_default() | |
| 749 | + .to_string(); | |
| 750 | + let file_stem = entry.path.file_stem().map(|s| s.to_string_lossy()); | |
| 751 | + let selection_end = | |
| 752 | + file_stem.map_or(file_name.len(), |file_stem| file_stem.len()); | |
| 748 | 753 | self.filename_editor.update(cx, |editor, cx| { |
| 749 | − editor.set_text(filename, cx); | |
| 750 | − editor.select_all(&Default::default(), cx); | |
| 754 | + editor.set_text(file_name, cx); | |
| 755 | + editor.change_selections(Some(Autoscroll::fit()), cx, |s| { | |
| 756 | + s.select_ranges([0..selection_end]) | |
| 757 | + }) | |
| 751 | 758 | }); |
| 752 | 759 | cx.focus(&self.filename_editor); |
| 753 | 760 | self.update_visible_entries(None, cx); |
| @@ -1942,7 +1949,7 @@ mod tests { · 1188 unmodified lines | ||
| 1942 | 1949 | .update(cx, |panel, cx| { |
| 1943 | 1950 | panel |
| 1944 | 1951 | .filename_editor |
| 1945 | − .update(cx, |editor, cx| editor.set_text("another-filename", cx)); | |
| 1952 | + .update(cx, |editor, cx| editor.set_text("another-filename.txt", cx)); | |
| 1946 | 1953 | panel.confirm(&Confirm, cx).unwrap() |
| 1947 | 1954 | }) |
| 1948 | 1955 | .await |
| @@ -1956,14 +1963,14 @@ mod tests { · 7 unmodified lines | ||
| 1956 | 1963 | " v b", |
| 1957 | 1964 | " > 3", |
| 1958 | 1965 | " > 4", |
| 1959 | − " another-filename <== selected", | |
| 1966 | + " another-filename.txt <== selected", | |
| 1960 | 1967 | " > C", |
| 1961 | 1968 | " .dockerignore", |
| 1962 | 1969 | " the-new-filename", |
| 1963 | 1970 | ] |
| 1964 | 1971 | ); |
| 1965 | 1972 | |
| 1966 | − select_path(&panel, "root1/b/another-filename", cx); | |
| 1973 | + select_path(&panel, "root1/b/another-filename.txt", cx); | |
| 1967 | 1974 | panel.update(cx, |panel, cx| panel.rename(&Rename, cx)); |
| 1968 | 1975 | assert_eq!( |
| 1969 | 1976 | visible_entries_as_strings(&panel, 0..10, cx), |
| @@ -1974,7 +1981,7 @@ mod tests { · 4 unmodified lines | ||
| 1974 | 1981 | " v b", |
| 1975 | 1982 | " > 3", |
| 1976 | 1983 | " > 4", |
| 1977 | − " [EDITOR: 'another-filename'] <== selected", | |
| 1984 | + " [EDITOR: 'another-filename.txt'] <== selected", | |
| 1978 | 1985 | " > C", |
| 1979 | 1986 | " .dockerignore", |
| 1980 | 1987 | " the-new-filename", |
| @@ -1982,9 +1989,15 @@ mod tests { · 1 unmodified line | ||
| 1982 | 1989 | ); |
| 1983 | 1990 | |
| 1984 | 1991 | let confirm = panel.update(cx, |panel, cx| { |
| 1985 | − panel | |
| 1986 | − .filename_editor | |
| 1987 | − .update(cx, |editor, cx| editor.set_text("a-different-filename", cx)); | |
| 1992 | + panel.filename_editor.update(cx, |editor, cx| { | |
| 1993 | + let file_name_selections = editor.selections.all::<usize>(cx); | |
| 1994 | + assert_eq!(file_name_selections.len(), 1, "File editing should have a single selection, but got: {file_name_selections:?}"); | |
| 1995 | + let file_name_selection = &file_name_selections[0]; | |
| 1996 | + assert_eq!(file_name_selection.start, 0, "Should select the file name from the start"); | |
| 1997 | + assert_eq!(file_name_selection.end, "another-filename".len(), "Should not select file extension"); | |
| 1998 | + | |
| 1999 | + editor.set_text("a-different-filename.tar.gz", cx) | |
| 2000 | + }); | |
| 1988 | 2001 | panel.confirm(&Confirm, cx).unwrap() |
| 1989 | 2002 | }); |
| 1990 | 2003 | assert_eq!( |
| @@ -1996,7 +2009,7 @@ mod tests { · 5 unmodified lines | ||
| 1996 | 2009 | " v b", |
| 1997 | 2010 | " > 3", |
| 1998 | 2011 | " > 4", |
| 1999 | − " [PROCESSING: 'a-different-filename'] <== selected", | |
| 2012 | + " [PROCESSING: 'a-different-filename.tar.gz'] <== selected", | |
| 2000 | 2013 | " > C", |
| 2001 | 2014 | " .dockerignore", |
| 2002 | 2015 | " the-new-filename", |
| @@ -2013,13 +2026,42 @@ mod tests { · 10 unmodified lines | ||
| 2013 | 2026 | " v b", |
| 2014 | 2027 | " > 3", |
| 2015 | 2028 | " > 4", |
| 2016 | − " a-different-filename <== selected", | |
| 2029 | + " a-different-filename.tar.gz <== selected", | |
| 2017 | 2030 | " > C", |
| 2018 | 2031 | " .dockerignore", |
| 2019 | 2032 | " the-new-filename", |
| 2020 | 2033 | ] |
| 2021 | 2034 | ); |
| 2022 | 2035 | |
| 2036 | + panel.update(cx, |panel, cx| panel.rename(&Rename, cx)); | |
| 2037 | + assert_eq!( | |
| 2038 | + visible_entries_as_strings(&panel, 0..10, cx), | |
| 2039 | + &[ | |
| 2040 | + "v root1", | |
| 2041 | + " > .git", | |
| 2042 | + " > a", | |
| 2043 | + " v b", | |
| 2044 | + " > 3", | |
| 2045 | + " > 4", | |
| 2046 | + " [EDITOR: 'a-different-filename.tar.gz'] <== selected", | |
| 2047 | + " > C", | |
| 2048 | + " .dockerignore", | |
| 2049 | + " the-new-filename", | |
| 2050 | + ] | |
| 2051 | + ); | |
| 2052 | + | |
| 2053 | + panel.update(cx, |panel, cx| { | |
| 2054 | + panel.filename_editor.update(cx, |editor, cx| { | |
| 2055 | + let file_name_selections = editor.selections.all::<usize>(cx); | |
| 2056 | + assert_eq!(file_name_selections.len(), 1, "File editing should have a single selection, but got: {file_name_selections:?}"); | |
| 2057 | + let file_name_selection = &file_name_selections[0]; | |
| 2058 | + assert_eq!(file_name_selection.start, 0, "Should select the file name from the start"); | |
| 2059 | + assert_eq!(file_name_selection.end, "a-different-filename.tar".len(), "Should not select file extension, but still may select anything up to the last dot"); | |
| 2060 | + | |
| 2061 | + }); | |
| 2062 | + panel.cancel(&Cancel, cx) | |
| 2063 | + }); | |
| 2064 | + | |
| 2023 | 2065 | panel.update(cx, |panel, cx| panel.new_directory(&NewDirectory, cx)); |
| 2024 | 2066 | assert_eq!( |
| 2025 | 2067 | visible_entries_as_strings(&panel, 0..10, cx), |
| @@ -2031,7 +2073,7 @@ mod tests { · 5 unmodified lines | ||
| 2031 | 2073 | " > [EDITOR: ''] <== selected", |
| 2032 | 2074 | " > 3", |
| 2033 | 2075 | " > 4", |
| 2034 | − " a-different-filename", | |
| 2076 | + " a-different-filename.tar.gz", | |
| 2035 | 2077 | " > C", |
| 2036 | 2078 | " .dockerignore", |
| 2037 | 2079 | ] |
| @@ -2054,7 +2096,7 @@ mod tests { · 16 unmodified lines | ||
| 2054 | 2096 | " > [PROCESSING: 'new-dir']", |
| 2055 | 2097 | " > 3 <== selected", |
| 2056 | 2098 | " > 4", |
| 2057 | − " a-different-filename", | |
| 2099 | + " a-different-filename.tar.gz", | |
| 2058 | 2100 | " > C", |
| 2059 | 2101 | " .dockerignore", |
| 2060 | 2102 | ] |
| @@ -2071,7 +2113,7 @@ mod tests { · 10 unmodified lines | ||
| 2071 | 2113 | " > 3 <== selected", |
| 2072 | 2114 | " > 4", |
| 2073 | 2115 | " > new-dir", |
| 2074 | − " a-different-filename", | |
| 2116 | + " a-different-filename.tar.gz", | |
| 2075 | 2117 | " > C", |
| 2076 | 2118 | " .dockerignore", |
| 2077 | 2119 | ] |
| @@ -2088,7 +2130,7 @@ mod tests { · 10 unmodified lines | ||
| 2088 | 2130 | " > [EDITOR: '3'] <== selected", |
| 2089 | 2131 | " > 4", |
| 2090 | 2132 | " > new-dir", |
| 2091 | − " a-different-filename", | |
| 2133 | + " a-different-filename.tar.gz", | |
| 2092 | 2134 | " > C", |
| 2093 | 2135 | " .dockerignore", |
| 2094 | 2136 | ] |
| @@ -2106,7 +2148,7 @@ mod tests { · 11 unmodified lines | ||
| 2106 | 2148 | " > 3 <== selected", |
| 2107 | 2149 | " > 4", |
| 2108 | 2150 | " > new-dir", |
| 2109 | − " a-different-filename", | |
| 2151 | + " a-different-filename.tar.gz", | |
| 2110 | 2152 | " > C", |
| 2111 | 2153 | " .dockerignore", |
| 2112 | 2154 | ] |