|
45 | 45 | // Partial selection spanning a hard newline produces non-zero geometry and at least one client rect. |
46 | 46 | const textareaElement = setupControl('textarea', 'first line\nSECOND LINE\nthird'); |
47 | 47 | const firstLine = 'first line'; |
48 | | - const range = textareaElement.getValueRange(firstLine.length - 4, firstLine.length + 5); |
| 48 | + const range = textareaElement.createValueRange(firstLine.length - 4, firstLine.length + 5); |
49 | 49 | const boundingRect = rect(range, textareaElement, 'Bounding box inside: '); |
50 | 50 | assert_greater_than(boundingRect.width, 0); |
51 | 51 | assert_greater_than(boundingRect.height, 0); |
|
55 | 55 | test(() => { |
56 | 56 | // Selection that spans a blank line should still produce non-zero geometry. |
57 | 57 | const textareaElement = setupControl('textarea', 'line1\n\nline3'); |
58 | | - const range = textareaElement.getValueRange(0, textareaElement.value.length); |
| 58 | + const range = textareaElement.createValueRange(0, textareaElement.value.length); |
59 | 59 | const boundingRect = rect(range, textareaElement, 'Bounding box inside: '); |
60 | 60 | assert_greater_than(boundingRect.height, 0); |
61 | 61 | assert_greater_than(boundingRect.width, 0); |
|
66 | 66 | const textareaElement = setupControl('textarea', 'ABCDEFGHIJKLMNOPQRSTUVWXYZ 0123456789 abcdefghijklmnopqrstuvwxyz'); |
67 | 67 | textareaElement.style.whiteSpace = 'pre-wrap'; |
68 | 68 | textareaElement.style.width = '160px'; |
69 | | - const range = textareaElement.getValueRange(0, textareaElement.value.length); |
| 69 | + const range = textareaElement.createValueRange(0, textareaElement.value.length); |
70 | 70 | const boundingRect = rect(range, textareaElement, 'Bounding box inside: '); |
71 | 71 | assert_greater_than_equal(range.getClientRects().length, 2, 'soft wrap multiple rects'); |
72 | 72 | }, 'Soft-wrapped long single line (textarea)'); |
|
75 | 75 | // Caret before newline and start of next line have non-decreasing y and expected x ordering. |
76 | 76 | const value = '123456\n789012'; |
77 | 77 | const textareaElement = setupControl('textarea', value); |
78 | | - const caretBeforeNewlineRect = rect(textareaElement.getValueRange(6, 6), textareaElement, 'caret before newline inside: '); |
79 | | - const caretNextLineRect = rect(textareaElement.getValueRange(7, 7), textareaElement, 'caret next line inside: '); |
| 78 | + const caretBeforeNewlineRect = rect(textareaElement.createValueRange(6, 6), textareaElement, 'caret before newline inside: '); |
| 79 | + const caretNextLineRect = rect(textareaElement.createValueRange(7, 7), textareaElement, 'caret next line inside: '); |
80 | 80 | // Allow caret before newline to be aligned or slightly (sub-pixel) to the right. |
81 | 81 | assert_greater_than_equal(caretBeforeNewlineRect.x + 0.5, caretNextLineRect.x, 'caret before newline at or to the right (epsilon) of next line start'); |
82 | 82 | assert_less_than_equal(caretBeforeNewlineRect.y, caretNextLineRect.y, 'next line lower or equal y'); |
|
85 | 85 | test(() => { |
86 | 86 | // Live insert/delete operations adjust selection left/width as expected (grow/shift/shrink). |
87 | 87 | const inputElement = setupControl('input', 'ABCDE'); |
88 | | - const range = inputElement.getValueRange(1, 3); |
| 88 | + const range = inputElement.createValueRange(1, 3); |
89 | 89 |
|
90 | 90 | const leftBeforeInsertion = rect(range, inputElement).left; |
91 | 91 | inputElement.setRangeText('ZZ', 0, 0); |
|
111 | 111 | test(() => { |
112 | 112 | // Interior deletion shrinks width; insertion before selection shifts selection right in textarea. |
113 | 113 | const textareaElement = setupControl('textarea', 'ABCDE'); |
114 | | - const range = textareaElement.getValueRange(1, 4); |
| 114 | + const range = textareaElement.createValueRange(1, 4); |
115 | 115 | const widthBeforeDeletion = rect(range, textareaElement).width; |
116 | 116 | textareaElement.setRangeText('', 2, 3); |
117 | 117 | assert_less_than(rect(range, textareaElement).width, widthBeforeDeletion, 'textarea interior deletion shrinks width'); |
|
124 | 124 | test(() => { |
125 | 125 | // Inserting text inside selection increases its width. |
126 | 126 | const element = setupControl(controlType, 'ABCDE'); |
127 | | - const range = element.getValueRange(1, 4); |
| 127 | + const range = element.createValueRange(1, 4); |
128 | 128 | const widthBeforeInsertion = rect(range, element).width; |
129 | 129 | element.setRangeText('ZZ', 2, 2); |
130 | 130 | assert_greater_than(rect(range, element).width, widthBeforeInsertion, 'insertion inside expands width'); |
|
133 | 133 | test(() => { |
134 | 134 | // Deleting full selection collapses to a caret. |
135 | 135 | const element = setupControl(controlType, 'ABCDE'); |
136 | | - const range = element.getValueRange(1, 4); |
| 136 | + const range = element.createValueRange(1, 4); |
137 | 137 | assert_greater_than(rect(range, element).width, 0, 'pre width greater than 0'); |
138 | 138 | element.setRangeText('', 1, 4); |
139 | 139 | assert_true(range.collapsed, 'collapsed after deletion'); |
|
144 | 144 | test(() => { |
145 | 145 | // Shrink near end clamps range end; subsequent insertion at end does not auto-extend. |
146 | 146 | const element = setupControl(controlType, 'HelloWorld'); |
147 | | - const range = element.getValueRange(0, element.value.length); |
| 147 | + const range = element.createValueRange(0, element.value.length); |
148 | 148 | element.setRangeText('', 7, 10); |
149 | 149 | const endAfterShrink = range.endOffset; |
150 | 150 | assert_equals(endAfterShrink, element.value.length, 'end clamped after shrink'); |
|
155 | 155 | test(() => { |
156 | 156 | // Tail deletion clamps end offset while remaining selection geometry stays non-zero. |
157 | 157 | const element = setupControl(controlType, 'HelloWorld'); |
158 | | - const range = element.getValueRange(0, element.value.length); |
| 158 | + const range = element.createValueRange(0, element.value.length); |
159 | 159 | element.setRangeText('', 5, 10); |
160 | 160 | assert_equals(element.value, 'Hello', 'value shrunk to Hello'); |
161 | 161 | assert_equals(range.endOffset, element.value.length, 'end offset clamped to new value length'); |
|
167 | 167 | test(() => { |
168 | 168 | // Deleting selected text collapses to a caret with zero width. |
169 | 169 | const inputElement = setupControl('input', 'ABCDE'); |
170 | | - const range = inputElement.getValueRange(1, 4); |
| 170 | + const range = inputElement.createValueRange(1, 4); |
171 | 171 | inputElement.setRangeText('', 1, 4); |
172 | 172 | assert_true(range.collapsed, 'collapsed after deletion'); |
173 | 173 | assert_approx_equals(rect(range, inputElement).width, 0, 0.05, 'width should be 0'); |
|
0 commit comments