fix crash where text_editor enables the linewrap(#254)

This commit is contained in:
Jinhao 2017-09-13 04:58:05 +08:00
parent 803acb13f0
commit c45f621eea

View File

@ -556,6 +556,7 @@ namespace nana{ namespace widgets
virtual void merge_lines(std::size_t first, std::size_t second) = 0;
//Calculates how many lines the specified line of text takes with a specified pixels of width.
virtual void add_lines(std::size_t pos, std::size_t lines) = 0;
virtual void prepare() = 0;
virtual void pre_calc_line(std::size_t line, unsigned pixels) = 0;
virtual void pre_calc_lines(unsigned pixels) = 0;
virtual std::size_t take_lines() const = 0;
@ -668,6 +669,12 @@ namespace nana{ namespace widgets
}
}
void prepare() override
{
auto const line_count = editor_.textbase().lines();
this->sections_.resize(line_count);
}
void pre_calc_line(std::size_t pos, unsigned) override
{
auto const & text = editor_.textbase().getline(pos);
@ -781,6 +788,12 @@ namespace nana{ namespace widgets
}
}
void prepare() override
{
auto const lines = editor_.textbase().lines();
linemtr_.resize(lines);
}
void pre_calc_line(std::size_t line, unsigned pixels) override
{
const string_type& lnstr = editor_.textbase().getline(line);
@ -1234,7 +1247,7 @@ namespace nana{ namespace widgets
void text_editor::typeface_changed()
{
impl_->capacities.behavior->pre_calc_lines(width_pixels());
_m_reset_content_size(true);
}
void text_editor::indent(bool enb, std::function<std::string()> generator)
@ -2886,10 +2899,14 @@ namespace nana{ namespace widgets
auto text_lines = textbase().lines();
if (text_lines <= max_lines)
{
impl_->capacities.behavior->prepare();
auto const width_px = _m_width_px(true);
std::size_t lines = 0;
for (std::size_t i = 0; i < text_lines; ++i)
{
impl_->capacities.behavior->pre_calc_line(i, csize.width);
impl_->capacities.behavior->pre_calc_line(i, width_px);
lines += impl_->capacities.behavior->take_lines(i);
if (lines > max_lines)