diff options
author | Robin Haberkorn <robin.haberkorn@googlemail.com> | 2012-12-04 03:15:24 +0100 |
---|---|---|
committer | Robin Haberkorn <robin.haberkorn@googlemail.com> | 2012-12-04 03:15:24 +0100 |
commit | 457fe1498d5fe88e0447ddecd617281f7afd3304 (patch) | |
tree | 15f1d8a3c4c6c20e678a5eef2559b7ad2a8e91ab /search.cpp | |
parent | aca9517b3d90180581570596cb5ac768ef8c127e (diff) | |
download | sciteco-457fe1498d5fe88e0447ddecd617281f7afd3304.tar.gz |
search and replace command (FS)
* makes use of Scintilla selections, so their usage has been improved
* search commands preserve selection on termination (escape)
* selections are restored on rubout
* search-replace command makes use of the Insert command's state (may serve as a base class now)
but does not pop additional values from stack (like "I" does)
Diffstat (limited to 'search.cpp')
-rw-r--r-- | search.cpp | 39 |
1 files changed, 35 insertions, 4 deletions
@@ -9,10 +9,16 @@ #include "search.h" namespace States { - StateSearch search; - StateSearchAll searchall; + StateSearch search; + StateSearchAll searchall; + StateReplace replace; + StateReplace_insert replace_insert; } +/* + * Command states + */ + void StateSearch::initial(void) throw (Error) { @@ -324,7 +330,9 @@ StateSearch::process(const gchar *str, gint count = parameters.count; - undo.push_msg(SCI_GOTOPOS, interface.ssm(SCI_GETCURRENTPOS)); + undo.push_msg(SCI_SETSEL, + interface.ssm(SCI_GETANCHOR), + interface.ssm(SCI_GETCURRENTPOS)); search_reg->undo_set_integer(); search_reg->set_integer(FAILURE); @@ -407,8 +415,14 @@ StateSearch::done(const gchar *str) throw (Error) QRegister *search_reg = QRegisters::globals["_"]; if (*str) { + /* workaround: preserve selection (also on rubout) */ + gint anchor = interface.ssm(SCI_GETANCHOR); + undo.push_msg(SCI_SETANCHOR, anchor); + search_reg->undo_set_string(); search_reg->set_string(str); + + interface.ssm(SCI_SETANCHOR, anchor); } else { gchar *search_str = search_reg->get_string(); process(search_str, 0 /* unused */); @@ -470,7 +484,24 @@ StateSearchAll::done(const gchar *str) throw (Error) BEGIN_EXEC(&States::start); StateSearch::done(str); - QRegisters::hook(QRegisters::HOOK_EDIT); + return &States::start; } + +State * +StateReplace::done(const gchar *str) throw (Error) +{ + BEGIN_EXEC(&States::replace_insert); + + StateSearch::done(str); + + interface.ssm(SCI_BEGINUNDOACTION); + interface.ssm(SCI_REPLACESEL, 0, (sptr_t)""); + interface.ssm(SCI_ENDUNDOACTION); + ring.dirtify(); + + undo.push_msg(SCI_UNDO); + + return &States::replace_insert; +} |