1
   2
   3
   4
   5
   6
   7
   8
   9
  10
  11
  12
  13
  14
  15
  16
  17
  18
  19
  20
  21
  22
  23
  24
  25
  26
  27
  28
  29
  30
  31
  32
  33
  34
  35
  36
  37
  38
  39
  40
  41
  42
  43
  44
  45
  46
  47
  48
  49
  50
  51
  52
  53
  54
  55
  56
  57
  58
  59
  60
  61
  62
  63
  64
  65
  66
  67
  68
  69
  70
  71
  72
  73
  74
  75
  76
  77
  78
  79
  80
  81
  82
  83
  84
  85
  86
  87
  88
  89
  90
  91
  92
  93
  94
  95
  96
  97
  98
  99
 100
 101
 102
 103
 104
 105
 106
 107
 108
 109
 110
 111
 112
 113
 114
 115
 116
 117
 118
 119
 120
 121
 122
 123
 124
 125
 126
 127
 128
 129
 130
 131
 132
 133
 134
 135
 136
 137
 138
 139
 140
 141
 142
 143
 144
 145
 146
 147
 148
 149
 150
 151
 152
 153
 154
 155
 156
 157
 158
 159
 160
 161
 162
 163
 164
 165
 166
 167
 168
 169
 170
 171
 172
 173
 174
 175
 176
 177
 178
 179
 180
 181
 182
 183
 184
 185
 186
 187
 188
 189
 190
 191
 192
 193
 194
 195
 196
 197
 198
 199
 200
 201
 202
 203
 204
 205
 206
 207
 208
 209
 210
 211
 212
 213
 214
 215
 216
 217
 218
 219
 220
 221
 222
 223
 224
 225
 226
 227
 228
 229
 230
 231
 232
 233
 234
 235
 236
 237
 238
 239
 240
 241
 242
 243
 244
 245
 246
 247
 248
 249
 250
 251
 252
 253
 254
 255
 256
 257
 258
 259
 260
 261
 262
 263
 264
 265
 266
 267
 268
 269
 270
 271
 272
 273
 274
 275
 276
 277
 278
 279
 280
 281
 282
 283
 284
 285
 286
 287
 288
 289
 290
 291
 292
 293
 294
 295
 296
 297
 298
 299
 300
 301
 302
 303
 304
 305
 306
 307
 308
 309
 310
 311
 312
 313
 314
 315
 316
 317
 318
 319
 320
 321
 322
 323
 324
 325
 326
 327
 328
 329
 330
 331
 332
 333
 334
 335
 336
 337
 338
 339
 340
 341
 342
 343
 344
 345
 346
 347
 348
 349
 350
 351
 352
 353
 354
 355
 356
 357
 358
 359
 360
 361
 362
 363
 364
 365
 366
 367
 368
 369
 370
 371
 372
 373
 374
 375
 376
 377
 378
 379
 380
 381
 382
 383
 384
 385
 386
 387
 388
 389
 390
 391
 392
 393
 394
 395
 396
 397
 398
 399
 400
 401
 402
 403
 404
 405
 406
 407
 408
 409
 410
 411
 412
 413
 414
 415
 416
 417
 418
 419
 420
 421
 422
 423
 424
 425
 426
 427
 428
 429
 430
 431
 432
 433
 434
 435
 436
 437
 438
 439
 440
 441
 442
 443
 444
 445
 446
 447
 448
 449
 450
 451
 452
 453
 454
 455
 456
 457
 458
 459
 460
 461
 462
 463
 464
 465
 466
 467
 468
 469
 470
 471
 472
 473
 474
 475
 476
 477
 478
 479
 480
 481
 482
 483
 484
 485
 486
 487
 488
 489
 490
 491
 492
 493
 494
 495
 496
 497
 498
 499
 500
 501
 502
 503
 504
 505
 506
 507
 508
 509
 510
 511
 512
 513
 514
 515
 516
 517
 518
 519
 520
 521
 522
 523
 524
 525
 526
 527
 528
 529
 530
 531
 532
 533
 534
 535
 536
 537
 538
 539
 540
 541
 542
 543
 544
 545
 546
 547
 548
 549
 550
 551
 552
 553
 554
 555
 556
 557
 558
 559
 560
 561
 562
 563
 564
 565
 566
 567
 568
 569
 570
 571
 572
 573
 574
 575
 576
 577
 578
 579
 580
 581
 582
 583
 584
 585
 586
 587
 588
 589
 590
 591
 592
 593
 594
 595
 596
 597
 598
 599
 600
 601
 602
 603
 604
 605
 606
 607
 608
 609
 610
 611
 612
 613
 614
 615
 616
 617
 618
 619
 620
 621
 622
 623
 624
 625
 626
 627
 628
 629
 630
 631
 632
 633
 634
 635
 636
 637
 638
 639
 640
 641
 642
 643
 644
 645
 646
 647
 648
 649
 650
 651
 652
 653
 654
 655
 656
 657
 658
 659
 660
 661
 662
 663
 664
 665
 666
 667
 668
 669
 670
 671
 672
 673
 674
 675
 676
 677
 678
 679
 680
 681
 682
 683
 684
 685
 686
 687
 688
 689
 690
 691
 692
 693
 694
 695
 696
 697
 698
 699
 700
 701
 702
 703
 704
 705
 706
 707
 708
 709
 710
 711
 712
 713
 714
 715
 716
 717
 718
 719
 720
 721
 722
 723
 724
 725
 726
 727
 728
 729
 730
 731
 732
 733
 734
 735
 736
 737
 738
 739
 740
 741
 742
 743
 744
 745
 746
 747
 748
 749
 750
 751
 752
 753
 754
 755
 756
 757
 758
 759
 760
 761
 762
 763
 764
 765
 766
 767
 768
 769
 770
 771
 772
 773
 774
 775
 776
 777
 778
 779
 780
 781
 782
 783
 784
 785
 786
 787
 788
 789
 790
 791
 792
 793
 794
 795
 796
 797
 798
 799
 800
 801
 802
 803
 804
 805
 806
 807
 808
 809
 810
 811
 812
 813
 814
 815
 816
 817
 818
 819
 820
 821
 822
 823
 824
 825
 826
 827
 828
 829
 830
 831
 832
 833
 834
 835
 836
 837
 838
 839
 840
 841
 842
 843
 844
 845
 846
 847
 848
 849
 850
 851
 852
 853
 854
 855
 856
 857
 858
 859
 860
 861
 862
 863
 864
 865
 866
 867
 868
 869
 870
 871
 872
 873
 874
 875
 876
 877
 878
 879
 880
 881
 882
 883
 884
 885
 886
 887
 888
 889
 890
 891
 892
 893
 894
 895
 896
 897
 898
 899
 900
 901
 902
 903
 904
 905
 906
 907
 908
 909
 910
 911
 912
 913
 914
 915
 916
 917
 918
 919
 920
 921
 922
 923
 924
 925
 926
 927
 928
 929
 930
 931
 932
 933
 934
 935
 936
 937
 938
 939
 940
 941
 942
 943
 944
 945
 946
 947
 948
 949
 950
 951
 952
 953
 954
 955
 956
 957
 958
 959
 960
 961
 962
 963
 964
 965
 966
 967
 968
 969
 970
 971
 972
 973
 974
 975
 976
 977
 978
 979
 980
 981
 982
 983
 984
 985
 986
 987
 988
 989
 990
 991
 992
 993
 994
 995
 996
 997
 998
 999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328
3329
3330
3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344
3345
3346
3347
3348
3349
3350
3351
3352
3353
3354
3355
3356
3357
3358
3359
3360
3361
3362
3363
3364
3365
3366
3367
3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381
3382
3383
3384
3385
3386
3387
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397
3398
3399
3400
3401
3402
3403
3404
3405
3406
3407
3408
3409
3410
3411
3412
3413
3414
3415
3416
3417
3418
3419
3420
3421
3422
3423
3424
3425
3426
3427
3428
3429
3430
3431
3432
3433
3434
3435
3436
3437
3438
3439
3440
3441
3442
3443
3444
3445
3446
3447
3448
3449
3450
3451
3452
3453
3454
3455
3456
3457
3458
3459
3460
3461
3462
3463
3464
3465
3466
3467
3468
3469
3470
3471
3472
3473
3474
3475
3476
3477
3478
3479
3480
3481
3482
3483
3484
3485
3486
3487
3488
3489
3490
3491
3492
3493
3494
3495
3496
3497
3498
3499
3500
3501
3502
3503
3504
3505
3506
3507
3508
3509
3510
3511
3512
3513
3514
3515
3516
3517
3518
3519
3520
3521
3522
3523
3524
3525
3526
3527
3528
3529
3530
3531
3532
3533
3534
3535
3536
3537
3538
3539
3540
3541
3542
3543
3544
3545
3546
3547
3548
3549
3550
3551
3552
3553
3554
3555
3556
3557
3558
3559
3560
3561
3562
3563
3564
3565
3566
3567
3568
3569
3570
3571
3572
3573
3574
3575
3576
3577
3578
3579
3580
3581
3582
3583
3584
3585
3586
3587
3588
3589
3590
3591
3592
3593
3594
3595
3596
3597
3598
3599
3600
3601
3602
3603
3604
3605
3606
3607
3608
3609
3610
3611
3612
3613
3614
3615
3616
3617
3618
3619
3620
3621
3622
3623
3624
3625
3626
3627
3628
3629
3630
3631
3632
3633
3634
3635
3636
3637
3638
3639
3640
3641
3642
3643
3644
3645
3646
3647
3648
3649
3650
3651
3652
3653
3654
3655
3656
3657
3658
3659
3660
3661
3662
3663
3664
3665
3666
3667
3668
3669
3670
3671
3672
3673
3674
3675
3676
3677
3678
3679
3680
3681
3682
3683
3684
3685
3686
3687
3688
3689
3690
3691
3692
3693
3694
3695
3696
3697
3698
3699
3700
3701
3702
3703
3704
3705
3706
3707
3708
3709
3710
3711
3712
3713
3714
3715
3716
3717
3718
3719
3720
3721
3722
3723
3724
3725
3726
3727
3728
3729
3730
3731
3732
3733
3734
3735
3736
3737
3738
3739
3740
3741
3742
3743
3744
3745
3746
3747
3748
3749
3750
3751
3752
3753
3754
3755
3756
3757
3758
3759
3760
3761
3762
3763
3764
3765
3766
3767
3768
3769
3770
3771
3772
3773
3774
3775
3776
3777
3778
3779
3780
3781
3782
3783
3784
3785
3786
3787
3788
3789
3790
3791
3792
3793
3794
3795
3796
3797
3798
3799
3800
3801
3802
3803
3804
3805
3806
3807
3808
3809
3810
3811
3812
3813
3814
3815
3816
3817
3818
3819
3820
3821
3822
3823
3824
3825
3826
3827
3828
3829
3830
3831
3832
3833
3834
3835
3836
3837
3838
3839
3840
3841
3842
3843
3844
3845
3846
3847
3848
3849
3850
3851
3852
3853
3854
3855
3856
3857
3858
3859
3860
3861
3862
3863
3864
3865
3866
3867
3868
3869
3870
3871
3872
3873
3874
3875
3876
3877
3878
3879
3880
3881
3882
3883
3884
3885
3886
3887
3888
3889
3890
3891
3892
3893
3894
3895
3896
3897
3898
3899
3900
3901
3902
3903
3904
3905
3906
3907
3908
3909
3910
3911
3912
3913
3914
3915
3916
3917
3918
3919
3920
3921
3922
3923
3924
3925
3926
3927
3928
3929
3930
3931
3932
3933
3934
3935
3936
3937
3938
3939
3940
3941
3942
3943
3944
3945
3946
3947
3948
3949
3950
3951
3952
3953
3954
3955
3956
3957
3958
3959
3960
3961
3962
3963
3964
3965
3966
3967
3968
3969
3970
3971
3972
3973
3974
3975
3976
3977
3978
3979
3980
3981
3982
3983
3984
3985
3986
3987
3988
3989
3990
3991
3992
3993
3994
3995
3996
3997
3998
3999
4000
4001
4002
4003
4004
4005
4006
4007
4008
4009
4010
4011
4012
4013
4014
4015
4016
4017
4018
4019
4020
4021
4022
4023
4024
4025
4026
4027
4028
4029
4030
4031
4032
4033
4034
4035
4036
4037
4038
4039
4040
4041
4042
4043
4044
4045
4046
4047
4048
4049
4050
4051
4052
4053
4054
4055
4056
4057
4058
4059
4060
4061
4062
4063
4064
4065
4066
4067
4068
4069
4070
4071
4072
4073
4074
4075
4076
4077
4078
4079
4080
4081
4082
4083
4084
4085
4086
4087
4088
4089
4090
4091
4092
4093
4094
4095
4096
4097
4098
4099
4100
4101
4102
4103
4104
4105
4106
4107
4108
4109
4110
4111
4112
4113
4114
4115
4116
4117
4118
4119
4120
4121
4122
4123
4124
4125
4126
4127
4128
4129
4130
4131
4132
4133
4134
4135
4136
4137
4138
4139
4140
4141
4142
4143
4144
4145
4146
4147
4148
4149
4150
4151
4152
4153
4154
4155
4156
4157
4158
4159
4160
4161
4162
4163
4164
4165
4166
4167
4168
4169
4170
4171
4172
4173
4174
4175
4176
4177
4178
4179
4180
4181
4182
4183
4184
4185
4186
4187
4188
4189
4190
4191
4192
4193
4194
4195
4196
4197
4198
4199
4200
4201
4202
4203
4204
4205
4206
4207
4208
4209
4210
4211
4212
4213
4214
4215
4216
4217
4218
4219
4220
4221
4222
4223
4224
4225
4226
4227
4228
4229
4230
4231
4232
4233
4234
4235
4236
4237
4238
4239
4240
4241
4242
4243
4244
4245
4246
4247
4248
4249
4250
4251
4252
4253
4254
4255
4256
4257
4258
4259
4260
4261
4262
4263
4264
4265
4266
4267
4268
4269
4270
4271
4272
4273
4274
4275
4276
4277
4278
4279
4280
4281
4282
4283
4284
4285
4286
4287
4288
4289
4290
4291
4292
4293
4294
4295
4296
4297
4298
4299
4300
4301
4302
4303
4304
4305
4306
4307
4308
4309
4310
4311
4312
4313
4314
4315
4316
4317
4318
4319
4320
4321
4322
4323
4324
4325
4326
4327
4328
4329
4330
4331
4332
4333
4334
4335
4336
4337
4338
4339
4340
4341
4342
4343
4344
4345
4346
4347
4348
4349
4350
4351
4352
4353
4354
4355
4356
4357
4358
4359
4360
4361
4362
4363
4364
4365
4366
4367
4368
4369
4370
4371
4372
4373
4374
4375
4376
4377
4378
4379
4380
4381
4382
4383
4384
4385
4386
4387
4388
4389
4390
4391
4392
4393
4394
4395
4396
4397
4398
4399
4400
4401
4402
4403
4404
4405
4406
4407
4408
4409
4410
4411
4412
4413
4414
4415
4416
4417
4418
4419
4420
4421
4422
4423
4424
4425
4426
4427
4428
4429
4430
4431
4432
4433
4434
4435
4436
4437
4438
4439
4440
4441
4442
4443
4444
4445
4446
4447
4448
4449
4450
4451
4452
4453
4454
4455
4456
4457
4458
4459
4460
4461
4462
4463
4464
4465
4466
4467
4468
4469
4470
4471
4472
4473
4474
4475
4476
4477
4478
4479
4480
4481
4482
4483
4484
4485
4486
4487
4488
4489
4490
4491
4492
4493
4494
4495
4496
4497
4498
4499
4500
4501
4502
4503
4504
4505
4506
4507
4508
4509
4510
4511
4512
4513
4514
4515
4516
4517
4518
4519
4520
4521
4522
4523
4524
4525
4526
4527
4528
4529
4530
4531
4532
4533
4534
4535
4536
4537
4538
4539
4540
4541
4542
4543
4544
4545
4546
4547
4548
4549
4550
4551
4552
4553
4554
4555
4556
4557
4558
4559
4560
4561
4562
4563
4564
4565
4566
4567
4568
4569
4570
4571
4572
4573
4574
4575
4576
4577
4578
4579
4580
4581
4582
4583
4584
4585
4586
4587
4588
4589
4590
4591
4592
4593
4594
4595
4596
4597
4598
4599
4600
4601
4602
4603
4604
4605
4606
4607
4608
4609
4610
4611
4612
4613
4614
4615
4616
4617
4618
4619
4620
4621
4622
4623
4624
4625
4626
4627
4628
4629
4630
4631
4632
4633
4634
4635
4636
4637
4638
4639
4640
4641
4642
4643
4644
4645
4646
4647
4648
4649
4650
4651
4652
4653
4654
4655
4656
4657
4658
4659
4660
4661
/**************************************************************************/
/*  editor_help.cpp                                                       */
/**************************************************************************/
/*                         This file is part of:                          */
/*                             GODOT ENGINE                               */
/*                        https://godotengine.org                         */
/**************************************************************************/
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur.                  */
/*                                                                        */
/* Permission is hereby granted, free of charge, to any person obtaining  */
/* a copy of this software and associated documentation files (the        */
/* "Software"), to deal in the Software without restriction, including    */
/* without limitation the rights to use, copy, modify, merge, publish,    */
/* distribute, sublicense, and/or sell copies of the Software, and to     */
/* permit persons to whom the Software is furnished to do so, subject to  */
/* the following conditions:                                              */
/*                                                                        */
/* The above copyright notice and this permission notice shall be         */
/* included in all copies or substantial portions of the Software.        */
/*                                                                        */
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,        */
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF     */
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY   */
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,   */
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE      */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.                 */
/**************************************************************************/

#include "editor_help.h"

#include "core/config/project_settings.h"
#include "core/core_constants.h"
#include "core/extension/gdextension.h"
#include "core/input/input.h"
#include "core/io/json.h"
#include "core/object/script_language.h"
#include "core/os/keyboard.h"
#include "core/string/string_builder.h"
#include "core/version_generated.gen.h"
#include "editor/doc_data_compressed.gen.h"
#include "editor/editor_main_screen.h"
#include "editor/editor_node.h"
#include "editor/editor_paths.h"
#include "editor/editor_property_name_processor.h"
#include "editor/editor_settings.h"
#include "editor/editor_string_names.h"
#include "editor/plugins/script_editor_plugin.h"
#include "editor/themes/editor_scale.h"
#include "scene/gui/line_edit.h"

#include "modules/modules_enabled.gen.h" // For gdscript, mono.

// For syntax highlighting.
#ifdef MODULE_GDSCRIPT_ENABLED
#include "modules/gdscript/editor/gdscript_highlighter.h"
#include "modules/gdscript/gdscript.h"
#endif

// For syntax highlighting.
#ifdef MODULE_MONO_ENABLED
#include "editor/plugins/script_editor_plugin.h"
#include "modules/mono/csharp_script.h"
#endif

#define CONTRIBUTE_URL vformat("%s/contributing/documentation/updating_the_class_reference.html", VERSION_DOCS_URL)

#ifdef MODULE_MONO_ENABLED
// Sync with the types mentioned in https://docs.godotengine.org/en/stable/tutorials/scripting/c_sharp/c_sharp_differences.html
const Vector<String> classes_with_csharp_differences = {
	"@GlobalScope",
	"String",
	"NodePath",
	"Signal",
	"Callable",
	"RID",
	"Basis",
	"Transform2D",
	"Transform3D",
	"Rect2",
	"Rect2i",
	"AABB",
	"Quaternion",
	"Projection",
	"Color",
	"Array",
	"Dictionary",
	"PackedByteArray",
	"PackedColorArray",
	"PackedFloat32Array",
	"PackedFloat64Array",
	"PackedInt32Array",
	"PackedInt64Array",
	"PackedStringArray",
	"PackedVector2Array",
	"PackedVector3Array",
	"PackedVector4Array",
	"Variant",
};
#endif

static const String nbsp = String::chr(160);
static const String nbsp_equal_nbsp = nbsp + "=" + nbsp;
static const String colon_nbsp = ":" + nbsp;

const Vector<String> packed_array_types = {
	"PackedByteArray",
	"PackedColorArray",
	"PackedFloat32Array",
	"PackedFloat64Array",
	"PackedInt32Array",
	"PackedInt64Array",
	"PackedStringArray",
	"PackedVector2Array",
	"PackedVector3Array",
	"PackedVector4Array",
};

static String _replace_nbsp_with_space(const String &p_string) {
	return p_string.replace(nbsp, " ");
}

static String _fix_constant(const String &p_constant) {
	if (p_constant.strip_edges() == "4294967295") {
		return "0xFFFFFFFF";
	}

	if (p_constant.strip_edges() == "2147483647") {
		return "0x7FFFFFFF";
	}

	if (p_constant.strip_edges() == "1048575") {
		return "0xFFFFF";
	}

	return p_constant;
}

static void _add_qualifiers_to_rt(const String &p_qualifiers, RichTextLabel *p_rt) {
	for (const String &qualifier : p_qualifiers.split_spaces()) {
		String hint;
		if (qualifier == "vararg") {
			hint = TTR("This method supports a variable number of arguments.");
		} else if (qualifier == "virtual") {
			hint = TTR("This method is called by the engine.\nIt can be overridden to customize built-in behavior.");
		} else if (qualifier == "const") {
			hint = TTR("This method has no side effects.\nIt does not modify the object in any way.");
		} else if (qualifier == "static") {
			hint = TTR("This method does not need an instance to be called.\nIt can be called directly using the class name.");
		}

		p_rt->add_text(" ");
		if (hint.is_empty()) {
			p_rt->add_text(qualifier);
		} else {
			p_rt->push_hint(hint);
			p_rt->add_text(qualifier);
			p_rt->pop(); // hint
		}
	}
}

// Removes unnecessary prefix from `p_class_specifier` when within the `p_edited_class` context.
static String _contextualize_class_specifier(const String &p_class_specifier, const String &p_edited_class) {
	// If this is a completely different context than the current class, then keep full path.
	if (!p_class_specifier.begins_with(p_edited_class)) {
		return p_class_specifier;
	}

	// Here equal `length()` and `begins_with()` from above implies `p_class_specifier == p_edited_class`.
	if (p_class_specifier.length() == p_edited_class.length()) {
		int rfind = p_class_specifier.rfind_char('.');
		if (rfind == -1) { // Single identifier.
			return p_class_specifier;
		}
		// Multiple specifiers: keep last one only.
		return p_class_specifier.substr(rfind + 1);
	}

	// They share a _name_ prefix but not a _class specifier_ prefix, e.g. `Tree` and `TreeItem`.
	// `begins_with()` and `length()`s being different implies `p_class_specifier.length() > p_edited_class.length()` so this is safe.
	if (p_class_specifier[p_edited_class.length()] != '.') {
		return p_class_specifier;
	}

	// Remove class specifier prefix.
	return p_class_specifier.substr(p_edited_class.length() + 1);
}

