fix support path:line:column in command palette / open file #1081#1149
fix support path:line:column in command palette / open file #1081#1149sinelaw merged 2 commits intosinelaw:masterfrom
Conversation
c3ee6d4 to
40aeef1
Compare
There was a problem hiding this comment.
Pull request overview
Adds support for path:line:column (and path:line) inputs when opening files via prompts, so users can jump directly to a location after opening a file (fixes #1081).
Changes:
- Introduces a crate-visible
Editor::parse_path_line_colhelper and unit tests for it. - Uses the parser when confirming “Open File” prompts and when opening files via the file browser, jumping to the requested line/column after opening.
- Adds an e2e test covering
jump.txt:3:5via the Open File dialog.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| crates/fresh-editor/src/app/prompt_actions.rs | Adds the path/line/col parser, applies it to Open File + Quick Open confirm flows, and adds unit tests. |
| crates/fresh-editor/src/app/file_open_input.rs | Parses path:line:col in the file browser prompt input and jumps after opening. |
| crates/fresh-editor/tests/e2e/file_browser.rs | Adds an e2e regression test to ensure cursor lands at the specified line/column after opening with a suffix. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
cb459d2 to
fceb11f
Compare
|
Please rebase on latest master and
|
|
Also: Thanks |
…d jump to the specified location after opening. Taught the Open File dialog to parse path:line[:col] from the prompt input and jump after open. Made the path:line:col parser crate-visible so the file browser can reuse it safely. Added an e2e test that opens jump.txt:3:5 via the Open File dialog and asserts the cursor lands at Ln 3, Col 5. Co-authored-by: Copilot <[email protected]>
Deduplicate the file-open-and-jump logic in handle_quick_open_file (prompt_actions.rs). The block at ~line 1313-1358 (the if line.is_some() && !path_from_input.is_empty() fallback) is nearly identical to the code in the selected_index branch above it. Extract a shared helper. Move parse_path_line_col off Editor. It's a pure string-parsing function with no self usage — make it a free function (or put it in a utility module) rather than an impl Editor method. Add e2e test for Quick Open with path:line:col — this is a separate user flow from the file browser and needs its own e2e coverage. Add e2e test for path:line (line only, no column) — the parser unit test covers it, but the actual jump-to-line behavior through the full stack is untested.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 4 out of 4 changed files in this pull request and generated 5 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| let prompt_input = self | ||
| .prompt | ||
| .as_ref() | ||
| .map(|p| p.input.clone()) | ||
| .unwrap_or_default(); | ||
| let (path_input, line, column) = parse_path_line_col(&prompt_input); | ||
|
|
||
| // Get the current directory from file open state |
There was a problem hiding this comment.
In the file browser, parse_path_line_col() is used during confirmation, but the incremental filtering logic still uses the raw prompt input (so typing jump.txt:3:5 will apply the filter with the suffix and likely hide the intended file in the list). Consider stripping the :line(:col) suffix when computing/applying the filter as well, so Open File browsing/autocomplete continues to work while entering a jump suffix.
| Err(e) => { | ||
| // Check if this is a large file encoding confirmation error | ||
| if let Some(confirmation) = | ||
| e.downcast_ref::<crate::model::buffer::LargeFileEncodingConfirmation>() | ||
| { | ||
| self.start_large_file_encoding_confirmation(confirmation); | ||
| } else { | ||
| self.set_status_message( |
There was a problem hiding this comment.
When open_file() fails with LargeFileEncodingConfirmation, the jump target (line/column) is dropped: the confirmation prompt only stores path, and after the user confirms, the file is opened without applying goto_line_col. If path:line:col should work for large-file/encoding-confirm flows too, consider threading the optional line/column through the ConfirmLargeFileEncoding prompt type and applying the jump after the confirmed open.
| /// Open a file from the file browser and optionally jump to line/column | ||
| fn file_open_open_file_at_location( | ||
| &mut self, | ||
| path: std::path::PathBuf, | ||
| line: Option<usize>, | ||
| column: Option<usize>, | ||
| ) { | ||
| // Check if encoding detection is disabled - if so, prompt for encoding first | ||
| let detect_encoding = self | ||
| .file_open_state |
There was a problem hiding this comment.
file_open_open_file_at_location adds optional line/column, but note that if open_file(&path) goes through the large-file encoding confirmation prompt, there’s currently no way to carry this jump target through (the prompt type only stores path). If path:line:col should work even when encoding confirmation is required, consider threading line/column through that prompt flow and applying goto_line_col after the confirmed open.
| // Regenerate file suggestions since prompt was already taken by confirm_prompt | ||
| let suggestions = self.get_file_suggestions(input); |
There was a problem hiding this comment.
In Quick Open file confirm, suggestions are regenerated using the raw input (which may include the :line:col suffix). This likely breaks fuzzy matching/selection because file_provider.suggestions() will see e.g. jump.txt:3:5 instead of jump.txt. Consider regenerating suggestions from the parsed path_from_input (and likewise updating the suggestion-generation path used while typing) so path:line:col doesn't disable normal file matching.
| // Regenerate file suggestions since prompt was already taken by confirm_prompt | |
| let suggestions = self.get_file_suggestions(input); | |
| // Regenerate file suggestions since prompt was already taken by confirm_prompt. | |
| // Use the parsed path (without :line:col) for suggestion matching so that | |
| // adding a line/column suffix does not break fuzzy file matching. | |
| let suggestion_query = if path_from_input.is_empty() { | |
| input | |
| } else { | |
| &path_from_input | |
| }; | |
| let suggestions = self.get_file_suggestions(suggestion_query); |
| @@ -49,6 +108,9 @@ impl Editor { | |||
| t!("file.error_opening", error = e.to_string()).to_string(), | |||
| ); | |||
| } else { | |||
| if let Some(line) = line { | |||
| self.goto_line_col(line, column); | |||
| } | |||
| self.set_status_message( | |||
| t!("buffer.opened", name = resolved_path.display().to_string()).to_string(), | |||
| ); | |||
There was a problem hiding this comment.
PromptType::OpenFile now parses path:line:col, but it still has its own open-file + status-message logic and does not handle LargeFileEncodingConfirmation like open_file_with_jump does. To keep behavior consistent (and avoid duplication), consider reusing the helper here as well (or factoring a shared open+confirm path) so Open File supports the same large-file workflow as Quick Open and the file browser.
|
fixed |
- Strip :line:col suffix in Quick Open live filtering and confirm handler so suggestions stay visible while typing a jump target - Reject zero values in parse_path_line_col (goto_line_col is 1-indexed) - Use open_file_with_jump in OpenFile prompt for consistent error handling Co-Authored-By: Claude Opus 4.6 <[email protected]>
- Strip :line:col suffix in Quick Open live filtering and confirm handler so suggestions stay visible while typing a jump target - Reject zero values in parse_path_line_col (goto_line_col is 1-indexed) - Use open_file_with_jump in OpenFile prompt for consistent error handling Co-Authored-By: Claude Opus 4.6 <[email protected]>
- Strip :line:col suffix in Quick Open live filtering and confirm handler so suggestions stay visible while typing a jump target - Reject zero values in parse_path_line_col (goto_line_col is 1-indexed) - Use open_file_with_jump in OpenFile prompt for consistent error handling Co-Authored-By: Claude Opus 4.6 <[email protected]>
- Strip :line:col suffix in Quick Open live filtering and confirm handler so suggestions stay visible while typing a jump target - Reject zero values in parse_path_line_col (goto_line_col is 1-indexed) - Use open_file_with_jump in OpenFile prompt for consistent error handling Co-Authored-By: Claude Opus 4.6 <[email protected]>
fix #1081
Made the path:line:col parser crate-visible so the file browser can reuse it safely.
Added an e2e test that opens jump.txt:3:5 via the Open File dialog and asserts the cursor lands at Ln 3, Col 5.