Fix launcher clipboard pasting not respecting caret position, fixes #586 (Thanks igor725)

This commit is contained in:
UnknownShadow200 2019-05-26 20:25:47 +10:00
parent 2ee398b0a3
commit 855ab96aaa
4 changed files with 30 additions and 22 deletions

View File

@ -455,9 +455,7 @@ void LInput_SetText(struct LInput* w, const String* text_) {
w->_TextHeight = size.Height;
}
bool LInput_Append(struct LInput* w, char c) {
if (w->TextFilter && !w->TextFilter(c)) return false;
static CC_NOINLINE bool LInput_AppendRaw(struct LInput* w, char c) {
if (c >= ' ' && c <= '~' && c != '&' && w->Text.length < w->Text.capacity) {
if (w->CaretPos == -1) {
String_Append(&w->Text, c);
@ -465,12 +463,26 @@ bool LInput_Append(struct LInput* w, char c) {
String_InsertAt(&w->Text, w->CaretPos, c);
w->CaretPos++;
}
if (w->TextChanged) w->TextChanged(w);
return true;
}
return false;
}
bool LInput_Append(struct LInput* w, char c) {
bool appended = LInput_AppendRaw(w, c);
if (appended && w->TextChanged) w->TextChanged(w);
return appended;
}
static void LInput_AppendString(struct LInput* w, const String* str) {
int i, appended = 0;
for (i = 0; i < str->length; i++) {
if (LInput_AppendRaw(w, str->buffer[i])) appended++;
}
if (appended && w->TextChanged) w->TextChanged(w);
}
bool LInput_Backspace(struct LInput* w) {
if (w->Text.length == 0 || w->CaretPos == 0) return false;
@ -519,8 +531,7 @@ bool LInput_CopyFromClipboard(struct LInput* w) {
if (!text.length) return false;
if (w->ClipboardFilter) w->ClipboardFilter(&text);
String_AppendString(&w->Text, &text);
if (w->TextChanged) w->TextChanged(w);
LInput_AppendString(w, &text);
return true;
}

View File

@ -71,8 +71,6 @@ struct LInput {
void (*ClipboardFilter)(String* str);
/* Callback invoked when the text is changed. Can be NULL. */
void (*TextChanged)(struct LInput* w);
/* Filter that only lets certain characters be entered. Can be NULL. */
bool (*TextFilter)(char c);
/* Specifies the position that characters are inserted/deleted from. */
/* NOTE: -1 to insert/delete characters at end of the text. */
int CaretPos;

View File

@ -842,8 +842,8 @@ struct FontData {
FT_StreamRec stream;
uint8_t buffer[8192]; /* small buffer to minimise disk I/O */
uint16_t widths[256]; /* cached width of each character glyph */
FT_Glyph glyphs[256]; /* cached glyphs */
FT_Glyph shadow_glyphs[256]; /* cached glyphs (for back layer shadow) */
FT_BitmapGlyph glyphs[256]; /* cached glyphs */
FT_BitmapGlyph shadow_glyphs[256]; /* cached glyphs (for back layer shadow) */
#ifdef CC_BUILD_OSX
char filename[FILENAME_SIZE + 1];
#endif
@ -871,11 +871,11 @@ static void FontData_Free(struct FontData* font) {
for (i = 0; i < 256; i++) {
if (!font->glyphs[i]) continue;
FT_Done_Glyph(font->glyphs[i]);
FT_Done_Glyph((FT_Glyph)font->glyphs[i]);
}
for (i = 0; i < 256; i++) {
if (!font->shadow_glyphs[i]) continue;
FT_Done_Glyph(font->shadow_glyphs[i]);
FT_Done_Glyph((FT_Glyph)font->shadow_glyphs[i]);
}
}
@ -1165,9 +1165,10 @@ static void Platform_BlackWhiteGlyph(FT_Bitmap* img, Bitmap* bmp, int x, int y,
int Platform_TextDraw(struct DrawTextArgs* args, Bitmap* bmp, int x, int y, BitmapCol col, bool shadow) {
struct FontData* data = (struct FontData*)args->Font.Handle;
FT_BitmapGlyph* glyphs = data->glyphs;
FT_Face face = data->face;
String text = args->Text;
FT_Glyph* glyphs = data->glyphs;
int descender, height, begX = x;
/* glyph state */
@ -1197,7 +1198,8 @@ int Platform_TextDraw(struct DrawTextArgs* args, Bitmap* bmp, int x, int y, Bitm
continue;
}
FT_Get_Glyph(face->glyph, &glyph); /* TODO: Check error */
/* due to FT_LOAD_RENDER, glyph is always a bitmap one */
FT_Get_Glyph(face->glyph, (FT_Glyph)&glyph); /* TODO: Check error */
glyphs[(uint8_t)text.buffer[i]] = glyph;
}

View File

@ -738,11 +738,8 @@ void Window_DisableRawMouse(void) {
static Display* win_display;
static int win_screen;
static Window win_rootWin;
static Window win_handle;
static Window win_rootWin, win_handle;
static XVisualInfo win_visual;
static int borderLeft, borderRight, borderTop, borderBottom;
static Atom wm_destroy, net_wm_state;
static Atom net_wm_state_minimized;
@ -751,7 +748,7 @@ static Atom net_wm_state_maximized_horizontal;
static Atom net_wm_state_maximized_vertical;
static Atom xa_clipboard, xa_targets, xa_utf8_string, xa_data_sel;
static Atom xa_atom = 4, xa_cardinal = 6;
static Atom xa_atom = 4;
static long win_eventMask;