zed icon indicating copy to clipboard operation
zed copied to clipboard

Multiline regular expression search toggle (regex multi-line support)

Open notpeter opened this issue 9 months ago • 0 comments

Summary

Add explicit support for using multi-line regexes.

Description

Zed currently only supports multiline regex implicitly if there is a \n included in the needle: https://github.com/zed-industries/zed/blob/8cf7206adf2fd902cff39d4ea3391a5764d7892c/crates/project/src/search.rs#L140

But there are regular expressions without an explicit \n that behave differently between multiline mode and single line mode. \s+$ is one such example:

  • https://github.com/zed-industries/zed/issues/25901#issuecomment-2692996651

There are a number of design considerations:

  1. Is the icon present when not in regex mode?
  2. Does Zed preserve the existing intuitive behavior that when your needle includes \n do we automatically enable multiline?
  3. Do we automatically enable for \s which includes \n?
  4. Icon for multiline toggle

Given that few people understand the subtle implications of multiline vs non-multiline regexes, it may be a disabled button most of the time (when not in regex mode) and that VSCode, JetBrains and Sublime do not include explicit multi-line regex toggles, it might be reasonable to make this require an opt-in setting like "features": { "regex_multiline" } to avoid more confusing buttons to the existing set:

Image

References:

  • https://docs.rs/regex/latest/regex/#perl-character-classes-unicode-friendly
  • https://www.unicode.org/reports/tr18/#Compatibility_Properties
  • https://www.unicode.org/Public/UCD/latest/ucd/PropList.txt

notpeter avatar Mar 03 '25 14:03 notpeter