Skip to content

fix support path:line:column in command palette / open file #1081#1149

Merged
sinelaw merged 2 commits intosinelaw:masterfrom
asukaminato0721:1081
Mar 5, 2026
Merged

fix support path:line:column in command palette / open file #1081#1149
sinelaw merged 2 commits intosinelaw:masterfrom
asukaminato0721:1081

Conversation

@asukaminato0721
Copy link
Copy Markdown
Contributor

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.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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_col helper 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:5 via 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.

@sinelaw
Copy link
Copy Markdown
Owner

sinelaw commented Mar 2, 2026

Please rebase on latest master and

  1. 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.
  2. 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.

@sinelaw
Copy link
Copy Markdown
Owner

sinelaw commented Mar 2, 2026

Also:
3. 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.
4. 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.

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.
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment on lines 169 to 176
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
Copy link

Copilot AI Mar 3, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot uses AI. Check for mistakes.
Comment on lines +1280 to +1287
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(
Copy link

Copilot AI Mar 3, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot uses AI. Check for mistakes.
Comment on lines +299 to 308
/// 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
Copy link

Copilot AI Mar 3, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot uses AI. Check for mistakes.
Comment on lines 1302 to 1303
// Regenerate file suggestions since prompt was already taken by confirm_prompt
let suggestions = self.get_file_suggestions(input);
Copy link

Copilot AI Mar 3, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
// 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);

Copilot uses AI. Check for mistakes.
Comment on lines 96 to 116
@@ -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(),
);
Copy link

Copilot AI Mar 3, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot uses AI. Check for mistakes.
@asukaminato0721
Copy link
Copy Markdown
Contributor Author

fixed

@sinelaw sinelaw merged commit 40f48a8 into sinelaw:master Mar 5, 2026
11 of 12 checks passed
sinelaw added a commit that referenced this pull request Mar 5, 2026
- 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]>
sinelaw added a commit that referenced this pull request Mar 5, 2026
- 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]>
sinelaw added a commit that referenced this pull request Mar 5, 2026
- 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]>
sinelaw added a commit that referenced this pull request Mar 5, 2026
- 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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

support path:line:column in command palette / open file

3 participants