/// EditorHelp ///

// TODO: This is sometimes used directly as `doc->something`, other times as `EditorHelp::get_doc_data()`, which is thread-safe.
// Might this be a problem?
DocTools *EditorHelp::doc = nullptr;
DocTools *EditorHelp::ext_doc = nullptr;

int EditorHelp::doc_generation_count = 0;
String EditorHelp::doc_version_hash;
Thread EditorHelp::worker_thread;

static bool _attempt_doc_load(const String &p_class) {
	// Docgen always happens in the outer-most class: it also generates docs for inner classes.
	const String outer_class = p_class.get_slicec('.', 0);
	if (!ScriptServer::is_global_class(outer_class)) {
		return false;
	}

	// `ResourceLoader` is used in order to have a script-agnostic way to load scripts.
	// This forces GDScript to compile the code, which is unnecessary for docgen, but it's a good compromise right now.
	const Ref<Script> script = ResourceLoader::load(ScriptServer::get_global_class_path(outer_class), outer_class);
	if (script.is_valid()) {
		const Vector<DocData::ClassDoc> docs = script->get_documentation();
		for (int j = 0; j < docs.size(); j++) {
			const DocData::ClassDoc &doc = docs.get(j);
			EditorHelp::get_doc_data()->add_doc(doc);
		}
		return true;
	}

	return false;
}

void EditorHelp::_update_theme_item_cache() {
	VBoxContainer::_update_theme_item_cache();

	theme_cache.text_color = get_theme_color(SNAME("text_color"), SNAME("EditorHelp"));
	theme_cache.title_color = get_theme_color(SNAME("title_color"), SNAME("EditorHelp"));
	theme_cache.headline_color = get_theme_color(SNAME("headline_color"), SNAME("EditorHelp"));
	theme_cache.comment_color = get_theme_color(SNAME("comment_color"), SNAME("EditorHelp"));
	theme_cache.symbol_color = get_theme_color(SNAME("symbol_color"), SNAME("EditorHelp"));
	theme_cache.value_color = get_theme_color(SNAME("value_color"), SNAME("EditorHelp"));
	theme_cache.qualifier_color = get_theme_color(SNAME("qualifier_color"), SNAME("EditorHelp"));
	theme_cache.type_color = get_theme_color(SNAME("type_color"), SNAME("EditorHelp"));
	theme_cache.override_color = get_theme_color(SNAME("override_color"), SNAME("EditorHelp"));

	theme_cache.doc_font = get_theme_font(SNAME("doc"), EditorStringName(EditorFonts));
	theme_cache.doc_bold_font = get_theme_font(SNAME("doc_bold"), EditorStringName(EditorFonts));
	theme_cache.doc_italic_font = get_theme_font(SNAME("doc_italic"), EditorStringName(EditorFonts));
	theme_cache.doc_title_font = get_theme_font(SNAME("doc_title"), EditorStringName(EditorFonts));
	theme_cache.doc_code_font = get_theme_font(SNAME("doc_source"), EditorStringName(EditorFonts));
	theme_cache.doc_kbd_font = get_theme_font(SNAME("doc_keyboard"), EditorStringName(EditorFonts));

	theme_cache.doc_font_size = get_theme_font_size(SNAME("doc_size"), EditorStringName(EditorFonts));
	theme_cache.doc_title_font_size = get_theme_font_size(SNAME("doc_title_size"), EditorStringName(EditorFonts));
	theme_cache.doc_code_font_size = get_theme_font_size(SNAME("doc_source_size"), EditorStringName(EditorFonts));
	theme_cache.doc_kbd_font_size = get_theme_font_size(SNAME("doc_keyboard_size"), EditorStringName(EditorFonts));

	theme_cache.background_style = get_theme_stylebox(SNAME("background"), SNAME("EditorHelp"));

	class_desc->begin_bulk_theme_override();
	class_desc->add_theme_font_override("normal_font", theme_cache.doc_font);
	class_desc->add_theme_font_size_override("normal_font_size", theme_cache.doc_font_size);

	class_desc->add_theme_constant_override(SceneStringName(line_separation), get_theme_constant(SceneStringName(line_separation), SNAME("EditorHelp")));
	class_desc->add_theme_constant_override("table_h_separation", get_theme_constant(SNAME("table_h_separation"), SNAME("EditorHelp")));
	class_desc->add_theme_constant_override("table_v_separation", get_theme_constant(SNAME("table_v_separation"), SNAME("EditorHelp")));
	class_desc->add_theme_constant_override("text_highlight_h_padding", get_theme_constant(SNAME("text_highlight_h_padding"), SNAME("EditorHelp")));
	class_desc->add_theme_constant_override("text_highlight_v_padding", get_theme_constant(SNAME("text_highlight_v_padding"), SNAME("EditorHelp")));
	class_desc->end_bulk_theme_override();
}

void EditorHelp::_search(bool p_search_previous) {
	if (p_search_previous) {
		find_bar->search_prev();
	} else {
		find_bar->search_next();
	}
}

void EditorHelp::_class_desc_finished() {
	if (scroll_to >= 0) {
		class_desc->scroll_to_paragraph(scroll_to);
	}
	scroll_to = -1;
}

void EditorHelp::_class_list_select(const String &p_select) {
	_goto_desc(p_select);
}

void EditorHelp::_class_desc_select(const String &p_select) {
	if (p_select.begins_with("$")) { // Enum.
		const String link = p_select.substr(1);

		String enum_class_name;
		String enum_name;
		if (CoreConstants::is_global_enum(link)) {
			enum_class_name = "@GlobalScope";
			enum_name = link;
		} else {
			const int dot_pos = link.rfind_char('.');
			if (dot_pos >= 0) {
				enum_class_name = link.left(dot_pos);
				enum_name = link.substr(dot_pos + 1);
			} else {
				enum_class_name = edited_class;
				enum_name = link;
			}
		}

		emit_signal(SNAME("go_to_help"), "class_enum:" + enum_class_name + ":" + enum_name);
	} else if (p_select.begins_with("#")) { // Class.
		emit_signal(SNAME("go_to_help"), "class_name:" + p_select.substr(1));
	} else if (p_select.begins_with("@")) { // Member.
		const int tag_end = p_select.find_char(' ');
		const String tag = p_select.substr(1, tag_end - 1);
		const String link = p_select.substr(tag_end + 1).lstrip(" ");

		String topic;
		const HashMap<String, int> *table = nullptr;

		if (tag == "method") {
			topic = "class_method";
			table = &method_line;
		} else if (tag == "constructor") {
			topic = "class_method";
			table = &method_line;
		} else if (tag == "operator") {
			topic = "class_method";
			table = &method_line;
		} else if (tag == "member") {
			topic = "class_property";
			table = &property_line;
		} else if (tag == "enum") {
			topic = "class_enum";
			table = &enum_line;
		} else if (tag == "signal") {
			topic = "class_signal";
			table = &signal_line;
		} else if (tag == "constant") {
			topic = "class_constant";
			table = &constant_line;
		} else if (tag == "annotation") {
			topic = "class_annotation";
			table = &annotation_line;
		} else if (tag == "theme_item") {
			topic = "class_theme_item";
			table = &theme_property_line;
		} else {
			return;
		}

		// Case order is important here to correctly handle edge cases like `Variant.Type` in `@GlobalScope`.
		if (table->has(link)) {
			// Found in the current page.
			if (class_desc->is_finished()) {
				emit_signal(SNAME("request_save_history"));
				class_desc->scroll_to_paragraph((*table)[link]);
			} else {
				scroll_to = (*table)[link];
			}
		} else {
			// Look for link in `@GlobalScope`.
			if (topic == "class_enum") {
				const DocData::ClassDoc &cd = doc->class_list["@GlobalScope"];
				const String enum_link = link.trim_prefix("@GlobalScope.");

				for (const DocData::ConstantDoc &constant : cd.constants) {
					if (constant.enumeration == enum_link) {
						// Found in `@GlobalScope`.
						emit_signal(SNAME("go_to_help"), topic + ":@GlobalScope:" + enum_link);
						return;
					}
				}
			} else if (topic == "class_constant") {
				const DocData::ClassDoc &cd = doc->class_list["@GlobalScope"];

				for (const DocData::ConstantDoc &constant : cd.constants) {
					if (constant.name == link) {
						// Found in `@GlobalScope`.
						emit_signal(SNAME("go_to_help"), topic + ":@GlobalScope:" + link);
						return;
					}
				}
			}

			if (link.contains_char('.')) {
				const int class_end = link.rfind_char('.');
				emit_signal(SNAME("go_to_help"), topic + ":" + link.left(class_end) + ":" + link.substr(class_end + 1));
			}
		}
	} else if (p_select.begins_with("http:") || p_select.begins_with("https:")) {
		OS::get_singleton()->shell_open(p_select);
	} else if (p_select.begins_with("^")) { // Copy button.
		DisplayServer::get_singleton()->clipboard_set(p_select.substr(1));
	}
}

void EditorHelp::_class_desc_input(const Ref<InputEvent> &p_input) {
}

void EditorHelp::_class_desc_resized(bool p_force_update_theme) {
	// Add extra horizontal margins for better readability.
	// The margins increase as the width of the editor help container increases.
	real_t char_width = theme_cache.doc_code_font->get_char_size('x', theme_cache.doc_code_font_size).width;
	const int new_display_margin = MAX(30 * EDSCALE, get_parent_anchorable_rect().size.width - char_width * 120 * EDSCALE) * 0.5;
	if (display_margin != new_display_margin || p_force_update_theme) {
		display_margin = new_display_margin;

		Ref<StyleBox> class_desc_stylebox = theme_cache.background_style->duplicate();
		class_desc_stylebox->set_content_margin(SIDE_LEFT, display_margin);
		class_desc_stylebox->set_content_margin(SIDE_RIGHT, display_margin);
		class_desc->add_theme_style_override(CoreStringName(normal), class_desc_stylebox);
		class_desc->add_theme_style_override("focused", class_desc_stylebox);
	}
}

static void _add_type_to_rt(const String &p_type, const String &p_enum, bool p_is_bitfield, RichTextLabel *p_rt, const Control *p_owner_node, const String &p_class) {
	const Color type_color = p_owner_node->get_theme_color(SNAME("type_color"), SNAME("EditorHelp"));

	if (p_type.is_empty() || p_type == "void") {
		p_rt->push_color(Color(type_color, 0.5));
		p_rt->push_hint(TTR("No return value."));
		p_rt->add_text("void");
		p_rt->pop(); // hint
		p_rt->pop(); // color
		return;
	}

	bool is_enum_type = !p_enum.is_empty();
	bool is_bitfield = p_is_bitfield && is_enum_type;
	bool can_ref = !p_type.contains_char('*') || is_enum_type;

	String link_t = p_type; // For links in metadata
	String display_t; // For display purposes.
	if (is_enum_type) {
		link_t = p_enum; // The link for enums is always the full enum description
		display_t = _contextualize_class_specifier(p_enum, p_class);
	} else {
		display_t = _contextualize_class_specifier(p_type, p_class);
	}

	p_rt->push_color(type_color);
	bool add_typed_container = false;
	if (can_ref) {
		if (link_t.ends_with("[]")) {
			add_typed_container = true;
			link_t = link_t.trim_suffix("[]");
			display_t = display_t.trim_suffix("[]");

			p_rt->push_meta("#Array", RichTextLabel::META_UNDERLINE_ON_HOVER); // class
			p_rt->add_text("Array");
			p_rt->pop(); // meta
			p_rt->add_text("[");
		} else if (link_t.begins_with("Dictionary[")) {
			add_typed_container = true;
			link_t = link_t.trim_prefix("Dictionary[").trim_suffix("]");
			display_t = display_t.trim_prefix("Dictionary[").trim_suffix("]");

			p_rt->push_meta("#Dictionary", RichTextLabel::META_UNDERLINE_ON_HOVER); // class
			p_rt->add_text("Dictionary");
			p_rt->pop(); // meta
			p_rt->add_text("[");
			p_rt->push_meta("#" + link_t.get_slice(", ", 0), RichTextLabel::META_UNDERLINE_ON_HOVER); // class
			p_rt->add_text(_contextualize_class_specifier(display_t.get_slice(", ", 0), p_class));
			p_rt->pop(); // meta
			p_rt->add_text(", ");

			link_t = link_t.get_slice(", ", 1);
			display_t = _contextualize_class_specifier(display_t.get_slice(", ", 1), p_class);
		} else if (is_bitfield) {
			p_rt->push_color(Color(type_color, 0.5));
			p_rt->push_hint(TTR("This value is an integer composed as a bitmask of the following flags."));
			p_rt->add_text("BitField");
			p_rt->pop(); // hint
			p_rt->add_text("[");
			p_rt->pop(); // color
		}

		if (is_enum_type) {
			p_rt->push_meta("$" + link_t, RichTextLabel::META_UNDERLINE_ON_HOVER); // enum
		} else {
			p_rt->push_meta("#" + link_t, RichTextLabel::META_UNDERLINE_ON_HOVER); // class
		}
	}
	p_rt->add_text(display_t);
	if (can_ref) {
		p_rt->pop(); // meta
		if (add_typed_container) {
			p_rt->add_text("]");
		} else if (is_bitfield) {
			p_rt->push_color(Color(type_color, 0.5));
			p_rt->add_text("]");
			p_rt->pop(); // color
		}
	}
	p_rt->pop(); // color
}

void EditorHelp::_add_type(const String &p_type, const String &p_enum, bool p_is_bitfield) {
	_add_type_to_rt(p_type, p_enum, p_is_bitfield, class_desc, this, edited_class);
}

void EditorHelp::_add_type_icon(const String &p_type, int p_size, const String &p_fallback) {
	Ref<Texture2D> icon = EditorNode::get_singleton()->get_class_icon(p_type, p_fallback);
	Vector2i size = Vector2i(icon->get_width(), icon->get_height());
	if (p_size > 0) {
		// Ensures icon scales proportionally on both axes, based on icon height.
		float ratio = p_size / float(size.height);
		size.width *= ratio;
		size.height *= ratio;
	}

	class_desc->add_image(icon, size.width, size.height);
}

// Macros for assigning the deprecated/experimental marks to class members in overview.

#define DEPRECATED_DOC_TAG                                                                   \
	class_desc->push_font(theme_cache.doc_bold_font);                                        \
	class_desc->push_color(get_theme_color(SNAME("error_color"), EditorStringName(Editor))); \
	Ref<Texture2D> error_icon = get_editor_theme_icon(SNAME("StatusError"));                 \
	class_desc->add_image(error_icon, error_icon->get_width(), error_icon->get_height());    \
	class_desc->add_text(String::chr(160) + TTR("Deprecated"));                              \
	class_desc->pop();                                                                       \
	class_desc->pop();

#define EXPERIMENTAL_DOC_TAG                                                                    \
	class_desc->push_font(theme_cache.doc_bold_font);                                           \
	class_desc->push_color(get_theme_color(SNAME("warning_color"), EditorStringName(Editor)));  \
	Ref<Texture2D> warning_icon = get_editor_theme_icon(SNAME("NodeWarning"));                  \
	class_desc->add_image(warning_icon, warning_icon->get_width(), warning_icon->get_height()); \
	class_desc->add_text(String::chr(160) + TTR("Experimental"));                               \
	class_desc->pop();                                                                          \
	class_desc->pop();

// Macros for displaying the deprecated/experimental info in class member descriptions.

#define DEPRECATED_DOC_MSG(m_message, m_default_message)                                     \
	Ref<Texture2D> error_icon = get_editor_theme_icon(SNAME("StatusError"));                 \
	class_desc->add_image(error_icon, error_icon->get_width(), error_icon->get_height());    \
	class_desc->add_text(nbsp);                                                              \
	class_desc->push_color(get_theme_color(SNAME("error_color"), EditorStringName(Editor))); \
	class_desc->push_font(theme_cache.doc_bold_font);                                        \
	class_desc->add_text(TTR("Deprecated:"));                                                \
	class_desc->pop();                                                                       \
	class_desc->pop();                                                                       \
	class_desc->add_text(" ");                                                               \
	if ((m_message).is_empty()) {                                                            \
		class_desc->add_text(m_default_message);                                             \
	} else {                                                                                 \
		_add_text(m_message);                                                                \
	}

#define EXPERIMENTAL_DOC_MSG(m_message, m_default_message)                                      \
	Ref<Texture2D> warning_icon = get_editor_theme_icon(SNAME("NodeWarning"));                  \
	class_desc->add_image(warning_icon, warning_icon->get_width(), warning_icon->get_height()); \
	class_desc->add_text(nbsp);                                                                 \
	class_desc->push_color(get_theme_color(SNAME("warning_color"), EditorStringName(Editor)));  \
	class_desc->push_font(theme_cache.doc_bold_font);                                           \
	class_desc->add_text(TTR("Experimental:"));                                                 \
	class_desc->pop();                                                                          \
	class_desc->pop();                                                                          \
	class_desc->add_text(" ");                                                                  \
	if ((m_message).is_empty()) {                                                               \
		class_desc->add_text(m_default_message);                                                \
	} else {                                                                                    \
		_add_text(m_message);                                                                   \
	}

void EditorHelp::_add_method(const DocData::MethodDoc &p_method, bool p_overview, bool p_override) {
	if (p_override) {
		method_line[p_method.name] = class_desc->get_paragraph_count() - 2; // Gets overridden if description.
	}

	const bool is_vararg = p_method.qualifiers.contains("vararg");

	if (p_overview) {
		class_desc->push_cell();
		class_desc->push_paragraph(HORIZONTAL_ALIGNMENT_RIGHT, Control::TEXT_DIRECTION_AUTO, "");
	} else {
		_add_bulletpoint();
	}

	_add_type(p_method.return_type, p_method.return_enum, p_method.return_is_bitfield);

	if (p_overview) {
		class_desc->pop(); // paragraph
		class_desc->pop(); // cell
		class_desc->push_cell();
	} else {
		class_desc->add_text(" ");
	}

	const bool is_documented = p_method.is_deprecated || p_method.is_experimental || !p_method.description.strip_edges().is_empty();

	if (p_overview && is_documented) {
		class_desc->push_meta("@method " + p_method.name, RichTextLabel::META_UNDERLINE_ON_HOVER);
	}

	class_desc->push_color(theme_cache.headline_color);
	class_desc->add_text(p_method.name);
	class_desc->pop(); // color

	if (p_overview && is_documented) {
		class_desc->pop(); // meta
	}

	class_desc->push_color(theme_cache.symbol_color);
	class_desc->add_text("(");
	class_desc->pop(); // color

	for (int j = 0; j < p_method.arguments.size(); j++) {
		const DocData::ArgumentDoc &argument = p_method.arguments[j];

		class_desc->push_color(theme_cache.text_color);

		if (j > 0) {
			class_desc->add_text(", ");
		}

		class_desc->add_text(argument.name);
		class_desc->add_text(colon_nbsp);
		_add_type(argument.type, argument.enumeration, argument.is_bitfield);

		if (!argument.default_value.is_empty()) {
			class_desc->push_color(theme_cache.symbol_color);
			class_desc->add_text(nbsp_equal_nbsp);
			class_desc->pop(); // color

			class_desc->push_color(theme_cache.value_color);
			class_desc->add_text(_fix_constant(argument.default_value));
			class_desc->pop(); // color
		}

		class_desc->pop(); // color
	}

	if (is_vararg) {
		if (!p_method.arguments.is_empty()) {
			class_desc->push_color(theme_cache.text_color);
			class_desc->add_text(", ");
			class_desc->pop(); // color
		}

		class_desc->push_color(theme_cache.symbol_color);
		class_desc->add_text("...");
		class_desc->pop(); // color
	}

	class_desc->push_color(theme_cache.symbol_color);
	class_desc->add_text(")");
	class_desc->pop(); // color

	if (!p_method.qualifiers.is_empty()) {
		class_desc->push_color(theme_cache.qualifier_color);
		_add_qualifiers_to_rt(p_method.qualifiers, class_desc);
		class_desc->pop(); // color
	}

	if (p_overview) {
		if (p_method.is_deprecated) {
			class_desc->add_text(" ");
			DEPRECATED_DOC_TAG;
		}

		if (p_method.is_experimental) {
			class_desc->add_text(" ");
			EXPERIMENTAL_DOC_TAG;
		}

		class_desc->pop(); // cell
	}
}

void EditorHelp::_add_bulletpoint() {
	static const char32_t prefix[3] = { 0x25CF /* filled circle */, ' ', 0 };
	class_desc->add_text(String(prefix));
}

void EditorHelp::_push_normal_font() {
	class_desc->push_font(theme_cache.doc_font);
	class_desc->push_font_size(theme_cache.doc_font_size);
}

void EditorHelp::_pop_normal_font() {
	class_desc->pop(); // font_size
	class_desc->pop(); // font
}

void EditorHelp::_push_title_font() {
	class_desc->push_font(theme_cache.doc_title_font);
	class_desc->push_font_size(theme_cache.doc_title_font_size);
	class_desc->push_color(theme_cache.title_color);
}

void EditorHelp::_pop_title_font() {
	class_desc->pop(); // color
	class_desc->pop(); // font_size
	class_desc->pop(); // font
}

void EditorHelp::_push_code_font() {
	class_desc->push_font(theme_cache.doc_code_font);
	class_desc->push_font_size(theme_cache.doc_code_font_size);
}

void EditorHelp::_pop_code_font() {
	class_desc->pop(); // font_size
	class_desc->pop(); // font
}

Error EditorHelp::_goto_desc(const String &p_class) {
	// If class doesn't have docs listed, attempt on-demand docgen
	if (!doc->class_list.has(p_class) && !_attempt_doc_load(p_class)) {
		return ERR_DOES_NOT_EXIST;
	}

	select_locked = true;

	class_desc->show();

	description_line = 0;

	if (p_class == edited_class) {
		return OK; // Already there.
	}

	edited_class = p_class;
	_update_doc();
	return OK;
}

