diff --git a/include/nana/gui/widgets/skeletons/text_editor.hpp b/include/nana/gui/widgets/skeletons/text_editor.hpp index 22e099e4..a6904e2e 100644 --- a/include/nana/gui/widgets/skeletons/text_editor.hpp +++ b/include/nana/gui/widgets/skeletons/text_editor.hpp @@ -52,7 +52,15 @@ namespace nana{ namespace widgets { max_steps_ = maxs; if (maxs && (commands_.size() >= maxs)) + { + auto move = commands_.size() - pos_; commands_.erase(commands_.begin(), commands_.begin() + (commands_.size() - maxs + 1)); + pos_ = commands_.size() - std::min(move, commands_.size()); + } + else if (0 == maxs) + { + clear(); + } } std::size_t max_steps() const @@ -258,6 +266,7 @@ namespace nana{ namespace widgets void del(); void backspace(bool record_undo = true); void undo(bool reverse); + void set_undo_queue_length(std::size_t len); void move_ns(bool to_north); //Moves up and down void move_left(); void move_right(); diff --git a/include/nana/gui/widgets/textbox.hpp b/include/nana/gui/widgets/textbox.hpp index 12008c37..b10425f7 100644 --- a/include/nana/gui/widgets/textbox.hpp +++ b/include/nana/gui/widgets/textbox.hpp @@ -228,6 +228,12 @@ namespace nana /// E.g. Whether caret moves to left of selected content or moves to left of last position when left arrow key is pressed. /// @param move_to_end determines whether to move caret to left of selected_content or to left of last position. void select_behavior(bool move_to_end); + + /// Sets the undo/redo queue length + /** + * @param len The length of the queue. If this parameter is zero, the undo/redo is disabled. + */ + void set_undo_queue_length(std::size_t len); protected: //Overrides widget's virtual functions native_string_type _m_caption() const throw() override; diff --git a/source/gui/widgets/skeletons/text_editor.cpp b/source/gui/widgets/skeletons/text_editor.cpp index a030471a..3cda2d81 100644 --- a/source/gui/widgets/skeletons/text_editor.cpp +++ b/source/gui/widgets/skeletons/text_editor.cpp @@ -2348,6 +2348,11 @@ namespace nana{ namespace widgets _m_scrollbar(); } + void text_editor::set_undo_queue_length(std::size_t len) + { + undo_.max_steps(len); + } + void text_editor::move_ns(bool to_north) { const bool redraw_required = _m_cancel_select(0); diff --git a/source/gui/widgets/textbox.cpp b/source/gui/widgets/textbox.cpp index 76aed3ac..dcc2b702 100644 --- a/source/gui/widgets/textbox.cpp +++ b/source/gui/widgets/textbox.cpp @@ -606,6 +606,14 @@ namespace drawerbase { editor->select_behavior(move_to_end); } + void textbox::set_undo_queue_length(std::size_t len) + { + internal_scope_guard lock; + auto editor = get_drawer_trigger().editor(); + if (editor) + editor->set_undo_queue_length(len); + } + //Override _m_caption for caption() auto textbox::_m_caption() const throw() -> native_string_type {