slap-editor / slap

Sublime-like terminal-based text editor
MIT License
6.14k stars 216 forks source link

Implement Replace #374

Open pdl opened 7 years ago

pdl commented 7 years ago

This is a simple implementation of a replace feature. Find continues to work as before, but there is an additional replace line and button. Pressing the button, or hitting enter with the replace line focussed, does a replace. No attempt is made to perform capture interpolation, e.g. of$1 (It's not hard, and I have all the necessary bits of code, but different editors have different behaviours so I want to separate out that bikeshedding specification discussion).

One issue I have found is that the tab order is not stable. I don't know if I'm doing something wrong or whether this is a (mis)feature of the way blessed objects are created, where they specify their parents rather than being actively appended to them as you would with a DOM. It is usable, and always possible to tab to all the fields, but sometimes when hitting tab from the find field, you get the replace field, as you'd expect, and other times, you get the Replace button. I'm not able to solve this but I wonder if the react-blessed rewrite will take care of it.

Note that this renders #367 redundant.

dbkaplun commented 7 years ago

Looks great! Only thing is the replace doesn't work for me. :) Here's what I tried:

At which point I'm not sure why but nothing happens.

pdl commented 7 years ago

OK, looks like the enter key is not triggering the button - you can tab into the Replace button and trigger it manually. I'll look into it.

pdl commented 7 years ago

OK, that should be fixed. I've also added a commit which implements replacement text as after a bit more investigation I'm confident in the behaviour. This adds a dependency, which I've written for the purpose.