howl-editor / howl

The Howl Editor
http://howl.io
Other
712 stars 68 forks source link

Bizarre issue with replacing text in REALLY large file #160

Closed refi64 closed 8 years ago

refi64 commented 8 years ago

Well, this is...interesting...

Download this huge, 700-line file C source file. Now, open the file in Howl, hit Ctrl-H to replace text, and enter m->groups, then enter a slash to move on to the replacement text. Notice that Howl selects the wrong region of text to replace:

howl_sel0

Now, anything you type will proceed to completely wreck the remainder of the file:

howl_sel1

shalabhc commented 8 years ago

I cannot reproduce this in master. Here are my screenshots - works as expected. Anything special with your config or file?

replace-1 replace-1 replace-3

refi64 commented 8 years ago

Well, this is weird.

If I try it on the file anywhere else, it works correctly.

BUT...

If I save the file as ~/rejit2/tst.c, then the bug appears!

EDIT: Or it has to do with the files in the directory. If I rename it, then it still doesn't work.

refi64 commented 8 years ago

Here's how to reproduce it:

  1. Clone ReJit somewhere.
  2. Open tst.c in that directory.

Any other way will cause the bug not to appear. This is easily the weirdest bug I've ever come across...

shalabhc commented 8 years ago

OK, I can reproduce this now by the instructions above. I haven't found the root issue but I suspect it is either in aullar/buffer.moon or in replacement.moon.

The following patch fixes it for me, @kirbyfan64 can you verify it fixes it for you too?:

--- a/lib/howl/interactions/replacement.moon
+++ b/lib/howl/interactions/replacement.moon
@@ -285,6 +285,7 @@ class Replacement
     highlight.remove_all 'replace_strikeout', @preview_buffer

   _highlight_match: (name, pos, len) =>
+    @preview_buffer.text
     highlight.apply name, @preview_buffer, pos, len

   _toggle_current: =>

I discovered this because I wasn't able to reproduce the issue once I added the log that accessed preview_buffer.text.

I'm also having trouble reducing the test case itself. It seems some combination of the below is needed:

I suspect calling preview_buffer\chunk(...) = ... to replace some chunk (line 241 in replacement.py) has something to do with it.

Still looking, ideas welcome...

shalabhc commented 8 years ago

I can reproduce the problem by using the buffer API directly, so I think the bug is in aullar.buffer.

  1. Download tst.c: wget https://github.com/kirbyfan64/rejit/raw/master/tst.c
  2. Run howl, open a new buffer, paste below code. Select all and howl-moon-eval:

    howl.bindings.push
     f2: ->
       buffer = howl.app.editor.buffer
       first = 26985
       last = 27376
    
       text = buffer\chunk(first, last).text
       buffer\chunk(first, last).text = text
  3. Open tst.c, go to line 759
  4. Press f2 to run the test code above.

The buffer text changes, even though the text should not because the replacement is identical.

@nilnor - sorry, couldn't reduce the test case to something simpler.

nilnor commented 8 years ago

@kirbyfan64 Thanks for the report, and thanks @shalabhc for drilling down and making it easy to reproduce! Should be fixed now, but please verify if you have a moment.

refi64 commented 8 years ago

@nilnor Yup, that fixed the issue!