Fix pasting text into chat input in web client not properly moving up chat log when pased text wraps over end of one line

This commit is contained in:
UnknownShadow200 2020-02-16 23:32:31 +11:00
parent 579e1bea2e
commit 0c30388670
3 changed files with 16 additions and 10 deletions

View File

@ -405,6 +405,10 @@ static void ChatScreen_UpdateChatYOffsets(struct ChatScreen* s) {
Widget_Layout(&s->chat); Widget_Layout(&s->chat);
} }
static void ChatScreen_OnInputTextChanged(void* elem) {
ChatScreen_UpdateChatYOffsets(Gui_Chat);
}
static String ChatScreen_GetChat(void* obj, int i) { static String ChatScreen_GetChat(void* obj, int i) {
i += ChatScreen_Instance.chatIndex; i += ChatScreen_Instance.chatIndex;
@ -749,7 +753,6 @@ static int ChatScreen_KeyPress(void* screen, char keyChar) {
} }
InputWidget_Append(&s->input.base, keyChar); InputWidget_Append(&s->input.base, keyChar);
ChatScreen_UpdateChatYOffsets(s);
return true; return true;
} }
@ -759,7 +762,6 @@ static int ChatScreen_TextChanged(void* screen, const String* str) {
if (!s->grabsInput) return false; if (!s->grabsInput) return false;
InputWidget_SetText(&s->input.base, str); InputWidget_SetText(&s->input.base, str);
ChatScreen_UpdateChatYOffsets(s);
#endif #endif
return true; return true;
} }
@ -794,7 +796,6 @@ static int ChatScreen_KeyDown(void* screen, int key) {
ChatScreen_ScrollChatBy(s, +Gui_Chatlines); ChatScreen_ScrollChatBy(s, +Gui_Chatlines);
} else { } else {
Elem_HandlesKeyDown(&s->input.base, key); Elem_HandlesKeyDown(&s->input.base, key);
ChatScreen_UpdateChatYOffsets(s);
} }
return key < KEY_F1 || key > KEY_F35; return key < KEY_F1 || key > KEY_F35;
} }
@ -903,6 +904,7 @@ static int ChatScreen_PointerDown(void* screen, int id, int x, int y) {
static void ChatScreen_Init(void* screen) { static void ChatScreen_Init(void* screen) {
struct ChatScreen* s = (struct ChatScreen*)screen; struct ChatScreen* s = (struct ChatScreen*)screen;
ChatInputWidget_Create(&s->input); ChatInputWidget_Create(&s->input);
s->input.base.OnTextChanged = ChatScreen_OnInputTextChanged;
SpecialInputWidget_Create(&s->altText, &s->chatFont, &s->input.base); SpecialInputWidget_Create(&s->altText, &s->chatFont, &s->input.base);
TextGroupWidget_Create(&s->status, CHAT_MAX_STATUS, TextGroupWidget_Create(&s->status, CHAT_MAX_STATUS,
@ -1011,7 +1013,6 @@ void ChatScreen_OpenInput(const String* text) {
void ChatScreen_AppendInput(const String* text) { void ChatScreen_AppendInput(const String* text) {
struct ChatScreen* s = &ChatScreen_Instance; struct ChatScreen* s = &ChatScreen_Instance;
InputWidget_AppendText(&s->input.base, text); InputWidget_AppendText(&s->input.base, text);
ChatScreen_UpdateChatYOffsets(s);
} }
void ChatScreen_SetChatlines(int lines) { void ChatScreen_SetChatlines(int lines) {

View File

@ -892,8 +892,9 @@ void TableWidget_OnInventoryChanged(struct TableWidget* w) {
*#########################################################################################################################*/ *#########################################################################################################################*/
static void InputWidget_Reset(struct InputWidget* w) { static void InputWidget_Reset(struct InputWidget* w) {
Widget_Reset(w); Widget_Reset(w);
w->caretPos = -1; w->caretPos = -1;
w->caretOffset = Display_ScaleY(2); w->caretOffset = Display_ScaleY(2);
w->OnTextChanged = NULL;
} }
static void InputWidget_FormatLine(struct InputWidget* w, int i, String* line) { static void InputWidget_FormatLine(struct InputWidget* w, int i, String* line) {
@ -1025,6 +1026,7 @@ void InputWidget_Clear(struct InputWidget* w) {
w->caretPos = -1; w->caretPos = -1;
Gfx_DeleteTexture(&w->inputTex.ID); Gfx_DeleteTexture(&w->inputTex.ID);
/* TODO: Maybe call w->OnTextChanged */
} }
static cc_bool InputWidget_AllowedChar(void* widget, char c) { static cc_bool InputWidget_AllowedChar(void* widget, char c) {
@ -1186,12 +1188,14 @@ void InputWidget_UpdateText(struct InputWidget* w) {
w->RemakeTexture(w); w->RemakeTexture(w);
InputWidget_UpdateCaret(w); InputWidget_UpdateCaret(w);
Window_SetKeyboardText(&w->text); Window_SetKeyboardText(&w->text);
if (w->OnTextChanged) w->OnTextChanged(w);
} }
void InputWidget_SetText(struct InputWidget* w, const String* str) { void InputWidget_SetText(struct InputWidget* w, const String* str) {
InputWidget_Clear(w); InputWidget_Clear(w);
InputWidget_AppendText(w, str); InputWidget_AppendText(w, str);
/* If text is empty, InputWidget_UpdateText won't have been called */ /* If text is empty, InputWidget_UpdateText won't have been called */
/* TODO: InputWidet_UpdateText should probably always be called... */
if (!w->text.length) Window_SetKeyboardText(&w->text); if (!w->text.length) Window_SetKeyboardText(&w->text);
} }

View File

@ -107,11 +107,12 @@ struct InputWidget {
void (*RemakeTexture)(void* elem); /* Remakes the raw texture containing all the chat lines. Also updates dimensions. */ void (*RemakeTexture)(void* elem); /* Remakes the raw texture containing all the chat lines. Also updates dimensions. */
void (*OnPressedEnter)(void* elem); /* Invoked when the user presses enter. */ void (*OnPressedEnter)(void* elem); /* Invoked when the user presses enter. */
cc_bool (*AllowedChar)(void* elem, char c); cc_bool (*AllowedChar)(void* elem, char c);
void (*OnTextChanged)(void* elem); /* Callback invoked whenever text changes. */
String text; String text; /* The actual raw text */
String lines[INPUTWIDGET_MAX_LINES]; /* raw text of each line */ String lines[INPUTWIDGET_MAX_LINES]; /* text of each line after word wrapping */
int lineWidths[INPUTWIDGET_MAX_LINES]; /* Width of each line in pixels */ int lineWidths[INPUTWIDGET_MAX_LINES]; /* Width of each line in pixels */
int lineHeight; int lineHeight; /* Height of a line in pixels */
struct Texture inputTex; struct Texture inputTex;
int prefixWidth; int prefixWidth;
cc_bool convertPercents; cc_bool convertPercents;