fix bug of text_editor scrollbar

This commit is contained in:
Jinhao 2017-05-30 10:43:10 +08:00
parent 2f21c33392
commit 5746fc33f6
3 changed files with 20 additions and 13 deletions

View File

@ -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)

View File

@ -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);

View File

@ -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;
}