History

When renaming in project panel, select file names without extensions (#2776)

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

Kirill Bulatov committed 3 years ago

Commit 25ea07c2 parents 33b215a 804da681 file · +61 −19Browse files

Unified · Split

crates/project_panel/src/project_panel.rs+61−19
@@ -4,7 +4,7 @@ mod project_panel_settings; · 3 unmodified lines
4use context_menu::{ContextMenu, ContextMenuItem};4use context_menu::{ContextMenu, ContextMenuItem};
5use db::kvp::KEY_VALUE_STORE;5use db::kvp::KEY_VALUE_STORE;
6use drag_and_drop::{DragAndDrop, Draggable};6use drag_and_drop::{DragAndDrop, Draggable};
7use editor::{Cancel, Editor};7use editor::{scroll::autoscroll::Autoscroll, Cancel, Editor};
8use file_associations::FileAssociations;8use file_associations::FileAssociations;
9 9
10use futures::stream::StreamExt;10use futures::stream::StreamExt;
@@ -741,13 +741,20 @@ impl ProjectPanel { · 730 unmodified lines
741 is_dir: entry.is_dir(),741 is_dir: entry.is_dir(),
742 processing_filename: None,742 processing_filename: None,
743 });743 });
744 let filename = entry744 let file_name = entry
745 .path745 .path
746 .file_name()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 self.filename_editor.update(cx, |editor, cx| {753 self.filename_editor.update(cx, |editor, cx| {
749 editor.set_text(filename, cx);754 editor.set_text(file_name, cx);
750 editor.select_all(&Default::default(), cx);755 editor.change_selections(Some(Autoscroll::fit()), cx, |s| {
756 s.select_ranges([0..selection_end])
757 })
751 });758 });
752 cx.focus(&self.filename_editor);759 cx.focus(&self.filename_editor);
753 self.update_visible_entries(None, cx);760 self.update_visible_entries(None, cx);
@@ -1942,7 +1949,7 @@ mod tests { · 1188 unmodified lines
1942 .update(cx, |panel, cx| {1949 .update(cx, |panel, cx| {
1943 panel1950 panel
1944 .filename_editor1951 .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 panel.confirm(&Confirm, cx).unwrap()1953 panel.confirm(&Confirm, cx).unwrap()
1947 })1954 })
1948 .await1955 .await
@@ -1956,14 +1963,14 @@ mod tests { · 7 unmodified lines
1956 " v b",1963 " v b",
1957 " > 3",1964 " > 3",
1958 " > 4",1965 " > 4",
1959 " another-filename <== selected",1966 " another-filename.txt <== selected",
1960 " > C",1967 " > C",
1961 " .dockerignore",1968 " .dockerignore",
1962 " the-new-filename",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 panel.update(cx, |panel, cx| panel.rename(&Rename, cx));1974 panel.update(cx, |panel, cx| panel.rename(&Rename, cx));
1968 assert_eq!(1975 assert_eq!(
1969 visible_entries_as_strings(&panel, 0..10, cx),1976 visible_entries_as_strings(&panel, 0..10, cx),
@@ -1974,7 +1981,7 @@ mod tests { · 4 unmodified lines
1974 " v b",1981 " v b",
1975 " > 3",1982 " > 3",
1976 " > 4",1983 " > 4",
1977 " [EDITOR: 'another-filename'] <== selected",1984 " [EDITOR: 'another-filename.txt'] <== selected",
1978 " > C",1985 " > C",
1979 " .dockerignore",1986 " .dockerignore",
1980 " the-new-filename",1987 " the-new-filename",
@@ -1982,9 +1989,15 @@ mod tests { · 1 unmodified line
1982 );1989 );
1983 1990
1984 let confirm = panel.update(cx, |panel, cx| {1991 let confirm = panel.update(cx, |panel, cx| {
1985 panel1992 panel.filename_editor.update(cx, |editor, cx| {
1986 .filename_editor1993 let file_name_selections = editor.selections.all::<usize>(cx);
1987 .update(cx, |editor, cx| editor.set_text("a-different-filename", 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 panel.confirm(&Confirm, cx).unwrap()2001 panel.confirm(&Confirm, cx).unwrap()
1989 });2002 });
1990 assert_eq!(2003 assert_eq!(
@@ -1996,7 +2009,7 @@ mod tests { · 5 unmodified lines
1996 " v b",2009 " v b",
1997 " > 3",2010 " > 3",
1998 " > 4",2011 " > 4",
1999 " [PROCESSING: 'a-different-filename'] <== selected",2012 " [PROCESSING: 'a-different-filename.tar.gz'] <== selected",
2000 " > C",2013 " > C",
2001 " .dockerignore",2014 " .dockerignore",
2002 " the-new-filename",2015 " the-new-filename",
@@ -2013,13 +2026,42 @@ mod tests { · 10 unmodified lines
2013 " v b",2026 " v b",
2014 " > 3",2027 " > 3",
2015 " > 4",2028 " > 4",
2016 " a-different-filename <== selected",2029 " a-different-filename.tar.gz <== selected",
2017 " > C",2030 " > C",
2018 " .dockerignore",2031 " .dockerignore",
2019 " the-new-filename",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 panel.update(cx, |panel, cx| panel.new_directory(&NewDirectory, cx));2065 panel.update(cx, |panel, cx| panel.new_directory(&NewDirectory, cx));
2024 assert_eq!(2066 assert_eq!(
2025 visible_entries_as_strings(&panel, 0..10, cx),2067 visible_entries_as_strings(&panel, 0..10, cx),
@@ -2031,7 +2073,7 @@ mod tests { · 5 unmodified lines
2031 " > [EDITOR: ''] <== selected",2073 " > [EDITOR: ''] <== selected",
2032 " > 3",2074 " > 3",
2033 " > 4",2075 " > 4",
2034 " a-different-filename",2076 " a-different-filename.tar.gz",
2035 " > C",2077 " > C",
2036 " .dockerignore",2078 " .dockerignore",
2037 ]2079 ]
@@ -2054,7 +2096,7 @@ mod tests { · 16 unmodified lines
2054 " > [PROCESSING: 'new-dir']",2096 " > [PROCESSING: 'new-dir']",
2055 " > 3 <== selected",2097 " > 3 <== selected",
2056 " > 4",2098 " > 4",
2057 " a-different-filename",2099 " a-different-filename.tar.gz",
2058 " > C",2100 " > C",
2059 " .dockerignore",2101 " .dockerignore",
2060 ]2102 ]
@@ -2071,7 +2113,7 @@ mod tests { · 10 unmodified lines
2071 " > 3 <== selected",2113 " > 3 <== selected",
2072 " > 4",2114 " > 4",
2073 " > new-dir",2115 " > new-dir",
2074 " a-different-filename",2116 " a-different-filename.tar.gz",
2075 " > C",2117 " > C",
2076 " .dockerignore",2118 " .dockerignore",
2077 ]2119 ]
@@ -2088,7 +2130,7 @@ mod tests { · 10 unmodified lines
2088 " > [EDITOR: '3'] <== selected",2130 " > [EDITOR: '3'] <== selected",
2089 " > 4",2131 " > 4",
2090 " > new-dir",2132 " > new-dir",
2091 " a-different-filename",2133 " a-different-filename.tar.gz",
2092 " > C",2134 " > C",
2093 " .dockerignore",2135 " .dockerignore",
2094 ]2136 ]
@@ -2106,7 +2148,7 @@ mod tests { · 11 unmodified lines
2106 " > 3 <== selected",2148 " > 3 <== selected",
2107 " > 4",2149 " > 4",
2108 " > new-dir",2150 " > new-dir",
2109 " a-different-filename",2151 " a-different-filename.tar.gz",
2110 " > C",2152 " > C",
2111 " .dockerignore",2153 " .dockerignore",
2112 ]2154 ]

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t