Skip to content

Commit

Permalink
Merge pull request #91 from mark-summerfield/main
Browse files Browse the repository at this point in the history
Added TextEditor Undo and Redo support.
  • Loading branch information
pwiecz committed Jul 2, 2023
2 parents 30e3dbc + 73d7cbf commit 3291a88
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 1 deletion.
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

0 comments on commit 3291a88

Please sign in to comment.