void EditorHelp::_update_method_list(MethodType p_method_type, const Vector<DocData::MethodDoc> &p_methods) {
	class_desc->add_newline();
	class_desc->add_newline();

	static const char *titles_by_type[METHOD_TYPE_MAX] = {
		TTRC("Methods"),
		TTRC("Constructors"),
		TTRC("Operators"),
	};
	const String title = TTRGET(titles_by_type[p_method_type]);

	section_line.push_back(Pair<String, int>(title, class_desc->get_paragraph_count() - 2));
	_push_title_font();
	class_desc->add_text(title);
	_pop_title_font();

	class_desc->add_newline();
	class_desc->add_newline();

	class_desc->push_indent(1);
	_push_code_font();
	class_desc->push_table(2);
	class_desc->set_table_column_expand(1, true);

	bool any_previous = false;
	for (int pass = 0; pass < 2; pass++) {
		Vector<DocData::MethodDoc> m;

		for (const DocData::MethodDoc &method : p_methods) {
			const String &q = method.qualifiers;
			if ((pass == 0 && q.contains("virtual")) || (pass == 1 && !q.contains("virtual"))) {
				m.push_back(method);
			}
		}

		if (any_previous && !m.is_empty()) {
			class_desc->push_cell();
			class_desc->pop(); // cell
			class_desc->push_cell();
			class_desc->pop(); // cell
		}

		String group_prefix;
		for (int i = 0; i < m.size(); i++) {
			const String new_prefix = m[i].name.left(3);
			bool is_new_group = false;

			if (i < m.size() - 1 && new_prefix == m[i + 1].name.left(3) && new_prefix != group_prefix) {
				is_new_group = i > 0;
				group_prefix = new_prefix;
			} else if (!group_prefix.is_empty() && new_prefix != group_prefix) {
				is_new_group = true;
				group_prefix = "";
			}

			if (is_new_group && pass == 1) {
				class_desc->push_cell();
				class_desc->pop(); // cell
				class_desc->push_cell();
				class_desc->pop(); // cell
			}

			// For constructors always point to the first one.
			_add_method(m[i], true, (p_method_type != METHOD_TYPE_CONSTRUCTOR || i == 0));
		}

		any_previous = !m.is_empty();
	}

	class_desc->pop(); // table
	_pop_code_font();
	class_desc->pop(); // indent
}

void EditorHelp::_update_method_descriptions(const DocData::ClassDoc &p_classdoc, MethodType p_method_type, const Vector<DocData::MethodDoc> &p_methods) {
#define HANDLE_DOC(m_string) ((p_classdoc.is_script_doc ? (m_string) : DTR(m_string)).strip_edges())

	class_desc->add_newline();
	class_desc->add_newline();
	class_desc->add_newline();

	static const char *titles_by_type[METHOD_TYPE_MAX] = {
		TTRC("Method Descriptions"),
		TTRC("Constructor Descriptions"),
		TTRC("Operator Descriptions"),
	};
	const String title = TTRGET(titles_by_type[p_method_type]);

	section_line.push_back(Pair<String, int>(title, class_desc->get_paragraph_count() - 2));
	_push_title_font();
	class_desc->add_text(title);
	_pop_title_font();

	String link_color_text = theme_cache.title_color.to_html(false);

	for (int pass = 0; pass < 2; pass++) {
		Vector<DocData::MethodDoc> methods_filtered;

		for (int i = 0; i < p_methods.size(); i++) {
			const String &q = p_methods[i].qualifiers;
			if ((pass == 0 && q.contains("virtual")) || (pass == 1 && !q.contains("virtual"))) {
				methods_filtered.push_back(p_methods[i]);
			}
		}

		for (int i = 0; i < methods_filtered.size(); i++) {
			const DocData::MethodDoc &method = methods_filtered[i];

			class_desc->add_newline();
			class_desc->add_newline();
			class_desc->add_newline();

			_push_code_font();
			// For constructors always point to the first one.
			_add_method(method, false, (p_method_type != METHOD_TYPE_CONSTRUCTOR || i == 0));
			_pop_code_font();

			class_desc->add_newline();
			class_desc->add_newline();

			class_desc->push_indent(1);
			_push_normal_font();
			class_desc->push_color(theme_cache.text_color);

			bool has_prev_text = false;

			if (method.is_deprecated) {
				has_prev_text = true;

				static const char *messages_by_type[METHOD_TYPE_MAX] = {
					TTRC("This method may be changed or removed in future versions."),
					TTRC("This constructor may be changed or removed in future versions."),
					TTRC("This operator may be changed or removed in future versions."),
				};
				DEPRECATED_DOC_MSG(HANDLE_DOC(method.deprecated_message), TTRGET(messages_by_type[p_method_type]));
			}

			if (method.is_experimental) {
				if (has_prev_text) {
					class_desc->add_newline();
					class_desc->add_newline();
				}
				has_prev_text = true;

				static const char *messages_by_type[METHOD_TYPE_MAX] = {
					TTRC("This method may be changed or removed in future versions."),
					TTRC("This constructor may be changed or removed in future versions."),
					TTRC("This operator may be changed or removed in future versions."),
				};
				EXPERIMENTAL_DOC_MSG(HANDLE_DOC(method.experimental_message), TTRGET(messages_by_type[p_method_type]));
			}

			if (!method.errors_returned.is_empty()) {
				if (has_prev_text) {
					class_desc->add_newline();
					class_desc->add_newline();
				}
				has_prev_text = true;

				class_desc->add_text(TTR("Error codes returned:"));
				class_desc->add_newline();
				class_desc->push_list(0, RichTextLabel::LIST_DOTS, false);
				for (int j = 0; j < method.errors_returned.size(); j++) {
					if (j > 0) {
						class_desc->add_newline();
					}

					int val = method.errors_returned[j];
					String text = itos(val);
					for (int k = 0; k < CoreConstants::get_global_constant_count(); k++) {
						if (CoreConstants::get_global_constant_value(k) == val && CoreConstants::get_global_constant_enum(k) == SNAME("Error")) {
							text = CoreConstants::get_global_constant_name(k);
							break;
						}
					}

					class_desc->push_font(theme_cache.doc_bold_font);
					class_desc->add_text(text);
					class_desc->pop(); // font
				}
				class_desc->pop(); // list
			}

			const String descr = HANDLE_DOC(method.description);
			const bool is_documented = method.is_deprecated || method.is_experimental || !descr.is_empty();
			if (!descr.is_empty()) {
				if (has_prev_text) {
					class_desc->add_newline();
					class_desc->add_newline();
				}
				has_prev_text = true;

				_add_text(descr);
			} else if (!is_documented) {
				if (has_prev_text) {
					class_desc->add_newline();
					class_desc->add_newline();
				}
				has_prev_text = true;

				String message;
				if (p_classdoc.is_script_doc) {
					static const char *messages_by_type[METHOD_TYPE_MAX] = {
						TTRC("There is currently no description for this method."),
						TTRC("There is currently no description for this constructor."),
						TTRC("There is currently no description for this operator."),
					};
					message = TTRGET(messages_by_type[p_method_type]);
				} else {
					static const char *messages_by_type[METHOD_TYPE_MAX] = {
						TTRC("There is currently no description for this method. Please help us by [color=$color][url=$url]contributing one[/url][/color]!"),
						TTRC("There is currently no description for this constructor. Please help us by [color=$color][url=$url]contributing one[/url][/color]!"),
						TTRC("There is currently no description for this operator. Please help us by [color=$color][url=$url]contributing one[/url][/color]!"),
					};
					message = TTRGET(messages_by_type[p_method_type]).replace("$url", CONTRIBUTE_URL).replace("$color", link_color_text);
				}

				class_desc->add_image(get_editor_theme_icon(SNAME("Error")));
				class_desc->add_text(" ");
				class_desc->push_color(theme_cache.comment_color);
				class_desc->append_text(message);
				class_desc->pop(); // color
			}

			class_desc->pop(); // color
			_pop_normal_font();
			class_desc->pop(); // indent
		}
	}

#undef HANDLE_DOC
}

