test_text_edit.h 339 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163
  1. /**************************************************************************/
  2. /* test_text_edit.h */
  3. /**************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /**************************************************************************/
  8. /* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
  9. /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
  10. /* */
  11. /* Permission is hereby granted, free of charge, to any person obtaining */
  12. /* a copy of this software and associated documentation files (the */
  13. /* "Software"), to deal in the Software without restriction, including */
  14. /* without limitation the rights to use, copy, modify, merge, publish, */
  15. /* distribute, sublicense, and/or sell copies of the Software, and to */
  16. /* permit persons to whom the Software is furnished to do so, subject to */
  17. /* the following conditions: */
  18. /* */
  19. /* The above copyright notice and this permission notice shall be */
  20. /* included in all copies or substantial portions of the Software. */
  21. /* */
  22. /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
  23. /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
  24. /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
  25. /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
  26. /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
  27. /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
  28. /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  29. /**************************************************************************/
  30. #ifndef TEST_TEXT_EDIT_H
  31. #define TEST_TEXT_EDIT_H
  32. #include "scene/gui/text_edit.h"
  33. #include "tests/test_macros.h"
  34. namespace TestTextEdit {
  35. static inline Array build_array() {
  36. return Array();
  37. }
  38. template <typename... Targs>
  39. static inline Array build_array(Variant item, Targs... Fargs) {
  40. Array a = build_array(Fargs...);
  41. a.push_front(item);
  42. return a;
  43. }
  44. static inline Array reverse_nested(Array array) {
  45. Array reversed_array = array.duplicate(true);
  46. reversed_array.reverse();
  47. for (int i = 0; i < reversed_array.size(); i++) {
  48. ((Array)reversed_array[i]).reverse();
  49. }
  50. return reversed_array;
  51. }
  52. TEST_CASE("[SceneTree][TextEdit] text entry") {
  53. SceneTree::get_singleton()->get_root()->set_physics_object_picking(false);
  54. TextEdit *text_edit = memnew(TextEdit);
  55. SceneTree::get_singleton()->get_root()->add_child(text_edit);
  56. text_edit->grab_focus();
  57. Array empty_signal_args;
  58. empty_signal_args.push_back(Array());
  59. SUBCASE("[TextEdit] text entry") {
  60. SIGNAL_WATCH(text_edit, "text_set");
  61. SIGNAL_WATCH(text_edit, "text_changed");
  62. SIGNAL_WATCH(text_edit, "lines_edited_from");
  63. SIGNAL_WATCH(text_edit, "caret_changed");
  64. Array lines_edited_args = build_array(build_array(0, 0), build_array(0, 0));
  65. SUBCASE("[TextEdit] clear and set text") {
  66. // "text_changed" should not be emitted on clear / set.
  67. text_edit->clear();
  68. MessageQueue::get_singleton()->flush();
  69. CHECK(text_edit->get_text() == "");
  70. CHECK(text_edit->get_caret_column() == 0);
  71. CHECK(text_edit->get_line_count() == 1);
  72. SIGNAL_CHECK("text_set", empty_signal_args);
  73. SIGNAL_CHECK("lines_edited_from", lines_edited_args);
  74. SIGNAL_CHECK_FALSE("caret_changed");
  75. SIGNAL_CHECK_FALSE("text_changed");
  76. text_edit->set_text("test text");
  77. MessageQueue::get_singleton()->flush();
  78. CHECK(text_edit->get_text() == "test text");
  79. CHECK(text_edit->get_caret_column() == 0);
  80. CHECK(text_edit->get_line_count() == 1);
  81. SIGNAL_CHECK("text_set", empty_signal_args);
  82. SIGNAL_CHECK("lines_edited_from", lines_edited_args);
  83. SIGNAL_CHECK("caret_changed", empty_signal_args);
  84. SIGNAL_CHECK_FALSE("text_changed");
  85. text_edit->clear();
  86. MessageQueue::get_singleton()->flush();
  87. CHECK(text_edit->get_text() == "");
  88. CHECK(text_edit->get_caret_column() == 0);
  89. SIGNAL_CHECK("text_set", empty_signal_args);
  90. SIGNAL_CHECK("lines_edited_from", lines_edited_args);
  91. SIGNAL_CHECK_FALSE("caret_changed");
  92. SIGNAL_CHECK_FALSE("text_changed");
  93. // Can undo / redo words when editable.
  94. text_edit->undo();
  95. MessageQueue::get_singleton()->flush();
  96. CHECK(text_edit->get_text() == "test text");
  97. CHECK(text_edit->get_caret_column() == 0);
  98. SIGNAL_CHECK("lines_edited_from", lines_edited_args);
  99. SIGNAL_CHECK("text_changed", empty_signal_args);
  100. SIGNAL_CHECK_FALSE("caret_changed");
  101. SIGNAL_CHECK_FALSE("text_set");
  102. text_edit->redo();
  103. MessageQueue::get_singleton()->flush();
  104. CHECK(text_edit->get_text() == "");
  105. CHECK(text_edit->get_caret_column() == 0);
  106. SIGNAL_CHECK("lines_edited_from", lines_edited_args);
  107. SIGNAL_CHECK("text_changed", empty_signal_args);
  108. SIGNAL_CHECK_FALSE("caret_changed");
  109. SIGNAL_CHECK_FALSE("text_set");
  110. // Cannot undo when not-editable but should still clear.
  111. text_edit->undo();
  112. MessageQueue::get_singleton()->flush();
  113. CHECK(text_edit->get_text() == "test text");
  114. CHECK(text_edit->get_caret_column() == 0);
  115. SIGNAL_CHECK("lines_edited_from", lines_edited_args);
  116. SIGNAL_CHECK("text_changed", empty_signal_args);
  117. SIGNAL_CHECK_FALSE("caret_changed");
  118. SIGNAL_CHECK_FALSE("text_set");
  119. // Can clear even if not editable.
  120. text_edit->set_editable(false);
  121. Array lines_edited_clear_args = build_array(build_array(1, 0));
  122. text_edit->clear();
  123. MessageQueue::get_singleton()->flush();
  124. CHECK(text_edit->get_text() == "");
  125. CHECK(text_edit->get_caret_column() == 0);
  126. SIGNAL_CHECK("text_set", empty_signal_args);
  127. SIGNAL_CHECK("lines_edited_from", lines_edited_clear_args);
  128. SIGNAL_CHECK_FALSE("caret_changed");
  129. SIGNAL_CHECK_FALSE("text_changed");
  130. text_edit->set_editable(true);
  131. text_edit->undo();
  132. MessageQueue::get_singleton()->flush();
  133. CHECK(text_edit->get_text() == "");
  134. CHECK(text_edit->get_caret_column() == 0);
  135. SIGNAL_CHECK_FALSE("text_set");
  136. SIGNAL_CHECK_FALSE("lines_edited_from");
  137. SIGNAL_CHECK_FALSE("text_changed");
  138. SIGNAL_CHECK_FALSE("caret_changed");
  139. // Can still undo set_text.
  140. text_edit->set_editable(false);
  141. text_edit->set_text("test text");
  142. MessageQueue::get_singleton()->flush();
  143. CHECK(text_edit->get_text() == "test text");
  144. CHECK(text_edit->get_caret_column() == 0);
  145. SIGNAL_CHECK("text_set", empty_signal_args);
  146. SIGNAL_CHECK("lines_edited_from", lines_edited_args);
  147. SIGNAL_CHECK("caret_changed", empty_signal_args);
  148. SIGNAL_CHECK_FALSE("text_changed");
  149. text_edit->set_editable(true);
  150. text_edit->undo();
  151. MessageQueue::get_singleton()->flush();
  152. CHECK(text_edit->get_text() == "");
  153. CHECK(text_edit->get_caret_column() == 0);
  154. SIGNAL_CHECK("lines_edited_from", lines_edited_args);
  155. SIGNAL_CHECK("text_changed", empty_signal_args);
  156. SIGNAL_CHECK_FALSE("caret_changed");
  157. SIGNAL_CHECK_FALSE("text_set");
  158. // Any selections are removed.
  159. text_edit->set_text("test text");
  160. MessageQueue::get_singleton()->flush();
  161. text_edit->select_all();
  162. SIGNAL_CHECK("caret_changed", empty_signal_args);
  163. MessageQueue::get_singleton()->flush();
  164. CHECK(text_edit->get_text() == "test text");
  165. CHECK(text_edit->get_caret_column() == 9);
  166. CHECK(text_edit->has_selection());
  167. SIGNAL_CHECK("text_set", empty_signal_args);
  168. SIGNAL_CHECK("lines_edited_from", lines_edited_args);
  169. SIGNAL_CHECK("caret_changed", empty_signal_args);
  170. SIGNAL_CHECK_FALSE("text_changed");
  171. text_edit->set_text("test");
  172. MessageQueue::get_singleton()->flush();
  173. CHECK(text_edit->get_text() == "test");
  174. CHECK(text_edit->get_caret_column() == 0);
  175. CHECK_FALSE(text_edit->has_selection());
  176. SIGNAL_CHECK("text_set", empty_signal_args);
  177. SIGNAL_CHECK("lines_edited_from", lines_edited_args);
  178. SIGNAL_CHECK("caret_changed", empty_signal_args);
  179. SIGNAL_CHECK_FALSE("text_changed");
  180. text_edit->select_all();
  181. MessageQueue::get_singleton()->flush();
  182. SIGNAL_CHECK("caret_changed", empty_signal_args);
  183. CHECK(text_edit->has_selection());
  184. text_edit->clear();
  185. MessageQueue::get_singleton()->flush();
  186. CHECK(text_edit->get_text() == "");
  187. CHECK(text_edit->get_caret_column() == 0);
  188. CHECK_FALSE(text_edit->has_selection());
  189. SIGNAL_CHECK("text_set", empty_signal_args);
  190. SIGNAL_CHECK("lines_edited_from", lines_edited_args);
  191. SIGNAL_CHECK("caret_changed", empty_signal_args);
  192. SIGNAL_CHECK_FALSE("text_changed");
  193. }
  194. SUBCASE("[TextEdit] insert text") {
  195. // insert_text is 0 indexed.
  196. ERR_PRINT_OFF;
  197. text_edit->insert_text("test", 1, 0);
  198. ERR_PRINT_ON;
  199. MessageQueue::get_singleton()->flush();
  200. CHECK(text_edit->get_text() == "");
  201. SIGNAL_CHECK_FALSE("lines_edited_from");
  202. SIGNAL_CHECK_FALSE("text_changed");
  203. SIGNAL_CHECK_FALSE("caret_changed");
  204. SIGNAL_CHECK_FALSE("text_set");
  205. // Insert text when there is no text.
  206. lines_edited_args = build_array(build_array(0, 0));
  207. text_edit->insert_text("tes", 0, 0);
  208. MessageQueue::get_singleton()->flush();
  209. CHECK(text_edit->get_text() == "tes");
  210. CHECK(text_edit->get_caret_line() == 0);
  211. CHECK(text_edit->get_caret_column() == 3);
  212. SIGNAL_CHECK("lines_edited_from", lines_edited_args);
  213. SIGNAL_CHECK("text_changed", empty_signal_args);
  214. SIGNAL_CHECK("caret_changed", empty_signal_args);
  215. SIGNAL_CHECK_FALSE("text_set");
  216. // Insert multiple lines.
  217. lines_edited_args = build_array(build_array(0, 1));
  218. text_edit->insert_text("t\ninserting text", 0, 3);
  219. MessageQueue::get_singleton()->flush();
  220. CHECK(text_edit->get_text() == "test\ninserting text");
  221. CHECK(text_edit->get_caret_line() == 1);
  222. CHECK(text_edit->get_caret_column() == 14);
  223. SIGNAL_CHECK("lines_edited_from", lines_edited_args);
  224. SIGNAL_CHECK("text_changed", empty_signal_args);
  225. SIGNAL_CHECK("caret_changed", empty_signal_args);
  226. SIGNAL_CHECK_FALSE("text_set");
  227. // Can insert even if not editable.
  228. lines_edited_args = build_array(build_array(1, 1));
  229. text_edit->set_editable(false);
  230. text_edit->insert_text("mid", 1, 2);
  231. MessageQueue::get_singleton()->flush();
  232. CHECK(text_edit->get_text() == "test\ninmidserting text");
  233. CHECK(text_edit->get_caret_line() == 1);
  234. CHECK(text_edit->get_caret_column() == 17);
  235. SIGNAL_CHECK("lines_edited_from", lines_edited_args);
  236. SIGNAL_CHECK("text_changed", empty_signal_args);
  237. SIGNAL_CHECK("caret_changed", empty_signal_args);
  238. SIGNAL_CHECK_FALSE("text_set");
  239. text_edit->set_editable(true);
  240. // Undo insert.
  241. text_edit->undo();
  242. MessageQueue::get_singleton()->flush();
  243. CHECK(text_edit->get_text() == "test\ninserting text");
  244. CHECK(text_edit->get_caret_line() == 1);
  245. CHECK(text_edit->get_caret_column() == 14);
  246. SIGNAL_CHECK("lines_edited_from", lines_edited_args);
  247. SIGNAL_CHECK("text_changed", empty_signal_args);
  248. SIGNAL_CHECK("caret_changed", empty_signal_args);
  249. SIGNAL_CHECK_FALSE("text_set");
  250. // Redo insert.
  251. text_edit->redo();
  252. MessageQueue::get_singleton()->flush();
  253. CHECK(text_edit->get_text() == "test\ninmidserting text");
  254. CHECK(text_edit->get_caret_line() == 1);
  255. CHECK(text_edit->get_caret_column() == 17);
  256. SIGNAL_CHECK("lines_edited_from", lines_edited_args);
  257. SIGNAL_CHECK("text_changed", empty_signal_args);
  258. SIGNAL_CHECK("caret_changed", empty_signal_args);
  259. SIGNAL_CHECK_FALSE("text_set");
  260. // Insert offsets carets after the edit.
  261. text_edit->add_caret(1, 1);
  262. text_edit->add_caret(1, 4);
  263. text_edit->select(1, 4, 1, 6, 2);
  264. MessageQueue::get_singleton()->flush();
  265. SIGNAL_DISCARD("caret_changed");
  266. lines_edited_args = build_array(build_array(1, 2));
  267. text_edit->insert_text("\n ", 1, 2);
  268. MessageQueue::get_singleton()->flush();
  269. CHECK(text_edit->get_text() == "test\nin\n midserting text");
  270. CHECK(text_edit->get_caret_count() == 3);
  271. CHECK_FALSE(text_edit->has_selection(0));
  272. CHECK(text_edit->get_caret_line(0) == 2);
  273. CHECK(text_edit->get_caret_column(0) == 16);
  274. CHECK_FALSE(text_edit->has_selection(1));
  275. CHECK(text_edit->get_caret_line(1) == 1);
  276. CHECK(text_edit->get_caret_column(1) == 1);
  277. CHECK(text_edit->has_selection(2));
  278. CHECK(text_edit->get_caret_line(2) == 2);
  279. CHECK(text_edit->get_caret_column(2) == 5);
  280. CHECK(text_edit->get_selection_origin_line(2) == 2);
  281. CHECK(text_edit->get_selection_origin_column(2) == 3);
  282. SIGNAL_CHECK("lines_edited_from", lines_edited_args);
  283. SIGNAL_CHECK("text_changed", empty_signal_args);
  284. SIGNAL_CHECK("caret_changed", empty_signal_args);
  285. SIGNAL_CHECK_FALSE("text_set");
  286. text_edit->remove_secondary_carets();
  287. text_edit->deselect();
  288. // Insert text outside of selections.
  289. text_edit->set_text("test text");
  290. text_edit->add_caret(0, 8);
  291. text_edit->select(0, 1, 0, 4, 0);
  292. text_edit->select(0, 4, 0, 8, 1);
  293. MessageQueue::get_singleton()->flush();
  294. SIGNAL_DISCARD("text_set");
  295. SIGNAL_DISCARD("lines_edited_from");
  296. SIGNAL_DISCARD("text_changed");
  297. SIGNAL_DISCARD("caret_changed");
  298. lines_edited_args = build_array(build_array(0, 0));
  299. text_edit->insert_text("a", 0, 4, true, false);
  300. MessageQueue::get_singleton()->flush();
  301. CHECK(text_edit->get_text() == "testa text");
  302. CHECK(text_edit->get_caret_count() == 2);
  303. CHECK(text_edit->has_selection(0));
  304. CHECK(text_edit->get_caret_line(0) == 0);
  305. CHECK(text_edit->get_caret_column(0) == 4);
  306. CHECK(text_edit->get_selection_origin_line(0) == 0);
  307. CHECK(text_edit->get_selection_origin_column(0) == 1);
  308. CHECK(text_edit->has_selection(1));
  309. CHECK(text_edit->get_caret_line(1) == 0);
  310. CHECK(text_edit->get_caret_column(1) == 9);
  311. CHECK(text_edit->get_selection_origin_line(1) == 0);
  312. CHECK(text_edit->get_selection_origin_column(1) == 5);
  313. // Insert text to beginning of selections.
  314. text_edit->set_text("test text");
  315. text_edit->add_caret(0, 8);
  316. text_edit->select(0, 1, 0, 4, 0);
  317. text_edit->select(0, 4, 0, 8, 1);
  318. MessageQueue::get_singleton()->flush();
  319. SIGNAL_DISCARD("text_set");
  320. SIGNAL_DISCARD("lines_edited_from");
  321. SIGNAL_DISCARD("text_changed");
  322. SIGNAL_DISCARD("caret_changed");
  323. lines_edited_args = build_array(build_array(0, 0));
  324. text_edit->insert_text("a", 0, 4, false, false);
  325. MessageQueue::get_singleton()->flush();
  326. CHECK(text_edit->get_text() == "testa text");
  327. CHECK(text_edit->get_caret_count() == 2);
  328. CHECK(text_edit->has_selection(0));
  329. CHECK(text_edit->get_caret_line(0) == 0);
  330. CHECK(text_edit->get_caret_column(0) == 4);
  331. CHECK(text_edit->get_selection_origin_line(0) == 0);
  332. CHECK(text_edit->get_selection_origin_column(0) == 1);
  333. CHECK(text_edit->has_selection(1));
  334. CHECK(text_edit->get_caret_line(1) == 0);
  335. CHECK(text_edit->get_caret_column(1) == 9);
  336. CHECK(text_edit->get_selection_origin_line(1) == 0);
  337. CHECK(text_edit->get_selection_origin_column(1) == 4);
  338. // Insert text to end of selections.
  339. text_edit->set_text("test text");
  340. text_edit->add_caret(0, 8);
  341. text_edit->select(0, 1, 0, 4, 0);
  342. text_edit->select(0, 4, 0, 8, 1);
  343. MessageQueue::get_singleton()->flush();
  344. SIGNAL_DISCARD("text_set");
  345. SIGNAL_DISCARD("lines_edited_from");
  346. SIGNAL_DISCARD("text_changed");
  347. SIGNAL_DISCARD("caret_changed");
  348. lines_edited_args = build_array(build_array(0, 0));
  349. text_edit->insert_text("a", 0, 4, true, true);
  350. MessageQueue::get_singleton()->flush();
  351. CHECK(text_edit->get_text() == "testa text");
  352. CHECK(text_edit->get_caret_count() == 2);
  353. CHECK(text_edit->has_selection(0));
  354. CHECK(text_edit->get_caret_line(0) == 0);
  355. CHECK(text_edit->get_caret_column(0) == 5);
  356. CHECK(text_edit->get_selection_origin_line(0) == 0);
  357. CHECK(text_edit->get_selection_origin_column(0) == 1);
  358. CHECK(text_edit->has_selection(1));
  359. CHECK(text_edit->get_caret_line(1) == 0);
  360. CHECK(text_edit->get_caret_column(1) == 9);
  361. CHECK(text_edit->get_selection_origin_line(1) == 0);
  362. CHECK(text_edit->get_selection_origin_column(1) == 5);
  363. // Insert text inside of selections.
  364. text_edit->set_text("test text");
  365. text_edit->add_caret(0, 8);
  366. text_edit->select(0, 1, 0, 4, 0);
  367. text_edit->select(0, 4, 0, 8, 1);
  368. MessageQueue::get_singleton()->flush();
  369. SIGNAL_DISCARD("text_set");
  370. SIGNAL_DISCARD("lines_edited_from");
  371. SIGNAL_DISCARD("text_changed");
  372. SIGNAL_DISCARD("caret_changed");
  373. lines_edited_args = build_array(build_array(0, 0));
  374. text_edit->insert_text("a", 0, 4, false, true);
  375. MessageQueue::get_singleton()->flush();
  376. CHECK(text_edit->get_text() == "testa text");
  377. CHECK(text_edit->get_caret_count() == 1);
  378. CHECK(text_edit->has_selection(0));
  379. CHECK(text_edit->get_caret_line(0) == 0);
  380. CHECK(text_edit->get_caret_column(0) == 9);
  381. CHECK(text_edit->get_selection_origin_line(0) == 0);
  382. CHECK(text_edit->get_selection_origin_column(0) == 1);
  383. }
  384. SUBCASE("[TextEdit] remove text") {
  385. lines_edited_args = build_array(build_array(0, 0), build_array(0, 2));
  386. text_edit->set_text("test\nremoveing text\nthird line");
  387. MessageQueue::get_singleton()->flush();
  388. SIGNAL_CHECK("text_set", empty_signal_args);
  389. SIGNAL_CHECK("lines_edited_from", lines_edited_args);
  390. SIGNAL_CHECK("caret_changed", empty_signal_args);
  391. SIGNAL_CHECK_FALSE("text_changed");
  392. // remove_text is 0 indexed.
  393. ERR_PRINT_OFF;
  394. text_edit->remove_text(3, 0, 3, 4);
  395. ERR_PRINT_ON;
  396. MessageQueue::get_singleton()->flush();
  397. CHECK(text_edit->get_text() == "test\nremoveing text\nthird line");
  398. SIGNAL_CHECK_FALSE("lines_edited_from");
  399. SIGNAL_CHECK_FALSE("text_changed");
  400. SIGNAL_CHECK_FALSE("caret_changed");
  401. SIGNAL_CHECK_FALSE("text_set");
  402. // Remove multiple lines.
  403. text_edit->set_caret_line(2);
  404. text_edit->set_caret_column(10);
  405. MessageQueue::get_singleton()->flush();
  406. SIGNAL_DISCARD("caret_changed");
  407. lines_edited_args = build_array(build_array(2, 1));
  408. text_edit->remove_text(1, 9, 2, 2);
  409. MessageQueue::get_singleton()->flush();
  410. CHECK(text_edit->get_text() == "test\nremoveingird line");
  411. CHECK(text_edit->get_caret_line() == 1);
  412. CHECK(text_edit->get_caret_column() == 17);
  413. SIGNAL_CHECK("lines_edited_from", lines_edited_args);
  414. SIGNAL_CHECK("text_changed", empty_signal_args);
  415. SIGNAL_CHECK("caret_changed", empty_signal_args);
  416. SIGNAL_CHECK_FALSE("text_set");
  417. // Can remove even if not editable.
  418. lines_edited_args = build_array(build_array(1, 1));
  419. text_edit->set_editable(false);
  420. text_edit->remove_text(1, 5, 1, 6);
  421. MessageQueue::get_singleton()->flush();
  422. CHECK(text_edit->get_text() == "test\nremovingird line");
  423. CHECK(text_edit->get_caret_line() == 1);
  424. CHECK(text_edit->get_caret_column() == 16);
  425. SIGNAL_CHECK("lines_edited_from", lines_edited_args);
  426. SIGNAL_CHECK("text_changed", empty_signal_args);
  427. SIGNAL_CHECK("caret_changed", empty_signal_args);
  428. SIGNAL_CHECK_FALSE("text_set");
  429. text_edit->set_editable(true);
  430. // Undo remove.
  431. text_edit->undo();
  432. MessageQueue::get_singleton()->flush();
  433. CHECK(text_edit->get_text() == "test\nremoveingird line");
  434. CHECK(text_edit->get_caret_line() == 1);
  435. CHECK(text_edit->get_caret_column() == 17);
  436. SIGNAL_CHECK("lines_edited_from", lines_edited_args);
  437. SIGNAL_CHECK("text_changed", empty_signal_args);
  438. SIGNAL_CHECK("caret_changed", empty_signal_args);
  439. SIGNAL_CHECK_FALSE("text_set");
  440. // Redo remove.
  441. text_edit->redo();
  442. MessageQueue::get_singleton()->flush();
  443. CHECK(text_edit->get_text() == "test\nremovingird line");
  444. CHECK(text_edit->get_caret_line() == 1);
  445. CHECK(text_edit->get_caret_column() == 16);
  446. SIGNAL_CHECK("lines_edited_from", lines_edited_args);
  447. SIGNAL_CHECK("text_changed", empty_signal_args);
  448. SIGNAL_CHECK("caret_changed", empty_signal_args);
  449. SIGNAL_CHECK_FALSE("text_set");
  450. // Remove collapses carets and offsets carets after the edit.
  451. text_edit->set_caret_line(1);
  452. text_edit->set_caret_column(9);
  453. text_edit->add_caret(1, 10);
  454. text_edit->select(1, 10, 1, 13, 1);
  455. text_edit->add_caret(1, 14);
  456. text_edit->add_caret(1, 2);
  457. MessageQueue::get_singleton()->flush();
  458. SIGNAL_CHECK("caret_changed", empty_signal_args);
  459. text_edit->remove_text(1, 8, 1, 11);
  460. MessageQueue::get_singleton()->flush();
  461. CHECK(text_edit->get_text() == "test\nremoving line");
  462. // Caret 0 was merged into the selection.
  463. CHECK(text_edit->get_caret_count() == 3);
  464. CHECK(text_edit->has_selection(0));
  465. CHECK(text_edit->get_caret_line(0) == 1);
  466. CHECK(text_edit->get_caret_column(0) == 10);
  467. CHECK(text_edit->get_selection_origin_line(0) == 1);
  468. CHECK(text_edit->get_selection_origin_column(0) == 8);
  469. CHECK(text_edit->get_caret_line(1) == 1);
  470. CHECK(text_edit->get_caret_column(1) == 11);
  471. CHECK(text_edit->get_caret_line(2) == 1);
  472. CHECK(text_edit->get_caret_column(2) == 2);
  473. SIGNAL_CHECK("lines_edited_from", lines_edited_args);
  474. SIGNAL_CHECK("text_changed", empty_signal_args);
  475. SIGNAL_CHECK("caret_changed", empty_signal_args);
  476. SIGNAL_CHECK_FALSE("text_set");
  477. text_edit->remove_secondary_carets();
  478. }
  479. SUBCASE("[TextEdit] set and get line") {
  480. // Set / Get line is 0 indexed.
  481. text_edit->set_line(1, "test");
  482. MessageQueue::get_singleton()->flush();
  483. CHECK(text_edit->get_text() == "");
  484. SIGNAL_CHECK_FALSE("lines_edited_from");
  485. SIGNAL_CHECK_FALSE("text_set");
  486. SIGNAL_CHECK_FALSE("text_changed");
  487. SIGNAL_CHECK_FALSE("caret_changed");
  488. text_edit->set_line(0, "test");
  489. MessageQueue::get_singleton()->flush();
  490. CHECK(text_edit->get_text() == "test");
  491. CHECK(text_edit->get_line(0) == "test");
  492. CHECK(text_edit->get_line(1) == "");
  493. CHECK(text_edit->get_line_count() == 1);
  494. SIGNAL_CHECK("lines_edited_from", lines_edited_args);
  495. SIGNAL_CHECK("text_changed", empty_signal_args);
  496. SIGNAL_CHECK_FALSE("text_set");
  497. SIGNAL_CHECK_FALSE("caret_changed");
  498. // Setting to a longer line, caret and selections should be preserved.
  499. text_edit->select_all();
  500. MessageQueue::get_singleton()->flush();
  501. SIGNAL_DISCARD("caret_changed");
  502. text_edit->set_line(0, "test text");
  503. MessageQueue::get_singleton()->flush();
  504. CHECK(text_edit->get_line(0) == "test text");
  505. CHECK(text_edit->has_selection());
  506. CHECK(text_edit->get_selected_text() == "test");
  507. CHECK(text_edit->get_selection_origin_column() == 0);
  508. CHECK(text_edit->get_caret_column() == 4);
  509. SIGNAL_CHECK("lines_edited_from", lines_edited_args);
  510. SIGNAL_CHECK("text_changed", empty_signal_args);
  511. SIGNAL_CHECK_FALSE("caret_changed");
  512. SIGNAL_CHECK_FALSE("text_set");
  513. // Setting to a shorter line, selection and caret should be adjusted. Also works if not editable.
  514. text_edit->set_editable(false);
  515. text_edit->set_line(0, "te");
  516. MessageQueue::get_singleton()->flush();
  517. CHECK(text_edit->get_line(0) == "te");
  518. CHECK(text_edit->has_selection());
  519. CHECK(text_edit->get_selected_text() == "te");
  520. CHECK(text_edit->get_caret_column() == 2);
  521. SIGNAL_CHECK("lines_edited_from", lines_edited_args);
  522. SIGNAL_CHECK("caret_changed", empty_signal_args);
  523. SIGNAL_CHECK("text_changed", empty_signal_args);
  524. SIGNAL_CHECK_FALSE("text_set");
  525. text_edit->set_editable(true);
  526. // Undo / redo should work.
  527. text_edit->undo();
  528. MessageQueue::get_singleton()->flush();
  529. CHECK(text_edit->get_line(0) == "test text");
  530. CHECK(text_edit->has_selection());
  531. CHECK(text_edit->get_selected_text() == "test");
  532. CHECK(text_edit->get_caret_column() == 4);
  533. SIGNAL_CHECK("lines_edited_from", lines_edited_args);
  534. SIGNAL_CHECK("caret_changed", empty_signal_args);
  535. SIGNAL_CHECK("text_changed", empty_signal_args);
  536. SIGNAL_CHECK_FALSE("text_set");
  537. text_edit->redo();
  538. MessageQueue::get_singleton()->flush();
  539. CHECK(text_edit->get_line(0) == "te");
  540. CHECK(text_edit->has_selection());
  541. CHECK(text_edit->get_caret_column() == 2);
  542. SIGNAL_CHECK("lines_edited_from", lines_edited_args);
  543. SIGNAL_CHECK("caret_changed", empty_signal_args);
  544. SIGNAL_CHECK("text_changed", empty_signal_args);
  545. SIGNAL_CHECK_FALSE("text_set");
  546. // Out of range.
  547. ERR_PRINT_OFF;
  548. text_edit->set_line(-1, "test");
  549. MessageQueue::get_singleton()->flush();
  550. CHECK(text_edit->get_line(0) == "te");
  551. SIGNAL_CHECK_FALSE("lines_edited_from");
  552. SIGNAL_CHECK_FALSE("caret_changed");
  553. SIGNAL_CHECK_FALSE("text_changed");
  554. SIGNAL_CHECK_FALSE("text_set");
  555. text_edit->set_line(1, "test");
  556. MessageQueue::get_singleton()->flush();
  557. CHECK(text_edit->get_line(0) == "te");
  558. SIGNAL_CHECK_FALSE("lines_edited_from");
  559. SIGNAL_CHECK_FALSE("caret_changed");
  560. SIGNAL_CHECK_FALSE("text_changed");
  561. SIGNAL_CHECK_FALSE("text_set");
  562. ERR_PRINT_ON;
  563. // Both ends of selection are adjusted and deselects.
  564. text_edit->set_text("test text");
  565. text_edit->select(0, 8, 0, 6);
  566. MessageQueue::get_singleton()->flush();
  567. SIGNAL_DISCARD("lines_edited_from");
  568. SIGNAL_DISCARD("text_set");
  569. SIGNAL_DISCARD("text_changed");
  570. SIGNAL_DISCARD("caret_changed");
  571. text_edit->set_line(0, "test");
  572. MessageQueue::get_singleton()->flush();
  573. CHECK(text_edit->get_line(0) == "test");
  574. CHECK_FALSE(text_edit->has_selection());
  575. CHECK(text_edit->get_caret_column() == 4);
  576. SIGNAL_CHECK("lines_edited_from", lines_edited_args);
  577. SIGNAL_CHECK("text_changed", empty_signal_args);
  578. SIGNAL_CHECK("caret_changed", empty_signal_args);
  579. SIGNAL_CHECK_FALSE("text_set");
  580. // Multiple carets adjust to keep visual position.
  581. text_edit->set_text("test text");
  582. text_edit->set_caret_column(2);
  583. text_edit->add_caret(0, 0);
  584. text_edit->add_caret(0, 1);
  585. text_edit->add_caret(0, 6);
  586. MessageQueue::get_singleton()->flush();
  587. SIGNAL_DISCARD("lines_edited_from");
  588. SIGNAL_DISCARD("text_set");
  589. SIGNAL_DISCARD("text_changed");
  590. SIGNAL_DISCARD("caret_changed");
  591. text_edit->set_line(0, "\tset line");
  592. MessageQueue::get_singleton()->flush();
  593. CHECK(text_edit->get_line(0) == "\tset line");
  594. CHECK(text_edit->get_caret_count() == 3);
  595. CHECK_FALSE(text_edit->has_selection());
  596. // In the default font, these are the same positions.
  597. CHECK(text_edit->get_caret_column(0) == 1);
  598. CHECK(text_edit->get_caret_column(1) == 0);
  599. // The previous caret at index 2 was merged.
  600. CHECK(text_edit->get_caret_column(2) == 4);
  601. SIGNAL_CHECK("lines_edited_from", lines_edited_args);
  602. SIGNAL_CHECK("text_changed", empty_signal_args);
  603. SIGNAL_CHECK("caret_changed", empty_signal_args);
  604. SIGNAL_CHECK_FALSE("text_set");
  605. text_edit->remove_secondary_carets();
  606. // Insert multiple lines.
  607. text_edit->set_text("test text\nsecond line");
  608. text_edit->set_caret_column(5);
  609. text_edit->add_caret(1, 6);
  610. MessageQueue::get_singleton()->flush();
  611. SIGNAL_DISCARD("lines_edited_from");
  612. SIGNAL_DISCARD("text_set");
  613. SIGNAL_DISCARD("text_changed");
  614. SIGNAL_DISCARD("caret_changed");
  615. lines_edited_args = build_array(build_array(0, 0), build_array(0, 1));
  616. text_edit->set_line(0, "multiple\nlines");
  617. MessageQueue::get_singleton()->flush();
  618. CHECK(text_edit->get_text() == "multiple\nlines\nsecond line");
  619. CHECK(text_edit->get_caret_count() == 2);
  620. CHECK_FALSE(text_edit->has_selection());
  621. CHECK(text_edit->get_caret_line(0) == 0);
  622. CHECK(text_edit->get_caret_column(0) == 3); // In the default font, this is the same position.
  623. CHECK(text_edit->get_caret_line(1) == 2);
  624. CHECK(text_edit->get_caret_column(1) == 6);
  625. SIGNAL_CHECK("lines_edited_from", lines_edited_args);
  626. SIGNAL_CHECK("text_changed", empty_signal_args);
  627. SIGNAL_CHECK("caret_changed", empty_signal_args);
  628. SIGNAL_CHECK_FALSE("text_set");
  629. text_edit->remove_secondary_carets();
  630. }
  631. SUBCASE("[TextEdit] swap lines") {
  632. lines_edited_args = build_array(build_array(0, 0), build_array(0, 1));
  633. text_edit->set_text("testing\nswap");
  634. MessageQueue::get_singleton()->flush();
  635. CHECK(text_edit->get_text() == "testing\nswap");
  636. SIGNAL_CHECK("text_set", empty_signal_args);
  637. SIGNAL_CHECK("lines_edited_from", lines_edited_args);
  638. SIGNAL_CHECK("caret_changed", empty_signal_args);
  639. SIGNAL_CHECK_FALSE("text_changed");
  640. text_edit->set_caret_column(text_edit->get_line(0).length());
  641. MessageQueue::get_singleton()->flush();
  642. SIGNAL_CHECK("caret_changed", empty_signal_args);
  643. // Emitted twice for each line.
  644. lines_edited_args = build_array(build_array(0, 0), build_array(0, 0), build_array(1, 1), build_array(1, 1));
  645. // Order does not matter. Works when not editable.
  646. text_edit->set_editable(false);
  647. text_edit->swap_lines(1, 0);
  648. MessageQueue::get_singleton()->flush();
  649. CHECK(text_edit->get_text() == "swap\ntesting");
  650. SIGNAL_CHECK("lines_edited_from", lines_edited_args);
  651. SIGNAL_CHECK("caret_changed", empty_signal_args);
  652. SIGNAL_CHECK("text_changed", empty_signal_args);
  653. SIGNAL_CHECK_FALSE("text_set");
  654. text_edit->set_editable(true);
  655. // Single undo/redo action.
  656. text_edit->undo();
  657. MessageQueue::get_singleton()->flush();
  658. CHECK(text_edit->get_text() == "testing\nswap");
  659. SIGNAL_CHECK("lines_edited_from", reverse_nested(lines_edited_args));
  660. SIGNAL_CHECK("caret_changed", empty_signal_args);
  661. SIGNAL_CHECK("text_changed", empty_signal_args);
  662. SIGNAL_CHECK_FALSE("text_set");
  663. text_edit->redo();
  664. MessageQueue::get_singleton()->flush();
  665. CHECK(text_edit->get_text() == "swap\ntesting");
  666. SIGNAL_CHECK("lines_edited_from", lines_edited_args);
  667. SIGNAL_CHECK("caret_changed", empty_signal_args);
  668. SIGNAL_CHECK("text_changed", empty_signal_args);
  669. SIGNAL_CHECK_FALSE("text_set");
  670. // Out of range.
  671. ERR_PRINT_OFF;
  672. text_edit->swap_lines(-1, 0);
  673. CHECK(text_edit->get_text() == "swap\ntesting");
  674. text_edit->swap_lines(0, -1);
  675. CHECK(text_edit->get_text() == "swap\ntesting");
  676. text_edit->swap_lines(2, 0);
  677. CHECK(text_edit->get_text() == "swap\ntesting");
  678. text_edit->swap_lines(0, 2);
  679. CHECK(text_edit->get_text() == "swap\ntesting");
  680. MessageQueue::get_singleton()->flush();
  681. SIGNAL_CHECK_FALSE("lines_edited_from");
  682. SIGNAL_CHECK_FALSE("caret_changed");
  683. SIGNAL_CHECK_FALSE("text_changed");
  684. SIGNAL_CHECK_FALSE("text_set");
  685. ERR_PRINT_ON;
  686. // Carets are also swapped.
  687. text_edit->set_caret_line(0);
  688. text_edit->set_caret_column(2);
  689. text_edit->select(0, 0, 0, 2);
  690. text_edit->add_caret(1, 6);
  691. MessageQueue::get_singleton()->flush();
  692. SIGNAL_DISCARD("caret_changed");
  693. lines_edited_args = build_array(build_array(1, 1), build_array(1, 1), build_array(0, 0), build_array(0, 0));
  694. text_edit->swap_lines(0, 1);
  695. MessageQueue::get_singleton()->flush();
  696. CHECK(text_edit->get_text() == "testing\nswap");
  697. CHECK(text_edit->get_caret_count() == 2);
  698. CHECK(text_edit->has_selection(0));
  699. CHECK(text_edit->get_caret_line(0) == 1);
  700. CHECK(text_edit->get_caret_column(0) == 2);
  701. CHECK(text_edit->get_selection_origin_line(0) == 1);
  702. CHECK(text_edit->get_selection_origin_column(0) == 0);
  703. CHECK_FALSE(text_edit->has_selection(1));
  704. CHECK(text_edit->get_caret_line(1) == 0);
  705. CHECK(text_edit->get_caret_column(1) == 6);
  706. SIGNAL_CHECK("lines_edited_from", lines_edited_args);
  707. SIGNAL_CHECK("caret_changed", empty_signal_args);
  708. SIGNAL_CHECK("text_changed", empty_signal_args);
  709. SIGNAL_CHECK_FALSE("text_set");
  710. text_edit->remove_secondary_carets();
  711. // Swap non adjacent lines.
  712. text_edit->insert_line_at(1, "new line");
  713. text_edit->set_caret_line(1);
  714. text_edit->set_caret_column(5);
  715. MessageQueue::get_singleton()->flush();
  716. CHECK(text_edit->get_text() == "testing\nnew line\nswap");
  717. SIGNAL_DISCARD("caret_changed");
  718. SIGNAL_DISCARD("lines_edited_from");
  719. SIGNAL_DISCARD("text_changed");
  720. lines_edited_args = build_array(build_array(2, 2), build_array(2, 2), build_array(0, 0), build_array(0, 0));
  721. text_edit->swap_lines(0, 2);
  722. MessageQueue::get_singleton()->flush();
  723. CHECK(text_edit->get_text() == "swap\nnew line\ntesting");
  724. CHECK(text_edit->get_caret_line() == 1);
  725. CHECK(text_edit->get_caret_column() == 5);
  726. SIGNAL_CHECK("lines_edited_from", lines_edited_args);
  727. SIGNAL_CHECK_FALSE("caret_changed");
  728. SIGNAL_CHECK("text_changed", empty_signal_args);
  729. SIGNAL_CHECK_FALSE("text_set");
  730. }
  731. SUBCASE("[TextEdit] insert line at") {
  732. lines_edited_args = build_array(build_array(0, 0), build_array(0, 1));
  733. text_edit->set_text("testing\nswap");
  734. MessageQueue::get_singleton()->flush();
  735. CHECK(text_edit->get_text() == "testing\nswap");
  736. SIGNAL_CHECK("text_set", empty_signal_args);
  737. SIGNAL_CHECK("lines_edited_from", lines_edited_args);
  738. SIGNAL_CHECK("caret_changed", empty_signal_args);
  739. SIGNAL_CHECK_FALSE("text_changed");
  740. text_edit->select_all();
  741. MessageQueue::get_singleton()->flush();
  742. CHECK(text_edit->has_selection());
  743. CHECK(text_edit->get_selection_from_line() == 0);
  744. CHECK(text_edit->get_selection_to_line() == 1);
  745. SIGNAL_CHECK("caret_changed", empty_signal_args);
  746. // Insert line at inserts a line before and moves caret and selection. Works when not editable.
  747. text_edit->set_editable(false);
  748. lines_edited_args = build_array(build_array(0, 1));
  749. text_edit->insert_line_at(0, "new");
  750. MessageQueue::get_singleton()->flush();
  751. CHECK(text_edit->get_text() == "new\ntesting\nswap");
  752. CHECK(text_edit->get_caret_line() == 2);
  753. CHECK(text_edit->get_caret_column() == text_edit->get_line(2).size() - 1);
  754. CHECK(text_edit->has_selection());
  755. CHECK(text_edit->get_selection_from_line() == 1);
  756. CHECK(text_edit->get_selection_from_column() == 0);
  757. CHECK(text_edit->get_selection_to_line() == 2);
  758. CHECK(text_edit->get_selection_to_column() == 4);
  759. SIGNAL_CHECK("lines_edited_from", lines_edited_args);
  760. SIGNAL_CHECK("caret_changed", empty_signal_args);
  761. SIGNAL_CHECK("text_changed", empty_signal_args);
  762. SIGNAL_CHECK_FALSE("text_set");
  763. text_edit->set_editable(true);
  764. // Can undo/redo as single action.
  765. text_edit->undo();
  766. MessageQueue::get_singleton()->flush();
  767. CHECK(text_edit->get_text() == "testing\nswap");
  768. CHECK(text_edit->has_selection());
  769. SIGNAL_CHECK("lines_edited_from", reverse_nested(lines_edited_args));
  770. SIGNAL_CHECK("caret_changed", empty_signal_args);
  771. SIGNAL_CHECK("text_changed", empty_signal_args);
  772. SIGNAL_CHECK_FALSE("text_set");
  773. text_edit->redo();
  774. MessageQueue::get_singleton()->flush();
  775. CHECK(text_edit->get_text() == "new\ntesting\nswap");
  776. CHECK(text_edit->has_selection());
  777. SIGNAL_CHECK("lines_edited_from", lines_edited_args);
  778. SIGNAL_CHECK("caret_changed", empty_signal_args);
  779. SIGNAL_CHECK("text_changed", empty_signal_args);
  780. SIGNAL_CHECK_FALSE("text_set");
  781. // Adding inside selection extends selection.
  782. text_edit->select_all();
  783. MessageQueue::get_singleton()->flush();
  784. CHECK(text_edit->has_selection());
  785. CHECK(text_edit->get_selection_from_line() == 0);
  786. CHECK(text_edit->get_selection_to_line() == 2);
  787. SIGNAL_CHECK_FALSE("caret_changed");
  788. lines_edited_args = build_array(build_array(2, 3));
  789. text_edit->insert_line_at(2, "after");
  790. MessageQueue::get_singleton()->flush();
  791. CHECK(text_edit->get_text() == "new\ntesting\nafter\nswap");
  792. CHECK(text_edit->get_caret_line() == 3);
  793. CHECK(text_edit->get_caret_column() == text_edit->get_line(3).size() - 1);
  794. CHECK(text_edit->has_selection());
  795. CHECK(text_edit->get_selection_from_line() == 0);
  796. CHECK(text_edit->get_selection_to_line() == 3);
  797. SIGNAL_CHECK("lines_edited_from", lines_edited_args);
  798. SIGNAL_CHECK("caret_changed", empty_signal_args);
  799. SIGNAL_CHECK("text_changed", empty_signal_args);
  800. SIGNAL_CHECK_FALSE("text_set");
  801. // Out of range.
  802. ERR_PRINT_OFF;
  803. text_edit->insert_line_at(-1, "after");
  804. CHECK(text_edit->get_text() == "new\ntesting\nafter\nswap");
  805. text_edit->insert_line_at(4, "after");
  806. CHECK(text_edit->get_text() == "new\ntesting\nafter\nswap");
  807. MessageQueue::get_singleton()->flush();
  808. SIGNAL_CHECK_FALSE("lines_edited_from");
  809. SIGNAL_CHECK_FALSE("caret_changed");
  810. SIGNAL_CHECK_FALSE("text_changed");
  811. SIGNAL_CHECK_FALSE("text_set");
  812. ERR_PRINT_ON;
  813. // Can insert multiple lines.
  814. text_edit->select(0, 1, 2, 2);
  815. MessageQueue::get_singleton()->flush();
  816. SIGNAL_DISCARD("caret_changed");
  817. lines_edited_args = build_array(build_array(2, 4));
  818. text_edit->insert_line_at(2, "multiple\nlines");
  819. MessageQueue::get_singleton()->flush();
  820. CHECK(text_edit->get_text() == "new\ntesting\nmultiple\nlines\nafter\nswap");
  821. CHECK(text_edit->has_selection());
  822. CHECK(text_edit->get_caret_line() == 4);
  823. CHECK(text_edit->get_caret_column() == 2);
  824. CHECK(text_edit->get_selection_origin_line() == 0);
  825. CHECK(text_edit->get_selection_origin_column() == 1);
  826. SIGNAL_CHECK("lines_edited_from", lines_edited_args);
  827. SIGNAL_CHECK("caret_changed", empty_signal_args);
  828. SIGNAL_CHECK("text_changed", empty_signal_args);
  829. SIGNAL_CHECK_FALSE("text_set");
  830. }
  831. SUBCASE("[TextEdit] remove line at") {
  832. lines_edited_args = build_array(build_array(0, 0), build_array(0, 5));
  833. text_edit->set_text("testing\nremove line at\n\tremove\nlines\n\ntest");
  834. MessageQueue::get_singleton()->flush();
  835. CHECK(text_edit->get_text() == "testing\nremove line at\n\tremove\nlines\n\ntest");
  836. SIGNAL_CHECK("text_set", empty_signal_args);
  837. SIGNAL_CHECK("lines_edited_from", lines_edited_args);
  838. SIGNAL_CHECK("caret_changed", empty_signal_args);
  839. SIGNAL_CHECK_FALSE("text_changed");
  840. // Remove line handles multiple carets.
  841. text_edit->set_caret_line(2);
  842. text_edit->set_caret_column(0);
  843. text_edit->add_caret(2, 7);
  844. text_edit->select(2, 1, 2, 7, 1);
  845. text_edit->add_caret(3, 1);
  846. text_edit->add_caret(4, 5);
  847. text_edit->add_caret(1, 5);
  848. MessageQueue::get_singleton()->flush();
  849. SIGNAL_DISCARD("caret_changed");
  850. lines_edited_args = build_array(build_array(3, 2));
  851. text_edit->remove_line_at(2, true);
  852. MessageQueue::get_singleton()->flush();
  853. CHECK(text_edit->get_text() == "testing\nremove line at\nlines\n\ntest");
  854. CHECK(text_edit->get_caret_count() == 5);
  855. CHECK_FALSE(text_edit->has_selection(0)); // Same line.
  856. CHECK(text_edit->get_caret_line(0) == 2);
  857. CHECK(text_edit->get_caret_column(0) == 0);
  858. CHECK(text_edit->has_selection(1)); // Same line, clamped.
  859. CHECK(text_edit->get_caret_line(1) == 2);
  860. CHECK(text_edit->get_caret_column(1) == 5);
  861. CHECK(text_edit->get_selection_origin_line(1) == 2);
  862. CHECK(text_edit->get_selection_origin_column(1) == 3); // In the default font, this is the same position.
  863. CHECK_FALSE(text_edit->has_selection(2)); // Moved up.
  864. CHECK(text_edit->get_caret_line(2) == 2);
  865. CHECK(text_edit->get_caret_column(2) == 1);
  866. CHECK_FALSE(text_edit->has_selection(3)); // Moved up.
  867. CHECK(text_edit->get_caret_line(3) == 3);
  868. CHECK(text_edit->get_caret_column(3) == 0);
  869. CHECK_FALSE(text_edit->has_selection(4)); // Didn't move.
  870. CHECK(text_edit->get_caret_line(4) == 1);
  871. CHECK(text_edit->get_caret_column(4) == 5);
  872. SIGNAL_CHECK("lines_edited_from", lines_edited_args);
  873. SIGNAL_CHECK("caret_changed", empty_signal_args);
  874. SIGNAL_CHECK("text_changed", empty_signal_args);
  875. SIGNAL_CHECK_FALSE("text_set");
  876. text_edit->remove_secondary_carets();
  877. // Remove first line.
  878. text_edit->set_caret_line(0);
  879. text_edit->set_caret_column(5);
  880. text_edit->add_caret(4, 4);
  881. MessageQueue::get_singleton()->flush();
  882. SIGNAL_DISCARD("caret_changed");
  883. lines_edited_args = build_array(build_array(1, 0));
  884. text_edit->remove_line_at(0, false);
  885. MessageQueue::get_singleton()->flush();
  886. CHECK(text_edit->get_text() == "remove line at\nlines\n\ntest");
  887. CHECK(text_edit->get_caret_count() == 2);
  888. CHECK(text_edit->get_caret_line(0) == 0);
  889. CHECK(text_edit->get_caret_column(0) == 0);
  890. CHECK(text_edit->get_caret_line(1) == 3);
  891. CHECK(text_edit->get_caret_column(1) == 4);
  892. SIGNAL_CHECK("lines_edited_from", lines_edited_args);
  893. SIGNAL_CHECK("caret_changed", empty_signal_args);
  894. SIGNAL_CHECK("text_changed", empty_signal_args);
  895. SIGNAL_CHECK_FALSE("text_set");
  896. text_edit->remove_secondary_carets();
  897. // Remove empty line.
  898. text_edit->set_caret_line(2);
  899. text_edit->set_caret_column(0);
  900. MessageQueue::get_singleton()->flush();
  901. SIGNAL_DISCARD("caret_changed");
  902. lines_edited_args = build_array(build_array(3, 2));
  903. text_edit->remove_line_at(2, false);
  904. MessageQueue::get_singleton()->flush();
  905. CHECK(text_edit->get_text() == "remove line at\nlines\ntest");
  906. CHECK(text_edit->get_caret_line(0) == 1);
  907. CHECK(text_edit->get_caret_column(0) == 0);
  908. SIGNAL_CHECK("lines_edited_from", lines_edited_args);
  909. SIGNAL_CHECK("caret_changed", empty_signal_args);
  910. SIGNAL_CHECK("text_changed", empty_signal_args);
  911. SIGNAL_CHECK_FALSE("text_set");
  912. // Remove last line.
  913. text_edit->set_caret_line(2);
  914. text_edit->set_caret_column(2);
  915. MessageQueue::get_singleton()->flush();
  916. SIGNAL_DISCARD("caret_changed");
  917. lines_edited_args = build_array(build_array(2, 1));
  918. text_edit->remove_line_at(2, true);
  919. MessageQueue::get_singleton()->flush();
  920. CHECK(text_edit->get_text() == "remove line at\nlines");
  921. CHECK(text_edit->get_caret_line(0) == 1);
  922. CHECK(text_edit->get_caret_column(0) == 5);
  923. SIGNAL_CHECK("lines_edited_from", lines_edited_args);
  924. SIGNAL_CHECK("caret_changed", empty_signal_args);
  925. SIGNAL_CHECK("text_changed", empty_signal_args);
  926. SIGNAL_CHECK_FALSE("text_set");
  927. // Out of bounds.
  928. text_edit->set_caret_line(0);
  929. text_edit->set_caret_column(2);
  930. MessageQueue::get_singleton()->flush();
  931. SIGNAL_DISCARD("caret_changed");
  932. ERR_PRINT_OFF
  933. text_edit->remove_line_at(2, true);
  934. ERR_PRINT_ON
  935. MessageQueue::get_singleton()->flush();
  936. CHECK(text_edit->get_text() == "remove line at\nlines");
  937. CHECK(text_edit->get_caret_line(0) == 0);
  938. CHECK(text_edit->get_caret_column(0) == 2);
  939. SIGNAL_CHECK_FALSE("lines_edited_from");
  940. SIGNAL_CHECK_FALSE("caret_changed");
  941. SIGNAL_CHECK_FALSE("text_changed");
  942. SIGNAL_CHECK_FALSE("text_set");
  943. // Remove regular line with move caret up and not editable.
  944. text_edit->set_editable(false);
  945. text_edit->set_caret_line(1);
  946. text_edit->set_caret_column(2);
  947. MessageQueue::get_singleton()->flush();
  948. SIGNAL_DISCARD("caret_changed");
  949. lines_edited_args = build_array(build_array(1, 0));
  950. text_edit->remove_line_at(1, false);
  951. MessageQueue::get_singleton()->flush();
  952. CHECK(text_edit->get_text() == "remove line at");
  953. CHECK(text_edit->get_caret_line(0) == 0);
  954. CHECK(text_edit->get_caret_column(0) == 1); // In the default font, this is the same position.
  955. SIGNAL_CHECK("lines_edited_from", lines_edited_args);
  956. SIGNAL_CHECK("caret_changed", empty_signal_args);
  957. SIGNAL_CHECK("text_changed", empty_signal_args);
  958. SIGNAL_CHECK_FALSE("text_set");
  959. text_edit->set_editable(true);
  960. // Undo.
  961. text_edit->undo();
  962. MessageQueue::get_singleton()->flush();
  963. CHECK(text_edit->get_text() == "remove line at\nlines");
  964. CHECK(text_edit->get_caret_line(0) == 1);
  965. CHECK(text_edit->get_caret_column(0) == 2);
  966. SIGNAL_CHECK("lines_edited_from", reverse_nested(lines_edited_args));
  967. SIGNAL_CHECK("caret_changed", empty_signal_args);
  968. SIGNAL_CHECK("text_changed", empty_signal_args);
  969. SIGNAL_CHECK_FALSE("text_set");
  970. // Redo.
  971. text_edit->redo();
  972. MessageQueue::get_singleton()->flush();
  973. CHECK(text_edit->get_text() == "remove line at");
  974. CHECK(text_edit->get_caret_line(0) == 0);
  975. CHECK(text_edit->get_caret_column(0) == 1);
  976. SIGNAL_CHECK("lines_edited_from", lines_edited_args);
  977. SIGNAL_CHECK("caret_changed", empty_signal_args);
  978. SIGNAL_CHECK("text_changed", empty_signal_args);
  979. SIGNAL_CHECK_FALSE("text_set");
  980. // Remove only line removes line content.
  981. text_edit->set_caret_line(0);
  982. text_edit->set_caret_column(10);
  983. MessageQueue::get_singleton()->flush();
  984. SIGNAL_DISCARD("caret_changed");
  985. lines_edited_args = build_array(build_array(0, 0));
  986. text_edit->remove_line_at(0);
  987. MessageQueue::get_singleton()->flush();
  988. CHECK(text_edit->get_text() == "");
  989. CHECK(text_edit->get_line_count() == 1);
  990. CHECK(text_edit->get_caret_line(0) == 0);
  991. CHECK(text_edit->get_caret_column(0) == 0);
  992. SIGNAL_CHECK("lines_edited_from", lines_edited_args);
  993. SIGNAL_CHECK("caret_changed", empty_signal_args);
  994. SIGNAL_CHECK("text_changed", empty_signal_args);
  995. SIGNAL_CHECK_FALSE("text_set");
  996. }
  997. SUBCASE("[TextEdit] insert text at caret") {
  998. lines_edited_args = build_array(build_array(0, 1));
  999. // Insert text at caret can insert multiple lines.
  1000. text_edit->insert_text_at_caret("testing\nswap");
  1001. MessageQueue::get_singleton()->flush();
  1002. CHECK(text_edit->get_text() == "testing\nswap");
  1003. CHECK(text_edit->get_caret_line() == 1);
  1004. CHECK(text_edit->get_caret_column() == text_edit->get_line(1).size() - 1);
  1005. SIGNAL_CHECK("lines_edited_from", lines_edited_args);
  1006. SIGNAL_CHECK("text_changed", empty_signal_args);
  1007. SIGNAL_CHECK("caret_changed", empty_signal_args);
  1008. SIGNAL_CHECK_FALSE("text_set");
  1009. // Text is inserted at caret.
  1010. text_edit->set_caret_line(0, false);
  1011. text_edit->set_caret_column(2);
  1012. MessageQueue::get_singleton()->flush();
  1013. SIGNAL_DISCARD("caret_changed");
  1014. lines_edited_args = build_array(build_array(0, 0));
  1015. text_edit->insert_text_at_caret("mid");
  1016. MessageQueue::get_singleton()->flush();
  1017. CHECK(text_edit->get_text() == "temidsting\nswap");
  1018. CHECK(text_edit->get_caret_line() == 0);
  1019. CHECK(text_edit->get_caret_column() == 5);
  1020. SIGNAL_CHECK("lines_edited_from", lines_edited_args);
  1021. SIGNAL_CHECK("text_changed", empty_signal_args);
  1022. SIGNAL_CHECK("caret_changed", empty_signal_args);
  1023. SIGNAL_CHECK_FALSE("text_set");
  1024. // Selections are deleted then text is inserted. It also works even if not editable.
  1025. text_edit->select(0, 0, 0, text_edit->get_line(0).length());
  1026. CHECK(text_edit->has_selection());
  1027. lines_edited_args = build_array(build_array(0, 0), build_array(0, 0));
  1028. text_edit->set_editable(false);
  1029. text_edit->insert_text_at_caret("new line");
  1030. MessageQueue::get_singleton()->flush();
  1031. CHECK(text_edit->get_text() == "new line\nswap");
  1032. CHECK(text_edit->get_caret_line() == 0);
  1033. CHECK(text_edit->get_caret_column() == text_edit->get_line(0).size() - 1);
  1034. CHECK_FALSE(text_edit->has_selection());
  1035. SIGNAL_CHECK("lines_edited_from", lines_edited_args);
  1036. SIGNAL_CHECK("text_changed", empty_signal_args);
  1037. SIGNAL_CHECK("caret_changed", empty_signal_args);
  1038. SIGNAL_CHECK_FALSE("text_set");
  1039. text_edit->set_editable(true);
  1040. // Undo restores text and selection.
  1041. text_edit->undo();
  1042. MessageQueue::get_singleton()->flush();
  1043. CHECK(text_edit->get_text() == "temidsting\nswap");
  1044. CHECK(text_edit->get_caret_line() == 0);
  1045. CHECK(text_edit->get_caret_column() == text_edit->get_line(0).length());
  1046. CHECK(text_edit->has_selection());
  1047. CHECK(text_edit->get_selection_origin_line() == 0);
  1048. CHECK(text_edit->get_selection_origin_column() == 0);
  1049. SIGNAL_CHECK("lines_edited_from", lines_edited_args);
  1050. SIGNAL_CHECK("text_changed", empty_signal_args);
  1051. SIGNAL_CHECK("caret_changed", empty_signal_args);
  1052. SIGNAL_CHECK_FALSE("text_set");
  1053. text_edit->redo();
  1054. MessageQueue::get_singleton()->flush();
  1055. CHECK(text_edit->get_text() == "new line\nswap");
  1056. CHECK(text_edit->get_caret_line() == 0);
  1057. CHECK(text_edit->get_caret_column() == 8);
  1058. CHECK_FALSE(text_edit->has_selection());
  1059. SIGNAL_CHECK("lines_edited_from", lines_edited_args);
  1060. SIGNAL_CHECK("text_changed", empty_signal_args);
  1061. SIGNAL_CHECK("caret_changed", empty_signal_args);
  1062. SIGNAL_CHECK_FALSE("text_set");
  1063. }
  1064. SIGNAL_UNWATCH(text_edit, "text_set");
  1065. SIGNAL_UNWATCH(text_edit, "text_changed");
  1066. SIGNAL_UNWATCH(text_edit, "lines_edited_from");
  1067. SIGNAL_UNWATCH(text_edit, "caret_changed");
  1068. }
  1069. SUBCASE("[TextEdit] indent level") {
  1070. CHECK(text_edit->get_indent_level(0) == 0);
  1071. CHECK(text_edit->get_first_non_whitespace_column(0) == 0);
  1072. text_edit->set_line(0, "a");
  1073. CHECK(text_edit->get_indent_level(0) == 0);
  1074. CHECK(text_edit->get_first_non_whitespace_column(0) == 0);
  1075. text_edit->set_line(0, "\t");
  1076. CHECK(text_edit->get_indent_level(0) == 4);
  1077. CHECK(text_edit->get_first_non_whitespace_column(0) == 1);
  1078. text_edit->set_tab_size(8);
  1079. CHECK(text_edit->get_indent_level(0) == 8);
  1080. text_edit->set_line(0, "\t a");
  1081. CHECK(text_edit->get_first_non_whitespace_column(0) == 2);
  1082. CHECK(text_edit->get_indent_level(0) == 9);
  1083. }
  1084. SUBCASE("[TextEdit] selection") {
  1085. SIGNAL_WATCH(text_edit, "text_set");
  1086. SIGNAL_WATCH(text_edit, "text_changed");
  1087. SIGNAL_WATCH(text_edit, "lines_edited_from");
  1088. SIGNAL_WATCH(text_edit, "caret_changed");
  1089. Array lines_edited_args = build_array(build_array(0, 0), build_array(0, 0));
  1090. SUBCASE("[TextEdit] select all") {
  1091. // Select when there is no text does not select.
  1092. text_edit->select_all();
  1093. CHECK_FALSE(text_edit->has_selection());
  1094. CHECK(text_edit->get_selection_from_line() == 0);
  1095. CHECK(text_edit->get_selection_from_column() == 0);
  1096. CHECK(text_edit->get_selection_to_line() == 0);
  1097. CHECK(text_edit->get_selection_to_column() == 0);
  1098. CHECK(text_edit->get_selected_text() == "");
  1099. // Select all selects all text.
  1100. text_edit->set_text("test\nselection");
  1101. SEND_GUI_ACTION("ui_text_select_all");
  1102. CHECK(text_edit->get_viewport()->is_input_handled());
  1103. MessageQueue::get_singleton()->flush();
  1104. CHECK(text_edit->get_selected_text() == "test\nselection");
  1105. CHECK(text_edit->has_selection());
  1106. CHECK(text_edit->get_selection_from_line() == 0);
  1107. CHECK(text_edit->get_selection_from_column() == 0);
  1108. CHECK(text_edit->get_selection_to_line() == 1);
  1109. CHECK(text_edit->get_selection_to_column() == 9);
  1110. CHECK(text_edit->get_selection_mode() == TextEdit::SelectionMode::SELECTION_MODE_SHIFT);
  1111. CHECK(text_edit->is_caret_after_selection_origin());
  1112. CHECK(text_edit->get_caret_line() == 1);
  1113. CHECK(text_edit->get_caret_column() == 9);
  1114. SIGNAL_CHECK("caret_changed", empty_signal_args);
  1115. // Cannot select when disabled.
  1116. text_edit->set_caret_line(0);
  1117. text_edit->set_caret_column(0);
  1118. text_edit->set_selecting_enabled(false);
  1119. CHECK_FALSE(text_edit->has_selection());
  1120. CHECK(text_edit->get_selected_text() == "");
  1121. CHECK(text_edit->get_caret_line() == 0);
  1122. CHECK(text_edit->get_caret_column() == 0);
  1123. text_edit->select_all();
  1124. CHECK_FALSE(text_edit->has_selection());
  1125. CHECK(text_edit->get_selected_text() == "");
  1126. CHECK(text_edit->get_caret_line() == 0);
  1127. CHECK(text_edit->get_caret_column() == 0);
  1128. }
  1129. SUBCASE("[TextEdit] select word under caret") {
  1130. text_edit->set_text("\ntest test\ntest test");
  1131. text_edit->set_caret_column(0);
  1132. text_edit->set_caret_line(1);
  1133. text_edit->add_caret(2, 0);
  1134. text_edit->add_caret(2, 2);
  1135. CHECK(text_edit->get_caret_count() == 3);
  1136. MessageQueue::get_singleton()->flush();
  1137. SIGNAL_DISCARD("text_set");
  1138. SIGNAL_DISCARD("text_changed");
  1139. SIGNAL_DISCARD("lines_edited_from");
  1140. SIGNAL_DISCARD("caret_changed");
  1141. // Select word under caret with multiple carets.
  1142. text_edit->select_word_under_caret();
  1143. CHECK(text_edit->has_selection(0));
  1144. CHECK(text_edit->get_selected_text(0) == "test");
  1145. CHECK(text_edit->get_selection_from_line(0) == 1);
  1146. CHECK(text_edit->get_selection_from_column(0) == 0);
  1147. CHECK(text_edit->get_selection_to_line(0) == 1);
  1148. CHECK(text_edit->get_selection_to_column(0) == 4);
  1149. CHECK(text_edit->get_caret_line(0) == 1);
  1150. CHECK(text_edit->get_caret_column(0) == 4);
  1151. CHECK(text_edit->has_selection(1));
  1152. CHECK(text_edit->get_selected_text(1) == "test");
  1153. CHECK(text_edit->get_selection_from_line(1) == 2);
  1154. CHECK(text_edit->get_selection_from_column(1) == 0);
  1155. CHECK(text_edit->get_selection_to_line(1) == 2);
  1156. CHECK(text_edit->get_selection_to_column(1) == 4);
  1157. CHECK(text_edit->get_caret_line(1) == 2);
  1158. CHECK(text_edit->get_caret_column(1) == 4);
  1159. CHECK(text_edit->get_caret_count() == 2);
  1160. // Select word under caret disables selection if there is already a selection.
  1161. text_edit->select_word_under_caret();
  1162. CHECK_FALSE(text_edit->has_selection());
  1163. CHECK(text_edit->get_selected_text() == "");
  1164. SEND_GUI_ACTION("ui_text_select_word_under_caret");
  1165. CHECK(text_edit->get_viewport()->is_input_handled());
  1166. MessageQueue::get_singleton()->flush();
  1167. CHECK(text_edit->has_selection(0));
  1168. CHECK(text_edit->get_selected_text(0) == "test");
  1169. CHECK(text_edit->get_selection_from_line(0) == 1);
  1170. CHECK(text_edit->get_selection_from_column(0) == 0);
  1171. CHECK(text_edit->get_selection_to_line(0) == 1);
  1172. CHECK(text_edit->get_selection_to_column(0) == 4);
  1173. CHECK(text_edit->get_caret_line(0) == 1);
  1174. CHECK(text_edit->get_caret_column(0) == 4);
  1175. CHECK(text_edit->has_selection(1));
  1176. CHECK(text_edit->get_selected_text(1) == "test");
  1177. CHECK(text_edit->get_selection_from_line(1) == 2);
  1178. CHECK(text_edit->get_selection_from_column(1) == 0);
  1179. CHECK(text_edit->get_selection_to_line(1) == 2);
  1180. CHECK(text_edit->get_selection_to_column(1) == 4);
  1181. CHECK(text_edit->get_caret_line(1) == 2);
  1182. CHECK(text_edit->get_caret_column(1) == 4);
  1183. CHECK(text_edit->get_selected_text() == "test\ntest");
  1184. SIGNAL_CHECK("caret_changed", empty_signal_args);
  1185. // Cannot select when disabled.
  1186. text_edit->set_selecting_enabled(false);
  1187. text_edit->select_word_under_caret();
  1188. CHECK_FALSE(text_edit->has_selection());
  1189. CHECK(text_edit->get_selected_text() == "");
  1190. CHECK(text_edit->get_caret_line(0) == 1);
  1191. CHECK(text_edit->get_caret_column(0) == 4);
  1192. CHECK(text_edit->get_caret_line(1) == 2);
  1193. CHECK(text_edit->get_caret_column(1) == 4);
  1194. SIGNAL_CHECK_FALSE("caret_changed");
  1195. text_edit->set_selecting_enabled(true);
  1196. // Select word under caret when there is no word does not select.
  1197. text_edit->set_caret_line(1, false, true, -1, 0);
  1198. text_edit->set_caret_column(5, false, 0);
  1199. text_edit->set_caret_line(2, false, true, -1, 1);
  1200. text_edit->set_caret_column(5, false, 1);
  1201. text_edit->select_word_under_caret();
  1202. CHECK_FALSE(text_edit->has_selection());
  1203. CHECK(text_edit->get_selected_text() == "");
  1204. text_edit->select_word_under_caret();
  1205. CHECK_FALSE(text_edit->has_selection());
  1206. CHECK(text_edit->get_selected_text() == "");
  1207. CHECK(text_edit->get_caret_line(0) == 1);
  1208. CHECK(text_edit->get_caret_column(0) == 5);
  1209. CHECK(text_edit->get_caret_line(1) == 2);
  1210. CHECK(text_edit->get_caret_column(1) == 5);
  1211. SIGNAL_CHECK_FALSE("caret_changed");
  1212. }
  1213. SUBCASE("[TextEdit] add selection for next occurrence") {
  1214. text_edit->set_text("\ntest other_test\nrandom test\nword test word nonrandom");
  1215. text_edit->set_caret_column(0);
  1216. text_edit->set_caret_line(1);
  1217. // First selection made by the implicit select_word_under_caret call.
  1218. text_edit->add_selection_for_next_occurrence();
  1219. CHECK(text_edit->get_caret_count() == 1);
  1220. CHECK(text_edit->get_selected_text(0) == "test");
  1221. CHECK(text_edit->get_selection_from_line(0) == 1);
  1222. CHECK(text_edit->get_selection_from_column(0) == 0);
  1223. CHECK(text_edit->get_selection_to_line(0) == 1);
  1224. CHECK(text_edit->get_selection_to_column(0) == 4);
  1225. CHECK(text_edit->get_caret_line(0) == 1);
  1226. CHECK(text_edit->get_caret_column(0) == 4);
  1227. text_edit->add_selection_for_next_occurrence();
  1228. CHECK(text_edit->get_caret_count() == 2);
  1229. CHECK(text_edit->get_selected_text(1) == "test");
  1230. CHECK(text_edit->get_selection_from_line(1) == 1);
  1231. CHECK(text_edit->get_selection_from_column(1) == 13);
  1232. CHECK(text_edit->get_selection_to_line(1) == 1);
  1233. CHECK(text_edit->get_selection_to_column(1) == 17);
  1234. CHECK(text_edit->get_caret_line(1) == 1);
  1235. CHECK(text_edit->get_caret_column(1) == 17);
  1236. text_edit->add_selection_for_next_occurrence();
  1237. CHECK(text_edit->get_caret_count() == 3);
  1238. CHECK(text_edit->get_selected_text(2) == "test");
  1239. CHECK(text_edit->get_selection_from_line(2) == 2);
  1240. CHECK(text_edit->get_selection_from_column(2) == 9);
  1241. CHECK(text_edit->get_selection_to_line(2) == 2);
  1242. CHECK(text_edit->get_selection_to_column(2) == 13);
  1243. CHECK(text_edit->get_caret_line(2) == 2);
  1244. CHECK(text_edit->get_caret_column(2) == 13);
  1245. text_edit->add_selection_for_next_occurrence();
  1246. CHECK(text_edit->get_caret_count() == 4);
  1247. CHECK(text_edit->get_selected_text(3) == "test");
  1248. CHECK(text_edit->get_selection_from_line(3) == 3);
  1249. CHECK(text_edit->get_selection_from_column(3) == 5);
  1250. CHECK(text_edit->get_selection_to_line(3) == 3);
  1251. CHECK(text_edit->get_selection_to_column(3) == 9);
  1252. CHECK(text_edit->get_caret_line(3) == 3);
  1253. CHECK(text_edit->get_caret_column(3) == 9);
  1254. // A different word with a new manually added caret.
  1255. text_edit->add_caret(2, 1);
  1256. text_edit->select(2, 0, 2, 4, 4);
  1257. CHECK(text_edit->get_selected_text(4) == "rand");
  1258. text_edit->add_selection_for_next_occurrence();
  1259. CHECK(text_edit->get_caret_count() == 6);
  1260. CHECK(text_edit->get_selected_text(5) == "rand");
  1261. CHECK(text_edit->get_selection_from_line(5) == 3);
  1262. CHECK(text_edit->get_selection_from_column(5) == 18);
  1263. CHECK(text_edit->get_selection_to_line(5) == 3);
  1264. CHECK(text_edit->get_selection_to_column(5) == 22);
  1265. CHECK(text_edit->get_caret_line(5) == 3);
  1266. CHECK(text_edit->get_caret_column(5) == 22);
  1267. // Make sure the previous selections are still active.
  1268. CHECK(text_edit->get_selected_text(0) == "test");
  1269. CHECK(text_edit->get_selected_text(1) == "test");
  1270. CHECK(text_edit->get_selected_text(2) == "test");
  1271. CHECK(text_edit->get_selected_text(3) == "test");
  1272. }
  1273. SUBCASE("[TextEdit] skip selection for next occurrence") {
  1274. text_edit->set_text("\ntest other_test\nrandom test\nword test word nonrandom");
  1275. text_edit->set_caret_column(0);
  1276. text_edit->set_caret_line(1);
  1277. // Without selection on the current caret, the caret as 'jumped' to the next occurrence of the word under the caret.
  1278. text_edit->skip_selection_for_next_occurrence();
  1279. CHECK(text_edit->get_caret_count() == 1);
  1280. CHECK_FALSE(text_edit->has_selection(0));
  1281. CHECK(text_edit->get_caret_line(0) == 1);
  1282. CHECK(text_edit->get_caret_column(0) == 13);
  1283. // Repeating previous action.
  1284. // This time caret is in 'other_test' (other_|test)
  1285. // so the searched term will be 'other_test' or not just 'test'
  1286. // => no occurrence, as a side effect, the caret will move to start of the term.
  1287. text_edit->skip_selection_for_next_occurrence();
  1288. CHECK(text_edit->get_caret_count() == 1);
  1289. CHECK_FALSE(text_edit->has_selection(0));
  1290. CHECK(text_edit->get_caret_line(0) == 1);
  1291. CHECK(text_edit->get_caret_column(0) == 7);
  1292. // Repeating action again should do nothing now
  1293. text_edit->skip_selection_for_next_occurrence();
  1294. CHECK(text_edit->get_caret_count() == 1);
  1295. CHECK_FALSE(text_edit->has_selection(0));
  1296. CHECK(text_edit->get_caret_line(0) == 1);
  1297. CHECK(text_edit->get_caret_column(0) == 7);
  1298. // Moving back to the first 'test' occurrence.
  1299. text_edit->set_caret_column(0);
  1300. text_edit->set_caret_line(1);
  1301. // But this time, create a selection of it.
  1302. text_edit->add_selection_for_next_occurrence();
  1303. CHECK(text_edit->get_caret_count() == 1);
  1304. CHECK(text_edit->has_selection(0));
  1305. CHECK(text_edit->get_selected_text(0) == "test");
  1306. CHECK(text_edit->get_selection_from_line(0) == 1);
  1307. CHECK(text_edit->get_selection_from_column(0) == 0);
  1308. CHECK(text_edit->get_selection_to_line(0) == 1);
  1309. CHECK(text_edit->get_selection_to_column(0) == 4);
  1310. CHECK(text_edit->get_caret_line(0) == 1);
  1311. CHECK(text_edit->get_caret_column(0) == 4);
  1312. // Then, skipping it, but this time, selection has been made on the next occurrence.
  1313. text_edit->skip_selection_for_next_occurrence();
  1314. CHECK(text_edit->get_caret_count() == 1);
  1315. CHECK(text_edit->has_selection(0));
  1316. CHECK(text_edit->get_selected_text(0) == "test");
  1317. CHECK(text_edit->get_selection_from_line(0) == 1);
  1318. CHECK(text_edit->get_selection_from_column(0) == 13);
  1319. CHECK(text_edit->get_selection_to_line(0) == 1);
  1320. CHECK(text_edit->get_selection_to_column(0) == 17);
  1321. CHECK(text_edit->get_caret_line(0) == 1);
  1322. CHECK(text_edit->get_caret_column(0) == 17);
  1323. text_edit->skip_selection_for_next_occurrence();
  1324. CHECK(text_edit->get_caret_count() == 1);
  1325. CHECK(text_edit->has_selection(0));
  1326. CHECK(text_edit->get_selected_text(0) == "test");
  1327. CHECK(text_edit->get_selection_from_line(0) == 2);
  1328. CHECK(text_edit->get_selection_from_column(0) == 9);
  1329. CHECK(text_edit->get_selection_to_line(0) == 2);
  1330. CHECK(text_edit->get_selection_to_column(0) == 13);
  1331. CHECK(text_edit->get_caret_line(0) == 2);
  1332. CHECK(text_edit->get_caret_column(0) == 13);
  1333. text_edit->skip_selection_for_next_occurrence();
  1334. CHECK(text_edit->get_caret_count() == 1);
  1335. CHECK(text_edit->has_selection(0));
  1336. CHECK(text_edit->get_selected_text(0) == "test");
  1337. CHECK(text_edit->get_selection_from_line(0) == 3);
  1338. CHECK(text_edit->get_selection_from_column(0) == 5);
  1339. CHECK(text_edit->get_selection_to_line(0) == 3);
  1340. CHECK(text_edit->get_selection_to_column(0) == 9);
  1341. CHECK(text_edit->get_caret_line(0) == 3);
  1342. CHECK(text_edit->get_caret_column(0) == 9);
  1343. // Last skip, we are back to the first occurrence.
  1344. text_edit->skip_selection_for_next_occurrence();
  1345. CHECK(text_edit->has_selection(0));
  1346. CHECK(text_edit->get_selected_text(0) == "test");
  1347. CHECK(text_edit->get_selection_from_line(0) == 1);
  1348. CHECK(text_edit->get_selection_from_column(0) == 0);
  1349. CHECK(text_edit->get_selection_to_line(0) == 1);
  1350. CHECK(text_edit->get_selection_to_column(0) == 4);
  1351. CHECK(text_edit->get_caret_line(0) == 1);
  1352. CHECK(text_edit->get_caret_column(0) == 4);
  1353. // Adding first occurrence to selections/carets list
  1354. // and select occurrence on 'other_test'.
  1355. text_edit->add_selection_for_next_occurrence();
  1356. CHECK(text_edit->get_caret_count() == 2);
  1357. CHECK(text_edit->has_selection(0));
  1358. CHECK(text_edit->get_selected_text(0) == "test");
  1359. CHECK(text_edit->has_selection(1));
  1360. CHECK(text_edit->get_selected_text(1) == "test");
  1361. CHECK(text_edit->get_selection_from_line(1) == 1);
  1362. CHECK(text_edit->get_selection_from_column(1) == 13);
  1363. CHECK(text_edit->get_selection_to_line(1) == 1);
  1364. CHECK(text_edit->get_selection_to_column(1) == 17);
  1365. CHECK(text_edit->get_caret_line(1) == 1);
  1366. CHECK(text_edit->get_caret_column(1) == 17);
  1367. // We don't want this occurrence.
  1368. // Let's skip it.
  1369. text_edit->skip_selection_for_next_occurrence();
  1370. CHECK(text_edit->get_caret_count() == 2);
  1371. CHECK(text_edit->has_selection(0));
  1372. CHECK(text_edit->get_selected_text(0) == "test");
  1373. CHECK(text_edit->get_selected_text(1) == "test");
  1374. CHECK(text_edit->get_selection_from_line(1) == 2);
  1375. CHECK(text_edit->get_selection_from_column(1) == 9);
  1376. CHECK(text_edit->get_selection_to_line(1) == 2);
  1377. CHECK(text_edit->get_selection_to_column(1) == 13);
  1378. CHECK(text_edit->get_caret_line(1) == 2);
  1379. CHECK(text_edit->get_caret_column(1) == 13);
  1380. text_edit->skip_selection_for_next_occurrence();
  1381. CHECK(text_edit->get_caret_count() == 2);
  1382. CHECK(text_edit->has_selection(0));
  1383. CHECK(text_edit->get_selected_text(0) == "test");
  1384. CHECK(text_edit->get_selected_text(1) == "test");
  1385. CHECK(text_edit->get_selection_from_line(1) == 3);
  1386. CHECK(text_edit->get_selection_from_column(1) == 5);
  1387. CHECK(text_edit->get_selection_to_line(1) == 3);
  1388. CHECK(text_edit->get_selection_to_column(1) == 9);
  1389. CHECK(text_edit->get_caret_line(1) == 3);
  1390. CHECK(text_edit->get_caret_column(1) == 9);
  1391. // We are back the first occurrence.
  1392. text_edit->skip_selection_for_next_occurrence();
  1393. CHECK(text_edit->get_caret_count() == 1);
  1394. CHECK(text_edit->has_selection(0));
  1395. CHECK(text_edit->get_selected_text(0) == "test");
  1396. CHECK(text_edit->get_selection_from_line(0) == 1);
  1397. CHECK(text_edit->get_selection_from_column(0) == 0);
  1398. CHECK(text_edit->get_selection_to_line(0) == 1);
  1399. CHECK(text_edit->get_selection_to_column(0) == 4);
  1400. CHECK(text_edit->get_caret_line(0) == 1);
  1401. CHECK(text_edit->get_caret_column(0) == 4);
  1402. }
  1403. SUBCASE("[TextEdit] deselect on focus loss") {
  1404. text_edit->set_text("test");
  1405. text_edit->set_deselect_on_focus_loss_enabled(true);
  1406. CHECK(text_edit->is_deselect_on_focus_loss_enabled());
  1407. text_edit->grab_focus();
  1408. text_edit->select_all();
  1409. CHECK(text_edit->has_focus());
  1410. CHECK(text_edit->has_selection());
  1411. text_edit->release_focus();
  1412. CHECK_FALSE(text_edit->has_focus());
  1413. CHECK_FALSE(text_edit->has_selection());
  1414. text_edit->set_deselect_on_focus_loss_enabled(false);
  1415. CHECK_FALSE(text_edit->is_deselect_on_focus_loss_enabled());
  1416. text_edit->grab_focus();
  1417. text_edit->select_all();
  1418. CHECK(text_edit->has_focus());
  1419. CHECK(text_edit->has_selection());
  1420. text_edit->release_focus();
  1421. CHECK_FALSE(text_edit->has_focus());
  1422. CHECK(text_edit->has_selection());
  1423. text_edit->set_deselect_on_focus_loss_enabled(true);
  1424. CHECK_FALSE(text_edit->has_selection());
  1425. }
  1426. SUBCASE("[TextEdit] key select") {
  1427. text_edit->set_text("test");
  1428. text_edit->grab_focus();
  1429. SEND_GUI_KEY_EVENT(Key::RIGHT | KeyModifierMask::SHIFT)
  1430. CHECK(text_edit->has_selection());
  1431. CHECK(text_edit->get_selected_text() == "t");
  1432. CHECK(text_edit->is_caret_after_selection_origin());
  1433. #ifdef MACOS_ENABLED
  1434. SEND_GUI_KEY_EVENT(Key::RIGHT | KeyModifierMask::SHIFT | KeyModifierMask::ALT)
  1435. #else
  1436. SEND_GUI_KEY_EVENT(Key::RIGHT | KeyModifierMask::SHIFT | KeyModifierMask::CMD_OR_CTRL)
  1437. #endif
  1438. CHECK(text_edit->has_selection());
  1439. CHECK(text_edit->get_selected_text() == "test");
  1440. CHECK(text_edit->is_caret_after_selection_origin());
  1441. SEND_GUI_KEY_EVENT(Key::LEFT | KeyModifierMask::SHIFT)
  1442. CHECK(text_edit->has_selection());
  1443. CHECK(text_edit->get_selected_text() == "tes");
  1444. CHECK(text_edit->is_caret_after_selection_origin());
  1445. #ifdef MACOS_ENABLED
  1446. SEND_GUI_KEY_EVENT(Key::LEFT | KeyModifierMask::SHIFT | KeyModifierMask::ALT)
  1447. #else
  1448. SEND_GUI_KEY_EVENT(Key::LEFT | KeyModifierMask::SHIFT | KeyModifierMask::CMD_OR_CTRL)
  1449. #endif
  1450. CHECK_FALSE(text_edit->has_selection());
  1451. CHECK(text_edit->get_selected_text() == "");
  1452. SEND_GUI_KEY_EVENT(Key::RIGHT | KeyModifierMask::SHIFT)
  1453. CHECK(text_edit->has_selection());
  1454. CHECK(text_edit->get_selected_text() == "t");
  1455. SEND_GUI_KEY_EVENT(Key::RIGHT)
  1456. CHECK_FALSE(text_edit->has_selection());
  1457. CHECK(text_edit->get_selected_text() == "");
  1458. SEND_GUI_KEY_EVENT(Key::LEFT | KeyModifierMask::SHIFT)
  1459. CHECK(text_edit->has_selection());
  1460. CHECK(text_edit->get_selected_text() == "t");
  1461. CHECK_FALSE(text_edit->is_caret_after_selection_origin());
  1462. SEND_GUI_KEY_EVENT(Key::LEFT)
  1463. CHECK_FALSE(text_edit->has_selection());
  1464. CHECK(text_edit->get_selected_text() == "");
  1465. // Cannot select when disabled.
  1466. text_edit->set_selecting_enabled(false);
  1467. SEND_GUI_KEY_EVENT(Key::RIGHT | KeyModifierMask::SHIFT)
  1468. CHECK_FALSE(text_edit->has_selection());
  1469. CHECK(text_edit->get_selected_text() == "");
  1470. text_edit->set_selecting_enabled(true);
  1471. }
  1472. SUBCASE("[TextEdit] mouse drag select") {
  1473. // Set size for mouse input.
  1474. text_edit->set_size(Size2(200, 200));
  1475. text_edit->set_text("this is some text\nfor selection");
  1476. text_edit->grab_focus();
  1477. MessageQueue::get_singleton()->flush();
  1478. // Click and drag to make a selection.
  1479. SEND_GUI_MOUSE_BUTTON_EVENT(text_edit->get_rect_at_line_column(1, 0).get_center(), MouseButton::LEFT, MouseButtonMask::LEFT, Key::NONE);
  1480. // Add (2,0) to bring it past the center point of the grapheme and account for integer division flooring.
  1481. SEND_GUI_MOUSE_MOTION_EVENT(text_edit->get_rect_at_line_column(1, 5).get_center() + Point2i(2, 0), MouseButtonMask::LEFT, Key::NONE);
  1482. CHECK(text_edit->has_selection());
  1483. CHECK(text_edit->get_selected_text() == "for s");
  1484. CHECK(text_edit->get_selection_mode() == TextEdit::SELECTION_MODE_POINTER);
  1485. CHECK(text_edit->get_selection_origin_line() == 1);
  1486. CHECK(text_edit->get_selection_origin_column() == 0);
  1487. CHECK(text_edit->get_caret_line() == 1);
  1488. CHECK(text_edit->get_caret_column() == 5);
  1489. CHECK(text_edit->is_caret_after_selection_origin());
  1490. CHECK(text_edit->is_dragging_cursor());
  1491. // Releasing finishes.
  1492. SEND_GUI_MOUSE_BUTTON_RELEASED_EVENT(text_edit->get_rect_at_line_column(1, 5).get_center() + Point2i(2, 0), MouseButton::LEFT, MouseButtonMask::LEFT, Key::NONE);
  1493. CHECK(text_edit->has_selection());
  1494. CHECK(text_edit->get_selected_text() == "for s");
  1495. SEND_GUI_MOUSE_MOTION_EVENT(text_edit->get_rect_at_line_column(1, 9).get_center() + Point2i(2, 0), MouseButtonMask::NONE, Key::NONE);
  1496. CHECK(text_edit->has_selection());
  1497. CHECK(text_edit->get_selected_text() == "for s");
  1498. CHECK(text_edit->get_selection_origin_line() == 1);
  1499. CHECK(text_edit->get_selection_origin_column() == 0);
  1500. CHECK(text_edit->get_caret_line() == 1);
  1501. CHECK(text_edit->get_caret_column() == 5);
  1502. CHECK(text_edit->is_caret_after_selection_origin());
  1503. // Clicking clears selection.
  1504. SEND_GUI_MOUSE_BUTTON_EVENT(text_edit->get_rect_at_line_column(0, 7).get_center() + Point2i(2, 0), MouseButton::LEFT, MouseButtonMask::LEFT, Key::NONE);
  1505. CHECK_FALSE(text_edit->has_selection());
  1506. CHECK(text_edit->get_caret_line() == 0);
  1507. CHECK(text_edit->get_caret_column() == 7);
  1508. // Cannot select when disabled, but caret still moves.
  1509. text_edit->set_selecting_enabled(false);
  1510. SEND_GUI_MOUSE_BUTTON_EVENT(text_edit->get_rect_at_line_column(1, 0).get_center(), MouseButton::LEFT, MouseButtonMask::LEFT, Key::NONE);
  1511. CHECK(text_edit->get_caret_line() == 1);
  1512. CHECK(text_edit->get_caret_column() == 0);
  1513. SEND_GUI_MOUSE_MOTION_EVENT(text_edit->get_rect_at_line_column(1, 5).get_center() + Point2i(2, 0), MouseButtonMask::LEFT, Key::NONE);
  1514. CHECK_FALSE(text_edit->has_selection());
  1515. CHECK(text_edit->get_caret_line() == 1);
  1516. CHECK(text_edit->get_caret_column() == 5);
  1517. text_edit->set_selecting_enabled(true);
  1518. // Only last caret is moved when adding a selection.
  1519. text_edit->set_caret_line(0);
  1520. text_edit->set_caret_column(4);
  1521. text_edit->add_caret(0, 15);
  1522. text_edit->select(0, 11, 0, 15, 1);
  1523. MessageQueue::get_singleton()->flush();
  1524. SEND_GUI_MOUSE_BUTTON_EVENT(text_edit->get_rect_at_line_column(1, 5).get_center() + Point2i(2, 0), MouseButton::LEFT, MouseButtonMask::LEFT, Key::NONE | KeyModifierMask::ALT);
  1525. SEND_GUI_MOUSE_MOTION_EVENT(text_edit->get_rect_at_line_column(1, 0).get_center(), MouseButtonMask::LEFT, Key::NONE);
  1526. CHECK(text_edit->get_caret_count() == 3);
  1527. CHECK(text_edit->get_selection_mode() == TextEdit::SELECTION_MODE_POINTER);
  1528. CHECK_FALSE(text_edit->has_selection(0));
  1529. CHECK(text_edit->get_caret_line(0) == 0);
  1530. CHECK(text_edit->get_caret_column(0) == 4);
  1531. CHECK(text_edit->has_selection(1));
  1532. CHECK(text_edit->get_selection_origin_line(1) == 0);
  1533. CHECK(text_edit->get_selection_origin_column(1) == 11);
  1534. CHECK(text_edit->get_caret_line(1) == 0);
  1535. CHECK(text_edit->get_caret_column(1) == 15);
  1536. CHECK(text_edit->has_selection(2));
  1537. CHECK(text_edit->get_selected_text(2) == "for s");
  1538. CHECK(text_edit->get_selection_origin_line(2) == 1);
  1539. CHECK(text_edit->get_selection_origin_column(2) == 5);
  1540. CHECK(text_edit->get_caret_line(2) == 1);
  1541. CHECK(text_edit->get_caret_column(2) == 0);
  1542. CHECK_FALSE(text_edit->is_caret_after_selection_origin(2));
  1543. // Overlapping carets and selections merges them.
  1544. SEND_GUI_MOUSE_MOTION_EVENT(text_edit->get_rect_at_line_column(0, 3).get_center() + Point2i(2, 0), MouseButtonMask::LEFT, Key::NONE);
  1545. CHECK(text_edit->get_caret_count() == 1);
  1546. CHECK(text_edit->has_selection());
  1547. CHECK(text_edit->get_selected_text() == "s is some text\nfor s");
  1548. CHECK(text_edit->get_selection_mode() == TextEdit::SELECTION_MODE_POINTER);
  1549. CHECK(text_edit->get_selection_origin_line() == 1);
  1550. CHECK(text_edit->get_selection_origin_column() == 5);
  1551. CHECK(text_edit->get_caret_line() == 0);
  1552. CHECK(text_edit->get_caret_column() == 3);
  1553. CHECK_FALSE(text_edit->is_caret_after_selection_origin());
  1554. // Entering text stops selecting.
  1555. text_edit->insert_text_at_caret("a");
  1556. CHECK_FALSE(text_edit->has_selection());
  1557. CHECK(text_edit->get_text() == "thiaelection");
  1558. CHECK(text_edit->get_caret_line() == 0);
  1559. CHECK(text_edit->get_caret_column() == 4);
  1560. SEND_GUI_MOUSE_MOTION_EVENT(text_edit->get_rect_at_line_column(0, 10).get_center() + Point2i(2, 0), MouseButtonMask::NONE, Key::NONE);
  1561. CHECK_FALSE(text_edit->has_selection());
  1562. CHECK(text_edit->get_caret_line() == 0);
  1563. CHECK(text_edit->get_caret_column() == 4);
  1564. // Wrapped lines.
  1565. text_edit->set_line_wrapping_mode(TextEdit::LineWrappingMode::LINE_WRAPPING_BOUNDARY);
  1566. text_edit->set_text("this is some text\nfor selection");
  1567. text_edit->set_size(Size2(110, 100));
  1568. MessageQueue::get_singleton()->flush();
  1569. // Line 0 wraps: 'this is ', 'some text'.
  1570. // Line 1 wraps: 'for ', 'selection'.
  1571. CHECK(text_edit->is_line_wrapped(0));
  1572. // Select to the first character of a wrapped line.
  1573. SEND_GUI_MOUSE_BUTTON_EVENT(text_edit->get_rect_at_line_column(0, 11).get_center(), MouseButton::LEFT, MouseButtonMask::LEFT, Key::NONE);
  1574. SEND_GUI_MOUSE_MOTION_EVENT(text_edit->get_rect_at_line_column(0, 8).get_center(), MouseButtonMask::LEFT, Key::NONE);
  1575. CHECK(text_edit->has_selection());
  1576. CHECK(text_edit->get_selected_text() == "so");
  1577. CHECK(text_edit->get_selection_mode() == TextEdit::SELECTION_MODE_POINTER);
  1578. CHECK(text_edit->get_selection_origin_line() == 0);
  1579. CHECK(text_edit->get_selection_origin_column() == 10);
  1580. CHECK(text_edit->get_caret_line() == 0);
  1581. CHECK(text_edit->get_caret_column() == 8);
  1582. CHECK(text_edit->is_dragging_cursor());
  1583. }
  1584. SUBCASE("[TextEdit] mouse word select") {
  1585. // Set size for mouse input.
  1586. text_edit->set_size(Size2(200, 200));
  1587. text_edit->set_text("this is some text\nfor selection\n");
  1588. MessageQueue::get_singleton()->flush();
  1589. SIGNAL_DISCARD("caret_changed");
  1590. // Double click to select word.
  1591. SEND_GUI_DOUBLE_CLICK(text_edit->get_rect_at_line_column(1, 2).get_center() + Point2i(2, 0), Key::NONE);
  1592. CHECK(text_edit->has_selection());
  1593. CHECK(text_edit->get_selected_text() == "for");
  1594. CHECK(text_edit->get_selection_mode() == TextEdit::SELECTION_MODE_WORD);
  1595. CHECK(text_edit->get_selection_from_line() == 1);
  1596. CHECK(text_edit->get_selection_from_column() == 0);
  1597. CHECK(text_edit->get_selection_to_line() == 1);
  1598. CHECK(text_edit->get_selection_to_column() == 3);
  1599. CHECK(text_edit->get_caret_line() == 1);
  1600. CHECK(text_edit->get_caret_column() == 3);
  1601. CHECK(text_edit->is_caret_after_selection_origin());
  1602. SIGNAL_CHECK("caret_changed", empty_signal_args);
  1603. // Moving mouse selects entire words at a time.
  1604. SEND_GUI_MOUSE_MOTION_EVENT(text_edit->get_rect_at_line_column(1, 6).get_center() + Point2i(2, 0), MouseButtonMask::LEFT, Key::NONE);
  1605. CHECK(text_edit->has_selection());
  1606. CHECK(text_edit->get_selected_text() == "for selection");
  1607. CHECK(text_edit->get_selection_mode() == TextEdit::SELECTION_MODE_WORD);
  1608. CHECK(text_edit->get_selection_from_line() == 1);
  1609. CHECK(text_edit->get_selection_from_column() == 0);
  1610. CHECK(text_edit->get_selection_to_line() == 1);
  1611. CHECK(text_edit->get_selection_to_column() == 13);
  1612. CHECK(text_edit->get_caret_line() == 1);
  1613. CHECK(text_edit->get_caret_column() == 13);
  1614. CHECK(text_edit->is_caret_after_selection_origin());
  1615. CHECK(text_edit->is_dragging_cursor());
  1616. SIGNAL_CHECK("caret_changed", empty_signal_args);
  1617. // Moving to a word before the initial selected word reverses selection direction and keeps the initial word selected.
  1618. SEND_GUI_MOUSE_MOTION_EVENT(text_edit->get_rect_at_line_column(0, 10).get_center(), MouseButtonMask::LEFT, Key::NONE);
  1619. CHECK(text_edit->has_selection());
  1620. CHECK(text_edit->get_selected_text() == "some text\nfor");
  1621. CHECK(text_edit->get_selection_mode() == TextEdit::SELECTION_MODE_WORD);
  1622. CHECK(text_edit->get_selection_from_line() == 0);
  1623. CHECK(text_edit->get_selection_from_column() == 8);
  1624. CHECK(text_edit->get_selection_to_line() == 1);
  1625. CHECK(text_edit->get_selection_to_column() == 3);
  1626. CHECK(text_edit->get_caret_line() == 0);
  1627. CHECK(text_edit->get_caret_column() == 8);
  1628. CHECK_FALSE(text_edit->is_caret_after_selection_origin());
  1629. SIGNAL_CHECK("caret_changed", empty_signal_args);
  1630. // Releasing finishes.
  1631. SEND_GUI_MOUSE_BUTTON_RELEASED_EVENT(text_edit->get_rect_at_line_column(0, 10).get_center(), MouseButton::LEFT, MouseButtonMask::LEFT, Key::NONE);
  1632. CHECK(text_edit->has_selection());
  1633. CHECK(text_edit->get_selected_text() == "some text\nfor");
  1634. SEND_GUI_MOUSE_MOTION_EVENT(text_edit->get_rect_at_line_column(1, 2).get_center(), MouseButtonMask::NONE, Key::NONE);
  1635. CHECK(text_edit->has_selection());
  1636. CHECK(text_edit->get_selected_text() == "some text\nfor");
  1637. text_edit->deselect();
  1638. // Can start word select mode on an empty line.
  1639. SEND_GUI_DOUBLE_CLICK(text_edit->get_rect_at_line_column(2, 0).get_center() + Point2i(2, 0), Key::NONE);
  1640. CHECK_FALSE(text_edit->has_selection());
  1641. CHECK(text_edit->get_selection_mode() == TextEdit::SELECTION_MODE_WORD);
  1642. CHECK(text_edit->get_caret_line() == 2);
  1643. CHECK(text_edit->get_caret_column() == 0);
  1644. SEND_GUI_MOUSE_MOTION_EVENT(text_edit->get_rect_at_line_column(1, 9).get_center(), MouseButtonMask::LEFT, Key::NONE);
  1645. CHECK(text_edit->has_selection());
  1646. CHECK(text_edit->get_selected_text() == "selection\n");
  1647. CHECK(text_edit->get_selection_mode() == TextEdit::SELECTION_MODE_WORD);
  1648. CHECK(text_edit->get_caret_line() == 1);
  1649. CHECK(text_edit->get_caret_column() == 4);
  1650. CHECK(text_edit->get_selection_origin_line() == 2);
  1651. CHECK(text_edit->get_selection_origin_column() == 0);
  1652. // Clicking clears selection.
  1653. SEND_GUI_MOUSE_BUTTON_EVENT(text_edit->get_rect_at_line_column(0, 0).get_center(), MouseButton::LEFT, MouseButtonMask::LEFT, Key::NONE);
  1654. CHECK_FALSE(text_edit->has_selection());
  1655. CHECK(text_edit->get_caret_line() == 0);
  1656. CHECK(text_edit->get_caret_column() == 0);
  1657. // Can start word select mode when not on a word.
  1658. SEND_GUI_DOUBLE_CLICK(text_edit->get_rect_at_line_column(0, 12).get_center() + Point2i(2, 0), Key::NONE);
  1659. CHECK(text_edit->get_selection_mode() == TextEdit::SELECTION_MODE_WORD);
  1660. CHECK_FALSE(text_edit->has_selection());
  1661. CHECK(text_edit->get_caret_line() == 0);
  1662. CHECK(text_edit->get_caret_column() == 12);
  1663. SEND_GUI_MOUSE_MOTION_EVENT(text_edit->get_rect_at_line_column(1, 9).get_center(), MouseButtonMask::LEFT, Key::NONE);
  1664. CHECK(text_edit->get_selection_mode() == TextEdit::SELECTION_MODE_WORD);
  1665. CHECK(text_edit->has_selection());
  1666. CHECK(text_edit->get_selected_text() == " text\nfor selection");
  1667. CHECK(text_edit->get_caret_line() == 1);
  1668. CHECK(text_edit->get_caret_column() == 13);
  1669. CHECK(text_edit->get_selection_origin_line() == 0);
  1670. CHECK(text_edit->get_selection_origin_column() == 12);
  1671. SEND_GUI_MOUSE_MOTION_EVENT(text_edit->get_rect_at_line_column(0, 10).get_center(), MouseButtonMask::LEFT, Key::NONE);
  1672. CHECK(text_edit->get_selection_mode() == TextEdit::SELECTION_MODE_WORD);
  1673. CHECK(text_edit->has_selection());
  1674. CHECK(text_edit->get_selected_text() == "some");
  1675. CHECK(text_edit->get_caret_line() == 0);
  1676. CHECK(text_edit->get_caret_column() == 8);
  1677. CHECK(text_edit->get_selection_origin_line() == 0);
  1678. CHECK(text_edit->get_selection_origin_column() == 12);
  1679. SEND_GUI_MOUSE_BUTTON_RELEASED_EVENT(text_edit->get_rect_at_line_column(0, 15).get_center(), MouseButton::LEFT, MouseButtonMask::LEFT, Key::NONE);
  1680. // Add a new selection without affecting the old one.
  1681. SEND_GUI_MOUSE_BUTTON_EVENT(text_edit->get_rect_at_line_column(1, 5).get_center() + Point2i(2, 0), MouseButton::LEFT, MouseButtonMask::LEFT, Key::NONE | KeyModifierMask::ALT);
  1682. SEND_GUI_MOUSE_MOTION_EVENT(text_edit->get_rect_at_line_column(1, 8).get_center() + Point2i(2, 0), MouseButtonMask::LEFT, Key::NONE | KeyModifierMask::ALT);
  1683. CHECK(text_edit->get_selection_mode() == TextEdit::SELECTION_MODE_POINTER);
  1684. CHECK(text_edit->get_caret_count() == 2);
  1685. CHECK(text_edit->has_selection(0));
  1686. CHECK(text_edit->get_selected_text(0) == "some");
  1687. CHECK(text_edit->get_caret_line(0) == 0);
  1688. CHECK(text_edit->get_caret_column(0) == 8);
  1689. CHECK(text_edit->get_selection_origin_line(0) == 0);
  1690. CHECK(text_edit->get_selection_origin_column(0) == 12);
  1691. CHECK(text_edit->has_selection(1));
  1692. CHECK(text_edit->get_selected_text(1) == "ele");
  1693. CHECK(text_edit->get_caret_line(1) == 1);
  1694. CHECK(text_edit->get_caret_column(1) == 8);
  1695. CHECK(text_edit->get_selection_origin_line(1) == 1);
  1696. CHECK(text_edit->get_selection_origin_column(1) == 5);
  1697. // Shift + double click to extend selection and start word select mode.
  1698. SEND_GUI_MOUSE_BUTTON_RELEASED_EVENT(text_edit->get_rect_at_line_column(1, 8).get_center(), MouseButton::LEFT, MouseButtonMask::LEFT, Key::NONE);
  1699. text_edit->remove_secondary_carets();
  1700. SEND_GUI_DOUBLE_CLICK(text_edit->get_rect_at_line_column(1, 7).get_center() + Point2i(2, 0), Key::NONE | KeyModifierMask::SHIFT);
  1701. CHECK(text_edit->get_selection_mode() == TextEdit::SELECTION_MODE_WORD);
  1702. CHECK(text_edit->has_selection());
  1703. CHECK(text_edit->get_selected_text() == " text\nfor selection");
  1704. CHECK(text_edit->get_caret_line() == 1);
  1705. CHECK(text_edit->get_caret_column() == 13);
  1706. CHECK(text_edit->get_selection_origin_line() == 0);
  1707. CHECK(text_edit->get_selection_origin_column() == 12);
  1708. // Cannot select when disabled, but caret still moves to end of word.
  1709. text_edit->set_selecting_enabled(false);
  1710. SEND_GUI_DOUBLE_CLICK(text_edit->get_rect_at_line_column(1, 1).get_center() + Point2i(2, 0), Key::NONE);
  1711. CHECK_FALSE(text_edit->has_selection());
  1712. CHECK(text_edit->get_caret_line() == 1);
  1713. CHECK(text_edit->get_caret_column() == 3);
  1714. text_edit->set_selecting_enabled(true);
  1715. }
  1716. SUBCASE("[TextEdit] mouse line select") {
  1717. // Set size for mouse input.
  1718. text_edit->set_size(Size2(200, 200));
  1719. text_edit->set_text("this is some text\nfor selection\nwith 3 lines");
  1720. MessageQueue::get_singleton()->flush();
  1721. // Triple click to select line.
  1722. SEND_GUI_DOUBLE_CLICK(text_edit->get_rect_at_line_column(1, 2).get_center(), Key::NONE);
  1723. SEND_GUI_MOUSE_BUTTON_EVENT(text_edit->get_rect_at_line_column(1, 2).get_center(), MouseButton::LEFT, MouseButtonMask::LEFT, Key::NONE);
  1724. CHECK(text_edit->has_selection());
  1725. CHECK(text_edit->get_selected_text() == "for selection\n");
  1726. CHECK(text_edit->get_selection_mode() == TextEdit::SELECTION_MODE_LINE);
  1727. CHECK(text_edit->get_selection_from_line() == 1);
  1728. CHECK(text_edit->get_selection_from_column() == 0);
  1729. CHECK(text_edit->get_selection_to_line() == 2);
  1730. CHECK(text_edit->get_selection_to_column() == 0);
  1731. CHECK(text_edit->get_caret_line() == 2);
  1732. CHECK(text_edit->get_caret_column() == 0);
  1733. CHECK(text_edit->is_caret_after_selection_origin());
  1734. // Moving mouse selects entire lines at a time. Selecting above reverses the selection direction.
  1735. SEND_GUI_MOUSE_MOTION_EVENT(text_edit->get_rect_at_line_column(0, 10).get_center(), MouseButtonMask::LEFT, Key::NONE);
  1736. CHECK(text_edit->has_selection());
  1737. CHECK(text_edit->get_selected_text() == "this is some text\nfor selection");
  1738. CHECK(text_edit->get_selection_mode() == TextEdit::SELECTION_MODE_LINE);
  1739. CHECK(text_edit->get_selection_from_line() == 0);
  1740. CHECK(text_edit->get_selection_from_column() == 0);
  1741. CHECK(text_edit->get_selection_to_line() == 1);
  1742. CHECK(text_edit->get_selection_to_column() == 13);
  1743. CHECK(text_edit->get_caret_line() == 0);
  1744. CHECK(text_edit->get_caret_column() == 0);
  1745. CHECK_FALSE(text_edit->is_caret_after_selection_origin());
  1746. CHECK(text_edit->is_dragging_cursor());
  1747. // Selecting to the last line puts the caret at end of the line.
  1748. SEND_GUI_MOUSE_MOTION_EVENT(text_edit->get_rect_at_line_column(2, 10).get_center(), MouseButtonMask::LEFT, Key::NONE);
  1749. CHECK(text_edit->has_selection());
  1750. CHECK(text_edit->get_selected_text() == "for selection\nwith 3 lines");
  1751. CHECK(text_edit->get_selection_mode() == TextEdit::SELECTION_MODE_LINE);
  1752. CHECK(text_edit->get_selection_from_line() == 1);
  1753. CHECK(text_edit->get_selection_from_column() == 0);
  1754. CHECK(text_edit->get_selection_to_line() == 2);
  1755. CHECK(text_edit->get_selection_to_column() == 12);
  1756. CHECK(text_edit->get_caret_line() == 2);
  1757. CHECK(text_edit->get_caret_column() == 12);
  1758. CHECK(text_edit->is_caret_after_selection_origin());
  1759. // Releasing finishes.
  1760. SEND_GUI_MOUSE_BUTTON_RELEASED_EVENT(text_edit->get_rect_at_line_column(2, 10).get_center(), MouseButton::LEFT, MouseButtonMask::LEFT, Key::NONE);
  1761. CHECK(text_edit->has_selection());
  1762. CHECK(text_edit->get_selected_text() == "for selection\nwith 3 lines");
  1763. SEND_GUI_MOUSE_MOTION_EVENT(text_edit->get_rect_at_line_column(1, 2).get_center(), MouseButtonMask::NONE, Key::NONE);
  1764. CHECK(text_edit->has_selection());
  1765. CHECK(text_edit->get_selected_text() == "for selection\nwith 3 lines");
  1766. // Clicking clears selection.
  1767. SEND_GUI_MOUSE_BUTTON_EVENT(text_edit->get_rect_at_line_column(0, 0).get_center(), MouseButton::LEFT, MouseButtonMask::LEFT, Key::NONE);
  1768. CHECK_FALSE(text_edit->has_selection());
  1769. CHECK(text_edit->get_caret_line() == 0);
  1770. CHECK(text_edit->get_caret_column() == 0);
  1771. SEND_GUI_MOUSE_BUTTON_RELEASED_EVENT(text_edit->get_rect_at_line_column(0, 0).get_center(), MouseButton::LEFT, MouseButtonMask::LEFT, Key::NONE);
  1772. // Can start line select mode on an empty line.
  1773. text_edit->set_text("this is some text\n\nfor selection\nwith 4 lines");
  1774. MessageQueue::get_singleton()->flush();
  1775. SEND_GUI_DOUBLE_CLICK(text_edit->get_rect_at_line_column(1, 0).get_center() + Point2i(2, 0), Key::NONE);
  1776. SEND_GUI_MOUSE_BUTTON_EVENT(text_edit->get_rect_at_line_column(1, 0).get_center(), MouseButton::LEFT, MouseButtonMask::LEFT, Key::NONE);
  1777. CHECK(text_edit->has_selection());
  1778. CHECK(text_edit->get_selected_text() == "\n");
  1779. CHECK(text_edit->get_selection_mode() == TextEdit::SELECTION_MODE_LINE);
  1780. CHECK(text_edit->get_caret_line() == 2);
  1781. CHECK(text_edit->get_caret_column() == 0);
  1782. CHECK(text_edit->get_selection_origin_line() == 1);
  1783. CHECK(text_edit->get_selection_origin_column() == 0);
  1784. SEND_GUI_MOUSE_MOTION_EVENT(text_edit->get_rect_at_line_column(2, 9).get_center(), MouseButtonMask::LEFT, Key::NONE);
  1785. CHECK(text_edit->has_selection());
  1786. CHECK(text_edit->get_selected_text() == "\nfor selection\n");
  1787. CHECK(text_edit->get_selection_mode() == TextEdit::SELECTION_MODE_LINE);
  1788. CHECK(text_edit->get_caret_line() == 3);
  1789. CHECK(text_edit->get_caret_column() == 0);
  1790. CHECK(text_edit->get_selection_origin_line() == 1);
  1791. CHECK(text_edit->get_selection_origin_column() == 0);
  1792. // Add a new selection without affecting the old one.
  1793. SEND_GUI_MOUSE_BUTTON_EVENT(text_edit->get_rect_at_line_column(0, 3).get_center(), MouseButton::LEFT, MouseButtonMask::LEFT, Key::NONE | KeyModifierMask::ALT);
  1794. SEND_GUI_MOUSE_MOTION_EVENT(text_edit->get_rect_at_line_column(0, 4).get_center() + Point2i(2, 0), MouseButtonMask::LEFT, Key::NONE | KeyModifierMask::ALT);
  1795. CHECK(text_edit->get_selection_mode() == TextEdit::SELECTION_MODE_POINTER);
  1796. CHECK(text_edit->get_caret_count() == 2);
  1797. CHECK(text_edit->has_selection(0));
  1798. CHECK(text_edit->get_selected_text(0) == "\nfor selection\n");
  1799. CHECK(text_edit->get_caret_line(0) == 3);
  1800. CHECK(text_edit->get_caret_column(0) == 0);
  1801. CHECK(text_edit->get_selection_origin_line(0) == 1);
  1802. CHECK(text_edit->get_selection_origin_column(0) == 0);
  1803. CHECK(text_edit->has_selection(1));
  1804. CHECK(text_edit->get_selected_text(1) == "is");
  1805. CHECK(text_edit->get_caret_line(1) == 0);
  1806. CHECK(text_edit->get_caret_column(1) == 4);
  1807. CHECK(text_edit->get_selection_origin_line(1) == 0);
  1808. CHECK(text_edit->get_selection_origin_column(1) == 2);
  1809. text_edit->remove_secondary_carets();
  1810. text_edit->deselect();
  1811. // Selecting the last line puts caret at the end.
  1812. SEND_GUI_DOUBLE_CLICK(text_edit->get_rect_at_line_column(3, 3).get_center(), Key::NONE);
  1813. SEND_GUI_MOUSE_BUTTON_EVENT(text_edit->get_rect_at_line_column(3, 3).get_center(), MouseButton::LEFT, MouseButtonMask::LEFT, Key::NONE);
  1814. CHECK(text_edit->get_selection_mode() == TextEdit::SELECTION_MODE_LINE);
  1815. CHECK(text_edit->has_selection());
  1816. CHECK(text_edit->get_selected_text() == "with 4 lines");
  1817. CHECK(text_edit->get_caret_line() == 3);
  1818. CHECK(text_edit->get_caret_column() == 12);
  1819. CHECK(text_edit->get_selection_origin_line() == 3);
  1820. CHECK(text_edit->get_selection_origin_column() == 0);
  1821. // Selecting above reverses direction.
  1822. SEND_GUI_MOUSE_MOTION_EVENT(text_edit->get_rect_at_line_column(2, 10).get_center(), MouseButtonMask::LEFT, Key::NONE);
  1823. CHECK(text_edit->get_selection_mode() == TextEdit::SELECTION_MODE_LINE);
  1824. CHECK(text_edit->has_selection());
  1825. CHECK(text_edit->get_selected_text() == "for selection\nwith 4 lines");
  1826. CHECK(text_edit->get_caret_line() == 2);
  1827. CHECK(text_edit->get_caret_column() == 0);
  1828. CHECK(text_edit->get_selection_origin_line() == 3);
  1829. CHECK(text_edit->get_selection_origin_column() == 12);
  1830. SEND_GUI_MOUSE_BUTTON_RELEASED_EVENT(text_edit->get_rect_at_line_column(2, 10).get_center(), MouseButton::LEFT, MouseButtonMask::LEFT, Key::NONE);
  1831. // Shift + triple click to extend selection and restart line select mode.
  1832. SEND_GUI_DOUBLE_CLICK(text_edit->get_rect_at_line_column(0, 9).get_center() + Point2i(2, 0), Key::NONE | KeyModifierMask::SHIFT);
  1833. SEND_GUI_MOUSE_BUTTON_EVENT(text_edit->get_rect_at_line_column(0, 9).get_center(), MouseButton::LEFT, MouseButtonMask::LEFT, Key::NONE | KeyModifierMask::SHIFT);
  1834. CHECK(text_edit->get_selection_mode() == TextEdit::SELECTION_MODE_LINE);
  1835. CHECK(text_edit->has_selection());
  1836. CHECK(text_edit->get_selected_text() == "this is some text\n\nfor selection\nwith 4 lines");
  1837. CHECK(text_edit->get_caret_line() == 0);
  1838. CHECK(text_edit->get_caret_column() == 0);
  1839. CHECK(text_edit->get_selection_origin_line() == 3);
  1840. CHECK(text_edit->get_selection_origin_column() == 12);
  1841. // Cannot select when disabled, but caret still moves to the start of the next line.
  1842. text_edit->set_selecting_enabled(false);
  1843. SEND_GUI_DOUBLE_CLICK(text_edit->get_rect_at_line_column(0, 2).get_center(), Key::NONE);
  1844. SEND_GUI_MOUSE_BUTTON_EVENT(text_edit->get_rect_at_line_column(0, 2).get_center(), MouseButton::LEFT, MouseButtonMask::LEFT, Key::NONE);
  1845. CHECK_FALSE(text_edit->has_selection());
  1846. CHECK(text_edit->get_caret_line() == 1);
  1847. CHECK(text_edit->get_caret_column() == 0);
  1848. text_edit->set_selecting_enabled(true);
  1849. }
  1850. SUBCASE("[TextEdit] mouse shift click select") {
  1851. // Set size for mouse input.
  1852. text_edit->set_size(Size2(200, 200));
  1853. text_edit->set_text("this is some text\nfor selection");
  1854. MessageQueue::get_singleton()->flush();
  1855. // Shift click to make a selection from the previous caret position.
  1856. SEND_GUI_MOUSE_BUTTON_EVENT(text_edit->get_rect_at_line_column(1, 1).get_center() + Point2i(2, 0), MouseButton::LEFT, MouseButtonMask::LEFT, Key::NONE);
  1857. SEND_GUI_MOUSE_BUTTON_EVENT(text_edit->get_rect_at_line_column(1, 5).get_center() + Point2i(2, 0), MouseButton::LEFT, MouseButtonMask::LEFT, Key::NONE | KeyModifierMask::SHIFT);
  1858. CHECK(text_edit->has_selection());
  1859. CHECK(text_edit->get_selected_text() == "or s");
  1860. CHECK(text_edit->get_selection_mode() == TextEdit::SELECTION_MODE_POINTER);
  1861. CHECK(text_edit->get_selection_origin_line() == 1);
  1862. CHECK(text_edit->get_selection_origin_column() == 1);
  1863. CHECK(text_edit->get_caret_line() == 1);
  1864. CHECK(text_edit->get_caret_column() == 5);
  1865. CHECK(text_edit->is_caret_after_selection_origin());
  1866. // Shift click above to switch selection direction. Uses original selection position.
  1867. SEND_GUI_MOUSE_BUTTON_EVENT(text_edit->get_rect_at_line_column(0, 6).get_center() + Point2i(2, 0), MouseButton::LEFT, MouseButtonMask::LEFT, Key::NONE | KeyModifierMask::SHIFT);
  1868. CHECK(text_edit->has_selection());
  1869. CHECK(text_edit->get_selected_text() == "s some text\nf");
  1870. CHECK(text_edit->get_selection_mode() == TextEdit::SELECTION_MODE_POINTER);
  1871. CHECK(text_edit->get_selection_origin_line() == 1);
  1872. CHECK(text_edit->get_selection_origin_column() == 1);
  1873. CHECK(text_edit->get_caret_line() == 0);
  1874. CHECK(text_edit->get_caret_column() == 6);
  1875. CHECK_FALSE(text_edit->is_caret_after_selection_origin());
  1876. // Clicking clears selection.
  1877. SEND_GUI_MOUSE_BUTTON_EVENT(text_edit->get_rect_at_line_column(1, 7).get_center() + Point2i(2, 0), MouseButton::LEFT, MouseButtonMask::LEFT, Key::NONE);
  1878. CHECK_FALSE(text_edit->has_selection());
  1879. CHECK(text_edit->get_caret_line() == 1);
  1880. CHECK(text_edit->get_caret_column() == 7);
  1881. // Cannot select when disabled, but caret still moves.
  1882. text_edit->set_selecting_enabled(false);
  1883. SEND_GUI_MOUSE_BUTTON_EVENT(text_edit->get_rect_at_line_column(1, 0).get_center(), MouseButton::LEFT, MouseButtonMask::LEFT, Key::NONE);
  1884. CHECK(text_edit->get_caret_line() == 1);
  1885. CHECK(text_edit->get_caret_column() == 0);
  1886. SEND_GUI_MOUSE_BUTTON_EVENT(text_edit->get_rect_at_line_column(1, 5).get_center() + Point2i(2, 0), MouseButton::LEFT, MouseButtonMask::LEFT, Key::NONE | KeyModifierMask::SHIFT);
  1887. CHECK_FALSE(text_edit->has_selection());
  1888. CHECK(text_edit->get_caret_line() == 1);
  1889. CHECK(text_edit->get_caret_column() == 5);
  1890. text_edit->set_selecting_enabled(true);
  1891. }
  1892. SUBCASE("[TextEdit] select and deselect") {
  1893. text_edit->set_text("this is some text\nfor selection");
  1894. MessageQueue::get_singleton()->flush();
  1895. SIGNAL_DISCARD("caret_changed");
  1896. // Select clamps input to full text.
  1897. text_edit->select(-1, -1, 500, 500);
  1898. MessageQueue::get_singleton()->flush();
  1899. CHECK(text_edit->has_selection());
  1900. CHECK(text_edit->get_selected_text() == "this is some text\nfor selection");
  1901. CHECK(text_edit->is_caret_after_selection_origin(0));
  1902. CHECK(text_edit->get_selection_origin_line(0) == 0);
  1903. CHECK(text_edit->get_selection_origin_column(0) == 0);
  1904. CHECK(text_edit->get_caret_line(0) == 1);
  1905. CHECK(text_edit->get_caret_column(0) == 13);
  1906. CHECK(text_edit->get_selection_from_line(0) == text_edit->get_selection_origin_line(0));
  1907. CHECK(text_edit->get_selection_from_column(0) == text_edit->get_selection_origin_column(0));
  1908. CHECK(text_edit->get_selection_to_line(0) == text_edit->get_caret_line(0));
  1909. CHECK(text_edit->get_selection_to_column(0) == text_edit->get_caret_column(0));
  1910. SIGNAL_CHECK("caret_changed", empty_signal_args);
  1911. text_edit->deselect();
  1912. MessageQueue::get_singleton()->flush();
  1913. CHECK_FALSE(text_edit->has_selection());
  1914. SIGNAL_CHECK_FALSE("caret_changed");
  1915. // Select works in the other direction.
  1916. text_edit->select(500, 500, -1, -1);
  1917. MessageQueue::get_singleton()->flush();
  1918. CHECK(text_edit->has_selection());
  1919. CHECK(text_edit->get_selected_text() == "this is some text\nfor selection");
  1920. CHECK_FALSE(text_edit->is_caret_after_selection_origin(0));
  1921. CHECK(text_edit->get_selection_origin_line(0) == 1);
  1922. CHECK(text_edit->get_selection_origin_column(0) == 13);
  1923. CHECK(text_edit->get_caret_line(0) == 0);
  1924. CHECK(text_edit->get_caret_column(0) == 0);
  1925. CHECK(text_edit->get_selection_from_line(0) == text_edit->get_caret_line(0));
  1926. CHECK(text_edit->get_selection_from_column(0) == text_edit->get_caret_column(0));
  1927. CHECK(text_edit->get_selection_to_line(0) == text_edit->get_selection_origin_line(0));
  1928. CHECK(text_edit->get_selection_to_column(0) == text_edit->get_selection_origin_column(0));
  1929. SIGNAL_CHECK("caret_changed", empty_signal_args);
  1930. text_edit->deselect();
  1931. MessageQueue::get_singleton()->flush();
  1932. CHECK_FALSE(text_edit->has_selection());
  1933. SIGNAL_CHECK_FALSE("caret_changed");
  1934. // Select part of a line.
  1935. text_edit->select(0, 4, 0, 8);
  1936. MessageQueue::get_singleton()->flush();
  1937. CHECK(text_edit->has_selection());
  1938. CHECK(text_edit->get_selected_text() == " is ");
  1939. CHECK(text_edit->is_caret_after_selection_origin(0));
  1940. CHECK(text_edit->get_selection_origin_line(0) == 0);
  1941. CHECK(text_edit->get_selection_origin_column(0) == 4);
  1942. CHECK(text_edit->get_caret_line(0) == 0);
  1943. CHECK(text_edit->get_caret_column(0) == 8);
  1944. CHECK(text_edit->get_selection_from_line(0) == text_edit->get_selection_origin_line(0));
  1945. CHECK(text_edit->get_selection_from_column(0) == text_edit->get_selection_origin_column(0));
  1946. CHECK(text_edit->get_selection_to_line(0) == text_edit->get_caret_line(0));
  1947. CHECK(text_edit->get_selection_to_column(0) == text_edit->get_caret_column(0));
  1948. SIGNAL_CHECK("caret_changed", empty_signal_args);
  1949. text_edit->deselect();
  1950. MessageQueue::get_singleton()->flush();
  1951. CHECK_FALSE(text_edit->has_selection());
  1952. SIGNAL_CHECK_FALSE("caret_changed");
  1953. // Select part of a line in the other direction.
  1954. text_edit->select(0, 8, 0, 4);
  1955. MessageQueue::get_singleton()->flush();
  1956. CHECK(text_edit->has_selection());
  1957. CHECK(text_edit->get_selected_text() == " is ");
  1958. CHECK_FALSE(text_edit->is_caret_after_selection_origin(0));
  1959. CHECK(text_edit->get_selection_origin_line(0) == 0);
  1960. CHECK(text_edit->get_selection_origin_column(0) == 8);
  1961. CHECK(text_edit->get_caret_line(0) == 0);
  1962. CHECK(text_edit->get_caret_column(0) == 4);
  1963. CHECK(text_edit->get_selection_from_line(0) == text_edit->get_caret_line(0));
  1964. CHECK(text_edit->get_selection_from_column(0) == text_edit->get_caret_column(0));
  1965. CHECK(text_edit->get_selection_to_line(0) == text_edit->get_selection_origin_line(0));
  1966. CHECK(text_edit->get_selection_to_column(0) == text_edit->get_selection_origin_column(0));
  1967. SIGNAL_CHECK("caret_changed", empty_signal_args);
  1968. // Cannot select when disabled.
  1969. text_edit->set_selecting_enabled(false);
  1970. CHECK_FALSE(text_edit->has_selection());
  1971. text_edit->select(0, 8, 0, 4);
  1972. MessageQueue::get_singleton()->flush();
  1973. CHECK_FALSE(text_edit->has_selection());
  1974. SIGNAL_CHECK_FALSE("caret_changed");
  1975. text_edit->set_selecting_enabled(true);
  1976. }
  1977. SUBCASE("[TextEdit] delete selection") {
  1978. text_edit->set_text("this is some text\nfor selection");
  1979. MessageQueue::get_singleton()->flush();
  1980. // Delete selection does nothing if there is no selection.
  1981. text_edit->set_caret_line(0);
  1982. text_edit->set_caret_column(8);
  1983. CHECK_FALSE(text_edit->has_selection());
  1984. text_edit->delete_selection();
  1985. CHECK(text_edit->get_text() == "this is some text\nfor selection");
  1986. CHECK_FALSE(text_edit->has_selection());
  1987. CHECK(text_edit->get_caret_line() == 0);
  1988. CHECK(text_edit->get_caret_column() == 8);
  1989. // Backspace removes selection.
  1990. text_edit->select(0, 4, 0, 8);
  1991. CHECK(text_edit->has_selection());
  1992. SEND_GUI_ACTION("ui_text_backspace");
  1993. CHECK_FALSE(text_edit->has_selection());
  1994. CHECK(text_edit->get_text() == "thissome text\nfor selection");
  1995. CHECK(text_edit->get_caret_line() == 0);
  1996. CHECK(text_edit->get_caret_column() == 4);
  1997. // Undo restores previous selection.
  1998. text_edit->undo();
  1999. CHECK(text_edit->get_text() == "this is some text\nfor selection");
  2000. CHECK(text_edit->has_selection());
  2001. CHECK(text_edit->get_caret_line() == 0);
  2002. CHECK(text_edit->get_caret_column() == 8);
  2003. CHECK(text_edit->get_selection_origin_line() == 0);
  2004. CHECK(text_edit->get_selection_origin_column() == 4);
  2005. // Redo restores caret.
  2006. text_edit->redo();
  2007. CHECK(text_edit->get_text() == "thissome text\nfor selection");
  2008. CHECK_FALSE(text_edit->has_selection());
  2009. CHECK(text_edit->get_caret_line() == 0);
  2010. CHECK(text_edit->get_caret_column() == 4);
  2011. text_edit->undo();
  2012. CHECK(text_edit->get_text() == "this is some text\nfor selection");
  2013. CHECK(text_edit->has_selection());
  2014. CHECK(text_edit->get_caret_line() == 0);
  2015. CHECK(text_edit->get_caret_column() == 8);
  2016. text_edit->select(0, 4, 0, 8);
  2017. CHECK(text_edit->has_selection());
  2018. // Delete selection removes text, deselects, and moves caret.
  2019. text_edit->delete_selection();
  2020. CHECK(text_edit->get_text() == "thissome text\nfor selection");
  2021. CHECK_FALSE(text_edit->has_selection());
  2022. CHECK(text_edit->get_caret_line() == 0);
  2023. CHECK(text_edit->get_caret_column() == 4);
  2024. // Undo delete works.
  2025. text_edit->undo();
  2026. CHECK(text_edit->get_text() == "this is some text\nfor selection");
  2027. CHECK(text_edit->has_selection());
  2028. CHECK(text_edit->get_caret_line() == 0);
  2029. CHECK(text_edit->get_caret_column() == 8);
  2030. CHECK(text_edit->get_selection_origin_line() == 0);
  2031. CHECK(text_edit->get_selection_origin_column() == 4);
  2032. // Redo delete works.
  2033. text_edit->redo();
  2034. CHECK(text_edit->get_text() == "thissome text\nfor selection");
  2035. CHECK_FALSE(text_edit->has_selection());
  2036. CHECK(text_edit->get_caret_line() == 0);
  2037. CHECK(text_edit->get_caret_column() == 4);
  2038. text_edit->undo();
  2039. CHECK(text_edit->has_selection());
  2040. CHECK(text_edit->get_text() == "this is some text\nfor selection");
  2041. CHECK(text_edit->get_caret_line() == 0);
  2042. CHECK(text_edit->get_caret_column() == 8);
  2043. // Can still delete if not editable.
  2044. text_edit->set_editable(false);
  2045. text_edit->delete_selection();
  2046. text_edit->set_editable(false);
  2047. CHECK_FALSE(text_edit->has_selection());
  2048. CHECK(text_edit->get_text() == "thissome text\nfor selection");
  2049. // Cannot undo since it was not editable.
  2050. text_edit->undo();
  2051. CHECK_FALSE(text_edit->has_selection());
  2052. CHECK(text_edit->get_text() == "thissome text\nfor selection");
  2053. // Delete multiple adjacent selections on the same line.
  2054. text_edit->select(0, 0, 0, 5);
  2055. text_edit->add_caret(0, 8);
  2056. text_edit->select(0, 5, 0, 8, 1);
  2057. CHECK(text_edit->get_caret_count() == 2);
  2058. text_edit->delete_selection();
  2059. CHECK(text_edit->get_text() == " text\nfor selection");
  2060. CHECK(text_edit->get_caret_count() == 1);
  2061. CHECK_FALSE(text_edit->has_selection());
  2062. CHECK(text_edit->get_caret_line() == 0);
  2063. CHECK(text_edit->get_caret_column() == 0);
  2064. // Delete mulitline selection. Ignore non selections.
  2065. text_edit->remove_secondary_carets();
  2066. text_edit->select(1, 3, 0, 2);
  2067. text_edit->add_caret(1, 7);
  2068. text_edit->delete_selection();
  2069. CHECK(text_edit->get_text() == " t selection");
  2070. CHECK(text_edit->get_caret_count() == 2);
  2071. CHECK_FALSE(text_edit->has_selection(0));
  2072. CHECK(text_edit->get_caret_line(0) == 0);
  2073. CHECK(text_edit->get_caret_column(0) == 2);
  2074. CHECK_FALSE(text_edit->has_selection(1));
  2075. CHECK(text_edit->get_caret_line(1) == 0);
  2076. CHECK(text_edit->get_caret_column(1) == 6);
  2077. }
  2078. SUBCASE("[TextEdit] text drag") {
  2079. text_edit->set_size(Size2(200, 200));
  2080. text_edit->set_text("drag test\ndrop here ''");
  2081. text_edit->grab_click_focus();
  2082. MessageQueue::get_singleton()->flush();
  2083. // Drag and drop selected text to mouse position.
  2084. text_edit->select(0, 0, 0, 4);
  2085. SEND_GUI_MOUSE_BUTTON_EVENT(text_edit->get_rect_at_line_column(0, 2).get_center() + Point2i(2, 0), MouseButton::LEFT, MouseButtonMask::LEFT, Key::NONE);
  2086. CHECK(text_edit->is_mouse_over_selection());
  2087. SEND_GUI_MOUSE_MOTION_EVENT(text_edit->get_rect_at_line_column(0, 7).get_center() + Point2i(2, 0), MouseButtonMask::LEFT, Key::NONE);
  2088. CHECK(text_edit->get_viewport()->gui_is_dragging());
  2089. CHECK(text_edit->get_viewport()->gui_get_drag_data() == "drag");
  2090. CHECK(text_edit->has_selection());
  2091. CHECK(text_edit->get_caret_line() == 0);
  2092. CHECK(text_edit->get_caret_column() == 4);
  2093. CHECK(text_edit->get_selection_origin_line() == 0);
  2094. CHECK(text_edit->get_selection_origin_column() == 0);
  2095. SEND_GUI_MOUSE_MOTION_EVENT(text_edit->get_rect_at_line_column(1, 11).get_center() + Point2i(2, 0), MouseButtonMask::LEFT, Key::NONE);
  2096. SEND_GUI_MOUSE_BUTTON_RELEASED_EVENT(text_edit->get_rect_at_line_column(1, 11).get_center() + Point2i(2, 0), MouseButton::LEFT, MouseButtonMask::NONE, Key::NONE);
  2097. CHECK_FALSE(text_edit->get_viewport()->gui_is_dragging());
  2098. CHECK(text_edit->get_text() == " test\ndrop here 'drag'");
  2099. CHECK(text_edit->has_selection());
  2100. CHECK(text_edit->get_caret_line() == 1);
  2101. CHECK(text_edit->get_caret_column() == 15);
  2102. CHECK(text_edit->get_selection_origin_line() == 1);
  2103. CHECK(text_edit->get_selection_origin_column() == 11);
  2104. // Undo.
  2105. text_edit->undo();
  2106. CHECK(text_edit->get_text() == "drag test\ndrop here ''");
  2107. CHECK(text_edit->has_selection());
  2108. CHECK(text_edit->get_caret_line() == 0);
  2109. CHECK(text_edit->get_caret_column() == 4);
  2110. CHECK(text_edit->get_selection_origin_line() == 0);
  2111. CHECK(text_edit->get_selection_origin_column() == 0);
  2112. // Redo.
  2113. text_edit->redo();
  2114. CHECK(text_edit->get_text() == " test\ndrop here 'drag'");
  2115. CHECK(text_edit->has_selection());
  2116. CHECK(text_edit->get_caret_line() == 1);
  2117. CHECK(text_edit->get_caret_column() == 15);
  2118. CHECK(text_edit->get_selection_origin_line() == 1);
  2119. CHECK(text_edit->get_selection_origin_column() == 11);
  2120. // Hold control when dropping to not delete selected text.
  2121. text_edit->select(1, 10, 1, 16);
  2122. SEND_GUI_MOUSE_BUTTON_EVENT(text_edit->get_rect_at_line_column(1, 12).get_center() + Point2i(2, 0), MouseButton::LEFT, MouseButtonMask::LEFT, Key::NONE);
  2123. CHECK(text_edit->is_mouse_over_selection());
  2124. SEND_GUI_MOUSE_MOTION_EVENT(text_edit->get_rect_at_line_column(1, 7).get_center() + Point2i(2, 0), MouseButtonMask::LEFT, Key::NONE);
  2125. CHECK(text_edit->get_viewport()->gui_is_dragging());
  2126. CHECK(text_edit->get_viewport()->gui_get_drag_data() == "'drag'");
  2127. CHECK(text_edit->has_selection());
  2128. SEND_GUI_MOUSE_MOTION_EVENT(text_edit->get_rect_at_line_column(0, 0).get_center(), MouseButtonMask::LEFT, Key::NONE);
  2129. SEND_GUI_KEY_EVENT(Key::CMD_OR_CTRL);
  2130. SEND_GUI_MOUSE_BUTTON_RELEASED_EVENT(text_edit->get_rect_at_line_column(0, 0).get_center(), MouseButton::LEFT, MouseButtonMask::NONE, Key::NONE);
  2131. SEND_GUI_KEY_UP_EVENT(Key::CMD_OR_CTRL);
  2132. CHECK_FALSE(text_edit->get_viewport()->gui_is_dragging());
  2133. CHECK(text_edit->get_text() == "'drag' test\ndrop here 'drag'");
  2134. CHECK(text_edit->has_selection());
  2135. CHECK(text_edit->get_caret_line() == 0);
  2136. CHECK(text_edit->get_caret_column() == 6);
  2137. CHECK(text_edit->get_selection_origin_line() == 0);
  2138. CHECK(text_edit->get_selection_origin_column() == 0);
  2139. // Multiple caret drags entire selection.
  2140. text_edit->select(0, 11, 0, 7, 0);
  2141. text_edit->add_caret(1, 2);
  2142. text_edit->select(1, 2, 1, 4, 1);
  2143. text_edit->add_caret(1, 12);
  2144. SEND_GUI_MOUSE_BUTTON_EVENT(text_edit->get_rect_at_line_column(1, 3).get_center() + Point2i(2, 0), MouseButton::LEFT, MouseButtonMask::LEFT, Key::NONE);
  2145. CHECK(text_edit->is_mouse_over_selection(true, 1));
  2146. SEND_GUI_MOUSE_MOTION_EVENT(text_edit->get_rect_at_line_column(1, 12).get_center() + Point2i(2, 0), MouseButtonMask::LEFT, Key::NONE);
  2147. CHECK(text_edit->get_viewport()->gui_is_dragging());
  2148. CHECK(text_edit->get_viewport()->gui_get_drag_data() == "test\nop");
  2149. // Carets aren't removed from dragging, only dropping.
  2150. CHECK(text_edit->get_caret_count() == 3);
  2151. CHECK(text_edit->has_selection(0));
  2152. CHECK(text_edit->get_caret_line(0) == 0);
  2153. CHECK(text_edit->get_caret_column(0) == 7);
  2154. CHECK(text_edit->get_selection_origin_line(0) == 0);
  2155. CHECK(text_edit->get_selection_origin_column(0) == 11);
  2156. CHECK(text_edit->has_selection(1));
  2157. CHECK(text_edit->get_caret_line(1) == 1);
  2158. CHECK(text_edit->get_caret_column(1) == 4);
  2159. CHECK(text_edit->get_selection_origin_line(1) == 1);
  2160. CHECK(text_edit->get_selection_origin_column(1) == 2);
  2161. CHECK_FALSE(text_edit->has_selection(2));
  2162. CHECK(text_edit->get_caret_line(2) == 1);
  2163. CHECK(text_edit->get_caret_column(2) == 12);
  2164. SEND_GUI_MOUSE_MOTION_EVENT(text_edit->get_rect_at_line_column(1, 9).get_center() + Point2i(2, 0), MouseButtonMask::LEFT, Key::NONE);
  2165. SEND_GUI_MOUSE_BUTTON_RELEASED_EVENT(text_edit->get_rect_at_line_column(1, 9).get_center() + Point2i(2, 0), MouseButton::LEFT, MouseButtonMask::NONE, Key::NONE);
  2166. CHECK_FALSE(text_edit->get_viewport()->gui_is_dragging());
  2167. CHECK(text_edit->get_text() == "'drag' \ndr heretest\nop 'drag'");
  2168. CHECK(text_edit->get_caret_count() == 1);
  2169. CHECK(text_edit->has_selection());
  2170. CHECK(text_edit->get_caret_line() == 2);
  2171. CHECK(text_edit->get_caret_column() == 2);
  2172. CHECK(text_edit->get_selection_origin_line() == 1);
  2173. CHECK(text_edit->get_selection_origin_column() == 7);
  2174. // Drop onto same selection should do effectively nothing.
  2175. text_edit->select(1, 3, 1, 7);
  2176. SEND_GUI_MOUSE_BUTTON_EVENT(text_edit->get_rect_at_line_column(1, 6).get_center() + Point2i(2, 0), MouseButton::LEFT, MouseButtonMask::LEFT, Key::NONE);
  2177. CHECK(text_edit->is_mouse_over_selection());
  2178. SEND_GUI_MOUSE_MOTION_EVENT(text_edit->get_rect_at_line_column(0, 1).get_center() + Point2i(2, 0), MouseButtonMask::LEFT, Key::NONE);
  2179. CHECK(text_edit->get_viewport()->gui_is_dragging());
  2180. CHECK(text_edit->get_viewport()->gui_get_drag_data() == "here");
  2181. SEND_GUI_MOUSE_BUTTON_RELEASED_EVENT(text_edit->get_rect_at_line_column(1, 7).get_center() + Point2i(2, 0), MouseButton::LEFT, MouseButtonMask::NONE, Key::NONE);
  2182. CHECK_FALSE(text_edit->get_viewport()->gui_is_dragging());
  2183. CHECK(text_edit->get_text() == "'drag' \ndr heretest\nop 'drag'");
  2184. CHECK(text_edit->get_caret_count() == 1);
  2185. CHECK(text_edit->has_selection());
  2186. CHECK(text_edit->get_caret_line() == 1);
  2187. CHECK(text_edit->get_caret_column() == 7);
  2188. CHECK(text_edit->get_selection_origin_line() == 1);
  2189. CHECK(text_edit->get_selection_origin_column() == 3);
  2190. // Cannot drag when drag and drop selection is disabled. It becomes regular drag to select.
  2191. text_edit->set_drag_and_drop_selection_enabled(false);
  2192. text_edit->select(0, 1, 0, 5);
  2193. SEND_GUI_MOUSE_BUTTON_EVENT(text_edit->get_rect_at_line_column(0, 2).get_center() + Point2i(2, 0), MouseButton::LEFT, MouseButtonMask::LEFT, Key::NONE);
  2194. CHECK_FALSE(text_edit->is_mouse_over_selection());
  2195. SEND_GUI_MOUSE_MOTION_EVENT(text_edit->get_rect_at_line_column(1, 7).get_center() + Point2i(2, 0), MouseButtonMask::LEFT, Key::NONE);
  2196. CHECK_FALSE(text_edit->get_viewport()->gui_is_dragging());
  2197. SEND_GUI_MOUSE_BUTTON_RELEASED_EVENT(text_edit->get_rect_at_line_column(1, 7).get_center() + Point2i(2, 0), MouseButton::LEFT, MouseButtonMask::NONE, Key::NONE);
  2198. CHECK_FALSE(text_edit->get_viewport()->gui_is_dragging());
  2199. CHECK(text_edit->get_text() == "'drag' \ndr heretest\nop 'drag'");
  2200. CHECK(text_edit->has_selection());
  2201. CHECK(text_edit->get_caret_line() == 1);
  2202. CHECK(text_edit->get_caret_column() == 7);
  2203. CHECK(text_edit->get_selection_origin_line() == 0);
  2204. CHECK(text_edit->get_selection_origin_column() == 2);
  2205. text_edit->set_drag_and_drop_selection_enabled(true);
  2206. // Cancel drag and drop from Escape key.
  2207. text_edit->select(0, 1, 0, 5);
  2208. SEND_GUI_MOUSE_BUTTON_EVENT(text_edit->get_rect_at_line_column(0, 3).get_center() + Point2i(2, 0), MouseButton::LEFT, MouseButtonMask::LEFT, Key::NONE);
  2209. CHECK(text_edit->is_mouse_over_selection());
  2210. SEND_GUI_MOUSE_MOTION_EVENT(text_edit->get_rect_at_line_column(0, 1).get_center() + Point2i(2, 0), MouseButtonMask::LEFT, Key::NONE);
  2211. CHECK(text_edit->get_viewport()->gui_is_dragging());
  2212. CHECK(text_edit->get_viewport()->gui_get_drag_data() == "drag");
  2213. SEND_GUI_KEY_EVENT(Key::ESCAPE);
  2214. CHECK_FALSE(text_edit->get_viewport()->gui_is_dragging());
  2215. CHECK(text_edit->get_text() == "'drag' \ndr heretest\nop 'drag'");
  2216. CHECK(text_edit->has_selection());
  2217. CHECK(text_edit->get_caret_line() == 0);
  2218. CHECK(text_edit->get_caret_column() == 5);
  2219. CHECK(text_edit->get_selection_origin_line() == 0);
  2220. CHECK(text_edit->get_selection_origin_column() == 1);
  2221. // Cancel drag and drop from caret move key input.
  2222. text_edit->select(0, 1, 0, 5);
  2223. SEND_GUI_MOUSE_BUTTON_EVENT(text_edit->get_rect_at_line_column(0, 3).get_center() + Point2i(2, 0), MouseButton::LEFT, MouseButtonMask::LEFT, Key::NONE);
  2224. CHECK(text_edit->is_mouse_over_selection());
  2225. SEND_GUI_MOUSE_MOTION_EVENT(text_edit->get_rect_at_line_column(0, 1).get_center() + Point2i(2, 0), MouseButtonMask::LEFT, Key::NONE);
  2226. CHECK(text_edit->get_viewport()->gui_is_dragging());
  2227. CHECK(text_edit->get_viewport()->gui_get_drag_data() == "drag");
  2228. SEND_GUI_KEY_EVENT(Key::RIGHT);
  2229. CHECK_FALSE(text_edit->get_viewport()->gui_is_dragging());
  2230. CHECK(text_edit->get_text() == "'drag' \ndr heretest\nop 'drag'");
  2231. CHECK_FALSE(text_edit->has_selection());
  2232. CHECK(text_edit->get_caret_line() == 0);
  2233. CHECK(text_edit->get_caret_column() == 5);
  2234. // Cancel drag and drop from text key input.
  2235. text_edit->select(0, 1, 0, 5);
  2236. SEND_GUI_MOUSE_BUTTON_EVENT(text_edit->get_rect_at_line_column(0, 3).get_center() + Point2i(2, 0), MouseButton::LEFT, MouseButtonMask::LEFT, Key::NONE);
  2237. CHECK(text_edit->is_mouse_over_selection());
  2238. SEND_GUI_MOUSE_MOTION_EVENT(text_edit->get_rect_at_line_column(0, 1).get_center() + Point2i(2, 0), MouseButtonMask::LEFT, Key::NONE);
  2239. CHECK(text_edit->get_viewport()->gui_is_dragging());
  2240. CHECK(text_edit->get_viewport()->gui_get_drag_data() == "drag");
  2241. SEND_GUI_KEY_EVENT(Key::A);
  2242. CHECK_FALSE(text_edit->get_viewport()->gui_is_dragging());
  2243. CHECK(text_edit->get_text() == "'A' \ndr heretest\nop 'drag'");
  2244. CHECK_FALSE(text_edit->has_selection());
  2245. CHECK(text_edit->get_caret_line() == 0);
  2246. CHECK(text_edit->get_caret_column() == 2);
  2247. }
  2248. SUBCASE("[TextEdit] text drag to another text edit") {
  2249. TextEdit *target_text_edit = memnew(TextEdit);
  2250. SceneTree::get_singleton()->get_root()->add_child(target_text_edit);
  2251. target_text_edit->set_size(Size2(200, 200));
  2252. target_text_edit->set_position(Point2(400, 0));
  2253. text_edit->set_size(Size2(200, 200));
  2254. CHECK_FALSE(text_edit->is_mouse_over_selection());
  2255. text_edit->set_text("drag me");
  2256. text_edit->select_all();
  2257. text_edit->grab_click_focus();
  2258. CHECK(text_edit->has_selection());
  2259. CHECK(text_edit->get_caret_line() == 0);
  2260. CHECK(text_edit->get_caret_column() == 7);
  2261. CHECK(text_edit->get_selection_origin_line() == 0);
  2262. CHECK(text_edit->get_selection_origin_column() == 0);
  2263. MessageQueue::get_singleton()->flush();
  2264. // Drag text between text edits.
  2265. SEND_GUI_MOUSE_BUTTON_EVENT(text_edit->get_rect_at_line_column(0, 0).get_center(), MouseButton::LEFT, MouseButtonMask::LEFT, Key::NONE);
  2266. CHECK(text_edit->is_mouse_over_selection());
  2267. SEND_GUI_MOUSE_MOTION_EVENT(text_edit->get_rect_at_line_column(0, 7).get_center(), MouseButtonMask::LEFT, Key::NONE);
  2268. CHECK(text_edit->get_viewport()->gui_is_dragging());
  2269. CHECK(text_edit->get_viewport()->gui_get_drag_data() == "drag me");
  2270. CHECK(text_edit->has_selection());
  2271. CHECK(text_edit->get_caret_line() == 0);
  2272. CHECK(text_edit->get_caret_column() == 7);
  2273. CHECK(text_edit->get_selection_origin_line() == 0);
  2274. CHECK(text_edit->get_selection_origin_column() == 0);
  2275. Point2i target_line0 = target_text_edit->get_position() + Point2i(1, target_text_edit->get_line_height() / 2);
  2276. SEND_GUI_MOUSE_MOTION_EVENT(target_line0, MouseButtonMask::LEFT, Key::NONE);
  2277. CHECK(text_edit->get_viewport()->gui_is_dragging());
  2278. CHECK(target_text_edit->get_caret_line() == 0);
  2279. CHECK(target_text_edit->get_caret_column() == 0);
  2280. SEND_GUI_MOUSE_BUTTON_RELEASED_EVENT(target_line0, MouseButton::LEFT, MouseButtonMask::NONE, Key::NONE);
  2281. CHECK_FALSE(text_edit->get_viewport()->gui_is_dragging());
  2282. CHECK(text_edit->get_text() == "");
  2283. CHECK_FALSE(text_edit->has_selection());
  2284. CHECK(text_edit->get_caret_line() == 0);
  2285. CHECK(text_edit->get_caret_column() == 0);
  2286. CHECK(target_text_edit->get_text() == "drag me");
  2287. CHECK(target_text_edit->has_selection());
  2288. CHECK(target_text_edit->get_caret_line() == 0);
  2289. CHECK(target_text_edit->get_caret_column() == 7);
  2290. CHECK(target_text_edit->get_selection_origin_line() == 0);
  2291. CHECK(target_text_edit->get_selection_origin_column() == 0);
  2292. // Undo is separate per TextEdit.
  2293. text_edit->undo();
  2294. CHECK(text_edit->get_text() == "drag me");
  2295. CHECK(text_edit->has_selection());
  2296. CHECK(text_edit->get_caret_line() == 0);
  2297. CHECK(text_edit->get_caret_column() == 7);
  2298. CHECK(text_edit->get_selection_origin_line() == 0);
  2299. CHECK(text_edit->get_selection_origin_column() == 0);
  2300. CHECK(target_text_edit->get_text() == "drag me");
  2301. CHECK(target_text_edit->has_selection());
  2302. CHECK(target_text_edit->get_caret_line() == 0);
  2303. CHECK(target_text_edit->get_caret_column() == 7);
  2304. CHECK(target_text_edit->get_selection_origin_line() == 0);
  2305. CHECK(target_text_edit->get_selection_origin_column() == 0);
  2306. target_text_edit->undo();
  2307. CHECK(text_edit->get_text() == "drag me");
  2308. CHECK(text_edit->has_selection());
  2309. CHECK(text_edit->get_caret_line() == 0);
  2310. CHECK(text_edit->get_caret_column() == 7);
  2311. CHECK(text_edit->get_selection_origin_line() == 0);
  2312. CHECK(text_edit->get_selection_origin_column() == 0);
  2313. CHECK(target_text_edit->get_text() == "");
  2314. CHECK_FALSE(target_text_edit->has_selection());
  2315. CHECK(target_text_edit->get_caret_line() == 0);
  2316. CHECK(target_text_edit->get_caret_column() == 0);
  2317. // Redo is also separate.
  2318. text_edit->redo();
  2319. CHECK(text_edit->get_text() == "");
  2320. CHECK_FALSE(text_edit->has_selection());
  2321. CHECK(text_edit->get_caret_line() == 0);
  2322. CHECK(text_edit->get_caret_column() == 0);
  2323. CHECK(target_text_edit->get_text() == "");
  2324. CHECK_FALSE(target_text_edit->has_selection());
  2325. CHECK(target_text_edit->get_caret_line() == 0);
  2326. CHECK(target_text_edit->get_caret_column() == 0);
  2327. target_text_edit->redo();
  2328. CHECK(text_edit->get_text() == "");
  2329. CHECK_FALSE(text_edit->has_selection());
  2330. CHECK(text_edit->get_caret_line() == 0);
  2331. CHECK(text_edit->get_caret_column() == 0);
  2332. CHECK(target_text_edit->get_text() == "drag me");
  2333. CHECK(target_text_edit->has_selection());
  2334. CHECK(target_text_edit->get_caret_line() == 0);
  2335. CHECK(target_text_edit->get_caret_column() == 7);
  2336. CHECK(target_text_edit->get_selection_origin_line() == 0);
  2337. CHECK(target_text_edit->get_selection_origin_column() == 0);
  2338. // Hold control to not remove selected text.
  2339. text_edit->set_text("drag test\ndrop test");
  2340. MessageQueue::get_singleton()->flush();
  2341. target_text_edit->select(0, 0, 0, 3, 0);
  2342. target_text_edit->add_caret(0, 5);
  2343. text_edit->select(0, 5, 0, 7, 0);
  2344. text_edit->add_caret(0, 1);
  2345. text_edit->select(0, 1, 0, 0, 1);
  2346. SEND_GUI_MOUSE_BUTTON_EVENT(text_edit->get_rect_at_line_column(0, 5).get_center() + Point2i(2, 0), MouseButton::LEFT, MouseButtonMask::LEFT, Key::NONE);
  2347. CHECK(text_edit->is_mouse_over_selection(true, 0));
  2348. SEND_GUI_MOUSE_MOTION_EVENT(text_edit->get_rect_at_line_column(1, 6).get_center(), MouseButtonMask::LEFT, Key::NONE);
  2349. CHECK(text_edit->get_viewport()->gui_is_dragging());
  2350. CHECK(text_edit->get_viewport()->gui_get_drag_data() == "d\nte");
  2351. CHECK(text_edit->has_selection());
  2352. SEND_GUI_KEY_EVENT(Key::CMD_OR_CTRL);
  2353. SEND_GUI_MOUSE_MOTION_EVENT(target_text_edit->get_position() + target_text_edit->get_rect_at_line_column(0, 6).get_center() + Point2i(2, 0), MouseButtonMask::LEFT, Key::NONE);
  2354. SEND_GUI_MOUSE_BUTTON_RELEASED_EVENT(target_text_edit->get_position() + target_text_edit->get_rect_at_line_column(0, 6).get_center() + Point2i(2, 0), MouseButton::LEFT, MouseButtonMask::NONE, Key::NONE);
  2355. SEND_GUI_KEY_UP_EVENT(Key::CMD_OR_CTRL);
  2356. CHECK_FALSE(text_edit->get_viewport()->gui_is_dragging());
  2357. CHECK(text_edit->get_text() == "drag test\ndrop test");
  2358. CHECK(text_edit->get_caret_count() == 2);
  2359. CHECK_FALSE(text_edit->has_selection());
  2360. CHECK(text_edit->get_caret_line(0) == 0);
  2361. CHECK(text_edit->get_caret_column(0) == 7);
  2362. CHECK(text_edit->get_caret_line(1) == 0);
  2363. CHECK(text_edit->get_caret_column(1) == 0);
  2364. CHECK(target_text_edit->get_text() == "drag md\ntee");
  2365. CHECK(target_text_edit->get_caret_count() == 1);
  2366. CHECK(target_text_edit->has_selection());
  2367. CHECK(target_text_edit->get_caret_line() == 1);
  2368. CHECK(target_text_edit->get_caret_column() == 2);
  2369. CHECK(target_text_edit->get_selection_origin_line() == 0);
  2370. CHECK(target_text_edit->get_selection_origin_column() == 6);
  2371. // Drop onto selected text deletes the selected text first.
  2372. text_edit->set_deselect_on_focus_loss_enabled(false);
  2373. target_text_edit->set_deselect_on_focus_loss_enabled(false);
  2374. text_edit->remove_secondary_carets();
  2375. text_edit->select(0, 5, 0, 9);
  2376. target_text_edit->select(0, 6, 0, 8);
  2377. SEND_GUI_MOUSE_BUTTON_EVENT(text_edit->get_rect_at_line_column(0, 6).get_center() + Point2i(2, 0), MouseButton::LEFT, MouseButtonMask::LEFT, Key::NONE);
  2378. CHECK(text_edit->is_mouse_over_selection(true, 0));
  2379. SEND_GUI_MOUSE_MOTION_EVENT(text_edit->get_rect_at_line_column(1, 7).get_center(), MouseButtonMask::LEFT, Key::NONE);
  2380. CHECK(text_edit->get_viewport()->gui_is_dragging());
  2381. CHECK(text_edit->get_viewport()->gui_get_drag_data() == "test");
  2382. CHECK(text_edit->has_selection());
  2383. SEND_GUI_MOUSE_MOTION_EVENT(target_text_edit->get_position() + target_text_edit->get_rect_at_line_column(0, 7).get_center() + Point2i(2, 0), MouseButtonMask::LEFT, Key::NONE);
  2384. SEND_GUI_MOUSE_BUTTON_RELEASED_EVENT(target_text_edit->get_position() + target_text_edit->get_rect_at_line_column(0, 7).get_center() + Point2i(2, 0), MouseButton::LEFT, MouseButtonMask::NONE, Key::NONE);
  2385. CHECK_FALSE(text_edit->get_viewport()->gui_is_dragging());
  2386. CHECK(text_edit->get_text() == "drag \ndrop test");
  2387. CHECK(target_text_edit->get_caret_count() == 1);
  2388. CHECK_FALSE(text_edit->has_selection());
  2389. CHECK(text_edit->get_caret_line() == 0);
  2390. CHECK(text_edit->get_caret_column() == 5);
  2391. CHECK(target_text_edit->get_text() == "drag mdtest\ntee");
  2392. CHECK(target_text_edit->has_selection());
  2393. CHECK(target_text_edit->get_caret_line() == 0);
  2394. CHECK(target_text_edit->get_caret_column() == 11);
  2395. CHECK(target_text_edit->get_selection_origin_line() == 0);
  2396. CHECK(target_text_edit->get_selection_origin_column() == 7);
  2397. text_edit->set_deselect_on_focus_loss_enabled(true);
  2398. target_text_edit->set_deselect_on_focus_loss_enabled(true);
  2399. // Can drop even when drag and drop selection is disabled.
  2400. target_text_edit->set_drag_and_drop_selection_enabled(false);
  2401. text_edit->select(0, 4, 0, 5);
  2402. target_text_edit->deselect();
  2403. SEND_GUI_MOUSE_BUTTON_EVENT(text_edit->get_rect_at_line_column(0, 4).get_center() + Point2i(2, 0), MouseButton::LEFT, MouseButtonMask::LEFT, Key::NONE);
  2404. CHECK(text_edit->is_mouse_over_selection());
  2405. SEND_GUI_MOUSE_MOTION_EVENT(text_edit->get_rect_at_line_column(1, 7).get_center() + Point2i(2, 0), MouseButtonMask::LEFT, Key::NONE);
  2406. CHECK(text_edit->get_viewport()->gui_is_dragging());
  2407. CHECK(text_edit->get_viewport()->gui_get_drag_data() == " ");
  2408. CHECK(text_edit->has_selection());
  2409. SEND_GUI_MOUSE_MOTION_EVENT(target_text_edit->get_position() + target_text_edit->get_rect_at_line_column(0, 2).get_center() + Point2i(2, 0), MouseButtonMask::LEFT, Key::NONE);
  2410. SEND_GUI_MOUSE_BUTTON_RELEASED_EVENT(target_text_edit->get_position() + target_text_edit->get_rect_at_line_column(0, 7).get_center() + Point2i(2, 0), MouseButton::LEFT, MouseButtonMask::NONE, Key::NONE);
  2411. CHECK_FALSE(text_edit->get_viewport()->gui_is_dragging());
  2412. CHECK(text_edit->get_text() == "drag\ndrop test");
  2413. CHECK(target_text_edit->get_text() == "drag md test\ntee");
  2414. CHECK_FALSE(text_edit->has_selection());
  2415. CHECK(text_edit->get_caret_line() == 0);
  2416. CHECK(text_edit->get_caret_column() == 4);
  2417. CHECK(target_text_edit->has_selection());
  2418. CHECK(target_text_edit->get_caret_line() == 0);
  2419. CHECK(target_text_edit->get_caret_column() == 8);
  2420. CHECK(target_text_edit->get_selection_origin_line() == 0);
  2421. CHECK(target_text_edit->get_selection_origin_column() == 7);
  2422. target_text_edit->set_drag_and_drop_selection_enabled(true);
  2423. // Cannot drop when not editable.
  2424. target_text_edit->set_editable(false);
  2425. text_edit->select(0, 1, 0, 4);
  2426. target_text_edit->deselect();
  2427. SEND_GUI_MOUSE_BUTTON_EVENT(text_edit->get_rect_at_line_column(0, 2).get_center() + Point2i(2, 0), MouseButton::LEFT, MouseButtonMask::LEFT, Key::NONE);
  2428. CHECK(text_edit->is_mouse_over_selection());
  2429. SEND_GUI_MOUSE_MOTION_EVENT(text_edit->get_rect_at_line_column(1, 7).get_center() + Point2i(2, 0), MouseButtonMask::LEFT, Key::NONE);
  2430. CHECK(text_edit->get_viewport()->gui_is_dragging());
  2431. CHECK(text_edit->get_viewport()->gui_get_drag_data() == "rag");
  2432. CHECK(text_edit->has_selection());
  2433. SEND_GUI_MOUSE_MOTION_EVENT(target_text_edit->get_position() + target_text_edit->get_rect_at_line_column(0, 2).get_center() + Point2i(2, 0), MouseButtonMask::LEFT, Key::NONE);
  2434. SEND_GUI_MOUSE_BUTTON_RELEASED_EVENT(target_text_edit->get_position() + target_text_edit->get_rect_at_line_column(0, 2).get_center() + Point2i(2, 0), MouseButton::LEFT, MouseButtonMask::NONE, Key::NONE);
  2435. CHECK_FALSE(text_edit->get_viewport()->gui_is_dragging());
  2436. CHECK(text_edit->get_text() == "drag\ndrop test");
  2437. CHECK(target_text_edit->get_text() == "drag md test\ntee");
  2438. CHECK(text_edit->has_selection());
  2439. CHECK_FALSE(target_text_edit->has_selection());
  2440. target_text_edit->set_editable(true);
  2441. // Can drag when not editable, but text will not be removed.
  2442. text_edit->set_editable(false);
  2443. text_edit->select(0, 0, 0, 4);
  2444. SEND_GUI_MOUSE_BUTTON_EVENT(text_edit->get_rect_at_line_column(0, 2).get_center() + Point2i(2, 0), MouseButton::LEFT, MouseButtonMask::LEFT, Key::NONE);
  2445. CHECK(text_edit->is_mouse_over_selection());
  2446. SEND_GUI_MOUSE_MOTION_EVENT(text_edit->get_rect_at_line_column(1, 7).get_center() + Point2i(2, 0), MouseButtonMask::LEFT, Key::NONE);
  2447. CHECK(text_edit->get_viewport()->gui_is_dragging());
  2448. CHECK(text_edit->get_viewport()->gui_get_drag_data() == "drag");
  2449. CHECK(text_edit->has_selection());
  2450. SEND_GUI_MOUSE_MOTION_EVENT(target_text_edit->get_position() + target_text_edit->get_rect_at_line_column(0, 4).get_center() + Point2i(2, 0), MouseButtonMask::LEFT, Key::NONE);
  2451. SEND_GUI_MOUSE_BUTTON_RELEASED_EVENT(target_text_edit->get_position() + target_text_edit->get_rect_at_line_column(0, 4).get_center() + Point2i(2, 0), MouseButton::LEFT, MouseButtonMask::NONE, Key::NONE);
  2452. CHECK_FALSE(text_edit->get_viewport()->gui_is_dragging());
  2453. CHECK(text_edit->get_text() == "drag\ndrop test");
  2454. CHECK(target_text_edit->get_text() == "dragdrag md test\ntee");
  2455. CHECK_FALSE(text_edit->has_selection());
  2456. CHECK(text_edit->get_caret_line() == 0);
  2457. CHECK(text_edit->get_caret_column() == 4);
  2458. CHECK(target_text_edit->has_selection());
  2459. CHECK(target_text_edit->get_caret_line() == 0);
  2460. CHECK(target_text_edit->get_caret_column() == 8);
  2461. CHECK(target_text_edit->get_selection_origin_line() == 0);
  2462. CHECK(target_text_edit->get_selection_origin_column() == 4);
  2463. text_edit->set_editable(true);
  2464. memdelete(target_text_edit);
  2465. }
  2466. SIGNAL_UNWATCH(text_edit, "text_set");
  2467. SIGNAL_UNWATCH(text_edit, "text_changed");
  2468. SIGNAL_UNWATCH(text_edit, "lines_edited_from");
  2469. SIGNAL_UNWATCH(text_edit, "caret_changed");
  2470. }
  2471. SUBCASE("[TextEdit] overridable actions") {
  2472. DisplayServerMock *DS = (DisplayServerMock *)(DisplayServer::get_singleton());
  2473. SIGNAL_WATCH(text_edit, "text_set");
  2474. SIGNAL_WATCH(text_edit, "text_changed");
  2475. SIGNAL_WATCH(text_edit, "lines_edited_from");
  2476. SIGNAL_WATCH(text_edit, "caret_changed");
  2477. Array lines_edited_args = build_array(build_array(0, 0));
  2478. SUBCASE("[TextEdit] backspace") {
  2479. text_edit->set_text("this is\nsome\n");
  2480. text_edit->set_caret_line(0);
  2481. text_edit->set_caret_column(0);
  2482. MessageQueue::get_singleton()->flush();
  2483. SIGNAL_DISCARD("text_set");
  2484. SIGNAL_DISCARD("text_changed");
  2485. SIGNAL_DISCARD("lines_edited_from");
  2486. SIGNAL_DISCARD("caret_changed");
  2487. // Cannot backspace at start of text.
  2488. text_edit->backspace();
  2489. MessageQueue::get_singleton()->flush();
  2490. SIGNAL_CHECK_FALSE("text_changed");
  2491. SIGNAL_CHECK_FALSE("caret_changed");
  2492. SIGNAL_CHECK_FALSE("lines_edited_from");
  2493. // Backspace at start of line removes the line.
  2494. text_edit->set_caret_line(2);
  2495. text_edit->set_caret_column(0);
  2496. MessageQueue::get_singleton()->flush();
  2497. SIGNAL_DISCARD("caret_changed");
  2498. lines_edited_args = build_array(build_array(2, 1));
  2499. text_edit->backspace();
  2500. MessageQueue::get_singleton()->flush();
  2501. CHECK(text_edit->get_text() == "this is\nsome");
  2502. CHECK(text_edit->get_caret_line() == 1);
  2503. CHECK(text_edit->get_caret_column() == 4);
  2504. SIGNAL_CHECK("caret_changed", empty_signal_args);
  2505. SIGNAL_CHECK("text_changed", empty_signal_args);
  2506. SIGNAL_CHECK("lines_edited_from", lines_edited_args);
  2507. // Backspace removes a character.
  2508. lines_edited_args = build_array(build_array(1, 1));
  2509. text_edit->backspace();
  2510. MessageQueue::get_singleton()->flush();
  2511. CHECK(text_edit->get_text() == "this is\nsom");
  2512. CHECK(text_edit->get_caret_line() == 1);
  2513. CHECK(text_edit->get_caret_column() == 3);
  2514. SIGNAL_CHECK("caret_changed", empty_signal_args);
  2515. SIGNAL_CHECK("text_changed", empty_signal_args);
  2516. SIGNAL_CHECK("lines_edited_from", lines_edited_args);
  2517. // Backspace when text is selected removes the selection.
  2518. text_edit->end_complex_operation();
  2519. text_edit->select(1, 0, 1, 3);
  2520. text_edit->backspace();
  2521. MessageQueue::get_singleton()->flush();
  2522. CHECK(text_edit->get_text() == "this is\n");
  2523. CHECK(text_edit->get_caret_line() == 1);
  2524. CHECK(text_edit->get_caret_column() == 0);
  2525. SIGNAL_CHECK("caret_changed", empty_signal_args);
  2526. SIGNAL_CHECK("text_changed", empty_signal_args);
  2527. SIGNAL_CHECK("lines_edited_from", lines_edited_args);
  2528. // Cannot backspace if not editable.
  2529. text_edit->set_editable(false);
  2530. text_edit->backspace();
  2531. text_edit->set_editable(true);
  2532. MessageQueue::get_singleton()->flush();
  2533. CHECK(text_edit->get_text() == "this is\n");
  2534. CHECK(text_edit->get_caret_line() == 1);
  2535. CHECK(text_edit->get_caret_column() == 0);
  2536. SIGNAL_CHECK_FALSE("text_changed");
  2537. SIGNAL_CHECK_FALSE("caret_changed");
  2538. SIGNAL_CHECK_FALSE("lines_edited_from");
  2539. // Undo restores text to the previous end of complex operation.
  2540. text_edit->undo();
  2541. MessageQueue::get_singleton()->flush();
  2542. CHECK(text_edit->get_text() == "this is\nsom");
  2543. CHECK(text_edit->get_caret_line() == 1);
  2544. CHECK(text_edit->get_caret_column() == 3);
  2545. SIGNAL_CHECK("caret_changed", empty_signal_args);
  2546. SIGNAL_CHECK("text_changed", empty_signal_args);
  2547. SIGNAL_CHECK("lines_edited_from", lines_edited_args);
  2548. // Redo.
  2549. text_edit->redo();
  2550. MessageQueue::get_singleton()->flush();
  2551. CHECK(text_edit->get_text() == "this is\n");
  2552. CHECK(text_edit->get_caret_line() == 1);
  2553. CHECK(text_edit->get_caret_column() == 0);
  2554. SIGNAL_CHECK("caret_changed", empty_signal_args);
  2555. SIGNAL_CHECK("text_changed", empty_signal_args);
  2556. SIGNAL_CHECK("lines_edited_from", lines_edited_args);
  2557. // See ui_text_backspace for more backspace tests.
  2558. }
  2559. SUBCASE("[TextEdit] cut") {
  2560. // Cut without a selection removes the entire line.
  2561. text_edit->set_text("this is\nsome\n");
  2562. text_edit->set_caret_line(0);
  2563. text_edit->set_caret_column(6);
  2564. MessageQueue::get_singleton()->flush();
  2565. SIGNAL_DISCARD("text_set");
  2566. SIGNAL_DISCARD("text_changed");
  2567. SIGNAL_DISCARD("lines_edited_from");
  2568. SIGNAL_DISCARD("caret_changed");
  2569. lines_edited_args = build_array(build_array(1, 0));
  2570. text_edit->cut();
  2571. MessageQueue::get_singleton()->flush();
  2572. CHECK(DS->clipboard_get() == "this is\n");
  2573. CHECK(text_edit->get_text() == "some\n");
  2574. CHECK(text_edit->get_caret_line() == 0);
  2575. CHECK(text_edit->get_caret_column() == 3); // In the default font, this is the same position.
  2576. SIGNAL_CHECK("caret_changed", empty_signal_args);
  2577. SIGNAL_CHECK("text_changed", empty_signal_args);
  2578. SIGNAL_CHECK("lines_edited_from", lines_edited_args);
  2579. // Undo restores the cut text.
  2580. text_edit->undo();
  2581. MessageQueue::get_singleton()->flush();
  2582. CHECK(DS->clipboard_get() == "this is\n");
  2583. CHECK(text_edit->get_text() == "this is\nsome\n");
  2584. CHECK(text_edit->get_caret_line() == 0);
  2585. CHECK(text_edit->get_caret_column() == 6);
  2586. SIGNAL_CHECK("caret_changed", empty_signal_args);
  2587. SIGNAL_CHECK("text_changed", empty_signal_args);
  2588. SIGNAL_CHECK("lines_edited_from", reverse_nested(lines_edited_args));
  2589. // Redo.
  2590. text_edit->redo();
  2591. MessageQueue::get_singleton()->flush();
  2592. CHECK(DS->clipboard_get() == "this is\n");
  2593. CHECK(text_edit->get_text() == "some\n");
  2594. CHECK(text_edit->get_caret_line() == 0);
  2595. CHECK(text_edit->get_caret_column() == 3);
  2596. SIGNAL_CHECK("caret_changed", empty_signal_args);
  2597. SIGNAL_CHECK("text_changed", empty_signal_args);
  2598. SIGNAL_CHECK("lines_edited_from", lines_edited_args);
  2599. // Cut with a selection removes just the selection.
  2600. text_edit->set_text("this is\nsome\n");
  2601. text_edit->select(0, 5, 0, 7);
  2602. MessageQueue::get_singleton()->flush();
  2603. SIGNAL_DISCARD("text_set");
  2604. SIGNAL_DISCARD("text_changed");
  2605. SIGNAL_DISCARD("lines_edited_from");
  2606. SIGNAL_DISCARD("caret_changed");
  2607. lines_edited_args = build_array(build_array(0, 0));
  2608. SEND_GUI_ACTION("ui_cut");
  2609. CHECK(text_edit->get_viewport()->is_input_handled());
  2610. MessageQueue::get_singleton()->flush();
  2611. CHECK(DS->clipboard_get() == "is");
  2612. CHECK(text_edit->get_text() == "this \nsome\n");
  2613. CHECK_FALSE(text_edit->get_caret_line());
  2614. CHECK(text_edit->get_caret_line() == 0);
  2615. CHECK(text_edit->get_caret_column() == 5);
  2616. SIGNAL_CHECK("caret_changed", empty_signal_args);
  2617. SIGNAL_CHECK("text_changed", empty_signal_args);
  2618. SIGNAL_CHECK("lines_edited_from", lines_edited_args);
  2619. // Cut does not change the text if not editable. Text is still added to clipboard.
  2620. text_edit->set_text("this is\nsome\n");
  2621. text_edit->set_caret_line(0);
  2622. text_edit->set_caret_column(5);
  2623. MessageQueue::get_singleton()->flush();
  2624. SIGNAL_DISCARD("text_set");
  2625. SIGNAL_DISCARD("text_changed");
  2626. SIGNAL_DISCARD("lines_edited_from");
  2627. SIGNAL_DISCARD("caret_changed");
  2628. text_edit->set_editable(false);
  2629. text_edit->cut();
  2630. MessageQueue::get_singleton()->flush();
  2631. text_edit->set_editable(true);
  2632. CHECK(DS->clipboard_get() == "this is\n");
  2633. CHECK(text_edit->get_text() == "this is\nsome\n");
  2634. CHECK(text_edit->get_caret_line() == 0);
  2635. CHECK(text_edit->get_caret_column() == 5);
  2636. SIGNAL_CHECK_FALSE("caret_changed");
  2637. SIGNAL_CHECK_FALSE("text_changed");
  2638. SIGNAL_CHECK_FALSE("lines_edited_from");
  2639. // Cut line with multiple carets.
  2640. text_edit->set_text("this is\nsome\n");
  2641. text_edit->set_caret_line(0);
  2642. text_edit->set_caret_column(3);
  2643. text_edit->add_caret(0, 2);
  2644. text_edit->add_caret(0, 4);
  2645. text_edit->add_caret(2, 0);
  2646. MessageQueue::get_singleton()->flush();
  2647. SIGNAL_DISCARD("text_set");
  2648. SIGNAL_DISCARD("text_changed");
  2649. SIGNAL_DISCARD("lines_edited_from");
  2650. SIGNAL_DISCARD("caret_changed");
  2651. lines_edited_args = build_array(build_array(1, 0), build_array(1, 0));
  2652. text_edit->cut();
  2653. MessageQueue::get_singleton()->flush();
  2654. CHECK(DS->clipboard_get() == "this is\n\n");
  2655. CHECK(text_edit->get_text() == "some");
  2656. CHECK(text_edit->get_caret_count() == 3);
  2657. CHECK_FALSE(text_edit->has_selection(0));
  2658. CHECK(text_edit->get_caret_line(0) == 0);
  2659. CHECK(text_edit->get_caret_column(0) == 2); // In the default font, this is the same position.
  2660. // The previous caret at index 1 was merged.
  2661. CHECK_FALSE(text_edit->has_selection(1));
  2662. CHECK(text_edit->get_caret_line(1) == 0);
  2663. CHECK(text_edit->get_caret_column(1) == 3); // In the default font, this is the same position.
  2664. CHECK_FALSE(text_edit->has_selection(2));
  2665. CHECK(text_edit->get_caret_line(2) == 0);
  2666. CHECK(text_edit->get_caret_column(2) == 4);
  2667. SIGNAL_CHECK("caret_changed", empty_signal_args);
  2668. SIGNAL_CHECK("text_changed", empty_signal_args);
  2669. SIGNAL_CHECK("lines_edited_from", lines_edited_args);
  2670. text_edit->remove_secondary_carets();
  2671. // Cut on the only line removes the contents.
  2672. text_edit->set_caret_line(0);
  2673. text_edit->set_caret_column(2);
  2674. MessageQueue::get_singleton()->flush();
  2675. SIGNAL_DISCARD("caret_changed");
  2676. lines_edited_args = build_array(build_array(0, 0));
  2677. text_edit->cut();
  2678. MessageQueue::get_singleton()->flush();
  2679. CHECK(DS->clipboard_get() == "some\n");
  2680. CHECK(text_edit->get_text() == "");
  2681. CHECK(text_edit->get_line_count() == 1);
  2682. CHECK(text_edit->get_caret_line() == 0);
  2683. CHECK(text_edit->get_caret_column() == 0);
  2684. SIGNAL_CHECK("caret_changed", empty_signal_args);
  2685. SIGNAL_CHECK("text_changed", empty_signal_args);
  2686. SIGNAL_CHECK("lines_edited_from", lines_edited_args);
  2687. // Cut empty line.
  2688. text_edit->cut();
  2689. MessageQueue::get_singleton()->flush();
  2690. CHECK(DS->clipboard_get() == "\n");
  2691. CHECK(text_edit->get_text() == "");
  2692. CHECK(text_edit->get_caret_line() == 0);
  2693. CHECK(text_edit->get_caret_column() == 0);
  2694. SIGNAL_CHECK_FALSE("caret_changed");
  2695. // These signals are emitted even if there is no change.
  2696. SIGNAL_CHECK("text_changed", empty_signal_args);
  2697. SIGNAL_CHECK("lines_edited_from", lines_edited_args);
  2698. // Cut multiple lines, in order.
  2699. text_edit->set_text("this is\nsome\ntext to\nbe\n\ncut");
  2700. text_edit->set_caret_line(2);
  2701. text_edit->set_caret_column(7);
  2702. text_edit->add_caret(3, 0);
  2703. text_edit->add_caret(0, 2);
  2704. MessageQueue::get_singleton()->flush();
  2705. SIGNAL_DISCARD("text_set");
  2706. SIGNAL_DISCARD("text_changed");
  2707. SIGNAL_DISCARD("lines_edited_from");
  2708. SIGNAL_DISCARD("caret_changed");
  2709. lines_edited_args = build_array(build_array(1, 0), build_array(3, 2), build_array(2, 1));
  2710. text_edit->cut();
  2711. MessageQueue::get_singleton()->flush();
  2712. CHECK(DS->clipboard_get() == "this is\ntext to\nbe\n");
  2713. CHECK(text_edit->get_text() == "some\n\ncut");
  2714. CHECK(text_edit->get_caret_count() == 2);
  2715. CHECK(text_edit->get_caret_line(0) == 1);
  2716. CHECK(text_edit->get_caret_column(0) == 0);
  2717. CHECK(text_edit->get_caret_line(1) == 0);
  2718. CHECK(text_edit->get_caret_column(1) == 2);
  2719. SIGNAL_CHECK("caret_changed", empty_signal_args);
  2720. SIGNAL_CHECK("text_changed", empty_signal_args);
  2721. SIGNAL_CHECK("lines_edited_from", lines_edited_args);
  2722. text_edit->remove_secondary_carets();
  2723. // Cut multiple selections, in order. Ignores regular carets.
  2724. text_edit->set_text("this is\nsome\ntext to\nbe\n\ncut");
  2725. text_edit->add_caret(3, 0);
  2726. text_edit->add_caret(0, 2);
  2727. text_edit->add_caret(2, 0);
  2728. text_edit->select(1, 0, 1, 2, 0);
  2729. text_edit->select(3, 0, 4, 0, 1);
  2730. text_edit->select(0, 5, 0, 3, 2);
  2731. MessageQueue::get_singleton()->flush();
  2732. SIGNAL_DISCARD("text_set");
  2733. SIGNAL_DISCARD("text_changed");
  2734. SIGNAL_DISCARD("lines_edited_from");
  2735. SIGNAL_DISCARD("caret_changed");
  2736. lines_edited_args = build_array(build_array(1, 1), build_array(4, 3), build_array(0, 0));
  2737. text_edit->cut();
  2738. MessageQueue::get_singleton()->flush();
  2739. CHECK(DS->clipboard_get() == "s \nso\nbe\n");
  2740. CHECK(text_edit->get_text() == "thiis\nme\ntext to\n\ncut");
  2741. CHECK(text_edit->get_caret_count() == 4);
  2742. CHECK_FALSE(text_edit->has_selection());
  2743. CHECK(text_edit->get_caret_line(0) == 1);
  2744. CHECK(text_edit->get_caret_column(0) == 0);
  2745. CHECK(text_edit->get_caret_line(1) == 3);
  2746. CHECK(text_edit->get_caret_column(1) == 0);
  2747. CHECK(text_edit->get_caret_line(2) == 0);
  2748. CHECK(text_edit->get_caret_column(2) == 3);
  2749. CHECK(text_edit->get_caret_line(3) == 2);
  2750. CHECK(text_edit->get_caret_column(3) == 0);
  2751. SIGNAL_CHECK("caret_changed", empty_signal_args);
  2752. SIGNAL_CHECK("text_changed", empty_signal_args);
  2753. SIGNAL_CHECK("lines_edited_from", lines_edited_args);
  2754. }
  2755. SUBCASE("[TextEdit] copy") {
  2756. text_edit->set_text("this is\nsome\ntest\n\ntext");
  2757. MessageQueue::get_singleton()->flush();
  2758. SIGNAL_DISCARD("text_set");
  2759. SIGNAL_DISCARD("text_changed");
  2760. SIGNAL_DISCARD("lines_edited_from");
  2761. SIGNAL_DISCARD("caret_changed");
  2762. // Copy selected text.
  2763. text_edit->select(0, 0, 1, 2, 0);
  2764. MessageQueue::get_singleton()->flush();
  2765. SIGNAL_DISCARD("caret_changed");
  2766. DS->clipboard_set_primary("");
  2767. text_edit->copy();
  2768. MessageQueue::get_singleton()->flush();
  2769. CHECK(DS->clipboard_get() == "this is\nso");
  2770. CHECK(DS->clipboard_get_primary() == "");
  2771. CHECK(text_edit->get_text() == "this is\nsome\ntest\n\ntext");
  2772. CHECK(text_edit->has_selection());
  2773. CHECK(text_edit->get_selection_origin_line() == 0);
  2774. CHECK(text_edit->get_selection_origin_column() == 0);
  2775. CHECK(text_edit->get_caret_line() == 1);
  2776. CHECK(text_edit->get_caret_column() == 2);
  2777. SIGNAL_CHECK_FALSE("caret_changed");
  2778. SIGNAL_CHECK_FALSE("text_changed");
  2779. SIGNAL_CHECK_FALSE("lines_edited_from");
  2780. // Copy with GUI action.
  2781. text_edit->select(0, 0, 0, 2, 0);
  2782. MessageQueue::get_singleton()->flush();
  2783. SIGNAL_DISCARD("caret_changed");
  2784. SEND_GUI_ACTION("ui_copy");
  2785. MessageQueue::get_singleton()->flush();
  2786. CHECK(DS->clipboard_get() == "th");
  2787. SIGNAL_CHECK_FALSE("caret_changed");
  2788. SIGNAL_CHECK_FALSE("text_changed");
  2789. SIGNAL_CHECK_FALSE("lines_edited_from");
  2790. // Can copy even if not editable.
  2791. text_edit->select(2, 4, 1, 2, 0);
  2792. MessageQueue::get_singleton()->flush();
  2793. SIGNAL_DISCARD("caret_changed");
  2794. text_edit->set_editable(false);
  2795. text_edit->copy();
  2796. text_edit->set_editable(true);
  2797. MessageQueue::get_singleton()->flush();
  2798. CHECK(DS->clipboard_get() == "me\ntest");
  2799. SIGNAL_CHECK_FALSE("caret_changed");
  2800. SIGNAL_CHECK_FALSE("text_changed");
  2801. SIGNAL_CHECK_FALSE("lines_edited_from");
  2802. text_edit->deselect();
  2803. // Copy full line when there is no selection.
  2804. text_edit->set_caret_line(0);
  2805. text_edit->set_caret_column(2);
  2806. MessageQueue::get_singleton()->flush();
  2807. SIGNAL_DISCARD("caret_changed");
  2808. text_edit->copy();
  2809. MessageQueue::get_singleton()->flush();
  2810. CHECK(DS->clipboard_get() == "this is\n");
  2811. SIGNAL_CHECK_FALSE("caret_changed");
  2812. SIGNAL_CHECK_FALSE("text_changed");
  2813. SIGNAL_CHECK_FALSE("lines_edited_from");
  2814. // Copy empty line.
  2815. text_edit->set_caret_line(3);
  2816. text_edit->set_caret_column(0);
  2817. MessageQueue::get_singleton()->flush();
  2818. SIGNAL_DISCARD("caret_changed");
  2819. text_edit->copy();
  2820. MessageQueue::get_singleton()->flush();
  2821. CHECK(DS->clipboard_get() == "\n");
  2822. SIGNAL_CHECK_FALSE("caret_changed");
  2823. SIGNAL_CHECK_FALSE("text_changed");
  2824. SIGNAL_CHECK_FALSE("lines_edited_from");
  2825. text_edit->deselect();
  2826. // Copy full line with multiple carets on that line only copies once.
  2827. text_edit->set_caret_line(1);
  2828. text_edit->set_caret_column(2);
  2829. text_edit->add_caret(1, 0);
  2830. text_edit->add_caret(1, 4);
  2831. MessageQueue::get_singleton()->flush();
  2832. SIGNAL_DISCARD("caret_changed");
  2833. text_edit->copy();
  2834. MessageQueue::get_singleton()->flush();
  2835. CHECK(DS->clipboard_get() == "some\n");
  2836. SIGNAL_CHECK_FALSE("caret_changed");
  2837. SIGNAL_CHECK_FALSE("text_changed");
  2838. SIGNAL_CHECK_FALSE("lines_edited_from");
  2839. text_edit->remove_secondary_carets();
  2840. // Copy selected text from all selections with `\n` in between, in order. Ignore regular carets.
  2841. text_edit->set_caret_line(2);
  2842. text_edit->set_caret_column(4);
  2843. text_edit->add_caret(4, 0);
  2844. text_edit->add_caret(0, 4);
  2845. text_edit->add_caret(1, 0);
  2846. text_edit->select(1, 3, 2, 4, 0);
  2847. text_edit->select(4, 4, 4, 0, 1);
  2848. text_edit->select(0, 5, 0, 4, 2);
  2849. MessageQueue::get_singleton()->flush();
  2850. SIGNAL_DISCARD("caret_changed");
  2851. text_edit->copy();
  2852. MessageQueue::get_singleton()->flush();
  2853. CHECK(DS->clipboard_get() == " \ne\ntest\ntext");
  2854. SIGNAL_CHECK_FALSE("caret_changed");
  2855. SIGNAL_CHECK_FALSE("text_changed");
  2856. SIGNAL_CHECK_FALSE("lines_edited_from");
  2857. text_edit->remove_secondary_carets();
  2858. text_edit->deselect();
  2859. // Copy multiple lines with multiple carets, in order.
  2860. text_edit->set_caret_line(3);
  2861. text_edit->set_caret_column(0);
  2862. text_edit->add_caret(4, 2);
  2863. text_edit->add_caret(0, 4);
  2864. MessageQueue::get_singleton()->flush();
  2865. SIGNAL_DISCARD("caret_changed");
  2866. text_edit->copy();
  2867. MessageQueue::get_singleton()->flush();
  2868. CHECK(DS->clipboard_get() == "this is\n\ntext\n");
  2869. SIGNAL_CHECK_FALSE("caret_changed");
  2870. SIGNAL_CHECK_FALSE("text_changed");
  2871. SIGNAL_CHECK_FALSE("lines_edited_from");
  2872. }
  2873. SUBCASE("[TextEdit] paste") {
  2874. // Paste text from clipboard at caret.
  2875. text_edit->set_text("this is\nsome\n\ntext");
  2876. text_edit->set_caret_line(1);
  2877. text_edit->set_caret_column(2);
  2878. MessageQueue::get_singleton()->flush();
  2879. SIGNAL_DISCARD("text_set");
  2880. SIGNAL_DISCARD("text_changed");
  2881. SIGNAL_DISCARD("lines_edited_from");
  2882. SIGNAL_DISCARD("caret_changed");
  2883. lines_edited_args = build_array(build_array(1, 1));
  2884. DS->clipboard_set("paste");
  2885. text_edit->paste();
  2886. MessageQueue::get_singleton()->flush();
  2887. CHECK(DS->clipboard_get() == "paste");
  2888. CHECK(text_edit->get_text() == "this is\nsopasteme\n\ntext");
  2889. CHECK_FALSE(text_edit->has_selection());
  2890. CHECK(text_edit->get_caret_line() == 1);
  2891. CHECK(text_edit->get_caret_column() == 7);
  2892. SIGNAL_CHECK("caret_changed", empty_signal_args);
  2893. SIGNAL_CHECK("text_changed", empty_signal_args);
  2894. SIGNAL_CHECK("lines_edited_from", lines_edited_args);
  2895. // Undo.
  2896. text_edit->undo();
  2897. MessageQueue::get_singleton()->flush();
  2898. CHECK(DS->clipboard_get() == "paste");
  2899. CHECK(text_edit->get_text() == "this is\nsome\n\ntext");
  2900. CHECK(text_edit->get_caret_line() == 1);
  2901. CHECK(text_edit->get_caret_column() == 2);
  2902. SIGNAL_CHECK("caret_changed", empty_signal_args);
  2903. SIGNAL_CHECK("text_changed", empty_signal_args);
  2904. SIGNAL_CHECK("lines_edited_from", lines_edited_args);
  2905. // Redo.
  2906. text_edit->redo();
  2907. MessageQueue::get_singleton()->flush();
  2908. CHECK(DS->clipboard_get() == "paste");
  2909. CHECK(text_edit->get_text() == "this is\nsopasteme\n\ntext");
  2910. CHECK(text_edit->get_caret_line() == 1);
  2911. CHECK(text_edit->get_caret_column() == 7);
  2912. SIGNAL_CHECK("caret_changed", empty_signal_args);
  2913. SIGNAL_CHECK("text_changed", empty_signal_args);
  2914. SIGNAL_CHECK("lines_edited_from", lines_edited_args);
  2915. // Paste on empty line. Use GUI action.
  2916. text_edit->set_text("this is\nsome\n\ntext");
  2917. text_edit->set_caret_line(2);
  2918. text_edit->set_caret_column(0);
  2919. MessageQueue::get_singleton()->flush();
  2920. SIGNAL_DISCARD("text_set");
  2921. SIGNAL_DISCARD("text_changed");
  2922. SIGNAL_DISCARD("lines_edited_from");
  2923. SIGNAL_DISCARD("caret_changed");
  2924. lines_edited_args = build_array(build_array(2, 2));
  2925. DS->clipboard_set("paste2");
  2926. SEND_GUI_ACTION("ui_paste");
  2927. MessageQueue::get_singleton()->flush();
  2928. CHECK(DS->clipboard_get() == "paste2");
  2929. CHECK(text_edit->get_text() == "this is\nsome\npaste2\ntext");
  2930. CHECK(text_edit->get_caret_line() == 2);
  2931. CHECK(text_edit->get_caret_column() == 6);
  2932. SIGNAL_CHECK("caret_changed", empty_signal_args);
  2933. SIGNAL_CHECK("text_changed", empty_signal_args);
  2934. SIGNAL_CHECK("lines_edited_from", lines_edited_args);
  2935. // Paste removes selection before pasting.
  2936. text_edit->set_text("this is\nsome\n\ntext");
  2937. text_edit->select(0, 5, 1, 3);
  2938. MessageQueue::get_singleton()->flush();
  2939. SIGNAL_DISCARD("text_set");
  2940. SIGNAL_DISCARD("text_changed");
  2941. SIGNAL_DISCARD("lines_edited_from");
  2942. SIGNAL_DISCARD("caret_changed");
  2943. lines_edited_args = build_array(build_array(1, 0), build_array(0, 0));
  2944. DS->clipboard_set("paste");
  2945. text_edit->paste();
  2946. MessageQueue::get_singleton()->flush();
  2947. CHECK(DS->clipboard_get() == "paste");
  2948. CHECK(text_edit->get_text() == "this pastee\n\ntext");
  2949. CHECK_FALSE(text_edit->has_selection());
  2950. CHECK(text_edit->get_caret_line() == 0);
  2951. CHECK(text_edit->get_caret_column() == 10);
  2952. SIGNAL_CHECK("caret_changed", empty_signal_args);
  2953. SIGNAL_CHECK("text_changed", empty_signal_args);
  2954. SIGNAL_CHECK("lines_edited_from", lines_edited_args);
  2955. // Paste multiple lines.
  2956. text_edit->set_text("this is\nsome\n\ntext");
  2957. text_edit->set_caret_line(0);
  2958. text_edit->set_caret_column(1);
  2959. MessageQueue::get_singleton()->flush();
  2960. SIGNAL_DISCARD("text_set");
  2961. SIGNAL_DISCARD("text_changed");
  2962. SIGNAL_DISCARD("lines_edited_from");
  2963. SIGNAL_DISCARD("caret_changed");
  2964. lines_edited_args = build_array(build_array(0, 3));
  2965. DS->clipboard_set("multi\n\nline\npaste");
  2966. text_edit->paste();
  2967. MessageQueue::get_singleton()->flush();
  2968. CHECK(DS->clipboard_get() == "multi\n\nline\npaste");
  2969. CHECK(text_edit->get_text() == "tmulti\n\nline\npastehis is\nsome\n\ntext");
  2970. CHECK(text_edit->get_caret_line() == 3);
  2971. CHECK(text_edit->get_caret_column() == 5);
  2972. SIGNAL_CHECK("caret_changed", empty_signal_args);
  2973. SIGNAL_CHECK("text_changed", empty_signal_args);
  2974. SIGNAL_CHECK("lines_edited_from", lines_edited_args);
  2975. // Paste full line after copying it.
  2976. text_edit->set_text("this is\nsome\n\ntext");
  2977. text_edit->set_caret_line(1);
  2978. text_edit->set_caret_column(2);
  2979. MessageQueue::get_singleton()->flush();
  2980. SIGNAL_DISCARD("text_set");
  2981. SIGNAL_DISCARD("text_changed");
  2982. SIGNAL_DISCARD("lines_edited_from");
  2983. SIGNAL_DISCARD("caret_changed");
  2984. lines_edited_args = build_array(build_array(1, 2));
  2985. DS->clipboard_set("");
  2986. text_edit->copy();
  2987. text_edit->set_caret_column(3);
  2988. CHECK(DS->clipboard_get() == "some\n");
  2989. MessageQueue::get_singleton()->flush();
  2990. SIGNAL_DISCARD("caret_changed");
  2991. text_edit->paste();
  2992. MessageQueue::get_singleton()->flush();
  2993. CHECK(DS->clipboard_get() == "some\n");
  2994. CHECK(text_edit->get_text() == "this is\nsome\nsome\n\ntext");
  2995. CHECK(text_edit->get_caret_line() == 2);
  2996. CHECK(text_edit->get_caret_column() == 3);
  2997. SIGNAL_CHECK("caret_changed", empty_signal_args);
  2998. SIGNAL_CHECK("text_changed", empty_signal_args);
  2999. SIGNAL_CHECK("lines_edited_from", lines_edited_args);
  3000. // Do not paste as line since it wasn't copied.
  3001. text_edit->set_text("this is\nsome\n\ntext");
  3002. text_edit->set_caret_line(0);
  3003. text_edit->set_caret_column(4);
  3004. MessageQueue::get_singleton()->flush();
  3005. SIGNAL_DISCARD("text_set");
  3006. SIGNAL_DISCARD("text_changed");
  3007. SIGNAL_DISCARD("lines_edited_from");
  3008. SIGNAL_DISCARD("caret_changed");
  3009. lines_edited_args = build_array(build_array(0, 1));
  3010. DS->clipboard_set("paste\n");
  3011. text_edit->paste();
  3012. MessageQueue::get_singleton()->flush();
  3013. CHECK(DS->clipboard_get() == "paste\n");
  3014. CHECK(text_edit->get_text() == "thispaste\n is\nsome\n\ntext");
  3015. CHECK(text_edit->get_caret_line() == 1);
  3016. CHECK(text_edit->get_caret_column() == 0);
  3017. SIGNAL_CHECK("caret_changed", empty_signal_args);
  3018. SIGNAL_CHECK("text_changed", empty_signal_args);
  3019. SIGNAL_CHECK("lines_edited_from", lines_edited_args);
  3020. // Paste text at each caret.
  3021. text_edit->set_text("this is\nsome\n\ntext");
  3022. text_edit->set_caret_line(1);
  3023. text_edit->set_caret_column(2);
  3024. text_edit->add_caret(3, 4);
  3025. text_edit->add_caret(0, 4);
  3026. MessageQueue::get_singleton()->flush();
  3027. SIGNAL_DISCARD("text_set");
  3028. SIGNAL_DISCARD("text_changed");
  3029. SIGNAL_DISCARD("lines_edited_from");
  3030. SIGNAL_DISCARD("caret_changed");
  3031. lines_edited_args = build_array(build_array(0, 1), build_array(2, 3), build_array(5, 6));
  3032. DS->clipboard_set("paste\ntest");
  3033. text_edit->paste();
  3034. MessageQueue::get_singleton()->flush();
  3035. CHECK(DS->clipboard_get() == "paste\ntest");
  3036. CHECK(text_edit->get_text() == "thispaste\ntest is\nsopaste\ntestme\n\ntextpaste\ntest");
  3037. CHECK(text_edit->get_caret_count() == 3);
  3038. CHECK(text_edit->get_caret_line(0) == 3);
  3039. CHECK(text_edit->get_caret_column(0) == 4);
  3040. CHECK(text_edit->get_caret_line(1) == 6);
  3041. CHECK(text_edit->get_caret_column(1) == 4);
  3042. CHECK(text_edit->get_caret_line(2) == 1);
  3043. CHECK(text_edit->get_caret_column(2) == 4);
  3044. SIGNAL_CHECK("caret_changed", empty_signal_args);
  3045. SIGNAL_CHECK("text_changed", empty_signal_args);
  3046. SIGNAL_CHECK("lines_edited_from", lines_edited_args);
  3047. text_edit->remove_secondary_carets();
  3048. // Paste line per caret when the amount of lines is equal to the number of carets.
  3049. text_edit->set_text("this is\nsome\n\ntext");
  3050. text_edit->set_caret_line(1);
  3051. text_edit->set_caret_column(2);
  3052. text_edit->add_caret(3, 4);
  3053. text_edit->add_caret(0, 4);
  3054. MessageQueue::get_singleton()->flush();
  3055. SIGNAL_DISCARD("text_set");
  3056. SIGNAL_DISCARD("text_changed");
  3057. SIGNAL_DISCARD("lines_edited_from");
  3058. SIGNAL_DISCARD("caret_changed");
  3059. lines_edited_args = build_array(build_array(0, 0), build_array(1, 1), build_array(3, 3));
  3060. DS->clipboard_set("paste\ntest\n1");
  3061. text_edit->paste();
  3062. MessageQueue::get_singleton()->flush();
  3063. CHECK(DS->clipboard_get() == "paste\ntest\n1");
  3064. CHECK(text_edit->get_text() == "thispaste is\nsotestme\n\ntext1");
  3065. CHECK(text_edit->get_caret_count() == 3);
  3066. CHECK(text_edit->get_caret_line(0) == 1);
  3067. CHECK(text_edit->get_caret_column(0) == 6);
  3068. CHECK(text_edit->get_caret_line(1) == 3);
  3069. CHECK(text_edit->get_caret_column(1) == 5);
  3070. CHECK(text_edit->get_caret_line(2) == 0);
  3071. CHECK(text_edit->get_caret_column(2) == 9);
  3072. SIGNAL_CHECK("caret_changed", empty_signal_args);
  3073. SIGNAL_CHECK("text_changed", empty_signal_args);
  3074. SIGNAL_CHECK("lines_edited_from", lines_edited_args);
  3075. text_edit->remove_secondary_carets();
  3076. // Cannot paste when not editable.
  3077. text_edit->set_text("this is\nsome\n\ntext");
  3078. text_edit->set_caret_line(0);
  3079. text_edit->set_caret_column(4);
  3080. MessageQueue::get_singleton()->flush();
  3081. SIGNAL_DISCARD("text_set");
  3082. SIGNAL_DISCARD("text_changed");
  3083. SIGNAL_DISCARD("lines_edited_from");
  3084. SIGNAL_DISCARD("caret_changed");
  3085. DS->clipboard_set("no paste");
  3086. text_edit->set_editable(false);
  3087. text_edit->paste();
  3088. text_edit->set_editable(true);
  3089. MessageQueue::get_singleton()->flush();
  3090. CHECK(DS->clipboard_get() == "no paste");
  3091. CHECK(text_edit->get_text() == "this is\nsome\n\ntext");
  3092. CHECK(text_edit->get_caret_line() == 0);
  3093. CHECK(text_edit->get_caret_column() == 4);
  3094. SIGNAL_CHECK_FALSE("caret_changed");
  3095. SIGNAL_CHECK_FALSE("text_changed");
  3096. SIGNAL_CHECK_FALSE("lines_edited_from");
  3097. }
  3098. SUBCASE("[TextEdit] paste primary") {
  3099. // Set size for mouse input.
  3100. text_edit->set_size(Size2(200, 200));
  3101. text_edit->grab_focus();
  3102. DS->clipboard_set("");
  3103. DS->clipboard_set_primary("");
  3104. CHECK(DS->clipboard_get_primary() == "");
  3105. // Select text with mouse to put into primary clipboard.
  3106. text_edit->set_text("this is\nsome\n\ntext");
  3107. MessageQueue::get_singleton()->flush();
  3108. SIGNAL_DISCARD("text_set");
  3109. SIGNAL_DISCARD("text_changed");
  3110. SIGNAL_DISCARD("lines_edited_from");
  3111. SIGNAL_DISCARD("caret_changed");
  3112. SEND_GUI_MOUSE_BUTTON_EVENT(text_edit->get_rect_at_line_column(0, 2).get_center() + Point2i(2, 0), MouseButton::LEFT, MouseButtonMask::LEFT, Key::NONE);
  3113. SEND_GUI_MOUSE_MOTION_EVENT(text_edit->get_rect_at_line_column(1, 3).get_center() + Point2i(2, 0), MouseButtonMask::LEFT, Key::NONE);
  3114. SEND_GUI_MOUSE_BUTTON_RELEASED_EVENT(text_edit->get_rect_at_line_column(1, 3).get_center() + Point2i(2, 0), MouseButton::LEFT, MouseButtonMask::LEFT, Key::NONE);
  3115. CHECK(DS->clipboard_get() == "");
  3116. CHECK(DS->clipboard_get_primary() == "is is\nsom");
  3117. CHECK(text_edit->get_text() == "this is\nsome\n\ntext");
  3118. CHECK(text_edit->has_selection());
  3119. CHECK(text_edit->get_selected_text() == "is is\nsom");
  3120. CHECK(text_edit->get_selection_origin_line() == 0);
  3121. CHECK(text_edit->get_selection_origin_column() == 2);
  3122. CHECK(text_edit->get_caret_line() == 1);
  3123. CHECK(text_edit->get_caret_column() == 3);
  3124. SIGNAL_CHECK_FALSE("text_set");
  3125. SIGNAL_CHECK_FALSE("text_changed");
  3126. SIGNAL_CHECK_FALSE("lines_edited_from");
  3127. // Middle click to paste at mouse.
  3128. SIGNAL_DISCARD("text_set");
  3129. SIGNAL_DISCARD("text_changed");
  3130. SIGNAL_DISCARD("lines_edited_from");
  3131. SIGNAL_DISCARD("caret_changed");
  3132. lines_edited_args = build_array(build_array(3, 4));
  3133. SEND_GUI_MOUSE_BUTTON_EVENT(text_edit->get_rect_at_line_column(3, 2).get_center() + Point2i(2, 0), MouseButton::MIDDLE, MouseButtonMask::MIDDLE, Key::NONE);
  3134. CHECK(DS->clipboard_get_primary() == "is is\nsom");
  3135. CHECK(text_edit->get_text() == "this is\nsome\n\nteis is\nsomxt");
  3136. CHECK_FALSE(text_edit->has_selection());
  3137. CHECK(text_edit->get_caret_line() == 4);
  3138. CHECK(text_edit->get_caret_column() == 3);
  3139. SIGNAL_CHECK("caret_changed", empty_signal_args);
  3140. SIGNAL_CHECK("text_changed", empty_signal_args);
  3141. SIGNAL_CHECK("lines_edited_from", lines_edited_args);
  3142. // Paste at mouse position if there is only one caret.
  3143. text_edit->set_text("this is\nsome\n\ntext");
  3144. SEND_GUI_MOUSE_MOTION_EVENT(text_edit->get_rect_at_line_column(0, 1).get_center() + Point2i(2, 0), MouseButtonMask::NONE, Key::NONE);
  3145. MessageQueue::get_singleton()->flush();
  3146. SIGNAL_DISCARD("text_set");
  3147. SIGNAL_DISCARD("text_changed");
  3148. SIGNAL_DISCARD("lines_edited_from");
  3149. SIGNAL_DISCARD("caret_changed");
  3150. DS->clipboard_set_primary("paste");
  3151. lines_edited_args = build_array(build_array(0, 0));
  3152. text_edit->paste_primary_clipboard();
  3153. MessageQueue::get_singleton()->flush();
  3154. CHECK(DS->clipboard_get_primary() == "paste");
  3155. CHECK(text_edit->get_text() == "tpastehis is\nsome\n\ntext");
  3156. CHECK_FALSE(text_edit->has_selection());
  3157. CHECK(text_edit->get_caret_line() == 0);
  3158. CHECK(text_edit->get_caret_column() == 6);
  3159. SIGNAL_CHECK("caret_changed", empty_signal_args);
  3160. SIGNAL_CHECK("text_changed", empty_signal_args);
  3161. SIGNAL_CHECK("lines_edited_from", lines_edited_args);
  3162. // Paste at all carets if there are multiple carets.
  3163. text_edit->set_text("this is\nsome\n\ntext");
  3164. text_edit->set_caret_line(1);
  3165. text_edit->set_caret_column(0);
  3166. text_edit->add_caret(2, 0);
  3167. SEND_GUI_MOUSE_MOTION_EVENT(text_edit->get_rect_at_line_column(0, 1).get_center() + Point2i(2, 0), MouseButtonMask::NONE, Key::NONE);
  3168. MessageQueue::get_singleton()->flush();
  3169. SIGNAL_DISCARD("text_set");
  3170. SIGNAL_DISCARD("text_changed");
  3171. SIGNAL_DISCARD("lines_edited_from");
  3172. SIGNAL_DISCARD("caret_changed");
  3173. DS->clipboard_set_primary("paste");
  3174. lines_edited_args = build_array(build_array(1, 1), build_array(2, 2));
  3175. text_edit->paste_primary_clipboard();
  3176. MessageQueue::get_singleton()->flush();
  3177. CHECK(DS->clipboard_get_primary() == "paste");
  3178. CHECK(text_edit->get_text() == "this is\npastesome\npaste\ntext");
  3179. CHECK_FALSE(text_edit->has_selection());
  3180. CHECK(text_edit->get_caret_count() == 2);
  3181. CHECK(text_edit->get_caret_line(0) == 1);
  3182. CHECK(text_edit->get_caret_column(0) == 5);
  3183. CHECK(text_edit->get_caret_line(1) == 2);
  3184. CHECK(text_edit->get_caret_column(1) == 5);
  3185. SIGNAL_CHECK("caret_changed", empty_signal_args);
  3186. SIGNAL_CHECK("text_changed", empty_signal_args);
  3187. SIGNAL_CHECK("lines_edited_from", lines_edited_args);
  3188. // Cannot paste if not editable.
  3189. text_edit->set_text("this is\nsome\n\ntext");
  3190. text_edit->set_caret_line(0);
  3191. text_edit->set_caret_column(4);
  3192. SEND_GUI_MOUSE_MOTION_EVENT(text_edit->get_rect_at_line_column(1, 3).get_center() + Point2i(2, 0), MouseButtonMask::NONE, Key::NONE);
  3193. MessageQueue::get_singleton()->flush();
  3194. SIGNAL_DISCARD("text_set");
  3195. SIGNAL_DISCARD("text_changed");
  3196. SIGNAL_DISCARD("lines_edited_from");
  3197. SIGNAL_DISCARD("caret_changed");
  3198. DS->clipboard_set("no paste");
  3199. text_edit->set_editable(false);
  3200. text_edit->paste_primary_clipboard();
  3201. text_edit->set_editable(true);
  3202. MessageQueue::get_singleton()->flush();
  3203. CHECK(DS->clipboard_get() == "no paste");
  3204. CHECK(text_edit->get_text() == "this is\nsome\n\ntext");
  3205. CHECK(text_edit->get_caret_line() == 0);
  3206. CHECK(text_edit->get_caret_column() == 4);
  3207. SIGNAL_CHECK_FALSE("caret_changed");
  3208. SIGNAL_CHECK_FALSE("text_changed");
  3209. SIGNAL_CHECK_FALSE("lines_edited_from");
  3210. }
  3211. SUBCASE("[TextEdit] cut when empty selection clipboard disabled") {
  3212. text_edit->set_empty_selection_clipboard_enabled(false);
  3213. DS->clipboard_set("");
  3214. text_edit->set_text("this is\nsome\n");
  3215. text_edit->set_caret_line(0);
  3216. text_edit->set_caret_column(6);
  3217. MessageQueue::get_singleton()->flush();
  3218. SIGNAL_DISCARD("text_set");
  3219. SIGNAL_DISCARD("text_changed");
  3220. SIGNAL_DISCARD("lines_edited_from");
  3221. SIGNAL_DISCARD("caret_changed");
  3222. text_edit->cut();
  3223. MessageQueue::get_singleton()->flush();
  3224. CHECK(DS->clipboard_get() == "");
  3225. CHECK(text_edit->get_text() == "this is\nsome\n");
  3226. CHECK(text_edit->get_caret_line() == 0);
  3227. CHECK(text_edit->get_caret_column() == 6);
  3228. SIGNAL_CHECK_FALSE("caret_changed");
  3229. SIGNAL_CHECK_FALSE("text_changed");
  3230. SIGNAL_CHECK_FALSE("lines_edited_from");
  3231. }
  3232. SUBCASE("[TextEdit] copy when empty selection clipboard disabled") {
  3233. text_edit->set_empty_selection_clipboard_enabled(false);
  3234. DS->clipboard_set("");
  3235. text_edit->set_text("this is\nsome\n");
  3236. text_edit->set_caret_line(0);
  3237. text_edit->set_caret_column(6);
  3238. MessageQueue::get_singleton()->flush();
  3239. SIGNAL_DISCARD("text_set");
  3240. SIGNAL_DISCARD("text_changed");
  3241. SIGNAL_DISCARD("lines_edited_from");
  3242. SIGNAL_DISCARD("caret_changed");
  3243. text_edit->copy();
  3244. MessageQueue::get_singleton()->flush();
  3245. CHECK(DS->clipboard_get() == "");
  3246. CHECK(text_edit->get_text() == "this is\nsome\n");
  3247. CHECK(text_edit->get_caret_line() == 0);
  3248. CHECK(text_edit->get_caret_column() == 6);
  3249. SIGNAL_CHECK_FALSE("caret_changed");
  3250. SIGNAL_CHECK_FALSE("text_changed");
  3251. SIGNAL_CHECK_FALSE("lines_edited_from");
  3252. }
  3253. SIGNAL_UNWATCH(text_edit, "text_set");
  3254. SIGNAL_UNWATCH(text_edit, "text_changed");
  3255. SIGNAL_UNWATCH(text_edit, "lines_edited_from");
  3256. SIGNAL_UNWATCH(text_edit, "caret_changed");
  3257. }
  3258. SUBCASE("[TextEdit] input") {
  3259. SIGNAL_WATCH(text_edit, "text_set");
  3260. SIGNAL_WATCH(text_edit, "text_changed");
  3261. SIGNAL_WATCH(text_edit, "lines_edited_from");
  3262. SIGNAL_WATCH(text_edit, "caret_changed");
  3263. Array lines_edited_args = build_array(build_array(0, 0));
  3264. SUBCASE("[TextEdit] ui_text_newline_above") {
  3265. text_edit->set_text("this is some test text.\nthis is some test text.");
  3266. MessageQueue::get_singleton()->flush();
  3267. SIGNAL_DISCARD("text_set");
  3268. SIGNAL_DISCARD("text_changed");
  3269. SIGNAL_DISCARD("lines_edited_from");
  3270. SIGNAL_DISCARD("caret_changed");
  3271. // Insert new line above.
  3272. text_edit->select(0, 0, 0, 4);
  3273. text_edit->add_caret(1, 4);
  3274. CHECK(text_edit->get_caret_count() == 2);
  3275. MessageQueue::get_singleton()->flush();
  3276. SIGNAL_DISCARD("caret_changed");
  3277. lines_edited_args = build_array(build_array(0, 1), build_array(2, 3));
  3278. SEND_GUI_ACTION("ui_text_newline_above");
  3279. CHECK(text_edit->get_viewport()->is_input_handled());
  3280. CHECK(text_edit->get_text() == "\nthis is some test text.\n\nthis is some test text.");
  3281. CHECK_FALSE(text_edit->has_selection(0));
  3282. CHECK(text_edit->get_caret_line(0) == 0);
  3283. CHECK(text_edit->get_caret_column(0) == 0);
  3284. CHECK_FALSE(text_edit->has_selection(1));
  3285. CHECK(text_edit->get_caret_line(1) == 2);
  3286. CHECK(text_edit->get_caret_column(1) == 0);
  3287. SIGNAL_CHECK("caret_changed", empty_signal_args);
  3288. SIGNAL_CHECK("text_changed", empty_signal_args);
  3289. SIGNAL_CHECK("lines_edited_from", lines_edited_args);
  3290. // Undo.
  3291. text_edit->undo();
  3292. MessageQueue::get_singleton()->flush();
  3293. CHECK(text_edit->get_text() == "this is some test text.\nthis is some test text.");
  3294. CHECK(text_edit->has_selection(0));
  3295. CHECK(text_edit->get_caret_line(0) == 0);
  3296. CHECK(text_edit->get_caret_column(0) == 4);
  3297. CHECK(text_edit->get_selection_origin_line(0) == 0);
  3298. CHECK(text_edit->get_selection_origin_column(0) == 0);
  3299. CHECK_FALSE(text_edit->has_selection(1));
  3300. CHECK(text_edit->get_caret_line(1) == 1);
  3301. CHECK(text_edit->get_caret_column(1) == 4);
  3302. SIGNAL_CHECK("caret_changed", empty_signal_args);
  3303. SIGNAL_CHECK("text_changed", empty_signal_args);
  3304. SIGNAL_CHECK("lines_edited_from", reverse_nested(lines_edited_args));
  3305. // Redo.
  3306. text_edit->redo();
  3307. MessageQueue::get_singleton()->flush();
  3308. CHECK(text_edit->get_text() == "\nthis is some test text.\n\nthis is some test text.");
  3309. CHECK_FALSE(text_edit->has_selection(0));
  3310. CHECK(text_edit->get_caret_line(0) == 0);
  3311. CHECK(text_edit->get_caret_column(0) == 0);
  3312. CHECK_FALSE(text_edit->has_selection(1));
  3313. CHECK(text_edit->get_caret_line(1) == 2);
  3314. CHECK(text_edit->get_caret_column(1) == 0);
  3315. SIGNAL_CHECK("caret_changed", empty_signal_args);
  3316. SIGNAL_CHECK("text_changed", empty_signal_args);
  3317. SIGNAL_CHECK("lines_edited_from", lines_edited_args);
  3318. // Does not work if not editable.
  3319. text_edit->set_caret_line(1);
  3320. text_edit->set_caret_column(4);
  3321. text_edit->set_caret_line(3, false, true, -1, 1);
  3322. text_edit->set_caret_column(4, false, 1);
  3323. MessageQueue::get_singleton()->flush();
  3324. SIGNAL_DISCARD("caret_changed");
  3325. text_edit->set_editable(false);
  3326. SEND_GUI_ACTION("ui_text_newline_above");
  3327. CHECK(text_edit->get_viewport()->is_input_handled());
  3328. CHECK(text_edit->get_text() == "\nthis is some test text.\n\nthis is some test text.");
  3329. CHECK_FALSE(text_edit->has_selection(0));
  3330. CHECK(text_edit->get_caret_line(0) == 1);
  3331. CHECK(text_edit->get_caret_column(0) == 4);
  3332. CHECK_FALSE(text_edit->has_selection(1));
  3333. CHECK(text_edit->get_caret_line(1) == 3);
  3334. CHECK(text_edit->get_caret_column(1) == 4);
  3335. SIGNAL_CHECK_FALSE("caret_changed");
  3336. SIGNAL_CHECK_FALSE("text_changed");
  3337. SIGNAL_CHECK_FALSE("lines_edited_from");
  3338. text_edit->set_editable(true);
  3339. // Works on first line, empty lines, and only happens at caret for selections.
  3340. text_edit->select(1, 10, 0, 0);
  3341. MessageQueue::get_singleton()->flush();
  3342. SIGNAL_DISCARD("caret_changed");
  3343. lines_edited_args = build_array(build_array(0, 1), build_array(4, 5));
  3344. SEND_GUI_ACTION("ui_text_newline_above");
  3345. CHECK(text_edit->get_viewport()->is_input_handled());
  3346. CHECK(text_edit->get_text() == "\n\nthis is some test text.\n\n\nthis is some test text.");
  3347. CHECK_FALSE(text_edit->has_selection(0));
  3348. CHECK(text_edit->get_caret_line(0) == 0);
  3349. CHECK(text_edit->get_caret_column(0) == 0);
  3350. CHECK_FALSE(text_edit->has_selection(1));
  3351. CHECK(text_edit->get_caret_line(1) == 4);
  3352. CHECK(text_edit->get_caret_column(1) == 0);
  3353. SIGNAL_CHECK("caret_changed", empty_signal_args);
  3354. SIGNAL_CHECK("text_changed", empty_signal_args);
  3355. SIGNAL_CHECK("lines_edited_from", lines_edited_args);
  3356. // Insert multiple new lines above from one line.
  3357. text_edit->set_text("test");
  3358. text_edit->set_caret_line(0);
  3359. text_edit->set_caret_column(1);
  3360. text_edit->add_caret(0, 3);
  3361. MessageQueue::get_singleton()->flush();
  3362. SIGNAL_DISCARD("text_set");
  3363. SIGNAL_DISCARD("text_changed");
  3364. SIGNAL_DISCARD("lines_edited_from");
  3365. SIGNAL_DISCARD("caret_changed");
  3366. lines_edited_args = build_array(build_array(0, 1), build_array(1, 2));
  3367. SEND_GUI_ACTION("ui_text_newline_above");
  3368. CHECK(text_edit->get_viewport()->is_input_handled());
  3369. CHECK(text_edit->get_text() == "\n\ntest");
  3370. CHECK_FALSE(text_edit->has_selection(0));
  3371. CHECK(text_edit->get_caret_line(0) == 0);
  3372. CHECK(text_edit->get_caret_column(0) == 0);
  3373. CHECK_FALSE(text_edit->has_selection(1));
  3374. CHECK(text_edit->get_caret_line(1) == 1);
  3375. CHECK(text_edit->get_caret_column(1) == 0);
  3376. SIGNAL_CHECK("caret_changed", empty_signal_args);
  3377. SIGNAL_CHECK("text_changed", empty_signal_args);
  3378. SIGNAL_CHECK("lines_edited_from", lines_edited_args);
  3379. }
  3380. SUBCASE("[TextEdit] ui_text_newline_blank") {
  3381. text_edit->set_text("this is some test text.\nthis is some test text.");
  3382. MessageQueue::get_singleton()->flush();
  3383. SIGNAL_DISCARD("text_set");
  3384. SIGNAL_DISCARD("text_changed");
  3385. SIGNAL_DISCARD("lines_edited_from");
  3386. // Insert new line below.
  3387. text_edit->select(0, 0, 0, 4);
  3388. text_edit->add_caret(1, 4);
  3389. CHECK(text_edit->get_caret_count() == 2);
  3390. MessageQueue::get_singleton()->flush();
  3391. SIGNAL_DISCARD("caret_changed");
  3392. lines_edited_args = build_array(build_array(0, 1), build_array(2, 3));
  3393. SEND_GUI_ACTION("ui_text_newline_blank");
  3394. CHECK(text_edit->get_viewport()->is_input_handled());
  3395. CHECK(text_edit->get_text() == "this is some test text.\n\nthis is some test text.\n");
  3396. CHECK_FALSE(text_edit->has_selection(0));
  3397. CHECK(text_edit->get_caret_line(0) == 1);
  3398. CHECK(text_edit->get_caret_column(0) == 0);
  3399. CHECK_FALSE(text_edit->has_selection(1));
  3400. CHECK(text_edit->get_caret_line(1) == 3);
  3401. CHECK(text_edit->get_caret_column(1) == 0);
  3402. SIGNAL_CHECK("caret_changed", empty_signal_args);
  3403. SIGNAL_CHECK("text_changed", empty_signal_args);
  3404. SIGNAL_CHECK("lines_edited_from", lines_edited_args);
  3405. // Undo.
  3406. text_edit->undo();
  3407. MessageQueue::get_singleton()->flush();
  3408. CHECK(text_edit->get_text() == "this is some test text.\nthis is some test text.");
  3409. CHECK(text_edit->has_selection(0));
  3410. CHECK(text_edit->get_caret_line(0) == 0);
  3411. CHECK(text_edit->get_caret_column(0) == 4);
  3412. CHECK(text_edit->get_selection_origin_line(0) == 0);
  3413. CHECK(text_edit->get_selection_origin_column(0) == 0);
  3414. CHECK_FALSE(text_edit->has_selection(1));
  3415. CHECK(text_edit->get_caret_line(1) == 1);
  3416. CHECK(text_edit->get_caret_column(1) == 4);
  3417. SIGNAL_CHECK("caret_changed", empty_signal_args);
  3418. SIGNAL_CHECK("text_changed", empty_signal_args);
  3419. SIGNAL_CHECK("lines_edited_from", reverse_nested(lines_edited_args));
  3420. // Redo.
  3421. text_edit->redo();
  3422. MessageQueue::get_singleton()->flush();
  3423. CHECK(text_edit->get_text() == "this is some test text.\n\nthis is some test text.\n");
  3424. CHECK(text_edit->get_caret_line(0) == 1);
  3425. CHECK(text_edit->get_caret_column(0) == 0);
  3426. CHECK_FALSE(text_edit->has_selection(0));
  3427. CHECK(text_edit->get_caret_line(1) == 3);
  3428. CHECK(text_edit->get_caret_column(1) == 0);
  3429. CHECK_FALSE(text_edit->has_selection(1));
  3430. SIGNAL_CHECK("caret_changed", empty_signal_args);
  3431. SIGNAL_CHECK("text_changed", empty_signal_args);
  3432. SIGNAL_CHECK("lines_edited_from", lines_edited_args);
  3433. // Does not work if not editable.
  3434. text_edit->set_editable(false);
  3435. SEND_GUI_ACTION("ui_text_newline_blank");
  3436. CHECK(text_edit->get_viewport()->is_input_handled());
  3437. CHECK(text_edit->get_text() == "this is some test text.\n\nthis is some test text.\n");
  3438. CHECK_FALSE(text_edit->has_selection(0));
  3439. CHECK(text_edit->get_caret_line(0) == 1);
  3440. CHECK(text_edit->get_caret_column(0) == 0);
  3441. CHECK_FALSE(text_edit->has_selection(1));
  3442. CHECK(text_edit->get_caret_line(1) == 3);
  3443. CHECK(text_edit->get_caret_column(1) == 0);
  3444. SIGNAL_CHECK_FALSE("caret_changed");
  3445. SIGNAL_CHECK_FALSE("text_changed");
  3446. SIGNAL_CHECK_FALSE("lines_edited_from");
  3447. text_edit->set_editable(true);
  3448. // Insert multiple new lines below from one line.
  3449. text_edit->set_text("test");
  3450. text_edit->set_caret_line(0);
  3451. text_edit->set_caret_column(1);
  3452. text_edit->add_caret(0, 3);
  3453. MessageQueue::get_singleton()->flush();
  3454. SIGNAL_DISCARD("text_set");
  3455. SIGNAL_DISCARD("text_changed");
  3456. SIGNAL_DISCARD("lines_edited_from");
  3457. SIGNAL_DISCARD("caret_changed");
  3458. lines_edited_args = build_array(build_array(0, 1), build_array(0, 1));
  3459. SEND_GUI_ACTION("ui_text_newline_blank");
  3460. CHECK(text_edit->get_viewport()->is_input_handled());
  3461. CHECK(text_edit->get_text() == "test\n\n");
  3462. CHECK_FALSE(text_edit->has_selection(0));
  3463. CHECK(text_edit->get_caret_line(0) == 2);
  3464. CHECK(text_edit->get_caret_column(0) == 0);
  3465. CHECK_FALSE(text_edit->has_selection(1));
  3466. CHECK(text_edit->get_caret_line(1) == 1);
  3467. CHECK(text_edit->get_caret_column(1) == 0);
  3468. SIGNAL_CHECK("caret_changed", empty_signal_args);
  3469. SIGNAL_CHECK("text_changed", empty_signal_args);
  3470. SIGNAL_CHECK("lines_edited_from", lines_edited_args);
  3471. }
  3472. SUBCASE("[TextEdit] ui_text_newline") {
  3473. text_edit->set_text("this is some test text.\nthis is some test text.");
  3474. MessageQueue::get_singleton()->flush();
  3475. SIGNAL_DISCARD("text_set");
  3476. SIGNAL_DISCARD("text_changed");
  3477. SIGNAL_DISCARD("lines_edited_from");
  3478. SIGNAL_DISCARD("caret_changed");
  3479. // Insert new line at caret.
  3480. text_edit->select(0, 0, 0, 4);
  3481. text_edit->add_caret(1, 4);
  3482. CHECK(text_edit->get_caret_count() == 2);
  3483. MessageQueue::get_singleton()->flush();
  3484. SIGNAL_DISCARD("caret_changed");
  3485. // Lines edited: deletion, insert line, insert line.
  3486. lines_edited_args = build_array(build_array(0, 0), build_array(0, 1), build_array(2, 3));
  3487. SEND_GUI_ACTION("ui_text_newline");
  3488. CHECK(text_edit->get_viewport()->is_input_handled());
  3489. CHECK(text_edit->get_text() == "\n is some test text.\nthis\n is some test text.");
  3490. CHECK_FALSE(text_edit->has_selection(0));
  3491. CHECK(text_edit->get_caret_line(0) == 1);
  3492. CHECK(text_edit->get_caret_column(0) == 0);
  3493. CHECK_FALSE(text_edit->has_selection(1));
  3494. CHECK(text_edit->get_caret_line(1) == 3);
  3495. CHECK(text_edit->get_caret_column(1) == 0);
  3496. SIGNAL_CHECK("caret_changed", empty_signal_args);
  3497. SIGNAL_CHECK("text_changed", empty_signal_args);
  3498. SIGNAL_CHECK("lines_edited_from", lines_edited_args);
  3499. // Undo.
  3500. text_edit->undo();
  3501. MessageQueue::get_singleton()->flush();
  3502. CHECK(text_edit->get_text() == "this is some test text.\nthis is some test text.");
  3503. CHECK(text_edit->has_selection(0));
  3504. CHECK(text_edit->get_caret_line(0) == 0);
  3505. CHECK(text_edit->get_caret_column(0) == 4);
  3506. CHECK(text_edit->get_selection_origin_line(0) == 0);
  3507. CHECK(text_edit->get_selection_origin_column(0) == 0);
  3508. CHECK_FALSE(text_edit->has_selection(1));
  3509. CHECK(text_edit->get_caret_line(1) == 1);
  3510. CHECK(text_edit->get_caret_column(1) == 4);
  3511. SIGNAL_CHECK("caret_changed", empty_signal_args);
  3512. SIGNAL_CHECK("text_changed", empty_signal_args);
  3513. SIGNAL_CHECK("lines_edited_from", reverse_nested(lines_edited_args));
  3514. // Redo.
  3515. text_edit->redo();
  3516. MessageQueue::get_singleton()->flush();
  3517. CHECK(text_edit->get_text() == "\n is some test text.\nthis\n is some test text.");
  3518. CHECK_FALSE(text_edit->has_selection(0));
  3519. CHECK(text_edit->get_caret_line(0) == 1);
  3520. CHECK(text_edit->get_caret_column(0) == 0);
  3521. CHECK_FALSE(text_edit->has_selection(1));
  3522. CHECK(text_edit->get_caret_line(1) == 3);
  3523. CHECK(text_edit->get_caret_column(1) == 0);
  3524. SIGNAL_CHECK("caret_changed", empty_signal_args);
  3525. SIGNAL_CHECK("text_changed", empty_signal_args);
  3526. SIGNAL_CHECK("lines_edited_from", lines_edited_args);
  3527. // Does not work if not editable.
  3528. text_edit->set_editable(false);
  3529. SEND_GUI_ACTION("ui_text_newline");
  3530. CHECK(text_edit->get_viewport()->is_input_handled());
  3531. CHECK(text_edit->get_text() == "\n is some test text.\nthis\n is some test text.");
  3532. CHECK_FALSE(text_edit->has_selection(0));
  3533. CHECK(text_edit->get_caret_line(0) == 1);
  3534. CHECK(text_edit->get_caret_column(0) == 0);
  3535. CHECK_FALSE(text_edit->has_selection(1));
  3536. CHECK(text_edit->get_caret_line(1) == 3);
  3537. CHECK(text_edit->get_caret_column(1) == 0);
  3538. SIGNAL_CHECK_FALSE("caret_changed");
  3539. SIGNAL_CHECK_FALSE("text_changed");
  3540. SIGNAL_CHECK_FALSE("lines_edited_from");
  3541. text_edit->set_editable(true);
  3542. }
  3543. SUBCASE("[TextEdit] ui_text_backspace_all_to_left") {
  3544. Ref<InputEvent> tmpevent = InputEventKey::create_reference(Key::BACKSPACE | KeyModifierMask::ALT | KeyModifierMask::CMD_OR_CTRL);
  3545. InputMap::get_singleton()->action_add_event("ui_text_backspace_all_to_left", tmpevent);
  3546. text_edit->set_text("\nthis is some test text.\n\nthis is some test text.");
  3547. MessageQueue::get_singleton()->flush();
  3548. SIGNAL_DISCARD("text_set");
  3549. SIGNAL_DISCARD("text_changed");
  3550. SIGNAL_DISCARD("lines_edited_from");
  3551. SIGNAL_DISCARD("caret_changed");
  3552. // Remove all text to the left.
  3553. text_edit->set_caret_line(1);
  3554. text_edit->set_caret_column(5);
  3555. text_edit->add_caret(1, 2);
  3556. text_edit->add_caret(1, 8);
  3557. lines_edited_args = build_array(build_array(1, 1));
  3558. MessageQueue::get_singleton()->flush();
  3559. SIGNAL_DISCARD("caret_changed");
  3560. SEND_GUI_ACTION("ui_text_backspace_all_to_left");
  3561. CHECK(text_edit->get_viewport()->is_input_handled());
  3562. CHECK(text_edit->get_text() == "\nsome test text.\n\nthis is some test text.");
  3563. CHECK(text_edit->get_caret_count() == 1);
  3564. CHECK_FALSE(text_edit->has_selection());
  3565. CHECK(text_edit->get_caret_line() == 1);
  3566. CHECK(text_edit->get_caret_column() == 0);
  3567. SIGNAL_CHECK("caret_changed", empty_signal_args);
  3568. SIGNAL_CHECK("text_changed", empty_signal_args);
  3569. SIGNAL_CHECK("lines_edited_from", lines_edited_args);
  3570. // Undo.
  3571. text_edit->undo();
  3572. MessageQueue::get_singleton()->flush();
  3573. CHECK(text_edit->get_text() == "\nthis is some test text.\n\nthis is some test text.");
  3574. CHECK(text_edit->get_caret_count() == 3);
  3575. CHECK_FALSE(text_edit->has_selection(0));
  3576. CHECK(text_edit->get_caret_line(0) == 1);
  3577. CHECK(text_edit->get_caret_column(0) == 5);
  3578. CHECK_FALSE(text_edit->has_selection(1));
  3579. CHECK(text_edit->get_caret_line(1) == 1);
  3580. CHECK(text_edit->get_caret_column(1) == 2);
  3581. CHECK_FALSE(text_edit->has_selection(2));
  3582. CHECK(text_edit->get_caret_line(2) == 1);
  3583. CHECK(text_edit->get_caret_column(2) == 8);
  3584. SIGNAL_CHECK("caret_changed", empty_signal_args);
  3585. SIGNAL_CHECK("text_changed", empty_signal_args);
  3586. SIGNAL_CHECK("lines_edited_from", lines_edited_args);
  3587. // Redo.
  3588. text_edit->redo();
  3589. MessageQueue::get_singleton()->flush();
  3590. CHECK(text_edit->get_text() == "\nsome test text.\n\nthis is some test text.");
  3591. CHECK(text_edit->get_caret_count() == 1);
  3592. CHECK_FALSE(text_edit->has_selection());
  3593. CHECK(text_edit->get_caret_line() == 1);
  3594. CHECK(text_edit->get_caret_column() == 0);
  3595. SIGNAL_CHECK("caret_changed", empty_signal_args);
  3596. SIGNAL_CHECK("text_changed", empty_signal_args);
  3597. SIGNAL_CHECK("lines_edited_from", lines_edited_args);
  3598. // Acts as a normal backspace with selections.
  3599. text_edit->select(1, 5, 1, 9, 0);
  3600. text_edit->add_caret(3, 4);
  3601. text_edit->select(3, 7, 3, 4, 1);
  3602. MessageQueue::get_singleton()->flush();
  3603. SIGNAL_DISCARD("caret_changed");
  3604. lines_edited_args = build_array(build_array(3, 3), build_array(1, 1));
  3605. SEND_GUI_ACTION("ui_text_backspace_all_to_left");
  3606. CHECK(text_edit->get_viewport()->is_input_handled());
  3607. CHECK(text_edit->get_text() == "\nsome text.\n\nthis some test text.");
  3608. CHECK(text_edit->get_caret_count() == 2);
  3609. CHECK_FALSE(text_edit->has_selection(0));
  3610. CHECK(text_edit->get_caret_line(0) == 1);
  3611. CHECK(text_edit->get_caret_column(0) == 5);
  3612. CHECK_FALSE(text_edit->has_selection(1));
  3613. CHECK(text_edit->get_caret_line(1) == 3);
  3614. CHECK(text_edit->get_caret_column(1) == 4);
  3615. SIGNAL_CHECK("caret_changed", empty_signal_args);
  3616. SIGNAL_CHECK("text_changed", empty_signal_args);
  3617. SIGNAL_CHECK("lines_edited_from", lines_edited_args);
  3618. // Acts as a normal backspace when at the start of a line.
  3619. text_edit->set_caret_column(0);
  3620. text_edit->set_caret_column(0, false, 1);
  3621. MessageQueue::get_singleton()->flush();
  3622. SIGNAL_DISCARD("caret_changed");
  3623. lines_edited_args = build_array(build_array(3, 2), build_array(1, 0));
  3624. SEND_GUI_ACTION("ui_text_backspace_all_to_left");
  3625. CHECK(text_edit->get_viewport()->is_input_handled());
  3626. CHECK(text_edit->get_text() == "some text.\nthis some test text.");
  3627. CHECK(text_edit->get_caret_count() == 2);
  3628. CHECK_FALSE(text_edit->has_selection(0));
  3629. CHECK(text_edit->get_caret_line(0) == 0);
  3630. CHECK(text_edit->get_caret_column(0) == 0);
  3631. CHECK_FALSE(text_edit->has_selection(1));
  3632. CHECK(text_edit->get_caret_line(1) == 1);
  3633. CHECK(text_edit->get_caret_column(1) == 0);
  3634. SIGNAL_CHECK("caret_changed", empty_signal_args);
  3635. SIGNAL_CHECK("text_changed", empty_signal_args);
  3636. SIGNAL_CHECK("lines_edited_from", lines_edited_args);
  3637. // Does not work if not editable.
  3638. text_edit->set_caret_column(text_edit->get_line(0).length());
  3639. text_edit->set_caret_column(text_edit->get_line(1).length(), false, 1);
  3640. MessageQueue::get_singleton()->flush();
  3641. SIGNAL_DISCARD("caret_changed");
  3642. text_edit->set_editable(false);
  3643. SEND_GUI_ACTION("ui_text_backspace_all_to_left");
  3644. CHECK(text_edit->get_viewport()->is_input_handled());
  3645. CHECK(text_edit->get_text() == "some text.\nthis some test text.");
  3646. CHECK(text_edit->get_caret_count() == 2);
  3647. CHECK_FALSE(text_edit->has_selection(0));
  3648. CHECK(text_edit->get_caret_line(0) == 0);
  3649. CHECK(text_edit->get_caret_column(0) == text_edit->get_line(0).length());
  3650. CHECK_FALSE(text_edit->has_selection(1));
  3651. CHECK(text_edit->get_caret_line(1) == 1);
  3652. CHECK(text_edit->get_caret_column(1) == text_edit->get_line(1).length());
  3653. SIGNAL_CHECK_FALSE("caret_changed");
  3654. SIGNAL_CHECK_FALSE("text_changed");
  3655. SIGNAL_CHECK_FALSE("lines_edited_from");
  3656. text_edit->set_editable(true);
  3657. // Remove entire line content when at the end of the line.
  3658. lines_edited_args = build_array(build_array(1, 1), build_array(0, 0));
  3659. SEND_GUI_ACTION("ui_text_backspace_all_to_left");
  3660. CHECK(text_edit->get_viewport()->is_input_handled());
  3661. CHECK(text_edit->get_text() == "\n");
  3662. CHECK(text_edit->get_caret_count() == 2);
  3663. CHECK_FALSE(text_edit->has_selection(0));
  3664. CHECK(text_edit->get_caret_line(0) == 0);
  3665. CHECK(text_edit->get_caret_column(0) == 0);
  3666. CHECK_FALSE(text_edit->has_selection(1));
  3667. CHECK(text_edit->get_caret_line(1) == 1);
  3668. CHECK(text_edit->get_caret_column(1) == 0);
  3669. SIGNAL_CHECK("caret_changed", empty_signal_args);
  3670. SIGNAL_CHECK("text_changed", empty_signal_args);
  3671. SIGNAL_CHECK("lines_edited_from", lines_edited_args);
  3672. text_edit->remove_secondary_carets();
  3673. // Removing newline effectively happens after removing text.
  3674. text_edit->set_text("test\nlines");
  3675. text_edit->set_caret_line(1);
  3676. text_edit->set_caret_column(0);
  3677. text_edit->add_caret(1, 4);
  3678. SEND_GUI_ACTION("ui_text_backspace_all_to_left");
  3679. CHECK(text_edit->get_viewport()->is_input_handled());
  3680. CHECK_FALSE(text_edit->has_selection());
  3681. CHECK(text_edit->get_text() == "tests");
  3682. CHECK(text_edit->get_caret_count() == 1);
  3683. CHECK(text_edit->get_caret_line(0) == 0);
  3684. CHECK(text_edit->get_caret_column(0) == 4);
  3685. text_edit->remove_secondary_carets();
  3686. // Removing newline effectively happens after removing text, reverse caret order.
  3687. text_edit->set_text("test\nlines");
  3688. text_edit->set_caret_line(1);
  3689. text_edit->set_caret_column(4);
  3690. text_edit->add_caret(1, 0);
  3691. SEND_GUI_ACTION("ui_text_backspace_all_to_left");
  3692. CHECK(text_edit->get_viewport()->is_input_handled());
  3693. CHECK_FALSE(text_edit->has_selection());
  3694. CHECK(text_edit->get_text() == "tests");
  3695. CHECK(text_edit->get_caret_count() == 1);
  3696. CHECK(text_edit->get_caret_line(0) == 0);
  3697. CHECK(text_edit->get_caret_column(0) == 4);
  3698. text_edit->remove_secondary_carets();
  3699. InputMap::get_singleton()->action_erase_event("ui_text_backspace_all_to_left", tmpevent);
  3700. }
  3701. SUBCASE("[TextEdit] ui_text_backspace_word") {
  3702. text_edit->set_text("\nthis is some test text.\n\nthis is some test text.");
  3703. MessageQueue::get_singleton()->flush();
  3704. SIGNAL_DISCARD("text_set");
  3705. SIGNAL_DISCARD("text_changed");
  3706. SIGNAL_DISCARD("lines_edited_from");
  3707. // Acts as a normal backspace with selections.
  3708. text_edit->select(1, 8, 1, 15);
  3709. text_edit->add_caret(3, 6);
  3710. text_edit->select(3, 10, 3, 6, 1);
  3711. MessageQueue::get_singleton()->flush();
  3712. SIGNAL_DISCARD("caret_changed");
  3713. lines_edited_args = build_array(build_array(3, 3), build_array(1, 1));
  3714. SEND_GUI_ACTION("ui_text_backspace_word");
  3715. CHECK(text_edit->get_viewport()->is_input_handled());
  3716. CHECK(text_edit->get_text() == "\nthis is st text.\n\nthis ime test text.");
  3717. CHECK(text_edit->get_caret_count() == 2);
  3718. CHECK_FALSE(text_edit->has_selection(0));
  3719. CHECK(text_edit->get_caret_line(0) == 1);
  3720. CHECK(text_edit->get_caret_column(0) == 8);
  3721. CHECK_FALSE(text_edit->has_selection(1));
  3722. CHECK(text_edit->get_caret_line(1) == 3);
  3723. CHECK(text_edit->get_caret_column(1) == 6);
  3724. SIGNAL_CHECK("caret_changed", empty_signal_args);
  3725. SIGNAL_CHECK("text_changed", empty_signal_args);
  3726. SIGNAL_CHECK("lines_edited_from", lines_edited_args);
  3727. text_edit->end_complex_operation();
  3728. lines_edited_args = build_array(build_array(3, 2), build_array(1, 0));
  3729. // Start of line should also be a normal backspace.
  3730. text_edit->set_caret_column(0);
  3731. text_edit->set_caret_column(0, false, 1);
  3732. MessageQueue::get_singleton()->flush();
  3733. SIGNAL_DISCARD("caret_changed");
  3734. SEND_GUI_ACTION("ui_text_backspace_word");
  3735. CHECK(text_edit->get_viewport()->is_input_handled());
  3736. CHECK(text_edit->get_text() == "this is st text.\nthis ime test text.");
  3737. CHECK(text_edit->get_caret_count() == 2);
  3738. CHECK_FALSE(text_edit->has_selection(0));
  3739. CHECK(text_edit->get_caret_line(0) == 0);
  3740. CHECK(text_edit->get_caret_column(0) == 0);
  3741. CHECK_FALSE(text_edit->has_selection(1));
  3742. CHECK(text_edit->get_caret_line(1) == 1);
  3743. CHECK(text_edit->get_caret_column(1) == 0);
  3744. SIGNAL_CHECK("caret_changed", empty_signal_args);
  3745. SIGNAL_CHECK("text_changed", empty_signal_args);
  3746. SIGNAL_CHECK("lines_edited_from", lines_edited_args);
  3747. // Does not work if not editable.
  3748. text_edit->set_editable(false);
  3749. SEND_GUI_ACTION("ui_text_backspace_word");
  3750. CHECK(text_edit->get_viewport()->is_input_handled());
  3751. CHECK(text_edit->get_text() == "this is st text.\nthis ime test text.");
  3752. CHECK(text_edit->get_caret_count() == 2);
  3753. CHECK_FALSE(text_edit->has_selection(0));
  3754. CHECK(text_edit->get_caret_line(0) == 0);
  3755. CHECK(text_edit->get_caret_column(0) == 0);
  3756. CHECK_FALSE(text_edit->has_selection(1));
  3757. CHECK(text_edit->get_caret_line(1) == 1);
  3758. CHECK(text_edit->get_caret_column(1) == 0);
  3759. SIGNAL_CHECK_FALSE("caret_changed");
  3760. SIGNAL_CHECK_FALSE("text_changed");
  3761. SIGNAL_CHECK_FALSE("lines_edited_from");
  3762. text_edit->set_editable(true);
  3763. // FIXME: Remove after GH-77101 is fixed.
  3764. text_edit->start_action(TextEdit::ACTION_NONE);
  3765. // Remove text to the start of the word to the left of the caret.
  3766. text_edit->set_caret_column(text_edit->get_line(0).length());
  3767. text_edit->set_caret_column(12, false, 1);
  3768. MessageQueue::get_singleton()->flush();
  3769. SIGNAL_DISCARD("caret_changed");
  3770. lines_edited_args = build_array(build_array(1, 1), build_array(0, 0));
  3771. SEND_GUI_ACTION("ui_text_backspace_word");
  3772. CHECK(text_edit->get_viewport()->is_input_handled());
  3773. CHECK(text_edit->get_text() == "this is st \nthis ime t text.");
  3774. CHECK(text_edit->get_caret_count() == 2);
  3775. CHECK_FALSE(text_edit->has_selection(0));
  3776. CHECK(text_edit->get_caret_line(0) == 0);
  3777. CHECK(text_edit->get_caret_column(0) == 11);
  3778. CHECK_FALSE(text_edit->has_selection(1));
  3779. CHECK(text_edit->get_caret_line(1) == 1);
  3780. CHECK(text_edit->get_caret_column(1) == 9);
  3781. SIGNAL_CHECK("caret_changed", empty_signal_args);
  3782. SIGNAL_CHECK("text_changed", empty_signal_args);
  3783. SIGNAL_CHECK("lines_edited_from", lines_edited_args);
  3784. // Undo.
  3785. text_edit->undo();
  3786. MessageQueue::get_singleton()->flush();
  3787. CHECK(text_edit->get_text() == "this is st text.\nthis ime test text.");
  3788. CHECK(text_edit->get_caret_count() == 2);
  3789. CHECK_FALSE(text_edit->has_selection(0));
  3790. CHECK(text_edit->get_caret_line(0) == 0);
  3791. CHECK(text_edit->get_caret_column(0) == 16);
  3792. CHECK_FALSE(text_edit->has_selection(1));
  3793. CHECK(text_edit->get_caret_line(1) == 1);
  3794. CHECK(text_edit->get_caret_column(1) == 12);
  3795. SIGNAL_CHECK("caret_changed", empty_signal_args);
  3796. SIGNAL_CHECK("text_changed", empty_signal_args);
  3797. SIGNAL_CHECK("lines_edited_from", reverse_nested(lines_edited_args));
  3798. // Redo.
  3799. text_edit->redo();
  3800. MessageQueue::get_singleton()->flush();
  3801. CHECK(text_edit->get_text() == "this is st \nthis ime t text.");
  3802. CHECK(text_edit->get_caret_count() == 2);
  3803. CHECK_FALSE(text_edit->has_selection(0));
  3804. CHECK(text_edit->get_caret_line(0) == 0);
  3805. CHECK(text_edit->get_caret_column(0) == 11);
  3806. CHECK_FALSE(text_edit->has_selection(1));
  3807. CHECK(text_edit->get_caret_line(1) == 1);
  3808. CHECK(text_edit->get_caret_column(1) == 9);
  3809. SIGNAL_CHECK("caret_changed", empty_signal_args);
  3810. SIGNAL_CHECK("text_changed", empty_signal_args);
  3811. SIGNAL_CHECK("lines_edited_from", lines_edited_args);
  3812. // Removing newline effectively happens after removing text.
  3813. text_edit->set_text("test\nlines");
  3814. text_edit->set_caret_line(1);
  3815. text_edit->set_caret_column(0);
  3816. text_edit->add_caret(1, 4);
  3817. SEND_GUI_ACTION("ui_text_backspace_word");
  3818. CHECK(text_edit->get_viewport()->is_input_handled());
  3819. CHECK_FALSE(text_edit->has_selection());
  3820. CHECK(text_edit->get_text() == "tests");
  3821. CHECK(text_edit->get_caret_count() == 1);
  3822. CHECK(text_edit->get_caret_line(0) == 0);
  3823. CHECK(text_edit->get_caret_column(0) == 4);
  3824. text_edit->remove_secondary_carets();
  3825. // Removing newline effectively happens after removing text, reverse caret order.
  3826. text_edit->set_text("test\nlines");
  3827. text_edit->set_caret_line(1);
  3828. text_edit->set_caret_column(4);
  3829. text_edit->add_caret(1, 0);
  3830. SEND_GUI_ACTION("ui_text_backspace_word");
  3831. CHECK(text_edit->get_viewport()->is_input_handled());
  3832. CHECK_FALSE(text_edit->has_selection());
  3833. CHECK(text_edit->get_text() == "tests");
  3834. CHECK(text_edit->get_caret_count() == 1);
  3835. CHECK(text_edit->get_caret_line(0) == 0);
  3836. CHECK(text_edit->get_caret_column(0) == 4);
  3837. text_edit->remove_secondary_carets();
  3838. // Remove when there are no words, only symbols.
  3839. text_edit->set_text("#{}");
  3840. text_edit->set_caret_line(0);
  3841. text_edit->set_caret_column(3);
  3842. SEND_GUI_ACTION("ui_text_backspace_word");
  3843. CHECK(text_edit->get_viewport()->is_input_handled());
  3844. CHECK_FALSE(text_edit->has_selection());
  3845. CHECK(text_edit->get_text() == "");
  3846. CHECK(text_edit->get_caret_line(0) == 0);
  3847. CHECK(text_edit->get_caret_column(0) == 0);
  3848. }
  3849. SUBCASE("[TextEdit] ui_text_backspace_word same line") {
  3850. text_edit->set_text("test longwordtest test");
  3851. MessageQueue::get_singleton()->flush();
  3852. SIGNAL_DISCARD("text_set");
  3853. SIGNAL_DISCARD("text_changed");
  3854. SIGNAL_DISCARD("lines_edited_from");
  3855. SIGNAL_DISCARD("caret_changed");
  3856. // Multiple carets on the same line is handled.
  3857. text_edit->set_caret_line(0);
  3858. text_edit->set_caret_column(4);
  3859. text_edit->add_caret(0, 11);
  3860. text_edit->add_caret(0, 15);
  3861. text_edit->add_caret(0, 9);
  3862. MessageQueue::get_singleton()->flush();
  3863. SIGNAL_DISCARD("caret_changed");
  3864. lines_edited_args = build_array(build_array(0, 0), build_array(0, 0));
  3865. SEND_GUI_ACTION("ui_text_backspace_word");
  3866. CHECK(text_edit->get_viewport()->is_input_handled());
  3867. CHECK(text_edit->get_text() == " st test");
  3868. CHECK(text_edit->get_caret_count() == 2);
  3869. CHECK_FALSE(text_edit->has_selection(0));
  3870. CHECK(text_edit->get_caret_line(0) == 0);
  3871. CHECK(text_edit->get_caret_column(0) == 0);
  3872. CHECK_FALSE(text_edit->has_selection(1));
  3873. CHECK(text_edit->get_caret_line(1) == 0);
  3874. CHECK(text_edit->get_caret_column(1) == 1);
  3875. SIGNAL_CHECK("caret_changed", empty_signal_args);
  3876. SIGNAL_CHECK("text_changed", empty_signal_args);
  3877. SIGNAL_CHECK("lines_edited_from", lines_edited_args);
  3878. text_edit->undo();
  3879. MessageQueue::get_singleton()->flush();
  3880. CHECK(text_edit->get_text() == "test longwordtest test");
  3881. CHECK(text_edit->get_caret_count() == 4);
  3882. CHECK_FALSE(text_edit->has_selection(0));
  3883. CHECK(text_edit->get_caret_line(0) == 0);
  3884. CHECK(text_edit->get_caret_column(0) == 4);
  3885. CHECK_FALSE(text_edit->has_selection(1));
  3886. CHECK(text_edit->get_caret_line(1) == 0);
  3887. CHECK(text_edit->get_caret_column(1) == 11);
  3888. CHECK_FALSE(text_edit->has_selection(2));
  3889. CHECK(text_edit->get_caret_line(2) == 0);
  3890. CHECK(text_edit->get_caret_column(2) == 15);
  3891. CHECK_FALSE(text_edit->has_selection(3));
  3892. CHECK(text_edit->get_caret_line(3) == 0);
  3893. CHECK(text_edit->get_caret_column(3) == 9);
  3894. SIGNAL_CHECK("caret_changed", empty_signal_args);
  3895. SIGNAL_CHECK("text_changed", empty_signal_args);
  3896. SIGNAL_CHECK("lines_edited_from", reverse_nested(lines_edited_args));
  3897. text_edit->redo();
  3898. MessageQueue::get_singleton()->flush();
  3899. CHECK(text_edit->get_text() == " st test");
  3900. CHECK(text_edit->get_caret_count() == 2);
  3901. CHECK_FALSE(text_edit->has_selection(0));
  3902. CHECK(text_edit->get_caret_line(0) == 0);
  3903. CHECK(text_edit->get_caret_column(0) == 0);
  3904. CHECK_FALSE(text_edit->has_selection(1));
  3905. CHECK(text_edit->get_caret_line(1) == 0);
  3906. CHECK(text_edit->get_caret_column(1) == 1);
  3907. SIGNAL_CHECK("caret_changed", empty_signal_args);
  3908. SIGNAL_CHECK("text_changed", empty_signal_args);
  3909. SIGNAL_CHECK("lines_edited_from", lines_edited_args);
  3910. }
  3911. SUBCASE("[TextEdit] ui_text_backspace") {
  3912. text_edit->set_text("\nthis is some test text.\n\nthis is some test text.");
  3913. MessageQueue::get_singleton()->flush();
  3914. SIGNAL_DISCARD("text_set");
  3915. SIGNAL_DISCARD("text_changed");
  3916. SIGNAL_DISCARD("lines_edited_from");
  3917. // Remove selected text when there are selections.
  3918. text_edit->select(1, 0, 1, 4);
  3919. text_edit->add_caret(3, 4);
  3920. text_edit->select(3, 5, 3, 2, 1);
  3921. MessageQueue::get_singleton()->flush();
  3922. SIGNAL_DISCARD("caret_changed");
  3923. lines_edited_args = build_array(build_array(3, 3), build_array(1, 1));
  3924. SEND_GUI_ACTION("ui_text_backspace");
  3925. CHECK(text_edit->get_viewport()->is_input_handled());
  3926. CHECK(text_edit->get_text() == "\n is some test text.\n\nthis some test text.");
  3927. CHECK(text_edit->get_caret_count() == 2);
  3928. CHECK_FALSE(text_edit->has_selection(0));
  3929. CHECK(text_edit->get_caret_line(0) == 1);
  3930. CHECK(text_edit->get_caret_column(0) == 0);
  3931. CHECK_FALSE(text_edit->has_selection(1));
  3932. CHECK(text_edit->get_caret_line(1) == 3);
  3933. CHECK(text_edit->get_caret_column(1) == 2);
  3934. SIGNAL_CHECK("caret_changed", empty_signal_args);
  3935. SIGNAL_CHECK("text_changed", empty_signal_args);
  3936. SIGNAL_CHECK("lines_edited_from", lines_edited_args);
  3937. // Undo remove selection.
  3938. text_edit->undo();
  3939. MessageQueue::get_singleton()->flush();
  3940. CHECK(text_edit->get_caret_count() == 2);
  3941. CHECK(text_edit->get_text() == "\nthis is some test text.\n\nthis is some test text.");
  3942. CHECK(text_edit->get_caret_count() == 2);
  3943. CHECK(text_edit->has_selection(0));
  3944. CHECK(text_edit->get_caret_line(0) == 1);
  3945. CHECK(text_edit->get_caret_column(0) == 4);
  3946. CHECK(text_edit->get_selection_origin_line(0) == 1);
  3947. CHECK(text_edit->get_selection_origin_column(0) == 0);
  3948. CHECK(text_edit->has_selection(1));
  3949. CHECK(text_edit->get_caret_line(1) == 3);
  3950. CHECK(text_edit->get_caret_column(1) == 2);
  3951. CHECK(text_edit->get_selection_origin_line(1) == 3);
  3952. CHECK(text_edit->get_selection_origin_column(1) == 5);
  3953. SIGNAL_CHECK("caret_changed", empty_signal_args);
  3954. SIGNAL_CHECK("text_changed", empty_signal_args);
  3955. SIGNAL_CHECK("lines_edited_from", reverse_nested(lines_edited_args));
  3956. // Redo remove selection.
  3957. text_edit->redo();
  3958. MessageQueue::get_singleton()->flush();
  3959. CHECK(text_edit->get_text() == "\n is some test text.\n\nthis some test text.");
  3960. CHECK(text_edit->get_caret_count() == 2);
  3961. CHECK_FALSE(text_edit->has_selection(0));
  3962. CHECK(text_edit->get_caret_line(0) == 1);
  3963. CHECK(text_edit->get_caret_column(0) == 0);
  3964. CHECK_FALSE(text_edit->has_selection(1));
  3965. CHECK(text_edit->get_caret_line(1) == 3);
  3966. CHECK(text_edit->get_caret_column(1) == 2);
  3967. SIGNAL_CHECK("caret_changed", empty_signal_args);
  3968. SIGNAL_CHECK("text_changed", empty_signal_args);
  3969. SIGNAL_CHECK("lines_edited_from", lines_edited_args);
  3970. // Remove the newline when at start of line.
  3971. text_edit->set_caret_column(0, false, 1);
  3972. MessageQueue::get_singleton()->flush();
  3973. SIGNAL_DISCARD("caret_changed");
  3974. lines_edited_args = build_array(build_array(3, 2), build_array(1, 0));
  3975. SEND_GUI_ACTION("ui_text_backspace");
  3976. CHECK(text_edit->get_viewport()->is_input_handled());
  3977. CHECK(text_edit->get_text() == " is some test text.\nthis some test text.");
  3978. CHECK(text_edit->get_caret_count() == 2);
  3979. CHECK_FALSE(text_edit->has_selection(0));
  3980. CHECK(text_edit->get_caret_line(0) == 0);
  3981. CHECK(text_edit->get_caret_column(0) == 0);
  3982. CHECK_FALSE(text_edit->has_selection(1));
  3983. CHECK(text_edit->get_caret_line(1) == 1);
  3984. CHECK(text_edit->get_caret_column(1) == 0);
  3985. SIGNAL_CHECK("caret_changed", empty_signal_args);
  3986. SIGNAL_CHECK("text_changed", empty_signal_args);
  3987. SIGNAL_CHECK("lines_edited_from", lines_edited_args);
  3988. // Undo remove newline.
  3989. text_edit->undo();
  3990. MessageQueue::get_singleton()->flush();
  3991. CHECK(text_edit->get_text() == "\n is some test text.\n\nthis some test text.");
  3992. CHECK(text_edit->get_caret_count() == 2);
  3993. CHECK_FALSE(text_edit->has_selection(0));
  3994. CHECK(text_edit->get_caret_line(0) == 1);
  3995. CHECK(text_edit->get_caret_column(0) == 0);
  3996. CHECK_FALSE(text_edit->has_selection(1));
  3997. CHECK(text_edit->get_caret_line(1) == 3);
  3998. CHECK(text_edit->get_caret_column(1) == 0);
  3999. SIGNAL_CHECK("caret_changed", empty_signal_args);
  4000. SIGNAL_CHECK("text_changed", empty_signal_args);
  4001. SIGNAL_CHECK("lines_edited_from", reverse_nested(lines_edited_args));
  4002. // Redo remove newline.
  4003. text_edit->redo();
  4004. MessageQueue::get_singleton()->flush();
  4005. CHECK(text_edit->get_text() == " is some test text.\nthis some test text.");
  4006. CHECK(text_edit->get_caret_count() == 2);
  4007. CHECK_FALSE(text_edit->has_selection(0));
  4008. CHECK(text_edit->get_caret_line(0) == 0);
  4009. CHECK(text_edit->get_caret_column(0) == 0);
  4010. CHECK_FALSE(text_edit->has_selection(1));
  4011. CHECK(text_edit->get_caret_line(1) == 1);
  4012. CHECK(text_edit->get_caret_column(1) == 0);
  4013. SIGNAL_CHECK("caret_changed", empty_signal_args);
  4014. SIGNAL_CHECK("text_changed", empty_signal_args);
  4015. SIGNAL_CHECK("lines_edited_from", lines_edited_args);
  4016. // Does not work if not editable.
  4017. text_edit->set_caret_column(text_edit->get_line(0).length());
  4018. text_edit->set_caret_column(15, false, 1);
  4019. MessageQueue::get_singleton()->flush();
  4020. SIGNAL_DISCARD("caret_changed");
  4021. text_edit->set_editable(false);
  4022. SEND_GUI_ACTION("ui_text_backspace");
  4023. CHECK(text_edit->get_viewport()->is_input_handled());
  4024. CHECK(text_edit->get_text() == " is some test text.\nthis some test text.");
  4025. CHECK(text_edit->get_caret_count() == 2);
  4026. CHECK_FALSE(text_edit->has_selection(0));
  4027. CHECK(text_edit->get_caret_line(0) == 0);
  4028. CHECK(text_edit->get_caret_column(0) == text_edit->get_line(0).length());
  4029. CHECK_FALSE(text_edit->has_selection(1));
  4030. CHECK(text_edit->get_caret_line(1) == 1);
  4031. CHECK(text_edit->get_caret_column(1) == 15);
  4032. SIGNAL_CHECK_FALSE("caret_changed");
  4033. SIGNAL_CHECK_FALSE("text_changed");
  4034. SIGNAL_CHECK_FALSE("lines_edited_from");
  4035. text_edit->set_editable(true);
  4036. // FIXME: Remove after GH-77101 is fixed.
  4037. text_edit->start_action(TextEdit::ACTION_NONE);
  4038. // Backspace removes character to the left.
  4039. lines_edited_args = build_array(build_array(1, 1), build_array(0, 0));
  4040. SEND_GUI_ACTION("ui_text_backspace");
  4041. CHECK(text_edit->get_viewport()->is_input_handled());
  4042. CHECK(text_edit->get_text() == " is some test text\nthis some testtext.");
  4043. CHECK(text_edit->get_caret_count() == 2);
  4044. CHECK_FALSE(text_edit->has_selection(0));
  4045. CHECK(text_edit->get_caret_line(0) == 0);
  4046. CHECK(text_edit->get_caret_column(0) == 18);
  4047. CHECK_FALSE(text_edit->has_selection(1));
  4048. CHECK(text_edit->get_caret_line(1) == 1);
  4049. CHECK(text_edit->get_caret_column(1) == 14);
  4050. SIGNAL_CHECK("caret_changed", empty_signal_args);
  4051. SIGNAL_CHECK("text_changed", empty_signal_args);
  4052. SIGNAL_CHECK("lines_edited_from", lines_edited_args);
  4053. // Backspace another character without changing caret.
  4054. SEND_GUI_ACTION("ui_text_backspace");
  4055. CHECK(text_edit->get_viewport()->is_input_handled());
  4056. CHECK(text_edit->get_text() == " is some test tex\nthis some testext.");
  4057. CHECK(text_edit->get_caret_count() == 2);
  4058. CHECK_FALSE(text_edit->has_selection(0));
  4059. CHECK(text_edit->get_caret_line(0) == 0);
  4060. CHECK(text_edit->get_caret_column(0) == 17);
  4061. CHECK_FALSE(text_edit->has_selection(1));
  4062. CHECK(text_edit->get_caret_line(1) == 1);
  4063. CHECK(text_edit->get_caret_column(1) == 13);
  4064. SIGNAL_CHECK("caret_changed", empty_signal_args);
  4065. SIGNAL_CHECK("text_changed", empty_signal_args);
  4066. SIGNAL_CHECK("lines_edited_from", lines_edited_args);
  4067. // Undo both backspaces.
  4068. lines_edited_args = build_array(build_array(1, 1), build_array(0, 0), build_array(1, 1), build_array(0, 0));
  4069. text_edit->undo();
  4070. MessageQueue::get_singleton()->flush();
  4071. CHECK(text_edit->get_text() == " is some test text.\nthis some test text.");
  4072. CHECK(text_edit->get_caret_count() == 2);
  4073. CHECK_FALSE(text_edit->has_selection(0));
  4074. CHECK(text_edit->get_caret_line(0) == 0);
  4075. CHECK(text_edit->get_caret_column(0) == 19);
  4076. CHECK_FALSE(text_edit->has_selection(1));
  4077. CHECK(text_edit->get_caret_line(1) == 1);
  4078. CHECK(text_edit->get_caret_column(1) == 15);
  4079. SIGNAL_CHECK("caret_changed", empty_signal_args);
  4080. SIGNAL_CHECK("text_changed", empty_signal_args);
  4081. SIGNAL_CHECK("lines_edited_from", reverse_nested(lines_edited_args));
  4082. // Redo both backspaces.
  4083. text_edit->redo();
  4084. MessageQueue::get_singleton()->flush();
  4085. CHECK(text_edit->get_text() == " is some test tex\nthis some testext.");
  4086. CHECK(text_edit->get_caret_count() == 2);
  4087. CHECK_FALSE(text_edit->has_selection(0));
  4088. CHECK(text_edit->get_caret_line(0) == 0);
  4089. CHECK(text_edit->get_caret_column(0) == 17);
  4090. CHECK_FALSE(text_edit->has_selection(1));
  4091. CHECK(text_edit->get_caret_line(1) == 1);
  4092. CHECK(text_edit->get_caret_column(1) == 13);
  4093. SIGNAL_CHECK("caret_changed", empty_signal_args);
  4094. SIGNAL_CHECK("text_changed", empty_signal_args);
  4095. SIGNAL_CHECK("lines_edited_from", lines_edited_args);
  4096. // Backspace with multiple carets that will overlap.
  4097. text_edit->remove_secondary_carets();
  4098. text_edit->set_caret_line(0);
  4099. text_edit->set_caret_column(8);
  4100. text_edit->add_caret(0, 7);
  4101. text_edit->add_caret(0, 9);
  4102. MessageQueue::get_singleton()->flush();
  4103. SIGNAL_DISCARD("caret_changed");
  4104. lines_edited_args = build_array(build_array(0, 0), build_array(0, 0), build_array(0, 0));
  4105. SEND_GUI_ACTION("ui_text_backspace");
  4106. CHECK(text_edit->get_viewport()->is_input_handled());
  4107. CHECK(text_edit->get_text() == " is sotest tex\nthis some testext.");
  4108. CHECK(text_edit->get_caret_count() == 1);
  4109. CHECK_FALSE(text_edit->has_selection());
  4110. CHECK(text_edit->get_caret_line() == 0);
  4111. CHECK(text_edit->get_caret_column() == 6);
  4112. SIGNAL_CHECK("caret_changed", empty_signal_args);
  4113. SIGNAL_CHECK("text_changed", empty_signal_args);
  4114. SIGNAL_CHECK("lines_edited_from", lines_edited_args);
  4115. // Select each line of text, from right to left. Remove selection to column 0.
  4116. text_edit->select(0, text_edit->get_line(0).length(), 0, 0);
  4117. text_edit->add_caret(1, 0);
  4118. text_edit->select(1, text_edit->get_line(1).length(), 1, 0, 1);
  4119. MessageQueue::get_singleton()->flush();
  4120. SIGNAL_DISCARD("caret_changed");
  4121. lines_edited_args = build_array(build_array(1, 1), build_array(0, 0));
  4122. SEND_GUI_ACTION("ui_text_backspace");
  4123. CHECK(text_edit->get_text() == "\n");
  4124. CHECK(text_edit->get_caret_count() == 2);
  4125. CHECK_FALSE(text_edit->has_selection(0));
  4126. CHECK(text_edit->get_caret_line(0) == 0);
  4127. CHECK(text_edit->get_caret_column(0) == 0);
  4128. CHECK_FALSE(text_edit->has_selection(1));
  4129. CHECK(text_edit->get_caret_line(1) == 1);
  4130. CHECK(text_edit->get_caret_column(1) == 0);
  4131. SIGNAL_CHECK_FALSE("caret_changed");
  4132. SIGNAL_CHECK("text_changed", empty_signal_args);
  4133. SIGNAL_CHECK("lines_edited_from", lines_edited_args);
  4134. // Backspace at start of first line does nothing.
  4135. text_edit->remove_secondary_carets();
  4136. text_edit->deselect();
  4137. text_edit->set_caret_line(0);
  4138. text_edit->set_caret_column(0);
  4139. MessageQueue::get_singleton()->flush();
  4140. SIGNAL_DISCARD("caret_changed");
  4141. SEND_GUI_ACTION("ui_text_backspace");
  4142. CHECK(text_edit->get_viewport()->is_input_handled());
  4143. CHECK(text_edit->get_text() == "\n");
  4144. CHECK(text_edit->get_caret_count() == 1);
  4145. CHECK_FALSE(text_edit->has_selection());
  4146. CHECK(text_edit->get_caret_line() == 0);
  4147. CHECK(text_edit->get_caret_column() == 0);
  4148. SIGNAL_CHECK_FALSE("caret_changed");
  4149. SIGNAL_CHECK_FALSE("text_changed");
  4150. SIGNAL_CHECK_FALSE("lines_edited_from");
  4151. }
  4152. SUBCASE("[TextEdit] ui_text_delete_all_to_right") {
  4153. Ref<InputEvent> tmpevent = InputEventKey::create_reference(Key::BACKSPACE | KeyModifierMask::ALT | KeyModifierMask::CMD_OR_CTRL);
  4154. InputMap::get_singleton()->action_add_event("ui_text_delete_all_to_right", tmpevent);
  4155. text_edit->set_text("this is some test text.\nthis is some test text.\n");
  4156. MessageQueue::get_singleton()->flush();
  4157. SIGNAL_DISCARD("text_set");
  4158. SIGNAL_DISCARD("text_changed");
  4159. SIGNAL_DISCARD("lines_edited_from");
  4160. // Remove all text to right of caret.
  4161. text_edit->set_caret_line(0);
  4162. text_edit->set_caret_column(18);
  4163. text_edit->add_caret(0, 16);
  4164. text_edit->add_caret(0, 20);
  4165. MessageQueue::get_singleton()->flush();
  4166. SIGNAL_DISCARD("caret_changed");
  4167. lines_edited_args = build_array(build_array(0, 0));
  4168. SEND_GUI_ACTION("ui_text_delete_all_to_right");
  4169. CHECK(text_edit->get_viewport()->is_input_handled());
  4170. CHECK(text_edit->get_text() == "this is some tes\nthis is some test text.\n");
  4171. CHECK(text_edit->get_caret_count() == 1);
  4172. CHECK_FALSE(text_edit->has_selection(0));
  4173. CHECK(text_edit->get_caret_line(0) == 0);
  4174. CHECK(text_edit->get_caret_column(0) == 16);
  4175. SIGNAL_CHECK("caret_changed", empty_signal_args);
  4176. SIGNAL_CHECK("text_changed", empty_signal_args);
  4177. SIGNAL_CHECK("lines_edited_from", lines_edited_args);
  4178. // Undo.
  4179. lines_edited_args = build_array(build_array(0, 0));
  4180. text_edit->undo();
  4181. MessageQueue::get_singleton()->flush();
  4182. CHECK(text_edit->get_text() == "this is some test text.\nthis is some test text.\n");
  4183. CHECK(text_edit->get_caret_count() == 3);
  4184. CHECK_FALSE(text_edit->has_selection(0));
  4185. CHECK(text_edit->get_caret_line(0) == 0);
  4186. CHECK(text_edit->get_caret_column(0) == 18);
  4187. CHECK_FALSE(text_edit->has_selection(1));
  4188. CHECK(text_edit->get_caret_line(1) == 0);
  4189. CHECK(text_edit->get_caret_column(1) == 16);
  4190. CHECK_FALSE(text_edit->has_selection(2));
  4191. CHECK(text_edit->get_caret_line(2) == 0);
  4192. CHECK(text_edit->get_caret_column(2) == 20);
  4193. SIGNAL_CHECK("caret_changed", empty_signal_args);
  4194. SIGNAL_CHECK("text_changed", empty_signal_args);
  4195. SIGNAL_CHECK("lines_edited_from", lines_edited_args);
  4196. // Redo.
  4197. text_edit->redo();
  4198. MessageQueue::get_singleton()->flush();
  4199. CHECK(text_edit->get_text() == "this is some tes\nthis is some test text.\n");
  4200. CHECK(text_edit->get_caret_count() == 1);
  4201. CHECK_FALSE(text_edit->has_selection(0));
  4202. CHECK(text_edit->get_caret_line(0) == 0);
  4203. CHECK(text_edit->get_caret_column(0) == 16);
  4204. SIGNAL_CHECK("caret_changed", empty_signal_args);
  4205. SIGNAL_CHECK("text_changed", empty_signal_args);
  4206. SIGNAL_CHECK("lines_edited_from", lines_edited_args);
  4207. // Acts as a normal delete with selections.
  4208. text_edit->select(0, 0, 0, 4);
  4209. text_edit->add_caret(1, 4);
  4210. text_edit->select(1, 8, 1, 4, 1);
  4211. MessageQueue::get_singleton()->flush();
  4212. SIGNAL_DISCARD("caret_changed");
  4213. lines_edited_args = build_array(build_array(0, 0), build_array(1, 1));
  4214. SEND_GUI_ACTION("ui_text_delete_all_to_right");
  4215. CHECK(text_edit->get_viewport()->is_input_handled());
  4216. CHECK(text_edit->get_text() == " is some tes\nthissome test text.\n");
  4217. CHECK(text_edit->get_caret_count() == 2);
  4218. CHECK_FALSE(text_edit->has_selection(0));
  4219. CHECK(text_edit->get_caret_line(0) == 0);
  4220. CHECK(text_edit->get_caret_column(0) == 0);
  4221. CHECK_FALSE(text_edit->has_selection(1));
  4222. CHECK(text_edit->get_caret_line(1) == 1);
  4223. CHECK(text_edit->get_caret_column(1) == 4);
  4224. SIGNAL_CHECK("caret_changed", empty_signal_args);
  4225. SIGNAL_CHECK("text_changed", empty_signal_args);
  4226. SIGNAL_CHECK("lines_edited_from", lines_edited_args);
  4227. // Does nothing when caret is at end of line.
  4228. text_edit->set_caret_column(text_edit->get_line(0).length());
  4229. text_edit->set_caret_column(text_edit->get_line(1).length(), false, 1);
  4230. MessageQueue::get_singleton()->flush();
  4231. SIGNAL_DISCARD("caret_changed");
  4232. SEND_GUI_ACTION("ui_text_delete_all_to_right");
  4233. CHECK(text_edit->get_viewport()->is_input_handled());
  4234. CHECK(text_edit->get_text() == " is some tes\nthissome test text.\n");
  4235. CHECK(text_edit->get_caret_count() == 2);
  4236. CHECK_FALSE(text_edit->has_selection(0));
  4237. CHECK(text_edit->get_caret_line(0) == 0);
  4238. CHECK(text_edit->get_caret_column(0) == text_edit->get_line(0).length());
  4239. CHECK_FALSE(text_edit->has_selection(1));
  4240. CHECK(text_edit->get_caret_line(1) == 1);
  4241. CHECK(text_edit->get_caret_column(1) == text_edit->get_line(1).length());
  4242. SIGNAL_CHECK_FALSE("caret_changed");
  4243. SIGNAL_CHECK_FALSE("text_changed");
  4244. SIGNAL_CHECK_FALSE("lines_edited_from");
  4245. // Does not work if not editable.
  4246. text_edit->set_caret_column(0);
  4247. text_edit->set_caret_column(0, false, 1);
  4248. MessageQueue::get_singleton()->flush();
  4249. SIGNAL_DISCARD("caret_changed");
  4250. text_edit->set_editable(false);
  4251. SEND_GUI_ACTION("ui_text_delete_all_to_right");
  4252. CHECK(text_edit->get_viewport()->is_input_handled());
  4253. CHECK(text_edit->get_text() == " is some tes\nthissome test text.\n");
  4254. CHECK(text_edit->get_caret_count() == 2);
  4255. CHECK_FALSE(text_edit->has_selection(0));
  4256. CHECK(text_edit->get_caret_line(0) == 0);
  4257. CHECK(text_edit->get_caret_column(0) == 0);
  4258. CHECK_FALSE(text_edit->has_selection(1));
  4259. CHECK(text_edit->get_caret_line(1) == 1);
  4260. CHECK(text_edit->get_caret_column(1) == 0);
  4261. SIGNAL_CHECK_FALSE("caret_changed");
  4262. SIGNAL_CHECK_FALSE("text_changed");
  4263. SIGNAL_CHECK_FALSE("lines_edited_from");
  4264. text_edit->set_editable(true);
  4265. // Delete entire line.
  4266. SEND_GUI_ACTION("ui_text_delete_all_to_right");
  4267. CHECK(text_edit->get_viewport()->is_input_handled());
  4268. CHECK(text_edit->get_text() == "\n\n");
  4269. CHECK(text_edit->get_caret_count() == 2);
  4270. CHECK_FALSE(text_edit->has_selection(0));
  4271. CHECK(text_edit->get_caret_line(0) == 0);
  4272. CHECK(text_edit->get_caret_column(0) == 0);
  4273. CHECK_FALSE(text_edit->has_selection(1));
  4274. CHECK(text_edit->get_caret_line(1) == 1);
  4275. CHECK(text_edit->get_caret_column(1) == 0);
  4276. SIGNAL_CHECK_FALSE("caret_changed");
  4277. SIGNAL_CHECK("text_changed", empty_signal_args);
  4278. SIGNAL_CHECK("lines_edited_from", lines_edited_args);
  4279. InputMap::get_singleton()->action_erase_event("ui_text_delete_all_to_right", tmpevent);
  4280. }
  4281. SUBCASE("[TextEdit] ui_text_delete_word") {
  4282. text_edit->set_caret_mid_grapheme_enabled(true);
  4283. CHECK(text_edit->is_caret_mid_grapheme_enabled());
  4284. text_edit->set_text("this is some test text.\n\nthis is some test text.\n");
  4285. MessageQueue::get_singleton()->flush();
  4286. SIGNAL_DISCARD("text_set");
  4287. SIGNAL_DISCARD("text_changed");
  4288. SIGNAL_DISCARD("lines_edited_from");
  4289. SIGNAL_DISCARD("caret_changed");
  4290. // Acts as a normal delete with selections.
  4291. text_edit->select(0, 8, 0, 15);
  4292. text_edit->add_caret(2, 6);
  4293. text_edit->select(2, 10, 2, 6, 1);
  4294. MessageQueue::get_singleton()->flush();
  4295. SIGNAL_DISCARD("caret_changed");
  4296. lines_edited_args = build_array(build_array(0, 0), build_array(2, 2));
  4297. SEND_GUI_ACTION("ui_text_delete_word");
  4298. CHECK(text_edit->get_viewport()->is_input_handled());
  4299. CHECK(text_edit->get_text() == "this is st text.\n\nthis ime test text.\n");
  4300. CHECK(text_edit->get_caret_count() == 2);
  4301. CHECK_FALSE(text_edit->has_selection(0));
  4302. CHECK(text_edit->get_caret_line(0) == 0);
  4303. CHECK(text_edit->get_caret_column(0) == 8);
  4304. CHECK_FALSE(text_edit->has_selection(1));
  4305. CHECK(text_edit->get_caret_line(1) == 2);
  4306. CHECK(text_edit->get_caret_column(1) == 6);
  4307. SIGNAL_CHECK("caret_changed", empty_signal_args);
  4308. SIGNAL_CHECK("text_changed", empty_signal_args);
  4309. SIGNAL_CHECK("lines_edited_from", lines_edited_args);
  4310. // Removes newlines when at end of line.
  4311. text_edit->set_caret_column(text_edit->get_line(0).length());
  4312. text_edit->set_caret_column(text_edit->get_line(2).length(), false, 1);
  4313. MessageQueue::get_singleton()->flush();
  4314. SIGNAL_DISCARD("caret_changed");
  4315. lines_edited_args = build_array(build_array(1, 0), build_array(2, 1));
  4316. SEND_GUI_ACTION("ui_text_delete_word");
  4317. CHECK(text_edit->get_viewport()->is_input_handled());
  4318. CHECK(text_edit->get_text() == "this is st text.\nthis ime test text.");
  4319. CHECK(text_edit->get_caret_count() == 2);
  4320. CHECK_FALSE(text_edit->has_selection(0));
  4321. CHECK(text_edit->get_caret_line(0) == 0);
  4322. CHECK(text_edit->get_caret_column(0) == text_edit->get_line(0).length());
  4323. CHECK_FALSE(text_edit->has_selection(1));
  4324. CHECK(text_edit->get_caret_line(1) == 1);
  4325. CHECK(text_edit->get_caret_column(1) == text_edit->get_line(1).length());
  4326. SIGNAL_CHECK("caret_changed", empty_signal_args);
  4327. SIGNAL_CHECK("text_changed", empty_signal_args);
  4328. SIGNAL_CHECK("lines_edited_from", lines_edited_args);
  4329. // Does not work if not editable.
  4330. text_edit->set_caret_column(0);
  4331. text_edit->set_caret_column(10, false, 1);
  4332. MessageQueue::get_singleton()->flush();
  4333. SIGNAL_DISCARD("caret_changed");
  4334. text_edit->set_editable(false);
  4335. SEND_GUI_ACTION("ui_text_delete_word");
  4336. CHECK(text_edit->get_viewport()->is_input_handled());
  4337. CHECK(text_edit->get_text() == "this is st text.\nthis ime test text.");
  4338. CHECK(text_edit->get_caret_count() == 2);
  4339. CHECK_FALSE(text_edit->has_selection(0));
  4340. CHECK(text_edit->get_caret_line(0) == 0);
  4341. CHECK(text_edit->get_caret_column(0) == 0);
  4342. CHECK_FALSE(text_edit->has_selection(1));
  4343. CHECK(text_edit->get_caret_line(1) == 1);
  4344. CHECK(text_edit->get_caret_column(1) == 10);
  4345. SIGNAL_CHECK_FALSE("caret_changed");
  4346. SIGNAL_CHECK_FALSE("text_changed");
  4347. SIGNAL_CHECK_FALSE("lines_edited_from");
  4348. text_edit->set_editable(true);
  4349. // FIXME: Remove after GH-77101 is fixed.
  4350. text_edit->start_action(TextEdit::ACTION_NONE);
  4351. // Delete to the end of the word right of the caret.
  4352. lines_edited_args = build_array(build_array(0, 0), build_array(1, 1));
  4353. SEND_GUI_ACTION("ui_text_delete_word");
  4354. CHECK(text_edit->get_viewport()->is_input_handled());
  4355. CHECK(text_edit->get_text() == " is st text.\nthis ime t text.");
  4356. CHECK(text_edit->get_caret_count() == 2);
  4357. CHECK_FALSE(text_edit->has_selection(0));
  4358. CHECK(text_edit->get_caret_line(0) == 0);
  4359. CHECK(text_edit->get_caret_column(0) == 0);
  4360. CHECK_FALSE(text_edit->has_selection(1));
  4361. CHECK(text_edit->get_caret_line(1) == 1);
  4362. CHECK(text_edit->get_caret_column(1) == 10);
  4363. SIGNAL_CHECK_FALSE("caret_changed");
  4364. SIGNAL_CHECK("text_changed", empty_signal_args);
  4365. SIGNAL_CHECK("lines_edited_from", lines_edited_args);
  4366. // Undo.
  4367. text_edit->undo();
  4368. MessageQueue::get_singleton()->flush();
  4369. CHECK(text_edit->get_text() == "this is st text.\nthis ime test text.");
  4370. CHECK(text_edit->get_caret_count() == 2);
  4371. CHECK_FALSE(text_edit->has_selection(0));
  4372. CHECK(text_edit->get_caret_line(0) == 0);
  4373. CHECK(text_edit->get_caret_column(0) == 0);
  4374. CHECK_FALSE(text_edit->has_selection(1));
  4375. CHECK(text_edit->get_caret_line(1) == 1);
  4376. CHECK(text_edit->get_caret_column(1) == 10);
  4377. SIGNAL_CHECK_FALSE("caret_changed");
  4378. SIGNAL_CHECK("text_changed", empty_signal_args);
  4379. SIGNAL_CHECK("lines_edited_from", reverse_nested(lines_edited_args));
  4380. // Redo.
  4381. text_edit->redo();
  4382. MessageQueue::get_singleton()->flush();
  4383. CHECK(text_edit->get_text() == " is st text.\nthis ime t text.");
  4384. CHECK(text_edit->get_caret_count() == 2);
  4385. CHECK_FALSE(text_edit->has_selection(0));
  4386. CHECK(text_edit->get_caret_line(0) == 0);
  4387. CHECK(text_edit->get_caret_column(0) == 0);
  4388. CHECK_FALSE(text_edit->has_selection(1));
  4389. CHECK(text_edit->get_caret_line(1) == 1);
  4390. CHECK(text_edit->get_caret_column(1) == 10);
  4391. SIGNAL_CHECK_FALSE("caret_changed");
  4392. SIGNAL_CHECK("text_changed", empty_signal_args);
  4393. SIGNAL_CHECK("lines_edited_from", lines_edited_args);
  4394. // Delete one word with multiple carets.
  4395. text_edit->remove_secondary_carets();
  4396. text_edit->set_text("onelongword test");
  4397. text_edit->set_caret_line(0);
  4398. text_edit->set_caret_column(6);
  4399. text_edit->add_caret(0, 9);
  4400. text_edit->add_caret(0, 3);
  4401. lines_edited_args = build_array(build_array(0, 0));
  4402. MessageQueue::get_singleton()->flush();
  4403. SIGNAL_DISCARD("text_set");
  4404. SIGNAL_DISCARD("text_changed");
  4405. SIGNAL_DISCARD("lines_edited_from");
  4406. SIGNAL_DISCARD("caret_changed");
  4407. SEND_GUI_ACTION("ui_text_delete_word");
  4408. CHECK(text_edit->get_viewport()->is_input_handled());
  4409. CHECK(text_edit->get_text() == "one test");
  4410. CHECK(text_edit->get_caret_count() == 1);
  4411. CHECK_FALSE(text_edit->has_selection(0));
  4412. CHECK(text_edit->get_caret_line(0) == 0);
  4413. CHECK(text_edit->get_caret_column(0) == 3);
  4414. SIGNAL_CHECK("caret_changed", empty_signal_args);
  4415. SIGNAL_CHECK("text_changed", empty_signal_args);
  4416. SIGNAL_CHECK("lines_edited_from", lines_edited_args);
  4417. // Removing newline effectively happens after removing text.
  4418. text_edit->set_text("test\nlines");
  4419. text_edit->set_caret_line(0);
  4420. text_edit->set_caret_column(2);
  4421. text_edit->add_caret(0, 4);
  4422. SEND_GUI_ACTION("ui_text_delete_word");
  4423. CHECK(text_edit->get_viewport()->is_input_handled());
  4424. CHECK_FALSE(text_edit->has_selection());
  4425. CHECK(text_edit->get_text() == "telines");
  4426. CHECK(text_edit->get_caret_count() == 1);
  4427. CHECK(text_edit->get_caret_line(0) == 0);
  4428. CHECK(text_edit->get_caret_column(0) == 2);
  4429. text_edit->remove_secondary_carets();
  4430. // Removing newline effectively happens after removing text, reverse caret order.
  4431. text_edit->set_text("test\nlines");
  4432. text_edit->set_caret_line(0);
  4433. text_edit->set_caret_column(4);
  4434. text_edit->add_caret(0, 2);
  4435. SEND_GUI_ACTION("ui_text_delete_word");
  4436. CHECK(text_edit->get_viewport()->is_input_handled());
  4437. CHECK_FALSE(text_edit->has_selection());
  4438. CHECK(text_edit->get_text() == "telines");
  4439. CHECK(text_edit->get_caret_count() == 1);
  4440. CHECK(text_edit->get_caret_line(0) == 0);
  4441. CHECK(text_edit->get_caret_column(0) == 2);
  4442. text_edit->remove_secondary_carets();
  4443. // Remove when there are no words, only symbols.
  4444. text_edit->set_text("#{}");
  4445. text_edit->set_caret_line(0);
  4446. text_edit->set_caret_column(0);
  4447. SEND_GUI_ACTION("ui_text_delete_word");
  4448. CHECK(text_edit->get_viewport()->is_input_handled());
  4449. CHECK_FALSE(text_edit->has_selection());
  4450. CHECK(text_edit->get_text() == "");
  4451. CHECK(text_edit->get_caret_line(0) == 0);
  4452. CHECK(text_edit->get_caret_column(0) == 0);
  4453. }
  4454. SUBCASE("[TextEdit] ui_text_delete_word same line") {
  4455. text_edit->set_text("test longwordtest test");
  4456. MessageQueue::get_singleton()->flush();
  4457. SIGNAL_DISCARD("text_set");
  4458. SIGNAL_DISCARD("text_changed");
  4459. SIGNAL_DISCARD("lines_edited_from");
  4460. SIGNAL_DISCARD("caret_changed");
  4461. // Multiple carets on the same line is handled.
  4462. text_edit->set_caret_line(0);
  4463. text_edit->set_caret_column(0);
  4464. text_edit->add_caret(0, 11);
  4465. text_edit->add_caret(0, 15);
  4466. text_edit->add_caret(0, 9);
  4467. MessageQueue::get_singleton()->flush();
  4468. SIGNAL_DISCARD("caret_changed");
  4469. lines_edited_args = build_array(build_array(0, 0), build_array(0, 0));
  4470. SEND_GUI_ACTION("ui_text_delete_word");
  4471. CHECK(text_edit->get_viewport()->is_input_handled());
  4472. CHECK(text_edit->get_text() == " long test");
  4473. CHECK(text_edit->get_caret_count() == 2);
  4474. CHECK_FALSE(text_edit->has_selection(0));
  4475. CHECK(text_edit->get_caret_line(0) == 0);
  4476. CHECK(text_edit->get_caret_column(0) == 0);
  4477. CHECK_FALSE(text_edit->has_selection(1));
  4478. CHECK(text_edit->get_caret_line(1) == 0);
  4479. CHECK(text_edit->get_caret_column(1) == 5);
  4480. SIGNAL_CHECK("caret_changed", empty_signal_args);
  4481. SIGNAL_CHECK("text_changed", empty_signal_args);
  4482. SIGNAL_CHECK("lines_edited_from", lines_edited_args);
  4483. lines_edited_args = build_array(build_array(0, 0), build_array(0, 0));
  4484. text_edit->undo();
  4485. MessageQueue::get_singleton()->flush();
  4486. CHECK(text_edit->get_text() == "test longwordtest test");
  4487. CHECK(text_edit->get_caret_count() == 4);
  4488. CHECK_FALSE(text_edit->has_selection(0));
  4489. CHECK(text_edit->get_caret_line(0) == 0);
  4490. CHECK(text_edit->get_caret_column(0) == 0);
  4491. CHECK_FALSE(text_edit->has_selection(1));
  4492. CHECK(text_edit->get_caret_line(1) == 0);
  4493. CHECK(text_edit->get_caret_column(1) == 11);
  4494. CHECK_FALSE(text_edit->has_selection(2));
  4495. CHECK(text_edit->get_caret_line(2) == 0);
  4496. CHECK(text_edit->get_caret_column(2) == 15);
  4497. CHECK_FALSE(text_edit->has_selection(3));
  4498. CHECK(text_edit->get_caret_line(3) == 0);
  4499. CHECK(text_edit->get_caret_column(3) == 9);
  4500. SIGNAL_CHECK("caret_changed", empty_signal_args);
  4501. SIGNAL_CHECK("text_changed", empty_signal_args);
  4502. SIGNAL_CHECK("lines_edited_from", reverse_nested(lines_edited_args));
  4503. text_edit->redo();
  4504. MessageQueue::get_singleton()->flush();
  4505. CHECK(text_edit->get_text() == " long test");
  4506. CHECK(text_edit->get_caret_count() == 2);
  4507. CHECK_FALSE(text_edit->has_selection(0));
  4508. CHECK(text_edit->get_caret_line(0) == 0);
  4509. CHECK(text_edit->get_caret_column(0) == 0);
  4510. CHECK_FALSE(text_edit->has_selection(1));
  4511. CHECK(text_edit->get_caret_line(1) == 0);
  4512. CHECK(text_edit->get_caret_column(1) == 5);
  4513. SIGNAL_CHECK("caret_changed", empty_signal_args);
  4514. SIGNAL_CHECK("text_changed", empty_signal_args);
  4515. SIGNAL_CHECK("lines_edited_from", lines_edited_args);
  4516. }
  4517. SUBCASE("[TextEdit] ui_text_delete") {
  4518. text_edit->set_caret_mid_grapheme_enabled(true);
  4519. CHECK(text_edit->is_caret_mid_grapheme_enabled());
  4520. text_edit->set_text("this is some test text.\n\nthis is some test text.\n");
  4521. MessageQueue::get_singleton()->flush();
  4522. SIGNAL_DISCARD("text_set");
  4523. SIGNAL_DISCARD("text_changed");
  4524. SIGNAL_DISCARD("lines_edited_from");
  4525. SIGNAL_DISCARD("caret_changed");
  4526. // Remove selected text when there are selections.
  4527. text_edit->select(0, 0, 0, 4);
  4528. text_edit->add_caret(2, 2);
  4529. text_edit->select(2, 5, 2, 2, 1);
  4530. MessageQueue::get_singleton()->flush();
  4531. SIGNAL_DISCARD("caret_changed");
  4532. lines_edited_args = build_array(build_array(0, 0), build_array(2, 2));
  4533. SEND_GUI_ACTION("ui_text_delete");
  4534. CHECK(text_edit->get_viewport()->is_input_handled());
  4535. CHECK(text_edit->get_text() == " is some test text.\n\nthis some test text.\n");
  4536. CHECK(text_edit->get_caret_count() == 2);
  4537. CHECK_FALSE(text_edit->has_selection(0));
  4538. CHECK(text_edit->get_caret_line(0) == 0);
  4539. CHECK(text_edit->get_caret_column(0) == 0);
  4540. CHECK_FALSE(text_edit->has_selection(1));
  4541. CHECK(text_edit->get_caret_line(1) == 2);
  4542. CHECK(text_edit->get_caret_column(1) == 2);
  4543. SIGNAL_CHECK("caret_changed", empty_signal_args);
  4544. SIGNAL_CHECK("text_changed", empty_signal_args);
  4545. SIGNAL_CHECK("lines_edited_from", lines_edited_args);
  4546. // Undo remove selection.
  4547. text_edit->undo();
  4548. MessageQueue::get_singleton()->flush();
  4549. CHECK(text_edit->get_caret_count() == 2);
  4550. CHECK(text_edit->get_text() == "this is some test text.\n\nthis is some test text.\n");
  4551. CHECK(text_edit->get_caret_count() == 2);
  4552. CHECK(text_edit->has_selection(0));
  4553. CHECK(text_edit->get_caret_line(0) == 0);
  4554. CHECK(text_edit->get_caret_column(0) == 4);
  4555. CHECK(text_edit->get_selection_origin_line(0) == 0);
  4556. CHECK(text_edit->get_selection_origin_column(0) == 0);
  4557. CHECK(text_edit->has_selection(1));
  4558. CHECK(text_edit->get_caret_line(1) == 2);
  4559. CHECK(text_edit->get_caret_column(1) == 2);
  4560. CHECK(text_edit->get_selection_origin_line(1) == 2);
  4561. CHECK(text_edit->get_selection_origin_column(1) == 5);
  4562. SIGNAL_CHECK("caret_changed", empty_signal_args);
  4563. SIGNAL_CHECK("text_changed", empty_signal_args);
  4564. SIGNAL_CHECK("lines_edited_from", reverse_nested(lines_edited_args));
  4565. // Redo remove selection.
  4566. text_edit->redo();
  4567. MessageQueue::get_singleton()->flush();
  4568. CHECK(text_edit->get_text() == " is some test text.\n\nthis some test text.\n");
  4569. CHECK(text_edit->get_caret_count() == 2);
  4570. CHECK_FALSE(text_edit->has_selection(0));
  4571. CHECK(text_edit->get_caret_line(0) == 0);
  4572. CHECK(text_edit->get_caret_column(0) == 0);
  4573. CHECK_FALSE(text_edit->has_selection(1));
  4574. CHECK(text_edit->get_caret_line(1) == 2);
  4575. CHECK(text_edit->get_caret_column(1) == 2);
  4576. SIGNAL_CHECK("caret_changed", empty_signal_args);
  4577. SIGNAL_CHECK("text_changed", empty_signal_args);
  4578. SIGNAL_CHECK("lines_edited_from", lines_edited_args);
  4579. // Remove newline when at end of line.
  4580. text_edit->set_caret_column(text_edit->get_line(0).length());
  4581. text_edit->set_caret_column(text_edit->get_line(2).length(), false, 1);
  4582. MessageQueue::get_singleton()->flush();
  4583. SIGNAL_DISCARD("caret_changed");
  4584. lines_edited_args = build_array(build_array(1, 0), build_array(2, 1));
  4585. SEND_GUI_ACTION("ui_text_delete");
  4586. CHECK(text_edit->get_viewport()->is_input_handled());
  4587. CHECK(text_edit->get_text() == " is some test text.\nthis some test text.");
  4588. CHECK(text_edit->get_caret_count() == 2);
  4589. CHECK_FALSE(text_edit->has_selection(0));
  4590. CHECK(text_edit->get_caret_line(0) == 0);
  4591. CHECK(text_edit->get_caret_column(0) == 19);
  4592. CHECK_FALSE(text_edit->has_selection(1));
  4593. CHECK(text_edit->get_caret_line(1) == 1);
  4594. CHECK(text_edit->get_caret_column(1) == 20);
  4595. SIGNAL_CHECK("caret_changed", empty_signal_args);
  4596. SIGNAL_CHECK("text_changed", empty_signal_args);
  4597. SIGNAL_CHECK("lines_edited_from", lines_edited_args);
  4598. // Undo remove newline.
  4599. text_edit->undo();
  4600. MessageQueue::get_singleton()->flush();
  4601. CHECK(text_edit->get_text() == " is some test text.\n\nthis some test text.\n");
  4602. CHECK(text_edit->get_caret_count() == 2);
  4603. CHECK_FALSE(text_edit->has_selection(0));
  4604. CHECK(text_edit->get_caret_line(0) == 0);
  4605. CHECK(text_edit->get_caret_column(0) == 19);
  4606. CHECK_FALSE(text_edit->has_selection(1));
  4607. CHECK(text_edit->get_caret_line(1) == 2);
  4608. CHECK(text_edit->get_caret_column(1) == 20);
  4609. SIGNAL_CHECK("caret_changed", empty_signal_args);
  4610. SIGNAL_CHECK("text_changed", empty_signal_args);
  4611. SIGNAL_CHECK("lines_edited_from", reverse_nested(lines_edited_args));
  4612. // Redo remove newline.
  4613. text_edit->redo();
  4614. MessageQueue::get_singleton()->flush();
  4615. CHECK(text_edit->get_text() == " is some test text.\nthis some test text.");
  4616. CHECK(text_edit->get_caret_count() == 2);
  4617. CHECK_FALSE(text_edit->has_selection(0));
  4618. CHECK(text_edit->get_caret_line(0) == 0);
  4619. CHECK(text_edit->get_caret_column(0) == 19);
  4620. CHECK_FALSE(text_edit->has_selection(1));
  4621. CHECK(text_edit->get_caret_line(1) == 1);
  4622. CHECK(text_edit->get_caret_column(1) == 20);
  4623. SIGNAL_CHECK("caret_changed", empty_signal_args);
  4624. SIGNAL_CHECK("text_changed", empty_signal_args);
  4625. SIGNAL_CHECK("lines_edited_from", lines_edited_args);
  4626. // Does not work if not editable.
  4627. text_edit->set_caret_column(0);
  4628. text_edit->set_caret_column(15, false, 1);
  4629. MessageQueue::get_singleton()->flush();
  4630. SIGNAL_DISCARD("caret_changed");
  4631. text_edit->set_editable(false);
  4632. SEND_GUI_ACTION("ui_text_delete");
  4633. CHECK(text_edit->get_viewport()->is_input_handled());
  4634. CHECK(text_edit->get_text() == " is some test text.\nthis some test text.");
  4635. CHECK(text_edit->get_caret_count() == 2);
  4636. CHECK_FALSE(text_edit->has_selection(0));
  4637. CHECK(text_edit->get_caret_line(0) == 0);
  4638. CHECK(text_edit->get_caret_column(0) == 0);
  4639. CHECK_FALSE(text_edit->has_selection(1));
  4640. CHECK(text_edit->get_caret_line(1) == 1);
  4641. CHECK(text_edit->get_caret_column(1) == 15);
  4642. SIGNAL_CHECK_FALSE("caret_changed");
  4643. SIGNAL_CHECK_FALSE("text_changed");
  4644. SIGNAL_CHECK_FALSE("lines_edited_from");
  4645. text_edit->set_editable(true);
  4646. // FIXME: Remove after GH-77101 is fixed.
  4647. text_edit->start_action(TextEdit::EditAction::ACTION_NONE);
  4648. // Delete removes character to the right.
  4649. lines_edited_args = build_array(build_array(0, 0), build_array(1, 1));
  4650. SEND_GUI_ACTION("ui_text_delete");
  4651. CHECK(text_edit->get_viewport()->is_input_handled());
  4652. CHECK(text_edit->get_text() == "is some test text.\nthis some test ext.");
  4653. CHECK(text_edit->get_caret_count() == 2);
  4654. CHECK_FALSE(text_edit->has_selection(0));
  4655. CHECK(text_edit->get_caret_line(0) == 0);
  4656. CHECK(text_edit->get_caret_column(0) == 0);
  4657. CHECK_FALSE(text_edit->has_selection(1));
  4658. CHECK(text_edit->get_caret_line(1) == 1);
  4659. CHECK(text_edit->get_caret_column(1) == 15);
  4660. SIGNAL_CHECK_FALSE("caret_changed");
  4661. SIGNAL_CHECK("text_changed", empty_signal_args);
  4662. SIGNAL_CHECK("lines_edited_from", lines_edited_args);
  4663. // Delete another character without changing caret.
  4664. SEND_GUI_ACTION("ui_text_delete");
  4665. CHECK(text_edit->get_viewport()->is_input_handled());
  4666. CHECK(text_edit->get_text() == "s some test text.\nthis some test xt.");
  4667. CHECK(text_edit->get_caret_count() == 2);
  4668. CHECK_FALSE(text_edit->has_selection(0));
  4669. CHECK(text_edit->get_caret_line(0) == 0);
  4670. CHECK(text_edit->get_caret_column(0) == 0);
  4671. CHECK_FALSE(text_edit->has_selection(1));
  4672. CHECK(text_edit->get_caret_line(1) == 1);
  4673. CHECK(text_edit->get_caret_column(1) == 15);
  4674. SIGNAL_CHECK_FALSE("caret_changed");
  4675. SIGNAL_CHECK("text_changed", empty_signal_args);
  4676. SIGNAL_CHECK("lines_edited_from", lines_edited_args);
  4677. // Undo both deletes.
  4678. lines_edited_args = build_array(build_array(0, 0), build_array(1, 1), build_array(0, 0), build_array(1, 1));
  4679. text_edit->undo();
  4680. MessageQueue::get_singleton()->flush();
  4681. CHECK(text_edit->get_text() == " is some test text.\nthis some test text.");
  4682. CHECK(text_edit->get_caret_count() == 2);
  4683. CHECK_FALSE(text_edit->has_selection(0));
  4684. CHECK(text_edit->get_caret_line(0) == 0);
  4685. CHECK(text_edit->get_caret_column(0) == 0);
  4686. CHECK_FALSE(text_edit->has_selection(1));
  4687. CHECK(text_edit->get_caret_line(1) == 1);
  4688. CHECK(text_edit->get_caret_column(1) == 15);
  4689. SIGNAL_CHECK_FALSE("caret_changed");
  4690. SIGNAL_CHECK("text_changed", empty_signal_args);
  4691. SIGNAL_CHECK("lines_edited_from", reverse_nested(lines_edited_args));
  4692. // Redo both deletes.
  4693. text_edit->redo();
  4694. MessageQueue::get_singleton()->flush();
  4695. CHECK(text_edit->get_text() == "s some test text.\nthis some test xt.");
  4696. CHECK(text_edit->get_caret_count() == 2);
  4697. CHECK_FALSE(text_edit->has_selection(0));
  4698. CHECK(text_edit->get_caret_line(0) == 0);
  4699. CHECK(text_edit->get_caret_column(0) == 0);
  4700. CHECK_FALSE(text_edit->has_selection(1));
  4701. CHECK(text_edit->get_caret_line(1) == 1);
  4702. CHECK(text_edit->get_caret_column(1) == 15);
  4703. SIGNAL_CHECK_FALSE("caret_changed");
  4704. SIGNAL_CHECK("text_changed", empty_signal_args);
  4705. SIGNAL_CHECK("lines_edited_from", lines_edited_args);
  4706. // Delete at end of last line does nothing.
  4707. text_edit->remove_secondary_carets();
  4708. text_edit->set_caret_line(1);
  4709. text_edit->set_caret_column(18);
  4710. MessageQueue::get_singleton()->flush();
  4711. SIGNAL_DISCARD("caret_changed");
  4712. SEND_GUI_ACTION("ui_text_delete");
  4713. CHECK(text_edit->get_viewport()->is_input_handled());
  4714. CHECK(text_edit->get_text() == "s some test text.\nthis some test xt.");
  4715. CHECK(text_edit->get_caret_count() == 1);
  4716. CHECK_FALSE(text_edit->has_selection(0));
  4717. CHECK(text_edit->get_caret_line(0) == 1);
  4718. CHECK(text_edit->get_caret_column(0) == 18);
  4719. SIGNAL_CHECK_FALSE("caret_changed");
  4720. SIGNAL_CHECK_FALSE("text_changed");
  4721. SIGNAL_CHECK_FALSE("lines_edited_from");
  4722. }
  4723. SUBCASE("[TextEdit] ui_text_caret_word_left") {
  4724. text_edit->set_text("\nthis is some test text.\nthis is some test text.");
  4725. text_edit->set_caret_line(1);
  4726. text_edit->set_caret_column(15);
  4727. text_edit->add_caret(2, 10);
  4728. text_edit->select(1, 10, 1, 15);
  4729. text_edit->select(2, 15, 2, 10, 1);
  4730. MessageQueue::get_singleton()->flush();
  4731. SIGNAL_DISCARD("text_set");
  4732. SIGNAL_DISCARD("text_changed");
  4733. SIGNAL_DISCARD("lines_edited_from");
  4734. SIGNAL_DISCARD("caret_changed");
  4735. // Deselect to start of previous word when selection is right to left.
  4736. // Select to start of next word when selection is left to right.
  4737. #ifdef MACOS_ENABLED
  4738. SEND_GUI_KEY_EVENT(Key::LEFT | KeyModifierMask::ALT | KeyModifierMask::SHIFT);
  4739. #else
  4740. SEND_GUI_KEY_EVENT(Key::LEFT | KeyModifierMask::CMD_OR_CTRL | KeyModifierMask::SHIFT);
  4741. #endif
  4742. CHECK(text_edit->get_viewport()->is_input_handled());
  4743. CHECK(text_edit->get_caret_count() == 2);
  4744. CHECK(text_edit->has_selection(0));
  4745. CHECK(text_edit->get_selected_text(0) == "me ");
  4746. CHECK(text_edit->get_caret_line(0) == 1);
  4747. CHECK(text_edit->get_caret_column(0) == 13);
  4748. CHECK(text_edit->get_selection_origin_line(0) == 1);
  4749. CHECK(text_edit->get_selection_origin_column(0) == 10);
  4750. CHECK(text_edit->is_caret_after_selection_origin(0));
  4751. CHECK(text_edit->has_selection(1));
  4752. CHECK(text_edit->get_selected_text(1) == "some te");
  4753. CHECK(text_edit->get_caret_line(1) == 2);
  4754. CHECK(text_edit->get_caret_column(1) == 8);
  4755. CHECK(text_edit->get_selection_origin_line(1) == 2);
  4756. CHECK(text_edit->get_selection_origin_column(1) == 15);
  4757. CHECK_FALSE(text_edit->is_caret_after_selection_origin(1));
  4758. SIGNAL_CHECK("caret_changed", empty_signal_args);
  4759. SIGNAL_CHECK_FALSE("text_changed");
  4760. SIGNAL_CHECK_FALSE("lines_edited_from");
  4761. // Select to start of word with shift.
  4762. text_edit->deselect();
  4763. text_edit->set_caret_column(7);
  4764. text_edit->set_caret_column(16, false, 1);
  4765. MessageQueue::get_singleton()->flush();
  4766. SIGNAL_DISCARD("caret_changed");
  4767. #ifdef MACOS_ENABLED
  4768. SEND_GUI_KEY_EVENT(Key::LEFT | KeyModifierMask::ALT | KeyModifierMask::SHIFT);
  4769. #else
  4770. SEND_GUI_KEY_EVENT(Key::LEFT | KeyModifierMask::CMD_OR_CTRL | KeyModifierMask::SHIFT);
  4771. #endif
  4772. CHECK(text_edit->get_viewport()->is_input_handled());
  4773. CHECK(text_edit->get_caret_count() == 2);
  4774. CHECK(text_edit->has_selection(0));
  4775. CHECK(text_edit->get_selected_text(0) == "is");
  4776. CHECK(text_edit->get_caret_line(0) == 1);
  4777. CHECK(text_edit->get_caret_column(0) == 5);
  4778. CHECK(text_edit->get_selection_origin_line(0) == 1);
  4779. CHECK(text_edit->get_selection_origin_column(0) == 7);
  4780. CHECK_FALSE(text_edit->is_caret_after_selection_origin(0));
  4781. CHECK(text_edit->has_selection(1));
  4782. CHECK(text_edit->get_selected_text(1) == "tes");
  4783. CHECK(text_edit->get_caret_line(1) == 2);
  4784. CHECK(text_edit->get_caret_column(1) == 13);
  4785. CHECK(text_edit->get_selection_origin_line(1) == 2);
  4786. CHECK(text_edit->get_selection_origin_column(1) == 16);
  4787. CHECK_FALSE(text_edit->is_caret_after_selection_origin(1));
  4788. SIGNAL_CHECK("caret_changed", empty_signal_args);
  4789. SIGNAL_CHECK_FALSE("text_changed");
  4790. SIGNAL_CHECK_FALSE("lines_edited_from");
  4791. // Deselect and move caret to start of next word without shift.
  4792. SEND_GUI_ACTION("ui_text_caret_word_left");
  4793. CHECK(text_edit->get_viewport()->is_input_handled());
  4794. CHECK(text_edit->get_caret_count() == 2);
  4795. CHECK_FALSE(text_edit->has_selection(0));
  4796. CHECK(text_edit->get_caret_line(0) == 1);
  4797. CHECK(text_edit->get_caret_column(0) == 0);
  4798. CHECK_FALSE(text_edit->has_selection(1));
  4799. CHECK(text_edit->get_caret_line(1) == 2);
  4800. CHECK(text_edit->get_caret_column(1) == 8);
  4801. SIGNAL_CHECK("caret_changed", empty_signal_args);
  4802. SIGNAL_CHECK_FALSE("text_changed");
  4803. SIGNAL_CHECK_FALSE("lines_edited_from");
  4804. // Moves to end of previous line when at start of line. Does nothing at start of text.
  4805. text_edit->set_caret_line(0);
  4806. text_edit->set_caret_column(0);
  4807. text_edit->set_caret_column(0, false, 1);
  4808. MessageQueue::get_singleton()->flush();
  4809. SIGNAL_DISCARD("caret_changed");
  4810. SEND_GUI_ACTION("ui_text_caret_word_left");
  4811. CHECK(text_edit->get_viewport()->is_input_handled());
  4812. CHECK(text_edit->get_caret_count() == 2);
  4813. CHECK_FALSE(text_edit->has_selection(0));
  4814. CHECK(text_edit->get_caret_line(0) == 0);
  4815. CHECK(text_edit->get_caret_column(0) == 0);
  4816. CHECK_FALSE(text_edit->has_selection(1));
  4817. CHECK(text_edit->get_caret_line(1) == 1);
  4818. CHECK(text_edit->get_caret_column(1) == 23);
  4819. SIGNAL_CHECK("caret_changed", empty_signal_args);
  4820. SIGNAL_CHECK_FALSE("text_changed");
  4821. SIGNAL_CHECK_FALSE("lines_edited_from");
  4822. // Move when there are no words, only symbols.
  4823. text_edit->set_text("#{}");
  4824. text_edit->set_caret_line(0);
  4825. text_edit->set_caret_column(3);
  4826. SEND_GUI_ACTION("ui_text_caret_word_left");
  4827. CHECK(text_edit->get_viewport()->is_input_handled());
  4828. CHECK(text_edit->get_caret_line(0) == 0);
  4829. CHECK(text_edit->get_caret_column(0) == 0);
  4830. }
  4831. SUBCASE("[TextEdit] ui_text_caret_left") {
  4832. text_edit->set_text("\nthis is some test text.\nthis is some test text.");
  4833. text_edit->set_caret_line(1);
  4834. text_edit->set_caret_column(7);
  4835. text_edit->select(1, 3, 1, 7);
  4836. text_edit->add_caret(2, 3);
  4837. text_edit->select(2, 7, 2, 3, 1);
  4838. MessageQueue::get_singleton()->flush();
  4839. SIGNAL_DISCARD("text_set");
  4840. SIGNAL_DISCARD("text_changed");
  4841. SIGNAL_DISCARD("lines_edited_from");
  4842. SIGNAL_DISCARD("caret_changed");
  4843. // Remove one character from selection when selection is left to right.
  4844. // Add one character to selection when selection is right to left.
  4845. SEND_GUI_KEY_EVENT(Key::LEFT | KeyModifierMask::SHIFT);
  4846. CHECK(text_edit->get_viewport()->is_input_handled());
  4847. CHECK(text_edit->get_caret_count() == 2);
  4848. CHECK(text_edit->has_selection(0));
  4849. CHECK(text_edit->get_selected_text(0) == "s i");
  4850. CHECK(text_edit->get_caret_line(0) == 1);
  4851. CHECK(text_edit->get_caret_column(0) == 6);
  4852. CHECK(text_edit->get_selection_origin_line(0) == 1);
  4853. CHECK(text_edit->get_selection_origin_column(0) == 3);
  4854. CHECK(text_edit->is_caret_after_selection_origin(0));
  4855. CHECK(text_edit->has_selection(1));
  4856. CHECK(text_edit->get_selected_text(1) == "is is");
  4857. CHECK(text_edit->get_caret_line(1) == 2);
  4858. CHECK(text_edit->get_caret_column(1) == 2);
  4859. CHECK(text_edit->get_selection_origin_line(1) == 2);
  4860. CHECK(text_edit->get_selection_origin_column(1) == 7);
  4861. CHECK_FALSE(text_edit->is_caret_after_selection_origin(1));
  4862. SIGNAL_CHECK("caret_changed", empty_signal_args);
  4863. SIGNAL_CHECK_FALSE("text_changed");
  4864. SIGNAL_CHECK_FALSE("lines_edited_from");
  4865. // Deselect and put caret at selection start without shift.
  4866. SEND_GUI_ACTION("ui_text_caret_left");
  4867. CHECK(text_edit->get_viewport()->is_input_handled());
  4868. CHECK(text_edit->get_caret_count() == 2);
  4869. CHECK_FALSE(text_edit->has_selection(0));
  4870. CHECK(text_edit->get_caret_line(0) == 1);
  4871. CHECK(text_edit->get_caret_column(0) == 3);
  4872. CHECK_FALSE(text_edit->has_selection(1));
  4873. CHECK(text_edit->get_caret_line(1) == 2);
  4874. CHECK(text_edit->get_caret_column(1) == 2);
  4875. SIGNAL_CHECK("caret_changed", empty_signal_args);
  4876. SIGNAL_CHECK_FALSE("text_changed");
  4877. SIGNAL_CHECK_FALSE("lines_edited_from");
  4878. // Move caret one character to the left.
  4879. SEND_GUI_ACTION("ui_text_caret_left");
  4880. CHECK(text_edit->get_viewport()->is_input_handled());
  4881. CHECK(text_edit->get_caret_count() == 2);
  4882. CHECK_FALSE(text_edit->has_selection(0));
  4883. CHECK(text_edit->get_caret_line(0) == 1);
  4884. CHECK(text_edit->get_caret_column(0) == 2);
  4885. CHECK_FALSE(text_edit->has_selection(1));
  4886. CHECK(text_edit->get_caret_line(1) == 2);
  4887. CHECK(text_edit->get_caret_column(1) == 1);
  4888. SIGNAL_CHECK("caret_changed", empty_signal_args);
  4889. SIGNAL_CHECK_FALSE("text_changed");
  4890. SIGNAL_CHECK_FALSE("lines_edited_from");
  4891. // Select one character to the left with shift and no existing selection.
  4892. SEND_GUI_KEY_EVENT(Key::LEFT | KeyModifierMask::SHIFT);
  4893. CHECK(text_edit->get_viewport()->is_input_handled());
  4894. CHECK(text_edit->get_caret_count() == 2);
  4895. CHECK(text_edit->has_selection(0));
  4896. CHECK(text_edit->get_selected_text(0) == "h");
  4897. CHECK(text_edit->get_caret_line(0) == 1);
  4898. CHECK(text_edit->get_caret_column(0) == 1);
  4899. CHECK(text_edit->get_selection_origin_line(0) == 1);
  4900. CHECK(text_edit->get_selection_origin_column(0) == 2);
  4901. CHECK_FALSE(text_edit->is_caret_after_selection_origin(0));
  4902. CHECK(text_edit->has_selection(1));
  4903. CHECK(text_edit->get_selected_text(1) == "t");
  4904. CHECK(text_edit->get_caret_line(1) == 2);
  4905. CHECK(text_edit->get_caret_column(1) == 0);
  4906. CHECK(text_edit->get_selection_origin_line(1) == 2);
  4907. CHECK(text_edit->get_selection_origin_column(1) == 1);
  4908. CHECK_FALSE(text_edit->is_caret_after_selection_origin(1));
  4909. SIGNAL_CHECK("caret_changed", empty_signal_args);
  4910. SIGNAL_CHECK_FALSE("text_changed");
  4911. SIGNAL_CHECK_FALSE("lines_edited_from");
  4912. // Moves to end of previous line when at start of line. Does nothing at start of text.
  4913. text_edit->deselect();
  4914. text_edit->set_caret_line(0);
  4915. text_edit->set_caret_column(0);
  4916. text_edit->set_caret_column(0, false, 1);
  4917. MessageQueue::get_singleton()->flush();
  4918. SIGNAL_DISCARD("caret_changed");
  4919. SEND_GUI_ACTION("ui_text_caret_left");
  4920. CHECK(text_edit->get_viewport()->is_input_handled());
  4921. CHECK(text_edit->get_caret_count() == 2);
  4922. CHECK_FALSE(text_edit->has_selection(0));
  4923. CHECK(text_edit->get_caret_line(0) == 0);
  4924. CHECK(text_edit->get_caret_column(0) == 0);
  4925. CHECK_FALSE(text_edit->has_selection(1));
  4926. CHECK(text_edit->get_caret_line(1) == 1);
  4927. CHECK(text_edit->get_caret_column(1) == 23);
  4928. SIGNAL_CHECK("caret_changed", empty_signal_args);
  4929. SIGNAL_CHECK_FALSE("text_changed");
  4930. SIGNAL_CHECK_FALSE("lines_edited_from");
  4931. // Selects to end of previous line when at start of line.
  4932. text_edit->remove_secondary_carets();
  4933. text_edit->set_caret_line(1);
  4934. text_edit->set_caret_column(0);
  4935. text_edit->select(1, 1, 1, 0);
  4936. MessageQueue::get_singleton()->flush();
  4937. SIGNAL_DISCARD("caret_changed");
  4938. SEND_GUI_KEY_EVENT(Key::LEFT | KeyModifierMask::SHIFT);
  4939. CHECK(text_edit->get_viewport()->is_input_handled());
  4940. CHECK(text_edit->get_caret_count() == 1);
  4941. CHECK(text_edit->has_selection(0));
  4942. CHECK(text_edit->get_selected_text(0) == "\nt");
  4943. CHECK(text_edit->get_caret_line(0) == 0);
  4944. CHECK(text_edit->get_caret_column(0) == 0);
  4945. CHECK(text_edit->get_selection_origin_line(0) == 1);
  4946. CHECK(text_edit->get_selection_origin_column(0) == 1);
  4947. CHECK_FALSE(text_edit->is_caret_after_selection_origin(0));
  4948. SIGNAL_CHECK("caret_changed", empty_signal_args);
  4949. SIGNAL_CHECK_FALSE("text_changed");
  4950. SIGNAL_CHECK_FALSE("lines_edited_from");
  4951. // Merge selections when they overlap.
  4952. text_edit->set_caret_line(1);
  4953. text_edit->set_caret_column(4);
  4954. text_edit->select(1, 6, 1, 4);
  4955. text_edit->add_caret(1, 8);
  4956. text_edit->select(1, 8, 1, 6, 1);
  4957. MessageQueue::get_singleton()->flush();
  4958. SIGNAL_DISCARD("caret_changed");
  4959. CHECK(text_edit->get_caret_count() == 2);
  4960. SEND_GUI_KEY_EVENT(Key::LEFT | KeyModifierMask::SHIFT);
  4961. CHECK(text_edit->get_viewport()->is_input_handled());
  4962. CHECK(text_edit->get_caret_count() == 1);
  4963. CHECK(text_edit->has_selection(0));
  4964. CHECK(text_edit->get_selected_text(0) == "s is ");
  4965. CHECK(text_edit->get_caret_line(0) == 1);
  4966. CHECK(text_edit->get_caret_column(0) == 3);
  4967. CHECK(text_edit->get_selection_origin_line(0) == 1);
  4968. CHECK(text_edit->get_selection_origin_column(0) == 8);
  4969. CHECK_FALSE(text_edit->is_caret_after_selection_origin(0));
  4970. SIGNAL_CHECK("caret_changed", empty_signal_args);
  4971. SIGNAL_CHECK_FALSE("text_changed");
  4972. SIGNAL_CHECK_FALSE("lines_edited_from");
  4973. }
  4974. SUBCASE("[TextEdit] ui_text_caret_word_right") {
  4975. text_edit->set_text("this is some test text\n\nthis is some test text");
  4976. text_edit->set_caret_line(0);
  4977. text_edit->set_caret_column(15);
  4978. text_edit->add_caret(2, 10);
  4979. text_edit->select(0, 10, 0, 15);
  4980. text_edit->select(2, 15, 2, 10, 1);
  4981. MessageQueue::get_singleton()->flush();
  4982. SIGNAL_DISCARD("text_set");
  4983. SIGNAL_DISCARD("text_changed");
  4984. SIGNAL_DISCARD("lines_edited_from");
  4985. SIGNAL_DISCARD("caret_changed");
  4986. // Select to end of next word when selection is right to left.
  4987. // Deselect to end of previous word when selection is left to right.
  4988. #ifdef MACOS_ENABLED
  4989. SEND_GUI_KEY_EVENT(Key::RIGHT | KeyModifierMask::ALT | KeyModifierMask::SHIFT);
  4990. #else
  4991. SEND_GUI_KEY_EVENT(Key::RIGHT | KeyModifierMask::CMD_OR_CTRL | KeyModifierMask::SHIFT);
  4992. #endif
  4993. CHECK(text_edit->get_viewport()->is_input_handled());
  4994. CHECK(text_edit->get_caret_count() == 2);
  4995. CHECK(text_edit->has_selection(0));
  4996. CHECK(text_edit->get_selected_text(0) == "me test");
  4997. CHECK(text_edit->get_caret_line(0) == 0);
  4998. CHECK(text_edit->get_caret_column(0) == 17);
  4999. CHECK(text_edit->get_selection_origin_line(0) == 0);
  5000. CHECK(text_edit->get_selection_origin_column(0) == 10);
  5001. CHECK(text_edit->is_caret_after_selection_origin(0));
  5002. CHECK(text_edit->has_selection(1));
  5003. CHECK(text_edit->get_selected_text(1) == " te");
  5004. CHECK(text_edit->get_caret_line(1) == 2);
  5005. CHECK(text_edit->get_caret_column(1) == 12);
  5006. CHECK(text_edit->get_selection_origin_line(1) == 2);
  5007. CHECK(text_edit->get_selection_origin_column(1) == 15);
  5008. CHECK_FALSE(text_edit->is_caret_after_selection_origin(1));
  5009. SIGNAL_CHECK("caret_changed", empty_signal_args);
  5010. SIGNAL_CHECK_FALSE("text_changed");
  5011. SIGNAL_CHECK_FALSE("lines_edited_from");
  5012. // Select to end of word with shift.
  5013. text_edit->deselect();
  5014. text_edit->set_caret_column(13);
  5015. text_edit->set_caret_column(15, false, 1);
  5016. MessageQueue::get_singleton()->flush();
  5017. SIGNAL_DISCARD("caret_changed");
  5018. #ifdef MACOS_ENABLED
  5019. SEND_GUI_KEY_EVENT(Key::RIGHT | KeyModifierMask::ALT | KeyModifierMask::SHIFT);
  5020. #else
  5021. SEND_GUI_KEY_EVENT(Key::RIGHT | KeyModifierMask::CMD_OR_CTRL | KeyModifierMask::SHIFT);
  5022. #endif
  5023. CHECK(text_edit->get_viewport()->is_input_handled());
  5024. CHECK(text_edit->get_caret_count() == 2);
  5025. CHECK(text_edit->has_selection(0));
  5026. CHECK(text_edit->get_selected_text(0) == "test");
  5027. CHECK(text_edit->get_caret_line(0) == 0);
  5028. CHECK(text_edit->get_caret_column(0) == 17);
  5029. CHECK(text_edit->get_selection_origin_line(0) == 0);
  5030. CHECK(text_edit->get_selection_origin_column(0) == 13);
  5031. CHECK(text_edit->is_caret_after_selection_origin(0));
  5032. CHECK(text_edit->has_selection(1));
  5033. CHECK(text_edit->get_selected_text(1) == "st");
  5034. CHECK(text_edit->get_caret_line(1) == 2);
  5035. CHECK(text_edit->get_caret_column(1) == 17);
  5036. CHECK(text_edit->get_selection_origin_line(1) == 2);
  5037. CHECK(text_edit->get_selection_origin_column(1) == 15);
  5038. CHECK(text_edit->is_caret_after_selection_origin(1));
  5039. SIGNAL_CHECK("caret_changed", empty_signal_args);
  5040. SIGNAL_CHECK_FALSE("text_changed");
  5041. SIGNAL_CHECK_FALSE("lines_edited_from");
  5042. // Deselect and move caret to end of next word without shift.
  5043. SEND_GUI_ACTION("ui_text_caret_word_right");
  5044. CHECK(text_edit->get_viewport()->is_input_handled());
  5045. CHECK(text_edit->get_caret_count() == 2);
  5046. CHECK_FALSE(text_edit->has_selection(0));
  5047. CHECK(text_edit->get_caret_line(0) == 0);
  5048. CHECK(text_edit->get_caret_column(0) == 22);
  5049. CHECK_FALSE(text_edit->has_selection(1));
  5050. CHECK(text_edit->get_caret_line(1) == 2);
  5051. CHECK(text_edit->get_caret_column(1) == 22);
  5052. SIGNAL_CHECK("caret_changed", empty_signal_args);
  5053. SIGNAL_CHECK_FALSE("text_changed");
  5054. SIGNAL_CHECK_FALSE("lines_edited_from");
  5055. // Moves to start of next line when at end of line. Does nothing at end of text.
  5056. SEND_GUI_ACTION("ui_text_caret_word_right");
  5057. CHECK(text_edit->get_viewport()->is_input_handled());
  5058. CHECK(text_edit->get_caret_count() == 2);
  5059. CHECK_FALSE(text_edit->has_selection(0));
  5060. CHECK(text_edit->get_caret_line(0) == 1);
  5061. CHECK(text_edit->get_caret_column(0) == 0);
  5062. CHECK_FALSE(text_edit->has_selection(1));
  5063. CHECK(text_edit->get_caret_line(1) == 2);
  5064. CHECK(text_edit->get_caret_column(1) == 22);
  5065. SIGNAL_CHECK("caret_changed", empty_signal_args);
  5066. SIGNAL_CHECK_FALSE("text_changed");
  5067. SIGNAL_CHECK_FALSE("lines_edited_from");
  5068. // Move when there are no words, only symbols.
  5069. text_edit->set_text("#{}");
  5070. text_edit->set_caret_line(0);
  5071. text_edit->set_caret_column(0);
  5072. SEND_GUI_ACTION("ui_text_caret_word_right");
  5073. CHECK(text_edit->get_viewport()->is_input_handled());
  5074. CHECK(text_edit->get_caret_line(0) == 0);
  5075. CHECK(text_edit->get_caret_column(0) == 3);
  5076. }
  5077. SUBCASE("[TextEdit] ui_text_caret_right") {
  5078. text_edit->set_text("this is some test text\n\nthis is some test text");
  5079. text_edit->set_caret_line(0);
  5080. text_edit->set_caret_column(19);
  5081. text_edit->select(0, 15, 0, 19);
  5082. text_edit->add_caret(2, 15);
  5083. text_edit->select(2, 19, 2, 15, 1);
  5084. MessageQueue::get_singleton()->flush();
  5085. SIGNAL_DISCARD("text_set");
  5086. SIGNAL_DISCARD("text_changed");
  5087. SIGNAL_DISCARD("lines_edited_from");
  5088. SIGNAL_DISCARD("caret_changed");
  5089. // Remove one character from selection when selection is right to left.
  5090. // Add one character to selection when selection is left to right.
  5091. SEND_GUI_KEY_EVENT(Key::RIGHT | KeyModifierMask::SHIFT);
  5092. CHECK(text_edit->get_viewport()->is_input_handled());
  5093. CHECK(text_edit->get_caret_count() == 2);
  5094. CHECK(text_edit->has_selection(0));
  5095. CHECK(text_edit->get_selected_text(0) == "st te");
  5096. CHECK(text_edit->get_caret_line(0) == 0);
  5097. CHECK(text_edit->get_caret_column(0) == 20);
  5098. CHECK(text_edit->get_selection_origin_line(0) == 0);
  5099. CHECK(text_edit->get_selection_origin_column(0) == 15);
  5100. CHECK(text_edit->is_caret_after_selection_origin(0));
  5101. CHECK(text_edit->has_selection(1));
  5102. CHECK(text_edit->get_selected_text(1) == "t t");
  5103. CHECK(text_edit->get_caret_line(1) == 2);
  5104. CHECK(text_edit->get_caret_column(1) == 16);
  5105. CHECK(text_edit->get_selection_origin_line(1) == 2);
  5106. CHECK(text_edit->get_selection_origin_column(1) == 19);
  5107. CHECK_FALSE(text_edit->is_caret_after_selection_origin(1));
  5108. SIGNAL_CHECK("caret_changed", empty_signal_args);
  5109. SIGNAL_CHECK_FALSE("text_changed");
  5110. SIGNAL_CHECK_FALSE("lines_edited_from");
  5111. // Deselect and put caret at selection end without shift.
  5112. SEND_GUI_ACTION("ui_text_caret_right");
  5113. CHECK(text_edit->get_viewport()->is_input_handled());
  5114. CHECK(text_edit->get_caret_count() == 2);
  5115. CHECK_FALSE(text_edit->has_selection(0));
  5116. CHECK(text_edit->get_caret_line(0) == 0);
  5117. CHECK(text_edit->get_caret_column(0) == 20);
  5118. CHECK_FALSE(text_edit->has_selection(1));
  5119. CHECK(text_edit->get_caret_line(1) == 2);
  5120. CHECK(text_edit->get_caret_column(1) == 19);
  5121. SIGNAL_CHECK("caret_changed", empty_signal_args);
  5122. SIGNAL_CHECK_FALSE("text_changed");
  5123. SIGNAL_CHECK_FALSE("lines_edited_from");
  5124. // Move caret one character to the right.
  5125. SEND_GUI_ACTION("ui_text_caret_right");
  5126. CHECK(text_edit->get_viewport()->is_input_handled());
  5127. CHECK(text_edit->get_caret_count() == 2);
  5128. CHECK_FALSE(text_edit->has_selection(0));
  5129. CHECK(text_edit->get_caret_line(0) == 0);
  5130. CHECK(text_edit->get_caret_column(0) == 21);
  5131. CHECK_FALSE(text_edit->has_selection(1));
  5132. CHECK(text_edit->get_caret_line(1) == 2);
  5133. CHECK(text_edit->get_caret_column(1) == 20);
  5134. SIGNAL_CHECK("caret_changed", empty_signal_args);
  5135. SIGNAL_CHECK_FALSE("text_changed");
  5136. SIGNAL_CHECK_FALSE("lines_edited_from");
  5137. // Select one character to the right with shift and no existing selection.
  5138. SEND_GUI_KEY_EVENT(Key::RIGHT | KeyModifierMask::SHIFT);
  5139. CHECK(text_edit->get_viewport()->is_input_handled());
  5140. CHECK(text_edit->get_caret_count() == 2);
  5141. CHECK(text_edit->has_selection(0));
  5142. CHECK(text_edit->get_selected_text(0) == "t");
  5143. CHECK(text_edit->get_caret_line(0) == 0);
  5144. CHECK(text_edit->get_caret_column(0) == 22);
  5145. CHECK(text_edit->get_selection_origin_line(0) == 0);
  5146. CHECK(text_edit->get_selection_origin_column(0) == 21);
  5147. CHECK(text_edit->is_caret_after_selection_origin(0));
  5148. CHECK(text_edit->has_selection(1));
  5149. CHECK(text_edit->get_selected_text(1) == "x");
  5150. CHECK(text_edit->get_caret_line(1) == 2);
  5151. CHECK(text_edit->get_caret_column(1) == 21);
  5152. CHECK(text_edit->get_selection_origin_line(1) == 2);
  5153. CHECK(text_edit->get_selection_origin_column(1) == 20);
  5154. CHECK(text_edit->is_caret_after_selection_origin(1));
  5155. SIGNAL_CHECK("caret_changed", empty_signal_args);
  5156. SIGNAL_CHECK_FALSE("text_changed");
  5157. SIGNAL_CHECK_FALSE("lines_edited_from");
  5158. // Moves to start of next line when at end of line. Does nothing at end of text.
  5159. text_edit->deselect();
  5160. text_edit->set_caret_line(0);
  5161. text_edit->set_caret_column(22);
  5162. text_edit->set_caret_column(22, false, 1);
  5163. MessageQueue::get_singleton()->flush();
  5164. SIGNAL_DISCARD("caret_changed");
  5165. SEND_GUI_ACTION("ui_text_caret_right");
  5166. CHECK(text_edit->get_viewport()->is_input_handled());
  5167. CHECK(text_edit->get_caret_count() == 2);
  5168. CHECK_FALSE(text_edit->has_selection(0));
  5169. CHECK(text_edit->get_caret_line(0) == 1);
  5170. CHECK(text_edit->get_caret_column(0) == 0);
  5171. CHECK_FALSE(text_edit->has_selection(1));
  5172. CHECK(text_edit->get_caret_line(1) == 2);
  5173. CHECK(text_edit->get_caret_column(1) == 22);
  5174. SIGNAL_CHECK("caret_changed", empty_signal_args);
  5175. SIGNAL_CHECK_FALSE("text_changed");
  5176. SIGNAL_CHECK_FALSE("lines_edited_from");
  5177. // Selects to start of next line when at end of line.
  5178. text_edit->remove_secondary_carets();
  5179. text_edit->set_caret_line(0);
  5180. text_edit->set_caret_column(22);
  5181. text_edit->select(0, 21, 0, 22);
  5182. MessageQueue::get_singleton()->flush();
  5183. SIGNAL_DISCARD("caret_changed");
  5184. SEND_GUI_KEY_EVENT(Key::RIGHT | KeyModifierMask::SHIFT);
  5185. CHECK(text_edit->get_viewport()->is_input_handled());
  5186. CHECK(text_edit->get_caret_count() == 1);
  5187. CHECK(text_edit->has_selection(0));
  5188. CHECK(text_edit->get_selected_text(0) == "t\n");
  5189. CHECK(text_edit->get_caret_line(0) == 1);
  5190. CHECK(text_edit->get_caret_column(0) == 0);
  5191. CHECK(text_edit->get_selection_origin_line(0) == 0);
  5192. CHECK(text_edit->get_selection_origin_column(0) == 21);
  5193. CHECK(text_edit->is_caret_after_selection_origin(0));
  5194. SIGNAL_CHECK("caret_changed", empty_signal_args);
  5195. SIGNAL_CHECK_FALSE("text_changed");
  5196. SIGNAL_CHECK_FALSE("lines_edited_from");
  5197. // Merge selections when they overlap.
  5198. text_edit->set_caret_line(0);
  5199. text_edit->set_caret_column(4);
  5200. text_edit->select(0, 4, 0, 6);
  5201. text_edit->add_caret(0, 8);
  5202. text_edit->select(0, 6, 0, 8, 1);
  5203. MessageQueue::get_singleton()->flush();
  5204. SIGNAL_DISCARD("caret_changed");
  5205. CHECK(text_edit->get_caret_count() == 2);
  5206. SEND_GUI_KEY_EVENT(Key::RIGHT | KeyModifierMask::SHIFT);
  5207. CHECK(text_edit->get_viewport()->is_input_handled());
  5208. CHECK(text_edit->get_caret_count() == 1);
  5209. CHECK(text_edit->has_selection(0));
  5210. CHECK(text_edit->get_selected_text(0) == " is s");
  5211. CHECK(text_edit->get_caret_line(0) == 0);
  5212. CHECK(text_edit->get_caret_column(0) == 9);
  5213. CHECK(text_edit->get_selection_origin_line(0) == 0);
  5214. CHECK(text_edit->get_selection_origin_column(0) == 4);
  5215. CHECK(text_edit->is_caret_after_selection_origin(0));
  5216. SIGNAL_CHECK("caret_changed", empty_signal_args);
  5217. SIGNAL_CHECK_FALSE("text_changed");
  5218. SIGNAL_CHECK_FALSE("lines_edited_from");
  5219. }
  5220. SUBCASE("[TextEdit] ui_text_caret_up") {
  5221. text_edit->set_line_wrapping_mode(TextEdit::LineWrappingMode::LINE_WRAPPING_BOUNDARY);
  5222. text_edit->set_size(Size2(110, 100));
  5223. text_edit->set_text("this is some\nother test\nlines\ngo here\nthis is some\nother test\nlines\ngo here");
  5224. text_edit->set_caret_line(3);
  5225. text_edit->set_caret_column(7);
  5226. text_edit->add_caret(7, 7);
  5227. CHECK(text_edit->get_caret_count() == 2);
  5228. MessageQueue::get_singleton()->flush();
  5229. // Lines 0 and 4 are wrapped into 2 parts: 'this is ' and 'some'.
  5230. CHECK(text_edit->is_line_wrapped(0));
  5231. SIGNAL_DISCARD("text_set");
  5232. SIGNAL_DISCARD("text_changed");
  5233. SIGNAL_DISCARD("lines_edited_from");
  5234. SIGNAL_DISCARD("caret_changed");
  5235. // Select + up should select everything to the left on that line.
  5236. SEND_GUI_KEY_EVENT(Key::UP | KeyModifierMask::SHIFT);
  5237. CHECK(text_edit->get_viewport()->is_input_handled());
  5238. CHECK(text_edit->get_caret_line() == 2);
  5239. CHECK(text_edit->get_caret_column() == 5);
  5240. CHECK(text_edit->get_selected_text(0) == "\ngo here");
  5241. CHECK(text_edit->has_selection(0));
  5242. CHECK(text_edit->get_caret_line(1) == 6);
  5243. CHECK(text_edit->get_caret_column(1) == 5);
  5244. CHECK(text_edit->get_selected_text(1) == "\ngo here");
  5245. CHECK(text_edit->has_selection(1));
  5246. SIGNAL_CHECK("caret_changed", empty_signal_args);
  5247. SIGNAL_CHECK_FALSE("text_changed");
  5248. SIGNAL_CHECK_FALSE("lines_edited_from");
  5249. // Should deselect and move up.
  5250. SEND_GUI_ACTION("ui_text_caret_up");
  5251. CHECK(text_edit->get_viewport()->is_input_handled());
  5252. CHECK(text_edit->get_caret_line() == 1);
  5253. CHECK(text_edit->get_caret_column() == 8);
  5254. CHECK_FALSE(text_edit->has_selection(0));
  5255. CHECK(text_edit->get_caret_line(1) == 5);
  5256. CHECK(text_edit->get_caret_column(1) == 8);
  5257. CHECK_FALSE(text_edit->has_selection(1));
  5258. SIGNAL_CHECK("caret_changed", empty_signal_args);
  5259. SIGNAL_CHECK_FALSE("text_changed");
  5260. SIGNAL_CHECK_FALSE("lines_edited_from");
  5261. // Normal up over wrapped line.
  5262. SEND_GUI_ACTION("ui_text_caret_up");
  5263. CHECK(text_edit->get_viewport()->is_input_handled());
  5264. CHECK(text_edit->get_caret_line() == 0);
  5265. CHECK(text_edit->get_caret_column() == 12);
  5266. CHECK_FALSE(text_edit->has_selection(0));
  5267. CHECK(text_edit->get_caret_line(1) == 4);
  5268. CHECK(text_edit->get_caret_column(1) == 12);
  5269. CHECK_FALSE(text_edit->has_selection(1));
  5270. SIGNAL_CHECK("caret_changed", empty_signal_args);
  5271. SIGNAL_CHECK_FALSE("text_changed");
  5272. SIGNAL_CHECK_FALSE("lines_edited_from");
  5273. // Normal up over wrapped line to line 0.
  5274. text_edit->set_caret_column(12, false);
  5275. SEND_GUI_ACTION("ui_text_caret_up");
  5276. CHECK(text_edit->get_viewport()->is_input_handled());
  5277. CHECK(text_edit->get_caret_line() == 0);
  5278. CHECK(text_edit->get_caret_column() == 7);
  5279. CHECK_FALSE(text_edit->has_selection(0));
  5280. CHECK(text_edit->get_caret_line(1) == 4);
  5281. CHECK(text_edit->get_caret_column(1) == 7);
  5282. CHECK_FALSE(text_edit->has_selection(1));
  5283. SIGNAL_CHECK("caret_changed", empty_signal_args);
  5284. SIGNAL_CHECK_FALSE("text_changed");
  5285. SIGNAL_CHECK_FALSE("lines_edited_from");
  5286. // Normal up from column 0 to a wrapped line.
  5287. text_edit->remove_secondary_carets();
  5288. text_edit->set_caret_line(5);
  5289. text_edit->set_caret_column(0);
  5290. SEND_GUI_ACTION("ui_text_caret_up");
  5291. CHECK(text_edit->get_viewport()->is_input_handled());
  5292. CHECK(text_edit->get_caret_line() == 4);
  5293. CHECK(text_edit->get_caret_column() == 8);
  5294. CHECK_FALSE(text_edit->has_selection(0));
  5295. // Normal up to column 0 of a wrapped line.
  5296. SEND_GUI_ACTION("ui_text_caret_up");
  5297. CHECK(text_edit->get_viewport()->is_input_handled());
  5298. CHECK(text_edit->get_caret_line() == 4);
  5299. CHECK(text_edit->get_caret_column() == 0);
  5300. CHECK_FALSE(text_edit->has_selection(0));
  5301. }
  5302. SUBCASE("[TextEdit] ui_text_caret_down") {
  5303. text_edit->set_line_wrapping_mode(TextEdit::LineWrappingMode::LINE_WRAPPING_BOUNDARY);
  5304. text_edit->set_size(Size2(110, 100));
  5305. text_edit->set_text("go here\nlines\nother test\nthis is some\ngo here\nlines\nother test\nthis is some");
  5306. text_edit->set_caret_line(0);
  5307. text_edit->set_caret_column(7);
  5308. text_edit->add_caret(4, 7);
  5309. CHECK(text_edit->get_caret_count() == 2);
  5310. MessageQueue::get_singleton()->flush();
  5311. // Lines 3 and 7 are wrapped into 2 parts: 'this is ' and 'some'.
  5312. CHECK(text_edit->is_line_wrapped(3));
  5313. SIGNAL_DISCARD("text_set");
  5314. SIGNAL_DISCARD("text_changed");
  5315. SIGNAL_DISCARD("lines_edited_from");
  5316. SIGNAL_DISCARD("caret_changed");
  5317. // Select + down should select everything to the right on that line.
  5318. SEND_GUI_KEY_EVENT(Key::DOWN | KeyModifierMask::SHIFT);
  5319. CHECK(text_edit->get_viewport()->is_input_handled());
  5320. CHECK(text_edit->get_caret_line() == 1);
  5321. CHECK(text_edit->get_caret_column() == 5);
  5322. CHECK(text_edit->get_selected_text(0) == "\nlines");
  5323. CHECK(text_edit->has_selection(0));
  5324. CHECK(text_edit->get_caret_line(1) == 5);
  5325. CHECK(text_edit->get_caret_column(1) == 5);
  5326. CHECK(text_edit->get_selected_text(1) == "\nlines");
  5327. CHECK(text_edit->has_selection(1));
  5328. SIGNAL_CHECK("caret_changed", empty_signal_args);
  5329. SIGNAL_CHECK_FALSE("text_changed");
  5330. SIGNAL_CHECK_FALSE("lines_edited_from");
  5331. // Should deselect and move down.
  5332. SEND_GUI_ACTION("ui_text_caret_down");
  5333. CHECK(text_edit->get_viewport()->is_input_handled());
  5334. CHECK(text_edit->get_caret_line() == 2);
  5335. CHECK(text_edit->get_caret_column() == 8);
  5336. CHECK_FALSE(text_edit->has_selection(0));
  5337. CHECK(text_edit->get_caret_line(1) == 6);
  5338. CHECK(text_edit->get_caret_column(1) == 8);
  5339. CHECK_FALSE(text_edit->has_selection(1));
  5340. SIGNAL_CHECK("caret_changed", empty_signal_args);
  5341. SIGNAL_CHECK_FALSE("text_changed");
  5342. SIGNAL_CHECK_FALSE("lines_edited_from");
  5343. // Normal down over wrapped line.
  5344. SEND_GUI_ACTION("ui_text_caret_down");
  5345. CHECK(text_edit->get_viewport()->is_input_handled());
  5346. CHECK(text_edit->get_caret_line() == 3);
  5347. CHECK(text_edit->get_caret_column() == 7);
  5348. CHECK_FALSE(text_edit->has_selection(0));
  5349. CHECK(text_edit->get_caret_line(1) == 7);
  5350. CHECK(text_edit->get_caret_column(1) == 7);
  5351. CHECK_FALSE(text_edit->has_selection(1));
  5352. SIGNAL_CHECK("caret_changed", empty_signal_args);
  5353. SIGNAL_CHECK_FALSE("text_changed");
  5354. SIGNAL_CHECK_FALSE("lines_edited_from");
  5355. // Normal down over wrapped line to last wrapped line.
  5356. text_edit->set_caret_column(7, false);
  5357. SEND_GUI_ACTION("ui_text_caret_down");
  5358. CHECK(text_edit->get_viewport()->is_input_handled());
  5359. CHECK(text_edit->get_caret_line() == 3);
  5360. CHECK(text_edit->get_caret_column() == 12);
  5361. CHECK_FALSE(text_edit->has_selection(0));
  5362. CHECK(text_edit->get_caret_line(1) == 7);
  5363. CHECK(text_edit->get_caret_column(1) == 12);
  5364. CHECK_FALSE(text_edit->has_selection(1));
  5365. SIGNAL_CHECK("caret_changed", empty_signal_args);
  5366. SIGNAL_CHECK_FALSE("text_changed");
  5367. SIGNAL_CHECK_FALSE("lines_edited_from");
  5368. // Normal down to column 0 of a wrapped line.
  5369. text_edit->remove_secondary_carets();
  5370. text_edit->set_caret_line(3);
  5371. text_edit->set_caret_column(0);
  5372. SEND_GUI_ACTION("ui_text_caret_down");
  5373. CHECK(text_edit->get_viewport()->is_input_handled());
  5374. CHECK(text_edit->get_caret_line() == 3);
  5375. CHECK(text_edit->get_caret_column() == 8);
  5376. CHECK_FALSE(text_edit->has_selection(0));
  5377. // Normal down out of visual column 0 of a wrapped line moves to start of next line.
  5378. SEND_GUI_ACTION("ui_text_caret_down");
  5379. CHECK(text_edit->get_viewport()->is_input_handled());
  5380. CHECK(text_edit->get_caret_line() == 4);
  5381. CHECK(text_edit->get_caret_column() == 0);
  5382. CHECK_FALSE(text_edit->has_selection(0));
  5383. }
  5384. SUBCASE("[TextEdit] ui_text_caret_document_start") {
  5385. text_edit->set_line_wrapping_mode(TextEdit::LineWrappingMode::LINE_WRAPPING_BOUNDARY);
  5386. text_edit->set_size(Size2(110, 100));
  5387. text_edit->set_text("this is some\nother test\nlines\ngo here");
  5388. text_edit->set_caret_line(4);
  5389. text_edit->set_caret_column(7);
  5390. text_edit->add_caret(3, 2);
  5391. CHECK(text_edit->get_caret_count() == 2);
  5392. MessageQueue::get_singleton()->flush();
  5393. CHECK(text_edit->is_line_wrapped(0));
  5394. SIGNAL_DISCARD("text_set");
  5395. SIGNAL_DISCARD("text_changed");
  5396. SIGNAL_DISCARD("lines_edited_from");
  5397. SIGNAL_DISCARD("caret_changed");
  5398. #ifdef MACOS_ENABLED
  5399. SEND_GUI_KEY_EVENT(Key::UP | KeyModifierMask::CMD_OR_CTRL | KeyModifierMask::SHIFT);
  5400. #else
  5401. SEND_GUI_KEY_EVENT(Key::HOME | KeyModifierMask::CMD_OR_CTRL | KeyModifierMask::SHIFT);
  5402. #endif
  5403. CHECK(text_edit->get_viewport()->is_input_handled());
  5404. CHECK(text_edit->get_text() == "this is some\nother test\nlines\ngo here");
  5405. CHECK(text_edit->get_caret_line() == 0);
  5406. CHECK(text_edit->get_caret_column() == 0);
  5407. CHECK(text_edit->get_selected_text() == "this is some\nother test\nlines\ngo here");
  5408. CHECK(text_edit->has_selection());
  5409. SIGNAL_CHECK("caret_changed", empty_signal_args);
  5410. SIGNAL_CHECK_FALSE("text_changed");
  5411. SIGNAL_CHECK_FALSE("lines_edited_from");
  5412. CHECK(text_edit->get_caret_count() == 1);
  5413. SEND_GUI_ACTION("ui_text_caret_document_start");
  5414. CHECK(text_edit->get_viewport()->is_input_handled());
  5415. CHECK(text_edit->get_text() == "this is some\nother test\nlines\ngo here");
  5416. CHECK(text_edit->get_caret_line() == 0);
  5417. CHECK(text_edit->get_caret_column() == 0);
  5418. CHECK_FALSE(text_edit->has_selection());
  5419. SIGNAL_CHECK_FALSE("caret_changed");
  5420. SIGNAL_CHECK_FALSE("text_changed");
  5421. SIGNAL_CHECK_FALSE("lines_edited_from");
  5422. }
  5423. SUBCASE("[TextEdit] ui_text_caret_document_end") {
  5424. text_edit->set_line_wrapping_mode(TextEdit::LineWrappingMode::LINE_WRAPPING_BOUNDARY);
  5425. text_edit->set_size(Size2(110, 100));
  5426. text_edit->set_text("go here\nlines\nother test\nthis is some");
  5427. text_edit->set_caret_line(0);
  5428. text_edit->set_caret_column(0);
  5429. text_edit->add_caret(1, 0);
  5430. CHECK(text_edit->get_caret_count() == 2);
  5431. MessageQueue::get_singleton()->flush();
  5432. CHECK(text_edit->is_line_wrapped(3));
  5433. SIGNAL_DISCARD("text_set");
  5434. SIGNAL_DISCARD("text_changed");
  5435. SIGNAL_DISCARD("lines_edited_from");
  5436. SIGNAL_DISCARD("caret_changed");
  5437. #ifdef MACOS_ENABLED
  5438. SEND_GUI_KEY_EVENT(Key::DOWN | KeyModifierMask::CMD_OR_CTRL | KeyModifierMask::SHIFT);
  5439. #else
  5440. SEND_GUI_KEY_EVENT(Key::END | KeyModifierMask::CMD_OR_CTRL | KeyModifierMask::SHIFT);
  5441. #endif
  5442. CHECK(text_edit->get_viewport()->is_input_handled());
  5443. CHECK(text_edit->get_text() == "go here\nlines\nother test\nthis is some");
  5444. CHECK(text_edit->get_caret_line() == 3);
  5445. CHECK(text_edit->get_caret_column() == 12);
  5446. CHECK(text_edit->get_selected_text() == "go here\nlines\nother test\nthis is some");
  5447. CHECK(text_edit->has_selection());
  5448. SIGNAL_CHECK("caret_changed", empty_signal_args);
  5449. SIGNAL_CHECK_FALSE("text_changed");
  5450. SIGNAL_CHECK_FALSE("lines_edited_from");
  5451. CHECK(text_edit->get_caret_count() == 1);
  5452. SEND_GUI_ACTION("ui_text_caret_document_end");
  5453. CHECK(text_edit->get_viewport()->is_input_handled());
  5454. CHECK(text_edit->get_text() == "go here\nlines\nother test\nthis is some");
  5455. CHECK(text_edit->get_caret_line() == 3);
  5456. CHECK(text_edit->get_caret_column() == 12);
  5457. CHECK_FALSE(text_edit->has_selection());
  5458. SIGNAL_CHECK_FALSE("caret_changed");
  5459. SIGNAL_CHECK_FALSE("text_changed");
  5460. SIGNAL_CHECK_FALSE("lines_edited_from");
  5461. }
  5462. SUBCASE("[TextEdit] ui_text_caret_line_start") {
  5463. text_edit->set_line_wrapping_mode(TextEdit::LineWrappingMode::LINE_WRAPPING_BOUNDARY);
  5464. text_edit->set_size(Size2(110, 100));
  5465. text_edit->set_text(" this is some\n this is some");
  5466. text_edit->set_caret_line(0);
  5467. text_edit->set_caret_column(text_edit->get_line(0).length());
  5468. text_edit->add_caret(1, text_edit->get_line(1).length());
  5469. CHECK(text_edit->get_caret_count() == 2);
  5470. MessageQueue::get_singleton()->flush();
  5471. CHECK(text_edit->is_line_wrapped(0));
  5472. SIGNAL_DISCARD("text_set");
  5473. SIGNAL_DISCARD("text_changed");
  5474. SIGNAL_DISCARD("lines_edited_from");
  5475. SIGNAL_DISCARD("caret_changed");
  5476. #ifdef MACOS_ENABLED
  5477. SEND_GUI_KEY_EVENT(Key::LEFT | KeyModifierMask::CMD_OR_CTRL | KeyModifierMask::SHIFT);
  5478. #else
  5479. SEND_GUI_KEY_EVENT(Key::HOME | KeyModifierMask::SHIFT);
  5480. #endif
  5481. CHECK(text_edit->get_viewport()->is_input_handled());
  5482. CHECK(text_edit->get_caret_line() == 0);
  5483. CHECK(text_edit->get_caret_column() == 10);
  5484. CHECK(text_edit->has_selection(0));
  5485. CHECK(text_edit->get_selected_text(0) == "some");
  5486. CHECK(text_edit->get_caret_line(1) == 1);
  5487. CHECK(text_edit->get_caret_column(1) == 10);
  5488. CHECK(text_edit->has_selection(1));
  5489. CHECK(text_edit->get_selected_text(1) == "some");
  5490. SIGNAL_CHECK("caret_changed", empty_signal_args);
  5491. SIGNAL_CHECK_FALSE("text_changed");
  5492. SIGNAL_CHECK_FALSE("lines_edited_from");
  5493. SEND_GUI_ACTION("ui_text_caret_line_start");
  5494. CHECK(text_edit->get_viewport()->is_input_handled());
  5495. CHECK(text_edit->get_caret_line() == 0);
  5496. CHECK(text_edit->get_caret_column() == 2);
  5497. CHECK_FALSE(text_edit->has_selection(0));
  5498. CHECK(text_edit->get_caret_line(1) == 1);
  5499. CHECK(text_edit->get_caret_column(1) == 2);
  5500. CHECK_FALSE(text_edit->has_selection(1));
  5501. SIGNAL_CHECK("caret_changed", empty_signal_args);
  5502. SIGNAL_CHECK_FALSE("text_changed");
  5503. SIGNAL_CHECK_FALSE("lines_edited_from");
  5504. SEND_GUI_ACTION("ui_text_caret_line_start");
  5505. CHECK(text_edit->get_viewport()->is_input_handled());
  5506. CHECK(text_edit->get_caret_line() == 0);
  5507. CHECK(text_edit->get_caret_column() == 0);
  5508. CHECK_FALSE(text_edit->has_selection(0));
  5509. CHECK(text_edit->get_caret_line(1) == 1);
  5510. CHECK(text_edit->get_caret_column(1) == 0);
  5511. CHECK_FALSE(text_edit->has_selection(1));
  5512. SIGNAL_CHECK("caret_changed", empty_signal_args);
  5513. SIGNAL_CHECK_FALSE("text_changed");
  5514. SIGNAL_CHECK_FALSE("lines_edited_from");
  5515. SEND_GUI_ACTION("ui_text_caret_line_start");
  5516. CHECK(text_edit->get_viewport()->is_input_handled());
  5517. CHECK(text_edit->get_caret_line() == 0);
  5518. CHECK(text_edit->get_caret_column() == 2);
  5519. CHECK_FALSE(text_edit->has_selection(0));
  5520. CHECK(text_edit->get_caret_line(1) == 1);
  5521. CHECK(text_edit->get_caret_column(1) == 2);
  5522. CHECK_FALSE(text_edit->has_selection(1));
  5523. SIGNAL_CHECK("caret_changed", empty_signal_args);
  5524. SIGNAL_CHECK_FALSE("text_changed");
  5525. SIGNAL_CHECK_FALSE("lines_edited_from");
  5526. }
  5527. SUBCASE("[TextEdit] ui_text_caret_line_end") {
  5528. text_edit->set_line_wrapping_mode(TextEdit::LineWrappingMode::LINE_WRAPPING_BOUNDARY);
  5529. text_edit->set_size(Size2(110, 100));
  5530. text_edit->set_text(" this is some\n this is some");
  5531. text_edit->set_caret_line(0);
  5532. text_edit->set_caret_column(0);
  5533. text_edit->add_caret(1, 0);
  5534. CHECK(text_edit->get_caret_count() == 2);
  5535. MessageQueue::get_singleton()->flush();
  5536. CHECK(text_edit->is_line_wrapped(0));
  5537. SIGNAL_DISCARD("text_set");
  5538. SIGNAL_DISCARD("text_changed");
  5539. SIGNAL_DISCARD("lines_edited_from");
  5540. SIGNAL_DISCARD("caret_changed");
  5541. #ifdef MACOS_ENABLED
  5542. SEND_GUI_KEY_EVENT(Key::RIGHT | KeyModifierMask::CMD_OR_CTRL | KeyModifierMask::SHIFT);
  5543. #else
  5544. SEND_GUI_KEY_EVENT(Key::END | KeyModifierMask::SHIFT);
  5545. #endif
  5546. CHECK(text_edit->get_viewport()->is_input_handled());
  5547. CHECK(text_edit->get_caret_line() == 0);
  5548. CHECK(text_edit->get_caret_column() == 9);
  5549. CHECK(text_edit->has_selection(0));
  5550. CHECK(text_edit->get_selected_text(0) == " this is");
  5551. CHECK(text_edit->get_caret_line(1) == 1);
  5552. CHECK(text_edit->get_caret_column(1) == 9);
  5553. CHECK(text_edit->has_selection(1));
  5554. CHECK(text_edit->get_selected_text(1) == " this is");
  5555. SIGNAL_CHECK("caret_changed", empty_signal_args);
  5556. SIGNAL_CHECK_FALSE("text_changed");
  5557. SIGNAL_CHECK_FALSE("lines_edited_from");
  5558. SEND_GUI_ACTION("ui_text_caret_line_end");
  5559. CHECK(text_edit->get_viewport()->is_input_handled());
  5560. CHECK(text_edit->get_caret_line() == 0);
  5561. CHECK(text_edit->get_caret_column() == text_edit->get_line(0).length());
  5562. CHECK_FALSE(text_edit->has_selection(0));
  5563. CHECK(text_edit->get_viewport()->is_input_handled());
  5564. CHECK(text_edit->get_caret_line(1) == 1);
  5565. CHECK(text_edit->get_caret_column(1) == text_edit->get_line(1).length());
  5566. CHECK_FALSE(text_edit->has_selection(1));
  5567. SIGNAL_CHECK("caret_changed", empty_signal_args);
  5568. SIGNAL_CHECK_FALSE("text_changed");
  5569. SIGNAL_CHECK_FALSE("lines_edited_from");
  5570. }
  5571. SUBCASE("[TextEdit] unicode") {
  5572. text_edit->set_text("\n");
  5573. text_edit->set_caret_line(0);
  5574. text_edit->set_caret_column(0);
  5575. text_edit->add_caret(1, 0);
  5576. CHECK(text_edit->get_caret_count() == 2);
  5577. text_edit->insert_text_at_caret("a");
  5578. MessageQueue::get_singleton()->flush();
  5579. SIGNAL_DISCARD("text_set");
  5580. SIGNAL_DISCARD("text_changed");
  5581. SIGNAL_DISCARD("lines_edited_from");
  5582. SIGNAL_DISCARD("caret_changed");
  5583. lines_edited_args = build_array(build_array(0, 0), build_array(1, 1));
  5584. SEND_GUI_KEY_EVENT(Key::A);
  5585. CHECK(text_edit->get_viewport()->is_input_handled());
  5586. CHECK(text_edit->get_text() == "aA\naA");
  5587. CHECK(text_edit->get_caret_column() == 2);
  5588. CHECK(text_edit->get_caret_column(1) == 2);
  5589. SIGNAL_CHECK("caret_changed", empty_signal_args);
  5590. SIGNAL_CHECK("text_changed", empty_signal_args);
  5591. SIGNAL_CHECK("lines_edited_from", lines_edited_args);
  5592. // Undo reverts both carets.
  5593. text_edit->undo();
  5594. MessageQueue::get_singleton()->flush();
  5595. CHECK(text_edit->get_text() == "a\na");
  5596. CHECK(text_edit->get_caret_column() == 1);
  5597. CHECK(text_edit->get_caret_column(1) == 1);
  5598. SIGNAL_CHECK("caret_changed", empty_signal_args);
  5599. SIGNAL_CHECK("text_changed", empty_signal_args);
  5600. SIGNAL_CHECK("lines_edited_from", reverse_nested(lines_edited_args));
  5601. // Redo.
  5602. text_edit->redo();
  5603. MessageQueue::get_singleton()->flush();
  5604. CHECK(text_edit->get_text() == "aA\naA");
  5605. CHECK(text_edit->get_caret_column() == 2);
  5606. CHECK(text_edit->get_caret_column(1) == 2);
  5607. SIGNAL_CHECK("caret_changed", empty_signal_args);
  5608. SIGNAL_CHECK("text_changed", empty_signal_args);
  5609. SIGNAL_CHECK("lines_edited_from", lines_edited_args);
  5610. // Does not work if not editable.
  5611. text_edit->set_editable(false);
  5612. SEND_GUI_KEY_EVENT(Key::A);
  5613. CHECK_FALSE(text_edit->get_viewport()->is_input_handled()); // Should this be handled?
  5614. CHECK(text_edit->get_text() == "aA\naA");
  5615. CHECK(text_edit->get_caret_column() == 2);
  5616. CHECK(text_edit->get_caret_column(1) == 2);
  5617. SIGNAL_CHECK_FALSE("caret_changed");
  5618. SIGNAL_CHECK_FALSE("text_changed");
  5619. SIGNAL_CHECK_FALSE("lines_edited_from");
  5620. text_edit->set_editable(true);
  5621. lines_edited_args = build_array(build_array(0, 0), build_array(0, 0), build_array(1, 1), build_array(1, 1));
  5622. text_edit->select(0, 0, 0, 1);
  5623. text_edit->select(1, 0, 1, 1, 1);
  5624. SEND_GUI_KEY_EVENT(Key::B);
  5625. CHECK(text_edit->get_viewport()->is_input_handled());
  5626. CHECK(text_edit->get_text() == "BA\nBA");
  5627. CHECK(text_edit->get_caret_column() == 1);
  5628. CHECK(text_edit->get_caret_column(1) == 1);
  5629. SIGNAL_CHECK("caret_changed", empty_signal_args);
  5630. SIGNAL_CHECK("text_changed", empty_signal_args);
  5631. SIGNAL_CHECK("lines_edited_from", lines_edited_args);
  5632. SEND_GUI_ACTION("ui_text_toggle_insert_mode");
  5633. CHECK(text_edit->is_overtype_mode_enabled());
  5634. SEND_GUI_KEY_EVENT(Key::B);
  5635. CHECK(text_edit->get_viewport()->is_input_handled());
  5636. CHECK(text_edit->get_text() == "BB\nBB");
  5637. CHECK(text_edit->get_caret_column() == 2);
  5638. SIGNAL_CHECK("caret_changed", empty_signal_args);
  5639. SIGNAL_CHECK("text_changed", empty_signal_args);
  5640. SIGNAL_CHECK("lines_edited_from", lines_edited_args);
  5641. text_edit->select(0, 0, 0, 1);
  5642. text_edit->select(1, 0, 1, 1, 1);
  5643. SEND_GUI_KEY_EVENT(Key::A);
  5644. CHECK(text_edit->get_viewport()->is_input_handled());
  5645. CHECK(text_edit->get_text() == "AB\nAB");
  5646. CHECK(text_edit->get_caret_column() == 1);
  5647. CHECK(text_edit->get_caret_column(1) == 1);
  5648. SIGNAL_CHECK("caret_changed", empty_signal_args);
  5649. SIGNAL_CHECK("text_changed", empty_signal_args);
  5650. SIGNAL_CHECK("lines_edited_from", lines_edited_args);
  5651. text_edit->set_overtype_mode_enabled(false);
  5652. CHECK_FALSE(text_edit->is_overtype_mode_enabled());
  5653. lines_edited_args = build_array(build_array(0, 0), build_array(1, 1));
  5654. SEND_GUI_KEY_EVENT(Key::TAB);
  5655. CHECK(text_edit->get_viewport()->is_input_handled());
  5656. CHECK(text_edit->get_text() == "A\tB\nA\tB");
  5657. CHECK(text_edit->get_caret_column() == 2);
  5658. CHECK(text_edit->get_caret_column(1) == 2);
  5659. SIGNAL_CHECK("caret_changed", empty_signal_args);
  5660. SIGNAL_CHECK("text_changed", empty_signal_args);
  5661. SIGNAL_CHECK("lines_edited_from", lines_edited_args);
  5662. }
  5663. SIGNAL_UNWATCH(text_edit, "text_set");
  5664. SIGNAL_UNWATCH(text_edit, "text_changed");
  5665. SIGNAL_UNWATCH(text_edit, "lines_edited_from");
  5666. SIGNAL_UNWATCH(text_edit, "caret_changed");
  5667. }
  5668. memdelete(text_edit);
  5669. }
  5670. TEST_CASE("[SceneTree][TextEdit] context menu") {
  5671. TextEdit *text_edit = memnew(TextEdit);
  5672. SceneTree::get_singleton()->get_root()->add_child(text_edit);
  5673. text_edit->set_size(Size2(800, 200));
  5674. text_edit->set_line(0, "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec vasius mattis leo, sed porta ex lacinia bibendum. Nunc bibendum pellentesque.");
  5675. MessageQueue::get_singleton()->flush();
  5676. text_edit->set_context_menu_enabled(false);
  5677. CHECK_FALSE(text_edit->is_context_menu_enabled());
  5678. CHECK_FALSE(text_edit->is_menu_visible());
  5679. SEND_GUI_MOUSE_BUTTON_EVENT(Point2i(600, 10), MouseButton::RIGHT, MouseButtonMask::RIGHT, Key::NONE);
  5680. CHECK_FALSE(text_edit->is_menu_visible());
  5681. text_edit->set_context_menu_enabled(true);
  5682. CHECK(text_edit->is_context_menu_enabled());
  5683. CHECK_FALSE(text_edit->is_menu_visible());
  5684. SEND_GUI_MOUSE_BUTTON_EVENT(Point2i(700, 10), MouseButton::RIGHT, MouseButtonMask::RIGHT, Key::NONE);
  5685. CHECK(text_edit->is_menu_visible());
  5686. memdelete(text_edit);
  5687. }
  5688. TEST_CASE("[SceneTree][TextEdit] versioning") {
  5689. TextEdit *text_edit = memnew(TextEdit);
  5690. SceneTree::get_singleton()->get_root()->add_child(text_edit);
  5691. // Action undo / redo states are tested in the action test e.g selection_delete.
  5692. CHECK_FALSE(text_edit->has_undo());
  5693. CHECK_FALSE(text_edit->has_redo());
  5694. CHECK(text_edit->get_version() == 0);
  5695. CHECK(text_edit->get_saved_version() == 0);
  5696. text_edit->begin_complex_operation();
  5697. text_edit->begin_complex_operation();
  5698. text_edit->begin_complex_operation();
  5699. text_edit->insert_text_at_caret("test");
  5700. CHECK(text_edit->get_version() == 1);
  5701. CHECK(text_edit->get_saved_version() == 0);
  5702. CHECK(text_edit->has_undo());
  5703. CHECK_FALSE(text_edit->has_redo());
  5704. text_edit->end_complex_operation();
  5705. // Can undo and redo mid op.
  5706. text_edit->insert_text_at_caret(" nested");
  5707. CHECK(text_edit->get_version() == 2);
  5708. CHECK(text_edit->get_saved_version() == 0);
  5709. CHECK(text_edit->has_undo());
  5710. CHECK_FALSE(text_edit->has_redo());
  5711. text_edit->undo();
  5712. CHECK(text_edit->has_redo());
  5713. text_edit->redo();
  5714. text_edit->end_complex_operation();
  5715. text_edit->insert_text_at_caret(" ops");
  5716. CHECK(text_edit->get_version() == 3);
  5717. CHECK(text_edit->get_saved_version() == 0);
  5718. CHECK(text_edit->has_undo());
  5719. CHECK_FALSE(text_edit->has_redo());
  5720. text_edit->end_complex_operation();
  5721. text_edit->tag_saved_version();
  5722. CHECK(text_edit->get_saved_version() == 3);
  5723. text_edit->undo();
  5724. CHECK(text_edit->get_line(0) == "");
  5725. CHECK(text_edit->get_version() == 0);
  5726. CHECK(text_edit->get_saved_version() == 3);
  5727. CHECK_FALSE(text_edit->has_undo());
  5728. CHECK(text_edit->has_redo());
  5729. text_edit->redo();
  5730. CHECK(text_edit->get_line(0) == "test ops nested");
  5731. CHECK(text_edit->get_version() == 3);
  5732. CHECK(text_edit->get_saved_version() == 3);
  5733. CHECK(text_edit->has_undo());
  5734. CHECK_FALSE(text_edit->has_redo());
  5735. text_edit->clear_undo_history();
  5736. CHECK_FALSE(text_edit->has_undo());
  5737. CHECK_FALSE(text_edit->has_redo());
  5738. CHECK(text_edit->get_version() == 3); // Should this be cleared?
  5739. CHECK(text_edit->get_saved_version() == 0);
  5740. SUBCASE("[TextEdit] versioning selection") {
  5741. text_edit->set_text("Godot Engine\nWaiting for Godot\nTest Text for multi carat\nLine 4 Text");
  5742. text_edit->set_multiple_carets_enabled(true);
  5743. text_edit->remove_secondary_carets();
  5744. text_edit->deselect();
  5745. text_edit->set_caret_line(0);
  5746. text_edit->set_caret_column(0);
  5747. CHECK(text_edit->get_caret_count() == 1);
  5748. Array caret_index;
  5749. caret_index.push_back(0);
  5750. for (int i = 1; i < 4; i++) {
  5751. caret_index.push_back(text_edit->add_caret(i, 0));
  5752. CHECK((int)caret_index.back() >= 0);
  5753. }
  5754. CHECK(text_edit->get_caret_count() == 4);
  5755. for (int i = 0; i < 4; i++) {
  5756. text_edit->select(i, 0, i, 5, caret_index[i]);
  5757. }
  5758. CHECK(text_edit->get_caret_count() == 4);
  5759. for (int i = 0; i < 4; i++) {
  5760. CHECK(text_edit->has_selection(caret_index[i]));
  5761. CHECK(text_edit->get_selection_from_line(caret_index[i]) == i);
  5762. CHECK(text_edit->get_selection_from_column(caret_index[i]) == 0);
  5763. CHECK(text_edit->get_selection_to_line(caret_index[i]) == i);
  5764. CHECK(text_edit->get_selection_to_column(caret_index[i]) == 5);
  5765. }
  5766. text_edit->begin_complex_operation();
  5767. text_edit->deselect();
  5768. text_edit->set_text("New Line Text");
  5769. text_edit->select(0, 0, 0, 7, 0);
  5770. text_edit->end_complex_operation();
  5771. CHECK(text_edit->get_caret_count() == 1);
  5772. CHECK(text_edit->get_selected_text(0) == "New Lin");
  5773. text_edit->undo();
  5774. CHECK(text_edit->get_caret_count() == 4);
  5775. for (int i = 0; i < 4; i++) {
  5776. CHECK(text_edit->has_selection(caret_index[i]));
  5777. CHECK(text_edit->get_selection_from_line(caret_index[i]) == i);
  5778. CHECK(text_edit->get_selection_from_column(caret_index[i]) == 0);
  5779. CHECK(text_edit->get_selection_to_line(caret_index[i]) == i);
  5780. CHECK(text_edit->get_selection_to_column(caret_index[i]) == 5);
  5781. }
  5782. }
  5783. memdelete(text_edit);
  5784. }
  5785. TEST_CASE("[SceneTree][TextEdit] search") {
  5786. TextEdit *text_edit = memnew(TextEdit);
  5787. SceneTree::get_singleton()->get_root()->add_child(text_edit);
  5788. text_edit->set_text("hay needle, hay\nHAY NEEDLE, HAY\nwordword.word.word");
  5789. int length = text_edit->get_line(1).length();
  5790. CHECK(text_edit->search("test", 0, 0, 0) == Point2i(-1, -1));
  5791. CHECK(text_edit->search("test", TextEdit::SEARCH_MATCH_CASE, 0, 0) == Point2i(-1, -1));
  5792. CHECK(text_edit->search("test", TextEdit::SEARCH_WHOLE_WORDS, 0, 0) == Point2i(-1, -1));
  5793. CHECK(text_edit->search("test", TextEdit::SEARCH_BACKWARDS, 0, 0) == Point2i(-1, -1));
  5794. CHECK(text_edit->search("test", 0, 1, length) == Point2i(-1, -1));
  5795. CHECK(text_edit->search("test", TextEdit::SEARCH_MATCH_CASE, 1, length) == Point2i(-1, -1));
  5796. CHECK(text_edit->search("test", TextEdit::SEARCH_WHOLE_WORDS, 1, length) == Point2i(-1, -1));
  5797. CHECK(text_edit->search("test", TextEdit::SEARCH_BACKWARDS, 1, length) == Point2i(-1, -1));
  5798. CHECK(text_edit->search("needle", 0, 0, 0) == Point2i(4, 0));
  5799. CHECK(text_edit->search("needle", 0, 1, length) == Point2i(4, 0));
  5800. CHECK(text_edit->search("needle", 0, 0, 5) == Point2i(4, 1));
  5801. CHECK(text_edit->search("needle", TextEdit::SEARCH_BACKWARDS, 0, 0) == Point2i(4, 1));
  5802. CHECK(text_edit->search("needle", TextEdit::SEARCH_BACKWARDS, 1, 5) == Point2i(4, 1));
  5803. CHECK(text_edit->search("needle", TextEdit::SEARCH_BACKWARDS, 1, 3) == Point2i(4, 0));
  5804. CHECK(text_edit->search("needle", TextEdit::SEARCH_MATCH_CASE, 0, 0) == Point2i(4, 0));
  5805. CHECK(text_edit->search("needle", TextEdit::SEARCH_MATCH_CASE | TextEdit::SEARCH_BACKWARDS, 0, 0) == Point2i(4, 0));
  5806. CHECK(text_edit->search("needle", TextEdit::SEARCH_WHOLE_WORDS | TextEdit::SEARCH_MATCH_CASE, 0, 0) == Point2i(4, 0));
  5807. CHECK(text_edit->search("needle", TextEdit::SEARCH_WHOLE_WORDS | TextEdit::SEARCH_MATCH_CASE | TextEdit::SEARCH_BACKWARDS, 0, 0) == Point2i(4, 0));
  5808. CHECK(text_edit->search("need", TextEdit::SEARCH_MATCH_CASE, 0, 0) == Point2i(4, 0));
  5809. CHECK(text_edit->search("need", TextEdit::SEARCH_MATCH_CASE | TextEdit::SEARCH_BACKWARDS, 0, 0) == Point2i(4, 0));
  5810. CHECK(text_edit->search("need", TextEdit::SEARCH_WHOLE_WORDS | TextEdit::SEARCH_MATCH_CASE, 0, 0) == Point2i(-1, -1));
  5811. CHECK(text_edit->search("need", TextEdit::SEARCH_WHOLE_WORDS | TextEdit::SEARCH_MATCH_CASE | TextEdit::SEARCH_BACKWARDS, 0, 0) == Point2i(-1, -1));
  5812. CHECK(text_edit->search("word", TextEdit::SEARCH_WHOLE_WORDS, 2, 0) == Point2i(9, 2));
  5813. CHECK(text_edit->search("word", TextEdit::SEARCH_WHOLE_WORDS, 2, 10) == Point2i(14, 2));
  5814. CHECK(text_edit->search(".word", TextEdit::SEARCH_WHOLE_WORDS, 2, 0) == Point2i(8, 2));
  5815. CHECK(text_edit->search("word.", TextEdit::SEARCH_WHOLE_WORDS, 2, 0) == Point2i(9, 2));
  5816. ERR_PRINT_OFF;
  5817. CHECK(text_edit->search("", 0, 0, 0) == Point2i(-1, -1));
  5818. CHECK(text_edit->search("needle", 0, -1, 0) == Point2i(-1, -1));
  5819. CHECK(text_edit->search("needle", 0, 0, -1) == Point2i(-1, -1));
  5820. CHECK(text_edit->search("needle", 0, 100, 0) == Point2i(-1, -1));
  5821. CHECK(text_edit->search("needle", 0, 0, 100) == Point2i(-1, -1));
  5822. ERR_PRINT_ON;
  5823. memdelete(text_edit);
  5824. }
  5825. TEST_CASE("[SceneTree][TextEdit] mouse") {
  5826. TextEdit *text_edit = memnew(TextEdit);
  5827. SceneTree::get_singleton()->get_root()->add_child(text_edit);
  5828. text_edit->set_size(Size2(800, 200));
  5829. CHECK(text_edit->get_rect_at_line_column(0, 0).get_position() == Point2i(0, 0));
  5830. text_edit->set_line(0, "A");
  5831. MessageQueue::get_singleton()->flush();
  5832. CHECK(text_edit->get_rect_at_line_column(0, 1).get_position().x > 0);
  5833. text_edit->clear(); // Necessary, otherwise the following test cases fail.
  5834. text_edit->set_line(0, "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec vasius mattis leo, sed porta ex lacinia bibendum. Nunc bibendum pellentesque.");
  5835. MessageQueue::get_singleton()->flush();
  5836. CHECK(text_edit->get_word_at_pos(text_edit->get_pos_at_line_column(0, 1)) == "Lorem");
  5837. CHECK(text_edit->get_word_at_pos(text_edit->get_pos_at_line_column(0, 9)) == "ipsum");
  5838. ERR_PRINT_OFF;
  5839. CHECK(text_edit->get_pos_at_line_column(0, -1) == Point2i(-1, -1));
  5840. CHECK(text_edit->get_pos_at_line_column(-1, 0) == Point2i(-1, -1));
  5841. CHECK(text_edit->get_pos_at_line_column(-1, -1) == Point2i(-1, -1));
  5842. CHECK(text_edit->get_pos_at_line_column(0, 500) == Point2i(-1, -1));
  5843. CHECK(text_edit->get_pos_at_line_column(2, 0) == Point2i(-1, -1));
  5844. CHECK(text_edit->get_pos_at_line_column(2, 500) == Point2i(-1, -1));
  5845. // Out of view.
  5846. CHECK(text_edit->get_pos_at_line_column(0, text_edit->get_line(0).length() - 1) == Point2i(-1, -1));
  5847. ERR_PRINT_ON;
  5848. // Add method to get drawn column count?
  5849. Point2i start_pos = text_edit->get_pos_at_line_column(0, 0);
  5850. Point2i end_pos = text_edit->get_pos_at_line_column(0, 105);
  5851. CHECK(text_edit->get_line_column_at_pos(Point2i(start_pos.x, start_pos.y)) == Point2i(0, 0));
  5852. CHECK(text_edit->get_line_column_at_pos(Point2i(end_pos.x, end_pos.y)) == Point2i(104, 0));
  5853. // Should this return Point2i(-1, -1) if its also < 0 not just > vis_lines.
  5854. CHECK(text_edit->get_line_column_at_pos(Point2i(end_pos.x - 100, end_pos.y), false) == Point2i(90, 0));
  5855. CHECK(text_edit->get_line_column_at_pos(Point2i(end_pos.x, end_pos.y + 100), false) == Point2i(-1, -1));
  5856. CHECK(text_edit->get_line_column_at_pos(Point2i(end_pos.x - 100, end_pos.y + 100), false) == Point2i(-1, -1));
  5857. CHECK(text_edit->get_line_column_at_pos(Point2i(end_pos.x, end_pos.y - 100), false) == Point2i(104, 0));
  5858. CHECK(text_edit->get_line_column_at_pos(Point2i(end_pos.x - 100, end_pos.y - 100), false) == Point2i(90, 0));
  5859. CHECK(text_edit->get_line_column_at_pos(Point2i(end_pos.x - 100, end_pos.y)) == Point2i(90, 0));
  5860. CHECK(text_edit->get_line_column_at_pos(Point2i(end_pos.x, end_pos.y + 100)) == Point2i(140, 0));
  5861. CHECK(text_edit->get_line_column_at_pos(Point2i(end_pos.x - 100, end_pos.y + 100)) == Point2i(140, 0));
  5862. CHECK(text_edit->get_line_column_at_pos(Point2i(end_pos.x, end_pos.y - 100)) == Point2i(104, 0));
  5863. CHECK(text_edit->get_line_column_at_pos(Point2i(end_pos.x - 100, end_pos.y - 100)) == Point2i(90, 0));
  5864. memdelete(text_edit);
  5865. }
  5866. TEST_CASE("[SceneTree][TextEdit] caret") {
  5867. TextEdit *text_edit = memnew(TextEdit);
  5868. text_edit->set_context_menu_enabled(false); // Prohibit sending InputEvents to the context menu.
  5869. SceneTree::get_singleton()->get_root()->add_child(text_edit);
  5870. text_edit->set_size(Size2(800, 200));
  5871. text_edit->grab_focus();
  5872. text_edit->set_line(0, "ffi");
  5873. text_edit->set_caret_mid_grapheme_enabled(true);
  5874. CHECK(text_edit->is_caret_mid_grapheme_enabled());
  5875. SEND_GUI_ACTION("ui_text_caret_right");
  5876. CHECK(text_edit->get_caret_column() == 1);
  5877. SEND_GUI_ACTION("ui_text_caret_right");
  5878. CHECK(text_edit->get_caret_column() == 2);
  5879. SEND_GUI_ACTION("ui_text_caret_right");
  5880. CHECK(text_edit->get_caret_column() == 3);
  5881. SEND_GUI_ACTION("ui_text_caret_left");
  5882. CHECK(text_edit->get_caret_column() == 2);
  5883. text_edit->set_line(0, "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec vasius mattis leo, sed porta ex lacinia bibendum. Nunc bibendum pellentesque.");
  5884. for (int i = 0; i < 3; i++) {
  5885. text_edit->insert_line_at(0, "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec vasius mattis leo, sed porta ex lacinia bibendum. Nunc bibendum pellentesque.");
  5886. }
  5887. MessageQueue::get_singleton()->flush();
  5888. text_edit->set_caret_blink_enabled(false);
  5889. CHECK_FALSE(text_edit->is_caret_blink_enabled());
  5890. text_edit->set_caret_blink_enabled(true);
  5891. CHECK(text_edit->is_caret_blink_enabled());
  5892. text_edit->set_caret_blink_interval(10);
  5893. CHECK(text_edit->get_caret_blink_interval() == 10);
  5894. ERR_PRINT_OFF;
  5895. text_edit->set_caret_blink_interval(-1);
  5896. CHECK(text_edit->get_caret_blink_interval() == 10);
  5897. text_edit->set_caret_blink_interval(0);
  5898. CHECK(text_edit->get_caret_blink_interval() == 10);
  5899. ERR_PRINT_ON;
  5900. text_edit->set_caret_type(TextEdit::CaretType::CARET_TYPE_LINE);
  5901. CHECK(text_edit->get_caret_type() == TextEdit::CaretType::CARET_TYPE_LINE);
  5902. text_edit->set_caret_type(TextEdit::CaretType::CARET_TYPE_BLOCK);
  5903. CHECK(text_edit->get_caret_type() == TextEdit::CaretType::CARET_TYPE_BLOCK);
  5904. text_edit->set_caret_type(TextEdit::CaretType::CARET_TYPE_LINE);
  5905. CHECK(text_edit->get_caret_type() == TextEdit::CaretType::CARET_TYPE_LINE);
  5906. int caret_col = text_edit->get_caret_column();
  5907. text_edit->set_move_caret_on_right_click_enabled(false);
  5908. CHECK_FALSE(text_edit->is_move_caret_on_right_click_enabled());
  5909. SEND_GUI_MOUSE_BUTTON_EVENT(Point2i(100, 1), MouseButton::RIGHT, MouseButtonMask::RIGHT, Key::NONE);
  5910. CHECK(text_edit->get_caret_column() == caret_col);
  5911. text_edit->set_move_caret_on_right_click_enabled(true);
  5912. CHECK(text_edit->is_move_caret_on_right_click_enabled());
  5913. SEND_GUI_MOUSE_BUTTON_EVENT(Point2i(100, 1), MouseButton::RIGHT, MouseButtonMask::RIGHT, Key::NONE);
  5914. CHECK(text_edit->get_caret_column() != caret_col);
  5915. text_edit->set_move_caret_on_right_click_enabled(false);
  5916. CHECK_FALSE(text_edit->is_move_caret_on_right_click_enabled());
  5917. text_edit->set_caret_column(0);
  5918. CHECK(text_edit->get_word_under_caret() == "Lorem");
  5919. text_edit->set_caret_column(4);
  5920. CHECK(text_edit->get_word_under_caret() == "Lorem");
  5921. text_edit->set_caret_column(1);
  5922. text_edit->add_caret(0, 15);
  5923. CHECK(text_edit->get_word_under_caret() == "Lorem\ndolor");
  5924. text_edit->remove_secondary_carets();
  5925. // Should this work?
  5926. text_edit->set_caret_column(5);
  5927. CHECK(text_edit->get_word_under_caret() == "");
  5928. text_edit->set_caret_column(6);
  5929. CHECK(text_edit->get_word_under_caret() == "");
  5930. text_edit->set_caret_line(1);
  5931. CHECK(text_edit->get_caret_line() == 1);
  5932. text_edit->set_caret_line(-1);
  5933. CHECK(text_edit->get_caret_line() == 0);
  5934. text_edit->set_caret_line(100);
  5935. CHECK(text_edit->get_caret_line() == 3);
  5936. text_edit->set_caret_column(-1);
  5937. CHECK(text_edit->get_caret_column() == 0);
  5938. text_edit->set_caret_column(10000000);
  5939. CHECK(text_edit->get_caret_column() == 141);
  5940. memdelete(text_edit);
  5941. }
  5942. TEST_CASE("[SceneTree][TextEdit] multicaret") {
  5943. TextEdit *text_edit = memnew(TextEdit);
  5944. SceneTree::get_singleton()->get_root()->add_child(text_edit);
  5945. text_edit->set_multiple_carets_enabled(true);
  5946. Array empty_signal_args;
  5947. empty_signal_args.push_back(Array());
  5948. SIGNAL_WATCH(text_edit, "caret_changed");
  5949. text_edit->set_text("this is\nsome test\ntext");
  5950. text_edit->set_caret_line(0);
  5951. text_edit->set_caret_column(0);
  5952. MessageQueue::get_singleton()->flush();
  5953. SIGNAL_DISCARD("caret_changed");
  5954. SUBCASE("[TextEdit] add remove caret") {
  5955. // Overlapping.
  5956. CHECK(text_edit->add_caret(0, 0) == -1);
  5957. MessageQueue::get_singleton()->flush();
  5958. SIGNAL_CHECK_FALSE("caret_changed");
  5959. // Select.
  5960. text_edit->select(2, 4, 0, 0);
  5961. // Cannot add in selection.
  5962. CHECK(text_edit->add_caret(0, 0) == -1);
  5963. CHECK(text_edit->add_caret(2, 4) == -1);
  5964. CHECK(text_edit->add_caret(1, 2) == -1);
  5965. // Cannot add when out of bounds.
  5966. CHECK(text_edit->add_caret(-1, 0) == -1);
  5967. CHECK(text_edit->add_caret(5, 0) == -1);
  5968. CHECK(text_edit->add_caret(0, 100) == -1);
  5969. MessageQueue::get_singleton()->flush();
  5970. SIGNAL_CHECK_FALSE("caret_changed");
  5971. CHECK(text_edit->get_caret_count() == 1);
  5972. text_edit->deselect();
  5973. SIGNAL_CHECK_FALSE("caret_changed");
  5974. CHECK(text_edit->add_caret(0, 1) == 1);
  5975. MessageQueue::get_singleton()->flush();
  5976. SIGNAL_CHECK("caret_changed", empty_signal_args);
  5977. CHECK(text_edit->get_caret_count() == 2);
  5978. CHECK(text_edit->get_caret_line(0) == 0);
  5979. CHECK(text_edit->get_caret_column(0) == 0);
  5980. CHECK(text_edit->get_caret_line(1) == 0);
  5981. CHECK(text_edit->get_caret_column(1) == 1);
  5982. ERR_PRINT_OFF;
  5983. text_edit->remove_caret(-1);
  5984. text_edit->remove_caret(5);
  5985. ERR_PRINT_ON;
  5986. CHECK(text_edit->get_caret_count() == 2);
  5987. SIGNAL_CHECK_FALSE("caret_changed");
  5988. text_edit->remove_caret(0);
  5989. SIGNAL_CHECK_FALSE("caret_changed");
  5990. CHECK(text_edit->get_caret_count() == 1);
  5991. CHECK(text_edit->get_caret_line(0) == 0);
  5992. CHECK(text_edit->get_caret_column(0) == 1);
  5993. ERR_PRINT_OFF;
  5994. text_edit->remove_caret(0);
  5995. CHECK(text_edit->get_caret_count() == 1);
  5996. ERR_PRINT_ON;
  5997. }
  5998. SUBCASE("[TextEdit] sort carets") {
  5999. Vector<int> sorted_carets = { 0, 1, 2 };
  6000. // Ascending order.
  6001. text_edit->remove_secondary_carets();
  6002. text_edit->add_caret(0, 1);
  6003. text_edit->add_caret(1, 0);
  6004. CHECK(text_edit->get_sorted_carets() == sorted_carets);
  6005. // Descending order.
  6006. sorted_carets = { 2, 1, 0 };
  6007. text_edit->remove_secondary_carets();
  6008. text_edit->set_caret_line(1);
  6009. text_edit->add_caret(0, 1);
  6010. text_edit->add_caret(0, 0);
  6011. CHECK(text_edit->get_sorted_carets() == sorted_carets);
  6012. // Mixed order.
  6013. sorted_carets = { 0, 2, 1, 3 };
  6014. text_edit->remove_secondary_carets();
  6015. text_edit->set_caret_line(0);
  6016. text_edit->add_caret(1, 0);
  6017. text_edit->add_caret(0, 1);
  6018. text_edit->add_caret(1, 1);
  6019. CHECK(text_edit->get_sorted_carets() == sorted_carets);
  6020. // Overlapping carets.
  6021. sorted_carets = { 0, 1, 3, 2 };
  6022. text_edit->remove_secondary_carets();
  6023. text_edit->add_caret(0, 1);
  6024. text_edit->add_caret(1, 2);
  6025. text_edit->add_caret(0, 2);
  6026. text_edit->set_caret_column(1, false, 3);
  6027. CHECK(text_edit->get_sorted_carets() == sorted_carets);
  6028. // Sorted by selection start.
  6029. sorted_carets = { 1, 0 };
  6030. text_edit->remove_secondary_carets();
  6031. text_edit->select(1, 3, 1, 5);
  6032. text_edit->add_caret(2, 0);
  6033. text_edit->select(1, 0, 2, 0, 1);
  6034. CHECK(text_edit->get_sorted_carets() == sorted_carets);
  6035. }
  6036. SUBCASE("[TextEdit] merge carets") {
  6037. text_edit->set_text("this is some text\nfor selection");
  6038. MessageQueue::get_singleton()->flush();
  6039. // Don't merge carets that are not overlapping.
  6040. text_edit->set_caret_line(0);
  6041. text_edit->set_caret_column(4);
  6042. text_edit->add_caret(0, 6);
  6043. text_edit->add_caret(1, 6);
  6044. text_edit->merge_overlapping_carets();
  6045. CHECK(text_edit->get_caret_count() == 3);
  6046. CHECK_FALSE(text_edit->has_selection());
  6047. CHECK(text_edit->get_caret_line(0) == 0);
  6048. CHECK(text_edit->get_caret_column(0) == 4);
  6049. CHECK(text_edit->get_caret_line(1) == 0);
  6050. CHECK(text_edit->get_caret_column(1) == 6);
  6051. CHECK(text_edit->get_caret_line(2) == 1);
  6052. CHECK(text_edit->get_caret_column(2) == 6);
  6053. text_edit->remove_secondary_carets();
  6054. // Don't merge when in a multicaret edit.
  6055. text_edit->begin_multicaret_edit();
  6056. text_edit->set_caret_line(0);
  6057. text_edit->set_caret_column(4);
  6058. text_edit->add_caret(0, 4);
  6059. text_edit->merge_overlapping_carets();
  6060. CHECK(text_edit->is_in_mulitcaret_edit());
  6061. CHECK_FALSE(text_edit->has_selection());
  6062. CHECK(text_edit->get_caret_count() == 2);
  6063. CHECK(text_edit->get_caret_line(0) == 0);
  6064. CHECK(text_edit->get_caret_column(0) == 4);
  6065. CHECK(text_edit->get_caret_line(1) == 0);
  6066. CHECK(text_edit->get_caret_column(1) == 4);
  6067. // Merge overlapping carets. Merge at the end of the multicaret edit.
  6068. text_edit->end_multicaret_edit();
  6069. CHECK_FALSE(text_edit->is_in_mulitcaret_edit());
  6070. CHECK_FALSE(text_edit->has_selection());
  6071. CHECK(text_edit->get_caret_count() == 1);
  6072. CHECK(text_edit->get_caret_line(0) == 0);
  6073. CHECK(text_edit->get_caret_column(0) == 4);
  6074. // Don't merge selections that are not overlapping.
  6075. text_edit->set_caret_line(0);
  6076. text_edit->set_caret_column(4);
  6077. text_edit->add_caret(0, 2);
  6078. text_edit->add_caret(1, 4);
  6079. text_edit->select(0, 4, 1, 2, 0);
  6080. text_edit->select(0, 2, 0, 3, 1);
  6081. text_edit->select(1, 4, 1, 8, 2);
  6082. text_edit->merge_overlapping_carets();
  6083. CHECK(text_edit->get_caret_count() == 3);
  6084. CHECK(text_edit->has_selection(0));
  6085. CHECK(text_edit->has_selection(1));
  6086. CHECK(text_edit->has_selection(2));
  6087. text_edit->remove_secondary_carets();
  6088. text_edit->deselect();
  6089. // Don't merge selections that are only touching.
  6090. text_edit->set_caret_line(0);
  6091. text_edit->set_caret_column(4);
  6092. text_edit->add_caret(1, 2);
  6093. text_edit->select(0, 4, 1, 2, 0);
  6094. text_edit->select(1, 2, 1, 5, 1);
  6095. text_edit->merge_overlapping_carets();
  6096. CHECK(text_edit->get_caret_count() == 2);
  6097. CHECK(text_edit->has_selection(0));
  6098. CHECK(text_edit->has_selection(1));
  6099. text_edit->remove_secondary_carets();
  6100. text_edit->deselect();
  6101. // Merge carets into selection.
  6102. text_edit->set_caret_line(0);
  6103. text_edit->set_caret_column(3);
  6104. text_edit->add_caret(0, 2);
  6105. text_edit->add_caret(1, 4);
  6106. text_edit->add_caret(1, 8);
  6107. text_edit->add_caret(1, 10);
  6108. text_edit->select(0, 2, 1, 8, 0);
  6109. text_edit->merge_overlapping_carets();
  6110. CHECK(text_edit->get_caret_count() == 2);
  6111. CHECK(text_edit->has_selection(0));
  6112. CHECK(text_edit->get_selection_from_line(0) == 0);
  6113. CHECK(text_edit->get_selection_from_column(0) == 2);
  6114. CHECK(text_edit->get_selection_to_line(0) == 1);
  6115. CHECK(text_edit->get_selection_to_column(0) == 8);
  6116. CHECK(text_edit->is_caret_after_selection_origin(0));
  6117. CHECK_FALSE(text_edit->has_selection(1));
  6118. CHECK(text_edit->get_caret_line(1) == 1);
  6119. CHECK(text_edit->get_caret_column(1) == 10);
  6120. text_edit->remove_secondary_carets();
  6121. text_edit->deselect();
  6122. // Merge partially overlapping selections.
  6123. text_edit->set_caret_line(0);
  6124. text_edit->set_caret_column(1);
  6125. text_edit->add_caret(0, 2);
  6126. text_edit->add_caret(0, 3);
  6127. text_edit->select(0, 2, 0, 6, 0);
  6128. text_edit->select(0, 4, 1, 3, 1);
  6129. text_edit->select(1, 0, 1, 5, 2);
  6130. text_edit->merge_overlapping_carets();
  6131. CHECK(text_edit->get_caret_count() == 1);
  6132. CHECK(text_edit->has_selection(0));
  6133. CHECK(text_edit->get_selection_from_line(0) == 0);
  6134. CHECK(text_edit->get_selection_from_column(0) == 2);
  6135. CHECK(text_edit->get_selection_to_line(0) == 1);
  6136. CHECK(text_edit->get_selection_to_column(0) == 5);
  6137. CHECK(text_edit->is_caret_after_selection_origin(0));
  6138. text_edit->remove_secondary_carets();
  6139. text_edit->deselect();
  6140. // Merge smaller overlapping selection into a bigger one.
  6141. text_edit->set_caret_line(0);
  6142. text_edit->set_caret_column(1);
  6143. text_edit->add_caret(0, 2);
  6144. text_edit->add_caret(0, 3);
  6145. text_edit->select(0, 2, 0, 6, 0);
  6146. text_edit->select(0, 8, 1, 3, 1);
  6147. text_edit->select(0, 2, 1, 5, 2);
  6148. text_edit->merge_overlapping_carets();
  6149. CHECK(text_edit->get_caret_count() == 1);
  6150. CHECK(text_edit->has_selection(0));
  6151. CHECK(text_edit->get_selection_from_line(0) == 0);
  6152. CHECK(text_edit->get_selection_from_column(0) == 2);
  6153. CHECK(text_edit->get_selection_to_line(0) == 1);
  6154. CHECK(text_edit->get_selection_to_column(0) == 5);
  6155. CHECK(text_edit->is_caret_after_selection_origin(0));
  6156. text_edit->remove_secondary_carets();
  6157. text_edit->deselect();
  6158. // Merge equal overlapping selections.
  6159. text_edit->set_caret_line(0);
  6160. text_edit->set_caret_column(1);
  6161. text_edit->add_caret(0, 2);
  6162. text_edit->select(0, 2, 1, 6, 0);
  6163. text_edit->select(0, 2, 1, 6, 1);
  6164. text_edit->merge_overlapping_carets();
  6165. CHECK(text_edit->has_selection(0));
  6166. CHECK(text_edit->get_selection_from_line(0) == 0);
  6167. CHECK(text_edit->get_selection_from_column(0) == 2);
  6168. CHECK(text_edit->get_selection_to_line(0) == 1);
  6169. CHECK(text_edit->get_selection_to_column(0) == 6);
  6170. CHECK(text_edit->is_caret_after_selection_origin(0));
  6171. }
  6172. SUBCASE("[TextEdit] collapse carets") {
  6173. text_edit->set_text("this is some text\nfor selection");
  6174. // Collapse carets in range, dont affect other carets.
  6175. text_edit->add_caret(0, 9);
  6176. text_edit->add_caret(1, 0);
  6177. text_edit->add_caret(1, 2);
  6178. text_edit->add_caret(1, 6);
  6179. text_edit->begin_multicaret_edit();
  6180. text_edit->collapse_carets(0, 8, 1, 2);
  6181. CHECK(text_edit->get_caret_count() == 5);
  6182. CHECK_FALSE(text_edit->has_selection());
  6183. CHECK(text_edit->get_caret_line(0) == 0);
  6184. CHECK(text_edit->get_caret_column(0) == 0);
  6185. CHECK(text_edit->get_caret_line(1) == 0);
  6186. CHECK(text_edit->get_caret_column(1) == 8);
  6187. CHECK(text_edit->get_caret_line(2) == 0);
  6188. CHECK(text_edit->get_caret_column(2) == 8);
  6189. CHECK(text_edit->get_caret_line(3) == 1);
  6190. CHECK(text_edit->get_caret_column(3) == 2);
  6191. CHECK(text_edit->get_caret_line(4) == 1);
  6192. CHECK(text_edit->get_caret_column(4) == 6);
  6193. CHECK_FALSE(text_edit->multicaret_edit_ignore_caret(0));
  6194. CHECK(text_edit->multicaret_edit_ignore_caret(1));
  6195. CHECK(text_edit->multicaret_edit_ignore_caret(2));
  6196. CHECK_FALSE(text_edit->multicaret_edit_ignore_caret(3));
  6197. CHECK_FALSE(text_edit->multicaret_edit_ignore_caret(4));
  6198. // Collapsed carets get merged at the end of the edit.
  6199. text_edit->end_multicaret_edit();
  6200. CHECK(text_edit->get_caret_count() == 4);
  6201. CHECK_FALSE(text_edit->has_selection());
  6202. CHECK(text_edit->get_caret_line(0) == 0);
  6203. CHECK(text_edit->get_caret_column(0) == 0);
  6204. CHECK(text_edit->get_caret_line(1) == 0);
  6205. CHECK(text_edit->get_caret_column(1) == 8);
  6206. CHECK(text_edit->get_caret_line(2) == 1);
  6207. CHECK(text_edit->get_caret_column(2) == 2);
  6208. CHECK(text_edit->get_caret_line(3) == 1);
  6209. CHECK(text_edit->get_caret_column(3) == 6);
  6210. text_edit->remove_secondary_carets();
  6211. // Collapse inclusive.
  6212. text_edit->set_caret_line(0);
  6213. text_edit->set_caret_column(3);
  6214. text_edit->add_caret(1, 2);
  6215. text_edit->collapse_carets(0, 3, 1, 2, true);
  6216. CHECK(text_edit->get_caret_count() == 1);
  6217. CHECK_FALSE(text_edit->has_selection());
  6218. CHECK(text_edit->get_caret_line() == 0);
  6219. CHECK(text_edit->get_caret_column() == 3);
  6220. text_edit->remove_secondary_carets();
  6221. // Deselect if selection was encompassed.
  6222. text_edit->select(0, 5, 0, 7);
  6223. text_edit->collapse_carets(0, 3, 1, 2);
  6224. CHECK_FALSE(text_edit->has_selection());
  6225. CHECK(text_edit->get_caret_line() == 0);
  6226. CHECK(text_edit->get_caret_column() == 3);
  6227. // Clamp only caret end of selection.
  6228. text_edit->select(0, 1, 0, 7);
  6229. text_edit->collapse_carets(0, 3, 1, 2);
  6230. CHECK(text_edit->has_selection());
  6231. CHECK(text_edit->get_caret_line() == 0);
  6232. CHECK(text_edit->get_caret_column() == 3);
  6233. CHECK(text_edit->get_selection_origin_line() == 0);
  6234. CHECK(text_edit->get_selection_origin_column() == 1);
  6235. text_edit->deselect();
  6236. // Clamp only selection origin end of selection.
  6237. text_edit->select(0, 7, 0, 1);
  6238. text_edit->collapse_carets(0, 3, 1, 2);
  6239. CHECK(text_edit->has_selection());
  6240. CHECK(text_edit->get_caret_line() == 0);
  6241. CHECK(text_edit->get_caret_column() == 1);
  6242. CHECK(text_edit->get_selection_origin_line() == 0);
  6243. CHECK(text_edit->get_selection_origin_column() == 3);
  6244. text_edit->deselect();
  6245. }
  6246. SUBCASE("[TextEdit] add caret at carets") {
  6247. text_edit->remove_secondary_carets();
  6248. text_edit->set_caret_line(1);
  6249. text_edit->set_caret_column(9);
  6250. // Add caret below. Column will clamp.
  6251. text_edit->add_caret_at_carets(true);
  6252. CHECK(text_edit->get_caret_count() == 2);
  6253. CHECK_FALSE(text_edit->has_selection());
  6254. CHECK(text_edit->get_caret_line(0) == 1);
  6255. CHECK(text_edit->get_caret_column(0) == 9);
  6256. CHECK(text_edit->get_caret_line(1) == 2);
  6257. CHECK(text_edit->get_caret_column(1) == 4);
  6258. // Cannot add below when at last line.
  6259. text_edit->add_caret_at_carets(true);
  6260. CHECK(text_edit->get_caret_count() == 2);
  6261. CHECK_FALSE(text_edit->has_selection());
  6262. CHECK(text_edit->get_caret_line(0) == 1);
  6263. CHECK(text_edit->get_caret_column(0) == 9);
  6264. CHECK(text_edit->get_caret_line(1) == 2);
  6265. CHECK(text_edit->get_caret_column(1) == 4);
  6266. // Add caret above. Column will clamp.
  6267. text_edit->add_caret_at_carets(false);
  6268. CHECK(text_edit->get_caret_count() == 3);
  6269. CHECK_FALSE(text_edit->has_selection());
  6270. CHECK(text_edit->get_caret_line(0) == 1);
  6271. CHECK(text_edit->get_caret_column(0) == 9);
  6272. CHECK(text_edit->get_caret_line(1) == 2);
  6273. CHECK(text_edit->get_caret_column(1) == 4);
  6274. CHECK(text_edit->get_caret_line(2) == 0);
  6275. CHECK(text_edit->get_caret_column(2) == 7);
  6276. // Cannot add above when at first line.
  6277. text_edit->add_caret_at_carets(false);
  6278. CHECK(text_edit->get_caret_count() == 3);
  6279. CHECK_FALSE(text_edit->has_selection());
  6280. CHECK(text_edit->get_caret_line(0) == 1);
  6281. CHECK(text_edit->get_caret_column(0) == 9);
  6282. CHECK(text_edit->get_caret_line(1) == 2);
  6283. CHECK(text_edit->get_caret_column(1) == 4);
  6284. CHECK(text_edit->get_caret_line(2) == 0);
  6285. CHECK(text_edit->get_caret_column(2) == 7);
  6286. // Cannot add below when at the last line for selection.
  6287. text_edit->remove_secondary_carets();
  6288. text_edit->select(2, 1, 2, 4);
  6289. text_edit->add_caret_at_carets(true);
  6290. CHECK(text_edit->get_caret_count() == 1);
  6291. CHECK(text_edit->has_selection(0));
  6292. CHECK(text_edit->get_selection_origin_line(0) == 2);
  6293. CHECK(text_edit->get_selection_origin_column(0) == 1);
  6294. CHECK(text_edit->get_caret_line(0) == 2);
  6295. CHECK(text_edit->get_caret_column(0) == 4);
  6296. // Cannot add above when at the first line for selection.
  6297. text_edit->select(0, 1, 0, 4);
  6298. text_edit->add_caret_at_carets(false);
  6299. CHECK(text_edit->get_caret_count() == 1);
  6300. CHECK(text_edit->has_selection(0));
  6301. CHECK(text_edit->get_selection_origin_line(0) == 0);
  6302. CHECK(text_edit->get_selection_origin_column(0) == 1);
  6303. CHECK(text_edit->get_caret_line(0) == 0);
  6304. CHECK(text_edit->get_caret_column(0) == 4);
  6305. // Add selection below.
  6306. text_edit->select(0, 0, 0, 4);
  6307. text_edit->add_caret_at_carets(true);
  6308. CHECK(text_edit->get_caret_count() == 2);
  6309. CHECK(text_edit->has_selection(0));
  6310. CHECK(text_edit->get_selection_origin_line(0) == 0);
  6311. CHECK(text_edit->get_selection_origin_column(0) == 0);
  6312. CHECK(text_edit->get_caret_line(0) == 0);
  6313. CHECK(text_edit->get_caret_column(0) == 4);
  6314. CHECK(text_edit->has_selection(1));
  6315. CHECK(text_edit->get_selection_origin_line(1) == 1);
  6316. CHECK(text_edit->get_selection_origin_column(1) == 0);
  6317. CHECK(text_edit->get_caret_line(1) == 1);
  6318. CHECK(text_edit->get_caret_column(1) == 3); // In the default font, this is the same position.
  6319. // Add selection below again.
  6320. text_edit->add_caret_at_carets(true);
  6321. CHECK(text_edit->get_caret_count() == 3);
  6322. CHECK(text_edit->has_selection(0));
  6323. CHECK(text_edit->get_selection_origin_line(0) == 0);
  6324. CHECK(text_edit->get_selection_origin_column(0) == 0);
  6325. CHECK(text_edit->get_caret_line(0) == 0);
  6326. CHECK(text_edit->get_caret_column(0) == 4);
  6327. CHECK(text_edit->has_selection(1));
  6328. CHECK(text_edit->get_selection_origin_line(1) == 1);
  6329. CHECK(text_edit->get_selection_origin_column(1) == 0);
  6330. CHECK(text_edit->get_caret_line(1) == 1);
  6331. CHECK(text_edit->get_caret_column(1) == 3);
  6332. CHECK(text_edit->has_selection(2));
  6333. CHECK(text_edit->get_selection_origin_line(2) == 2);
  6334. CHECK(text_edit->get_selection_origin_column(2) == 0);
  6335. CHECK(text_edit->get_caret_line(2) == 2);
  6336. CHECK(text_edit->get_caret_column(2) == 4);
  6337. text_edit->set_text("\tthis is\nsome\n\ttest text");
  6338. MessageQueue::get_singleton()->flush();
  6339. // Last fit x is preserved when adding below.
  6340. text_edit->remove_secondary_carets();
  6341. text_edit->deselect();
  6342. text_edit->set_caret_line(0);
  6343. text_edit->set_caret_column(6);
  6344. text_edit->add_caret_at_carets(true);
  6345. text_edit->add_caret_at_carets(true);
  6346. CHECK_FALSE(text_edit->has_selection());
  6347. CHECK(text_edit->get_caret_count() == 3);
  6348. CHECK(text_edit->get_caret_line(0) == 0);
  6349. CHECK(text_edit->get_caret_column(0) == 6);
  6350. CHECK(text_edit->get_caret_line(1) == 1);
  6351. CHECK(text_edit->get_caret_column(1) == 4);
  6352. CHECK(text_edit->get_caret_line(2) == 2);
  6353. CHECK(text_edit->get_caret_column(2) == 6);
  6354. // Last fit x is preserved when adding above.
  6355. text_edit->remove_secondary_carets();
  6356. text_edit->deselect();
  6357. text_edit->set_caret_line(2);
  6358. text_edit->set_caret_column(9);
  6359. text_edit->add_caret_at_carets(false);
  6360. text_edit->add_caret_at_carets(false);
  6361. CHECK_FALSE(text_edit->has_selection());
  6362. CHECK(text_edit->get_caret_count() == 3);
  6363. CHECK(text_edit->get_caret_line(0) == 2);
  6364. CHECK(text_edit->get_caret_column(0) == 9);
  6365. CHECK(text_edit->get_caret_line(1) == 1);
  6366. CHECK(text_edit->get_caret_column(1) == 4);
  6367. CHECK(text_edit->get_caret_line(2) == 0);
  6368. CHECK(text_edit->get_caret_column(2) == 8);
  6369. // Last fit x is preserved when selection adding below.
  6370. text_edit->remove_secondary_carets();
  6371. text_edit->deselect();
  6372. text_edit->select(0, 8, 0, 5);
  6373. text_edit->add_caret_at_carets(true);
  6374. text_edit->add_caret_at_carets(true);
  6375. CHECK(text_edit->get_caret_count() == 3);
  6376. CHECK(text_edit->has_selection(0));
  6377. CHECK(text_edit->get_selection_origin_line(0) == 0);
  6378. CHECK(text_edit->get_selection_origin_column(0) == 8);
  6379. CHECK(text_edit->get_caret_line(0) == 0);
  6380. CHECK(text_edit->get_caret_column(0) == 5);
  6381. CHECK_FALSE(text_edit->has_selection(1));
  6382. CHECK(text_edit->get_caret_line(1) == 1);
  6383. CHECK(text_edit->get_caret_column(1) == 4);
  6384. CHECK(text_edit->has_selection(2));
  6385. CHECK(text_edit->get_selection_origin_line(2) == 2);
  6386. CHECK(text_edit->get_selection_origin_column(2) == 7);
  6387. CHECK(text_edit->get_caret_line(2) == 2);
  6388. CHECK(text_edit->get_caret_column(2) == 5);
  6389. // Last fit x is preserved when selection adding above.
  6390. text_edit->remove_secondary_carets();
  6391. text_edit->deselect();
  6392. text_edit->select(2, 9, 2, 5);
  6393. text_edit->add_caret_at_carets(false);
  6394. text_edit->add_caret_at_carets(false);
  6395. CHECK(text_edit->get_caret_count() == 3);
  6396. CHECK(text_edit->has_selection(0));
  6397. CHECK(text_edit->get_selection_origin_line(0) == 2);
  6398. CHECK(text_edit->get_selection_origin_column(0) == 9);
  6399. CHECK(text_edit->get_caret_line(0) == 2);
  6400. CHECK(text_edit->get_caret_column(0) == 5);
  6401. CHECK_FALSE(text_edit->has_selection(1));
  6402. CHECK(text_edit->get_caret_line(1) == 1);
  6403. CHECK(text_edit->get_caret_column(1) == 4);
  6404. CHECK(text_edit->has_selection(2));
  6405. CHECK(text_edit->get_selection_origin_line(2) == 0);
  6406. CHECK(text_edit->get_selection_origin_column(2) == 8);
  6407. CHECK(text_edit->get_caret_line(2) == 0);
  6408. CHECK(text_edit->get_caret_column(2) == 5);
  6409. // Selections are merged when they overlap.
  6410. text_edit->remove_secondary_carets();
  6411. text_edit->deselect();
  6412. text_edit->select(0, 1, 0, 5);
  6413. text_edit->add_caret(1, 0);
  6414. text_edit->select(1, 1, 1, 3, 1);
  6415. text_edit->add_caret_at_carets(true);
  6416. CHECK(text_edit->get_caret_count() == 3);
  6417. CHECK(text_edit->has_selection(0));
  6418. CHECK(text_edit->get_selection_origin_line(0) == 0);
  6419. CHECK(text_edit->get_selection_origin_column(0) == 1);
  6420. CHECK(text_edit->get_caret_line(0) == 0);
  6421. CHECK(text_edit->get_caret_column(0) == 5);
  6422. CHECK(text_edit->has_selection(1));
  6423. CHECK(text_edit->get_selection_origin_line(1) == 1);
  6424. CHECK(text_edit->get_selection_origin_column(1) == 1);
  6425. CHECK(text_edit->get_caret_line(1) == 1);
  6426. CHECK(text_edit->get_caret_column(1) == 4);
  6427. CHECK(text_edit->has_selection(2));
  6428. CHECK(text_edit->get_selection_origin_line(2) == 2);
  6429. CHECK(text_edit->get_selection_origin_column(2) == 0);
  6430. CHECK(text_edit->get_caret_line(2) == 2);
  6431. CHECK(text_edit->get_caret_column(2) == 3);
  6432. // Multiline selection.
  6433. text_edit->remove_secondary_carets();
  6434. text_edit->deselect();
  6435. text_edit->set_caret_line(0);
  6436. text_edit->set_caret_column(1);
  6437. text_edit->select(0, 3, 1, 1);
  6438. text_edit->add_caret_at_carets(true);
  6439. CHECK(text_edit->get_caret_count() == 2);
  6440. CHECK(text_edit->has_selection(0));
  6441. CHECK(text_edit->get_selection_origin_line(0) == 0);
  6442. CHECK(text_edit->get_selection_origin_column(0) == 3);
  6443. CHECK(text_edit->get_caret_line(0) == 1);
  6444. CHECK(text_edit->get_caret_column(0) == 1);
  6445. CHECK(text_edit->has_selection(1));
  6446. CHECK(text_edit->get_selection_origin_line(1) == 1);
  6447. CHECK(text_edit->get_selection_origin_column(1) == 3);
  6448. CHECK(text_edit->get_caret_line(1) == 2);
  6449. CHECK(text_edit->get_caret_column(1) == 0);
  6450. text_edit->set_line_wrapping_mode(TextEdit::LineWrappingMode::LINE_WRAPPING_BOUNDARY);
  6451. text_edit->set_size(Size2(50, 100));
  6452. // Line wraps: `\t,this, is\nso,me\n\t,test, ,text`.
  6453. CHECK(text_edit->is_line_wrapped(0));
  6454. MessageQueue::get_singleton()->flush();
  6455. // Add caret below on next line wrap.
  6456. text_edit->remove_secondary_carets();
  6457. text_edit->deselect();
  6458. text_edit->set_caret_line(0);
  6459. text_edit->set_caret_column(4);
  6460. text_edit->add_caret_at_carets(true);
  6461. CHECK_FALSE(text_edit->has_selection());
  6462. CHECK(text_edit->get_caret_count() == 2);
  6463. CHECK(text_edit->get_caret_line(0) == 0);
  6464. CHECK(text_edit->get_caret_column(0) == 4);
  6465. CHECK(text_edit->get_caret_line(1) == 0);
  6466. CHECK(text_edit->get_caret_column(1) == 8);
  6467. // Add caret below from end of line wrap.
  6468. text_edit->add_caret_at_carets(true);
  6469. CHECK_FALSE(text_edit->has_selection());
  6470. CHECK(text_edit->get_caret_count() == 3);
  6471. CHECK(text_edit->get_caret_line(0) == 0);
  6472. CHECK(text_edit->get_caret_column(0) == 4);
  6473. CHECK(text_edit->get_caret_line(1) == 0);
  6474. CHECK(text_edit->get_caret_column(1) == 8);
  6475. CHECK(text_edit->get_caret_line(2) == 1);
  6476. CHECK(text_edit->get_caret_column(2) == 1);
  6477. // Add caret below from last line and not last line wrap.
  6478. text_edit->remove_secondary_carets();
  6479. text_edit->deselect();
  6480. text_edit->set_caret_line(2);
  6481. text_edit->set_caret_column(5);
  6482. text_edit->add_caret_at_carets(true);
  6483. CHECK_FALSE(text_edit->has_selection());
  6484. CHECK(text_edit->get_caret_count() == 2);
  6485. CHECK(text_edit->get_caret_line(0) == 2);
  6486. CHECK(text_edit->get_caret_column(0) == 5);
  6487. CHECK(text_edit->get_caret_line(1) == 2);
  6488. CHECK(text_edit->get_caret_column(1) == 6);
  6489. // Cannot add caret below from last line last line wrap.
  6490. text_edit->add_caret_at_carets(true);
  6491. CHECK_FALSE(text_edit->has_selection());
  6492. CHECK(text_edit->get_caret_count() == 2);
  6493. CHECK(text_edit->get_caret_line(0) == 2);
  6494. CHECK(text_edit->get_caret_column(0) == 5);
  6495. CHECK(text_edit->get_caret_line(1) == 2);
  6496. CHECK(text_edit->get_caret_column(1) == 6);
  6497. // Add caret above from not first line wrap.
  6498. text_edit->remove_secondary_carets();
  6499. text_edit->deselect();
  6500. text_edit->set_caret_line(1);
  6501. text_edit->set_caret_column(4);
  6502. text_edit->add_caret_at_carets(false);
  6503. CHECK_FALSE(text_edit->has_selection());
  6504. CHECK(text_edit->get_caret_count() == 2);
  6505. CHECK(text_edit->get_caret_line(0) == 1);
  6506. CHECK(text_edit->get_caret_column(0) == 4);
  6507. CHECK(text_edit->get_caret_line(1) == 1);
  6508. CHECK(text_edit->get_caret_column(1) == 1);
  6509. // Add caret above from first line wrap.
  6510. text_edit->add_caret_at_carets(false);
  6511. CHECK_FALSE(text_edit->has_selection());
  6512. CHECK(text_edit->get_caret_count() == 3);
  6513. CHECK(text_edit->get_caret_line(0) == 1);
  6514. CHECK(text_edit->get_caret_column(0) == 4);
  6515. CHECK(text_edit->get_caret_line(1) == 1);
  6516. CHECK(text_edit->get_caret_column(1) == 1);
  6517. CHECK(text_edit->get_caret_line(2) == 0);
  6518. CHECK(text_edit->get_caret_column(2) == 8);
  6519. // Add caret above from first line and not first line wrap.
  6520. text_edit->add_caret_at_carets(false);
  6521. CHECK_FALSE(text_edit->has_selection());
  6522. CHECK(text_edit->get_caret_count() == 4);
  6523. CHECK(text_edit->get_caret_line(0) == 1);
  6524. CHECK(text_edit->get_caret_column(0) == 4);
  6525. CHECK(text_edit->get_caret_line(1) == 1);
  6526. CHECK(text_edit->get_caret_column(1) == 1);
  6527. CHECK(text_edit->get_caret_line(2) == 0);
  6528. CHECK(text_edit->get_caret_column(2) == 8);
  6529. CHECK(text_edit->get_caret_line(3) == 0);
  6530. CHECK(text_edit->get_caret_column(3) == 4);
  6531. // Cannot add caret above from first line first line wrap.
  6532. text_edit->remove_secondary_carets();
  6533. text_edit->deselect();
  6534. text_edit->set_caret_line(0);
  6535. text_edit->set_caret_column(0);
  6536. text_edit->add_caret_at_carets(false);
  6537. CHECK_FALSE(text_edit->has_selection());
  6538. CHECK(text_edit->get_caret_count() == 1);
  6539. CHECK(text_edit->get_caret_line(0) == 0);
  6540. CHECK(text_edit->get_caret_column(0) == 0);
  6541. // Does nothing if multiple carets are disabled.
  6542. text_edit->set_multiple_carets_enabled(false);
  6543. text_edit->add_caret_at_carets(true);
  6544. CHECK(text_edit->get_caret_count() == 1);
  6545. }
  6546. memdelete(text_edit);
  6547. }
  6548. TEST_CASE("[SceneTree][TextEdit] line wrapping") {
  6549. TextEdit *text_edit = memnew(TextEdit);
  6550. SceneTree::get_singleton()->get_root()->add_child(text_edit);
  6551. text_edit->grab_focus();
  6552. // Set size for boundary.
  6553. text_edit->set_size(Size2(800, 200));
  6554. text_edit->set_line(0, "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec vasius mattis leo, sed porta ex lacinia bibendum. Nunc bibendum pellentesque.");
  6555. CHECK_FALSE(text_edit->is_line_wrapped(0));
  6556. CHECK(text_edit->get_line_wrap_count(0) == 0);
  6557. CHECK(text_edit->get_line_wrap_index_at_column(0, 130) == 0);
  6558. CHECK(text_edit->get_line_wrapped_text(0).size() == 1);
  6559. SIGNAL_WATCH(text_edit, "text_set");
  6560. SIGNAL_WATCH(text_edit, "text_changed");
  6561. SIGNAL_WATCH(text_edit, "lines_edited_from");
  6562. SIGNAL_WATCH(text_edit, "caret_changed");
  6563. text_edit->set_line_wrapping_mode(TextEdit::LineWrappingMode::LINE_WRAPPING_BOUNDARY);
  6564. SIGNAL_CHECK_FALSE("text_set");
  6565. SIGNAL_CHECK_FALSE("text_changed");
  6566. SIGNAL_CHECK_FALSE("lines_edited_from");
  6567. SIGNAL_CHECK_FALSE("caret_changed");
  6568. CHECK(text_edit->is_line_wrapped(0));
  6569. CHECK(text_edit->get_line_wrap_count(0) == 1);
  6570. CHECK(text_edit->get_line_wrap_index_at_column(0, 130) == 1);
  6571. CHECK(text_edit->get_line_wrapped_text(0).size() == 2);
  6572. SIGNAL_UNWATCH(text_edit, "text_set");
  6573. SIGNAL_UNWATCH(text_edit, "text_changed");
  6574. SIGNAL_UNWATCH(text_edit, "lines_edited_from");
  6575. SIGNAL_UNWATCH(text_edit, "caret_changed");
  6576. ERR_PRINT_OFF;
  6577. CHECK_FALSE(text_edit->is_line_wrapped(-1));
  6578. CHECK_FALSE(text_edit->is_line_wrapped(1));
  6579. CHECK(text_edit->get_line_wrap_count(-1) == 0);
  6580. CHECK(text_edit->get_line_wrap_count(1) == 0);
  6581. CHECK(text_edit->get_line_wrap_index_at_column(-1, 0) == 0);
  6582. CHECK(text_edit->get_line_wrap_index_at_column(0, -1) == 0);
  6583. CHECK(text_edit->get_line_wrap_index_at_column(1, 0) == 0);
  6584. CHECK(text_edit->get_line_wrap_index_at_column(0, 10000) == 0);
  6585. CHECK(text_edit->get_line_wrapped_text(-1).size() == 0);
  6586. CHECK(text_edit->get_line_wrapped_text(1).size() == 0);
  6587. ERR_PRINT_ON;
  6588. memdelete(text_edit);
  6589. }
  6590. TEST_CASE("[SceneTree][TextEdit] viewport") {
  6591. TextEdit *text_edit = memnew(TextEdit);
  6592. SceneTree::get_singleton()->get_root()->add_child(text_edit);
  6593. // No subcases here for performance.
  6594. text_edit->set_size(Size2(800, 600));
  6595. for (int i = 0; i < 50; i++) {
  6596. text_edit->insert_line_at(0, "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec vasius mattis leo, sed porta ex lacinia bibendum. Nunc bibendum pellentesque.");
  6597. }
  6598. MessageQueue::get_singleton()->flush();
  6599. const int visible_lines = text_edit->get_visible_line_count();
  6600. const int total_visible_lines = text_edit->get_total_visible_line_count();
  6601. CHECK(total_visible_lines == 51);
  6602. // First visible line.
  6603. CHECK(text_edit->get_first_visible_line() == 0);
  6604. CHECK(text_edit->get_v_scroll() == 0);
  6605. CHECK(text_edit->get_last_full_visible_line() == visible_lines - 1);
  6606. CHECK(text_edit->get_last_full_visible_line_wrap_index() == 0);
  6607. text_edit->set_line_as_first_visible(visible_lines);
  6608. MessageQueue::get_singleton()->flush();
  6609. CHECK(text_edit->get_first_visible_line() == visible_lines);
  6610. CHECK(text_edit->get_v_scroll() == visible_lines);
  6611. CHECK(text_edit->get_last_full_visible_line() == (visible_lines * 2) - 1);
  6612. CHECK(text_edit->get_last_full_visible_line_wrap_index() == 0);
  6613. ERR_PRINT_OFF;
  6614. text_edit->set_line_as_first_visible(-1);
  6615. text_edit->set_line_as_first_visible(500);
  6616. text_edit->set_line_as_first_visible(0, -1);
  6617. text_edit->set_line_as_first_visible(0, 500);
  6618. CHECK(text_edit->get_first_visible_line() == visible_lines);
  6619. ERR_PRINT_ON;
  6620. // Wrap.
  6621. text_edit->set_line_wrapping_mode(TextEdit::LineWrappingMode::LINE_WRAPPING_BOUNDARY);
  6622. MessageQueue::get_singleton()->flush();
  6623. CHECK(text_edit->get_total_visible_line_count() > total_visible_lines);
  6624. text_edit->set_line_as_first_visible(5, 1);
  6625. MessageQueue::get_singleton()->flush();
  6626. CHECK(text_edit->get_first_visible_line() == 5);
  6627. CHECK(text_edit->get_v_scroll() == 11);
  6628. CHECK(text_edit->get_last_full_visible_line() == visible_lines - 6);
  6629. CHECK(text_edit->get_last_full_visible_line_wrap_index() == 1);
  6630. // Reset.
  6631. text_edit->set_line_wrapping_mode(TextEdit::LineWrappingMode::LINE_WRAPPING_NONE);
  6632. MessageQueue::get_singleton()->flush();
  6633. CHECK(text_edit->get_total_visible_line_count() == total_visible_lines);
  6634. text_edit->set_line_as_first_visible(0);
  6635. MessageQueue::get_singleton()->flush();
  6636. CHECK(text_edit->get_first_visible_line() == 0);
  6637. CHECK(text_edit->get_v_scroll() == 0);
  6638. CHECK(text_edit->get_last_full_visible_line() == visible_lines - 1);
  6639. CHECK(text_edit->get_last_full_visible_line_wrap_index() == 0);
  6640. // Last visible line.
  6641. text_edit->set_line_as_last_visible(visible_lines * 2);
  6642. MessageQueue::get_singleton()->flush();
  6643. CHECK(text_edit->get_first_visible_line() == visible_lines);
  6644. CHECK(text_edit->get_v_scroll() == visible_lines);
  6645. CHECK(text_edit->get_last_full_visible_line() == (visible_lines * 2) - 1);
  6646. CHECK(text_edit->get_last_full_visible_line_wrap_index() == 0);
  6647. ERR_PRINT_OFF;
  6648. text_edit->set_line_as_last_visible(-1);
  6649. text_edit->set_line_as_last_visible(500);
  6650. text_edit->set_line_as_last_visible(0, -1);
  6651. text_edit->set_line_as_last_visible(0, 500);
  6652. CHECK(text_edit->get_first_visible_line() == visible_lines);
  6653. CHECK(text_edit->get_last_full_visible_line() == (visible_lines * 2) - 1);
  6654. ERR_PRINT_ON;
  6655. // Wrap.
  6656. text_edit->set_line_wrapping_mode(TextEdit::LineWrappingMode::LINE_WRAPPING_BOUNDARY);
  6657. MessageQueue::get_singleton()->flush();
  6658. CHECK(text_edit->get_total_visible_line_count() > total_visible_lines);
  6659. text_edit->set_line_as_last_visible(visible_lines + 5, 1);
  6660. MessageQueue::get_singleton()->flush();
  6661. CHECK(text_edit->get_first_visible_line() == 16);
  6662. CHECK(text_edit->get_v_scroll() == 32.0);
  6663. CHECK(text_edit->get_last_full_visible_line() == visible_lines + 5);
  6664. CHECK(text_edit->get_last_full_visible_line_wrap_index() == 0);
  6665. // Reset.
  6666. text_edit->set_line_wrapping_mode(TextEdit::LineWrappingMode::LINE_WRAPPING_NONE);
  6667. MessageQueue::get_singleton()->flush();
  6668. CHECK(text_edit->get_total_visible_line_count() == total_visible_lines);
  6669. text_edit->set_line_as_first_visible(0);
  6670. MessageQueue::get_singleton()->flush();
  6671. CHECK(text_edit->get_first_visible_line() == 0);
  6672. CHECK(text_edit->get_v_scroll() == 0);
  6673. CHECK(text_edit->get_last_full_visible_line() == visible_lines - 1);
  6674. CHECK(text_edit->get_last_full_visible_line_wrap_index() == 0);
  6675. // Center.
  6676. text_edit->set_line_as_center_visible(visible_lines + (visible_lines / 2));
  6677. MessageQueue::get_singleton()->flush();
  6678. CHECK(text_edit->get_first_visible_line() == visible_lines);
  6679. CHECK(text_edit->get_v_scroll() == visible_lines);
  6680. CHECK(text_edit->get_last_full_visible_line() == (visible_lines * 2) - 1);
  6681. CHECK(text_edit->get_last_full_visible_line_wrap_index() == 0);
  6682. ERR_PRINT_OFF;
  6683. text_edit->set_line_as_last_visible(-1);
  6684. text_edit->set_line_as_last_visible(500);
  6685. text_edit->set_line_as_last_visible(0, -1);
  6686. text_edit->set_line_as_last_visible(0, 500);
  6687. CHECK(text_edit->get_first_visible_line() == visible_lines);
  6688. CHECK(text_edit->get_last_full_visible_line() == (visible_lines * 2) - 1);
  6689. ERR_PRINT_ON;
  6690. // Wrap.
  6691. text_edit->set_line_wrapping_mode(TextEdit::LineWrappingMode::LINE_WRAPPING_BOUNDARY);
  6692. MessageQueue::get_singleton()->flush();
  6693. CHECK(text_edit->get_total_visible_line_count() > total_visible_lines);
  6694. text_edit->set_line_as_center_visible(visible_lines + (visible_lines / 2) + 5, 1);
  6695. MessageQueue::get_singleton()->flush();
  6696. CHECK(text_edit->get_first_visible_line() == visible_lines + (visible_lines / 2));
  6697. CHECK(text_edit->get_v_scroll() == (visible_lines * 3));
  6698. CHECK(text_edit->get_last_full_visible_line() == (visible_lines * 2) - 1);
  6699. CHECK(text_edit->get_last_full_visible_line_wrap_index() == 1);
  6700. // Scroll past eof.
  6701. int line_count = text_edit->get_line_count();
  6702. text_edit->set_scroll_past_end_of_file_enabled(true);
  6703. MessageQueue::get_singleton()->flush();
  6704. text_edit->set_line_as_center_visible(line_count - 1);
  6705. MessageQueue::get_singleton()->flush();
  6706. CHECK(text_edit->get_first_visible_line() == (visible_lines * 2) + 3);
  6707. CHECK(text_edit->get_v_scroll() == (visible_lines * 4) + 6);
  6708. CHECK(text_edit->get_last_full_visible_line() == (visible_lines * 2) + 8);
  6709. CHECK(text_edit->get_last_full_visible_line_wrap_index() == 0);
  6710. text_edit->set_scroll_past_end_of_file_enabled(false);
  6711. MessageQueue::get_singleton()->flush();
  6712. CHECK(text_edit->get_first_visible_line() == (visible_lines * 2) + 3);
  6713. CHECK(text_edit->get_v_scroll() == (visible_lines * 4) - 4);
  6714. CHECK(text_edit->get_last_full_visible_line() == (visible_lines * 2) + 8);
  6715. CHECK(text_edit->get_last_full_visible_line_wrap_index() == 0);
  6716. // Reset.
  6717. text_edit->set_line_wrapping_mode(TextEdit::LineWrappingMode::LINE_WRAPPING_NONE);
  6718. MessageQueue::get_singleton()->flush();
  6719. CHECK(text_edit->get_total_visible_line_count() == total_visible_lines);
  6720. text_edit->set_line_as_first_visible(0);
  6721. MessageQueue::get_singleton()->flush();
  6722. CHECK(text_edit->get_first_visible_line() == 0);
  6723. CHECK(text_edit->get_v_scroll() == 0);
  6724. CHECK(text_edit->get_last_full_visible_line() == visible_lines - 1);
  6725. CHECK(text_edit->get_last_full_visible_line_wrap_index() == 0);
  6726. // Auto adjust - todo: horizontal scroll.
  6727. // Below.
  6728. MessageQueue::get_singleton()->flush();
  6729. CHECK_FALSE(text_edit->is_caret_visible());
  6730. text_edit->set_caret_line(visible_lines + 5, false);
  6731. CHECK_FALSE(text_edit->is_caret_visible());
  6732. text_edit->adjust_viewport_to_caret();
  6733. MessageQueue::get_singleton()->flush();
  6734. CHECK(text_edit->is_caret_visible());
  6735. CHECK(text_edit->get_first_visible_line() == 5);
  6736. CHECK(text_edit->get_v_scroll() == 5);
  6737. CHECK(text_edit->get_last_full_visible_line() == (visible_lines - 1) + 5);
  6738. CHECK(text_edit->get_last_full_visible_line_wrap_index() == 0);
  6739. text_edit->center_viewport_to_caret();
  6740. MessageQueue::get_singleton()->flush();
  6741. CHECK(text_edit->get_first_visible_line() == visible_lines - 5);
  6742. CHECK(text_edit->get_v_scroll() == visible_lines - 5);
  6743. CHECK(text_edit->get_last_full_visible_line() == (visible_lines * 2) - 6);
  6744. CHECK(text_edit->get_last_full_visible_line_wrap_index() == 0);
  6745. // Caret visible, do nothing.
  6746. text_edit->adjust_viewport_to_caret();
  6747. MessageQueue::get_singleton()->flush();
  6748. CHECK(text_edit->get_first_visible_line() == visible_lines - 5);
  6749. CHECK(text_edit->get_v_scroll() == visible_lines - 5);
  6750. CHECK(text_edit->get_last_full_visible_line() == (visible_lines * 2) - 6);
  6751. CHECK(text_edit->get_last_full_visible_line_wrap_index() == 0);
  6752. // Above.
  6753. text_edit->set_caret_line(1, false);
  6754. MessageQueue::get_singleton()->flush();
  6755. text_edit->adjust_viewport_to_caret();
  6756. MessageQueue::get_singleton()->flush();
  6757. CHECK(text_edit->is_caret_visible());
  6758. CHECK(text_edit->get_first_visible_line() == 1);
  6759. CHECK(text_edit->get_v_scroll() == 1);
  6760. CHECK(text_edit->get_last_full_visible_line() == visible_lines);
  6761. CHECK(text_edit->get_last_full_visible_line_wrap_index() == 0);
  6762. CHECK(text_edit->get_caret_wrap_index() == 0);
  6763. text_edit->set_line_as_first_visible(0);
  6764. MessageQueue::get_singleton()->flush();
  6765. CHECK(text_edit->get_first_visible_line() == 0);
  6766. CHECK(text_edit->get_v_scroll() == 0);
  6767. CHECK(text_edit->get_last_full_visible_line() == visible_lines - 1);
  6768. CHECK(text_edit->get_last_full_visible_line_wrap_index() == 0);
  6769. text_edit->adjust_viewport_to_caret();
  6770. MessageQueue::get_singleton()->flush();
  6771. CHECK(text_edit->get_first_visible_line() == 0);
  6772. CHECK(text_edit->get_v_scroll() == 0);
  6773. CHECK(text_edit->get_last_full_visible_line() == visible_lines - 1);
  6774. CHECK(text_edit->get_last_full_visible_line_wrap_index() == 0);
  6775. // Wrap.
  6776. text_edit->set_line_wrapping_mode(TextEdit::LineWrappingMode::LINE_WRAPPING_BOUNDARY);
  6777. MessageQueue::get_singleton()->flush();
  6778. CHECK(text_edit->get_total_visible_line_count() > total_visible_lines);
  6779. text_edit->set_caret_line(visible_lines + 5, false, true, 1);
  6780. MessageQueue::get_singleton()->flush();
  6781. text_edit->adjust_viewport_to_caret();
  6782. MessageQueue::get_singleton()->flush();
  6783. CHECK(text_edit->get_first_visible_line() == (visible_lines / 2) + 6);
  6784. CHECK(text_edit->get_v_scroll() == (visible_lines + (visible_lines / 2)) + 1);
  6785. CHECK(text_edit->get_last_full_visible_line() == (visible_lines) + 5);
  6786. CHECK(text_edit->get_last_full_visible_line_wrap_index() == 0);
  6787. CHECK(text_edit->get_caret_wrap_index() == 1);
  6788. text_edit->center_viewport_to_caret();
  6789. MessageQueue::get_singleton()->flush();
  6790. CHECK(text_edit->get_first_visible_line() == visible_lines);
  6791. CHECK(text_edit->get_v_scroll() == (visible_lines * 2) + 1);
  6792. CHECK(text_edit->get_last_full_visible_line() == (visible_lines * 2) - 11);
  6793. CHECK(text_edit->get_last_full_visible_line_wrap_index() == 1);
  6794. // Caret visible, do nothing.
  6795. text_edit->adjust_viewport_to_caret();
  6796. MessageQueue::get_singleton()->flush();
  6797. CHECK(text_edit->get_first_visible_line() == visible_lines);
  6798. CHECK(text_edit->get_v_scroll() == (visible_lines * 2) + 1);
  6799. CHECK(text_edit->get_last_full_visible_line() == (visible_lines * 2) - 11);
  6800. CHECK(text_edit->get_last_full_visible_line_wrap_index() == 1);
  6801. // Above.
  6802. text_edit->set_caret_line(1, false, true, 1);
  6803. MessageQueue::get_singleton()->flush();
  6804. text_edit->adjust_viewport_to_caret();
  6805. MessageQueue::get_singleton()->flush();
  6806. CHECK(text_edit->is_caret_visible());
  6807. CHECK(text_edit->get_first_visible_line() == 1);
  6808. CHECK(text_edit->get_v_scroll() == 3);
  6809. CHECK(text_edit->get_last_full_visible_line() == (visible_lines / 2) + 1);
  6810. CHECK(text_edit->get_last_full_visible_line_wrap_index() == 1);
  6811. CHECK(text_edit->get_caret_wrap_index() == 1);
  6812. text_edit->set_line_as_first_visible(0);
  6813. MessageQueue::get_singleton()->flush();
  6814. CHECK(text_edit->is_caret_visible());
  6815. CHECK(text_edit->get_first_visible_line() == 0);
  6816. CHECK(text_edit->get_v_scroll() == 0);
  6817. CHECK(text_edit->get_last_full_visible_line() == visible_lines - 11);
  6818. CHECK(text_edit->get_last_full_visible_line_wrap_index() == 0);
  6819. text_edit->adjust_viewport_to_caret();
  6820. MessageQueue::get_singleton()->flush();
  6821. CHECK(text_edit->get_first_visible_line() == 0);
  6822. CHECK(text_edit->get_v_scroll() == 0);
  6823. CHECK(text_edit->get_last_full_visible_line() == visible_lines - 11);
  6824. CHECK(text_edit->get_last_full_visible_line_wrap_index() == 0);
  6825. // Reset.
  6826. text_edit->set_line_wrapping_mode(TextEdit::LineWrappingMode::LINE_WRAPPING_NONE);
  6827. MessageQueue::get_singleton()->flush();
  6828. CHECK(text_edit->get_total_visible_line_count() == total_visible_lines);
  6829. text_edit->set_line_as_first_visible(0);
  6830. MessageQueue::get_singleton()->flush();
  6831. CHECK(text_edit->get_first_visible_line() == 0);
  6832. CHECK(text_edit->get_v_scroll() == 0);
  6833. CHECK(text_edit->get_last_full_visible_line() == visible_lines - 1);
  6834. CHECK(text_edit->get_last_full_visible_line_wrap_index() == 0);
  6835. CHECK(text_edit->get_caret_wrap_index() == 0);
  6836. // Smooth scroll.
  6837. text_edit->set_v_scroll_speed(10);
  6838. CHECK(text_edit->get_v_scroll_speed() == 10);
  6839. ERR_PRINT_OFF;
  6840. text_edit->set_v_scroll_speed(-1);
  6841. CHECK(text_edit->get_v_scroll_speed() == 10);
  6842. text_edit->set_v_scroll_speed(0);
  6843. CHECK(text_edit->get_v_scroll_speed() == 10);
  6844. text_edit->set_v_scroll_speed(1);
  6845. CHECK(text_edit->get_v_scroll_speed() == 1);
  6846. ERR_PRINT_ON;
  6847. // Scroll.
  6848. int v_scroll = text_edit->get_v_scroll();
  6849. SEND_GUI_MOUSE_BUTTON_EVENT(Point2i(10, 10), MouseButton::WHEEL_DOWN, 0, Key::NONE);
  6850. CHECK(text_edit->get_v_scroll() > v_scroll);
  6851. SEND_GUI_MOUSE_BUTTON_EVENT(Point2i(10, 10), MouseButton::WHEEL_UP, 0, Key::NONE);
  6852. CHECK(text_edit->get_v_scroll() == v_scroll);
  6853. // smooth scroll speed.
  6854. text_edit->set_smooth_scroll_enabled(true);
  6855. v_scroll = text_edit->get_v_scroll();
  6856. SEND_GUI_MOUSE_BUTTON_EVENT(Point2i(10, 10), MouseButton::WHEEL_DOWN, 0, Key::NONE);
  6857. text_edit->notification(TextEdit::NOTIFICATION_INTERNAL_PHYSICS_PROCESS);
  6858. CHECK(text_edit->get_v_scroll() >= v_scroll);
  6859. SEND_GUI_MOUSE_BUTTON_EVENT(Point2i(10, 10), MouseButton::WHEEL_UP, 0, Key::NONE);
  6860. text_edit->notification(TextEdit::NOTIFICATION_INTERNAL_PHYSICS_PROCESS);
  6861. CHECK(text_edit->get_v_scroll() == v_scroll);
  6862. v_scroll = text_edit->get_v_scroll();
  6863. text_edit->set_v_scroll_speed(10000);
  6864. SEND_GUI_MOUSE_BUTTON_EVENT(Point2i(10, 10), MouseButton::WHEEL_DOWN, 0, Key::NONE);
  6865. text_edit->notification(TextEdit::NOTIFICATION_INTERNAL_PHYSICS_PROCESS);
  6866. CHECK(text_edit->get_v_scroll() >= v_scroll);
  6867. SEND_GUI_MOUSE_BUTTON_EVENT(Point2i(10, 10), MouseButton::WHEEL_UP, 0, Key::NONE);
  6868. text_edit->notification(TextEdit::NOTIFICATION_INTERNAL_PHYSICS_PROCESS);
  6869. CHECK(text_edit->get_v_scroll() == v_scroll);
  6870. ERR_PRINT_OFF;
  6871. CHECK(text_edit->get_scroll_pos_for_line(-1) == 0);
  6872. CHECK(text_edit->get_scroll_pos_for_line(1000) == 0);
  6873. CHECK(text_edit->get_scroll_pos_for_line(1, -1) == 0);
  6874. CHECK(text_edit->get_scroll_pos_for_line(1, 100) == 0);
  6875. ERR_PRINT_ON;
  6876. text_edit->set_h_scroll(-100);
  6877. CHECK(text_edit->get_h_scroll() == 0);
  6878. text_edit->set_h_scroll(10000000);
  6879. CHECK(text_edit->get_h_scroll() == 306);
  6880. CHECK(text_edit->get_h_scroll_bar()->get_combined_minimum_size().x == 8);
  6881. text_edit->set_h_scroll(-100);
  6882. CHECK(text_edit->get_h_scroll() == 0);
  6883. text_edit->set_smooth_scroll_enabled(false);
  6884. CHECK(text_edit->get_first_visible_line() == 0);
  6885. CHECK(text_edit->get_v_scroll() == 0);
  6886. CHECK(text_edit->get_last_full_visible_line() == visible_lines - 1);
  6887. CHECK(text_edit->get_last_full_visible_line_wrap_index() == 0);
  6888. text_edit->grab_focus();
  6889. SEND_GUI_ACTION("ui_text_scroll_down");
  6890. CHECK(text_edit->get_viewport()->is_input_handled());
  6891. CHECK(text_edit->get_caret_line() == 1);
  6892. CHECK(text_edit->get_first_visible_line() == 1);
  6893. CHECK(text_edit->get_v_scroll() == 1);
  6894. CHECK(text_edit->get_last_full_visible_line() == visible_lines);
  6895. CHECK(text_edit->get_last_full_visible_line_wrap_index() == 0);
  6896. CHECK(text_edit->get_caret_wrap_index() == 0);
  6897. SEND_GUI_ACTION("ui_text_scroll_up");
  6898. CHECK(text_edit->get_viewport()->is_input_handled());
  6899. CHECK(text_edit->get_caret_line() == 1);
  6900. CHECK(text_edit->get_first_visible_line() == 0);
  6901. CHECK(text_edit->get_v_scroll() == 0);
  6902. CHECK(text_edit->get_last_full_visible_line() == visible_lines - 1);
  6903. CHECK(text_edit->get_last_full_visible_line_wrap_index() == 0);
  6904. CHECK(text_edit->get_caret_wrap_index() == 0);
  6905. // Page down, similar to VSCode, to end of page then scroll.
  6906. SEND_GUI_ACTION("ui_text_caret_page_down");
  6907. CHECK(text_edit->get_viewport()->is_input_handled());
  6908. CHECK(text_edit->get_caret_line() == 21);
  6909. CHECK(text_edit->get_first_visible_line() == 0);
  6910. CHECK(text_edit->get_v_scroll() == 0);
  6911. CHECK(text_edit->get_last_full_visible_line() == visible_lines - 1);
  6912. CHECK(text_edit->get_last_full_visible_line_wrap_index() == 0);
  6913. CHECK(text_edit->get_caret_wrap_index() == 0);
  6914. SEND_GUI_ACTION("ui_text_caret_page_down");
  6915. CHECK(text_edit->get_viewport()->is_input_handled());
  6916. CHECK(text_edit->get_caret_line() == 41);
  6917. CHECK(text_edit->get_first_visible_line() == 20);
  6918. CHECK(text_edit->get_v_scroll() == 20);
  6919. CHECK(text_edit->get_last_full_visible_line() == (visible_lines - 1) * 2);
  6920. CHECK(text_edit->get_last_full_visible_line_wrap_index() == 0);
  6921. CHECK(text_edit->get_caret_wrap_index() == 0);
  6922. SEND_GUI_ACTION("ui_text_caret_page_up");
  6923. CHECK(text_edit->get_viewport()->is_input_handled());
  6924. CHECK(text_edit->get_caret_line() == 21);
  6925. CHECK(text_edit->get_first_visible_line() == 20);
  6926. CHECK(text_edit->get_v_scroll() == 20);
  6927. CHECK(text_edit->get_last_full_visible_line() == (visible_lines - 1) * 2);
  6928. CHECK(text_edit->get_last_full_visible_line_wrap_index() == 0);
  6929. CHECK(text_edit->get_caret_wrap_index() == 0);
  6930. SEND_GUI_ACTION("ui_text_caret_page_up");
  6931. CHECK(text_edit->get_viewport()->is_input_handled());
  6932. CHECK(text_edit->get_caret_line() == 1);
  6933. CHECK(text_edit->get_first_visible_line() == 1);
  6934. CHECK(text_edit->get_v_scroll() == 1);
  6935. CHECK(text_edit->get_last_full_visible_line() == visible_lines);
  6936. CHECK(text_edit->get_last_full_visible_line_wrap_index() == 0);
  6937. CHECK(text_edit->get_caret_wrap_index() == 0);
  6938. text_edit->set_line_wrapping_mode(TextEdit::LineWrappingMode::LINE_WRAPPING_NONE);
  6939. MessageQueue::get_singleton()->flush();
  6940. text_edit->grab_focus();
  6941. SEND_GUI_ACTION("ui_text_scroll_down");
  6942. CHECK(text_edit->get_viewport()->is_input_handled());
  6943. CHECK(text_edit->get_caret_line() == 2);
  6944. CHECK(text_edit->get_first_visible_line() == 2);
  6945. CHECK(text_edit->get_v_scroll() == 2);
  6946. CHECK(text_edit->get_last_full_visible_line() == visible_lines + 1);
  6947. CHECK(text_edit->get_last_full_visible_line_wrap_index() == 0);
  6948. CHECK(text_edit->get_caret_wrap_index() == 0);
  6949. SEND_GUI_ACTION("ui_text_scroll_up");
  6950. CHECK(text_edit->get_viewport()->is_input_handled());
  6951. CHECK(text_edit->get_caret_line() == 2);
  6952. CHECK(text_edit->get_first_visible_line() == 1);
  6953. CHECK(text_edit->get_v_scroll() == 1);
  6954. CHECK(text_edit->get_last_full_visible_line() == visible_lines);
  6955. CHECK(text_edit->get_last_full_visible_line_wrap_index() == 0);
  6956. CHECK(text_edit->get_caret_wrap_index() == 0);
  6957. // Page down, similar to VSCode, to end of page then scroll.
  6958. SEND_GUI_ACTION("ui_text_caret_page_down");
  6959. CHECK(text_edit->get_viewport()->is_input_handled());
  6960. CHECK(text_edit->get_caret_line() == 22);
  6961. CHECK(text_edit->get_first_visible_line() == 1);
  6962. CHECK(text_edit->get_v_scroll() == 1);
  6963. CHECK(text_edit->get_last_full_visible_line() == visible_lines);
  6964. CHECK(text_edit->get_last_full_visible_line_wrap_index() == 0);
  6965. CHECK(text_edit->get_caret_wrap_index() == 0);
  6966. SEND_GUI_ACTION("ui_text_caret_page_down");
  6967. CHECK(text_edit->get_viewport()->is_input_handled());
  6968. CHECK(text_edit->get_caret_line() == 42);
  6969. CHECK(text_edit->get_first_visible_line() == 21);
  6970. CHECK(text_edit->get_v_scroll() == 21);
  6971. CHECK(text_edit->get_last_full_visible_line() == (visible_lines * 2) - 1);
  6972. CHECK(text_edit->get_last_full_visible_line_wrap_index() == 0);
  6973. CHECK(text_edit->get_caret_wrap_index() == 0);
  6974. SEND_GUI_ACTION("ui_text_caret_page_up");
  6975. CHECK(text_edit->get_viewport()->is_input_handled());
  6976. CHECK(text_edit->get_caret_line() == 22);
  6977. CHECK(text_edit->get_first_visible_line() == 21);
  6978. CHECK(text_edit->get_v_scroll() == 21);
  6979. CHECK(text_edit->get_last_full_visible_line() == (visible_lines * 2) - 1);
  6980. CHECK(text_edit->get_last_full_visible_line_wrap_index() == 0);
  6981. CHECK(text_edit->get_caret_wrap_index() == 0);
  6982. SEND_GUI_ACTION("ui_text_caret_page_up");
  6983. CHECK(text_edit->get_viewport()->is_input_handled());
  6984. CHECK(text_edit->get_caret_line() == 2);
  6985. CHECK(text_edit->get_first_visible_line() == 2);
  6986. CHECK(text_edit->get_v_scroll() == 2);
  6987. CHECK(text_edit->get_last_full_visible_line() == visible_lines + 1);
  6988. CHECK(text_edit->get_last_full_visible_line_wrap_index() == 0);
  6989. CHECK(text_edit->get_caret_wrap_index() == 0);
  6990. // Typing and undo / redo should adjust viewport.
  6991. text_edit->set_caret_line(0);
  6992. text_edit->set_caret_column(0);
  6993. text_edit->set_line_as_first_visible(5);
  6994. MessageQueue::get_singleton()->flush();
  6995. CHECK(text_edit->get_first_visible_line() == 5);
  6996. SEND_GUI_KEY_EVENT(Key::A);
  6997. CHECK(text_edit->get_first_visible_line() == 0);
  6998. text_edit->set_line_as_first_visible(5);
  6999. MessageQueue::get_singleton()->flush();
  7000. CHECK(text_edit->get_first_visible_line() == 5);
  7001. text_edit->undo();
  7002. MessageQueue::get_singleton()->flush();
  7003. CHECK(text_edit->get_first_visible_line() == 0);
  7004. text_edit->set_line_as_first_visible(5);
  7005. MessageQueue::get_singleton()->flush();
  7006. CHECK(text_edit->get_first_visible_line() == 5);
  7007. text_edit->redo();
  7008. MessageQueue::get_singleton()->flush();
  7009. CHECK(text_edit->get_first_visible_line() == 0);
  7010. memdelete(text_edit);
  7011. }
  7012. TEST_CASE("[SceneTree][TextEdit] setter getters") {
  7013. TextEdit *text_edit = memnew(TextEdit);
  7014. SceneTree::get_singleton()->get_root()->add_child(text_edit);
  7015. SUBCASE("[TextEdit] set and get placeholder") {
  7016. text_edit->set_placeholder("test\nplaceholder");
  7017. CHECK(text_edit->get_placeholder() == "test\nplaceholder");
  7018. CHECK(text_edit->get_text() == "");
  7019. CHECK(text_edit->get_line_count() == 1);
  7020. CHECK(text_edit->get_last_full_visible_line() == 0);
  7021. }
  7022. SUBCASE("[TextEdit] highlight current line") {
  7023. text_edit->set_highlight_current_line(true);
  7024. CHECK(text_edit->is_highlight_current_line_enabled());
  7025. text_edit->set_highlight_current_line(false);
  7026. CHECK_FALSE(text_edit->is_highlight_current_line_enabled());
  7027. }
  7028. SUBCASE("[TextEdit] highlight all occurrences") {
  7029. text_edit->set_highlight_all_occurrences(true);
  7030. CHECK(text_edit->is_highlight_all_occurrences_enabled());
  7031. text_edit->set_highlight_all_occurrences(false);
  7032. CHECK_FALSE(text_edit->is_highlight_all_occurrences_enabled());
  7033. }
  7034. SUBCASE("[TextEdit] draw control chars") {
  7035. text_edit->set_draw_control_chars(true);
  7036. CHECK(text_edit->get_draw_control_chars());
  7037. text_edit->set_draw_control_chars(false);
  7038. CHECK_FALSE(text_edit->get_draw_control_chars());
  7039. }
  7040. SUBCASE("[TextEdit] draw tabs") {
  7041. text_edit->set_draw_tabs(true);
  7042. CHECK(text_edit->is_drawing_tabs());
  7043. text_edit->set_draw_tabs(false);
  7044. CHECK_FALSE(text_edit->is_drawing_tabs());
  7045. }
  7046. SUBCASE("[TextEdit] draw spaces") {
  7047. text_edit->set_draw_spaces(true);
  7048. CHECK(text_edit->is_drawing_spaces());
  7049. text_edit->set_draw_spaces(false);
  7050. CHECK_FALSE(text_edit->is_drawing_spaces());
  7051. }
  7052. SUBCASE("[TextEdit] draw minimap") {
  7053. text_edit->set_draw_minimap(true);
  7054. CHECK(text_edit->is_drawing_minimap());
  7055. text_edit->set_draw_minimap(false);
  7056. CHECK_FALSE(text_edit->is_drawing_minimap());
  7057. }
  7058. SUBCASE("[TextEdit] minimap width") {
  7059. text_edit->set_minimap_width(-1);
  7060. CHECK(text_edit->get_minimap_width() == -1);
  7061. text_edit->set_minimap_width(1000);
  7062. CHECK(text_edit->get_minimap_width() == 1000);
  7063. }
  7064. SUBCASE("[TextEdit] line color background") {
  7065. ERR_PRINT_OFF;
  7066. text_edit->set_line_background_color(-1, Color("#ff0000"));
  7067. text_edit->set_line_background_color(0, Color("#00ff00"));
  7068. text_edit->set_line_background_color(1, Color("#0000ff"));
  7069. CHECK(text_edit->get_line_background_color(-1) == Color());
  7070. CHECK(text_edit->get_line_background_color(0) == Color("#00ff00"));
  7071. CHECK(text_edit->get_line_background_color(1) == Color());
  7072. ERR_PRINT_ON;
  7073. text_edit->set_line_background_color(0, Color("#ffff00"));
  7074. CHECK(text_edit->get_line_background_color(0) == Color("#ffff00"));
  7075. }
  7076. memdelete(text_edit);
  7077. }
  7078. TEST_CASE("[SceneTree][TextEdit] gutters") {
  7079. TextEdit *text_edit = memnew(TextEdit);
  7080. SceneTree::get_singleton()->get_root()->add_child(text_edit);
  7081. Array empty_signal_args;
  7082. empty_signal_args.push_back(Array());
  7083. SIGNAL_WATCH(text_edit, "gutter_clicked");
  7084. SIGNAL_WATCH(text_edit, "gutter_added");
  7085. SIGNAL_WATCH(text_edit, "gutter_removed");
  7086. SUBCASE("[TextEdit] gutter add and remove") {
  7087. text_edit->add_gutter();
  7088. CHECK(text_edit->get_gutter_count() == 1);
  7089. CHECK(text_edit->get_gutter_width(0) == 24);
  7090. CHECK(text_edit->get_total_gutter_width() == 24 + 2);
  7091. SIGNAL_CHECK("gutter_added", empty_signal_args);
  7092. text_edit->set_gutter_name(0, "test_gutter");
  7093. CHECK(text_edit->get_gutter_name(0) == "test_gutter");
  7094. text_edit->set_gutter_width(0, 10);
  7095. CHECK(text_edit->get_gutter_width(0) == 10);
  7096. CHECK(text_edit->get_total_gutter_width() == 10 + 2);
  7097. text_edit->add_gutter(-100);
  7098. text_edit->set_gutter_width(1, 10);
  7099. CHECK(text_edit->get_gutter_width(1) == 10);
  7100. CHECK(text_edit->get_total_gutter_width() == 20 + 2);
  7101. CHECK(text_edit->get_gutter_count() == 2);
  7102. CHECK(text_edit->get_gutter_name(0) == "test_gutter");
  7103. SIGNAL_CHECK("gutter_added", empty_signal_args);
  7104. text_edit->set_gutter_draw(1, false);
  7105. CHECK(text_edit->get_total_gutter_width() == 10 + 2);
  7106. text_edit->add_gutter(100);
  7107. CHECK(text_edit->get_gutter_count() == 3);
  7108. CHECK(text_edit->get_gutter_width(2) == 24);
  7109. CHECK(text_edit->get_total_gutter_width() == 34 + 2);
  7110. CHECK(text_edit->get_gutter_name(0) == "test_gutter");
  7111. SIGNAL_CHECK("gutter_added", empty_signal_args);
  7112. text_edit->add_gutter(0);
  7113. CHECK(text_edit->get_gutter_count() == 4);
  7114. CHECK(text_edit->get_gutter_width(0) == 24);
  7115. CHECK(text_edit->get_total_gutter_width() == 58 + 2);
  7116. CHECK(text_edit->get_gutter_name(1) == "test_gutter");
  7117. SIGNAL_CHECK("gutter_added", empty_signal_args);
  7118. text_edit->remove_gutter(2);
  7119. CHECK(text_edit->get_gutter_name(1) == "test_gutter");
  7120. CHECK(text_edit->get_gutter_count() == 3);
  7121. CHECK(text_edit->get_total_gutter_width() == 58 + 2);
  7122. SIGNAL_CHECK("gutter_removed", empty_signal_args);
  7123. text_edit->remove_gutter(0);
  7124. CHECK(text_edit->get_gutter_name(0) == "test_gutter");
  7125. CHECK(text_edit->get_gutter_count() == 2);
  7126. CHECK(text_edit->get_total_gutter_width() == 34 + 2);
  7127. SIGNAL_CHECK("gutter_removed", empty_signal_args);
  7128. ERR_PRINT_OFF;
  7129. text_edit->remove_gutter(-1);
  7130. SIGNAL_CHECK_FALSE("gutter_removed");
  7131. text_edit->remove_gutter(100);
  7132. SIGNAL_CHECK_FALSE("gutter_removed");
  7133. CHECK(text_edit->get_gutter_name(-1) == "");
  7134. CHECK(text_edit->get_gutter_name(100) == "");
  7135. ERR_PRINT_ON;
  7136. }
  7137. SUBCASE("[TextEdit] gutter data") {
  7138. text_edit->add_gutter();
  7139. CHECK(text_edit->get_gutter_count() == 1);
  7140. SIGNAL_CHECK("gutter_added", empty_signal_args);
  7141. text_edit->set_gutter_name(0, "test_gutter");
  7142. CHECK(text_edit->get_gutter_name(0) == "test_gutter");
  7143. text_edit->set_gutter_width(0, 10);
  7144. CHECK(text_edit->get_gutter_width(0) == 10);
  7145. text_edit->set_gutter_clickable(0, true);
  7146. CHECK(text_edit->is_gutter_clickable(0));
  7147. text_edit->set_gutter_overwritable(0, true);
  7148. CHECK(text_edit->is_gutter_overwritable(0));
  7149. text_edit->set_gutter_type(0, TextEdit::GutterType::GUTTER_TYPE_CUSTOM);
  7150. CHECK(text_edit->get_gutter_type(0) == TextEdit::GutterType::GUTTER_TYPE_CUSTOM);
  7151. text_edit->set_text("test\ntext");
  7152. ERR_PRINT_OFF;
  7153. text_edit->set_line_gutter_metadata(1, 0, "test");
  7154. text_edit->set_line_gutter_metadata(0, -1, "test");
  7155. text_edit->set_line_gutter_metadata(0, 2, "test");
  7156. text_edit->set_line_gutter_metadata(2, 0, "test");
  7157. text_edit->set_line_gutter_metadata(-1, 0, "test");
  7158. CHECK(text_edit->get_line_gutter_metadata(1, 0) == "test");
  7159. CHECK(text_edit->get_line_gutter_metadata(0, -1) == "");
  7160. CHECK(text_edit->get_line_gutter_metadata(0, 2) == "");
  7161. CHECK(text_edit->get_line_gutter_metadata(2, 0) == "");
  7162. CHECK(text_edit->get_line_gutter_metadata(-1, 0) == "");
  7163. text_edit->set_line_gutter_text(1, 0, "test");
  7164. text_edit->set_line_gutter_text(0, -1, "test");
  7165. text_edit->set_line_gutter_text(0, 2, "test");
  7166. text_edit->set_line_gutter_text(2, 0, "test");
  7167. text_edit->set_line_gutter_text(-1, 0, "test");
  7168. CHECK(text_edit->get_line_gutter_text(1, 0) == "test");
  7169. CHECK(text_edit->get_line_gutter_text(0, -1) == "");
  7170. CHECK(text_edit->get_line_gutter_text(0, 2) == "");
  7171. CHECK(text_edit->get_line_gutter_text(2, 0) == "");
  7172. CHECK(text_edit->get_line_gutter_text(-1, 0) == "");
  7173. text_edit->set_line_gutter_item_color(1, 0, Color(1, 0, 0));
  7174. text_edit->set_line_gutter_item_color(0, -1, Color(1, 0, 0));
  7175. text_edit->set_line_gutter_item_color(0, 2, Color(1, 0, 0));
  7176. text_edit->set_line_gutter_item_color(2, 0, Color(1, 0, 0));
  7177. text_edit->set_line_gutter_item_color(-1, 0, Color(1, 0, 0));
  7178. CHECK(text_edit->get_line_gutter_item_color(1, 0) == Color(1, 0, 0));
  7179. CHECK(text_edit->get_line_gutter_item_color(0, -1) == Color());
  7180. CHECK(text_edit->get_line_gutter_item_color(0, 2) == Color());
  7181. CHECK(text_edit->get_line_gutter_item_color(2, 0) == Color());
  7182. CHECK(text_edit->get_line_gutter_item_color(-1, 0) == Color());
  7183. text_edit->set_line_gutter_clickable(1, 0, true);
  7184. text_edit->set_line_gutter_clickable(0, -1, true);
  7185. text_edit->set_line_gutter_clickable(0, 2, true);
  7186. text_edit->set_line_gutter_clickable(2, 0, true);
  7187. text_edit->set_line_gutter_clickable(-1, 0, true);
  7188. CHECK(text_edit->is_line_gutter_clickable(1, 0) == true);
  7189. CHECK(text_edit->is_line_gutter_clickable(0, -1) == false);
  7190. CHECK(text_edit->is_line_gutter_clickable(0, 2) == false);
  7191. CHECK(text_edit->is_line_gutter_clickable(2, 0) == false);
  7192. CHECK(text_edit->is_line_gutter_clickable(-1, 0) == false);
  7193. ERR_PRINT_ON;
  7194. // Merging tested via CodeEdit gutters.
  7195. }
  7196. SIGNAL_UNWATCH(text_edit, "gutter_clicked");
  7197. SIGNAL_UNWATCH(text_edit, "gutter_added");
  7198. SIGNAL_UNWATCH(text_edit, "gutter_removed");
  7199. memdelete(text_edit);
  7200. }
  7201. } // namespace TestTextEdit
  7202. #endif // TEST_TEXT_EDIT_H