mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 17:07:34 +00:00
LibGUI+FontEditor: Restore normalized selections on Undo/Redo
Selections are always normalized when saving undo commands. The restore_selection() function reverses this process so negatively sized selections (created right-to-left) continue to resize correctly with the keyboard when restored.
This commit is contained in:
parent
02212f373b
commit
40e94a315a
3 changed files with 16 additions and 2 deletions
|
@ -811,7 +811,7 @@ void MainWidget::undo()
|
||||||
deferred_invoke([this, glyph] {
|
deferred_invoke([this, glyph] {
|
||||||
auto start = m_undo_selection->restored_start();
|
auto start = m_undo_selection->restored_start();
|
||||||
auto size = m_undo_selection->restored_size();
|
auto size = m_undo_selection->restored_size();
|
||||||
m_glyph_map_widget->set_selection(start, size, glyph);
|
m_glyph_map_widget->restore_selection(start, size, glyph);
|
||||||
m_glyph_map_widget->scroll_to_glyph(glyph);
|
m_glyph_map_widget->scroll_to_glyph(glyph);
|
||||||
m_glyph_map_widget->set_focus(true);
|
m_glyph_map_widget->set_focus(true);
|
||||||
});
|
});
|
||||||
|
@ -841,7 +841,7 @@ void MainWidget::redo()
|
||||||
deferred_invoke([this, glyph] {
|
deferred_invoke([this, glyph] {
|
||||||
auto start = m_undo_selection->restored_start();
|
auto start = m_undo_selection->restored_start();
|
||||||
auto size = m_undo_selection->restored_size();
|
auto size = m_undo_selection->restored_size();
|
||||||
m_glyph_map_widget->set_selection(start, size, glyph);
|
m_glyph_map_widget->restore_selection(start, size, glyph);
|
||||||
m_glyph_map_widget->scroll_to_glyph(glyph);
|
m_glyph_map_widget->scroll_to_glyph(glyph);
|
||||||
m_glyph_map_widget->set_focus(true);
|
m_glyph_map_widget->set_focus(true);
|
||||||
});
|
});
|
||||||
|
|
|
@ -97,6 +97,17 @@ void GlyphMapWidget::set_selection(int start, int size, Optional<u32> active_gly
|
||||||
set_active_glyph(active_glyph.value(), ShouldResetSelection::No);
|
set_active_glyph(active_glyph.value(), ShouldResetSelection::No);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void GlyphMapWidget::restore_selection(int start, int size, int active_glyph)
|
||||||
|
{
|
||||||
|
if (start == active_glyph && size > 1) {
|
||||||
|
start = active_glyph + size - 1;
|
||||||
|
size = -size + 1;
|
||||||
|
}
|
||||||
|
m_selection.set_start(start);
|
||||||
|
m_selection.set_size(size);
|
||||||
|
set_active_glyph(active_glyph, ShouldResetSelection::No);
|
||||||
|
}
|
||||||
|
|
||||||
Gfx::IntRect GlyphMapWidget::get_outer_rect(int glyph) const
|
Gfx::IntRect GlyphMapWidget::get_outer_rect(int glyph) const
|
||||||
{
|
{
|
||||||
glyph -= m_active_range.first;
|
glyph -= m_active_range.first;
|
||||||
|
|
|
@ -57,7 +57,10 @@ public:
|
||||||
|
|
||||||
void set_active_range(Unicode::CodePointRange);
|
void set_active_range(Unicode::CodePointRange);
|
||||||
void set_active_glyph(int, ShouldResetSelection = ShouldResetSelection::Yes);
|
void set_active_glyph(int, ShouldResetSelection = ShouldResetSelection::Yes);
|
||||||
|
|
||||||
void set_selection(int start, int size, Optional<u32> active_glyph = {});
|
void set_selection(int start, int size, Optional<u32> active_glyph = {});
|
||||||
|
void restore_selection(int start, int size, int active_glyph);
|
||||||
|
|
||||||
void scroll_to_glyph(int);
|
void scroll_to_glyph(int);
|
||||||
void update_glyph(int);
|
void update_glyph(int);
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue