fix crash that text_editor undo enter with selected text

This commit is contained in:
Jinhao
2017-06-02 04:26:19 +08:00
parent a87703d418
commit a6c6a84147

View File

@@ -143,6 +143,11 @@ namespace nana{ namespace widgets
//sel_a_ and sel_b_ are not sorted, sel_b_ keeps the caret position. //sel_a_ and sel_b_ are not sorted, sel_b_ keeps the caret position.
sel_a_ = editor_.select_.a; sel_a_ = editor_.select_.a;
sel_b_ = editor_.select_.b; sel_b_ = editor_.select_.b;
if (sel_a_ != sel_b_)
{
selected_text_ = editor_._m_make_select_string();
}
} }
void set_caret_pos() void set_caret_pos()
@@ -179,8 +184,7 @@ namespace nana{ namespace widgets
void set_removed(std::wstring str) void set_removed(std::wstring str)
{ {
//use selected_text_ as removed text selected_text_ = std::move(str);
selected_text_ = str;
} }
void execute(bool redo) override void execute(bool redo) override
@@ -287,17 +291,17 @@ namespace nana{ namespace widgets
} }
else else
editor_.textbase().erase(pos_.y, pos_.x, text_.size()); //undo editor_.textbase().erase(pos_.y, pos_.x, text_.size()); //undo
}
if (!selected_text_.empty()) if (!selected_text_.empty())
{ {
editor_.points_.caret = sel_a_; editor_.points_.caret = (std::min)(sel_a_, sel_b_);
editor_._m_put(selected_text_); editor_._m_put(selected_text_);
editor_.points_.caret = sel_b_; editor_.points_.caret = sel_b_;
editor_.select_.a = sel_a_; //Reset the selected text editor_.select_.a = sel_a_; //Reset the selected text
editor_.select_.b = sel_b_; editor_.select_.b = sel_b_;
} }
} }
}
editor_.move_caret(editor_.points_.caret); editor_.move_caret(editor_.points_.caret);
} }
private: private:
@@ -2161,8 +2165,6 @@ namespace nana{ namespace widgets
} }
else else
{ {
undo_ptr->set_removed(this->_m_make_select_string());
undo_ptr->set_selected_text(); undo_ptr->set_selected_text();
points_.caret = _m_erase_select(); points_.caret = _m_erase_select();
undo_ptr->set_caret_pos(); undo_ptr->set_caret_pos();