diff options
-rw-r--r-- | parser.cpp | 9 | ||||
-rw-r--r-- | parser.h | 11 | ||||
-rw-r--r-- | search.cpp | 39 | ||||
-rw-r--r-- | search.h | 25 |
4 files changed, 70 insertions, 14 deletions
@@ -22,7 +22,7 @@ gint macro_pc = 0; namespace States { StateStart start; StateControl control; - StateFlowCommand flowcommand; + StateFCommand fcommand; StateCondCommand condcommand; StateECommand ecommand; StateScintilla_symbols scintilla_symbols; @@ -446,7 +446,7 @@ StateStart::StateStart() : State() transitions['!'] = &States::label; transitions['O'] = &States::gotocmd; transitions['^'] = &States::control; - transitions['F'] = &States::flowcommand; + transitions['F'] = &States::fcommand; transitions['"'] = &States::condcommand; transitions['E'] = &States::ecommand; transitions['I'] = &States::insert; @@ -1012,13 +1012,14 @@ StateStart::custom(gchar chr) throw (Error) return this; } -StateFlowCommand::StateFlowCommand() : State() +StateFCommand::StateFCommand() : State() { transitions['\0'] = this; + transitions['S'] = &States::replace; } State * -StateFlowCommand::custom(gchar chr) throw (Error) +StateFCommand::custom(gchar chr) throw (Error) { switch (chr) { /* @@ -180,9 +180,9 @@ private: State *custom(gchar chr) throw (Error); }; -class StateFlowCommand : public State { +class StateFCommand : public State { public: - StateFlowCommand(); + StateFCommand(); private: State *custom(gchar chr) throw (Error); @@ -217,8 +217,11 @@ private: State *done(const gchar *str) throw (Error); }; +/* + * also serves as base class for replace-insertion states + */ class StateInsert : public StateExpectString { -private: +protected: void initial(void) throw (Error); void process(const gchar *str, gint new_chars) throw (Error); State *done(const gchar *str) throw (Error); @@ -227,7 +230,7 @@ private: namespace States { extern StateStart start; extern StateControl control; - extern StateFlowCommand flowcommand; + extern StateFCommand fcommand; extern StateCondCommand condcommand; extern StateECommand ecommand; extern StateScintilla_symbols scintilla_symbols; @@ -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; +} @@ -7,7 +7,13 @@ #include "parser.h" #include "qbuffers.h" +/* + * "S" command state and base class for all other search/replace commands + */ class StateSearch : public StateExpectString { +public: + StateSearch(bool last = true) : StateExpectString(true, last) {} + protected: struct Parameters { gint dot; @@ -42,9 +48,24 @@ private: State *done(const gchar *str) throw (Error); }; +class StateReplace : public StateSearch { +public: + StateReplace() : StateSearch(false) {} + +private: + State *done(const gchar *str) throw (Error); +}; + +class StateReplace_insert : public StateInsert { +private: + void initial(void) throw (Error) {} +}; + namespace States { - extern StateSearch search; - extern StateSearchAll searchall; + extern StateSearch search; + extern StateSearchAll searchall; + extern StateReplace replace; + extern StateReplace_insert replace_insert; } #endif |