editor: Use window->add_keyboard_shortcut to handle Ctrl+S
Some checks failed
Build and test / build (push) Failing after 13m5s

This commit is contained in:
apio 2024-04-15 19:34:09 +02:00
parent 2f56a52489
commit 69f3e28f2c
Signed by: apio
GPG Key ID: B8A7D06E42258954
3 changed files with 13 additions and 18 deletions

View File

@ -98,24 +98,6 @@ Result<ui::EventResult> EditorWidget::handle_key_event(const ui::KeyEventRequest
return ui::EventResult::DidHandle;
}
if (request.modifiers & ui::Mod_Ctrl)
{
switch (request.key)
{
case 's': {
auto result = save_file();
if (result.has_error())
{
os::eprintln("editor: failed to save file: %s", result.error_string());
return ui::EventResult::DidNotHandle;
}
os::println("editor: buffer saved to %s successfully", m_path.name().chars());
return ui::EventResult::DidNotHandle;
}
default: return ui::EventResult::DidNotHandle;
}
}
if (request.code == moon::K_Backspace)
{
if (m_cursor == 0) return ui::EventResult::DidNotHandle;

View File

@ -26,6 +26,11 @@ class EditorWidget : public ui::TextInput
Result<void> draw(ui::Canvas& canvas) override;
os::Path& path()
{
return m_path;
}
private:
SharedPtr<ui::Font> m_font;

View File

@ -9,6 +9,7 @@
#include "EditorWidget.h"
#include <os/ArgumentParser.h>
#include <os/File.h>
#include <ui/App.h>
Result<int> luna_main(int argc, char** argv)
@ -33,6 +34,13 @@ Result<int> luna_main(int argc, char** argv)
window->set_main_widget(*editor);
if (!path.is_empty()) TRY(editor->load_file(path));
TRY(window->add_keyboard_shortcut({ moon::K_CH26, ui::Mod_Ctrl }, true, [&](ui::Shortcut) {
auto result = editor->save_file();
if (result.has_error()) os::eprintln("editor: failed to save file: %s", result.error_string());
else
os::println("editor: buffer saved to %s successfully", editor->path().name().chars());
}));
window->draw();
return app.run();