void EditorHelp::_update_doc() {
	if (!doc->class_list.has(edited_class)) {
		return;
	}

	scroll_locked = true;

	class_desc->clear();
	method_line.clear();
	section_line.clear();
	section_line.push_back(Pair<String, int>(TTR("Top"), 0));

	String link_color_text = theme_cache.title_color.to_html(false);

	DocData::ClassDoc cd = doc->class_list[edited_class]; // Make a copy, so we can sort without worrying.

#define HANDLE_DOC(m_string) ((cd.is_script_doc ? (m_string) : DTR(m_string)).strip_edges())

	// Class name

	_push_title_font();

	class_desc->add_text(TTR("Class:") + " ");
	_add_type_icon(edited_class, theme_cache.doc_title_font_size, "Object");
	class_desc->add_text(nbsp);

	class_desc->push_color(theme_cache.headline_color);
	class_desc->add_text(edited_class);
	class_desc->pop(); // color

	_pop_title_font();

	if (cd.is_deprecated) {
		class_desc->add_newline();
		DEPRECATED_DOC_MSG(HANDLE_DOC(cd.deprecated_message), TTR("This class may be changed or removed in future versions."));
	}

	if (cd.is_experimental) {
		class_desc->add_newline();
		EXPERIMENTAL_DOC_MSG(HANDLE_DOC(cd.experimental_message), TTR("This class may be changed or removed in future versions."));
	}

	// Inheritance tree

	// Ascendents
	if (!cd.inherits.is_empty()) {
		class_desc->add_newline();

		_push_normal_font();
		class_desc->push_color(theme_cache.title_color);

		class_desc->add_text(TTR("Inherits:") + " ");

		String inherits = cd.inherits;
		while (!inherits.is_empty()) {
			_add_type_icon(inherits, theme_cache.doc_font_size, "ArrowRight");
			class_desc->add_text(nbsp); // Otherwise icon borrows hyperlink from `_add_type()`.
			_add_type(inherits);

			inherits = doc->class_list[inherits].inherits;

			if (!inherits.is_empty()) {
				class_desc->add_text(" < ");
			}
		}

		class_desc->pop(); // color
		_pop_normal_font();
	}

	// Descendants
	if ((cd.is_script_doc || ClassDB::class_exists(cd.name)) && doc->inheriting.has(cd.name)) {
		class_desc->add_newline();

		_push_normal_font();
		class_desc->push_color(theme_cache.title_color);
		class_desc->add_text(TTR("Inherited by:") + " ");

		for (RBSet<String, NaturalNoCaseComparator>::Element *itr = doc->inheriting[cd.name].front(); itr; itr = itr->next()) {
			if (itr->prev()) {
				class_desc->add_text(" , ");
			}

			_add_type_icon(itr->get(), theme_cache.doc_font_size, "ArrowRight");
			class_desc->add_text(nbsp); // Otherwise icon borrows hyperlink from `_add_type()`.
			_add_type(itr->get());
		}

		class_desc->pop(); // color
		_pop_normal_font();
	}

	bool has_description = false;

	// Brief description
	const String brief_class_descr = HANDLE_DOC(cd.brief_description);
	if (!brief_class_descr.is_empty()) {
		has_description = true;

		class_desc->add_newline();
		class_desc->add_newline();

		class_desc->push_indent(1);
		class_desc->push_font(theme_cache.doc_bold_font);
		class_desc->push_color(theme_cache.text_color);

		_add_text(brief_class_descr);

		class_desc->pop(); // color
		class_desc->pop(); // font
		class_desc->pop(); // indent
	}

	// Class description
	const String class_descr = HANDLE_DOC(cd.description);
	if (!class_descr.is_empty()) {
		has_description = true;

		class_desc->add_newline();
		class_desc->add_newline();

		section_line.push_back(Pair<String, int>(TTR("Description"), class_desc->get_paragraph_count() - 2));
		description_line = class_desc->get_paragraph_count() - 2;
		_push_title_font();
		class_desc->add_text(TTR("Description"));
		_pop_title_font();

		class_desc->add_newline();
		class_desc->add_newline();

		class_desc->push_indent(1);
		_push_normal_font();
		class_desc->push_color(theme_cache.text_color);

		_add_text(class_descr);

		class_desc->pop(); // color
		_pop_normal_font();
		class_desc->pop(); // indent
	}

	if (!has_description) {
		class_desc->add_newline();
		class_desc->add_newline();

		class_desc->push_indent(1);
		_push_normal_font();

		class_desc->add_image(get_editor_theme_icon(SNAME("Error")));
		class_desc->add_text(" ");

		class_desc->push_color(theme_cache.comment_color);
		if (cd.is_script_doc) {
			class_desc->add_text(TTR("There is currently no description for this class."));
		} else {
			class_desc->append_text(TTR("There is currently no description for this class. Please help us by [color=$color][url=$url]contributing one[/url][/color]!").replace("$url", CONTRIBUTE_URL).replace("$color", link_color_text));
		}
		class_desc->pop(); // color

		_pop_normal_font();
		class_desc->pop(); // indent
	}

#ifdef MODULE_MONO_ENABLED
	if (classes_with_csharp_differences.has(cd.name)) {
		class_desc->add_newline();
		class_desc->add_newline();

		const String &csharp_differences_url = vformat("%s/tutorials/scripting/c_sharp/c_sharp_differences.html", VERSION_DOCS_URL);

		class_desc->push_indent(1);
		_push_normal_font();
		class_desc->push_color(theme_cache.text_color);

		class_desc->append_text("[b]" + TTR("Note:") + "[/b] " + vformat(TTR("There are notable differences when using this API with C#. See [url=%s]C# API differences to GDScript[/url] for more information."), csharp_differences_url));

		class_desc->pop(); // color
		_pop_normal_font();
		class_desc->pop(); // indent
	}
#endif

	// Online tutorials
	if (!cd.tutorials.is_empty()) {
		class_desc->add_newline();
		class_desc->add_newline();

		_push_title_font();
		class_desc->add_text(TTR("Online Tutorials"));
		_pop_title_font();

		class_desc->add_newline();

		class_desc->push_indent(1);
		_push_code_font();
		class_desc->push_color(theme_cache.symbol_color);

		for (const DocData::TutorialDoc &tutorial : cd.tutorials) {
			const String link = HANDLE_DOC(tutorial.link);

			String link_text = HANDLE_DOC(tutorial.title);
			if (link_text.is_empty()) {
				const int sep_pos = link.find("//");
				if (sep_pos >= 0) {
					link_text = link.substr(sep_pos + 2);
				} else {
					link_text = link;
				}
			}

			class_desc->add_newline();
			_add_bulletpoint();
			class_desc->append_text("[url=" + link + "]" + link_text + "[/url]");
		}

		class_desc->pop(); // color
		_pop_code_font();
		class_desc->pop(); // indent
	}

	// Properties overview
	HashSet<String> skip_methods;

	bool has_properties = false;
	bool has_property_descriptions = false;
	for (const DocData::PropertyDoc &prop : cd.properties) {
		const bool is_documented = prop.is_deprecated || prop.is_experimental || !prop.description.strip_edges().is_empty();
		if (!is_documented && prop.name.begins_with("_")) {
			continue;
		}
		has_properties = true;
		if (!prop.overridden) {
			has_property_descriptions = true;
			break;
		}
	}

	if (has_properties) {
		class_desc->add_newline();
		class_desc->add_newline();

		section_line.push_back(Pair<String, int>(TTR("Properties"), class_desc->get_paragraph_count() - 2));
		_push_title_font();
		class_desc->add_text(TTR("Properties"));
		_pop_title_font();

		class_desc->add_newline();
		class_desc->add_newline();

		class_desc->push_indent(1);
		_push_code_font();
		class_desc->push_table(4);
		class_desc->set_table_column_expand(1, true);

		cd.properties.sort_custom<PropertyCompare>();

		bool is_generating_overridden_properties = true; // Set to false as soon as we encounter a non-overridden property.
		bool overridden_property_exists = false;

		for (const DocData::PropertyDoc &prop : cd.properties) {
			// Ignore undocumented private.
			const bool is_documented = prop.is_deprecated || prop.is_experimental || !prop.description.strip_edges().is_empty();
			if (!is_documented && prop.name.begins_with("_")) {
				continue;
			}

			if (is_generating_overridden_properties && !prop.overridden) {
				is_generating_overridden_properties = false;
				// No need for the extra spacing when there's no overridden property.
				if (overridden_property_exists) {
					class_desc->push_cell();
					class_desc->pop(); // cell
					class_desc->push_cell();
					class_desc->pop(); // cell
					class_desc->push_cell();
					class_desc->pop(); // cell
					class_desc->push_cell();
					class_desc->pop(); // cell
				}
			}

			property_line[prop.name] = class_desc->get_paragraph_count() - 2; // Gets overridden if description.

			// Property type.
			class_desc->push_cell();
			class_desc->push_paragraph(HORIZONTAL_ALIGNMENT_RIGHT, Control::TEXT_DIRECTION_AUTO, "");
			_add_type(prop.type, prop.enumeration, prop.is_bitfield);
			class_desc->pop(); // paragraph
			class_desc->pop(); // cell

			bool describe = false;

			if (!prop.setter.is_empty()) {
				skip_methods.insert(prop.setter);
				describe = true;
			}
			if (!prop.getter.is_empty()) {
				skip_methods.insert(prop.getter);
				describe = true;
			}

			if (is_documented) {
				describe = true;
			}

			if (prop.overridden) {
				describe = false;
			}

			// Property name.
			class_desc->push_cell();
			class_desc->push_color(theme_cache.headline_color);

			if (describe) {
				class_desc->push_meta("@member " + prop.name, RichTextLabel::META_UNDERLINE_ON_HOVER);
			}

			class_desc->add_text(prop.name);

			if (describe) {
				class_desc->pop(); // meta
			}

			class_desc->pop(); // color
			class_desc->pop(); // cell

			// Property value.
			class_desc->push_cell();

			if (!prop.default_value.is_empty()) {
				if (prop.overridden) {
					class_desc->push_color(theme_cache.override_color);
					class_desc->add_text("[");
					const String link = vformat("[url=@member %s.%s]%s[/url]", prop.overrides, prop.name, prop.overrides);
					class_desc->append_text(vformat(TTR("overrides %s:"), link));
					class_desc->add_text(" " + _fix_constant(prop.default_value) + "]");
					class_desc->pop(); // color
					overridden_property_exists = true;
				} else {
					class_desc->push_color(theme_cache.symbol_color);
					class_desc->add_text("[" + TTR("default:") + " ");
					class_desc->pop(); // color

					class_desc->push_color(theme_cache.value_color);
					class_desc->add_text(_fix_constant(prop.default_value));
					class_desc->pop(); // color

					class_desc->push_color(theme_cache.symbol_color);
					class_desc->add_text("]");
					class_desc->pop(); // color
				}
			}

			class_desc->pop(); // cell

			// Property setter/getter and deprecated/experimental marks.
			class_desc->push_cell();

			bool has_prev_text = false;

			if (cd.is_script_doc && (!prop.setter.is_empty() || !prop.getter.is_empty())) {
				has_prev_text = true;

				class_desc->push_color(theme_cache.symbol_color);
				class_desc->add_text("[" + TTR("property:") + " ");
				class_desc->pop(); // color

				if (!prop.setter.is_empty()) {
					class_desc->push_color(theme_cache.value_color);
					class_desc->add_text("setter");
					class_desc->pop(); // color
				}
				if (!prop.getter.is_empty()) {
					if (!prop.setter.is_empty()) {
						class_desc->push_color(theme_cache.symbol_color);
						class_desc->add_text(", ");
						class_desc->pop(); // color
					}
					class_desc->push_color(theme_cache.value_color);
					class_desc->add_text("getter");
					class_desc->pop(); // color
				}

				class_desc->push_color(theme_cache.symbol_color);
				class_desc->add_text("]");
				class_desc->pop(); // color
			}

			if (prop.is_deprecated) {
				if (has_prev_text) {
					class_desc->add_text(" ");
				}
				has_prev_text = true;
				DEPRECATED_DOC_TAG;
			}

			if (prop.is_experimental) {
				if (has_prev_text) {
					class_desc->add_text(" ");
				}
				has_prev_text = true;
				EXPERIMENTAL_DOC_TAG;
			}

			class_desc->pop(); // cell
		}

		class_desc->pop(); // table
		_pop_code_font();
		class_desc->pop(); // indent
	}

	// Methods overview
	bool sort_methods = EDITOR_GET("text_editor/help/sort_functions_alphabetically");

	Vector<DocData::MethodDoc> methods;

	for (const DocData::MethodDoc &method : cd.methods) {
		if (skip_methods.has(method.name)) {
			if (method.arguments.is_empty() /* getter */ || (method.arguments.size() == 1 && method.return_type == "void" /* setter */)) {
				continue;
			}
		}
		// Ignore undocumented non virtual private.
		const bool is_documented = method.is_deprecated || method.is_experimental || !method.description.strip_edges().is_empty();
		if (!is_documented && method.name.begins_with("_") && !method.qualifiers.contains("virtual")) {
			continue;
		}
		methods.push_back(method);
	}

	if (!cd.constructors.is_empty()) {
		if (sort_methods) {
			cd.constructors.sort();
		}
		_update_method_list(METHOD_TYPE_CONSTRUCTOR, cd.constructors);
	}

	if (!methods.is_empty()) {
		if (sort_methods) {
			methods.sort();
		}
		_update_method_list(METHOD_TYPE_METHOD, methods);
	}

	if (!cd.operators.is_empty()) {
		if (sort_methods) {
			cd.operators.sort();
		}
		_update_method_list(METHOD_TYPE_OPERATOR, cd.operators);
	}

	// Theme properties
	if (!cd.theme_properties.is_empty()) {
		class_desc->add_newline();
		class_desc->add_newline();

		section_line.push_back(Pair<String, int>(TTR("Theme Properties"), class_desc->get_paragraph_count() - 2));
		_push_title_font();
		class_desc->add_text(TTR("Theme Properties"));
		_pop_title_font();

		String theme_data_type;
		HashMap<String, String> data_type_names;
		data_type_names["color"] = TTR("Colors");
		data_type_names["constant"] = TTR("Constants");
		data_type_names["font"] = TTR("Fonts");
		data_type_names["font_size"] = TTR("Font Sizes");
		data_type_names["icon"] = TTR("Icons");
		data_type_names["style"] = TTR("Styles");

		for (const DocData::ThemeItemDoc &theme_item : cd.theme_properties) {
			if (theme_data_type != theme_item.data_type) {
				theme_data_type = theme_item.data_type;

				class_desc->add_newline();
				class_desc->add_newline();

				class_desc->push_indent(1);
				_push_title_font();

				if (data_type_names.has(theme_data_type)) {
					class_desc->add_text(data_type_names[theme_data_type]);
				} else {
					class_desc->add_text(theme_data_type);
				}

				_pop_title_font();
				class_desc->pop(); // indent
			}

			class_desc->add_newline();
			class_desc->add_newline();

			theme_property_line[theme_item.name] = class_desc->get_paragraph_count() - 2; // Gets overridden if description.

			class_desc->push_indent(1);

			// Theme item header.
			_push_code_font();
			_add_bulletpoint();

			// Theme item object type.
			_add_type(theme_item.type);

			// Theme item name.
			class_desc->push_color(theme_cache.headline_color);
			class_desc->add_text(" ");
			class_desc->add_text(theme_item.name);
			class_desc->pop(); // color

			// Theme item default value.
			if (!theme_item.default_value.is_empty()) {
				class_desc->push_color(theme_cache.symbol_color);
				class_desc->add_text(" [" + TTR("default:") + " ");
				class_desc->pop(); // color

				class_desc->push_color(theme_cache.value_color);
				class_desc->add_text(_fix_constant(theme_item.default_value));
				class_desc->pop(); // color

				class_desc->push_color(theme_cache.symbol_color);
				class_desc->add_text("]");
				class_desc->pop(); // color
			}

			_pop_code_font();

			// Theme item description.
			class_desc->push_indent(1);
			_push_normal_font();
			class_desc->push_color(theme_cache.comment_color);

			bool has_prev_text = false;

			if (theme_item.is_deprecated) {
				has_prev_text = true;
				DEPRECATED_DOC_MSG(HANDLE_DOC(theme_item.deprecated_message), TTR("This theme property may be changed or removed in future versions."));
			}

			if (theme_item.is_experimental) {
				if (has_prev_text) {
					class_desc->add_newline();
					class_desc->add_newline();
				}
				has_prev_text = true;
				EXPERIMENTAL_DOC_MSG(HANDLE_DOC(theme_item.experimental_message), TTR("This theme property may be changed or removed in future versions."));
			}

			const String descr = HANDLE_DOC(theme_item.description);
			if (!descr.is_empty()) {
				if (has_prev_text) {
					class_desc->add_newline();
					class_desc->add_newline();
				}
				has_prev_text = true;
				_add_text(descr);
			} else if (!has_prev_text) {
				class_desc->add_image(get_editor_theme_icon(SNAME("Error")));
				class_desc->add_text(" ");
				class_desc->push_color(theme_cache.comment_color);
				if (cd.is_script_doc) {
					class_desc->add_text(TTR("There is currently no description for this theme property."));
				} else {
					class_desc->append_text(TTR("There is currently no description for this theme property. Please help us by [color=$color][url=$url]contributing one[/url][/color]!").replace("$url", CONTRIBUTE_URL).replace("$color", link_color_text));
				}
				class_desc->pop(); // color
			}

			class_desc->pop(); // color
			_pop_normal_font();
			class_desc->pop(); // indent

			class_desc->pop(); // indent
		}
	}

	// Signals
	if (!cd.signals.is_empty()) {
		if (sort_methods) {
			cd.signals.sort();
		}

		class_desc->add_newline();
		class_desc->add_newline();

		section_line.push_back(Pair<String, int>(TTR("Signals"), class_desc->get_paragraph_count() - 2));
		_push_title_font();
		class_desc->add_text(TTR("Signals"));
		_pop_title_font();

		for (const DocData::MethodDoc &signal : cd.signals) {
			class_desc->add_newline();
			class_desc->add_newline();

			signal_line[signal.name] = class_desc->get_paragraph_count() - 2; // Gets overridden if description.

			class_desc->push_indent(1);

			// Signal header.
			_push_code_font();
			_add_bulletpoint();
			class_desc->push_color(theme_cache.headline_color);
			class_desc->add_text(signal.name);
			class_desc->pop(); // color

			class_desc->push_color(theme_cache.symbol_color);
			class_desc->add_text("(");
			class_desc->pop(); // color

			for (int j = 0; j < signal.arguments.size(); j++) {
				const DocData::ArgumentDoc &argument = signal.arguments[j];

				class_desc->push_color(theme_cache.text_color);

				if (j > 0) {
					class_desc->add_text(", ");
				}

				class_desc->add_text(argument.name);
				class_desc->add_text(colon_nbsp);
				_add_type(argument.type, argument.enumeration, argument.is_bitfield);

				// Signals currently do not support default argument values, neither the core nor GDScript.
				// This code is just for completeness.
				if (!argument.default_value.is_empty()) {
					class_desc->push_color(theme_cache.symbol_color);
					class_desc->add_text(nbsp_equal_nbsp);
					class_desc->pop(); // color

					class_desc->push_color(theme_cache.value_color);
					class_desc->add_text(_fix_constant(argument.default_value));
					class_desc->pop(); // color
				}

				class_desc->pop(); // color
			}

			class_desc->push_color(theme_cache.symbol_color);
			class_desc->add_text(")");
			class_desc->pop(); // color

			_pop_code_font();

			class_desc->add_newline();

			// Signal description.
			class_desc->push_indent(1);
			_push_normal_font();
			class_desc->push_color(theme_cache.comment_color);

			const String descr = HANDLE_DOC(signal.description);
			const bool is_multiline = descr.find_char('\n') > 0;
			bool has_prev_text = false;

			if (signal.is_deprecated) {
				has_prev_text = true;
				DEPRECATED_DOC_MSG(HANDLE_DOC(signal.deprecated_message), TTR("This signal may be changed or removed in future versions."));
			}

			if (signal.is_experimental) {
				if (has_prev_text) {
					class_desc->add_newline();
					if (is_multiline) {
						class_desc->add_newline();
					}
				}
				has_prev_text = true;
				EXPERIMENTAL_DOC_MSG(HANDLE_DOC(signal.experimental_message), TTR("This signal may be changed or removed in future versions."));
			}

			if (!descr.is_empty()) {
				if (has_prev_text) {
					class_desc->add_newline();
					if (is_multiline) {
						class_desc->add_newline();
					}
				}
				has_prev_text = true;
				_add_text(descr);
			} else if (!has_prev_text) {
				class_desc->add_image(get_editor_theme_icon(SNAME("Error")));
				class_desc->add_text(" ");
				class_desc->push_color(theme_cache.comment_color);
				if (cd.is_script_doc) {
					class_desc->add_text(TTR("There is currently no description for this signal."));
				} else {
					class_desc->append_text(TTR("There is currently no description for this signal. Please help us by [color=$color][url=$url]contributing one[/url][/color]!").replace("$url", CONTRIBUTE_URL).replace("$color", link_color_text));
				}
				class_desc->pop(); // color
			}

			class_desc->pop(); // color
			_pop_normal_font();
			class_desc->pop(); // indent

			class_desc->pop(); // indent
		}
	}

	// Constants and enums
	if (!cd.constants.is_empty()) {
		HashMap<String, Vector<DocData::ConstantDoc>> enums;
		Vector<DocData::ConstantDoc> constants;

		for (const DocData::ConstantDoc &constant : cd.constants) {
			if (!constant.enumeration.is_empty()) {
				if (!enums.has(constant.enumeration)) {
					enums[constant.enumeration] = Vector<DocData::ConstantDoc>();
				}

				enums[constant.enumeration].push_back(constant);
			} else {
				// Ignore undocumented private.
				const bool is_documented = constant.is_deprecated || constant.is_experimental || !constant.description.strip_edges().is_empty();
				if (!is_documented && constant.name.begins_with("_")) {
					continue;
				}
				constants.push_back(constant);
			}
		}

		// Enums
		bool has_enums = enums.size() && !cd.is_script_doc;
		if (enums.size() && !has_enums) {
			for (KeyValue<String, DocData::EnumDoc> &E : cd.enums) {
				const bool is_documented = E.value.is_deprecated || E.value.is_experimental || !E.value.description.strip_edges().is_empty();
				if (!is_documented && E.key.begins_with("_")) {
					continue;
				}
				has_enums = true;
				break;
			}
		}
		if (has_enums) {
			class_desc->add_newline();
			class_desc->add_newline();

			section_line.push_back(Pair<String, int>(TTR("Enumerations"), class_desc->get_paragraph_count() - 2));
			_push_title_font();
			class_desc->add_text(TTR("Enumerations"));
			_pop_title_font();

			for (KeyValue<String, Vector<DocData::ConstantDoc>> &E : enums) {
				String key = E.key;
				if ((key.get_slice_count(".") > 1) && (key.get_slice(".", 0) == edited_class)) {
					key = key.get_slice(".", 1);
				}
				if (cd.enums.has(key)) {
					const bool is_documented = cd.enums[key].is_deprecated || cd.enums[key].is_experimental || !cd.enums[key].description.strip_edges().is_empty();
					if (!is_documented && cd.is_script_doc && E.key.begins_with("_")) {
						continue;
					}
				}

				class_desc->add_newline();
				class_desc->add_newline();

				// Enum header.
				_push_code_font();

				enum_line[E.key] = class_desc->get_paragraph_count() - 2;
				class_desc->push_color(theme_cache.title_color);
				if (E.value.size() && E.value[0].is_bitfield) {
					class_desc->add_text("flags ");
				} else {
					class_desc->add_text("enum ");
				}
				class_desc->pop(); // color

				class_desc->push_color(theme_cache.headline_color);
				class_desc->add_text(key);
				class_desc->pop(); // color

				class_desc->push_color(theme_cache.symbol_color);
				class_desc->add_text(":");
				class_desc->pop(); // color

				_pop_code_font();

				// Enum description.
				if (key != "@unnamed_enums" && cd.enums.has(key)) {
					const String descr = HANDLE_DOC(cd.enums[key].description);
					const bool is_multiline = descr.find_char('\n') > 0;
					if (cd.enums[key].is_deprecated || cd.enums[key].is_experimental || !descr.is_empty()) {
						class_desc->add_newline();

						class_desc->push_indent(1);
						_push_normal_font();
						class_desc->push_color(theme_cache.text_color);

						bool has_prev_text = false;

						if (cd.enums[key].is_deprecated) {
							has_prev_text = true;
							DEPRECATED_DOC_MSG(HANDLE_DOC(cd.enums[key].deprecated_message), TTR("This enumeration may be changed or removed in future versions."));
						}

						if (cd.enums[key].is_experimental) {
							if (has_prev_text) {
								class_desc->add_newline();
								if (is_multiline) {
									class_desc->add_newline();
								}
							}
							has_prev_text = true;
							EXPERIMENTAL_DOC_MSG(HANDLE_DOC(cd.enums[key].experimental_message), TTR("This enumeration may be changed or removed in future versions."));
						}

						if (!descr.is_empty()) {
							if (has_prev_text) {
								class_desc->add_newline();
								if (is_multiline) {
									class_desc->add_newline();
								}
							}
							has_prev_text = true;
							_add_text(descr);
						}

						class_desc->pop(); // color
						_pop_normal_font();
						class_desc->pop(); // indent
					}
				}

				HashMap<String, int> enum_values;
				const int enum_start_line = enum_line[E.key];

				bool prev_is_multiline = true; // Use a large margin for the first item.
				for (const DocData::ConstantDoc &enum_value : E.value) {
					const String descr = HANDLE_DOC(enum_value.description);
					const bool is_multiline = descr.find_char('\n') > 0;

					class_desc->add_newline();
					if (prev_is_multiline || is_multiline) {
						class_desc->add_newline();
					}
					prev_is_multiline = is_multiline;

					if (cd.name == "@GlobalScope") {
						enum_values[enum_value.name] = enum_start_line;
					}

					// Add the enum constant line to the constant_line map so we can locate it as a constant.
					constant_line[enum_value.name] = class_desc->get_paragraph_count() - 2;

					class_desc->push_indent(1);

					// Enum value header.
					_push_code_font();
					_add_bulletpoint();

					class_desc->push_color(theme_cache.headline_color);
					class_desc->add_text(enum_value.name);
					class_desc->pop(); // color

					class_desc->push_color(theme_cache.symbol_color);
					class_desc->add_text(nbsp_equal_nbsp);
					class_desc->pop(); // color

					class_desc->push_color(theme_cache.value_color);
					class_desc->add_text(_fix_constant(enum_value.value));
					class_desc->pop(); // color

					_pop_code_font();

					// Enum value description.
					if (enum_value.is_deprecated || enum_value.is_experimental || !descr.is_empty()) {
						class_desc->add_newline();

						class_desc->push_indent(1);
						_push_normal_font();
						class_desc->push_color(theme_cache.comment_color);

						bool has_prev_text = false;

						if (enum_value.is_deprecated) {
							has_prev_text = true;
							DEPRECATED_DOC_MSG(HANDLE_DOC(enum_value.deprecated_message), TTR("This constant may be changed or removed in future versions."));
						}

						if (enum_value.is_experimental) {
							if (has_prev_text) {
								class_desc->add_newline();
								if (is_multiline) {
									class_desc->add_newline();
								}
							}
							has_prev_text = true;
							EXPERIMENTAL_DOC_MSG(HANDLE_DOC(enum_value.experimental_message), TTR("This constant may be changed or removed in future versions."));
						}

						if (!descr.is_empty()) {
							if (has_prev_text) {
								class_desc->add_newline();
								if (is_multiline) {
									class_desc->add_newline();
								}
							}
							has_prev_text = true;
							_add_text(descr);
						}

						class_desc->pop(); // color
						_pop_normal_font();
						class_desc->pop(); // indent
					}

					class_desc->pop(); // indent
				}

				if (cd.name == "@GlobalScope") {
					enum_values_line[E.key] = enum_values;
				}
			}
		}

		// Constants
		if (!constants.is_empty()) {
			class_desc->add_newline();
			class_desc->add_newline();

			section_line.push_back(Pair<String, int>(TTR("Constants"), class_desc->get_paragraph_count() - 2));
			_push_title_font();
			class_desc->add_text(TTR("Constants"));
			_pop_title_font();

			bool prev_is_multiline = true; // Use a large margin for the first item.
			for (const DocData::ConstantDoc &constant : constants) {
				const String descr = HANDLE_DOC(constant.description);
				const bool is_multiline = descr.find_char('\n') > 0;

				class_desc->add_newline();
				if (prev_is_multiline || is_multiline) {
					class_desc->add_newline();
				}
				prev_is_multiline = is_multiline;

				constant_line[constant.name] = class_desc->get_paragraph_count() - 2;

				class_desc->push_indent(1);

				// Constant header.
				_push_code_font();

				if (constant.value.begins_with("Color(") && constant.value.ends_with(")")) {
					String stripped = constant.value.replace(" ", "").replace("Color(", "").replace(")", "");
					PackedFloat64Array color = stripped.split_floats(",");
					if (color.size() >= 3) {
						class_desc->push_color(Color(color[0], color[1], color[2]));
						_add_bulletpoint();
						class_desc->pop(); // color
					}
				} else {
					_add_bulletpoint();
				}

				class_desc->push_color(theme_cache.headline_color);
				class_desc->add_text(constant.name);
				class_desc->pop(); // color

				class_desc->push_color(theme_cache.symbol_color);
				class_desc->add_text(nbsp_equal_nbsp);
				class_desc->pop(); // color

				class_desc->push_color(theme_cache.value_color);
				class_desc->add_text(_fix_constant(constant.value));
				class_desc->pop(); // color

				_pop_code_font();

				// Constant description.
				if (constant.is_deprecated || constant.is_experimental || !descr.is_empty()) {
					class_desc->add_newline();

					class_desc->push_indent(1);
					_push_normal_font();
					class_desc->push_color(theme_cache.comment_color);

					bool has_prev_text = false;

					if (constant.is_deprecated) {
						has_prev_text = true;
						DEPRECATED_DOC_MSG(HANDLE_DOC(constant.deprecated_message), TTR("This constant may be changed or removed in future versions."));
					}

					if (constant.is_experimental) {
						if (has_prev_text) {
							class_desc->add_newline();
							if (is_multiline) {
								class_desc->add_newline();
							}
						}
						has_prev_text = true;
						EXPERIMENTAL_DOC_MSG(HANDLE_DOC(constant.experimental_message), TTR("This constant may be changed or removed in future versions."));
					}

					if (!descr.is_empty()) {
						if (has_prev_text) {
							class_desc->add_newline();
							if (is_multiline) {
								class_desc->add_newline();
							}
						}
						has_prev_text = true;
						_add_text(descr);
					}

					class_desc->pop(); // color
					_pop_normal_font();
					class_desc->pop(); // indent
				}

				class_desc->pop(); // indent
			}
		}
	}

	// Annotations
	if (!cd.annotations.is_empty()) {
		if (sort_methods) {
			cd.annotations.sort();
		}

		class_desc->add_newline();
		class_desc->add_newline();

		section_line.push_back(Pair<String, int>(TTR("Annotations"), class_desc->get_paragraph_count() - 2));
		_push_title_font();
		class_desc->add_text(TTR("Annotations"));
		_pop_title_font();

		for (const DocData::MethodDoc &annotation : cd.annotations) {
			class_desc->add_newline();
			class_desc->add_newline();

			annotation_line[annotation.name] = class_desc->get_paragraph_count() - 2; // Gets overridden if description.

			class_desc->push_indent(1);

			// Annotation header.
			_push_code_font();
			_add_bulletpoint();

			class_desc->push_color(theme_cache.headline_color);
			class_desc->add_text(annotation.name);
			class_desc->pop(); // color

			if (!annotation.arguments.is_empty()) {
				class_desc->push_color(theme_cache.symbol_color);
				class_desc->add_text("(");
				class_desc->pop(); // color

				for (int j = 0; j < annotation.arguments.size(); j++) {
					const DocData::ArgumentDoc &argument = annotation.arguments[j];

					class_desc->push_color(theme_cache.text_color);

					if (j > 0) {
						class_desc->add_text(", ");
					}

					class_desc->add_text(argument.name);
					class_desc->add_text(colon_nbsp);
					_add_type(argument.type, argument.enumeration, argument.is_bitfield);

					if (!argument.default_value.is_empty()) {
						class_desc->push_color(theme_cache.symbol_color);
						class_desc->add_text(nbsp_equal_nbsp);
						class_desc->pop(); // color

						class_desc->push_color(theme_cache.value_color);
						class_desc->add_text(_fix_constant(argument.default_value));
						class_desc->pop(); // color
					}

					class_desc->pop(); // color
				}

				if (annotation.qualifiers.contains("vararg")) {
					if (!annotation.arguments.is_empty()) {
						class_desc->push_color(theme_cache.text_color);
						class_desc->add_text(", ");
						class_desc->pop(); // color
					}

					class_desc->push_color(theme_cache.symbol_color);
					class_desc->add_text("...");
					class_desc->pop(); // color
				}

				class_desc->push_color(theme_cache.symbol_color);
				class_desc->add_text(")");
				class_desc->pop(); // color
			}

			if (!annotation.qualifiers.is_empty()) {
				class_desc->push_color(theme_cache.qualifier_color);
				_add_qualifiers_to_rt(annotation.qualifiers, class_desc);
				class_desc->pop(); // color
			}

			_pop_code_font();

			class_desc->add_newline();

			// Annotation description.
			class_desc->push_indent(1);
			_push_normal_font();
			class_desc->push_color(theme_cache.comment_color);

			const String descr = HANDLE_DOC(annotation.description);
			if (!descr.is_empty()) {
				_add_text(descr);
			} else {
				class_desc->add_image(get_editor_theme_icon(SNAME("Error")));
				class_desc->add_text(" ");
				class_desc->push_color(theme_cache.comment_color);
				if (cd.is_script_doc) {
					class_desc->add_text(TTR("There is currently no description for this annotation."));
				} else {
					class_desc->append_text(TTR("There is currently no description for this annotation. Please help us by [color=$color][url=$url]contributing one[/url][/color]!").replace("$url", CONTRIBUTE_URL).replace("$color", link_color_text));
				}
				class_desc->pop(); // color
			}

			class_desc->pop(); // color
			_pop_normal_font();
			class_desc->pop(); // indent

			class_desc->pop(); // indent
		}
	}

	// Property descriptions
	if (has_property_descriptions) {
		class_desc->add_newline();
		class_desc->add_newline();
		class_desc->add_newline();

		section_line.push_back(Pair<String, int>(TTR("Property Descriptions"), class_desc->get_paragraph_count() - 2));
		_push_title_font();
		class_desc->add_text(TTR("Property Descriptions"));
		_pop_title_font();

		for (const DocData::PropertyDoc &prop : cd.properties) {
			if (prop.overridden) {
				continue;
			}
			// Ignore undocumented private.
			const bool is_documented = prop.is_deprecated || prop.is_experimental || !prop.description.strip_edges().is_empty();
			if (!is_documented && prop.name.begins_with("_")) {
				continue;
			}

			class_desc->add_newline();
			class_desc->add_newline();
			class_desc->add_newline();

			property_line[prop.name] = class_desc->get_paragraph_count() - 2;

			class_desc->push_table(2);
			class_desc->set_table_column_expand(1, true);

			class_desc->push_cell();
			_push_code_font();
			_add_bulletpoint();
			_add_type(prop.type, prop.enumeration, prop.is_bitfield);
			_pop_code_font();
			class_desc->pop(); // cell

			class_desc->push_cell();
			_push_code_font();

			class_desc->push_color(theme_cache.headline_color);
			class_desc->add_text(prop.name);
			class_desc->pop(); // color

			if (!prop.default_value.is_empty()) {
				class_desc->push_color(theme_cache.symbol_color);
				class_desc->add_text(" [" + TTR("default:") + " ");
				class_desc->pop(); // color

				class_desc->push_color(theme_cache.value_color);
				class_desc->add_text(_fix_constant(prop.default_value));
				class_desc->pop(); // color

				class_desc->push_color(theme_cache.symbol_color);
				class_desc->add_text("]");
				class_desc->pop(); // color
			}

			if (cd.is_script_doc && (!prop.setter.is_empty() || !prop.getter.is_empty())) {
				class_desc->push_color(theme_cache.symbol_color);
				class_desc->add_text(" [" + TTR("property:") + " ");
				class_desc->pop(); // color

				if (!prop.setter.is_empty()) {
					class_desc->push_color(theme_cache.value_color);
					class_desc->add_text("setter");
					class_desc->pop(); // color
				}
				if (!prop.getter.is_empty()) {
					if (!prop.setter.is_empty()) {
						class_desc->push_color(theme_cache.symbol_color);
						class_desc->add_text(", ");
						class_desc->pop(); // color
					}
					class_desc->push_color(theme_cache.value_color);
					class_desc->add_text("getter");
					class_desc->pop(); // color
				}

				class_desc->push_color(theme_cache.symbol_color);
				class_desc->add_text("]");
				class_desc->pop(); // color
			}

			_pop_code_font();
			class_desc->pop(); // cell

			// Script doc doesn't have setter, getter.
			if (!cd.is_script_doc) {
				HashMap<String, DocData::MethodDoc> method_map;
				for (int j = 0; j < methods.size(); j++) {
					method_map[methods[j].name] = methods[j];
				}

				if (!prop.setter.is_empty()) {
					class_desc->push_cell();
					class_desc->pop(); // cell

					class_desc->push_cell();
					_push_code_font();
					class_desc->push_color(theme_cache.text_color);

					if (method_map[prop.setter].arguments.size() > 1) {
						// Setters with additional arguments are exposed in the method list, so we link them here for quick access.
						class_desc->push_meta("@method " + prop.setter);
						class_desc->add_text(prop.setter + TTR("(value)"));
						class_desc->pop(); // meta
					} else {
						class_desc->add_text(prop.setter + TTR("(value)"));
					}

					class_desc->pop(); // color
					class_desc->push_color(theme_cache.comment_color);
					class_desc->add_text(" setter");
					class_desc->pop(); // color
					_pop_code_font();
					class_desc->pop(); // cell

					method_line[prop.setter] = property_line[prop.name];
				}

				if (!prop.getter.is_empty()) {
					class_desc->push_cell();
					class_desc->pop(); // cell

					class_desc->push_cell();
					_push_code_font();
					class_desc->push_color(theme_cache.text_color);

					if (!method_map[prop.getter].arguments.is_empty()) {
						// Getters with additional arguments are exposed in the method list, so we link them here for quick access.
						class_desc->push_meta("@method " + prop.getter);
						class_desc->add_text(prop.getter + "()");
						class_desc->pop(); // meta
					} else {
						class_desc->add_text(prop.getter + "()");
					}

					class_desc->pop(); // color
					class_desc->push_color(theme_cache.comment_color);
					class_desc->add_text(" getter");
					class_desc->pop(); // color
					_pop_code_font();
					class_desc->pop(); // cell

					method_line[prop.getter] = property_line[prop.name];
				}
			}

			class_desc->pop(); // table

			class_desc->add_newline();
			class_desc->add_newline();

			class_desc->push_indent(1);
			_push_normal_font();
			class_desc->push_color(theme_cache.text_color);

			bool has_prev_text = false;

			if (prop.is_deprecated) {
				has_prev_text = true;
				DEPRECATED_DOC_MSG(HANDLE_DOC(prop.deprecated_message), TTR("This property may be changed or removed in future versions."));
			}

			if (prop.is_experimental) {
				if (has_prev_text) {
					class_desc->add_newline();
					class_desc->add_newline();
				}
				has_prev_text = true;
				EXPERIMENTAL_DOC_MSG(HANDLE_DOC(prop.experimental_message), TTR("This property may be changed or removed in future versions."));
			}

			const String descr = HANDLE_DOC(prop.description);
			if (!descr.is_empty()) {
				if (has_prev_text) {
					class_desc->add_newline();
					class_desc->add_newline();
				}
				has_prev_text = true;
				_add_text(descr);
			} else if (!has_prev_text) {
				class_desc->add_image(get_editor_theme_icon(SNAME("Error")));
				class_desc->add_text(" ");
				class_desc->push_color(theme_cache.comment_color);
				if (cd.is_script_doc) {
					class_desc->add_text(TTR("There is currently no description for this property."));
				} else {
					class_desc->append_text(TTR("There is currently no description for this property. Please help us by [color=$color][url=$url]contributing one[/url][/color]!").replace("$url", CONTRIBUTE_URL).replace("$color", link_color_text));
				}
				class_desc->pop(); // color
			}

			// Add copy note to built-in properties returning `Packed*Array`.
			if (!cd.is_script_doc && packed_array_types.has(prop.type)) {
				class_desc->add_newline();
				class_desc->add_newline();
				_add_text(vformat(TTR("[b]Note:[/b] The returned array is [i]copied[/i] and any changes to it will not update the original property value. See [%s] for more details."), prop.type));
			}

			class_desc->pop(); // color
			_pop_normal_font();
			class_desc->pop(); // indent
		}
	}

	// Constructor descriptions
	if (!cd.constructors.is_empty()) {
		_update_method_descriptions(cd, METHOD_TYPE_CONSTRUCTOR, cd.constructors);
	}

	// Method descriptions
	if (!methods.is_empty()) {
		_update_method_descriptions(cd, METHOD_TYPE_METHOD, methods);
	}

	// Operator descriptions
	if (!cd.operators.is_empty()) {
		_update_method_descriptions(cd, METHOD_TYPE_OPERATOR, cd.operators);
	}

	// Allow the document to be scrolled slightly below the end.
	class_desc->add_newline();
	class_desc->add_newline();

	// Free the scroll.
	scroll_locked = false;

#undef HANDLE_DOC
}

