mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-06-11 10:18:15 +09:00
HackStudio+TextEditor: Persist EditingEngineType across editors
Persist EditingEngine mode in HackStudio and TextEditor when opening new files or editing splits. Previously, the EditingEngine defaulted to a RegularEditingEngine for a new Editor, even if Vim Emulation had been selected in the existing Editor.
This commit is contained in:
parent
fa94978a7e
commit
8d0143a380
Notes:
sideshowbarker
2024-07-19 17:11:50 +09:00
Author: https://github.com/sfrieds3
Commit: 8d0143a380
Pull-request: https://github.com/SerenityOS/serenity/pull/11194
2 changed files with 26 additions and 6 deletions
|
@ -54,7 +54,12 @@ MainWidget::MainWidget()
|
||||||
m_editor = *find_descendant_of_type_named<GUI::TextEditor>("editor");
|
m_editor = *find_descendant_of_type_named<GUI::TextEditor>("editor");
|
||||||
m_editor->set_ruler_visible(true);
|
m_editor->set_ruler_visible(true);
|
||||||
m_editor->set_automatic_indentation_enabled(true);
|
m_editor->set_automatic_indentation_enabled(true);
|
||||||
m_editor->set_editing_engine(make<GUI::RegularEditingEngine>());
|
if (m_editor->editing_engine()->is_regular())
|
||||||
|
m_editor->set_editing_engine(make<GUI::RegularEditingEngine>());
|
||||||
|
else if (m_editor->editing_engine()->is_vim())
|
||||||
|
m_editor->set_editing_engine(make<GUI::VimEditingEngine>());
|
||||||
|
else
|
||||||
|
VERIFY_NOT_REACHED();
|
||||||
|
|
||||||
m_editor->on_change = [this] {
|
m_editor->on_change = [this] {
|
||||||
update_preview();
|
update_preview();
|
||||||
|
|
|
@ -293,7 +293,12 @@ bool HackStudioWidget::open_file(const String& full_filename, size_t line, size_
|
||||||
}
|
}
|
||||||
current_editor().horizontal_scrollbar().set_value(new_project_file->horizontal_scroll_value());
|
current_editor().horizontal_scrollbar().set_value(new_project_file->horizontal_scroll_value());
|
||||||
current_editor().vertical_scrollbar().set_value(new_project_file->vertical_scroll_value());
|
current_editor().vertical_scrollbar().set_value(new_project_file->vertical_scroll_value());
|
||||||
current_editor().set_editing_engine(make<GUI::RegularEditingEngine>());
|
if (current_editor().editing_engine()->is_regular())
|
||||||
|
current_editor().set_editing_engine(make<GUI::RegularEditingEngine>());
|
||||||
|
else if (current_editor().editing_engine()->is_vim())
|
||||||
|
current_editor().set_editing_engine(make<GUI::VimEditingEngine>());
|
||||||
|
else
|
||||||
|
VERIFY_NOT_REACHED();
|
||||||
|
|
||||||
set_edit_mode(EditMode::Text);
|
set_edit_mode(EditMode::Text);
|
||||||
|
|
||||||
|
@ -587,6 +592,7 @@ void HackStudioWidget::add_new_editor(GUI::Widget& parent)
|
||||||
} else {
|
} else {
|
||||||
parent.add_child(wrapper);
|
parent.add_child(wrapper);
|
||||||
}
|
}
|
||||||
|
auto previous_editor_wrapper = m_current_editor_wrapper;
|
||||||
m_current_editor_wrapper = wrapper;
|
m_current_editor_wrapper = wrapper;
|
||||||
m_all_editor_wrappers.append(wrapper);
|
m_all_editor_wrappers.append(wrapper);
|
||||||
wrapper->editor().set_focus(true);
|
wrapper->editor().set_focus(true);
|
||||||
|
@ -595,6 +601,12 @@ void HackStudioWidget::add_new_editor(GUI::Widget& parent)
|
||||||
wrapper->editor().on_cursor_change = [this] { on_cursor_change(); };
|
wrapper->editor().on_cursor_change = [this] { on_cursor_change(); };
|
||||||
wrapper->on_change = [this] { update_gml_preview(); };
|
wrapper->on_change = [this] { update_gml_preview(); };
|
||||||
set_edit_mode(EditMode::Text);
|
set_edit_mode(EditMode::Text);
|
||||||
|
if (previous_editor_wrapper && previous_editor_wrapper->editor().editing_engine()->is_regular())
|
||||||
|
wrapper->editor().set_editing_engine(make<GUI::RegularEditingEngine>());
|
||||||
|
else if (previous_editor_wrapper && previous_editor_wrapper->editor().editing_engine()->is_vim())
|
||||||
|
wrapper->editor().set_editing_engine(make<GUI::VimEditingEngine>());
|
||||||
|
else
|
||||||
|
wrapper->editor().set_editing_engine(make<GUI::RegularEditingEngine>());
|
||||||
}
|
}
|
||||||
|
|
||||||
NonnullRefPtr<GUI::Action> HackStudioWidget::create_switch_to_next_editor_action()
|
NonnullRefPtr<GUI::Action> HackStudioWidget::create_switch_to_next_editor_action()
|
||||||
|
@ -1148,10 +1160,13 @@ void HackStudioWidget::create_edit_menu(GUI::Window& window)
|
||||||
edit_menu.add_separator();
|
edit_menu.add_separator();
|
||||||
|
|
||||||
auto vim_emulation_setting_action = GUI::Action::create_checkable("&Vim Emulation", { Mod_Ctrl | Mod_Shift | Mod_Alt, Key_V }, [this](auto& action) {
|
auto vim_emulation_setting_action = GUI::Action::create_checkable("&Vim Emulation", { Mod_Ctrl | Mod_Shift | Mod_Alt, Key_V }, [this](auto& action) {
|
||||||
if (action.is_checked())
|
if (action.is_checked()) {
|
||||||
current_editor().set_editing_engine(make<GUI::VimEditingEngine>());
|
for (auto& editor_wrapper : m_all_editor_wrappers)
|
||||||
else
|
editor_wrapper.editor().set_editing_engine(make<GUI::VimEditingEngine>());
|
||||||
current_editor().set_editing_engine(make<GUI::RegularEditingEngine>());
|
} else {
|
||||||
|
for (auto& editor_wrapper : m_all_editor_wrappers)
|
||||||
|
editor_wrapper.editor().set_editing_engine(make<GUI::RegularEditingEngine>());
|
||||||
|
}
|
||||||
});
|
});
|
||||||
vim_emulation_setting_action->set_checked(false);
|
vim_emulation_setting_action->set_checked(false);
|
||||||
edit_menu.add_action(vim_emulation_setting_action);
|
edit_menu.add_action(vim_emulation_setting_action);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue