Skip to content

Commit

Permalink
fixed regression vertical scroll and cursor position of previous node…
Browse files Browse the repository at this point in the history
…s not remembered (#2460)
  • Loading branch information
giuspen committed Mar 23, 2024
1 parent 5d805d8 commit b7a8b37
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions src/ct/ct_main_win_events.cc
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,18 @@ void CtMainWin::_on_treeview_cursor_changed()
if (prevNodeId == nodeId) {
return;
}
const gint64 prevNodeIdDataHolder = _prevTreeIter.get_node_id_data_holder();
Glib::RefPtr<Gsv::Buffer> rTextBuffer = _prevTreeIter.get_node_text_buffer();
if (rTextBuffer->get_modified()) {
_fileSaveNeeded = true;
rTextBuffer->set_modified(false);
_ctStateMachine.update_state(_prevTreeIter);
}
_nodesCursorPos[nodeIdDataHolder] = rTextBuffer->property_cursor_position();
_nodesVScrollPos[nodeIdDataHolder] = round(_scrolledwindowText.get_vadjustment()->get_value());
const int scr = round(_scrolledwindowText.get_vadjustment()->get_value());
const int cur = rTextBuffer->property_cursor_position();
_nodesVScrollPos[prevNodeIdDataHolder] = scr;
_nodesCursorPos[prevNodeIdDataHolder] = cur;
//spdlog::debug("W[{}] scr={}, cur={}", prevNodeIdDataHolder, scr, cur);
}

Glib::RefPtr<Gsv::Buffer> rTextBuffer = treeIter.get_node_text_buffer();
Expand All @@ -61,9 +65,15 @@ void CtMainWin::_on_treeview_cursor_changed()
_uCtTreestore->text_view_apply_textbuffer(treeIter, &_ctTextview);

if (user_active()) {
auto mapIter = _nodesCursorPos.find(nodeIdDataHolder);
if (mapIter != _nodesCursorPos.end() and mapIter->second > 0) {
text_view_apply_cursor_position(treeIter, mapIter->second, _nodesVScrollPos.at(nodeIdDataHolder));
auto mapScrIter = _nodesVScrollPos.find(nodeIdDataHolder);
auto mapCurIter = _nodesCursorPos.find(nodeIdDataHolder);
if (mapScrIter != _nodesVScrollPos.end() and
mapCurIter != _nodesCursorPos.end() and mapCurIter->second > 0)
{
const int scr = mapScrIter->second;
const int cur = mapCurIter->second;
text_view_apply_cursor_position(treeIter, cur, scr);
//spdlog::debug("R[{}] scr={}, cur={}", nodeIdDataHolder, scr, cur);
}
else {
text_view_apply_cursor_position(treeIter, 0, 0);
Expand Down

0 comments on commit b7a8b37

Please sign in to comment.