|
2 | 2 | using NUnit.Framework;
|
3 | 3 | using System.IO;
|
4 | 4 | using System.Collections.Generic;
|
5 |
| - |
| 5 | +using UnityEngine.UI; |
| 6 | +using UnityEngine.EventSystems; |
6 | 7 |
|
7 | 8 | namespace TMPro
|
8 | 9 | {
|
@@ -183,6 +184,56 @@ public void Parsing_TextInfo_RichText(int sourceTextIndex, int characterCount, i
|
183 | 184 | Assert.AreEqual(m_TextComponent.textInfo.lineCount, lineCount);
|
184 | 185 | }
|
185 | 186 |
|
| 187 | + public static IEnumerable<object[]> TestCases_MultiLineNewline_OnLastLine_WhenPressedEnter_Caret_ShouldNotGoto_NextLine() |
| 188 | + { |
| 189 | + yield return new object[] { 1, 1 }; |
| 190 | + yield return new object[] { 2, 2 }; |
| 191 | + yield return new object[] { 3, 3 }; |
| 192 | + yield return new object[] { 4, 4 }; |
| 193 | + yield return new object[] { 5, 5 }; |
| 194 | + yield return new object[] { 6, 6 }; |
| 195 | + } |
| 196 | + |
| 197 | + [Test, TestCaseSource("TestCases_MultiLineNewline_OnLastLine_WhenPressedEnter_Caret_ShouldNotGoto_NextLine")] |
| 198 | + public void MultiLineNewline_OnLastLine_WhenPressedEnter_Caret_ShouldNotGoto_NextLine(int lineLimit, int expectedLineCount) |
| 199 | + { |
| 200 | + GameObject cameraObject = new GameObject("Camera Object", typeof(Camera)); |
| 201 | + GameObject canvasObject = new GameObject("Canvas Object", typeof(Canvas), typeof(GraphicRaycaster)); |
| 202 | + canvasObject.GetComponent<Canvas>().renderMode = RenderMode.ScreenSpaceOverlay; |
| 203 | + GameObject inputObject = new GameObject("Input Object", typeof(TMP_InputField)); |
| 204 | + inputObject.transform.parent = canvasObject.transform; |
| 205 | + inputObject.AddComponent<Image>(); |
| 206 | + TMP_InputField m_InputField = inputObject.GetComponent<TMP_InputField>(); |
| 207 | + m_InputField.targetGraphic = inputObject.GetComponent<Image>(); |
| 208 | + m_InputField.textComponent = m_TextComponent; |
| 209 | + m_InputField.lineType = TMP_InputField.LineType.MultiLineNewline; |
| 210 | + m_InputField.lineLimit = lineLimit; |
| 211 | + |
| 212 | + GameObject eventGameObject = new GameObject("Event Object", typeof(EventSystem), typeof(StandaloneInputModule)); |
| 213 | + Event enterKeyDownEvent = new Event { type = EventType.KeyDown, keyCode = KeyCode.KeypadEnter, modifiers = EventModifiers.None, character = '\n' }; |
| 214 | + |
| 215 | + m_InputField.text = "POTUS"; |
| 216 | + EventSystem.current.SetSelectedGameObject(inputObject); |
| 217 | + m_InputField.ActivateInputField(); |
| 218 | + int count = 0; |
| 219 | + while (count < lineLimit + 3) |
| 220 | + { |
| 221 | + m_InputField.ProcessEvent(enterKeyDownEvent); |
| 222 | + m_InputField.ForceLabelUpdate(); |
| 223 | + count++; |
| 224 | + } |
| 225 | + |
| 226 | + m_InputField.textComponent.ForceMeshUpdate(); |
| 227 | + CanvasUpdateRegistry.RegisterCanvasElementForGraphicRebuild(m_InputField); |
| 228 | + |
| 229 | + m_InputField.DeactivateInputField(); |
| 230 | + GameObject.Destroy(eventGameObject); |
| 231 | + GameObject.Destroy(inputObject); |
| 232 | + GameObject.Destroy(canvasObject); |
| 233 | + GameObject.Destroy(cameraObject); |
| 234 | + |
| 235 | + Assert.AreEqual(m_TextComponent.textInfo.lineCount, expectedLineCount); |
| 236 | + } |
186 | 237 |
|
187 | 238 | //[OneTimeTearDown]
|
188 | 239 | //public void Cleanup()
|
|
0 commit comments