Skip to content

Commit

Permalink
scintilla_get_clipboard() now returns a copy of clipboard text dire…
Browse files Browse the repository at this point in the history
…ctly.

The function no longer mimics the Scintilla API for stringresult for the sake
of convenience.
  • Loading branch information
orbitalquark committed Jul 23, 2020
1 parent b1fcddf commit 0bc59c0
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 20 deletions.
24 changes: 13 additions & 11 deletions ScintillaCurses.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -1416,19 +1416,21 @@ class ScintillaCurses : public ScintillaBase {
}
}
/**
* Copies the text of the internal clipboard, not the primary and/or secondary
* X selections, into the given buffer and returns the size of the clipboard
* text.
* @param text The buffer to copy clipboard text to.
* @return size of the clipboard text
* Returns a NUL-terminated copy of the text on the internal clipboard, not
* the primary and/or secondary X selections.
* The caller is responsible for `free`ing the returned text.
* @param len An optional pointer to store the length of the returned text in.
* @return clipboard text
*/
int GetClipboard(char *buffer) {
if (buffer) memcpy(buffer, clipboard.Data(), clipboard.Length() + 1);
return clipboard.Length() + 1;
char *GetClipboard(int *len) {
if (len) *len = clipboard.Length();
char *text = new char[clipboard.Length() + 1];
memcpy(text, clipboard.Data(), clipboard.Length() + 1);
return text;
}
};

// Link with C. Documentation in Scintilla.h.
// Link with C. Documentation in ScintillaCurses.h.
extern "C" {
void *scintilla_new(
void (*callback)(void *, int, SCNotification *, void *), void *userdata)
Expand Down Expand Up @@ -1468,8 +1470,8 @@ bool scintilla_send_mouse(
return (scicurses->MouseRelease(time, y, x, ctrl), true);
return false;
}
int scintilla_get_clipboard(void *sci, char *buffer) {
return reinterpret_cast<ScintillaCurses *>(sci)->GetClipboard(buffer);
char *scintilla_get_clipboard(void *sci, int *len) {
return reinterpret_cast<ScintillaCurses *>(sci)->GetClipboard(len);
}
void scintilla_noutrefresh(void *sci) {
reinterpret_cast<ScintillaCurses *>(sci)->NoutRefresh();
Expand Down
16 changes: 7 additions & 9 deletions ScintillaCurses.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,18 +69,16 @@ bool scintilla_send_mouse(
void *sci, int event, unsigned int time, int button, int y, int x, bool shift,
bool ctrl, bool alt);
/**
* Copies the text of Scintilla's internal clipboard, not the primary and/or
* secondary X selections, into the given buffer and returns the size of the
* clipboard text.
* Call with a `null` buffer first to get the size of the buffer needed to store
* clipboard text.
* Keep in mind clipboard text may contain null bytes.
* Returns a NUL-terminated copy of the text on Scintilla's internal clipboard,
* not the primary and/or secondary X selections.
* The caller is responsible for `free`ing the returned text.
* Keep in mind clipboard text may contain NUL bytes.
* Curses does not have to be initialized before calling this function.
* @param sci The Scintilla window returned by `scintilla_new()`.
* @param buffer The buffer to copy clipboard text to.
* @return size of the clipboard text.
* @param len An optional pointer to store the length of the returned text in.
* @return the clipboard text.
*/
int scintilla_get_clipboard(void *sci, char *buffer);
char *scintilla_get_clipboard(void *sci, int *len);
/**
* Refreshes the Scintilla window on the virtual screen.
* This should be done along with the normal curses `noutrefresh()`, as the
Expand Down

0 comments on commit 0bc59c0

Please sign in to comment.