base: cut copy fixes
This commit is contained in:
@@ -840,15 +840,11 @@ static bool _handle_messages() {
|
||||
}
|
||||
else if (controlDown && (ksKey == XK_c || ksKey == XK_C)) {
|
||||
XSetSelectionOwner(x11_ctx.display, CLIPBOARD, window, CurrentTime);
|
||||
char *text = iron_internal_copy_callback();
|
||||
if (text != NULL)
|
||||
iron_copy_to_clipboard(text);
|
||||
iron_internal_copy_callback();
|
||||
}
|
||||
else if (controlDown && (ksKey == XK_x || ksKey == XK_X)) {
|
||||
XSetSelectionOwner(x11_ctx.display, CLIPBOARD, window, CurrentTime);
|
||||
char *text = iron_internal_cut_callback();
|
||||
if (text != NULL)
|
||||
iron_copy_to_clipboard(text);
|
||||
iron_internal_cut_callback();
|
||||
}
|
||||
|
||||
if (event.xkey.keycode == ignoreKeycode) {
|
||||
|
||||
@@ -209,18 +209,10 @@ static bool capslock = false;
|
||||
NSString *base = [theEvent charactersIgnoringModifiers];
|
||||
unichar bc = [base length] ? [base characterAtIndex:0] : ch;
|
||||
if (bc == 'x') {
|
||||
char *text = iron_internal_cut_callback();
|
||||
if (text != NULL) {
|
||||
NSPasteboard *board = [NSPasteboard generalPasteboard];
|
||||
[board clearContents];
|
||||
[board setString:[NSString stringWithUTF8String:text] forType:NSStringPboardType];
|
||||
}
|
||||
iron_internal_cut_callback();
|
||||
}
|
||||
if (bc == 'c') {
|
||||
char *text = iron_internal_copy_callback();
|
||||
if (text != NULL) {
|
||||
iron_copy_to_clipboard(text);
|
||||
}
|
||||
iron_internal_copy_callback();
|
||||
}
|
||||
if (bc == 'v') {
|
||||
NSPasteboard *board = [NSPasteboard generalPasteboard];
|
||||
|
||||
@@ -236,6 +236,6 @@ const char *iron_internal_save_path() {
|
||||
return ".";
|
||||
}
|
||||
|
||||
// char *iron_internal_cut_callback(void);
|
||||
// char *iron_internal_copy_callback(void);
|
||||
// void iron_internal_cut_callback(void);
|
||||
// void iron_internal_copy_callback(void);
|
||||
// void iron_internal_paste_callback(char *);
|
||||
|
||||
@@ -623,27 +623,11 @@ LRESULT WINAPI IronWindowsMessageProcedure(HWND hWnd, UINT msg, WPARAM wParam, L
|
||||
#endif
|
||||
else {
|
||||
if (controlDown && keyTranslated[wParam] == KEY_CODE_X) {
|
||||
char *text = iron_internal_cut_callback();
|
||||
if (text != NULL) {
|
||||
wchar_t wtext[4096];
|
||||
MultiByteToWideChar(CP_UTF8, 0, text, -1, wtext, 4096);
|
||||
OpenClipboard(hWnd);
|
||||
EmptyClipboard();
|
||||
size_t size = (wcslen(wtext) + 1) * sizeof(wchar_t);
|
||||
HANDLE handle = GlobalAlloc(GMEM_MOVEABLE, size);
|
||||
void *data = GlobalLock(handle);
|
||||
memcpy(data, wtext, size);
|
||||
GlobalUnlock(handle);
|
||||
SetClipboardData(CF_UNICODETEXT, handle);
|
||||
CloseClipboard();
|
||||
}
|
||||
iron_internal_cut_callback();
|
||||
}
|
||||
|
||||
if (controlDown && keyTranslated[wParam] == KEY_CODE_C) {
|
||||
char *text = iron_internal_copy_callback();
|
||||
if (text != NULL) {
|
||||
iron_copy_to_clipboard(text);
|
||||
}
|
||||
iron_internal_copy_callback();
|
||||
}
|
||||
|
||||
if (controlDown && keyTranslated[wParam] == KEY_CODE_V) {
|
||||
|
||||
+4
-6
@@ -248,14 +248,12 @@ void _update() {
|
||||
gpu_present();
|
||||
}
|
||||
|
||||
char *_copy(void *data) {
|
||||
strcpy(temp_string, ui_copy());
|
||||
return temp_string;
|
||||
void _copy(void *data) {
|
||||
ui_copy();
|
||||
}
|
||||
|
||||
char *_cut(void *data) {
|
||||
strcpy(temp_string, ui_cut());
|
||||
return temp_string;
|
||||
void _cut(void *data) {
|
||||
ui_cut();
|
||||
}
|
||||
|
||||
void _paste(char *text, void *data) {
|
||||
|
||||
@@ -90,9 +90,9 @@ static void (*shutdown_callback)(void *) = NULL;
|
||||
static void *shutdown_callback_data = NULL;
|
||||
static void (*drop_files_callback)(char *, void *) = NULL;
|
||||
static void *drop_files_callback_data = NULL;
|
||||
static char *(*cut_callback)(void *) = NULL;
|
||||
static void (*cut_callback)(void *) = NULL;
|
||||
static void *cut_callback_data = NULL;
|
||||
static char *(*copy_callback)(void *) = NULL;
|
||||
static void (*copy_callback)(void *) = NULL;
|
||||
static void *copy_callback_data = NULL;
|
||||
static void (*paste_callback)(char *, void *) = NULL;
|
||||
static void *paste_callback_data = NULL;
|
||||
@@ -125,12 +125,12 @@ void iron_set_drop_files_callback(void (*callback)(char *, void *), void *data)
|
||||
drop_files_callback_data = data;
|
||||
}
|
||||
|
||||
void iron_set_cut_callback(char *(*callback)(void *), void *data) {
|
||||
void iron_set_cut_callback(void (*callback)(void *), void *data) {
|
||||
cut_callback = callback;
|
||||
cut_callback_data = data;
|
||||
}
|
||||
|
||||
void iron_set_copy_callback(char *(*callback)(void *), void *data) {
|
||||
void iron_set_copy_callback(void (*callback)(void *), void *data) {
|
||||
copy_callback = callback;
|
||||
copy_callback_data = data;
|
||||
}
|
||||
@@ -170,18 +170,16 @@ void iron_internal_drop_files_callback(char *filePath) {
|
||||
}
|
||||
}
|
||||
|
||||
char *iron_internal_cut_callback(void) {
|
||||
void iron_internal_cut_callback(void) {
|
||||
if (cut_callback != NULL) {
|
||||
return cut_callback(cut_callback_data);
|
||||
cut_callback(cut_callback_data);
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
char *iron_internal_copy_callback(void) {
|
||||
void iron_internal_copy_callback(void) {
|
||||
if (copy_callback != NULL) {
|
||||
return copy_callback(copy_callback_data);
|
||||
copy_callback(copy_callback_data);
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void iron_internal_paste_callback(char *value) {
|
||||
|
||||
@@ -112,8 +112,8 @@ void iron_set_pause_callback(void (*callback)(void *), void *data);
|
||||
void iron_set_background_callback(void (*callback)(void *), void *data);
|
||||
void iron_set_shutdown_callback(void (*callback)(void *), void *data);
|
||||
void iron_set_drop_files_callback(void (*callback)(char *, void *), void *data);
|
||||
void iron_set_cut_callback(char *(*callback)(void *), void *data);
|
||||
void iron_set_copy_callback(char *(*callback)(void *), void *data);
|
||||
void iron_set_cut_callback(void (*callback)(void *), void *data);
|
||||
void iron_set_copy_callback(void (*callback)(void *), void *data);
|
||||
void iron_set_paste_callback(void (*callback)(char *, void *), void *data);
|
||||
|
||||
bool iron_internal_frame(void);
|
||||
@@ -125,8 +125,8 @@ void iron_internal_foreground_callback(void);
|
||||
void iron_internal_background_callback(void);
|
||||
void iron_internal_shutdown_callback(void);
|
||||
void iron_internal_drop_files_callback(char *);
|
||||
char *iron_internal_cut_callback(void);
|
||||
char *iron_internal_copy_callback(void);
|
||||
void iron_internal_cut_callback(void);
|
||||
void iron_internal_copy_callback(void);
|
||||
void iron_internal_paste_callback(char *);
|
||||
|
||||
typedef enum {
|
||||
|
||||
@@ -1344,6 +1344,8 @@ void ui_update_text_edit(int align, bool editable, bool live_update) {
|
||||
strncpy(ui_text_to_copy, text + current->cursor_x, len);
|
||||
ui_text_to_copy[len] = '\0';
|
||||
}
|
||||
iron_copy_to_clipboard(ui_text_to_copy);
|
||||
ui_is_copy = false;
|
||||
}
|
||||
|
||||
if (editable && ui_is_cut) { // Cut
|
||||
@@ -2725,14 +2727,13 @@ void ui_touch_move(ui_t *ui, int index, int x, int y) {
|
||||
}
|
||||
#endif
|
||||
|
||||
char *ui_copy() {
|
||||
void ui_copy() {
|
||||
ui_is_copy = true;
|
||||
return &ui_text_to_copy[0];
|
||||
}
|
||||
|
||||
char *ui_cut() {
|
||||
void ui_cut() {
|
||||
ui_is_cut = true;
|
||||
return ui_copy();
|
||||
ui_copy();
|
||||
}
|
||||
|
||||
void ui_paste(char *s) {
|
||||
|
||||
@@ -335,8 +335,8 @@ void ui_touch_down(ui_t *ui, int index, int x, int y);
|
||||
void ui_touch_up(ui_t *ui, int index, int x, int y);
|
||||
void ui_touch_move(ui_t *ui, int index, int x, int y);
|
||||
#endif
|
||||
char *ui_copy();
|
||||
char *ui_cut();
|
||||
void ui_copy();
|
||||
void ui_cut();
|
||||
void ui_paste(char *s);
|
||||
void ui_theme_default(ui_theme_t *t);
|
||||
ui_t *ui_get_current();
|
||||
|
||||
@@ -609,6 +609,7 @@ char *ui_text_area(ui_handle_t *handle, int align, bool editable, char *label, b
|
||||
current->submit_text_handle = NULL;
|
||||
// Suppress cut / paste / select-all in ui_update_text_edit for multi-line handling
|
||||
bool _is_cut = ui_is_cut;
|
||||
bool _is_copy = ui_is_copy;
|
||||
bool _is_paste = ui_is_paste;
|
||||
bool _is_a_down = current->is_a_down;
|
||||
int _key_char = current->key_char;
|
||||
@@ -618,6 +619,7 @@ char *ui_text_area(ui_handle_t *handle, int align, bool editable, char *label, b
|
||||
bool paste_is_multiline = ui_is_paste && strchr(ui_text_to_paste, '\n') != NULL;
|
||||
if ((text_area_selection_start != -1 && text_area_selection_start != i) || paste_is_multiline) {
|
||||
ui_is_cut = false;
|
||||
ui_is_copy = false;
|
||||
ui_is_paste = false;
|
||||
// Suppress editing keys for multi-line selection, keep navigation keys active
|
||||
if (current->key_code == KEY_CODE_BACKSPACE || current->key_code == KEY_CODE_DELETE || current->key_code == KEY_CODE_RETURN ||
|
||||
@@ -640,6 +642,7 @@ char *ui_text_area(ui_handle_t *handle, int align, bool editable, char *label, b
|
||||
if ((text_area_selection_start != -1 && text_area_selection_start != i) || paste_is_multiline) {
|
||||
// Restore flags that were suppressed for multi-line handling
|
||||
ui_is_cut = _is_cut;
|
||||
ui_is_copy = _is_copy;
|
||||
ui_is_paste = _is_paste;
|
||||
current->key_code = _key_code;
|
||||
current->highlight_anchor = _highlight_anchor;
|
||||
@@ -752,6 +755,8 @@ char *ui_text_area(ui_handle_t *handle, int align, bool editable, char *label, b
|
||||
strcat(ui_text_to_copy, "\n");
|
||||
}
|
||||
}
|
||||
iron_copy_to_clipboard(ui_text_to_copy);
|
||||
ui_is_copy = false;
|
||||
}
|
||||
if (editable && (ui_is_cut || current->key_code == KEY_CODE_BACKSPACE || current->key_code == KEY_CODE_DELETE)) {
|
||||
// Delete from sel_top_col on sel_top_line to sel_bot_col on sel_bot_line
|
||||
|
||||
Reference in New Issue
Block a user