void EditorHelp::_request_help(const String &p_string) {
	Error err = _goto_desc(p_string);
	if (err == OK) {
		EditorNode::get_singleton()->get_editor_main_screen()->select(EditorMainScreen::EDITOR_SCRIPT);
	}
}

void EditorHelp::_help_callback(const String &p_topic) {
	String what = p_topic.get_slice(":", 0);
	String clss = p_topic.get_slice(":", 1);
	String name;
	if (p_topic.get_slice_count(":") == 3) {
		name = p_topic.get_slice(":", 2);
	}

	_request_help(clss); // First go to class.

	int line = 0;

	if (what == "class_desc") {
		line = description_line;
	} else if (what == "class_signal") {
		if (signal_line.has(name)) {
			line = signal_line[name];
		}
	} else if (what == "class_method" || what == "class_method_desc") {
		if (method_line.has(name)) {
			line = method_line[name];
		}
	} else if (what == "class_property") {
		if (property_line.has(name)) {
			line = property_line[name];
		}
	} else if (what == "class_enum") {
		if (enum_line.has(name)) {
			line = enum_line[name];
		}
	} else if (what == "class_theme_item") {
		if (theme_property_line.has(name)) {
			line = theme_property_line[name];
		}
	} else if (what == "class_constant") {
		if (constant_line.has(name)) {
			line = constant_line[name];
		}
	} else if (what == "class_annotation") {
		if (annotation_line.has(name)) {
			line = annotation_line[name];
		}
	} else if (what == "class_global") { // Deprecated.
		if (constant_line.has(name)) {
			line = constant_line[name];
		} else if (method_line.has(name)) {
			line = method_line[name];
		} else {
			HashMap<String, HashMap<String, int>>::Iterator iter = enum_values_line.begin();
			while (true) {
				if (iter->value.has(name)) {
					line = iter->value[name];
					break;
				} else if (iter == enum_values_line.last()) {
					break;
				} else {
					++iter;
				}
			}
		}
	}

	if (class_desc->is_finished()) {
		class_desc->scroll_to_paragraph(line);
	} else {
		scroll_to = line;
	}
}

static void _add_text_to_rt(const String &p_bbcode, RichTextLabel *p_rt, const Control *p_owner_node, const String &p_class) {
	const DocTools *doc = EditorHelp::get_doc_data();

	bool is_native = false;
	{
		const HashMap<String, DocData::ClassDoc>::ConstIterator E = doc->class_list.find(p_class);
		if (E && !E->value.is_script_doc) {
			is_native = true;
		}
	}

	const bool using_tab_indent = int(EDITOR_GET("text_editor/behavior/indent/type")) == 0;

	const Ref<Font> doc_font = p_owner_node->get_theme_font(SNAME("doc"), EditorStringName(EditorFonts));
	const Ref<Font> doc_bold_font = p_owner_node->get_theme_font(SNAME("doc_bold"), EditorStringName(EditorFonts));
	const Ref<Font> doc_italic_font = p_owner_node->get_theme_font(SNAME("doc_italic"), EditorStringName(EditorFonts));
	const Ref<Font> doc_code_font = p_owner_node->get_theme_font(SNAME("doc_source"), EditorStringName(EditorFonts));
	const Ref<Font> doc_kbd_font = p_owner_node->get_theme_font(SNAME("doc_keyboard"), EditorStringName(EditorFonts));

	const int doc_font_size = p_owner_node->get_theme_font_size(SNAME("doc_size"), EditorStringName(EditorFonts));
	const int doc_code_font_size = p_owner_node->get_theme_font_size(SNAME("doc_source_size"), EditorStringName(EditorFonts));
	const int doc_kbd_font_size = p_owner_node->get_theme_font_size(SNAME("doc_keyboard_size"), EditorStringName(EditorFonts));

	const Color type_color = p_owner_node->get_theme_color(SNAME("type_color"), SNAME("EditorHelp"));
	const Color code_color = p_owner_node->get_theme_color(SNAME("code_color"), SNAME("EditorHelp"));
	const Color kbd_color = p_owner_node->get_theme_color(SNAME("kbd_color"), SNAME("EditorHelp"));
	const Color code_dark_color = Color(code_color, 0.8);

	const Color link_color = p_owner_node->get_theme_color(SNAME("link_color"), SNAME("EditorHelp"));
	const Color link_method_color = p_owner_node->get_theme_color(SNAME("accent_color"), EditorStringName(Editor));
	const Color link_property_color = link_color.lerp(p_owner_node->get_theme_color(SNAME("accent_color"), EditorStringName(Editor)), 0.25);
	const Color link_annotation_color = link_color.lerp(p_owner_node->get_theme_color(SNAME("accent_color"), EditorStringName(Editor)), 0.5);

	const Color code_bg_color = p_owner_node->get_theme_color(SNAME("code_bg_color"), SNAME("EditorHelp"));
	const Color kbd_bg_color = p_owner_node->get_theme_color(SNAME("kbd_bg_color"), SNAME("EditorHelp"));
	const Color param_bg_color = p_owner_node->get_theme_color(SNAME("param_bg_color"), SNAME("EditorHelp"));

	String bbcode = p_bbcode.dedent().replace("\t", "").replace("\r", "").strip_edges();

	// Select the correct code examples.
	switch ((int)EDITOR_GET("text_editor/help/class_reference_examples")) {
		case 0: // GDScript
			bbcode = bbcode.replace("[gdscript", "[codeblock lang=gdscript"); // Tag can have extra arguments.
			bbcode = bbcode.replace("[/gdscript]", "[/codeblock]");

			for (int pos = bbcode.find("[csharp"); pos != -1; pos = bbcode.find("[csharp")) {
				int end_pos = bbcode.find("[/csharp]");
				if (end_pos == -1) {
					WARN_PRINT("Unclosed [csharp] block or parse fail in code (search for tag errors)");
					break;
				}

				bbcode = bbcode.left(pos) + bbcode.substr(end_pos + 9); // 9 is length of "[/csharp]".
				while (bbcode[pos] == '\n') {
					bbcode = bbcode.left(pos) + bbcode.substr(pos + 1);
				}
			}
			break;
		case 1: // C#
			bbcode = bbcode.replace("[csharp", "[codeblock lang=csharp"); // Tag can have extra arguments.
			bbcode = bbcode.replace("[/csharp]", "[/codeblock]");

			for (int pos = bbcode.find("[gdscript"); pos != -1; pos = bbcode.find("[gdscript")) {
				int end_pos = bbcode.find("[/gdscript]");
				if (end_pos == -1) {
					WARN_PRINT("Unclosed [gdscript] block or parse fail in code (search for tag errors)");
					break;
				}

				bbcode = bbcode.left(pos) + bbcode.substr(end_pos + 11); // 11 is length of "[/gdscript]".
				while (bbcode[pos] == '\n') {
					bbcode = bbcode.left(pos) + bbcode.substr(pos + 1);
				}
			}
			break;
		case 2: // GDScript and C#
			bbcode = bbcode.replace("[csharp", "[b]C#:[/b]\n[codeblock lang=csharp"); // Tag can have extra arguments.
			bbcode = bbcode.replace("[gdscript", "[b]GDScript:[/b]\n[codeblock lang=gdscript"); // Tag can have extra arguments.

			bbcode = bbcode.replace("[/csharp]", "[/codeblock]");
			bbcode = bbcode.replace("[/gdscript]", "[/codeblock]");
			break;
	}

	// Remove codeblocks (they would be printed otherwise).
	bbcode = bbcode.replace("[codeblocks]\n", "");
	bbcode = bbcode.replace("\n[/codeblocks]", "");
	bbcode = bbcode.replace("[codeblocks]", "");
	bbcode = bbcode.replace("[/codeblocks]", "");

	// Remove `\n` here because `\n` is replaced by `\n\n` later.
	// Will be compensated when parsing `[/codeblock]`.
	bbcode = bbcode.replace("[/codeblock]\n", "[/codeblock]");

	List<String> tag_stack;

	int pos = 0;
	while (pos < bbcode.length()) {
		int brk_pos = bbcode.find_char('[', pos);

		if (brk_pos < 0) {
			brk_pos = bbcode.length();
		}

		if (brk_pos > pos) {
			p_rt->add_text(bbcode.substr(pos, brk_pos - pos).replace("\n", "\n\n"));
		}

		if (brk_pos == bbcode.length()) {
			break; // Nothing else to add.
		}

		int brk_end = bbcode.find_char(']', brk_pos + 1);

		if (brk_end == -1) {
			p_rt->add_text(bbcode.substr(brk_pos, bbcode.length() - brk_pos).replace("\n", "\n\n"));
			break;
		}

		const String tag = bbcode.substr(brk_pos + 1, brk_end - brk_pos - 1);

		if (tag.begins_with("/")) {
			bool tag_ok = tag_stack.size() && tag_stack.front()->get() == tag.substr(1);

			if (!tag_ok) {
				p_rt->add_text("[");
				pos = brk_pos + 1;
				continue;
			}

			tag_stack.pop_front();
			pos = brk_end + 1;
			if (tag == "/img") {
				// Nothing to do.
			} else if (tag == "/url") {
				p_rt->pop(); // meta
				p_rt->pop(); // color
				p_rt->add_text(nbsp);
				p_rt->add_image(p_owner_node->get_editor_theme_icon(SNAME("ExternalLink")), 0, doc_font_size, link_color);
			} else {
				p_rt->pop();
			}
		} else if (tag.begins_with("method ") || tag.begins_with("constructor ") || tag.begins_with("operator ") || tag.begins_with("member ") || tag.begins_with("signal ") || tag.begins_with("enum ") || tag.begins_with("constant ") || tag.begins_with("annotation ") || tag.begins_with("theme_item ")) {
			const int tag_end = tag.find_char(' ');
			const String link_tag = tag.left(tag_end);
			const String link_target = tag.substr(tag_end + 1).lstrip(" ");

			Color target_color = link_color;
			RichTextLabel::MetaUnderline underline_mode = RichTextLabel::META_UNDERLINE_ON_HOVER;
			if (link_tag == "method" || link_tag == "constructor" || link_tag == "operator") {
				target_color = link_method_color;
			} else if (link_tag == "member" || link_tag == "signal" || link_tag == "theme_item") {
				target_color = link_property_color;
			} else if (link_tag == "annotation") {
				target_color = link_annotation_color;
			} else {
				// Better visibility for constants, enums, etc.
				underline_mode = RichTextLabel::META_UNDERLINE_ALWAYS;
			}

			// Use monospace font to make clickable references
			// easier to distinguish from inline code and other text.
			p_rt->push_font(doc_code_font);
			p_rt->push_font_size(doc_code_font_size);
			p_rt->push_color(target_color);
			p_rt->push_meta("@" + link_tag + " " + link_target, underline_mode);

			if (link_tag == "member" &&
					((!link_target.contains_char('.') && (p_class == "ProjectSettings" || p_class == "EditorSettings")) ||
							link_target.begins_with("ProjectSettings.") || link_target.begins_with("EditorSettings."))) {
				// Special formatting for both ProjectSettings and EditorSettings.
				String prefix;
				if (link_target.begins_with("EditorSettings.")) {
					prefix = "(" + TTR("Editor") + ") ";
				}

				const String setting_name = link_target.trim_prefix("ProjectSettings.").trim_prefix("EditorSettings.");
				PackedStringArray setting_sections;
				for (const String &section : setting_name.split("/", false)) {
					setting_sections.append(EditorPropertyNameProcessor::get_singleton()->process_name(section, EditorPropertyNameProcessor::get_settings_style()));
				}

				p_rt->push_bold();
				p_rt->add_text(prefix + String(" > ").join(setting_sections));
				p_rt->pop(); // bold
			} else {
				p_rt->add_text(link_target + (link_tag == "method" ? "()" : ""));
			}

			p_rt->pop(); // meta
			p_rt->pop(); // color
			p_rt->pop(); // font_size
			p_rt->pop(); // font

			pos = brk_end + 1;
		} else if (tag.begins_with("param ")) {
			const int tag_end = tag.find_char(' ');
			const String param_name = tag.substr(tag_end + 1).lstrip(" ");

			// Use monospace font with translucent background color to make code easier to distinguish from other text.
			p_rt->push_font(doc_code_font);
			p_rt->push_font_size(doc_code_font_size);
			p_rt->push_bgcolor(param_bg_color);
			p_rt->push_color(code_color);

			p_rt->add_text(param_name);

			p_rt->pop(); // color
			p_rt->pop(); // bgcolor
			p_rt->pop(); // font_size
			p_rt->pop(); // font

			pos = brk_end + 1;
		} else if (tag == p_class) {
			// Use a bold font when class reference tags are in their own page.
			p_rt->push_font(doc_bold_font);
			p_rt->add_text(tag);
			p_rt->pop(); // font

			pos = brk_end + 1;
		} else if (doc->class_list.has(tag)) {
			// Use a monospace font for class reference tags such as [Node2D] or [SceneTree].

			p_rt->push_font(doc_code_font);
			p_rt->push_font_size(doc_code_font_size);
			p_rt->push_color(type_color);
			p_rt->push_meta("#" + tag, RichTextLabel::META_UNDERLINE_ON_HOVER);

			p_rt->add_text(tag);

			p_rt->pop(); // meta
			p_rt->pop(); // color
			p_rt->pop(); // font_size
			p_rt->pop(); // font

			pos = brk_end + 1;
		} else if (tag == "b") {
			// Use bold font.
			p_rt->push_font(doc_bold_font);

			pos = brk_end + 1;
			tag_stack.push_front(tag);
		} else if (tag == "i") {
			// Use italics font.
			p_rt->push_font(doc_italic_font);

			pos = brk_end + 1;
			tag_stack.push_front(tag);
		} else if (tag == "code" || tag.begins_with("code ")) {
			int end_pos = bbcode.find("[/code]", brk_end + 1);
			if (end_pos < 0) {
				end_pos = bbcode.length();
			}

			// Use monospace font with darkened background color to make code easier to distinguish from other text.
			p_rt->push_font(doc_code_font);
			p_rt->push_font_size(doc_code_font_size);
			p_rt->push_bgcolor(code_bg_color);
			p_rt->push_color(code_color.lerp(p_owner_node->get_theme_color(SNAME("error_color"), EditorStringName(Editor)), 0.6));

			p_rt->add_text(bbcode.substr(brk_end + 1, end_pos - (brk_end + 1)));

			p_rt->pop(); // color
			p_rt->pop(); // bgcolor
			p_rt->pop(); // font_size
			p_rt->pop(); // font

			pos = end_pos + 7; // `len("[/code]")`.
		} else if (tag == "codeblock" || tag.begins_with("codeblock ")) {
			int end_pos = bbcode.find("[/codeblock]", brk_end + 1);
			if (end_pos < 0) {
				end_pos = bbcode.length();
			}

			const String codeblock_text = bbcode.substr(brk_end + 1, end_pos - (brk_end + 1)).strip_edges();

			String codeblock_copy_text = codeblock_text;
			if (using_tab_indent) {
				// Replace the code block's space indentation with tabs.
				StringBuilder builder;
				PackedStringArray text_lines = codeblock_copy_text.split("\n");
				for (const String &line : text_lines) {
					const String stripped_line = line.dedent();
					const int space_count = line.length() - stripped_line.length();

					if (builder.num_strings_appended() > 0) {
						builder.append("\n");
					}
					if (space_count > 0) {
						builder.append(String("\t").repeat(MAX(space_count / 4, 1)) + stripped_line);
					} else {
						builder.append(line);
					}
				}
				codeblock_copy_text = builder.as_string();
			}

			String lang;
			const PackedStringArray args = tag.trim_prefix("codeblock").split(" ", false);
			for (int i = args.size() - 1; i >= 0; i--) {
				if (args[i].begins_with("lang=")) {
					lang = args[i].trim_prefix("lang=");
					break;
				}
			}

			// Use monospace font with darkened background color to make code easier to distinguish from other text.
			// Use a single-column table with cell row background color instead of `[bgcolor]`.
			// This makes the background color highlight cover the entire block, rather than individual lines.
			p_rt->push_font(doc_code_font);
			p_rt->push_font_size(doc_code_font_size);
			p_rt->push_table(2);

			p_rt->push_cell();
			p_rt->set_cell_row_background_color(code_bg_color, Color(code_bg_color, 0.99));
			p_rt->set_cell_padding(Rect2(10 * EDSCALE, 10 * EDSCALE, 10 * EDSCALE, 10 * EDSCALE));
			p_rt->push_color(code_dark_color);

			bool codeblock_printed = false;<--- Assignment 'codeblock_printed=false', assigned value is 0<--- Assignment 'codeblock_printed=false', assigned value is 0<--- Assignment 'codeblock_printed=false', assigned value is 0

#ifdef MODULE_GDSCRIPT_ENABLED
			if (!codeblock_printed && (lang.is_empty() || lang == "gdscript")) {<--- Condition '!codeblock_printed' is always true
				EditorHelpHighlighter::get_singleton()->highlight(p_rt, EditorHelpHighlighter::LANGUAGE_GDSCRIPT, codeblock_text, is_native);
				codeblock_printed = true;
			}
#endif

#ifdef MODULE_MONO_ENABLED
			if (!codeblock_printed && lang == "csharp") {<--- Condition '!codeblock_printed' is always true
				EditorHelpHighlighter::get_singleton()->highlight(p_rt, EditorHelpHighlighter::LANGUAGE_CSHARP, codeblock_text, is_native);
				codeblock_printed = true;
			}
#endif

			if (!codeblock_printed) {<--- Condition '!codeblock_printed' is always true
				p_rt->add_text(codeblock_text);
				codeblock_printed = true;
			}

			p_rt->pop(); // color
			p_rt->pop(); // cell

			// Copy codeblock button.
			p_rt->push_cell();
			p_rt->set_cell_row_background_color(code_bg_color, Color(code_bg_color, 0.99));
			p_rt->set_cell_padding(Rect2(0, 10 * EDSCALE, 0, 10 * EDSCALE));
			p_rt->set_cell_size_override(Vector2(1, 1), Vector2(10, 10) * EDSCALE);
			p_rt->push_meta("^" + codeblock_copy_text, RichTextLabel::META_UNDERLINE_ON_HOVER);
			p_rt->add_image(p_owner_node->get_editor_theme_icon(SNAME("ActionCopy")), 24 * EDSCALE, 24 * EDSCALE, Color(link_property_color, 0.3), INLINE_ALIGNMENT_BOTTOM_TO, Rect2(), Variant(), false, TTR("Click to copy."));
			p_rt->pop(); // meta
			p_rt->pop(); // cell

			p_rt->pop(); // table
			p_rt->pop(); // font_size
			p_rt->pop(); // font

			pos = end_pos + 12; // `len("[/codeblock]")`.

			// Compensate for `\n` removed before the loop.
			if (pos < bbcode.length()) {
				p_rt->add_newline();
			}
		} else if (tag == "kbd") {
			int end_pos = bbcode.find("[/kbd]", brk_end + 1);
			if (end_pos < 0) {
				end_pos = bbcode.length();
			}

			// Use keyboard font with custom color and background color.
			p_rt->push_font(doc_kbd_font);
			p_rt->push_font_size(doc_kbd_font_size);
			p_rt->push_bgcolor(kbd_bg_color);
			p_rt->push_color(kbd_color);

			p_rt->add_text(bbcode.substr(brk_end + 1, end_pos - (brk_end + 1)));

			p_rt->pop(); // color
			p_rt->pop(); // bgcolor
			p_rt->pop(); // font_size
			p_rt->pop(); // font

			pos = end_pos + 6; // `len("[/kbd]")`.
		} else if (tag == "center") {
			// Align to center.
			p_rt->push_paragraph(HORIZONTAL_ALIGNMENT_CENTER, Control::TEXT_DIRECTION_AUTO, "");
			pos = brk_end + 1;
			tag_stack.push_front(tag);
		} else if (tag == "br") {
			// Force a line break.
			p_rt->add_newline();
			pos = brk_end + 1;
		} else if (tag == "u") {
			// Use underline.
			p_rt->push_underline();
			pos = brk_end + 1;
			tag_stack.push_front(tag);
		} else if (tag == "s") {
			// Use strikethrough.
			p_rt->push_strikethrough();
			pos = brk_end + 1;
			tag_stack.push_front(tag);
		} else if (tag == "lb") {
			p_rt->add_text("[");
			pos = brk_end + 1;
		} else if (tag == "rb") {
			p_rt->add_text("]");
			pos = brk_end + 1;
		} else if (tag == "url" || tag.begins_with("url=")) {
			String url;
			if (tag.begins_with("url=")) {
				url = tag.substr(4);
			} else {
				int end = bbcode.find_char('[', brk_end);
				if (end == -1) {
					end = bbcode.length();
				}
				url = bbcode.substr(brk_end + 1, end - brk_end - 1);
			}

			p_rt->push_color(link_color);
			p_rt->push_meta(url, RichTextLabel::META_UNDERLINE_ON_HOVER, url + "\n\n" + TTR("Click to open in browser."));

			pos = brk_end + 1;
			tag_stack.push_front("url");
		} else if (tag.begins_with("img")) {
			int width = 0;
			int height = 0;
			bool size_in_percent = false;
			if (tag.length() > 4) {
				Vector<String> subtags = tag.substr(4).split(" ");
				HashMap<String, String> bbcode_options;
				for (int i = 0; i < subtags.size(); i++) {
					const String &expr = subtags[i];
					int value_pos = expr.find_char('=');
					if (value_pos > -1) {
						bbcode_options[expr.left(value_pos)] = expr.substr(value_pos + 1).unquote();
					}
				}
				HashMap<String, String>::Iterator width_option = bbcode_options.find("width");
				if (width_option) {
					width = width_option->value.to_int();
					if (width_option->value.ends_with("%")) {
						size_in_percent = true;
					}
				}

				HashMap<String, String>::Iterator height_option = bbcode_options.find("height");
				if (height_option) {
					height = height_option->value.to_int();
					if (height_option->value.ends_with("%")) {
						size_in_percent = true;
					}
				}
			}
			int end = bbcode.find_char('[', brk_end);
			if (end == -1) {
				end = bbcode.length();
			}

			String image_path = bbcode.substr(brk_end + 1, end - brk_end - 1);
			p_rt->add_image(ResourceLoader::load(image_path, "Texture2D"), width, height, Color(1, 1, 1), INLINE_ALIGNMENT_CENTER, Rect2(), Variant(), false, String(), size_in_percent);

			pos = end;
			tag_stack.push_front("img");
		} else if (tag.begins_with("color=")) {
			String col = tag.substr(6);
			Color color = Color::from_string(col, Color());
			p_rt->push_color(color);

			pos = brk_end + 1;
			tag_stack.push_front("color");
		} else if (tag.begins_with("font=")) {
			String font_path = tag.substr(5);
			Ref<Font> font = ResourceLoader::load(font_path, "Font");
			if (font.is_valid()) {
				p_rt->push_font(font);
			} else {
				p_rt->push_font(doc_font);
			}

			pos = brk_end + 1;
			tag_stack.push_front("font");
		} else {
			p_rt->add_text("["); // Ignore.
			pos = brk_pos + 1;
		}
	}

	// Close unclosed tags.
	for (const String &tag : tag_stack) {
		if (tag != "img") {
			p_rt->pop();
		}
	}
}

