Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -577,7 +577,7 @@ emojis = "0.6.1"
env_logger = "0.11"
encoding_rs = "0.8"
exec = "0.3.1"
fancy-regex = "0.17.0"
fancy-regex = "0.18.0"
fork = "0.4.0"
futures = "0.3.32"
futures-concurrency = "7.7.1"
Expand Down
1 change: 1 addition & 0 deletions crates/project/src/search.rs
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,7 @@ impl SearchQuery {

let regex = RegexBuilder::new(&pattern)
.case_insensitive(!case_sensitive)
.crlf(true)
.build()?;
Ok(Self::Regex {
regex,
Expand Down
33 changes: 32 additions & 1 deletion crates/project/tests/integration/search.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use language::Buffer;
use project::search::SearchQuery;
use text::Rope;
use util::{
Expand Down Expand Up @@ -130,6 +131,37 @@ fn test_case_sensitive_pattern_items() {
);
}

#[gpui::test]
async fn test_multiline_regex_crlf(cx: &mut gpui::TestAppContext) {
// Verify that `$` line-end anchors work correctly on CRLF content.
// With .crlf(true) on the RegexBuilder, `$` in multiline mode matches
// before \r\n (not just before \n), so a pattern like `^hello$\r?\n`
// correctly matches "hello\r\n" in CRLF files. Without .crlf(true),
// `$` would only anchor before a bare \n, so the `\r` before the newline
// would prevent the anchor from firing and the pattern would never match.
let search_query = SearchQuery::regex(
"^hello$\r?\n",
false,
false,
false,
false,
Default::default(),
Default::default(),
false,
None,
)
.expect("Should be able to create a regex SearchQuery");

let text = Rope::from("hello\r\nworld\r\nhello\r\nworld");
let snapshot = cx
.update(|app| Buffer::build_snapshot(text, None, None, None, app))
.await;

let results = search_query.search(&snapshot, None).await;
// Each "hello\r\n" is 7 bytes; matches should cover those byte ranges.
assert_eq!(results, vec![0..7, 14..21]);
}

#[gpui::test]
async fn test_multiline_regex(cx: &mut gpui::TestAppContext) {
let search_query = SearchQuery::regex(
Expand All @@ -145,7 +177,6 @@ async fn test_multiline_regex(cx: &mut gpui::TestAppContext) {
)
.expect("Should be able to create a regex SearchQuery");

use language::Buffer;
let text = Rope::from("hello\nworld\nhello\nworld");
let snapshot = cx
.update(|app| Buffer::build_snapshot(text, None, None, None, app))
Expand Down