From d0f217fbac0c8a3d7f8c3bccab6e03c1cbae5581 Mon Sep 17 00:00:00 2001 From: Jinhao Date: Sun, 26 Mar 2017 04:56:43 +0800 Subject: [PATCH] fix bug that didn't reset text_editor content offset(#193) --- source/gui/widgets/skeletons/text_editor.cpp | 21 ++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/source/gui/widgets/skeletons/text_editor.cpp b/source/gui/widgets/skeletons/text_editor.cpp index 0a697979..a6c750e6 100644 --- a/source/gui/widgets/skeletons/text_editor.cpp +++ b/source/gui/widgets/skeletons/text_editor.cpp @@ -1661,6 +1661,27 @@ namespace nana{ namespace widgets impl_->counterpart.buffer.make(r.dimension()); impl_->capacities.behavior->pre_calc_lines(width_pixels()); + + if (points_.offset.x > 0) + { + auto maxline = textbase().max_line(); + nana::size text_size = _m_text_extent_size(textbase().getline(maxline.first).c_str(), maxline.second); + + text_size.width += 1; + + points_.offset.x = (std::max)(0, + static_cast(text_size.width + 1) - static_cast(this->width_pixels()) + ); + } + + if (points_.offset.y > 0) + { + auto const lines = impl_->capacities.behavior->take_lines(); + auto const scr_lines = this->screen_lines(); + + _m_offset_y((std::max)(static_cast(lines)-static_cast(scr_lines), 0)); + } + _m_scrollbar(); move_caret(points_.caret);