void EditorHelp::_add_text(const String &p_bbcode) {
	_add_text_to_rt(p_bbcode, class_desc, this, edited_class);
}

void EditorHelp::_wait_for_thread() {
	if (worker_thread.is_started()) {
		worker_thread.wait_to_finish();
	}
}

void EditorHelp::_compute_doc_version_hash() {
	uint32_t version_hash = Engine::get_singleton()->get_version_info().hash();
	doc_version_hash = vformat("%d/%d/%d/%s", version_hash, ClassDB::get_api_hash(ClassDB::API_CORE), ClassDB::get_api_hash(ClassDB::API_EDITOR), _doc_data_hash);
}

String EditorHelp::get_cache_full_path() {
	return EditorPaths::get_singleton()->get_cache_dir().path_join(vformat("editor_doc_cache-%d.%d.res", VERSION_MAJOR, VERSION_MINOR));
}

void EditorHelp::load_xml_buffer(const uint8_t *p_buffer, int p_size) {
	if (!ext_doc) {
		ext_doc = memnew(DocTools);
	}

	ext_doc->load_xml(p_buffer, p_size);

	if (doc) {
		doc->load_xml(p_buffer, p_size);
	}
}

void EditorHelp::remove_class(const String &p_class) {
	if (ext_doc && ext_doc->has_doc(p_class)) {
		ext_doc->remove_doc(p_class);
	}

	if (doc && doc->has_doc(p_class)) {
		doc->remove_doc(p_class);
	}
}

void EditorHelp::_load_doc_thread(void *p_udata) {
	Ref<Resource> cache_res = ResourceLoader::load(get_cache_full_path());
	if (cache_res.is_valid() && cache_res->get_meta("version_hash", "") == doc_version_hash) {
		Array classes = cache_res->get_meta("classes", Array());
		for (int i = 0; i < classes.size(); i++) {
			doc->add_doc(DocData::ClassDoc::from_dict(classes[i]));
		}

		// Extensions' docs are not cached. Generate them now (on the main thread).
		callable_mp_static(&EditorHelp::_gen_extensions_docs).call_deferred();
	} else {
		// We have to go back to the main thread to start from scratch, bypassing any possibly existing cache.
		callable_mp_static(&EditorHelp::generate_doc).call_deferred(false);
	}

	OS::get_singleton()->benchmark_end_measure("EditorHelp", vformat("Generate Documentation (Run %d)", doc_generation_count));
}

void EditorHelp::_gen_doc_thread(void *p_udata) {
	DocTools compdoc;
	compdoc.load_compressed(_doc_data_compressed, _doc_data_compressed_size, _doc_data_uncompressed_size);
	doc->merge_from(compdoc); // Ensure all is up to date.

	Ref<Resource> cache_res;
	cache_res.instantiate();
	cache_res->set_meta("version_hash", doc_version_hash);
	Array classes;
	for (const KeyValue<String, DocData::ClassDoc> &E : doc->class_list) {
		if (ClassDB::class_exists(E.value.name)) {
			ClassDB::APIType api = ClassDB::get_api_type(E.value.name);
			if (api == ClassDB::API_EXTENSION || api == ClassDB::API_EDITOR_EXTENSION) {
				continue;
			}
		}
		classes.push_back(DocData::ClassDoc::to_dict(E.value));
	}
	cache_res->set_meta("classes", classes);
	Error err = ResourceSaver::save(cache_res, get_cache_full_path(), ResourceSaver::FLAG_COMPRESS);
	if (err) {
		ERR_PRINT("Cannot save editor help cache (" + get_cache_full_path() + ").");
	}

	OS::get_singleton()->benchmark_end_measure("EditorHelp", vformat("Generate Documentation (Run %d)", doc_generation_count));
}

void EditorHelp::_gen_extensions_docs() {
	doc->generate((DocTools::GENERATE_FLAG_SKIP_BASIC_TYPES | DocTools::GENERATE_FLAG_EXTENSION_CLASSES_ONLY));

	// Append extra doc data, as it gets overridden by the generation step.
	if (ext_doc) {
		doc->merge_from(*ext_doc);
	}
}

void EditorHelp::generate_doc(bool p_use_cache) {
	doc_generation_count++;
	OS::get_singleton()->benchmark_begin_measure("EditorHelp", vformat("Generate Documentation (Run %d)", doc_generation_count));

	// In case not the first attempt.
	_wait_for_thread();

	if (!doc) {
		doc = memnew(DocTools);
	}

	if (doc_version_hash.is_empty()) {
		_compute_doc_version_hash();
	}

	if (p_use_cache && FileAccess::exists(get_cache_full_path())) {
		worker_thread.start(_load_doc_thread, nullptr);
	} else {
		print_verbose("Regenerating editor help cache");
		doc->generate();
		worker_thread.start(_gen_doc_thread, nullptr);
	}
}

void EditorHelp::_toggle_scripts_pressed() {
	ScriptEditor::get_singleton()->toggle_scripts_panel();
	update_toggle_scripts_button();
}

void EditorHelp::_notification(int p_what) {
	switch (p_what) {
		case NOTIFICATION_POSTINITIALIZE: {
			// Requires theme to be up to date.
			_class_desc_resized(false);
		} break;

		case EditorSettings::NOTIFICATION_EDITOR_SETTINGS_CHANGED: {
			bool need_update = false;
			if (EditorSettings::get_singleton()->check_changed_settings_in_group("text_editor/help")) {
				need_update = true;
			}
#if defined(MODULE_GDSCRIPT_ENABLED) || defined(MODULE_MONO_ENABLED)
			if (!need_update && EditorSettings::get_singleton()->check_changed_settings_in_group("text_editor/theme/highlighting")) {
				need_update = true;
			}
#endif
			if (!need_update) {
				break;
			}
			[[fallthrough]];
		}
		case NOTIFICATION_READY: {
			_wait_for_thread();
			_update_doc();
		} break;

		case NOTIFICATION_THEME_CHANGED: {
			if (is_inside_tree()) {
				_class_desc_resized(true);
			}
			update_toggle_scripts_button();
		} break;

		case NOTIFICATION_VISIBILITY_CHANGED: {
			update_toggle_scripts_button();
		} break;
	}
}

void EditorHelp::go_to_help(const String &p_help) {
	_wait_for_thread();
	_help_callback(p_help);
}

void EditorHelp::go_to_class(const String &p_class) {
	_wait_for_thread();
	_goto_desc(p_class);
}

void EditorHelp::update_doc() {
	_wait_for_thread();
	ERR_FAIL_COND(!doc->class_list.has(edited_class));
	ERR_FAIL_COND(!doc->class_list[edited_class].is_script_doc);
	_update_doc();
}

void EditorHelp::cleanup_doc() {
	_wait_for_thread();
	memdelete(doc);
	doc = nullptr;
}

Vector<Pair<String, int>> EditorHelp::get_sections() {
	_wait_for_thread();
	Vector<Pair<String, int>> sections;

	for (int i = 0; i < section_line.size(); i++) {
		sections.push_back(Pair<String, int>(section_line[i].first, i));
	}
	return sections;
}

void EditorHelp::scroll_to_section(int p_section_index) {
	_wait_for_thread();
	int line = section_line[p_section_index].second;
	if (class_desc->is_finished()) {
		class_desc->scroll_to_paragraph(line);
	} else {
		scroll_to = line;
	}
}

void EditorHelp::popup_search() {
	_wait_for_thread();
	find_bar->popup_search();
}

String EditorHelp::get_class() {
	return edited_class;
}

void EditorHelp::search_again(bool p_search_previous) {
	_search(p_search_previous);
}

int EditorHelp::get_scroll() const {
	return class_desc->get_v_scroll_bar()->get_value();
}

void EditorHelp::set_scroll(int p_scroll) {
	class_desc->get_v_scroll_bar()->set_value(p_scroll);
}

void EditorHelp::update_toggle_scripts_button() {
	if (is_layout_rtl()) {
		toggle_scripts_button->set_button_icon(get_editor_theme_icon(ScriptEditor::get_singleton()->is_scripts_panel_toggled() ? SNAME("Forward") : SNAME("Back")));
	} else {
		toggle_scripts_button->set_button_icon(get_editor_theme_icon(ScriptEditor::get_singleton()->is_scripts_panel_toggled() ? SNAME("Back") : SNAME("Forward")));
	}
	toggle_scripts_button->set_tooltip_text(vformat("%s (%s)", TTR("Toggle Scripts Panel"), ED_GET_SHORTCUT("script_editor/toggle_scripts_panel")->get_as_text()));
}

void EditorHelp::_bind_methods() {
	ClassDB::bind_method("_class_list_select", &EditorHelp::_class_list_select);
	ClassDB::bind_method("_request_help", &EditorHelp::_request_help);
	ClassDB::bind_method("_search", &EditorHelp::_search);
	ClassDB::bind_method("_help_callback", &EditorHelp::_help_callback);

	ADD_SIGNAL(MethodInfo("go_to_help"));
	ADD_SIGNAL(MethodInfo("request_save_history"));
}

void EditorHelp::init_gdext_pointers() {
	GDExtensionEditorHelp::editor_help_load_xml_buffer = &EditorHelp::load_xml_buffer;
	GDExtensionEditorHelp::editor_help_remove_class = &EditorHelp::remove_class;
}

EditorHelp::EditorHelp() {
	set_custom_minimum_size(Size2(150 * EDSCALE, 0));

	class_desc = memnew(RichTextLabel);
	class_desc->set_tab_size(8);
	add_child(class_desc);
	class_desc->set_threaded(true);
	class_desc->set_v_size_flags(SIZE_EXPAND_FILL);

	class_desc->connect(SceneStringName(finished), callable_mp(this, &EditorHelp::_class_desc_finished));
	class_desc->connect("meta_clicked", callable_mp(this, &EditorHelp::_class_desc_select));
	class_desc->connect(SceneStringName(gui_input), callable_mp(this, &EditorHelp::_class_desc_input));
	class_desc->connect(SceneStringName(resized), callable_mp(this, &EditorHelp::_class_desc_resized).bind(false));

	// Added second so it opens at the bottom so it won't offset the entire widget.
	find_bar = memnew(FindBar);
	add_child(find_bar);
	find_bar->hide();
	find_bar->set_rich_text_label(class_desc);

	status_bar = memnew(HBoxContainer);
	add_child(status_bar);
	status_bar->set_h_size_flags(SIZE_EXPAND_FILL);
	status_bar->set_custom_minimum_size(Size2(0, 24 * EDSCALE));

	toggle_scripts_button = memnew(Button);
	toggle_scripts_button->set_flat(true);
	toggle_scripts_button->connect(SceneStringName(pressed), callable_mp(this, &EditorHelp::_toggle_scripts_pressed));
	status_bar->add_child(toggle_scripts_button);

	class_desc->set_selection_enabled(true);
	class_desc->set_context_menu_enabled(true);
	class_desc->set_selection_modifier(callable_mp_static(_replace_nbsp_with_space));

	class_desc->hide();
}

EditorHelp::~EditorHelp() {
}

DocTools *EditorHelp::get_doc_data() {
	_wait_for_thread();
	return doc;
}

/// EditorHelpBit ///

#define HANDLE_DOC(m_string) ((is_native ? DTR(m_string) : (m_string)).strip_edges())

EditorHelpBit::HelpData EditorHelpBit::_get_class_help_data(const StringName &p_class_name) {
	if (doc_class_cache.has(p_class_name)) {
		return doc_class_cache[p_class_name];
	}

	HelpData result;

	const HashMap<String, DocData::ClassDoc>::ConstIterator E = EditorHelp::get_doc_data()->class_list.find(p_class_name);
	if (E) {
		// Non-native class shouldn't be cached, nor translated.
		const bool is_native = !E->value.is_script_doc;

		const String brief_description = HANDLE_DOC(E->value.brief_description);
		const String long_description = HANDLE_DOC(E->value.description);

		if (!brief_description.is_empty()) {
			result.description += "[b]" + brief_description + "[/b]";
		}
		if (!long_description.is_empty()) {
			if (!result.description.is_empty()) {
				result.description += '\n';
			}
			result.description += long_description;
		}
		if (E->value.is_deprecated) {
			if (E->value.deprecated_message.is_empty()) {
				result.deprecated_message = TTR("This class may be changed or removed in future versions.");
			} else {
				result.deprecated_message = HANDLE_DOC(E->value.deprecated_message);
			}
		}
		if (E->value.is_experimental) {
			if (E->value.experimental_message.is_empty()) {
				result.experimental_message = TTR("This class may be changed or removed in future versions.");
			} else {
				result.experimental_message = HANDLE_DOC(E->value.experimental_message);
			}
		}

		if (is_native) {
			doc_class_cache[p_class_name] = result;
		}
	}

	return result;
}

EditorHelpBit::HelpData EditorHelpBit::_get_enum_help_data(const StringName &p_class_name, const StringName &p_enum_name) {
	if (doc_enum_cache.has(p_class_name) && doc_enum_cache[p_class_name].has(p_enum_name)) {
		return doc_enum_cache[p_class_name][p_enum_name];
	}

	HelpData result;

	const DocTools *dd = EditorHelp::get_doc_data();
	const HashMap<String, DocData::ClassDoc>::ConstIterator E = dd->class_list.find(p_class_name);
	if (E) {
		// Non-native enums shouldn't be cached, nor translated.
		const bool is_native = !E->value.is_script_doc;

		for (const KeyValue<String, DocData::EnumDoc> &kv : E->value.enums) {
			const StringName enum_name = kv.key;
			const DocData::EnumDoc &enum_doc = kv.value;

			HelpData current;
			current.description = HANDLE_DOC(enum_doc.description);
			if (enum_doc.is_deprecated) {
				if (enum_doc.deprecated_message.is_empty()) {
					current.deprecated_message = TTR("This enumeration may be changed or removed in future versions.");
				} else {
					current.deprecated_message = HANDLE_DOC(enum_doc.deprecated_message);
				}
			}
			if (enum_doc.is_experimental) {
				if (enum_doc.experimental_message.is_empty()) {
					current.experimental_message = TTR("This enumeration may be changed or removed in future versions.");
				} else {
					current.experimental_message = HANDLE_DOC(enum_doc.experimental_message);
				}
			}

			if (enum_name == p_enum_name) {
				result = current;

				if (!is_native) {
					break;
				}
			}

			if (is_native) {
				doc_enum_cache[p_class_name][enum_name] = current;
			}
		}
	}

	return result;
}

EditorHelpBit::HelpData EditorHelpBit::_get_constant_help_data(const StringName &p_class_name, const StringName &p_constant_name) {
	if (doc_constant_cache.has(p_class_name) && doc_constant_cache[p_class_name].has(p_constant_name)) {
		return doc_constant_cache[p_class_name][p_constant_name];
	}

	HelpData result;

	const DocTools *dd = EditorHelp::get_doc_data();
	const HashMap<String, DocData::ClassDoc>::ConstIterator E = dd->class_list.find(p_class_name);
	if (E) {
		// Non-native constants shouldn't be cached, nor translated.
		const bool is_native = !E->value.is_script_doc;

		for (const DocData::ConstantDoc &constant : E->value.constants) {
			HelpData current;
			current.description = HANDLE_DOC(constant.description);
			if (constant.is_deprecated) {
				if (constant.deprecated_message.is_empty()) {
					current.deprecated_message = TTR("This constant may be changed or removed in future versions.");
				} else {
					current.deprecated_message = HANDLE_DOC(constant.deprecated_message);
				}
			}
			if (constant.is_experimental) {
				if (constant.experimental_message.is_empty()) {
					current.experimental_message = TTR("This constant may be changed or removed in future versions.");
				} else {
					current.experimental_message = HANDLE_DOC(constant.experimental_message);
				}
			}
			current.doc_type = { constant.type, constant.enumeration, constant.is_bitfield };
			if (constant.is_value_valid) {
				current.value = constant.value;
			}

			if (constant.name == p_constant_name) {
				result = current;

				if (!is_native) {
					break;
				}
			}

			if (is_native) {
				doc_constant_cache[p_class_name][constant.name] = current;
			}
		}
	}

	return result;
}

EditorHelpBit::HelpData EditorHelpBit::_get_property_help_data(const StringName &p_class_name, const StringName &p_property_name) {
	if (doc_property_cache.has(p_class_name) && doc_property_cache[p_class_name].has(p_property_name)) {
		return doc_property_cache[p_class_name][p_property_name];
	}

	HelpData result;

	const DocTools *dd = EditorHelp::get_doc_data();
	const HashMap<String, DocData::ClassDoc>::ConstIterator E = dd->class_list.find(p_class_name);
	if (E) {
		// Non-native properties shouldn't be cached, nor translated.
		const bool is_native = !E->value.is_script_doc;

		for (const DocData::PropertyDoc &property : E->value.properties) {
			HelpData current;
			current.description = HANDLE_DOC(property.description);
			if (property.is_deprecated) {
				if (property.deprecated_message.is_empty()) {
					current.deprecated_message = TTR("This property may be changed or removed in future versions.");
				} else {
					current.deprecated_message = HANDLE_DOC(property.deprecated_message);
				}
			}
			if (property.is_experimental) {
				if (property.experimental_message.is_empty()) {
					current.experimental_message = TTR("This property may be changed or removed in future versions.");
				} else {
					current.experimental_message = HANDLE_DOC(property.experimental_message);
				}
			}
			current.doc_type = { property.type, property.enumeration, property.is_bitfield };
			current.value = property.default_value;

			String enum_class_name;
			String enum_name;
			if (CoreConstants::is_global_enum(property.enumeration)) {
				enum_class_name = "@GlobalScope";
				enum_name = property.enumeration;
			} else {
				const int dot_pos = property.enumeration.rfind_char('.');
				if (dot_pos >= 0) {
					enum_class_name = property.enumeration.left(dot_pos);
					enum_name = property.enumeration.substr(dot_pos + 1);
				}
			}

			if (!enum_class_name.is_empty() && !enum_name.is_empty()) {
				// Classes can use enums from other classes, so check from which it came.
				const HashMap<String, DocData::ClassDoc>::ConstIterator enum_class = dd->class_list.find(enum_class_name);
				if (enum_class) {
					const String enum_prefix = EditorPropertyNameProcessor::get_singleton()->process_name(enum_name, EditorPropertyNameProcessor::STYLE_CAPITALIZED) + " ";
					for (DocData::ConstantDoc constant : enum_class->value.constants) {
						// Don't display `_MAX` enum value descriptions, as these are never exposed in the inspector.
						if (constant.enumeration == enum_name && !constant.name.ends_with("_MAX")) {
							// Prettify the enum value display, so that "<ENUM_NAME>_<ITEM>" becomes "Item".
							const String item_name = EditorPropertyNameProcessor::get_singleton()->process_name(constant.name, EditorPropertyNameProcessor::STYLE_CAPITALIZED).trim_prefix(enum_prefix);
							String item_descr = HANDLE_DOC(constant.description);
							if (item_descr.is_empty()) {
								item_descr = "[color=<EditorHelpBitCommentColor>][i]" + TTR("No description available.") + "[/i][/color]";
							}
							current.description += vformat("\n[b]%s:[/b] %s", item_name, item_descr);
						}
					}
					current.description = current.description.lstrip("\n");
				}
			}

			if (property.name == p_property_name) {
				result = current;

				if (!is_native) {
					break;
				}
			}

			if (is_native) {
				doc_property_cache[p_class_name][property.name] = current;
			}
		}
	}

	return result;
}

