Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added TextEditor Undo and Redo support. #91

Merged
merged 1 commit into from
Jul 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions text.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -167,10 +167,18 @@ void go_fltk_TextEditor_paste(Fl_Text_Editor *e) {
Fl_Text_Editor::kf_paste(0, e);
}

void go_fltk_TextEditor_redo(Fl_Text_Editor *e) {
Fl_Text_Editor::kf_redo(0, e);
}

void go_fltk_TextEditor_select_all(Fl_Text_Editor *e) {
Fl_Text_Editor::kf_select_all(0, e);
}

void go_fltk_TextEditor_undo(Fl_Text_Editor *e) {
Fl_Text_Editor::kf_undo(0, e);
}

// --- Text Buffer ---

void modify_callback_handler(int pos, int nInserted, int nDeleted, int nRestyled, const char *deletedText, void *cbArg) {
Expand Down
15 changes: 15 additions & 0 deletions text.go
Original file line number Diff line number Diff line change
Expand Up @@ -432,22 +432,37 @@ func (t *TextEditor) Insert() {
C.go_fltk_TextEditor_insert((*C.Fl_Text_Editor)(t.ptr()))
}

// Cut cuts the selected text from the editor's buffer into the clipboard.
func (t *TextEditor) Cut() {
C.go_fltk_TextEditor_cut((*C.Fl_Text_Editor)(t.ptr()))
}

// Delete deletes the selected text from the editor's buffer.
func (t *TextEditor) Delete() {
C.go_fltk_TextEditor_delete((*C.Fl_Text_Editor)(t.ptr()))
}

// Paste pastes the clipboard's text into the editor's buffer at the
// insertion point.
func (t *TextEditor) Paste() {
C.go_fltk_TextEditor_paste((*C.Fl_Text_Editor)(t.ptr()))
}

// Redo redoes the last undone edit.
func (t *TextEditor) Redo() {
C.go_fltk_TextEditor_redo((*C.Fl_Text_Editor)(t.ptr()))
}

// SelectAll selects all the editor's text.
func (t *TextEditor) SelectAll() {
C.go_fltk_TextEditor_select_all((*C.Fl_Text_Editor)(t.ptr()))
}

// Undo undoes the last edit.
func (t *TextEditor) Undo() {
C.go_fltk_TextEditor_undo((*C.Fl_Text_Editor)(t.ptr()))
}

// NewTextEditor returns a TextEditor.
//
// Example:
Expand Down
4 changes: 3 additions & 1 deletion text.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ extern "C" {
extern void go_fltk_TextEditor_cut(Fl_Text_Editor *e);
extern void go_fltk_TextEditor_delete(Fl_Text_Editor *e);
extern void go_fltk_TextEditor_paste(Fl_Text_Editor *e);
extern void go_fltk_TextEditor_redo(Fl_Text_Editor *e);
extern void go_fltk_TextEditor_select_all(Fl_Text_Editor *e);
extern void go_fltk_TextEditor_undo(Fl_Text_Editor *e);

extern GText_Display *go_fltk_new_TextDisplay(int x, int y, int w, int h, const char *text);
extern void go_fltk_TextDisplay_set_buffer(Fl_Text_Display *d, Fl_Text_Buffer *buf);
Expand All @@ -30,7 +32,7 @@ extern "C" {
extern int go_fltk_TextDisplay_move_up(Fl_Text_Display *d);
extern int go_fltk_TextDisplay_move_down(Fl_Text_Display *d);
extern void go_fltk_TextDisplay_show_insert_position(Fl_Text_Display *d);
extern void go_fltk_TextDisplay_hide_cursor(Fl_Text_Display *d);
extern void go_fltk_TextDisplay_hide_cursor(Fl_Text_Display *d);
extern unsigned int go_fltk_TextDisplay_text_color(Fl_Text_Display *d);
extern void go_fltk_TextDisplay_set_text_color(Fl_Text_Display* d, unsigned int color);
extern int go_fltk_TextDisplay_text_font(Fl_Text_Display *d);
Expand Down