diff --git a/Paper/ElementBuilder.cs b/Paper/ElementBuilder.cs index 2d6fbba..9ddd8f1 100644 --- a/Paper/ElementBuilder.cs +++ b/Paper/ElementBuilder.cs @@ -1322,8 +1322,8 @@ private TextInputState LoadTextInputState(string initialValue, bool isMultiLine) { var defaultState = new TextInputState { - Value = initialValue ?? "", - CursorPosition = (initialValue ?? "").Length, + Value = initialValue, + CursorPosition = initialValue.Length, SelectionStart = -1, SelectionEnd = -1, ScrollOffsetX = 0.0, @@ -1333,6 +1333,7 @@ private TextInputState LoadTextInputState(string initialValue, bool isMultiLine) }; var state = _paper.GetElementStorage(_handle, "TextInputState", defaultState); + state.Value = initialValue; state.IsFocused = _paper.IsElementFocused(_handle.Data.ID); state.IsMultiLine = isMultiLine; // Ensure consistency state.ClampValues(); @@ -1708,7 +1709,7 @@ private bool ProcessKeyCommand(ref TextInputState state, PaperKey key, TextInput public ElementBuilder TextField( string value, TextInputSettings settings, - Action onChange = null, + Action onChange, [System.Runtime.CompilerServices.CallerLineNumber] int intID = 0) { return CreateTextInput(value, settings, onChange, false, intID); @@ -1729,7 +1730,7 @@ public ElementBuilder TextField( public ElementBuilder TextField( string value, FontFile font, - Action onChange = null, + Action onChange, Color? textColor = null, string placeholder = "", Color? placeholderColor = null, @@ -1755,7 +1756,7 @@ public ElementBuilder TextField( public ElementBuilder TextArea( string value, TextInputSettings settings, - Action onChange = null, + Action onChange, [System.Runtime.CompilerServices.CallerLineNumber] int intID = 0) { return CreateTextInput(value, settings, onChange, true, intID); @@ -1776,7 +1777,7 @@ public ElementBuilder TextArea( public ElementBuilder TextArea( string value, FontFile font, - Action onChange = null, + Action onChange, string placeholder = "", Color? textColor = null, Color? placeholderColor = null, @@ -1958,7 +1959,7 @@ private ElementBuilder CreateTextInput( SaveTextInputState(currentState); if (valueChanged) - onChange?.Invoke(currentState.Value); + onChange.Invoke(currentState.Value); }); // Handle character input @@ -1982,7 +1983,7 @@ private ElementBuilder CreateTextInput( EnsureCursorVisible(ref currentState, settings, isMultiLine); SaveTextInputState(currentState); - onChange?.Invoke(currentState.Value); + onChange.Invoke(currentState.Value); }); // Render cursor and selection diff --git a/Samples/Shared/PaperDemo.Components.cs b/Samples/Shared/PaperDemo.Components.cs index 03845db..f00ca37 100644 --- a/Samples/Shared/PaperDemo.Components.cs +++ b/Samples/Shared/PaperDemo.Components.cs @@ -158,7 +158,7 @@ public static void DefineStyles() .Register(); } - public static ElementBuilder Secondary(string stringID, string value, Action onChange = null, string placeholder = "", int intID = 0, [CallerLineNumber] int lineID = 0) + public static ElementBuilder Secondary(string stringID, string value, Action onChange, string placeholder = "", int intID = 0, [CallerLineNumber] int lineID = 0) { ElementBuilder parent = PaperDemo.Gui.Box(stringID, intID, lineID).Style("shadcs-text-field-secondary").TabIndex(0); using (parent.Enter())