EditorHelpBit::HelpData EditorHelpBit::_get_theme_item_help_data(const StringName &p_class_name, const StringName &p_theme_item_name) {
	if (doc_theme_item_cache.has(p_class_name) && doc_theme_item_cache[p_class_name].has(p_theme_item_name)) {
		return doc_theme_item_cache[p_class_name][p_theme_item_name];
	}

	HelpData result;

	bool found = false;
	const DocTools *dd = EditorHelp::get_doc_data();
	HashMap<String, DocData::ClassDoc>::ConstIterator E = dd->class_list.find(p_class_name);
	while (E) {
		// Non-native theme items shouldn't be cached, nor translated.
		const bool is_native = !E->value.is_script_doc;

		for (const DocData::ThemeItemDoc &theme_item : E->value.theme_properties) {
			HelpData current;
			current.description = HANDLE_DOC(theme_item.description);
			if (theme_item.is_deprecated) {
				if (theme_item.deprecated_message.is_empty()) {
					current.deprecated_message = TTR("This theme property may be changed or removed in future versions.");
				} else {
					current.deprecated_message = HANDLE_DOC(theme_item.deprecated_message);
				}
			}
			if (theme_item.is_experimental) {
				if (theme_item.experimental_message.is_empty()) {
					current.experimental_message = TTR("This theme property may be changed or removed in future versions.");
				} else {
					current.experimental_message = HANDLE_DOC(theme_item.experimental_message);
				}
			}
			current.doc_type = { theme_item.type, String(), false };
			current.value = theme_item.default_value;

			if (theme_item.name == p_theme_item_name) {
				result = current;
				found = true;

				if (!is_native) {
					break;
				}
			}

			if (is_native) {
				doc_theme_item_cache[p_class_name][theme_item.name] = current;
			}
		}

		if (found || E->value.inherits.is_empty()) {
			break;
		}

		// Check for inherited theme items.
		E = dd->class_list.find(E->value.inherits);
	}

	return result;
}

EditorHelpBit::HelpData EditorHelpBit::_get_method_help_data(const StringName &p_class_name, const StringName &p_method_name) {
	if (doc_method_cache.has(p_class_name) && doc_method_cache[p_class_name].has(p_method_name)) {
		return doc_method_cache[p_class_name][p_method_name];
	}

	HelpData result;

	const HashMap<String, DocData::ClassDoc>::ConstIterator E = EditorHelp::get_doc_data()->class_list.find(p_class_name);
	if (E) {
		// Non-native methods shouldn't be cached, nor translated.
		const bool is_native = !E->value.is_script_doc;

		for (const DocData::MethodDoc &method : E->value.methods) {
			HelpData current;
			current.description = HANDLE_DOC(method.description);
			if (method.is_deprecated) {
				if (method.deprecated_message.is_empty()) {
					current.deprecated_message = TTR("This method may be changed or removed in future versions.");
				} else {
					current.deprecated_message = HANDLE_DOC(method.deprecated_message);
				}
			}
			if (method.is_experimental) {
				if (method.experimental_message.is_empty()) {
					current.experimental_message = TTR("This method may be changed or removed in future versions.");
				} else {
					current.experimental_message = HANDLE_DOC(method.experimental_message);
				}
			}
			current.doc_type = { method.return_type, method.return_enum, method.return_is_bitfield };
			for (const DocData::ArgumentDoc &argument : method.arguments) {
				const DocType argument_type = { argument.type, argument.enumeration, argument.is_bitfield };
				current.arguments.push_back({ argument.name, argument_type, argument.default_value });
			}
			current.qualifiers = method.qualifiers;

			if (method.name == p_method_name) {
				result = current;

				if (!is_native) {
					break;
				}
			}

			if (is_native) {
				doc_method_cache[p_class_name][method.name] = current;
			}
		}
	}

	return result;
}

EditorHelpBit::HelpData EditorHelpBit::_get_signal_help_data(const StringName &p_class_name, const StringName &p_signal_name) {
	if (doc_signal_cache.has(p_class_name) && doc_signal_cache[p_class_name].has(p_signal_name)) {
		return doc_signal_cache[p_class_name][p_signal_name];
	}

	HelpData result;

	const HashMap<String, DocData::ClassDoc>::ConstIterator E = EditorHelp::get_doc_data()->class_list.find(p_class_name);
	if (E) {
		// Non-native signals shouldn't be cached, nor translated.
		const bool is_native = !E->value.is_script_doc;

		for (const DocData::MethodDoc &signal : E->value.signals) {
			HelpData current;
			current.description = HANDLE_DOC(signal.description);
			if (signal.is_deprecated) {
				if (signal.deprecated_message.is_empty()) {
					current.deprecated_message = TTR("This signal may be changed or removed in future versions.");
				} else {
					current.deprecated_message = HANDLE_DOC(signal.deprecated_message);
				}
			}
			if (signal.is_experimental) {
				if (signal.experimental_message.is_empty()) {
					current.experimental_message = TTR("This signal may be changed or removed in future versions.");
				} else {
					current.experimental_message = HANDLE_DOC(signal.experimental_message);
				}
			}
			for (const DocData::ArgumentDoc &argument : signal.arguments) {
				const DocType argument_type = { argument.type, argument.enumeration, argument.is_bitfield };
				current.arguments.push_back({ argument.name, argument_type, argument.default_value });
			}
			current.qualifiers = signal.qualifiers;

			if (signal.name == p_signal_name) {
				result = current;

				if (!is_native) {
					break;
				}
			}

			if (is_native) {
				doc_signal_cache[p_class_name][signal.name] = current;
			}
		}
	}

	return result;
}

EditorHelpBit::HelpData EditorHelpBit::_get_annotation_help_data(const StringName &p_class_name, const StringName &p_annotation_name) {
	if (doc_annotation_cache.has(p_class_name) && doc_annotation_cache[p_class_name].has(p_annotation_name)) {
		return doc_annotation_cache[p_class_name][p_annotation_name];
	}

	HelpData result;

	const HashMap<String, DocData::ClassDoc>::ConstIterator E = EditorHelp::get_doc_data()->class_list.find(p_class_name);
	if (E) {
		// Non-native annotations shouldn't be cached, nor translated.
		const bool is_native = !E->value.is_script_doc;

		for (const DocData::MethodDoc &annotation : E->value.annotations) {
			HelpData current;
			current.description = HANDLE_DOC(annotation.description);
			if (annotation.is_deprecated) {
				if (annotation.deprecated_message.is_empty()) {
					current.deprecated_message = TTR("This annotation may be changed or removed in future versions.");
				} else {
					current.deprecated_message = HANDLE_DOC(annotation.deprecated_message);
				}
			}
			if (annotation.is_experimental) {
				if (annotation.experimental_message.is_empty()) {
					current.experimental_message = TTR("This annotation may be changed or removed in future versions.");
				} else {
					current.experimental_message = HANDLE_DOC(annotation.experimental_message);
				}
			}
			for (const DocData::ArgumentDoc &argument : annotation.arguments) {
				const DocType argument_type = { argument.type, argument.enumeration, argument.is_bitfield };
				current.arguments.push_back({ argument.name, argument_type, argument.default_value });
			}
			current.qualifiers = annotation.qualifiers;

			if (annotation.name == p_annotation_name) {
				result = current;

				if (!is_native) {
					break;
				}
			}

			if (is_native) {
				doc_annotation_cache[p_class_name][annotation.name] = current;
			}
		}
	}

	return result;
}

#undef HANDLE_DOC

void EditorHelpBit::_add_type_to_title(const DocType &p_doc_type) {
	_add_type_to_rt(p_doc_type.type, p_doc_type.enumeration, p_doc_type.is_bitfield, title, this, symbol_class_name);
}

void EditorHelpBit::_update_labels() {
	const Ref<Font> doc_bold_font = get_theme_font(SNAME("doc_bold"), EditorStringName(EditorFonts));

	if (!symbol_type.is_empty() || !symbol_name.is_empty()) {
		title->clear();

		title->push_font(doc_bold_font);

		if (!symbol_type.is_empty()) {
			title->push_color(get_theme_color(SNAME("title_color"), SNAME("EditorHelp")));
			title->add_text(symbol_type);
			title->pop(); // color
		}

		if (!symbol_type.is_empty() && !symbol_name.is_empty()) {
			title->add_text(" ");
		}

		if (!symbol_name.is_empty()) {
			if (!symbol_doc_link.is_empty()) {
				title->push_meta(symbol_doc_link, RichTextLabel::META_UNDERLINE_ON_HOVER);
			}
			if (use_class_prefix && !symbol_class_name.is_empty() && symbol_hint != SYMBOL_HINT_INHERITANCE) {
				title->add_text(symbol_class_name + ".");
			}
			title->add_text(symbol_name);
			if (!symbol_doc_link.is_empty()) {
				title->pop(); // meta
			}
		}

		title->pop(); // font

		const Color symbol_color = get_theme_color(SNAME("symbol_color"), SNAME("EditorHelp"));
		const Color value_color = get_theme_color(SNAME("value_color"), SNAME("EditorHelp"));
		const Color qualifier_color = get_theme_color(SNAME("qualifier_color"), SNAME("EditorHelp"));
		const Ref<Font> doc_source = get_theme_font(SNAME("doc_source"), EditorStringName(EditorFonts));
		const int doc_source_size = get_theme_font_size(SNAME("doc_source_size"), EditorStringName(EditorFonts));

		switch (symbol_hint) {
			case SYMBOL_HINT_NONE: {
				// Nothing to do.
			} break;
			case SYMBOL_HINT_INHERITANCE: {
				const HashMap<String, DocData::ClassDoc> &class_list = EditorHelp::get_doc_data()->class_list;
				const DocData::ClassDoc *class_doc = class_list.getptr(symbol_class_name);
				String inherits = class_doc ? class_doc->inherits : String();

				if (!inherits.is_empty()) {
					title->push_font(doc_source);
					title->push_font_size(doc_source_size * 0.9);

					while (!inherits.is_empty()) {
						title->push_color(symbol_color);
						title->add_text(" <" + nbsp);
						title->pop(); // color

						_add_type_to_title({ inherits, String(), false });

						inherits = class_list[inherits].inherits;
					}

					title->pop(); // font_size
					title->pop(); // font
				}
			} break;
			case SYMBOL_HINT_ASSIGNABLE: {
				const bool has_type = !help_data.doc_type.type.is_empty();
				const bool has_value = !help_data.value.is_empty();

				if (has_type || has_value) {
					title->push_font(doc_source);
					title->push_font_size(doc_source_size * 0.9);

					if (has_type) {
						title->push_color(symbol_color);
						title->add_text(colon_nbsp);
						title->pop(); // color

						_add_type_to_title(help_data.doc_type);
					}

					if (has_value) {
						title->push_color(symbol_color);
						title->add_text(nbsp_equal_nbsp);
						title->pop(); // color

						title->push_color(value_color);
						title->add_text(_fix_constant(help_data.value));
						title->pop(); // color
					}

					title->pop(); // font_size
					title->pop(); // font
				}
			} break;
			case SYMBOL_HINT_SIGNATURE: {
				title->push_font(doc_source);
				title->push_font_size(doc_source_size * 0.9);

				title->push_color(symbol_color);
				title->add_text("(");
				title->pop(); // color

				for (int i = 0; i < help_data.arguments.size(); i++) {
					const ArgumentData &argument = help_data.arguments[i];

					if (i > 0) {
						title->add_text(", ");
					}

					title->add_text(argument.name);

					title->push_color(symbol_color);
					title->add_text(colon_nbsp);
					title->pop(); // color

					_add_type_to_title(argument.doc_type);

					if (!argument.default_value.is_empty()) {
						title->push_color(symbol_color);
						title->add_text(nbsp_equal_nbsp);
						title->pop(); // color

						title->push_color(value_color);
						title->add_text(_fix_constant(argument.default_value));
						title->pop(); // color
					}
				}

				if (help_data.qualifiers.contains("vararg")) {
					if (!help_data.arguments.is_empty()) {
						title->add_text(", ");
					}

					title->push_color(symbol_color);
					title->add_text("...");
					title->pop(); // color
				}

				title->push_color(symbol_color);
				title->add_text(")");
				title->pop(); // color

				if (!help_data.doc_type.type.is_empty()) {
					title->push_color(symbol_color);
					title->add_text(" ->" + nbsp);
					title->pop(); // color

					_add_type_to_title(help_data.doc_type);
				}

				if (!help_data.qualifiers.is_empty()) {
					title->push_color(qualifier_color);
					_add_qualifiers_to_rt(help_data.qualifiers, title);
					title->pop(); // color
				}

				title->pop(); // font_size
				title->pop(); // font
			} break;
		}

		title->show();
	} else {
		title->hide();
	}

	content->clear();

	bool has_prev_text = false;

	if (!help_data.deprecated_message.is_empty()) {
		has_prev_text = true;

		Ref<Texture2D> error_icon = get_editor_theme_icon(SNAME("StatusError"));
		content->add_image(error_icon, error_icon->get_width(), error_icon->get_height());
		content->add_text(nbsp);
		content->push_color(get_theme_color(SNAME("error_color"), EditorStringName(Editor)));
		content->push_font(doc_bold_font);
		content->add_text(TTR("Deprecated:"));
		content->pop(); // font
		content->pop(); // color
		content->add_text(" ");
		_add_text_to_rt(help_data.deprecated_message, content, this, symbol_class_name);
	}

	if (!help_data.experimental_message.is_empty()) {
		if (has_prev_text) {
			content->add_newline();
			content->add_newline();
		}
		has_prev_text = true;

		Ref<Texture2D> warning_icon = get_editor_theme_icon(SNAME("NodeWarning"));
		content->add_image(warning_icon, warning_icon->get_width(), warning_icon->get_height());
		content->add_text(nbsp);
		content->push_color(get_theme_color(SNAME("warning_color"), EditorStringName(Editor)));
		content->push_font(doc_bold_font);
		content->add_text(TTR("Experimental:"));
		content->pop(); // font
		content->pop(); // color
		content->add_text(" ");
		_add_text_to_rt(help_data.experimental_message, content, this, symbol_class_name);
	}

	if (!help_data.description.is_empty()) {
		if (has_prev_text) {
			content->add_newline();
			content->add_newline();
		}
		has_prev_text = true;<--- Variable 'has_prev_text' is assigned a value that is never used.

		const Color comment_color = get_theme_color(SNAME("comment_color"), SNAME("EditorHelp"));
		_add_text_to_rt(help_data.description.replace("<EditorHelpBitCommentColor>", comment_color.to_html()), content, this, symbol_class_name);
	}

	if (is_inside_tree()) {
		update_content_height();
	}
}

void EditorHelpBit::_go_to_help(const String &p_what) {
	EditorNode::get_singleton()->get_editor_main_screen()->select(EditorMainScreen::EDITOR_SCRIPT);
	ScriptEditor::get_singleton()->goto_help(p_what);
	emit_signal(SNAME("request_hide"));
}

void EditorHelpBit::_meta_clicked(const String &p_select) {
	if (p_select.begins_with("$")) { // Enum.
		const String link = p_select.substr(1);

		String enum_class_name;
		String enum_name;
		if (CoreConstants::is_global_enum(link)) {
			enum_class_name = "@GlobalScope";
			enum_name = link;
		} else {
			const int dot_pos = link.rfind_char('.');
			if (dot_pos >= 0) {
				enum_class_name = link.left(dot_pos);
				enum_name = link.substr(dot_pos + 1);
			} else {
				enum_class_name = symbol_class_name;
				enum_name = link;
			}
		}

		_go_to_help("class_enum:" + enum_class_name + ":" + enum_name);
	} else if (p_select.begins_with("#")) { // Class.
		_go_to_help("class_name:" + p_select.substr(1));
	} else if (p_select.begins_with("@")) { // Member.
		const int tag_end = p_select.find_char(' ');
		const String tag = p_select.substr(1, tag_end - 1);
		const String link = p_select.substr(tag_end + 1).lstrip(" ");

		String topic;
		if (tag == "method") {
			topic = "class_method";
		} else if (tag == "constructor") {
			topic = "class_method";
		} else if (tag == "operator") {
			topic = "class_method";
		} else if (tag == "member") {
			topic = "class_property";
		} else if (tag == "enum") {
			topic = "class_enum";
		} else if (tag == "signal") {
			topic = "class_signal";
		} else if (tag == "constant") {
			topic = "class_constant";
		} else if (tag == "annotation") {
			topic = "class_annotation";
		} else if (tag == "theme_item") {
			topic = "class_theme_item";
		} else {
			return;
		}

		if (topic == "class_enum") {
			const String enum_link = link.trim_prefix("@GlobalScope.");
			if (CoreConstants::is_global_enum(enum_link)) {
				_go_to_help(topic + ":@GlobalScope:" + enum_link);
				return;
			}
		} else if (topic == "class_constant") {
			if (CoreConstants::is_global_constant(link)) {
				_go_to_help(topic + ":@GlobalScope:" + link);
				return;
			}
		}

		if (link.contains_char('.')) {
			const int class_end = link.rfind_char('.');
			_go_to_help(topic + ":" + link.left(class_end) + ":" + link.substr(class_end + 1));
		} else {
			_go_to_help(topic + ":" + symbol_class_name + ":" + link);
		}
	} else if (p_select.begins_with("http:") || p_select.begins_with("https:")) {
		OS::get_singleton()->shell_open(p_select);
	} else if (p_select.begins_with("^")) { // Copy button.
		DisplayServer::get_singleton()->clipboard_set(p_select.substr(1));
	}
}

void EditorHelpBit::_bind_methods() {
	ADD_SIGNAL(MethodInfo("request_hide"));
}

void EditorHelpBit::_notification(int p_what) {
	switch (p_what) {
		case NOTIFICATION_THEME_CHANGED:
			_update_labels();
			break;
	}
}

void EditorHelpBit::parse_symbol(const String &p_symbol, const String &p_prologue) {
	const PackedStringArray slices = p_symbol.split("|", true, 3);
	ERR_FAIL_COND_MSG(slices.size() < 3, R"(Invalid doc id: The expected format is "item_type|class_name|item_name[|item_data]".)");

	const String &item_type = slices[0];
	const String &class_name = slices[1];
	const String &item_name = slices[2];

	Dictionary item_data;
	if (slices.size() > 3) {
		item_data = JSON::parse_string(slices[3]);
	}

	symbol_doc_link = String();
	symbol_class_name = class_name;
	symbol_type = String();
	symbol_name = item_name;
	symbol_hint = SYMBOL_HINT_NONE;
	help_data = HelpData();

	if (item_type == "class") {
		symbol_doc_link = vformat("#%s", class_name);
		symbol_type = TTR("Class");
		symbol_name = class_name;
		symbol_hint = SYMBOL_HINT_INHERITANCE;
		help_data = _get_class_help_data(class_name);
	} else if (item_type == "enum") {
		symbol_doc_link = vformat("$%s.%s", class_name, item_name);
		symbol_type = TTR("Enumeration");
		help_data = _get_enum_help_data(class_name, item_name);
	} else if (item_type == "constant") {
		symbol_doc_link = vformat("@constant %s.%s", class_name, item_name);
		symbol_type = TTR("Constant");
		symbol_hint = SYMBOL_HINT_ASSIGNABLE;
		help_data = _get_constant_help_data(class_name, item_name);
	} else if (item_type == "property") {
		if (item_name.begins_with("metadata/")) {
			symbol_type = TTR("Metadata");
			symbol_name = item_name.trim_prefix("metadata/");
		} else if (class_name == "ProjectSettings" || class_name == "EditorSettings") {
			symbol_doc_link = vformat("@member %s.%s", class_name, item_name);
			symbol_type = TTR("Setting");
			symbol_hint = SYMBOL_HINT_ASSIGNABLE;
		} else {
			symbol_doc_link = vformat("@member %s.%s", class_name, item_name);
			symbol_type = TTR("Property");
			symbol_hint = SYMBOL_HINT_ASSIGNABLE;
		}
		help_data = _get_property_help_data(class_name, item_name);
	} else if (item_type == "internal_property") {
		symbol_type = TTR("Internal Property");
		help_data.description = "[color=<EditorHelpBitCommentColor>][i]" + TTR("This property can only be set in the Inspector.") + "[/i][/color]";
	} else if (item_type == "theme_item") {
		symbol_doc_link = vformat("@theme_item %s.%s", class_name, item_name);
		symbol_type = TTR("Theme Property");
		symbol_hint = SYMBOL_HINT_ASSIGNABLE;
		help_data = _get_theme_item_help_data(class_name, item_name);
	} else if (item_type == "method") {
		symbol_doc_link = vformat("@method %s.%s", class_name, item_name);
		symbol_type = TTR("Method");
		symbol_hint = SYMBOL_HINT_SIGNATURE;
		help_data = _get_method_help_data(class_name, item_name);
	} else if (item_type == "signal") {
		symbol_doc_link = vformat("@signal %s.%s", class_name, item_name);
		symbol_type = TTR("Signal");
		symbol_hint = SYMBOL_HINT_SIGNATURE;
		help_data = _get_signal_help_data(class_name, item_name);
	} else if (item_type == "annotation") {
		symbol_doc_link = vformat("@annotation %s.%s", class_name, item_name);
		symbol_type = TTR("Annotation");
		symbol_hint = SYMBOL_HINT_SIGNATURE;
		help_data = _get_annotation_help_data(class_name, item_name);
	} else if (item_type == "local_constant" || item_type == "local_variable") {
		symbol_type = (item_type == "local_constant") ? TTR("Local Constant") : TTR("Local Variable");
		symbol_hint = SYMBOL_HINT_ASSIGNABLE;
		help_data.description = item_data.get("description", "").operator String().strip_edges();
		if (item_data.get("is_deprecated", false)) {
			const String deprecated_message = item_data.get("deprecated_message", "").operator String().strip_edges();
			if (deprecated_message.is_empty()) {
				if (item_type == "local_constant") {
					help_data.deprecated_message = TTR("This constant may be changed or removed in future versions.");
				} else {
					help_data.deprecated_message = TTR("This variable may be changed or removed in future versions.");
				}
			} else {
				help_data.deprecated_message = deprecated_message;
			}
		}
		if (item_data.get("is_experimental", false)) {
			const String experimental_message = item_data.get("experimental_message", "").operator String().strip_edges();
			if (experimental_message.is_empty()) {
				if (item_type == "local_constant") {
					help_data.experimental_message = TTR("This constant may be changed or removed in future versions.");
				} else {
					help_data.experimental_message = TTR("This variable may be changed or removed in future versions.");
				}
			} else {
				help_data.experimental_message = experimental_message;
			}
		}
		help_data.doc_type.type = item_data.get("doc_type", "");
		help_data.doc_type.enumeration = item_data.get("enumeration", "");
		help_data.doc_type.is_bitfield = item_data.get("is_bitfield", false);
		help_data.value = item_data.get("value", "");
	} else {
		ERR_FAIL_MSG("Invalid doc id: Unknown item type " + item_type.quote() + ".");
	}

	// Do not add links for custom or undocumented symbols.
	if (symbol_class_name.is_empty() || (help_data.description.is_empty() && help_data.deprecated_message.is_empty() && help_data.experimental_message.is_empty())) {
		symbol_doc_link = String();
	}

	if (!p_prologue.is_empty()) {
		if (help_data.description.is_empty()) {
			help_data.description = p_prologue;
		} else {
			help_data.description = p_prologue + "\n" + help_data.description;
		}
	}

	if (help_data.description.is_empty()) {
		help_data.description = "[color=<EditorHelpBitCommentColor>][i]" + TTR("No description available.") + "[/i][/color]";
	}

	if (is_inside_tree()) {
		_update_labels();
	}
}

