texworks icon indicating copy to clipboard operation
texworks copied to clipboard

regex button in Find/replace should escape the search field accordingly

Open jlaurens opened this issue 4 years ago • 2 comments

Is your feature request related to a problem? Please describe. When the regex option is checked in the find panel, setting the search field from the currently selected text usefully escapes appropriate characters. If we want to make a normal search, we uncheck the regex box but the search field remains escaped and must be edited by hand.

Describe the solution you'd like When we check the regex box, the search field gets escaped. When we uncheck the regex box, the search field gets unescaped.

Describe alternatives you've considered

  • Uncheck the regex box and close the find panel, but that does not turn the regex option off.

Additional context Add any other context or screenshots about the feature request here.

jlaurens avatar Nov 18 '21 14:11 jlaurens

Thanks for the suggestion. However, I don't fully understand it. The escaping is a feature of the "copy to find" function, not of the find dialog itself (or its regexp checkbox). "Copy to find" just makes sure what gets copied is appropriate for the current mode (the one selected the last time the user hit "Ok"). Once it's copied it's a search string like any other. There are many things we could discuss about the current implementation. For one, is a separate "Copy to find" really useful (or should the find dialog, e.g., just take whatever is selected if anything)? Also, should the regex option automatically escape (and unescape) when toggled (I quite like the fact it doesn't; this way, I can compose my regex and if I later find out I forgot to check the box I can do so without it screwing up my regex)? Moreover, the code currently uses Qt's QRegularExpression::escape and there is no corresponding QRegularExpression::unescape. Writing such a function that handles all (corner) cases is probably quite difficult (if possible at all; how would you handle, e.g., "wildcards" such as \s or \d?)

stloeffler avatar Nov 28 '21 10:11 stloeffler

Under the light of your comments, next example of design will illustrate my point of view

"Copy to find" action:

  1. switch "on copy to find mode" on,
  2. store the selected text as raw search string
  3. continue on actual implementation

Whenever the search string is edited, switch "on copy to find mode" off.

For the regex mode, some supplemental instructions are needed

  1. when switching to regex mode, if "on copy to find mode" is on, set the search string to the escaped raw search string
  2. when switching from regex mode, if "on copy to find mode" is on, set the find string to the raw search string

When the find/replace panel is discarded, clean the raw search string storage and switch "on copy to find mode" off.

Alternate solutions:

  • let the find panel record the options even when the search is canceled, simpler implementation, but heavy UI,
  • let each editor window have its own embedded find panel (more modern but with a much higher cost!)

jlaurens avatar Dec 10 '21 14:12 jlaurens