sagemathinc / cocalc

CoCalc: Collaborative Calculation in the Cloud
https://CoCalc.com
Other
1.17k stars 216 forks source link

codemirror search/replace issues with backslash escape character #2142

Open haraldschilly opened 7 years ago

haraldschilly commented 7 years ago

The issue is motivated by search+replace of \latexcommand in latex code, but it is in general about any backslashes in search strings when used for replacing text. The core issue seems to be that at some point an escaped backslash is getting removed. Steps to reproduce:

  1. enter in a *.md document something like:
    
    test \foo

test \foo foo

test foo \foo baz


2. the goal is to replace all `\foo` by `\abc`
3. searching for `\foo` requires to escape the backslash: `\\foo`
4. it finds one, good. But then, when clicking on the search/replace button **again**, it is only `\foo` and therefore it will find plain `foo` in the text, and replace it.

So, the question is, is it strictly necessary to escape the backslash in (3.) or should it be done automatically? Or, in step (4.), should it be escaped again? Somewhere there the escaped backslash is lost.
haraldschilly commented 7 years ago

There is also another problem: in a file where somewhere is /tmp/cocalc, and searching for /tmp/cocalc, only gives tmp. Maybe it automatically translates this into a regex? Oh yes, it does! So, maybe that should be an optional flag...

williamstein commented 1 week ago

Oh yes, it does! So, maybe that should be an optional flag...

This is not our code; it's an upstream CodeMirror plugin -- https://codemirror.net/5/demo/search.html

WORKAROUNDS: