123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335 |
- /**************************************************************************/
- /* 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 {
- TEST_CASE("[SceneTree][TextEdit] text entry") {
- 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 args1;
- args1.push_back(0);
- args1.push_back(0);
- Array lines_edited_args;
- lines_edited_args.push_back(args1);
- lines_edited_args.push_back(args1.duplicate());
- 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");
- // Clear.
- text_edit->set_editable(false);
- Array lines_edited_clear_args;
- Array new_args = args1.duplicate();
- new_args[0] = 1;
- lines_edited_clear_args.push_back(new_args);
- 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] 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) == "");
- 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();
- CHECK(text_edit->has_selection());
- SIGNAL_CHECK("caret_changed", empty_signal_args);
- 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");
- 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;
- }
- SUBCASE("[TextEdit] swap lines") {
- ((Array)lines_edited_args[1])[1] = 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);
- ((Array)lines_edited_args[1])[1] = 0;
- Array swap_args;
- swap_args.push_back(1);
- swap_args.push_back(1);
- lines_edited_args.push_back(swap_args);
- lines_edited_args.push_back(swap_args);
- // Order does not matter. Should also work if 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);
- lines_edited_args.reverse();
- // Single undo/redo action
- text_edit->undo();
- MessageQueue::get_singleton()->flush();
- CHECK(text_edit->get_text() == "testing\nswap");
- 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");
- lines_edited_args.reverse();
- 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");
- SIGNAL_CHECK_FALSE("lines_edited_from");
- SIGNAL_CHECK_FALSE("caret_changed");
- SIGNAL_CHECK_FALSE("text_changed");
- SIGNAL_CHECK_FALSE("text_set");
- text_edit->swap_lines(0, -1);
- CHECK(text_edit->get_text() == "swap\ntesting");
- SIGNAL_CHECK_FALSE("lines_edited_from");
- SIGNAL_CHECK_FALSE("caret_changed");
- SIGNAL_CHECK_FALSE("text_changed");
- SIGNAL_CHECK_FALSE("text_set");
- text_edit->swap_lines(2, 0);
- CHECK(text_edit->get_text() == "swap\ntesting");
- SIGNAL_CHECK_FALSE("lines_edited_from");
- SIGNAL_CHECK_FALSE("caret_changed");
- SIGNAL_CHECK_FALSE("text_changed");
- SIGNAL_CHECK_FALSE("text_set");
- text_edit->swap_lines(0, 2);
- CHECK(text_edit->get_text() == "swap\ntesting");
- SIGNAL_CHECK_FALSE("lines_edited_from");
- SIGNAL_CHECK_FALSE("caret_changed");
- SIGNAL_CHECK_FALSE("text_changed");
- SIGNAL_CHECK_FALSE("text_set");
- ERR_PRINT_ON;
- }
- SUBCASE("[TextEdit] insert line at") {
- ((Array)lines_edited_args[1])[1] = 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 before should move caret and selecion, and works when not editable.
- text_edit->set_editable(false);
- lines_edited_args.remove_at(0);
- 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_to_line() == 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);
- // can undo/redo as single action
- ((Array)lines_edited_args[0])[0] = 1;
- ((Array)lines_edited_args[0])[1] = 0;
- text_edit->undo();
- MessageQueue::get_singleton()->flush();
- CHECK(text_edit->get_text() == "testing\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");
- ((Array)lines_edited_args[0])[0] = 0;
- ((Array)lines_edited_args[0])[1] = 1;
- 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");
- ((Array)lines_edited_args[0])[0] = 2;
- ((Array)lines_edited_args[0])[1] = 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");
- SIGNAL_CHECK_FALSE("lines_edited_from");
- SIGNAL_CHECK_FALSE("caret_changed");
- SIGNAL_CHECK_FALSE("text_changed");
- SIGNAL_CHECK_FALSE("text_set");
- text_edit->insert_line_at(4, "after");
- CHECK(text_edit->get_text() == "new\ntesting\nafter\nswap");
- SIGNAL_CHECK_FALSE("lines_edited_from");
- SIGNAL_CHECK_FALSE("caret_changed");
- SIGNAL_CHECK_FALSE("text_changed");
- SIGNAL_CHECK_FALSE("text_set");
- ERR_PRINT_ON;
- }
- SUBCASE("[TextEdit] insert line at caret") {
- lines_edited_args.pop_back();
- ((Array)lines_edited_args[0])[1] = 1;
- 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_edit->set_caret_line(0, false);
- text_edit->set_caret_column(2);
- SIGNAL_DISCARD("caret_changed");
- ((Array)lines_edited_args[0])[1] = 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");
- text_edit->select(0, 0, 0, text_edit->get_line(0).length());
- CHECK(text_edit->has_selection());
- lines_edited_args.push_back(args1.duplicate());
- 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);
- 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() == 5);
- CHECK(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->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 args1;
- args1.push_back(0);
- args1.push_back(0);
- Array lines_edited_args;
- lines_edited_args.push_back(args1);
- lines_edited_args.push_back(args1.duplicate());
- SUBCASE("[TextEdit] select all") {
- text_edit->select_all();
- CHECK_FALSE(text_edit->has_selection());
- ERR_PRINT_OFF;
- CHECK(text_edit->get_selection_from_line() == -1);
- CHECK(text_edit->get_selection_from_column() == -1);
- CHECK(text_edit->get_selection_to_line() == -1);
- CHECK(text_edit->get_selection_to_column() == -1);
- CHECK(text_edit->get_selected_text() == "");
- ERR_PRINT_ON;
- 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->get_caret_line() == 1);
- CHECK(text_edit->get_caret_column() == 9);
- SIGNAL_CHECK("caret_changed", empty_signal_args);
- 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");
- 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);
- 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);
- 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);
- text_edit->set_caret_line(1, false, true, 0, 0);
- text_edit->set_caret_column(5, false, 0);
- text_edit->set_caret_line(2, false, true, 0, 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] 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");
- #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");
- SEND_GUI_KEY_EVENT(Key::LEFT | KeyModifierMask::SHIFT)
- CHECK(text_edit->has_selection());
- CHECK(text_edit->get_selected_text() == "tes");
- #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");
- SEND_GUI_KEY_EVENT(Key::LEFT)
- CHECK_FALSE(text_edit->has_selection());
- CHECK(text_edit->get_selected_text() == "");
- 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();
- SEND_GUI_MOUSE_BUTTON_EVENT(text_edit->get_pos_at_line_column(0, 1), MouseButton::LEFT, MouseButtonMask::LEFT, Key::NONE);
- SEND_GUI_MOUSE_MOTION_EVENT(text_edit->get_pos_at_line_column(0, 7), 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_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() == 5);
- CHECK(text_edit->get_caret_line() == 1);
- CHECK(text_edit->get_caret_column() == 5);
- SEND_GUI_MOUSE_BUTTON_EVENT(text_edit->get_pos_at_line_column(0, 9), MouseButton::LEFT, MouseButtonMask::LEFT, Key::NONE);
- CHECK_FALSE(text_edit->has_selection());
- text_edit->set_selecting_enabled(false);
- SEND_GUI_MOUSE_BUTTON_EVENT(text_edit->get_pos_at_line_column(0, 1), MouseButton::LEFT, MouseButtonMask::LEFT, Key::NONE);
- SEND_GUI_MOUSE_MOTION_EVENT(text_edit->get_pos_at_line_column(0, 7), 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);
- }
- 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");
- MessageQueue::get_singleton()->flush();
- SIGNAL_DISCARD("caret_changed");
- SEND_GUI_DOUBLE_CLICK(text_edit->get_pos_at_line_column(0, 2), 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);
- SIGNAL_CHECK("caret_changed", empty_signal_args);
- SEND_GUI_MOUSE_MOTION_EVENT(text_edit->get_pos_at_line_column(0, 7), 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);
- SIGNAL_CHECK("caret_changed", empty_signal_args);
- Point2i line_0 = text_edit->get_pos_at_line_column(0, 0);
- line_0.y /= 2;
- SEND_GUI_MOUSE_BUTTON_EVENT(line_0, MouseButton::LEFT, MouseButtonMask::LEFT, Key::NONE);
- CHECK_FALSE(text_edit->has_selection());
- text_edit->set_selecting_enabled(false);
- SEND_GUI_DOUBLE_CLICK(text_edit->get_pos_at_line_column(0, 2), 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");
- MessageQueue::get_singleton()->flush();
- SEND_GUI_DOUBLE_CLICK(text_edit->get_pos_at_line_column(0, 2), Key::NONE);
- SEND_GUI_MOUSE_BUTTON_EVENT(text_edit->get_pos_at_line_column(0, 2), MouseButton::LEFT, 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_LINE);
- 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() == 0);
- Point2i line_0 = text_edit->get_pos_at_line_column(0, 0);
- line_0.y /= 2;
- SEND_GUI_MOUSE_BUTTON_EVENT(line_0, MouseButton::LEFT, MouseButtonMask::LEFT, Key::NONE);
- CHECK_FALSE(text_edit->has_selection());
- text_edit->set_selecting_enabled(false);
- SEND_GUI_DOUBLE_CLICK(text_edit->get_pos_at_line_column(0, 2), Key::NONE);
- SEND_GUI_MOUSE_BUTTON_EVENT(text_edit->get_pos_at_line_column(0, 2), 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();
- SEND_GUI_MOUSE_BUTTON_EVENT(text_edit->get_pos_at_line_column(0, 0), MouseButton::LEFT, MouseButtonMask::LEFT, Key::NONE);
- SEND_GUI_MOUSE_BUTTON_EVENT(text_edit->get_pos_at_line_column(0, 7), MouseButton::LEFT, MouseButtonMask::LEFT, Key::NONE | KeyModifierMask::SHIFT);
- 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_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() == 5);
- CHECK(text_edit->get_caret_line() == 1);
- CHECK(text_edit->get_caret_column() == 5);
- SEND_GUI_MOUSE_BUTTON_EVENT(text_edit->get_pos_at_line_column(0, 9), MouseButton::LEFT, MouseButtonMask::LEFT, Key::NONE);
- CHECK_FALSE(text_edit->has_selection());
- text_edit->set_selecting_enabled(false);
- SEND_GUI_MOUSE_BUTTON_EVENT(text_edit->get_pos_at_line_column(0, 0), MouseButton::LEFT, MouseButtonMask::LEFT, Key::NONE);
- SEND_GUI_MOUSE_BUTTON_EVENT(text_edit->get_pos_at_line_column(0, 7), 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();
- text_edit->select(-1, -1, 500, 500);
- CHECK(text_edit->has_selection());
- CHECK(text_edit->get_selected_text() == "this is some text\nfor selection");
- text_edit->deselect();
- CHECK_FALSE(text_edit->has_selection());
- text_edit->select(500, 500, -1, -1);
- CHECK(text_edit->has_selection());
- CHECK(text_edit->get_selected_text() == "this is some text\nfor selection");
- text_edit->deselect();
- CHECK_FALSE(text_edit->has_selection());
- text_edit->select(0, 4, 0, 8);
- CHECK(text_edit->has_selection());
- CHECK(text_edit->get_selected_text() == " is ");
- text_edit->deselect();
- CHECK_FALSE(text_edit->has_selection());
- text_edit->select(0, 8, 0, 4);
- CHECK(text_edit->has_selection());
- CHECK(text_edit->get_selected_text() == " is ");
- text_edit->set_selecting_enabled(false);
- CHECK_FALSE(text_edit->has_selection());
- text_edit->select(0, 8, 0, 4);
- CHECK_FALSE(text_edit->has_selection());
- text_edit->set_selecting_enabled(true);
- text_edit->select(0, 8, 0, 4);
- CHECK(text_edit->has_selection());
- SEND_GUI_ACTION("ui_text_caret_right");
- CHECK_FALSE(text_edit->has_selection());
- text_edit->delete_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);
- text_edit->select(0, 8, 0, 4);
- CHECK(text_edit->has_selection());
- SEND_GUI_ACTION("ui_text_backspace");
- CHECK(text_edit->get_text() == "thissome text\nfor 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);
- text_edit->redo();
- 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);
- 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);
- text_edit->select(0, 8, 0, 4);
- CHECK(text_edit->has_selection());
- text_edit->delete_selection();
- CHECK_FALSE(text_edit->has_selection());
- CHECK(text_edit->get_text() == "thissome text\nfor selection");
- 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);
- text_edit->redo();
- 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);
- 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);
- 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");
- text_edit->undo();
- CHECK_FALSE(text_edit->has_selection());
- CHECK(text_edit->get_text() == "thissome text\nfor selection");
- }
- // Add readonly test?
- SUBCASE("[TextEdit] text drag") {
- 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();
- MessageQueue::get_singleton()->flush();
- Point2i line_0 = text_edit->get_pos_at_line_column(0, 0);
- line_0.y /= 2;
- SEND_GUI_MOUSE_BUTTON_EVENT(line_0, MouseButton::LEFT, MouseButtonMask::LEFT, Key::NONE);
- CHECK(text_edit->is_mouse_over_selection());
- SEND_GUI_MOUSE_MOTION_EVENT(text_edit->get_pos_at_line_column(0, 7), MouseButtonMask::LEFT, Key::NONE);
- CHECK(text_edit->get_viewport()->gui_is_dragging());
- CHECK(text_edit->get_viewport()->gui_get_drag_data() == "drag me");
- line_0 = target_text_edit->get_pos_at_line_column(0, 0);
- line_0.y /= 2;
- line_0.x += 401; // As empty add one.
- SEND_GUI_MOUSE_MOTION_EVENT(line_0, MouseButtonMask::LEFT, Key::NONE);
- CHECK(text_edit->get_viewport()->gui_is_dragging());
- SEND_GUI_MOUSE_BUTTON_RELEASED_EVENT(line_0, MouseButton::LEFT, MouseButtonMask::NONE, Key::NONE);
- CHECK_FALSE(text_edit->get_viewport()->gui_is_dragging());
- CHECK(text_edit->get_text() == "");
- CHECK(target_text_edit->get_text() == "drag me");
- 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") {
- 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 args1;
- args1.push_back(0);
- args1.push_back(0);
- Array lines_edited_args;
- lines_edited_args.push_back(args1);
- 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");
- text_edit->backspace();
- MessageQueue::get_singleton()->flush();
- SIGNAL_CHECK_FALSE("text_changed");
- SIGNAL_CHECK_FALSE("caret_changed");
- SIGNAL_CHECK_FALSE("lines_edited_from");
- text_edit->set_caret_line(2);
- text_edit->set_caret_column(0);
- MessageQueue::get_singleton()->flush();
- SIGNAL_DISCARD("caret_changed");
- ((Array)lines_edited_args[0])[0] = 2;
- ((Array)lines_edited_args[0])[1] = 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);
- ((Array)lines_edited_args[0])[0] = 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);
- 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);
- 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");
- 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);
- }
- SUBCASE("[TextEdit] cut") {
- 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");
- ERR_PRINT_OFF;
- text_edit->cut();
- MessageQueue::get_singleton()->flush();
- ERR_PRINT_ON; // Can't check display server content.
- ((Array)lines_edited_args[0])[0] = 1;
- CHECK(text_edit->get_text() == "some\n");
- CHECK(text_edit->get_caret_line() == 0);
- 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);
- ((Array)lines_edited_args[0])[0] = 0;
- ((Array)lines_edited_args[0])[1] = 1;
- text_edit->undo();
- MessageQueue::get_singleton()->flush();
- 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", lines_edited_args);
- ((Array)lines_edited_args[0])[0] = 1;
- ((Array)lines_edited_args[0])[1] = 0;
- text_edit->redo();
- MessageQueue::get_singleton()->flush();
- CHECK(text_edit->get_text() == "some\n");
- CHECK(text_edit->get_caret_line() == 0);
- 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);
- text_edit->set_text("this is\nsome\n");
- MessageQueue::get_singleton()->flush();
- SIGNAL_DISCARD("text_set");
- SIGNAL_DISCARD("text_changed");
- SIGNAL_DISCARD("lines_edited_from");
- SIGNAL_DISCARD("caret_changed");
- ((Array)lines_edited_args[0])[0] = 0;
- text_edit->select(0, 5, 0, 7);
- ERR_PRINT_OFF;
- SEND_GUI_ACTION("ui_cut");
- CHECK(text_edit->get_viewport()->is_input_handled());
- MessageQueue::get_singleton()->flush();
- ERR_PRINT_ON; // Can't check display server content.
- CHECK(text_edit->get_text() == "this \nsome\n");
- 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);
- text_edit->set_editable(false);
- text_edit->cut();
- MessageQueue::get_singleton()->flush();
- text_edit->set_editable(true);
- CHECK(text_edit->get_text() == "this \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");
- }
- SUBCASE("[TextEdit] copy") {
- // TODO: Cannot test need display server support.
- }
- SUBCASE("[TextEdit] paste") {
- // TODO: Cannot test need display server support.
- }
- SUBCASE("[TextEdit] paste primary") {
- // TODO: Cannot test need display server support.
- }
- 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");
- }
- // Add undo / redo tests?
- 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 args1;
- args1.push_back(0);
- args1.push_back(0);
- Array lines_edited_args;
- lines_edited_args.push_back(args1);
- SUBCASE("[TextEdit] ui_text_newline_above") {
- text_edit->set_text("this is some test text.\nthis is some test text.");
- text_edit->select(0, 0, 0, 4);
- text_edit->set_caret_column(4);
- text_edit->add_caret(1, 4);
- text_edit->select(1, 0, 1, 4, 1);
- CHECK(text_edit->get_caret_count() == 2);
- MessageQueue::get_singleton()->flush();
- SIGNAL_DISCARD("text_set");
- SIGNAL_DISCARD("text_changed");
- SIGNAL_DISCARD("lines_edited_from");
- SIGNAL_DISCARD("caret_changed");
- // For the second caret.
- Array args2;
- args2.push_back(0);
- args2.push_back(1);
- lines_edited_args.push_front(args2);
- ((Array)lines_edited_args[1])[1] = 1;
- 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(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) == 2);
- 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);
- text_edit->set_caret_line(1);
- text_edit->set_caret_column(4);
- text_edit->set_caret_line(3, false, true, 0, 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(text_edit->get_caret_line() == 1);
- CHECK(text_edit->get_caret_column() == 4);
- CHECK_FALSE(text_edit->has_selection(0));
- CHECK(text_edit->get_caret_line(1) == 3);
- CHECK(text_edit->get_caret_column(1) == 4);
- CHECK_FALSE(text_edit->has_selection(1));
- SIGNAL_CHECK_FALSE("caret_changed");
- SIGNAL_CHECK_FALSE("text_changed");
- SIGNAL_CHECK_FALSE("lines_edited_from");
- text_edit->set_editable(true);
- ((Array)lines_edited_args[0])[0] = 2;
- ((Array)lines_edited_args[0])[1] = 3;
- 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(text_edit->get_caret_line() == 1);
- CHECK(text_edit->get_caret_column() == 0);
- CHECK_FALSE(text_edit->has_selection(0));
- CHECK(text_edit->get_caret_line(1) == 4);
- 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);
- }
- SUBCASE("[TextEdit] ui_text_newline_blank") {
- text_edit->set_text("this is some test text.\nthis is some test text.");
- text_edit->select(0, 0, 0, 4);
- text_edit->set_caret_column(4);
- text_edit->add_caret(1, 4);
- text_edit->select(1, 0, 1, 4, 1);
- CHECK(text_edit->get_caret_count() == 2);
- MessageQueue::get_singleton()->flush();
- SIGNAL_DISCARD("text_set");
- SIGNAL_DISCARD("text_changed");
- SIGNAL_DISCARD("lines_edited_from");
- SIGNAL_DISCARD("caret_changed");
- // For the second caret.
- Array args2;
- args2.push_back(1);
- args2.push_back(2);
- lines_edited_args.push_front(args2);
- ((Array)lines_edited_args[1])[1] = 1;
- 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(text_edit->get_caret_line() == 1);
- CHECK(text_edit->get_caret_column() == 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);
- 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(text_edit->get_caret_line() == 1);
- CHECK(text_edit->get_caret_column() == 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_FALSE("caret_changed");
- SIGNAL_CHECK_FALSE("text_changed");
- SIGNAL_CHECK_FALSE("lines_edited_from");
- text_edit->set_editable(true);
- }
- SUBCASE("[TextEdit] ui_text_newline") {
- text_edit->set_text("this is some test text.\nthis is some test text.");
- text_edit->select(0, 0, 0, 4);
- text_edit->set_caret_column(4);
- text_edit->add_caret(1, 4);
- text_edit->select(1, 0, 1, 4, 1);
- CHECK(text_edit->get_caret_count() == 2);
- MessageQueue::get_singleton()->flush();
- SIGNAL_DISCARD("text_set");
- SIGNAL_DISCARD("text_changed");
- SIGNAL_DISCARD("lines_edited_from");
- SIGNAL_DISCARD("caret_changed");
- // For the second caret.
- Array args2;
- args2.push_back(1);
- args2.push_back(1);
- lines_edited_args.push_front(args2);
- lines_edited_args.push_front(args2.duplicate());
- ((Array)lines_edited_args[1])[1] = 2;
- lines_edited_args.push_back(lines_edited_args[2].duplicate());
- ((Array)lines_edited_args[3])[1] = 1;
- SEND_GUI_ACTION("ui_text_newline");
- CHECK(text_edit->get_viewport()->is_input_handled());
- CHECK(text_edit->get_text() == "\n is some test text.\n\n is some test text.");
- CHECK(text_edit->get_caret_line() == 1);
- CHECK(text_edit->get_caret_column() == 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);
- 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.\n\n is some test text.");
- CHECK(text_edit->get_caret_line() == 1);
- CHECK(text_edit->get_caret_column() == 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_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") {
- text_edit->set_text("\nthis is some test text.\n\nthis is some test text.");
- text_edit->select(1, 0, 1, 4);
- text_edit->set_caret_line(1);
- text_edit->set_caret_column(4);
- text_edit->add_caret(3, 4);
- text_edit->select(3, 0, 3, 4, 1);
- CHECK(text_edit->get_caret_count() == 2);
- MessageQueue::get_singleton()->flush();
- 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);
- SIGNAL_DISCARD("text_set");
- SIGNAL_DISCARD("text_changed");
- SIGNAL_DISCARD("lines_edited_from");
- SIGNAL_DISCARD("caret_changed");
- // For the second caret.
- Array args2;
- args2.push_back(3);
- args2.push_back(3);
- lines_edited_args.push_front(args2);
- // With selection should be a normal backspace.
- ((Array)lines_edited_args[1])[0] = 1;
- ((Array)lines_edited_args[1])[1] = 1;
- SEND_GUI_ACTION("ui_text_backspace_all_to_left");
- CHECK(text_edit->get_viewport()->is_input_handled());
- CHECK(text_edit->get_text() == "\n is some test text.\n\n is some test text.");
- CHECK(text_edit->get_caret_line() == 1);
- CHECK(text_edit->get_caret_column() == 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);
- ((Array)lines_edited_args[0])[1] = 2;
- ((Array)lines_edited_args[1])[1] = 0;
- // Start of line should also be a normal backspace.
- SEND_GUI_ACTION("ui_text_backspace_all_to_left");
- CHECK(text_edit->get_viewport()->is_input_handled());
- CHECK(text_edit->get_text() == " is some test text.\n is some test text.");
- 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("text_changed", empty_signal_args);
- SIGNAL_CHECK("lines_edited_from", lines_edited_args);
- 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("text_set");
- SIGNAL_DISCARD("text_changed");
- SIGNAL_DISCARD("lines_edited_from");
- 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() == " is some test text.\n is some test text.");
- 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_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_FALSE("caret_changed");
- SIGNAL_CHECK_FALSE("text_changed");
- SIGNAL_CHECK_FALSE("lines_edited_from");
- text_edit->set_editable(true);
- ((Array)lines_edited_args[0])[0] = 1;
- ((Array)lines_edited_args[0])[1] = 1;
- ((Array)lines_edited_args[1])[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_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("text_changed", empty_signal_args);
- SIGNAL_CHECK("lines_edited_from", lines_edited_args);
- 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.");
- text_edit->select(1, 0, 1, 4);
- text_edit->set_caret_line(1);
- text_edit->set_caret_column(4);
- text_edit->add_caret(3, 4);
- text_edit->select(3, 0, 3, 4, 1);
- CHECK(text_edit->get_caret_count() == 2);
- MessageQueue::get_singleton()->flush();
- SIGNAL_DISCARD("text_set");
- SIGNAL_DISCARD("text_changed");
- SIGNAL_DISCARD("lines_edited_from");
- SIGNAL_DISCARD("caret_changed");
- // For the second caret.
- Array args2;
- args2.push_back(3);
- args2.push_back(3);
- lines_edited_args.push_front(args2);
- // With selection should be a normal backspace.
- ((Array)lines_edited_args[1])[0] = 1;
- ((Array)lines_edited_args[1])[1] = 1;
- SEND_GUI_ACTION("ui_text_backspace_word");
- CHECK(text_edit->get_viewport()->is_input_handled());
- CHECK(text_edit->get_text() == "\n is some test text.\n\n is some test text.");
- CHECK(text_edit->get_caret_line() == 1);
- CHECK(text_edit->get_caret_column() == 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);
- text_edit->end_complex_operation();
- ((Array)lines_edited_args[0])[1] = 2;
- ((Array)lines_edited_args[1])[1] = 0;
- // Start of line should also be a normal backspace.
- SEND_GUI_ACTION("ui_text_backspace_word");
- CHECK(text_edit->get_viewport()->is_input_handled());
- CHECK(text_edit->get_text() == " is some test text.\n is some test text.");
- 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("text_changed", empty_signal_args);
- SIGNAL_CHECK("lines_edited_from", lines_edited_args);
- 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() == " is some test text.\n is some test text.");
- 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_FALSE("caret_changed");
- SIGNAL_CHECK_FALSE("text_changed");
- SIGNAL_CHECK_FALSE("lines_edited_from");
- text_edit->set_editable(true);
- 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("text_set");
- SIGNAL_DISCARD("text_changed");
- SIGNAL_DISCARD("lines_edited_from");
- SIGNAL_DISCARD("caret_changed");
- ((Array)lines_edited_args[0])[0] = 1;
- ((Array)lines_edited_args[0])[1] = 1;
- ((Array)lines_edited_args[1])[0] = 0;
- SEND_GUI_ACTION("ui_text_backspace_word");
- CHECK(text_edit->get_viewport()->is_input_handled());
- CHECK(text_edit->get_text() == " is some test \n is some test ");
- CHECK(text_edit->get_caret_line() == 0);
- CHECK(text_edit->get_caret_column() == 14);
- CHECK_FALSE(text_edit->has_selection(0));
- CHECK(text_edit->get_caret_line(1) == 1);
- CHECK(text_edit->get_caret_column(1) == 14);
- 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);
- }
- SUBCASE("[TextEdit] ui_text_backspace_word same line") {
- text_edit->set_text("test test test");
- text_edit->set_caret_column(4);
- text_edit->add_caret(0, 9);
- text_edit->add_caret(0, 15);
- // For the second caret.
- Array args2;
- args2.push_back(0);
- lines_edited_args.push_front(args2);
- // For the third caret.
- Array args3;
- args2.push_back(0);
- lines_edited_args.push_front(args2);
- 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");
- SEND_GUI_ACTION("ui_text_backspace_word");
- CHECK(text_edit->get_viewport()->is_input_handled());
- CHECK(text_edit->get_text() == " ");
- 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) == 0);
- CHECK(text_edit->get_caret_column(1) == 1);
- CHECK_FALSE(text_edit->has_selection(1));
- CHECK(text_edit->get_caret_line(2) == 0);
- CHECK(text_edit->get_caret_column(2) == 2);
- 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);
- }
- SUBCASE("[TextEdit] ui_text_backspace") {
- text_edit->set_text("\nthis is some test text.\n\nthis is some test text.");
- text_edit->select(1, 0, 1, 4);
- text_edit->set_caret_line(1);
- text_edit->set_caret_column(4);
- text_edit->add_caret(3, 4);
- text_edit->select(3, 0, 3, 4, 1);
- CHECK(text_edit->get_caret_count() == 2);
- MessageQueue::get_singleton()->flush();
- SIGNAL_DISCARD("text_set");
- SIGNAL_DISCARD("text_changed");
- SIGNAL_DISCARD("lines_edited_from");
- SIGNAL_DISCARD("caret_changed");
- // For the second caret.
- Array args2;
- args2.push_back(3);
- args2.push_back(3);
- lines_edited_args.push_front(args2);
- // With selection should be a normal backspace.
- ((Array)lines_edited_args[1])[0] = 1;
- ((Array)lines_edited_args[1])[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\n is some test text.");
- CHECK(text_edit->get_caret_line() == 1);
- CHECK(text_edit->get_caret_column() == 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);
- ((Array)lines_edited_args[0])[1] = 2;
- ((Array)lines_edited_args[1])[1] = 0;
- // Start of line should also be a normal backspace.
- SEND_GUI_ACTION("ui_text_backspace");
- CHECK(text_edit->get_viewport()->is_input_handled());
- CHECK(text_edit->get_text() == " is some test text.\n is some test text.");
- 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("text_changed", empty_signal_args);
- SIGNAL_CHECK("lines_edited_from", lines_edited_args);
- 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("text_set");
- SIGNAL_DISCARD("text_changed");
- SIGNAL_DISCARD("lines_edited_from");
- 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.\n is some test text.");
- 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_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_FALSE("caret_changed");
- SIGNAL_CHECK_FALSE("text_changed");
- SIGNAL_CHECK_FALSE("lines_edited_from");
- text_edit->set_editable(true);
- ((Array)lines_edited_args[0])[0] = 1;
- ((Array)lines_edited_args[0])[1] = 1;
- ((Array)lines_edited_args[1])[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\n is some test text");
- CHECK(text_edit->get_caret_line() == 0);
- CHECK(text_edit->get_caret_column() == 18);
- CHECK_FALSE(text_edit->has_selection(0));
- CHECK(text_edit->get_caret_line(1) == 1);
- CHECK(text_edit->get_caret_column(1) == 18);
- 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);
- // Select the entire text, from right to left
- text_edit->select(0, 18, 0, 0);
- text_edit->set_caret_line(0);
- text_edit->set_caret_column(0);
- text_edit->select(1, 18, 1, 0, 1);
- text_edit->set_caret_line(1, false, true, 0, 1);
- text_edit->set_caret_column(0, false, 1);
- 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_backspace");
- CHECK(text_edit->get_text() == "\n");
- CHECK(text_edit->get_caret_line() == 0);
- CHECK(text_edit->get_caret_column() == 0);
- 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);
- }
- 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");
- text_edit->select(0, 0, 0, 4);
- text_edit->set_caret_line(0);
- text_edit->set_caret_column(4);
- text_edit->add_caret(1, 4);
- text_edit->select(1, 0, 1, 4, 1);
- CHECK(text_edit->get_caret_count() == 2);
- MessageQueue::get_singleton()->flush();
- SIGNAL_DISCARD("text_set");
- SIGNAL_DISCARD("text_changed");
- SIGNAL_DISCARD("lines_edited_from");
- SIGNAL_DISCARD("caret_changed");
- // For the second caret.
- Array args2;
- args2.push_back(1);
- args2.push_back(1);
- lines_edited_args.push_front(args2);
- // With selection should be a normal delete.
- SEND_GUI_ACTION("ui_text_delete_all_to_right");
- CHECK(text_edit->get_viewport()->is_input_handled());
- CHECK(text_edit->get_text() == " is some test text.\n is some test text.\n");
- 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("text_changed", empty_signal_args);
- SIGNAL_CHECK("lines_edited_from", lines_edited_args);
- // End of line should not do anything.
- 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("text_set");
- SIGNAL_DISCARD("text_changed");
- SIGNAL_DISCARD("lines_edited_from");
- 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 test text.\n is some test text.\n");
- 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_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_FALSE("caret_changed");
- SIGNAL_CHECK_FALSE("text_changed");
- SIGNAL_CHECK_FALSE("lines_edited_from");
- text_edit->set_caret_column(0);
- text_edit->set_caret_column(0, false, 1);
- 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);
- SEND_GUI_ACTION("ui_text_delete_all_to_right");
- CHECK(text_edit->get_viewport()->is_input_handled());
- CHECK(text_edit->get_text() == " is some test text.\n is some test text.\n");
- 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_FALSE("caret_changed");
- SIGNAL_CHECK_FALSE("text_changed");
- SIGNAL_CHECK_FALSE("lines_edited_from");
- text_edit->set_editable(true);
- 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_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_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 ffi some test text.\n\nthis ffi some test text.\n");
- text_edit->select(0, 0, 0, 4);
- text_edit->set_caret_line(0);
- text_edit->set_caret_column(4);
- text_edit->add_caret(2, 4);
- text_edit->select(2, 0, 2, 4, 1);
- CHECK(text_edit->get_caret_count() == 2);
- MessageQueue::get_singleton()->flush();
- SIGNAL_DISCARD("text_set");
- SIGNAL_DISCARD("text_changed");
- SIGNAL_DISCARD("lines_edited_from");
- SIGNAL_DISCARD("caret_changed");
- // For the second caret.
- Array args2;
- args2.push_back(2);
- args2.push_back(2);
- lines_edited_args.push_front(args2);
- // With selection should be a normal delete.
- SEND_GUI_ACTION("ui_text_delete_word");
- CHECK(text_edit->get_viewport()->is_input_handled());
- CHECK(text_edit->get_text() == " ffi some test text.\n\n ffi some test text.\n");
- 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) == 2);
- 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);
- // With selection should be a normal delete.
- ((Array)lines_edited_args[0])[0] = 3;
- ((Array)lines_edited_args[1])[0] = 1;
- 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("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() == " ffi some test text.\n ffi some test text.");
- 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());
- 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(0));
- SIGNAL_CHECK("caret_changed", empty_signal_args);
- SIGNAL_CHECK("text_changed", empty_signal_args);
- SIGNAL_CHECK("lines_edited_from", lines_edited_args);
- ((Array)lines_edited_args[1])[0] = 0;
- ((Array)lines_edited_args[0])[0] = 1;
- ((Array)lines_edited_args[0])[1] = 1;
- text_edit->set_caret_column(0);
- text_edit->set_caret_column(0, false, 1);
- 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);
- SEND_GUI_ACTION("ui_text_delete_word");
- CHECK(text_edit->get_viewport()->is_input_handled());
- CHECK(text_edit->get_text() == " ffi some test text.\n ffi some test text.");
- 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_FALSE("caret_changed");
- SIGNAL_CHECK_FALSE("text_changed");
- SIGNAL_CHECK_FALSE("lines_edited_from");
- text_edit->set_editable(true);
- SEND_GUI_ACTION("ui_text_delete_word");
- CHECK(text_edit->get_viewport()->is_input_handled());
- CHECK(text_edit->get_text() == " some test text.\n some test text.");
- 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_FALSE("caret_changed");
- 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 ffi some test text.\nthis ffi some test text.");
- text_edit->select(0, 0, 0, 4);
- text_edit->set_caret_line(0);
- text_edit->set_caret_column(4);
- text_edit->add_caret(1, 4);
- text_edit->select(1, 0, 1, 4, 1);
- CHECK(text_edit->get_caret_count() == 2);
- MessageQueue::get_singleton()->flush();
- SIGNAL_DISCARD("text_set");
- SIGNAL_DISCARD("text_changed");
- SIGNAL_DISCARD("lines_edited_from");
- SIGNAL_DISCARD("caret_changed");
- // For the second caret.
- Array args2;
- args2.push_back(1);
- args2.push_back(1);
- lines_edited_args.push_front(args2);
- // With selection should be a normal delete.
- SEND_GUI_ACTION("ui_text_delete");
- CHECK(text_edit->get_viewport()->is_input_handled());
- CHECK(text_edit->get_text() == " ffi some test text.\n ffi some test text.");
- 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("text_changed", empty_signal_args);
- SIGNAL_CHECK("lines_edited_from", lines_edited_args);
- // With selection should be a normal delete.
- lines_edited_args.remove_at(0);
- ((Array)lines_edited_args[0])[0] = 1;
- text_edit->set_caret_column(text_edit->get_line(1).length(), false, 1);
- text_edit->set_caret_column(text_edit->get_line(0).length());
- 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");
- CHECK(text_edit->get_viewport()->is_input_handled());
- CHECK(text_edit->get_text() == " ffi some test text. ffi some test text.");
- CHECK(text_edit->get_caret_line() == 0);
- CHECK(text_edit->get_caret_column() == 20);
- CHECK_FALSE(text_edit->has_selection(0));
- SIGNAL_CHECK("caret_changed", empty_signal_args);
- SIGNAL_CHECK("text_changed", empty_signal_args);
- SIGNAL_CHECK("lines_edited_from", lines_edited_args);
- // Caret should be removed due to column preservation.
- CHECK(text_edit->get_caret_count() == 1);
- // Lets add it back.
- text_edit->set_caret_column(0);
- text_edit->add_caret(0, 20);
- ((Array)lines_edited_args[0])[0] = 0;
- lines_edited_args.push_back(args2);
- ((Array)lines_edited_args[1])[0] = 0;
- ((Array)lines_edited_args[1])[1] = 0;
- 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);
- SEND_GUI_ACTION("ui_text_delete");
- CHECK(text_edit->get_viewport()->is_input_handled());
- CHECK(text_edit->get_text() == " ffi some test text. ffi some test text.");
- 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) == 0);
- CHECK(text_edit->get_caret_column(1) == 20);
- CHECK_FALSE(text_edit->has_selection(1));
- SIGNAL_CHECK_FALSE("caret_changed");
- SIGNAL_CHECK_FALSE("text_changed");
- SIGNAL_CHECK_FALSE("lines_edited_from");
- text_edit->set_editable(true);
- text_edit->start_action(TextEdit::EditAction::ACTION_NONE);
- SEND_GUI_ACTION("ui_text_delete");
- CHECK(text_edit->get_viewport()->is_input_handled());
- CHECK(text_edit->get_text() == "ffi some test text.ffi some test text.");
- 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) == 0);
- CHECK(text_edit->get_caret_column(1) == 19);
- CHECK_FALSE(text_edit->has_selection(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->start_action(TextEdit::EditAction::ACTION_NONE);
- SEND_GUI_ACTION("ui_text_delete");
- CHECK(text_edit->get_viewport()->is_input_handled());
- CHECK(text_edit->get_text() == "fi some test text.fi some test text.");
- 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) == 0);
- CHECK(text_edit->get_caret_column(1) == 18);
- 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);
- text_edit->set_caret_mid_grapheme_enabled(false);
- CHECK_FALSE(text_edit->is_caret_mid_grapheme_enabled());
- text_edit->start_action(TextEdit::EditAction::ACTION_NONE);
- text_edit->undo();
- MessageQueue::get_singleton()->flush();
- CHECK(text_edit->get_text() == "ffi some test text.ffi some test text.");
- SIGNAL_DISCARD("text_set");
- SIGNAL_DISCARD("text_changed");
- SIGNAL_DISCARD("lines_edited_from");
- SIGNAL_DISCARD("caret_changed");
- SEND_GUI_ACTION("ui_text_delete");
- CHECK(text_edit->get_viewport()->is_input_handled());
- CHECK(text_edit->get_text() == " some test text. some test text.");
- 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) == 0);
- CHECK(text_edit->get_caret_column(1) == 16);
- 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);
- }
- 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(7);
- text_edit->add_caret(2, 7);
- CHECK(text_edit->get_caret_count() == 2);
- MessageQueue::get_singleton()->flush();
- SIGNAL_DISCARD("text_set");
- SIGNAL_DISCARD("text_changed");
- SIGNAL_DISCARD("lines_edited_from");
- SIGNAL_DISCARD("caret_changed");
- // Shift should select.
- #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_line() == 1);
- CHECK(text_edit->get_caret_column() == 5);
- CHECK(text_edit->get_selected_text(0) == "is");
- CHECK(text_edit->has_selection(0));
- CHECK(text_edit->get_caret_line(1) == 2);
- CHECK(text_edit->get_caret_column(1) == 5);
- CHECK(text_edit->get_selected_text(1) == "is");
- 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 still move caret with selection.
- SEND_GUI_ACTION("ui_text_caret_word_left");
- CHECK(text_edit->get_viewport()->is_input_handled());
- CHECK(text_edit->get_caret_line() == 1);
- CHECK(text_edit->get_caret_column() == 0);
- CHECK_FALSE(text_edit->has_selection(0));
- CHECK(text_edit->get_caret_line(1) == 2);
- 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");
- // Normal word left.
- SEND_GUI_ACTION("ui_text_caret_word_left");
- 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) == 23);
- 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_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, 2, 1, 7);
- text_edit->add_caret(2, 7);
- text_edit->select(2, 2, 2, 7, 1);
- CHECK(text_edit->get_caret_count() == 2);
- MessageQueue::get_singleton()->flush();
- SIGNAL_DISCARD("text_set");
- SIGNAL_DISCARD("text_changed");
- SIGNAL_DISCARD("lines_edited_from");
- SIGNAL_DISCARD("caret_changed");
- // Normal left should deselect and place at selection start.
- SEND_GUI_ACTION("ui_text_caret_left");
- CHECK(text_edit->get_viewport()->is_input_handled());
- CHECK(text_edit->get_caret_line() == 1);
- CHECK(text_edit->get_caret_column() == 2);
- CHECK_FALSE(text_edit->has_selection(0));
- CHECK(text_edit->get_caret_line(1) == 2);
- 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");
- // With shift should select.
- SEND_GUI_KEY_EVENT(Key::LEFT | KeyModifierMask::SHIFT);
- CHECK(text_edit->get_viewport()->is_input_handled());
- CHECK(text_edit->get_caret_line() == 1);
- CHECK(text_edit->get_caret_column() == 1);
- CHECK(text_edit->get_selected_text(0) == "h");
- CHECK(text_edit->has_selection(0));
- CHECK(text_edit->get_caret_line(1) == 2);
- CHECK(text_edit->get_caret_column(1) == 1);
- CHECK(text_edit->get_selected_text(1) == "h");
- CHECK(text_edit->has_selection(1));
- SIGNAL_CHECK("caret_changed", empty_signal_args);
- SIGNAL_CHECK_FALSE("text_changed");
- SIGNAL_CHECK_FALSE("lines_edited_from");
- // All ready at select left, should only deselect.
- SEND_GUI_ACTION("ui_text_caret_left");
- CHECK(text_edit->get_viewport()->is_input_handled());
- CHECK(text_edit->get_caret_line() == 1);
- CHECK(text_edit->get_caret_column() == 1);
- CHECK_FALSE(text_edit->has_selection(0));
- CHECK(text_edit->get_caret_line(1) == 2);
- CHECK(text_edit->get_caret_column(1) == 1);
- CHECK_FALSE(text_edit->has_selection(1));
- SIGNAL_CHECK_FALSE("caret_changed");
- SIGNAL_CHECK_FALSE("text_changed");
- SIGNAL_CHECK_FALSE("lines_edited_from");
- // Normal left.
- SEND_GUI_ACTION("ui_text_caret_left");
- CHECK(text_edit->get_viewport()->is_input_handled());
- CHECK(text_edit->get_caret_line() == 1);
- CHECK(text_edit->get_caret_column() == 0);
- CHECK_FALSE(text_edit->has_selection(0));
- CHECK(text_edit->get_caret_line(1) == 2);
- CHECK(text_edit->get_caret_column(1) == 0);
- CHECK_FALSE(text_edit->has_selection());
- SIGNAL_CHECK("caret_changed", empty_signal_args);
- SIGNAL_CHECK_FALSE("text_changed");
- SIGNAL_CHECK_FALSE("lines_edited_from");
- // Left at col 0 should go up a line.
- SEND_GUI_ACTION("ui_text_caret_left");
- 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) == 23);
- 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_word_right") {
- text_edit->set_text("this is some test text\n\nthis is some test text\n");
- text_edit->set_caret_line(0);
- text_edit->set_caret_column(13);
- text_edit->add_caret(2, 13);
- CHECK(text_edit->get_caret_count() == 2);
- MessageQueue::get_singleton()->flush();
- SIGNAL_DISCARD("text_set");
- SIGNAL_DISCARD("text_changed");
- SIGNAL_DISCARD("lines_edited_from");
- SIGNAL_DISCARD("caret_changed");
- // Shift should select.
- #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_line() == 0);
- CHECK(text_edit->get_caret_column() == 17);
- CHECK(text_edit->get_selected_text(0) == "test");
- CHECK(text_edit->has_selection(0));
- CHECK(text_edit->get_caret_line(1) == 2);
- CHECK(text_edit->get_caret_column(1) == 17);
- CHECK(text_edit->get_selected_text(1) == "test");
- 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 still move caret with selection.
- SEND_GUI_ACTION("ui_text_caret_word_right");
- CHECK(text_edit->get_viewport()->is_input_handled());
- CHECK(text_edit->get_caret_line() == 0);
- CHECK(text_edit->get_caret_column() == 22);
- CHECK_FALSE(text_edit->has_selection(0));
- CHECK(text_edit->get_caret_line(1) == 2);
- CHECK(text_edit->get_caret_column(1) == 22);
- 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 word right.
- SEND_GUI_ACTION("ui_text_caret_word_right");
- CHECK(text_edit->get_viewport()->is_input_handled());
- CHECK(text_edit->get_caret_line() == 1);
- CHECK(text_edit->get_caret_column() == 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_FALSE("text_changed");
- SIGNAL_CHECK_FALSE("lines_edited_from");
- }
- SUBCASE("[TextEdit] ui_text_caret_right") {
- text_edit->set_text("this is some test text\n\nthis is some test text\n");
- text_edit->set_caret_line(0);
- text_edit->set_caret_column(16);
- text_edit->select(0, 16, 0, 20);
- text_edit->add_caret(2, 16);
- text_edit->select(2, 16, 2, 20, 1);
- CHECK(text_edit->get_caret_count() == 2);
- MessageQueue::get_singleton()->flush();
- SIGNAL_DISCARD("text_set");
- SIGNAL_DISCARD("text_changed");
- SIGNAL_DISCARD("lines_edited_from");
- SIGNAL_DISCARD("caret_changed");
- // Normal right should deselect and place at selection start.
- SEND_GUI_ACTION("ui_text_caret_right");
- CHECK(text_edit->get_viewport()->is_input_handled());
- CHECK(text_edit->get_caret_line() == 0);
- CHECK(text_edit->get_caret_column() == 20);
- CHECK_FALSE(text_edit->has_selection(0));
- CHECK(text_edit->get_caret_line(1) == 2);
- CHECK(text_edit->get_caret_column(1) == 20);
- 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");
- // With shift should select.
- SEND_GUI_KEY_EVENT(Key::RIGHT | KeyModifierMask::SHIFT);
- CHECK(text_edit->get_viewport()->is_input_handled());
- CHECK(text_edit->get_caret_line() == 0);
- CHECK(text_edit->get_caret_column() == 21);
- CHECK(text_edit->get_selected_text(0) == "x");
- CHECK(text_edit->has_selection(0));
- CHECK(text_edit->get_caret_line(1) == 2);
- CHECK(text_edit->get_caret_column(1) == 21);
- CHECK(text_edit->get_selected_text(1) == "x");
- CHECK(text_edit->has_selection(1));
- SIGNAL_CHECK("caret_changed", empty_signal_args);
- SIGNAL_CHECK_FALSE("text_changed");
- SIGNAL_CHECK_FALSE("lines_edited_from");
- // All ready at select right, should only deselect.
- SEND_GUI_ACTION("ui_text_caret_right");
- CHECK(text_edit->get_viewport()->is_input_handled());
- CHECK(text_edit->get_caret_line() == 0);
- CHECK(text_edit->get_caret_column() == 21);
- CHECK_FALSE(text_edit->has_selection(0));
- CHECK(text_edit->get_caret_line(1) == 2);
- CHECK(text_edit->get_caret_column(1) == 21);
- CHECK_FALSE(text_edit->has_selection(1));
- SIGNAL_CHECK_FALSE("caret_changed");
- SIGNAL_CHECK_FALSE("text_changed");
- SIGNAL_CHECK_FALSE("lines_edited_from");
- // Normal right.
- SEND_GUI_ACTION("ui_text_caret_right");
- CHECK(text_edit->get_viewport()->is_input_handled());
- CHECK(text_edit->get_caret_line() == 0);
- CHECK(text_edit->get_caret_column() == 22);
- CHECK_FALSE(text_edit->has_selection(0));
- CHECK(text_edit->get_caret_line(1) == 2);
- CHECK(text_edit->get_caret_column(1) == 22);
- 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");
- // Right at end col should go down a line.
- SEND_GUI_ACTION("ui_text_caret_right");
- CHECK(text_edit->get_viewport()->is_input_handled());
- CHECK(text_edit->get_caret_line() == 1);
- CHECK(text_edit->get_caret_column() == 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_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();
- 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");
- text_edit->set_caret_column(12, false);
- // Normal up over wrapped line to line 0.
- 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");
- }
- 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();
- 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");
- text_edit->set_caret_column(7, false);
- // Normal down over wrapped line to last 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() == 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");
- }
- 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");
- // For the second caret.
- Array args2;
- args2.push_back(1);
- args2.push_back(1);
- lines_edited_args.push_front(args2);
- 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);
- 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.push_back(lines_edited_args[1].duplicate());
- lines_edited_args.push_front(args2.duplicate());
- 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.remove_at(0);
- lines_edited_args.remove_at(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);
- 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");
- 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));
- 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));
- 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_caret_mid_grapheme_enabled(false);
- CHECK_FALSE(text_edit->is_caret_mid_grapheme_enabled());
- SEND_GUI_ACTION("ui_text_caret_left");
- CHECK(text_edit->get_caret_column() == 0);
- 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() == 0);
- 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");
- // 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");
- // Selection
- text_edit->select(0, 0, 2, 4);
- CHECK(text_edit->add_caret(0, 0) == -1);
- CHECK(text_edit->add_caret(2, 4) == -1);
- CHECK(text_edit->add_caret(1, 2) == -1);
- // 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] caret index edit order") {
- Vector<int> caret_index_get_order;
- caret_index_get_order.push_back(1);
- caret_index_get_order.push_back(0);
- CHECK(text_edit->add_caret(1, 0));
- CHECK(text_edit->get_caret_count() == 2);
- CHECK(text_edit->get_caret_index_edit_order() == caret_index_get_order);
- text_edit->remove_secondary_carets();
- text_edit->set_caret_line(1);
- CHECK(text_edit->add_caret(0, 0));
- CHECK(text_edit->get_caret_count() == 2);
- caret_index_get_order.write[0] = 0;
- caret_index_get_order.write[1] = 1;
- CHECK(text_edit->get_caret_index_edit_order() == caret_index_get_order);
- }
- SUBCASE("[TextEdit] add caret at carets") {
- text_edit->remove_secondary_carets();
- text_edit->set_caret_line(1);
- text_edit->set_caret_column(9);
- text_edit->add_caret_at_carets(true);
- CHECK(text_edit->get_caret_count() == 2);
- CHECK(text_edit->get_caret_line(1) == 2);
- CHECK(text_edit->get_caret_column(1) == 4);
- text_edit->add_caret_at_carets(true);
- CHECK(text_edit->get_caret_count() == 2);
- text_edit->add_caret_at_carets(false);
- CHECK(text_edit->get_caret_count() == 3);
- CHECK(text_edit->get_caret_line(2) == 0);
- CHECK(text_edit->get_caret_column(2) == 7);
- text_edit->remove_secondary_carets();
- text_edit->set_caret_line(0);
- text_edit->set_caret_column(4);
- text_edit->select(0, 0, 0, 4);
- text_edit->add_caret_at_carets(true);
- CHECK(text_edit->get_caret_count() == 2);
- CHECK(text_edit->get_selection_from_line(1) == 1);
- CHECK(text_edit->get_selection_to_line(1) == 1);
- CHECK(text_edit->get_selection_from_column(1) == 0);
- CHECK(text_edit->get_selection_to_column(1) == 3);
- text_edit->add_caret_at_carets(true);
- CHECK(text_edit->get_caret_count() == 3);
- CHECK(text_edit->get_selection_from_line(2) == 2);
- CHECK(text_edit->get_selection_to_line(2) == 2);
- CHECK(text_edit->get_selection_from_column(2) == 0);
- CHECK(text_edit->get_selection_to_column(2) == 4);
- }
- 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) + 4);
- CHECK(text_edit->get_v_scroll() == (visible_lines + (visible_lines / 2)) - 1);
- CHECK(text_edit->get_last_full_visible_line() == (visible_lines) + 3);
- CHECK(text_edit->get_last_full_visible_line_wrap_index() == 1);
- 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() == 314);
- 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 minimao") {
- 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
|