17
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-10-26 15:54:53 +01:00

fix(editor): Esc takes back what a drag did

Esc in the middle of dragging a point of a track kept the moved point,
and the hint said so; dragging a straight was taken back but left an
empty step in the history; a vertex or the radius grip of a curve stayed
moved in the design. Now Esc puts back what was there before the drag in
all three, and the history doesn't keep a step for it.
This commit is contained in:
maj00r
2026-10-21 11:09:06 +02:00
parent 7da0432dca
commit ddde8d12d9
6 changed files with 33 additions and 2 deletions

View File

@@ -973,6 +973,16 @@ void editor_mode::undo_last()
}
}
void editor_mode::drop_step(std::size_t const Step)
{
if (Step == 0 || m_history.size() != Step)
return;
auto const redo{g_redo.size()};
undo_one();
if (g_redo.size() > redo)
g_redo.erase(g_redo.begin() + redo, g_redo.end());
}
void editor_mode::undo_one()
{
if (m_history.empty())

View File

@@ -174,6 +174,7 @@ class editor_mode : public application_mode, private editor_track::observer, pri
void redo_last();
// a single step of the history, see undo_last()
void undo_one();
void drop_step(std::size_t const Step);
void redo_one();
// the changes of the heightmap terrain since the last step become a step of the history: a stroke of the brush,
// or what a frame did; the next change is recorded from now on
@@ -984,6 +985,7 @@ class editor_mode : public application_mode, private editor_track::observer, pri
bool fit_has_before{false};
bool fit_has_after{false};
std::vector<std::pair<TTrack *, editor_track::state>> drag_states;
std::size_t drag_step{0};
glm::dvec3 preview_start{0.0};
glm::dvec3 preview_end{0.0};
glm::dvec3 edit_start{0.0};
@@ -1551,6 +1553,7 @@ class editor_mode : public application_mode, private editor_track::observer, pri
bool moved{false};
glm::vec2 from{0.f};
double height{0.0};
std::size_t step{0};
};
point_drag m_point_drag;
struct handle_drag
@@ -2258,6 +2261,7 @@ class editor_mode : public application_mode, private editor_track::observer, pri
void draw_infra_overlay() const;
bool m_route_dragging{false};
alignment::design m_route_drag_from;
float m_track_snap_radius{1.0f};
bool m_track_align_tangent{true};
bool m_track_drag_connected{true};

View File

@@ -351,6 +351,7 @@ void editor_mode::point_drag_update()
for (auto *dragged : m_track_drag)
states.emplace_back(dragged, editor_track::capture(*dragged));
push_track_snapshot(std::move(states));
drag.step = m_history.size();
records_watch_begin();
}
screen_projection const projection;

View File

@@ -1102,6 +1102,8 @@ void editor_mode::render_route_gizmo()
}
return;
}
if (false == m_route_dragging)
m_route_drag_from = route.design;
m_route_dragging = true;
if (grip)
{

View File

@@ -638,6 +638,7 @@ void editor_mode::render_straight_gizmo()
if (false == state.fitting)
{
push_track_snapshot(state.drag_states);
state.drag_step = m_history.size();
m_track_drag = tracks;
}
}
@@ -731,6 +732,7 @@ void editor_mode::cancel_track_tools()
m_track_dirty = true;
commit_track_drag(true);
m_track_drag.clear();
drop_step(state.drag_step);
}
state.dragging = false;
state.fitting = false;
@@ -743,10 +745,22 @@ void editor_mode::cancel_track_tools()
m_signal.placing = false;
m_signal.moving = false;
m_handle_drag = {};
if (m_route_dragging)
{
m_route_dragging = false;
m_route.design = m_route_drag_from;
route_update();
}
if (m_point_drag.active)
{
auto const step{m_point_drag.moved ? m_point_drag.step : 0};
m_track_snap = {};
point_drag_finish();
m_record_watch = {};
m_point_drag = {};
m_track_drag.clear();
m_track_drag_points.clear();
m_track_joints.clear();
drop_step(step);
}
if (m_switch.placing)
{

View File

@@ -1695,7 +1695,7 @@ std::vector<editor_mode::key_hint> editor_mode::track_key_hints(bool const All)
gizmo = true;
}
else if (m_point_drag.moved)
hints = {{"Drag", "moves the point, level"}, {"Over a free end", "the end joins it"}, {"Release", "done"}, {"Esc", "done"}};
hints = {{"Drag", "moves the point, level"}, {"Over a free end", "the end joins it"}, {"Release", "done"}, {"Esc", "cancel"}};
else if (m_track_point.valid())
{
char const *action{"moves the point along the axes"};