1
+ package org .fxmisc .richtext .api ;
2
+
3
+ import org .fxmisc .richtext .InlineCssTextAreaAppTest ;
4
+ import org .junit .Test ;
5
+
6
+ public class ReplaceTextTests extends InlineCssTextAreaAppTest {
7
+
8
+ @ Test
9
+ public void deselect_before_replaceText_does_not_cause_index_out_of_bounds_exception ()
10
+ {
11
+ interact ( () ->
12
+ {
13
+ area .replaceText ( "1234567890\n \n abcdefghij\n \n 1234567890\n \n abcdefghij" );
14
+
15
+ // Select last line of text
16
+ area .requestFollowCaret ();
17
+ area .selectLine ();
18
+
19
+ // Calling deselect, primes an IndexOutOfBoundsException to be thrown after replaceText
20
+ area .deselect ();
21
+
22
+ // An internal IndexOutOfBoundsException may occur in ParagraphText.getRangeShapeSafely
23
+ area .replaceText ( "1234567890\n \n abcdefghijklmno\n \n 1234567890\n \n abcde" );
24
+
25
+ // This would fail if an exception occurred during ParagraphText.layoutChildren:updateSelectionShape()
26
+ area .selectLine ();
27
+ });
28
+
29
+ }
30
+
31
+ @ Test
32
+ public void previous_selection_before_replaceText_does_not_cause_index_out_of_bounds_exception ()
33
+ {
34
+ interact ( () ->
35
+ {
36
+ // For this test to work the area MUST be at the end of the document
37
+ area .requestFollowCaret ();
38
+
39
+ // First text supplied by bug reporter: has 9 paragraphs, 344 characters
40
+ area .replaceText ( getTextA () );
41
+
42
+ // Any text can be selected anywhere in the document, this primed the exception
43
+ area .selectWord ();
44
+
45
+ // Second text supplied by bug reporter: has 9 paragraphs, 344 characters, and contains two Ä characters
46
+ area .replaceText ( getTextB () );
47
+
48
+ // An internal IndexOutOfBoundsException may occur in ParagraphText.getRangeShapeSafely
49
+ area .replaceText ( getTextA () );
50
+
51
+ // This would fail if an exception occurred during ParagraphText.layoutChildren:updateSelectionShape()
52
+ area .selectLine ();
53
+ });
54
+ }
55
+
56
+
57
+ // Reduced text supplied by bug reporter: has 9 paragraphs, 344 characters
58
+ private String getTextA ()
59
+ {
60
+ return "<!DOCTYPE HTML>\n " +
61
+ "\n " +
62
+ " Parempaa kuvaa ja äänentoistoa jo vuodesta 1981 - HifiStudio</title>\n " +
63
+ "\n " +
64
+ "<meta property=\" og:title\" content=\" HifiStudio - Parempaa kuvaa ja äänentoistoa jo vuodesta 1981\" />\n " +
65
+ "\n " +
66
+ "<meta property=\" og:url\" content=\" https://www.hifistudio.fi/fi/\" />\n " +
67
+ "\n " +
68
+ " <li><a href=\" /fi/tuotteet/muut-hifil" ;
69
+ }
70
+
71
+
72
+ // Reduced text supplied by bug reporter: has 9 paragraphs, 344 characters, and contains two Ä characters
73
+ private String getTextB ()
74
+ {
75
+ return "<!DOCTYPE HTML>\n " +
76
+ "\n " +
77
+ " SEINÄTELINEET - HifiStudio</title>\n " +
78
+ "\n " +
79
+ "<meta property=\" og:title\" content=\" HifiStudio - SEINÄTELINEET\" />\n " +
80
+ "\n " +
81
+ "<meta property=\" og:url\" content=\" https://www.hifistudio.fi/fi/tuotteet/laitetelineet/seinatelineet/91052\" />\n " +
82
+ "\n " +
83
+ " <li><a href=\" /fi/tuotteet/muut-hifilaitteet/cd-soittimet/15035\" class=\" top-product" ;
84
+ }
85
+ }
0 commit comments