diff options
| author | Matthias Melcher <github@matthiasm.com> | 2023-02-10 17:13:20 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-02-10 17:13:20 +0100 |
| commit | 7f87c847ba8ec976c6ad345942f9867658a89ab2 (patch) | |
| tree | 00717f3197ea9d2d76c45207dd4f468b2ee201cb /src/Fl_Text_Editor.cxx | |
| parent | 72f860438170638d6aa492b477a59ff88b565d9d (diff) | |
Unlimited undo/redo for Fl_Input_ and Fl_Text_Buffer (#558) (#676)
Diffstat (limited to 'src/Fl_Text_Editor.cxx')
| -rw-r--r-- | src/Fl_Text_Editor.cxx | 30 |
1 files changed, 24 insertions, 6 deletions
diff --git a/src/Fl_Text_Editor.cxx b/src/Fl_Text_Editor.cxx index 81dc2f441..c548ef6be 100644 --- a/src/Fl_Text_Editor.cxx +++ b/src/Fl_Text_Editor.cxx @@ -1,5 +1,5 @@ // -// Copyright 2001-2018 by Bill Spitzak and others. +// Copyright 2001-2023 by Bill Spitzak and others. // // Original code Copyright Mark Edel. Permission to distribute under // the LGPL for the FLTK library granted by Mark Edel. @@ -132,7 +132,9 @@ static struct { { FL_Page_Down, FL_CTRL|FL_SHIFT, Fl_Text_Editor::kf_c_s_move }, //{ FL_Clear, 0, Fl_Text_Editor::delete_to_eol }, { 'z', FL_CTRL, Fl_Text_Editor::kf_undo }, - { '/', FL_CTRL, Fl_Text_Editor::kf_undo }, + { 'z', FL_CTRL|FL_SHIFT, Fl_Text_Editor::kf_redo }, // MSWindows screen driver also defines Ctrl-Y + { '/', FL_CTRL, Fl_Text_Editor::kf_undo }, // Emacs + { '?', FL_CTRL, Fl_Text_Editor::kf_redo }, // Emacs { 'x', FL_CTRL, Fl_Text_Editor::kf_cut }, { FL_Delete, FL_SHIFT, Fl_Text_Editor::kf_cut }, { 'c', FL_CTRL, Fl_Text_Editor::kf_copy }, @@ -596,13 +598,13 @@ int Fl_Text_Editor::kf_select_all(int, Fl_Text_Editor* e) { } /** Undo last edit in the current buffer of editor \p 'e'. - Also deselects previous selection. - The key value \p 'c' is currently unused. -*/ + Also deselects previous selection. + The key value \p 'c' is currently unused. + */ int Fl_Text_Editor::kf_undo(int , Fl_Text_Editor* e) { e->buffer()->unselect(); Fl::copy("", 0, 0); - int crsr; + int crsr = e->insert_position(); int ret = e->buffer()->undo(&crsr); e->insert_position(crsr); e->show_insert_position(); @@ -611,6 +613,22 @@ int Fl_Text_Editor::kf_undo(int , Fl_Text_Editor* e) { return ret; } +/** Redo last undo action. + Also deselects previous selection. + The key value \p 'c' is currently unused. + */ +int Fl_Text_Editor::kf_redo(int , Fl_Text_Editor* e) { + e->buffer()->unselect(); + Fl::copy("", 0, 0); + int crsr = e->insert_position(); + int ret = e->buffer()->redo(&crsr); + e->insert_position(crsr); + e->show_insert_position(); + e->set_changed(); + if (e->when()&FL_WHEN_CHANGED) e->do_callback(); + return ret; +} + /** Handles a key press in the editor */ int Fl_Text_Editor::handle_key() { // Call FLTK's rules to try to turn this into a printing character. |
