From cf4ddd1dcf9fa9762aeae5e984b6295e82716d10 Mon Sep 17 00:00:00 2001 From: thankyouverycool <66646555+thankyouverycool@users.noreply.github.com> Date: Wed, 10 May 2023 17:01:01 -0400 Subject: [PATCH] FontEditor: Move common restoration work into restore_state() --- .../Applications/FontEditor/MainWidget.cpp | 42 ++++++------------- Userland/Applications/FontEditor/MainWidget.h | 1 + 2 files changed, 14 insertions(+), 29 deletions(-) diff --git a/Userland/Applications/FontEditor/MainWidget.cpp b/Userland/Applications/FontEditor/MainWidget.cpp index deb7b4e133..8195a8f202 100644 --- a/Userland/Applications/FontEditor/MainWidget.cpp +++ b/Userland/Applications/FontEditor/MainWidget.cpp @@ -803,12 +803,8 @@ void MainWidget::reset_selection_and_push_undo() push_undo(); } -void MainWidget::undo() +void MainWidget::restore_state() { - if (!m_undo_stack->can_undo()) - return; - m_undo_stack->undo(); - auto glyph = m_undo_selection->restored_active_glyph(); auto glyph_width = m_font->raw_glyph_width(glyph); if (glyph < m_range.first || glyph > m_range.last) @@ -820,43 +816,31 @@ void MainWidget::undo() m_glyph_map_widget->scroll_to_glyph(glyph); m_glyph_map_widget->set_focus(true); - if (m_font->is_fixed_width()) { + if (m_font->is_fixed_width()) m_glyph_editor_present_checkbox->set_checked(glyph_width > 0, GUI::AllowCallback::No); - } else { + else m_glyph_editor_width_spinbox->set_value(glyph_width, GUI::AllowCallback::No); - } + m_glyph_editor_widget->update(); m_glyph_map_widget->update(); update_preview(); update_statusbar(); } +void MainWidget::undo() +{ + if (!m_undo_stack->can_undo()) + return; + m_undo_stack->undo(); + restore_state(); +} + void MainWidget::redo() { if (!m_undo_stack->can_redo()) return; m_undo_stack->redo(); - - auto glyph = m_undo_selection->restored_active_glyph(); - auto glyph_width = m_font->raw_glyph_width(glyph); - if (glyph < m_range.first || glyph > m_range.last) - m_search_textbox->set_text(""sv); - - auto start = m_undo_selection->restored_start(); - auto size = m_undo_selection->restored_size(); - m_glyph_map_widget->restore_selection(start, size, glyph); - m_glyph_map_widget->scroll_to_glyph(glyph); - m_glyph_map_widget->set_focus(true); - - if (m_font->is_fixed_width()) { - m_glyph_editor_present_checkbox->set_checked(glyph_width > 0, GUI::AllowCallback::No); - } else { - m_glyph_editor_width_spinbox->set_value(glyph_width, GUI::AllowCallback::No); - } - m_glyph_editor_widget->update(); - m_glyph_map_widget->update(); - update_preview(); - update_statusbar(); + restore_state(); } bool MainWidget::request_close() diff --git a/Userland/Applications/FontEditor/MainWidget.h b/Userland/Applications/FontEditor/MainWidget.h index 273ee5369f..ad9d521c72 100644 --- a/Userland/Applications/FontEditor/MainWidget.h +++ b/Userland/Applications/FontEditor/MainWidget.h @@ -53,6 +53,7 @@ private: void undo(); void redo(); + void restore_state(); void did_modify_font(); void update_statusbar();