From 5746fc33f6333d1dab1f229a98f6d716b53fdad0 Mon Sep 17 00:00:00 2001 From: Jinhao Date: Tue, 30 May 2017 10:43:10 +0800 Subject: [PATCH] fix bug of text_editor scrollbar --- source/gui/widgets/skeletons/content_view.cpp | 21 ++++++++++--------- source/gui/widgets/skeletons/content_view.hpp | 2 +- source/gui/widgets/skeletons/text_editor.cpp | 10 +++++++-- 3 files changed, 20 insertions(+), 13 deletions(-) diff --git a/source/gui/widgets/skeletons/content_view.cpp b/source/gui/widgets/skeletons/content_view.cpp index 4e92845b..8995944a 100644 --- a/source/gui/widgets/skeletons/content_view.cpp +++ b/source/gui/widgets/skeletons/content_view.cpp @@ -30,7 +30,8 @@ namespace nana { point skew_vert; nana::size extra_px; - bool enable_update{ true }; + bool passive{ true }; //The passive mode determines whether to update if scrollbar changes. It updates the client window if passive is true. + bool drag_started{ false }; point origin; @@ -171,7 +172,7 @@ namespace nana { }); } - void size_changed(bool try_update) + void size_changed(bool passive) { auto imd_area = view.view_area(); @@ -186,11 +187,11 @@ namespace nana { if (this->events.scrolled) this->events.scrolled(); - if (this->enable_update) + if (this->passive) API::refresh_window(this->window_handle); }; - this->enable_update = try_update; + this->passive = passive; if (imd_area.width != disp_area.width) { @@ -199,7 +200,7 @@ namespace nana { vert.create(window_handle); vert.events().value_changed.connect_unignorable(event_fn); API::take_active(vert, false, window_handle); - this->enable_update = false; + this->passive = false; } vert.move({ @@ -226,7 +227,7 @@ namespace nana { horz.create(window_handle); horz.events().value_changed.connect_unignorable(event_fn); API::take_active(horz, false, window_handle); - this->enable_update = false; + this->passive = false; } horz.move({ @@ -246,7 +247,7 @@ namespace nana { origin.x = 0; } - this->enable_update = true; + this->passive = true; } }; @@ -462,12 +463,12 @@ namespace nana { return (pre_origin != impl_->origin); } - void content_view::sync(bool try_update) + void content_view::sync(bool passive) { - impl_->enable_update = try_update; + impl_->passive = passive; impl_->horz.value(impl_->origin.x); impl_->vert.value(impl_->origin.y); - impl_->enable_update = true; + impl_->passive = true; } void content_view::pursue(const point& cursor) diff --git a/source/gui/widgets/skeletons/content_view.hpp b/source/gui/widgets/skeletons/content_view.hpp index ce2c60b7..9abd59a4 100644 --- a/source/gui/widgets/skeletons/content_view.hpp +++ b/source/gui/widgets/skeletons/content_view.hpp @@ -74,7 +74,7 @@ namespace skeletons /// Returns true if the origin is moved bool move_origin(const point& skew); - void sync(bool try_update); + void sync(bool passive); void pursue(const point& cursor); diff --git a/source/gui/widgets/skeletons/text_editor.cpp b/source/gui/widgets/skeletons/text_editor.cpp index dda5d25b..3129d71c 100644 --- a/source/gui/widgets/skeletons/text_editor.cpp +++ b/source/gui/widgets/skeletons/text_editor.cpp @@ -1938,13 +1938,14 @@ namespace nana{ namespace widgets impl_->undo.push(std::move(undo_ptr)); + _m_reset_content_size(true); + if(graph_) { this->_m_adjust_view(); reset_caret(); impl_->try_refresh = sync_graph::refresh; - _m_reset_content_size(true); } } @@ -3497,7 +3498,7 @@ namespace nana{ namespace widgets bool text_editor::_m_update_caret_line(std::size_t secondary_before) { - if(false == this->_m_adjust_view()) + if (false == this->_m_adjust_view()) { if (_m_caret_to_coordinate(points_.caret).x < impl_->cview->view_area().right()) { @@ -3505,6 +3506,11 @@ namespace nana{ namespace widgets return false; } } + else + { + //The content view is adjusted, now syncs it with active mode to avoid updating. + impl_->cview->sync(false); + } impl_->try_refresh = sync_graph::refresh; return true; }