123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163 |
- /**************************************************************************/
- /* test_text_edit.h */
- /**************************************************************************/
- /* This file is part of: */
- /* GODOT ENGINE */
- /* https://godotengine.org */
- /**************************************************************************/
- /* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
- /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
- /* */
- /* Permission is hereby granted, free of charge, to any person obtaining */
- /* a copy of this software and associated documentation files (the */
- /* "Software"), to deal in the Software without restriction, including */
- /* without limitation the rights to use, copy, modify, merge, publish, */
- /* distribute, sublicense, and/or sell copies of the Software, and to */
- /* permit persons to whom the Software is furnished to do so, subject to */
- /* the following conditions: */
- /* */
- /* The above copyright notice and this permission notice shall be */
- /* included in all copies or substantial portions of the Software. */
- /* */
- /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
- /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
- /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
- /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
- /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
- /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
- /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
- /**************************************************************************/
- #ifndef TEST_TEXT_EDIT_H
- #define TEST_TEXT_EDIT_H
- #include "scene/gui/text_edit.h"
- #include "tests/test_macros.h"
- namespace TestTextEdit {
- static inline Array build_array() {
- return Array();
- }
- template <typename... Targs>
- static inline Array build_array(Variant item, Targs... Fargs) {
- Array a = build_array(Fargs...);
- a.push_front(item);
- return a;
- }
- static inline Array reverse_nested(Array array) {
- Array reversed_array = array.duplicate(true);
- reversed_array.reverse();
- for (int i = 0; i < reversed_array.size(); i++) {
- ((Array)reversed_array[i]).reverse();
- }
- return reversed_array;
- }
- TEST_CASE("[SceneTree][TextEdit] text entry") {
- SceneTree::get_singleton()->get_root()->set_physics_object_picking(false);
- TextEdit *text_edit = memnew(TextEdit);
- SceneTree::get_singleton()->get_root()->add_child(text_edit);
- text_edit->grab_focus();
- Array empty_signal_args;
- empty_signal_args.push_back(Array());
- SUBCASE("[TextEdit] text entry") {
- SIGNAL_WATCH(text_edit, "text_set");
- SIGNAL_WATCH(text_edit, "text_changed");
- SIGNAL_WATCH(text_edit, "lines_edited_from");
- SIGNAL_WATCH(text_edit, "caret_changed");
- Array lines_edited_args = build_array(build_array(0, 0), build_array(0, 0));
- SUBCASE("[TextEdit] clear and set text") {
- // "text_changed" should not be emitted on clear / set.
- text_edit->clear();
- MessageQueue::get_singleton()->flush();
- CHECK(text_edit->get_text() == "");
- CHECK(text_edit->get_caret_column() == 0);
- CHECK(text_edit->get_line_count() == 1);
- SIGNAL_CHECK("text_set", empty_signal_args);
- SIGNAL_CHECK("lines_edited_from", lines_edited_args);
- SIGNAL_CHECK_FALSE("caret_changed");
- SIGNAL_CHECK_FALSE("text_changed");
- text_edit->set_text("test text");
- MessageQueue::get_singleton()->flush();
- CHECK(text_edit->get_text() == "test text");
- CHECK(text_edit->get_caret_column() == 0);
- CHECK(text_edit->get_line_count() == 1);
- SIGNAL_CHECK("text_set", empty_signal_args);
- SIGNAL_CHECK("lines_edited_from", lines_edited_args);
- SIGNAL_CHECK("caret_changed", empty_signal_args);
- SIGNAL_CHECK_FALSE("text_changed");
- text_edit->clear();
- MessageQueue::get_singleton()->flush();
- CHECK(text_edit->get_text() == "");
- CHECK(text_edit->get_caret_column() == 0);
- SIGNAL_CHECK("text_set", empty_signal_args);
- SIGNAL_CHECK("lines_edited_from", lines_edited_args);
- SIGNAL_CHECK_FALSE("caret_changed");
- SIGNAL_CHECK_FALSE("text_changed");
- // Can undo / redo words when editable.
- text_edit->undo();
- MessageQueue::get_singleton()->flush();
- CHECK(text_edit->get_text() == "test text");
- CHECK(text_edit->get_caret_column() == 0);
- SIGNAL_CHECK("lines_edited_from", lines_edited_args);
- SIGNAL_CHECK("text_changed", empty_signal_args);
- SIGNAL_CHECK_FALSE("caret_changed");
- SIGNAL_CHECK_FALSE("text_set");
- text_edit->redo();
- MessageQueue::get_singleton()->flush();
- CHECK(text_edit->get_text() == "");
- CHECK(text_edit->get_caret_column() == 0);
- SIGNAL_CHECK("lines_edited_from", lines_edited_args);
- SIGNAL_CHECK("text_changed", empty_signal_args);
- SIGNAL_CHECK_FALSE("caret_changed");
- SIGNAL_CHECK_FALSE("text_set");
- // Cannot undo when not-editable but should still clear.
- text_edit->undo();
- MessageQueue::get_singleton()->flush();
- CHECK(text_edit->get_text() == "test text");
- CHECK(text_edit->get_caret_column() == 0);
- SIGNAL_CHECK("lines_edited_from", lines_edited_args);
- SIGNAL_CHECK("text_changed", empty_signal_args);
- SIGNAL_CHECK_FALSE("caret_changed");
- SIGNAL_CHECK_FALSE("text_set");
- // Can clear even if not editable.
- text_edit->set_editable(false);
- Array lines_edited_clear_args = build_array(build_array(1, 0));
- text_edit->clear();
- MessageQueue::get_singleton()->flush();
- CHECK(text_edit->get_text() == "");
- CHECK(text_edit->get_caret_column() == 0);
- SIGNAL_CHECK("text_set", empty_signal_args);
- SIGNAL_CHECK("lines_edited_from", lines_edited_clear_args);
- SIGNAL_CHECK_FALSE("caret_changed");
- SIGNAL_CHECK_FALSE("text_changed");
- text_edit->set_editable(true);
- text_edit->undo();
- MessageQueue::get_singleton()->flush();
- CHECK(text_edit->get_text() == "");
- CHECK(text_edit->get_caret_column() == 0);
- SIGNAL_CHECK_FALSE("text_set");
- SIGNAL_CHECK_FALSE("lines_edited_from");
- SIGNAL_CHECK_FALSE("text_changed");
- SIGNAL_CHECK_FALSE("caret_changed");
- // Can still undo set_text.
- text_edit->set_editable(false);
- text_edit->set_text("test text");
- MessageQueue::get_singleton()->flush();
- CHECK(text_edit->get_text() == "test text");
- CHECK(text_edit->get_caret_column() == 0);
- SIGNAL_CHECK("text_set", empty_signal_args);
- SIGNAL_CHECK("lines_edited_from", lines_edited_args);
- SIGNAL_CHECK("caret_changed", empty_signal_args);
- SIGNAL_CHECK_FALSE("text_changed");
- text_edit->set_editable(true);
- text_edit->undo();
- MessageQueue::get_singleton()->flush();
- CHECK(text_edit->get_text() == "");
- CHECK(text_edit->get_caret_column() == 0);
- SIGNAL_CHECK("lines_edited_from", lines_edited_args);
- SIGNAL_CHECK("text_changed", empty_signal_args);
- SIGNAL_CHECK_FALSE("caret_changed");
- SIGNAL_CHECK_FALSE("text_set");
- // Any selections are removed.
- text_edit->set_text("test text");
- MessageQueue::get_singleton()->flush();
- text_edit->select_all();
- SIGNAL_CHECK("caret_changed", empty_signal_args);
- MessageQueue::get_singleton()->flush();
- CHECK(text_edit->get_text() == "test text");
- CHECK(text_edit->get_caret_column() == 9);
- CHECK(text_edit->has_selection());
- SIGNAL_CHECK("text_set", empty_signal_args);
- SIGNAL_CHECK("lines_edited_from", lines_edited_args);
- SIGNAL_CHECK("caret_changed", empty_signal_args);
- SIGNAL_CHECK_FALSE("text_changed");
- text_edit->set_text("test");
- MessageQueue::get_singleton()->flush();
- CHECK(text_edit->get_text() == "test");
- CHECK(text_edit->get_caret_column() == 0);
- CHECK_FALSE(text_edit->has_selection());
- SIGNAL_CHECK("text_set", empty_signal_args);
- SIGNAL_CHECK("lines_edited_from", lines_edited_args);
- SIGNAL_CHECK("caret_changed", empty_signal_args);
- SIGNAL_CHECK_FALSE("text_changed");
- text_edit->select_all();
- MessageQueue::get_singleton()->flush();
- SIGNAL_CHECK("caret_changed", empty_signal_args);
- CHECK(text_edit->has_selection());
- text_edit->clear();
- MessageQueue::get_singleton()->flush();
- CHECK(text_edit->get_text() == "");
- CHECK(text_edit->get_caret_column() == 0);
- CHECK_FALSE(text_edit->has_selection());
- SIGNAL_CHECK("text_set", empty_signal_args);
- SIGNAL_CHECK("lines_edited_from", lines_edited_args);
- SIGNAL_CHECK("caret_changed", empty_signal_args);
- SIGNAL_CHECK_FALSE("text_changed");
- }
- SUBCASE("[TextEdit] insert text") {
- // insert_text is 0 indexed.
- ERR_PRINT_OFF;
- text_edit->insert_text("test", 1, 0);
- ERR_PRINT_ON;
- MessageQueue::get_singleton()->flush();
- CHECK(text_edit->get_text() == "");
- SIGNAL_CHECK_FALSE("lines_edited_from");
- SIGNAL_CHECK_FALSE("text_changed");
- SIGNAL_CHECK_FALSE("caret_changed");
- SIGNAL_CHECK_FALSE("text_set");
- // Insert text when there is no text.
- lines_edited_args = build_array(build_array(0, 0));
- text_edit->insert_text("tes", 0, 0);
- MessageQueue::get_singleton()->flush();
- CHECK(text_edit->get_text() == "tes");
- CHECK(text_edit->get_caret_line() == 0);
- CHECK(text_edit->get_caret_column() == 3);
- SIGNAL_CHECK("lines_edited_from", lines_edited_args);
- SIGNAL_CHECK("text_changed", empty_signal_args);
- SIGNAL_CHECK("caret_changed", empty_signal_args);
- SIGNAL_CHECK_FALSE("text_set");
- // Insert multiple lines.
- lines_edited_args = build_array(build_array(0, 1));
- text_edit->insert_text("t\ninserting text", 0, 3);
- MessageQueue::get_singleton()->flush();
- CHECK(text_edit->get_text() == "test\ninserting text");
- CHECK(text_edit->get_caret_line() == 1);
- CHECK(text_edit->get_caret_column() == 14);
- SIGNAL_CHECK("lines_edited_from", lines_edited_args);
- SIGNAL_CHECK("text_changed", empty_signal_args);
- SIGNAL_CHECK("caret_changed", empty_signal_args);
- SIGNAL_CHECK_FALSE("text_set");
- // Can insert even if not editable.
- lines_edited_args = build_array(build_array(1, 1));
- text_edit->set_editable(false);
- text_edit->insert_text("mid", 1, 2);
- MessageQueue::get_singleton()->flush();
- CHECK(text_edit->get_text() == "test\ninmidserting text");
- CHECK(text_edit->get_caret_line() == 1);
- CHECK(text_edit->get_caret_column() == 17);
- SIGNAL_CHECK("lines_edited_from", lines_edited_args);
- SIGNAL_CHECK("text_changed", empty_signal_args);
- SIGNAL_CHECK("caret_changed", empty_signal_args);
- SIGNAL_CHECK_FALSE("text_set");
- text_edit->set_editable(true);
- // Undo insert.
- text_edit->undo();
- MessageQueue::get_singleton()->flush();
- CHECK(text_edit->get_text() == "test\ninserting text");
- CHECK(text_edit->get_caret_line() == 1);
- CHECK(text_edit->get_caret_column() == 14);
- SIGNAL_CHECK("lines_edited_from", lines_edited_args);
- SIGNAL_CHECK("text_changed", empty_signal_args);
- SIGNAL_CHECK("caret_changed", empty_signal_args);
- SIGNAL_CHECK_FALSE("text_set");
- // Redo insert.
- text_edit->redo();
- MessageQueue::get_singleton()->flush();
- CHECK(text_edit->get_text() == "test\ninmidserting text");
- CHECK(text_edit->get_caret_line() == 1);
- CHECK(text_edit->get_caret_column() == 17);
- SIGNAL_CHECK("lines_edited_from", lines_edited_args);
- SIGNAL_CHECK("text_changed", empty_signal_args);
- SIGNAL_CHECK("caret_changed", empty_signal_args);
- SIGNAL_CHECK_FALSE("text_set");
- // Insert offsets carets after the edit.
- text_edit->add_caret(1, 1);
- text_edit->add_caret(1, 4);
- text_edit->select(1, 4, 1, 6, 2);
- MessageQueue::get_singleton()->flush();
- SIGNAL_DISCARD("caret_changed");
- lines_edited_args = build_array(build_array(1, 2));
- text_edit->insert_text("\n ", 1, 2);
- MessageQueue::get_singleton()->flush();
- CHECK(text_edit->get_text() == "test\nin\n midserting text");
- CHECK(text_edit->get_caret_count() == 3);
- CHECK_FALSE(text_edit->has_selection(0));
- CHECK(text_edit->get_caret_line(0) == 2);
- CHECK(text_edit->get_caret_column(0) == 16);
- CHECK_FALSE(text_edit->has_selection(1));
- CHECK(text_edit->get_caret_line(1) == 1);
- CHECK(text_edit->get_caret_column(1) == 1);
- CHECK(text_edit->has_selection(2));
- CHECK(text_edit->get_caret_line(2) == 2);
- CHECK(text_edit->get_caret_column(2) == 5);
- CHECK(text_edit->get_selection_origin_line(2) == 2);
- CHECK(text_edit->get_selection_origin_column(2) == 3);
- SIGNAL_CHECK("lines_edited_from", lines_edited_args);
- SIGNAL_CHECK("text_changed", empty_signal_args);
- SIGNAL_CHECK("caret_changed", empty_signal_args);
- SIGNAL_CHECK_FALSE("text_set");
- text_edit->remove_secondary_carets();
- text_edit->deselect();
- // Insert text outside of selections.
- text_edit->set_text("test text");
- text_edit->add_caret(0, 8);
- text_edit->select(0, 1, 0, 4, 0);
- text_edit->select(0, 4, 0, 8, 1);
- MessageQueue::get_singleton()->flush();
- SIGNAL_DISCARD("text_set");
- SIGNAL_DISCARD("lines_edited_from");
- SIGNAL_DISCARD("text_changed");
- SIGNAL_DISCARD("caret_changed");
- lines_edited_args = build_array(build_array(0, 0));
- text_edit->insert_text("a", 0, 4, true, false);
- MessageQueue::get_singleton()->flush();
- CHECK(text_edit->get_text() == "testa text");
- CHECK(text_edit->get_caret_count() == 2);
- CHECK(text_edit->has_selection(0));
- CHECK(text_edit->get_caret_line(0) == 0);
- CHECK(text_edit->get_caret_column(0) == 4);
- CHECK(text_edit->get_selection_origin_line(0) == 0);
- CHECK(text_edit->get_selection_origin_column(0) == 1);
- CHECK(text_edit->has_selection(1));
- CHECK(text_edit->get_caret_line(1) == 0);
- CHECK(text_edit->get_caret_column(1) == 9);
- CHECK(text_edit->get_selection_origin_line(1) == 0);
- CHECK(text_edit->get_selection_origin_column(1) == 5);
- // Insert text to beginning of selections.
- text_edit->set_text("test text");
- text_edit->add_caret(0, 8);
- text_edit->select(0, 1, 0, 4, 0);
- text_edit->select(0, 4, 0, 8, 1);
- MessageQueue::get_singleton()->flush();
- SIGNAL_DISCARD("text_set");
- SIGNAL_DISCARD("lines_edited_from");
- SIGNAL_DISCARD("text_changed");
- SIGNAL_DISCARD("caret_changed");
- lines_edited_args = build_array(build_array(0, 0));
- text_edit->insert_text("a", 0, 4, false, false);
- MessageQueue::get_singleton()->flush();
- CHECK(text_edit->get_text() == "testa text");
- CHECK(text_edit->get_caret_count() == 2);
- CHECK(text_edit->has_selection(0));
- CHECK(text_edit->get_caret_line(0) == 0);
- CHECK(text_edit->get_caret_column(0) == 4);
- CHECK(text_edit->get_selection_origin_line(0) == 0);
- CHECK(text_edit->get_selection_origin_column(0) == 1);
- CHECK(text_edit->has_selection(1));
- CHECK(text_edit->get_caret_line(1) == 0);
- CHECK(text_edit->get_caret_column(1) == 9);
- CHECK(text_edit->get_selection_origin_line(1) == 0);
- CHECK(text_edit->get_selection_origin_column(1) == 4);
- // Insert text to end of selections.
- text_edit->set_text("test text");
- text_edit->add_caret(0, 8);
- text_edit->select(0, 1, 0, 4, 0);
- text_edit->select(0, 4, 0, 8, 1);
- MessageQueue::get_singleton()->flush();
- SIGNAL_DISCARD("text_set");
- SIGNAL_DISCARD("lines_edited_from");
- SIGNAL_DISCARD("text_changed");
- SIGNAL_DISCARD("caret_changed");
- lines_edited_args = build_array(build_array(0, 0));
- text_edit->insert_text("a", 0, 4, true, true);
- MessageQueue::get_singleton()->flush();
- CHECK(text_edit->get_text() == "testa text");
- CHECK(text_edit->get_caret_count() == 2);
- CHECK(text_edit->has_selection(0));
- CHECK(text_edit->get_caret_line(0) == 0);
- CHECK(text_edit->get_caret_column(0) == 5);
- CHECK(text_edit->get_selection_origin_line(0) == 0);
- CHECK(text_edit->get_selection_origin_column(0) == 1);
- CHECK(text_edit->has_selection(1));
- CHECK(text_edit->get_caret_line(1) == 0);
- CHECK(text_edit->get_caret_column(1) == 9);
- CHECK(text_edit->get_selection_origin_line(1) == 0);
- CHECK(text_edit->get_selection_origin_column(1) == 5);
- // Insert text inside of selections.
- text_edit->set_text("test text");
- text_edit->add_caret(0, 8);
- text_edit->select(0, 1, 0, 4, 0);
- text_edit->select(0, 4, 0, 8, 1);
- MessageQueue::get_singleton()->flush();
- SIGNAL_DISCARD("text_set");
- SIGNAL_DISCARD("lines_edited_from");
- SIGNAL_DISCARD("text_changed");
- SIGNAL_DISCARD("caret_changed");
- lines_edited_args = build_array(build_array(0, 0));
- text_edit->insert_text("a", 0, 4, false, true);
- MessageQueue::get_singleton()->flush();
- CHECK(text_edit->get_text() == "testa text");
- CHECK(text_edit->get_caret_count() == 1);
- CHECK(text_edit->has_selection(0));
- CHECK(text_edit->get_caret_line(0) == 0);
- CHECK(text_edit->get_caret_column(0) == 9);
- CHECK(text_edit->get_selection_origin_line(0) == 0);
- CHECK(text_edit->get_selection_origin_column(0) == 1);
- }
- SUBCASE("[TextEdit] remove text") {
- lines_edited_args = build_array(build_array(0, 0), build_array(0, 2));
- text_edit->set_text("test\nremoveing text\nthird line");
- MessageQueue::get_singleton()->flush();
- SIGNAL_CHECK("text_set", empty_signal_args);
- SIGNAL_CHECK("lines_edited_from", lines_edited_args);
- SIGNAL_CHECK("caret_changed", empty_signal_args);
- SIGNAL_CHECK_FALSE("text_changed");
- // remove_text is 0 indexed.
- ERR_PRINT_OFF;
- text_edit->remove_text(3, 0, 3, 4);
- ERR_PRINT_ON;
- MessageQueue::get_singleton()->flush();
- CHECK(text_edit->get_text() == "test\nremoveing text\nthird line");
- SIGNAL_CHECK_FALSE("lines_edited_from");
- SIGNAL_CHECK_FALSE("text_changed");
- SIGNAL_CHECK_FALSE("caret_changed");
- SIGNAL_CHECK_FALSE("text_set");
- // Remove multiple lines.
- text_edit->set_caret_line(2);
- text_edit->set_caret_column(10);
- MessageQueue::get_singleton()->flush();
- SIGNAL_DISCARD("caret_changed");
- lines_edited_args = build_array(build_array(2, 1));
- text_edit->remove_text(1, 9, 2, 2);
- MessageQueue::get_singleton()->flush();
- CHECK(text_edit->get_text() == "test\nremoveingird line");
- CHECK(text_edit->get_caret_line() == 1);
- CHECK(text_edit->get_caret_column() == 17);
- SIGNAL_CHECK("lines_edited_from", lines_edited_args);
- SIGNAL_CHECK("text_changed", empty_signal_args);
- SIGNAL_CHECK("caret_changed", empty_signal_args);
- SIGNAL_CHECK_FALSE("text_set");
- // Can remove even if not editable.
- lines_edited_args = build_array(build_array(1, 1));
- text_edit->set_editable(false);
- text_edit->remove_text(1, 5, 1, 6);
- MessageQueue::get_singleton()->flush();
- CHECK(text_edit->get_text() == "test\nremovingird line");
- CHECK(text_edit->get_caret_line() == 1);
- CHECK(text_edit->get_caret_column() == 16);
- SIGNAL_CHECK("lines_edited_from", lines_edited_args);
- SIGNAL_CHECK("text_changed", empty_signal_args);
- SIGNAL_CHECK("caret_changed", empty_signal_args);
- SIGNAL_CHECK_FALSE("text_set");
- text_edit->set_editable(true);
- // Undo remove.
- text_edit->undo();
- MessageQueue::get_singleton()->flush();
- CHECK(text_edit->get_text() == "test\nremoveingird line");
- CHECK(text_edit->get_caret_line() == 1);
- CHECK(text_edit->get_caret_column() == 17);
- SIGNAL_CHECK("lines_edited_from", lines_edited_args);
- SIGNAL_CHECK("text_changed", empty_signal_args);
- SIGNAL_CHECK("caret_changed", empty_signal_args);
- SIGNAL_CHECK_FALSE("text_set");
- // Redo remove.
- text_edit->redo();
- MessageQueue::get_singleton()->flush();
- CHECK(text_edit->get_text() == "test\nremovingird line");
- CHECK(text_edit->get_caret_line() == 1);
- CHECK(text_edit->get_caret_column() == 16);
- SIGNAL_CHECK("lines_edited_from", lines_edited_args);
- SIGNAL_CHECK("text_changed", empty_signal_args);
- SIGNAL_CHECK("caret_changed", empty_signal_args);
- SIGNAL_CHECK_FALSE("text_set");
- // Remove collapses carets and offsets carets after the edit.
- text_edit->set_caret_line(1);
- text_edit->set_caret_column(9);
- text_edit->add_caret(1, 10);
- text_edit->select(1, 10, 1, 13, 1);
- text_edit->add_caret(1, 14);
- text_edit->add_caret(1, 2);
- MessageQueue::get_singleton()->flush();
- SIGNAL_CHECK("caret_changed", empty_signal_args);
- text_edit->remove_text(1, 8, 1, 11);
- MessageQueue::get_singleton()->flush();
- CHECK(text_edit->get_text() == "test\nremoving line");
- // Caret 0 was merged into the selection.
- CHECK(text_edit->get_caret_count() == 3);
- CHECK(text_edit->has_selection(0));
- CHECK(text_edit->get_caret_line(0) == 1);
- CHECK(text_edit->get_caret_column(0) == 10);
- CHECK(text_edit->get_selection_origin_line(0) == 1);
- CHECK(text_edit->get_selection_origin_column(0) == 8);
- CHECK(text_edit->get_caret_line(1) == 1);
- CHECK(text_edit->get_caret_column(1) == 11);
- CHECK(text_edit->get_caret_line(2) == 1);
- CHECK(text_edit->get_caret_column(2) == 2);
- SIGNAL_CHECK("lines_edited_from", lines_edited_args);
- SIGNAL_CHECK("text_changed", empty_signal_args);
- SIGNAL_CHECK("caret_changed", empty_signal_args);
- SIGNAL_CHECK_FALSE("text_set");
- text_edit->remove_secondary_carets();
- }
- SUBCASE("[TextEdit] set and get line") {
- // Set / Get line is 0 indexed.
- text_edit->set_line(1, "test");
- MessageQueue::get_singleton()->flush();
- CHECK(text_edit->get_text() == "");
- SIGNAL_CHECK_FALSE("lines_edited_from");
- SIGNAL_CHECK_FALSE("text_set");
- SIGNAL_CHECK_FALSE("text_changed");
- SIGNAL_CHECK_FALSE("caret_changed");
- text_edit->set_line(0, "test");
- MessageQueue::get_singleton()->flush();
- CHECK(text_edit->get_text() == "test");
- CHECK(text_edit->get_line(0) == "test");
- CHECK(text_edit->get_line(1) == "");
- CHECK(text_edit->get_line_count() == 1);
- SIGNAL_CHECK("lines_edited_from", lines_edited_args);
- SIGNAL_CHECK("text_changed", empty_signal_args);
- SIGNAL_CHECK_FALSE("text_set");
- SIGNAL_CHECK_FALSE("caret_changed");
- // Setting to a longer line, caret and selections should be preserved.
- text_edit->select_all();
- MessageQueue::get_singleton()->flush();
- SIGNAL_DISCARD("caret_changed");
- text_edit->set_line(0, "test text");
- MessageQueue::get_singleton()->flush();
- CHECK(text_edit->get_line(0) == "test text");
- CHECK(text_edit->has_selection());
- CHECK(text_edit->get_selected_text() == "test");
- CHECK(text_edit->get_selection_origin_column() == 0);
- CHECK(text_edit->get_caret_column() == 4);
- SIGNAL_CHECK("lines_edited_from", lines_edited_args);
- SIGNAL_CHECK("text_changed", empty_signal_args);
- SIGNAL_CHECK_FALSE("caret_changed");
- SIGNAL_CHECK_FALSE("text_set");
- // Setting to a shorter line, selection and caret should be adjusted. Also works if not editable.
- text_edit->set_editable(false);
- text_edit->set_line(0, "te");
- MessageQueue::get_singleton()->flush();
- CHECK(text_edit->get_line(0) == "te");
- CHECK(text_edit->has_selection());
- CHECK(text_edit->get_selected_text() == "te");
- CHECK(text_edit->get_caret_column() == 2);
- SIGNAL_CHECK("lines_edited_from", lines_edited_args);
- SIGNAL_CHECK("caret_changed", empty_signal_args);
- SIGNAL_CHECK("text_changed", empty_signal_args);
- SIGNAL_CHECK_FALSE("text_set");
- text_edit->set_editable(true);
- // Undo / redo should work.
- text_edit->undo();
- MessageQueue::get_singleton()->flush();
- CHECK(text_edit->get_line(0) == "test text");
- CHECK(text_edit->has_selection());
- CHECK(text_edit->get_selected_text() == "test");
- CHECK(text_edit->get_caret_column() == 4);
- SIGNAL_CHECK("lines_edited_from", lines_edited_args);
- SIGNAL_CHECK("caret_changed", empty_signal_args);
- SIGNAL_CHECK("text_changed", empty_signal_args);
- SIGNAL_CHECK_FALSE("text_set");
- text_edit->redo();
- MessageQueue::get_singleton()->flush();
- CHECK(text_edit->get_line(0) == "te");
- CHECK(text_edit->has_selection());
- CHECK(text_edit->get_caret_column() == 2);
- SIGNAL_CHECK("lines_edited_from", lines_edited_args);
- SIGNAL_CHECK("caret_changed", empty_signal_args);
- SIGNAL_CHECK("text_changed", empty_signal_args);
- SIGNAL_CHECK_FALSE("text_set");
- // Out of range.
- ERR_PRINT_OFF;
- text_edit->set_line(-1, "test");
- MessageQueue::get_singleton()->flush();
- CHECK(text_edit->get_line(0) == "te");
- SIGNAL_CHECK_FALSE("lines_edited_from");
- SIGNAL_CHECK_FALSE("caret_changed");
- SIGNAL_CHECK_FALSE("text_changed");
- SIGNAL_CHECK_FALSE("text_set");
- text_edit->set_line(1, "test");
- MessageQueue::get_singleton()->flush();
- CHECK(text_edit->get_line(0) == "te");
- SIGNAL_CHECK_FALSE("lines_edited_from");
- SIGNAL_CHECK_FALSE("caret_changed");
- SIGNAL_CHECK_FALSE("text_changed");
- SIGNAL_CHECK_FALSE("text_set");
- ERR_PRINT_ON;
- // Both ends of selection are adjusted and deselects.
- text_edit->set_text("test text");
- text_edit->select(0, 8, 0, 6);
- MessageQueue::get_singleton()->flush();
- SIGNAL_DISCARD("lines_edited_from");
- SIGNAL_DISCARD("text_set");
- SIGNAL_DISCARD("text_changed");
- SIGNAL_DISCARD("caret_changed");
- text_edit->set_line(0, "test");
- MessageQueue::get_singleton()->flush();
- CHECK(text_edit->get_line(0) == "test");
- CHECK_FALSE(text_edit->has_selection());
- CHECK(text_edit->get_caret_column() == 4);
- SIGNAL_CHECK("lines_edited_from", lines_edited_args);
- SIGNAL_CHECK("text_changed", empty_signal_args);
- SIGNAL_CHECK("caret_changed", empty_signal_args);
- SIGNAL_CHECK_FALSE("text_set");
- // Multiple carets adjust to keep visual position.
- text_edit->set_text("test text");
- text_edit->set_caret_column(2);
- text_edit->add_caret(0, 0);
- text_edit->add_caret(0, 1);
- text_edit->add_caret(0, 6);
- MessageQueue::get_singleton()->flush();
- SIGNAL_DISCARD("lines_edited_from");
- SIGNAL_DISCARD("text_set");
- SIGNAL_DISCARD("text_changed");
- SIGNAL_DISCARD("caret_changed");
- text_edit->set_line(0, "\tset line");
- MessageQueue::get_singleton()->flush();
- CHECK(text_edit->get_line(0) == "\tset line");
- CHECK(text_edit->get_caret_count() == 3);
- CHECK_FALSE(text_edit->has_selection());
- // In the default font, these are the same positions.
- CHECK(text_edit->get_caret_column(0) == 1);
- CHECK(text_edit->get_caret_column(1) == 0);
- // The previous caret at index 2 was merged.
- CHECK(text_edit->get_caret_column(2) == 4);
- SIGNAL_CHECK("lines_edited_from", lines_edited_args);
- SIGNAL_CHECK("text_changed", empty_signal_args);
- SIGNAL_CHECK("caret_changed", empty_signal_args);
- SIGNAL_CHECK_FALSE("text_set");
- text_edit->remove_secondary_carets();
- // Insert multiple lines.
- text_edit->set_text("test text\nsecond line");
- text_edit->set_caret_column(5);
- text_edit->add_caret(1, 6);
- MessageQueue::get_singleton()->flush();
- SIGNAL_DISCARD("lines_edited_from");
- SIGNAL_DISCARD("text_set");
- SIGNAL_DISCARD("text_changed");
- SIGNAL_DISCARD("caret_changed");
- lines_edited_args = build_array(build_array(0, 0), build_array(0, 1));
- text_edit->set_line(0, "multiple\nlines");
- MessageQueue::get_singleton()->flush();
- CHECK(text_edit->get_text() == "multiple\nlines\nsecond line");
- CHECK(text_edit->get_caret_count() == 2);
- CHECK_FALSE(text_edit->has_selection());
- CHECK(text_edit->get_caret_line(0) == 0);
- CHECK(text_edit->get_caret_column(0) == 3); // In the default font, this is the same position.
- CHECK(text_edit->get_caret_line(1) == 2);
- CHECK(text_edit->get_caret_column(1) == 6);
- SIGNAL_CHECK("lines_edited_from", lines_edited_args);
- SIGNAL_CHECK("text_changed", empty_signal_args);
- SIGNAL_CHECK("caret_changed", empty_signal_args);
- SIGNAL_CHECK_FALSE("text_set");
- text_edit->remove_secondary_carets();
- }
- SUBCASE("[TextEdit] swap lines") {
- lines_edited_args = build_array(build_array(0, 0), build_array(0, 1));
- text_edit->set_text("testing\nswap");
- MessageQueue::get_singleton()->flush();
- CHECK(text_edit->get_text() == "testing\nswap");
- SIGNAL_CHECK("text_set", empty_signal_args);
- SIGNAL_CHECK("lines_edited_from", lines_edited_args);
- SIGNAL_CHECK("caret_changed", empty_signal_args);
- SIGNAL_CHECK_FALSE("text_changed");
- text_edit->set_caret_column(text_edit->get_line(0).length());
- MessageQueue::get_singleton()->flush();
- SIGNAL_CHECK("caret_changed", empty_signal_args);
- // Emitted twice for each line.
- lines_edited_args = build_array(build_array(0, 0), build_array(0, 0), build_array(1, 1), build_array(1, 1));
- // Order does not matter. Works when not editable.
- text_edit->set_editable(false);
- text_edit->swap_lines(1, 0);
- MessageQueue::get_singleton()->flush();
- CHECK(text_edit->get_text() == "swap\ntesting");
- SIGNAL_CHECK("lines_edited_from", lines_edited_args);
- SIGNAL_CHECK("caret_changed", empty_signal_args);
- SIGNAL_CHECK("text_changed", empty_signal_args);
- SIGNAL_CHECK_FALSE("text_set");
- text_edit->set_editable(true);
- // Single undo/redo action.
- text_edit->undo();
- MessageQueue::get_singleton()->flush();
- CHECK(text_edit->get_text() == "testing\nswap");
- SIGNAL_CHECK("lines_edited_from", reverse_nested(lines_edited_args));
- SIGNAL_CHECK("caret_changed", empty_signal_args);
- SIGNAL_CHECK("text_changed", empty_signal_args);
- SIGNAL_CHECK_FALSE("text_set");
- text_edit->redo();
- MessageQueue::get_singleton()->flush();
- CHECK(text_edit->get_text() == "swap\ntesting");
- SIGNAL_CHECK("lines_edited_from", lines_edited_args);
- SIGNAL_CHECK("caret_changed", empty_signal_args);
- SIGNAL_CHECK("text_changed", empty_signal_args);
- SIGNAL_CHECK_FALSE("text_set");
- // Out of range.
- ERR_PRINT_OFF;
- text_edit->swap_lines(-1, 0);
- CHECK(text_edit->get_text() == "swap\ntesting");
- text_edit->swap_lines(0, -1);
- CHECK(text_edit->get_text() == "swap\ntesting");
- text_edit->swap_lines(2, 0);
- CHECK(text_edit->get_text() == "swap\ntesting");
- text_edit->swap_lines(0, 2);
- CHECK(text_edit->get_text() == "swap\ntesting");
- MessageQueue::get_singleton()->flush();
- SIGNAL_CHECK_FALSE("lines_edited_from");
- SIGNAL_CHECK_FALSE("caret_changed");
- SIGNAL_CHECK_FALSE("text_changed");
- SIGNAL_CHECK_FALSE("text_set");
- ERR_PRINT_ON;
- // Carets are also swapped.
- text_edit->set_caret_line(0);
- text_edit->set_caret_column(2);
- text_edit->select(0, 0, 0, 2);
- text_edit->add_caret(1, 6);
- MessageQueue::get_singleton()->flush();
- SIGNAL_DISCARD("caret_changed");
- lines_edited_args = build_array(build_array(1, 1), build_array(1, 1), build_array(0, 0), build_array(0, 0));
- text_edit->swap_lines(0, 1);
- MessageQueue::get_singleton()->flush();
- CHECK(text_edit->get_text() == "testing\nswap");
- CHECK(text_edit->get_caret_count() == 2);
- CHECK(text_edit->has_selection(0));
- CHECK(text_edit->get_caret_line(0) == 1);
- CHECK(text_edit->get_caret_column(0) == 2);
- CHECK(text_edit->get_selection_origin_line(0) == 1);
- CHECK(text_edit->get_selection_origin_column(0) == 0);
- CHECK_FALSE(text_edit->has_selection(1));
- CHECK(text_edit->get_caret_line(1) == 0);
- CHECK(text_edit->get_caret_column(1) == 6);
- SIGNAL_CHECK("lines_edited_from", lines_edited_args);
- SIGNAL_CHECK("caret_changed", empty_signal_args);
- SIGNAL_CHECK("text_changed", empty_signal_args);
- SIGNAL_CHECK_FALSE("text_set");
- text_edit->remove_secondary_carets();
- // Swap non adjacent lines.
- text_edit->insert_line_at(1, "new line");
- text_edit->set_caret_line(1);
- text_edit->set_caret_column(5);
- MessageQueue::get_singleton()->flush();
- CHECK(text_edit->get_text() == "testing\nnew line\nswap");
- SIGNAL_DISCARD("caret_changed");
- SIGNAL_DISCARD("lines_edited_from");
- SIGNAL_DISCARD("text_changed");
- lines_edited_args = build_array(build_array(2, 2), build_array(2, 2), build_array(0, 0), build_array(0, 0));
- text_edit->swap_lines(0, 2);
- MessageQueue::get_singleton()->flush();
- CHECK(text_edit->get_text() == "swap\nnew line\ntesting");
- CHECK(text_edit->get_caret_line() == 1);
- CHECK(text_edit->get_caret_column() == 5);
- SIGNAL_CHECK("lines_edited_from", lines_edited_args);
- SIGNAL_CHECK_FALSE("caret_changed");
- SIGNAL_CHECK("text_changed", empty_signal_args);
- SIGNAL_CHECK_FALSE("text_set");
- }
- SUBCASE("[TextEdit] insert line at") {
- lines_edited_args = build_array(build_array(0, 0), build_array(0, 1));
- text_edit->set_text("testing\nswap");
- MessageQueue::get_singleton()->flush();
- CHECK(text_edit->get_text() == "testing\nswap");
- SIGNAL_CHECK("text_set", empty_signal_args);
- SIGNAL_CHECK("lines_edited_from", lines_edited_args);
- SIGNAL_CHECK("caret_changed", empty_signal_args);
- SIGNAL_CHECK_FALSE("text_changed");
- text_edit->select_all();
- MessageQueue::get_singleton()->flush();
- CHECK(text_edit->has_selection());
- CHECK(text_edit->get_selection_from_line() == 0);
- CHECK(text_edit->get_selection_to_line() == 1);
- SIGNAL_CHECK("caret_changed", empty_signal_args);
- // Insert line at inserts a line before and moves caret and selection. Works when not editable.
- text_edit->set_editable(false);
- lines_edited_args = build_array(build_array(0, 1));
- text_edit->insert_line_at(0, "new");
- MessageQueue::get_singleton()->flush();
- CHECK(text_edit->get_text() == "new\ntesting\nswap");
- CHECK(text_edit->get_caret_line() == 2);
- CHECK(text_edit->get_caret_column() == text_edit->get_line(2).size() - 1);
- CHECK(text_edit->has_selection());
- CHECK(text_edit->get_selection_from_line() == 1);
- CHECK(text_edit->get_selection_from_column() == 0);
- CHECK(text_edit->get_selection_to_line() == 2);
- CHECK(text_edit->get_selection_to_column() == 4);
- SIGNAL_CHECK("lines_edited_from", lines_edited_args);
- SIGNAL_CHECK("caret_changed", empty_signal_args);
- SIGNAL_CHECK("text_changed", empty_signal_args);
- SIGNAL_CHECK_FALSE("text_set");
- text_edit->set_editable(true);
- // Can undo/redo as single action.
- text_edit->undo();
- MessageQueue::get_singleton()->flush();
- CHECK(text_edit->get_text() == "testing\nswap");
- CHECK(text_edit->has_selection());
- SIGNAL_CHECK("lines_edited_from", reverse_nested(lines_edited_args));
- SIGNAL_CHECK("caret_changed", empty_signal_args);
- SIGNAL_CHECK("text_changed", empty_signal_args);
- SIGNAL_CHECK_FALSE("text_set");
- text_edit->redo();
- MessageQueue::get_singleton()->flush();
- CHECK(text_edit->get_text() == "new\ntesting\nswap");
- CHECK(text_edit->has_selection());
- SIGNAL_CHECK("lines_edited_from", lines_edited_args);
- SIGNAL_CHECK("caret_changed", empty_signal_args);
- SIGNAL_CHECK("text_changed", empty_signal_args);
- SIGNAL_CHECK_FALSE("text_set");
- // Adding inside selection extends selection.
- text_edit->select_all();
- MessageQueue::get_singleton()->flush();
- CHECK(text_edit->has_selection());
- CHECK(text_edit->get_selection_from_line() == 0);
- CHECK(text_edit->get_selection_to_line() == 2);
- SIGNAL_CHECK_FALSE("caret_changed");
- lines_edited_args = build_array(build_array(2, 3));
- text_edit->insert_line_at(2, "after");
- MessageQueue::get_singleton()->flush();
- CHECK(text_edit->get_text() == "new\ntesting\nafter\nswap");
- CHECK(text_edit->get_caret_line() == 3);
- CHECK(text_edit->get_caret_column() == text_edit->get_line(3).size() - 1);
- CHECK(text_edit->has_selection());
- CHECK(text_edit->get_selection_from_line() == 0);
- CHECK(text_edit->get_selection_to_line() == 3);
- SIGNAL_CHECK("lines_edited_from", lines_edited_args);
- SIGNAL_CHECK("caret_changed", empty_signal_args);
- SIGNAL_CHECK("text_changed", empty_signal_args);
- SIGNAL_CHECK_FALSE("text_set");
- // Out of range.
- ERR_PRINT_OFF;
- text_edit->insert_line_at(-1, "after");
- CHECK(text_edit->get_text() == "new\ntesting\nafter\nswap");
- text_edit->insert_line_at(4, "after");
- CHECK(text_edit->get_text() == "new\ntesting\nafter\nswap");
- MessageQueue::get_singleton()->flush();
- SIGNAL_CHECK_FALSE("lines_edited_from");
- SIGNAL_CHECK_FALSE("caret_changed");
- SIGNAL_CHECK_FALSE("text_changed");
- SIGNAL_CHECK_FALSE("text_set");
- ERR_PRINT_ON;
- // Can insert multiple lines.
- text_edit->select(0, 1, 2, 2);
- MessageQueue::get_singleton()->flush();
- SIGNAL_DISCARD("caret_changed");
- lines_edited_args = build_array(build_array(2, 4));
- text_edit->insert_line_at(2, "multiple\nlines");
- MessageQueue::get_singleton()->flush();
- CHECK(text_edit->get_text() == "new\ntesting\nmultiple\nlines\nafter\nswap");
- CHECK(text_edit->has_selection());
- CHECK(text_edit->get_caret_line() == 4);
- CHECK(text_edit->get_caret_column() == 2);
- CHECK(text_edit->get_selection_origin_line() == 0);
- CHECK(text_edit->get_selection_origin_column() == 1);
- SIGNAL_CHECK("lines_edited_from", lines_edited_args);
- SIGNAL_CHECK("caret_changed", empty_signal_args);
- SIGNAL_CHECK("text_changed", empty_signal_args);
- SIGNAL_CHECK_FALSE("text_set");
- }
- SUBCASE("[TextEdit] remove line at") {
- lines_edited_args = build_array(build_array(0, 0), build_array(0, 5));
- text_edit->set_text("testing\nremove line at\n\tremove\nlines\n\ntest");
- MessageQueue::get_singleton()->flush();
- CHECK(text_edit->get_text() == "testing\nremove line at\n\tremove\nlines\n\ntest");
- SIGNAL_CHECK("text_set", empty_signal_args);
- SIGNAL_CHECK("lines_edited_from", lines_edited_args);
- SIGNAL_CHECK("caret_changed", empty_signal_args);
- SIGNAL_CHECK_FALSE("text_changed");
- // Remove line handles multiple carets.
- text_edit->set_caret_line(2);
- text_edit->set_caret_column(0);
- text_edit->add_caret(2, 7);
- text_edit->select(2, 1, 2, 7, 1);
- text_edit->add_caret(3, 1);
- text_edit->add_caret(4, 5);
- text_edit->add_caret(1, 5);
- MessageQueue::get_singleton()->flush();
- SIGNAL_DISCARD("caret_changed");
- lines_edited_args = build_array(build_array(3, 2));
- text_edit->remove_line_at(2, true);
- MessageQueue::get_singleton()->flush();
- CHECK(text_edit->get_text() == "testing\nremove line at\nlines\n\ntest");
- CHECK(text_edit->get_caret_count() == 5);
- CHECK_FALSE(text_edit->has_selection(0)); // Same line.
- CHECK(text_edit->get_caret_line(0) == 2);
- CHECK(text_edit->get_caret_column(0) == 0);
- CHECK(text_edit->has_selection(1)); // Same line, clamped.
- CHECK(text_edit->get_caret_line(1) == 2);
- CHECK(text_edit->get_caret_column(1) == 5);
- CHECK(text_edit->get_selection_origin_line(1) == 2);
- CHECK(text_edit->get_selection_origin_column(1) == 3); // In the default font, this is the same position.
- CHECK_FALSE(text_edit->has_selection(2)); // Moved up.
- CHECK(text_edit->get_caret_line(2) == 2);
- CHECK(text_edit->get_caret_column(2) == 1);
- CHECK_FALSE(text_edit->has_selection(3)); // Moved up.
- CHECK(text_edit->get_caret_line(3) == 3);
- CHECK(text_edit->get_caret_column(3) == 0);
- CHECK_FALSE(text_edit->has_selection(4)); // Didn't move.
- CHECK(text_edit->get_caret_line(4) == 1);
- CHECK(text_edit->get_caret_column(4) == 5);
- SIGNAL_CHECK("lines_edited_from", lines_edited_args);
- SIGNAL_CHECK("caret_changed", empty_signal_args);
- SIGNAL_CHECK("text_changed", empty_signal_args);
- SIGNAL_CHECK_FALSE("text_set");
- text_edit->remove_secondary_carets();
- // Remove first line.
- text_edit->set_caret_line(0);
- text_edit->set_caret_column(5);
- text_edit->add_caret(4, 4);
- MessageQueue::get_singleton()->flush();
- SIGNAL_DISCARD("caret_changed");
- lines_edited_args = build_array(build_array(1, 0));
- text_edit->remove_line_at(0, false);
- MessageQueue::get_singleton()->flush();
- CHECK(text_edit->get_text() == "remove line at\nlines\n\ntest");
- CHECK(text_edit->get_caret_count() == 2);
- CHECK(text_edit->get_caret_line(0) == 0);
- CHECK(text_edit->get_caret_column(0) == 0);
- CHECK(text_edit->get_caret_line(1) == 3);
- CHECK(text_edit->get_caret_column(1) == 4);
- SIGNAL_CHECK("lines_edited_from", lines_edited_args);
- SIGNAL_CHECK("caret_changed", empty_signal_args);
- SIGNAL_CHECK("text_changed", empty_signal_args);
- SIGNAL_CHECK_FALSE("text_set");
- text_edit->remove_secondary_carets();
- // Remove empty line.
- text_edit->set_caret_line(2);
- text_edit->set_caret_column(0);
- MessageQueue::get_singleton()->flush();
- SIGNAL_DISCARD("caret_changed");
- lines_edited_args = build_array(build_array(3, 2));
- text_edit->remove_line_at(2, false);
- MessageQueue::get_singleton()->flush();
- CHECK(text_edit->get_text() == "remove line at\nlines\ntest");
- CHECK(text_edit->get_caret_line(0) == 1);
- CHECK(text_edit->get_caret_column(0) == 0);
- SIGNAL_CHECK("lines_edited_from", lines_edited_args);
- SIGNAL_CHECK("caret_changed", empty_signal_args);
- SIGNAL_CHECK("text_changed", empty_signal_args);
- SIGNAL_CHECK_FALSE("text_set");
- // Remove last line.
- text_edit->set_caret_line(2);
- text_edit->set_caret_column(2);
- MessageQueue::get_singleton()->flush();
- SIGNAL_DISCARD("caret_changed");
- lines_edited_args = build_array(build_array(2, 1));
- text_edit->remove_line_at(2, true);
- MessageQueue::get_singleton()->flush();
- CHECK(text_edit->get_text() == "remove line at\nlines");
- CHECK(text_edit->get_caret_line(0) == 1);
- CHECK(text_edit->get_caret_column(0) == 5);
- SIGNAL_CHECK("lines_edited_from", lines_edited_args);
- SIGNAL_CHECK("caret_changed", empty_signal_args);
- SIGNAL_CHECK("text_changed", empty_signal_args);
- SIGNAL_CHECK_FALSE("text_set");
- // Out of bounds.
- text_edit->set_caret_line(0);
- text_edit->set_caret_column(2);
- MessageQueue::get_singleton()->flush();
- SIGNAL_DISCARD("caret_changed");
- ERR_PRINT_OFF
- text_edit->remove_line_at(2, true);
- ERR_PRINT_ON
- MessageQueue::get_singleton()->flush();
- CHECK(text_edit->get_text() == "remove line at\nlines");
- CHECK(text_edit->get_caret_line(0) == 0);
- CHECK(text_edit->get_caret_column(0) == 2);
- SIGNAL_CHECK_FALSE("lines_edited_from");
- SIGNAL_CHECK_FALSE("caret_changed");
- SIGNAL_CHECK_FALSE("text_changed");
- SIGNAL_CHECK_FALSE("text_set");
- // Remove regular line with move caret up and not editable.
- text_edit->set_editable(false);
- text_edit->set_caret_line(1);
- text_edit->set_caret_column(2);
- MessageQueue::get_singleton()->flush();
- SIGNAL_DISCARD("caret_changed");
- lines_edited_args = build_array(build_array(1, 0));
- text_edit->remove_line_at(1, false);
- MessageQueue::get_singleton()->flush();
- CHECK(text_edit->get_text() == "remove line at");
- CHECK(text_edit->get_caret_line(0) == 0);
- CHECK(text_edit->get_caret_column(0) == 1); // In the default font, this is the same position.
- SIGNAL_CHECK("lines_edited_from", lines_edited_args);
- SIGNAL_CHECK("caret_changed", empty_signal_args);
- SIGNAL_CHECK("text_changed", empty_signal_args);
- SIGNAL_CHECK_FALSE("text_set");
- text_edit->set_editable(true);
- // Undo.
- text_edit->undo();
- MessageQueue::get_singleton()->flush();
- CHECK(text_edit->get_text() == "remove line at\nlines");
- CHECK(text_edit->get_caret_line(0) == 1);
- CHECK(text_edit->get_caret_column(0) == 2);
- SIGNAL_CHECK("lines_edited_from", reverse_nested(lines_edited_args));
- SIGNAL_CHECK("caret_changed", empty_signal_args);
- SIGNAL_CHECK("text_changed", empty_signal_args);
- SIGNAL_CHECK_FALSE("text_set");
- // Redo.
- text_edit->redo();
- MessageQueue::get_singleton()->flush();
- CHECK(text_edit->get_text() == "remove line at");
- CHECK(text_edit->get_caret_line(0) == 0);
- CHECK(text_edit->get_caret_column(0) == 1);
- SIGNAL_CHECK("lines_edited_from", lines_edited_args);
- SIGNAL_CHECK("caret_changed", empty_signal_args);
- SIGNAL_CHECK("text_changed", empty_signal_args);
- SIGNAL_CHECK_FALSE("text_set");
- // Remove only line removes line content.
- text_edit->set_caret_line(0);
- text_edit->set_caret_column(10);
- MessageQueue::get_singleton()->flush();
- SIGNAL_DISCARD("caret_changed");
- lines_edited_args = build_array(build_array(0, 0));
- text_edit->remove_line_at(0);
- MessageQueue::get_singleton()->flush();
- CHECK(text_edit->get_text() == "");
- CHECK(text_edit->get_line_count() == 1);
- CHECK(text_edit->get_caret_line(0) == 0);
- CHECK(text_edit->get_caret_column(0) == 0);
- SIGNAL_CHECK("lines_edited_from", lines_edited_args);
- SIGNAL_CHECK("caret_changed", empty_signal_args);
- SIGNAL_CHECK("text_changed", empty_signal_args);
- SIGNAL_CHECK_FALSE("text_set");
- }
- SUBCASE("[TextEdit] insert text at caret") {
- lines_edited_args = build_array(build_array(0, 1));
- // Insert text at caret can insert multiple lines.
- text_edit->insert_text_at_caret("testing\nswap");
- MessageQueue::get_singleton()->flush();
- CHECK(text_edit->get_text() == "testing\nswap");
- CHECK(text_edit->get_caret_line() == 1);
- CHECK(text_edit->get_caret_column() == text_edit->get_line(1).size() - 1);
- SIGNAL_CHECK("lines_edited_from", lines_edited_args);
- SIGNAL_CHECK("text_changed", empty_signal_args);
- SIGNAL_CHECK("caret_changed", empty_signal_args);
- SIGNAL_CHECK_FALSE("text_set");
- // Text is inserted at caret.
- text_edit->set_caret_line(0, false);
- text_edit->set_caret_column(2);
- MessageQueue::get_singleton()->flush();
- SIGNAL_DISCARD("caret_changed");
- lines_edited_args = build_array(build_array(0, 0));
- text_edit->insert_text_at_caret("mid");
- MessageQueue::get_singleton()->flush();
- CHECK(text_edit->get_text() == "temidsting\nswap");
- CHECK(text_edit->get_caret_line() == 0);
- CHECK(text_edit->get_caret_column() == 5);
- SIGNAL_CHECK("lines_edited_from", lines_edited_args);
- SIGNAL_CHECK("text_changed", empty_signal_args);
- SIGNAL_CHECK("caret_changed", empty_signal_args);
- SIGNAL_CHECK_FALSE("text_set");
- // Selections are deleted then text is inserted. It also works even if not editable.
- text_edit->select(0, 0, 0, text_edit->get_line(0).length());
- CHECK(text_edit->has_selection());
- lines_edited_args = build_array(build_array(0, 0), build_array(0, 0));
- text_edit->set_editable(false);
- text_edit->insert_text_at_caret("new line");
- MessageQueue::get_singleton()->flush();
- CHECK(text_edit->get_text() == "new line\nswap");
- CHECK(text_edit->get_caret_line() == 0);
- CHECK(text_edit->get_caret_column() == text_edit->get_line(0).size() - 1);
- CHECK_FALSE(text_edit->has_selection());
- SIGNAL_CHECK("lines_edited_from", lines_edited_args);
- SIGNAL_CHECK("text_changed", empty_signal_args);
- SIGNAL_CHECK("caret_changed", empty_signal_args);
- SIGNAL_CHECK_FALSE("text_set");
- text_edit->set_editable(true);
- // Undo restores text and selection.
- text_edit->undo();
- MessageQueue::get_singleton()->flush();
- CHECK(text_edit->get_text() == "temidsting\nswap");
- CHECK(text_edit->get_caret_line() == 0);
- CHECK(text_edit->get_caret_column() == text_edit->get_line(0).length());
- CHECK(text_edit->has_selection());
- CHECK(text_edit->get_selection_origin_line() == 0);
- CHECK(text_edit->get_selection_origin_column() == 0);
- SIGNAL_CHECK("lines_edited_from", lines_edited_args);
- SIGNAL_CHECK("text_changed", empty_signal_args);
- SIGNAL_CHECK("caret_changed", empty_signal_args);
- SIGNAL_CHECK_FALSE("text_set");
- text_edit->redo();
- MessageQueue::get_singleton()->flush();
- CHECK(text_edit->get_text() == "new line\nswap");
- CHECK(text_edit->get_caret_line() == 0);
- CHECK(text_edit->get_caret_column() == 8);
- CHECK_FALSE(text_edit->has_selection());
- SIGNAL_CHECK("lines_edited_from", lines_edited_args);
- SIGNAL_CHECK("text_changed", empty_signal_args);
- SIGNAL_CHECK("caret_changed", empty_signal_args);
- SIGNAL_CHECK_FALSE("text_set");
- }
- SIGNAL_UNWATCH(text_edit, "text_set");
- SIGNAL_UNWATCH(text_edit, "text_changed");
- SIGNAL_UNWATCH(text_edit, "lines_edited_from");
- SIGNAL_UNWATCH(text_edit, "caret_changed");
- }
- SUBCASE("[TextEdit] indent level") {
- CHECK(text_edit->get_indent_level(0) == 0);
- CHECK(text_edit->get_first_non_whitespace_column(0) == 0);
- text_edit->set_line(0, "a");
- CHECK(text_edit->get_indent_level(0) == 0);
- CHECK(text_edit->get_first_non_whitespace_column(0) == 0);
- text_edit->set_line(0, "\t");
- CHECK(text_edit->get_indent_level(0) == 4);
- CHECK(text_edit->get_first_non_whitespace_column(0) == 1);
- text_edit->set_tab_size(8);
- CHECK(text_edit->get_indent_level(0) == 8);
- text_edit->set_line(0, "\t a");
- CHECK(text_edit->get_first_non_whitespace_column(0) == 2);
- CHECK(text_edit->get_indent_level(0) == 9);
- }
- SUBCASE("[TextEdit] selection") {
- SIGNAL_WATCH(text_edit, "text_set");
- SIGNAL_WATCH(text_edit, "text_changed");
- SIGNAL_WATCH(text_edit, "lines_edited_from");
- SIGNAL_WATCH(text_edit, "caret_changed");
- Array lines_edited_args = build_array(build_array(0, 0), build_array(0, 0));
- SUBCASE("[TextEdit] select all") {
- // Select when there is no text does not select.
- text_edit->select_all();
- CHECK_FALSE(text_edit->has_selection());
- CHECK(text_edit->get_selection_from_line() == 0);
- CHECK(text_edit->get_selection_from_column() == 0);
- CHECK(text_edit->get_selection_to_line() == 0);
- CHECK(text_edit->get_selection_to_column() == 0);
- CHECK(text_edit->get_selected_text() == "");
- // Select all selects all text.
- text_edit->set_text("test\nselection");
- SEND_GUI_ACTION("ui_text_select_all");
- CHECK(text_edit->get_viewport()->is_input_handled());
- MessageQueue::get_singleton()->flush();
- CHECK(text_edit->get_selected_text() == "test\nselection");
- CHECK(text_edit->has_selection());
- CHECK(text_edit->get_selection_from_line() == 0);
- CHECK(text_edit->get_selection_from_column() == 0);
- CHECK(text_edit->get_selection_to_line() == 1);
- CHECK(text_edit->get_selection_to_column() == 9);
- CHECK(text_edit->get_selection_mode() == TextEdit::SelectionMode::SELECTION_MODE_SHIFT);
- CHECK(text_edit->is_caret_after_selection_origin());
- CHECK(text_edit->get_caret_line() == 1);
- CHECK(text_edit->get_caret_column() == 9);
- SIGNAL_CHECK("caret_changed", empty_signal_args);
- // Cannot select when disabled.
- text_edit->set_caret_line(0);
- text_edit->set_caret_column(0);
- text_edit->set_selecting_enabled(false);
- CHECK_FALSE(text_edit->has_selection());
- CHECK(text_edit->get_selected_text() == "");
- CHECK(text_edit->get_caret_line() == 0);
- CHECK(text_edit->get_caret_column() == 0);
- text_edit->select_all();
- CHECK_FALSE(text_edit->has_selection());
- CHECK(text_edit->get_selected_text() == "");
- CHECK(text_edit->get_caret_line() == 0);
- CHECK(text_edit->get_caret_column() == 0);
- }
- SUBCASE("[TextEdit] select word under caret") {
- text_edit->set_text("\ntest test\ntest test");
- text_edit->set_caret_column(0);
- text_edit->set_caret_line(1);
- text_edit->add_caret(2, 0);
- text_edit->add_caret(2, 2);
- CHECK(text_edit->get_caret_count() == 3);
- MessageQueue::get_singleton()->flush();
- SIGNAL_DISCARD("text_set");
- SIGNAL_DISCARD("text_changed");
- SIGNAL_DISCARD("lines_edited_from");
- SIGNAL_DISCARD("caret_changed");
- // Select word under caret with multiple carets.
- text_edit->select_word_under_caret();
- CHECK(text_edit->has_selection(0));
- CHECK(text_edit->get_selected_text(0) == "test");
- CHECK(text_edit->get_selection_from_line(0) == 1);
- CHECK(text_edit->get_selection_from_column(0) == 0);
- CHECK(text_edit->get_selection_to_line(0) == 1);
- CHECK(text_edit->get_selection_to_column(0) == 4);
- CHECK(text_edit->get_caret_line(0) == 1);
- CHECK(text_edit->get_caret_column(0) == 4);
- CHECK(text_edit->has_selection(1));
- CHECK(text_edit->get_selected_text(1) == "test");
- CHECK(text_edit->get_selection_from_line(1) == 2);
- CHECK(text_edit->get_selection_from_column(1) == 0);
- CHECK(text_edit->get_selection_to_line(1) == 2);
- CHECK(text_edit->get_selection_to_column(1) == 4);
- CHECK(text_edit->get_caret_line(1) == 2);
- CHECK(text_edit->get_caret_column(1) == 4);
- CHECK(text_edit->get_caret_count() == 2);
- // Select word under caret disables selection if there is already a selection.
- text_edit->select_word_under_caret();
- CHECK_FALSE(text_edit->has_selection());
- CHECK(text_edit->get_selected_text() == "");
- SEND_GUI_ACTION("ui_text_select_word_under_caret");
- CHECK(text_edit->get_viewport()->is_input_handled());
- MessageQueue::get_singleton()->flush();
- CHECK(text_edit->has_selection(0));
- CHECK(text_edit->get_selected_text(0) == "test");
- CHECK(text_edit->get_selection_from_line(0) == 1);
- CHECK(text_edit->get_selection_from_column(0) == 0);
- CHECK(text_edit->get_selection_to_line(0) == 1);
- CHECK(text_edit->get_selection_to_column(0) == 4);
- CHECK(text_edit->get_caret_line(0) == 1);
- CHECK(text_edit->get_caret_column(0) == 4);
- CHECK(text_edit->has_selection(1));
- CHECK(text_edit->get_selected_text(1) == "test");
- CHECK(text_edit->get_selection_from_line(1) == 2);
- CHECK(text_edit->get_selection_from_column(1) == 0);
- CHECK(text_edit->get_selection_to_line(1) == 2);
- CHECK(text_edit->get_selection_to_column(1) == 4);
- CHECK(text_edit->get_caret_line(1) == 2);
- CHECK(text_edit->get_caret_column(1) == 4);
- CHECK(text_edit->get_selected_text() == "test\ntest");
- SIGNAL_CHECK("caret_changed", empty_signal_args);
- // Cannot select when disabled.
- text_edit->set_selecting_enabled(false);
- text_edit->select_word_under_caret();
- CHECK_FALSE(text_edit->has_selection());
- CHECK(text_edit->get_selected_text() == "");
- CHECK(text_edit->get_caret_line(0) == 1);
- CHECK(text_edit->get_caret_column(0) == 4);
- CHECK(text_edit->get_caret_line(1) == 2);
- CHECK(text_edit->get_caret_column(1) == 4);
- SIGNAL_CHECK_FALSE("caret_changed");
- text_edit->set_selecting_enabled(true);
- // Select word under caret when there is no word does not select.
- text_edit->set_caret_line(1, false, true, -1, 0);
- text_edit->set_caret_column(5, false, 0);
- text_edit->set_caret_line(2, false, true, -1, 1);
- text_edit->set_caret_column(5, false, 1);
- text_edit->select_word_under_caret();
- CHECK_FALSE(text_edit->has_selection());
- CHECK(text_edit->get_selected_text() == "");
- text_edit->select_word_under_caret();
- CHECK_FALSE(text_edit->has_selection());
- CHECK(text_edit->get_selected_text() == "");
- CHECK(text_edit->get_caret_line(0) == 1);
- CHECK(text_edit->get_caret_column(0) == 5);
- CHECK(text_edit->get_caret_line(1) == 2);
- CHECK(text_edit->get_caret_column(1) == 5);
- SIGNAL_CHECK_FALSE("caret_changed");
- }
- SUBCASE("[TextEdit] add selection for next occurrence") {
- text_edit->set_text("\ntest other_test\nrandom test\nword test word nonrandom");
- text_edit->set_caret_column(0);
- text_edit->set_caret_line(1);
- // First selection made by the implicit select_word_under_caret call.
- text_edit->add_selection_for_next_occurrence();
- CHECK(text_edit->get_caret_count() == 1);
- CHECK(text_edit->get_selected_text(0) == "test");
- CHECK(text_edit->get_selection_from_line(0) == 1);
- CHECK(text_edit->get_selection_from_column(0) == 0);
- CHECK(text_edit->get_selection_to_line(0) == 1);
- CHECK(text_edit->get_selection_to_column(0) == 4);
- CHECK(text_edit->get_caret_line(0) == 1);
- CHECK(text_edit->get_caret_column(0) == 4);
- text_edit->add_selection_for_next_occurrence();
- CHECK(text_edit->get_caret_count() == 2);
- CHECK(text_edit->get_selected_text(1) == "test");
- CHECK(text_edit->get_selection_from_line(1) == 1);
- CHECK(text_edit->get_selection_from_column(1) == 13);
- CHECK(text_edit->get_selection_to_line(1) == 1);
- CHECK(text_edit->get_selection_to_column(1) == 17);
- CHECK(text_edit->get_caret_line(1) == 1);
- CHECK(text_edit->get_caret_column(1) == 17);
- text_edit->add_selection_for_next_occurrence();
- CHECK(text_edit->get_caret_count() == 3);
- CHECK(text_edit->get_selected_text(2) == "test");
- CHECK(text_edit->get_selection_from_line(2) == 2);
- CHECK(text_edit->get_selection_from_column(2) == 9);
- CHECK(text_edit->get_selection_to_line(2) == 2);
- CHECK(text_edit->get_selection_to_column(2) == 13);
- CHECK(text_edit->get_caret_line(2) == 2);
- CHECK(text_edit->get_caret_column(2) == 13);
- text_edit->add_selection_for_next_occurrence();
- CHECK(text_edit->get_caret_count() == 4);
- CHECK(text_edit->get_selected_text(3) == "test");
- CHECK(text_edit->get_selection_from_line(3) == 3);
- CHECK(text_edit->get_selection_from_column(3) == 5);
- CHECK(text_edit->get_selection_to_line(3) == 3);
- CHECK(text_edit->get_selection_to_column(3) == 9);
- CHECK(text_edit->get_caret_line(3) == 3);
- CHECK(text_edit->get_caret_column(3) == 9);
- // A different word with a new manually added caret.
- text_edit->add_caret(2, 1);
- text_edit->select(2, 0, 2, 4, 4);
- CHECK(text_edit->get_selected_text(4) == "rand");
- text_edit->add_selection_for_next_occurrence();
- CHECK(text_edit->get_caret_count() == 6);
- CHECK(text_edit->get_selected_text(5) == "rand");
- CHECK(text_edit->get_selection_from_line(5) == 3);
- CHECK(text_edit->get_selection_from_column(5) == 18);
- CHECK(text_edit->get_selection_to_line(5) == 3);
- CHECK(text_edit->get_selection_to_column(5) == 22);
- CHECK(text_edit->get_caret_line(5) == 3);
- CHECK(text_edit->get_caret_column(5) == 22);
- // Make sure the previous selections are still active.
- CHECK(text_edit->get_selected_text(0) == "test");
- CHECK(text_edit->get_selected_text(1) == "test");
- CHECK(text_edit->get_selected_text(2) == "test");
- CHECK(text_edit->get_selected_text(3) == "test");
- }
- SUBCASE("[TextEdit] skip selection for next occurrence") {
- text_edit->set_text("\ntest other_test\nrandom test\nword test word nonrandom");
- text_edit->set_caret_column(0);
- text_edit->set_caret_line(1);
- // Without selection on the current caret, the caret as 'jumped' to the next occurrence of the word under the caret.
- text_edit->skip_selection_for_next_occurrence();
- CHECK(text_edit->get_caret_count() == 1);
- CHECK_FALSE(text_edit->has_selection(0));
- CHECK(text_edit->get_caret_line(0) == 1);
- CHECK(text_edit->get_caret_column(0) == 13);
- // Repeating previous action.
- // This time caret is in 'other_test' (other_|test)
- // so the searched term will be 'other_test' or not just 'test'
- // => no occurrence, as a side effect, the caret will move to start of the term.
- text_edit->skip_selection_for_next_occurrence();
- CHECK(text_edit->get_caret_count() == 1);
- CHECK_FALSE(text_edit->has_selection(0));
- CHECK(text_edit->get_caret_line(0) == 1);
- CHECK(text_edit->get_caret_column(0) == 7);
- // Repeating action again should do nothing now
- text_edit->skip_selection_for_next_occurrence();
- CHECK(text_edit->get_caret_count() == 1);
- CHECK_FALSE(text_edit->has_selection(0));
- CHECK(text_edit->get_caret_line(0) == 1);
- CHECK(text_edit->get_caret_column(0) == 7);
- // Moving back to the first 'test' occurrence.
- text_edit->set_caret_column(0);
- text_edit->set_caret_line(1);
- // But this time, create a selection of it.
- text_edit->add_selection_for_next_occurrence();
- CHECK(text_edit->get_caret_count() == 1);
- CHECK(text_edit->has_selection(0));
- CHECK(text_edit->get_selected_text(0) == "test");
- CHECK(text_edit->get_selection_from_line(0) == 1);
- CHECK(text_edit->get_selection_from_column(0) == 0);
- CHECK(text_edit->get_selection_to_line(0) == 1);
- CHECK(text_edit->get_selection_to_column(0) == 4);
- CHECK(text_edit->get_caret_line(0) == 1);
- CHECK(text_edit->get_caret_column(0) == 4);
- // Then, skipping it, but this time, selection has been made on the next occurrence.
- text_edit->skip_selection_for_next_occurrence();
- CHECK(text_edit->get_caret_count() == 1);
- CHECK(text_edit->has_selection(0));
- CHECK(text_edit->get_selected_text(0) == "test");
- CHECK(text_edit->get_selection_from_line(0) == 1);
- CHECK(text_edit->get_selection_from_column(0) == 13);
- CHECK(text_edit->get_selection_to_line(0) == 1);
- CHECK(text_edit->get_selection_to_column(0) == 17);
- CHECK(text_edit->get_caret_line(0) == 1);
- CHECK(text_edit->get_caret_column(0) == 17);
- text_edit->skip_selection_for_next_occurrence();
- CHECK(text_edit->get_caret_count() == 1);
- CHECK(text_edit->has_selection(0));
- CHECK(text_edit->get_selected_text(0) == "test");
- CHECK(text_edit->get_selection_from_line(0) == 2);
- CHECK(text_edit->get_selection_from_column(0) == 9);
- CHECK(text_edit->get_selection_to_line(0) == 2);
- CHECK(text_edit->get_selection_to_column(0) == 13);
- CHECK(text_edit->get_caret_line(0) == 2);
- CHECK(text_edit->get_caret_column(0) == 13);
- text_edit->skip_selection_for_next_occurrence();
- CHECK(text_edit->get_caret_count() == 1);
- CHECK(text_edit->has_selection(0));
- CHECK(text_edit->get_selected_text(0) == "test");
- CHECK(text_edit->get_selection_from_line(0) == 3);
- CHECK(text_edit->get_selection_from_column(0) == 5);
- CHECK(text_edit->get_selection_to_line(0) == 3);
- CHECK(text_edit->get_selection_to_column(0) == 9);
- CHECK(text_edit->get_caret_line(0) == 3);
- CHECK(text_edit->get_caret_column(0) == 9);
- // Last skip, we are back to the first occurrence.
- text_edit->skip_selection_for_next_occurrence();
- CHECK(text_edit->has_selection(0));
- CHECK(text_edit->get_selected_text(0) == "test");
- CHECK(text_edit->get_selection_from_line(0) == 1);
- CHECK(text_edit->get_selection_from_column(0) == 0);
- CHECK(text_edit->get_selection_to_line(0) == 1);
- CHECK(text_edit->get_selection_to_column(0) == 4);
- CHECK(text_edit->get_caret_line(0) == 1);
- CHECK(text_edit->get_caret_column(0) == 4);
- // Adding first occurrence to selections/carets list
- // and select occurrence on 'other_test'.
- text_edit->add_selection_for_next_occurrence();
- CHECK(text_edit->get_caret_count() == 2);
- CHECK(text_edit->has_selection(0));
- CHECK(text_edit->get_selected_text(0) == "test");
- CHECK(text_edit->has_selection(1));
- CHECK(text_edit->get_selected_text(1) == "test");
- CHECK(text_edit->get_selection_from_line(1) == 1);
- CHECK(text_edit->get_selection_from_column(1) == 13);
- CHECK(text_edit->get_selection_to_line(1) == 1);
- CHECK(text_edit->get_selection_to_column(1) == 17);
- CHECK(text_edit->get_caret_line(1) == 1);
- CHECK(text_edit->get_caret_column(1) == 17);
- // We don't want this occurrence.
- // Let's skip it.
- text_edit->skip_selection_for_next_occurrence();
- CHECK(text_edit->get_caret_count() == 2);
- CHECK(text_edit->has_selection(0));
- CHECK(text_edit->get_selected_text(0) == "test");
- CHECK(text_edit->get_selected_text(1) == "test");
- CHECK(text_edit->get_selection_from_line(1) == 2);
- CHECK(text_edit->get_selection_from_column(1) == 9);
- CHECK(text_edit->get_selection_to_line(1) == 2);
- CHECK(text_edit->get_selection_to_column(1) == 13);
- CHECK(text_edit->get_caret_line(1) == 2);
- CHECK(text_edit->get_caret_column(1) == 13);
- text_edit->skip_selection_for_next_occurrence();
- CHECK(text_edit->get_caret_count() == 2);
- CHECK(text_edit->has_selection(0));
- CHECK(text_edit->get_selected_text(0) == "test");
- CHECK(text_edit->get_selected_text(1) == "test");
- CHECK(text_edit->get_selection_from_line(1) == 3);
- CHECK(text_edit->get_selection_from_column(1) == 5);
- CHECK(text_edit->get_selection_to_line(1) == 3);
- CHECK(text_edit->get_selection_to_column(1) == 9);
- CHECK(text_edit->get_caret_line(1) == 3);
- CHECK(text_edit->get_caret_column(1) == 9);
- // We are back the first occurrence.
- text_edit->skip_selection_for_next_occurrence();
- CHECK(text_edit->get_caret_count() == 1);
- CHECK(text_edit->has_selection(0));
- CHECK(text_edit->get_selected_text(0) == "test");
- CHECK(text_edit->get_selection_from_line(0) == 1);
- CHECK(text_edit->get_selection_from_column(0) == 0);
- CHECK(text_edit->get_selection_to_line(0) == 1);
- CHECK(text_edit->get_selection_to_column(0) == 4);
- CHECK(text_edit->get_caret_line(0) == 1);
- CHECK(text_edit->get_caret_column(0) == 4);
- }
- SUBCASE("[TextEdit] deselect on focus loss") {
- text_edit->set_text("test");
- text_edit->set_deselect_on_focus_loss_enabled(true);
- CHECK(text_edit->is_deselect_on_focus_loss_enabled());
- text_edit->grab_focus();
- text_edit->select_all();
- CHECK(text_edit->has_focus());
- CHECK(text_edit->has_selection());
- text_edit->release_focus();
- CHECK_FALSE(text_edit->has_focus());
- CHECK_FALSE(text_edit->has_selection());
- text_edit->set_deselect_on_focus_loss_enabled(false);
- CHECK_FALSE(text_edit->is_deselect_on_focus_loss_enabled());
- text_edit->grab_focus();
- text_edit->select_all();
- CHECK(text_edit->has_focus());
- CHECK(text_edit->has_selection());
- text_edit->release_focus();
- CHECK_FALSE(text_edit->has_focus());
- CHECK(text_edit->has_selection());
- text_edit->set_deselect_on_focus_loss_enabled(true);
- CHECK_FALSE(text_edit->has_selection());
- }
- SUBCASE("[TextEdit] key select") {
- text_edit->set_text("test");
- text_edit->grab_focus();
- SEND_GUI_KEY_EVENT(Key::RIGHT | KeyModifierMask::SHIFT)
- CHECK(text_edit->has_selection());
- CHECK(text_edit->get_selected_text() == "t");
- CHECK(text_edit->is_caret_after_selection_origin());
- #ifdef MACOS_ENABLED
- SEND_GUI_KEY_EVENT(Key::RIGHT | KeyModifierMask::SHIFT | KeyModifierMask::ALT)
- #else
- SEND_GUI_KEY_EVENT(Key::RIGHT | KeyModifierMask::SHIFT | KeyModifierMask::CMD_OR_CTRL)
- #endif
- CHECK(text_edit->has_selection());
- CHECK(text_edit->get_selected_text() == "test");
- CHECK(text_edit->is_caret_after_selection_origin());
- SEND_GUI_KEY_EVENT(Key::LEFT | KeyModifierMask::SHIFT)
- CHECK(text_edit->has_selection());
- CHECK(text_edit->get_selected_text() == "tes");
- CHECK(text_edit->is_caret_after_selection_origin());
- #ifdef MACOS_ENABLED
- SEND_GUI_KEY_EVENT(Key::LEFT | KeyModifierMask::SHIFT | KeyModifierMask::ALT)
- #else
- SEND_GUI_KEY_EVENT(Key::LEFT | KeyModifierMask::SHIFT | KeyModifierMask::CMD_OR_CTRL)
- #endif
- CHECK_FALSE(text_edit->has_selection());
- CHECK(text_edit->get_selected_text() == "");
- SEND_GUI_KEY_EVENT(Key::RIGHT | KeyModifierMask::SHIFT)
- CHECK(text_edit->has_selection());
- CHECK(text_edit->get_selected_text() == "t");
- SEND_GUI_KEY_EVENT(Key::RIGHT)
- CHECK_FALSE(text_edit->has_selection());
- CHECK(text_edit->get_selected_text() == "");
- SEND_GUI_KEY_EVENT(Key::LEFT | KeyModifierMask::SHIFT)
- CHECK(text_edit->has_selection());
- CHECK(text_edit->get_selected_text() == "t");
- CHECK_FALSE(text_edit->is_caret_after_selection_origin());
- SEND_GUI_KEY_EVENT(Key::LEFT)
- CHECK_FALSE(text_edit->has_selection());
- CHECK(text_edit->get_selected_text() == "");
- // Cannot select when disabled.
- text_edit->set_selecting_enabled(false);
- SEND_GUI_KEY_EVENT(Key::RIGHT | KeyModifierMask::SHIFT)
- CHECK_FALSE(text_edit->has_selection());
- CHECK(text_edit->get_selected_text() == "");
- text_edit->set_selecting_enabled(true);
- }
- SUBCASE("[TextEdit] mouse drag select") {
- // Set size for mouse input.
- text_edit->set_size(Size2(200, 200));
- text_edit->set_text("this is some text\nfor selection");
- text_edit->grab_focus();
- MessageQueue::get_singleton()->flush();
- // Click and drag to make a selection.
- SEND_GUI_MOUSE_BUTTON_EVENT(text_edit->get_rect_at_line_column(1, 0).get_center(), MouseButton::LEFT, MouseButtonMask::LEFT, Key::NONE);
- // Add (2,0) to bring it past the center point of the grapheme and account for integer division flooring.
- SEND_GUI_MOUSE_MOTION_EVENT(text_edit->get_rect_at_line_column(1, 5).get_center() + Point2i(2, 0), MouseButtonMask::LEFT, Key::NONE);
- CHECK(text_edit->has_selection());
- CHECK(text_edit->get_selected_text() == "for s");
- CHECK(text_edit->get_selection_mode() == TextEdit::SELECTION_MODE_POINTER);
- CHECK(text_edit->get_selection_origin_line() == 1);
- CHECK(text_edit->get_selection_origin_column() == 0);
- CHECK(text_edit->get_caret_line() == 1);
- CHECK(text_edit->get_caret_column() == 5);
- CHECK(text_edit->is_caret_after_selection_origin());
- CHECK(text_edit->is_dragging_cursor());
- // Releasing finishes.
- 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);
- CHECK(text_edit->has_selection());
- CHECK(text_edit->get_selected_text() == "for s");
- SEND_GUI_MOUSE_MOTION_EVENT(text_edit->get_rect_at_line_column(1, 9).get_center() + Point2i(2, 0), MouseButtonMask::NONE, Key::NONE);
- CHECK(text_edit->has_selection());
- CHECK(text_edit->get_selected_text() == "for s");
- CHECK(text_edit->get_selection_origin_line() == 1);
- CHECK(text_edit->get_selection_origin_column() == 0);
- CHECK(text_edit->get_caret_line() == 1);
- CHECK(text_edit->get_caret_column() == 5);
- CHECK(text_edit->is_caret_after_selection_origin());
- // Clicking clears selection.
- 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);
- CHECK_FALSE(text_edit->has_selection());
- CHECK(text_edit->get_caret_line() == 0);
- CHECK(text_edit->get_caret_column() == 7);
- // Cannot select when disabled, but caret still moves.
- text_edit->set_selecting_enabled(false);
- SEND_GUI_MOUSE_BUTTON_EVENT(text_edit->get_rect_at_line_column(1, 0).get_center(), MouseButton::LEFT, MouseButtonMask::LEFT, Key::NONE);
- CHECK(text_edit->get_caret_line() == 1);
- CHECK(text_edit->get_caret_column() == 0);
- SEND_GUI_MOUSE_MOTION_EVENT(text_edit->get_rect_at_line_column(1, 5).get_center() + Point2i(2, 0), MouseButtonMask::LEFT, Key::NONE);
- CHECK_FALSE(text_edit->has_selection());
- CHECK(text_edit->get_caret_line() == 1);
- CHECK(text_edit->get_caret_column() == 5);
- text_edit->set_selecting_enabled(true);
- // Only last caret is moved when adding a selection.
- text_edit->set_caret_line(0);
- text_edit->set_caret_column(4);
- text_edit->add_caret(0, 15);
- text_edit->select(0, 11, 0, 15, 1);
- MessageQueue::get_singleton()->flush();
- 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);
- SEND_GUI_MOUSE_MOTION_EVENT(text_edit->get_rect_at_line_column(1, 0).get_center(), MouseButtonMask::LEFT, Key::NONE);
- CHECK(text_edit->get_caret_count() == 3);
- CHECK(text_edit->get_selection_mode() == TextEdit::SELECTION_MODE_POINTER);
- CHECK_FALSE(text_edit->has_selection(0));
- CHECK(text_edit->get_caret_line(0) == 0);
- CHECK(text_edit->get_caret_column(0) == 4);
- CHECK(text_edit->has_selection(1));
- CHECK(text_edit->get_selection_origin_line(1) == 0);
- CHECK(text_edit->get_selection_origin_column(1) == 11);
- CHECK(text_edit->get_caret_line(1) == 0);
- CHECK(text_edit->get_caret_column(1) == 15);
- CHECK(text_edit->has_selection(2));
- CHECK(text_edit->get_selected_text(2) == "for s");
- CHECK(text_edit->get_selection_origin_line(2) == 1);
- CHECK(text_edit->get_selection_origin_column(2) == 5);
- CHECK(text_edit->get_caret_line(2) == 1);
- CHECK(text_edit->get_caret_column(2) == 0);
- CHECK_FALSE(text_edit->is_caret_after_selection_origin(2));
- // Overlapping carets and selections merges them.
- SEND_GUI_MOUSE_MOTION_EVENT(text_edit->get_rect_at_line_column(0, 3).get_center() + Point2i(2, 0), MouseButtonMask::LEFT, Key::NONE);
- CHECK(text_edit->get_caret_count() == 1);
- CHECK(text_edit->has_selection());
- CHECK(text_edit->get_selected_text() == "s is some text\nfor s");
- CHECK(text_edit->get_selection_mode() == TextEdit::SELECTION_MODE_POINTER);
- CHECK(text_edit->get_selection_origin_line() == 1);
- CHECK(text_edit->get_selection_origin_column() == 5);
- CHECK(text_edit->get_caret_line() == 0);
- CHECK(text_edit->get_caret_column() == 3);
- CHECK_FALSE(text_edit->is_caret_after_selection_origin());
- // Entering text stops selecting.
- text_edit->insert_text_at_caret("a");
- CHECK_FALSE(text_edit->has_selection());
- CHECK(text_edit->get_text() == "thiaelection");
- CHECK(text_edit->get_caret_line() == 0);
- CHECK(text_edit->get_caret_column() == 4);
- SEND_GUI_MOUSE_MOTION_EVENT(text_edit->get_rect_at_line_column(0, 10).get_center() + Point2i(2, 0), MouseButtonMask::NONE, Key::NONE);
- CHECK_FALSE(text_edit->has_selection());
- CHECK(text_edit->get_caret_line() == 0);
- CHECK(text_edit->get_caret_column() == 4);
- // Wrapped lines.
- text_edit->set_line_wrapping_mode(TextEdit::LineWrappingMode::LINE_WRAPPING_BOUNDARY);
- text_edit->set_text("this is some text\nfor selection");
- text_edit->set_size(Size2(110, 100));
- MessageQueue::get_singleton()->flush();
- // Line 0 wraps: 'this is ', 'some text'.
- // Line 1 wraps: 'for ', 'selection'.
- CHECK(text_edit->is_line_wrapped(0));
- // Select to the first character of a wrapped line.
- SEND_GUI_MOUSE_BUTTON_EVENT(text_edit->get_rect_at_line_column(0, 11).get_center(), MouseButton::LEFT, MouseButtonMask::LEFT, Key::NONE);
- SEND_GUI_MOUSE_MOTION_EVENT(text_edit->get_rect_at_line_column(0, 8).get_center(), MouseButtonMask::LEFT, Key::NONE);
- CHECK(text_edit->has_selection());
- CHECK(text_edit->get_selected_text() == "so");
- CHECK(text_edit->get_selection_mode() == TextEdit::SELECTION_MODE_POINTER);
- CHECK(text_edit->get_selection_origin_line() == 0);
- CHECK(text_edit->get_selection_origin_column() == 10);
- CHECK(text_edit->get_caret_line() == 0);
- CHECK(text_edit->get_caret_column() == 8);
- CHECK(text_edit->is_dragging_cursor());
- }
- SUBCASE("[TextEdit] mouse word select") {
- // Set size for mouse input.
- text_edit->set_size(Size2(200, 200));
- text_edit->set_text("this is some text\nfor selection\n");
- MessageQueue::get_singleton()->flush();
- SIGNAL_DISCARD("caret_changed");
- // Double click to select word.
- SEND_GUI_DOUBLE_CLICK(text_edit->get_rect_at_line_column(1, 2).get_center() + Point2i(2, 0), Key::NONE);
- CHECK(text_edit->has_selection());
- CHECK(text_edit->get_selected_text() == "for");
- CHECK(text_edit->get_selection_mode() == TextEdit::SELECTION_MODE_WORD);
- CHECK(text_edit->get_selection_from_line() == 1);
- CHECK(text_edit->get_selection_from_column() == 0);
- CHECK(text_edit->get_selection_to_line() == 1);
- CHECK(text_edit->get_selection_to_column() == 3);
- CHECK(text_edit->get_caret_line() == 1);
- CHECK(text_edit->get_caret_column() == 3);
- CHECK(text_edit->is_caret_after_selection_origin());
- SIGNAL_CHECK("caret_changed", empty_signal_args);
- // Moving mouse selects entire words at a time.
- SEND_GUI_MOUSE_MOTION_EVENT(text_edit->get_rect_at_line_column(1, 6).get_center() + Point2i(2, 0), MouseButtonMask::LEFT, Key::NONE);
- CHECK(text_edit->has_selection());
- CHECK(text_edit->get_selected_text() == "for selection");
- CHECK(text_edit->get_selection_mode() == TextEdit::SELECTION_MODE_WORD);
- CHECK(text_edit->get_selection_from_line() == 1);
- CHECK(text_edit->get_selection_from_column() == 0);
- CHECK(text_edit->get_selection_to_line() == 1);
- CHECK(text_edit->get_selection_to_column() == 13);
- CHECK(text_edit->get_caret_line() == 1);
- CHECK(text_edit->get_caret_column() == 13);
- CHECK(text_edit->is_caret_after_selection_origin());
- CHECK(text_edit->is_dragging_cursor());
- SIGNAL_CHECK("caret_changed", empty_signal_args);
- // Moving to a word before the initial selected word reverses selection direction and keeps the initial word selected.
- SEND_GUI_MOUSE_MOTION_EVENT(text_edit->get_rect_at_line_column(0, 10).get_center(), MouseButtonMask::LEFT, Key::NONE);
- CHECK(text_edit->has_selection());
- CHECK(text_edit->get_selected_text() == "some text\nfor");
- CHECK(text_edit->get_selection_mode() == TextEdit::SELECTION_MODE_WORD);
- CHECK(text_edit->get_selection_from_line() == 0);
- CHECK(text_edit->get_selection_from_column() == 8);
- CHECK(text_edit->get_selection_to_line() == 1);
- CHECK(text_edit->get_selection_to_column() == 3);
- CHECK(text_edit->get_caret_line() == 0);
- CHECK(text_edit->get_caret_column() == 8);
- CHECK_FALSE(text_edit->is_caret_after_selection_origin());
- SIGNAL_CHECK("caret_changed", empty_signal_args);
- // Releasing finishes.
- SEND_GUI_MOUSE_BUTTON_RELEASED_EVENT(text_edit->get_rect_at_line_column(0, 10).get_center(), MouseButton::LEFT, MouseButtonMask::LEFT, Key::NONE);
- CHECK(text_edit->has_selection());
- CHECK(text_edit->get_selected_text() == "some text\nfor");
- SEND_GUI_MOUSE_MOTION_EVENT(text_edit->get_rect_at_line_column(1, 2).get_center(), MouseButtonMask::NONE, Key::NONE);
- CHECK(text_edit->has_selection());
- CHECK(text_edit->get_selected_text() == "some text\nfor");
- text_edit->deselect();
- // Can start word select mode on an empty line.
- SEND_GUI_DOUBLE_CLICK(text_edit->get_rect_at_line_column(2, 0).get_center() + Point2i(2, 0), Key::NONE);
- CHECK_FALSE(text_edit->has_selection());
- CHECK(text_edit->get_selection_mode() == TextEdit::SELECTION_MODE_WORD);
- CHECK(text_edit->get_caret_line() == 2);
- CHECK(text_edit->get_caret_column() == 0);
- SEND_GUI_MOUSE_MOTION_EVENT(text_edit->get_rect_at_line_column(1, 9).get_center(), MouseButtonMask::LEFT, Key::NONE);
- CHECK(text_edit->has_selection());
- CHECK(text_edit->get_selected_text() == "selection\n");
- CHECK(text_edit->get_selection_mode() == TextEdit::SELECTION_MODE_WORD);
- CHECK(text_edit->get_caret_line() == 1);
- CHECK(text_edit->get_caret_column() == 4);
- CHECK(text_edit->get_selection_origin_line() == 2);
- CHECK(text_edit->get_selection_origin_column() == 0);
- // Clicking clears selection.
- SEND_GUI_MOUSE_BUTTON_EVENT(text_edit->get_rect_at_line_column(0, 0).get_center(), MouseButton::LEFT, MouseButtonMask::LEFT, Key::NONE);
- CHECK_FALSE(text_edit->has_selection());
- CHECK(text_edit->get_caret_line() == 0);
- CHECK(text_edit->get_caret_column() == 0);
- // Can start word select mode when not on a word.
- SEND_GUI_DOUBLE_CLICK(text_edit->get_rect_at_line_column(0, 12).get_center() + Point2i(2, 0), Key::NONE);
- CHECK(text_edit->get_selection_mode() == TextEdit::SELECTION_MODE_WORD);
- CHECK_FALSE(text_edit->has_selection());
- CHECK(text_edit->get_caret_line() == 0);
- CHECK(text_edit->get_caret_column() == 12);
- SEND_GUI_MOUSE_MOTION_EVENT(text_edit->get_rect_at_line_column(1, 9).get_center(), MouseButtonMask::LEFT, Key::NONE);
- CHECK(text_edit->get_selection_mode() == TextEdit::SELECTION_MODE_WORD);
- CHECK(text_edit->has_selection());
- CHECK(text_edit->get_selected_text() == " text\nfor selection");
- CHECK(text_edit->get_caret_line() == 1);
- CHECK(text_edit->get_caret_column() == 13);
- CHECK(text_edit->get_selection_origin_line() == 0);
- CHECK(text_edit->get_selection_origin_column() == 12);
- SEND_GUI_MOUSE_MOTION_EVENT(text_edit->get_rect_at_line_column(0, 10).get_center(), MouseButtonMask::LEFT, Key::NONE);
- CHECK(text_edit->get_selection_mode() == TextEdit::SELECTION_MODE_WORD);
- CHECK(text_edit->has_selection());
- CHECK(text_edit->get_selected_text() == "some");
- CHECK(text_edit->get_caret_line() == 0);
- CHECK(text_edit->get_caret_column() == 8);
- CHECK(text_edit->get_selection_origin_line() == 0);
- CHECK(text_edit->get_selection_origin_column() == 12);
- SEND_GUI_MOUSE_BUTTON_RELEASED_EVENT(text_edit->get_rect_at_line_column(0, 15).get_center(), MouseButton::LEFT, MouseButtonMask::LEFT, Key::NONE);
- // Add a new selection without affecting the old one.
- 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);
- 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);
- CHECK(text_edit->get_selection_mode() == TextEdit::SELECTION_MODE_POINTER);
- CHECK(text_edit->get_caret_count() == 2);
- CHECK(text_edit->has_selection(0));
- CHECK(text_edit->get_selected_text(0) == "some");
- CHECK(text_edit->get_caret_line(0) == 0);
- CHECK(text_edit->get_caret_column(0) == 8);
- CHECK(text_edit->get_selection_origin_line(0) == 0);
- CHECK(text_edit->get_selection_origin_column(0) == 12);
- CHECK(text_edit->has_selection(1));
- CHECK(text_edit->get_selected_text(1) == "ele");
- CHECK(text_edit->get_caret_line(1) == 1);
- CHECK(text_edit->get_caret_column(1) == 8);
- CHECK(text_edit->get_selection_origin_line(1) == 1);
- CHECK(text_edit->get_selection_origin_column(1) == 5);
- // Shift + double click to extend selection and start word select mode.
- SEND_GUI_MOUSE_BUTTON_RELEASED_EVENT(text_edit->get_rect_at_line_column(1, 8).get_center(), MouseButton::LEFT, MouseButtonMask::LEFT, Key::NONE);
- text_edit->remove_secondary_carets();
- SEND_GUI_DOUBLE_CLICK(text_edit->get_rect_at_line_column(1, 7).get_center() + Point2i(2, 0), Key::NONE | KeyModifierMask::SHIFT);
- CHECK(text_edit->get_selection_mode() == TextEdit::SELECTION_MODE_WORD);
- CHECK(text_edit->has_selection());
- CHECK(text_edit->get_selected_text() == " text\nfor selection");
- CHECK(text_edit->get_caret_line() == 1);
- CHECK(text_edit->get_caret_column() == 13);
- CHECK(text_edit->get_selection_origin_line() == 0);
- CHECK(text_edit->get_selection_origin_column() == 12);
- // Cannot select when disabled, but caret still moves to end of word.
- text_edit->set_selecting_enabled(false);
- SEND_GUI_DOUBLE_CLICK(text_edit->get_rect_at_line_column(1, 1).get_center() + Point2i(2, 0), Key::NONE);
- CHECK_FALSE(text_edit->has_selection());
- CHECK(text_edit->get_caret_line() == 1);
- CHECK(text_edit->get_caret_column() == 3);
- text_edit->set_selecting_enabled(true);
- }
- SUBCASE("[TextEdit] mouse line select") {
- // Set size for mouse input.
- text_edit->set_size(Size2(200, 200));
- text_edit->set_text("this is some text\nfor selection\nwith 3 lines");
- MessageQueue::get_singleton()->flush();
- // Triple click to select line.
- SEND_GUI_DOUBLE_CLICK(text_edit->get_rect_at_line_column(1, 2).get_center(), Key::NONE);
- SEND_GUI_MOUSE_BUTTON_EVENT(text_edit->get_rect_at_line_column(1, 2).get_center(), MouseButton::LEFT, MouseButtonMask::LEFT, Key::NONE);
- CHECK(text_edit->has_selection());
- CHECK(text_edit->get_selected_text() == "for selection\n");
- CHECK(text_edit->get_selection_mode() == TextEdit::SELECTION_MODE_LINE);
- CHECK(text_edit->get_selection_from_line() == 1);
- CHECK(text_edit->get_selection_from_column() == 0);
- CHECK(text_edit->get_selection_to_line() == 2);
- CHECK(text_edit->get_selection_to_column() == 0);
- CHECK(text_edit->get_caret_line() == 2);
- CHECK(text_edit->get_caret_column() == 0);
- CHECK(text_edit->is_caret_after_selection_origin());
- // Moving mouse selects entire lines at a time. Selecting above reverses the selection direction.
- SEND_GUI_MOUSE_MOTION_EVENT(text_edit->get_rect_at_line_column(0, 10).get_center(), MouseButtonMask::LEFT, Key::NONE);
- CHECK(text_edit->has_selection());
- CHECK(text_edit->get_selected_text() == "this is some text\nfor selection");
- CHECK(text_edit->get_selection_mode() == TextEdit::SELECTION_MODE_LINE);
- CHECK(text_edit->get_selection_from_line() == 0);
- CHECK(text_edit->get_selection_from_column() == 0);
- CHECK(text_edit->get_selection_to_line() == 1);
- CHECK(text_edit->get_selection_to_column() == 13);
- CHECK(text_edit->get_caret_line() == 0);
- CHECK(text_edit->get_caret_column() == 0);
- CHECK_FALSE(text_edit->is_caret_after_selection_origin());
- CHECK(text_edit->is_dragging_cursor());
- // Selecting to the last line puts the caret at end of the line.
- SEND_GUI_MOUSE_MOTION_EVENT(text_edit->get_rect_at_line_column(2, 10).get_center(), MouseButtonMask::LEFT, Key::NONE);
- CHECK(text_edit->has_selection());
- CHECK(text_edit->get_selected_text() == "for selection\nwith 3 lines");
- CHECK(text_edit->get_selection_mode() == TextEdit::SELECTION_MODE_LINE);
- CHECK(text_edit->get_selection_from_line() == 1);
- CHECK(text_edit->get_selection_from_column() == 0);
- CHECK(text_edit->get_selection_to_line() == 2);
- CHECK(text_edit->get_selection_to_column() == 12);
- CHECK(text_edit->get_caret_line() == 2);
- CHECK(text_edit->get_caret_column() == 12);
- CHECK(text_edit->is_caret_after_selection_origin());
- // Releasing finishes.
- SEND_GUI_MOUSE_BUTTON_RELEASED_EVENT(text_edit->get_rect_at_line_column(2, 10).get_center(), MouseButton::LEFT, MouseButtonMask::LEFT, Key::NONE);
- CHECK(text_edit->has_selection());
- CHECK(text_edit->get_selected_text() == "for selection\nwith 3 lines");
- SEND_GUI_MOUSE_MOTION_EVENT(text_edit->get_rect_at_line_column(1, 2).get_center(), MouseButtonMask::NONE, Key::NONE);
- CHECK(text_edit->has_selection());
- CHECK(text_edit->get_selected_text() == "for selection\nwith 3 lines");
- // Clicking clears selection.
- SEND_GUI_MOUSE_BUTTON_EVENT(text_edit->get_rect_at_line_column(0, 0).get_center(), MouseButton::LEFT, MouseButtonMask::LEFT, Key::NONE);
- CHECK_FALSE(text_edit->has_selection());
- CHECK(text_edit->get_caret_line() == 0);
- CHECK(text_edit->get_caret_column() == 0);
- SEND_GUI_MOUSE_BUTTON_RELEASED_EVENT(text_edit->get_rect_at_line_column(0, 0).get_center(), MouseButton::LEFT, MouseButtonMask::LEFT, Key::NONE);
- // Can start line select mode on an empty line.
- text_edit->set_text("this is some text\n\nfor selection\nwith 4 lines");
- MessageQueue::get_singleton()->flush();
- SEND_GUI_DOUBLE_CLICK(text_edit->get_rect_at_line_column(1, 0).get_center() + Point2i(2, 0), Key::NONE);
- SEND_GUI_MOUSE_BUTTON_EVENT(text_edit->get_rect_at_line_column(1, 0).get_center(), MouseButton::LEFT, MouseButtonMask::LEFT, Key::NONE);
- CHECK(text_edit->has_selection());
- CHECK(text_edit->get_selected_text() == "\n");
- CHECK(text_edit->get_selection_mode() == TextEdit::SELECTION_MODE_LINE);
- CHECK(text_edit->get_caret_line() == 2);
- CHECK(text_edit->get_caret_column() == 0);
- CHECK(text_edit->get_selection_origin_line() == 1);
- CHECK(text_edit->get_selection_origin_column() == 0);
- SEND_GUI_MOUSE_MOTION_EVENT(text_edit->get_rect_at_line_column(2, 9).get_center(), MouseButtonMask::LEFT, Key::NONE);
- CHECK(text_edit->has_selection());
- CHECK(text_edit->get_selected_text() == "\nfor selection\n");
- CHECK(text_edit->get_selection_mode() == TextEdit::SELECTION_MODE_LINE);
- CHECK(text_edit->get_caret_line() == 3);
- CHECK(text_edit->get_caret_column() == 0);
- CHECK(text_edit->get_selection_origin_line() == 1);
- CHECK(text_edit->get_selection_origin_column() == 0);
- // Add a new selection without affecting the old one.
- SEND_GUI_MOUSE_BUTTON_EVENT(text_edit->get_rect_at_line_column(0, 3).get_center(), MouseButton::LEFT, MouseButtonMask::LEFT, Key::NONE | KeyModifierMask::ALT);
- 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);
- CHECK(text_edit->get_selection_mode() == TextEdit::SELECTION_MODE_POINTER);
- CHECK(text_edit->get_caret_count() == 2);
- CHECK(text_edit->has_selection(0));
- CHECK(text_edit->get_selected_text(0) == "\nfor selection\n");
- CHECK(text_edit->get_caret_line(0) == 3);
- CHECK(text_edit->get_caret_column(0) == 0);
- CHECK(text_edit->get_selection_origin_line(0) == 1);
- CHECK(text_edit->get_selection_origin_column(0) == 0);
- CHECK(text_edit->has_selection(1));
- CHECK(text_edit->get_selected_text(1) == "is");
- CHECK(text_edit->get_caret_line(1) == 0);
- CHECK(text_edit->get_caret_column(1) == 4);
- CHECK(text_edit->get_selection_origin_line(1) == 0);
- CHECK(text_edit->get_selection_origin_column(1) == 2);
- text_edit->remove_secondary_carets();
- text_edit->deselect();
- // Selecting the last line puts caret at the end.
- SEND_GUI_DOUBLE_CLICK(text_edit->get_rect_at_line_column(3, 3).get_center(), Key::NONE);
- SEND_GUI_MOUSE_BUTTON_EVENT(text_edit->get_rect_at_line_column(3, 3).get_center(), MouseButton::LEFT, MouseButtonMask::LEFT, Key::NONE);
- CHECK(text_edit->get_selection_mode() == TextEdit::SELECTION_MODE_LINE);
- CHECK(text_edit->has_selection());
- CHECK(text_edit->get_selected_text() == "with 4 lines");
- CHECK(text_edit->get_caret_line() == 3);
- CHECK(text_edit->get_caret_column() == 12);
- CHECK(text_edit->get_selection_origin_line() == 3);
- CHECK(text_edit->get_selection_origin_column() == 0);
- // Selecting above reverses direction.
- SEND_GUI_MOUSE_MOTION_EVENT(text_edit->get_rect_at_line_column(2, 10).get_center(), MouseButtonMask::LEFT, Key::NONE);
- CHECK(text_edit->get_selection_mode() == TextEdit::SELECTION_MODE_LINE);
- CHECK(text_edit->has_selection());
- CHECK(text_edit->get_selected_text() == "for selection\nwith 4 lines");
- CHECK(text_edit->get_caret_line() == 2);
- CHECK(text_edit->get_caret_column() == 0);
- CHECK(text_edit->get_selection_origin_line() == 3);
- CHECK(text_edit->get_selection_origin_column() == 12);
- SEND_GUI_MOUSE_BUTTON_RELEASED_EVENT(text_edit->get_rect_at_line_column(2, 10).get_center(), MouseButton::LEFT, MouseButtonMask::LEFT, Key::NONE);
- // Shift + triple click to extend selection and restart line select mode.
- SEND_GUI_DOUBLE_CLICK(text_edit->get_rect_at_line_column(0, 9).get_center() + Point2i(2, 0), Key::NONE | KeyModifierMask::SHIFT);
- SEND_GUI_MOUSE_BUTTON_EVENT(text_edit->get_rect_at_line_column(0, 9).get_center(), MouseButton::LEFT, MouseButtonMask::LEFT, Key::NONE | KeyModifierMask::SHIFT);
- CHECK(text_edit->get_selection_mode() == TextEdit::SELECTION_MODE_LINE);
- CHECK(text_edit->has_selection());
- CHECK(text_edit->get_selected_text() == "this is some text\n\nfor selection\nwith 4 lines");
- CHECK(text_edit->get_caret_line() == 0);
- CHECK(text_edit->get_caret_column() == 0);
- CHECK(text_edit->get_selection_origin_line() == 3);
- CHECK(text_edit->get_selection_origin_column() == 12);
- // Cannot select when disabled, but caret still moves to the start of the next line.
- text_edit->set_selecting_enabled(false);
- SEND_GUI_DOUBLE_CLICK(text_edit->get_rect_at_line_column(0, 2).get_center(), Key::NONE);
- SEND_GUI_MOUSE_BUTTON_EVENT(text_edit->get_rect_at_line_column(0, 2).get_center(), MouseButton::LEFT, MouseButtonMask::LEFT, Key::NONE);
- CHECK_FALSE(text_edit->has_selection());
- CHECK(text_edit->get_caret_line() == 1);
- CHECK(text_edit->get_caret_column() == 0);
- text_edit->set_selecting_enabled(true);
- }
- SUBCASE("[TextEdit] mouse shift click select") {
- // Set size for mouse input.
- text_edit->set_size(Size2(200, 200));
- text_edit->set_text("this is some text\nfor selection");
- MessageQueue::get_singleton()->flush();
- // Shift click to make a selection from the previous caret position.
- 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);
- 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);
- CHECK(text_edit->has_selection());
- CHECK(text_edit->get_selected_text() == "or s");
- CHECK(text_edit->get_selection_mode() == TextEdit::SELECTION_MODE_POINTER);
- CHECK(text_edit->get_selection_origin_line() == 1);
- CHECK(text_edit->get_selection_origin_column() == 1);
- CHECK(text_edit->get_caret_line() == 1);
- CHECK(text_edit->get_caret_column() == 5);
- CHECK(text_edit->is_caret_after_selection_origin());
- // Shift click above to switch selection direction. Uses original selection position.
- 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);
- CHECK(text_edit->has_selection());
- CHECK(text_edit->get_selected_text() == "s some text\nf");
- CHECK(text_edit->get_selection_mode() == TextEdit::SELECTION_MODE_POINTER);
- CHECK(text_edit->get_selection_origin_line() == 1);
- CHECK(text_edit->get_selection_origin_column() == 1);
- CHECK(text_edit->get_caret_line() == 0);
- CHECK(text_edit->get_caret_column() == 6);
- CHECK_FALSE(text_edit->is_caret_after_selection_origin());
- // Clicking clears selection.
- 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);
- CHECK_FALSE(text_edit->has_selection());
- CHECK(text_edit->get_caret_line() == 1);
- CHECK(text_edit->get_caret_column() == 7);
- // Cannot select when disabled, but caret still moves.
- text_edit->set_selecting_enabled(false);
- SEND_GUI_MOUSE_BUTTON_EVENT(text_edit->get_rect_at_line_column(1, 0).get_center(), MouseButton::LEFT, MouseButtonMask::LEFT, Key::NONE);
- CHECK(text_edit->get_caret_line() == 1);
- CHECK(text_edit->get_caret_column() == 0);
- 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);
- CHECK_FALSE(text_edit->has_selection());
- CHECK(text_edit->get_caret_line() == 1);
- CHECK(text_edit->get_caret_column() == 5);
- text_edit->set_selecting_enabled(true);
- }
- SUBCASE("[TextEdit] select and deselect") {
- text_edit->set_text("this is some text\nfor selection");
- MessageQueue::get_singleton()->flush();
- SIGNAL_DISCARD("caret_changed");
- // Select clamps input to full text.
- text_edit->select(-1, -1, 500, 500);
- MessageQueue::get_singleton()->flush();
- CHECK(text_edit->has_selection());
- CHECK(text_edit->get_selected_text() == "this is some text\nfor selection");
- CHECK(text_edit->is_caret_after_selection_origin(0));
- CHECK(text_edit->get_selection_origin_line(0) == 0);
- CHECK(text_edit->get_selection_origin_column(0) == 0);
- CHECK(text_edit->get_caret_line(0) == 1);
- CHECK(text_edit->get_caret_column(0) == 13);
- CHECK(text_edit->get_selection_from_line(0) == text_edit->get_selection_origin_line(0));
- CHECK(text_edit->get_selection_from_column(0) == text_edit->get_selection_origin_column(0));
- CHECK(text_edit->get_selection_to_line(0) == text_edit->get_caret_line(0));
- CHECK(text_edit->get_selection_to_column(0) == text_edit->get_caret_column(0));
- SIGNAL_CHECK("caret_changed", empty_signal_args);
- text_edit->deselect();
- MessageQueue::get_singleton()->flush();
- CHECK_FALSE(text_edit->has_selection());
- SIGNAL_CHECK_FALSE("caret_changed");
- // Select works in the other direction.
- text_edit->select(500, 500, -1, -1);
- MessageQueue::get_singleton()->flush();
- CHECK(text_edit->has_selection());
- CHECK(text_edit->get_selected_text() == "this is some text\nfor selection");
- CHECK_FALSE(text_edit->is_caret_after_selection_origin(0));
- CHECK(text_edit->get_selection_origin_line(0) == 1);
- CHECK(text_edit->get_selection_origin_column(0) == 13);
- CHECK(text_edit->get_caret_line(0) == 0);
- CHECK(text_edit->get_caret_column(0) == 0);
- CHECK(text_edit->get_selection_from_line(0) == text_edit->get_caret_line(0));
- CHECK(text_edit->get_selection_from_column(0) == text_edit->get_caret_column(0));
- CHECK(text_edit->get_selection_to_line(0) == text_edit->get_selection_origin_line(0));
- CHECK(text_edit->get_selection_to_column(0) == text_edit->get_selection_origin_column(0));
- SIGNAL_CHECK("caret_changed", empty_signal_args);
- text_edit->deselect();
- MessageQueue::get_singleton()->flush();
- CHECK_FALSE(text_edit->has_selection());
- SIGNAL_CHECK_FALSE("caret_changed");
- // Select part of a line.
- text_edit->select(0, 4, 0, 8);
- MessageQueue::get_singleton()->flush();
- CHECK(text_edit->has_selection());
- CHECK(text_edit->get_selected_text() == " is ");
- CHECK(text_edit->is_caret_after_selection_origin(0));
- CHECK(text_edit->get_selection_origin_line(0) == 0);
- CHECK(text_edit->get_selection_origin_column(0) == 4);
- CHECK(text_edit->get_caret_line(0) == 0);
- CHECK(text_edit->get_caret_column(0) == 8);
- CHECK(text_edit->get_selection_from_line(0) == text_edit->get_selection_origin_line(0));
- CHECK(text_edit->get_selection_from_column(0) == text_edit->get_selection_origin_column(0));
- CHECK(text_edit->get_selection_to_line(0) == text_edit->get_caret_line(0));
- CHECK(text_edit->get_selection_to_column(0) == text_edit->get_caret_column(0));
- SIGNAL_CHECK("caret_changed", empty_signal_args);
- text_edit->deselect();
- MessageQueue::get_singleton()->flush();
- CHECK_FALSE(text_edit->has_selection());
- SIGNAL_CHECK_FALSE("caret_changed");
- // Select part of a line in the other direction.
- text_edit->select(0, 8, 0, 4);
- MessageQueue::get_singleton()->flush();
- CHECK(text_edit->has_selection());
- CHECK(text_edit->get_selected_text() == " is ");
- CHECK_FALSE(text_edit->is_caret_after_selection_origin(0));
- CHECK(text_edit->get_selection_origin_line(0) == 0);
- CHECK(text_edit->get_selection_origin_column(0) == 8);
- CHECK(text_edit->get_caret_line(0) == 0);
- CHECK(text_edit->get_caret_column(0) == 4);
- CHECK(text_edit->get_selection_from_line(0) == text_edit->get_caret_line(0));
- CHECK(text_edit->get_selection_from_column(0) == text_edit->get_caret_column(0));
- CHECK(text_edit->get_selection_to_line(0) == text_edit->get_selection_origin_line(0));
- CHECK(text_edit->get_selection_to_column(0) == text_edit->get_selection_origin_column(0));
- SIGNAL_CHECK("caret_changed", empty_signal_args);
- // Cannot select when disabled.
- text_edit->set_selecting_enabled(false);
- CHECK_FALSE(text_edit->has_selection());
- text_edit->select(0, 8, 0, 4);
- MessageQueue::get_singleton()->flush();
- CHECK_FALSE(text_edit->has_selection());
- SIGNAL_CHECK_FALSE("caret_changed");
- text_edit->set_selecting_enabled(true);
- }
- SUBCASE("[TextEdit] delete selection") {
- text_edit->set_text("this is some text\nfor selection");
- MessageQueue::get_singleton()->flush();
- // Delete selection does nothing if there is no selection.
- text_edit->set_caret_line(0);
- text_edit->set_caret_column(8);
- CHECK_FALSE(text_edit->has_selection());
- text_edit->delete_selection();
- CHECK(text_edit->get_text() == "this is some text\nfor selection");
- CHECK_FALSE(text_edit->has_selection());
- CHECK(text_edit->get_caret_line() == 0);
- CHECK(text_edit->get_caret_column() == 8);
- // Backspace removes selection.
- text_edit->select(0, 4, 0, 8);
- CHECK(text_edit->has_selection());
- SEND_GUI_ACTION("ui_text_backspace");
- CHECK_FALSE(text_edit->has_selection());
- CHECK(text_edit->get_text() == "thissome text\nfor selection");
- CHECK(text_edit->get_caret_line() == 0);
- CHECK(text_edit->get_caret_column() == 4);
- // Undo restores previous selection.
- text_edit->undo();
- CHECK(text_edit->get_text() == "this is some text\nfor selection");
- CHECK(text_edit->has_selection());
- CHECK(text_edit->get_caret_line() == 0);
- CHECK(text_edit->get_caret_column() == 8);
- CHECK(text_edit->get_selection_origin_line() == 0);
- CHECK(text_edit->get_selection_origin_column() == 4);
- // Redo restores caret.
- text_edit->redo();
- CHECK(text_edit->get_text() == "thissome text\nfor selection");
- CHECK_FALSE(text_edit->has_selection());
- CHECK(text_edit->get_caret_line() == 0);
- CHECK(text_edit->get_caret_column() == 4);
- text_edit->undo();
- CHECK(text_edit->get_text() == "this is some text\nfor selection");
- CHECK(text_edit->has_selection());
- CHECK(text_edit->get_caret_line() == 0);
- CHECK(text_edit->get_caret_column() == 8);
- text_edit->select(0, 4, 0, 8);
- CHECK(text_edit->has_selection());
- // Delete selection removes text, deselects, and moves caret.
- text_edit->delete_selection();
- CHECK(text_edit->get_text() == "thissome text\nfor selection");
- CHECK_FALSE(text_edit->has_selection());
- CHECK(text_edit->get_caret_line() == 0);
- CHECK(text_edit->get_caret_column() == 4);
- // Undo delete works.
- text_edit->undo();
- CHECK(text_edit->get_text() == "this is some text\nfor selection");
- CHECK(text_edit->has_selection());
- CHECK(text_edit->get_caret_line() == 0);
- CHECK(text_edit->get_caret_column() == 8);
- CHECK(text_edit->get_selection_origin_line() == 0);
- CHECK(text_edit->get_selection_origin_column() == 4);
- // Redo delete works.
- text_edit->redo();
- CHECK(text_edit->get_text() == "thissome text\nfor selection");
- CHECK_FALSE(text_edit->has_selection());
- CHECK(text_edit->get_caret_line() == 0);
- CHECK(text_edit->get_caret_column() == 4);
- text_edit->undo();
- CHECK(text_edit->has_selection());
- CHECK(text_edit->get_text() == "this is some text\nfor selection");
- CHECK(text_edit->get_caret_line() == 0);
- CHECK(text_edit->get_caret_column() == 8);
- // Can still delete if not editable.
- text_edit->set_editable(false);
- text_edit->delete_selection();
- text_edit->set_editable(false);
- CHECK_FALSE(text_edit->has_selection());
- CHECK(text_edit->get_text() == "thissome text\nfor selection");
- // Cannot undo since it was not editable.
- text_edit->undo();
- CHECK_FALSE(text_edit->has_selection());
- CHECK(text_edit->get_text() == "thissome text\nfor selection");
- // Delete multiple adjacent selections on the same line.
- text_edit->select(0, 0, 0, 5);
- text_edit->add_caret(0, 8);
- text_edit->select(0, 5, 0, 8, 1);
- CHECK(text_edit->get_caret_count() == 2);
- text_edit->delete_selection();
- CHECK(text_edit->get_text() == " text\nfor selection");
- CHECK(text_edit->get_caret_count() == 1);
- CHECK_FALSE(text_edit->has_selection());
- CHECK(text_edit->get_caret_line() == 0);
- CHECK(text_edit->get_caret_column() == 0);
- // Delete mulitline selection. Ignore non selections.
- text_edit->remove_secondary_carets();
- text_edit->select(1, 3, 0, 2);
- text_edit->add_caret(1, 7);
- text_edit->delete_selection();
- CHECK(text_edit->get_text() == " t selection");
- CHECK(text_edit->get_caret_count() == 2);
- CHECK_FALSE(text_edit->has_selection(0));
- CHECK(text_edit->get_caret_line(0) == 0);
- CHECK(text_edit->get_caret_column(0) == 2);
- CHECK_FALSE(text_edit->has_selection(1));
- CHECK(text_edit->get_caret_line(1) == 0);
- CHECK(text_edit->get_caret_column(1) == 6);
- }
- SUBCASE("[TextEdit] text drag") {
- text_edit->set_size(Size2(200, 200));
- text_edit->set_text("drag test\ndrop here ''");
- text_edit->grab_click_focus();
- MessageQueue::get_singleton()->flush();
- // Drag and drop selected text to mouse position.
- text_edit->select(0, 0, 0, 4);
- 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);
- CHECK(text_edit->is_mouse_over_selection());
- SEND_GUI_MOUSE_MOTION_EVENT(text_edit->get_rect_at_line_column(0, 7).get_center() + Point2i(2, 0), MouseButtonMask::LEFT, Key::NONE);
- CHECK(text_edit->get_viewport()->gui_is_dragging());
- CHECK(text_edit->get_viewport()->gui_get_drag_data() == "drag");
- CHECK(text_edit->has_selection());
- CHECK(text_edit->get_caret_line() == 0);
- CHECK(text_edit->get_caret_column() == 4);
- CHECK(text_edit->get_selection_origin_line() == 0);
- CHECK(text_edit->get_selection_origin_column() == 0);
- SEND_GUI_MOUSE_MOTION_EVENT(text_edit->get_rect_at_line_column(1, 11).get_center() + Point2i(2, 0), MouseButtonMask::LEFT, Key::NONE);
- 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);
- CHECK_FALSE(text_edit->get_viewport()->gui_is_dragging());
- CHECK(text_edit->get_text() == " test\ndrop here 'drag'");
- CHECK(text_edit->has_selection());
- CHECK(text_edit->get_caret_line() == 1);
- CHECK(text_edit->get_caret_column() == 15);
- CHECK(text_edit->get_selection_origin_line() == 1);
- CHECK(text_edit->get_selection_origin_column() == 11);
- // Undo.
- text_edit->undo();
- CHECK(text_edit->get_text() == "drag test\ndrop here ''");
- CHECK(text_edit->has_selection());
- CHECK(text_edit->get_caret_line() == 0);
- CHECK(text_edit->get_caret_column() == 4);
- CHECK(text_edit->get_selection_origin_line() == 0);
- CHECK(text_edit->get_selection_origin_column() == 0);
- // Redo.
- text_edit->redo();
- CHECK(text_edit->get_text() == " test\ndrop here 'drag'");
- CHECK(text_edit->has_selection());
- CHECK(text_edit->get_caret_line() == 1);
- CHECK(text_edit->get_caret_column() == 15);
- CHECK(text_edit->get_selection_origin_line() == 1);
- CHECK(text_edit->get_selection_origin_column() == 11);
- // Hold control when dropping to not delete selected text.
- text_edit->select(1, 10, 1, 16);
- 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);
- CHECK(text_edit->is_mouse_over_selection());
- SEND_GUI_MOUSE_MOTION_EVENT(text_edit->get_rect_at_line_column(1, 7).get_center() + Point2i(2, 0), MouseButtonMask::LEFT, Key::NONE);
- CHECK(text_edit->get_viewport()->gui_is_dragging());
- CHECK(text_edit->get_viewport()->gui_get_drag_data() == "'drag'");
- CHECK(text_edit->has_selection());
- SEND_GUI_MOUSE_MOTION_EVENT(text_edit->get_rect_at_line_column(0, 0).get_center(), MouseButtonMask::LEFT, Key::NONE);
- SEND_GUI_KEY_EVENT(Key::CMD_OR_CTRL);
- SEND_GUI_MOUSE_BUTTON_RELEASED_EVENT(text_edit->get_rect_at_line_column(0, 0).get_center(), MouseButton::LEFT, MouseButtonMask::NONE, Key::NONE);
- SEND_GUI_KEY_UP_EVENT(Key::CMD_OR_CTRL);
- CHECK_FALSE(text_edit->get_viewport()->gui_is_dragging());
- CHECK(text_edit->get_text() == "'drag' test\ndrop here 'drag'");
- CHECK(text_edit->has_selection());
- CHECK(text_edit->get_caret_line() == 0);
- CHECK(text_edit->get_caret_column() == 6);
- CHECK(text_edit->get_selection_origin_line() == 0);
- CHECK(text_edit->get_selection_origin_column() == 0);
- // Multiple caret drags entire selection.
- text_edit->select(0, 11, 0, 7, 0);
- text_edit->add_caret(1, 2);
- text_edit->select(1, 2, 1, 4, 1);
- text_edit->add_caret(1, 12);
- 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);
- CHECK(text_edit->is_mouse_over_selection(true, 1));
- SEND_GUI_MOUSE_MOTION_EVENT(text_edit->get_rect_at_line_column(1, 12).get_center() + Point2i(2, 0), MouseButtonMask::LEFT, Key::NONE);
- CHECK(text_edit->get_viewport()->gui_is_dragging());
- CHECK(text_edit->get_viewport()->gui_get_drag_data() == "test\nop");
- // Carets aren't removed from dragging, only dropping.
- CHECK(text_edit->get_caret_count() == 3);
- CHECK(text_edit->has_selection(0));
- CHECK(text_edit->get_caret_line(0) == 0);
- CHECK(text_edit->get_caret_column(0) == 7);
- CHECK(text_edit->get_selection_origin_line(0) == 0);
- CHECK(text_edit->get_selection_origin_column(0) == 11);
- CHECK(text_edit->has_selection(1));
- CHECK(text_edit->get_caret_line(1) == 1);
- CHECK(text_edit->get_caret_column(1) == 4);
- CHECK(text_edit->get_selection_origin_line(1) == 1);
- CHECK(text_edit->get_selection_origin_column(1) == 2);
- CHECK_FALSE(text_edit->has_selection(2));
- CHECK(text_edit->get_caret_line(2) == 1);
- CHECK(text_edit->get_caret_column(2) == 12);
- SEND_GUI_MOUSE_MOTION_EVENT(text_edit->get_rect_at_line_column(1, 9).get_center() + Point2i(2, 0), MouseButtonMask::LEFT, Key::NONE);
- 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);
- CHECK_FALSE(text_edit->get_viewport()->gui_is_dragging());
- CHECK(text_edit->get_text() == "'drag' \ndr heretest\nop 'drag'");
- CHECK(text_edit->get_caret_count() == 1);
- CHECK(text_edit->has_selection());
- CHECK(text_edit->get_caret_line() == 2);
- CHECK(text_edit->get_caret_column() == 2);
- CHECK(text_edit->get_selection_origin_line() == 1);
- CHECK(text_edit->get_selection_origin_column() == 7);
- // Drop onto same selection should do effectively nothing.
- text_edit->select(1, 3, 1, 7);
- 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);
- CHECK(text_edit->is_mouse_over_selection());
- SEND_GUI_MOUSE_MOTION_EVENT(text_edit->get_rect_at_line_column(0, 1).get_center() + Point2i(2, 0), MouseButtonMask::LEFT, Key::NONE);
- CHECK(text_edit->get_viewport()->gui_is_dragging());
- CHECK(text_edit->get_viewport()->gui_get_drag_data() == "here");
- 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);
- CHECK_FALSE(text_edit->get_viewport()->gui_is_dragging());
- CHECK(text_edit->get_text() == "'drag' \ndr heretest\nop 'drag'");
- CHECK(text_edit->get_caret_count() == 1);
- CHECK(text_edit->has_selection());
- CHECK(text_edit->get_caret_line() == 1);
- CHECK(text_edit->get_caret_column() == 7);
- CHECK(text_edit->get_selection_origin_line() == 1);
- CHECK(text_edit->get_selection_origin_column() == 3);
- // Cannot drag when drag and drop selection is disabled. It becomes regular drag to select.
- text_edit->set_drag_and_drop_selection_enabled(false);
- text_edit->select(0, 1, 0, 5);
- 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);
- CHECK_FALSE(text_edit->is_mouse_over_selection());
- SEND_GUI_MOUSE_MOTION_EVENT(text_edit->get_rect_at_line_column(1, 7).get_center() + Point2i(2, 0), MouseButtonMask::LEFT, Key::NONE);
- CHECK_FALSE(text_edit->get_viewport()->gui_is_dragging());
- 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);
- CHECK_FALSE(text_edit->get_viewport()->gui_is_dragging());
- CHECK(text_edit->get_text() == "'drag' \ndr heretest\nop 'drag'");
- CHECK(text_edit->has_selection());
- CHECK(text_edit->get_caret_line() == 1);
- CHECK(text_edit->get_caret_column() == 7);
- CHECK(text_edit->get_selection_origin_line() == 0);
- CHECK(text_edit->get_selection_origin_column() == 2);
- text_edit->set_drag_and_drop_selection_enabled(true);
- // Cancel drag and drop from Escape key.
- text_edit->select(0, 1, 0, 5);
- 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);
- CHECK(text_edit->is_mouse_over_selection());
- SEND_GUI_MOUSE_MOTION_EVENT(text_edit->get_rect_at_line_column(0, 1).get_center() + Point2i(2, 0), MouseButtonMask::LEFT, Key::NONE);
- CHECK(text_edit->get_viewport()->gui_is_dragging());
- CHECK(text_edit->get_viewport()->gui_get_drag_data() == "drag");
- SEND_GUI_KEY_EVENT(Key::ESCAPE);
- CHECK_FALSE(text_edit->get_viewport()->gui_is_dragging());
- CHECK(text_edit->get_text() == "'drag' \ndr heretest\nop 'drag'");
- CHECK(text_edit->has_selection());
- CHECK(text_edit->get_caret_line() == 0);
- CHECK(text_edit->get_caret_column() == 5);
- CHECK(text_edit->get_selection_origin_line() == 0);
- CHECK(text_edit->get_selection_origin_column() == 1);
- // Cancel drag and drop from caret move key input.
- text_edit->select(0, 1, 0, 5);
- 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);
- CHECK(text_edit->is_mouse_over_selection());
- SEND_GUI_MOUSE_MOTION_EVENT(text_edit->get_rect_at_line_column(0, 1).get_center() + Point2i(2, 0), MouseButtonMask::LEFT, Key::NONE);
- CHECK(text_edit->get_viewport()->gui_is_dragging());
- CHECK(text_edit->get_viewport()->gui_get_drag_data() == "drag");
- SEND_GUI_KEY_EVENT(Key::RIGHT);
- CHECK_FALSE(text_edit->get_viewport()->gui_is_dragging());
- CHECK(text_edit->get_text() == "'drag' \ndr heretest\nop 'drag'");
- CHECK_FALSE(text_edit->has_selection());
- CHECK(text_edit->get_caret_line() == 0);
- CHECK(text_edit->get_caret_column() == 5);
- // Cancel drag and drop from text key input.
- text_edit->select(0, 1, 0, 5);
- 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);
- CHECK(text_edit->is_mouse_over_selection());
- SEND_GUI_MOUSE_MOTION_EVENT(text_edit->get_rect_at_line_column(0, 1).get_center() + Point2i(2, 0), MouseButtonMask::LEFT, Key::NONE);
- CHECK(text_edit->get_viewport()->gui_is_dragging());
- CHECK(text_edit->get_viewport()->gui_get_drag_data() == "drag");
- SEND_GUI_KEY_EVENT(Key::A);
- CHECK_FALSE(text_edit->get_viewport()->gui_is_dragging());
- CHECK(text_edit->get_text() == "'A' \ndr heretest\nop 'drag'");
- CHECK_FALSE(text_edit->has_selection());
- CHECK(text_edit->get_caret_line() == 0);
- CHECK(text_edit->get_caret_column() == 2);
- }
- SUBCASE("[TextEdit] text drag to another text edit") {
- TextEdit *target_text_edit = memnew(TextEdit);
- SceneTree::get_singleton()->get_root()->add_child(target_text_edit);
- target_text_edit->set_size(Size2(200, 200));
- target_text_edit->set_position(Point2(400, 0));
- text_edit->set_size(Size2(200, 200));
- CHECK_FALSE(text_edit->is_mouse_over_selection());
- text_edit->set_text("drag me");
- text_edit->select_all();
- text_edit->grab_click_focus();
- CHECK(text_edit->has_selection());
- CHECK(text_edit->get_caret_line() == 0);
- CHECK(text_edit->get_caret_column() == 7);
- CHECK(text_edit->get_selection_origin_line() == 0);
- CHECK(text_edit->get_selection_origin_column() == 0);
- MessageQueue::get_singleton()->flush();
- // Drag text between text edits.
- SEND_GUI_MOUSE_BUTTON_EVENT(text_edit->get_rect_at_line_column(0, 0).get_center(), MouseButton::LEFT, MouseButtonMask::LEFT, Key::NONE);
- CHECK(text_edit->is_mouse_over_selection());
- SEND_GUI_MOUSE_MOTION_EVENT(text_edit->get_rect_at_line_column(0, 7).get_center(), MouseButtonMask::LEFT, Key::NONE);
- CHECK(text_edit->get_viewport()->gui_is_dragging());
- CHECK(text_edit->get_viewport()->gui_get_drag_data() == "drag me");
- CHECK(text_edit->has_selection());
- CHECK(text_edit->get_caret_line() == 0);
- CHECK(text_edit->get_caret_column() == 7);
- CHECK(text_edit->get_selection_origin_line() == 0);
- CHECK(text_edit->get_selection_origin_column() == 0);
- Point2i target_line0 = target_text_edit->get_position() + Point2i(1, target_text_edit->get_line_height() / 2);
- SEND_GUI_MOUSE_MOTION_EVENT(target_line0, MouseButtonMask::LEFT, Key::NONE);
- CHECK(text_edit->get_viewport()->gui_is_dragging());
- CHECK(target_text_edit->get_caret_line() == 0);
- CHECK(target_text_edit->get_caret_column() == 0);
- SEND_GUI_MOUSE_BUTTON_RELEASED_EVENT(target_line0, MouseButton::LEFT, MouseButtonMask::NONE, Key::NONE);
- CHECK_FALSE(text_edit->get_viewport()->gui_is_dragging());
- CHECK(text_edit->get_text() == "");
- CHECK_FALSE(text_edit->has_selection());
- CHECK(text_edit->get_caret_line() == 0);
- CHECK(text_edit->get_caret_column() == 0);
- CHECK(target_text_edit->get_text() == "drag me");
- CHECK(target_text_edit->has_selection());
- CHECK(target_text_edit->get_caret_line() == 0);
- CHECK(target_text_edit->get_caret_column() == 7);
- CHECK(target_text_edit->get_selection_origin_line() == 0);
- CHECK(target_text_edit->get_selection_origin_column() == 0);
- // Undo is separate per TextEdit.
- text_edit->undo();
- CHECK(text_edit->get_text() == "drag me");
- CHECK(text_edit->has_selection());
- CHECK(text_edit->get_caret_line() == 0);
- CHECK(text_edit->get_caret_column() == 7);
- CHECK(text_edit->get_selection_origin_line() == 0);
- CHECK(text_edit->get_selection_origin_column() == 0);
- CHECK(target_text_edit->get_text() == "drag me");
- CHECK(target_text_edit->has_selection());
- CHECK(target_text_edit->get_caret_line() == 0);
- CHECK(target_text_edit->get_caret_column() == 7);
- CHECK(target_text_edit->get_selection_origin_line() == 0);
- CHECK(target_text_edit->get_selection_origin_column() == 0);
- target_text_edit->undo();
- CHECK(text_edit->get_text() == "drag me");
- CHECK(text_edit->has_selection());
- CHECK(text_edit->get_caret_line() == 0);
- CHECK(text_edit->get_caret_column() == 7);
- CHECK(text_edit->get_selection_origin_line() == 0);
- CHECK(text_edit->get_selection_origin_column() == 0);
- CHECK(target_text_edit->get_text() == "");
- CHECK_FALSE(target_text_edit->has_selection());
- CHECK(target_text_edit->get_caret_line() == 0);
- CHECK(target_text_edit->get_caret_column() == 0);
- // Redo is also separate.
- text_edit->redo();
- CHECK(text_edit->get_text() == "");
- CHECK_FALSE(text_edit->has_selection());
- CHECK(text_edit->get_caret_line() == 0);
- CHECK(text_edit->get_caret_column() == 0);
- CHECK(target_text_edit->get_text() == "");
- CHECK_FALSE(target_text_edit->has_selection());
- CHECK(target_text_edit->get_caret_line() == 0);
- CHECK(target_text_edit->get_caret_column() == 0);
- target_text_edit->redo();
- CHECK(text_edit->get_text() == "");
- CHECK_FALSE(text_edit->has_selection());
- CHECK(text_edit->get_caret_line() == 0);
- CHECK(text_edit->get_caret_column() == 0);
- CHECK(target_text_edit->get_text() == "drag me");
- CHECK(target_text_edit->has_selection());
- CHECK(target_text_edit->get_caret_line() == 0);
- CHECK(target_text_edit->get_caret_column() == 7);
- CHECK(target_text_edit->get_selection_origin_line() == 0);
- CHECK(target_text_edit->get_selection_origin_column() == 0);
- // Hold control to not remove selected text.
- text_edit->set_text("drag test\ndrop test");
- MessageQueue::get_singleton()->flush();
- target_text_edit->select(0, 0, 0, 3, 0);
- target_text_edit->add_caret(0, 5);
- text_edit->select(0, 5, 0, 7, 0);
- text_edit->add_caret(0, 1);
- text_edit->select(0, 1, 0, 0, 1);
- 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);
- CHECK(text_edit->is_mouse_over_selection(true, 0));
- SEND_GUI_MOUSE_MOTION_EVENT(text_edit->get_rect_at_line_column(1, 6).get_center(), MouseButtonMask::LEFT, Key::NONE);
- CHECK(text_edit->get_viewport()->gui_is_dragging());
- CHECK(text_edit->get_viewport()->gui_get_drag_data() == "d\nte");
- CHECK(text_edit->has_selection());
- SEND_GUI_KEY_EVENT(Key::CMD_OR_CTRL);
- 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);
- 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);
- SEND_GUI_KEY_UP_EVENT(Key::CMD_OR_CTRL);
- CHECK_FALSE(text_edit->get_viewport()->gui_is_dragging());
- CHECK(text_edit->get_text() == "drag test\ndrop test");
- CHECK(text_edit->get_caret_count() == 2);
- CHECK_FALSE(text_edit->has_selection());
- CHECK(text_edit->get_caret_line(0) == 0);
- CHECK(text_edit->get_caret_column(0) == 7);
- CHECK(text_edit->get_caret_line(1) == 0);
- CHECK(text_edit->get_caret_column(1) == 0);
- CHECK(target_text_edit->get_text() == "drag md\ntee");
- CHECK(target_text_edit->get_caret_count() == 1);
- CHECK(target_text_edit->has_selection());
- CHECK(target_text_edit->get_caret_line() == 1);
- CHECK(target_text_edit->get_caret_column() == 2);
- CHECK(target_text_edit->get_selection_origin_line() == 0);
- CHECK(target_text_edit->get_selection_origin_column() == 6);
- // Drop onto selected text deletes the selected text first.
- text_edit->set_deselect_on_focus_loss_enabled(false);
- target_text_edit->set_deselect_on_focus_loss_enabled(false);
- text_edit->remove_secondary_carets();
- text_edit->select(0, 5, 0, 9);
- target_text_edit->select(0, 6, 0, 8);
- 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);
- CHECK(text_edit->is_mouse_over_selection(true, 0));
- SEND_GUI_MOUSE_MOTION_EVENT(text_edit->get_rect_at_line_column(1, 7).get_center(), MouseButtonMask::LEFT, Key::NONE);
- CHECK(text_edit->get_viewport()->gui_is_dragging());
- CHECK(text_edit->get_viewport()->gui_get_drag_data() == "test");
- CHECK(text_edit->has_selection());
- 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);
- 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);
- CHECK_FALSE(text_edit->get_viewport()->gui_is_dragging());
- CHECK(text_edit->get_text() == "drag \ndrop test");
- CHECK(target_text_edit->get_caret_count() == 1);
- CHECK_FALSE(text_edit->has_selection());
- CHECK(text_edit->get_caret_line() == 0);
- CHECK(text_edit->get_caret_column() == 5);
- CHECK(target_text_edit->get_text() == "drag mdtest\ntee");
- CHECK(target_text_edit->has_selection());
- CHECK(target_text_edit->get_caret_line() == 0);
- CHECK(target_text_edit->get_caret_column() == 11);
- CHECK(target_text_edit->get_selection_origin_line() == 0);
- CHECK(target_text_edit->get_selection_origin_column() == 7);
- text_edit->set_deselect_on_focus_loss_enabled(true);
- target_text_edit->set_deselect_on_focus_loss_enabled(true);
- // Can drop even when drag and drop selection is disabled.
- target_text_edit->set_drag_and_drop_selection_enabled(false);
- text_edit->select(0, 4, 0, 5);
- target_text_edit->deselect();
- 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);
- CHECK(text_edit->is_mouse_over_selection());
- SEND_GUI_MOUSE_MOTION_EVENT(text_edit->get_rect_at_line_column(1, 7).get_center() + Point2i(2, 0), MouseButtonMask::LEFT, Key::NONE);
- CHECK(text_edit->get_viewport()->gui_is_dragging());
- CHECK(text_edit->get_viewport()->gui_get_drag_data() == " ");
- CHECK(text_edit->has_selection());
- 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);
- 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);
- CHECK_FALSE(text_edit->get_viewport()->gui_is_dragging());
- CHECK(text_edit->get_text() == "drag\ndrop test");
- CHECK(target_text_edit->get_text() == "drag md test\ntee");
- CHECK_FALSE(text_edit->has_selection());
- CHECK(text_edit->get_caret_line() == 0);
- CHECK(text_edit->get_caret_column() == 4);
- CHECK(target_text_edit->has_selection());
- CHECK(target_text_edit->get_caret_line() == 0);
- CHECK(target_text_edit->get_caret_column() == 8);
- CHECK(target_text_edit->get_selection_origin_line() == 0);
- CHECK(target_text_edit->get_selection_origin_column() == 7);
- target_text_edit->set_drag_and_drop_selection_enabled(true);
- // Cannot drop when not editable.
- target_text_edit->set_editable(false);
- text_edit->select(0, 1, 0, 4);
- target_text_edit->deselect();
- 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);
- CHECK(text_edit->is_mouse_over_selection());
- SEND_GUI_MOUSE_MOTION_EVENT(text_edit->get_rect_at_line_column(1, 7).get_center() + Point2i(2, 0), MouseButtonMask::LEFT, Key::NONE);
- CHECK(text_edit->get_viewport()->gui_is_dragging());
- CHECK(text_edit->get_viewport()->gui_get_drag_data() == "rag");
- CHECK(text_edit->has_selection());
- 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);
- 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);
- CHECK_FALSE(text_edit->get_viewport()->gui_is_dragging());
- CHECK(text_edit->get_text() == "drag\ndrop test");
- CHECK(target_text_edit->get_text() == "drag md test\ntee");
- CHECK(text_edit->has_selection());
- CHECK_FALSE(target_text_edit->has_selection());
- target_text_edit->set_editable(true);
- // Can drag when not editable, but text will not be removed.
- text_edit->set_editable(false);
- text_edit->select(0, 0, 0, 4);
- 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);
- CHECK(text_edit->is_mouse_over_selection());
- SEND_GUI_MOUSE_MOTION_EVENT(text_edit->get_rect_at_line_column(1, 7).get_center() + Point2i(2, 0), MouseButtonMask::LEFT, Key::NONE);
- CHECK(text_edit->get_viewport()->gui_is_dragging());
- CHECK(text_edit->get_viewport()->gui_get_drag_data() == "drag");
- CHECK(text_edit->has_selection());
- 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);
- 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);
- CHECK_FALSE(text_edit->get_viewport()->gui_is_dragging());
- CHECK(text_edit->get_text() == "drag\ndrop test");
- CHECK(target_text_edit->get_text() == "dragdrag md test\ntee");
- CHECK_FALSE(text_edit->has_selection());
- CHECK(text_edit->get_caret_line() == 0);
- CHECK(text_edit->get_caret_column() == 4);
- CHECK(target_text_edit->has_selection());
- CHECK(target_text_edit->get_caret_line() == 0);
- CHECK(target_text_edit->get_caret_column() == 8);
- CHECK(target_text_edit->get_selection_origin_line() == 0);
- CHECK(target_text_edit->get_selection_origin_column() == 4);
- text_edit->set_editable(true);
- memdelete(target_text_edit);
- }
- SIGNAL_UNWATCH(text_edit, "text_set");
- SIGNAL_UNWATCH(text_edit, "text_changed");
- SIGNAL_UNWATCH(text_edit, "lines_edited_from");
- SIGNAL_UNWATCH(text_edit, "caret_changed");
- }
- SUBCASE("[TextEdit] overridable actions") {
- DisplayServerMock *DS = (DisplayServerMock *)(DisplayServer::get_singleton());
- SIGNAL_WATCH(text_edit, "text_set");
- SIGNAL_WATCH(text_edit, "text_changed");
- SIGNAL_WATCH(text_edit, "lines_edited_from");
- SIGNAL_WATCH(text_edit, "caret_changed");
- Array lines_edited_args = build_array(build_array(0, 0));
- SUBCASE("[TextEdit] backspace") {
- text_edit->set_text("this is\nsome\n");
- text_edit->set_caret_line(0);
- text_edit->set_caret_column(0);
- MessageQueue::get_singleton()->flush();
- SIGNAL_DISCARD("text_set");
- SIGNAL_DISCARD("text_changed");
- SIGNAL_DISCARD("lines_edited_from");
- SIGNAL_DISCARD("caret_changed");
- // Cannot backspace at start of text.
- text_edit->backspace();
- MessageQueue::get_singleton()->flush();
- SIGNAL_CHECK_FALSE("text_changed");
- SIGNAL_CHECK_FALSE("caret_changed");
- SIGNAL_CHECK_FALSE("lines_edited_from");
- // Backspace at start of line removes the line.
- text_edit->set_caret_line(2);
- text_edit->set_caret_column(0);
- MessageQueue::get_singleton()->flush();
- SIGNAL_DISCARD("caret_changed");
- lines_edited_args = build_array(build_array(2, 1));
- text_edit->backspace();
- MessageQueue::get_singleton()->flush();
- CHECK(text_edit->get_text() == "this is\nsome");
- CHECK(text_edit->get_caret_line() == 1);
- CHECK(text_edit->get_caret_column() == 4);
- SIGNAL_CHECK("caret_changed", empty_signal_args);
- SIGNAL_CHECK("text_changed", empty_signal_args);
- SIGNAL_CHECK("lines_edited_from", lines_edited_args);
- // Backspace removes a character.
- lines_edited_args = build_array(build_array(1, 1));
- text_edit->backspace();
- MessageQueue::get_singleton()->flush();
- CHECK(text_edit->get_text() == "this is\nsom");
- CHECK(text_edit->get_caret_line() == 1);
- CHECK(text_edit->get_caret_column() == 3);
- SIGNAL_CHECK("caret_changed", empty_signal_args);
- SIGNAL_CHECK("text_changed", empty_signal_args);
- SIGNAL_CHECK("lines_edited_from", lines_edited_args);
- // Backspace when text is selected removes the selection.
- text_edit->end_complex_operation();
- text_edit->select(1, 0, 1, 3);
- text_edit->backspace();
- MessageQueue::get_singleton()->flush();
- CHECK(text_edit->get_text() == "this is\n");
- CHECK(text_edit->get_caret_line() == 1);
- CHECK(text_edit->get_caret_column() == 0);
- SIGNAL_CHECK("caret_changed", empty_signal_args);
- SIGNAL_CHECK("text_changed", empty_signal_args);
- SIGNAL_CHECK("lines_edited_from", lines_edited_args);
- // Cannot backspace if not editable.
- text_edit->set_editable(false);
- text_edit->backspace();
- text_edit->set_editable(true);
- MessageQueue::get_singleton()->flush();
- CHECK(text_edit->get_text() == "this is\n");
- CHECK(text_edit->get_caret_line() == 1);
- CHECK(text_edit->get_caret_column() == 0);
- SIGNAL_CHECK_FALSE("text_changed");
- SIGNAL_CHECK_FALSE("caret_changed");
- SIGNAL_CHECK_FALSE("lines_edited_from");
- // Undo restores text to the previous end of complex operation.
- text_edit->undo();
- MessageQueue::get_singleton()->flush();
- CHECK(text_edit->get_text() == "this is\nsom");
- CHECK(text_edit->get_caret_line() == 1);
- CHECK(text_edit->get_caret_column() == 3);
- SIGNAL_CHECK("caret_changed", empty_signal_args);
- SIGNAL_CHECK("text_changed", empty_signal_args);
- SIGNAL_CHECK("lines_edited_from", lines_edited_args);
- // Redo.
- text_edit->redo();
- MessageQueue::get_singleton()->flush();
- CHECK(text_edit->get_text() == "this is\n");
- CHECK(text_edit->get_caret_line() == 1);
- CHECK(text_edit->get_caret_column() == 0);
- SIGNAL_CHECK("caret_changed", empty_signal_args);
- SIGNAL_CHECK("text_changed", empty_signal_args);
- SIGNAL_CHECK("lines_edited_from", lines_edited_args);
- // See ui_text_backspace for more backspace tests.
- }
- SUBCASE("[TextEdit] cut") {
- // Cut without a selection removes the entire line.
- text_edit->set_text("this is\nsome\n");
- text_edit->set_caret_line(0);
- text_edit->set_caret_column(6);
- MessageQueue::get_singleton()->flush();
- SIGNAL_DISCARD("text_set");
- SIGNAL_DISCARD("text_changed");
- SIGNAL_DISCARD("lines_edited_from");
- SIGNAL_DISCARD("caret_changed");
- lines_edited_args = build_array(build_array(1, 0));
- text_edit->cut();
- MessageQueue::get_singleton()->flush();
- CHECK(DS->clipboard_get() == "this is\n");
- CHECK(text_edit->get_text() == "some\n");
- CHECK(text_edit->get_caret_line() == 0);
- CHECK(text_edit->get_caret_column() == 3); // In the default font, this is the same position.
- SIGNAL_CHECK("caret_changed", empty_signal_args);
- SIGNAL_CHECK("text_changed", empty_signal_args);
- SIGNAL_CHECK("lines_edited_from", lines_edited_args);
- // Undo restores the cut text.
- text_edit->undo();
- MessageQueue::get_singleton()->flush();
- CHECK(DS->clipboard_get() == "this is\n");
- CHECK(text_edit->get_text() == "this is\nsome\n");
- CHECK(text_edit->get_caret_line() == 0);
- CHECK(text_edit->get_caret_column() == 6);
- SIGNAL_CHECK("caret_changed", empty_signal_args);
- SIGNAL_CHECK("text_changed", empty_signal_args);
- SIGNAL_CHECK("lines_edited_from", reverse_nested(lines_edited_args));
- // Redo.
- text_edit->redo();
- MessageQueue::get_singleton()->flush();
- CHECK(DS->clipboard_get() == "this is\n");
- CHECK(text_edit->get_text() == "some\n");
- CHECK(text_edit->get_caret_line() == 0);
- CHECK(text_edit->get_caret_column() == 3);
- SIGNAL_CHECK("caret_changed", empty_signal_args);
- SIGNAL_CHECK("text_changed", empty_signal_args);
- SIGNAL_CHECK("lines_edited_from", lines_edited_args);
- // Cut with a selection removes just the selection.
- text_edit->set_text("this is\nsome\n");
- text_edit->select(0, 5, 0, 7);
- MessageQueue::get_singleton()->flush();
- SIGNAL_DISCARD("text_set");
- SIGNAL_DISCARD("text_changed");
- SIGNAL_DISCARD("lines_edited_from");
- SIGNAL_DISCARD("caret_changed");
- lines_edited_args = build_array(build_array(0, 0));
- SEND_GUI_ACTION("ui_cut");
- CHECK(text_edit->get_viewport()->is_input_handled());
- MessageQueue::get_singleton()->flush();
- CHECK(DS->clipboard_get() == "is");
- CHECK(text_edit->get_text() == "this \nsome\n");
- CHECK_FALSE(text_edit->get_caret_line());
- CHECK(text_edit->get_caret_line() == 0);
- CHECK(text_edit->get_caret_column() == 5);
- SIGNAL_CHECK("caret_changed", empty_signal_args);
- SIGNAL_CHECK("text_changed", empty_signal_args);
- SIGNAL_CHECK("lines_edited_from", lines_edited_args);
- // Cut does not change the text if not editable. Text is still added to clipboard.
- text_edit->set_text("this is\nsome\n");
- text_edit->set_caret_line(0);
- text_edit->set_caret_column(5);
- MessageQueue::get_singleton()->flush();
- SIGNAL_DISCARD("text_set");
- SIGNAL_DISCARD("text_changed");
- SIGNAL_DISCARD("lines_edited_from");
- SIGNAL_DISCARD("caret_changed");
- text_edit->set_editable(false);
- text_edit->cut();
- MessageQueue::get_singleton()->flush();
- text_edit->set_editable(true);
- CHECK(DS->clipboard_get() == "this is\n");
- CHECK(text_edit->get_text() == "this is\nsome\n");
- CHECK(text_edit->get_caret_line() == 0);
- CHECK(text_edit->get_caret_column() == 5);
- SIGNAL_CHECK_FALSE("caret_changed");
- SIGNAL_CHECK_FALSE("text_changed");
- SIGNAL_CHECK_FALSE("lines_edited_from");
- // Cut line with multiple carets.
- text_edit->set_text("this is\nsome\n");
- text_edit->set_caret_line(0);
- text_edit->set_caret_column(3);
- text_edit->add_caret(0, 2);
- text_edit->add_caret(0, 4);
- text_edit->add_caret(2, 0);
- MessageQueue::get_singleton()->flush();
- SIGNAL_DISCARD("text_set");
- SIGNAL_DISCARD("text_changed");
- SIGNAL_DISCARD("lines_edited_from");
- SIGNAL_DISCARD("caret_changed");
- lines_edited_args = build_array(build_array(1, 0), build_array(1, 0));
- text_edit->cut();
- MessageQueue::get_singleton()->flush();
- CHECK(DS->clipboard_get() == "this is\n\n");
- CHECK(text_edit->get_text() == "some");
- CHECK(text_edit->get_caret_count() == 3);
- CHECK_FALSE(text_edit->has_selection(0));
- CHECK(text_edit->get_caret_line(0) == 0);
- CHECK(text_edit->get_caret_column(0) == 2); // In the default font, this is the same position.
- // The previous caret at index 1 was merged.
- CHECK_FALSE(text_edit->has_selection(1));
- CHECK(text_edit->get_caret_line(1) == 0);
- CHECK(text_edit->get_caret_column(1) == 3); // In the default font, this is the same position.
- CHECK_FALSE(text_edit->has_selection(2));
- CHECK(text_edit->get_caret_line(2) == 0);
- CHECK(text_edit->get_caret_column(2) == 4);
- SIGNAL_CHECK("caret_changed", empty_signal_args);
- SIGNAL_CHECK("text_changed", empty_signal_args);
- SIGNAL_CHECK("lines_edited_from", lines_edited_args);
- text_edit->remove_secondary_carets();
- // Cut on the only line removes the contents.
- text_edit->set_caret_line(0);
- text_edit->set_caret_column(2);
- MessageQueue::get_singleton()->flush();
- SIGNAL_DISCARD("caret_changed");
- lines_edited_args = build_array(build_array(0, 0));
- text_edit->cut();
- MessageQueue::get_singleton()->flush();
- CHECK(DS->clipboard_get() == "some\n");
- CHECK(text_edit->get_text() == "");
- CHECK(text_edit->get_line_count() == 1);
- CHECK(text_edit->get_caret_line() == 0);
- CHECK(text_edit->get_caret_column() == 0);
- SIGNAL_CHECK("caret_changed", empty_signal_args);
- SIGNAL_CHECK("text_changed", empty_signal_args);
- SIGNAL_CHECK("lines_edited_from", lines_edited_args);
- // Cut empty line.
- text_edit->cut();
- MessageQueue::get_singleton()->flush();
- CHECK(DS->clipboard_get() == "\n");
- CHECK(text_edit->get_text() == "");
- CHECK(text_edit->get_caret_line() == 0);
- CHECK(text_edit->get_caret_column() == 0);
- SIGNAL_CHECK_FALSE("caret_changed");
- // These signals are emitted even if there is no change.
- SIGNAL_CHECK("text_changed", empty_signal_args);
- SIGNAL_CHECK("lines_edited_from", lines_edited_args);
- // Cut multiple lines, in order.
- text_edit->set_text("this is\nsome\ntext to\nbe\n\ncut");
- text_edit->set_caret_line(2);
- text_edit->set_caret_column(7);
- text_edit->add_caret(3, 0);
- text_edit->add_caret(0, 2);
- MessageQueue::get_singleton()->flush();
- SIGNAL_DISCARD("text_set");
- SIGNAL_DISCARD("text_changed");
- SIGNAL_DISCARD("lines_edited_from");
- SIGNAL_DISCARD("caret_changed");
- lines_edited_args = build_array(build_array(1, 0), build_array(3, 2), build_array(2, 1));
- text_edit->cut();
- MessageQueue::get_singleton()->flush();
- CHECK(DS->clipboard_get() == "this is\ntext to\nbe\n");
- CHECK(text_edit->get_text() == "some\n\ncut");
- CHECK(text_edit->get_caret_count() == 2);
- CHECK(text_edit->get_caret_line(0) == 1);
- CHECK(text_edit->get_caret_column(0) == 0);
- CHECK(text_edit->get_caret_line(1) == 0);
- CHECK(text_edit->get_caret_column(1) == 2);
- SIGNAL_CHECK("caret_changed", empty_signal_args);
- SIGNAL_CHECK("text_changed", empty_signal_args);
- SIGNAL_CHECK("lines_edited_from", lines_edited_args);
- text_edit->remove_secondary_carets();
- // Cut multiple selections, in order. Ignores regular carets.
- text_edit->set_text("this is\nsome\ntext to\nbe\n\ncut");
- text_edit->add_caret(3, 0);
- text_edit->add_caret(0, 2);
- text_edit->add_caret(2, 0);
- text_edit->select(1, 0, 1, 2, 0);
- text_edit->select(3, 0, 4, 0, 1);
- text_edit->select(0, 5, 0, 3, 2);
- MessageQueue::get_singleton()->flush();
- SIGNAL_DISCARD("text_set");
- SIGNAL_DISCARD("text_changed");
- SIGNAL_DISCARD("lines_edited_from");
- SIGNAL_DISCARD("caret_changed");
- lines_edited_args = build_array(build_array(1, 1), build_array(4, 3), build_array(0, 0));
- text_edit->cut();
- MessageQueue::get_singleton()->flush();
- CHECK(DS->clipboard_get() == "s \nso\nbe\n");
- CHECK(text_edit->get_text() == "thiis\nme\ntext to\n\ncut");
- CHECK(text_edit->get_caret_count() == 4);
- CHECK_FALSE(text_edit->has_selection());
- CHECK(text_edit->get_caret_line(0) == 1);
- CHECK(text_edit->get_caret_column(0) == 0);
- CHECK(text_edit->get_caret_line(1) == 3);
- CHECK(text_edit->get_caret_column(1) == 0);
- CHECK(text_edit->get_caret_line(2) == 0);
- CHECK(text_edit->get_caret_column(2) == 3);
- CHECK(text_edit->get_caret_line(3) == 2);
- CHECK(text_edit->get_caret_column(3) == 0);
- SIGNAL_CHECK("caret_changed", empty_signal_args);
- SIGNAL_CHECK("text_changed", empty_signal_args);
- SIGNAL_CHECK("lines_edited_from", lines_edited_args);
- }
- SUBCASE("[TextEdit] copy") {
- text_edit->set_text("this is\nsome\ntest\n\ntext");
- MessageQueue::get_singleton()->flush();
- SIGNAL_DISCARD("text_set");
- SIGNAL_DISCARD("text_changed");
- SIGNAL_DISCARD("lines_edited_from");
- SIGNAL_DISCARD("caret_changed");
- // Copy selected text.
- text_edit->select(0, 0, 1, 2, 0);
- MessageQueue::get_singleton()->flush();
- SIGNAL_DISCARD("caret_changed");
- DS->clipboard_set_primary("");
- text_edit->copy();
- MessageQueue::get_singleton()->flush();
- CHECK(DS->clipboard_get() == "this is\nso");
- CHECK(DS->clipboard_get_primary() == "");
- CHECK(text_edit->get_text() == "this is\nsome\ntest\n\ntext");
- CHECK(text_edit->has_selection());
- CHECK(text_edit->get_selection_origin_line() == 0);
- CHECK(text_edit->get_selection_origin_column() == 0);
- CHECK(text_edit->get_caret_line() == 1);
- CHECK(text_edit->get_caret_column() == 2);
- SIGNAL_CHECK_FALSE("caret_changed");
- SIGNAL_CHECK_FALSE("text_changed");
- SIGNAL_CHECK_FALSE("lines_edited_from");
- // Copy with GUI action.
- text_edit->select(0, 0, 0, 2, 0);
- MessageQueue::get_singleton()->flush();
- SIGNAL_DISCARD("caret_changed");
- SEND_GUI_ACTION("ui_copy");
- MessageQueue::get_singleton()->flush();
- CHECK(DS->clipboard_get() == "th");
- SIGNAL_CHECK_FALSE("caret_changed");
- SIGNAL_CHECK_FALSE("text_changed");
- SIGNAL_CHECK_FALSE("lines_edited_from");
- // Can copy even if not editable.
- text_edit->select(2, 4, 1, 2, 0);
- MessageQueue::get_singleton()->flush();
- SIGNAL_DISCARD("caret_changed");
- text_edit->set_editable(false);
- text_edit->copy();
- text_edit->set_editable(true);
- MessageQueue::get_singleton()->flush();
- CHECK(DS->clipboard_get() == "me\ntest");
- SIGNAL_CHECK_FALSE("caret_changed");
- SIGNAL_CHECK_FALSE("text_changed");
- SIGNAL_CHECK_FALSE("lines_edited_from");
- text_edit->deselect();
- // Copy full line when there is no selection.
- text_edit->set_caret_line(0);
- text_edit->set_caret_column(2);
- MessageQueue::get_singleton()->flush();
- SIGNAL_DISCARD("caret_changed");
- text_edit->copy();
- MessageQueue::get_singleton()->flush();
- CHECK(DS->clipboard_get() == "this is\n");
- SIGNAL_CHECK_FALSE("caret_changed");
- SIGNAL_CHECK_FALSE("text_changed");
- SIGNAL_CHECK_FALSE("lines_edited_from");
- // Copy empty line.
- text_edit->set_caret_line(3);
- text_edit->set_caret_column(0);
- MessageQueue::get_singleton()->flush();
- SIGNAL_DISCARD("caret_changed");
- text_edit->copy();
- MessageQueue::get_singleton()->flush();
- CHECK(DS->clipboard_get() == "\n");
- SIGNAL_CHECK_FALSE("caret_changed");
- SIGNAL_CHECK_FALSE("text_changed");
- SIGNAL_CHECK_FALSE("lines_edited_from");
- text_edit->deselect();
- // Copy full line with multiple carets on that line only copies once.
- text_edit->set_caret_line(1);
- text_edit->set_caret_column(2);
- text_edit->add_caret(1, 0);
- text_edit->add_caret(1, 4);
- MessageQueue::get_singleton()->flush();
- SIGNAL_DISCARD("caret_changed");
- text_edit->copy();
- MessageQueue::get_singleton()->flush();
- CHECK(DS->clipboard_get() == "some\n");
- SIGNAL_CHECK_FALSE("caret_changed");
- SIGNAL_CHECK_FALSE("text_changed");
- SIGNAL_CHECK_FALSE("lines_edited_from");
- text_edit->remove_secondary_carets();
- // Copy selected text from all selections with `\n` in between, in order. Ignore regular carets.
- text_edit->set_caret_line(2);
- text_edit->set_caret_column(4);
- text_edit->add_caret(4, 0);
- text_edit->add_caret(0, 4);
- text_edit->add_caret(1, 0);
- text_edit->select(1, 3, 2, 4, 0);
- text_edit->select(4, 4, 4, 0, 1);
- text_edit->select(0, 5, 0, 4, 2);
- MessageQueue::get_singleton()->flush();
- SIGNAL_DISCARD("caret_changed");
- text_edit->copy();
- MessageQueue::get_singleton()->flush();
- CHECK(DS->clipboard_get() == " \ne\ntest\ntext");
- SIGNAL_CHECK_FALSE("caret_changed");
- SIGNAL_CHECK_FALSE("text_changed");
- SIGNAL_CHECK_FALSE("lines_edited_from");
- text_edit->remove_secondary_carets();
- text_edit->deselect();
- // Copy multiple lines with multiple carets, in order.
- text_edit->set_caret_line(3);
- text_edit->set_caret_column(0);
- text_edit->add_caret(4, 2);
- text_edit->add_caret(0, 4);
- MessageQueue::get_singleton()->flush();
- SIGNAL_DISCARD("caret_changed");
- text_edit->copy();
- MessageQueue::get_singleton()->flush();
- CHECK(DS->clipboard_get() == "this is\n\ntext\n");
- SIGNAL_CHECK_FALSE("caret_changed");
- SIGNAL_CHECK_FALSE("text_changed");
- SIGNAL_CHECK_FALSE("lines_edited_from");
- }
- SUBCASE("[TextEdit] paste") {
- // Paste text from clipboard at caret.
- text_edit->set_text("this is\nsome\n\ntext");
- text_edit->set_caret_line(1);
- text_edit->set_caret_column(2);
- MessageQueue::get_singleton()->flush();
- SIGNAL_DISCARD("text_set");
- SIGNAL_DISCARD("text_changed");
- SIGNAL_DISCARD("lines_edited_from");
- SIGNAL_DISCARD("caret_changed");
- lines_edited_args = build_array(build_array(1, 1));
- DS->clipboard_set("paste");
- text_edit->paste();
- MessageQueue::get_singleton()->flush();
- CHECK(DS->clipboard_get() == "paste");
- CHECK(text_edit->get_text() == "this is\nsopasteme\n\ntext");
- CHECK_FALSE(text_edit->has_selection());
- CHECK(text_edit->get_caret_line() == 1);
- CHECK(text_edit->get_caret_column() == 7);
- SIGNAL_CHECK("caret_changed", empty_signal_args);
- SIGNAL_CHECK("text_changed", empty_signal_args);
- SIGNAL_CHECK("lines_edited_from", lines_edited_args);
- // Undo.
- text_edit->undo();
- MessageQueue::get_singleton()->flush();
- CHECK(DS->clipboard_get() == "paste");
- CHECK(text_edit->get_text() == "this is\nsome\n\ntext");
- CHECK(text_edit->get_caret_line() == 1);
- CHECK(text_edit->get_caret_column() == 2);
- SIGNAL_CHECK("caret_changed", empty_signal_args);
- SIGNAL_CHECK("text_changed", empty_signal_args);
- SIGNAL_CHECK("lines_edited_from", lines_edited_args);
- // Redo.
- text_edit->redo();
- MessageQueue::get_singleton()->flush();
- CHECK(DS->clipboard_get() == "paste");
- CHECK(text_edit->get_text() == "this is\nsopasteme\n\ntext");
- CHECK(text_edit->get_caret_line() == 1);
- CHECK(text_edit->get_caret_column() == 7);
- SIGNAL_CHECK("caret_changed", empty_signal_args);
- SIGNAL_CHECK("text_changed", empty_signal_args);
- SIGNAL_CHECK("lines_edited_from", lines_edited_args);
- // Paste on empty line. Use GUI action.
- text_edit->set_text("this is\nsome\n\ntext");
- text_edit->set_caret_line(2);
- text_edit->set_caret_column(0);
- MessageQueue::get_singleton()->flush();
- SIGNAL_DISCARD("text_set");
- SIGNAL_DISCARD("text_changed");
- SIGNAL_DISCARD("lines_edited_from");
- SIGNAL_DISCARD("caret_changed");
- lines_edited_args = build_array(build_array(2, 2));
- DS->clipboard_set("paste2");
- SEND_GUI_ACTION("ui_paste");
- MessageQueue::get_singleton()->flush();
- CHECK(DS->clipboard_get() == "paste2");
- CHECK(text_edit->get_text() == "this is\nsome\npaste2\ntext");
- CHECK(text_edit->get_caret_line() == 2);
- CHECK(text_edit->get_caret_column() == 6);
- SIGNAL_CHECK("caret_changed", empty_signal_args);
- SIGNAL_CHECK("text_changed", empty_signal_args);
- SIGNAL_CHECK("lines_edited_from", lines_edited_args);
- // Paste removes selection before pasting.
- text_edit->set_text("this is\nsome\n\ntext");
- text_edit->select(0, 5, 1, 3);
- MessageQueue::get_singleton()->flush();
- SIGNAL_DISCARD("text_set");
- SIGNAL_DISCARD("text_changed");
- SIGNAL_DISCARD("lines_edited_from");
- SIGNAL_DISCARD("caret_changed");
- lines_edited_args = build_array(build_array(1, 0), build_array(0, 0));
- DS->clipboard_set("paste");
- text_edit->paste();
- MessageQueue::get_singleton()->flush();
- CHECK(DS->clipboard_get() == "paste");
- CHECK(text_edit->get_text() == "this pastee\n\ntext");
- CHECK_FALSE(text_edit->has_selection());
- CHECK(text_edit->get_caret_line() == 0);
- CHECK(text_edit->get_caret_column() == 10);
- SIGNAL_CHECK("caret_changed", empty_signal_args);
- SIGNAL_CHECK("text_changed", empty_signal_args);
- SIGNAL_CHECK("lines_edited_from", lines_edited_args);
- // Paste multiple lines.
- text_edit->set_text("this is\nsome\n\ntext");
- text_edit->set_caret_line(0);
- text_edit->set_caret_column(1);
- MessageQueue::get_singleton()->flush();
- SIGNAL_DISCARD("text_set");
- SIGNAL_DISCARD("text_changed");
- SIGNAL_DISCARD("lines_edited_from");
- SIGNAL_DISCARD("caret_changed");
- lines_edited_args = build_array(build_array(0, 3));
- DS->clipboard_set("multi\n\nline\npaste");
- text_edit->paste();
- MessageQueue::get_singleton()->flush();
- CHECK(DS->clipboard_get() == "multi\n\nline\npaste");
- CHECK(text_edit->get_text() == "tmulti\n\nline\npastehis is\nsome\n\ntext");
- CHECK(text_edit->get_caret_line() == 3);
- CHECK(text_edit->get_caret_column() == 5);
- SIGNAL_CHECK("caret_changed", empty_signal_args);
- SIGNAL_CHECK("text_changed", empty_signal_args);
- SIGNAL_CHECK("lines_edited_from", lines_edited_args);
- // Paste full line after copying it.
- text_edit->set_text("this is\nsome\n\ntext");
- text_edit->set_caret_line(1);
- text_edit->set_caret_column(2);
- MessageQueue::get_singleton()->flush();
- SIGNAL_DISCARD("text_set");
- SIGNAL_DISCARD("text_changed");
- SIGNAL_DISCARD("lines_edited_from");
- SIGNAL_DISCARD("caret_changed");
- lines_edited_args = build_array(build_array(1, 2));
- DS->clipboard_set("");
- text_edit->copy();
- text_edit->set_caret_column(3);
- CHECK(DS->clipboard_get() == "some\n");
- MessageQueue::get_singleton()->flush();
- SIGNAL_DISCARD("caret_changed");
- text_edit->paste();
- MessageQueue::get_singleton()->flush();
- CHECK(DS->clipboard_get() == "some\n");
- CHECK(text_edit->get_text() == "this is\nsome\nsome\n\ntext");
- CHECK(text_edit->get_caret_line() == 2);
- CHECK(text_edit->get_caret_column() == 3);
- SIGNAL_CHECK("caret_changed", empty_signal_args);
- SIGNAL_CHECK("text_changed", empty_signal_args);
- SIGNAL_CHECK("lines_edited_from", lines_edited_args);
- // Do not paste as line since it wasn't copied.
- text_edit->set_text("this is\nsome\n\ntext");
- text_edit->set_caret_line(0);
- text_edit->set_caret_column(4);
- MessageQueue::get_singleton()->flush();
- SIGNAL_DISCARD("text_set");
- SIGNAL_DISCARD("text_changed");
- SIGNAL_DISCARD("lines_edited_from");
- SIGNAL_DISCARD("caret_changed");
- lines_edited_args = build_array(build_array(0, 1));
- DS->clipboard_set("paste\n");
- text_edit->paste();
- MessageQueue::get_singleton()->flush();
- CHECK(DS->clipboard_get() == "paste\n");
- CHECK(text_edit->get_text() == "thispaste\n is\nsome\n\ntext");
- CHECK(text_edit->get_caret_line() == 1);
- CHECK(text_edit->get_caret_column() == 0);
- SIGNAL_CHECK("caret_changed", empty_signal_args);
- SIGNAL_CHECK("text_changed", empty_signal_args);
- SIGNAL_CHECK("lines_edited_from", lines_edited_args);
- // Paste text at each caret.
- text_edit->set_text("this is\nsome\n\ntext");
- text_edit->set_caret_line(1);
- text_edit->set_caret_column(2);
- text_edit->add_caret(3, 4);
- text_edit->add_caret(0, 4);
- MessageQueue::get_singleton()->flush();
- SIGNAL_DISCARD("text_set");
- SIGNAL_DISCARD("text_changed");
- SIGNAL_DISCARD("lines_edited_from");
- SIGNAL_DISCARD("caret_changed");
- lines_edited_args = build_array(build_array(0, 1), build_array(2, 3), build_array(5, 6));
- DS->clipboard_set("paste\ntest");
- text_edit->paste();
- MessageQueue::get_singleton()->flush();
- CHECK(DS->clipboard_get() == "paste\ntest");
- CHECK(text_edit->get_text() == "thispaste\ntest is\nsopaste\ntestme\n\ntextpaste\ntest");
- CHECK(text_edit->get_caret_count() == 3);
- CHECK(text_edit->get_caret_line(0) == 3);
- CHECK(text_edit->get_caret_column(0) == 4);
- CHECK(text_edit->get_caret_line(1) == 6);
- CHECK(text_edit->get_caret_column(1) == 4);
- CHECK(text_edit->get_caret_line(2) == 1);
- CHECK(text_edit->get_caret_column(2) == 4);
- SIGNAL_CHECK("caret_changed", empty_signal_args);
- SIGNAL_CHECK("text_changed", empty_signal_args);
- SIGNAL_CHECK("lines_edited_from", lines_edited_args);
- text_edit->remove_secondary_carets();
- // Paste line per caret when the amount of lines is equal to the number of carets.
- text_edit->set_text("this is\nsome\n\ntext");
- text_edit->set_caret_line(1);
- text_edit->set_caret_column(2);
- text_edit->add_caret(3, 4);
- text_edit->add_caret(0, 4);
- MessageQueue::get_singleton()->flush();
- SIGNAL_DISCARD("text_set");
- SIGNAL_DISCARD("text_changed");
- SIGNAL_DISCARD("lines_edited_from");
- SIGNAL_DISCARD("caret_changed");
- lines_edited_args = build_array(build_array(0, 0), build_array(1, 1), build_array(3, 3));
- DS->clipboard_set("paste\ntest\n1");
- text_edit->paste();
- MessageQueue::get_singleton()->flush();
- CHECK(DS->clipboard_get() == "paste\ntest\n1");
- CHECK(text_edit->get_text() == "thispaste is\nsotestme\n\ntext1");
- CHECK(text_edit->get_caret_count() == 3);
- CHECK(text_edit->get_caret_line(0) == 1);
- CHECK(text_edit->get_caret_column(0) == 6);
- CHECK(text_edit->get_caret_line(1) == 3);
- CHECK(text_edit->get_caret_column(1) == 5);
- CHECK(text_edit->get_caret_line(2) == 0);
- CHECK(text_edit->get_caret_column(2) == 9);
- SIGNAL_CHECK("caret_changed", empty_signal_args);
- SIGNAL_CHECK("text_changed", empty_signal_args);
- SIGNAL_CHECK("lines_edited_from", lines_edited_args);
- text_edit->remove_secondary_carets();
- // Cannot paste when not editable.
- text_edit->set_text("this is\nsome\n\ntext");
- text_edit->set_caret_line(0);
- text_edit->set_caret_column(4);
- MessageQueue::get_singleton()->flush();
- SIGNAL_DISCARD("text_set");
- SIGNAL_DISCARD("text_changed");
- SIGNAL_DISCARD("lines_edited_from");
- SIGNAL_DISCARD("caret_changed");
- DS->clipboard_set("no paste");
- text_edit->set_editable(false);
- text_edit->paste();
- text_edit->set_editable(true);
- MessageQueue::get_singleton()->flush();
- CHECK(DS->clipboard_get() == "no paste");
- CHECK(text_edit->get_text() == "this is\nsome\n\ntext");
- CHECK(text_edit->get_caret_line() == 0);
- CHECK(text_edit->get_caret_column() == 4);
- SIGNAL_CHECK_FALSE("caret_changed");
- SIGNAL_CHECK_FALSE("text_changed");
- SIGNAL_CHECK_FALSE("lines_edited_from");
- }
- SUBCASE("[TextEdit] paste primary") {
- // Set size for mouse input.
- text_edit->set_size(Size2(200, 200));
- text_edit->grab_focus();
- DS->clipboard_set("");
- DS->clipboard_set_primary("");
- CHECK(DS->clipboard_get_primary() == "");
- // Select text with mouse to put into primary clipboard.
- text_edit->set_text("this is\nsome\n\ntext");
- MessageQueue::get_singleton()->flush();
- SIGNAL_DISCARD("text_set");
- SIGNAL_DISCARD("text_changed");
- SIGNAL_DISCARD("lines_edited_from");
- SIGNAL_DISCARD("caret_changed");
- 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);
- SEND_GUI_MOUSE_MOTION_EVENT(text_edit->get_rect_at_line_column(1, 3).get_center() + Point2i(2, 0), MouseButtonMask::LEFT, Key::NONE);
- 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);
- CHECK(DS->clipboard_get() == "");
- CHECK(DS->clipboard_get_primary() == "is is\nsom");
- CHECK(text_edit->get_text() == "this is\nsome\n\ntext");
- CHECK(text_edit->has_selection());
- CHECK(text_edit->get_selected_text() == "is is\nsom");
- CHECK(text_edit->get_selection_origin_line() == 0);
- CHECK(text_edit->get_selection_origin_column() == 2);
- CHECK(text_edit->get_caret_line() == 1);
- CHECK(text_edit->get_caret_column() == 3);
- SIGNAL_CHECK_FALSE("text_set");
- SIGNAL_CHECK_FALSE("text_changed");
- SIGNAL_CHECK_FALSE("lines_edited_from");
- // Middle click to paste at mouse.
- SIGNAL_DISCARD("text_set");
- SIGNAL_DISCARD("text_changed");
- SIGNAL_DISCARD("lines_edited_from");
- SIGNAL_DISCARD("caret_changed");
- lines_edited_args = build_array(build_array(3, 4));
- 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);
- CHECK(DS->clipboard_get_primary() == "is is\nsom");
- CHECK(text_edit->get_text() == "this is\nsome\n\nteis is\nsomxt");
- CHECK_FALSE(text_edit->has_selection());
- CHECK(text_edit->get_caret_line() == 4);
- CHECK(text_edit->get_caret_column() == 3);
- SIGNAL_CHECK("caret_changed", empty_signal_args);
- SIGNAL_CHECK("text_changed", empty_signal_args);
- SIGNAL_CHECK("lines_edited_from", lines_edited_args);
- // Paste at mouse position if there is only one caret.
- text_edit->set_text("this is\nsome\n\ntext");
- SEND_GUI_MOUSE_MOTION_EVENT(text_edit->get_rect_at_line_column(0, 1).get_center() + Point2i(2, 0), MouseButtonMask::NONE, Key::NONE);
- MessageQueue::get_singleton()->flush();
- SIGNAL_DISCARD("text_set");
- SIGNAL_DISCARD("text_changed");
- SIGNAL_DISCARD("lines_edited_from");
- SIGNAL_DISCARD("caret_changed");
- DS->clipboard_set_primary("paste");
- lines_edited_args = build_array(build_array(0, 0));
- text_edit->paste_primary_clipboard();
- MessageQueue::get_singleton()->flush();
- CHECK(DS->clipboard_get_primary() == "paste");
- CHECK(text_edit->get_text() == "tpastehis is\nsome\n\ntext");
- CHECK_FALSE(text_edit->has_selection());
- CHECK(text_edit->get_caret_line() == 0);
- CHECK(text_edit->get_caret_column() == 6);
- SIGNAL_CHECK("caret_changed", empty_signal_args);
- SIGNAL_CHECK("text_changed", empty_signal_args);
- SIGNAL_CHECK("lines_edited_from", lines_edited_args);
- // Paste at all carets if there are multiple carets.
- text_edit->set_text("this is\nsome\n\ntext");
- text_edit->set_caret_line(1);
- text_edit->set_caret_column(0);
- text_edit->add_caret(2, 0);
- SEND_GUI_MOUSE_MOTION_EVENT(text_edit->get_rect_at_line_column(0, 1).get_center() + Point2i(2, 0), MouseButtonMask::NONE, Key::NONE);
- MessageQueue::get_singleton()->flush();
- SIGNAL_DISCARD("text_set");
- SIGNAL_DISCARD("text_changed");
- SIGNAL_DISCARD("lines_edited_from");
- SIGNAL_DISCARD("caret_changed");
- DS->clipboard_set_primary("paste");
- lines_edited_args = build_array(build_array(1, 1), build_array(2, 2));
- text_edit->paste_primary_clipboard();
- MessageQueue::get_singleton()->flush();
- CHECK(DS->clipboard_get_primary() == "paste");
- CHECK(text_edit->get_text() == "this is\npastesome\npaste\ntext");
- CHECK_FALSE(text_edit->has_selection());
- CHECK(text_edit->get_caret_count() == 2);
- CHECK(text_edit->get_caret_line(0) == 1);
- CHECK(text_edit->get_caret_column(0) == 5);
- CHECK(text_edit->get_caret_line(1) == 2);
- CHECK(text_edit->get_caret_column(1) == 5);
- SIGNAL_CHECK("caret_changed", empty_signal_args);
- SIGNAL_CHECK("text_changed", empty_signal_args);
- SIGNAL_CHECK("lines_edited_from", lines_edited_args);
- // Cannot paste if not editable.
- text_edit->set_text("this is\nsome\n\ntext");
- text_edit->set_caret_line(0);
- text_edit->set_caret_column(4);
- SEND_GUI_MOUSE_MOTION_EVENT(text_edit->get_rect_at_line_column(1, 3).get_center() + Point2i(2, 0), MouseButtonMask::NONE, Key::NONE);
- MessageQueue::get_singleton()->flush();
- SIGNAL_DISCARD("text_set");
- SIGNAL_DISCARD("text_changed");
- SIGNAL_DISCARD("lines_edited_from");
- SIGNAL_DISCARD("caret_changed");
- DS->clipboard_set("no paste");
- text_edit->set_editable(false);
- text_edit->paste_primary_clipboard();
- text_edit->set_editable(true);
- MessageQueue::get_singleton()->flush();
- CHECK(DS->clipboard_get() == "no paste");
- CHECK(text_edit->get_text() == "this is\nsome\n\ntext");
- CHECK(text_edit->get_caret_line() == 0);
- CHECK(text_edit->get_caret_column() == 4);
- SIGNAL_CHECK_FALSE("caret_changed");
- SIGNAL_CHECK_FALSE("text_changed");
- SIGNAL_CHECK_FALSE("lines_edited_from");
- }
- SUBCASE("[TextEdit] cut when empty selection clipboard disabled") {
- text_edit->set_empty_selection_clipboard_enabled(false);
- DS->clipboard_set("");
- text_edit->set_text("this is\nsome\n");
- text_edit->set_caret_line(0);
- text_edit->set_caret_column(6);
- MessageQueue::get_singleton()->flush();
- SIGNAL_DISCARD("text_set");
- SIGNAL_DISCARD("text_changed");
- SIGNAL_DISCARD("lines_edited_from");
- SIGNAL_DISCARD("caret_changed");
- text_edit->cut();
- MessageQueue::get_singleton()->flush();
- CHECK(DS->clipboard_get() == "");
- CHECK(text_edit->get_text() == "this is\nsome\n");
- CHECK(text_edit->get_caret_line() == 0);
- CHECK(text_edit->get_caret_column() == 6);
- SIGNAL_CHECK_FALSE("caret_changed");
- SIGNAL_CHECK_FALSE("text_changed");
- SIGNAL_CHECK_FALSE("lines_edited_from");
- }
- SUBCASE("[TextEdit] copy when empty selection clipboard disabled") {
- text_edit->set_empty_selection_clipboard_enabled(false);
- DS->clipboard_set("");
- text_edit->set_text("this is\nsome\n");
- text_edit->set_caret_line(0);
- text_edit->set_caret_column(6);
- MessageQueue::get_singleton()->flush();
- SIGNAL_DISCARD("text_set");
- SIGNAL_DISCARD("text_changed");
- SIGNAL_DISCARD("lines_edited_from");
- SIGNAL_DISCARD("caret_changed");
- text_edit->copy();
- MessageQueue::get_singleton()->flush();
- CHECK(DS->clipboard_get() == "");
- CHECK(text_edit->get_text() == "this is\nsome\n");
- CHECK(text_edit->get_caret_line() == 0);
- CHECK(text_edit->get_caret_column() == 6);
- SIGNAL_CHECK_FALSE("caret_changed");
- SIGNAL_CHECK_FALSE("text_changed");
- SIGNAL_CHECK_FALSE("lines_edited_from");
- }
- SIGNAL_UNWATCH(text_edit, "text_set");
- SIGNAL_UNWATCH(text_edit, "text_changed");
- SIGNAL_UNWATCH(text_edit, "lines_edited_from");
- SIGNAL_UNWATCH(text_edit, "caret_changed");
- }
- SUBCASE("[TextEdit] input") {
- SIGNAL_WATCH(text_edit, "text_set");
- SIGNAL_WATCH(text_edit, "text_changed");
- SIGNAL_WATCH(text_edit, "lines_edited_from");
- SIGNAL_WATCH(text_edit, "caret_changed");
- Array lines_edited_args = build_array(build_array(0, 0));
- SUBCASE("[TextEdit] ui_text_newline_above") {
- text_edit->set_text("this is some test text.\nthis is some test text.");
- MessageQueue::get_singleton()->flush();
- SIGNAL_DISCARD("text_set");
- SIGNAL_DISCARD("text_changed");
- SIGNAL_DISCARD("lines_edited_from");
- SIGNAL_DISCARD("caret_changed");
- // Insert new line above.
- text_edit->select(0, 0, 0, 4);
- text_edit->add_caret(1, 4);
- CHECK(text_edit->get_caret_count() == 2);
- MessageQueue::get_singleton()->flush();
- SIGNAL_DISCARD("caret_changed");
- lines_edited_args = build_array(build_array(0, 1), build_array(2, 3));
- SEND_GUI_ACTION("ui_text_newline_above");
- CHECK(text_edit->get_viewport()->is_input_handled());
- CHECK(text_edit->get_text() == "\nthis is some test text.\n\nthis is some test text.");
- CHECK_FALSE(text_edit->has_selection(0));
- CHECK(text_edit->get_caret_line(0) == 0);
- CHECK(text_edit->get_caret_column(0) == 0);
- CHECK_FALSE(text_edit->has_selection(1));
- CHECK(text_edit->get_caret_line(1) == 2);
- CHECK(text_edit->get_caret_column(1) == 0);
- SIGNAL_CHECK("caret_changed", empty_signal_args);
- SIGNAL_CHECK("text_changed", empty_signal_args);
- SIGNAL_CHECK("lines_edited_from", lines_edited_args);
- // Undo.
- text_edit->undo();
- MessageQueue::get_singleton()->flush();
- CHECK(text_edit->get_text() == "this is some test text.\nthis is some test text.");
- CHECK(text_edit->has_selection(0));
- CHECK(text_edit->get_caret_line(0) == 0);
- CHECK(text_edit->get_caret_column(0) == 4);
- CHECK(text_edit->get_selection_origin_line(0) == 0);
- CHECK(text_edit->get_selection_origin_column(0) == 0);
- CHECK_FALSE(text_edit->has_selection(1));
- CHECK(text_edit->get_caret_line(1) == 1);
- CHECK(text_edit->get_caret_column(1) == 4);
- SIGNAL_CHECK("caret_changed", empty_signal_args);
- SIGNAL_CHECK("text_changed", empty_signal_args);
- SIGNAL_CHECK("lines_edited_from", reverse_nested(lines_edited_args));
- // Redo.
- text_edit->redo();
- MessageQueue::get_singleton()->flush();
- CHECK(text_edit->get_text() == "\nthis is some test text.\n\nthis is some test text.");
- CHECK_FALSE(text_edit->has_selection(0));
- CHECK(text_edit->get_caret_line(0) == 0);
- CHECK(text_edit->get_caret_column(0) == 0);
- CHECK_FALSE(text_edit->has_selection(1));
- CHECK(text_edit->get_caret_line(1) == 2);
- CHECK(text_edit->get_caret_column(1) == 0);
- SIGNAL_CHECK("caret_changed", empty_signal_args);
- SIGNAL_CHECK("text_changed", empty_signal_args);
- SIGNAL_CHECK("lines_edited_from", lines_edited_args);
- // Does not work if not editable.
- text_edit->set_caret_line(1);
- text_edit->set_caret_column(4);
- text_edit->set_caret_line(3, false, true, -1, 1);
- text_edit->set_caret_column(4, false, 1);
- MessageQueue::get_singleton()->flush();
- SIGNAL_DISCARD("caret_changed");
- text_edit->set_editable(false);
- SEND_GUI_ACTION("ui_text_newline_above");
- CHECK(text_edit->get_viewport()->is_input_handled());
- CHECK(text_edit->get_text() == "\nthis is some test text.\n\nthis is some test text.");
- CHECK_FALSE(text_edit->has_selection(0));
- CHECK(text_edit->get_caret_line(0) == 1);
- CHECK(text_edit->get_caret_column(0) == 4);
- CHECK_FALSE(text_edit->has_selection(1));
- CHECK(text_edit->get_caret_line(1) == 3);
- CHECK(text_edit->get_caret_column(1) == 4);
- SIGNAL_CHECK_FALSE("caret_changed");
- SIGNAL_CHECK_FALSE("text_changed");
- SIGNAL_CHECK_FALSE("lines_edited_from");
- text_edit->set_editable(true);
- // Works on first line, empty lines, and only happens at caret for selections.
- text_edit->select(1, 10, 0, 0);
- MessageQueue::get_singleton()->flush();
- SIGNAL_DISCARD("caret_changed");
- lines_edited_args = build_array(build_array(0, 1), build_array(4, 5));
- SEND_GUI_ACTION("ui_text_newline_above");
- CHECK(text_edit->get_viewport()->is_input_handled());
- CHECK(text_edit->get_text() == "\n\nthis is some test text.\n\n\nthis is some test text.");
- CHECK_FALSE(text_edit->has_selection(0));
- CHECK(text_edit->get_caret_line(0) == 0);
- CHECK(text_edit->get_caret_column(0) == 0);
- CHECK_FALSE(text_edit->has_selection(1));
- CHECK(text_edit->get_caret_line(1) == 4);
- CHECK(text_edit->get_caret_column(1) == 0);
- SIGNAL_CHECK("caret_changed", empty_signal_args);
- SIGNAL_CHECK("text_changed", empty_signal_args);
- SIGNAL_CHECK("lines_edited_from", lines_edited_args);
- // Insert multiple new lines above from one line.
- text_edit->set_text("test");
- text_edit->set_caret_line(0);
- text_edit->set_caret_column(1);
- text_edit->add_caret(0, 3);
- MessageQueue::get_singleton()->flush();
- SIGNAL_DISCARD("text_set");
- SIGNAL_DISCARD("text_changed");
- SIGNAL_DISCARD("lines_edited_from");
- SIGNAL_DISCARD("caret_changed");
- lines_edited_args = build_array(build_array(0, 1), build_array(1, 2));
- SEND_GUI_ACTION("ui_text_newline_above");
- CHECK(text_edit->get_viewport()->is_input_handled());
- CHECK(text_edit->get_text() == "\n\ntest");
- CHECK_FALSE(text_edit->has_selection(0));
- CHECK(text_edit->get_caret_line(0) == 0);
- CHECK(text_edit->get_caret_column(0) == 0);
- CHECK_FALSE(text_edit->has_selection(1));
- CHECK(text_edit->get_caret_line(1) == 1);
- CHECK(text_edit->get_caret_column(1) == 0);
- SIGNAL_CHECK("caret_changed", empty_signal_args);
- SIGNAL_CHECK("text_changed", empty_signal_args);
- SIGNAL_CHECK("lines_edited_from", lines_edited_args);
- }
- SUBCASE("[TextEdit] ui_text_newline_blank") {
- text_edit->set_text("this is some test text.\nthis is some test text.");
- MessageQueue::get_singleton()->flush();
- SIGNAL_DISCARD("text_set");
- SIGNAL_DISCARD("text_changed");
- SIGNAL_DISCARD("lines_edited_from");
- // Insert new line below.
- text_edit->select(0, 0, 0, 4);
- text_edit->add_caret(1, 4);
- CHECK(text_edit->get_caret_count() == 2);
- MessageQueue::get_singleton()->flush();
- SIGNAL_DISCARD("caret_changed");
- lines_edited_args = build_array(build_array(0, 1), build_array(2, 3));
- SEND_GUI_ACTION("ui_text_newline_blank");
- CHECK(text_edit->get_viewport()->is_input_handled());
- CHECK(text_edit->get_text() == "this is some test text.\n\nthis is some test text.\n");
- CHECK_FALSE(text_edit->has_selection(0));
- CHECK(text_edit->get_caret_line(0) == 1);
- CHECK(text_edit->get_caret_column(0) == 0);
- CHECK_FALSE(text_edit->has_selection(1));
- CHECK(text_edit->get_caret_line(1) == 3);
- CHECK(text_edit->get_caret_column(1) == 0);
- SIGNAL_CHECK("caret_changed", empty_signal_args);
- SIGNAL_CHECK("text_changed", empty_signal_args);
- SIGNAL_CHECK("lines_edited_from", lines_edited_args);
- // Undo.
- text_edit->undo();
- MessageQueue::get_singleton()->flush();
- CHECK(text_edit->get_text() == "this is some test text.\nthis is some test text.");
- CHECK(text_edit->has_selection(0));
- CHECK(text_edit->get_caret_line(0) == 0);
- CHECK(text_edit->get_caret_column(0) == 4);
- CHECK(text_edit->get_selection_origin_line(0) == 0);
- CHECK(text_edit->get_selection_origin_column(0) == 0);
- CHECK_FALSE(text_edit->has_selection(1));
- CHECK(text_edit->get_caret_line(1) == 1);
- CHECK(text_edit->get_caret_column(1) == 4);
- SIGNAL_CHECK("caret_changed", empty_signal_args);
- SIGNAL_CHECK("text_changed", empty_signal_args);
- SIGNAL_CHECK("lines_edited_from", reverse_nested(lines_edited_args));
- // Redo.
- text_edit->redo();
- MessageQueue::get_singleton()->flush();
- CHECK(text_edit->get_text() == "this is some test text.\n\nthis is some test text.\n");
- CHECK(text_edit->get_caret_line(0) == 1);
- CHECK(text_edit->get_caret_column(0) == 0);
- CHECK_FALSE(text_edit->has_selection(0));
- CHECK(text_edit->get_caret_line(1) == 3);
- CHECK(text_edit->get_caret_column(1) == 0);
- CHECK_FALSE(text_edit->has_selection(1));
- SIGNAL_CHECK("caret_changed", empty_signal_args);
- SIGNAL_CHECK("text_changed", empty_signal_args);
- SIGNAL_CHECK("lines_edited_from", lines_edited_args);
- // Does not work if not editable.
- text_edit->set_editable(false);
- SEND_GUI_ACTION("ui_text_newline_blank");
- CHECK(text_edit->get_viewport()->is_input_handled());
- CHECK(text_edit->get_text() == "this is some test text.\n\nthis is some test text.\n");
- CHECK_FALSE(text_edit->has_selection(0));
- CHECK(text_edit->get_caret_line(0) == 1);
- CHECK(text_edit->get_caret_column(0) == 0);
- CHECK_FALSE(text_edit->has_selection(1));
- CHECK(text_edit->get_caret_line(1) == 3);
- CHECK(text_edit->get_caret_column(1) == 0);
- SIGNAL_CHECK_FALSE("caret_changed");
- SIGNAL_CHECK_FALSE("text_changed");
- SIGNAL_CHECK_FALSE("lines_edited_from");
- text_edit->set_editable(true);
- // Insert multiple new lines below from one line.
- text_edit->set_text("test");
- text_edit->set_caret_line(0);
- text_edit->set_caret_column(1);
- text_edit->add_caret(0, 3);
- MessageQueue::get_singleton()->flush();
- SIGNAL_DISCARD("text_set");
- SIGNAL_DISCARD("text_changed");
- SIGNAL_DISCARD("lines_edited_from");
- SIGNAL_DISCARD("caret_changed");
- lines_edited_args = build_array(build_array(0, 1), build_array(0, 1));
- SEND_GUI_ACTION("ui_text_newline_blank");
- CHECK(text_edit->get_viewport()->is_input_handled());
- CHECK(text_edit->get_text() == "test\n\n");
- CHECK_FALSE(text_edit->has_selection(0));
- CHECK(text_edit->get_caret_line(0) == 2);
- CHECK(text_edit->get_caret_column(0) == 0);
- CHECK_FALSE(text_edit->has_selection(1));
- CHECK(text_edit->get_caret_line(1) == 1);
- CHECK(text_edit->get_caret_column(1) == 0);
- SIGNAL_CHECK("caret_changed", empty_signal_args);
- SIGNAL_CHECK("text_changed", empty_signal_args);
- SIGNAL_CHECK("lines_edited_from", lines_edited_args);
- }
- SUBCASE("[TextEdit] ui_text_newline") {
- text_edit->set_text("this is some test text.\nthis is some test text.");
- MessageQueue::get_singleton()->flush();
- SIGNAL_DISCARD("text_set");
- SIGNAL_DISCARD("text_changed");
- SIGNAL_DISCARD("lines_edited_from");
- SIGNAL_DISCARD("caret_changed");
- // Insert new line at caret.
- text_edit->select(0, 0, 0, 4);
- text_edit->add_caret(1, 4);
- CHECK(text_edit->get_caret_count() == 2);
- MessageQueue::get_singleton()->flush();
- SIGNAL_DISCARD("caret_changed");
- // Lines edited: deletion, insert line, insert line.
- lines_edited_args = build_array(build_array(0, 0), build_array(0, 1), build_array(2, 3));
- SEND_GUI_ACTION("ui_text_newline");
- CHECK(text_edit->get_viewport()->is_input_handled());
- CHECK(text_edit->get_text() == "\n is some test text.\nthis\n is some test text.");
- CHECK_FALSE(text_edit->has_selection(0));
- CHECK(text_edit->get_caret_line(0) == 1);
- CHECK(text_edit->get_caret_column(0) == 0);
- CHECK_FALSE(text_edit->has_selection(1));
- CHECK(text_edit->get_caret_line(1) == 3);
- CHECK(text_edit->get_caret_column(1) == 0);
- SIGNAL_CHECK("caret_changed", empty_signal_args);
- SIGNAL_CHECK("text_changed", empty_signal_args);
- SIGNAL_CHECK("lines_edited_from", lines_edited_args);
- // Undo.
- text_edit->undo();
- MessageQueue::get_singleton()->flush();
- CHECK(text_edit->get_text() == "this is some test text.\nthis is some test text.");
- CHECK(text_edit->has_selection(0));
- CHECK(text_edit->get_caret_line(0) == 0);
- CHECK(text_edit->get_caret_column(0) == 4);
- CHECK(text_edit->get_selection_origin_line(0) == 0);
- CHECK(text_edit->get_selection_origin_column(0) == 0);
- CHECK_FALSE(text_edit->has_selection(1));
- CHECK(text_edit->get_caret_line(1) == 1);
- CHECK(text_edit->get_caret_column(1) == 4);
- SIGNAL_CHECK("caret_changed", empty_signal_args);
- SIGNAL_CHECK("text_changed", empty_signal_args);
- SIGNAL_CHECK("lines_edited_from", reverse_nested(lines_edited_args));
- // Redo.
- text_edit->redo();
- MessageQueue::get_singleton()->flush();
- CHECK(text_edit->get_text() == "\n is some test text.\nthis\n is some test text.");
- CHECK_FALSE(text_edit->has_selection(0));
- CHECK(text_edit->get_caret_line(0) == 1);
- CHECK(text_edit->get_caret_column(0) == 0);
- CHECK_FALSE(text_edit->has_selection(1));
- CHECK(text_edit->get_caret_line(1) == 3);
- CHECK(text_edit->get_caret_column(1) == 0);
- SIGNAL_CHECK("caret_changed", empty_signal_args);
- SIGNAL_CHECK("text_changed", empty_signal_args);
- SIGNAL_CHECK("lines_edited_from", lines_edited_args);
- // Does not work if not editable.
- text_edit->set_editable(false);
- SEND_GUI_ACTION("ui_text_newline");
- CHECK(text_edit->get_viewport()->is_input_handled());
- CHECK(text_edit->get_text() == "\n is some test text.\nthis\n is some test text.");
- CHECK_FALSE(text_edit->has_selection(0));
- CHECK(text_edit->get_caret_line(0) == 1);
- CHECK(text_edit->get_caret_column(0) == 0);
- CHECK_FALSE(text_edit->has_selection(1));
- CHECK(text_edit->get_caret_line(1) == 3);
- CHECK(text_edit->get_caret_column(1) == 0);
- SIGNAL_CHECK_FALSE("caret_changed");
- SIGNAL_CHECK_FALSE("text_changed");
- SIGNAL_CHECK_FALSE("lines_edited_from");
- text_edit->set_editable(true);
- }
- SUBCASE("[TextEdit] ui_text_backspace_all_to_left") {
- Ref<InputEvent> tmpevent = InputEventKey::create_reference(Key::BACKSPACE | KeyModifierMask::ALT | KeyModifierMask::CMD_OR_CTRL);
- InputMap::get_singleton()->action_add_event("ui_text_backspace_all_to_left", tmpevent);
- text_edit->set_text("\nthis is some test text.\n\nthis is some test text.");
- MessageQueue::get_singleton()->flush();
- SIGNAL_DISCARD("text_set");
- SIGNAL_DISCARD("text_changed");
- SIGNAL_DISCARD("lines_edited_from");
- SIGNAL_DISCARD("caret_changed");
- // Remove all text to the left.
- text_edit->set_caret_line(1);
- text_edit->set_caret_column(5);
- text_edit->add_caret(1, 2);
- text_edit->add_caret(1, 8);
- lines_edited_args = build_array(build_array(1, 1));
- MessageQueue::get_singleton()->flush();
- SIGNAL_DISCARD("caret_changed");
- SEND_GUI_ACTION("ui_text_backspace_all_to_left");
- CHECK(text_edit->get_viewport()->is_input_handled());
- CHECK(text_edit->get_text() == "\nsome test text.\n\nthis is some test text.");
- CHECK(text_edit->get_caret_count() == 1);
- CHECK_FALSE(text_edit->has_selection());
- CHECK(text_edit->get_caret_line() == 1);
- CHECK(text_edit->get_caret_column() == 0);
- SIGNAL_CHECK("caret_changed", empty_signal_args);
- SIGNAL_CHECK("text_changed", empty_signal_args);
- SIGNAL_CHECK("lines_edited_from", lines_edited_args);
- // Undo.
- text_edit->undo();
- MessageQueue::get_singleton()->flush();
- CHECK(text_edit->get_text() == "\nthis is some test text.\n\nthis is some test text.");
- CHECK(text_edit->get_caret_count() == 3);
- CHECK_FALSE(text_edit->has_selection(0));
- CHECK(text_edit->get_caret_line(0) == 1);
- CHECK(text_edit->get_caret_column(0) == 5);
- CHECK_FALSE(text_edit->has_selection(1));
- CHECK(text_edit->get_caret_line(1) == 1);
- CHECK(text_edit->get_caret_column(1) == 2);
- CHECK_FALSE(text_edit->has_selection(2));
- CHECK(text_edit->get_caret_line(2) == 1);
- CHECK(text_edit->get_caret_column(2) == 8);
- SIGNAL_CHECK("caret_changed", empty_signal_args);
- SIGNAL_CHECK("text_changed", empty_signal_args);
- SIGNAL_CHECK("lines_edited_from", lines_edited_args);
- // Redo.
- text_edit->redo();
- MessageQueue::get_singleton()->flush();
- CHECK(text_edit->get_text() == "\nsome test text.\n\nthis is some test text.");
- CHECK(text_edit->get_caret_count() == 1);
- CHECK_FALSE(text_edit->has_selection());
- CHECK(text_edit->get_caret_line() == 1);
- CHECK(text_edit->get_caret_column() == 0);
- SIGNAL_CHECK("caret_changed", empty_signal_args);
- SIGNAL_CHECK("text_changed", empty_signal_args);
- SIGNAL_CHECK("lines_edited_from", lines_edited_args);
- // Acts as a normal backspace with selections.
- text_edit->select(1, 5, 1, 9, 0);
- text_edit->add_caret(3, 4);
- text_edit->select(3, 7, 3, 4, 1);
- MessageQueue::get_singleton()->flush();
- SIGNAL_DISCARD("caret_changed");
- lines_edited_args = build_array(build_array(3, 3), build_array(1, 1));
- SEND_GUI_ACTION("ui_text_backspace_all_to_left");
- CHECK(text_edit->get_viewport()->is_input_handled());
- CHECK(text_edit->get_text() == "\nsome text.\n\nthis some test text.");
- CHECK(text_edit->get_caret_count() == 2);
- CHECK_FALSE(text_edit->has_selection(0));
- CHECK(text_edit->get_caret_line(0) == 1);
- CHECK(text_edit->get_caret_column(0) == 5);
- CHECK_FALSE(text_edit->has_selection(1));
- CHECK(text_edit->get_caret_line(1) == 3);
- CHECK(text_edit->get_caret_column(1) == 4);
- SIGNAL_CHECK("caret_changed", empty_signal_args);
- SIGNAL_CHECK("text_changed", empty_signal_args);
- SIGNAL_CHECK("lines_edited_from", lines_edited_args);
- // Acts as a normal backspace when at the start of a line.
- text_edit->set_caret_column(0);
- text_edit->set_caret_column(0, false, 1);
- MessageQueue::get_singleton()->flush();
- SIGNAL_DISCARD("caret_changed");
- lines_edited_args = build_array(build_array(3, 2), build_array(1, 0));
- SEND_GUI_ACTION("ui_text_backspace_all_to_left");
- CHECK(text_edit->get_viewport()->is_input_handled());
- CHECK(text_edit->get_text() == "some text.\nthis some test text.");
- CHECK(text_edit->get_caret_count() == 2);
- CHECK_FALSE(text_edit->has_selection(0));
- CHECK(text_edit->get_caret_line(0) == 0);
- CHECK(text_edit->get_caret_column(0) == 0);
- CHECK_FALSE(text_edit->has_selection(1));
- CHECK(text_edit->get_caret_line(1) == 1);
- CHECK(text_edit->get_caret_column(1) == 0);
- SIGNAL_CHECK("caret_changed", empty_signal_args);
- SIGNAL_CHECK("text_changed", empty_signal_args);
- SIGNAL_CHECK("lines_edited_from", lines_edited_args);
- // Does not work if not editable.
- text_edit->set_caret_column(text_edit->get_line(0).length());
- text_edit->set_caret_column(text_edit->get_line(1).length(), false, 1);
- MessageQueue::get_singleton()->flush();
- SIGNAL_DISCARD("caret_changed");
- text_edit->set_editable(false);
- SEND_GUI_ACTION("ui_text_backspace_all_to_left");
- CHECK(text_edit->get_viewport()->is_input_handled());
- CHECK(text_edit->get_text() == "some text.\nthis some test text.");
- CHECK(text_edit->get_caret_count() == 2);
- CHECK_FALSE(text_edit->has_selection(0));
- CHECK(text_edit->get_caret_line(0) == 0);
- CHECK(text_edit->get_caret_column(0) == text_edit->get_line(0).length());
- CHECK_FALSE(text_edit->has_selection(1));
- CHECK(text_edit->get_caret_line(1) == 1);
- CHECK(text_edit->get_caret_column(1) == text_edit->get_line(1).length());
- SIGNAL_CHECK_FALSE("caret_changed");
- SIGNAL_CHECK_FALSE("text_changed");
- SIGNAL_CHECK_FALSE("lines_edited_from");
- text_edit->set_editable(true);
- // Remove entire line content when at the end of the line.
- lines_edited_args = build_array(build_array(1, 1), build_array(0, 0));
- SEND_GUI_ACTION("ui_text_backspace_all_to_left");
- CHECK(text_edit->get_viewport()->is_input_handled());
- CHECK(text_edit->get_text() == "\n");
- CHECK(text_edit->get_caret_count() == 2);
- CHECK_FALSE(text_edit->has_selection(0));
- CHECK(text_edit->get_caret_line(0) == 0);
- CHECK(text_edit->get_caret_column(0) == 0);
- CHECK_FALSE(text_edit->has_selection(1));
- CHECK(text_edit->get_caret_line(1) == 1);
- CHECK(text_edit->get_caret_column(1) == 0);
- SIGNAL_CHECK("caret_changed", empty_signal_args);
- SIGNAL_CHECK("text_changed", empty_signal_args);
- SIGNAL_CHECK("lines_edited_from", lines_edited_args);
- text_edit->remove_secondary_carets();
- // Removing newline effectively happens after removing text.
- text_edit->set_text("test\nlines");
- text_edit->set_caret_line(1);
- text_edit->set_caret_column(0);
- text_edit->add_caret(1, 4);
- SEND_GUI_ACTION("ui_text_backspace_all_to_left");
- CHECK(text_edit->get_viewport()->is_input_handled());
- CHECK_FALSE(text_edit->has_selection());
- CHECK(text_edit->get_text() == "tests");
- CHECK(text_edit->get_caret_count() == 1);
- CHECK(text_edit->get_caret_line(0) == 0);
- CHECK(text_edit->get_caret_column(0) == 4);
- text_edit->remove_secondary_carets();
- // Removing newline effectively happens after removing text, reverse caret order.
- text_edit->set_text("test\nlines");
- text_edit->set_caret_line(1);
- text_edit->set_caret_column(4);
- text_edit->add_caret(1, 0);
- SEND_GUI_ACTION("ui_text_backspace_all_to_left");
- CHECK(text_edit->get_viewport()->is_input_handled());
- CHECK_FALSE(text_edit->has_selection());
- CHECK(text_edit->get_text() == "tests");
- CHECK(text_edit->get_caret_count() == 1);
- CHECK(text_edit->get_caret_line(0) == 0);
- CHECK(text_edit->get_caret_column(0) == 4);
- text_edit->remove_secondary_carets();
- InputMap::get_singleton()->action_erase_event("ui_text_backspace_all_to_left", tmpevent);
- }
- SUBCASE("[TextEdit] ui_text_backspace_word") {
- text_edit->set_text("\nthis is some test text.\n\nthis is some test text.");
- MessageQueue::get_singleton()->flush();
- SIGNAL_DISCARD("text_set");
- SIGNAL_DISCARD("text_changed");
- SIGNAL_DISCARD("lines_edited_from");
- // Acts as a normal backspace with selections.
- text_edit->select(1, 8, 1, 15);
- text_edit->add_caret(3, 6);
- text_edit->select(3, 10, 3, 6, 1);
- MessageQueue::get_singleton()->flush();
- SIGNAL_DISCARD("caret_changed");
- lines_edited_args = build_array(build_array(3, 3), build_array(1, 1));
- SEND_GUI_ACTION("ui_text_backspace_word");
- CHECK(text_edit->get_viewport()->is_input_handled());
- CHECK(text_edit->get_text() == "\nthis is st text.\n\nthis ime test text.");
- CHECK(text_edit->get_caret_count() == 2);
- CHECK_FALSE(text_edit->has_selection(0));
- CHECK(text_edit->get_caret_line(0) == 1);
- CHECK(text_edit->get_caret_column(0) == 8);
- CHECK_FALSE(text_edit->has_selection(1));
- CHECK(text_edit->get_caret_line(1) == 3);
- CHECK(text_edit->get_caret_column(1) == 6);
- SIGNAL_CHECK("caret_changed", empty_signal_args);
- SIGNAL_CHECK("text_changed", empty_signal_args);
- SIGNAL_CHECK("lines_edited_from", lines_edited_args);
- text_edit->end_complex_operation();
- lines_edited_args = build_array(build_array(3, 2), build_array(1, 0));
- // Start of line should also be a normal backspace.
- text_edit->set_caret_column(0);
- text_edit->set_caret_column(0, false, 1);
- MessageQueue::get_singleton()->flush();
- SIGNAL_DISCARD("caret_changed");
- SEND_GUI_ACTION("ui_text_backspace_word");
- CHECK(text_edit->get_viewport()->is_input_handled());
- CHECK(text_edit->get_text() == "this is st text.\nthis ime test text.");
- CHECK(text_edit->get_caret_count() == 2);
- CHECK_FALSE(text_edit->has_selection(0));
- CHECK(text_edit->get_caret_line(0) == 0);
- CHECK(text_edit->get_caret_column(0) == 0);
- CHECK_FALSE(text_edit->has_selection(1));
- CHECK(text_edit->get_caret_line(1) == 1);
- CHECK(text_edit->get_caret_column(1) == 0);
- SIGNAL_CHECK("caret_changed", empty_signal_args);
- SIGNAL_CHECK("text_changed", empty_signal_args);
- SIGNAL_CHECK("lines_edited_from", lines_edited_args);
- // Does not work if not editable.
- text_edit->set_editable(false);
- SEND_GUI_ACTION("ui_text_backspace_word");
- CHECK(text_edit->get_viewport()->is_input_handled());
- CHECK(text_edit->get_text() == "this is st text.\nthis ime test text.");
- CHECK(text_edit->get_caret_count() == 2);
- CHECK_FALSE(text_edit->has_selection(0));
- CHECK(text_edit->get_caret_line(0) == 0);
- CHECK(text_edit->get_caret_column(0) == 0);
- CHECK_FALSE(text_edit->has_selection(1));
- CHECK(text_edit->get_caret_line(1) == 1);
- CHECK(text_edit->get_caret_column(1) == 0);
- SIGNAL_CHECK_FALSE("caret_changed");
- SIGNAL_CHECK_FALSE("text_changed");
- SIGNAL_CHECK_FALSE("lines_edited_from");
- text_edit->set_editable(true);
- // FIXME: Remove after GH-77101 is fixed.
- text_edit->start_action(TextEdit::ACTION_NONE);
- // Remove text to the start of the word to the left of the caret.
- text_edit->set_caret_column(text_edit->get_line(0).length());
- text_edit->set_caret_column(12, false, 1);
- MessageQueue::get_singleton()->flush();
- SIGNAL_DISCARD("caret_changed");
- lines_edited_args = build_array(build_array(1, 1), build_array(0, 0));
- SEND_GUI_ACTION("ui_text_backspace_word");
- CHECK(text_edit->get_viewport()->is_input_handled());
- CHECK(text_edit->get_text() == "this is st \nthis ime t text.");
- CHECK(text_edit->get_caret_count() == 2);
- CHECK_FALSE(text_edit->has_selection(0));
- CHECK(text_edit->get_caret_line(0) == 0);
- CHECK(text_edit->get_caret_column(0) == 11);
- CHECK_FALSE(text_edit->has_selection(1));
- CHECK(text_edit->get_caret_line(1) == 1);
- CHECK(text_edit->get_caret_column(1) == 9);
- SIGNAL_CHECK("caret_changed", empty_signal_args);
- SIGNAL_CHECK("text_changed", empty_signal_args);
- SIGNAL_CHECK("lines_edited_from", lines_edited_args);
- // Undo.
- text_edit->undo();
- MessageQueue::get_singleton()->flush();
- CHECK(text_edit->get_text() == "this is st text.\nthis ime test text.");
- CHECK(text_edit->get_caret_count() == 2);
- CHECK_FALSE(text_edit->has_selection(0));
- CHECK(text_edit->get_caret_line(0) == 0);
- CHECK(text_edit->get_caret_column(0) == 16);
- CHECK_FALSE(text_edit->has_selection(1));
- CHECK(text_edit->get_caret_line(1) == 1);
- CHECK(text_edit->get_caret_column(1) == 12);
- SIGNAL_CHECK("caret_changed", empty_signal_args);
- SIGNAL_CHECK("text_changed", empty_signal_args);
- SIGNAL_CHECK("lines_edited_from", reverse_nested(lines_edited_args));
- // Redo.
- text_edit->redo();
- MessageQueue::get_singleton()->flush();
- CHECK(text_edit->get_text() == "this is st \nthis ime t text.");
- CHECK(text_edit->get_caret_count() == 2);
- CHECK_FALSE(text_edit->has_selection(0));
- CHECK(text_edit->get_caret_line(0) == 0);
- CHECK(text_edit->get_caret_column(0) == 11);
- CHECK_FALSE(text_edit->has_selection(1));
- CHECK(text_edit->get_caret_line(1) == 1);
- CHECK(text_edit->get_caret_column(1) == 9);
- SIGNAL_CHECK("caret_changed", empty_signal_args);
- SIGNAL_CHECK("text_changed", empty_signal_args);
- SIGNAL_CHECK("lines_edited_from", lines_edited_args);
- // Removing newline effectively happens after removing text.
- text_edit->set_text("test\nlines");
- text_edit->set_caret_line(1);
- text_edit->set_caret_column(0);
- text_edit->add_caret(1, 4);
- SEND_GUI_ACTION("ui_text_backspace_word");
- CHECK(text_edit->get_viewport()->is_input_handled());
- CHECK_FALSE(text_edit->has_selection());
- CHECK(text_edit->get_text() == "tests");
- CHECK(text_edit->get_caret_count() == 1);
- CHECK(text_edit->get_caret_line(0) == 0);
- CHECK(text_edit->get_caret_column(0) == 4);
- text_edit->remove_secondary_carets();
- // Removing newline effectively happens after removing text, reverse caret order.
- text_edit->set_text("test\nlines");
- text_edit->set_caret_line(1);
- text_edit->set_caret_column(4);
- text_edit->add_caret(1, 0);
- SEND_GUI_ACTION("ui_text_backspace_word");
- CHECK(text_edit->get_viewport()->is_input_handled());
- CHECK_FALSE(text_edit->has_selection());
- CHECK(text_edit->get_text() == "tests");
- CHECK(text_edit->get_caret_count() == 1);
- CHECK(text_edit->get_caret_line(0) == 0);
- CHECK(text_edit->get_caret_column(0) == 4);
- text_edit->remove_secondary_carets();
- // Remove when there are no words, only symbols.
- text_edit->set_text("#{}");
- text_edit->set_caret_line(0);
- text_edit->set_caret_column(3);
- SEND_GUI_ACTION("ui_text_backspace_word");
- CHECK(text_edit->get_viewport()->is_input_handled());
- CHECK_FALSE(text_edit->has_selection());
- CHECK(text_edit->get_text() == "");
- CHECK(text_edit->get_caret_line(0) == 0);
- CHECK(text_edit->get_caret_column(0) == 0);
- }
- SUBCASE("[TextEdit] ui_text_backspace_word same line") {
- text_edit->set_text("test longwordtest test");
- MessageQueue::get_singleton()->flush();
- SIGNAL_DISCARD("text_set");
- SIGNAL_DISCARD("text_changed");
- SIGNAL_DISCARD("lines_edited_from");
- SIGNAL_DISCARD("caret_changed");
- // Multiple carets on the same line is handled.
- text_edit->set_caret_line(0);
- text_edit->set_caret_column(4);
- text_edit->add_caret(0, 11);
- text_edit->add_caret(0, 15);
- text_edit->add_caret(0, 9);
- MessageQueue::get_singleton()->flush();
- SIGNAL_DISCARD("caret_changed");
- lines_edited_args = build_array(build_array(0, 0), build_array(0, 0));
- SEND_GUI_ACTION("ui_text_backspace_word");
- CHECK(text_edit->get_viewport()->is_input_handled());
- CHECK(text_edit->get_text() == " st test");
- CHECK(text_edit->get_caret_count() == 2);
- CHECK_FALSE(text_edit->has_selection(0));
- CHECK(text_edit->get_caret_line(0) == 0);
- CHECK(text_edit->get_caret_column(0) == 0);
- CHECK_FALSE(text_edit->has_selection(1));
- CHECK(text_edit->get_caret_line(1) == 0);
- CHECK(text_edit->get_caret_column(1) == 1);
- SIGNAL_CHECK("caret_changed", empty_signal_args);
- SIGNAL_CHECK("text_changed", empty_signal_args);
- SIGNAL_CHECK("lines_edited_from", lines_edited_args);
- text_edit->undo();
- MessageQueue::get_singleton()->flush();
- CHECK(text_edit->get_text() == "test longwordtest test");
- CHECK(text_edit->get_caret_count() == 4);
- CHECK_FALSE(text_edit->has_selection(0));
- CHECK(text_edit->get_caret_line(0) == 0);
- CHECK(text_edit->get_caret_column(0) == 4);
- CHECK_FALSE(text_edit->has_selection(1));
- CHECK(text_edit->get_caret_line(1) == 0);
- CHECK(text_edit->get_caret_column(1) == 11);
- CHECK_FALSE(text_edit->has_selection(2));
- CHECK(text_edit->get_caret_line(2) == 0);
- CHECK(text_edit->get_caret_column(2) == 15);
- CHECK_FALSE(text_edit->has_selection(3));
- CHECK(text_edit->get_caret_line(3) == 0);
- CHECK(text_edit->get_caret_column(3) == 9);
- SIGNAL_CHECK("caret_changed", empty_signal_args);
- SIGNAL_CHECK("text_changed", empty_signal_args);
- SIGNAL_CHECK("lines_edited_from", reverse_nested(lines_edited_args));
- text_edit->redo();
- MessageQueue::get_singleton()->flush();
- CHECK(text_edit->get_text() == " st test");
- CHECK(text_edit->get_caret_count() == 2);
- CHECK_FALSE(text_edit->has_selection(0));
- CHECK(text_edit->get_caret_line(0) == 0);
- CHECK(text_edit->get_caret_column(0) == 0);
- CHECK_FALSE(text_edit->has_selection(1));
- CHECK(text_edit->get_caret_line(1) == 0);
- CHECK(text_edit->get_caret_column(1) == 1);
- SIGNAL_CHECK("caret_changed", empty_signal_args);
- SIGNAL_CHECK("text_changed", empty_signal_args);
- SIGNAL_CHECK("lines_edited_from", lines_edited_args);
- }
- SUBCASE("[TextEdit] ui_text_backspace") {
- text_edit->set_text("\nthis is some test text.\n\nthis is some test text.");
- MessageQueue::get_singleton()->flush();
- SIGNAL_DISCARD("text_set");
- SIGNAL_DISCARD("text_changed");
- SIGNAL_DISCARD("lines_edited_from");
- // Remove selected text when there are selections.
- text_edit->select(1, 0, 1, 4);
- text_edit->add_caret(3, 4);
- text_edit->select(3, 5, 3, 2, 1);
- MessageQueue::get_singleton()->flush();
- SIGNAL_DISCARD("caret_changed");
- lines_edited_args = build_array(build_array(3, 3), build_array(1, 1));
- SEND_GUI_ACTION("ui_text_backspace");
- CHECK(text_edit->get_viewport()->is_input_handled());
- CHECK(text_edit->get_text() == "\n is some test text.\n\nthis some test text.");
- CHECK(text_edit->get_caret_count() == 2);
- CHECK_FALSE(text_edit->has_selection(0));
- CHECK(text_edit->get_caret_line(0) == 1);
- CHECK(text_edit->get_caret_column(0) == 0);
- CHECK_FALSE(text_edit->has_selection(1));
- CHECK(text_edit->get_caret_line(1) == 3);
- CHECK(text_edit->get_caret_column(1) == 2);
- SIGNAL_CHECK("caret_changed", empty_signal_args);
- SIGNAL_CHECK("text_changed", empty_signal_args);
- SIGNAL_CHECK("lines_edited_from", lines_edited_args);
- // Undo remove selection.
- text_edit->undo();
- MessageQueue::get_singleton()->flush();
- CHECK(text_edit->get_caret_count() == 2);
- CHECK(text_edit->get_text() == "\nthis is some test text.\n\nthis is some test text.");
- CHECK(text_edit->get_caret_count() == 2);
- CHECK(text_edit->has_selection(0));
- CHECK(text_edit->get_caret_line(0) == 1);
- CHECK(text_edit->get_caret_column(0) == 4);
- CHECK(text_edit->get_selection_origin_line(0) == 1);
- CHECK(text_edit->get_selection_origin_column(0) == 0);
- CHECK(text_edit->has_selection(1));
- CHECK(text_edit->get_caret_line(1) == 3);
- CHECK(text_edit->get_caret_column(1) == 2);
- CHECK(text_edit->get_selection_origin_line(1) == 3);
- CHECK(text_edit->get_selection_origin_column(1) == 5);
- SIGNAL_CHECK("caret_changed", empty_signal_args);
- SIGNAL_CHECK("text_changed", empty_signal_args);
- SIGNAL_CHECK("lines_edited_from", reverse_nested(lines_edited_args));
- // Redo remove selection.
- text_edit->redo();
- MessageQueue::get_singleton()->flush();
- CHECK(text_edit->get_text() == "\n is some test text.\n\nthis some test text.");
- CHECK(text_edit->get_caret_count() == 2);
- CHECK_FALSE(text_edit->has_selection(0));
- CHECK(text_edit->get_caret_line(0) == 1);
- CHECK(text_edit->get_caret_column(0) == 0);
- CHECK_FALSE(text_edit->has_selection(1));
- CHECK(text_edit->get_caret_line(1) == 3);
- CHECK(text_edit->get_caret_column(1) == 2);
- SIGNAL_CHECK("caret_changed", empty_signal_args);
- SIGNAL_CHECK("text_changed", empty_signal_args);
- SIGNAL_CHECK("lines_edited_from", lines_edited_args);
- // Remove the newline when at start of line.
- text_edit->set_caret_column(0, false, 1);
- MessageQueue::get_singleton()->flush();
- SIGNAL_DISCARD("caret_changed");
- lines_edited_args = build_array(build_array(3, 2), build_array(1, 0));
- SEND_GUI_ACTION("ui_text_backspace");
- CHECK(text_edit->get_viewport()->is_input_handled());
- CHECK(text_edit->get_text() == " is some test text.\nthis some test text.");
- CHECK(text_edit->get_caret_count() == 2);
- CHECK_FALSE(text_edit->has_selection(0));
- CHECK(text_edit->get_caret_line(0) == 0);
- CHECK(text_edit->get_caret_column(0) == 0);
- CHECK_FALSE(text_edit->has_selection(1));
- CHECK(text_edit->get_caret_line(1) == 1);
- CHECK(text_edit->get_caret_column(1) == 0);
- SIGNAL_CHECK("caret_changed", empty_signal_args);
- SIGNAL_CHECK("text_changed", empty_signal_args);
- SIGNAL_CHECK("lines_edited_from", lines_edited_args);
- // Undo remove newline.
- text_edit->undo();
- MessageQueue::get_singleton()->flush();
- CHECK(text_edit->get_text() == "\n is some test text.\n\nthis some test text.");
- CHECK(text_edit->get_caret_count() == 2);
- CHECK_FALSE(text_edit->has_selection(0));
- CHECK(text_edit->get_caret_line(0) == 1);
- CHECK(text_edit->get_caret_column(0) == 0);
- CHECK_FALSE(text_edit->has_selection(1));
- CHECK(text_edit->get_caret_line(1) == 3);
- CHECK(text_edit->get_caret_column(1) == 0);
- SIGNAL_CHECK("caret_changed", empty_signal_args);
- SIGNAL_CHECK("text_changed", empty_signal_args);
- SIGNAL_CHECK("lines_edited_from", reverse_nested(lines_edited_args));
- // Redo remove newline.
- text_edit->redo();
- MessageQueue::get_singleton()->flush();
- CHECK(text_edit->get_text() == " is some test text.\nthis some test text.");
- CHECK(text_edit->get_caret_count() == 2);
- CHECK_FALSE(text_edit->has_selection(0));
- CHECK(text_edit->get_caret_line(0) == 0);
- CHECK(text_edit->get_caret_column(0) == 0);
- CHECK_FALSE(text_edit->has_selection(1));
- CHECK(text_edit->get_caret_line(1) == 1);
- CHECK(text_edit->get_caret_column(1) == 0);
- SIGNAL_CHECK("caret_changed", empty_signal_args);
- SIGNAL_CHECK("text_changed", empty_signal_args);
- SIGNAL_CHECK("lines_edited_from", lines_edited_args);
- // Does not work if not editable.
- text_edit->set_caret_column(text_edit->get_line(0).length());
- text_edit->set_caret_column(15, false, 1);
- MessageQueue::get_singleton()->flush();
- SIGNAL_DISCARD("caret_changed");
- text_edit->set_editable(false);
- SEND_GUI_ACTION("ui_text_backspace");
- CHECK(text_edit->get_viewport()->is_input_handled());
- CHECK(text_edit->get_text() == " is some test text.\nthis some test text.");
- CHECK(text_edit->get_caret_count() == 2);
- CHECK_FALSE(text_edit->has_selection(0));
- CHECK(text_edit->get_caret_line(0) == 0);
- CHECK(text_edit->get_caret_column(0) == text_edit->get_line(0).length());
- CHECK_FALSE(text_edit->has_selection(1));
- CHECK(text_edit->get_caret_line(1) == 1);
- CHECK(text_edit->get_caret_column(1) == 15);
- SIGNAL_CHECK_FALSE("caret_changed");
- SIGNAL_CHECK_FALSE("text_changed");
- SIGNAL_CHECK_FALSE("lines_edited_from");
- text_edit->set_editable(true);
- // FIXME: Remove after GH-77101 is fixed.
- text_edit->start_action(TextEdit::ACTION_NONE);
- // Backspace removes character to the left.
- lines_edited_args = build_array(build_array(1, 1), build_array(0, 0));
- SEND_GUI_ACTION("ui_text_backspace");
- CHECK(text_edit->get_viewport()->is_input_handled());
- CHECK(text_edit->get_text() == " is some test text\nthis some testtext.");
- CHECK(text_edit->get_caret_count() == 2);
- CHECK_FALSE(text_edit->has_selection(0));
- CHECK(text_edit->get_caret_line(0) == 0);
- CHECK(text_edit->get_caret_column(0) == 18);
- CHECK_FALSE(text_edit->has_selection(1));
- CHECK(text_edit->get_caret_line(1) == 1);
- CHECK(text_edit->get_caret_column(1) == 14);
- SIGNAL_CHECK("caret_changed", empty_signal_args);
- SIGNAL_CHECK("text_changed", empty_signal_args);
- SIGNAL_CHECK("lines_edited_from", lines_edited_args);
- // Backspace another character without changing caret.
- SEND_GUI_ACTION("ui_text_backspace");
- CHECK(text_edit->get_viewport()->is_input_handled());
- CHECK(text_edit->get_text() == " is some test tex\nthis some testext.");
- CHECK(text_edit->get_caret_count() == 2);
- CHECK_FALSE(text_edit->has_selection(0));
- CHECK(text_edit->get_caret_line(0) == 0);
- CHECK(text_edit->get_caret_column(0) == 17);
- CHECK_FALSE(text_edit->has_selection(1));
- CHECK(text_edit->get_caret_line(1) == 1);
- CHECK(text_edit->get_caret_column(1) == 13);
- SIGNAL_CHECK("caret_changed", empty_signal_args);
- SIGNAL_CHECK("text_changed", empty_signal_args);
- SIGNAL_CHECK("lines_edited_from", lines_edited_args);
- // Undo both backspaces.
- lines_edited_args = build_array(build_array(1, 1), build_array(0, 0), build_array(1, 1), build_array(0, 0));
- text_edit->undo();
- MessageQueue::get_singleton()->flush();
- CHECK(text_edit->get_text() == " is some test text.\nthis some test text.");
- CHECK(text_edit->get_caret_count() == 2);
- CHECK_FALSE(text_edit->has_selection(0));
- CHECK(text_edit->get_caret_line(0) == 0);
- CHECK(text_edit->get_caret_column(0) == 19);
- CHECK_FALSE(text_edit->has_selection(1));
- CHECK(text_edit->get_caret_line(1) == 1);
- CHECK(text_edit->get_caret_column(1) == 15);
- SIGNAL_CHECK("caret_changed", empty_signal_args);
- SIGNAL_CHECK("text_changed", empty_signal_args);
- SIGNAL_CHECK("lines_edited_from", reverse_nested(lines_edited_args));
- // Redo both backspaces.
- text_edit->redo();
- MessageQueue::get_singleton()->flush();
- CHECK(text_edit->get_text() == " is some test tex\nthis some testext.");
- CHECK(text_edit->get_caret_count() == 2);
- CHECK_FALSE(text_edit->has_selection(0));
- CHECK(text_edit->get_caret_line(0) == 0);
- CHECK(text_edit->get_caret_column(0) == 17);
- CHECK_FALSE(text_edit->has_selection(1));
- CHECK(text_edit->get_caret_line(1) == 1);
- CHECK(text_edit->get_caret_column(1) == 13);
- SIGNAL_CHECK("caret_changed", empty_signal_args);
- SIGNAL_CHECK("text_changed", empty_signal_args);
- SIGNAL_CHECK("lines_edited_from", lines_edited_args);
- // Backspace with multiple carets that will overlap.
- text_edit->remove_secondary_carets();
- text_edit->set_caret_line(0);
- text_edit->set_caret_column(8);
- text_edit->add_caret(0, 7);
- text_edit->add_caret(0, 9);
- MessageQueue::get_singleton()->flush();
- SIGNAL_DISCARD("caret_changed");
- lines_edited_args = build_array(build_array(0, 0), build_array(0, 0), build_array(0, 0));
- SEND_GUI_ACTION("ui_text_backspace");
- CHECK(text_edit->get_viewport()->is_input_handled());
- CHECK(text_edit->get_text() == " is sotest tex\nthis some testext.");
- CHECK(text_edit->get_caret_count() == 1);
- CHECK_FALSE(text_edit->has_selection());
- CHECK(text_edit->get_caret_line() == 0);
- CHECK(text_edit->get_caret_column() == 6);
- SIGNAL_CHECK("caret_changed", empty_signal_args);
- SIGNAL_CHECK("text_changed", empty_signal_args);
- SIGNAL_CHECK("lines_edited_from", lines_edited_args);
- // Select each line of text, from right to left. Remove selection to column 0.
- text_edit->select(0, text_edit->get_line(0).length(), 0, 0);
- text_edit->add_caret(1, 0);
- text_edit->select(1, text_edit->get_line(1).length(), 1, 0, 1);
- MessageQueue::get_singleton()->flush();
- SIGNAL_DISCARD("caret_changed");
- lines_edited_args = build_array(build_array(1, 1), build_array(0, 0));
- SEND_GUI_ACTION("ui_text_backspace");
- CHECK(text_edit->get_text() == "\n");
- CHECK(text_edit->get_caret_count() == 2);
- CHECK_FALSE(text_edit->has_selection(0));
- CHECK(text_edit->get_caret_line(0) == 0);
- CHECK(text_edit->get_caret_column(0) == 0);
- CHECK_FALSE(text_edit->has_selection(1));
- CHECK(text_edit->get_caret_line(1) == 1);
- CHECK(text_edit->get_caret_column(1) == 0);
- SIGNAL_CHECK_FALSE("caret_changed");
- SIGNAL_CHECK("text_changed", empty_signal_args);
- SIGNAL_CHECK("lines_edited_from", lines_edited_args);
- // Backspace at start of first line does nothing.
- text_edit->remove_secondary_carets();
- text_edit->deselect();
- text_edit->set_caret_line(0);
- text_edit->set_caret_column(0);
- MessageQueue::get_singleton()->flush();
- SIGNAL_DISCARD("caret_changed");
- SEND_GUI_ACTION("ui_text_backspace");
- CHECK(text_edit->get_viewport()->is_input_handled());
- CHECK(text_edit->get_text() == "\n");
- CHECK(text_edit->get_caret_count() == 1);
- CHECK_FALSE(text_edit->has_selection());
- CHECK(text_edit->get_caret_line() == 0);
- CHECK(text_edit->get_caret_column() == 0);
- SIGNAL_CHECK_FALSE("caret_changed");
- SIGNAL_CHECK_FALSE("text_changed");
- SIGNAL_CHECK_FALSE("lines_edited_from");
- }
- SUBCASE("[TextEdit] ui_text_delete_all_to_right") {
- Ref<InputEvent> tmpevent = InputEventKey::create_reference(Key::BACKSPACE | KeyModifierMask::ALT | KeyModifierMask::CMD_OR_CTRL);
- InputMap::get_singleton()->action_add_event("ui_text_delete_all_to_right", tmpevent);
- text_edit->set_text("this is some test text.\nthis is some test text.\n");
- MessageQueue::get_singleton()->flush();
- SIGNAL_DISCARD("text_set");
- SIGNAL_DISCARD("text_changed");
- SIGNAL_DISCARD("lines_edited_from");
- // Remove all text to right of caret.
- text_edit->set_caret_line(0);
- text_edit->set_caret_column(18);
- text_edit->add_caret(0, 16);
- text_edit->add_caret(0, 20);
- MessageQueue::get_singleton()->flush();
- SIGNAL_DISCARD("caret_changed");
- lines_edited_args = build_array(build_array(0, 0));
- SEND_GUI_ACTION("ui_text_delete_all_to_right");
- CHECK(text_edit->get_viewport()->is_input_handled());
- CHECK(text_edit->get_text() == "this is some tes\nthis is some test text.\n");
- CHECK(text_edit->get_caret_count() == 1);
- CHECK_FALSE(text_edit->has_selection(0));
- CHECK(text_edit->get_caret_line(0) == 0);
- CHECK(text_edit->get_caret_column(0) == 16);
- SIGNAL_CHECK("caret_changed", empty_signal_args);
- SIGNAL_CHECK("text_changed", empty_signal_args);
- SIGNAL_CHECK("lines_edited_from", lines_edited_args);
- // Undo.
- lines_edited_args = build_array(build_array(0, 0));
- text_edit->undo();
- MessageQueue::get_singleton()->flush();
- CHECK(text_edit->get_text() == "this is some test text.\nthis is some test text.\n");
- CHECK(text_edit->get_caret_count() == 3);
- CHECK_FALSE(text_edit->has_selection(0));
- CHECK(text_edit->get_caret_line(0) == 0);
- CHECK(text_edit->get_caret_column(0) == 18);
- CHECK_FALSE(text_edit->has_selection(1));
- CHECK(text_edit->get_caret_line(1) == 0);
- CHECK(text_edit->get_caret_column(1) == 16);
- CHECK_FALSE(text_edit->has_selection(2));
- CHECK(text_edit->get_caret_line(2) == 0);
- CHECK(text_edit->get_caret_column(2) == 20);
- SIGNAL_CHECK("caret_changed", empty_signal_args);
- SIGNAL_CHECK("text_changed", empty_signal_args);
- SIGNAL_CHECK("lines_edited_from", lines_edited_args);
- // Redo.
- text_edit->redo();
- MessageQueue::get_singleton()->flush();
- CHECK(text_edit->get_text() == "this is some tes\nthis is some test text.\n");
- CHECK(text_edit->get_caret_count() == 1);
- CHECK_FALSE(text_edit->has_selection(0));
- CHECK(text_edit->get_caret_line(0) == 0);
- CHECK(text_edit->get_caret_column(0) == 16);
- SIGNAL_CHECK("caret_changed", empty_signal_args);
- SIGNAL_CHECK("text_changed", empty_signal_args);
- SIGNAL_CHECK("lines_edited_from", lines_edited_args);
- // Acts as a normal delete with selections.
- text_edit->select(0, 0, 0, 4);
- text_edit->add_caret(1, 4);
- text_edit->select(1, 8, 1, 4, 1);
- MessageQueue::get_singleton()->flush();
- SIGNAL_DISCARD("caret_changed");
- lines_edited_args = build_array(build_array(0, 0), build_array(1, 1));
- SEND_GUI_ACTION("ui_text_delete_all_to_right");
- CHECK(text_edit->get_viewport()->is_input_handled());
- CHECK(text_edit->get_text() == " is some tes\nthissome test text.\n");
- CHECK(text_edit->get_caret_count() == 2);
- CHECK_FALSE(text_edit->has_selection(0));
- CHECK(text_edit->get_caret_line(0) == 0);
- CHECK(text_edit->get_caret_column(0) == 0);
- CHECK_FALSE(text_edit->has_selection(1));
- CHECK(text_edit->get_caret_line(1) == 1);
- CHECK(text_edit->get_caret_column(1) == 4);
- SIGNAL_CHECK("caret_changed", empty_signal_args);
- SIGNAL_CHECK("text_changed", empty_signal_args);
- SIGNAL_CHECK("lines_edited_from", lines_edited_args);
- // Does nothing when caret is at end of line.
- text_edit->set_caret_column(text_edit->get_line(0).length());
- text_edit->set_caret_column(text_edit->get_line(1).length(), false, 1);
- MessageQueue::get_singleton()->flush();
- SIGNAL_DISCARD("caret_changed");
- SEND_GUI_ACTION("ui_text_delete_all_to_right");
- CHECK(text_edit->get_viewport()->is_input_handled());
- CHECK(text_edit->get_text() == " is some tes\nthissome test text.\n");
- CHECK(text_edit->get_caret_count() == 2);
- CHECK_FALSE(text_edit->has_selection(0));
- CHECK(text_edit->get_caret_line(0) == 0);
- CHECK(text_edit->get_caret_column(0) == text_edit->get_line(0).length());
- CHECK_FALSE(text_edit->has_selection(1));
- CHECK(text_edit->get_caret_line(1) == 1);
- CHECK(text_edit->get_caret_column(1) == text_edit->get_line(1).length());
- SIGNAL_CHECK_FALSE("caret_changed");
- SIGNAL_CHECK_FALSE("text_changed");
- SIGNAL_CHECK_FALSE("lines_edited_from");
- // Does not work if not editable.
- text_edit->set_caret_column(0);
- text_edit->set_caret_column(0, false, 1);
- MessageQueue::get_singleton()->flush();
- SIGNAL_DISCARD("caret_changed");
- text_edit->set_editable(false);
- SEND_GUI_ACTION("ui_text_delete_all_to_right");
- CHECK(text_edit->get_viewport()->is_input_handled());
- CHECK(text_edit->get_text() == " is some tes\nthissome test text.\n");
- CHECK(text_edit->get_caret_count() == 2);
- CHECK_FALSE(text_edit->has_selection(0));
- CHECK(text_edit->get_caret_line(0) == 0);
- CHECK(text_edit->get_caret_column(0) == 0);
- CHECK_FALSE(text_edit->has_selection(1));
- CHECK(text_edit->get_caret_line(1) == 1);
- CHECK(text_edit->get_caret_column(1) == 0);
- SIGNAL_CHECK_FALSE("caret_changed");
- SIGNAL_CHECK_FALSE("text_changed");
- SIGNAL_CHECK_FALSE("lines_edited_from");
- text_edit->set_editable(true);
- // Delete entire line.
- SEND_GUI_ACTION("ui_text_delete_all_to_right");
- CHECK(text_edit->get_viewport()->is_input_handled());
- CHECK(text_edit->get_text() == "\n\n");
- CHECK(text_edit->get_caret_count() == 2);
- CHECK_FALSE(text_edit->has_selection(0));
- CHECK(text_edit->get_caret_line(0) == 0);
- CHECK(text_edit->get_caret_column(0) == 0);
- CHECK_FALSE(text_edit->has_selection(1));
- CHECK(text_edit->get_caret_line(1) == 1);
- CHECK(text_edit->get_caret_column(1) == 0);
- SIGNAL_CHECK_FALSE("caret_changed");
- SIGNAL_CHECK("text_changed", empty_signal_args);
- SIGNAL_CHECK("lines_edited_from", lines_edited_args);
- InputMap::get_singleton()->action_erase_event("ui_text_delete_all_to_right", tmpevent);
- }
- SUBCASE("[TextEdit] ui_text_delete_word") {
- text_edit->set_caret_mid_grapheme_enabled(true);
- CHECK(text_edit->is_caret_mid_grapheme_enabled());
- text_edit->set_text("this is some test text.\n\nthis is some test text.\n");
- MessageQueue::get_singleton()->flush();
- SIGNAL_DISCARD("text_set");
- SIGNAL_DISCARD("text_changed");
- SIGNAL_DISCARD("lines_edited_from");
- SIGNAL_DISCARD("caret_changed");
- // Acts as a normal delete with selections.
- text_edit->select(0, 8, 0, 15);
- text_edit->add_caret(2, 6);
- text_edit->select(2, 10, 2, 6, 1);
- MessageQueue::get_singleton()->flush();
- SIGNAL_DISCARD("caret_changed");
- lines_edited_args = build_array(build_array(0, 0), build_array(2, 2));
- SEND_GUI_ACTION("ui_text_delete_word");
- CHECK(text_edit->get_viewport()->is_input_handled());
- CHECK(text_edit->get_text() == "this is st text.\n\nthis ime test text.\n");
- CHECK(text_edit->get_caret_count() == 2);
- CHECK_FALSE(text_edit->has_selection(0));
- CHECK(text_edit->get_caret_line(0) == 0);
- CHECK(text_edit->get_caret_column(0) == 8);
- CHECK_FALSE(text_edit->has_selection(1));
- CHECK(text_edit->get_caret_line(1) == 2);
- CHECK(text_edit->get_caret_column(1) == 6);
- SIGNAL_CHECK("caret_changed", empty_signal_args);
- SIGNAL_CHECK("text_changed", empty_signal_args);
- SIGNAL_CHECK("lines_edited_from", lines_edited_args);
- // Removes newlines when at end of line.
- text_edit->set_caret_column(text_edit->get_line(0).length());
- text_edit->set_caret_column(text_edit->get_line(2).length(), false, 1);
- MessageQueue::get_singleton()->flush();
- SIGNAL_DISCARD("caret_changed");
- lines_edited_args = build_array(build_array(1, 0), build_array(2, 1));
- SEND_GUI_ACTION("ui_text_delete_word");
- CHECK(text_edit->get_viewport()->is_input_handled());
- CHECK(text_edit->get_text() == "this is st text.\nthis ime test text.");
- CHECK(text_edit->get_caret_count() == 2);
- CHECK_FALSE(text_edit->has_selection(0));
- CHECK(text_edit->get_caret_line(0) == 0);
- CHECK(text_edit->get_caret_column(0) == text_edit->get_line(0).length());
- CHECK_FALSE(text_edit->has_selection(1));
- CHECK(text_edit->get_caret_line(1) == 1);
- CHECK(text_edit->get_caret_column(1) == text_edit->get_line(1).length());
- SIGNAL_CHECK("caret_changed", empty_signal_args);
- SIGNAL_CHECK("text_changed", empty_signal_args);
- SIGNAL_CHECK("lines_edited_from", lines_edited_args);
- // Does not work if not editable.
- text_edit->set_caret_column(0);
- text_edit->set_caret_column(10, false, 1);
- MessageQueue::get_singleton()->flush();
- SIGNAL_DISCARD("caret_changed");
- text_edit->set_editable(false);
- SEND_GUI_ACTION("ui_text_delete_word");
- CHECK(text_edit->get_viewport()->is_input_handled());
- CHECK(text_edit->get_text() == "this is st text.\nthis ime test text.");
- CHECK(text_edit->get_caret_count() == 2);
- CHECK_FALSE(text_edit->has_selection(0));
- CHECK(text_edit->get_caret_line(0) == 0);
- CHECK(text_edit->get_caret_column(0) == 0);
- CHECK_FALSE(text_edit->has_selection(1));
- CHECK(text_edit->get_caret_line(1) == 1);
- CHECK(text_edit->get_caret_column(1) == 10);
- SIGNAL_CHECK_FALSE("caret_changed");
- SIGNAL_CHECK_FALSE("text_changed");
- SIGNAL_CHECK_FALSE("lines_edited_from");
- text_edit->set_editable(true);
- // FIXME: Remove after GH-77101 is fixed.
- text_edit->start_action(TextEdit::ACTION_NONE);
- // Delete to the end of the word right of the caret.
- lines_edited_args = build_array(build_array(0, 0), build_array(1, 1));
- SEND_GUI_ACTION("ui_text_delete_word");
- CHECK(text_edit->get_viewport()->is_input_handled());
- CHECK(text_edit->get_text() == " is st text.\nthis ime t text.");
- CHECK(text_edit->get_caret_count() == 2);
- CHECK_FALSE(text_edit->has_selection(0));
- CHECK(text_edit->get_caret_line(0) == 0);
- CHECK(text_edit->get_caret_column(0) == 0);
- CHECK_FALSE(text_edit->has_selection(1));
- CHECK(text_edit->get_caret_line(1) == 1);
- CHECK(text_edit->get_caret_column(1) == 10);
- SIGNAL_CHECK_FALSE("caret_changed");
- SIGNAL_CHECK("text_changed", empty_signal_args);
- SIGNAL_CHECK("lines_edited_from", lines_edited_args);
- // Undo.
- text_edit->undo();
- MessageQueue::get_singleton()->flush();
- CHECK(text_edit->get_text() == "this is st text.\nthis ime test text.");
- CHECK(text_edit->get_caret_count() == 2);
- CHECK_FALSE(text_edit->has_selection(0));
- CHECK(text_edit->get_caret_line(0) == 0);
- CHECK(text_edit->get_caret_column(0) == 0);
- CHECK_FALSE(text_edit->has_selection(1));
- CHECK(text_edit->get_caret_line(1) == 1);
- CHECK(text_edit->get_caret_column(1) == 10);
- SIGNAL_CHECK_FALSE("caret_changed");
- SIGNAL_CHECK("text_changed", empty_signal_args);
- SIGNAL_CHECK("lines_edited_from", reverse_nested(lines_edited_args));
- // Redo.
- text_edit->redo();
- MessageQueue::get_singleton()->flush();
- CHECK(text_edit->get_text() == " is st text.\nthis ime t text.");
- CHECK(text_edit->get_caret_count() == 2);
- CHECK_FALSE(text_edit->has_selection(0));
- CHECK(text_edit->get_caret_line(0) == 0);
- CHECK(text_edit->get_caret_column(0) == 0);
- CHECK_FALSE(text_edit->has_selection(1));
- CHECK(text_edit->get_caret_line(1) == 1);
- CHECK(text_edit->get_caret_column(1) == 10);
- SIGNAL_CHECK_FALSE("caret_changed");
- SIGNAL_CHECK("text_changed", empty_signal_args);
- SIGNAL_CHECK("lines_edited_from", lines_edited_args);
- // Delete one word with multiple carets.
- text_edit->remove_secondary_carets();
- text_edit->set_text("onelongword test");
- text_edit->set_caret_line(0);
- text_edit->set_caret_column(6);
- text_edit->add_caret(0, 9);
- text_edit->add_caret(0, 3);
- lines_edited_args = build_array(build_array(0, 0));
- MessageQueue::get_singleton()->flush();
- SIGNAL_DISCARD("text_set");
- SIGNAL_DISCARD("text_changed");
- SIGNAL_DISCARD("lines_edited_from");
- SIGNAL_DISCARD("caret_changed");
- SEND_GUI_ACTION("ui_text_delete_word");
- CHECK(text_edit->get_viewport()->is_input_handled());
- CHECK(text_edit->get_text() == "one test");
- CHECK(text_edit->get_caret_count() == 1);
- CHECK_FALSE(text_edit->has_selection(0));
- CHECK(text_edit->get_caret_line(0) == 0);
- CHECK(text_edit->get_caret_column(0) == 3);
- SIGNAL_CHECK("caret_changed", empty_signal_args);
- SIGNAL_CHECK("text_changed", empty_signal_args);
- SIGNAL_CHECK("lines_edited_from", lines_edited_args);
- // Removing newline effectively happens after removing text.
- text_edit->set_text("test\nlines");
- text_edit->set_caret_line(0);
- text_edit->set_caret_column(2);
- text_edit->add_caret(0, 4);
- SEND_GUI_ACTION("ui_text_delete_word");
- CHECK(text_edit->get_viewport()->is_input_handled());
- CHECK_FALSE(text_edit->has_selection());
- CHECK(text_edit->get_text() == "telines");
- CHECK(text_edit->get_caret_count() == 1);
- CHECK(text_edit->get_caret_line(0) == 0);
- CHECK(text_edit->get_caret_column(0) == 2);
- text_edit->remove_secondary_carets();
- // Removing newline effectively happens after removing text, reverse caret order.
- text_edit->set_text("test\nlines");
- text_edit->set_caret_line(0);
- text_edit->set_caret_column(4);
- text_edit->add_caret(0, 2);
- SEND_GUI_ACTION("ui_text_delete_word");
- CHECK(text_edit->get_viewport()->is_input_handled());
- CHECK_FALSE(text_edit->has_selection());
- CHECK(text_edit->get_text() == "telines");
- CHECK(text_edit->get_caret_count() == 1);
- CHECK(text_edit->get_caret_line(0) == 0);
- CHECK(text_edit->get_caret_column(0) == 2);
- text_edit->remove_secondary_carets();
- // Remove when there are no words, only symbols.
- text_edit->set_text("#{}");
- text_edit->set_caret_line(0);
- text_edit->set_caret_column(0);
- SEND_GUI_ACTION("ui_text_delete_word");
- CHECK(text_edit->get_viewport()->is_input_handled());
- CHECK_FALSE(text_edit->has_selection());
- CHECK(text_edit->get_text() == "");
- CHECK(text_edit->get_caret_line(0) == 0);
- CHECK(text_edit->get_caret_column(0) == 0);
- }
- SUBCASE("[TextEdit] ui_text_delete_word same line") {
- text_edit->set_text("test longwordtest test");
- MessageQueue::get_singleton()->flush();
- SIGNAL_DISCARD("text_set");
- SIGNAL_DISCARD("text_changed");
- SIGNAL_DISCARD("lines_edited_from");
- SIGNAL_DISCARD("caret_changed");
- // Multiple carets on the same line is handled.
- text_edit->set_caret_line(0);
- text_edit->set_caret_column(0);
- text_edit->add_caret(0, 11);
- text_edit->add_caret(0, 15);
- text_edit->add_caret(0, 9);
- MessageQueue::get_singleton()->flush();
- SIGNAL_DISCARD("caret_changed");
- lines_edited_args = build_array(build_array(0, 0), build_array(0, 0));
- SEND_GUI_ACTION("ui_text_delete_word");
- CHECK(text_edit->get_viewport()->is_input_handled());
- CHECK(text_edit->get_text() == " long test");
- CHECK(text_edit->get_caret_count() == 2);
- CHECK_FALSE(text_edit->has_selection(0));
- CHECK(text_edit->get_caret_line(0) == 0);
- CHECK(text_edit->get_caret_column(0) == 0);
- CHECK_FALSE(text_edit->has_selection(1));
- CHECK(text_edit->get_caret_line(1) == 0);
- CHECK(text_edit->get_caret_column(1) == 5);
- SIGNAL_CHECK("caret_changed", empty_signal_args);
- SIGNAL_CHECK("text_changed", empty_signal_args);
- SIGNAL_CHECK("lines_edited_from", lines_edited_args);
- lines_edited_args = build_array(build_array(0, 0), build_array(0, 0));
- text_edit->undo();
- MessageQueue::get_singleton()->flush();
- CHECK(text_edit->get_text() == "test longwordtest test");
- CHECK(text_edit->get_caret_count() == 4);
- CHECK_FALSE(text_edit->has_selection(0));
- CHECK(text_edit->get_caret_line(0) == 0);
- CHECK(text_edit->get_caret_column(0) == 0);
- CHECK_FALSE(text_edit->has_selection(1));
- CHECK(text_edit->get_caret_line(1) == 0);
- CHECK(text_edit->get_caret_column(1) == 11);
- CHECK_FALSE(text_edit->has_selection(2));
- CHECK(text_edit->get_caret_line(2) == 0);
- CHECK(text_edit->get_caret_column(2) == 15);
- CHECK_FALSE(text_edit->has_selection(3));
- CHECK(text_edit->get_caret_line(3) == 0);
- CHECK(text_edit->get_caret_column(3) == 9);
- SIGNAL_CHECK("caret_changed", empty_signal_args);
- SIGNAL_CHECK("text_changed", empty_signal_args);
- SIGNAL_CHECK("lines_edited_from", reverse_nested(lines_edited_args));
- text_edit->redo();
- MessageQueue::get_singleton()->flush();
- CHECK(text_edit->get_text() == " long test");
- CHECK(text_edit->get_caret_count() == 2);
- CHECK_FALSE(text_edit->has_selection(0));
- CHECK(text_edit->get_caret_line(0) == 0);
- CHECK(text_edit->get_caret_column(0) == 0);
- CHECK_FALSE(text_edit->has_selection(1));
- CHECK(text_edit->get_caret_line(1) == 0);
- CHECK(text_edit->get_caret_column(1) == 5);
- SIGNAL_CHECK("caret_changed", empty_signal_args);
- SIGNAL_CHECK("text_changed", empty_signal_args);
- SIGNAL_CHECK("lines_edited_from", lines_edited_args);
- }
- SUBCASE("[TextEdit] ui_text_delete") {
- text_edit->set_caret_mid_grapheme_enabled(true);
- CHECK(text_edit->is_caret_mid_grapheme_enabled());
- text_edit->set_text("this is some test text.\n\nthis is some test text.\n");
- MessageQueue::get_singleton()->flush();
- SIGNAL_DISCARD("text_set");
- SIGNAL_DISCARD("text_changed");
- SIGNAL_DISCARD("lines_edited_from");
- SIGNAL_DISCARD("caret_changed");
- // Remove selected text when there are selections.
- text_edit->select(0, 0, 0, 4);
- text_edit->add_caret(2, 2);
- text_edit->select(2, 5, 2, 2, 1);
- MessageQueue::get_singleton()->flush();
- SIGNAL_DISCARD("caret_changed");
- lines_edited_args = build_array(build_array(0, 0), build_array(2, 2));
- SEND_GUI_ACTION("ui_text_delete");
- CHECK(text_edit->get_viewport()->is_input_handled());
- CHECK(text_edit->get_text() == " is some test text.\n\nthis some test text.\n");
- CHECK(text_edit->get_caret_count() == 2);
- CHECK_FALSE(text_edit->has_selection(0));
- CHECK(text_edit->get_caret_line(0) == 0);
- CHECK(text_edit->get_caret_column(0) == 0);
- CHECK_FALSE(text_edit->has_selection(1));
- CHECK(text_edit->get_caret_line(1) == 2);
- CHECK(text_edit->get_caret_column(1) == 2);
- SIGNAL_CHECK("caret_changed", empty_signal_args);
- SIGNAL_CHECK("text_changed", empty_signal_args);
- SIGNAL_CHECK("lines_edited_from", lines_edited_args);
- // Undo remove selection.
- text_edit->undo();
- MessageQueue::get_singleton()->flush();
- CHECK(text_edit->get_caret_count() == 2);
- CHECK(text_edit->get_text() == "this is some test text.\n\nthis is some test text.\n");
- CHECK(text_edit->get_caret_count() == 2);
- CHECK(text_edit->has_selection(0));
- CHECK(text_edit->get_caret_line(0) == 0);
- CHECK(text_edit->get_caret_column(0) == 4);
- CHECK(text_edit->get_selection_origin_line(0) == 0);
- CHECK(text_edit->get_selection_origin_column(0) == 0);
- CHECK(text_edit->has_selection(1));
- CHECK(text_edit->get_caret_line(1) == 2);
- CHECK(text_edit->get_caret_column(1) == 2);
- CHECK(text_edit->get_selection_origin_line(1) == 2);
- CHECK(text_edit->get_selection_origin_column(1) == 5);
- SIGNAL_CHECK("caret_changed", empty_signal_args);
- SIGNAL_CHECK("text_changed", empty_signal_args);
- SIGNAL_CHECK("lines_edited_from", reverse_nested(lines_edited_args));
- // Redo remove selection.
- text_edit->redo();
- MessageQueue::get_singleton()->flush();
- CHECK(text_edit->get_text() == " is some test text.\n\nthis some test text.\n");
- CHECK(text_edit->get_caret_count() == 2);
- CHECK_FALSE(text_edit->has_selection(0));
- CHECK(text_edit->get_caret_line(0) == 0);
- CHECK(text_edit->get_caret_column(0) == 0);
- CHECK_FALSE(text_edit->has_selection(1));
- CHECK(text_edit->get_caret_line(1) == 2);
- CHECK(text_edit->get_caret_column(1) == 2);
- SIGNAL_CHECK("caret_changed", empty_signal_args);
- SIGNAL_CHECK("text_changed", empty_signal_args);
- SIGNAL_CHECK("lines_edited_from", lines_edited_args);
- // Remove newline when at end of line.
- text_edit->set_caret_column(text_edit->get_line(0).length());
- text_edit->set_caret_column(text_edit->get_line(2).length(), false, 1);
- MessageQueue::get_singleton()->flush();
- SIGNAL_DISCARD("caret_changed");
- lines_edited_args = build_array(build_array(1, 0), build_array(2, 1));
- SEND_GUI_ACTION("ui_text_delete");
- CHECK(text_edit->get_viewport()->is_input_handled());
- CHECK(text_edit->get_text() == " is some test text.\nthis some test text.");
- CHECK(text_edit->get_caret_count() == 2);
- CHECK_FALSE(text_edit->has_selection(0));
- CHECK(text_edit->get_caret_line(0) == 0);
- CHECK(text_edit->get_caret_column(0) == 19);
- CHECK_FALSE(text_edit->has_selection(1));
- CHECK(text_edit->get_caret_line(1) == 1);
- CHECK(text_edit->get_caret_column(1) == 20);
- SIGNAL_CHECK("caret_changed", empty_signal_args);
- SIGNAL_CHECK("text_changed", empty_signal_args);
- SIGNAL_CHECK("lines_edited_from", lines_edited_args);
- // Undo remove newline.
- text_edit->undo();
- MessageQueue::get_singleton()->flush();
- CHECK(text_edit->get_text() == " is some test text.\n\nthis some test text.\n");
- CHECK(text_edit->get_caret_count() == 2);
- CHECK_FALSE(text_edit->has_selection(0));
- CHECK(text_edit->get_caret_line(0) == 0);
- CHECK(text_edit->get_caret_column(0) == 19);
- CHECK_FALSE(text_edit->has_selection(1));
- CHECK(text_edit->get_caret_line(1) == 2);
- CHECK(text_edit->get_caret_column(1) == 20);
- SIGNAL_CHECK("caret_changed", empty_signal_args);
- SIGNAL_CHECK("text_changed", empty_signal_args);
- SIGNAL_CHECK("lines_edited_from", reverse_nested(lines_edited_args));
- // Redo remove newline.
- text_edit->redo();
- MessageQueue::get_singleton()->flush();
- CHECK(text_edit->get_text() == " is some test text.\nthis some test text.");
- CHECK(text_edit->get_caret_count() == 2);
- CHECK_FALSE(text_edit->has_selection(0));
- CHECK(text_edit->get_caret_line(0) == 0);
- CHECK(text_edit->get_caret_column(0) == 19);
- CHECK_FALSE(text_edit->has_selection(1));
- CHECK(text_edit->get_caret_line(1) == 1);
- CHECK(text_edit->get_caret_column(1) == 20);
- SIGNAL_CHECK("caret_changed", empty_signal_args);
- SIGNAL_CHECK("text_changed", empty_signal_args);
- SIGNAL_CHECK("lines_edited_from", lines_edited_args);
- // Does not work if not editable.
- text_edit->set_caret_column(0);
- text_edit->set_caret_column(15, false, 1);
- MessageQueue::get_singleton()->flush();
- SIGNAL_DISCARD("caret_changed");
- text_edit->set_editable(false);
- SEND_GUI_ACTION("ui_text_delete");
- CHECK(text_edit->get_viewport()->is_input_handled());
- CHECK(text_edit->get_text() == " is some test text.\nthis some test text.");
- CHECK(text_edit->get_caret_count() == 2);
- CHECK_FALSE(text_edit->has_selection(0));
- CHECK(text_edit->get_caret_line(0) == 0);
- CHECK(text_edit->get_caret_column(0) == 0);
- CHECK_FALSE(text_edit->has_selection(1));
- CHECK(text_edit->get_caret_line(1) == 1);
- CHECK(text_edit->get_caret_column(1) == 15);
- SIGNAL_CHECK_FALSE("caret_changed");
- SIGNAL_CHECK_FALSE("text_changed");
- SIGNAL_CHECK_FALSE("lines_edited_from");
- text_edit->set_editable(true);
- // FIXME: Remove after GH-77101 is fixed.
- text_edit->start_action(TextEdit::EditAction::ACTION_NONE);
- // Delete removes character to the right.
- lines_edited_args = build_array(build_array(0, 0), build_array(1, 1));
- SEND_GUI_ACTION("ui_text_delete");
- CHECK(text_edit->get_viewport()->is_input_handled());
- CHECK(text_edit->get_text() == "is some test text.\nthis some test ext.");
- CHECK(text_edit->get_caret_count() == 2);
- CHECK_FALSE(text_edit->has_selection(0));
- CHECK(text_edit->get_caret_line(0) == 0);
- CHECK(text_edit->get_caret_column(0) == 0);
- CHECK_FALSE(text_edit->has_selection(1));
- CHECK(text_edit->get_caret_line(1) == 1);
- CHECK(text_edit->get_caret_column(1) == 15);
- SIGNAL_CHECK_FALSE("caret_changed");
- SIGNAL_CHECK("text_changed", empty_signal_args);
- SIGNAL_CHECK("lines_edited_from", lines_edited_args);
- // Delete another character without changing caret.
- SEND_GUI_ACTION("ui_text_delete");
- CHECK(text_edit->get_viewport()->is_input_handled());
- CHECK(text_edit->get_text() == "s some test text.\nthis some test xt.");
- CHECK(text_edit->get_caret_count() == 2);
- CHECK_FALSE(text_edit->has_selection(0));
- CHECK(text_edit->get_caret_line(0) == 0);
- CHECK(text_edit->get_caret_column(0) == 0);
- CHECK_FALSE(text_edit->has_selection(1));
- CHECK(text_edit->get_caret_line(1) == 1);
- CHECK(text_edit->get_caret_column(1) == 15);
- SIGNAL_CHECK_FALSE("caret_changed");
- SIGNAL_CHECK("text_changed", empty_signal_args);
- SIGNAL_CHECK("lines_edited_from", lines_edited_args);
- // Undo both deletes.
- lines_edited_args = build_array(build_array(0, 0), build_array(1, 1), build_array(0, 0), build_array(1, 1));
- text_edit->undo();
- MessageQueue::get_singleton()->flush();
- CHECK(text_edit->get_text() == " is some test text.\nthis some test text.");
- CHECK(text_edit->get_caret_count() == 2);
- CHECK_FALSE(text_edit->has_selection(0));
- CHECK(text_edit->get_caret_line(0) == 0);
- CHECK(text_edit->get_caret_column(0) == 0);
- CHECK_FALSE(text_edit->has_selection(1));
- CHECK(text_edit->get_caret_line(1) == 1);
- CHECK(text_edit->get_caret_column(1) == 15);
- SIGNAL_CHECK_FALSE("caret_changed");
- SIGNAL_CHECK("text_changed", empty_signal_args);
- SIGNAL_CHECK("lines_edited_from", reverse_nested(lines_edited_args));
- // Redo both deletes.
- text_edit->redo();
- MessageQueue::get_singleton()->flush();
- CHECK(text_edit->get_text() == "s some test text.\nthis some test xt.");
- CHECK(text_edit->get_caret_count() == 2);
- CHECK_FALSE(text_edit->has_selection(0));
- CHECK(text_edit->get_caret_line(0) == 0);
- CHECK(text_edit->get_caret_column(0) == 0);
- CHECK_FALSE(text_edit->has_selection(1));
- CHECK(text_edit->get_caret_line(1) == 1);
- CHECK(text_edit->get_caret_column(1) == 15);
- SIGNAL_CHECK_FALSE("caret_changed");
- SIGNAL_CHECK("text_changed", empty_signal_args);
- SIGNAL_CHECK("lines_edited_from", lines_edited_args);
- // Delete at end of last line does nothing.
- text_edit->remove_secondary_carets();
- text_edit->set_caret_line(1);
- text_edit->set_caret_column(18);
- MessageQueue::get_singleton()->flush();
- SIGNAL_DISCARD("caret_changed");
- SEND_GUI_ACTION("ui_text_delete");
- CHECK(text_edit->get_viewport()->is_input_handled());
- CHECK(text_edit->get_text() == "s some test text.\nthis some test xt.");
- CHECK(text_edit->get_caret_count() == 1);
- CHECK_FALSE(text_edit->has_selection(0));
- CHECK(text_edit->get_caret_line(0) == 1);
- CHECK(text_edit->get_caret_column(0) == 18);
- SIGNAL_CHECK_FALSE("caret_changed");
- SIGNAL_CHECK_FALSE("text_changed");
- SIGNAL_CHECK_FALSE("lines_edited_from");
- }
- SUBCASE("[TextEdit] ui_text_caret_word_left") {
- text_edit->set_text("\nthis is some test text.\nthis is some test text.");
- text_edit->set_caret_line(1);
- text_edit->set_caret_column(15);
- text_edit->add_caret(2, 10);
- text_edit->select(1, 10, 1, 15);
- text_edit->select(2, 15, 2, 10, 1);
- MessageQueue::get_singleton()->flush();
- SIGNAL_DISCARD("text_set");
- SIGNAL_DISCARD("text_changed");
- SIGNAL_DISCARD("lines_edited_from");
- SIGNAL_DISCARD("caret_changed");
- // Deselect to start of previous word when selection is right to left.
- // Select to start of next word when selection is left to right.
- #ifdef MACOS_ENABLED
- SEND_GUI_KEY_EVENT(Key::LEFT | KeyModifierMask::ALT | KeyModifierMask::SHIFT);
- #else
- SEND_GUI_KEY_EVENT(Key::LEFT | KeyModifierMask::CMD_OR_CTRL | KeyModifierMask::SHIFT);
- #endif
- CHECK(text_edit->get_viewport()->is_input_handled());
- CHECK(text_edit->get_caret_count() == 2);
- CHECK(text_edit->has_selection(0));
- CHECK(text_edit->get_selected_text(0) == "me ");
- CHECK(text_edit->get_caret_line(0) == 1);
- CHECK(text_edit->get_caret_column(0) == 13);
- CHECK(text_edit->get_selection_origin_line(0) == 1);
- CHECK(text_edit->get_selection_origin_column(0) == 10);
- CHECK(text_edit->is_caret_after_selection_origin(0));
- CHECK(text_edit->has_selection(1));
- CHECK(text_edit->get_selected_text(1) == "some te");
- CHECK(text_edit->get_caret_line(1) == 2);
- CHECK(text_edit->get_caret_column(1) == 8);
- CHECK(text_edit->get_selection_origin_line(1) == 2);
- CHECK(text_edit->get_selection_origin_column(1) == 15);
- CHECK_FALSE(text_edit->is_caret_after_selection_origin(1));
- SIGNAL_CHECK("caret_changed", empty_signal_args);
- SIGNAL_CHECK_FALSE("text_changed");
- SIGNAL_CHECK_FALSE("lines_edited_from");
- // Select to start of word with shift.
- text_edit->deselect();
- text_edit->set_caret_column(7);
- text_edit->set_caret_column(16, false, 1);
- MessageQueue::get_singleton()->flush();
- SIGNAL_DISCARD("caret_changed");
- #ifdef MACOS_ENABLED
- SEND_GUI_KEY_EVENT(Key::LEFT | KeyModifierMask::ALT | KeyModifierMask::SHIFT);
- #else
- SEND_GUI_KEY_EVENT(Key::LEFT | KeyModifierMask::CMD_OR_CTRL | KeyModifierMask::SHIFT);
- #endif
- CHECK(text_edit->get_viewport()->is_input_handled());
- CHECK(text_edit->get_caret_count() == 2);
- CHECK(text_edit->has_selection(0));
- CHECK(text_edit->get_selected_text(0) == "is");
- CHECK(text_edit->get_caret_line(0) == 1);
- CHECK(text_edit->get_caret_column(0) == 5);
- CHECK(text_edit->get_selection_origin_line(0) == 1);
- CHECK(text_edit->get_selection_origin_column(0) == 7);
- CHECK_FALSE(text_edit->is_caret_after_selection_origin(0));
- CHECK(text_edit->has_selection(1));
- CHECK(text_edit->get_selected_text(1) == "tes");
- CHECK(text_edit->get_caret_line(1) == 2);
- CHECK(text_edit->get_caret_column(1) == 13);
- CHECK(text_edit->get_selection_origin_line(1) == 2);
- CHECK(text_edit->get_selection_origin_column(1) == 16);
- CHECK_FALSE(text_edit->is_caret_after_selection_origin(1));
- SIGNAL_CHECK("caret_changed", empty_signal_args);
- SIGNAL_CHECK_FALSE("text_changed");
- SIGNAL_CHECK_FALSE("lines_edited_from");
- // Deselect and move caret to start of next word without shift.
- SEND_GUI_ACTION("ui_text_caret_word_left");
- CHECK(text_edit->get_viewport()->is_input_handled());
- CHECK(text_edit->get_caret_count() == 2);
- CHECK_FALSE(text_edit->has_selection(0));
- CHECK(text_edit->get_caret_line(0) == 1);
- CHECK(text_edit->get_caret_column(0) == 0);
- CHECK_FALSE(text_edit->has_selection(1));
- CHECK(text_edit->get_caret_line(1) == 2);
- CHECK(text_edit->get_caret_column(1) == 8);
- SIGNAL_CHECK("caret_changed", empty_signal_args);
- SIGNAL_CHECK_FALSE("text_changed");
- SIGNAL_CHECK_FALSE("lines_edited_from");
- // Moves to end of previous line when at start of line. Does nothing at start of text.
- text_edit->set_caret_line(0);
- text_edit->set_caret_column(0);
- text_edit->set_caret_column(0, false, 1);
- MessageQueue::get_singleton()->flush();
- SIGNAL_DISCARD("caret_changed");
- SEND_GUI_ACTION("ui_text_caret_word_left");
- CHECK(text_edit->get_viewport()->is_input_handled());
- CHECK(text_edit->get_caret_count() == 2);
- CHECK_FALSE(text_edit->has_selection(0));
- CHECK(text_edit->get_caret_line(0) == 0);
- CHECK(text_edit->get_caret_column(0) == 0);
- CHECK_FALSE(text_edit->has_selection(1));
- CHECK(text_edit->get_caret_line(1) == 1);
- CHECK(text_edit->get_caret_column(1) == 23);
- SIGNAL_CHECK("caret_changed", empty_signal_args);
- SIGNAL_CHECK_FALSE("text_changed");
- SIGNAL_CHECK_FALSE("lines_edited_from");
- // Move when there are no words, only symbols.
- text_edit->set_text("#{}");
- text_edit->set_caret_line(0);
- text_edit->set_caret_column(3);
- SEND_GUI_ACTION("ui_text_caret_word_left");
- CHECK(text_edit->get_viewport()->is_input_handled());
- CHECK(text_edit->get_caret_line(0) == 0);
- CHECK(text_edit->get_caret_column(0) == 0);
- }
- SUBCASE("[TextEdit] ui_text_caret_left") {
- text_edit->set_text("\nthis is some test text.\nthis is some test text.");
- text_edit->set_caret_line(1);
- text_edit->set_caret_column(7);
- text_edit->select(1, 3, 1, 7);
- text_edit->add_caret(2, 3);
- text_edit->select(2, 7, 2, 3, 1);
- MessageQueue::get_singleton()->flush();
- SIGNAL_DISCARD("text_set");
- SIGNAL_DISCARD("text_changed");
- SIGNAL_DISCARD("lines_edited_from");
- SIGNAL_DISCARD("caret_changed");
- // Remove one character from selection when selection is left to right.
- // Add one character to selection when selection is right to left.
- SEND_GUI_KEY_EVENT(Key::LEFT | KeyModifierMask::SHIFT);
- CHECK(text_edit->get_viewport()->is_input_handled());
- CHECK(text_edit->get_caret_count() == 2);
- CHECK(text_edit->has_selection(0));
- CHECK(text_edit->get_selected_text(0) == "s i");
- CHECK(text_edit->get_caret_line(0) == 1);
- CHECK(text_edit->get_caret_column(0) == 6);
- CHECK(text_edit->get_selection_origin_line(0) == 1);
- CHECK(text_edit->get_selection_origin_column(0) == 3);
- CHECK(text_edit->is_caret_after_selection_origin(0));
- CHECK(text_edit->has_selection(1));
- CHECK(text_edit->get_selected_text(1) == "is is");
- CHECK(text_edit->get_caret_line(1) == 2);
- CHECK(text_edit->get_caret_column(1) == 2);
- CHECK(text_edit->get_selection_origin_line(1) == 2);
- CHECK(text_edit->get_selection_origin_column(1) == 7);
- CHECK_FALSE(text_edit->is_caret_after_selection_origin(1));
- SIGNAL_CHECK("caret_changed", empty_signal_args);
- SIGNAL_CHECK_FALSE("text_changed");
- SIGNAL_CHECK_FALSE("lines_edited_from");
- // Deselect and put caret at selection start without shift.
- SEND_GUI_ACTION("ui_text_caret_left");
- CHECK(text_edit->get_viewport()->is_input_handled());
- CHECK(text_edit->get_caret_count() == 2);
- CHECK_FALSE(text_edit->has_selection(0));
- CHECK(text_edit->get_caret_line(0) == 1);
- CHECK(text_edit->get_caret_column(0) == 3);
- CHECK_FALSE(text_edit->has_selection(1));
- CHECK(text_edit->get_caret_line(1) == 2);
- CHECK(text_edit->get_caret_column(1) == 2);
- SIGNAL_CHECK("caret_changed", empty_signal_args);
- SIGNAL_CHECK_FALSE("text_changed");
- SIGNAL_CHECK_FALSE("lines_edited_from");
- // Move caret one character to the left.
- SEND_GUI_ACTION("ui_text_caret_left");
- CHECK(text_edit->get_viewport()->is_input_handled());
- CHECK(text_edit->get_caret_count() == 2);
- CHECK_FALSE(text_edit->has_selection(0));
- CHECK(text_edit->get_caret_line(0) == 1);
- CHECK(text_edit->get_caret_column(0) == 2);
- CHECK_FALSE(text_edit->has_selection(1));
- CHECK(text_edit->get_caret_line(1) == 2);
- CHECK(text_edit->get_caret_column(1) == 1);
- SIGNAL_CHECK("caret_changed", empty_signal_args);
- SIGNAL_CHECK_FALSE("text_changed");
- SIGNAL_CHECK_FALSE("lines_edited_from");
- // Select one character to the left with shift and no existing selection.
- SEND_GUI_KEY_EVENT(Key::LEFT | KeyModifierMask::SHIFT);
- CHECK(text_edit->get_viewport()->is_input_handled());
- CHECK(text_edit->get_caret_count() == 2);
- CHECK(text_edit->has_selection(0));
- CHECK(text_edit->get_selected_text(0) == "h");
- CHECK(text_edit->get_caret_line(0) == 1);
- CHECK(text_edit->get_caret_column(0) == 1);
- CHECK(text_edit->get_selection_origin_line(0) == 1);
- CHECK(text_edit->get_selection_origin_column(0) == 2);
- CHECK_FALSE(text_edit->is_caret_after_selection_origin(0));
- CHECK(text_edit->has_selection(1));
- CHECK(text_edit->get_selected_text(1) == "t");
- CHECK(text_edit->get_caret_line(1) == 2);
- CHECK(text_edit->get_caret_column(1) == 0);
- CHECK(text_edit->get_selection_origin_line(1) == 2);
- CHECK(text_edit->get_selection_origin_column(1) == 1);
- CHECK_FALSE(text_edit->is_caret_after_selection_origin(1));
- SIGNAL_CHECK("caret_changed", empty_signal_args);
- SIGNAL_CHECK_FALSE("text_changed");
- SIGNAL_CHECK_FALSE("lines_edited_from");
- // Moves to end of previous line when at start of line. Does nothing at start of text.
- text_edit->deselect();
- text_edit->set_caret_line(0);
- text_edit->set_caret_column(0);
- text_edit->set_caret_column(0, false, 1);
- MessageQueue::get_singleton()->flush();
- SIGNAL_DISCARD("caret_changed");
- SEND_GUI_ACTION("ui_text_caret_left");
- CHECK(text_edit->get_viewport()->is_input_handled());
- CHECK(text_edit->get_caret_count() == 2);
- CHECK_FALSE(text_edit->has_selection(0));
- CHECK(text_edit->get_caret_line(0) == 0);
- CHECK(text_edit->get_caret_column(0) == 0);
- CHECK_FALSE(text_edit->has_selection(1));
- CHECK(text_edit->get_caret_line(1) == 1);
- CHECK(text_edit->get_caret_column(1) == 23);
- SIGNAL_CHECK("caret_changed", empty_signal_args);
- SIGNAL_CHECK_FALSE("text_changed");
- SIGNAL_CHECK_FALSE("lines_edited_from");
- // Selects to end of previous line when at start of line.
- text_edit->remove_secondary_carets();
- text_edit->set_caret_line(1);
- text_edit->set_caret_column(0);
- text_edit->select(1, 1, 1, 0);
- MessageQueue::get_singleton()->flush();
- SIGNAL_DISCARD("caret_changed");
- SEND_GUI_KEY_EVENT(Key::LEFT | KeyModifierMask::SHIFT);
- CHECK(text_edit->get_viewport()->is_input_handled());
- CHECK(text_edit->get_caret_count() == 1);
- CHECK(text_edit->has_selection(0));
- CHECK(text_edit->get_selected_text(0) == "\nt");
- CHECK(text_edit->get_caret_line(0) == 0);
- CHECK(text_edit->get_caret_column(0) == 0);
- CHECK(text_edit->get_selection_origin_line(0) == 1);
- CHECK(text_edit->get_selection_origin_column(0) == 1);
- CHECK_FALSE(text_edit->is_caret_after_selection_origin(0));
- SIGNAL_CHECK("caret_changed", empty_signal_args);
- SIGNAL_CHECK_FALSE("text_changed");
- SIGNAL_CHECK_FALSE("lines_edited_from");
- // Merge selections when they overlap.
- text_edit->set_caret_line(1);
- text_edit->set_caret_column(4);
- text_edit->select(1, 6, 1, 4);
- text_edit->add_caret(1, 8);
- text_edit->select(1, 8, 1, 6, 1);
- MessageQueue::get_singleton()->flush();
- SIGNAL_DISCARD("caret_changed");
- CHECK(text_edit->get_caret_count() == 2);
- SEND_GUI_KEY_EVENT(Key::LEFT | KeyModifierMask::SHIFT);
- CHECK(text_edit->get_viewport()->is_input_handled());
- CHECK(text_edit->get_caret_count() == 1);
- CHECK(text_edit->has_selection(0));
- CHECK(text_edit->get_selected_text(0) == "s is ");
- CHECK(text_edit->get_caret_line(0) == 1);
- CHECK(text_edit->get_caret_column(0) == 3);
- CHECK(text_edit->get_selection_origin_line(0) == 1);
- CHECK(text_edit->get_selection_origin_column(0) == 8);
- CHECK_FALSE(text_edit->is_caret_after_selection_origin(0));
- SIGNAL_CHECK("caret_changed", empty_signal_args);
- SIGNAL_CHECK_FALSE("text_changed");
- SIGNAL_CHECK_FALSE("lines_edited_from");
- }
- SUBCASE("[TextEdit] ui_text_caret_word_right") {
- text_edit->set_text("this is some test text\n\nthis is some test text");
- text_edit->set_caret_line(0);
- text_edit->set_caret_column(15);
- text_edit->add_caret(2, 10);
- text_edit->select(0, 10, 0, 15);
- text_edit->select(2, 15, 2, 10, 1);
- MessageQueue::get_singleton()->flush();
- SIGNAL_DISCARD("text_set");
- SIGNAL_DISCARD("text_changed");
- SIGNAL_DISCARD("lines_edited_from");
- SIGNAL_DISCARD("caret_changed");
- // Select to end of next word when selection is right to left.
- // Deselect to end of previous word when selection is left to right.
- #ifdef MACOS_ENABLED
- SEND_GUI_KEY_EVENT(Key::RIGHT | KeyModifierMask::ALT | KeyModifierMask::SHIFT);
- #else
- SEND_GUI_KEY_EVENT(Key::RIGHT | KeyModifierMask::CMD_OR_CTRL | KeyModifierMask::SHIFT);
- #endif
- CHECK(text_edit->get_viewport()->is_input_handled());
- CHECK(text_edit->get_caret_count() == 2);
- CHECK(text_edit->has_selection(0));
- CHECK(text_edit->get_selected_text(0) == "me test");
- CHECK(text_edit->get_caret_line(0) == 0);
- CHECK(text_edit->get_caret_column(0) == 17);
- CHECK(text_edit->get_selection_origin_line(0) == 0);
- CHECK(text_edit->get_selection_origin_column(0) == 10);
- CHECK(text_edit->is_caret_after_selection_origin(0));
- CHECK(text_edit->has_selection(1));
- CHECK(text_edit->get_selected_text(1) == " te");
- CHECK(text_edit->get_caret_line(1) == 2);
- CHECK(text_edit->get_caret_column(1) == 12);
- CHECK(text_edit->get_selection_origin_line(1) == 2);
- CHECK(text_edit->get_selection_origin_column(1) == 15);
- CHECK_FALSE(text_edit->is_caret_after_selection_origin(1));
- SIGNAL_CHECK("caret_changed", empty_signal_args);
- SIGNAL_CHECK_FALSE("text_changed");
- SIGNAL_CHECK_FALSE("lines_edited_from");
- // Select to end of word with shift.
- text_edit->deselect();
- text_edit->set_caret_column(13);
- text_edit->set_caret_column(15, false, 1);
- MessageQueue::get_singleton()->flush();
- SIGNAL_DISCARD("caret_changed");
- #ifdef MACOS_ENABLED
- SEND_GUI_KEY_EVENT(Key::RIGHT | KeyModifierMask::ALT | KeyModifierMask::SHIFT);
- #else
- SEND_GUI_KEY_EVENT(Key::RIGHT | KeyModifierMask::CMD_OR_CTRL | KeyModifierMask::SHIFT);
- #endif
- CHECK(text_edit->get_viewport()->is_input_handled());
- CHECK(text_edit->get_caret_count() == 2);
- CHECK(text_edit->has_selection(0));
- CHECK(text_edit->get_selected_text(0) == "test");
- CHECK(text_edit->get_caret_line(0) == 0);
- CHECK(text_edit->get_caret_column(0) == 17);
- CHECK(text_edit->get_selection_origin_line(0) == 0);
- CHECK(text_edit->get_selection_origin_column(0) == 13);
- CHECK(text_edit->is_caret_after_selection_origin(0));
- CHECK(text_edit->has_selection(1));
- CHECK(text_edit->get_selected_text(1) == "st");
- CHECK(text_edit->get_caret_line(1) == 2);
- CHECK(text_edit->get_caret_column(1) == 17);
- CHECK(text_edit->get_selection_origin_line(1) == 2);
- CHECK(text_edit->get_selection_origin_column(1) == 15);
- CHECK(text_edit->is_caret_after_selection_origin(1));
- SIGNAL_CHECK("caret_changed", empty_signal_args);
- SIGNAL_CHECK_FALSE("text_changed");
- SIGNAL_CHECK_FALSE("lines_edited_from");
- // Deselect and move caret to end of next word without shift.
- SEND_GUI_ACTION("ui_text_caret_word_right");
- CHECK(text_edit->get_viewport()->is_input_handled());
- CHECK(text_edit->get_caret_count() == 2);
- CHECK_FALSE(text_edit->has_selection(0));
- CHECK(text_edit->get_caret_line(0) == 0);
- CHECK(text_edit->get_caret_column(0) == 22);
- CHECK_FALSE(text_edit->has_selection(1));
- CHECK(text_edit->get_caret_line(1) == 2);
- CHECK(text_edit->get_caret_column(1) == 22);
- SIGNAL_CHECK("caret_changed", empty_signal_args);
- SIGNAL_CHECK_FALSE("text_changed");
- SIGNAL_CHECK_FALSE("lines_edited_from");
- // Moves to start of next line when at end of line. Does nothing at end of text.
- SEND_GUI_ACTION("ui_text_caret_word_right");
- CHECK(text_edit->get_viewport()->is_input_handled());
- CHECK(text_edit->get_caret_count() == 2);
- CHECK_FALSE(text_edit->has_selection(0));
- CHECK(text_edit->get_caret_line(0) == 1);
- CHECK(text_edit->get_caret_column(0) == 0);
- CHECK_FALSE(text_edit->has_selection(1));
- CHECK(text_edit->get_caret_line(1) == 2);
- CHECK(text_edit->get_caret_column(1) == 22);
- SIGNAL_CHECK("caret_changed", empty_signal_args);
- SIGNAL_CHECK_FALSE("text_changed");
- SIGNAL_CHECK_FALSE("lines_edited_from");
- // Move when there are no words, only symbols.
- text_edit->set_text("#{}");
- text_edit->set_caret_line(0);
- text_edit->set_caret_column(0);
- SEND_GUI_ACTION("ui_text_caret_word_right");
- CHECK(text_edit->get_viewport()->is_input_handled());
- CHECK(text_edit->get_caret_line(0) == 0);
- CHECK(text_edit->get_caret_column(0) == 3);
- }
- SUBCASE("[TextEdit] ui_text_caret_right") {
- text_edit->set_text("this is some test text\n\nthis is some test text");
- text_edit->set_caret_line(0);
- text_edit->set_caret_column(19);
- text_edit->select(0, 15, 0, 19);
- text_edit->add_caret(2, 15);
- text_edit->select(2, 19, 2, 15, 1);
- MessageQueue::get_singleton()->flush();
- SIGNAL_DISCARD("text_set");
- SIGNAL_DISCARD("text_changed");
- SIGNAL_DISCARD("lines_edited_from");
- SIGNAL_DISCARD("caret_changed");
- // Remove one character from selection when selection is right to left.
- // Add one character to selection when selection is left to right.
- SEND_GUI_KEY_EVENT(Key::RIGHT | KeyModifierMask::SHIFT);
- CHECK(text_edit->get_viewport()->is_input_handled());
- CHECK(text_edit->get_caret_count() == 2);
- CHECK(text_edit->has_selection(0));
- CHECK(text_edit->get_selected_text(0) == "st te");
- CHECK(text_edit->get_caret_line(0) == 0);
- CHECK(text_edit->get_caret_column(0) == 20);
- CHECK(text_edit->get_selection_origin_line(0) == 0);
- CHECK(text_edit->get_selection_origin_column(0) == 15);
- CHECK(text_edit->is_caret_after_selection_origin(0));
- CHECK(text_edit->has_selection(1));
- CHECK(text_edit->get_selected_text(1) == "t t");
- CHECK(text_edit->get_caret_line(1) == 2);
- CHECK(text_edit->get_caret_column(1) == 16);
- CHECK(text_edit->get_selection_origin_line(1) == 2);
- CHECK(text_edit->get_selection_origin_column(1) == 19);
- CHECK_FALSE(text_edit->is_caret_after_selection_origin(1));
- SIGNAL_CHECK("caret_changed", empty_signal_args);
- SIGNAL_CHECK_FALSE("text_changed");
- SIGNAL_CHECK_FALSE("lines_edited_from");
- // Deselect and put caret at selection end without shift.
- SEND_GUI_ACTION("ui_text_caret_right");
- CHECK(text_edit->get_viewport()->is_input_handled());
- CHECK(text_edit->get_caret_count() == 2);
- CHECK_FALSE(text_edit->has_selection(0));
- CHECK(text_edit->get_caret_line(0) == 0);
- CHECK(text_edit->get_caret_column(0) == 20);
- CHECK_FALSE(text_edit->has_selection(1));
- CHECK(text_edit->get_caret_line(1) == 2);
- CHECK(text_edit->get_caret_column(1) == 19);
- SIGNAL_CHECK("caret_changed", empty_signal_args);
- SIGNAL_CHECK_FALSE("text_changed");
- SIGNAL_CHECK_FALSE("lines_edited_from");
- // Move caret one character to the right.
- SEND_GUI_ACTION("ui_text_caret_right");
- CHECK(text_edit->get_viewport()->is_input_handled());
- CHECK(text_edit->get_caret_count() == 2);
- CHECK_FALSE(text_edit->has_selection(0));
- CHECK(text_edit->get_caret_line(0) == 0);
- CHECK(text_edit->get_caret_column(0) == 21);
- CHECK_FALSE(text_edit->has_selection(1));
- CHECK(text_edit->get_caret_line(1) == 2);
- CHECK(text_edit->get_caret_column(1) == 20);
- SIGNAL_CHECK("caret_changed", empty_signal_args);
- SIGNAL_CHECK_FALSE("text_changed");
- SIGNAL_CHECK_FALSE("lines_edited_from");
- // Select one character to the right with shift and no existing selection.
- SEND_GUI_KEY_EVENT(Key::RIGHT | KeyModifierMask::SHIFT);
- CHECK(text_edit->get_viewport()->is_input_handled());
- CHECK(text_edit->get_caret_count() == 2);
- CHECK(text_edit->has_selection(0));
- CHECK(text_edit->get_selected_text(0) == "t");
- CHECK(text_edit->get_caret_line(0) == 0);
- CHECK(text_edit->get_caret_column(0) == 22);
- CHECK(text_edit->get_selection_origin_line(0) == 0);
- CHECK(text_edit->get_selection_origin_column(0) == 21);
- CHECK(text_edit->is_caret_after_selection_origin(0));
- CHECK(text_edit->has_selection(1));
- CHECK(text_edit->get_selected_text(1) == "x");
- CHECK(text_edit->get_caret_line(1) == 2);
- CHECK(text_edit->get_caret_column(1) == 21);
- CHECK(text_edit->get_selection_origin_line(1) == 2);
- CHECK(text_edit->get_selection_origin_column(1) == 20);
- CHECK(text_edit->is_caret_after_selection_origin(1));
- SIGNAL_CHECK("caret_changed", empty_signal_args);
- SIGNAL_CHECK_FALSE("text_changed");
- SIGNAL_CHECK_FALSE("lines_edited_from");
- // Moves to start of next line when at end of line. Does nothing at end of text.
- text_edit->deselect();
- text_edit->set_caret_line(0);
- text_edit->set_caret_column(22);
- text_edit->set_caret_column(22, false, 1);
- MessageQueue::get_singleton()->flush();
- SIGNAL_DISCARD("caret_changed");
- SEND_GUI_ACTION("ui_text_caret_right");
- CHECK(text_edit->get_viewport()->is_input_handled());
- CHECK(text_edit->get_caret_count() == 2);
- CHECK_FALSE(text_edit->has_selection(0));
- CHECK(text_edit->get_caret_line(0) == 1);
- CHECK(text_edit->get_caret_column(0) == 0);
- CHECK_FALSE(text_edit->has_selection(1));
- CHECK(text_edit->get_caret_line(1) == 2);
- CHECK(text_edit->get_caret_column(1) == 22);
- SIGNAL_CHECK("caret_changed", empty_signal_args);
- SIGNAL_CHECK_FALSE("text_changed");
- SIGNAL_CHECK_FALSE("lines_edited_from");
- // Selects to start of next line when at end of line.
- text_edit->remove_secondary_carets();
- text_edit->set_caret_line(0);
- text_edit->set_caret_column(22);
- text_edit->select(0, 21, 0, 22);
- MessageQueue::get_singleton()->flush();
- SIGNAL_DISCARD("caret_changed");
- SEND_GUI_KEY_EVENT(Key::RIGHT | KeyModifierMask::SHIFT);
- CHECK(text_edit->get_viewport()->is_input_handled());
- CHECK(text_edit->get_caret_count() == 1);
- CHECK(text_edit->has_selection(0));
- CHECK(text_edit->get_selected_text(0) == "t\n");
- CHECK(text_edit->get_caret_line(0) == 1);
- CHECK(text_edit->get_caret_column(0) == 0);
- CHECK(text_edit->get_selection_origin_line(0) == 0);
- CHECK(text_edit->get_selection_origin_column(0) == 21);
- CHECK(text_edit->is_caret_after_selection_origin(0));
- SIGNAL_CHECK("caret_changed", empty_signal_args);
- SIGNAL_CHECK_FALSE("text_changed");
- SIGNAL_CHECK_FALSE("lines_edited_from");
- // Merge selections when they overlap.
- text_edit->set_caret_line(0);
- text_edit->set_caret_column(4);
- text_edit->select(0, 4, 0, 6);
- text_edit->add_caret(0, 8);
- text_edit->select(0, 6, 0, 8, 1);
- MessageQueue::get_singleton()->flush();
- SIGNAL_DISCARD("caret_changed");
- CHECK(text_edit->get_caret_count() == 2);
- SEND_GUI_KEY_EVENT(Key::RIGHT | KeyModifierMask::SHIFT);
- CHECK(text_edit->get_viewport()->is_input_handled());
- CHECK(text_edit->get_caret_count() == 1);
- CHECK(text_edit->has_selection(0));
- CHECK(text_edit->get_selected_text(0) == " is s");
- CHECK(text_edit->get_caret_line(0) == 0);
- CHECK(text_edit->get_caret_column(0) == 9);
- CHECK(text_edit->get_selection_origin_line(0) == 0);
- CHECK(text_edit->get_selection_origin_column(0) == 4);
- CHECK(text_edit->is_caret_after_selection_origin(0));
- SIGNAL_CHECK("caret_changed", empty_signal_args);
- SIGNAL_CHECK_FALSE("text_changed");
- SIGNAL_CHECK_FALSE("lines_edited_from");
- }
- SUBCASE("[TextEdit] ui_text_caret_up") {
- text_edit->set_line_wrapping_mode(TextEdit::LineWrappingMode::LINE_WRAPPING_BOUNDARY);
- text_edit->set_size(Size2(110, 100));
- text_edit->set_text("this is some\nother test\nlines\ngo here\nthis is some\nother test\nlines\ngo here");
- text_edit->set_caret_line(3);
- text_edit->set_caret_column(7);
- text_edit->add_caret(7, 7);
- CHECK(text_edit->get_caret_count() == 2);
- MessageQueue::get_singleton()->flush();
- // Lines 0 and 4 are wrapped into 2 parts: 'this is ' and 'some'.
- CHECK(text_edit->is_line_wrapped(0));
- SIGNAL_DISCARD("text_set");
- SIGNAL_DISCARD("text_changed");
- SIGNAL_DISCARD("lines_edited_from");
- SIGNAL_DISCARD("caret_changed");
- // Select + up should select everything to the left on that line.
- SEND_GUI_KEY_EVENT(Key::UP | KeyModifierMask::SHIFT);
- CHECK(text_edit->get_viewport()->is_input_handled());
- CHECK(text_edit->get_caret_line() == 2);
- CHECK(text_edit->get_caret_column() == 5);
- CHECK(text_edit->get_selected_text(0) == "\ngo here");
- CHECK(text_edit->has_selection(0));
- CHECK(text_edit->get_caret_line(1) == 6);
- CHECK(text_edit->get_caret_column(1) == 5);
- CHECK(text_edit->get_selected_text(1) == "\ngo here");
- CHECK(text_edit->has_selection(1));
- SIGNAL_CHECK("caret_changed", empty_signal_args);
- SIGNAL_CHECK_FALSE("text_changed");
- SIGNAL_CHECK_FALSE("lines_edited_from");
- // Should deselect and move up.
- SEND_GUI_ACTION("ui_text_caret_up");
- CHECK(text_edit->get_viewport()->is_input_handled());
- CHECK(text_edit->get_caret_line() == 1);
- CHECK(text_edit->get_caret_column() == 8);
- CHECK_FALSE(text_edit->has_selection(0));
- CHECK(text_edit->get_caret_line(1) == 5);
- CHECK(text_edit->get_caret_column(1) == 8);
- CHECK_FALSE(text_edit->has_selection(1));
- SIGNAL_CHECK("caret_changed", empty_signal_args);
- SIGNAL_CHECK_FALSE("text_changed");
- SIGNAL_CHECK_FALSE("lines_edited_from");
- // Normal up over wrapped line.
- SEND_GUI_ACTION("ui_text_caret_up");
- CHECK(text_edit->get_viewport()->is_input_handled());
- CHECK(text_edit->get_caret_line() == 0);
- CHECK(text_edit->get_caret_column() == 12);
- CHECK_FALSE(text_edit->has_selection(0));
- CHECK(text_edit->get_caret_line(1) == 4);
- CHECK(text_edit->get_caret_column(1) == 12);
- CHECK_FALSE(text_edit->has_selection(1));
- SIGNAL_CHECK("caret_changed", empty_signal_args);
- SIGNAL_CHECK_FALSE("text_changed");
- SIGNAL_CHECK_FALSE("lines_edited_from");
- // Normal up over wrapped line to line 0.
- text_edit->set_caret_column(12, false);
- SEND_GUI_ACTION("ui_text_caret_up");
- CHECK(text_edit->get_viewport()->is_input_handled());
- CHECK(text_edit->get_caret_line() == 0);
- CHECK(text_edit->get_caret_column() == 7);
- CHECK_FALSE(text_edit->has_selection(0));
- CHECK(text_edit->get_caret_line(1) == 4);
- CHECK(text_edit->get_caret_column(1) == 7);
- CHECK_FALSE(text_edit->has_selection(1));
- SIGNAL_CHECK("caret_changed", empty_signal_args);
- SIGNAL_CHECK_FALSE("text_changed");
- SIGNAL_CHECK_FALSE("lines_edited_from");
- // Normal up from column 0 to a wrapped line.
- text_edit->remove_secondary_carets();
- text_edit->set_caret_line(5);
- text_edit->set_caret_column(0);
- SEND_GUI_ACTION("ui_text_caret_up");
- CHECK(text_edit->get_viewport()->is_input_handled());
- CHECK(text_edit->get_caret_line() == 4);
- CHECK(text_edit->get_caret_column() == 8);
- CHECK_FALSE(text_edit->has_selection(0));
- // Normal up to column 0 of a wrapped line.
- SEND_GUI_ACTION("ui_text_caret_up");
- CHECK(text_edit->get_viewport()->is_input_handled());
- CHECK(text_edit->get_caret_line() == 4);
- CHECK(text_edit->get_caret_column() == 0);
- CHECK_FALSE(text_edit->has_selection(0));
- }
- SUBCASE("[TextEdit] ui_text_caret_down") {
- text_edit->set_line_wrapping_mode(TextEdit::LineWrappingMode::LINE_WRAPPING_BOUNDARY);
- text_edit->set_size(Size2(110, 100));
- text_edit->set_text("go here\nlines\nother test\nthis is some\ngo here\nlines\nother test\nthis is some");
- text_edit->set_caret_line(0);
- text_edit->set_caret_column(7);
- text_edit->add_caret(4, 7);
- CHECK(text_edit->get_caret_count() == 2);
- MessageQueue::get_singleton()->flush();
- // Lines 3 and 7 are wrapped into 2 parts: 'this is ' and 'some'.
- CHECK(text_edit->is_line_wrapped(3));
- SIGNAL_DISCARD("text_set");
- SIGNAL_DISCARD("text_changed");
- SIGNAL_DISCARD("lines_edited_from");
- SIGNAL_DISCARD("caret_changed");
- // Select + down should select everything to the right on that line.
- SEND_GUI_KEY_EVENT(Key::DOWN | KeyModifierMask::SHIFT);
- CHECK(text_edit->get_viewport()->is_input_handled());
- CHECK(text_edit->get_caret_line() == 1);
- CHECK(text_edit->get_caret_column() == 5);
- CHECK(text_edit->get_selected_text(0) == "\nlines");
- CHECK(text_edit->has_selection(0));
- CHECK(text_edit->get_caret_line(1) == 5);
- CHECK(text_edit->get_caret_column(1) == 5);
- CHECK(text_edit->get_selected_text(1) == "\nlines");
- CHECK(text_edit->has_selection(1));
- SIGNAL_CHECK("caret_changed", empty_signal_args);
- SIGNAL_CHECK_FALSE("text_changed");
- SIGNAL_CHECK_FALSE("lines_edited_from");
- // Should deselect and move down.
- SEND_GUI_ACTION("ui_text_caret_down");
- CHECK(text_edit->get_viewport()->is_input_handled());
- CHECK(text_edit->get_caret_line() == 2);
- CHECK(text_edit->get_caret_column() == 8);
- CHECK_FALSE(text_edit->has_selection(0));
- CHECK(text_edit->get_caret_line(1) == 6);
- CHECK(text_edit->get_caret_column(1) == 8);
- CHECK_FALSE(text_edit->has_selection(1));
- SIGNAL_CHECK("caret_changed", empty_signal_args);
- SIGNAL_CHECK_FALSE("text_changed");
- SIGNAL_CHECK_FALSE("lines_edited_from");
- // Normal down over wrapped line.
- SEND_GUI_ACTION("ui_text_caret_down");
- CHECK(text_edit->get_viewport()->is_input_handled());
- CHECK(text_edit->get_caret_line() == 3);
- CHECK(text_edit->get_caret_column() == 7);
- CHECK_FALSE(text_edit->has_selection(0));
- CHECK(text_edit->get_caret_line(1) == 7);
- CHECK(text_edit->get_caret_column(1) == 7);
- CHECK_FALSE(text_edit->has_selection(1));
- SIGNAL_CHECK("caret_changed", empty_signal_args);
- SIGNAL_CHECK_FALSE("text_changed");
- SIGNAL_CHECK_FALSE("lines_edited_from");
- // Normal down over wrapped line to last wrapped line.
- text_edit->set_caret_column(7, false);
- SEND_GUI_ACTION("ui_text_caret_down");
- CHECK(text_edit->get_viewport()->is_input_handled());
- CHECK(text_edit->get_caret_line() == 3);
- CHECK(text_edit->get_caret_column() == 12);
- CHECK_FALSE(text_edit->has_selection(0));
- CHECK(text_edit->get_caret_line(1) == 7);
- CHECK(text_edit->get_caret_column(1) == 12);
- CHECK_FALSE(text_edit->has_selection(1));
- SIGNAL_CHECK("caret_changed", empty_signal_args);
- SIGNAL_CHECK_FALSE("text_changed");
- SIGNAL_CHECK_FALSE("lines_edited_from");
- // Normal down to column 0 of a wrapped line.
- text_edit->remove_secondary_carets();
- text_edit->set_caret_line(3);
- text_edit->set_caret_column(0);
- SEND_GUI_ACTION("ui_text_caret_down");
- CHECK(text_edit->get_viewport()->is_input_handled());
- CHECK(text_edit->get_caret_line() == 3);
- CHECK(text_edit->get_caret_column() == 8);
- CHECK_FALSE(text_edit->has_selection(0));
- // Normal down out of visual column 0 of a wrapped line moves to start of next line.
- SEND_GUI_ACTION("ui_text_caret_down");
- CHECK(text_edit->get_viewport()->is_input_handled());
- CHECK(text_edit->get_caret_line() == 4);
- CHECK(text_edit->get_caret_column() == 0);
- CHECK_FALSE(text_edit->has_selection(0));
- }
- SUBCASE("[TextEdit] ui_text_caret_document_start") {
- text_edit->set_line_wrapping_mode(TextEdit::LineWrappingMode::LINE_WRAPPING_BOUNDARY);
- text_edit->set_size(Size2(110, 100));
- text_edit->set_text("this is some\nother test\nlines\ngo here");
- text_edit->set_caret_line(4);
- text_edit->set_caret_column(7);
- text_edit->add_caret(3, 2);
- CHECK(text_edit->get_caret_count() == 2);
- MessageQueue::get_singleton()->flush();
- CHECK(text_edit->is_line_wrapped(0));
- SIGNAL_DISCARD("text_set");
- SIGNAL_DISCARD("text_changed");
- SIGNAL_DISCARD("lines_edited_from");
- SIGNAL_DISCARD("caret_changed");
- #ifdef MACOS_ENABLED
- SEND_GUI_KEY_EVENT(Key::UP | KeyModifierMask::CMD_OR_CTRL | KeyModifierMask::SHIFT);
- #else
- SEND_GUI_KEY_EVENT(Key::HOME | KeyModifierMask::CMD_OR_CTRL | KeyModifierMask::SHIFT);
- #endif
- CHECK(text_edit->get_viewport()->is_input_handled());
- CHECK(text_edit->get_text() == "this is some\nother test\nlines\ngo here");
- CHECK(text_edit->get_caret_line() == 0);
- CHECK(text_edit->get_caret_column() == 0);
- CHECK(text_edit->get_selected_text() == "this is some\nother test\nlines\ngo here");
- CHECK(text_edit->has_selection());
- SIGNAL_CHECK("caret_changed", empty_signal_args);
- SIGNAL_CHECK_FALSE("text_changed");
- SIGNAL_CHECK_FALSE("lines_edited_from");
- CHECK(text_edit->get_caret_count() == 1);
- SEND_GUI_ACTION("ui_text_caret_document_start");
- CHECK(text_edit->get_viewport()->is_input_handled());
- CHECK(text_edit->get_text() == "this is some\nother test\nlines\ngo here");
- CHECK(text_edit->get_caret_line() == 0);
- CHECK(text_edit->get_caret_column() == 0);
- CHECK_FALSE(text_edit->has_selection());
- SIGNAL_CHECK_FALSE("caret_changed");
- SIGNAL_CHECK_FALSE("text_changed");
- SIGNAL_CHECK_FALSE("lines_edited_from");
- }
- SUBCASE("[TextEdit] ui_text_caret_document_end") {
- text_edit->set_line_wrapping_mode(TextEdit::LineWrappingMode::LINE_WRAPPING_BOUNDARY);
- text_edit->set_size(Size2(110, 100));
- text_edit->set_text("go here\nlines\nother test\nthis is some");
- text_edit->set_caret_line(0);
- text_edit->set_caret_column(0);
- text_edit->add_caret(1, 0);
- CHECK(text_edit->get_caret_count() == 2);
- MessageQueue::get_singleton()->flush();
- CHECK(text_edit->is_line_wrapped(3));
- SIGNAL_DISCARD("text_set");
- SIGNAL_DISCARD("text_changed");
- SIGNAL_DISCARD("lines_edited_from");
- SIGNAL_DISCARD("caret_changed");
- #ifdef MACOS_ENABLED
- SEND_GUI_KEY_EVENT(Key::DOWN | KeyModifierMask::CMD_OR_CTRL | KeyModifierMask::SHIFT);
- #else
- SEND_GUI_KEY_EVENT(Key::END | KeyModifierMask::CMD_OR_CTRL | KeyModifierMask::SHIFT);
- #endif
- CHECK(text_edit->get_viewport()->is_input_handled());
- CHECK(text_edit->get_text() == "go here\nlines\nother test\nthis is some");
- CHECK(text_edit->get_caret_line() == 3);
- CHECK(text_edit->get_caret_column() == 12);
- CHECK(text_edit->get_selected_text() == "go here\nlines\nother test\nthis is some");
- CHECK(text_edit->has_selection());
- SIGNAL_CHECK("caret_changed", empty_signal_args);
- SIGNAL_CHECK_FALSE("text_changed");
- SIGNAL_CHECK_FALSE("lines_edited_from");
- CHECK(text_edit->get_caret_count() == 1);
- SEND_GUI_ACTION("ui_text_caret_document_end");
- CHECK(text_edit->get_viewport()->is_input_handled());
- CHECK(text_edit->get_text() == "go here\nlines\nother test\nthis is some");
- CHECK(text_edit->get_caret_line() == 3);
- CHECK(text_edit->get_caret_column() == 12);
- CHECK_FALSE(text_edit->has_selection());
- SIGNAL_CHECK_FALSE("caret_changed");
- SIGNAL_CHECK_FALSE("text_changed");
- SIGNAL_CHECK_FALSE("lines_edited_from");
- }
- SUBCASE("[TextEdit] ui_text_caret_line_start") {
- text_edit->set_line_wrapping_mode(TextEdit::LineWrappingMode::LINE_WRAPPING_BOUNDARY);
- text_edit->set_size(Size2(110, 100));
- text_edit->set_text(" this is some\n this is some");
- text_edit->set_caret_line(0);
- text_edit->set_caret_column(text_edit->get_line(0).length());
- text_edit->add_caret(1, text_edit->get_line(1).length());
- CHECK(text_edit->get_caret_count() == 2);
- MessageQueue::get_singleton()->flush();
- CHECK(text_edit->is_line_wrapped(0));
- SIGNAL_DISCARD("text_set");
- SIGNAL_DISCARD("text_changed");
- SIGNAL_DISCARD("lines_edited_from");
- SIGNAL_DISCARD("caret_changed");
- #ifdef MACOS_ENABLED
- SEND_GUI_KEY_EVENT(Key::LEFT | KeyModifierMask::CMD_OR_CTRL | KeyModifierMask::SHIFT);
- #else
- SEND_GUI_KEY_EVENT(Key::HOME | KeyModifierMask::SHIFT);
- #endif
- CHECK(text_edit->get_viewport()->is_input_handled());
- CHECK(text_edit->get_caret_line() == 0);
- CHECK(text_edit->get_caret_column() == 10);
- CHECK(text_edit->has_selection(0));
- CHECK(text_edit->get_selected_text(0) == "some");
- CHECK(text_edit->get_caret_line(1) == 1);
- CHECK(text_edit->get_caret_column(1) == 10);
- CHECK(text_edit->has_selection(1));
- CHECK(text_edit->get_selected_text(1) == "some");
- SIGNAL_CHECK("caret_changed", empty_signal_args);
- SIGNAL_CHECK_FALSE("text_changed");
- SIGNAL_CHECK_FALSE("lines_edited_from");
- SEND_GUI_ACTION("ui_text_caret_line_start");
- CHECK(text_edit->get_viewport()->is_input_handled());
- CHECK(text_edit->get_caret_line() == 0);
- CHECK(text_edit->get_caret_column() == 2);
- CHECK_FALSE(text_edit->has_selection(0));
- CHECK(text_edit->get_caret_line(1) == 1);
- CHECK(text_edit->get_caret_column(1) == 2);
- CHECK_FALSE(text_edit->has_selection(1));
- SIGNAL_CHECK("caret_changed", empty_signal_args);
- SIGNAL_CHECK_FALSE("text_changed");
- SIGNAL_CHECK_FALSE("lines_edited_from");
- SEND_GUI_ACTION("ui_text_caret_line_start");
- CHECK(text_edit->get_viewport()->is_input_handled());
- CHECK(text_edit->get_caret_line() == 0);
- CHECK(text_edit->get_caret_column() == 0);
- CHECK_FALSE(text_edit->has_selection(0));
- CHECK(text_edit->get_caret_line(1) == 1);
- CHECK(text_edit->get_caret_column(1) == 0);
- CHECK_FALSE(text_edit->has_selection(1));
- SIGNAL_CHECK("caret_changed", empty_signal_args);
- SIGNAL_CHECK_FALSE("text_changed");
- SIGNAL_CHECK_FALSE("lines_edited_from");
- SEND_GUI_ACTION("ui_text_caret_line_start");
- CHECK(text_edit->get_viewport()->is_input_handled());
- CHECK(text_edit->get_caret_line() == 0);
- CHECK(text_edit->get_caret_column() == 2);
- CHECK_FALSE(text_edit->has_selection(0));
- CHECK(text_edit->get_caret_line(1) == 1);
- CHECK(text_edit->get_caret_column(1) == 2);
- CHECK_FALSE(text_edit->has_selection(1));
- SIGNAL_CHECK("caret_changed", empty_signal_args);
- SIGNAL_CHECK_FALSE("text_changed");
- SIGNAL_CHECK_FALSE("lines_edited_from");
- }
- SUBCASE("[TextEdit] ui_text_caret_line_end") {
- text_edit->set_line_wrapping_mode(TextEdit::LineWrappingMode::LINE_WRAPPING_BOUNDARY);
- text_edit->set_size(Size2(110, 100));
- text_edit->set_text(" this is some\n this is some");
- text_edit->set_caret_line(0);
- text_edit->set_caret_column(0);
- text_edit->add_caret(1, 0);
- CHECK(text_edit->get_caret_count() == 2);
- MessageQueue::get_singleton()->flush();
- CHECK(text_edit->is_line_wrapped(0));
- SIGNAL_DISCARD("text_set");
- SIGNAL_DISCARD("text_changed");
- SIGNAL_DISCARD("lines_edited_from");
- SIGNAL_DISCARD("caret_changed");
- #ifdef MACOS_ENABLED
- SEND_GUI_KEY_EVENT(Key::RIGHT | KeyModifierMask::CMD_OR_CTRL | KeyModifierMask::SHIFT);
- #else
- SEND_GUI_KEY_EVENT(Key::END | KeyModifierMask::SHIFT);
- #endif
- CHECK(text_edit->get_viewport()->is_input_handled());
- CHECK(text_edit->get_caret_line() == 0);
- CHECK(text_edit->get_caret_column() == 9);
- CHECK(text_edit->has_selection(0));
- CHECK(text_edit->get_selected_text(0) == " this is");
- CHECK(text_edit->get_caret_line(1) == 1);
- CHECK(text_edit->get_caret_column(1) == 9);
- CHECK(text_edit->has_selection(1));
- CHECK(text_edit->get_selected_text(1) == " this is");
- SIGNAL_CHECK("caret_changed", empty_signal_args);
- SIGNAL_CHECK_FALSE("text_changed");
- SIGNAL_CHECK_FALSE("lines_edited_from");
- SEND_GUI_ACTION("ui_text_caret_line_end");
- CHECK(text_edit->get_viewport()->is_input_handled());
- CHECK(text_edit->get_caret_line() == 0);
- CHECK(text_edit->get_caret_column() == text_edit->get_line(0).length());
- CHECK_FALSE(text_edit->has_selection(0));
- CHECK(text_edit->get_viewport()->is_input_handled());
- CHECK(text_edit->get_caret_line(1) == 1);
- CHECK(text_edit->get_caret_column(1) == text_edit->get_line(1).length());
- CHECK_FALSE(text_edit->has_selection(1));
- SIGNAL_CHECK("caret_changed", empty_signal_args);
- SIGNAL_CHECK_FALSE("text_changed");
- SIGNAL_CHECK_FALSE("lines_edited_from");
- }
- SUBCASE("[TextEdit] unicode") {
- text_edit->set_text("\n");
- text_edit->set_caret_line(0);
- text_edit->set_caret_column(0);
- text_edit->add_caret(1, 0);
- CHECK(text_edit->get_caret_count() == 2);
- text_edit->insert_text_at_caret("a");
- MessageQueue::get_singleton()->flush();
- SIGNAL_DISCARD("text_set");
- SIGNAL_DISCARD("text_changed");
- SIGNAL_DISCARD("lines_edited_from");
- SIGNAL_DISCARD("caret_changed");
- lines_edited_args = build_array(build_array(0, 0), build_array(1, 1));
- SEND_GUI_KEY_EVENT(Key::A);
- CHECK(text_edit->get_viewport()->is_input_handled());
- CHECK(text_edit->get_text() == "aA\naA");
- CHECK(text_edit->get_caret_column() == 2);
- CHECK(text_edit->get_caret_column(1) == 2);
- SIGNAL_CHECK("caret_changed", empty_signal_args);
- SIGNAL_CHECK("text_changed", empty_signal_args);
- SIGNAL_CHECK("lines_edited_from", lines_edited_args);
- // Undo reverts both carets.
- text_edit->undo();
- MessageQueue::get_singleton()->flush();
- CHECK(text_edit->get_text() == "a\na");
- CHECK(text_edit->get_caret_column() == 1);
- CHECK(text_edit->get_caret_column(1) == 1);
- SIGNAL_CHECK("caret_changed", empty_signal_args);
- SIGNAL_CHECK("text_changed", empty_signal_args);
- SIGNAL_CHECK("lines_edited_from", reverse_nested(lines_edited_args));
- // Redo.
- text_edit->redo();
- MessageQueue::get_singleton()->flush();
- CHECK(text_edit->get_text() == "aA\naA");
- CHECK(text_edit->get_caret_column() == 2);
- CHECK(text_edit->get_caret_column(1) == 2);
- SIGNAL_CHECK("caret_changed", empty_signal_args);
- SIGNAL_CHECK("text_changed", empty_signal_args);
- SIGNAL_CHECK("lines_edited_from", lines_edited_args);
- // Does not work if not editable.
- text_edit->set_editable(false);
- SEND_GUI_KEY_EVENT(Key::A);
- CHECK_FALSE(text_edit->get_viewport()->is_input_handled()); // Should this be handled?
- CHECK(text_edit->get_text() == "aA\naA");
- CHECK(text_edit->get_caret_column() == 2);
- CHECK(text_edit->get_caret_column(1) == 2);
- SIGNAL_CHECK_FALSE("caret_changed");
- SIGNAL_CHECK_FALSE("text_changed");
- SIGNAL_CHECK_FALSE("lines_edited_from");
- text_edit->set_editable(true);
- lines_edited_args = build_array(build_array(0, 0), build_array(0, 0), build_array(1, 1), build_array(1, 1));
- text_edit->select(0, 0, 0, 1);
- text_edit->select(1, 0, 1, 1, 1);
- SEND_GUI_KEY_EVENT(Key::B);
- CHECK(text_edit->get_viewport()->is_input_handled());
- CHECK(text_edit->get_text() == "BA\nBA");
- CHECK(text_edit->get_caret_column() == 1);
- CHECK(text_edit->get_caret_column(1) == 1);
- SIGNAL_CHECK("caret_changed", empty_signal_args);
- SIGNAL_CHECK("text_changed", empty_signal_args);
- SIGNAL_CHECK("lines_edited_from", lines_edited_args);
- SEND_GUI_ACTION("ui_text_toggle_insert_mode");
- CHECK(text_edit->is_overtype_mode_enabled());
- SEND_GUI_KEY_EVENT(Key::B);
- CHECK(text_edit->get_viewport()->is_input_handled());
- CHECK(text_edit->get_text() == "BB\nBB");
- CHECK(text_edit->get_caret_column() == 2);
- SIGNAL_CHECK("caret_changed", empty_signal_args);
- SIGNAL_CHECK("text_changed", empty_signal_args);
- SIGNAL_CHECK("lines_edited_from", lines_edited_args);
- text_edit->select(0, 0, 0, 1);
- text_edit->select(1, 0, 1, 1, 1);
- SEND_GUI_KEY_EVENT(Key::A);
- CHECK(text_edit->get_viewport()->is_input_handled());
- CHECK(text_edit->get_text() == "AB\nAB");
- CHECK(text_edit->get_caret_column() == 1);
- CHECK(text_edit->get_caret_column(1) == 1);
- SIGNAL_CHECK("caret_changed", empty_signal_args);
- SIGNAL_CHECK("text_changed", empty_signal_args);
- SIGNAL_CHECK("lines_edited_from", lines_edited_args);
- text_edit->set_overtype_mode_enabled(false);
- CHECK_FALSE(text_edit->is_overtype_mode_enabled());
- lines_edited_args = build_array(build_array(0, 0), build_array(1, 1));
- SEND_GUI_KEY_EVENT(Key::TAB);
- CHECK(text_edit->get_viewport()->is_input_handled());
- CHECK(text_edit->get_text() == "A\tB\nA\tB");
- CHECK(text_edit->get_caret_column() == 2);
- CHECK(text_edit->get_caret_column(1) == 2);
- SIGNAL_CHECK("caret_changed", empty_signal_args);
- SIGNAL_CHECK("text_changed", empty_signal_args);
- SIGNAL_CHECK("lines_edited_from", lines_edited_args);
- }
- SIGNAL_UNWATCH(text_edit, "text_set");
- SIGNAL_UNWATCH(text_edit, "text_changed");
- SIGNAL_UNWATCH(text_edit, "lines_edited_from");
- SIGNAL_UNWATCH(text_edit, "caret_changed");
- }
- memdelete(text_edit);
- }
- TEST_CASE("[SceneTree][TextEdit] context menu") {
- TextEdit *text_edit = memnew(TextEdit);
- SceneTree::get_singleton()->get_root()->add_child(text_edit);
- text_edit->set_size(Size2(800, 200));
- 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.");
- MessageQueue::get_singleton()->flush();
- text_edit->set_context_menu_enabled(false);
- CHECK_FALSE(text_edit->is_context_menu_enabled());
- CHECK_FALSE(text_edit->is_menu_visible());
- SEND_GUI_MOUSE_BUTTON_EVENT(Point2i(600, 10), MouseButton::RIGHT, MouseButtonMask::RIGHT, Key::NONE);
- CHECK_FALSE(text_edit->is_menu_visible());
- text_edit->set_context_menu_enabled(true);
- CHECK(text_edit->is_context_menu_enabled());
- CHECK_FALSE(text_edit->is_menu_visible());
- SEND_GUI_MOUSE_BUTTON_EVENT(Point2i(700, 10), MouseButton::RIGHT, MouseButtonMask::RIGHT, Key::NONE);
- CHECK(text_edit->is_menu_visible());
- memdelete(text_edit);
- }
- TEST_CASE("[SceneTree][TextEdit] versioning") {
- TextEdit *text_edit = memnew(TextEdit);
- SceneTree::get_singleton()->get_root()->add_child(text_edit);
- // Action undo / redo states are tested in the action test e.g selection_delete.
- CHECK_FALSE(text_edit->has_undo());
- CHECK_FALSE(text_edit->has_redo());
- CHECK(text_edit->get_version() == 0);
- CHECK(text_edit->get_saved_version() == 0);
- text_edit->begin_complex_operation();
- text_edit->begin_complex_operation();
- text_edit->begin_complex_operation();
- text_edit->insert_text_at_caret("test");
- CHECK(text_edit->get_version() == 1);
- CHECK(text_edit->get_saved_version() == 0);
- CHECK(text_edit->has_undo());
- CHECK_FALSE(text_edit->has_redo());
- text_edit->end_complex_operation();
- // Can undo and redo mid op.
- text_edit->insert_text_at_caret(" nested");
- CHECK(text_edit->get_version() == 2);
- CHECK(text_edit->get_saved_version() == 0);
- CHECK(text_edit->has_undo());
- CHECK_FALSE(text_edit->has_redo());
- text_edit->undo();
- CHECK(text_edit->has_redo());
- text_edit->redo();
- text_edit->end_complex_operation();
- text_edit->insert_text_at_caret(" ops");
- CHECK(text_edit->get_version() == 3);
- CHECK(text_edit->get_saved_version() == 0);
- CHECK(text_edit->has_undo());
- CHECK_FALSE(text_edit->has_redo());
- text_edit->end_complex_operation();
- text_edit->tag_saved_version();
- CHECK(text_edit->get_saved_version() == 3);
- text_edit->undo();
- CHECK(text_edit->get_line(0) == "");
- CHECK(text_edit->get_version() == 0);
- CHECK(text_edit->get_saved_version() == 3);
- CHECK_FALSE(text_edit->has_undo());
- CHECK(text_edit->has_redo());
- text_edit->redo();
- CHECK(text_edit->get_line(0) == "test ops nested");
- CHECK(text_edit->get_version() == 3);
- CHECK(text_edit->get_saved_version() == 3);
- CHECK(text_edit->has_undo());
- CHECK_FALSE(text_edit->has_redo());
- text_edit->clear_undo_history();
- CHECK_FALSE(text_edit->has_undo());
- CHECK_FALSE(text_edit->has_redo());
- CHECK(text_edit->get_version() == 3); // Should this be cleared?
- CHECK(text_edit->get_saved_version() == 0);
- SUBCASE("[TextEdit] versioning selection") {
- text_edit->set_text("Godot Engine\nWaiting for Godot\nTest Text for multi carat\nLine 4 Text");
- text_edit->set_multiple_carets_enabled(true);
- text_edit->remove_secondary_carets();
- text_edit->deselect();
- text_edit->set_caret_line(0);
- text_edit->set_caret_column(0);
- CHECK(text_edit->get_caret_count() == 1);
- Array caret_index;
- caret_index.push_back(0);
- for (int i = 1; i < 4; i++) {
- caret_index.push_back(text_edit->add_caret(i, 0));
- CHECK((int)caret_index.back() >= 0);
- }
- CHECK(text_edit->get_caret_count() == 4);
- for (int i = 0; i < 4; i++) {
- text_edit->select(i, 0, i, 5, caret_index[i]);
- }
- CHECK(text_edit->get_caret_count() == 4);
- for (int i = 0; i < 4; i++) {
- CHECK(text_edit->has_selection(caret_index[i]));
- CHECK(text_edit->get_selection_from_line(caret_index[i]) == i);
- CHECK(text_edit->get_selection_from_column(caret_index[i]) == 0);
- CHECK(text_edit->get_selection_to_line(caret_index[i]) == i);
- CHECK(text_edit->get_selection_to_column(caret_index[i]) == 5);
- }
- text_edit->begin_complex_operation();
- text_edit->deselect();
- text_edit->set_text("New Line Text");
- text_edit->select(0, 0, 0, 7, 0);
- text_edit->end_complex_operation();
- CHECK(text_edit->get_caret_count() == 1);
- CHECK(text_edit->get_selected_text(0) == "New Lin");
- text_edit->undo();
- CHECK(text_edit->get_caret_count() == 4);
- for (int i = 0; i < 4; i++) {
- CHECK(text_edit->has_selection(caret_index[i]));
- CHECK(text_edit->get_selection_from_line(caret_index[i]) == i);
- CHECK(text_edit->get_selection_from_column(caret_index[i]) == 0);
- CHECK(text_edit->get_selection_to_line(caret_index[i]) == i);
- CHECK(text_edit->get_selection_to_column(caret_index[i]) == 5);
- }
- }
- memdelete(text_edit);
- }
- TEST_CASE("[SceneTree][TextEdit] search") {
- TextEdit *text_edit = memnew(TextEdit);
- SceneTree::get_singleton()->get_root()->add_child(text_edit);
- text_edit->set_text("hay needle, hay\nHAY NEEDLE, HAY\nwordword.word.word");
- int length = text_edit->get_line(1).length();
- CHECK(text_edit->search("test", 0, 0, 0) == Point2i(-1, -1));
- CHECK(text_edit->search("test", TextEdit::SEARCH_MATCH_CASE, 0, 0) == Point2i(-1, -1));
- CHECK(text_edit->search("test", TextEdit::SEARCH_WHOLE_WORDS, 0, 0) == Point2i(-1, -1));
- CHECK(text_edit->search("test", TextEdit::SEARCH_BACKWARDS, 0, 0) == Point2i(-1, -1));
- CHECK(text_edit->search("test", 0, 1, length) == Point2i(-1, -1));
- CHECK(text_edit->search("test", TextEdit::SEARCH_MATCH_CASE, 1, length) == Point2i(-1, -1));
- CHECK(text_edit->search("test", TextEdit::SEARCH_WHOLE_WORDS, 1, length) == Point2i(-1, -1));
- CHECK(text_edit->search("test", TextEdit::SEARCH_BACKWARDS, 1, length) == Point2i(-1, -1));
- CHECK(text_edit->search("needle", 0, 0, 0) == Point2i(4, 0));
- CHECK(text_edit->search("needle", 0, 1, length) == Point2i(4, 0));
- CHECK(text_edit->search("needle", 0, 0, 5) == Point2i(4, 1));
- CHECK(text_edit->search("needle", TextEdit::SEARCH_BACKWARDS, 0, 0) == Point2i(4, 1));
- CHECK(text_edit->search("needle", TextEdit::SEARCH_BACKWARDS, 1, 5) == Point2i(4, 1));
- CHECK(text_edit->search("needle", TextEdit::SEARCH_BACKWARDS, 1, 3) == Point2i(4, 0));
- CHECK(text_edit->search("needle", TextEdit::SEARCH_MATCH_CASE, 0, 0) == Point2i(4, 0));
- CHECK(text_edit->search("needle", TextEdit::SEARCH_MATCH_CASE | TextEdit::SEARCH_BACKWARDS, 0, 0) == Point2i(4, 0));
- CHECK(text_edit->search("needle", TextEdit::SEARCH_WHOLE_WORDS | TextEdit::SEARCH_MATCH_CASE, 0, 0) == Point2i(4, 0));
- CHECK(text_edit->search("needle", TextEdit::SEARCH_WHOLE_WORDS | TextEdit::SEARCH_MATCH_CASE | TextEdit::SEARCH_BACKWARDS, 0, 0) == Point2i(4, 0));
- CHECK(text_edit->search("need", TextEdit::SEARCH_MATCH_CASE, 0, 0) == Point2i(4, 0));
- CHECK(text_edit->search("need", TextEdit::SEARCH_MATCH_CASE | TextEdit::SEARCH_BACKWARDS, 0, 0) == Point2i(4, 0));
- CHECK(text_edit->search("need", TextEdit::SEARCH_WHOLE_WORDS | TextEdit::SEARCH_MATCH_CASE, 0, 0) == Point2i(-1, -1));
- CHECK(text_edit->search("need", TextEdit::SEARCH_WHOLE_WORDS | TextEdit::SEARCH_MATCH_CASE | TextEdit::SEARCH_BACKWARDS, 0, 0) == Point2i(-1, -1));
- CHECK(text_edit->search("word", TextEdit::SEARCH_WHOLE_WORDS, 2, 0) == Point2i(9, 2));
- CHECK(text_edit->search("word", TextEdit::SEARCH_WHOLE_WORDS, 2, 10) == Point2i(14, 2));
- CHECK(text_edit->search(".word", TextEdit::SEARCH_WHOLE_WORDS, 2, 0) == Point2i(8, 2));
- CHECK(text_edit->search("word.", TextEdit::SEARCH_WHOLE_WORDS, 2, 0) == Point2i(9, 2));
- ERR_PRINT_OFF;
- CHECK(text_edit->search("", 0, 0, 0) == Point2i(-1, -1));
- CHECK(text_edit->search("needle", 0, -1, 0) == Point2i(-1, -1));
- CHECK(text_edit->search("needle", 0, 0, -1) == Point2i(-1, -1));
- CHECK(text_edit->search("needle", 0, 100, 0) == Point2i(-1, -1));
- CHECK(text_edit->search("needle", 0, 0, 100) == Point2i(-1, -1));
- ERR_PRINT_ON;
- memdelete(text_edit);
- }
- TEST_CASE("[SceneTree][TextEdit] mouse") {
- TextEdit *text_edit = memnew(TextEdit);
- SceneTree::get_singleton()->get_root()->add_child(text_edit);
- text_edit->set_size(Size2(800, 200));
- CHECK(text_edit->get_rect_at_line_column(0, 0).get_position() == Point2i(0, 0));
- text_edit->set_line(0, "A");
- MessageQueue::get_singleton()->flush();
- CHECK(text_edit->get_rect_at_line_column(0, 1).get_position().x > 0);
- text_edit->clear(); // Necessary, otherwise the following test cases fail.
- 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.");
- MessageQueue::get_singleton()->flush();
- CHECK(text_edit->get_word_at_pos(text_edit->get_pos_at_line_column(0, 1)) == "Lorem");
- CHECK(text_edit->get_word_at_pos(text_edit->get_pos_at_line_column(0, 9)) == "ipsum");
- ERR_PRINT_OFF;
- CHECK(text_edit->get_pos_at_line_column(0, -1) == Point2i(-1, -1));
- CHECK(text_edit->get_pos_at_line_column(-1, 0) == Point2i(-1, -1));
- CHECK(text_edit->get_pos_at_line_column(-1, -1) == Point2i(-1, -1));
- CHECK(text_edit->get_pos_at_line_column(0, 500) == Point2i(-1, -1));
- CHECK(text_edit->get_pos_at_line_column(2, 0) == Point2i(-1, -1));
- CHECK(text_edit->get_pos_at_line_column(2, 500) == Point2i(-1, -1));
- // Out of view.
- CHECK(text_edit->get_pos_at_line_column(0, text_edit->get_line(0).length() - 1) == Point2i(-1, -1));
- ERR_PRINT_ON;
- // Add method to get drawn column count?
- Point2i start_pos = text_edit->get_pos_at_line_column(0, 0);
- Point2i end_pos = text_edit->get_pos_at_line_column(0, 105);
- CHECK(text_edit->get_line_column_at_pos(Point2i(start_pos.x, start_pos.y)) == Point2i(0, 0));
- CHECK(text_edit->get_line_column_at_pos(Point2i(end_pos.x, end_pos.y)) == Point2i(104, 0));
- // Should this return Point2i(-1, -1) if its also < 0 not just > vis_lines.
- CHECK(text_edit->get_line_column_at_pos(Point2i(end_pos.x - 100, end_pos.y), false) == Point2i(90, 0));
- CHECK(text_edit->get_line_column_at_pos(Point2i(end_pos.x, end_pos.y + 100), false) == Point2i(-1, -1));
- CHECK(text_edit->get_line_column_at_pos(Point2i(end_pos.x - 100, end_pos.y + 100), false) == Point2i(-1, -1));
- CHECK(text_edit->get_line_column_at_pos(Point2i(end_pos.x, end_pos.y - 100), false) == Point2i(104, 0));
- CHECK(text_edit->get_line_column_at_pos(Point2i(end_pos.x - 100, end_pos.y - 100), false) == Point2i(90, 0));
- CHECK(text_edit->get_line_column_at_pos(Point2i(end_pos.x - 100, end_pos.y)) == Point2i(90, 0));
- CHECK(text_edit->get_line_column_at_pos(Point2i(end_pos.x, end_pos.y + 100)) == Point2i(140, 0));
- CHECK(text_edit->get_line_column_at_pos(Point2i(end_pos.x - 100, end_pos.y + 100)) == Point2i(140, 0));
- CHECK(text_edit->get_line_column_at_pos(Point2i(end_pos.x, end_pos.y - 100)) == Point2i(104, 0));
- CHECK(text_edit->get_line_column_at_pos(Point2i(end_pos.x - 100, end_pos.y - 100)) == Point2i(90, 0));
- memdelete(text_edit);
- }
- TEST_CASE("[SceneTree][TextEdit] caret") {
- TextEdit *text_edit = memnew(TextEdit);
- text_edit->set_context_menu_enabled(false); // Prohibit sending InputEvents to the context menu.
- SceneTree::get_singleton()->get_root()->add_child(text_edit);
- text_edit->set_size(Size2(800, 200));
- text_edit->grab_focus();
- text_edit->set_line(0, "ffi");
- text_edit->set_caret_mid_grapheme_enabled(true);
- CHECK(text_edit->is_caret_mid_grapheme_enabled());
- SEND_GUI_ACTION("ui_text_caret_right");
- CHECK(text_edit->get_caret_column() == 1);
- SEND_GUI_ACTION("ui_text_caret_right");
- CHECK(text_edit->get_caret_column() == 2);
- SEND_GUI_ACTION("ui_text_caret_right");
- CHECK(text_edit->get_caret_column() == 3);
- SEND_GUI_ACTION("ui_text_caret_left");
- CHECK(text_edit->get_caret_column() == 2);
- 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.");
- for (int i = 0; i < 3; i++) {
- 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.");
- }
- MessageQueue::get_singleton()->flush();
- text_edit->set_caret_blink_enabled(false);
- CHECK_FALSE(text_edit->is_caret_blink_enabled());
- text_edit->set_caret_blink_enabled(true);
- CHECK(text_edit->is_caret_blink_enabled());
- text_edit->set_caret_blink_interval(10);
- CHECK(text_edit->get_caret_blink_interval() == 10);
- ERR_PRINT_OFF;
- text_edit->set_caret_blink_interval(-1);
- CHECK(text_edit->get_caret_blink_interval() == 10);
- text_edit->set_caret_blink_interval(0);
- CHECK(text_edit->get_caret_blink_interval() == 10);
- ERR_PRINT_ON;
- text_edit->set_caret_type(TextEdit::CaretType::CARET_TYPE_LINE);
- CHECK(text_edit->get_caret_type() == TextEdit::CaretType::CARET_TYPE_LINE);
- text_edit->set_caret_type(TextEdit::CaretType::CARET_TYPE_BLOCK);
- CHECK(text_edit->get_caret_type() == TextEdit::CaretType::CARET_TYPE_BLOCK);
- text_edit->set_caret_type(TextEdit::CaretType::CARET_TYPE_LINE);
- CHECK(text_edit->get_caret_type() == TextEdit::CaretType::CARET_TYPE_LINE);
- int caret_col = text_edit->get_caret_column();
- text_edit->set_move_caret_on_right_click_enabled(false);
- CHECK_FALSE(text_edit->is_move_caret_on_right_click_enabled());
- SEND_GUI_MOUSE_BUTTON_EVENT(Point2i(100, 1), MouseButton::RIGHT, MouseButtonMask::RIGHT, Key::NONE);
- CHECK(text_edit->get_caret_column() == caret_col);
- text_edit->set_move_caret_on_right_click_enabled(true);
- CHECK(text_edit->is_move_caret_on_right_click_enabled());
- SEND_GUI_MOUSE_BUTTON_EVENT(Point2i(100, 1), MouseButton::RIGHT, MouseButtonMask::RIGHT, Key::NONE);
- CHECK(text_edit->get_caret_column() != caret_col);
- text_edit->set_move_caret_on_right_click_enabled(false);
- CHECK_FALSE(text_edit->is_move_caret_on_right_click_enabled());
- text_edit->set_caret_column(0);
- CHECK(text_edit->get_word_under_caret() == "Lorem");
- text_edit->set_caret_column(4);
- CHECK(text_edit->get_word_under_caret() == "Lorem");
- text_edit->set_caret_column(1);
- text_edit->add_caret(0, 15);
- CHECK(text_edit->get_word_under_caret() == "Lorem\ndolor");
- text_edit->remove_secondary_carets();
- // Should this work?
- text_edit->set_caret_column(5);
- CHECK(text_edit->get_word_under_caret() == "");
- text_edit->set_caret_column(6);
- CHECK(text_edit->get_word_under_caret() == "");
- text_edit->set_caret_line(1);
- CHECK(text_edit->get_caret_line() == 1);
- text_edit->set_caret_line(-1);
- CHECK(text_edit->get_caret_line() == 0);
- text_edit->set_caret_line(100);
- CHECK(text_edit->get_caret_line() == 3);
- text_edit->set_caret_column(-1);
- CHECK(text_edit->get_caret_column() == 0);
- text_edit->set_caret_column(10000000);
- CHECK(text_edit->get_caret_column() == 141);
- memdelete(text_edit);
- }
- TEST_CASE("[SceneTree][TextEdit] multicaret") {
- TextEdit *text_edit = memnew(TextEdit);
- SceneTree::get_singleton()->get_root()->add_child(text_edit);
- text_edit->set_multiple_carets_enabled(true);
- Array empty_signal_args;
- empty_signal_args.push_back(Array());
- SIGNAL_WATCH(text_edit, "caret_changed");
- text_edit->set_text("this is\nsome test\ntext");
- text_edit->set_caret_line(0);
- text_edit->set_caret_column(0);
- MessageQueue::get_singleton()->flush();
- SIGNAL_DISCARD("caret_changed");
- SUBCASE("[TextEdit] add remove caret") {
- // Overlapping.
- CHECK(text_edit->add_caret(0, 0) == -1);
- MessageQueue::get_singleton()->flush();
- SIGNAL_CHECK_FALSE("caret_changed");
- // Select.
- text_edit->select(2, 4, 0, 0);
- // Cannot add in selection.
- CHECK(text_edit->add_caret(0, 0) == -1);
- CHECK(text_edit->add_caret(2, 4) == -1);
- CHECK(text_edit->add_caret(1, 2) == -1);
- // Cannot add when out of bounds.
- CHECK(text_edit->add_caret(-1, 0) == -1);
- CHECK(text_edit->add_caret(5, 0) == -1);
- CHECK(text_edit->add_caret(0, 100) == -1);
- MessageQueue::get_singleton()->flush();
- SIGNAL_CHECK_FALSE("caret_changed");
- CHECK(text_edit->get_caret_count() == 1);
- text_edit->deselect();
- SIGNAL_CHECK_FALSE("caret_changed");
- CHECK(text_edit->add_caret(0, 1) == 1);
- MessageQueue::get_singleton()->flush();
- SIGNAL_CHECK("caret_changed", empty_signal_args);
- CHECK(text_edit->get_caret_count() == 2);
- CHECK(text_edit->get_caret_line(0) == 0);
- CHECK(text_edit->get_caret_column(0) == 0);
- CHECK(text_edit->get_caret_line(1) == 0);
- CHECK(text_edit->get_caret_column(1) == 1);
- ERR_PRINT_OFF;
- text_edit->remove_caret(-1);
- text_edit->remove_caret(5);
- ERR_PRINT_ON;
- CHECK(text_edit->get_caret_count() == 2);
- SIGNAL_CHECK_FALSE("caret_changed");
- text_edit->remove_caret(0);
- SIGNAL_CHECK_FALSE("caret_changed");
- CHECK(text_edit->get_caret_count() == 1);
- CHECK(text_edit->get_caret_line(0) == 0);
- CHECK(text_edit->get_caret_column(0) == 1);
- ERR_PRINT_OFF;
- text_edit->remove_caret(0);
- CHECK(text_edit->get_caret_count() == 1);
- ERR_PRINT_ON;
- }
- SUBCASE("[TextEdit] sort carets") {
- Vector<int> sorted_carets = { 0, 1, 2 };
- // Ascending order.
- text_edit->remove_secondary_carets();
- text_edit->add_caret(0, 1);
- text_edit->add_caret(1, 0);
- CHECK(text_edit->get_sorted_carets() == sorted_carets);
- // Descending order.
- sorted_carets = { 2, 1, 0 };
- text_edit->remove_secondary_carets();
- text_edit->set_caret_line(1);
- text_edit->add_caret(0, 1);
- text_edit->add_caret(0, 0);
- CHECK(text_edit->get_sorted_carets() == sorted_carets);
- // Mixed order.
- sorted_carets = { 0, 2, 1, 3 };
- text_edit->remove_secondary_carets();
- text_edit->set_caret_line(0);
- text_edit->add_caret(1, 0);
- text_edit->add_caret(0, 1);
- text_edit->add_caret(1, 1);
- CHECK(text_edit->get_sorted_carets() == sorted_carets);
- // Overlapping carets.
- sorted_carets = { 0, 1, 3, 2 };
- text_edit->remove_secondary_carets();
- text_edit->add_caret(0, 1);
- text_edit->add_caret(1, 2);
- text_edit->add_caret(0, 2);
- text_edit->set_caret_column(1, false, 3);
- CHECK(text_edit->get_sorted_carets() == sorted_carets);
- // Sorted by selection start.
- sorted_carets = { 1, 0 };
- text_edit->remove_secondary_carets();
- text_edit->select(1, 3, 1, 5);
- text_edit->add_caret(2, 0);
- text_edit->select(1, 0, 2, 0, 1);
- CHECK(text_edit->get_sorted_carets() == sorted_carets);
- }
- SUBCASE("[TextEdit] merge carets") {
- text_edit->set_text("this is some text\nfor selection");
- MessageQueue::get_singleton()->flush();
- // Don't merge carets that are not overlapping.
- text_edit->set_caret_line(0);
- text_edit->set_caret_column(4);
- text_edit->add_caret(0, 6);
- text_edit->add_caret(1, 6);
- text_edit->merge_overlapping_carets();
- CHECK(text_edit->get_caret_count() == 3);
- CHECK_FALSE(text_edit->has_selection());
- CHECK(text_edit->get_caret_line(0) == 0);
- CHECK(text_edit->get_caret_column(0) == 4);
- CHECK(text_edit->get_caret_line(1) == 0);
- CHECK(text_edit->get_caret_column(1) == 6);
- CHECK(text_edit->get_caret_line(2) == 1);
- CHECK(text_edit->get_caret_column(2) == 6);
- text_edit->remove_secondary_carets();
- // Don't merge when in a multicaret edit.
- text_edit->begin_multicaret_edit();
- text_edit->set_caret_line(0);
- text_edit->set_caret_column(4);
- text_edit->add_caret(0, 4);
- text_edit->merge_overlapping_carets();
- CHECK(text_edit->is_in_mulitcaret_edit());
- CHECK_FALSE(text_edit->has_selection());
- CHECK(text_edit->get_caret_count() == 2);
- CHECK(text_edit->get_caret_line(0) == 0);
- CHECK(text_edit->get_caret_column(0) == 4);
- CHECK(text_edit->get_caret_line(1) == 0);
- CHECK(text_edit->get_caret_column(1) == 4);
- // Merge overlapping carets. Merge at the end of the multicaret edit.
- text_edit->end_multicaret_edit();
- CHECK_FALSE(text_edit->is_in_mulitcaret_edit());
- CHECK_FALSE(text_edit->has_selection());
- CHECK(text_edit->get_caret_count() == 1);
- CHECK(text_edit->get_caret_line(0) == 0);
- CHECK(text_edit->get_caret_column(0) == 4);
- // Don't merge selections that are not overlapping.
- text_edit->set_caret_line(0);
- text_edit->set_caret_column(4);
- text_edit->add_caret(0, 2);
- text_edit->add_caret(1, 4);
- text_edit->select(0, 4, 1, 2, 0);
- text_edit->select(0, 2, 0, 3, 1);
- text_edit->select(1, 4, 1, 8, 2);
- text_edit->merge_overlapping_carets();
- CHECK(text_edit->get_caret_count() == 3);
- CHECK(text_edit->has_selection(0));
- CHECK(text_edit->has_selection(1));
- CHECK(text_edit->has_selection(2));
- text_edit->remove_secondary_carets();
- text_edit->deselect();
- // Don't merge selections that are only touching.
- text_edit->set_caret_line(0);
- text_edit->set_caret_column(4);
- text_edit->add_caret(1, 2);
- text_edit->select(0, 4, 1, 2, 0);
- text_edit->select(1, 2, 1, 5, 1);
- text_edit->merge_overlapping_carets();
- CHECK(text_edit->get_caret_count() == 2);
- CHECK(text_edit->has_selection(0));
- CHECK(text_edit->has_selection(1));
- text_edit->remove_secondary_carets();
- text_edit->deselect();
- // Merge carets into selection.
- text_edit->set_caret_line(0);
- text_edit->set_caret_column(3);
- text_edit->add_caret(0, 2);
- text_edit->add_caret(1, 4);
- text_edit->add_caret(1, 8);
- text_edit->add_caret(1, 10);
- text_edit->select(0, 2, 1, 8, 0);
- text_edit->merge_overlapping_carets();
- CHECK(text_edit->get_caret_count() == 2);
- CHECK(text_edit->has_selection(0));
- CHECK(text_edit->get_selection_from_line(0) == 0);
- CHECK(text_edit->get_selection_from_column(0) == 2);
- CHECK(text_edit->get_selection_to_line(0) == 1);
- CHECK(text_edit->get_selection_to_column(0) == 8);
- CHECK(text_edit->is_caret_after_selection_origin(0));
- CHECK_FALSE(text_edit->has_selection(1));
- CHECK(text_edit->get_caret_line(1) == 1);
- CHECK(text_edit->get_caret_column(1) == 10);
- text_edit->remove_secondary_carets();
- text_edit->deselect();
- // Merge partially overlapping selections.
- text_edit->set_caret_line(0);
- text_edit->set_caret_column(1);
- text_edit->add_caret(0, 2);
- text_edit->add_caret(0, 3);
- text_edit->select(0, 2, 0, 6, 0);
- text_edit->select(0, 4, 1, 3, 1);
- text_edit->select(1, 0, 1, 5, 2);
- text_edit->merge_overlapping_carets();
- CHECK(text_edit->get_caret_count() == 1);
- CHECK(text_edit->has_selection(0));
- CHECK(text_edit->get_selection_from_line(0) == 0);
- CHECK(text_edit->get_selection_from_column(0) == 2);
- CHECK(text_edit->get_selection_to_line(0) == 1);
- CHECK(text_edit->get_selection_to_column(0) == 5);
- CHECK(text_edit->is_caret_after_selection_origin(0));
- text_edit->remove_secondary_carets();
- text_edit->deselect();
- // Merge smaller overlapping selection into a bigger one.
- text_edit->set_caret_line(0);
- text_edit->set_caret_column(1);
- text_edit->add_caret(0, 2);
- text_edit->add_caret(0, 3);
- text_edit->select(0, 2, 0, 6, 0);
- text_edit->select(0, 8, 1, 3, 1);
- text_edit->select(0, 2, 1, 5, 2);
- text_edit->merge_overlapping_carets();
- CHECK(text_edit->get_caret_count() == 1);
- CHECK(text_edit->has_selection(0));
- CHECK(text_edit->get_selection_from_line(0) == 0);
- CHECK(text_edit->get_selection_from_column(0) == 2);
- CHECK(text_edit->get_selection_to_line(0) == 1);
- CHECK(text_edit->get_selection_to_column(0) == 5);
- CHECK(text_edit->is_caret_after_selection_origin(0));
- text_edit->remove_secondary_carets();
- text_edit->deselect();
- // Merge equal overlapping selections.
- text_edit->set_caret_line(0);
- text_edit->set_caret_column(1);
- text_edit->add_caret(0, 2);
- text_edit->select(0, 2, 1, 6, 0);
- text_edit->select(0, 2, 1, 6, 1);
- text_edit->merge_overlapping_carets();
- CHECK(text_edit->has_selection(0));
- CHECK(text_edit->get_selection_from_line(0) == 0);
- CHECK(text_edit->get_selection_from_column(0) == 2);
- CHECK(text_edit->get_selection_to_line(0) == 1);
- CHECK(text_edit->get_selection_to_column(0) == 6);
- CHECK(text_edit->is_caret_after_selection_origin(0));
- }
- SUBCASE("[TextEdit] collapse carets") {
- text_edit->set_text("this is some text\nfor selection");
- // Collapse carets in range, dont affect other carets.
- text_edit->add_caret(0, 9);
- text_edit->add_caret(1, 0);
- text_edit->add_caret(1, 2);
- text_edit->add_caret(1, 6);
- text_edit->begin_multicaret_edit();
- text_edit->collapse_carets(0, 8, 1, 2);
- CHECK(text_edit->get_caret_count() == 5);
- CHECK_FALSE(text_edit->has_selection());
- CHECK(text_edit->get_caret_line(0) == 0);
- CHECK(text_edit->get_caret_column(0) == 0);
- CHECK(text_edit->get_caret_line(1) == 0);
- CHECK(text_edit->get_caret_column(1) == 8);
- CHECK(text_edit->get_caret_line(2) == 0);
- CHECK(text_edit->get_caret_column(2) == 8);
- CHECK(text_edit->get_caret_line(3) == 1);
- CHECK(text_edit->get_caret_column(3) == 2);
- CHECK(text_edit->get_caret_line(4) == 1);
- CHECK(text_edit->get_caret_column(4) == 6);
- CHECK_FALSE(text_edit->multicaret_edit_ignore_caret(0));
- CHECK(text_edit->multicaret_edit_ignore_caret(1));
- CHECK(text_edit->multicaret_edit_ignore_caret(2));
- CHECK_FALSE(text_edit->multicaret_edit_ignore_caret(3));
- CHECK_FALSE(text_edit->multicaret_edit_ignore_caret(4));
- // Collapsed carets get merged at the end of the edit.
- text_edit->end_multicaret_edit();
- CHECK(text_edit->get_caret_count() == 4);
- CHECK_FALSE(text_edit->has_selection());
- CHECK(text_edit->get_caret_line(0) == 0);
- CHECK(text_edit->get_caret_column(0) == 0);
- CHECK(text_edit->get_caret_line(1) == 0);
- CHECK(text_edit->get_caret_column(1) == 8);
- CHECK(text_edit->get_caret_line(2) == 1);
- CHECK(text_edit->get_caret_column(2) == 2);
- CHECK(text_edit->get_caret_line(3) == 1);
- CHECK(text_edit->get_caret_column(3) == 6);
- text_edit->remove_secondary_carets();
- // Collapse inclusive.
- text_edit->set_caret_line(0);
- text_edit->set_caret_column(3);
- text_edit->add_caret(1, 2);
- text_edit->collapse_carets(0, 3, 1, 2, true);
- CHECK(text_edit->get_caret_count() == 1);
- CHECK_FALSE(text_edit->has_selection());
- CHECK(text_edit->get_caret_line() == 0);
- CHECK(text_edit->get_caret_column() == 3);
- text_edit->remove_secondary_carets();
- // Deselect if selection was encompassed.
- text_edit->select(0, 5, 0, 7);
- text_edit->collapse_carets(0, 3, 1, 2);
- CHECK_FALSE(text_edit->has_selection());
- CHECK(text_edit->get_caret_line() == 0);
- CHECK(text_edit->get_caret_column() == 3);
- // Clamp only caret end of selection.
- text_edit->select(0, 1, 0, 7);
- text_edit->collapse_carets(0, 3, 1, 2);
- CHECK(text_edit->has_selection());
- CHECK(text_edit->get_caret_line() == 0);
- CHECK(text_edit->get_caret_column() == 3);
- CHECK(text_edit->get_selection_origin_line() == 0);
- CHECK(text_edit->get_selection_origin_column() == 1);
- text_edit->deselect();
- // Clamp only selection origin end of selection.
- text_edit->select(0, 7, 0, 1);
- text_edit->collapse_carets(0, 3, 1, 2);
- CHECK(text_edit->has_selection());
- CHECK(text_edit->get_caret_line() == 0);
- CHECK(text_edit->get_caret_column() == 1);
- CHECK(text_edit->get_selection_origin_line() == 0);
- CHECK(text_edit->get_selection_origin_column() == 3);
- text_edit->deselect();
- }
- SUBCASE("[TextEdit] add caret at carets") {
- text_edit->remove_secondary_carets();
- text_edit->set_caret_line(1);
- text_edit->set_caret_column(9);
- // Add caret below. Column will clamp.
- text_edit->add_caret_at_carets(true);
- CHECK(text_edit->get_caret_count() == 2);
- CHECK_FALSE(text_edit->has_selection());
- CHECK(text_edit->get_caret_line(0) == 1);
- CHECK(text_edit->get_caret_column(0) == 9);
- CHECK(text_edit->get_caret_line(1) == 2);
- CHECK(text_edit->get_caret_column(1) == 4);
- // Cannot add below when at last line.
- text_edit->add_caret_at_carets(true);
- CHECK(text_edit->get_caret_count() == 2);
- CHECK_FALSE(text_edit->has_selection());
- CHECK(text_edit->get_caret_line(0) == 1);
- CHECK(text_edit->get_caret_column(0) == 9);
- CHECK(text_edit->get_caret_line(1) == 2);
- CHECK(text_edit->get_caret_column(1) == 4);
- // Add caret above. Column will clamp.
- text_edit->add_caret_at_carets(false);
- CHECK(text_edit->get_caret_count() == 3);
- CHECK_FALSE(text_edit->has_selection());
- CHECK(text_edit->get_caret_line(0) == 1);
- CHECK(text_edit->get_caret_column(0) == 9);
- CHECK(text_edit->get_caret_line(1) == 2);
- CHECK(text_edit->get_caret_column(1) == 4);
- CHECK(text_edit->get_caret_line(2) == 0);
- CHECK(text_edit->get_caret_column(2) == 7);
- // Cannot add above when at first line.
- text_edit->add_caret_at_carets(false);
- CHECK(text_edit->get_caret_count() == 3);
- CHECK_FALSE(text_edit->has_selection());
- CHECK(text_edit->get_caret_line(0) == 1);
- CHECK(text_edit->get_caret_column(0) == 9);
- CHECK(text_edit->get_caret_line(1) == 2);
- CHECK(text_edit->get_caret_column(1) == 4);
- CHECK(text_edit->get_caret_line(2) == 0);
- CHECK(text_edit->get_caret_column(2) == 7);
- // Cannot add below when at the last line for selection.
- text_edit->remove_secondary_carets();
- text_edit->select(2, 1, 2, 4);
- text_edit->add_caret_at_carets(true);
- CHECK(text_edit->get_caret_count() == 1);
- CHECK(text_edit->has_selection(0));
- CHECK(text_edit->get_selection_origin_line(0) == 2);
- CHECK(text_edit->get_selection_origin_column(0) == 1);
- CHECK(text_edit->get_caret_line(0) == 2);
- CHECK(text_edit->get_caret_column(0) == 4);
- // Cannot add above when at the first line for selection.
- text_edit->select(0, 1, 0, 4);
- text_edit->add_caret_at_carets(false);
- CHECK(text_edit->get_caret_count() == 1);
- CHECK(text_edit->has_selection(0));
- CHECK(text_edit->get_selection_origin_line(0) == 0);
- CHECK(text_edit->get_selection_origin_column(0) == 1);
- CHECK(text_edit->get_caret_line(0) == 0);
- CHECK(text_edit->get_caret_column(0) == 4);
- // Add selection below.
- text_edit->select(0, 0, 0, 4);
- text_edit->add_caret_at_carets(true);
- CHECK(text_edit->get_caret_count() == 2);
- CHECK(text_edit->has_selection(0));
- CHECK(text_edit->get_selection_origin_line(0) == 0);
- CHECK(text_edit->get_selection_origin_column(0) == 0);
- CHECK(text_edit->get_caret_line(0) == 0);
- CHECK(text_edit->get_caret_column(0) == 4);
- CHECK(text_edit->has_selection(1));
- CHECK(text_edit->get_selection_origin_line(1) == 1);
- CHECK(text_edit->get_selection_origin_column(1) == 0);
- CHECK(text_edit->get_caret_line(1) == 1);
- CHECK(text_edit->get_caret_column(1) == 3); // In the default font, this is the same position.
- // Add selection below again.
- text_edit->add_caret_at_carets(true);
- CHECK(text_edit->get_caret_count() == 3);
- CHECK(text_edit->has_selection(0));
- CHECK(text_edit->get_selection_origin_line(0) == 0);
- CHECK(text_edit->get_selection_origin_column(0) == 0);
- CHECK(text_edit->get_caret_line(0) == 0);
- CHECK(text_edit->get_caret_column(0) == 4);
- CHECK(text_edit->has_selection(1));
- CHECK(text_edit->get_selection_origin_line(1) == 1);
- CHECK(text_edit->get_selection_origin_column(1) == 0);
- CHECK(text_edit->get_caret_line(1) == 1);
- CHECK(text_edit->get_caret_column(1) == 3);
- CHECK(text_edit->has_selection(2));
- CHECK(text_edit->get_selection_origin_line(2) == 2);
- CHECK(text_edit->get_selection_origin_column(2) == 0);
- CHECK(text_edit->get_caret_line(2) == 2);
- CHECK(text_edit->get_caret_column(2) == 4);
- text_edit->set_text("\tthis is\nsome\n\ttest text");
- MessageQueue::get_singleton()->flush();
- // Last fit x is preserved when adding below.
- text_edit->remove_secondary_carets();
- text_edit->deselect();
- text_edit->set_caret_line(0);
- text_edit->set_caret_column(6);
- text_edit->add_caret_at_carets(true);
- text_edit->add_caret_at_carets(true);
- CHECK_FALSE(text_edit->has_selection());
- CHECK(text_edit->get_caret_count() == 3);
- CHECK(text_edit->get_caret_line(0) == 0);
- CHECK(text_edit->get_caret_column(0) == 6);
- CHECK(text_edit->get_caret_line(1) == 1);
- CHECK(text_edit->get_caret_column(1) == 4);
- CHECK(text_edit->get_caret_line(2) == 2);
- CHECK(text_edit->get_caret_column(2) == 6);
- // Last fit x is preserved when adding above.
- text_edit->remove_secondary_carets();
- text_edit->deselect();
- text_edit->set_caret_line(2);
- text_edit->set_caret_column(9);
- text_edit->add_caret_at_carets(false);
- text_edit->add_caret_at_carets(false);
- CHECK_FALSE(text_edit->has_selection());
- CHECK(text_edit->get_caret_count() == 3);
- CHECK(text_edit->get_caret_line(0) == 2);
- CHECK(text_edit->get_caret_column(0) == 9);
- CHECK(text_edit->get_caret_line(1) == 1);
- CHECK(text_edit->get_caret_column(1) == 4);
- CHECK(text_edit->get_caret_line(2) == 0);
- CHECK(text_edit->get_caret_column(2) == 8);
- // Last fit x is preserved when selection adding below.
- text_edit->remove_secondary_carets();
- text_edit->deselect();
- text_edit->select(0, 8, 0, 5);
- text_edit->add_caret_at_carets(true);
- text_edit->add_caret_at_carets(true);
- CHECK(text_edit->get_caret_count() == 3);
- CHECK(text_edit->has_selection(0));
- CHECK(text_edit->get_selection_origin_line(0) == 0);
- CHECK(text_edit->get_selection_origin_column(0) == 8);
- CHECK(text_edit->get_caret_line(0) == 0);
- CHECK(text_edit->get_caret_column(0) == 5);
- CHECK_FALSE(text_edit->has_selection(1));
- CHECK(text_edit->get_caret_line(1) == 1);
- CHECK(text_edit->get_caret_column(1) == 4);
- CHECK(text_edit->has_selection(2));
- CHECK(text_edit->get_selection_origin_line(2) == 2);
- CHECK(text_edit->get_selection_origin_column(2) == 7);
- CHECK(text_edit->get_caret_line(2) == 2);
- CHECK(text_edit->get_caret_column(2) == 5);
- // Last fit x is preserved when selection adding above.
- text_edit->remove_secondary_carets();
- text_edit->deselect();
- text_edit->select(2, 9, 2, 5);
- text_edit->add_caret_at_carets(false);
- text_edit->add_caret_at_carets(false);
- CHECK(text_edit->get_caret_count() == 3);
- CHECK(text_edit->has_selection(0));
- CHECK(text_edit->get_selection_origin_line(0) == 2);
- CHECK(text_edit->get_selection_origin_column(0) == 9);
- CHECK(text_edit->get_caret_line(0) == 2);
- CHECK(text_edit->get_caret_column(0) == 5);
- CHECK_FALSE(text_edit->has_selection(1));
- CHECK(text_edit->get_caret_line(1) == 1);
- CHECK(text_edit->get_caret_column(1) == 4);
- CHECK(text_edit->has_selection(2));
- CHECK(text_edit->get_selection_origin_line(2) == 0);
- CHECK(text_edit->get_selection_origin_column(2) == 8);
- CHECK(text_edit->get_caret_line(2) == 0);
- CHECK(text_edit->get_caret_column(2) == 5);
- // Selections are merged when they overlap.
- text_edit->remove_secondary_carets();
- text_edit->deselect();
- text_edit->select(0, 1, 0, 5);
- text_edit->add_caret(1, 0);
- text_edit->select(1, 1, 1, 3, 1);
- text_edit->add_caret_at_carets(true);
- CHECK(text_edit->get_caret_count() == 3);
- CHECK(text_edit->has_selection(0));
- CHECK(text_edit->get_selection_origin_line(0) == 0);
- CHECK(text_edit->get_selection_origin_column(0) == 1);
- CHECK(text_edit->get_caret_line(0) == 0);
- CHECK(text_edit->get_caret_column(0) == 5);
- CHECK(text_edit->has_selection(1));
- CHECK(text_edit->get_selection_origin_line(1) == 1);
- CHECK(text_edit->get_selection_origin_column(1) == 1);
- CHECK(text_edit->get_caret_line(1) == 1);
- CHECK(text_edit->get_caret_column(1) == 4);
- CHECK(text_edit->has_selection(2));
- CHECK(text_edit->get_selection_origin_line(2) == 2);
- CHECK(text_edit->get_selection_origin_column(2) == 0);
- CHECK(text_edit->get_caret_line(2) == 2);
- CHECK(text_edit->get_caret_column(2) == 3);
- // Multiline selection.
- text_edit->remove_secondary_carets();
- text_edit->deselect();
- text_edit->set_caret_line(0);
- text_edit->set_caret_column(1);
- text_edit->select(0, 3, 1, 1);
- text_edit->add_caret_at_carets(true);
- CHECK(text_edit->get_caret_count() == 2);
- CHECK(text_edit->has_selection(0));
- CHECK(text_edit->get_selection_origin_line(0) == 0);
- CHECK(text_edit->get_selection_origin_column(0) == 3);
- CHECK(text_edit->get_caret_line(0) == 1);
- CHECK(text_edit->get_caret_column(0) == 1);
- CHECK(text_edit->has_selection(1));
- CHECK(text_edit->get_selection_origin_line(1) == 1);
- CHECK(text_edit->get_selection_origin_column(1) == 3);
- CHECK(text_edit->get_caret_line(1) == 2);
- CHECK(text_edit->get_caret_column(1) == 0);
- text_edit->set_line_wrapping_mode(TextEdit::LineWrappingMode::LINE_WRAPPING_BOUNDARY);
- text_edit->set_size(Size2(50, 100));
- // Line wraps: `\t,this, is\nso,me\n\t,test, ,text`.
- CHECK(text_edit->is_line_wrapped(0));
- MessageQueue::get_singleton()->flush();
- // Add caret below on next line wrap.
- text_edit->remove_secondary_carets();
- text_edit->deselect();
- text_edit->set_caret_line(0);
- text_edit->set_caret_column(4);
- text_edit->add_caret_at_carets(true);
- CHECK_FALSE(text_edit->has_selection());
- CHECK(text_edit->get_caret_count() == 2);
- CHECK(text_edit->get_caret_line(0) == 0);
- CHECK(text_edit->get_caret_column(0) == 4);
- CHECK(text_edit->get_caret_line(1) == 0);
- CHECK(text_edit->get_caret_column(1) == 8);
- // Add caret below from end of line wrap.
- text_edit->add_caret_at_carets(true);
- CHECK_FALSE(text_edit->has_selection());
- CHECK(text_edit->get_caret_count() == 3);
- CHECK(text_edit->get_caret_line(0) == 0);
- CHECK(text_edit->get_caret_column(0) == 4);
- CHECK(text_edit->get_caret_line(1) == 0);
- CHECK(text_edit->get_caret_column(1) == 8);
- CHECK(text_edit->get_caret_line(2) == 1);
- CHECK(text_edit->get_caret_column(2) == 1);
- // Add caret below from last line and not last line wrap.
- text_edit->remove_secondary_carets();
- text_edit->deselect();
- text_edit->set_caret_line(2);
- text_edit->set_caret_column(5);
- text_edit->add_caret_at_carets(true);
- CHECK_FALSE(text_edit->has_selection());
- CHECK(text_edit->get_caret_count() == 2);
- CHECK(text_edit->get_caret_line(0) == 2);
- CHECK(text_edit->get_caret_column(0) == 5);
- CHECK(text_edit->get_caret_line(1) == 2);
- CHECK(text_edit->get_caret_column(1) == 6);
- // Cannot add caret below from last line last line wrap.
- text_edit->add_caret_at_carets(true);
- CHECK_FALSE(text_edit->has_selection());
- CHECK(text_edit->get_caret_count() == 2);
- CHECK(text_edit->get_caret_line(0) == 2);
- CHECK(text_edit->get_caret_column(0) == 5);
- CHECK(text_edit->get_caret_line(1) == 2);
- CHECK(text_edit->get_caret_column(1) == 6);
- // Add caret above from not first line wrap.
- text_edit->remove_secondary_carets();
- text_edit->deselect();
- text_edit->set_caret_line(1);
- text_edit->set_caret_column(4);
- text_edit->add_caret_at_carets(false);
- CHECK_FALSE(text_edit->has_selection());
- CHECK(text_edit->get_caret_count() == 2);
- CHECK(text_edit->get_caret_line(0) == 1);
- CHECK(text_edit->get_caret_column(0) == 4);
- CHECK(text_edit->get_caret_line(1) == 1);
- CHECK(text_edit->get_caret_column(1) == 1);
- // Add caret above from first line wrap.
- text_edit->add_caret_at_carets(false);
- CHECK_FALSE(text_edit->has_selection());
- CHECK(text_edit->get_caret_count() == 3);
- CHECK(text_edit->get_caret_line(0) == 1);
- CHECK(text_edit->get_caret_column(0) == 4);
- CHECK(text_edit->get_caret_line(1) == 1);
- CHECK(text_edit->get_caret_column(1) == 1);
- CHECK(text_edit->get_caret_line(2) == 0);
- CHECK(text_edit->get_caret_column(2) == 8);
- // Add caret above from first line and not first line wrap.
- text_edit->add_caret_at_carets(false);
- CHECK_FALSE(text_edit->has_selection());
- CHECK(text_edit->get_caret_count() == 4);
- CHECK(text_edit->get_caret_line(0) == 1);
- CHECK(text_edit->get_caret_column(0) == 4);
- CHECK(text_edit->get_caret_line(1) == 1);
- CHECK(text_edit->get_caret_column(1) == 1);
- CHECK(text_edit->get_caret_line(2) == 0);
- CHECK(text_edit->get_caret_column(2) == 8);
- CHECK(text_edit->get_caret_line(3) == 0);
- CHECK(text_edit->get_caret_column(3) == 4);
- // Cannot add caret above from first line first line wrap.
- text_edit->remove_secondary_carets();
- text_edit->deselect();
- text_edit->set_caret_line(0);
- text_edit->set_caret_column(0);
- text_edit->add_caret_at_carets(false);
- CHECK_FALSE(text_edit->has_selection());
- CHECK(text_edit->get_caret_count() == 1);
- CHECK(text_edit->get_caret_line(0) == 0);
- CHECK(text_edit->get_caret_column(0) == 0);
- // Does nothing if multiple carets are disabled.
- text_edit->set_multiple_carets_enabled(false);
- text_edit->add_caret_at_carets(true);
- CHECK(text_edit->get_caret_count() == 1);
- }
- memdelete(text_edit);
- }
- TEST_CASE("[SceneTree][TextEdit] line wrapping") {
- TextEdit *text_edit = memnew(TextEdit);
- SceneTree::get_singleton()->get_root()->add_child(text_edit);
- text_edit->grab_focus();
- // Set size for boundary.
- text_edit->set_size(Size2(800, 200));
- 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.");
- CHECK_FALSE(text_edit->is_line_wrapped(0));
- CHECK(text_edit->get_line_wrap_count(0) == 0);
- CHECK(text_edit->get_line_wrap_index_at_column(0, 130) == 0);
- CHECK(text_edit->get_line_wrapped_text(0).size() == 1);
- SIGNAL_WATCH(text_edit, "text_set");
- SIGNAL_WATCH(text_edit, "text_changed");
- SIGNAL_WATCH(text_edit, "lines_edited_from");
- SIGNAL_WATCH(text_edit, "caret_changed");
- text_edit->set_line_wrapping_mode(TextEdit::LineWrappingMode::LINE_WRAPPING_BOUNDARY);
- SIGNAL_CHECK_FALSE("text_set");
- SIGNAL_CHECK_FALSE("text_changed");
- SIGNAL_CHECK_FALSE("lines_edited_from");
- SIGNAL_CHECK_FALSE("caret_changed");
- CHECK(text_edit->is_line_wrapped(0));
- CHECK(text_edit->get_line_wrap_count(0) == 1);
- CHECK(text_edit->get_line_wrap_index_at_column(0, 130) == 1);
- CHECK(text_edit->get_line_wrapped_text(0).size() == 2);
- SIGNAL_UNWATCH(text_edit, "text_set");
- SIGNAL_UNWATCH(text_edit, "text_changed");
- SIGNAL_UNWATCH(text_edit, "lines_edited_from");
- SIGNAL_UNWATCH(text_edit, "caret_changed");
- ERR_PRINT_OFF;
- CHECK_FALSE(text_edit->is_line_wrapped(-1));
- CHECK_FALSE(text_edit->is_line_wrapped(1));
- CHECK(text_edit->get_line_wrap_count(-1) == 0);
- CHECK(text_edit->get_line_wrap_count(1) == 0);
- CHECK(text_edit->get_line_wrap_index_at_column(-1, 0) == 0);
- CHECK(text_edit->get_line_wrap_index_at_column(0, -1) == 0);
- CHECK(text_edit->get_line_wrap_index_at_column(1, 0) == 0);
- CHECK(text_edit->get_line_wrap_index_at_column(0, 10000) == 0);
- CHECK(text_edit->get_line_wrapped_text(-1).size() == 0);
- CHECK(text_edit->get_line_wrapped_text(1).size() == 0);
- ERR_PRINT_ON;
- memdelete(text_edit);
- }
- TEST_CASE("[SceneTree][TextEdit] viewport") {
- TextEdit *text_edit = memnew(TextEdit);
- SceneTree::get_singleton()->get_root()->add_child(text_edit);
- // No subcases here for performance.
- text_edit->set_size(Size2(800, 600));
- for (int i = 0; i < 50; i++) {
- 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.");
- }
- MessageQueue::get_singleton()->flush();
- const int visible_lines = text_edit->get_visible_line_count();
- const int total_visible_lines = text_edit->get_total_visible_line_count();
- CHECK(total_visible_lines == 51);
- // First visible line.
- CHECK(text_edit->get_first_visible_line() == 0);
- CHECK(text_edit->get_v_scroll() == 0);
- CHECK(text_edit->get_last_full_visible_line() == visible_lines - 1);
- CHECK(text_edit->get_last_full_visible_line_wrap_index() == 0);
- text_edit->set_line_as_first_visible(visible_lines);
- MessageQueue::get_singleton()->flush();
- CHECK(text_edit->get_first_visible_line() == visible_lines);
- CHECK(text_edit->get_v_scroll() == visible_lines);
- CHECK(text_edit->get_last_full_visible_line() == (visible_lines * 2) - 1);
- CHECK(text_edit->get_last_full_visible_line_wrap_index() == 0);
- ERR_PRINT_OFF;
- text_edit->set_line_as_first_visible(-1);
- text_edit->set_line_as_first_visible(500);
- text_edit->set_line_as_first_visible(0, -1);
- text_edit->set_line_as_first_visible(0, 500);
- CHECK(text_edit->get_first_visible_line() == visible_lines);
- ERR_PRINT_ON;
- // Wrap.
- text_edit->set_line_wrapping_mode(TextEdit::LineWrappingMode::LINE_WRAPPING_BOUNDARY);
- MessageQueue::get_singleton()->flush();
- CHECK(text_edit->get_total_visible_line_count() > total_visible_lines);
- text_edit->set_line_as_first_visible(5, 1);
- MessageQueue::get_singleton()->flush();
- CHECK(text_edit->get_first_visible_line() == 5);
- CHECK(text_edit->get_v_scroll() == 11);
- CHECK(text_edit->get_last_full_visible_line() == visible_lines - 6);
- CHECK(text_edit->get_last_full_visible_line_wrap_index() == 1);
- // Reset.
- text_edit->set_line_wrapping_mode(TextEdit::LineWrappingMode::LINE_WRAPPING_NONE);
- MessageQueue::get_singleton()->flush();
- CHECK(text_edit->get_total_visible_line_count() == total_visible_lines);
- text_edit->set_line_as_first_visible(0);
- MessageQueue::get_singleton()->flush();
- CHECK(text_edit->get_first_visible_line() == 0);
- CHECK(text_edit->get_v_scroll() == 0);
- CHECK(text_edit->get_last_full_visible_line() == visible_lines - 1);
- CHECK(text_edit->get_last_full_visible_line_wrap_index() == 0);
- // Last visible line.
- text_edit->set_line_as_last_visible(visible_lines * 2);
- MessageQueue::get_singleton()->flush();
- CHECK(text_edit->get_first_visible_line() == visible_lines);
- CHECK(text_edit->get_v_scroll() == visible_lines);
- CHECK(text_edit->get_last_full_visible_line() == (visible_lines * 2) - 1);
- CHECK(text_edit->get_last_full_visible_line_wrap_index() == 0);
- ERR_PRINT_OFF;
- text_edit->set_line_as_last_visible(-1);
- text_edit->set_line_as_last_visible(500);
- text_edit->set_line_as_last_visible(0, -1);
- text_edit->set_line_as_last_visible(0, 500);
- CHECK(text_edit->get_first_visible_line() == visible_lines);
- CHECK(text_edit->get_last_full_visible_line() == (visible_lines * 2) - 1);
- ERR_PRINT_ON;
- // Wrap.
- text_edit->set_line_wrapping_mode(TextEdit::LineWrappingMode::LINE_WRAPPING_BOUNDARY);
- MessageQueue::get_singleton()->flush();
- CHECK(text_edit->get_total_visible_line_count() > total_visible_lines);
- text_edit->set_line_as_last_visible(visible_lines + 5, 1);
- MessageQueue::get_singleton()->flush();
- CHECK(text_edit->get_first_visible_line() == 16);
- CHECK(text_edit->get_v_scroll() == 32.0);
- CHECK(text_edit->get_last_full_visible_line() == visible_lines + 5);
- CHECK(text_edit->get_last_full_visible_line_wrap_index() == 0);
- // Reset.
- text_edit->set_line_wrapping_mode(TextEdit::LineWrappingMode::LINE_WRAPPING_NONE);
- MessageQueue::get_singleton()->flush();
- CHECK(text_edit->get_total_visible_line_count() == total_visible_lines);
- text_edit->set_line_as_first_visible(0);
- MessageQueue::get_singleton()->flush();
- CHECK(text_edit->get_first_visible_line() == 0);
- CHECK(text_edit->get_v_scroll() == 0);
- CHECK(text_edit->get_last_full_visible_line() == visible_lines - 1);
- CHECK(text_edit->get_last_full_visible_line_wrap_index() == 0);
- // Center.
- text_edit->set_line_as_center_visible(visible_lines + (visible_lines / 2));
- MessageQueue::get_singleton()->flush();
- CHECK(text_edit->get_first_visible_line() == visible_lines);
- CHECK(text_edit->get_v_scroll() == visible_lines);
- CHECK(text_edit->get_last_full_visible_line() == (visible_lines * 2) - 1);
- CHECK(text_edit->get_last_full_visible_line_wrap_index() == 0);
- ERR_PRINT_OFF;
- text_edit->set_line_as_last_visible(-1);
- text_edit->set_line_as_last_visible(500);
- text_edit->set_line_as_last_visible(0, -1);
- text_edit->set_line_as_last_visible(0, 500);
- CHECK(text_edit->get_first_visible_line() == visible_lines);
- CHECK(text_edit->get_last_full_visible_line() == (visible_lines * 2) - 1);
- ERR_PRINT_ON;
- // Wrap.
- text_edit->set_line_wrapping_mode(TextEdit::LineWrappingMode::LINE_WRAPPING_BOUNDARY);
- MessageQueue::get_singleton()->flush();
- CHECK(text_edit->get_total_visible_line_count() > total_visible_lines);
- text_edit->set_line_as_center_visible(visible_lines + (visible_lines / 2) + 5, 1);
- MessageQueue::get_singleton()->flush();
- CHECK(text_edit->get_first_visible_line() == visible_lines + (visible_lines / 2));
- CHECK(text_edit->get_v_scroll() == (visible_lines * 3));
- CHECK(text_edit->get_last_full_visible_line() == (visible_lines * 2) - 1);
- CHECK(text_edit->get_last_full_visible_line_wrap_index() == 1);
- // Scroll past eof.
- int line_count = text_edit->get_line_count();
- text_edit->set_scroll_past_end_of_file_enabled(true);
- MessageQueue::get_singleton()->flush();
- text_edit->set_line_as_center_visible(line_count - 1);
- MessageQueue::get_singleton()->flush();
- CHECK(text_edit->get_first_visible_line() == (visible_lines * 2) + 3);
- CHECK(text_edit->get_v_scroll() == (visible_lines * 4) + 6);
- CHECK(text_edit->get_last_full_visible_line() == (visible_lines * 2) + 8);
- CHECK(text_edit->get_last_full_visible_line_wrap_index() == 0);
- text_edit->set_scroll_past_end_of_file_enabled(false);
- MessageQueue::get_singleton()->flush();
- CHECK(text_edit->get_first_visible_line() == (visible_lines * 2) + 3);
- CHECK(text_edit->get_v_scroll() == (visible_lines * 4) - 4);
- CHECK(text_edit->get_last_full_visible_line() == (visible_lines * 2) + 8);
- CHECK(text_edit->get_last_full_visible_line_wrap_index() == 0);
- // Reset.
- text_edit->set_line_wrapping_mode(TextEdit::LineWrappingMode::LINE_WRAPPING_NONE);
- MessageQueue::get_singleton()->flush();
- CHECK(text_edit->get_total_visible_line_count() == total_visible_lines);
- text_edit->set_line_as_first_visible(0);
- MessageQueue::get_singleton()->flush();
- CHECK(text_edit->get_first_visible_line() == 0);
- CHECK(text_edit->get_v_scroll() == 0);
- CHECK(text_edit->get_last_full_visible_line() == visible_lines - 1);
- CHECK(text_edit->get_last_full_visible_line_wrap_index() == 0);
- // Auto adjust - todo: horizontal scroll.
- // Below.
- MessageQueue::get_singleton()->flush();
- CHECK_FALSE(text_edit->is_caret_visible());
- text_edit->set_caret_line(visible_lines + 5, false);
- CHECK_FALSE(text_edit->is_caret_visible());
- text_edit->adjust_viewport_to_caret();
- MessageQueue::get_singleton()->flush();
- CHECK(text_edit->is_caret_visible());
- CHECK(text_edit->get_first_visible_line() == 5);
- CHECK(text_edit->get_v_scroll() == 5);
- CHECK(text_edit->get_last_full_visible_line() == (visible_lines - 1) + 5);
- CHECK(text_edit->get_last_full_visible_line_wrap_index() == 0);
- text_edit->center_viewport_to_caret();
- MessageQueue::get_singleton()->flush();
- CHECK(text_edit->get_first_visible_line() == visible_lines - 5);
- CHECK(text_edit->get_v_scroll() == visible_lines - 5);
- CHECK(text_edit->get_last_full_visible_line() == (visible_lines * 2) - 6);
- CHECK(text_edit->get_last_full_visible_line_wrap_index() == 0);
- // Caret visible, do nothing.
- text_edit->adjust_viewport_to_caret();
- MessageQueue::get_singleton()->flush();
- CHECK(text_edit->get_first_visible_line() == visible_lines - 5);
- CHECK(text_edit->get_v_scroll() == visible_lines - 5);
- CHECK(text_edit->get_last_full_visible_line() == (visible_lines * 2) - 6);
- CHECK(text_edit->get_last_full_visible_line_wrap_index() == 0);
- // Above.
- text_edit->set_caret_line(1, false);
- MessageQueue::get_singleton()->flush();
- text_edit->adjust_viewport_to_caret();
- MessageQueue::get_singleton()->flush();
- CHECK(text_edit->is_caret_visible());
- CHECK(text_edit->get_first_visible_line() == 1);
- CHECK(text_edit->get_v_scroll() == 1);
- CHECK(text_edit->get_last_full_visible_line() == visible_lines);
- CHECK(text_edit->get_last_full_visible_line_wrap_index() == 0);
- CHECK(text_edit->get_caret_wrap_index() == 0);
- text_edit->set_line_as_first_visible(0);
- MessageQueue::get_singleton()->flush();
- CHECK(text_edit->get_first_visible_line() == 0);
- CHECK(text_edit->get_v_scroll() == 0);
- CHECK(text_edit->get_last_full_visible_line() == visible_lines - 1);
- CHECK(text_edit->get_last_full_visible_line_wrap_index() == 0);
- text_edit->adjust_viewport_to_caret();
- MessageQueue::get_singleton()->flush();
- CHECK(text_edit->get_first_visible_line() == 0);
- CHECK(text_edit->get_v_scroll() == 0);
- CHECK(text_edit->get_last_full_visible_line() == visible_lines - 1);
- CHECK(text_edit->get_last_full_visible_line_wrap_index() == 0);
- // Wrap.
- text_edit->set_line_wrapping_mode(TextEdit::LineWrappingMode::LINE_WRAPPING_BOUNDARY);
- MessageQueue::get_singleton()->flush();
- CHECK(text_edit->get_total_visible_line_count() > total_visible_lines);
- text_edit->set_caret_line(visible_lines + 5, false, true, 1);
- MessageQueue::get_singleton()->flush();
- text_edit->adjust_viewport_to_caret();
- MessageQueue::get_singleton()->flush();
- CHECK(text_edit->get_first_visible_line() == (visible_lines / 2) + 6);
- CHECK(text_edit->get_v_scroll() == (visible_lines + (visible_lines / 2)) + 1);
- CHECK(text_edit->get_last_full_visible_line() == (visible_lines) + 5);
- CHECK(text_edit->get_last_full_visible_line_wrap_index() == 0);
- CHECK(text_edit->get_caret_wrap_index() == 1);
- text_edit->center_viewport_to_caret();
- MessageQueue::get_singleton()->flush();
- CHECK(text_edit->get_first_visible_line() == visible_lines);
- CHECK(text_edit->get_v_scroll() == (visible_lines * 2) + 1);
- CHECK(text_edit->get_last_full_visible_line() == (visible_lines * 2) - 11);
- CHECK(text_edit->get_last_full_visible_line_wrap_index() == 1);
- // Caret visible, do nothing.
- text_edit->adjust_viewport_to_caret();
- MessageQueue::get_singleton()->flush();
- CHECK(text_edit->get_first_visible_line() == visible_lines);
- CHECK(text_edit->get_v_scroll() == (visible_lines * 2) + 1);
- CHECK(text_edit->get_last_full_visible_line() == (visible_lines * 2) - 11);
- CHECK(text_edit->get_last_full_visible_line_wrap_index() == 1);
- // Above.
- text_edit->set_caret_line(1, false, true, 1);
- MessageQueue::get_singleton()->flush();
- text_edit->adjust_viewport_to_caret();
- MessageQueue::get_singleton()->flush();
- CHECK(text_edit->is_caret_visible());
- CHECK(text_edit->get_first_visible_line() == 1);
- CHECK(text_edit->get_v_scroll() == 3);
- CHECK(text_edit->get_last_full_visible_line() == (visible_lines / 2) + 1);
- CHECK(text_edit->get_last_full_visible_line_wrap_index() == 1);
- CHECK(text_edit->get_caret_wrap_index() == 1);
- text_edit->set_line_as_first_visible(0);
- MessageQueue::get_singleton()->flush();
- CHECK(text_edit->is_caret_visible());
- CHECK(text_edit->get_first_visible_line() == 0);
- CHECK(text_edit->get_v_scroll() == 0);
- CHECK(text_edit->get_last_full_visible_line() == visible_lines - 11);
- CHECK(text_edit->get_last_full_visible_line_wrap_index() == 0);
- text_edit->adjust_viewport_to_caret();
- MessageQueue::get_singleton()->flush();
- CHECK(text_edit->get_first_visible_line() == 0);
- CHECK(text_edit->get_v_scroll() == 0);
- CHECK(text_edit->get_last_full_visible_line() == visible_lines - 11);
- CHECK(text_edit->get_last_full_visible_line_wrap_index() == 0);
- // Reset.
- text_edit->set_line_wrapping_mode(TextEdit::LineWrappingMode::LINE_WRAPPING_NONE);
- MessageQueue::get_singleton()->flush();
- CHECK(text_edit->get_total_visible_line_count() == total_visible_lines);
- text_edit->set_line_as_first_visible(0);
- MessageQueue::get_singleton()->flush();
- CHECK(text_edit->get_first_visible_line() == 0);
- CHECK(text_edit->get_v_scroll() == 0);
- CHECK(text_edit->get_last_full_visible_line() == visible_lines - 1);
- CHECK(text_edit->get_last_full_visible_line_wrap_index() == 0);
- CHECK(text_edit->get_caret_wrap_index() == 0);
- // Smooth scroll.
- text_edit->set_v_scroll_speed(10);
- CHECK(text_edit->get_v_scroll_speed() == 10);
- ERR_PRINT_OFF;
- text_edit->set_v_scroll_speed(-1);
- CHECK(text_edit->get_v_scroll_speed() == 10);
- text_edit->set_v_scroll_speed(0);
- CHECK(text_edit->get_v_scroll_speed() == 10);
- text_edit->set_v_scroll_speed(1);
- CHECK(text_edit->get_v_scroll_speed() == 1);
- ERR_PRINT_ON;
- // Scroll.
- int v_scroll = text_edit->get_v_scroll();
- SEND_GUI_MOUSE_BUTTON_EVENT(Point2i(10, 10), MouseButton::WHEEL_DOWN, 0, Key::NONE);
- CHECK(text_edit->get_v_scroll() > v_scroll);
- SEND_GUI_MOUSE_BUTTON_EVENT(Point2i(10, 10), MouseButton::WHEEL_UP, 0, Key::NONE);
- CHECK(text_edit->get_v_scroll() == v_scroll);
- // smooth scroll speed.
- text_edit->set_smooth_scroll_enabled(true);
- v_scroll = text_edit->get_v_scroll();
- SEND_GUI_MOUSE_BUTTON_EVENT(Point2i(10, 10), MouseButton::WHEEL_DOWN, 0, Key::NONE);
- text_edit->notification(TextEdit::NOTIFICATION_INTERNAL_PHYSICS_PROCESS);
- CHECK(text_edit->get_v_scroll() >= v_scroll);
- SEND_GUI_MOUSE_BUTTON_EVENT(Point2i(10, 10), MouseButton::WHEEL_UP, 0, Key::NONE);
- text_edit->notification(TextEdit::NOTIFICATION_INTERNAL_PHYSICS_PROCESS);
- CHECK(text_edit->get_v_scroll() == v_scroll);
- v_scroll = text_edit->get_v_scroll();
- text_edit->set_v_scroll_speed(10000);
- SEND_GUI_MOUSE_BUTTON_EVENT(Point2i(10, 10), MouseButton::WHEEL_DOWN, 0, Key::NONE);
- text_edit->notification(TextEdit::NOTIFICATION_INTERNAL_PHYSICS_PROCESS);
- CHECK(text_edit->get_v_scroll() >= v_scroll);
- SEND_GUI_MOUSE_BUTTON_EVENT(Point2i(10, 10), MouseButton::WHEEL_UP, 0, Key::NONE);
- text_edit->notification(TextEdit::NOTIFICATION_INTERNAL_PHYSICS_PROCESS);
- CHECK(text_edit->get_v_scroll() == v_scroll);
- ERR_PRINT_OFF;
- CHECK(text_edit->get_scroll_pos_for_line(-1) == 0);
- CHECK(text_edit->get_scroll_pos_for_line(1000) == 0);
- CHECK(text_edit->get_scroll_pos_for_line(1, -1) == 0);
- CHECK(text_edit->get_scroll_pos_for_line(1, 100) == 0);
- ERR_PRINT_ON;
- text_edit->set_h_scroll(-100);
- CHECK(text_edit->get_h_scroll() == 0);
- text_edit->set_h_scroll(10000000);
- CHECK(text_edit->get_h_scroll() == 306);
- CHECK(text_edit->get_h_scroll_bar()->get_combined_minimum_size().x == 8);
- text_edit->set_h_scroll(-100);
- CHECK(text_edit->get_h_scroll() == 0);
- text_edit->set_smooth_scroll_enabled(false);
- CHECK(text_edit->get_first_visible_line() == 0);
- CHECK(text_edit->get_v_scroll() == 0);
- CHECK(text_edit->get_last_full_visible_line() == visible_lines - 1);
- CHECK(text_edit->get_last_full_visible_line_wrap_index() == 0);
- text_edit->grab_focus();
- SEND_GUI_ACTION("ui_text_scroll_down");
- CHECK(text_edit->get_viewport()->is_input_handled());
- CHECK(text_edit->get_caret_line() == 1);
- CHECK(text_edit->get_first_visible_line() == 1);
- CHECK(text_edit->get_v_scroll() == 1);
- CHECK(text_edit->get_last_full_visible_line() == visible_lines);
- CHECK(text_edit->get_last_full_visible_line_wrap_index() == 0);
- CHECK(text_edit->get_caret_wrap_index() == 0);
- SEND_GUI_ACTION("ui_text_scroll_up");
- CHECK(text_edit->get_viewport()->is_input_handled());
- CHECK(text_edit->get_caret_line() == 1);
- CHECK(text_edit->get_first_visible_line() == 0);
- CHECK(text_edit->get_v_scroll() == 0);
- CHECK(text_edit->get_last_full_visible_line() == visible_lines - 1);
- CHECK(text_edit->get_last_full_visible_line_wrap_index() == 0);
- CHECK(text_edit->get_caret_wrap_index() == 0);
- // Page down, similar to VSCode, to end of page then scroll.
- SEND_GUI_ACTION("ui_text_caret_page_down");
- CHECK(text_edit->get_viewport()->is_input_handled());
- CHECK(text_edit->get_caret_line() == 21);
- CHECK(text_edit->get_first_visible_line() == 0);
- CHECK(text_edit->get_v_scroll() == 0);
- CHECK(text_edit->get_last_full_visible_line() == visible_lines - 1);
- CHECK(text_edit->get_last_full_visible_line_wrap_index() == 0);
- CHECK(text_edit->get_caret_wrap_index() == 0);
- SEND_GUI_ACTION("ui_text_caret_page_down");
- CHECK(text_edit->get_viewport()->is_input_handled());
- CHECK(text_edit->get_caret_line() == 41);
- CHECK(text_edit->get_first_visible_line() == 20);
- CHECK(text_edit->get_v_scroll() == 20);
- CHECK(text_edit->get_last_full_visible_line() == (visible_lines - 1) * 2);
- CHECK(text_edit->get_last_full_visible_line_wrap_index() == 0);
- CHECK(text_edit->get_caret_wrap_index() == 0);
- SEND_GUI_ACTION("ui_text_caret_page_up");
- CHECK(text_edit->get_viewport()->is_input_handled());
- CHECK(text_edit->get_caret_line() == 21);
- CHECK(text_edit->get_first_visible_line() == 20);
- CHECK(text_edit->get_v_scroll() == 20);
- CHECK(text_edit->get_last_full_visible_line() == (visible_lines - 1) * 2);
- CHECK(text_edit->get_last_full_visible_line_wrap_index() == 0);
- CHECK(text_edit->get_caret_wrap_index() == 0);
- SEND_GUI_ACTION("ui_text_caret_page_up");
- CHECK(text_edit->get_viewport()->is_input_handled());
- CHECK(text_edit->get_caret_line() == 1);
- CHECK(text_edit->get_first_visible_line() == 1);
- CHECK(text_edit->get_v_scroll() == 1);
- CHECK(text_edit->get_last_full_visible_line() == visible_lines);
- CHECK(text_edit->get_last_full_visible_line_wrap_index() == 0);
- CHECK(text_edit->get_caret_wrap_index() == 0);
- text_edit->set_line_wrapping_mode(TextEdit::LineWrappingMode::LINE_WRAPPING_NONE);
- MessageQueue::get_singleton()->flush();
- text_edit->grab_focus();
- SEND_GUI_ACTION("ui_text_scroll_down");
- CHECK(text_edit->get_viewport()->is_input_handled());
- CHECK(text_edit->get_caret_line() == 2);
- CHECK(text_edit->get_first_visible_line() == 2);
- CHECK(text_edit->get_v_scroll() == 2);
- CHECK(text_edit->get_last_full_visible_line() == visible_lines + 1);
- CHECK(text_edit->get_last_full_visible_line_wrap_index() == 0);
- CHECK(text_edit->get_caret_wrap_index() == 0);
- SEND_GUI_ACTION("ui_text_scroll_up");
- CHECK(text_edit->get_viewport()->is_input_handled());
- CHECK(text_edit->get_caret_line() == 2);
- CHECK(text_edit->get_first_visible_line() == 1);
- CHECK(text_edit->get_v_scroll() == 1);
- CHECK(text_edit->get_last_full_visible_line() == visible_lines);
- CHECK(text_edit->get_last_full_visible_line_wrap_index() == 0);
- CHECK(text_edit->get_caret_wrap_index() == 0);
- // Page down, similar to VSCode, to end of page then scroll.
- SEND_GUI_ACTION("ui_text_caret_page_down");
- CHECK(text_edit->get_viewport()->is_input_handled());
- CHECK(text_edit->get_caret_line() == 22);
- CHECK(text_edit->get_first_visible_line() == 1);
- CHECK(text_edit->get_v_scroll() == 1);
- CHECK(text_edit->get_last_full_visible_line() == visible_lines);
- CHECK(text_edit->get_last_full_visible_line_wrap_index() == 0);
- CHECK(text_edit->get_caret_wrap_index() == 0);
- SEND_GUI_ACTION("ui_text_caret_page_down");
- CHECK(text_edit->get_viewport()->is_input_handled());
- CHECK(text_edit->get_caret_line() == 42);
- CHECK(text_edit->get_first_visible_line() == 21);
- CHECK(text_edit->get_v_scroll() == 21);
- CHECK(text_edit->get_last_full_visible_line() == (visible_lines * 2) - 1);
- CHECK(text_edit->get_last_full_visible_line_wrap_index() == 0);
- CHECK(text_edit->get_caret_wrap_index() == 0);
- SEND_GUI_ACTION("ui_text_caret_page_up");
- CHECK(text_edit->get_viewport()->is_input_handled());
- CHECK(text_edit->get_caret_line() == 22);
- CHECK(text_edit->get_first_visible_line() == 21);
- CHECK(text_edit->get_v_scroll() == 21);
- CHECK(text_edit->get_last_full_visible_line() == (visible_lines * 2) - 1);
- CHECK(text_edit->get_last_full_visible_line_wrap_index() == 0);
- CHECK(text_edit->get_caret_wrap_index() == 0);
- SEND_GUI_ACTION("ui_text_caret_page_up");
- CHECK(text_edit->get_viewport()->is_input_handled());
- CHECK(text_edit->get_caret_line() == 2);
- CHECK(text_edit->get_first_visible_line() == 2);
- CHECK(text_edit->get_v_scroll() == 2);
- CHECK(text_edit->get_last_full_visible_line() == visible_lines + 1);
- CHECK(text_edit->get_last_full_visible_line_wrap_index() == 0);
- CHECK(text_edit->get_caret_wrap_index() == 0);
- // Typing and undo / redo should adjust viewport.
- text_edit->set_caret_line(0);
- text_edit->set_caret_column(0);
- text_edit->set_line_as_first_visible(5);
- MessageQueue::get_singleton()->flush();
- CHECK(text_edit->get_first_visible_line() == 5);
- SEND_GUI_KEY_EVENT(Key::A);
- CHECK(text_edit->get_first_visible_line() == 0);
- text_edit->set_line_as_first_visible(5);
- MessageQueue::get_singleton()->flush();
- CHECK(text_edit->get_first_visible_line() == 5);
- text_edit->undo();
- MessageQueue::get_singleton()->flush();
- CHECK(text_edit->get_first_visible_line() == 0);
- text_edit->set_line_as_first_visible(5);
- MessageQueue::get_singleton()->flush();
- CHECK(text_edit->get_first_visible_line() == 5);
- text_edit->redo();
- MessageQueue::get_singleton()->flush();
- CHECK(text_edit->get_first_visible_line() == 0);
- memdelete(text_edit);
- }
- TEST_CASE("[SceneTree][TextEdit] setter getters") {
- TextEdit *text_edit = memnew(TextEdit);
- SceneTree::get_singleton()->get_root()->add_child(text_edit);
- SUBCASE("[TextEdit] set and get placeholder") {
- text_edit->set_placeholder("test\nplaceholder");
- CHECK(text_edit->get_placeholder() == "test\nplaceholder");
- CHECK(text_edit->get_text() == "");
- CHECK(text_edit->get_line_count() == 1);
- CHECK(text_edit->get_last_full_visible_line() == 0);
- }
- SUBCASE("[TextEdit] highlight current line") {
- text_edit->set_highlight_current_line(true);
- CHECK(text_edit->is_highlight_current_line_enabled());
- text_edit->set_highlight_current_line(false);
- CHECK_FALSE(text_edit->is_highlight_current_line_enabled());
- }
- SUBCASE("[TextEdit] highlight all occurrences") {
- text_edit->set_highlight_all_occurrences(true);
- CHECK(text_edit->is_highlight_all_occurrences_enabled());
- text_edit->set_highlight_all_occurrences(false);
- CHECK_FALSE(text_edit->is_highlight_all_occurrences_enabled());
- }
- SUBCASE("[TextEdit] draw control chars") {
- text_edit->set_draw_control_chars(true);
- CHECK(text_edit->get_draw_control_chars());
- text_edit->set_draw_control_chars(false);
- CHECK_FALSE(text_edit->get_draw_control_chars());
- }
- SUBCASE("[TextEdit] draw tabs") {
- text_edit->set_draw_tabs(true);
- CHECK(text_edit->is_drawing_tabs());
- text_edit->set_draw_tabs(false);
- CHECK_FALSE(text_edit->is_drawing_tabs());
- }
- SUBCASE("[TextEdit] draw spaces") {
- text_edit->set_draw_spaces(true);
- CHECK(text_edit->is_drawing_spaces());
- text_edit->set_draw_spaces(false);
- CHECK_FALSE(text_edit->is_drawing_spaces());
- }
- SUBCASE("[TextEdit] draw minimap") {
- text_edit->set_draw_minimap(true);
- CHECK(text_edit->is_drawing_minimap());
- text_edit->set_draw_minimap(false);
- CHECK_FALSE(text_edit->is_drawing_minimap());
- }
- SUBCASE("[TextEdit] minimap width") {
- text_edit->set_minimap_width(-1);
- CHECK(text_edit->get_minimap_width() == -1);
- text_edit->set_minimap_width(1000);
- CHECK(text_edit->get_minimap_width() == 1000);
- }
- SUBCASE("[TextEdit] line color background") {
- ERR_PRINT_OFF;
- text_edit->set_line_background_color(-1, Color("#ff0000"));
- text_edit->set_line_background_color(0, Color("#00ff00"));
- text_edit->set_line_background_color(1, Color("#0000ff"));
- CHECK(text_edit->get_line_background_color(-1) == Color());
- CHECK(text_edit->get_line_background_color(0) == Color("#00ff00"));
- CHECK(text_edit->get_line_background_color(1) == Color());
- ERR_PRINT_ON;
- text_edit->set_line_background_color(0, Color("#ffff00"));
- CHECK(text_edit->get_line_background_color(0) == Color("#ffff00"));
- }
- memdelete(text_edit);
- }
- TEST_CASE("[SceneTree][TextEdit] gutters") {
- TextEdit *text_edit = memnew(TextEdit);
- SceneTree::get_singleton()->get_root()->add_child(text_edit);
- Array empty_signal_args;
- empty_signal_args.push_back(Array());
- SIGNAL_WATCH(text_edit, "gutter_clicked");
- SIGNAL_WATCH(text_edit, "gutter_added");
- SIGNAL_WATCH(text_edit, "gutter_removed");
- SUBCASE("[TextEdit] gutter add and remove") {
- text_edit->add_gutter();
- CHECK(text_edit->get_gutter_count() == 1);
- CHECK(text_edit->get_gutter_width(0) == 24);
- CHECK(text_edit->get_total_gutter_width() == 24 + 2);
- SIGNAL_CHECK("gutter_added", empty_signal_args);
- text_edit->set_gutter_name(0, "test_gutter");
- CHECK(text_edit->get_gutter_name(0) == "test_gutter");
- text_edit->set_gutter_width(0, 10);
- CHECK(text_edit->get_gutter_width(0) == 10);
- CHECK(text_edit->get_total_gutter_width() == 10 + 2);
- text_edit->add_gutter(-100);
- text_edit->set_gutter_width(1, 10);
- CHECK(text_edit->get_gutter_width(1) == 10);
- CHECK(text_edit->get_total_gutter_width() == 20 + 2);
- CHECK(text_edit->get_gutter_count() == 2);
- CHECK(text_edit->get_gutter_name(0) == "test_gutter");
- SIGNAL_CHECK("gutter_added", empty_signal_args);
- text_edit->set_gutter_draw(1, false);
- CHECK(text_edit->get_total_gutter_width() == 10 + 2);
- text_edit->add_gutter(100);
- CHECK(text_edit->get_gutter_count() == 3);
- CHECK(text_edit->get_gutter_width(2) == 24);
- CHECK(text_edit->get_total_gutter_width() == 34 + 2);
- CHECK(text_edit->get_gutter_name(0) == "test_gutter");
- SIGNAL_CHECK("gutter_added", empty_signal_args);
- text_edit->add_gutter(0);
- CHECK(text_edit->get_gutter_count() == 4);
- CHECK(text_edit->get_gutter_width(0) == 24);
- CHECK(text_edit->get_total_gutter_width() == 58 + 2);
- CHECK(text_edit->get_gutter_name(1) == "test_gutter");
- SIGNAL_CHECK("gutter_added", empty_signal_args);
- text_edit->remove_gutter(2);
- CHECK(text_edit->get_gutter_name(1) == "test_gutter");
- CHECK(text_edit->get_gutter_count() == 3);
- CHECK(text_edit->get_total_gutter_width() == 58 + 2);
- SIGNAL_CHECK("gutter_removed", empty_signal_args);
- text_edit->remove_gutter(0);
- CHECK(text_edit->get_gutter_name(0) == "test_gutter");
- CHECK(text_edit->get_gutter_count() == 2);
- CHECK(text_edit->get_total_gutter_width() == 34 + 2);
- SIGNAL_CHECK("gutter_removed", empty_signal_args);
- ERR_PRINT_OFF;
- text_edit->remove_gutter(-1);
- SIGNAL_CHECK_FALSE("gutter_removed");
- text_edit->remove_gutter(100);
- SIGNAL_CHECK_FALSE("gutter_removed");
- CHECK(text_edit->get_gutter_name(-1) == "");
- CHECK(text_edit->get_gutter_name(100) == "");
- ERR_PRINT_ON;
- }
- SUBCASE("[TextEdit] gutter data") {
- text_edit->add_gutter();
- CHECK(text_edit->get_gutter_count() == 1);
- SIGNAL_CHECK("gutter_added", empty_signal_args);
- text_edit->set_gutter_name(0, "test_gutter");
- CHECK(text_edit->get_gutter_name(0) == "test_gutter");
- text_edit->set_gutter_width(0, 10);
- CHECK(text_edit->get_gutter_width(0) == 10);
- text_edit->set_gutter_clickable(0, true);
- CHECK(text_edit->is_gutter_clickable(0));
- text_edit->set_gutter_overwritable(0, true);
- CHECK(text_edit->is_gutter_overwritable(0));
- text_edit->set_gutter_type(0, TextEdit::GutterType::GUTTER_TYPE_CUSTOM);
- CHECK(text_edit->get_gutter_type(0) == TextEdit::GutterType::GUTTER_TYPE_CUSTOM);
- text_edit->set_text("test\ntext");
- ERR_PRINT_OFF;
- text_edit->set_line_gutter_metadata(1, 0, "test");
- text_edit->set_line_gutter_metadata(0, -1, "test");
- text_edit->set_line_gutter_metadata(0, 2, "test");
- text_edit->set_line_gutter_metadata(2, 0, "test");
- text_edit->set_line_gutter_metadata(-1, 0, "test");
- CHECK(text_edit->get_line_gutter_metadata(1, 0) == "test");
- CHECK(text_edit->get_line_gutter_metadata(0, -1) == "");
- CHECK(text_edit->get_line_gutter_metadata(0, 2) == "");
- CHECK(text_edit->get_line_gutter_metadata(2, 0) == "");
- CHECK(text_edit->get_line_gutter_metadata(-1, 0) == "");
- text_edit->set_line_gutter_text(1, 0, "test");
- text_edit->set_line_gutter_text(0, -1, "test");
- text_edit->set_line_gutter_text(0, 2, "test");
- text_edit->set_line_gutter_text(2, 0, "test");
- text_edit->set_line_gutter_text(-1, 0, "test");
- CHECK(text_edit->get_line_gutter_text(1, 0) == "test");
- CHECK(text_edit->get_line_gutter_text(0, -1) == "");
- CHECK(text_edit->get_line_gutter_text(0, 2) == "");
- CHECK(text_edit->get_line_gutter_text(2, 0) == "");
- CHECK(text_edit->get_line_gutter_text(-1, 0) == "");
- text_edit->set_line_gutter_item_color(1, 0, Color(1, 0, 0));
- text_edit->set_line_gutter_item_color(0, -1, Color(1, 0, 0));
- text_edit->set_line_gutter_item_color(0, 2, Color(1, 0, 0));
- text_edit->set_line_gutter_item_color(2, 0, Color(1, 0, 0));
- text_edit->set_line_gutter_item_color(-1, 0, Color(1, 0, 0));
- CHECK(text_edit->get_line_gutter_item_color(1, 0) == Color(1, 0, 0));
- CHECK(text_edit->get_line_gutter_item_color(0, -1) == Color());
- CHECK(text_edit->get_line_gutter_item_color(0, 2) == Color());
- CHECK(text_edit->get_line_gutter_item_color(2, 0) == Color());
- CHECK(text_edit->get_line_gutter_item_color(-1, 0) == Color());
- text_edit->set_line_gutter_clickable(1, 0, true);
- text_edit->set_line_gutter_clickable(0, -1, true);
- text_edit->set_line_gutter_clickable(0, 2, true);
- text_edit->set_line_gutter_clickable(2, 0, true);
- text_edit->set_line_gutter_clickable(-1, 0, true);
- CHECK(text_edit->is_line_gutter_clickable(1, 0) == true);
- CHECK(text_edit->is_line_gutter_clickable(0, -1) == false);
- CHECK(text_edit->is_line_gutter_clickable(0, 2) == false);
- CHECK(text_edit->is_line_gutter_clickable(2, 0) == false);
- CHECK(text_edit->is_line_gutter_clickable(-1, 0) == false);
- ERR_PRINT_ON;
- // Merging tested via CodeEdit gutters.
- }
- SIGNAL_UNWATCH(text_edit, "gutter_clicked");
- SIGNAL_UNWATCH(text_edit, "gutter_added");
- SIGNAL_UNWATCH(text_edit, "gutter_removed");
- memdelete(text_edit);
- }
- } // namespace TestTextEdit
- #endif // TEST_TEXT_EDIT_H
|