void EditorHelpBit::set_custom_text(const String &p_type, const String &p_name, const String &p_description) {
	symbol_doc_link = String();
	symbol_class_name = String();
	symbol_type = p_type;
	symbol_name = p_name;
	symbol_hint = SYMBOL_HINT_NONE;

	help_data = HelpData();
	help_data.description = p_description;

	if (is_inside_tree()) {
		_update_labels();
	}
}

void EditorHelpBit::set_content_height_limits(float p_min, float p_max) {
	ERR_FAIL_COND(p_min > p_max);
	content_min_height = p_min;
	content_max_height = p_max;

	if (is_inside_tree()) {
		update_content_height();
	}
}

void EditorHelpBit::update_content_height() {
	float content_height = content->get_content_height();
	const Ref<StyleBox> style = content->get_theme_stylebox(CoreStringName(normal));
	if (style.is_valid()) {
		content_height += style->get_content_margin(SIDE_TOP) + style->get_content_margin(SIDE_BOTTOM);
	}
	content->set_custom_minimum_size(Size2(content->get_custom_minimum_size().x, CLAMP(content_height, content_min_height, content_max_height)));
}

EditorHelpBit::EditorHelpBit(const String &p_symbol, const String &p_prologue, bool p_use_class_prefix, bool p_allow_selection) {
	add_theme_constant_override("separation", 0);

	title = memnew(RichTextLabel);
	title->set_theme_type_variation("EditorHelpBitTitle");
	title->set_custom_minimum_size(Size2(640 * EDSCALE, 0)); // GH-93031. Set the minimum width even if `fit_content` is true.
	title->set_fit_content(true);
	title->set_selection_enabled(p_allow_selection);
	title->set_context_menu_enabled(p_allow_selection);
	title->set_selection_modifier(callable_mp_static(_replace_nbsp_with_space));
	title->connect("meta_clicked", callable_mp(this, &EditorHelpBit::_meta_clicked));
	title->hide();
	add_child(title);

	content_min_height = 48 * EDSCALE;
	content_max_height = 360 * EDSCALE;

	content = memnew(RichTextLabel);
	content->set_theme_type_variation("EditorHelpBitContent");
	content->set_custom_minimum_size(Size2(640 * EDSCALE, content_min_height));
	content->set_selection_enabled(p_allow_selection);
	content->set_context_menu_enabled(p_allow_selection);
	content->set_selection_modifier(callable_mp_static(_replace_nbsp_with_space));
	content->connect("meta_clicked", callable_mp(this, &EditorHelpBit::_meta_clicked));
	add_child(content);

	use_class_prefix = p_use_class_prefix;

	if (!p_symbol.is_empty()) {
		parse_symbol(p_symbol, p_prologue);
	} else if (!p_prologue.is_empty()) {
		set_custom_text(String(), String(), p_prologue);
	}
}

/// EditorHelpBitTooltip ///

bool EditorHelpBitTooltip::_is_tooltip_visible = false;

Control *EditorHelpBitTooltip::_make_invisible_control() {
	Control *control = memnew(Control);
	control->set_visible(false);
	return control;
}

void EditorHelpBitTooltip::_start_timer() {
	if (timer->is_inside_tree() && timer->is_stopped()) {
		timer->start();
	}
}

void EditorHelpBitTooltip::_target_gui_input(const Ref<InputEvent> &p_event) {
	// Only scrolling is not checked in `NOTIFICATION_INTERNAL_PROCESS`.
	const Ref<InputEventMouseButton> mb = p_event;
	if (mb.is_valid()) {
		switch (mb->get_button_index()) {
			case MouseButton::WHEEL_UP:
			case MouseButton::WHEEL_DOWN:
			case MouseButton::WHEEL_LEFT:
			case MouseButton::WHEEL_RIGHT:
				queue_free();
				break;
			default:
				break;
		}
	}
}

void EditorHelpBitTooltip::_notification(int p_what) {
	switch (p_what) {
		case NOTIFICATION_ENTER_TREE:
			_is_tooltip_visible = true;
			_enter_tree_time = OS::get_singleton()->get_ticks_msec();
			break;
		case NOTIFICATION_EXIT_TREE:
			_is_tooltip_visible = false;
			break;
		case NOTIFICATION_WM_MOUSE_ENTER:
			_is_mouse_inside_tooltip = true;
			timer->stop();
			break;
		case NOTIFICATION_WM_MOUSE_EXIT:
			_is_mouse_inside_tooltip = false;
			_start_timer();
			break;
		case NOTIFICATION_INTERNAL_PROCESS:
			// A workaround to hide the tooltip since the window does not receive keyboard events
			// with `FLAG_POPUP` and `FLAG_NO_FOCUS` flags, so we can't use `_input_from_window()`.
			if (is_inside_tree()) {
				if (Input::get_singleton()->is_action_just_pressed(SNAME("ui_cancel"), true)) {
					queue_free();
					get_parent_viewport()->set_input_as_handled();
				} else if (Input::get_singleton()->is_anything_pressed_except_mouse()) {
					queue_free();
				} else if (!Input::get_singleton()->get_mouse_button_mask().is_empty()) {
					if (!_is_mouse_inside_tooltip) {
						queue_free();
					}
				} else if (!Input::get_singleton()->get_last_mouse_velocity().is_zero_approx()) {
					if (!_is_mouse_inside_tooltip && OS::get_singleton()->get_ticks_msec() - _enter_tree_time > 250) {
						_start_timer();
					}
				}
			}
			break;
	}
}

Control *EditorHelpBitTooltip::show_tooltip(Control *p_target, const String &p_symbol, const String &p_prologue, bool p_use_class_prefix) {
	ERR_FAIL_NULL_V(p_target, _make_invisible_control());

	// Show the custom tooltip only if it is not already visible.
	// The viewport will retrigger `make_custom_tooltip()` every few seconds
	// because the return control is not visible even if the custom tooltip is displayed.
	if (_is_tooltip_visible || Input::get_singleton()->is_anything_pressed()) {
		return _make_invisible_control();
	}

	EditorHelpBit *help_bit = memnew(EditorHelpBit(p_symbol, p_prologue, p_use_class_prefix, false));

	EditorHelpBitTooltip *tooltip = memnew(EditorHelpBitTooltip(p_target));
	help_bit->connect("request_hide", callable_mp(static_cast<Node *>(tooltip), &Node::queue_free));
	tooltip->add_child(help_bit);
	p_target->add_child(tooltip);

	help_bit->update_content_height();
	tooltip->popup_under_cursor();

	return _make_invisible_control();
}

// Copy-paste from `Viewport::_gui_show_tooltip()`.
void EditorHelpBitTooltip::popup_under_cursor() {
	Point2 mouse_pos = get_mouse_position();
	Point2 tooltip_offset = GLOBAL_GET("display/mouse_cursor/tooltip_position_offset");
	Rect2 r(mouse_pos + tooltip_offset, get_contents_minimum_size());
	r.size = r.size.min(get_max_size());

	Window *window = get_parent_visible_window();
	Rect2i vr;
	if (is_embedded()) {
		vr = get_embedder()->get_visible_rect();
	} else {
		vr = window->get_usable_parent_rect();
	}

	if (r.size.x + r.position.x > vr.size.x + vr.position.x) {
		// Place it in the opposite direction. If it fails, just hug the border.
		r.position.x = mouse_pos.x - r.size.x - tooltip_offset.x;

		if (r.position.x < vr.position.x) {
			r.position.x = vr.position.x + vr.size.x - r.size.x;
		}
	} else if (r.position.x < vr.position.x) {
		r.position.x = vr.position.x;
	}

	if (r.size.y + r.position.y > vr.size.y + vr.position.y) {
		// Same as above.
		r.position.y = mouse_pos.y - r.size.y - tooltip_offset.y;

		if (r.position.y < vr.position.y) {
			r.position.y = vr.position.y + vr.size.y - r.size.y;
		}
	} else if (r.position.y < vr.position.y) {
		r.position.y = vr.position.y;
	}

	// When `FLAG_POPUP` is false, it prevents the editor from losing focus when displaying the tooltip.
	// This way, clicks and double-clicks are still available outside the tooltip.
	set_flag(Window::FLAG_POPUP, false);
	set_flag(Window::FLAG_NO_FOCUS, true);
	popup(r);
}

EditorHelpBitTooltip::EditorHelpBitTooltip(Control *p_target) {
	ERR_FAIL_NULL(p_target);

	set_theme_type_variation("TooltipPanel");

	timer = memnew(Timer);
	timer->set_wait_time(0.25);
	timer->connect("timeout", callable_mp(static_cast<Node *>(this), &Node::queue_free));
	add_child(timer);

	p_target->connect(SceneStringName(mouse_exited), callable_mp(this, &EditorHelpBitTooltip::_start_timer));
	p_target->connect(SceneStringName(gui_input), callable_mp(this, &EditorHelpBitTooltip::_target_gui_input));

	set_process_internal(true);
}

#if defined(MODULE_GDSCRIPT_ENABLED) || defined(MODULE_MONO_ENABLED)
/// EditorHelpHighlighter ///

EditorHelpHighlighter *EditorHelpHighlighter::singleton = nullptr;

void EditorHelpHighlighter::create_singleton() {
	ERR_FAIL_COND(singleton != nullptr);
	singleton = memnew(EditorHelpHighlighter);
}

void EditorHelpHighlighter::free_singleton() {
	ERR_FAIL_NULL(singleton);
	memdelete(singleton);
	singleton = nullptr;
}

EditorHelpHighlighter *EditorHelpHighlighter::get_singleton() {
	return singleton;
}

EditorHelpHighlighter::HighlightData EditorHelpHighlighter::_get_highlight_data(Language p_language, const String &p_source, bool p_use_cache) {
	switch (p_language) {
		case LANGUAGE_GDSCRIPT:
#ifndef MODULE_GDSCRIPT_ENABLED
			ERR_FAIL_V_MSG(HighlightData(), "GDScript module is disabled.");
#endif
			break;
		case LANGUAGE_CSHARP:
#ifndef MODULE_MONO_ENABLED
			ERR_FAIL_V_MSG(HighlightData(), "Mono module is disabled.");
#endif
			break;
		default:
			ERR_FAIL_V_MSG(HighlightData(), "Invalid parameter \"p_language\".");
	}

	if (p_use_cache) {
		const HashMap<String, HighlightData>::ConstIterator E = highlight_data_caches[p_language].find(p_source);
		if (E) {
			return E->value;
		}
	}

	text_edits[p_language]->set_text(p_source);
	if (scripts[p_language].is_valid()) { // See GH-89610.
		scripts[p_language]->set_source_code(p_source);
	}
	highlighters[p_language]->_update_cache();

	HighlightData result;

	int source_offset = 0;
	int result_index = 0;
	for (int i = 0; i < text_edits[p_language]->get_line_count(); i++) {
		const Dictionary dict = highlighters[p_language]->_get_line_syntax_highlighting_impl(i);

		result.resize(result.size() + dict.size());

		const Variant *key = nullptr;
		int prev_column = -1;
		while ((key = dict.next(key)) != nullptr) {
			const int column = *key;
			ERR_FAIL_COND_V(column <= prev_column, HighlightData());
			prev_column = column;

			const Color color = dict[*key].operator Dictionary().get("color", Color());

			result.write[result_index] = { source_offset + column, color };
			result_index++;
		}

		source_offset += text_edits[p_language]->get_line(i).length() + 1; // Plus newline.
	}

	if (p_use_cache) {
		highlight_data_caches[p_language][p_source] = result;
	}

	return result;
}

void EditorHelpHighlighter::highlight(RichTextLabel *p_rich_text_label, Language p_language, const String &p_source, bool p_use_cache) {
	ERR_FAIL_NULL(p_rich_text_label);

	const HighlightData highlight_data = _get_highlight_data(p_language, p_source, p_use_cache);

	if (!highlight_data.is_empty()) {
		for (int i = 1; i < highlight_data.size(); i++) {
			const Pair<int, Color> &prev = highlight_data[i - 1];
			const Pair<int, Color> &curr = highlight_data[i];
			p_rich_text_label->push_color(prev.second);
			p_rich_text_label->add_text(p_source.substr(prev.first, curr.first - prev.first));
			p_rich_text_label->pop(); // color
		}

		const Pair<int, Color> &last = highlight_data[highlight_data.size() - 1];
		p_rich_text_label->push_color(last.second);
		p_rich_text_label->add_text(p_source.substr(last.first));
		p_rich_text_label->pop(); // color
	}
}

void EditorHelpHighlighter::reset_cache() {
	const Color text_color = EDITOR_GET("text_editor/theme/highlighting/text_color");

#ifdef MODULE_GDSCRIPT_ENABLED
	highlight_data_caches[LANGUAGE_GDSCRIPT].clear();
	text_edits[LANGUAGE_GDSCRIPT]->add_theme_color_override(SceneStringName(font_color), text_color);
#endif

#ifdef MODULE_MONO_ENABLED
	highlight_data_caches[LANGUAGE_CSHARP].clear();
	text_edits[LANGUAGE_CSHARP]->add_theme_color_override(SceneStringName(font_color), text_color);
#endif
}

EditorHelpHighlighter::EditorHelpHighlighter() {
	const Color text_color = EDITOR_GET("text_editor/theme/highlighting/text_color");

#ifdef MODULE_GDSCRIPT_ENABLED
	TextEdit *gdscript_text_edit = memnew(TextEdit);
	gdscript_text_edit->add_theme_color_override(SceneStringName(font_color), text_color);

	Ref<GDScript> gdscript;
	gdscript.instantiate();

	Ref<GDScriptSyntaxHighlighter> gdscript_highlighter;
	gdscript_highlighter.instantiate();
	gdscript_highlighter->set_text_edit(gdscript_text_edit);
	gdscript_highlighter->_set_edited_resource(gdscript);

	text_edits[LANGUAGE_GDSCRIPT] = gdscript_text_edit;
	scripts[LANGUAGE_GDSCRIPT] = gdscript;
	highlighters[LANGUAGE_GDSCRIPT] = gdscript_highlighter;
#endif

#ifdef MODULE_MONO_ENABLED
	TextEdit *csharp_text_edit = memnew(TextEdit);
	csharp_text_edit->add_theme_color_override(SceneStringName(font_color), text_color);

	// See GH-89610.
	//Ref<CSharpScript> csharp;
	//csharp.instantiate();

	Ref<EditorStandardSyntaxHighlighter> csharp_highlighter;
	csharp_highlighter.instantiate();
	csharp_highlighter->set_text_edit(csharp_text_edit);
	//csharp_highlighter->_set_edited_resource(csharp);
	csharp_highlighter->_set_script_language(CSharpLanguage::get_singleton());

	text_edits[LANGUAGE_CSHARP] = csharp_text_edit;
	//scripts[LANGUAGE_CSHARP] = csharp;
	highlighters[LANGUAGE_CSHARP] = csharp_highlighter;
#endif
}

EditorHelpHighlighter::~EditorHelpHighlighter() {
#ifdef MODULE_GDSCRIPT_ENABLED
	memdelete(text_edits[LANGUAGE_GDSCRIPT]);
#endif

#ifdef MODULE_MONO_ENABLED
	memdelete(text_edits[LANGUAGE_CSHARP]);
#endif
}

#endif // defined(MODULE_GDSCRIPT_ENABLED) || defined(MODULE_MONO_ENABLED)

/// FindBar ///

FindBar::FindBar() {
	search_text = memnew(LineEdit);
	add_child(search_text);
	search_text->set_custom_minimum_size(Size2(100 * EDSCALE, 0));
	search_text->set_h_size_flags(SIZE_EXPAND_FILL);
	search_text->connect(SceneStringName(text_changed), callable_mp(this, &FindBar::_search_text_changed));
	search_text->connect(SceneStringName(text_submitted), callable_mp(this, &FindBar::_search_text_submitted));

	matches_label = memnew(Label);
	add_child(matches_label);
	matches_label->hide();

	find_prev = memnew(Button);
	find_prev->set_flat(true);
	add_child(find_prev);
	find_prev->set_focus_mode(FOCUS_NONE);
	find_prev->connect(SceneStringName(pressed), callable_mp(this, &FindBar::search_prev));

	find_next = memnew(Button);
	find_next->set_flat(true);
	add_child(find_next);
	find_next->set_focus_mode(FOCUS_NONE);
	find_next->connect(SceneStringName(pressed), callable_mp(this, &FindBar::search_next));

	Control *space = memnew(Control);
	add_child(space);
	space->set_custom_minimum_size(Size2(4, 0) * EDSCALE);

	hide_button = memnew(TextureButton);
	add_child(hide_button);
	hide_button->set_focus_mode(FOCUS_NONE);
	hide_button->set_ignore_texture_size(true);
	hide_button->set_stretch_mode(TextureButton::STRETCH_KEEP_CENTERED);
	hide_button->connect(SceneStringName(pressed), callable_mp(this, &FindBar::_hide_bar));
}

void FindBar::popup_search() {
	show();
	bool grabbed_focus = false;
	if (!search_text->has_focus()) {
		search_text->grab_focus();
		grabbed_focus = true;
	}

	if (!search_text->get_text().is_empty()) {
		search_text->select_all();
		search_text->set_caret_column(search_text->get_text().length());
		if (grabbed_focus) {
			_search();
		}
	}
}

void FindBar::_notification(int p_what) {
	switch (p_what) {
		case NOTIFICATION_THEME_CHANGED: {
			find_prev->set_button_icon(get_editor_theme_icon(SNAME("MoveUp")));
			find_next->set_button_icon(get_editor_theme_icon(SNAME("MoveDown")));
			hide_button->set_texture_normal(get_editor_theme_icon(SNAME("Close")));
			hide_button->set_texture_hover(get_editor_theme_icon(SNAME("Close")));
			hide_button->set_texture_pressed(get_editor_theme_icon(SNAME("Close")));
			hide_button->set_custom_minimum_size(hide_button->get_texture_normal()->get_size());
			matches_label->add_theme_color_override(SceneStringName(font_color), results_count > 0 ? get_theme_color(SceneStringName(font_color), SNAME("Label")) : get_theme_color(SNAME("error_color"), EditorStringName(Editor)));
		} break;

		case NOTIFICATION_VISIBILITY_CHANGED: {
			set_process_unhandled_input(is_visible_in_tree());
		} break;
	}
}

void FindBar::set_rich_text_label(RichTextLabel *p_rich_text_label) {
	rich_text_label = p_rich_text_label;
}

bool FindBar::search_next() {
	return _search();
}

bool FindBar::search_prev() {
	return _search(true);
}

bool FindBar::_search(bool p_search_previous) {
	String stext = search_text->get_text();
	bool keep = prev_search == stext;

	bool ret = rich_text_label->search(stext, keep, p_search_previous);

	prev_search = stext;

	if (ret) {
		_update_results_count();
	} else {
		results_count = 0;
	}
	_update_matches_label();

	return ret;
}

void FindBar::_update_results_count() {
	results_count = 0;

	String searched = search_text->get_text();
	if (searched.is_empty()) {
		return;
	}

	String full_text = rich_text_label->get_parsed_text();

	int from_pos = 0;

	while (true) {
		int pos = full_text.findn(searched, from_pos);
		if (pos == -1) {
			break;
		}

		results_count++;
		from_pos = pos + searched.length();
	}
}

void FindBar::_update_matches_label() {
	if (search_text->get_text().is_empty() || results_count == -1) {
		matches_label->hide();
	} else {
		matches_label->show();

		matches_label->add_theme_color_override(SceneStringName(font_color), results_count > 0 ? get_theme_color(SceneStringName(font_color), SNAME("Label")) : get_theme_color(SNAME("error_color"), EditorStringName(Editor)));
		matches_label->set_text(vformat(results_count == 1 ? TTR("%d match.") : TTR("%d matches."), results_count));
	}
}

void FindBar::_hide_bar() {
	if (search_text->has_focus()) {
		rich_text_label->grab_focus();
	}

	hide();
}

void FindBar::unhandled_input(const Ref<InputEvent> &p_event) {
	ERR_FAIL_COND(p_event.is_null());

	Ref<InputEventKey> k = p_event;
	if (k.is_valid() && k->is_action_pressed(SNAME("ui_cancel"), false, true)) {
		if (rich_text_label->has_focus() || is_ancestor_of(get_viewport()->gui_get_focus_owner())) {
			_hide_bar();
			accept_event();
		}
	}
}

void FindBar::_search_text_changed(const String &p_text) {
	search_next();
}

void FindBar::_search_text_submitted(const String &p_text) {
	if (Input::get_singleton()->is_key_pressed(Key::SHIFT)) {
		search_prev();
	} else {
		search_next();
	}
}