TextViewTests.cs 344 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111
  1. using System.ComponentModel;
  2. using System.Reflection;
  3. using System.Text;
  4. using System.Text.RegularExpressions;
  5. using Xunit.Abstractions;
  6. namespace Terminal.Gui.ViewsTests;
  7. public class TextViewTests
  8. {
  9. private static TextView _textView;
  10. private readonly ITestOutputHelper _output;
  11. public TextViewTests (ITestOutputHelper output) { _output = output; }
  12. [Fact]
  13. [TextViewTestsAutoInitShutdown]
  14. public void AllowsReturn_Setting_To_True_Changes_Multiline_To_True_If_It_Is_False ()
  15. {
  16. Assert.True (_textView.AllowsReturn);
  17. Assert.True (_textView.Multiline);
  18. Assert.Equal (4, _textView.TabWidth);
  19. Assert.True (_textView.AllowsTab);
  20. _textView.NewKeyDownEvent (Key.Enter);
  21. Assert.Equal (
  22. Environment.NewLine + "TAB to jump between text fields.",
  23. _textView.Text
  24. );
  25. _textView.AllowsReturn = false;
  26. Assert.False (_textView.AllowsReturn);
  27. Assert.False (_textView.Multiline);
  28. Assert.Equal (0, _textView.TabWidth);
  29. Assert.False (_textView.AllowsTab);
  30. _textView.NewKeyDownEvent (Key.Enter);
  31. Assert.Equal (
  32. Environment.NewLine + "TAB to jump between text fields.",
  33. _textView.Text
  34. );
  35. }
  36. [Fact]
  37. [TextViewTestsAutoInitShutdown]
  38. public void AllowsTab_Setting_To_True_Changes_TabWidth_To_Default_If_It_Is_Zero ()
  39. {
  40. _textView.TabWidth = 0;
  41. Assert.Equal (0, _textView.TabWidth);
  42. Assert.True (_textView.AllowsTab);
  43. Assert.True (_textView.AllowsReturn);
  44. Assert.True (_textView.Multiline);
  45. _textView.AllowsTab = true;
  46. Assert.True (_textView.AllowsTab);
  47. Assert.Equal (4, _textView.TabWidth);
  48. Assert.True (_textView.AllowsReturn);
  49. Assert.True (_textView.Multiline);
  50. }
  51. [Fact]
  52. [TextViewTestsAutoInitShutdown]
  53. public void BackTab_Test_Follow_By_Tab ()
  54. {
  55. var top = new Toplevel ();
  56. top.Add (_textView);
  57. Application.Iteration += (s, a) =>
  58. {
  59. int width = _textView.Viewport.Width - 1;
  60. Assert.Equal (30, width + 1);
  61. Assert.Equal (10, _textView.Height);
  62. _textView.Text = "";
  63. for (var i = 0; i < 100; i++)
  64. {
  65. _textView.Text += "\t";
  66. }
  67. var col = 100;
  68. int tabWidth = _textView.TabWidth;
  69. int leftCol = _textView.LeftColumn;
  70. _textView.MoveEnd ();
  71. Assert.Equal (new Point (col, 0), _textView.CursorPosition);
  72. leftCol = GetLeftCol (leftCol);
  73. Assert.Equal (leftCol, _textView.LeftColumn);
  74. while (col > 0)
  75. {
  76. col--;
  77. _textView.NewKeyDownEvent (Key.Tab.WithShift);
  78. Assert.Equal (new Point (col, 0), _textView.CursorPosition);
  79. leftCol = GetLeftCol (leftCol);
  80. Assert.Equal (leftCol, _textView.LeftColumn);
  81. }
  82. while (col < 100)
  83. {
  84. col++;
  85. _textView.NewKeyDownEvent (Key.Tab);
  86. Assert.Equal (new Point (col, 0), _textView.CursorPosition);
  87. leftCol = GetLeftCol (leftCol);
  88. Assert.Equal (leftCol, _textView.LeftColumn);
  89. }
  90. Application.Top.Remove (_textView);
  91. Application.RequestStop ();
  92. };
  93. Application.Run (top);
  94. top.Dispose ();
  95. }
  96. [Fact]
  97. [TextViewTestsAutoInitShutdown]
  98. public void CanFocus_False_Wont_Focus_With_Mouse ()
  99. {
  100. Toplevel top = new ();
  101. var tv = new TextView { Width = Dim.Fill (), CanFocus = false, ReadOnly = true, Text = "some text" };
  102. var fv = new FrameView
  103. {
  104. Width = Dim.Fill (), Height = Dim.Fill (), CanFocus = false, Title = "I shouldn't get focus"
  105. };
  106. fv.Add (tv);
  107. top.Add (fv);
  108. Application.Begin (top);
  109. Assert.False (tv.CanFocus);
  110. Assert.False (tv.HasFocus);
  111. Assert.False (fv.CanFocus);
  112. Assert.False (fv.HasFocus);
  113. tv.NewMouseEvent (new MouseEventArgs { Position = new (1, 0), Flags = MouseFlags.Button1DoubleClicked });
  114. Assert.Empty (tv.SelectedText);
  115. Assert.False (tv.CanFocus);
  116. Assert.False (tv.HasFocus);
  117. Assert.False (fv.CanFocus);
  118. Assert.False (fv.HasFocus);
  119. fv.CanFocus = true;
  120. tv.CanFocus = true;
  121. tv.NewMouseEvent (new MouseEventArgs { Position = new (1, 0), Flags = MouseFlags.Button1DoubleClicked });
  122. Assert.Equal ("some ", tv.SelectedText);
  123. Assert.True (tv.CanFocus);
  124. Assert.True (tv.HasFocus);
  125. Assert.True (fv.CanFocus);
  126. Assert.True (fv.HasFocus);
  127. fv.CanFocus = false;
  128. tv.NewMouseEvent (new MouseEventArgs { Position = new (1, 0), Flags = MouseFlags.Button1DoubleClicked });
  129. Assert.Equal ("some ", tv.SelectedText); // Setting CanFocus to false don't change the SelectedText
  130. Assert.True (tv.CanFocus); // v2: CanFocus is not longer automatically changed
  131. Assert.False (tv.HasFocus);
  132. Assert.False (fv.CanFocus);
  133. Assert.False (fv.HasFocus);
  134. top.Dispose ();
  135. }
  136. [Fact]
  137. [TextViewTestsAutoInitShutdown]
  138. public void Changing_Selection_Or_CursorPosition_Update_SelectedLength_And_SelectedText ()
  139. {
  140. _textView.SelectionStartColumn = 2;
  141. _textView.SelectionStartRow = 0;
  142. Assert.Equal (0, _textView.CursorPosition.X);
  143. Assert.Equal (0, _textView.CursorPosition.Y);
  144. Assert.Equal (2, _textView.SelectedLength);
  145. Assert.Equal ("TA", _textView.SelectedText);
  146. _textView.CursorPosition = new Point (20, 0);
  147. Assert.Equal (2, _textView.SelectionStartColumn);
  148. Assert.Equal (0, _textView.SelectionStartRow);
  149. Assert.Equal (18, _textView.SelectedLength);
  150. Assert.Equal ("B to jump between ", _textView.SelectedText);
  151. }
  152. [Fact]
  153. public void CloseFile_Throws_If_FilePath_Is_Null ()
  154. {
  155. var tv = new TextView ();
  156. Assert.Throws<ArgumentNullException> (() => tv.CloseFile ());
  157. }
  158. [Fact]
  159. public void ContentsChanged_Event_Fires_ClearHistoryChanges ()
  160. {
  161. var eventcount = 0;
  162. var text = "This is the first line.\nThis is the second line.\nThis is the third line.";
  163. var tv = new TextView { Width = 50, Height = 10, Text = text };
  164. tv.ContentsChanged += (s, e) => { eventcount++; };
  165. Assert.True (tv.NewKeyDownEvent (Key.Enter));
  166. Assert.Equal (
  167. $"{Environment.NewLine}This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.",
  168. tv.Text
  169. );
  170. Assert.Equal (4, tv.Lines);
  171. var expectedEventCount = 1; // for ENTER key
  172. Assert.Equal (expectedEventCount, eventcount);
  173. tv.ClearHistoryChanges ();
  174. expectedEventCount = 2;
  175. Assert.Equal (expectedEventCount, eventcount);
  176. }
  177. [Fact]
  178. public void ContentsChanged_Event_Fires_LoadStream_By_Calling_HistoryText_Clear ()
  179. {
  180. var eventcount = 0;
  181. var tv = new TextView { Width = 50, Height = 10 };
  182. tv.ContentsChanged += (s, e) => { eventcount++; };
  183. var text = "This is the first line.\r\nThis is the second line.\r\n";
  184. tv.Load (new MemoryStream (Encoding.ASCII.GetBytes (text)));
  185. Assert.Equal (
  186. $"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}",
  187. tv.Text
  188. );
  189. Assert.Equal (1, eventcount);
  190. }
  191. [Fact]
  192. [AutoInitShutdown]
  193. public void ContentsChanged_Event_Fires_On_Init ()
  194. {
  195. Application.Iteration += (s, a) => { Application.RequestStop (); };
  196. var expectedRow = 0;
  197. var expectedCol = 0;
  198. var eventcount = 0;
  199. var tv = new TextView { Width = 50, Height = 10 };
  200. tv.ContentsChanged += (s, e) =>
  201. {
  202. eventcount++;
  203. Assert.Equal (expectedRow, e.Row);
  204. Assert.Equal (expectedCol, e.Col);
  205. };
  206. var top = new Toplevel ();
  207. top.Add (tv);
  208. Application.Begin (top);
  209. Assert.Equal (1, eventcount);
  210. top.Dispose ();
  211. }
  212. [Fact]
  213. [AutoInitShutdown]
  214. public void ContentsChanged_Event_Fires_On_InsertText ()
  215. {
  216. var eventcount = 0;
  217. var tv = new TextView { Width = 50, Height = 10 };
  218. tv.CursorPosition = Point.Empty;
  219. tv.ContentsChanged += (s, e) => { eventcount++; };
  220. Assert.Equal (0, eventcount);
  221. tv.InsertText ("a");
  222. Assert.Equal (1, eventcount);
  223. tv.CursorPosition = Point.Empty;
  224. tv.InsertText ("bcd");
  225. Assert.Equal (4, eventcount);
  226. tv.InsertText ("e");
  227. Assert.Equal (5, eventcount);
  228. tv.InsertText ("\n");
  229. Assert.Equal (6, eventcount);
  230. tv.InsertText ("1234");
  231. Assert.Equal (10, eventcount);
  232. }
  233. [Fact]
  234. public void ContentsChanged_Event_Fires_On_LoadFile_By_Calling_HistoryText_Clear ()
  235. {
  236. var eventcount = 0;
  237. var tv = new TextView { Width = 50, Height = 10 };
  238. tv.BeginInit ();
  239. tv.EndInit ();
  240. tv.ContentsChanged += (s, e) => { eventcount++; };
  241. var fileName = "textview.txt";
  242. File.WriteAllText (fileName, "This is the first line.\r\nThis is the second line.\r\n");
  243. tv.Load (fileName);
  244. Assert.Equal (1, eventcount);
  245. Assert.Equal (
  246. $"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}",
  247. tv.Text
  248. );
  249. }
  250. [Fact]
  251. [AutoInitShutdown]
  252. public void ContentsChanged_Event_Fires_On_Set_Text ()
  253. {
  254. Application.Iteration += (s, a) => { Application.RequestStop (); };
  255. var eventcount = 0;
  256. var expectedRow = 0;
  257. var expectedCol = 0;
  258. var tv = new TextView
  259. {
  260. Width = 50,
  261. Height = 10,
  262. // you'd think col would be 3, but it's 0 because TextView sets
  263. // row/col = 0 when you set Text
  264. Text = "abc"
  265. };
  266. tv.ContentsChanged += (s, e) =>
  267. {
  268. eventcount++;
  269. Assert.Equal (expectedRow, e.Row);
  270. Assert.Equal (expectedCol, e.Col);
  271. };
  272. Assert.Equal ("abc", tv.Text);
  273. var top = new Toplevel ();
  274. top.Add (tv);
  275. RunState rs = Application.Begin (top);
  276. Assert.Equal (1, eventcount); // for Initialize
  277. expectedCol = 0;
  278. tv.Text = "defg";
  279. Assert.Equal (2, eventcount); // for set Text = "defg"
  280. top.Dispose ();
  281. }
  282. [Fact]
  283. [AutoInitShutdown]
  284. public void ContentsChanged_Event_Fires_On_Typing ()
  285. {
  286. Application.Iteration += (s, a) => { Application.RequestStop (); };
  287. var eventcount = 0;
  288. var expectedRow = 0;
  289. var expectedCol = 0;
  290. var tv = new TextView { Width = 50, Height = 10 };
  291. tv.ContentsChanged += (s, e) =>
  292. {
  293. eventcount++;
  294. Assert.Equal (expectedRow, e.Row);
  295. Assert.Equal (expectedCol, e.Col);
  296. };
  297. var top = new Toplevel ();
  298. top.Add (tv);
  299. RunState rs = Application.Begin (top);
  300. Assert.Equal (1, eventcount); // for Initialize
  301. expectedCol = 0;
  302. tv.Text = "ay";
  303. Assert.Equal (2, eventcount);
  304. expectedCol = 1;
  305. tv.NewKeyDownEvent (Key.Y.WithShift);
  306. Assert.Equal (3, eventcount);
  307. Assert.Equal ("Yay", tv.Text);
  308. top.Dispose ();
  309. }
  310. [Fact]
  311. [TextViewTestsAutoInitShutdown]
  312. public void ContentsChanged_Event_Fires_On_Undo_Redo ()
  313. {
  314. var eventcount = 0;
  315. var expectedEventCount = 0;
  316. _textView.ContentsChanged += (s, e) => { eventcount++; };
  317. expectedEventCount++;
  318. _textView.Text = "This is the first line.\nThis is the second line.\nThis is the third line.";
  319. Assert.Equal (expectedEventCount, eventcount);
  320. expectedEventCount++;
  321. Assert.True (_textView.NewKeyDownEvent (Key.Enter));
  322. Assert.Equal (expectedEventCount, eventcount);
  323. // Undo
  324. expectedEventCount++;
  325. Assert.True (_textView.NewKeyDownEvent (Key.Z.WithCtrl));
  326. Assert.Equal (expectedEventCount, eventcount);
  327. // Redo
  328. expectedEventCount++;
  329. Assert.True (_textView.NewKeyDownEvent (Key.R.WithCtrl));
  330. Assert.Equal (expectedEventCount, eventcount);
  331. // Undo
  332. expectedEventCount++;
  333. Assert.True (_textView.NewKeyDownEvent (Key.Z.WithCtrl));
  334. Assert.Equal (expectedEventCount, eventcount);
  335. // Redo
  336. expectedEventCount++;
  337. Assert.True (_textView.NewKeyDownEvent (Key.R.WithCtrl));
  338. Assert.Equal (expectedEventCount, eventcount);
  339. }
  340. [Fact]
  341. [TextViewTestsAutoInitShutdown]
  342. public void ContentsChanged_Event_Fires_Using_Copy_Or_Cut_Tests ()
  343. {
  344. var eventcount = 0;
  345. _textView.ContentsChanged += (s, e) => { eventcount++; };
  346. var expectedEventCount = 1;
  347. // reset
  348. _textView.Text = TextViewTestsAutoInitShutdown.Txt;
  349. Assert.Equal (expectedEventCount, eventcount);
  350. expectedEventCount += 3;
  351. Copy_Or_Cut_And_Paste_With_No_Selection ();
  352. Assert.Equal (expectedEventCount, eventcount);
  353. // reset
  354. expectedEventCount += 1;
  355. _textView.Text = TextViewTestsAutoInitShutdown.Txt;
  356. Assert.Equal (expectedEventCount, eventcount);
  357. expectedEventCount += 3;
  358. Copy_Or_Cut_And_Paste_With_Selection ();
  359. Assert.Equal (expectedEventCount, eventcount);
  360. // reset
  361. expectedEventCount += 1;
  362. _textView.Text = TextViewTestsAutoInitShutdown.Txt;
  363. Assert.Equal (expectedEventCount, eventcount);
  364. expectedEventCount += 1;
  365. Copy_Or_Cut_Not_Null_If_Has_Selection ();
  366. Assert.Equal (expectedEventCount, eventcount);
  367. // reset
  368. expectedEventCount += 1;
  369. _textView.Text = TextViewTestsAutoInitShutdown.Txt;
  370. Assert.Equal (expectedEventCount, eventcount);
  371. expectedEventCount += 1;
  372. Copy_Or_Cut_Null_If_No_Selection ();
  373. Assert.Equal (expectedEventCount, eventcount);
  374. // reset
  375. expectedEventCount += 1;
  376. _textView.Text = TextViewTestsAutoInitShutdown.Txt;
  377. Assert.Equal (expectedEventCount, eventcount);
  378. expectedEventCount += 4;
  379. Copy_Without_Selection ();
  380. Assert.Equal (expectedEventCount, eventcount);
  381. // reset
  382. expectedEventCount += 1;
  383. _textView.Text = TextViewTestsAutoInitShutdown.Txt;
  384. Assert.Equal (expectedEventCount, eventcount);
  385. expectedEventCount += 4;
  386. Copy_Without_Selection ();
  387. Assert.Equal (expectedEventCount, eventcount);
  388. }
  389. [Fact]
  390. [TextViewTestsAutoInitShutdown]
  391. public void ContentsChanged_Event_Fires_Using_Kill_Delete_Tests ()
  392. {
  393. var eventcount = 0;
  394. _textView.ContentsChanged += (s, e) => { eventcount++; };
  395. var expectedEventCount = 1;
  396. Kill_Delete_WordForward ();
  397. Assert.Equal (expectedEventCount, eventcount); // for Initialize
  398. expectedEventCount += 1;
  399. Kill_Delete_WordBackward ();
  400. Assert.Equal (expectedEventCount, eventcount);
  401. expectedEventCount += 2;
  402. Kill_To_End_Delete_Forwards_Copy_To_The_Clipboard_And_Paste ();
  403. Assert.Equal (expectedEventCount, eventcount);
  404. expectedEventCount += 2;
  405. Kill_To_Start_Delete_Backwards_Copy_To_The_Clipboard_And_Paste ();
  406. Assert.Equal (expectedEventCount, eventcount);
  407. }
  408. [Fact]
  409. [AutoInitShutdown]
  410. public void ContentsChanged_Event_NoFires_On_CursorPosition ()
  411. {
  412. var eventcount = 0;
  413. var tv = new TextView { Width = 50, Height = 10 };
  414. tv.ContentsChanged += (s, e) => { eventcount++; };
  415. Assert.Equal (0, eventcount);
  416. tv.CursorPosition = Point.Empty;
  417. Assert.Equal (0, eventcount);
  418. }
  419. [Fact]
  420. [TextViewTestsAutoInitShutdown]
  421. public void Copy_Or_Cut_And_Paste_With_No_Selection ()
  422. {
  423. _textView.SelectionStartColumn = 20;
  424. _textView.SelectionStartRow = 0;
  425. _textView.CursorPosition = new Point (24, 0);
  426. _textView.NewKeyDownEvent (Key.C.WithCtrl); // Copy
  427. Assert.Equal ("text", _textView.SelectedText);
  428. Assert.Equal ("TAB to jump between text fields.", _textView.Text);
  429. _textView.SelectionStartColumn = 0;
  430. _textView.SelectionStartRow = 0;
  431. Assert.Equal (new Point (24, 0), _textView.CursorPosition);
  432. Assert.True (_textView.IsSelecting);
  433. _textView.IsSelecting = false;
  434. _textView.NewKeyDownEvent (Key.Y.WithCtrl); // Paste
  435. Assert.Equal (new Point (28, 0), _textView.CursorPosition);
  436. Assert.False (_textView.IsSelecting);
  437. Assert.Equal ("TAB to jump between texttext fields.", _textView.Text);
  438. _textView.SelectionStartColumn = 24;
  439. _textView.SelectionStartRow = 0;
  440. _textView.NewKeyDownEvent (Key.W.WithCtrl); // Cut
  441. Assert.Equal (new Point (24, 0), _textView.CursorPosition);
  442. Assert.False (_textView.IsSelecting);
  443. Assert.Equal ("", _textView.SelectedText);
  444. Assert.Equal ("TAB to jump between text fields.", _textView.Text);
  445. _textView.SelectionStartColumn = 0;
  446. _textView.SelectionStartRow = 0;
  447. _textView.IsSelecting = false;
  448. _textView.NewKeyDownEvent (Key.Y.WithCtrl); // Paste
  449. Assert.Equal (new Point (28, 0), _textView.CursorPosition);
  450. Assert.False (_textView.IsSelecting);
  451. Assert.Equal ("TAB to jump between texttext fields.", _textView.Text);
  452. }
  453. [Fact]
  454. [TextViewTestsAutoInitShutdown]
  455. public void Copy_Or_Cut_And_Paste_With_Selection ()
  456. {
  457. _textView.SelectionStartColumn = 20;
  458. _textView.SelectionStartRow = 0;
  459. _textView.CursorPosition = new Point (24, 0);
  460. _textView.NewKeyDownEvent (Key.C.WithCtrl); // Copy
  461. Assert.Equal ("text", _textView.SelectedText);
  462. Assert.Equal ("TAB to jump between text fields.", _textView.Text);
  463. _textView.NewKeyDownEvent (Key.Y.WithCtrl); // Paste
  464. Assert.Equal ("TAB to jump between text fields.", _textView.Text);
  465. _textView.SelectionStartColumn = 20;
  466. _textView.SelectionStartRow = 0;
  467. _textView.NewKeyDownEvent (Key.W.WithCtrl); // Cut
  468. _textView.NewKeyDownEvent (Key.Y.WithCtrl); // Paste
  469. Assert.Equal ("TAB to jump between text fields.", _textView.Text);
  470. }
  471. [Fact]
  472. [TextViewTestsAutoInitShutdown]
  473. public void Copy_Or_Cut_Not_Null_If_Has_Selection ()
  474. {
  475. _textView.SelectionStartColumn = 20;
  476. _textView.SelectionStartRow = 0;
  477. _textView.CursorPosition = new Point (24, 0);
  478. _textView.NewKeyDownEvent (Key.C.WithCtrl); // Copy
  479. Assert.Equal ("text", _textView.SelectedText);
  480. _textView.NewKeyDownEvent (Key.W.WithCtrl); // Cut
  481. Assert.Equal ("", _textView.SelectedText);
  482. }
  483. [Fact]
  484. [TextViewTestsAutoInitShutdown]
  485. public void Copy_Or_Cut_Null_If_No_Selection ()
  486. {
  487. _textView.SelectionStartColumn = 0;
  488. _textView.SelectionStartRow = 0;
  489. _textView.NewKeyDownEvent (Key.C.WithCtrl); // Copy
  490. Assert.Equal ("", _textView.SelectedText);
  491. _textView.NewKeyDownEvent (Key.W.WithCtrl); // Cut
  492. Assert.Equal ("", _textView.SelectedText);
  493. }
  494. [Fact]
  495. [TextViewTestsAutoInitShutdown]
  496. public void Copy_Paste_Surrogate_Pairs ()
  497. {
  498. _textView.Text = "TextView with some more test text. Unicode shouldn't 𝔹Aℝ𝔽!";
  499. _textView.SelectAll ();
  500. _textView.Cut ();
  501. Assert.Equal (
  502. "TextView with some more test text. Unicode shouldn't 𝔹Aℝ𝔽!",
  503. Application.Driver?.Clipboard.GetClipboardData ()
  504. );
  505. Assert.Equal (string.Empty, _textView.Text);
  506. _textView.Paste ();
  507. Assert.Equal ("TextView with some more test text. Unicode shouldn't 𝔹Aℝ𝔽!", _textView.Text);
  508. }
  509. [Fact]
  510. [TextViewTestsAutoInitShutdown]
  511. public void Copy_Without_Selection ()
  512. {
  513. _textView.Text = "This is the first line.\nThis is the second line.\n";
  514. _textView.CursorPosition = new Point (0, _textView.Lines - 1);
  515. _textView.NewKeyDownEvent (Key.C.WithCtrl); // Copy
  516. _textView.NewKeyDownEvent (Key.Y.WithCtrl); // Paste
  517. Assert.Equal (
  518. $"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}{Environment.NewLine}",
  519. _textView.Text
  520. );
  521. _textView.CursorPosition = new Point (3, 1);
  522. _textView.NewKeyDownEvent (Key.C.WithCtrl); // Copy
  523. _textView.NewKeyDownEvent (Key.Y.WithCtrl); // Paste
  524. Assert.Equal (
  525. $"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the second line.{Environment.NewLine}{Environment.NewLine}",
  526. _textView.Text
  527. );
  528. Assert.Equal (new Point (3, 2), _textView.CursorPosition);
  529. _textView.NewKeyDownEvent (Key.Y.WithCtrl); // Paste
  530. Assert.Equal (
  531. $"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the second line.{Environment.NewLine}{Environment.NewLine}",
  532. _textView.Text
  533. );
  534. Assert.Equal (new Point (3, 3), _textView.CursorPosition);
  535. }
  536. [Fact]
  537. [TextViewTestsAutoInitShutdown]
  538. public void Cursor_Position_Multiline_False_Initialization ()
  539. {
  540. Assert.False (_textView.IsInitialized);
  541. Assert.True (_textView.Multiline);
  542. _textView.Multiline = false;
  543. Assert.Equal (32, _textView.CursorPosition.X);
  544. Assert.Equal (0, _textView.CursorPosition.Y);
  545. Assert.Equal (0, _textView.SelectedLength);
  546. Assert.Equal ("", _textView.SelectedText);
  547. Assert.Equal ("TAB to jump between text fields.", _textView.Text);
  548. }
  549. [Fact]
  550. [TextViewTestsAutoInitShutdown]
  551. public void CursorPosition_With_Value_Greater_Than_Text_Length_Changes_To_Text_Length ()
  552. {
  553. _textView.CursorPosition = new Point (33, 1);
  554. Assert.Equal (32, _textView.CursorPosition.X);
  555. Assert.Equal (0, _textView.CursorPosition.Y);
  556. Assert.Equal (0, _textView.SelectedLength);
  557. Assert.Equal ("", _textView.SelectedText);
  558. }
  559. [Fact]
  560. [TextViewTestsAutoInitShutdown]
  561. public void CursorPosition_With_Value_Less_Than_Zero_Changes_To_Zero ()
  562. {
  563. _textView.CursorPosition = new Point (-1, -1);
  564. Assert.Equal (0, _textView.CursorPosition.X);
  565. Assert.Equal (0, _textView.CursorPosition.Y);
  566. Assert.Equal (0, _textView.SelectedLength);
  567. Assert.Equal ("", _textView.SelectedText);
  568. }
  569. [Fact]
  570. [TextViewTestsAutoInitShutdown]
  571. public void Cut_Not_Allowed_If_ReadOnly_Is_True ()
  572. {
  573. _textView.ReadOnly = true;
  574. _textView.SelectionStartColumn = 20;
  575. _textView.SelectionStartRow = 0;
  576. _textView.CursorPosition = new Point (24, 0);
  577. _textView.NewKeyDownEvent (Key.C.WithCtrl); // Copy
  578. Assert.Equal ("text", _textView.SelectedText);
  579. _textView.NewKeyDownEvent (
  580. Key.W.WithCtrl
  581. ); // Selecting is set to false after Cut.
  582. Assert.Equal ("", _textView.SelectedText);
  583. _textView.ReadOnly = false;
  584. Assert.False (_textView.IsSelecting);
  585. _textView.IsSelecting = true; // Needed to set Selecting to true.
  586. _textView.NewKeyDownEvent (Key.C.WithCtrl); // Copy
  587. Assert.Equal ("text", _textView.SelectedText);
  588. _textView.NewKeyDownEvent (Key.W.WithCtrl); // Cut
  589. Assert.Equal ("", _textView.SelectedText);
  590. }
  591. [Fact]
  592. [AutoInitShutdown]
  593. public void DeleteTextBackwards_WordWrap_False_Return_Undo ()
  594. {
  595. const string text = "This is the first line.\nThis is the second line.\n";
  596. var tv = new TextView { Width = Dim.Fill (), Height = Dim.Fill (), Text = text };
  597. string envText = tv.Text;
  598. var top = new Toplevel ();
  599. top.Add (tv);
  600. Application.Begin (top);
  601. Application.Refresh ();
  602. Assert.False (tv.WordWrap);
  603. Assert.Equal (Point.Empty, tv.CursorPosition);
  604. TestHelpers.AssertDriverContentsWithFrameAre (
  605. @"
  606. This is the first line.
  607. This is the second line.
  608. ",
  609. _output
  610. );
  611. tv.CursorPosition = new Point (3, 0);
  612. Assert.Equal (new Point (3, 0), tv.CursorPosition);
  613. Assert.True (tv.NewKeyDownEvent (Key.Backspace));
  614. tv.Draw ();
  615. Assert.Equal (new Point (2, 0), tv.CursorPosition);
  616. TestHelpers.AssertDriverContentsWithFrameAre (
  617. @"
  618. Ths is the first line.
  619. This is the second line.
  620. ",
  621. _output
  622. );
  623. tv.CursorPosition = new Point (0, 1);
  624. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  625. Assert.True (tv.NewKeyDownEvent (Key.Backspace));
  626. tv.Draw ();
  627. Assert.Equal (new Point (22, 0), tv.CursorPosition);
  628. TestHelpers.AssertDriverContentsWithFrameAre (
  629. @"
  630. Ths is the first line.This is the second line.
  631. ",
  632. _output
  633. );
  634. Assert.True (tv.NewKeyDownEvent (Key.Enter));
  635. tv.Draw ();
  636. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  637. TestHelpers.AssertDriverContentsWithFrameAre (
  638. @"
  639. Ths is the first line.
  640. This is the second line.
  641. ",
  642. _output
  643. );
  644. while (tv.Text != envText)
  645. {
  646. Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl));
  647. }
  648. Assert.Equal (envText, tv.Text);
  649. Assert.Equal (new Point (3, 0), tv.CursorPosition);
  650. Assert.False (tv.IsDirty);
  651. top.Dispose ();
  652. }
  653. [Fact]
  654. [AutoInitShutdown]
  655. public void DeleteTextBackwards_WordWrap_True_Return_Undo ()
  656. {
  657. const string text = "This is the first line.\nThis is the second line.\n";
  658. var tv = new TextView { Width = Dim.Fill (), Height = Dim.Fill (), Text = text, WordWrap = true };
  659. string envText = tv.Text;
  660. var top = new Toplevel ();
  661. top.Add (tv);
  662. Application.Begin (top);
  663. Application.Refresh ();
  664. Assert.True (tv.WordWrap);
  665. Assert.Equal (Point.Empty, tv.CursorPosition);
  666. TestHelpers.AssertDriverContentsWithFrameAre (
  667. @"
  668. This is the first line.
  669. This is the second line.
  670. ",
  671. _output
  672. );
  673. tv.CursorPosition = new Point (3, 0);
  674. Assert.Equal (new Point (3, 0), tv.CursorPosition);
  675. Assert.True (tv.NewKeyDownEvent (Key.Backspace));
  676. tv.Draw ();
  677. Assert.Equal (new Point (2, 0), tv.CursorPosition);
  678. TestHelpers.AssertDriverContentsWithFrameAre (
  679. @"
  680. Ths is the first line.
  681. This is the second line.
  682. ",
  683. _output
  684. );
  685. tv.CursorPosition = new Point (0, 1);
  686. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  687. Assert.True (tv.NewKeyDownEvent (Key.Backspace));
  688. tv.Draw ();
  689. Assert.Equal (new Point (22, 0), tv.CursorPosition);
  690. TestHelpers.AssertDriverContentsWithFrameAre (
  691. @"
  692. Ths is the first line.This is the second line.
  693. ",
  694. _output
  695. );
  696. Assert.True (tv.NewKeyDownEvent (Key.Enter));
  697. tv.Draw ();
  698. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  699. TestHelpers.AssertDriverContentsWithFrameAre (
  700. @"
  701. Ths is the first line.
  702. This is the second line.
  703. ",
  704. _output
  705. );
  706. while (tv.Text != envText)
  707. {
  708. Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl));
  709. }
  710. Assert.Equal (envText, tv.Text);
  711. Assert.Equal (new Point (3, 0), tv.CursorPosition);
  712. Assert.False (tv.IsDirty);
  713. top.Dispose ();
  714. }
  715. [Fact]
  716. [AutoInitShutdown]
  717. public void DeleteTextForwards_WordWrap_False_Return_Undo ()
  718. {
  719. const string text = "This is the first line.\nThis is the second line.\n";
  720. var tv = new TextView { Width = Dim.Fill (), Height = Dim.Fill (), Text = text };
  721. string envText = tv.Text;
  722. var top = new Toplevel ();
  723. top.Add (tv);
  724. Application.Begin (top);
  725. Application.Refresh ();
  726. Assert.False (tv.WordWrap);
  727. Assert.Equal (Point.Empty, tv.CursorPosition);
  728. TestHelpers.AssertDriverContentsWithFrameAre (
  729. @"
  730. This is the first line.
  731. This is the second line.
  732. ",
  733. _output
  734. );
  735. tv.CursorPosition = new Point (2, 0);
  736. Assert.Equal (new Point (2, 0), tv.CursorPosition);
  737. Assert.True (tv.NewKeyDownEvent (Key.Delete));
  738. tv.Draw ();
  739. Assert.Equal (new Point (2, 0), tv.CursorPosition);
  740. TestHelpers.AssertDriverContentsWithFrameAre (
  741. @"
  742. Ths is the first line.
  743. This is the second line.
  744. ",
  745. _output
  746. );
  747. tv.CursorPosition = new Point (22, 0);
  748. Assert.Equal (new Point (22, 0), tv.CursorPosition);
  749. Assert.True (tv.NewKeyDownEvent (Key.Delete));
  750. tv.Draw ();
  751. Assert.Equal (new Point (22, 0), tv.CursorPosition);
  752. TestHelpers.AssertDriverContentsWithFrameAre (
  753. @"
  754. Ths is the first line.This is the second line.
  755. ",
  756. _output
  757. );
  758. Assert.True (tv.NewKeyDownEvent (Key.Enter));
  759. tv.Draw ();
  760. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  761. TestHelpers.AssertDriverContentsWithFrameAre (
  762. @"
  763. Ths is the first line.
  764. This is the second line.
  765. ",
  766. _output
  767. );
  768. while (tv.Text != envText)
  769. {
  770. Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl));
  771. }
  772. Assert.Equal (envText, tv.Text);
  773. Assert.Equal (new Point (2, 0), tv.CursorPosition);
  774. Assert.False (tv.IsDirty);
  775. top.Dispose ();
  776. }
  777. [Fact]
  778. [AutoInitShutdown]
  779. public void DeleteTextForwards_WordWrap_True_Return_Undo ()
  780. {
  781. const string text = "This is the first line.\nThis is the second line.\n";
  782. var tv = new TextView { Width = Dim.Fill (), Height = Dim.Fill (), Text = text, WordWrap = true };
  783. string envText = tv.Text;
  784. var top = new Toplevel ();
  785. top.Add (tv);
  786. Application.Begin (top);
  787. Application.Refresh ();
  788. Assert.True (tv.WordWrap);
  789. Assert.Equal (Point.Empty, tv.CursorPosition);
  790. TestHelpers.AssertDriverContentsWithFrameAre (
  791. @"
  792. This is the first line.
  793. This is the second line.
  794. ",
  795. _output
  796. );
  797. tv.CursorPosition = new Point (2, 0);
  798. Assert.Equal (new Point (2, 0), tv.CursorPosition);
  799. Assert.True (tv.NewKeyDownEvent (Key.Delete));
  800. tv.Draw ();
  801. Assert.Equal (new Point (2, 0), tv.CursorPosition);
  802. TestHelpers.AssertDriverContentsWithFrameAre (
  803. @"
  804. Ths is the first line.
  805. This is the second line.
  806. ",
  807. _output
  808. );
  809. tv.CursorPosition = new Point (22, 0);
  810. Assert.Equal (new Point (22, 0), tv.CursorPosition);
  811. Assert.True (tv.NewKeyDownEvent (Key.Delete));
  812. tv.Draw ();
  813. Assert.Equal (new Point (22, 0), tv.CursorPosition);
  814. TestHelpers.AssertDriverContentsWithFrameAre (
  815. @"
  816. Ths is the first line.This is the second line.
  817. ",
  818. _output
  819. );
  820. Assert.True (tv.NewKeyDownEvent (Key.Enter));
  821. tv.Draw ();
  822. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  823. TestHelpers.AssertDriverContentsWithFrameAre (
  824. @"
  825. Ths is the first line.
  826. This is the second line.
  827. ",
  828. _output
  829. );
  830. while (tv.Text != envText)
  831. {
  832. Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl));
  833. }
  834. Assert.Equal (envText, tv.Text);
  835. Assert.Equal (new Point (2, 0), tv.CursorPosition);
  836. Assert.False (tv.IsDirty);
  837. top.Dispose ();
  838. }
  839. [Fact]
  840. [TextViewTestsAutoInitShutdown]
  841. public void DesiredCursorVisibility_Horizontal_Navigation ()
  842. {
  843. var text = "";
  844. for (var i = 0; i < 12; i++)
  845. {
  846. text += $"{i.ToString () [^1]}";
  847. }
  848. var tv = new TextView { Width = 10, Height = 10 };
  849. tv.Text = text;
  850. var top = new Toplevel ();
  851. top.Add (tv);
  852. Application.Begin (top);
  853. Assert.Equal (0, tv.LeftColumn);
  854. Assert.Equal (Point.Empty, tv.CursorPosition);
  855. Application.PositionCursor ();
  856. Assert.Equal (CursorVisibility.Default, tv.CursorVisibility);
  857. for (var i = 0; i < 12; i++)
  858. {
  859. tv.NewMouseEvent (new MouseEventArgs { Flags = MouseFlags.WheeledRight });
  860. Assert.Equal (Math.Min (i + 1, 11), tv.LeftColumn);
  861. Application.PositionCursor ();
  862. Application.Driver!.GetCursorVisibility (out CursorVisibility cursorVisibility);
  863. Assert.Equal (CursorVisibility.Invisible, cursorVisibility);
  864. }
  865. for (var i = 11; i > 0; i--)
  866. {
  867. tv.NewMouseEvent (new MouseEventArgs { Flags = MouseFlags.WheeledLeft });
  868. Assert.Equal (i - 1, tv.LeftColumn);
  869. Application.PositionCursor ();
  870. Application.Driver!.GetCursorVisibility (out CursorVisibility cursorVisibility);
  871. if (i - 1 == 0)
  872. {
  873. Assert.Equal (CursorVisibility.Default, cursorVisibility);
  874. }
  875. else
  876. {
  877. Assert.Equal (CursorVisibility.Invisible, cursorVisibility);
  878. }
  879. }
  880. top.Dispose ();
  881. Application.Shutdown ();
  882. }
  883. [Fact]
  884. [TextViewTestsAutoInitShutdown]
  885. public void DesiredCursorVisibility_Vertical_Navigation ()
  886. {
  887. var text = "";
  888. for (var i = 0; i < 12; i++)
  889. {
  890. text += $"This is the line {i}\n";
  891. }
  892. var tv = new TextView { Width = 10, Height = 10 };
  893. tv.Text = text;
  894. var top = new Toplevel ();
  895. top.Add (tv);
  896. Application.Begin (top);
  897. Assert.Equal (0, tv.TopRow);
  898. Application.PositionCursor ();
  899. Assert.Equal (CursorVisibility.Default, tv.CursorVisibility);
  900. for (var i = 0; i < 12; i++)
  901. {
  902. tv.NewMouseEvent (new MouseEventArgs { Flags = MouseFlags.WheeledDown });
  903. Application.PositionCursor ();
  904. Assert.Equal (i + 1, tv.TopRow);
  905. Application.Driver!.GetCursorVisibility (out CursorVisibility cursorVisibility);
  906. Assert.Equal (CursorVisibility.Invisible, cursorVisibility);
  907. }
  908. for (var i = 12; i > 0; i--)
  909. {
  910. tv.NewMouseEvent (new MouseEventArgs { Flags = MouseFlags.WheeledUp });
  911. Application.PositionCursor ();
  912. Assert.Equal (i - 1, tv.TopRow);
  913. Application.PositionCursor ();
  914. Application.Driver!.GetCursorVisibility (out CursorVisibility cursorVisibility);
  915. if (i - 1 == 0)
  916. {
  917. Assert.Equal (CursorVisibility.Default, cursorVisibility);
  918. }
  919. else
  920. {
  921. Assert.Equal (CursorVisibility.Invisible, cursorVisibility);
  922. }
  923. }
  924. top.Dispose ();
  925. Application.Shutdown ();
  926. }
  927. [Fact]
  928. public void GetRegion_StringFromRunes_Environment_NewLine ()
  929. {
  930. var tv = new TextView { Text = $"1{Environment.NewLine}2" };
  931. Assert.Equal ($"1{Environment.NewLine}2", tv.Text);
  932. Assert.Equal ("", tv.SelectedText);
  933. tv.SelectAll ();
  934. Assert.Equal ($"1{Environment.NewLine}2", tv.Text);
  935. Assert.Equal ($"1{Environment.NewLine}2", tv.SelectedText);
  936. }
  937. [Fact]
  938. public void HistoryText_ClearHistoryChanges ()
  939. {
  940. var text = "This is the first line.\nThis is the second line.\nThis is the third line.";
  941. var tv = new TextView { Text = text };
  942. Assert.True (tv.NewKeyDownEvent (Key.Enter));
  943. Assert.Equal (
  944. $"{Environment.NewLine}This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.",
  945. tv.Text
  946. );
  947. Assert.Equal (4, tv.Lines);
  948. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  949. Assert.True (tv.IsDirty);
  950. Assert.True (tv.HasHistoryChanges);
  951. tv.ClearHistoryChanges ();
  952. Assert.Equal (
  953. $"{Environment.NewLine}This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.",
  954. tv.Text
  955. );
  956. Assert.Equal (4, tv.Lines);
  957. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  958. Assert.False (tv.IsDirty);
  959. Assert.False (tv.HasHistoryChanges);
  960. }
  961. [Fact]
  962. public void HistoryText_Exceptions ()
  963. {
  964. var ht = new HistoryText ();
  965. foreach (object ls in Enum.GetValues (typeof (HistoryText.LineStatus)))
  966. {
  967. if ((HistoryText.LineStatus)ls != HistoryText.LineStatus.Original)
  968. {
  969. Assert.Throws<ArgumentException> (
  970. () => ht.Add (
  971. new List<List<Cell>> { new () },
  972. Point.Empty,
  973. (HistoryText.LineStatus)ls
  974. )
  975. );
  976. }
  977. }
  978. Assert.Null (Record.Exception (() => ht.Add (new List<List<Cell>> { new () }, Point.Empty)));
  979. }
  980. [Fact]
  981. public void HistoryText_IsDirty_HasHistoryChanges ()
  982. {
  983. var tv = new TextView ();
  984. Assert.Equal ("", tv.Text);
  985. Assert.Equal (1, tv.Lines);
  986. Assert.Equal (Point.Empty, tv.CursorPosition);
  987. Assert.False (tv.IsDirty);
  988. Assert.False (tv.HasHistoryChanges);
  989. Assert.True (tv.NewKeyDownEvent (Key.D1));
  990. Assert.Equal ("1", tv.Text);
  991. Assert.Equal (1, tv.Lines);
  992. Assert.Equal (new Point (1, 0), tv.CursorPosition);
  993. Assert.True (tv.IsDirty);
  994. Assert.True (tv.HasHistoryChanges);
  995. Assert.True (tv.NewKeyDownEvent (Key.Enter));
  996. Assert.Equal ($"1{Environment.NewLine}", tv.Text);
  997. Assert.Equal (2, tv.Lines);
  998. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  999. Assert.True (tv.IsDirty);
  1000. Assert.True (tv.HasHistoryChanges);
  1001. Assert.True (tv.NewKeyDownEvent (Key.D2));
  1002. Assert.Equal ($"1{Environment.NewLine}2", tv.Text);
  1003. Assert.Equal (2, tv.Lines);
  1004. Assert.Equal (new Point (1, 1), tv.CursorPosition);
  1005. Assert.True (tv.IsDirty);
  1006. Assert.True (tv.HasHistoryChanges);
  1007. Assert.True (tv.NewKeyDownEvent (Key.Backspace));
  1008. Assert.Equal ($"1{Environment.NewLine}", tv.Text);
  1009. Assert.Equal (2, tv.Lines);
  1010. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  1011. Assert.True (tv.IsDirty);
  1012. Assert.True (tv.HasHistoryChanges);
  1013. Assert.True (tv.NewKeyDownEvent (Key.Backspace));
  1014. Assert.Equal ("1", tv.Text);
  1015. Assert.Equal (1, tv.Lines);
  1016. Assert.Equal (new Point (1, 0), tv.CursorPosition);
  1017. Assert.True (tv.IsDirty);
  1018. Assert.True (tv.HasHistoryChanges);
  1019. Assert.True (tv.NewKeyDownEvent (Key.Backspace));
  1020. Assert.Equal ("", tv.Text);
  1021. Assert.Equal (1, tv.Lines);
  1022. Assert.Equal (Point.Empty, tv.CursorPosition);
  1023. // IsDirty cannot be based on HasHistoryChanges because HasHistoryChanges is greater than 0
  1024. // The only way is comparing from the original text
  1025. Assert.False (tv.IsDirty);
  1026. // Still true because HasHistoryChanges is greater than 0
  1027. Assert.True (tv.HasHistoryChanges);
  1028. }
  1029. [Fact]
  1030. public void HistoryText_Undo_Redo_Changing_On_Middle_Clear_History_Forwards ()
  1031. {
  1032. var tv = new TextView ();
  1033. Assert.True (tv.NewKeyDownEvent (Key.D1));
  1034. Assert.Equal ("1", tv.Text);
  1035. Assert.Equal (1, tv.Lines);
  1036. Assert.Equal (new Point (1, 0), tv.CursorPosition);
  1037. Assert.True (tv.NewKeyDownEvent (Key.D2));
  1038. Assert.Equal ("12", tv.Text);
  1039. Assert.Equal (1, tv.Lines);
  1040. Assert.Equal (new Point (2, 0), tv.CursorPosition);
  1041. Assert.True (tv.NewKeyDownEvent (Key.D3));
  1042. Assert.Equal ("123", tv.Text);
  1043. Assert.Equal (1, tv.Lines);
  1044. Assert.Equal (new Point (3, 0), tv.CursorPosition);
  1045. // Undo
  1046. Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl));
  1047. Assert.Equal ("12", tv.Text);
  1048. Assert.Equal (1, tv.Lines);
  1049. Assert.Equal (new Point (2, 0), tv.CursorPosition);
  1050. Assert.True (tv.NewKeyDownEvent (Key.D4));
  1051. Assert.Equal ("124", tv.Text);
  1052. Assert.Equal (1, tv.Lines);
  1053. Assert.Equal (new Point (3, 0), tv.CursorPosition);
  1054. // Redo
  1055. Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl));
  1056. Assert.Equal ("124", tv.Text);
  1057. Assert.Equal (1, tv.Lines);
  1058. Assert.Equal (new Point (3, 0), tv.CursorPosition);
  1059. }
  1060. [Fact]
  1061. [AutoInitShutdown (useFakeClipboard: true)]
  1062. public void HistoryText_Undo_Redo_Copy_Without_Selection_Multi_Line_Paste ()
  1063. {
  1064. var text = "This is the first line.\nThis is the second line.\nThis is the third line.";
  1065. var tv = new TextView { Text = text };
  1066. tv.CursorPosition = new Point (23, 0);
  1067. Assert.True (tv.NewKeyDownEvent (Key.C.WithCtrl));
  1068. Assert.Equal (
  1069. $"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.",
  1070. tv.Text
  1071. );
  1072. Assert.Equal ("", tv.SelectedText);
  1073. Assert.Equal ("This is the first line.", Clipboard.Contents);
  1074. Assert.Equal (3, tv.Lines);
  1075. Assert.Equal (new Point (23, 0), tv.CursorPosition);
  1076. Assert.True (tv.NewKeyDownEvent (Key.Y.WithCtrl));
  1077. Assert.Equal (
  1078. $"This is the first line.{Environment.NewLine}This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.",
  1079. tv.Text
  1080. );
  1081. Assert.Equal (4, tv.Lines);
  1082. Assert.Equal (new Point (23, 1), tv.CursorPosition);
  1083. // Undo
  1084. Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl));
  1085. Assert.Equal (
  1086. $"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.",
  1087. tv.Text
  1088. );
  1089. Assert.Equal (3, tv.Lines);
  1090. Assert.Equal (new Point (23, 0), tv.CursorPosition);
  1091. // Redo
  1092. Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl));
  1093. Assert.Equal (
  1094. $"This is the first line.{Environment.NewLine}This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.",
  1095. tv.Text
  1096. );
  1097. Assert.Equal (4, tv.Lines);
  1098. Assert.Equal (new Point (23, 1), tv.CursorPosition);
  1099. }
  1100. [Fact]
  1101. [AutoInitShutdown]
  1102. public void HistoryText_Undo_Redo_Cut_Multi_Line_Another_Selected_Paste ()
  1103. {
  1104. var text = "This is the first line.\nThis is the second line.\nThis is the third line.";
  1105. var tv = new TextView { Text = text };
  1106. tv.SelectionStartColumn = 12;
  1107. tv.CursorPosition = new Point (17, 0);
  1108. Assert.True (tv.NewKeyDownEvent (Key.W.WithCtrl));
  1109. Assert.Equal (
  1110. $"This is the line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.",
  1111. tv.Text
  1112. );
  1113. Assert.Equal ("", tv.SelectedText);
  1114. Assert.Equal (3, tv.Lines);
  1115. Assert.Equal (new Point (12, 0), tv.CursorPosition);
  1116. tv.SelectionStartColumn = 12;
  1117. tv.SelectionStartRow = 1;
  1118. tv.CursorPosition = new Point (18, 1);
  1119. Assert.True (tv.NewKeyDownEvent (Key.Y.WithCtrl));
  1120. Assert.Equal (
  1121. $"This is the line.{Environment.NewLine}This is the first line.{Environment.NewLine}This is the third line.",
  1122. tv.Text
  1123. );
  1124. Assert.Equal (3, tv.Lines);
  1125. Assert.Equal (new Point (17, 1), tv.CursorPosition);
  1126. // Undo
  1127. Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl));
  1128. Assert.Equal (
  1129. $"This is the line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.",
  1130. tv.Text
  1131. );
  1132. Assert.Equal (3, tv.Lines);
  1133. Assert.Equal (new Point (12, 1), tv.CursorPosition);
  1134. Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl));
  1135. Assert.Equal (
  1136. $"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.",
  1137. tv.Text
  1138. );
  1139. Assert.Equal (3, tv.Lines);
  1140. Assert.Equal (new Point (12, 0), tv.CursorPosition);
  1141. // Redo
  1142. Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl));
  1143. Assert.Equal (
  1144. $"This is the line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.",
  1145. tv.Text
  1146. );
  1147. Assert.Equal (3, tv.Lines);
  1148. Assert.Equal (new Point (12, 0), tv.CursorPosition);
  1149. Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl));
  1150. Assert.Equal (
  1151. $"This is the line.{Environment.NewLine}This is the first line.{Environment.NewLine}This is the third line.",
  1152. tv.Text
  1153. );
  1154. Assert.Equal (3, tv.Lines);
  1155. Assert.Equal (new Point (17, 1), tv.CursorPosition);
  1156. }
  1157. [Fact]
  1158. [AutoInitShutdown]
  1159. public void HistoryText_Undo_Redo_Cut_Multi_Line_Selected_Paste ()
  1160. {
  1161. var text = "This is the first line.\nThis is the second line.\nThis is the third line.";
  1162. var tv = new TextView { Text = text };
  1163. tv.SelectionStartColumn = 12;
  1164. tv.CursorPosition = new Point (17, 0);
  1165. Assert.True (tv.NewKeyDownEvent (Key.W.WithCtrl));
  1166. Assert.Equal (
  1167. $"This is the line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.",
  1168. tv.Text
  1169. );
  1170. Assert.Equal ("", tv.SelectedText);
  1171. Assert.Equal (3, tv.Lines);
  1172. Assert.Equal (new Point (12, 0), tv.CursorPosition);
  1173. tv.SelectionStartColumn = 12;
  1174. tv.CursorPosition = new Point (11, 1);
  1175. Assert.True (tv.NewKeyDownEvent (Key.Y.WithCtrl));
  1176. Assert.Equal ($"This is the first second line.{Environment.NewLine}This is the third line.", tv.Text);
  1177. Assert.Equal (2, tv.Lines);
  1178. Assert.Equal (new Point (17, 0), tv.CursorPosition);
  1179. // Undo
  1180. Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl));
  1181. Assert.Equal (
  1182. $"This is the line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.",
  1183. tv.Text
  1184. );
  1185. Assert.Equal (3, tv.Lines);
  1186. Assert.Equal (new Point (12, 0), tv.CursorPosition);
  1187. // Redo
  1188. Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl));
  1189. Assert.Equal ($"This is the first second line.{Environment.NewLine}This is the third line.", tv.Text);
  1190. Assert.Equal (2, tv.Lines);
  1191. Assert.Equal (new Point (17, 0), tv.CursorPosition);
  1192. }
  1193. [Fact]
  1194. [AutoInitShutdown]
  1195. public void HistoryText_Undo_Redo_Cut_Simple_Paste_Starting ()
  1196. {
  1197. var text = "This is the first line.\nThis is the second line.\nThis is the third line.";
  1198. var tv = new TextView { Text = text };
  1199. tv.SelectionStartColumn = 12;
  1200. tv.CursorPosition = new Point (18, 1);
  1201. Assert.True (tv.NewKeyDownEvent (Key.W.WithCtrl));
  1202. Assert.Equal ($"This is the line.{Environment.NewLine}This is the third line.", tv.Text);
  1203. Assert.Equal ("", tv.SelectedText);
  1204. Assert.Equal (2, tv.Lines);
  1205. Assert.Equal (new Point (12, 0), tv.CursorPosition);
  1206. tv.IsSelecting = false;
  1207. Assert.True (tv.NewKeyDownEvent (Key.Y.WithCtrl));
  1208. Assert.Equal (
  1209. $"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.",
  1210. tv.Text
  1211. );
  1212. Assert.Equal (3, tv.Lines);
  1213. Assert.Equal (new Point (18, 1), tv.CursorPosition);
  1214. // Undo
  1215. Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl));
  1216. Assert.Equal ($"This is the line.{Environment.NewLine}This is the third line.", tv.Text);
  1217. Assert.Equal (2, tv.Lines);
  1218. Assert.Equal (new Point (12, 0), tv.CursorPosition);
  1219. // Redo
  1220. Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl));
  1221. Assert.Equal (
  1222. $"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.",
  1223. tv.Text
  1224. );
  1225. Assert.Equal (3, tv.Lines);
  1226. Assert.Equal (new Point (18, 1), tv.CursorPosition);
  1227. }
  1228. [Fact]
  1229. public void HistoryText_Undo_Redo_Disabled_On_WordWrap ()
  1230. {
  1231. var text = "This is the first line.\nThis is the second line.\nThis is the third line.\n";
  1232. var tv = new TextView { Width = 80, Height = 5, Text = text };
  1233. Assert.False (tv.WordWrap);
  1234. tv.WordWrap = true;
  1235. tv.SelectionStartColumn = 12;
  1236. tv.CursorPosition = new Point (12, 2);
  1237. Assert.True (tv.NewKeyDownEvent (Key.Enter));
  1238. Assert.Equal ($"This is the {Environment.NewLine}third line.{Environment.NewLine}", tv.Text);
  1239. Assert.Equal (3, tv.Lines);
  1240. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  1241. Assert.True (tv.NewKeyDownEvent (Key.A));
  1242. Assert.Equal ($"This is the {Environment.NewLine}athird line.{Environment.NewLine}", tv.Text);
  1243. Assert.Equal (3, tv.Lines);
  1244. Assert.Equal (new Point (1, 1), tv.CursorPosition);
  1245. Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl));
  1246. Assert.Equal ($"This is the {Environment.NewLine}third line.{Environment.NewLine}", tv.Text);
  1247. Assert.Equal (3, tv.Lines);
  1248. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  1249. Assert.True (tv.IsDirty);
  1250. Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl));
  1251. Assert.Equal ($"This is the {Environment.NewLine}athird line.{Environment.NewLine}", tv.Text);
  1252. Assert.Equal (3, tv.Lines);
  1253. Assert.Equal (new Point (1, 1), tv.CursorPosition);
  1254. }
  1255. [Fact]
  1256. [AutoInitShutdown]
  1257. public void HistoryText_Undo_Redo_Empty_Copy_Without_Selection_Multi_Line_Selected_Paste ()
  1258. {
  1259. var text = "\nThis is the first line.\nThis is the second line.";
  1260. var tv = new TextView { Text = text };
  1261. Assert.True (tv.NewKeyDownEvent (Key.C.WithCtrl));
  1262. Assert.Equal (
  1263. $"{Environment.NewLine}This is the first line.{Environment.NewLine}This is the second line.",
  1264. tv.Text
  1265. );
  1266. Assert.Equal ("", tv.SelectedText);
  1267. Assert.Equal (3, tv.Lines);
  1268. Assert.Equal (Point.Empty, tv.CursorPosition);
  1269. Assert.True (tv.NewKeyDownEvent (Key.Y.WithCtrl));
  1270. Assert.Equal (
  1271. $"{Environment.NewLine}{Environment.NewLine}This is the first line.{Environment.NewLine}This is the second line.",
  1272. tv.Text
  1273. );
  1274. Assert.Equal (4, tv.Lines);
  1275. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  1276. // Undo
  1277. Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl));
  1278. Assert.Equal (
  1279. $"{Environment.NewLine}This is the first line.{Environment.NewLine}This is the second line.",
  1280. tv.Text
  1281. );
  1282. Assert.Equal (3, tv.Lines);
  1283. Assert.Equal (Point.Empty, tv.CursorPosition);
  1284. // Redo
  1285. Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl));
  1286. Assert.Equal (
  1287. $"{Environment.NewLine}{Environment.NewLine}This is the first line.{Environment.NewLine}This is the second line.",
  1288. tv.Text
  1289. );
  1290. Assert.Equal (4, tv.Lines);
  1291. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  1292. }
  1293. [Fact]
  1294. public void HistoryText_Undo_Redo_Ending_With_Newline_Multi_Line_Selected_Almost_All_Return_And_InsertText ()
  1295. {
  1296. var text = "This is the first line.\nThis is the second line.\nThis is the third line.\n";
  1297. var tv = new TextView { Text = text };
  1298. tv.SelectionStartColumn = 12;
  1299. tv.CursorPosition = new Point (12, 2);
  1300. Assert.True (tv.NewKeyDownEvent (Key.Enter));
  1301. Assert.Equal ($"This is the {Environment.NewLine}third line.{Environment.NewLine}", tv.Text);
  1302. Assert.Equal (3, tv.Lines);
  1303. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  1304. Assert.True (tv.NewKeyDownEvent (Key.A));
  1305. Assert.Equal ($"This is the {Environment.NewLine}athird line.{Environment.NewLine}", tv.Text);
  1306. Assert.Equal (3, tv.Lines);
  1307. Assert.Equal (new Point (1, 1), tv.CursorPosition);
  1308. // Undo
  1309. Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl));
  1310. Assert.Equal ($"This is the {Environment.NewLine}third line.{Environment.NewLine}", tv.Text);
  1311. Assert.Equal (3, tv.Lines);
  1312. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  1313. Assert.True (tv.IsDirty);
  1314. Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl));
  1315. Assert.Equal (
  1316. $"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.{Environment.NewLine}",
  1317. tv.Text
  1318. );
  1319. Assert.Equal (4, tv.Lines);
  1320. Assert.Equal (new Point (12, 2), tv.CursorPosition);
  1321. Assert.False (tv.IsDirty);
  1322. // Redo
  1323. Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl));
  1324. Assert.Equal ($"This is the {Environment.NewLine}third line.{Environment.NewLine}", tv.Text);
  1325. Assert.Equal (3, tv.Lines);
  1326. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  1327. Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl));
  1328. Assert.Equal ($"This is the {Environment.NewLine}athird line.{Environment.NewLine}", tv.Text);
  1329. Assert.Equal (3, tv.Lines);
  1330. Assert.Equal (new Point (1, 1), tv.CursorPosition);
  1331. // Undo
  1332. Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl));
  1333. Assert.Equal ($"This is the {Environment.NewLine}third line.{Environment.NewLine}", tv.Text);
  1334. Assert.Equal (3, tv.Lines);
  1335. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  1336. Assert.True (tv.IsDirty);
  1337. Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl));
  1338. Assert.Equal (
  1339. $"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.{Environment.NewLine}",
  1340. tv.Text
  1341. );
  1342. Assert.Equal (4, tv.Lines);
  1343. Assert.Equal (new Point (12, 2), tv.CursorPosition);
  1344. Assert.False (tv.IsDirty);
  1345. // Redo
  1346. Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl));
  1347. Assert.Equal ($"This is the {Environment.NewLine}third line.{Environment.NewLine}", tv.Text);
  1348. Assert.Equal (3, tv.Lines);
  1349. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  1350. Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl));
  1351. Assert.Equal ($"This is the {Environment.NewLine}athird line.{Environment.NewLine}", tv.Text);
  1352. Assert.Equal (3, tv.Lines);
  1353. Assert.Equal (new Point (1, 1), tv.CursorPosition);
  1354. }
  1355. [Fact]
  1356. public void HistoryText_Undo_Redo_First_Line_Selected_Return_And_InsertText ()
  1357. {
  1358. var text = "This is the first line.\nThis is the second line.\nThis is the third line.";
  1359. var tv = new TextView { Text = text };
  1360. tv.SelectionStartColumn = 12;
  1361. tv.CursorPosition = new Point (17, 0);
  1362. Assert.True (tv.NewKeyDownEvent (Key.Enter));
  1363. Assert.Equal (
  1364. $"This is the {Environment.NewLine} line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.",
  1365. tv.Text
  1366. );
  1367. Assert.Equal (4, tv.Lines);
  1368. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  1369. Assert.True (tv.NewKeyDownEvent (Key.A));
  1370. Assert.Equal (
  1371. $"This is the {Environment.NewLine}a line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.",
  1372. tv.Text
  1373. );
  1374. Assert.Equal (4, tv.Lines);
  1375. Assert.Equal (new Point (1, 1), tv.CursorPosition);
  1376. // Undo
  1377. Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl));
  1378. Assert.Equal (
  1379. $"This is the {Environment.NewLine} line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.",
  1380. tv.Text
  1381. );
  1382. Assert.Equal (4, tv.Lines);
  1383. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  1384. Assert.True (tv.IsDirty);
  1385. Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl));
  1386. Assert.Equal (
  1387. $"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.",
  1388. tv.Text
  1389. );
  1390. Assert.Equal (3, tv.Lines);
  1391. Assert.Equal (new Point (17, 0), tv.CursorPosition);
  1392. Assert.False (tv.IsDirty);
  1393. // Redo
  1394. Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl));
  1395. Assert.Equal (
  1396. $"This is the {Environment.NewLine} line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.",
  1397. tv.Text
  1398. );
  1399. Assert.Equal (4, tv.Lines);
  1400. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  1401. Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl));
  1402. Assert.Equal (
  1403. $"This is the {Environment.NewLine}a line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.",
  1404. tv.Text
  1405. );
  1406. Assert.Equal (4, tv.Lines);
  1407. Assert.Equal (new Point (1, 1), tv.CursorPosition);
  1408. // Undo
  1409. Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl));
  1410. Assert.Equal (
  1411. $"This is the {Environment.NewLine} line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.",
  1412. tv.Text
  1413. );
  1414. Assert.Equal (4, tv.Lines);
  1415. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  1416. Assert.True (tv.IsDirty);
  1417. Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl));
  1418. Assert.Equal (
  1419. $"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.",
  1420. tv.Text
  1421. );
  1422. Assert.Equal (3, tv.Lines);
  1423. Assert.Equal (new Point (17, 0), tv.CursorPosition);
  1424. Assert.False (tv.IsDirty);
  1425. // Redo
  1426. Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl));
  1427. Assert.Equal (
  1428. $"This is the {Environment.NewLine} line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.",
  1429. tv.Text
  1430. );
  1431. Assert.Equal (4, tv.Lines);
  1432. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  1433. Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl));
  1434. Assert.Equal (
  1435. $"This is the {Environment.NewLine}a line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.",
  1436. tv.Text
  1437. );
  1438. Assert.Equal (4, tv.Lines);
  1439. Assert.Equal (new Point (1, 1), tv.CursorPosition);
  1440. }
  1441. [Fact]
  1442. [AutoInitShutdown]
  1443. public void HistoryText_Undo_Redo_KillToEndOfLine ()
  1444. {
  1445. var text = "First line.\nSecond line.";
  1446. var tv = new TextView { Text = text };
  1447. Assert.True (tv.NewKeyDownEvent (Key.K.WithCtrl));
  1448. Assert.Equal ($"{Environment.NewLine}Second line.", tv.Text);
  1449. Assert.Equal ("", tv.SelectedText);
  1450. Assert.Equal ("First line.", Clipboard.Contents);
  1451. Assert.Equal (2, tv.Lines);
  1452. Assert.Equal (Point.Empty, tv.CursorPosition);
  1453. Assert.True (tv.NewKeyDownEvent (Key.K.WithCtrl));
  1454. Assert.Equal ("Second line.", tv.Text);
  1455. Assert.Equal ("", tv.SelectedText);
  1456. Assert.Equal ($"First line.{Environment.NewLine}", Clipboard.Contents);
  1457. Assert.Equal (1, tv.Lines);
  1458. Assert.Equal (Point.Empty, tv.CursorPosition);
  1459. Assert.True (tv.NewKeyDownEvent (Key.K.WithCtrl));
  1460. Assert.Equal ("", tv.Text);
  1461. Assert.Equal ("", tv.SelectedText);
  1462. Assert.Equal ($"First line.{Environment.NewLine}Second line.", Clipboard.Contents);
  1463. Assert.Equal (1, tv.Lines);
  1464. Assert.Equal (Point.Empty, tv.CursorPosition);
  1465. // Undo
  1466. Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl));
  1467. Assert.Equal ("Second line.", tv.Text);
  1468. Assert.Equal (1, tv.Lines);
  1469. Assert.Equal (Point.Empty, tv.CursorPosition);
  1470. Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl));
  1471. Assert.Equal ($"{Environment.NewLine}Second line.", tv.Text);
  1472. Assert.Equal (2, tv.Lines);
  1473. Assert.Equal (Point.Empty, tv.CursorPosition);
  1474. Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl));
  1475. Assert.Equal ($"First line.{Environment.NewLine}Second line.", tv.Text);
  1476. Assert.Equal (2, tv.Lines);
  1477. Assert.Equal (Point.Empty, tv.CursorPosition);
  1478. // Redo
  1479. Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl));
  1480. Assert.Equal ($"{Environment.NewLine}Second line.", tv.Text);
  1481. Assert.Equal (2, tv.Lines);
  1482. Assert.Equal (Point.Empty, tv.CursorPosition);
  1483. Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl));
  1484. Assert.Equal ("Second line.", tv.Text);
  1485. Assert.Equal (1, tv.Lines);
  1486. Assert.Equal (Point.Empty, tv.CursorPosition);
  1487. Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl));
  1488. Assert.Equal ("", tv.Text);
  1489. Assert.Equal (1, tv.Lines);
  1490. Assert.Equal (Point.Empty, tv.CursorPosition);
  1491. }
  1492. [Fact]
  1493. [AutoInitShutdown]
  1494. public void HistoryText_Undo_Redo_KillToLeftStart ()
  1495. {
  1496. var text = "First line.\nSecond line.";
  1497. var tv = new TextView { Text = text };
  1498. Assert.True (tv.NewKeyDownEvent (Key.End.WithCtrl));
  1499. Assert.Equal ($"First line.{Environment.NewLine}Second line.", tv.Text);
  1500. Assert.Equal ("", tv.SelectedText);
  1501. Assert.Equal (2, tv.Lines);
  1502. Assert.Equal (new Point (12, 1), tv.CursorPosition);
  1503. Assert.True (tv.NewKeyDownEvent (Key.Backspace.WithCtrl.WithShift));
  1504. Assert.Equal ($"First line.{Environment.NewLine}", tv.Text);
  1505. Assert.Equal ("", tv.SelectedText);
  1506. Assert.Equal ("Second line.", Clipboard.Contents);
  1507. Assert.Equal (2, tv.Lines);
  1508. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  1509. Assert.True (tv.NewKeyDownEvent (Key.Backspace.WithCtrl.WithShift));
  1510. Assert.Equal ("First line.", tv.Text);
  1511. Assert.Equal ("", tv.SelectedText);
  1512. Assert.Equal ($"Second line.{Environment.NewLine}", Clipboard.Contents);
  1513. Assert.Equal (1, tv.Lines);
  1514. Assert.Equal (new Point (11, 0), tv.CursorPosition);
  1515. Assert.True (tv.NewKeyDownEvent (Key.Backspace.WithCtrl.WithShift));
  1516. Assert.Equal ("", tv.Text);
  1517. Assert.Equal ("", tv.SelectedText);
  1518. Assert.Equal ($"Second line.{Environment.NewLine}First line.", Clipboard.Contents);
  1519. Assert.Equal (1, tv.Lines);
  1520. Assert.Equal (Point.Empty, tv.CursorPosition);
  1521. // Undo
  1522. Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl));
  1523. Assert.Equal ("First line.", tv.Text);
  1524. Assert.Equal (1, tv.Lines);
  1525. Assert.Equal (new Point (11, 0), tv.CursorPosition);
  1526. Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl));
  1527. Assert.Equal ($"First line.{Environment.NewLine}", tv.Text);
  1528. Assert.Equal (2, tv.Lines);
  1529. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  1530. Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl));
  1531. Assert.Equal ($"First line.{Environment.NewLine}Second line.", tv.Text);
  1532. Assert.Equal (2, tv.Lines);
  1533. Assert.Equal (new Point (12, 1), tv.CursorPosition);
  1534. // Redo
  1535. Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl));
  1536. Assert.Equal ($"First line.{Environment.NewLine}", tv.Text);
  1537. Assert.Equal (2, tv.Lines);
  1538. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  1539. Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl));
  1540. Assert.Equal ("First line.", tv.Text);
  1541. Assert.Equal (1, tv.Lines);
  1542. Assert.Equal (new Point (11, 0), tv.CursorPosition);
  1543. Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl));
  1544. Assert.Equal ("", tv.Text);
  1545. Assert.Equal (1, tv.Lines);
  1546. Assert.Equal (Point.Empty, tv.CursorPosition);
  1547. }
  1548. [Fact]
  1549. public void HistoryText_Undo_Redo_KillWordBackward ()
  1550. {
  1551. var text = "First line.\nSecond line.";
  1552. var tv = new TextView { Text = text };
  1553. Assert.True (tv.NewKeyDownEvent (Key.End.WithCtrl));
  1554. Assert.Equal ($"First line.{Environment.NewLine}Second line.", tv.Text);
  1555. Assert.Equal ("", tv.SelectedText);
  1556. Assert.Equal (2, tv.Lines);
  1557. Assert.Equal (new Point (12, 1), tv.CursorPosition);
  1558. Assert.True (tv.NewKeyDownEvent (Key.Backspace.WithCtrl));
  1559. Assert.Equal ($"First line.{Environment.NewLine}Second line", tv.Text);
  1560. Assert.Equal ("", tv.SelectedText);
  1561. Assert.Equal (2, tv.Lines);
  1562. Assert.Equal (new Point (11, 1), tv.CursorPosition);
  1563. Assert.True (tv.NewKeyDownEvent (Key.Backspace.WithCtrl));
  1564. Assert.Equal ($"First line.{Environment.NewLine}Second ", tv.Text);
  1565. Assert.Equal ("", tv.SelectedText);
  1566. Assert.Equal (2, tv.Lines);
  1567. Assert.Equal (new Point (7, 1), tv.CursorPosition);
  1568. Assert.True (tv.NewKeyDownEvent (Key.Backspace.WithCtrl));
  1569. Assert.Equal ($"First line.{Environment.NewLine}", tv.Text);
  1570. Assert.Equal ("", tv.SelectedText);
  1571. Assert.Equal (2, tv.Lines);
  1572. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  1573. Assert.True (tv.NewKeyDownEvent (Key.Backspace.WithCtrl));
  1574. Assert.Equal ("First line.", tv.Text);
  1575. Assert.Equal ("", tv.SelectedText);
  1576. Assert.Equal (1, tv.Lines);
  1577. Assert.Equal (new Point (11, 0), tv.CursorPosition);
  1578. Assert.True (tv.NewKeyDownEvent (Key.Backspace.WithCtrl));
  1579. Assert.Equal ("First line", tv.Text);
  1580. Assert.Equal ("", tv.SelectedText);
  1581. Assert.Equal (1, tv.Lines);
  1582. Assert.Equal (new Point (10, 0), tv.CursorPosition);
  1583. Assert.True (tv.NewKeyDownEvent (Key.Backspace.WithCtrl));
  1584. Assert.Equal ("First ", tv.Text);
  1585. Assert.Equal ("", tv.SelectedText);
  1586. Assert.Equal (1, tv.Lines);
  1587. Assert.Equal (new Point (6, 0), tv.CursorPosition);
  1588. Assert.True (tv.NewKeyDownEvent (Key.Backspace.WithCtrl));
  1589. Assert.Equal ("", tv.Text);
  1590. Assert.Equal ("", tv.SelectedText);
  1591. Assert.Equal (1, tv.Lines);
  1592. Assert.Equal (Point.Empty, tv.CursorPosition);
  1593. // Undo
  1594. Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl));
  1595. Assert.Equal ("First ", tv.Text);
  1596. Assert.Equal (1, tv.Lines);
  1597. Assert.Equal (new Point (6, 0), tv.CursorPosition);
  1598. Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl));
  1599. Assert.Equal ("First line", tv.Text);
  1600. Assert.Equal (1, tv.Lines);
  1601. Assert.Equal (new Point (10, 0), tv.CursorPosition);
  1602. Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl));
  1603. Assert.Equal ("First line.", tv.Text);
  1604. Assert.Equal (1, tv.Lines);
  1605. Assert.Equal (new Point (11, 0), tv.CursorPosition);
  1606. Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl));
  1607. Assert.Equal ($"First line.{Environment.NewLine}", tv.Text);
  1608. Assert.Equal (2, tv.Lines);
  1609. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  1610. Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl));
  1611. Assert.Equal ($"First line.{Environment.NewLine}Second ", tv.Text);
  1612. Assert.Equal (2, tv.Lines);
  1613. Assert.Equal (new Point (7, 1), tv.CursorPosition);
  1614. Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl));
  1615. Assert.Equal ($"First line.{Environment.NewLine}Second line", tv.Text);
  1616. Assert.Equal (2, tv.Lines);
  1617. Assert.Equal (new Point (11, 1), tv.CursorPosition);
  1618. Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl));
  1619. Assert.Equal ($"First line.{Environment.NewLine}Second line.", tv.Text);
  1620. Assert.Equal (2, tv.Lines);
  1621. Assert.Equal (new Point (12, 1), tv.CursorPosition);
  1622. // Redo
  1623. Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl));
  1624. Assert.Equal ($"First line.{Environment.NewLine}Second line", tv.Text);
  1625. Assert.Equal (2, tv.Lines);
  1626. Assert.Equal (new Point (11, 1), tv.CursorPosition);
  1627. Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl));
  1628. Assert.Equal ($"First line.{Environment.NewLine}Second ", tv.Text);
  1629. Assert.Equal (2, tv.Lines);
  1630. Assert.Equal (new Point (7, 1), tv.CursorPosition);
  1631. Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl));
  1632. Assert.Equal ($"First line.{Environment.NewLine}", tv.Text);
  1633. Assert.Equal (2, tv.Lines);
  1634. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  1635. Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl));
  1636. Assert.Equal ("First line.", tv.Text);
  1637. Assert.Equal (1, tv.Lines);
  1638. Assert.Equal (new Point (11, 0), tv.CursorPosition);
  1639. Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl));
  1640. Assert.Equal ("First line", tv.Text);
  1641. Assert.Equal (1, tv.Lines);
  1642. Assert.Equal (new Point (10, 0), tv.CursorPosition);
  1643. Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl));
  1644. Assert.Equal ("First ", tv.Text);
  1645. Assert.Equal (1, tv.Lines);
  1646. Assert.Equal (new Point (6, 0), tv.CursorPosition);
  1647. Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl));
  1648. Assert.Equal ("", tv.Text);
  1649. Assert.Equal (1, tv.Lines);
  1650. Assert.Equal (Point.Empty, tv.CursorPosition);
  1651. }
  1652. [Fact]
  1653. public void HistoryText_Undo_Redo_KillWordForward ()
  1654. {
  1655. var text = "First line.\nSecond line.";
  1656. var tv = new TextView { Text = text };
  1657. Assert.True (tv.NewKeyDownEvent (Key.Delete.WithCtrl));
  1658. Assert.Equal ($"line.{Environment.NewLine}Second line.", tv.Text);
  1659. Assert.Equal ("", tv.SelectedText);
  1660. Assert.Equal (2, tv.Lines);
  1661. Assert.Equal (Point.Empty, tv.CursorPosition);
  1662. Assert.True (tv.NewKeyDownEvent (Key.Delete.WithCtrl));
  1663. Assert.Equal ($"{Environment.NewLine}Second line.", tv.Text);
  1664. Assert.Equal (2, tv.Lines);
  1665. Assert.Equal (Point.Empty, tv.CursorPosition);
  1666. Assert.True (tv.NewKeyDownEvent (Key.Delete.WithCtrl));
  1667. Assert.Equal ("Second line.", tv.Text);
  1668. Assert.Equal (1, tv.Lines);
  1669. Assert.Equal (Point.Empty, tv.CursorPosition);
  1670. Assert.True (tv.NewKeyDownEvent (Key.Delete.WithCtrl));
  1671. Assert.Equal ("line.", tv.Text);
  1672. Assert.Equal (1, tv.Lines);
  1673. Assert.Equal (Point.Empty, tv.CursorPosition);
  1674. Assert.True (tv.NewKeyDownEvent (Key.Delete.WithCtrl));
  1675. Assert.Equal ("", tv.Text);
  1676. Assert.Equal (1, tv.Lines);
  1677. Assert.Equal (Point.Empty, tv.CursorPosition);
  1678. // Undo
  1679. Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl));
  1680. Assert.Equal ("line.", tv.Text);
  1681. Assert.Equal (1, tv.Lines);
  1682. Assert.Equal (Point.Empty, tv.CursorPosition);
  1683. Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl));
  1684. Assert.Equal ("Second line.", tv.Text);
  1685. Assert.Equal (1, tv.Lines);
  1686. Assert.Equal (Point.Empty, tv.CursorPosition);
  1687. Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl));
  1688. Assert.Equal ($"{Environment.NewLine}Second line.", tv.Text);
  1689. Assert.Equal (2, tv.Lines);
  1690. Assert.Equal (Point.Empty, tv.CursorPosition);
  1691. Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl));
  1692. Assert.Equal ($"line.{Environment.NewLine}Second line.", tv.Text);
  1693. Assert.Equal (2, tv.Lines);
  1694. Assert.Equal (Point.Empty, tv.CursorPosition);
  1695. Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl));
  1696. Assert.Equal ($"First line.{Environment.NewLine}Second line.", tv.Text);
  1697. Assert.Equal (2, tv.Lines);
  1698. Assert.Equal (Point.Empty, tv.CursorPosition);
  1699. // Redo
  1700. Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl));
  1701. Assert.Equal ($"line.{Environment.NewLine}Second line.", tv.Text);
  1702. Assert.Equal (2, tv.Lines);
  1703. Assert.Equal (Point.Empty, tv.CursorPosition);
  1704. Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl));
  1705. Assert.Equal ($"{Environment.NewLine}Second line.", tv.Text);
  1706. Assert.Equal (2, tv.Lines);
  1707. Assert.Equal (Point.Empty, tv.CursorPosition);
  1708. Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl));
  1709. Assert.Equal ("Second line.", tv.Text);
  1710. Assert.Equal (1, tv.Lines);
  1711. Assert.Equal (Point.Empty, tv.CursorPosition);
  1712. Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl));
  1713. Assert.Equal ("line.", tv.Text);
  1714. Assert.Equal (1, tv.Lines);
  1715. Assert.Equal (Point.Empty, tv.CursorPosition);
  1716. Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl));
  1717. Assert.Equal ("", tv.Text);
  1718. Assert.Equal (1, tv.Lines);
  1719. Assert.Equal (Point.Empty, tv.CursorPosition);
  1720. }
  1721. [Fact]
  1722. [AutoInitShutdown]
  1723. public void HistoryText_Undo_Redo_Multi_Line_DeleteCharLeft ()
  1724. {
  1725. var text = "This is the first line.\nThis is the second line.\nThis is the third line.";
  1726. var tv = new TextView { Width = 10, Height = 2, Text = text };
  1727. Toplevel top = new ();
  1728. top.Add (tv);
  1729. Application.Begin (top);
  1730. Assert.Equal (
  1731. $"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.",
  1732. tv.Text
  1733. );
  1734. Assert.Equal (3, tv.Lines);
  1735. Assert.Equal (Point.Empty, tv.CursorPosition);
  1736. var ntimes = 3;
  1737. tv.CursorPosition = new Point (7, 1);
  1738. for (var i = 0; i < ntimes; i++)
  1739. {
  1740. tv.DeleteCharLeft ();
  1741. }
  1742. Assert.Equal (
  1743. $"This is the first line.{Environment.NewLine}This the second line.{Environment.NewLine}This is the third line.",
  1744. tv.Text
  1745. );
  1746. Assert.Equal (3, tv.Lines);
  1747. Assert.Equal (new Point (4, 1), tv.CursorPosition);
  1748. tv.CursorPosition = new Point (7, 0);
  1749. for (var i = 0; i < ntimes; i++)
  1750. {
  1751. tv.DeleteCharLeft ();
  1752. }
  1753. Assert.Equal (
  1754. $"This the first line.{Environment.NewLine}This the second line.{Environment.NewLine}This is the third line.",
  1755. tv.Text
  1756. );
  1757. Assert.Equal (3, tv.Lines);
  1758. Assert.Equal (new Point (4, 0), tv.CursorPosition);
  1759. tv.CursorPosition = new Point (7, 2);
  1760. for (var i = 0; i < ntimes; i++)
  1761. {
  1762. tv.DeleteCharLeft ();
  1763. }
  1764. Assert.Equal (
  1765. $"This the first line.{Environment.NewLine}This the second line.{Environment.NewLine}This the third line.",
  1766. tv.Text
  1767. );
  1768. Assert.Equal (3, tv.Lines);
  1769. Assert.Equal (new Point (4, 2), tv.CursorPosition);
  1770. for (var i = 0; i < ntimes; i++)
  1771. {
  1772. Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl));
  1773. switch (i)
  1774. {
  1775. case 0:
  1776. Assert.Equal (
  1777. $"This the first line.{Environment.NewLine}This the second line.{Environment.NewLine}This the third line.",
  1778. tv.Text
  1779. );
  1780. Assert.Equal (new Point (5, 2), tv.CursorPosition);
  1781. break;
  1782. case 1:
  1783. Assert.Equal (
  1784. $"This the first line.{Environment.NewLine}This the second line.{Environment.NewLine}This i the third line.",
  1785. tv.Text
  1786. );
  1787. Assert.Equal (new Point (6, 2), tv.CursorPosition);
  1788. break;
  1789. case 2:
  1790. Assert.Equal (
  1791. $"This the first line.{Environment.NewLine}This the second line.{Environment.NewLine}This is the third line.",
  1792. tv.Text
  1793. );
  1794. Assert.Equal (new Point (7, 2), tv.CursorPosition);
  1795. break;
  1796. }
  1797. }
  1798. Assert.Equal (
  1799. $"This the first line.{Environment.NewLine}This the second line.{Environment.NewLine}This is the third line.",
  1800. tv.Text
  1801. );
  1802. Assert.Equal (3, tv.Lines);
  1803. Assert.Equal (new Point (7, 2), tv.CursorPosition);
  1804. for (var i = 0; i < ntimes; i++)
  1805. {
  1806. Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl));
  1807. switch (i)
  1808. {
  1809. case 0:
  1810. Assert.Equal (
  1811. $"This the first line.{Environment.NewLine}This the second line.{Environment.NewLine}This is the third line.",
  1812. tv.Text
  1813. );
  1814. Assert.Equal (new Point (5, 0), tv.CursorPosition);
  1815. break;
  1816. case 1:
  1817. Assert.Equal (
  1818. $"This i the first line.{Environment.NewLine}This the second line.{Environment.NewLine}This is the third line.",
  1819. tv.Text
  1820. );
  1821. Assert.Equal (new Point (6, 0), tv.CursorPosition);
  1822. break;
  1823. case 2:
  1824. Assert.Equal (
  1825. $"This is the first line.{Environment.NewLine}This the second line.{Environment.NewLine}This is the third line.",
  1826. tv.Text
  1827. );
  1828. Assert.Equal (new Point (7, 0), tv.CursorPosition);
  1829. break;
  1830. }
  1831. }
  1832. Assert.Equal (
  1833. $"This is the first line.{Environment.NewLine}This the second line.{Environment.NewLine}This is the third line.",
  1834. tv.Text
  1835. );
  1836. Assert.Equal (3, tv.Lines);
  1837. Assert.Equal (new Point (7, 0), tv.CursorPosition);
  1838. for (var i = 0; i < ntimes; i++)
  1839. {
  1840. Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl));
  1841. switch (i)
  1842. {
  1843. case 0:
  1844. Assert.Equal (
  1845. $"This is the first line.{Environment.NewLine}This the second line.{Environment.NewLine}This is the third line.",
  1846. tv.Text
  1847. );
  1848. Assert.Equal (new Point (5, 1), tv.CursorPosition);
  1849. break;
  1850. case 1:
  1851. Assert.Equal (
  1852. $"This is the first line.{Environment.NewLine}This i the second line.{Environment.NewLine}This is the third line.",
  1853. tv.Text
  1854. );
  1855. Assert.Equal (new Point (6, 1), tv.CursorPosition);
  1856. break;
  1857. case 2:
  1858. Assert.Equal (
  1859. $"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.",
  1860. tv.Text
  1861. );
  1862. Assert.Equal (new Point (7, 1), tv.CursorPosition);
  1863. break;
  1864. }
  1865. }
  1866. Assert.Equal (
  1867. $"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.",
  1868. tv.Text
  1869. );
  1870. Assert.Equal (3, tv.Lines);
  1871. Assert.Equal (new Point (7, 1), tv.CursorPosition);
  1872. for (var i = 0; i < ntimes; i++)
  1873. {
  1874. Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl));
  1875. }
  1876. Assert.Equal (
  1877. $"This is the first line.{Environment.NewLine}This the second line.{Environment.NewLine}This is the third line.",
  1878. tv.Text
  1879. );
  1880. Assert.Equal (3, tv.Lines);
  1881. Assert.Equal (new Point (4, 1), tv.CursorPosition);
  1882. for (var i = 0; i < ntimes; i++)
  1883. {
  1884. Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl));
  1885. }
  1886. Assert.Equal (
  1887. $"This the first line.{Environment.NewLine}This the second line.{Environment.NewLine}This is the third line.",
  1888. tv.Text
  1889. );
  1890. Assert.Equal (3, tv.Lines);
  1891. Assert.Equal (new Point (4, 0), tv.CursorPosition);
  1892. for (var i = 0; i < ntimes; i++)
  1893. {
  1894. Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl));
  1895. }
  1896. Assert.Equal (
  1897. $"This the first line.{Environment.NewLine}This the second line.{Environment.NewLine}This the third line.",
  1898. tv.Text
  1899. );
  1900. Assert.Equal (3, tv.Lines);
  1901. Assert.Equal (new Point (4, 2), tv.CursorPosition);
  1902. top.Dispose ();
  1903. }
  1904. [Fact]
  1905. [AutoInitShutdown]
  1906. public void HistoryText_Undo_Redo_Multi_Line_DeleteCharRight ()
  1907. {
  1908. var text = "This is the first line.\nThis is the second line.\nThis is the third line.";
  1909. var tv = new TextView { Width = 10, Height = 2, Text = text };
  1910. Toplevel top = new ();
  1911. top.Add (tv);
  1912. Application.Begin (top);
  1913. Assert.Equal (
  1914. $"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.",
  1915. tv.Text
  1916. );
  1917. Assert.Equal (3, tv.Lines);
  1918. Assert.Equal (Point.Empty, tv.CursorPosition);
  1919. var ntimes = 3;
  1920. tv.CursorPosition = new Point (7, 1);
  1921. for (var i = 0; i < ntimes; i++)
  1922. {
  1923. tv.DeleteCharRight ();
  1924. }
  1925. Assert.Equal (
  1926. $"This is the first line.{Environment.NewLine}This ise second line.{Environment.NewLine}This is the third line.",
  1927. tv.Text
  1928. );
  1929. Assert.Equal (3, tv.Lines);
  1930. Assert.Equal (new Point (7, 1), tv.CursorPosition);
  1931. tv.CursorPosition = new Point (7, 0);
  1932. for (var i = 0; i < ntimes; i++)
  1933. {
  1934. tv.DeleteCharRight ();
  1935. }
  1936. Assert.Equal (
  1937. $"This ise first line.{Environment.NewLine}This ise second line.{Environment.NewLine}This is the third line.",
  1938. tv.Text
  1939. );
  1940. Assert.Equal (3, tv.Lines);
  1941. Assert.Equal (new Point (7, 0), tv.CursorPosition);
  1942. tv.CursorPosition = new Point (7, 2);
  1943. for (var i = 0; i < ntimes; i++)
  1944. {
  1945. tv.DeleteCharRight ();
  1946. }
  1947. Assert.Equal (
  1948. $"This ise first line.{Environment.NewLine}This ise second line.{Environment.NewLine}This ise third line.",
  1949. tv.Text
  1950. );
  1951. Assert.Equal (3, tv.Lines);
  1952. Assert.Equal (new Point (7, 2), tv.CursorPosition);
  1953. for (var i = 0; i < ntimes; i++)
  1954. {
  1955. Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl));
  1956. }
  1957. Assert.Equal (
  1958. $"This ise first line.{Environment.NewLine}This ise second line.{Environment.NewLine}This is the third line.",
  1959. tv.Text
  1960. );
  1961. Assert.Equal (3, tv.Lines);
  1962. Assert.Equal (new Point (7, 2), tv.CursorPosition);
  1963. for (var i = 0; i < ntimes; i++)
  1964. {
  1965. Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl));
  1966. }
  1967. Assert.Equal (
  1968. $"This is the first line.{Environment.NewLine}This ise second line.{Environment.NewLine}This is the third line.",
  1969. tv.Text
  1970. );
  1971. Assert.Equal (3, tv.Lines);
  1972. Assert.Equal (new Point (7, 0), tv.CursorPosition);
  1973. for (var i = 0; i < ntimes; i++)
  1974. {
  1975. Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl));
  1976. }
  1977. Assert.Equal (
  1978. $"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.",
  1979. tv.Text
  1980. );
  1981. Assert.Equal (3, tv.Lines);
  1982. Assert.Equal (new Point (7, 1), tv.CursorPosition);
  1983. for (var i = 0; i < ntimes; i++)
  1984. {
  1985. Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl));
  1986. }
  1987. Assert.Equal (
  1988. $"This is the first line.{Environment.NewLine}This ise second line.{Environment.NewLine}This is the third line.",
  1989. tv.Text
  1990. );
  1991. Assert.Equal (3, tv.Lines);
  1992. Assert.Equal (new Point (7, 1), tv.CursorPosition);
  1993. for (var i = 0; i < ntimes; i++)
  1994. {
  1995. Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl));
  1996. }
  1997. Assert.Equal (
  1998. $"This ise first line.{Environment.NewLine}This ise second line.{Environment.NewLine}This is the third line.",
  1999. tv.Text
  2000. );
  2001. Assert.Equal (3, tv.Lines);
  2002. Assert.Equal (new Point (7, 0), tv.CursorPosition);
  2003. for (var i = 0; i < ntimes; i++)
  2004. {
  2005. Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl));
  2006. }
  2007. Assert.Equal (
  2008. $"This ise first line.{Environment.NewLine}This ise second line.{Environment.NewLine}This ise third line.",
  2009. tv.Text
  2010. );
  2011. Assert.Equal (3, tv.Lines);
  2012. Assert.Equal (new Point (7, 2), tv.CursorPosition);
  2013. top.Dispose ();
  2014. }
  2015. [Fact]
  2016. [AutoInitShutdown]
  2017. public void HistoryText_Undo_Redo_Multi_Line_InsertText ()
  2018. {
  2019. var text = "This is the first line.\nThis is the second line.\nThis is the third line.";
  2020. var tv = new TextView { Width = 10, Height = 2, Text = text };
  2021. Toplevel top = new ();
  2022. top.Add (tv);
  2023. Application.Begin (top);
  2024. Assert.Equal (
  2025. $"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.",
  2026. tv.Text
  2027. );
  2028. Assert.Equal (3, tv.Lines);
  2029. Assert.Equal (Point.Empty, tv.CursorPosition);
  2030. var messy = " messy";
  2031. tv.CursorPosition = new Point (7, 1);
  2032. tv.InsertText (messy);
  2033. Assert.Equal (
  2034. $"This is the first line.{Environment.NewLine}This is messy the second line.{Environment.NewLine}This is the third line.",
  2035. tv.Text
  2036. );
  2037. Assert.Equal (3, tv.Lines);
  2038. Assert.Equal (new Point (13, 1), tv.CursorPosition);
  2039. tv.CursorPosition = new Point (7, 0);
  2040. tv.InsertText (messy);
  2041. Assert.Equal (
  2042. $"This is messy the first line.{Environment.NewLine}This is messy the second line.{Environment.NewLine}This is the third line.",
  2043. tv.Text
  2044. );
  2045. Assert.Equal (3, tv.Lines);
  2046. Assert.Equal (new Point (13, 0), tv.CursorPosition);
  2047. tv.CursorPosition = new Point (7, 2);
  2048. tv.InsertText (messy);
  2049. Assert.Equal (
  2050. $"This is messy the first line.{Environment.NewLine}This is messy the second line.{Environment.NewLine}This is messy the third line.",
  2051. tv.Text
  2052. );
  2053. Assert.Equal (3, tv.Lines);
  2054. Assert.Equal (new Point (13, 2), tv.CursorPosition);
  2055. for (var i = 0; i < messy.Length; i++)
  2056. {
  2057. Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl));
  2058. }
  2059. Assert.Equal (
  2060. $"This is messy the first line.{Environment.NewLine}This is messy the second line.{Environment.NewLine}This is the third line.",
  2061. tv.Text
  2062. );
  2063. Assert.Equal (3, tv.Lines);
  2064. Assert.Equal (new Point (7, 2), tv.CursorPosition);
  2065. for (var i = 0; i < messy.Length; i++)
  2066. {
  2067. Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl));
  2068. }
  2069. Assert.Equal (
  2070. $"This is the first line.{Environment.NewLine}This is messy the second line.{Environment.NewLine}This is the third line.",
  2071. tv.Text
  2072. );
  2073. Assert.Equal (3, tv.Lines);
  2074. Assert.Equal (new Point (7, 0), tv.CursorPosition);
  2075. for (var i = 0; i < messy.Length; i++)
  2076. {
  2077. Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl));
  2078. }
  2079. Assert.Equal (
  2080. $"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.",
  2081. tv.Text
  2082. );
  2083. Assert.Equal (3, tv.Lines);
  2084. Assert.Equal (new Point (7, 1), tv.CursorPosition);
  2085. for (var i = 0; i < messy.Length; i++)
  2086. {
  2087. Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl));
  2088. }
  2089. Assert.Equal (
  2090. $"This is the first line.{Environment.NewLine}This is messy the second line.{Environment.NewLine}This is the third line.",
  2091. tv.Text
  2092. );
  2093. Assert.Equal (3, tv.Lines);
  2094. Assert.Equal (new Point (13, 1), tv.CursorPosition);
  2095. for (var i = 0; i < messy.Length; i++)
  2096. {
  2097. Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl));
  2098. }
  2099. Assert.Equal (
  2100. $"This is messy the first line.{Environment.NewLine}This is messy the second line.{Environment.NewLine}This is the third line.",
  2101. tv.Text
  2102. );
  2103. Assert.Equal (3, tv.Lines);
  2104. Assert.Equal (new Point (13, 0), tv.CursorPosition);
  2105. for (var i = 0; i < messy.Length; i++)
  2106. {
  2107. Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl));
  2108. }
  2109. Assert.Equal (
  2110. $"This is messy the first line.{Environment.NewLine}This is messy the second line.{Environment.NewLine}This is messy the third line.",
  2111. tv.Text
  2112. );
  2113. Assert.Equal (3, tv.Lines);
  2114. Assert.Equal (new Point (13, 2), tv.CursorPosition);
  2115. top.Dispose ();
  2116. }
  2117. [Fact]
  2118. public void HistoryText_Undo_Redo_Multi_Line_Selected_All_Return_And_InsertText ()
  2119. {
  2120. var text = "This is the first line.\nThis is the second line.\nThis is the third line.";
  2121. var tv = new TextView { Text = text };
  2122. Assert.True (tv.NewKeyDownEvent (Key.End.WithCtrl.WithShift));
  2123. Assert.Equal (
  2124. $"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.",
  2125. tv.Text
  2126. );
  2127. Assert.Equal (3, tv.Lines);
  2128. Assert.Equal (new Point (23, 2), tv.CursorPosition);
  2129. Assert.True (tv.NewKeyDownEvent (Key.Enter));
  2130. Assert.Equal ($"{Environment.NewLine}", tv.Text);
  2131. Assert.Equal (2, tv.Lines);
  2132. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  2133. Assert.True (tv.NewKeyDownEvent (Key.A));
  2134. Assert.Equal ($"{Environment.NewLine}a", tv.Text);
  2135. Assert.Equal (2, tv.Lines);
  2136. Assert.Equal (new Point (1, 1), tv.CursorPosition);
  2137. // Undo
  2138. Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl));
  2139. Assert.Equal ($"{Environment.NewLine}", tv.Text);
  2140. Assert.Equal (2, tv.Lines);
  2141. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  2142. Assert.True (tv.IsDirty);
  2143. Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl));
  2144. Assert.Equal (
  2145. $"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.",
  2146. tv.Text
  2147. );
  2148. Assert.Equal (3, tv.Lines);
  2149. Assert.Equal (new Point (23, 2), tv.CursorPosition);
  2150. Assert.False (tv.IsDirty);
  2151. // Redo
  2152. Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl));
  2153. Assert.Equal ($"{Environment.NewLine}", tv.Text);
  2154. Assert.Equal (2, tv.Lines);
  2155. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  2156. Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl));
  2157. Assert.Equal ($"{Environment.NewLine}a", tv.Text);
  2158. Assert.Equal (2, tv.Lines);
  2159. Assert.Equal (new Point (1, 1), tv.CursorPosition);
  2160. // Undo
  2161. Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl));
  2162. Assert.Equal ($"{Environment.NewLine}", tv.Text);
  2163. Assert.Equal (2, tv.Lines);
  2164. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  2165. Assert.True (tv.IsDirty);
  2166. Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl));
  2167. Assert.Equal (
  2168. $"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.",
  2169. tv.Text
  2170. );
  2171. Assert.Equal (3, tv.Lines);
  2172. Assert.Equal (new Point (23, 2), tv.CursorPosition);
  2173. Assert.False (tv.IsDirty);
  2174. // Redo
  2175. Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl));
  2176. Assert.Equal ($"{Environment.NewLine}", tv.Text);
  2177. Assert.Equal (2, tv.Lines);
  2178. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  2179. Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl));
  2180. Assert.Equal ($"{Environment.NewLine}a", tv.Text);
  2181. Assert.Equal (2, tv.Lines);
  2182. Assert.Equal (new Point (1, 1), tv.CursorPosition);
  2183. }
  2184. [Fact]
  2185. [AutoInitShutdown]
  2186. public void HistoryText_Undo_Redo_Multi_Line_Selected_Copy_Simple_Paste_Starting_On_Letter ()
  2187. {
  2188. var text = "This is the first line.\nThis is the second line.\nThis is the third line.";
  2189. var tv = new TextView { Text = text };
  2190. tv.SelectionStartColumn = 12;
  2191. tv.CursorPosition = new Point (18, 1);
  2192. Assert.True (tv.NewKeyDownEvent (Key.C.WithCtrl));
  2193. Assert.Equal (
  2194. $"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.",
  2195. tv.Text
  2196. );
  2197. Assert.Equal ($"first line.{Environment.NewLine}This is the second", tv.SelectedText);
  2198. Assert.Equal (3, tv.Lines);
  2199. Assert.Equal (new Point (18, 1), tv.CursorPosition);
  2200. tv.IsSelecting = false;
  2201. tv.CursorPosition = new Point (17, 1);
  2202. Assert.True (tv.NewKeyDownEvent (Key.Y.WithCtrl));
  2203. Assert.Equal (
  2204. $"This is the first line.{Environment.NewLine}This is the seconfirst line.{Environment.NewLine}This is the secondd line.{Environment.NewLine}This is the third line.",
  2205. tv.Text
  2206. );
  2207. Assert.Equal (4, tv.Lines);
  2208. Assert.Equal (new Point (18, 2), tv.CursorPosition);
  2209. // Undo
  2210. Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl));
  2211. Assert.Equal (
  2212. $"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.",
  2213. tv.Text
  2214. );
  2215. Assert.Equal (3, tv.Lines);
  2216. Assert.Equal (new Point (17, 1), tv.CursorPosition);
  2217. // Redo
  2218. Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl));
  2219. Assert.Equal (
  2220. $"This is the first line.{Environment.NewLine}This is the seconfirst line.{Environment.NewLine}This is the secondd line.{Environment.NewLine}This is the third line.",
  2221. tv.Text
  2222. );
  2223. Assert.Equal (4, tv.Lines);
  2224. Assert.Equal (new Point (18, 2), tv.CursorPosition);
  2225. }
  2226. [Fact]
  2227. [AutoInitShutdown (useFakeClipboard: true)]
  2228. public void HistoryText_Undo_Redo_Multi_Line_Selected_Copy_Simple_Paste_Starting_On_Space ()
  2229. {
  2230. var text = "This is the first line.\nThis is the second line.\nThis is the third line.";
  2231. var tv = new TextView { Text = text };
  2232. tv.SelectionStartColumn = 12;
  2233. tv.CursorPosition = new Point (18, 1);
  2234. Assert.True (tv.NewKeyDownEvent (Key.C.WithCtrl));
  2235. Assert.Equal (
  2236. $"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.",
  2237. tv.Text
  2238. );
  2239. Assert.Equal ($"first line.{Environment.NewLine}This is the second", tv.SelectedText);
  2240. Assert.Equal (3, tv.Lines);
  2241. Assert.Equal (new Point (18, 1), tv.CursorPosition);
  2242. tv.IsSelecting = false;
  2243. Assert.True (tv.NewKeyDownEvent (Key.Y.WithCtrl));
  2244. Assert.Equal (
  2245. $"This is the first line.{Environment.NewLine}This is the secondfirst line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.",
  2246. tv.Text
  2247. );
  2248. Assert.Equal (4, tv.Lines);
  2249. Assert.Equal (new Point (18, 2), tv.CursorPosition);
  2250. // Undo
  2251. Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl));
  2252. Assert.Equal (
  2253. $"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.",
  2254. tv.Text
  2255. );
  2256. Assert.Equal (3, tv.Lines);
  2257. Assert.Equal (new Point (18, 1), tv.CursorPosition);
  2258. // Redo
  2259. Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl));
  2260. Assert.Equal (
  2261. $"This is the first line.{Environment.NewLine}This is the secondfirst line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.",
  2262. tv.Text
  2263. );
  2264. Assert.Equal (4, tv.Lines);
  2265. Assert.Equal (new Point (18, 2), tv.CursorPosition);
  2266. }
  2267. [Fact]
  2268. public void HistoryText_Undo_Redo_Multi_Line_Selected_DeleteCharLeft_All ()
  2269. {
  2270. var text = "This is the first line.\nThis is the second line.\nThis is the third line.";
  2271. var tv = new TextView { Text = text };
  2272. Assert.Equal (
  2273. $"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.",
  2274. tv.Text
  2275. );
  2276. Assert.Equal (3, tv.Lines);
  2277. Assert.Equal (Point.Empty, tv.CursorPosition);
  2278. Assert.False (tv.IsDirty);
  2279. Assert.False (tv.HasHistoryChanges);
  2280. Assert.True (tv.NewKeyDownEvent (Key.End.WithCtrl.WithShift));
  2281. Assert.Equal (
  2282. $"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.",
  2283. tv.Text
  2284. );
  2285. Assert.Equal (
  2286. $"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.",
  2287. tv.SelectedText
  2288. );
  2289. Assert.Equal (3, tv.Lines);
  2290. Assert.Equal (new Point (23, 2), tv.CursorPosition);
  2291. Assert.Equal (70 + Environment.NewLine.Length * 2, tv.SelectedLength);
  2292. Assert.False (tv.IsDirty);
  2293. Assert.False (tv.HasHistoryChanges);
  2294. Assert.True (tv.NewKeyDownEvent (Key.Backspace));
  2295. Assert.Equal ("", tv.Text);
  2296. Assert.Equal ("", tv.SelectedText);
  2297. Assert.Equal (1, tv.Lines);
  2298. Assert.Equal (Point.Empty, tv.CursorPosition);
  2299. Assert.Equal (0, tv.SelectedLength);
  2300. Assert.True (tv.IsDirty);
  2301. Assert.True (tv.HasHistoryChanges);
  2302. // Undo
  2303. Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl));
  2304. Assert.Equal (
  2305. $"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.",
  2306. tv.Text
  2307. );
  2308. Assert.Equal ("", tv.SelectedText);
  2309. Assert.Equal (3, tv.Lines);
  2310. Assert.Equal (new Point (23, 2), tv.CursorPosition);
  2311. Assert.Equal (0, tv.SelectedLength);
  2312. Assert.False (tv.IsDirty);
  2313. Assert.True (tv.HasHistoryChanges);
  2314. // Redo
  2315. Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl));
  2316. Assert.Equal ("", tv.Text);
  2317. Assert.Equal ("", tv.SelectedText);
  2318. Assert.Equal (1, tv.Lines);
  2319. Assert.Equal (Point.Empty, tv.CursorPosition);
  2320. Assert.Equal (0, tv.SelectedLength);
  2321. Assert.True (tv.IsDirty);
  2322. Assert.True (tv.HasHistoryChanges);
  2323. }
  2324. [Fact]
  2325. public void HistoryText_Undo_Redo_Multi_Line_Selected_DeleteCharRight_All ()
  2326. {
  2327. var text = "This is the first line.\nThis is the second line.\nThis is the third line.";
  2328. var tv = new TextView { Text = text };
  2329. Assert.Equal (
  2330. $"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.",
  2331. tv.Text
  2332. );
  2333. Assert.Equal (3, tv.Lines);
  2334. Assert.Equal (Point.Empty, tv.CursorPosition);
  2335. Assert.False (tv.IsDirty);
  2336. Assert.False (tv.HasHistoryChanges);
  2337. Assert.True (tv.NewKeyDownEvent (Key.End.WithCtrl.WithShift));
  2338. Assert.Equal (
  2339. $"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.",
  2340. tv.Text
  2341. );
  2342. Assert.Equal (
  2343. $"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.",
  2344. tv.SelectedText
  2345. );
  2346. Assert.Equal (3, tv.Lines);
  2347. Assert.Equal (new Point (23, 2), tv.CursorPosition);
  2348. Assert.Equal (70 + Environment.NewLine.Length * 2, tv.SelectedLength);
  2349. Assert.False (tv.IsDirty);
  2350. Assert.False (tv.HasHistoryChanges);
  2351. Assert.True (tv.NewKeyDownEvent (Key.Delete));
  2352. Assert.Equal ("", tv.Text);
  2353. Assert.Equal ("", tv.SelectedText);
  2354. Assert.Equal (1, tv.Lines);
  2355. Assert.Equal (Point.Empty, tv.CursorPosition);
  2356. Assert.Equal (0, tv.SelectedLength);
  2357. Assert.True (tv.IsDirty);
  2358. Assert.True (tv.HasHistoryChanges);
  2359. // Undo
  2360. Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl));
  2361. Assert.Equal (
  2362. $"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.",
  2363. tv.Text
  2364. );
  2365. Assert.Equal ("", tv.SelectedText);
  2366. Assert.Equal (3, tv.Lines);
  2367. Assert.Equal (new Point (23, 2), tv.CursorPosition);
  2368. Assert.Equal (0, tv.SelectedLength);
  2369. Assert.False (tv.IsDirty);
  2370. Assert.True (tv.HasHistoryChanges);
  2371. // Redo
  2372. Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl));
  2373. Assert.Equal ("", tv.Text);
  2374. Assert.Equal ("", tv.SelectedText);
  2375. Assert.Equal (1, tv.Lines);
  2376. Assert.Equal (Point.Empty, tv.CursorPosition);
  2377. Assert.Equal (0, tv.SelectedLength);
  2378. Assert.True (tv.IsDirty);
  2379. Assert.True (tv.HasHistoryChanges);
  2380. }
  2381. [Fact]
  2382. [AutoInitShutdown]
  2383. public void HistoryText_Undo_Redo_Multi_Line_Selected_InsertText ()
  2384. {
  2385. var text =
  2386. $"This is the first line.{Environment.NewLine}This is the second line.\nThis is the third line.";
  2387. var tv = new TextView { Width = 10, Height = 2, Text = text };
  2388. Toplevel top = new ();
  2389. top.Add (tv);
  2390. Application.Begin (top);
  2391. Assert.Equal (
  2392. $"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.",
  2393. tv.Text
  2394. );
  2395. Assert.Equal (3, tv.Lines);
  2396. Assert.Equal (Point.Empty, tv.CursorPosition);
  2397. var messy = " messy";
  2398. tv.CursorPosition = new Point (7, 0);
  2399. tv.SelectionStartColumn = 11;
  2400. tv.SelectionStartRow = 2;
  2401. Assert.Equal (51 + Environment.NewLine.Length * 2, tv.SelectedLength);
  2402. for (var i = 0; i < messy.Length; i++)
  2403. {
  2404. tv.InsertText (messy [i].ToString ());
  2405. switch (i)
  2406. {
  2407. case 0:
  2408. Assert.Equal ("This is third line.", tv.Text);
  2409. Assert.Equal (new Point (8, 0), tv.CursorPosition);
  2410. break;
  2411. case 1:
  2412. Assert.Equal ("This is m third line.", tv.Text);
  2413. Assert.Equal (new Point (9, 0), tv.CursorPosition);
  2414. break;
  2415. case 2:
  2416. Assert.Equal ("This is me third line.", tv.Text);
  2417. Assert.Equal (new Point (10, 0), tv.CursorPosition);
  2418. break;
  2419. case 3:
  2420. Assert.Equal ("This is mes third line.", tv.Text);
  2421. Assert.Equal (new Point (11, 0), tv.CursorPosition);
  2422. break;
  2423. case 4:
  2424. Assert.Equal ("This is mess third line.", tv.Text);
  2425. Assert.Equal (new Point (12, 0), tv.CursorPosition);
  2426. break;
  2427. case 5:
  2428. Assert.Equal ("This is messy third line.", tv.Text);
  2429. Assert.Equal (new Point (13, 0), tv.CursorPosition);
  2430. break;
  2431. }
  2432. }
  2433. Assert.Equal ("This is messy third line.", tv.Text);
  2434. Assert.Equal (1, tv.Lines);
  2435. Assert.Equal (new Point (13, 0), tv.CursorPosition);
  2436. Assert.Equal (11, tv.SelectionStartColumn);
  2437. Assert.Equal (2, tv.SelectionStartRow);
  2438. Assert.Equal (0, tv.SelectedLength);
  2439. for (var i = 0; i < messy.Length; i++)
  2440. {
  2441. Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl));
  2442. switch (i)
  2443. {
  2444. case 0:
  2445. Assert.Equal ("This is mess third line.", tv.Text);
  2446. Assert.Equal (new Point (12, 0), tv.CursorPosition);
  2447. break;
  2448. case 1:
  2449. Assert.Equal ("This is mes third line.", tv.Text);
  2450. Assert.Equal (new Point (11, 0), tv.CursorPosition);
  2451. break;
  2452. case 2:
  2453. Assert.Equal ("This is me third line.", tv.Text);
  2454. Assert.Equal (new Point (10, 0), tv.CursorPosition);
  2455. break;
  2456. case 3:
  2457. Assert.Equal ("This is m third line.", tv.Text);
  2458. Assert.Equal (new Point (9, 0), tv.CursorPosition);
  2459. break;
  2460. case 4:
  2461. Assert.Equal ("This is third line.", tv.Text);
  2462. Assert.Equal (new Point (8, 0), tv.CursorPosition);
  2463. break;
  2464. case 5:
  2465. Assert.Equal (
  2466. $"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.",
  2467. tv.Text
  2468. );
  2469. Assert.Equal (new Point (7, 0), tv.CursorPosition);
  2470. break;
  2471. }
  2472. }
  2473. Assert.Equal (
  2474. $"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.",
  2475. tv.Text
  2476. );
  2477. Assert.Equal (3, tv.Lines);
  2478. Assert.Equal (new Point (7, 0), tv.CursorPosition);
  2479. Assert.Equal (11, tv.SelectionStartColumn);
  2480. Assert.Equal (2, tv.SelectionStartRow);
  2481. Assert.Equal (0, tv.SelectedLength);
  2482. for (var i = 0; i < messy.Length; i++)
  2483. {
  2484. Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl));
  2485. switch (i)
  2486. {
  2487. case 0:
  2488. Assert.Equal ("This is third line.", tv.Text);
  2489. Assert.Equal (new Point (8, 0), tv.CursorPosition);
  2490. break;
  2491. case 1:
  2492. Assert.Equal ("This is m third line.", tv.Text);
  2493. Assert.Equal (new Point (9, 0), tv.CursorPosition);
  2494. break;
  2495. case 2:
  2496. Assert.Equal ("This is me third line.", tv.Text);
  2497. Assert.Equal (new Point (10, 0), tv.CursorPosition);
  2498. break;
  2499. case 3:
  2500. Assert.Equal ("This is mes third line.", tv.Text);
  2501. Assert.Equal (new Point (11, 0), tv.CursorPosition);
  2502. break;
  2503. case 4:
  2504. Assert.Equal ("This is mess third line.", tv.Text);
  2505. Assert.Equal (new Point (12, 0), tv.CursorPosition);
  2506. break;
  2507. case 5:
  2508. Assert.Equal ("This is messy third line.", tv.Text);
  2509. Assert.Equal (new Point (13, 0), tv.CursorPosition);
  2510. break;
  2511. }
  2512. }
  2513. Assert.Equal ("This is messy third line.", tv.Text);
  2514. Assert.Equal (1, tv.Lines);
  2515. Assert.Equal (new Point (13, 0), tv.CursorPosition);
  2516. Assert.Equal (11, tv.SelectionStartColumn);
  2517. Assert.Equal (2, tv.SelectionStartRow);
  2518. Assert.Equal (0, tv.SelectedLength);
  2519. top.Dispose ();
  2520. }
  2521. [Fact]
  2522. [AutoInitShutdown]
  2523. public void HistoryText_Undo_Redo_Multi_Line_Selected_InsertText_Twice_On_Same_Line ()
  2524. {
  2525. var text = "One\nTwo\nThree";
  2526. var tv = new TextView { Width = 10, Height = 2, Text = text };
  2527. Toplevel top = new ();
  2528. top.Add (tv);
  2529. Application.Begin (top);
  2530. Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}Three", tv.Text);
  2531. Assert.Equal (3, tv.Lines);
  2532. Assert.Equal (Point.Empty, tv.CursorPosition);
  2533. Assert.False (tv.IsDirty);
  2534. tv.SelectionStartColumn = 0;
  2535. tv.SelectionStartRow = 0;
  2536. tv.CursorPosition = new Point (0, 1);
  2537. Assert.Equal (3 + Environment.NewLine.Length, tv.SelectedLength);
  2538. Assert.True (tv.NewKeyDownEvent (Key.D1));
  2539. Assert.Equal ($"1Two{Environment.NewLine}Three", tv.Text);
  2540. Assert.Equal (new Point (1, 0), tv.CursorPosition);
  2541. Assert.Equal (0, tv.SelectedLength);
  2542. Assert.True (tv.IsDirty);
  2543. tv.SelectionStartColumn = 1;
  2544. tv.SelectionStartRow = 0;
  2545. tv.CursorPosition = new Point (1, 1);
  2546. Assert.Equal (4 + Environment.NewLine.Length, tv.SelectedLength);
  2547. Assert.True (tv.NewKeyDownEvent (Key.D2));
  2548. Assert.Equal ("12hree", tv.Text);
  2549. Assert.Equal (new Point (2, 0), tv.CursorPosition);
  2550. Assert.Equal (0, tv.SelectedLength);
  2551. Assert.True (tv.IsDirty);
  2552. Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl));
  2553. Assert.Equal ($"1Two{Environment.NewLine}Three", tv.Text);
  2554. Assert.Equal (new Point (1, 1), tv.CursorPosition);
  2555. Assert.Equal (0, tv.SelectedLength);
  2556. Assert.True (tv.IsDirty);
  2557. Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl));
  2558. Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}Three", tv.Text);
  2559. Assert.Equal (3, tv.Lines);
  2560. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  2561. Assert.Equal (0, tv.SelectedLength);
  2562. Assert.False (tv.IsDirty);
  2563. Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl));
  2564. Assert.Equal ($"1Two{Environment.NewLine}Three", tv.Text);
  2565. Assert.Equal (new Point (1, 0), tv.CursorPosition);
  2566. Assert.Equal (0, tv.SelectedLength);
  2567. Assert.True (tv.IsDirty);
  2568. Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl));
  2569. Assert.Equal ("12hree", tv.Text);
  2570. Assert.Equal (new Point (2, 0), tv.CursorPosition);
  2571. Assert.Equal (0, tv.SelectedLength);
  2572. Assert.True (tv.IsDirty);
  2573. top.Dispose ();
  2574. }
  2575. [Fact]
  2576. [AutoInitShutdown]
  2577. public void HistoryText_Undo_Redo_Multi_Line_Selected_InsertText_Twice_On_Same_Line_With_End_Line ()
  2578. {
  2579. var text = "One\nTwo\nThree\n";
  2580. var tv = new TextView { Width = 10, Height = 2, Text = text };
  2581. Toplevel top = new ();
  2582. top.Add (tv);
  2583. Application.Begin (top);
  2584. Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}Three{Environment.NewLine}", tv.Text);
  2585. Assert.Equal (4, tv.Lines);
  2586. Assert.Equal (Point.Empty, tv.CursorPosition);
  2587. Assert.False (tv.IsDirty);
  2588. tv.SelectionStartColumn = 0;
  2589. tv.SelectionStartRow = 0;
  2590. tv.CursorPosition = new Point (0, 1);
  2591. Assert.Equal (3 + Environment.NewLine.Length, tv.SelectedLength);
  2592. Assert.True (tv.NewKeyDownEvent (Key.D1));
  2593. Assert.Equal ($"1Two{Environment.NewLine}Three{Environment.NewLine}", tv.Text);
  2594. Assert.Equal (new Point (1, 0), tv.CursorPosition);
  2595. Assert.Equal (0, tv.SelectedLength);
  2596. Assert.True (tv.IsDirty);
  2597. tv.SelectionStartColumn = 1;
  2598. tv.SelectionStartRow = 0;
  2599. tv.CursorPosition = new Point (1, 1);
  2600. Assert.Equal (4 + Environment.NewLine.Length, tv.SelectedLength);
  2601. Assert.True (tv.NewKeyDownEvent (Key.D2));
  2602. Assert.Equal ($"12hree{Environment.NewLine}", tv.Text);
  2603. Assert.Equal (new Point (2, 0), tv.CursorPosition);
  2604. Assert.Equal (0, tv.SelectedLength);
  2605. Assert.True (tv.IsDirty);
  2606. Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl));
  2607. Assert.Equal ($"1Two{Environment.NewLine}Three{Environment.NewLine}", tv.Text);
  2608. Assert.Equal (new Point (1, 1), tv.CursorPosition);
  2609. Assert.Equal (0, tv.SelectedLength);
  2610. Assert.True (tv.IsDirty);
  2611. Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl));
  2612. Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}Three{Environment.NewLine}", tv.Text);
  2613. Assert.Equal (4, tv.Lines);
  2614. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  2615. Assert.Equal (0, tv.SelectedLength);
  2616. Assert.False (tv.IsDirty);
  2617. Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl));
  2618. Assert.Equal ($"1Two{Environment.NewLine}Three{Environment.NewLine}", tv.Text);
  2619. Assert.Equal (new Point (1, 0), tv.CursorPosition);
  2620. Assert.Equal (0, tv.SelectedLength);
  2621. Assert.True (tv.IsDirty);
  2622. Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl));
  2623. Assert.Equal ($"12hree{Environment.NewLine}", tv.Text);
  2624. Assert.Equal (new Point (2, 0), tv.CursorPosition);
  2625. Assert.Equal (0, tv.SelectedLength);
  2626. Assert.True (tv.IsDirty);
  2627. top.Dispose ();
  2628. }
  2629. [Fact]
  2630. [AutoInitShutdown]
  2631. public void HistoryText_Undo_Redo_Multi_Line_Selected_With_Empty_Text ()
  2632. {
  2633. var tv = new TextView { Width = 10, Height = 2 };
  2634. Toplevel top = new ();
  2635. top.Add (tv);
  2636. Application.Begin (top);
  2637. Assert.Equal ("", tv.Text);
  2638. Assert.Equal (1, tv.Lines);
  2639. Assert.Equal (Point.Empty, tv.CursorPosition);
  2640. Assert.False (tv.IsDirty);
  2641. Assert.True (tv.NewKeyDownEvent (Key.O.WithShift));
  2642. Assert.Equal ("O", tv.Text);
  2643. Assert.Equal (1, tv.Lines);
  2644. Assert.Equal (new Point (1, 0), tv.CursorPosition);
  2645. Assert.True (tv.IsDirty);
  2646. Assert.True (tv.NewKeyDownEvent (Key.N));
  2647. Assert.Equal ("On", tv.Text);
  2648. Assert.Equal (1, tv.Lines);
  2649. Assert.Equal (new Point (2, 0), tv.CursorPosition);
  2650. Assert.True (tv.IsDirty);
  2651. Assert.True (tv.NewKeyDownEvent (Key.E));
  2652. Assert.Equal ("One", tv.Text);
  2653. Assert.Equal (1, tv.Lines);
  2654. Assert.Equal (new Point (3, 0), tv.CursorPosition);
  2655. Assert.True (tv.IsDirty);
  2656. Assert.True (tv.NewKeyDownEvent (Key.Enter));
  2657. Assert.Equal ($"One{Environment.NewLine}", tv.Text);
  2658. Assert.Equal (2, tv.Lines);
  2659. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  2660. Assert.True (tv.IsDirty);
  2661. Assert.True (tv.NewKeyDownEvent (Key.T.WithShift));
  2662. Assert.Equal ($"One{Environment.NewLine}T", tv.Text);
  2663. Assert.Equal (2, tv.Lines);
  2664. Assert.Equal (new Point (1, 1), tv.CursorPosition);
  2665. Assert.True (tv.IsDirty);
  2666. Assert.True (tv.NewKeyDownEvent (Key.W));
  2667. Assert.Equal ($"One{Environment.NewLine}Tw", tv.Text);
  2668. Assert.Equal (2, tv.Lines);
  2669. Assert.Equal (new Point (2, 1), tv.CursorPosition);
  2670. Assert.True (tv.IsDirty);
  2671. Assert.True (tv.NewKeyDownEvent (Key.O));
  2672. Assert.Equal ($"One{Environment.NewLine}Two", tv.Text);
  2673. Assert.Equal (2, tv.Lines);
  2674. Assert.Equal (new Point (3, 1), tv.CursorPosition);
  2675. Assert.True (tv.IsDirty);
  2676. Assert.True (tv.NewKeyDownEvent (Key.Enter));
  2677. Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}", tv.Text);
  2678. Assert.Equal (3, tv.Lines);
  2679. Assert.Equal (new Point (0, 2), tv.CursorPosition);
  2680. Assert.True (tv.IsDirty);
  2681. Assert.True (tv.NewKeyDownEvent (Key.T.WithShift));
  2682. Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}T", tv.Text);
  2683. Assert.Equal (3, tv.Lines);
  2684. Assert.Equal (new Point (1, 2), tv.CursorPosition);
  2685. Assert.True (tv.IsDirty);
  2686. Assert.True (tv.NewKeyDownEvent (Key.H));
  2687. Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}Th", tv.Text);
  2688. Assert.Equal (3, tv.Lines);
  2689. Assert.Equal (new Point (2, 2), tv.CursorPosition);
  2690. Assert.True (tv.IsDirty);
  2691. Assert.True (tv.NewKeyDownEvent (Key.R));
  2692. Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}Thr", tv.Text);
  2693. Assert.Equal (3, tv.Lines);
  2694. Assert.Equal (new Point (3, 2), tv.CursorPosition);
  2695. Assert.True (tv.IsDirty);
  2696. Assert.True (tv.NewKeyDownEvent (Key.E));
  2697. Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}Thre", tv.Text);
  2698. Assert.Equal (3, tv.Lines);
  2699. Assert.Equal (new Point (4, 2), tv.CursorPosition);
  2700. Assert.True (tv.IsDirty);
  2701. Assert.True (tv.NewKeyDownEvent (Key.E));
  2702. Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}Three", tv.Text);
  2703. Assert.Equal (3, tv.Lines);
  2704. Assert.Equal (new Point (5, 2), tv.CursorPosition);
  2705. Assert.True (tv.IsDirty);
  2706. Assert.True (tv.NewKeyDownEvent (Key.Enter));
  2707. Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}Three{Environment.NewLine}", tv.Text);
  2708. Assert.Equal (4, tv.Lines);
  2709. Assert.Equal (new Point (0, 3), tv.CursorPosition);
  2710. Assert.True (tv.IsDirty);
  2711. tv.SelectionStartColumn = 0;
  2712. tv.SelectionStartRow = 0;
  2713. tv.CursorPosition = new Point (0, 1);
  2714. Assert.Equal (3 + Environment.NewLine.Length, tv.SelectedLength);
  2715. Assert.True (tv.NewKeyDownEvent (Key.D1));
  2716. Assert.Equal ($"1Two{Environment.NewLine}Three{Environment.NewLine}", tv.Text);
  2717. Assert.Equal (3, tv.Lines);
  2718. Assert.Equal (new Point (1, 0), tv.CursorPosition);
  2719. Assert.Equal (0, tv.SelectedLength);
  2720. Assert.True (tv.IsDirty);
  2721. tv.SelectionStartColumn = 1;
  2722. tv.SelectionStartRow = 0;
  2723. tv.CursorPosition = new Point (1, 1);
  2724. Assert.Equal (4 + Environment.NewLine.Length, tv.SelectedLength);
  2725. Assert.True (tv.NewKeyDownEvent (Key.D2));
  2726. Assert.Equal ($"12hree{Environment.NewLine}", tv.Text);
  2727. Assert.Equal (2, tv.Lines);
  2728. Assert.Equal (new Point (2, 0), tv.CursorPosition);
  2729. Assert.Equal (0, tv.SelectedLength);
  2730. Assert.True (tv.IsDirty);
  2731. // Undoing
  2732. Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl));
  2733. Assert.Equal ($"1Two{Environment.NewLine}Three{Environment.NewLine}", tv.Text);
  2734. Assert.Equal (3, tv.Lines);
  2735. Assert.Equal (new Point (1, 1), tv.CursorPosition);
  2736. Assert.Equal (0, tv.SelectedLength);
  2737. Assert.True (tv.IsDirty);
  2738. Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl));
  2739. Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}Three{Environment.NewLine}", tv.Text);
  2740. Assert.Equal (4, tv.Lines);
  2741. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  2742. Assert.Equal (0, tv.SelectedLength);
  2743. Assert.True (tv.IsDirty);
  2744. Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl));
  2745. Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}Three", tv.Text);
  2746. Assert.Equal (3, tv.Lines);
  2747. Assert.Equal (new Point (5, 2), tv.CursorPosition);
  2748. Assert.Equal (0, tv.SelectedLength);
  2749. Assert.True (tv.IsDirty);
  2750. Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl));
  2751. Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}Thre", tv.Text);
  2752. Assert.Equal (3, tv.Lines);
  2753. Assert.Equal (new Point (4, 2), tv.CursorPosition);
  2754. Assert.True (tv.IsDirty);
  2755. Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl));
  2756. Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}Thr", tv.Text);
  2757. Assert.Equal (3, tv.Lines);
  2758. Assert.Equal (new Point (3, 2), tv.CursorPosition);
  2759. Assert.Equal (0, tv.SelectedLength);
  2760. Assert.True (tv.IsDirty);
  2761. Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl));
  2762. Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}Th", tv.Text);
  2763. Assert.Equal (3, tv.Lines);
  2764. Assert.Equal (new Point (2, 2), tv.CursorPosition);
  2765. Assert.Equal (0, tv.SelectedLength);
  2766. Assert.True (tv.IsDirty);
  2767. Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl));
  2768. Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}T", tv.Text);
  2769. Assert.Equal (3, tv.Lines);
  2770. Assert.Equal (new Point (1, 2), tv.CursorPosition);
  2771. Assert.Equal (0, tv.SelectedLength);
  2772. Assert.True (tv.IsDirty);
  2773. Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl));
  2774. Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}", tv.Text);
  2775. Assert.Equal (3, tv.Lines);
  2776. Assert.Equal (new Point (0, 2), tv.CursorPosition);
  2777. Assert.Equal (0, tv.SelectedLength);
  2778. Assert.True (tv.IsDirty);
  2779. Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl));
  2780. Assert.Equal ($"One{Environment.NewLine}Two", tv.Text);
  2781. Assert.Equal (2, tv.Lines);
  2782. Assert.Equal (new Point (3, 1), tv.CursorPosition);
  2783. Assert.Equal (0, tv.SelectedLength);
  2784. Assert.True (tv.IsDirty);
  2785. Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl));
  2786. Assert.Equal ($"One{Environment.NewLine}Tw", tv.Text);
  2787. Assert.Equal (2, tv.Lines);
  2788. Assert.Equal (new Point (2, 1), tv.CursorPosition);
  2789. Assert.Equal (0, tv.SelectedLength);
  2790. Assert.True (tv.IsDirty);
  2791. Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl));
  2792. Assert.Equal ($"One{Environment.NewLine}T", tv.Text);
  2793. Assert.Equal (2, tv.Lines);
  2794. Assert.Equal (new Point (1, 1), tv.CursorPosition);
  2795. Assert.Equal (0, tv.SelectedLength);
  2796. Assert.True (tv.IsDirty);
  2797. Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl));
  2798. Assert.Equal ($"One{Environment.NewLine}", tv.Text);
  2799. Assert.Equal (2, tv.Lines);
  2800. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  2801. Assert.Equal (0, tv.SelectedLength);
  2802. Assert.True (tv.IsDirty);
  2803. Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl));
  2804. Assert.Equal ("One", tv.Text);
  2805. Assert.Equal (1, tv.Lines);
  2806. Assert.Equal (new Point (3, 0), tv.CursorPosition);
  2807. Assert.Equal (0, tv.SelectedLength);
  2808. Assert.True (tv.IsDirty);
  2809. Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl));
  2810. Assert.Equal ("On", tv.Text);
  2811. Assert.Equal (1, tv.Lines);
  2812. Assert.Equal (new Point (2, 0), tv.CursorPosition);
  2813. Assert.Equal (0, tv.SelectedLength);
  2814. Assert.True (tv.IsDirty);
  2815. Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl));
  2816. Assert.Equal ("O", tv.Text);
  2817. Assert.Equal (1, tv.Lines);
  2818. Assert.Equal (new Point (1, 0), tv.CursorPosition);
  2819. Assert.Equal (0, tv.SelectedLength);
  2820. Assert.True (tv.IsDirty);
  2821. Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl));
  2822. Assert.Equal ("", tv.Text);
  2823. Assert.Equal (1, tv.Lines);
  2824. Assert.Equal (Point.Empty, tv.CursorPosition);
  2825. Assert.Equal (0, tv.SelectedLength);
  2826. Assert.False (tv.IsDirty);
  2827. Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl));
  2828. Assert.Equal ("", tv.Text);
  2829. Assert.Equal (1, tv.Lines);
  2830. Assert.Equal (Point.Empty, tv.CursorPosition);
  2831. Assert.Equal (0, tv.SelectedLength);
  2832. Assert.False (tv.IsDirty);
  2833. // Redoing
  2834. Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl));
  2835. Assert.Equal ("O", tv.Text);
  2836. Assert.Equal (1, tv.Lines);
  2837. Assert.Equal (new Point (1, 0), tv.CursorPosition);
  2838. Assert.Equal (0, tv.SelectedLength);
  2839. Assert.True (tv.IsDirty);
  2840. Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl));
  2841. Assert.Equal ("On", tv.Text);
  2842. Assert.Equal (1, tv.Lines);
  2843. Assert.Equal (new Point (2, 0), tv.CursorPosition);
  2844. Assert.Equal (0, tv.SelectedLength);
  2845. Assert.True (tv.IsDirty);
  2846. Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl));
  2847. Assert.Equal ("One", tv.Text);
  2848. Assert.Equal (1, tv.Lines);
  2849. Assert.Equal (new Point (3, 0), tv.CursorPosition);
  2850. Assert.Equal (0, tv.SelectedLength);
  2851. Assert.True (tv.IsDirty);
  2852. Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl));
  2853. Assert.Equal ($"One{Environment.NewLine}", tv.Text);
  2854. Assert.Equal (2, tv.Lines);
  2855. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  2856. Assert.Equal (0, tv.SelectedLength);
  2857. Assert.True (tv.IsDirty);
  2858. Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl));
  2859. Assert.Equal ($"One{Environment.NewLine}T", tv.Text);
  2860. Assert.Equal (2, tv.Lines);
  2861. Assert.Equal (new Point (1, 1), tv.CursorPosition);
  2862. Assert.Equal (0, tv.SelectedLength);
  2863. Assert.True (tv.IsDirty);
  2864. Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl));
  2865. Assert.Equal ($"One{Environment.NewLine}Tw", tv.Text);
  2866. Assert.Equal (2, tv.Lines);
  2867. Assert.Equal (new Point (2, 1), tv.CursorPosition);
  2868. Assert.Equal (0, tv.SelectedLength);
  2869. Assert.True (tv.IsDirty);
  2870. Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl));
  2871. Assert.Equal ($"One{Environment.NewLine}Two", tv.Text);
  2872. Assert.Equal (2, tv.Lines);
  2873. Assert.Equal (new Point (3, 1), tv.CursorPosition);
  2874. Assert.Equal (0, tv.SelectedLength);
  2875. Assert.True (tv.IsDirty);
  2876. Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl));
  2877. Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}", tv.Text);
  2878. Assert.Equal (3, tv.Lines);
  2879. Assert.Equal (new Point (0, 2), tv.CursorPosition);
  2880. Assert.Equal (0, tv.SelectedLength);
  2881. Assert.True (tv.IsDirty);
  2882. Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl));
  2883. Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}T", tv.Text);
  2884. Assert.Equal (3, tv.Lines);
  2885. Assert.Equal (new Point (1, 2), tv.CursorPosition);
  2886. Assert.Equal (0, tv.SelectedLength);
  2887. Assert.True (tv.IsDirty);
  2888. Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl));
  2889. Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}Th", tv.Text);
  2890. Assert.Equal (3, tv.Lines);
  2891. Assert.Equal (new Point (2, 2), tv.CursorPosition);
  2892. Assert.Equal (0, tv.SelectedLength);
  2893. Assert.True (tv.IsDirty);
  2894. Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl));
  2895. Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}Thr", tv.Text);
  2896. Assert.Equal (3, tv.Lines);
  2897. Assert.Equal (new Point (3, 2), tv.CursorPosition);
  2898. Assert.Equal (0, tv.SelectedLength);
  2899. Assert.True (tv.IsDirty);
  2900. Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl));
  2901. Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}Thre", tv.Text);
  2902. Assert.Equal (3, tv.Lines);
  2903. Assert.Equal (new Point (4, 2), tv.CursorPosition);
  2904. Assert.Equal (0, tv.SelectedLength);
  2905. Assert.True (tv.IsDirty);
  2906. Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl));
  2907. Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}Three", tv.Text);
  2908. Assert.Equal (3, tv.Lines);
  2909. Assert.Equal (new Point (5, 2), tv.CursorPosition);
  2910. Assert.Equal (0, tv.SelectedLength);
  2911. Assert.True (tv.IsDirty);
  2912. Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl));
  2913. Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}Three{Environment.NewLine}", tv.Text);
  2914. Assert.Equal (4, tv.Lines);
  2915. Assert.Equal (new Point (0, 3), tv.CursorPosition);
  2916. Assert.Equal (0, tv.SelectedLength);
  2917. Assert.True (tv.IsDirty);
  2918. Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl));
  2919. Assert.Equal ($"1Two{Environment.NewLine}Three{Environment.NewLine}", tv.Text);
  2920. Assert.Equal (3, tv.Lines);
  2921. Assert.Equal (new Point (1, 0), tv.CursorPosition);
  2922. Assert.Equal (0, tv.SelectedLength);
  2923. Assert.True (tv.IsDirty);
  2924. Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl));
  2925. Assert.Equal ($"12hree{Environment.NewLine}", tv.Text);
  2926. Assert.Equal (2, tv.Lines);
  2927. Assert.Equal (new Point (2, 0), tv.CursorPosition);
  2928. Assert.Equal (0, tv.SelectedLength);
  2929. Assert.True (tv.IsDirty);
  2930. top.Dispose ();
  2931. }
  2932. [Fact]
  2933. [AutoInitShutdown]
  2934. public void HistoryText_Undo_Redo_Multi_Line_With_Empty_Text ()
  2935. {
  2936. var tv = new TextView { Width = 10, Height = 2 };
  2937. Toplevel top = new ();
  2938. top.Add (tv);
  2939. Application.Begin (top);
  2940. Assert.Equal ("", tv.Text);
  2941. Assert.Equal (1, tv.Lines);
  2942. Assert.Equal (Point.Empty, tv.CursorPosition);
  2943. Assert.False (tv.IsDirty);
  2944. Assert.True (tv.NewKeyDownEvent (Key.O.WithShift));
  2945. Assert.Equal ("O", tv.Text);
  2946. Assert.Equal (1, tv.Lines);
  2947. Assert.Equal (new Point (1, 0), tv.CursorPosition);
  2948. Assert.True (tv.IsDirty);
  2949. Assert.True (tv.NewKeyDownEvent (Key.N));
  2950. Assert.Equal ("On", tv.Text);
  2951. Assert.Equal (1, tv.Lines);
  2952. Assert.Equal (new Point (2, 0), tv.CursorPosition);
  2953. Assert.True (tv.IsDirty);
  2954. Assert.True (tv.NewKeyDownEvent (Key.E));
  2955. Assert.Equal ("One", tv.Text);
  2956. Assert.Equal (1, tv.Lines);
  2957. Assert.Equal (new Point (3, 0), tv.CursorPosition);
  2958. Assert.True (tv.IsDirty);
  2959. Assert.True (tv.NewKeyDownEvent (Key.Enter));
  2960. Assert.Equal ($"One{Environment.NewLine}", tv.Text);
  2961. Assert.Equal (2, tv.Lines);
  2962. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  2963. Assert.True (tv.IsDirty);
  2964. Assert.True (tv.NewKeyDownEvent (Key.T.WithShift));
  2965. Assert.Equal ($"One{Environment.NewLine}T", tv.Text);
  2966. Assert.Equal (2, tv.Lines);
  2967. Assert.Equal (new Point (1, 1), tv.CursorPosition);
  2968. Assert.True (tv.IsDirty);
  2969. Assert.True (tv.NewKeyDownEvent (Key.W));
  2970. Assert.Equal ($"One{Environment.NewLine}Tw", tv.Text);
  2971. Assert.Equal (2, tv.Lines);
  2972. Assert.Equal (new Point (2, 1), tv.CursorPosition);
  2973. Assert.True (tv.IsDirty);
  2974. Assert.True (tv.NewKeyDownEvent (Key.O));
  2975. Assert.Equal ($"One{Environment.NewLine}Two", tv.Text);
  2976. Assert.Equal (2, tv.Lines);
  2977. Assert.Equal (new Point (3, 1), tv.CursorPosition);
  2978. Assert.True (tv.IsDirty);
  2979. Assert.True (tv.NewKeyDownEvent (Key.Enter));
  2980. Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}", tv.Text);
  2981. Assert.Equal (3, tv.Lines);
  2982. Assert.Equal (new Point (0, 2), tv.CursorPosition);
  2983. Assert.True (tv.IsDirty);
  2984. Assert.True (tv.NewKeyDownEvent (Key.T.WithShift));
  2985. Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}T", tv.Text);
  2986. Assert.Equal (3, tv.Lines);
  2987. Assert.Equal (new Point (1, 2), tv.CursorPosition);
  2988. Assert.True (tv.IsDirty);
  2989. Assert.True (tv.NewKeyDownEvent (Key.H));
  2990. Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}Th", tv.Text);
  2991. Assert.Equal (3, tv.Lines);
  2992. Assert.Equal (new Point (2, 2), tv.CursorPosition);
  2993. Assert.True (tv.IsDirty);
  2994. Assert.True (tv.NewKeyDownEvent (Key.R));
  2995. Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}Thr", tv.Text);
  2996. Assert.Equal (3, tv.Lines);
  2997. Assert.Equal (new Point (3, 2), tv.CursorPosition);
  2998. Assert.True (tv.IsDirty);
  2999. Assert.True (tv.NewKeyDownEvent (Key.E));
  3000. Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}Thre", tv.Text);
  3001. Assert.Equal (3, tv.Lines);
  3002. Assert.Equal (new Point (4, 2), tv.CursorPosition);
  3003. Assert.True (tv.IsDirty);
  3004. Assert.True (tv.NewKeyDownEvent (Key.E));
  3005. Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}Three", tv.Text);
  3006. Assert.Equal (3, tv.Lines);
  3007. Assert.Equal (new Point (5, 2), tv.CursorPosition);
  3008. Assert.True (tv.IsDirty);
  3009. Assert.True (tv.NewKeyDownEvent (Key.Enter));
  3010. Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}Three{Environment.NewLine}", tv.Text);
  3011. Assert.Equal (4, tv.Lines);
  3012. Assert.Equal (new Point (0, 3), tv.CursorPosition);
  3013. Assert.True (tv.IsDirty);
  3014. // Undoing
  3015. Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl));
  3016. Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}Three", tv.Text);
  3017. Assert.Equal (3, tv.Lines);
  3018. Assert.Equal (new Point (5, 2), tv.CursorPosition);
  3019. Assert.True (tv.IsDirty);
  3020. Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl));
  3021. Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}Thre", tv.Text);
  3022. Assert.Equal (3, tv.Lines);
  3023. Assert.Equal (new Point (4, 2), tv.CursorPosition);
  3024. Assert.True (tv.IsDirty);
  3025. Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl));
  3026. Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}Thr", tv.Text);
  3027. Assert.Equal (3, tv.Lines);
  3028. Assert.Equal (new Point (3, 2), tv.CursorPosition);
  3029. Assert.True (tv.IsDirty);
  3030. Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl));
  3031. Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}Th", tv.Text);
  3032. Assert.Equal (3, tv.Lines);
  3033. Assert.Equal (new Point (2, 2), tv.CursorPosition);
  3034. Assert.True (tv.IsDirty);
  3035. Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl));
  3036. Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}T", tv.Text);
  3037. Assert.Equal (3, tv.Lines);
  3038. Assert.Equal (new Point (1, 2), tv.CursorPosition);
  3039. Assert.True (tv.IsDirty);
  3040. Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl));
  3041. Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}", tv.Text);
  3042. Assert.Equal (3, tv.Lines);
  3043. Assert.Equal (new Point (0, 2), tv.CursorPosition);
  3044. Assert.True (tv.IsDirty);
  3045. Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl));
  3046. Assert.Equal ($"One{Environment.NewLine}Two", tv.Text);
  3047. Assert.Equal (2, tv.Lines);
  3048. Assert.Equal (new Point (3, 1), tv.CursorPosition);
  3049. Assert.True (tv.IsDirty);
  3050. Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl));
  3051. Assert.Equal ($"One{Environment.NewLine}Tw", tv.Text);
  3052. Assert.Equal (2, tv.Lines);
  3053. Assert.Equal (new Point (2, 1), tv.CursorPosition);
  3054. Assert.True (tv.IsDirty);
  3055. Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl));
  3056. Assert.Equal ($"One{Environment.NewLine}T", tv.Text);
  3057. Assert.Equal (2, tv.Lines);
  3058. Assert.Equal (new Point (1, 1), tv.CursorPosition);
  3059. Assert.True (tv.IsDirty);
  3060. Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl));
  3061. Assert.Equal ($"One{Environment.NewLine}", tv.Text);
  3062. Assert.Equal (2, tv.Lines);
  3063. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  3064. Assert.True (tv.IsDirty);
  3065. Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl));
  3066. Assert.Equal ("One", tv.Text);
  3067. Assert.Equal (1, tv.Lines);
  3068. Assert.Equal (new Point (3, 0), tv.CursorPosition);
  3069. Assert.True (tv.IsDirty);
  3070. Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl));
  3071. Assert.Equal ("On", tv.Text);
  3072. Assert.Equal (1, tv.Lines);
  3073. Assert.Equal (new Point (2, 0), tv.CursorPosition);
  3074. Assert.True (tv.IsDirty);
  3075. Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl));
  3076. Assert.Equal ("O", tv.Text);
  3077. Assert.Equal (1, tv.Lines);
  3078. Assert.Equal (new Point (1, 0), tv.CursorPosition);
  3079. Assert.True (tv.IsDirty);
  3080. Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl));
  3081. Assert.Equal ("", tv.Text);
  3082. Assert.Equal (1, tv.Lines);
  3083. Assert.Equal (Point.Empty, tv.CursorPosition);
  3084. Assert.False (tv.IsDirty);
  3085. Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl));
  3086. Assert.Equal ("", tv.Text);
  3087. Assert.Equal (1, tv.Lines);
  3088. Assert.Equal (Point.Empty, tv.CursorPosition);
  3089. Assert.False (tv.IsDirty);
  3090. // Redoing
  3091. Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl));
  3092. Assert.Equal ("O", tv.Text);
  3093. Assert.Equal (1, tv.Lines);
  3094. Assert.Equal (new Point (1, 0), tv.CursorPosition);
  3095. Assert.True (tv.IsDirty);
  3096. Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl));
  3097. Assert.Equal ("On", tv.Text);
  3098. Assert.Equal (1, tv.Lines);
  3099. Assert.Equal (new Point (2, 0), tv.CursorPosition);
  3100. Assert.True (tv.IsDirty);
  3101. Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl));
  3102. Assert.Equal ("One", tv.Text);
  3103. Assert.Equal (1, tv.Lines);
  3104. Assert.Equal (new Point (3, 0), tv.CursorPosition);
  3105. Assert.True (tv.IsDirty);
  3106. Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl));
  3107. Assert.Equal ($"One{Environment.NewLine}", tv.Text);
  3108. Assert.Equal (2, tv.Lines);
  3109. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  3110. Assert.True (tv.IsDirty);
  3111. Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl));
  3112. Assert.Equal ($"One{Environment.NewLine}T", tv.Text);
  3113. Assert.Equal (2, tv.Lines);
  3114. Assert.Equal (new Point (1, 1), tv.CursorPosition);
  3115. Assert.True (tv.IsDirty);
  3116. Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl));
  3117. Assert.Equal ($"One{Environment.NewLine}Tw", tv.Text);
  3118. Assert.Equal (2, tv.Lines);
  3119. Assert.Equal (new Point (2, 1), tv.CursorPosition);
  3120. Assert.True (tv.IsDirty);
  3121. Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl));
  3122. Assert.Equal ($"One{Environment.NewLine}Two", tv.Text);
  3123. Assert.Equal (2, tv.Lines);
  3124. Assert.Equal (new Point (3, 1), tv.CursorPosition);
  3125. Assert.True (tv.IsDirty);
  3126. Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl));
  3127. Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}", tv.Text);
  3128. Assert.Equal (3, tv.Lines);
  3129. Assert.Equal (new Point (0, 2), tv.CursorPosition);
  3130. Assert.True (tv.IsDirty);
  3131. Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl));
  3132. Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}T", tv.Text);
  3133. Assert.Equal (3, tv.Lines);
  3134. Assert.Equal (new Point (1, 2), tv.CursorPosition);
  3135. Assert.True (tv.IsDirty);
  3136. Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl));
  3137. Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}Th", tv.Text);
  3138. Assert.Equal (3, tv.Lines);
  3139. Assert.Equal (new Point (2, 2), tv.CursorPosition);
  3140. Assert.True (tv.IsDirty);
  3141. Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl));
  3142. Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}Thr", tv.Text);
  3143. Assert.Equal (3, tv.Lines);
  3144. Assert.Equal (new Point (3, 2), tv.CursorPosition);
  3145. Assert.True (tv.IsDirty);
  3146. Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl));
  3147. Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}Thre", tv.Text);
  3148. Assert.Equal (3, tv.Lines);
  3149. Assert.Equal (new Point (4, 2), tv.CursorPosition);
  3150. Assert.True (tv.IsDirty);
  3151. Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl));
  3152. Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}Three", tv.Text);
  3153. Assert.Equal (3, tv.Lines);
  3154. Assert.Equal (new Point (5, 2), tv.CursorPosition);
  3155. Assert.True (tv.IsDirty);
  3156. Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl));
  3157. Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}Three{Environment.NewLine}", tv.Text);
  3158. Assert.Equal (4, tv.Lines);
  3159. Assert.Equal (new Point (0, 3), tv.CursorPosition);
  3160. Assert.True (tv.IsDirty);
  3161. Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl));
  3162. Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}Three{Environment.NewLine}", tv.Text);
  3163. Assert.Equal (4, tv.Lines);
  3164. Assert.Equal (new Point (0, 3), tv.CursorPosition);
  3165. Assert.True (tv.IsDirty);
  3166. top.Dispose ();
  3167. }
  3168. [Fact]
  3169. public void HistoryText_Undo_Redo_Multiline_Selected_Tab_BackTab ()
  3170. {
  3171. var text = "First line.\nSecond line.\nThird line.";
  3172. var tv = new TextView { Width = 80, Height = 5, Text = text };
  3173. tv.SelectionStartColumn = 6;
  3174. tv.CursorPosition = new Point (6, 2);
  3175. Assert.True (tv.NewKeyDownEvent (Key.Tab));
  3176. Assert.Equal ("First \tline.", tv.Text);
  3177. Assert.Equal (1, tv.Lines);
  3178. Assert.Equal (new Point (7, 0), tv.CursorPosition);
  3179. Assert.True (tv.NewKeyDownEvent (Key.Tab.WithShift));
  3180. Assert.Equal ("First line.", tv.Text);
  3181. Assert.Equal (1, tv.Lines);
  3182. Assert.Equal (new Point (6, 0), tv.CursorPosition);
  3183. // Undo
  3184. Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl));
  3185. Assert.Equal ("First \tline.", tv.Text);
  3186. Assert.Equal (1, tv.Lines);
  3187. Assert.Equal (new Point (7, 0), tv.CursorPosition);
  3188. Assert.True (tv.IsDirty);
  3189. Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl));
  3190. Assert.Equal ($"First line.{Environment.NewLine}Second line.{Environment.NewLine}Third line.", tv.Text);
  3191. Assert.Equal (3, tv.Lines);
  3192. Assert.Equal (new Point (6, 2), tv.CursorPosition);
  3193. Assert.False (tv.IsDirty);
  3194. // Redo
  3195. Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl));
  3196. Assert.Equal ("First \tline.", tv.Text);
  3197. Assert.Equal (1, tv.Lines);
  3198. Assert.Equal (new Point (7, 0), tv.CursorPosition);
  3199. Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl));
  3200. Assert.Equal ("First line.", tv.Text);
  3201. Assert.Equal (1, tv.Lines);
  3202. Assert.Equal (new Point (6, 0), tv.CursorPosition);
  3203. }
  3204. [Fact]
  3205. public void HistoryText_Undo_Redo_Multiline_Simples_Tab_BackTab ()
  3206. {
  3207. var text = "First line.\nSecond line.\nThird line.";
  3208. var tv = new TextView { Width = 80, Height = 5, Text = text };
  3209. Assert.True (tv.NewKeyDownEvent (Key.Tab));
  3210. Assert.Equal (
  3211. $"\tFirst line.{Environment.NewLine}Second line.{Environment.NewLine}Third line.",
  3212. tv.Text
  3213. );
  3214. Assert.Equal (3, tv.Lines);
  3215. Assert.Equal (new Point (1, 0), tv.CursorPosition);
  3216. Assert.True (tv.NewKeyDownEvent (Key.Tab.WithShift));
  3217. Assert.Equal ($"First line.{Environment.NewLine}Second line.{Environment.NewLine}Third line.", tv.Text);
  3218. Assert.Equal (3, tv.Lines);
  3219. Assert.Equal (Point.Empty, tv.CursorPosition);
  3220. // Undo
  3221. Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl));
  3222. Assert.Equal (
  3223. $"\tFirst line.{Environment.NewLine}Second line.{Environment.NewLine}Third line.",
  3224. tv.Text
  3225. );
  3226. Assert.Equal (3, tv.Lines);
  3227. Assert.Equal (new Point (1, 0), tv.CursorPosition);
  3228. Assert.True (tv.IsDirty);
  3229. Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl));
  3230. Assert.Equal ($"First line.{Environment.NewLine}Second line.{Environment.NewLine}Third line.", tv.Text);
  3231. Assert.Equal (3, tv.Lines);
  3232. Assert.Equal (Point.Empty, tv.CursorPosition);
  3233. Assert.False (tv.IsDirty);
  3234. // Redo
  3235. Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl));
  3236. Assert.Equal (
  3237. $"\tFirst line.{Environment.NewLine}Second line.{Environment.NewLine}Third line.",
  3238. tv.Text
  3239. );
  3240. Assert.Equal (3, tv.Lines);
  3241. Assert.Equal (new Point (1, 0), tv.CursorPosition);
  3242. Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl));
  3243. Assert.Equal ($"First line.{Environment.NewLine}Second line.{Environment.NewLine}Third line.", tv.Text);
  3244. Assert.Equal (3, tv.Lines);
  3245. Assert.Equal (Point.Empty, tv.CursorPosition);
  3246. }
  3247. [Fact]
  3248. [AutoInitShutdown]
  3249. public void HistoryText_Undo_Redo_Setting_Clipboard_Multi_Line_Selected_Paste ()
  3250. {
  3251. var text = "This is the first line.\nThis is the second line.";
  3252. var tv = new TextView { Text = text };
  3253. Clipboard.Contents = "Inserted\nNewLine";
  3254. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.", tv.Text);
  3255. Assert.Equal ("", tv.SelectedText);
  3256. Assert.Equal (2, tv.Lines);
  3257. Assert.Equal (Point.Empty, tv.CursorPosition);
  3258. Assert.True (tv.NewKeyDownEvent (Key.Y.WithCtrl));
  3259. Assert.Equal (
  3260. $"Inserted{Environment.NewLine}NewLineThis is the first line.{Environment.NewLine}This is the second line.",
  3261. tv.Text
  3262. );
  3263. Assert.Equal (3, tv.Lines);
  3264. Assert.Equal (new Point (7, 1), tv.CursorPosition);
  3265. // Undo
  3266. Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl));
  3267. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.", tv.Text);
  3268. Assert.Equal (2, tv.Lines);
  3269. Assert.Equal (Point.Empty, tv.CursorPosition);
  3270. // Redo
  3271. Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl));
  3272. Assert.Equal (
  3273. $"Inserted{Environment.NewLine}NewLineThis is the first line.{Environment.NewLine}This is the second line.",
  3274. tv.Text
  3275. );
  3276. Assert.Equal (3, tv.Lines);
  3277. Assert.Equal (new Point (7, 1), tv.CursorPosition);
  3278. }
  3279. [Fact]
  3280. [AutoInitShutdown (useFakeClipboard: true)]
  3281. public void HistoryText_Undo_Redo_Simple_Copy_Multi_Line_Selected_Paste ()
  3282. {
  3283. var text = "This is the first line.\nThis is the second line.\nThis is the third line.";
  3284. var tv = new TextView { Text = text };
  3285. tv.SelectionStartColumn = 12;
  3286. tv.CursorPosition = new Point (17, 0);
  3287. Assert.True (tv.NewKeyDownEvent (Key.C.WithCtrl));
  3288. Assert.Equal (
  3289. $"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.",
  3290. tv.Text
  3291. );
  3292. Assert.Equal ("first", tv.SelectedText);
  3293. Assert.Equal (3, tv.Lines);
  3294. Assert.Equal (new Point (17, 0), tv.CursorPosition);
  3295. tv.SelectionStartColumn = 12;
  3296. tv.CursorPosition = new Point (11, 1);
  3297. Assert.True (tv.NewKeyDownEvent (Key.Y.WithCtrl));
  3298. Assert.Equal ($"This is the first second line.{Environment.NewLine}This is the third line.", tv.Text);
  3299. Assert.Equal (2, tv.Lines);
  3300. Assert.Equal (new Point (17, 0), tv.CursorPosition);
  3301. // Undo
  3302. Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl));
  3303. Assert.Equal (
  3304. $"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.",
  3305. tv.Text
  3306. );
  3307. Assert.Equal (3, tv.Lines);
  3308. Assert.Equal (new Point (12, 0), tv.CursorPosition);
  3309. // Redo
  3310. Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl));
  3311. Assert.Equal ($"This is the first second line.{Environment.NewLine}This is the third line.", tv.Text);
  3312. Assert.Equal (2, tv.Lines);
  3313. Assert.Equal (new Point (17, 0), tv.CursorPosition);
  3314. }
  3315. [Fact]
  3316. [AutoInitShutdown]
  3317. public void HistoryText_Undo_Redo_Single_Line_DeleteCharLeft ()
  3318. {
  3319. var text = "This is the first line.\nThis is the second line.\nThis is the third line.";
  3320. var tv = new TextView { Width = 10, Height = 2, Text = text };
  3321. Toplevel top = new ();
  3322. top.Add (tv);
  3323. Application.Begin (top);
  3324. Assert.Equal (
  3325. $"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.",
  3326. tv.Text
  3327. );
  3328. Assert.Equal (3, tv.Lines);
  3329. Assert.Equal (Point.Empty, tv.CursorPosition);
  3330. var ntimes = 3;
  3331. tv.CursorPosition = new Point (7, 1);
  3332. for (var i = 0; i < ntimes; i++)
  3333. {
  3334. tv.DeleteCharLeft ();
  3335. }
  3336. Assert.Equal (
  3337. $"This is the first line.{Environment.NewLine}This the second line.{Environment.NewLine}This is the third line.",
  3338. tv.Text
  3339. );
  3340. Assert.Equal (3, tv.Lines);
  3341. Assert.Equal (new Point (4, 1), tv.CursorPosition);
  3342. for (var i = 0; i < ntimes; i++)
  3343. {
  3344. Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl));
  3345. }
  3346. Assert.Equal (
  3347. $"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.",
  3348. tv.Text
  3349. );
  3350. Assert.Equal (3, tv.Lines);
  3351. Assert.Equal (new Point (7, 1), tv.CursorPosition);
  3352. for (var i = 0; i < ntimes; i++)
  3353. {
  3354. Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl));
  3355. }
  3356. Assert.Equal (
  3357. $"This is the first line.{Environment.NewLine}This the second line.{Environment.NewLine}This is the third line.",
  3358. tv.Text
  3359. );
  3360. Assert.Equal (3, tv.Lines);
  3361. Assert.Equal (new Point (4, 1), tv.CursorPosition);
  3362. top.Dispose ();
  3363. }
  3364. [Fact]
  3365. [AutoInitShutdown]
  3366. public void HistoryText_Undo_Redo_Single_Line_DeleteCharRight ()
  3367. {
  3368. var text = "This is the first line.\nThis is the second line.\nThis is the third line.";
  3369. var tv = new TextView { Width = 10, Height = 2, Text = text };
  3370. Toplevel top = new ();
  3371. top.Add (tv);
  3372. Application.Begin (top);
  3373. Assert.Equal (
  3374. $"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.",
  3375. tv.Text
  3376. );
  3377. Assert.Equal (3, tv.Lines);
  3378. Assert.Equal (Point.Empty, tv.CursorPosition);
  3379. var ntimes = 3;
  3380. tv.CursorPosition = new Point (7, 1);
  3381. for (var i = 0; i < ntimes; i++)
  3382. {
  3383. tv.DeleteCharRight ();
  3384. }
  3385. Assert.Equal (
  3386. $"This is the first line.{Environment.NewLine}This ise second line.{Environment.NewLine}This is the third line.",
  3387. tv.Text
  3388. );
  3389. Assert.Equal (3, tv.Lines);
  3390. Assert.Equal (new Point (7, 1), tv.CursorPosition);
  3391. for (var i = 0; i < ntimes; i++)
  3392. {
  3393. Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl));
  3394. }
  3395. Assert.Equal (
  3396. $"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.",
  3397. tv.Text
  3398. );
  3399. Assert.Equal (3, tv.Lines);
  3400. Assert.Equal (new Point (7, 1), tv.CursorPosition);
  3401. for (var i = 0; i < ntimes; i++)
  3402. {
  3403. Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl));
  3404. }
  3405. Assert.Equal (
  3406. $"This is the first line.{Environment.NewLine}This ise second line.{Environment.NewLine}This is the third line.",
  3407. tv.Text
  3408. );
  3409. Assert.Equal (3, tv.Lines);
  3410. Assert.Equal (new Point (7, 1), tv.CursorPosition);
  3411. top.Dispose ();
  3412. }
  3413. [Fact]
  3414. [AutoInitShutdown]
  3415. public void HistoryText_Undo_Redo_Single_Line_InsertText ()
  3416. {
  3417. var text = "This is the first line.\nThis is the second line.\nThis is the third line.";
  3418. var tv = new TextView { Width = 10, Height = 2, Text = text };
  3419. Toplevel top = new ();
  3420. top.Add (tv);
  3421. Application.Begin (top);
  3422. Assert.Equal (
  3423. $"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.",
  3424. tv.Text
  3425. );
  3426. Assert.Equal (3, tv.Lines);
  3427. Assert.Equal (Point.Empty, tv.CursorPosition);
  3428. var messy = " messy";
  3429. tv.CursorPosition = new Point (7, 1);
  3430. tv.InsertText (messy);
  3431. Assert.Equal (
  3432. $"This is the first line.{Environment.NewLine}This is messy the second line.{Environment.NewLine}This is the third line.",
  3433. tv.Text
  3434. );
  3435. Assert.Equal (3, tv.Lines);
  3436. Assert.Equal (new Point (13, 1), tv.CursorPosition);
  3437. for (var i = 0; i < messy.Length; i++)
  3438. {
  3439. Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl));
  3440. }
  3441. Assert.Equal (
  3442. $"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.",
  3443. tv.Text
  3444. );
  3445. Assert.Equal (3, tv.Lines);
  3446. Assert.Equal (new Point (7, 1), tv.CursorPosition);
  3447. for (var i = 0; i < messy.Length; i++)
  3448. {
  3449. Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl));
  3450. }
  3451. Assert.Equal (
  3452. $"This is the first line.{Environment.NewLine}This is messy the second line.{Environment.NewLine}This is the third line.",
  3453. tv.Text
  3454. );
  3455. Assert.Equal (3, tv.Lines);
  3456. Assert.Equal (new Point (13, 1), tv.CursorPosition);
  3457. top.Dispose ();
  3458. }
  3459. [Fact]
  3460. [AutoInitShutdown]
  3461. public void HistoryText_Undo_Redo_Single_Line_Selected_DeleteCharLeft ()
  3462. {
  3463. var text = "This is the first line.\nThis is the second line.\nThis is the third line.";
  3464. var tv = new TextView { Width = 10, Height = 2, Text = text };
  3465. Toplevel top = new ();
  3466. top.Add (tv);
  3467. Application.Begin (top);
  3468. Assert.Equal (
  3469. $"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.",
  3470. tv.Text
  3471. );
  3472. Assert.Equal (3, tv.Lines);
  3473. Assert.Equal (Point.Empty, tv.CursorPosition);
  3474. var ntimes = 3;
  3475. tv.CursorPosition = new Point (7, 1);
  3476. tv.SelectionStartColumn = 11;
  3477. tv.SelectionStartRow = 1;
  3478. Assert.Equal (4, tv.SelectedLength);
  3479. for (var i = 0; i < ntimes; i++)
  3480. {
  3481. tv.DeleteCharLeft ();
  3482. }
  3483. Assert.Equal (
  3484. $"This is the first line.{Environment.NewLine}This second line.{Environment.NewLine}This is the third line.",
  3485. tv.Text
  3486. );
  3487. Assert.Equal (3, tv.Lines);
  3488. Assert.Equal (new Point (5, 1), tv.CursorPosition);
  3489. Assert.Equal (11, tv.SelectionStartColumn);
  3490. Assert.Equal (1, tv.SelectionStartRow);
  3491. Assert.Equal (0, tv.SelectedLength);
  3492. for (var i = 0; i < ntimes; i++)
  3493. {
  3494. Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl));
  3495. }
  3496. Assert.Equal (
  3497. $"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.",
  3498. tv.Text
  3499. );
  3500. Assert.Equal (3, tv.Lines);
  3501. Assert.Equal (new Point (7, 1), tv.CursorPosition);
  3502. Assert.Equal (11, tv.SelectionStartColumn);
  3503. Assert.Equal (1, tv.SelectionStartRow);
  3504. Assert.Equal (0, tv.SelectedLength);
  3505. for (var i = 0; i < ntimes; i++)
  3506. {
  3507. Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl));
  3508. }
  3509. Assert.Equal (
  3510. $"This is the first line.{Environment.NewLine}This second line.{Environment.NewLine}This is the third line.",
  3511. tv.Text
  3512. );
  3513. Assert.Equal (3, tv.Lines);
  3514. Assert.Equal (new Point (5, 1), tv.CursorPosition);
  3515. Assert.Equal (11, tv.SelectionStartColumn);
  3516. Assert.Equal (1, tv.SelectionStartRow);
  3517. Assert.Equal (0, tv.SelectedLength);
  3518. top.Dispose ();
  3519. }
  3520. [Fact]
  3521. [AutoInitShutdown]
  3522. public void HistoryText_Undo_Redo_Single_Line_Selected_DeleteCharRight ()
  3523. {
  3524. var text = "This is the first line.\nThis is the second line.\nThis is the third line.";
  3525. var tv = new TextView { Width = 10, Height = 2, Text = text };
  3526. Toplevel top = new ();
  3527. top.Add (tv);
  3528. Application.Begin (top);
  3529. Assert.Equal (
  3530. $"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.",
  3531. tv.Text
  3532. );
  3533. Assert.Equal (3, tv.Lines);
  3534. Assert.Equal (Point.Empty, tv.CursorPosition);
  3535. var ntimes = 3;
  3536. tv.CursorPosition = new Point (7, 1);
  3537. tv.SelectionStartColumn = 11;
  3538. tv.SelectionStartRow = 1;
  3539. Assert.Equal (4, tv.SelectedLength);
  3540. for (var i = 0; i < ntimes; i++)
  3541. {
  3542. tv.DeleteCharRight ();
  3543. }
  3544. Assert.Equal (
  3545. $"This is the first line.{Environment.NewLine}This isecond line.{Environment.NewLine}This is the third line.",
  3546. tv.Text
  3547. );
  3548. Assert.Equal (3, tv.Lines);
  3549. Assert.Equal (new Point (7, 1), tv.CursorPosition);
  3550. Assert.Equal (11, tv.SelectionStartColumn);
  3551. Assert.Equal (1, tv.SelectionStartRow);
  3552. Assert.Equal (0, tv.SelectedLength);
  3553. for (var i = 0; i < ntimes; i++)
  3554. {
  3555. Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl));
  3556. }
  3557. Assert.Equal (
  3558. $"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.",
  3559. tv.Text
  3560. );
  3561. Assert.Equal (3, tv.Lines);
  3562. Assert.Equal (new Point (7, 1), tv.CursorPosition);
  3563. Assert.Equal (11, tv.SelectionStartColumn);
  3564. Assert.Equal (1, tv.SelectionStartRow);
  3565. Assert.Equal (0, tv.SelectedLength);
  3566. for (var i = 0; i < ntimes; i++)
  3567. {
  3568. Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl));
  3569. }
  3570. Assert.Equal (
  3571. $"This is the first line.{Environment.NewLine}This isecond line.{Environment.NewLine}This is the third line.",
  3572. tv.Text
  3573. );
  3574. Assert.Equal (3, tv.Lines);
  3575. Assert.Equal (new Point (7, 1), tv.CursorPosition);
  3576. Assert.Equal (11, tv.SelectionStartColumn);
  3577. Assert.Equal (1, tv.SelectionStartRow);
  3578. Assert.Equal (0, tv.SelectedLength);
  3579. top.Dispose ();
  3580. }
  3581. [Fact]
  3582. [AutoInitShutdown]
  3583. public void HistoryText_Undo_Redo_Single_Line_Selected_InsertText ()
  3584. {
  3585. var text = "This is the first line.\nThis is the second line.\nThis is the third line.";
  3586. var tv = new TextView { Width = 10, Height = 2, Text = text };
  3587. Toplevel top = new ();
  3588. top.Add (tv);
  3589. Application.Begin (top);
  3590. Assert.Equal (
  3591. $"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.",
  3592. tv.Text
  3593. );
  3594. Assert.Equal (3, tv.Lines);
  3595. Assert.Equal (Point.Empty, tv.CursorPosition);
  3596. var messy = " messy";
  3597. tv.CursorPosition = new Point (7, 1);
  3598. tv.SelectionStartColumn = 11;
  3599. tv.SelectionStartRow = 1;
  3600. Assert.Equal (4, tv.SelectedLength);
  3601. tv.InsertText (messy);
  3602. Assert.Equal (
  3603. $"This is the first line.{Environment.NewLine}This is messy second line.{Environment.NewLine}This is the third line.",
  3604. tv.Text
  3605. );
  3606. Assert.Equal (3, tv.Lines);
  3607. Assert.Equal (new Point (13, 1), tv.CursorPosition);
  3608. Assert.Equal (11, tv.SelectionStartColumn);
  3609. Assert.Equal (1, tv.SelectionStartRow);
  3610. Assert.Equal (0, tv.SelectedLength);
  3611. for (var i = 0; i < messy.Length; i++)
  3612. {
  3613. Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl));
  3614. }
  3615. Assert.Equal (
  3616. $"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.",
  3617. tv.Text
  3618. );
  3619. Assert.Equal (3, tv.Lines);
  3620. Assert.Equal (new Point (7, 1), tv.CursorPosition);
  3621. Assert.Equal (11, tv.SelectionStartColumn);
  3622. Assert.Equal (1, tv.SelectionStartRow);
  3623. Assert.Equal (0, tv.SelectedLength);
  3624. for (var i = 0; i < messy.Length; i++)
  3625. {
  3626. Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl));
  3627. }
  3628. Assert.Equal (
  3629. $"This is the first line.{Environment.NewLine}This is messy second line.{Environment.NewLine}This is the third line.",
  3630. tv.Text
  3631. );
  3632. Assert.Equal (3, tv.Lines);
  3633. Assert.Equal (new Point (13, 1), tv.CursorPosition);
  3634. Assert.Equal (11, tv.SelectionStartColumn);
  3635. Assert.Equal (1, tv.SelectionStartRow);
  3636. Assert.Equal (0, tv.SelectedLength);
  3637. top.Dispose ();
  3638. }
  3639. [Fact]
  3640. public void HistoryText_Undo_Redo_Single_Line_Selected_Return ()
  3641. {
  3642. var text = "This is the first line.\nThis is the second line.\nThis is the third line.";
  3643. var tv = new TextView { Text = text };
  3644. tv.SelectionStartColumn = 12;
  3645. tv.CursorPosition = new Point (17, 0);
  3646. Assert.True (tv.NewKeyDownEvent (Key.Enter));
  3647. Assert.Equal (
  3648. $"This is the {Environment.NewLine} line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.",
  3649. tv.Text
  3650. );
  3651. Assert.Equal (4, tv.Lines);
  3652. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  3653. // Undo
  3654. Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl));
  3655. Assert.Equal (
  3656. $"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.",
  3657. tv.Text
  3658. );
  3659. Assert.Equal (3, tv.Lines);
  3660. Assert.Equal (new Point (17, 0), tv.CursorPosition);
  3661. Assert.False (tv.IsDirty);
  3662. // Redo
  3663. Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl));
  3664. Assert.Equal (
  3665. $"This is the {Environment.NewLine} line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.",
  3666. tv.Text
  3667. );
  3668. Assert.Equal (4, tv.Lines);
  3669. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  3670. // Undo
  3671. Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl));
  3672. Assert.Equal (
  3673. $"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.",
  3674. tv.Text
  3675. );
  3676. Assert.Equal (3, tv.Lines);
  3677. Assert.Equal (new Point (17, 0), tv.CursorPosition);
  3678. Assert.False (tv.IsDirty);
  3679. // Redo
  3680. Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl));
  3681. Assert.Equal (
  3682. $"This is the {Environment.NewLine} line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.",
  3683. tv.Text
  3684. );
  3685. Assert.Equal (4, tv.Lines);
  3686. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  3687. }
  3688. [Fact]
  3689. public void HistoryText_Undo_Redo_Single_Second_Line_Selected_Return ()
  3690. {
  3691. var text = "This is the first line.\nThis is the second line.\nThis is the third line.";
  3692. var tv = new TextView { Text = text };
  3693. tv.SelectionStartColumn = 12;
  3694. tv.SelectionStartRow = 1;
  3695. tv.CursorPosition = new Point (18, 1);
  3696. Assert.True (tv.NewKeyDownEvent (Key.Enter));
  3697. Assert.Equal (
  3698. $"This is the first line.{Environment.NewLine}This is the {Environment.NewLine} line.{Environment.NewLine}This is the third line.",
  3699. tv.Text
  3700. );
  3701. Assert.Equal (4, tv.Lines);
  3702. Assert.Equal (new Point (0, 2), tv.CursorPosition);
  3703. // Undo
  3704. Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl));
  3705. Assert.Equal (
  3706. $"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.",
  3707. tv.Text
  3708. );
  3709. Assert.Equal (3, tv.Lines);
  3710. Assert.Equal (new Point (18, 1), tv.CursorPosition);
  3711. Assert.False (tv.IsDirty);
  3712. // Redo
  3713. Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl));
  3714. Assert.Equal (
  3715. $"This is the first line.{Environment.NewLine}This is the {Environment.NewLine} line.{Environment.NewLine}This is the third line.",
  3716. tv.Text
  3717. );
  3718. Assert.Equal (4, tv.Lines);
  3719. Assert.Equal (new Point (0, 2), tv.CursorPosition);
  3720. // Undo
  3721. Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl));
  3722. Assert.Equal (
  3723. $"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.",
  3724. tv.Text
  3725. );
  3726. Assert.Equal (3, tv.Lines);
  3727. Assert.Equal (new Point (18, 1), tv.CursorPosition);
  3728. Assert.False (tv.IsDirty);
  3729. // Redo
  3730. Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl));
  3731. Assert.Equal (
  3732. $"This is the first line.{Environment.NewLine}This is the {Environment.NewLine} line.{Environment.NewLine}This is the third line.",
  3733. tv.Text
  3734. );
  3735. Assert.Equal (4, tv.Lines);
  3736. Assert.Equal (new Point (0, 2), tv.CursorPosition);
  3737. }
  3738. [Fact]
  3739. public void HistoryText_Undo_Redo_Single_Second_Line_Selected_Return_And_InsertText ()
  3740. {
  3741. var text = "This is the first line.\nThis is the second line.\nThis is the third line.";
  3742. var tv = new TextView { Text = text };
  3743. tv.SelectionStartColumn = 12;
  3744. tv.SelectionStartRow = 1;
  3745. tv.CursorPosition = new Point (18, 1);
  3746. Assert.True (tv.NewKeyDownEvent (Key.Enter));
  3747. Assert.Equal (
  3748. $"This is the first line.{Environment.NewLine}This is the {Environment.NewLine} line.{Environment.NewLine}This is the third line.",
  3749. tv.Text
  3750. );
  3751. Assert.Equal (4, tv.Lines);
  3752. Assert.Equal (new Point (0, 2), tv.CursorPosition);
  3753. Assert.True (tv.NewKeyDownEvent (Key.A));
  3754. Assert.Equal (
  3755. $"This is the first line.{Environment.NewLine}This is the {Environment.NewLine}a line.{Environment.NewLine}This is the third line.",
  3756. tv.Text
  3757. );
  3758. Assert.Equal (4, tv.Lines);
  3759. Assert.Equal (new Point (1, 2), tv.CursorPosition);
  3760. // Undo
  3761. Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl));
  3762. Assert.Equal (
  3763. $"This is the first line.{Environment.NewLine}This is the {Environment.NewLine} line.{Environment.NewLine}This is the third line.",
  3764. tv.Text
  3765. );
  3766. Assert.Equal (4, tv.Lines);
  3767. Assert.Equal (new Point (0, 2), tv.CursorPosition);
  3768. Assert.True (tv.IsDirty);
  3769. Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl));
  3770. Assert.Equal (
  3771. $"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.",
  3772. tv.Text
  3773. );
  3774. Assert.Equal (3, tv.Lines);
  3775. Assert.Equal (new Point (18, 1), tv.CursorPosition);
  3776. Assert.False (tv.IsDirty);
  3777. // Redo
  3778. Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl));
  3779. Assert.Equal (
  3780. $"This is the first line.{Environment.NewLine}This is the {Environment.NewLine} line.{Environment.NewLine}This is the third line.",
  3781. tv.Text
  3782. );
  3783. Assert.Equal (4, tv.Lines);
  3784. Assert.Equal (new Point (0, 2), tv.CursorPosition);
  3785. Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl));
  3786. Assert.Equal (
  3787. $"This is the first line.{Environment.NewLine}This is the {Environment.NewLine}a line.{Environment.NewLine}This is the third line.",
  3788. tv.Text
  3789. );
  3790. Assert.Equal (4, tv.Lines);
  3791. Assert.Equal (new Point (1, 2), tv.CursorPosition);
  3792. // Undo
  3793. Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl));
  3794. Assert.Equal (
  3795. $"This is the first line.{Environment.NewLine}This is the {Environment.NewLine} line.{Environment.NewLine}This is the third line.",
  3796. tv.Text
  3797. );
  3798. Assert.Equal (4, tv.Lines);
  3799. Assert.Equal (new Point (0, 2), tv.CursorPosition);
  3800. Assert.True (tv.IsDirty);
  3801. Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl));
  3802. Assert.Equal (
  3803. $"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.",
  3804. tv.Text
  3805. );
  3806. Assert.Equal (3, tv.Lines);
  3807. Assert.Equal (new Point (18, 1), tv.CursorPosition);
  3808. Assert.False (tv.IsDirty);
  3809. // Redo
  3810. Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl));
  3811. Assert.Equal (
  3812. $"This is the first line.{Environment.NewLine}This is the {Environment.NewLine} line.{Environment.NewLine}This is the third line.",
  3813. tv.Text
  3814. );
  3815. Assert.Equal (4, tv.Lines);
  3816. Assert.Equal (new Point (0, 2), tv.CursorPosition);
  3817. Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl));
  3818. Assert.Equal (
  3819. $"This is the first line.{Environment.NewLine}This is the {Environment.NewLine}a line.{Environment.NewLine}This is the third line.",
  3820. tv.Text
  3821. );
  3822. Assert.Equal (4, tv.Lines);
  3823. Assert.Equal (new Point (1, 2), tv.CursorPosition);
  3824. }
  3825. [Fact]
  3826. public void HistoryText_Undo_Redo_Three_Line_Selected_Return ()
  3827. {
  3828. var text = "This is the first line.\nThis is the second line.\nThis is the third line.";
  3829. var tv = new TextView { Text = text };
  3830. tv.SelectionStartColumn = 12;
  3831. tv.CursorPosition = new Point (17, 2);
  3832. Assert.True (tv.NewKeyDownEvent (Key.Enter));
  3833. Assert.Equal ($"This is the {Environment.NewLine} line.", tv.Text);
  3834. Assert.Equal (2, tv.Lines);
  3835. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  3836. // Undo
  3837. Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl));
  3838. Assert.Equal (
  3839. $"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.",
  3840. tv.Text
  3841. );
  3842. Assert.Equal (3, tv.Lines);
  3843. Assert.Equal (new Point (17, 2), tv.CursorPosition);
  3844. Assert.False (tv.IsDirty);
  3845. // Redo
  3846. Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl));
  3847. Assert.Equal ($"This is the {Environment.NewLine} line.", tv.Text);
  3848. Assert.Equal (2, tv.Lines);
  3849. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  3850. // Undo
  3851. Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl));
  3852. Assert.Equal (
  3853. $"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.",
  3854. tv.Text
  3855. );
  3856. Assert.Equal (3, tv.Lines);
  3857. Assert.Equal (new Point (17, 2), tv.CursorPosition);
  3858. Assert.False (tv.IsDirty);
  3859. // Redo
  3860. Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl));
  3861. Assert.Equal ($"This is the {Environment.NewLine} line.", tv.Text);
  3862. Assert.Equal (2, tv.Lines);
  3863. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  3864. }
  3865. [Fact]
  3866. public void HistoryText_Undo_Redo_Two_Line_Selected_Return ()
  3867. {
  3868. var text = "This is the first line.\nThis is the second line.\nThis is the third line.";
  3869. var tv = new TextView { Text = text };
  3870. tv.SelectionStartColumn = 12;
  3871. tv.CursorPosition = new Point (18, 1);
  3872. Assert.True (tv.NewKeyDownEvent (Key.Enter));
  3873. Assert.Equal (
  3874. $"This is the {Environment.NewLine} line.{Environment.NewLine}This is the third line.",
  3875. tv.Text
  3876. );
  3877. Assert.Equal (3, tv.Lines);
  3878. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  3879. // Undo
  3880. Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl));
  3881. Assert.Equal (
  3882. $"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.",
  3883. tv.Text
  3884. );
  3885. Assert.Equal (3, tv.Lines);
  3886. Assert.Equal (new Point (18, 1), tv.CursorPosition);
  3887. Assert.False (tv.IsDirty);
  3888. // Redo
  3889. Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl));
  3890. Assert.Equal (
  3891. $"This is the {Environment.NewLine} line.{Environment.NewLine}This is the third line.",
  3892. tv.Text
  3893. );
  3894. Assert.Equal (3, tv.Lines);
  3895. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  3896. // Undo
  3897. Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl));
  3898. Assert.Equal (
  3899. $"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.",
  3900. tv.Text
  3901. );
  3902. Assert.Equal (3, tv.Lines);
  3903. Assert.Equal (new Point (18, 1), tv.CursorPosition);
  3904. Assert.False (tv.IsDirty);
  3905. // Redo
  3906. Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl));
  3907. Assert.Equal (
  3908. $"This is the {Environment.NewLine} line.{Environment.NewLine}This is the third line.",
  3909. tv.Text
  3910. );
  3911. Assert.Equal (3, tv.Lines);
  3912. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  3913. }
  3914. [Fact]
  3915. public void HistoryText_Undo_Redo_ApplyCellsAttribute ()
  3916. {
  3917. var text = "This is the first line.\nThis is the second line.\nThis is the third line.";
  3918. var tv = new TextView { Text = text };
  3919. tv.SelectionStartColumn = 12;
  3920. tv.CursorPosition = new Point (18, 1);
  3921. if (Environment.NewLine.Length == 2)
  3922. {
  3923. Assert.Equal (31, tv.SelectedLength);
  3924. }
  3925. else
  3926. {
  3927. Assert.Equal (30, tv.SelectedLength);
  3928. }
  3929. Assert.Equal ($"first line.{Environment.NewLine}This is the second", tv.SelectedText);
  3930. Assert.Equal ($"first line.{Environment.NewLine}This is the second", Cell.ToString (tv.SelectedCellsList));
  3931. Assert.Equal (new Point (18, 1), tv.CursorPosition);
  3932. Assert.False (tv.IsDirty);
  3933. AssertNullAttribute ();
  3934. tv.ApplyCellsAttribute (new (Color.Red, Color.Green));
  3935. AssertRedGreenAttribute ();
  3936. Assert.Equal (0, tv.SelectedLength);
  3937. Assert.Equal ("", tv.SelectedText);
  3938. Assert.Equal ($"first line.{Environment.NewLine}This is the second", Cell.ToString (tv.SelectedCellsList));
  3939. Assert.Equal (new Point (18, 1), tv.CursorPosition);
  3940. Assert.True (tv.IsDirty);
  3941. // Undo
  3942. Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl));
  3943. AssertNullAttribute ();
  3944. Assert.Equal (12, tv.SelectionStartColumn);
  3945. Assert.Equal (0, tv.SelectionStartRow);
  3946. Assert.Equal (0, tv.SelectedLength);
  3947. Assert.Equal ("", tv.SelectedText);
  3948. Assert.Empty (tv.SelectedCellsList);
  3949. Assert.Equal (new Point (12, 0), tv.CursorPosition);
  3950. Assert.False (tv.IsDirty);
  3951. // Redo
  3952. Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl));
  3953. AssertRedGreenAttribute ();
  3954. Assert.Equal (12, tv.SelectionStartColumn);
  3955. Assert.Equal (0, tv.SelectionStartRow);
  3956. Assert.Equal (0, tv.SelectedLength);
  3957. Assert.Equal ("", tv.SelectedText);
  3958. Assert.Empty (tv.SelectedCellsList);
  3959. Assert.Equal (new Point (12, 0), tv.CursorPosition);
  3960. Assert.True (tv.IsDirty);
  3961. void AssertNullAttribute ()
  3962. {
  3963. tv.GetRegion (out List<List<Cell>> region, 0, 12, 1, 18);
  3964. foreach (List<Cell> cells in region)
  3965. {
  3966. foreach (Cell cell in cells)
  3967. {
  3968. Assert.Null (cell.Attribute);
  3969. }
  3970. }
  3971. }
  3972. void AssertRedGreenAttribute ()
  3973. {
  3974. tv.GetRegion (out List<List<Cell>> region, 0, 12, 1, 18);
  3975. foreach (List<Cell> cells in region)
  3976. {
  3977. foreach (Cell cell in cells)
  3978. {
  3979. Assert.Equal ("[Red,Green]", cell.Attribute.ToString ());
  3980. }
  3981. }
  3982. }
  3983. }
  3984. [Fact]
  3985. public void Internal_Tests ()
  3986. {
  3987. var txt = "This is a text.";
  3988. List<Cell> txtRunes = Cell.StringToCells (txt);
  3989. Assert.Equal (txt.Length, txtRunes.Count);
  3990. Assert.Equal ('T', txtRunes [0].Rune.Value);
  3991. Assert.Equal ('h', txtRunes [1].Rune.Value);
  3992. Assert.Equal ('i', txtRunes [2].Rune.Value);
  3993. Assert.Equal ('s', txtRunes [3].Rune.Value);
  3994. Assert.Equal (' ', txtRunes [4].Rune.Value);
  3995. Assert.Equal ('i', txtRunes [5].Rune.Value);
  3996. Assert.Equal ('s', txtRunes [6].Rune.Value);
  3997. Assert.Equal (' ', txtRunes [7].Rune.Value);
  3998. Assert.Equal ('a', txtRunes [8].Rune.Value);
  3999. Assert.Equal (' ', txtRunes [9].Rune.Value);
  4000. Assert.Equal ('t', txtRunes [10].Rune.Value);
  4001. Assert.Equal ('e', txtRunes [11].Rune.Value);
  4002. Assert.Equal ('x', txtRunes [12].Rune.Value);
  4003. Assert.Equal ('t', txtRunes [13].Rune.Value);
  4004. Assert.Equal ('.', txtRunes [^1].Rune.Value);
  4005. var col = 0;
  4006. Assert.True (TextModel.SetCol (ref col, 80, 79));
  4007. Assert.False (TextModel.SetCol (ref col, 80, 80));
  4008. Assert.Equal (79, col);
  4009. var start = 0;
  4010. var x = 8;
  4011. Assert.Equal (8, TextModel.GetColFromX (txtRunes, start, x));
  4012. Assert.Equal ('a', txtRunes [start + x].Rune.Value);
  4013. start = 1;
  4014. x = 7;
  4015. Assert.Equal (7, TextModel.GetColFromX (txtRunes, start, x));
  4016. Assert.Equal ('a', txtRunes [start + x].Rune.Value);
  4017. Assert.Equal ((15, 15), TextModel.DisplaySize (txtRunes));
  4018. Assert.Equal ((6, 6), TextModel.DisplaySize (txtRunes, 1, 7));
  4019. Assert.Equal (0, TextModel.CalculateLeftColumn (txtRunes, 0, 7, 8));
  4020. Assert.Equal (1, TextModel.CalculateLeftColumn (txtRunes, 0, 8, 8));
  4021. Assert.Equal (2, TextModel.CalculateLeftColumn (txtRunes, 0, 9, 8));
  4022. var tm = new TextModel ();
  4023. tm.AddLine (0, Cell.StringToCells ("This is first line."));
  4024. tm.AddLine (1, Cell.StringToCells ("This is last line."));
  4025. Assert.Equal ((new Point (2, 0), true), tm.FindNextText ("is", out bool gaveFullTurn));
  4026. Assert.False (gaveFullTurn);
  4027. Assert.Equal ((new Point (5, 0), true), tm.FindNextText ("is", out gaveFullTurn));
  4028. Assert.False (gaveFullTurn);
  4029. Assert.Equal ((new Point (2, 1), true), tm.FindNextText ("is", out gaveFullTurn));
  4030. Assert.False (gaveFullTurn);
  4031. Assert.Equal ((new Point (5, 1), true), tm.FindNextText ("is", out gaveFullTurn));
  4032. Assert.False (gaveFullTurn);
  4033. Assert.Equal ((new Point (2, 0), true), tm.FindNextText ("is", out gaveFullTurn));
  4034. Assert.True (gaveFullTurn);
  4035. tm.ResetContinuousFind (Point.Empty);
  4036. Assert.Equal ((new Point (5, 1), true), tm.FindPreviousText ("is", out gaveFullTurn));
  4037. Assert.False (gaveFullTurn);
  4038. Assert.Equal ((new Point (2, 1), true), tm.FindPreviousText ("is", out gaveFullTurn));
  4039. Assert.False (gaveFullTurn);
  4040. Assert.Equal ((new Point (5, 0), true), tm.FindPreviousText ("is", out gaveFullTurn));
  4041. Assert.False (gaveFullTurn);
  4042. Assert.Equal ((new Point (2, 0), true), tm.FindPreviousText ("is", out gaveFullTurn));
  4043. Assert.False (gaveFullTurn);
  4044. Assert.Equal ((new Point (5, 1), true), tm.FindPreviousText ("is", out gaveFullTurn));
  4045. Assert.True (gaveFullTurn);
  4046. Assert.Equal ((new Point (9, 1), true), tm.ReplaceAllText ("is", false, false, "really"));
  4047. Assert.Equal (Cell.StringToCells ("Threally really first line."), tm.GetLine (0));
  4048. Assert.Equal (Cell.StringToCells ("Threally really last line."), tm.GetLine (1));
  4049. tm = new TextModel ();
  4050. tm.AddLine (0, Cell.StringToCells ("This is first line."));
  4051. tm.AddLine (1, Cell.StringToCells ("This is last line."));
  4052. Assert.Equal ((new Point (5, 1), true), tm.ReplaceAllText ("is", false, true, "really"));
  4053. Assert.Equal (Cell.StringToCells ("This really first line."), tm.GetLine (0));
  4054. Assert.Equal (Cell.StringToCells ("This really last line."), tm.GetLine (1));
  4055. }
  4056. [Fact]
  4057. [AutoInitShutdown (useFakeClipboard: true)]
  4058. public void KeyBindings_Command ()
  4059. {
  4060. var text = "This is the first line.\nThis is the second line.\nThis is the third line.";
  4061. var tv = new TextView { Width = 10, Height = 2, Text = text };
  4062. Toplevel top = new ();
  4063. top.Add (tv);
  4064. Application.Begin (top);
  4065. Assert.Equal (
  4066. $"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.",
  4067. tv.Text
  4068. );
  4069. Assert.Equal (3, tv.Lines);
  4070. Assert.Equal (Point.Empty, tv.CursorPosition);
  4071. Assert.False (tv.ReadOnly);
  4072. Assert.True (tv.CanFocus);
  4073. var g = (SingleWordSuggestionGenerator)tv.Autocomplete.SuggestionGenerator;
  4074. tv.CanFocus = false;
  4075. Assert.True (tv.NewKeyDownEvent (Key.CursorLeft));
  4076. tv.CanFocus = true;
  4077. Assert.False (tv.NewKeyDownEvent (Key.CursorLeft));
  4078. Assert.True (tv.NewKeyDownEvent (Key.CursorRight));
  4079. Assert.Equal (new Point (1, 0), tv.CursorPosition);
  4080. Assert.True (tv.NewKeyDownEvent (Key.End.WithCtrl));
  4081. Assert.Equal (2, tv.CurrentRow);
  4082. Assert.Equal (23, tv.CurrentColumn);
  4083. Assert.Equal (tv.CurrentColumn, tv.GetCurrentLine ().Count);
  4084. Assert.Equal (new Point (23, 2), tv.CursorPosition);
  4085. Assert.False (tv.NewKeyDownEvent (Key.CursorRight));
  4086. Assert.NotNull (tv.Autocomplete);
  4087. Assert.Empty (g.AllSuggestions);
  4088. Assert.True (tv.NewKeyDownEvent (Key.F.WithShift));
  4089. tv.Draw ();
  4090. Assert.Equal (
  4091. $"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.F",
  4092. tv.Text
  4093. );
  4094. Assert.Equal (new Point (24, 2), tv.CursorPosition);
  4095. Assert.Empty (tv.Autocomplete.Suggestions);
  4096. Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl));
  4097. tv.Draw ();
  4098. Assert.Equal (
  4099. $"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.",
  4100. tv.Text
  4101. );
  4102. Assert.Equal (new Point (23, 2), tv.CursorPosition);
  4103. Assert.Empty (tv.Autocomplete.Suggestions);
  4104. Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl));
  4105. tv.Draw ();
  4106. Assert.Equal (
  4107. $"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.F",
  4108. tv.Text
  4109. );
  4110. Assert.Equal (new Point (24, 2), tv.CursorPosition);
  4111. Assert.Empty (tv.Autocomplete.Suggestions);
  4112. Assert.True (tv.NewKeyDownEvent (Key.Backspace));
  4113. Assert.Equal (
  4114. $"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.",
  4115. tv.Text
  4116. );
  4117. Assert.Equal (new Point (23, 2), tv.CursorPosition);
  4118. g.AllSuggestions = Regex.Matches (tv.Text, "\\w+")
  4119. .Select (s => s.Value)
  4120. .Distinct ()
  4121. .ToList ();
  4122. Assert.Equal (7, g.AllSuggestions.Count);
  4123. Assert.Equal ("This", g.AllSuggestions [0]);
  4124. Assert.Equal ("is", g.AllSuggestions [1]);
  4125. Assert.Equal ("the", g.AllSuggestions [2]);
  4126. Assert.Equal ("first", g.AllSuggestions [3]);
  4127. Assert.Equal ("line", g.AllSuggestions [4]);
  4128. Assert.Equal ("second", g.AllSuggestions [5]);
  4129. Assert.Equal ("third", g.AllSuggestions [^1]);
  4130. Assert.True (tv.NewKeyDownEvent (Key.F.WithShift));
  4131. tv.Draw ();
  4132. Assert.Equal (
  4133. $"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.F",
  4134. tv.Text
  4135. );
  4136. Assert.Equal (new Point (24, 2), tv.CursorPosition);
  4137. Assert.Single (tv.Autocomplete.Suggestions);
  4138. Assert.Equal ("first", tv.Autocomplete.Suggestions [0].Replacement);
  4139. Assert.True (tv.NewKeyDownEvent (Key.Enter));
  4140. Assert.Equal (
  4141. $"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first",
  4142. tv.Text
  4143. );
  4144. Assert.Equal (new Point (28, 2), tv.CursorPosition);
  4145. Assert.Empty (tv.Autocomplete.Suggestions);
  4146. Assert.False (tv.Autocomplete.Visible);
  4147. g.AllSuggestions = new List<string> ();
  4148. tv.Autocomplete.ClearSuggestions ();
  4149. Assert.Empty (g.AllSuggestions);
  4150. Assert.Empty (tv.Autocomplete.Suggestions);
  4151. Assert.True (tv.NewKeyDownEvent (Key.PageUp));
  4152. Assert.Equal (24, tv.GetCurrentLine ().Count);
  4153. Assert.Equal (new Point (24, 1), tv.CursorPosition);
  4154. Assert.True (tv.NewKeyDownEvent (new Key (Key.PageUp)));
  4155. Assert.Equal (23, tv.GetCurrentLine ().Count);
  4156. Assert.Equal (new Point (23, 0), tv.CursorPosition);
  4157. Assert.True (tv.NewKeyDownEvent (Key.PageDown));
  4158. Assert.Equal (24, tv.GetCurrentLine ().Count);
  4159. Assert.Equal (new Point (23, 1), tv.CursorPosition); // gets the previous length
  4160. Assert.True (tv.NewKeyDownEvent (Key.V.WithCtrl));
  4161. Assert.Equal (28, tv.GetCurrentLine ().Count);
  4162. Assert.Equal (new Point (23, 2), tv.CursorPosition); // gets the previous length
  4163. Assert.Equal (0, tv.SelectedLength);
  4164. Assert.Equal ("", tv.SelectedText);
  4165. Assert.True (tv.NewKeyDownEvent (Key.PageUp.WithShift));
  4166. Assert.Equal (24, tv.GetCurrentLine ().Count);
  4167. Assert.Equal (new Point (23, 1), tv.CursorPosition); // gets the previous length
  4168. Assert.Equal (24 + Environment.NewLine.Length, tv.SelectedLength);
  4169. Assert.Equal ($".{Environment.NewLine}This is the third line.", tv.SelectedText);
  4170. Assert.True (tv.NewKeyDownEvent (Key.PageDown.WithShift));
  4171. Assert.Equal (28, tv.GetCurrentLine ().Count);
  4172. Assert.Equal (new Point (23, 2), tv.CursorPosition); // gets the previous length
  4173. Assert.Equal (0, tv.SelectedLength);
  4174. Assert.Equal ("", tv.SelectedText);
  4175. Assert.True (tv.NewKeyDownEvent (Key.Home.WithCtrl));
  4176. Assert.Equal (Point.Empty, tv.CursorPosition);
  4177. Assert.True (tv.NewKeyDownEvent (Key.N.WithCtrl));
  4178. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  4179. Assert.Equal (0, tv.SelectedLength);
  4180. Assert.Equal ("", tv.SelectedText);
  4181. Assert.True (tv.NewKeyDownEvent (Key.P.WithCtrl));
  4182. Assert.Equal (Point.Empty, tv.CursorPosition);
  4183. Assert.Equal (0, tv.SelectedLength);
  4184. Assert.Equal ("", tv.SelectedText);
  4185. Assert.True (tv.NewKeyDownEvent (Key.CursorDown));
  4186. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  4187. Assert.Equal (0, tv.SelectedLength);
  4188. Assert.Equal ("", tv.SelectedText);
  4189. Assert.True (tv.NewKeyDownEvent (Key.CursorUp));
  4190. Assert.Equal (Point.Empty, tv.CursorPosition);
  4191. Assert.Equal (0, tv.SelectedLength);
  4192. Assert.Equal ("", tv.SelectedText);
  4193. Assert.True (tv.NewKeyDownEvent (Key.CursorDown.WithShift));
  4194. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  4195. Assert.Equal (23 + Environment.NewLine.Length, tv.SelectedLength);
  4196. Assert.Equal ($"This is the first line.{Environment.NewLine}", tv.SelectedText);
  4197. Assert.True (tv.NewKeyDownEvent (Key.CursorUp.WithShift));
  4198. Assert.Equal (Point.Empty, tv.CursorPosition);
  4199. Assert.Equal (0, tv.SelectedLength);
  4200. Assert.Equal ("", tv.SelectedText);
  4201. Assert.True (tv.NewKeyDownEvent (Key.F.WithCtrl));
  4202. Assert.Equal (new Point (1, 0), tv.CursorPosition);
  4203. Assert.Equal (0, tv.SelectedLength);
  4204. Assert.Equal ("", tv.SelectedText);
  4205. Assert.True (tv.NewKeyDownEvent (Key.B.WithCtrl));
  4206. Assert.Equal (Point.Empty, tv.CursorPosition);
  4207. Assert.Equal (0, tv.SelectedLength);
  4208. Assert.Equal ("", tv.SelectedText);
  4209. Assert.True (tv.NewKeyDownEvent (Key.CursorRight));
  4210. Assert.Equal (new Point (1, 0), tv.CursorPosition);
  4211. Assert.Equal (0, tv.SelectedLength);
  4212. Assert.Equal ("", tv.SelectedText);
  4213. Assert.True (tv.NewKeyDownEvent (Key.CursorLeft));
  4214. Assert.Equal (Point.Empty, tv.CursorPosition);
  4215. Assert.Equal (0, tv.SelectedLength);
  4216. Assert.Equal ("", tv.SelectedText);
  4217. Assert.False (tv.IsSelecting);
  4218. Assert.True (tv.NewKeyDownEvent (Key.CursorRight.WithShift));
  4219. Assert.Equal (new Point (1, 0), tv.CursorPosition);
  4220. Assert.Equal (1, tv.SelectedLength);
  4221. Assert.Equal ("T", tv.SelectedText);
  4222. Assert.True (tv.IsSelecting);
  4223. Assert.True (tv.NewKeyDownEvent (Key.CursorLeft.WithShift));
  4224. Assert.Equal (Point.Empty, tv.CursorPosition);
  4225. Assert.Equal (0, tv.SelectedLength);
  4226. Assert.Equal ("", tv.SelectedText);
  4227. Assert.True (tv.IsSelecting);
  4228. Assert.True (tv.NewKeyDownEvent (Key.Delete));
  4229. Assert.Equal (
  4230. $"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first",
  4231. tv.Text
  4232. );
  4233. Assert.Equal (Point.Empty, tv.CursorPosition);
  4234. Assert.Equal (0, tv.SelectedLength);
  4235. Assert.Equal ("", tv.SelectedText);
  4236. Assert.False (tv.IsSelecting);
  4237. Assert.True (tv.NewKeyDownEvent (Key.Delete));
  4238. Assert.Equal (
  4239. $"his is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first",
  4240. tv.Text
  4241. );
  4242. Assert.Equal (Point.Empty, tv.CursorPosition);
  4243. Assert.Equal (0, tv.SelectedLength);
  4244. Assert.Equal ("", tv.SelectedText);
  4245. Assert.False (tv.IsSelecting);
  4246. Assert.True (tv.NewKeyDownEvent (Key.D.WithCtrl));
  4247. Assert.Equal (
  4248. $"is is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first",
  4249. tv.Text
  4250. );
  4251. Assert.Equal (Point.Empty, tv.CursorPosition);
  4252. Assert.True (tv.NewKeyDownEvent (Key.End));
  4253. Assert.Equal (
  4254. $"is is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first",
  4255. tv.Text
  4256. );
  4257. Assert.Equal (new Point (21, 0), tv.CursorPosition);
  4258. Assert.True (tv.NewKeyDownEvent (Key.Backspace));
  4259. Assert.Equal (
  4260. $"is is the first line{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first",
  4261. tv.Text
  4262. );
  4263. Assert.Equal (new Point (20, 0), tv.CursorPosition);
  4264. Assert.True (tv.NewKeyDownEvent (Key.Backspace));
  4265. Assert.Equal (
  4266. $"is is the first lin{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first",
  4267. tv.Text
  4268. );
  4269. Assert.Equal (new Point (19, 0), tv.CursorPosition);
  4270. Assert.True (tv.NewKeyDownEvent (Key.Home));
  4271. Assert.Equal (Point.Empty, tv.CursorPosition);
  4272. Assert.Equal (0, tv.SelectedLength);
  4273. Assert.Equal ("", tv.SelectedText);
  4274. Assert.False (tv.IsSelecting);
  4275. Assert.True (tv.NewKeyDownEvent (Key.End.WithShift));
  4276. Assert.Equal (new Point (19, 0), tv.CursorPosition);
  4277. Assert.Equal (19, tv.SelectedLength);
  4278. Assert.Equal ("is is the first lin", tv.SelectedText);
  4279. Assert.True (tv.IsSelecting);
  4280. Assert.True (tv.NewKeyDownEvent (Key.Home.WithShift));
  4281. Assert.Equal (Point.Empty, tv.CursorPosition);
  4282. Assert.Equal (0, tv.SelectedLength);
  4283. Assert.Equal ("", tv.SelectedText);
  4284. Assert.True (tv.IsSelecting);
  4285. Assert.True (tv.NewKeyDownEvent (Key.E.WithCtrl));
  4286. Assert.Equal (new Point (19, 0), tv.CursorPosition);
  4287. Assert.Equal (0, tv.SelectedLength);
  4288. Assert.Equal ("", tv.SelectedText);
  4289. Assert.False (tv.IsSelecting);
  4290. Assert.True (tv.NewKeyDownEvent (Key.A.WithCtrl));
  4291. Assert.Equal (Point.Empty, tv.CursorPosition);
  4292. Assert.Equal (0, tv.SelectedLength);
  4293. Assert.Equal ("", tv.SelectedText);
  4294. Assert.False (tv.IsSelecting);
  4295. Assert.True (tv.NewKeyDownEvent (Key.K.WithCtrl));
  4296. Assert.Equal (
  4297. $"{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first",
  4298. tv.Text
  4299. );
  4300. Assert.Equal (Point.Empty, tv.CursorPosition);
  4301. Assert.Equal (0, tv.SelectedLength);
  4302. Assert.Equal ("", tv.SelectedText);
  4303. Assert.False (tv.IsSelecting);
  4304. Assert.Equal ("is is the first lin", Clipboard.Contents);
  4305. Assert.True (tv.NewKeyDownEvent (Key.Y.WithCtrl));
  4306. Assert.Equal (
  4307. $"is is the first lin{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first",
  4308. tv.Text
  4309. );
  4310. Assert.Equal (new Point (19, 0), tv.CursorPosition);
  4311. Assert.Equal (0, tv.SelectedLength);
  4312. Assert.Equal ("", tv.SelectedText);
  4313. Assert.False (tv.IsSelecting);
  4314. Assert.Equal ("is is the first lin", Clipboard.Contents);
  4315. tv.CursorPosition = Point.Empty;
  4316. Assert.True (tv.NewKeyDownEvent (Key.Delete.WithCtrl.WithShift));
  4317. Assert.Equal (
  4318. $"{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first",
  4319. tv.Text
  4320. );
  4321. Assert.Equal (Point.Empty, tv.CursorPosition);
  4322. Assert.Equal (0, tv.SelectedLength);
  4323. Assert.Equal ("", tv.SelectedText);
  4324. Assert.False (tv.IsSelecting);
  4325. Assert.Equal ("is is the first lin", Clipboard.Contents);
  4326. Assert.True (tv.NewKeyDownEvent (Key.Y.WithCtrl));
  4327. Assert.Equal (
  4328. $"is is the first lin{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first",
  4329. tv.Text
  4330. );
  4331. Assert.Equal (new Point (19, 0), tv.CursorPosition);
  4332. Assert.Equal (0, tv.SelectedLength);
  4333. Assert.Equal ("", tv.SelectedText);
  4334. Assert.False (tv.IsSelecting);
  4335. Assert.Equal ("is is the first lin", Clipboard.Contents);
  4336. Assert.True (tv.NewKeyDownEvent (Key.Backspace.WithCtrl.WithShift));
  4337. Assert.Equal (
  4338. $"{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first",
  4339. tv.Text
  4340. );
  4341. Assert.Equal (Point.Empty, tv.CursorPosition);
  4342. Assert.Equal (0, tv.SelectedLength);
  4343. Assert.Equal ("", tv.SelectedText);
  4344. Assert.False (tv.IsSelecting);
  4345. tv.ReadOnly = true;
  4346. Assert.True (tv.NewKeyDownEvent (Key.Y.WithCtrl));
  4347. Assert.Equal (
  4348. $"{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first",
  4349. tv.Text
  4350. );
  4351. Assert.Equal (Point.Empty, tv.CursorPosition);
  4352. Assert.Equal (0, tv.SelectedLength);
  4353. Assert.Equal ("", tv.SelectedText);
  4354. Assert.False (tv.IsSelecting);
  4355. tv.ReadOnly = false;
  4356. Assert.True (tv.NewKeyDownEvent (Key.Y.WithCtrl));
  4357. Assert.Equal (
  4358. $"is is the first lin{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first",
  4359. tv.Text
  4360. );
  4361. Assert.Equal (new Point (19, 0), tv.CursorPosition);
  4362. Assert.Equal (0, tv.SelectedLength);
  4363. Assert.Equal ("", tv.SelectedText);
  4364. Assert.False (tv.IsSelecting);
  4365. Assert.Equal (0, tv.SelectionStartColumn);
  4366. Assert.Equal (0, tv.SelectionStartRow);
  4367. Assert.True (tv.NewKeyDownEvent (Key.Space.WithCtrl));
  4368. Assert.Equal (
  4369. $"is is the first lin{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first",
  4370. tv.Text
  4371. );
  4372. Assert.Equal (new Point (19, 0), tv.CursorPosition);
  4373. Assert.Equal (0, tv.SelectedLength);
  4374. Assert.Equal ("", tv.SelectedText);
  4375. Assert.True (tv.IsSelecting);
  4376. Assert.Equal (19, tv.SelectionStartColumn);
  4377. Assert.Equal (0, tv.SelectionStartRow);
  4378. Assert.True (tv.NewKeyDownEvent (Key.Space.WithCtrl));
  4379. Assert.Equal (
  4380. $"is is the first lin{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first",
  4381. tv.Text
  4382. );
  4383. Assert.Equal (new Point (19, 0), tv.CursorPosition);
  4384. Assert.Equal (0, tv.SelectedLength);
  4385. Assert.Equal ("", tv.SelectedText);
  4386. Assert.False (tv.IsSelecting);
  4387. Assert.Equal (19, tv.SelectionStartColumn);
  4388. Assert.Equal (0, tv.SelectionStartRow);
  4389. tv.SelectionStartColumn = 0;
  4390. Assert.True (tv.NewKeyDownEvent (Key.C.WithCtrl));
  4391. Assert.Equal (
  4392. $"is is the first lin{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first",
  4393. tv.Text
  4394. );
  4395. Assert.Equal (new Point (19, 0), tv.CursorPosition);
  4396. Assert.Equal (19, tv.SelectedLength);
  4397. Assert.Equal ("is is the first lin", tv.SelectedText);
  4398. Assert.True (tv.IsSelecting);
  4399. Assert.Equal (0, tv.SelectionStartColumn);
  4400. Assert.Equal (0, tv.SelectionStartRow);
  4401. Assert.True (tv.NewKeyDownEvent (Key.C.WithCtrl));
  4402. Assert.Equal (
  4403. $"is is the first lin{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first",
  4404. tv.Text
  4405. );
  4406. Assert.Equal (new Point (19, 0), tv.CursorPosition);
  4407. Assert.Equal (19, tv.SelectedLength);
  4408. Assert.Equal ("is is the first lin", tv.SelectedText);
  4409. Assert.True (tv.IsSelecting);
  4410. Assert.Equal (0, tv.SelectionStartColumn);
  4411. Assert.Equal (0, tv.SelectionStartRow);
  4412. Assert.True (tv.NewKeyDownEvent (Key.X.WithCtrl));
  4413. Assert.Equal (
  4414. $"{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first",
  4415. tv.Text
  4416. );
  4417. Assert.Equal (Point.Empty, tv.CursorPosition);
  4418. Assert.Equal (0, tv.SelectedLength);
  4419. Assert.Equal ("", tv.SelectedText);
  4420. Assert.False (tv.IsSelecting);
  4421. Assert.Equal (0, tv.SelectionStartColumn);
  4422. Assert.Equal (0, tv.SelectionStartRow);
  4423. Assert.Equal ("is is the first lin", Clipboard.Contents);
  4424. Assert.True (tv.NewKeyDownEvent (Key.W.WithCtrl));
  4425. Assert.Equal (
  4426. $"{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first",
  4427. tv.Text
  4428. );
  4429. Assert.Equal (Point.Empty, tv.CursorPosition);
  4430. Assert.Equal (0, tv.SelectedLength);
  4431. Assert.Equal ("", tv.SelectedText);
  4432. Assert.False (tv.IsSelecting);
  4433. Assert.Equal (0, tv.SelectionStartColumn);
  4434. Assert.Equal (0, tv.SelectionStartRow);
  4435. Assert.Equal ("", Clipboard.Contents);
  4436. Assert.True (tv.NewKeyDownEvent (Key.X.WithCtrl));
  4437. Assert.Equal (
  4438. $"{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first",
  4439. tv.Text
  4440. );
  4441. Assert.Equal (Point.Empty, tv.CursorPosition);
  4442. Assert.Equal (0, tv.SelectedLength);
  4443. Assert.Equal ("", tv.SelectedText);
  4444. Assert.False (tv.IsSelecting);
  4445. Assert.Equal (0, tv.SelectionStartColumn);
  4446. Assert.Equal (0, tv.SelectionStartRow);
  4447. Assert.Equal ("", Clipboard.Contents);
  4448. Assert.True (tv.NewKeyDownEvent (Key.End.WithCtrl));
  4449. Assert.Equal (
  4450. $"{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first",
  4451. tv.Text
  4452. );
  4453. Assert.Equal (new Point (28, 2), tv.CursorPosition);
  4454. Assert.Equal (0, tv.SelectedLength);
  4455. Assert.Equal ("", tv.SelectedText);
  4456. Assert.False (tv.IsSelecting);
  4457. Assert.True (tv.NewKeyDownEvent (Key.CursorLeft.WithCtrl));
  4458. Assert.Equal (
  4459. $"{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first",
  4460. tv.Text
  4461. );
  4462. Assert.Equal (new Point (18, 2), tv.CursorPosition);
  4463. Assert.Equal (0, tv.SelectedLength);
  4464. Assert.Equal ("", tv.SelectedText);
  4465. Assert.False (tv.IsSelecting);
  4466. Assert.True (tv.NewKeyDownEvent (Key.CursorLeft.WithShift.WithCtrl));
  4467. Assert.Equal (
  4468. $"{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first",
  4469. tv.Text
  4470. );
  4471. Assert.Equal (new Point (12, 2), tv.CursorPosition);
  4472. Assert.Equal (6, tv.SelectedLength);
  4473. Assert.Equal ("third ", tv.SelectedText);
  4474. Assert.True (tv.IsSelecting);
  4475. Assert.True (tv.NewKeyDownEvent (Key.CursorLeft.WithCtrl));
  4476. Assert.Equal (
  4477. $"{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first",
  4478. tv.Text
  4479. );
  4480. Assert.Equal (new Point (8, 2), tv.CursorPosition);
  4481. Assert.Equal (0, tv.SelectedLength);
  4482. Assert.Equal ("", tv.SelectedText);
  4483. Assert.False (tv.IsSelecting);
  4484. Assert.True (tv.NewKeyDownEvent (Key.CursorRight.WithCtrl));
  4485. Assert.Equal (
  4486. $"{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first",
  4487. tv.Text
  4488. );
  4489. Assert.Equal (new Point (12, 2), tv.CursorPosition);
  4490. Assert.Equal (0, tv.SelectedLength);
  4491. Assert.Equal ("", tv.SelectedText);
  4492. Assert.False (tv.IsSelecting);
  4493. Assert.True (tv.NewKeyDownEvent (Key.CursorRight.WithShift.WithCtrl));
  4494. Assert.Equal (
  4495. $"{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first",
  4496. tv.Text
  4497. );
  4498. Assert.Equal (new Point (18, 2), tv.CursorPosition);
  4499. Assert.Equal (6, tv.SelectedLength);
  4500. Assert.Equal ("third ", tv.SelectedText);
  4501. Assert.True (tv.IsSelecting);
  4502. Assert.True (tv.NewKeyDownEvent (Key.CursorRight.WithCtrl));
  4503. Assert.Equal (
  4504. $"{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first",
  4505. tv.Text
  4506. );
  4507. Assert.Equal (new Point (22, 2), tv.CursorPosition);
  4508. Assert.Equal (0, tv.SelectedLength);
  4509. Assert.Equal ("", tv.SelectedText);
  4510. Assert.False (tv.IsSelecting);
  4511. Assert.True (tv.NewKeyDownEvent (Key.CursorRight.WithCtrl));
  4512. Assert.Equal (
  4513. $"{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first",
  4514. tv.Text
  4515. );
  4516. Assert.Equal (new Point (23, 2), tv.CursorPosition);
  4517. Assert.Equal (0, tv.SelectedLength);
  4518. Assert.Equal ("", tv.SelectedText);
  4519. Assert.False (tv.IsSelecting);
  4520. Assert.True (tv.NewKeyDownEvent (Key.CursorRight.WithCtrl));
  4521. Assert.Equal (
  4522. $"{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first",
  4523. tv.Text
  4524. );
  4525. Assert.Equal (new Point (28, 2), tv.CursorPosition);
  4526. Assert.Equal (0, tv.SelectedLength);
  4527. Assert.Equal ("", tv.SelectedText);
  4528. Assert.False (tv.IsSelecting);
  4529. Assert.True (tv.NewKeyDownEvent (Key.Home.WithCtrl));
  4530. Assert.Equal (
  4531. $"{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first",
  4532. tv.Text
  4533. );
  4534. Assert.Equal (Point.Empty, tv.CursorPosition);
  4535. Assert.Equal (0, tv.SelectedLength);
  4536. Assert.Equal ("", tv.SelectedText);
  4537. Assert.False (tv.IsSelecting);
  4538. Assert.True (tv.NewKeyDownEvent (Key.Delete.WithCtrl));
  4539. Assert.Equal ($"This is the second line.{Environment.NewLine}This is the third line.first", tv.Text);
  4540. Assert.Equal (Point.Empty, tv.CursorPosition);
  4541. Assert.Equal (0, tv.SelectedLength);
  4542. Assert.Equal ("", tv.SelectedText);
  4543. Assert.False (tv.IsSelecting);
  4544. Assert.True (tv.NewKeyDownEvent (Key.End.WithCtrl));
  4545. Assert.Equal ($"This is the second line.{Environment.NewLine}This is the third line.first", tv.Text);
  4546. Assert.Equal (new Point (28, 1), tv.CursorPosition);
  4547. Assert.Equal (0, tv.SelectedLength);
  4548. Assert.Equal ("", tv.SelectedText);
  4549. Assert.False (tv.IsSelecting);
  4550. Assert.False (tv.IsSelecting);
  4551. Assert.True (tv.NewKeyDownEvent (Key.Backspace.WithCtrl));
  4552. Assert.Equal ($"This is the second line.{Environment.NewLine}This is the third ", tv.Text);
  4553. Assert.Equal (new Point (18, 1), tv.CursorPosition);
  4554. Assert.Equal (0, tv.SelectedLength);
  4555. Assert.Equal ("", tv.SelectedText);
  4556. Assert.False (tv.IsSelecting);
  4557. Assert.True (tv.AllowsReturn);
  4558. tv.AllowsReturn = false;
  4559. Assert.Equal (Point.Empty, tv.CursorPosition);
  4560. Assert.False (tv.IsSelecting);
  4561. Assert.False (tv.NewKeyDownEvent (Key.Enter)); // Accepted event not handled
  4562. Assert.Equal ($"This is the second line.{Environment.NewLine}This is the third ", tv.Text);
  4563. Assert.Equal (Point.Empty, tv.CursorPosition);
  4564. Assert.Equal (0, tv.SelectedLength);
  4565. Assert.Equal ("", tv.SelectedText);
  4566. Assert.False (tv.IsSelecting);
  4567. Assert.False (tv.AllowsReturn);
  4568. tv.AllowsReturn = true;
  4569. Assert.Equal (Point.Empty, tv.CursorPosition);
  4570. Assert.True (tv.NewKeyDownEvent (Key.Enter));
  4571. Assert.Equal (
  4572. $"{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third ",
  4573. tv.Text
  4574. );
  4575. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  4576. Assert.Equal (0, tv.SelectedLength);
  4577. Assert.Equal ("", tv.SelectedText);
  4578. Assert.False (tv.IsSelecting);
  4579. Assert.True (tv.AllowsReturn);
  4580. Assert.True (tv.NewKeyDownEvent (Key.End.WithShift.WithCtrl));
  4581. Assert.Equal (
  4582. $"{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third ",
  4583. tv.Text
  4584. );
  4585. Assert.Equal (new Point (18, 2), tv.CursorPosition);
  4586. Assert.Equal (42 + Environment.NewLine.Length, tv.SelectedLength);
  4587. Assert.Equal ($"This is the second line.{Environment.NewLine}This is the third ", tv.SelectedText);
  4588. Assert.True (tv.IsSelecting);
  4589. Assert.True (tv.NewKeyDownEvent (Key.Home.WithShift.WithCtrl));
  4590. Assert.Equal (
  4591. $"{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third ",
  4592. tv.Text
  4593. );
  4594. Assert.Equal (Point.Empty, tv.CursorPosition);
  4595. Assert.Equal (Environment.NewLine.Length, tv.SelectedLength);
  4596. Assert.Equal ($"{Environment.NewLine}", tv.SelectedText);
  4597. Assert.True (tv.IsSelecting);
  4598. Assert.True (tv.NewKeyDownEvent (Key.T.WithCtrl));
  4599. Assert.Equal (
  4600. $"{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third ",
  4601. tv.Text
  4602. );
  4603. Assert.Equal (new Point (18, 2), tv.CursorPosition);
  4604. Assert.Equal (42 + Environment.NewLine.Length * 2, tv.SelectedLength);
  4605. Assert.Equal (
  4606. $"{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third ",
  4607. tv.SelectedText
  4608. );
  4609. Assert.True (tv.IsSelecting);
  4610. Assert.True (tv.Used);
  4611. Assert.True (tv.NewKeyDownEvent (Key.InsertChar));
  4612. Assert.False (tv.Used);
  4613. Assert.True (tv.AllowsTab);
  4614. Assert.Equal (new Point (18, 2), tv.CursorPosition);
  4615. tv.AllowsTab = false;
  4616. Assert.False (tv.NewKeyDownEvent (Key.Tab));
  4617. Assert.Equal (
  4618. $"{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third ",
  4619. tv.Text
  4620. );
  4621. Assert.False (tv.AllowsTab);
  4622. tv.AllowsTab = true;
  4623. Assert.Equal (new Point (18, 2), tv.CursorPosition);
  4624. Assert.True (tv.IsSelecting);
  4625. tv.IsSelecting = false;
  4626. Assert.True (tv.NewKeyDownEvent (Key.Tab));
  4627. Assert.Equal (
  4628. $"{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third \t",
  4629. tv.Text
  4630. );
  4631. Assert.True (tv.AllowsTab);
  4632. tv.AllowsTab = false;
  4633. Assert.False (tv.NewKeyDownEvent (Key.Tab.WithShift));
  4634. Assert.Equal (
  4635. $"{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third \t",
  4636. tv.Text
  4637. );
  4638. Assert.False (tv.AllowsTab);
  4639. tv.AllowsTab = true;
  4640. Assert.True (tv.NewKeyDownEvent (Key.Tab.WithShift));
  4641. Assert.Equal (
  4642. $"{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third ",
  4643. tv.Text
  4644. );
  4645. Assert.True (tv.AllowsTab);
  4646. Assert.False (tv.NewKeyDownEvent (Key.F6));
  4647. Assert.False (tv.NewKeyDownEvent (Application.NextTabGroupKey));
  4648. Assert.False (tv.NewKeyDownEvent (Key.F6.WithShift));
  4649. Assert.False (tv.NewKeyDownEvent (Application.PrevTabGroupKey));
  4650. Assert.True (tv.NewKeyDownEvent (ContextMenu.DefaultKey));
  4651. Assert.True (tv.ContextMenu != null && tv.ContextMenu.MenuBar.Visible);
  4652. top.Dispose ();
  4653. }
  4654. [Fact]
  4655. [TextViewTestsAutoInitShutdown]
  4656. public void Kill_Delete_WordBackward ()
  4657. {
  4658. _textView.Text = "This is the first line.";
  4659. _textView.MoveEnd ();
  4660. var iteration = 0;
  4661. var iterationsFinished = false;
  4662. while (!iterationsFinished)
  4663. {
  4664. _textView.NewKeyDownEvent (Key.Backspace.WithCtrl);
  4665. switch (iteration)
  4666. {
  4667. case 0:
  4668. Assert.Equal (22, _textView.CursorPosition.X);
  4669. Assert.Equal (0, _textView.CursorPosition.Y);
  4670. Assert.Equal ("This is the first line", _textView.Text);
  4671. break;
  4672. case 1:
  4673. Assert.Equal (18, _textView.CursorPosition.X);
  4674. Assert.Equal (0, _textView.CursorPosition.Y);
  4675. Assert.Equal ("This is the first ", _textView.Text);
  4676. break;
  4677. case 2:
  4678. Assert.Equal (12, _textView.CursorPosition.X);
  4679. Assert.Equal (0, _textView.CursorPosition.Y);
  4680. Assert.Equal ("This is the ", _textView.Text);
  4681. break;
  4682. case 3:
  4683. Assert.Equal (8, _textView.CursorPosition.X);
  4684. Assert.Equal (0, _textView.CursorPosition.Y);
  4685. Assert.Equal ("This is ", _textView.Text);
  4686. break;
  4687. case 4:
  4688. Assert.Equal (5, _textView.CursorPosition.X);
  4689. Assert.Equal (0, _textView.CursorPosition.Y);
  4690. Assert.Equal ("This ", _textView.Text);
  4691. break;
  4692. case 5:
  4693. Assert.Equal (0, _textView.CursorPosition.X);
  4694. Assert.Equal (0, _textView.CursorPosition.Y);
  4695. Assert.Equal ("", _textView.Text);
  4696. break;
  4697. default:
  4698. iterationsFinished = true;
  4699. break;
  4700. }
  4701. iteration++;
  4702. }
  4703. }
  4704. [Fact]
  4705. [TextViewTestsAutoInitShutdown]
  4706. public void Kill_Delete_WordBackward_Multiline ()
  4707. {
  4708. _textView.Text = "This is the first line.\nThis is the second line.";
  4709. _textView.Width = 4;
  4710. _textView.MoveEnd ();
  4711. var iteration = 0;
  4712. var iterationsFinished = false;
  4713. while (!iterationsFinished)
  4714. {
  4715. _textView.NewKeyDownEvent (Key.Backspace.WithCtrl);
  4716. switch (iteration)
  4717. {
  4718. case 0:
  4719. Assert.Equal (23, _textView.CursorPosition.X);
  4720. Assert.Equal (1, _textView.CursorPosition.Y);
  4721. Assert.Equal (
  4722. "This is the first line."
  4723. + Environment.NewLine
  4724. + "This is the second line",
  4725. _textView.Text
  4726. );
  4727. break;
  4728. case 1:
  4729. Assert.Equal (19, _textView.CursorPosition.X);
  4730. Assert.Equal (1, _textView.CursorPosition.Y);
  4731. Assert.Equal (
  4732. "This is the first line."
  4733. + Environment.NewLine
  4734. + "This is the second ",
  4735. _textView.Text
  4736. );
  4737. break;
  4738. case 2:
  4739. Assert.Equal (12, _textView.CursorPosition.X);
  4740. Assert.Equal (1, _textView.CursorPosition.Y);
  4741. Assert.Equal (
  4742. "This is the first line."
  4743. + Environment.NewLine
  4744. + "This is the ",
  4745. _textView.Text
  4746. );
  4747. break;
  4748. case 3:
  4749. Assert.Equal (8, _textView.CursorPosition.X);
  4750. Assert.Equal (1, _textView.CursorPosition.Y);
  4751. Assert.Equal (
  4752. "This is the first line."
  4753. + Environment.NewLine
  4754. + "This is ",
  4755. _textView.Text
  4756. );
  4757. break;
  4758. case 4:
  4759. Assert.Equal (5, _textView.CursorPosition.X);
  4760. Assert.Equal (1, _textView.CursorPosition.Y);
  4761. Assert.Equal (
  4762. "This is the first line."
  4763. + Environment.NewLine
  4764. + "This ",
  4765. _textView.Text
  4766. );
  4767. break;
  4768. case 5:
  4769. Assert.Equal (0, _textView.CursorPosition.X);
  4770. Assert.Equal (1, _textView.CursorPosition.Y);
  4771. Assert.Equal ("This is the first line." + Environment.NewLine, _textView.Text);
  4772. break;
  4773. case 6:
  4774. Assert.Equal (23, _textView.CursorPosition.X);
  4775. Assert.Equal (0, _textView.CursorPosition.Y);
  4776. Assert.Equal ("This is the first line.", _textView.Text);
  4777. break;
  4778. case 7:
  4779. Assert.Equal (22, _textView.CursorPosition.X);
  4780. Assert.Equal (0, _textView.CursorPosition.Y);
  4781. Assert.Equal ("This is the first line", _textView.Text);
  4782. break;
  4783. case 8:
  4784. Assert.Equal (18, _textView.CursorPosition.X);
  4785. Assert.Equal (0, _textView.CursorPosition.Y);
  4786. Assert.Equal ("This is the first ", _textView.Text);
  4787. break;
  4788. case 9:
  4789. Assert.Equal (12, _textView.CursorPosition.X);
  4790. Assert.Equal (0, _textView.CursorPosition.Y);
  4791. Assert.Equal ("This is the ", _textView.Text);
  4792. break;
  4793. case 10:
  4794. Assert.Equal (8, _textView.CursorPosition.X);
  4795. Assert.Equal (0, _textView.CursorPosition.Y);
  4796. Assert.Equal ("This is ", _textView.Text);
  4797. break;
  4798. case 11:
  4799. Assert.Equal (5, _textView.CursorPosition.X);
  4800. Assert.Equal (0, _textView.CursorPosition.Y);
  4801. Assert.Equal ("This ", _textView.Text);
  4802. break;
  4803. case 12:
  4804. Assert.Equal (0, _textView.CursorPosition.X);
  4805. Assert.Equal (0, _textView.CursorPosition.Y);
  4806. Assert.Equal ("", _textView.Text);
  4807. break;
  4808. default:
  4809. iterationsFinished = true;
  4810. break;
  4811. }
  4812. iteration++;
  4813. }
  4814. }
  4815. [Fact]
  4816. [TextViewTestsAutoInitShutdown]
  4817. public void Kill_Delete_WordForward ()
  4818. {
  4819. _textView.Text = "This is the first line.";
  4820. var iteration = 0;
  4821. var iterationsFinished = false;
  4822. while (!iterationsFinished)
  4823. {
  4824. _textView.NewKeyDownEvent (Key.Delete.WithCtrl);
  4825. switch (iteration)
  4826. {
  4827. case 0:
  4828. Assert.Equal (0, _textView.CursorPosition.X);
  4829. Assert.Equal (0, _textView.CursorPosition.Y);
  4830. Assert.Equal ("is the first line.", _textView.Text);
  4831. break;
  4832. case 1:
  4833. Assert.Equal (0, _textView.CursorPosition.X);
  4834. Assert.Equal (0, _textView.CursorPosition.Y);
  4835. Assert.Equal ("the first line.", _textView.Text);
  4836. break;
  4837. case 2:
  4838. Assert.Equal (0, _textView.CursorPosition.X);
  4839. Assert.Equal (0, _textView.CursorPosition.Y);
  4840. Assert.Equal ("first line.", _textView.Text);
  4841. break;
  4842. case 3:
  4843. Assert.Equal (0, _textView.CursorPosition.X);
  4844. Assert.Equal (0, _textView.CursorPosition.Y);
  4845. Assert.Equal ("line.", _textView.Text);
  4846. break;
  4847. case 4:
  4848. Assert.Equal (0, _textView.CursorPosition.X);
  4849. Assert.Equal (0, _textView.CursorPosition.Y);
  4850. Assert.Equal ("", _textView.Text);
  4851. break;
  4852. default:
  4853. iterationsFinished = true;
  4854. break;
  4855. }
  4856. iteration++;
  4857. }
  4858. }
  4859. [Fact]
  4860. [TextViewTestsAutoInitShutdown]
  4861. public void Kill_Delete_WordForward_Multiline ()
  4862. {
  4863. _textView.Text = "This is the first line.\nThis is the second line.";
  4864. _textView.Width = 4;
  4865. var iteration = 0;
  4866. var iterationsFinished = false;
  4867. while (!iterationsFinished)
  4868. {
  4869. _textView.NewKeyDownEvent (Key.Delete.WithCtrl);
  4870. switch (iteration)
  4871. {
  4872. case 0:
  4873. Assert.Equal (0, _textView.CursorPosition.X);
  4874. Assert.Equal (0, _textView.CursorPosition.Y);
  4875. Assert.Equal (
  4876. "is the first line."
  4877. + Environment.NewLine
  4878. + "This is the second line.",
  4879. _textView.Text
  4880. );
  4881. break;
  4882. case 1:
  4883. Assert.Equal (0, _textView.CursorPosition.X);
  4884. Assert.Equal (0, _textView.CursorPosition.Y);
  4885. Assert.Equal (
  4886. "the first line."
  4887. + Environment.NewLine
  4888. + "This is the second line.",
  4889. _textView.Text
  4890. );
  4891. break;
  4892. case 2:
  4893. Assert.Equal (0, _textView.CursorPosition.X);
  4894. Assert.Equal (0, _textView.CursorPosition.Y);
  4895. Assert.Equal (
  4896. "first line."
  4897. + Environment.NewLine
  4898. + "This is the second line.",
  4899. _textView.Text
  4900. );
  4901. break;
  4902. case 3:
  4903. Assert.Equal (0, _textView.CursorPosition.X);
  4904. Assert.Equal (0, _textView.CursorPosition.Y);
  4905. Assert.Equal (
  4906. "line."
  4907. + Environment.NewLine
  4908. + "This is the second line.",
  4909. _textView.Text
  4910. );
  4911. break;
  4912. case 4:
  4913. Assert.Equal (0, _textView.CursorPosition.X);
  4914. Assert.Equal (0, _textView.CursorPosition.Y);
  4915. Assert.Equal (
  4916. ""
  4917. + Environment.NewLine
  4918. + "This is the second line.",
  4919. _textView.Text
  4920. );
  4921. break;
  4922. case 5:
  4923. Assert.Equal (0, _textView.CursorPosition.X);
  4924. Assert.Equal (0, _textView.CursorPosition.Y);
  4925. Assert.Equal ("This is the second line.", _textView.Text);
  4926. break;
  4927. case 6:
  4928. Assert.Equal (0, _textView.CursorPosition.X);
  4929. Assert.Equal (0, _textView.CursorPosition.Y);
  4930. Assert.Equal ("is the second line.", _textView.Text);
  4931. break;
  4932. case 7:
  4933. Assert.Equal (0, _textView.CursorPosition.X);
  4934. Assert.Equal (0, _textView.CursorPosition.Y);
  4935. Assert.Equal ("the second line.", _textView.Text);
  4936. break;
  4937. case 8:
  4938. Assert.Equal (0, _textView.CursorPosition.X);
  4939. Assert.Equal (0, _textView.CursorPosition.Y);
  4940. Assert.Equal ("second line.", _textView.Text);
  4941. break;
  4942. case 9:
  4943. Assert.Equal (0, _textView.CursorPosition.X);
  4944. Assert.Equal (0, _textView.CursorPosition.Y);
  4945. Assert.Equal ("line.", _textView.Text);
  4946. break;
  4947. case 10:
  4948. Assert.Equal (0, _textView.CursorPosition.X);
  4949. Assert.Equal (0, _textView.CursorPosition.Y);
  4950. Assert.Equal ("", _textView.Text);
  4951. break;
  4952. default:
  4953. iterationsFinished = true;
  4954. break;
  4955. }
  4956. iteration++;
  4957. }
  4958. }
  4959. [Fact]
  4960. [TextViewTestsAutoInitShutdown]
  4961. public void Kill_To_End_Delete_Forwards_Copy_To_The_Clipboard_And_Paste ()
  4962. {
  4963. _textView.Text = "This is the first line.\nThis is the second line.";
  4964. var iteration = 0;
  4965. var iterationsFinished = false;
  4966. while (!iterationsFinished)
  4967. {
  4968. switch (iteration)
  4969. {
  4970. case 0:
  4971. _textView.NewKeyDownEvent (Key.K.WithCtrl);
  4972. Assert.Equal (0, _textView.CursorPosition.X);
  4973. Assert.Equal (0, _textView.CursorPosition.Y);
  4974. Assert.Equal ($"{Environment.NewLine}This is the second line.", _textView.Text);
  4975. Assert.Equal ("This is the first line.", Clipboard.Contents);
  4976. break;
  4977. case 1:
  4978. _textView.NewKeyDownEvent (
  4979. new Key (
  4980. KeyCode.Delete | KeyCode.CtrlMask | KeyCode.ShiftMask
  4981. )
  4982. );
  4983. Assert.Equal (0, _textView.CursorPosition.X);
  4984. Assert.Equal (0, _textView.CursorPosition.Y);
  4985. Assert.Equal ("This is the second line.", _textView.Text);
  4986. Assert.Equal ($"This is the first line.{Environment.NewLine}", Clipboard.Contents);
  4987. break;
  4988. case 2:
  4989. _textView.NewKeyDownEvent (Key.K.WithCtrl);
  4990. Assert.Equal (0, _textView.CursorPosition.X);
  4991. Assert.Equal (0, _textView.CursorPosition.Y);
  4992. Assert.Equal ("", _textView.Text);
  4993. Assert.Equal (
  4994. $"This is the first line.{Environment.NewLine}This is the second line.",
  4995. Clipboard.Contents
  4996. );
  4997. // Paste
  4998. _textView.NewKeyDownEvent (Key.Y.WithCtrl);
  4999. Assert.Equal (
  5000. $"This is the first line.{Environment.NewLine}This is the second line.",
  5001. _textView.Text
  5002. );
  5003. break;
  5004. default:
  5005. iterationsFinished = true;
  5006. break;
  5007. }
  5008. iteration++;
  5009. }
  5010. }
  5011. [Fact]
  5012. [TextViewTestsAutoInitShutdown]
  5013. public void Kill_To_Start_Delete_Backwards_Copy_To_The_Clipboard_And_Paste ()
  5014. {
  5015. _textView.Text = "This is the first line.\nThis is the second line.";
  5016. _textView.MoveEnd ();
  5017. var iteration = 0;
  5018. var iterationsFinished = false;
  5019. while (!iterationsFinished)
  5020. {
  5021. switch (iteration)
  5022. {
  5023. case 0:
  5024. _textView.NewKeyDownEvent (Key.Backspace.WithCtrl.WithShift);
  5025. Assert.Equal (0, _textView.CursorPosition.X);
  5026. Assert.Equal (1, _textView.CursorPosition.Y);
  5027. Assert.Equal ($"This is the first line.{Environment.NewLine}", _textView.Text);
  5028. Assert.Equal ("This is the second line.", Clipboard.Contents);
  5029. break;
  5030. case 1:
  5031. _textView.NewKeyDownEvent (
  5032. new Key (
  5033. KeyCode.Backspace | KeyCode.CtrlMask | KeyCode.ShiftMask
  5034. )
  5035. );
  5036. Assert.Equal (23, _textView.CursorPosition.X);
  5037. Assert.Equal (0, _textView.CursorPosition.Y);
  5038. Assert.Equal ("This is the first line.", _textView.Text);
  5039. Assert.Equal ($"This is the second line.{Environment.NewLine}", Clipboard.Contents);
  5040. break;
  5041. case 2:
  5042. _textView.NewKeyDownEvent (Key.Backspace.WithCtrl.WithShift);
  5043. Assert.Equal (0, _textView.CursorPosition.X);
  5044. Assert.Equal (0, _textView.CursorPosition.Y);
  5045. Assert.Equal ("", _textView.Text);
  5046. Assert.Equal (
  5047. $"This is the second line.{Environment.NewLine}This is the first line.",
  5048. Clipboard.Contents
  5049. );
  5050. // Paste inverted
  5051. _textView.NewKeyDownEvent (Key.Y.WithCtrl);
  5052. Assert.Equal (
  5053. $"This is the second line.{Environment.NewLine}This is the first line.",
  5054. _textView.Text
  5055. );
  5056. break;
  5057. default:
  5058. iterationsFinished = true;
  5059. break;
  5060. }
  5061. iteration++;
  5062. }
  5063. }
  5064. [Fact]
  5065. public void LeftColumn_Add_One_If_Text_Length_Is_Equal_To_Width ()
  5066. {
  5067. var tv = new TextView { Width = 10, Text = "1234567890" };
  5068. Assert.Equal (Point.Empty, tv.CursorPosition);
  5069. Assert.Equal (0, tv.LeftColumn);
  5070. tv.CursorPosition = new Point (9, 0);
  5071. Assert.Equal (new Point (9, 0), tv.CursorPosition);
  5072. Assert.Equal (0, tv.LeftColumn);
  5073. Assert.True (tv.NewKeyDownEvent (Key.CursorRight));
  5074. tv.CursorPosition = new Point (10, 0);
  5075. Assert.Equal (new Point (10, 0), tv.CursorPosition);
  5076. Assert.Equal (1, tv.LeftColumn);
  5077. }
  5078. [Fact]
  5079. public void LoadFile_Throws_If_File_Is_Empty ()
  5080. {
  5081. var result = false;
  5082. var tv = new TextView ();
  5083. Assert.Throws<ArgumentException> (() => result = tv.Load (""));
  5084. Assert.False (result);
  5085. }
  5086. [Fact]
  5087. public void LoadFile_Throws_If_File_Is_Null ()
  5088. {
  5089. var result = false;
  5090. var tv = new TextView ();
  5091. Assert.Throws<ArgumentNullException> (() => result = tv.Load ((string)null));
  5092. Assert.False (result);
  5093. }
  5094. [Fact]
  5095. public void LoadFile_Throws_If_File_Not_Exist ()
  5096. {
  5097. var result = false;
  5098. var tv = new TextView ();
  5099. Assert.Throws<FileNotFoundException> (() => result = tv.Load ("blabla"));
  5100. Assert.False (result);
  5101. }
  5102. [Fact]
  5103. public void LoadStream_CRLF ()
  5104. {
  5105. var text = "This is the first line.\r\nThis is the second line.\r\n";
  5106. var tv = new TextView ();
  5107. tv.Load (new MemoryStream (Encoding.ASCII.GetBytes (text)));
  5108. Assert.Equal (
  5109. $"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}",
  5110. tv.Text
  5111. );
  5112. }
  5113. [Fact]
  5114. public void LoadStream_IsDirty ()
  5115. {
  5116. var text = "Testing";
  5117. using (var stream = new MemoryStream ())
  5118. {
  5119. var writer = new StreamWriter (stream);
  5120. writer.Write (text);
  5121. writer.Flush ();
  5122. stream.Position = 0;
  5123. var tv = new TextView ();
  5124. tv.Load (stream);
  5125. Assert.Equal (7, text.Length);
  5126. Assert.Equal (text.Length, tv.Text.Length);
  5127. Assert.Equal (text, tv.Text);
  5128. Assert.False (tv.IsDirty);
  5129. }
  5130. }
  5131. [Fact]
  5132. public void LoadStream_IsDirty_With_Null_On_The_Text ()
  5133. {
  5134. var text = "Test\0ing";
  5135. using (var stream = new MemoryStream ())
  5136. {
  5137. var writer = new StreamWriter (stream);
  5138. writer.Write (text);
  5139. writer.Flush ();
  5140. stream.Position = 0;
  5141. var tv = new TextView ();
  5142. tv.Load (stream);
  5143. Assert.Equal (8, text.Length);
  5144. Assert.Equal (text.Length, tv.Text.Length);
  5145. Assert.Equal (8, text.Length);
  5146. Assert.Equal (8, tv.Text.Length);
  5147. Assert.Equal (text, tv.Text);
  5148. Assert.False (tv.IsDirty);
  5149. Assert.Equal ((Rune)'\u2400', ((Rune)tv.Text [4]).MakePrintable ());
  5150. }
  5151. }
  5152. [Fact]
  5153. public void LoadStream_LF ()
  5154. {
  5155. var text = "This is the first line.\nThis is the second line.\n";
  5156. var tv = new TextView ();
  5157. tv.Load (new MemoryStream (Encoding.ASCII.GetBytes (text)));
  5158. Assert.Equal (
  5159. $"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}",
  5160. tv.Text
  5161. );
  5162. }
  5163. [Fact]
  5164. public void LoadStream_Stream_Is_Empty ()
  5165. {
  5166. var tv = new TextView ();
  5167. tv.Load (new MemoryStream ());
  5168. Assert.Equal ("", tv.Text);
  5169. }
  5170. [Fact]
  5171. public void LoadStream_Throws_If_Stream_Is_Null ()
  5172. {
  5173. var tv = new TextView ();
  5174. Assert.Throws<ArgumentNullException> (() => tv.Load ((Stream)null));
  5175. }
  5176. [Fact]
  5177. [TextViewTestsAutoInitShutdown]
  5178. public void Mouse_Button_Shift_Preserves_Selection ()
  5179. {
  5180. Assert.Equal ("TAB to jump between text fields.", _textView.Text);
  5181. Assert.True (
  5182. _textView.NewMouseEvent (
  5183. new MouseEventArgs { Position = new (12, 0), Flags = MouseFlags.Button1Pressed | MouseFlags.ButtonShift }
  5184. )
  5185. );
  5186. Assert.Equal (0, _textView.SelectionStartColumn);
  5187. Assert.Equal (0, _textView.SelectionStartRow);
  5188. Assert.Equal (new Point (12, 0), _textView.CursorPosition);
  5189. Assert.True (_textView.IsSelecting);
  5190. Assert.Equal ("TAB to jump ", _textView.SelectedText);
  5191. Assert.True (_textView.NewMouseEvent (new MouseEventArgs { Position = new (12, 0), Flags = MouseFlags.Button1Clicked }));
  5192. Assert.Equal (0, _textView.SelectionStartRow);
  5193. Assert.Equal (0, _textView.SelectionStartRow);
  5194. Assert.Equal (new Point (12, 0), _textView.CursorPosition);
  5195. Assert.True (_textView.IsSelecting);
  5196. Assert.Equal ("TAB to jump ", _textView.SelectedText);
  5197. Assert.True (
  5198. _textView.NewMouseEvent (
  5199. new MouseEventArgs { Position = new (19, 0), Flags = MouseFlags.Button1Pressed | MouseFlags.ButtonShift }
  5200. )
  5201. );
  5202. Assert.Equal (0, _textView.SelectionStartRow);
  5203. Assert.Equal (0, _textView.SelectionStartRow);
  5204. Assert.Equal (new Point (19, 0), _textView.CursorPosition);
  5205. Assert.True (_textView.IsSelecting);
  5206. Assert.Equal ("TAB to jump between", _textView.SelectedText);
  5207. Assert.True (_textView.NewMouseEvent (new MouseEventArgs { Position = new (19, 0), Flags = MouseFlags.Button1Clicked }));
  5208. Assert.Equal (0, _textView.SelectionStartRow);
  5209. Assert.Equal (0, _textView.SelectionStartRow);
  5210. Assert.Equal (new Point (19, 0), _textView.CursorPosition);
  5211. Assert.True (_textView.IsSelecting);
  5212. Assert.Equal ("TAB to jump between", _textView.SelectedText);
  5213. Assert.True (
  5214. _textView.NewMouseEvent (
  5215. new MouseEventArgs { Position = new (24, 0), Flags = MouseFlags.Button1Pressed | MouseFlags.ButtonShift }
  5216. )
  5217. );
  5218. Assert.Equal (0, _textView.SelectionStartRow);
  5219. Assert.Equal (0, _textView.SelectionStartRow);
  5220. Assert.Equal (new Point (24, 0), _textView.CursorPosition);
  5221. Assert.True (_textView.IsSelecting);
  5222. Assert.Equal ("TAB to jump between text", _textView.SelectedText);
  5223. Assert.True (_textView.NewMouseEvent (new MouseEventArgs { Position = new (24, 0), Flags = MouseFlags.Button1Clicked }));
  5224. Assert.Equal (0, _textView.SelectionStartRow);
  5225. Assert.Equal (0, _textView.SelectionStartRow);
  5226. Assert.Equal (new Point (24, 0), _textView.CursorPosition);
  5227. Assert.True (_textView.IsSelecting);
  5228. Assert.Equal ("TAB to jump between text", _textView.SelectedText);
  5229. Assert.True (_textView.NewMouseEvent (new MouseEventArgs { Position = new (24, 0), Flags = MouseFlags.Button1Pressed }));
  5230. Assert.Equal (0, _textView.SelectionStartRow);
  5231. Assert.Equal (0, _textView.SelectionStartRow);
  5232. Assert.Equal (new Point (24, 0), _textView.CursorPosition);
  5233. Assert.True (_textView.IsSelecting);
  5234. Assert.Equal ("", _textView.SelectedText);
  5235. }
  5236. [Fact]
  5237. [AutoInitShutdown]
  5238. public void MoveDown_By_Setting_CursorPosition ()
  5239. {
  5240. var tv = new TextView { Width = 10, Height = 5 };
  5241. // add 100 lines of wide text to view
  5242. for (var i = 0; i < 100; i++)
  5243. {
  5244. tv.Text += new string ('x', 100) + (i == 99 ? "" : Environment.NewLine);
  5245. }
  5246. Assert.Equal (Point.Empty, tv.CursorPosition);
  5247. tv.CursorPosition = new Point (5, 50);
  5248. Assert.Equal (new Point (5, 50), tv.CursorPosition);
  5249. tv.CursorPosition = new Point (200, 200);
  5250. Assert.Equal (new Point (100, 99), tv.CursorPosition);
  5251. }
  5252. [Fact]
  5253. [TextViewTestsAutoInitShutdown]
  5254. public void Multiline_Setting_Changes_AllowsReturn_AllowsTab_Height_WordWrap ()
  5255. {
  5256. Assert.True (_textView.Multiline);
  5257. Assert.True (_textView.AllowsReturn);
  5258. Assert.Equal (4, _textView.TabWidth);
  5259. Assert.True (_textView.AllowsTab);
  5260. Assert.False (_textView.WordWrap);
  5261. _textView.WordWrap = true;
  5262. Assert.True (_textView.WordWrap);
  5263. _textView.Multiline = false;
  5264. Assert.False (_textView.Multiline);
  5265. Assert.False (_textView.AllowsReturn);
  5266. Assert.Equal (0, _textView.TabWidth);
  5267. Assert.False (_textView.AllowsTab);
  5268. Assert.False (_textView.WordWrap);
  5269. _textView.WordWrap = true;
  5270. Assert.False (_textView.WordWrap);
  5271. _textView.Multiline = true;
  5272. Assert.True (_textView.Multiline);
  5273. Assert.True (_textView.AllowsReturn);
  5274. Assert.Equal (4, _textView.TabWidth);
  5275. Assert.True (_textView.AllowsTab);
  5276. Assert.False (_textView.WordWrap);
  5277. }
  5278. [Fact]
  5279. [TextViewTestsAutoInitShutdown]
  5280. public void Paste_Always_Clear_The_SelectedText ()
  5281. {
  5282. _textView.SelectionStartColumn = 20;
  5283. _textView.SelectionStartRow = 0;
  5284. _textView.CursorPosition = new Point (24, 0);
  5285. _textView.NewKeyDownEvent (Key.C.WithCtrl); // Copy
  5286. Assert.Equal ("text", _textView.SelectedText);
  5287. _textView.NewKeyDownEvent (Key.Y.WithCtrl); // Paste
  5288. Assert.Equal ("", _textView.SelectedText);
  5289. }
  5290. [Fact]
  5291. public void ReplaceAllText_Does_Not_Throw_Exception ()
  5292. {
  5293. var textToFind = "hello! hello!";
  5294. var textToReplace = "hello!";
  5295. var tv = new TextView { Width = 20, Height = 3, Text = textToFind };
  5296. Exception exception = Record.Exception (() => tv.ReplaceAllText (textToFind, false, false, textToReplace));
  5297. Assert.Null (exception);
  5298. Assert.Equal (textToReplace, tv.Text);
  5299. }
  5300. [Fact]
  5301. [AutoInitShutdown]
  5302. public void ScrollDownTillCaretOffscreen_ThenType ()
  5303. {
  5304. var tv = new TextView { Width = 10, Height = 5 };
  5305. // add 100 lines of wide text to view
  5306. for (var i = 0; i < 100; i++)
  5307. {
  5308. tv.Text += new string ('x', 100) + Environment.NewLine;
  5309. }
  5310. Assert.Equal (0, tv.CursorPosition.Y);
  5311. tv.ScrollTo (50);
  5312. Assert.Equal (0, tv.CursorPosition.Y);
  5313. tv.NewKeyDownEvent (Key.P);
  5314. }
  5315. [Fact]
  5316. [AutoInitShutdown]
  5317. public void ScrollTo_CursorPosition ()
  5318. {
  5319. var tv = new TextView { Width = 10, Height = 5 };
  5320. // add 100 lines of wide text to view
  5321. for (var i = 0; i < 100; i++)
  5322. {
  5323. tv.Text += new string ('x', 100) + (i == 99 ? "" : Environment.NewLine);
  5324. }
  5325. Assert.Equal (Point.Empty, tv.CursorPosition);
  5326. tv.ScrollTo (50);
  5327. Assert.Equal (Point.Empty, tv.CursorPosition);
  5328. tv.CursorPosition = new Point (tv.LeftColumn, tv.TopRow);
  5329. Assert.Equal (new Point (0, 50), tv.CursorPosition);
  5330. }
  5331. [Fact]
  5332. [TextViewTestsAutoInitShutdown]
  5333. public void Selected_Text_Shows ()
  5334. {
  5335. // Proves #3022 is fixed (TextField selected text does not show in v2)
  5336. var top = new Toplevel ();
  5337. top.Add (_textView);
  5338. RunState rs = Application.Begin (top);
  5339. _textView.CursorPosition = Point.Empty;
  5340. _textView.SelectionStartColumn = 0;
  5341. _textView.SelectionStartRow = 0;
  5342. Attribute [] attributes =
  5343. {
  5344. _textView.ColorScheme.Focus,
  5345. new (_textView.ColorScheme.Focus.Background, _textView.ColorScheme.Focus.Foreground)
  5346. };
  5347. // TAB to jump between text fields.
  5348. TestHelpers.AssertDriverAttributesAre ("0000000", _output, Application.Driver, attributes);
  5349. Assert.Empty (_textView.SelectedCellsList);
  5350. _textView.NewKeyDownEvent (Key.CursorRight.WithCtrl.WithShift);
  5351. Application.RunIteration (ref rs, true);
  5352. Assert.Equal (new Point (4, 0), _textView.CursorPosition);
  5353. // TAB to jump between text fields.
  5354. TestHelpers.AssertDriverAttributesAre ("1111000", _output, Application.Driver, attributes);
  5355. Assert.Equal ("TAB ", Cell.ToString (_textView.SelectedCellsList [^1]));
  5356. top.Dispose ();
  5357. }
  5358. [Fact]
  5359. [TextViewTestsAutoInitShutdown]
  5360. public void Selection_And_CursorPosition_With_Value_Greater_Than_Text_Length_Changes_Both_To_Text_Length ()
  5361. {
  5362. _textView.CursorPosition = new Point (33, 2);
  5363. _textView.SelectionStartColumn = 33;
  5364. _textView.SelectionStartRow = 33;
  5365. Assert.Equal (32, _textView.CursorPosition.X);
  5366. Assert.Equal (0, _textView.CursorPosition.Y);
  5367. Assert.Equal (32, _textView.SelectionStartColumn);
  5368. Assert.Equal (0, _textView.SelectionStartRow);
  5369. Assert.Equal (0, _textView.SelectedLength);
  5370. Assert.Equal ("", _textView.SelectedText);
  5371. }
  5372. [Fact]
  5373. [TextViewTestsAutoInitShutdown]
  5374. public void Selection_With_Empty_Text ()
  5375. {
  5376. _textView = new TextView ();
  5377. _textView.CursorPosition = new Point (2, 0);
  5378. _textView.SelectionStartColumn = 33;
  5379. _textView.SelectionStartRow = 1;
  5380. Assert.Equal (0, _textView.SelectionStartColumn);
  5381. Assert.Equal (0, _textView.SelectionStartRow);
  5382. Assert.Equal (0, _textView.SelectedLength);
  5383. Assert.Equal ("", _textView.SelectedText);
  5384. }
  5385. [Fact]
  5386. [TextViewTestsAutoInitShutdown]
  5387. public void Selection_With_Value_Greater_Than_Text_Length_Changes_To_Text_Length ()
  5388. {
  5389. _textView.CursorPosition = new Point (2, 0);
  5390. _textView.SelectionStartColumn = 33;
  5391. _textView.SelectionStartRow = 1;
  5392. Assert.Equal (32, _textView.SelectionStartColumn);
  5393. Assert.Equal (0, _textView.SelectionStartRow);
  5394. Assert.Equal (30, _textView.SelectedLength);
  5395. Assert.Equal ("B to jump between text fields.", _textView.SelectedText);
  5396. }
  5397. [Fact]
  5398. [TextViewTestsAutoInitShutdown]
  5399. public void Selection_With_Value_Less_Than_Zero_Changes_To_Zero ()
  5400. {
  5401. _textView.SelectionStartColumn = -2;
  5402. _textView.SelectionStartRow = -2;
  5403. Assert.Equal (0, _textView.SelectionStartColumn);
  5404. Assert.Equal (0, _textView.SelectionStartRow);
  5405. Assert.Equal (0, _textView.SelectedLength);
  5406. Assert.Equal ("", _textView.SelectedText);
  5407. }
  5408. [Fact]
  5409. public void StringToRunes_Slipts_CRLF ()
  5410. {
  5411. var text = "This is the first line.\r\nThis is the second line.\r\n";
  5412. var tv = new TextView ();
  5413. tv.Text = text;
  5414. Assert.Equal (
  5415. $"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}",
  5416. tv.Text
  5417. );
  5418. }
  5419. [Fact]
  5420. public void StringToRunes_Slipts_LF ()
  5421. {
  5422. var text = "This is the first line.\nThis is the second line.\n";
  5423. var tv = new TextView ();
  5424. tv.Text = text;
  5425. Assert.Equal (
  5426. $"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}",
  5427. tv.Text
  5428. );
  5429. }
  5430. [Fact]
  5431. [TextViewTestsAutoInitShutdown]
  5432. public void Tab_Test_Follow_By_BackTab ()
  5433. {
  5434. var top = new Toplevel ();
  5435. top.Add (_textView);
  5436. Application.Iteration += (s, a) =>
  5437. {
  5438. int width = _textView.Viewport.Width - 1;
  5439. Assert.Equal (30, width + 1);
  5440. Assert.Equal (10, _textView.Height);
  5441. _textView.Text = "";
  5442. var col = 0;
  5443. var leftCol = 0;
  5444. int tabWidth = _textView.TabWidth;
  5445. while (col < 100)
  5446. {
  5447. col++;
  5448. _textView.NewKeyDownEvent (Key.Tab);
  5449. Assert.Equal (new Point (col, 0), _textView.CursorPosition);
  5450. leftCol = GetLeftCol (leftCol);
  5451. Assert.Equal (leftCol, _textView.LeftColumn);
  5452. }
  5453. while (col > 0)
  5454. {
  5455. col--;
  5456. _textView.NewKeyDownEvent (Key.Tab.WithShift);
  5457. Assert.Equal (new Point (col, 0), _textView.CursorPosition);
  5458. leftCol = GetLeftCol (leftCol);
  5459. Assert.Equal (leftCol, _textView.LeftColumn);
  5460. }
  5461. top.Remove (_textView);
  5462. Application.RequestStop ();
  5463. };
  5464. Application.Run (top);
  5465. top.Dispose ();
  5466. }
  5467. [Fact]
  5468. [TextViewTestsAutoInitShutdown]
  5469. public void Tab_Test_Follow_By_BackTab_With_Text ()
  5470. {
  5471. var top = new Toplevel ();
  5472. top.Add (_textView);
  5473. Application.Iteration += (s, a) =>
  5474. {
  5475. int width = _textView.Viewport.Width - 1;
  5476. Assert.Equal (30, width + 1);
  5477. Assert.Equal (10, _textView.Height);
  5478. var col = 0;
  5479. var leftCol = 0;
  5480. Assert.Equal (new Point (col, 0), _textView.CursorPosition);
  5481. Assert.Equal (leftCol, _textView.LeftColumn);
  5482. while (col < 100)
  5483. {
  5484. col++;
  5485. _textView.NewKeyDownEvent (Key.Tab);
  5486. Assert.Equal (new Point (col, 0), _textView.CursorPosition);
  5487. leftCol = GetLeftCol (leftCol);
  5488. Assert.Equal (leftCol, _textView.LeftColumn);
  5489. }
  5490. while (col > 0)
  5491. {
  5492. col--;
  5493. _textView.NewKeyDownEvent (Key.Tab.WithShift);
  5494. Assert.Equal (new Point (col, 0), _textView.CursorPosition);
  5495. leftCol = GetLeftCol (leftCol);
  5496. Assert.Equal (leftCol, _textView.LeftColumn);
  5497. }
  5498. top.Remove (_textView);
  5499. Application.RequestStop ();
  5500. };
  5501. Application.Run (top);
  5502. top.Dispose ();
  5503. }
  5504. [Fact]
  5505. [TextViewTestsAutoInitShutdown]
  5506. public void Tab_Test_Follow_By_CursorLeft_And_Then_Follow_By_CursorRight ()
  5507. {
  5508. var top = new Toplevel ();
  5509. top.Add (_textView);
  5510. Application.Iteration += (s, a) =>
  5511. {
  5512. int width = _textView.Viewport.Width - 1;
  5513. Assert.Equal (30, width + 1);
  5514. Assert.Equal (10, _textView.Height);
  5515. _textView.Text = "";
  5516. var col = 0;
  5517. var leftCol = 0;
  5518. int tabWidth = _textView.TabWidth;
  5519. while (col < 100)
  5520. {
  5521. col++;
  5522. _textView.NewKeyDownEvent (Key.Tab);
  5523. Assert.Equal (new Point (col, 0), _textView.CursorPosition);
  5524. leftCol = GetLeftCol (leftCol);
  5525. Assert.Equal (leftCol, _textView.LeftColumn);
  5526. }
  5527. while (col > 0)
  5528. {
  5529. col--;
  5530. _textView.NewKeyDownEvent (Key.CursorLeft);
  5531. Assert.Equal (new Point (col, 0), _textView.CursorPosition);
  5532. leftCol = GetLeftCol (leftCol);
  5533. Assert.Equal (leftCol, _textView.LeftColumn);
  5534. }
  5535. while (col < 100)
  5536. {
  5537. col++;
  5538. _textView.NewKeyDownEvent (Key.CursorRight);
  5539. Assert.Equal (new Point (col, 0), _textView.CursorPosition);
  5540. leftCol = GetLeftCol (leftCol);
  5541. Assert.Equal (leftCol, _textView.LeftColumn);
  5542. }
  5543. top.Remove (_textView);
  5544. Application.RequestStop ();
  5545. };
  5546. Application.Run (top);
  5547. top.Dispose ();
  5548. }
  5549. [Fact]
  5550. [TextViewTestsAutoInitShutdown]
  5551. public void Tab_Test_Follow_By_CursorLeft_And_Then_Follow_By_CursorRight_With_Text ()
  5552. {
  5553. var top = new Toplevel ();
  5554. top.Add (_textView);
  5555. Application.Iteration += (s, a) =>
  5556. {
  5557. int width = _textView.Viewport.Width - 1;
  5558. Assert.Equal (30, width + 1);
  5559. Assert.Equal (10, _textView.Height);
  5560. Assert.Equal ("TAB to jump between text fields.", _textView.Text);
  5561. var col = 0;
  5562. var leftCol = 0;
  5563. int tabWidth = _textView.TabWidth;
  5564. while (col < 100)
  5565. {
  5566. col++;
  5567. _textView.NewKeyDownEvent (Key.Tab);
  5568. Assert.Equal (new Point (col, 0), _textView.CursorPosition);
  5569. leftCol = GetLeftCol (leftCol);
  5570. Assert.Equal (leftCol, _textView.LeftColumn);
  5571. }
  5572. Assert.Equal (132, _textView.Text.Length);
  5573. while (col > 0)
  5574. {
  5575. col--;
  5576. _textView.NewKeyDownEvent (Key.CursorLeft);
  5577. Assert.Equal (new Point (col, 0), _textView.CursorPosition);
  5578. leftCol = GetLeftCol (leftCol);
  5579. Assert.Equal (leftCol, _textView.LeftColumn);
  5580. }
  5581. while (col < 100)
  5582. {
  5583. col++;
  5584. _textView.NewKeyDownEvent (Key.CursorRight);
  5585. Assert.Equal (new Point (col, 0), _textView.CursorPosition);
  5586. leftCol = GetLeftCol (leftCol);
  5587. Assert.Equal (leftCol, _textView.LeftColumn);
  5588. }
  5589. top.Remove (_textView);
  5590. Application.RequestStop ();
  5591. };
  5592. Application.Run (top);
  5593. top.Dispose ();
  5594. }
  5595. [Fact]
  5596. [TextViewTestsAutoInitShutdown]
  5597. public void Tab_Test_Follow_By_Home_And_Then_Follow_By_End_And_Then_Follow_By_BackTab_With_Text ()
  5598. {
  5599. var top = new Toplevel ();
  5600. top.Add (_textView);
  5601. Application.Iteration += (s, a) =>
  5602. {
  5603. int width = _textView.Viewport.Width - 1;
  5604. Assert.Equal (30, width + 1);
  5605. Assert.Equal (10, _textView.Height);
  5606. var col = 0;
  5607. var leftCol = 0;
  5608. Assert.Equal (new Point (col, 0), _textView.CursorPosition);
  5609. Assert.Equal (leftCol, _textView.LeftColumn);
  5610. Assert.Equal ("TAB to jump between text fields.", _textView.Text);
  5611. Assert.Equal (32, _textView.Text.Length);
  5612. while (col < 100)
  5613. {
  5614. col++;
  5615. _textView.NewKeyDownEvent (Key.Tab);
  5616. Assert.Equal (new Point (col, 0), _textView.CursorPosition);
  5617. leftCol = GetLeftCol (leftCol);
  5618. Assert.Equal (leftCol, _textView.LeftColumn);
  5619. }
  5620. _textView.NewKeyDownEvent (Key.Home);
  5621. col = 0;
  5622. Assert.Equal (new Point (col, 0), _textView.CursorPosition);
  5623. leftCol = 0;
  5624. Assert.Equal (leftCol, _textView.LeftColumn);
  5625. _textView.NewKeyDownEvent (Key.End);
  5626. col = _textView.Text.Length;
  5627. Assert.Equal (132, _textView.Text.Length);
  5628. Assert.Equal (new Point (col, 0), _textView.CursorPosition);
  5629. leftCol = GetLeftCol (leftCol);
  5630. Assert.Equal (leftCol, _textView.LeftColumn);
  5631. string txt = _textView.Text;
  5632. while (col - 1 > 0 && txt [col - 1] != '\t')
  5633. {
  5634. col--;
  5635. }
  5636. _textView.CursorPosition = new Point (col, 0);
  5637. leftCol = GetLeftCol (leftCol);
  5638. while (col > 0)
  5639. {
  5640. col--;
  5641. _textView.NewKeyDownEvent (Key.Tab.WithShift);
  5642. Assert.Equal (new Point (col, 0), _textView.CursorPosition);
  5643. leftCol = GetLeftCol (leftCol);
  5644. Assert.Equal (leftCol, _textView.LeftColumn);
  5645. }
  5646. Assert.Equal ("TAB to jump between text fields.", _textView.Text);
  5647. Assert.Equal (32, _textView.Text.Length);
  5648. top.Remove (_textView);
  5649. Application.RequestStop ();
  5650. };
  5651. Application.Run (top);
  5652. top.Dispose ();
  5653. }
  5654. [Fact]
  5655. [TextViewTestsAutoInitShutdown]
  5656. public void TabWidth_Setting_To_Zero_Keeps_AllowsTab ()
  5657. {
  5658. var top = new Toplevel ();
  5659. top.Add (_textView);
  5660. Application.Begin (top);
  5661. Assert.Equal (4, _textView.TabWidth);
  5662. Assert.True (_textView.AllowsTab);
  5663. Assert.True (_textView.AllowsReturn);
  5664. Assert.True (_textView.Multiline);
  5665. _textView.TabWidth = -1;
  5666. Assert.Equal (0, _textView.TabWidth);
  5667. Assert.True (_textView.AllowsTab);
  5668. Assert.True (_textView.AllowsReturn);
  5669. Assert.True (_textView.Multiline);
  5670. _textView.NewKeyDownEvent (Key.Tab);
  5671. Assert.Equal ("\tTAB to jump between text fields.", _textView.Text);
  5672. Application.Refresh ();
  5673. TestHelpers.AssertDriverContentsWithFrameAre (
  5674. @"
  5675. TAB to jump between text field",
  5676. _output
  5677. );
  5678. _textView.TabWidth = 4;
  5679. Application.Refresh ();
  5680. TestHelpers.AssertDriverContentsWithFrameAre (
  5681. @"
  5682. TAB to jump between text f",
  5683. _output
  5684. );
  5685. _textView.NewKeyDownEvent (Key.Tab.WithShift);
  5686. Assert.Equal ("TAB to jump between text fields.", _textView.Text);
  5687. Assert.True (_textView.NeedsDisplay);
  5688. Application.Refresh ();
  5689. TestHelpers.AssertDriverContentsWithFrameAre (
  5690. @"
  5691. TAB to jump between text field",
  5692. _output
  5693. );
  5694. top.Dispose ();
  5695. }
  5696. [Fact]
  5697. [TextViewTestsAutoInitShutdown]
  5698. public void TextChanged_Event ()
  5699. {
  5700. _textView.TextChanged += (s, e) =>
  5701. {
  5702. if (_textView.Text == "changing")
  5703. {
  5704. Assert.Equal ("changing", _textView.Text);
  5705. _textView.Text = "changed";
  5706. }
  5707. };
  5708. _textView.Text = "changing";
  5709. Assert.Equal ("changed", _textView.Text);
  5710. }
  5711. [Fact]
  5712. [TextViewTestsAutoInitShutdown]
  5713. public void TextChanged_Event_NoFires_OnTyping ()
  5714. {
  5715. var eventcount = 0;
  5716. _textView.TextChanged += (s, e) => { eventcount++; };
  5717. _textView.Text = "ay";
  5718. Assert.Equal (1, eventcount);
  5719. _textView.NewKeyDownEvent (Key.Y.WithShift);
  5720. Assert.Equal (1, eventcount);
  5721. Assert.Equal ("Yay", _textView.Text);
  5722. }
  5723. [Fact]
  5724. [TextViewTestsAutoInitShutdown]
  5725. public void TextView_InsertText_Newline_CRLF ()
  5726. {
  5727. var tv = new TextView { Width = 10, Height = 10 };
  5728. tv.InsertText ("\r\naaa\r\nbbb");
  5729. PlatformID p = Environment.OSVersion.Platform;
  5730. if (p == PlatformID.Win32NT || p == PlatformID.Win32S || p == PlatformID.Win32Windows)
  5731. {
  5732. Assert.Equal ("\r\naaa\r\nbbb", tv.Text);
  5733. }
  5734. else
  5735. {
  5736. Assert.Equal ("\naaa\nbbb", tv.Text);
  5737. }
  5738. Assert.Equal ($"{Environment.NewLine}aaa{Environment.NewLine}bbb", tv.Text);
  5739. var win = new Window ();
  5740. win.Add (tv);
  5741. var top = new Toplevel ();
  5742. top.Add (win);
  5743. Application.Begin (top);
  5744. ((FakeDriver)Application.Driver!).SetBufferSize (15, 15);
  5745. Application.Refresh ();
  5746. //this passes
  5747. Rectangle pos = TestHelpers.AssertDriverContentsWithFrameAre (
  5748. @"
  5749. ┌─────────────┐
  5750. │ │
  5751. │aaa │
  5752. │bbb │
  5753. │ │
  5754. │ │
  5755. │ │
  5756. │ │
  5757. │ │
  5758. │ │
  5759. │ │
  5760. │ │
  5761. │ │
  5762. │ │
  5763. └─────────────┘",
  5764. _output
  5765. );
  5766. Assert.Equal (new Rectangle (0, 0, 15, 15), pos);
  5767. Assert.True (tv.Used);
  5768. tv.Used = false;
  5769. tv.CursorPosition = Point.Empty;
  5770. tv.InsertText ("\r\naaa\r\nbbb");
  5771. Application.Refresh ();
  5772. TestHelpers.AssertDriverContentsWithFrameAre (
  5773. @"
  5774. ┌─────────────┐
  5775. │ │
  5776. │aaa │
  5777. │bbb │
  5778. │aaa │
  5779. │bbb │
  5780. │ │
  5781. │ │
  5782. │ │
  5783. │ │
  5784. │ │
  5785. │ │
  5786. │ │
  5787. │ │
  5788. └─────────────┘",
  5789. _output
  5790. );
  5791. top.Dispose ();
  5792. }
  5793. [Fact]
  5794. [TextViewTestsAutoInitShutdown]
  5795. public void TextView_InsertText_Newline_LF ()
  5796. {
  5797. var tv = new TextView { Width = 10, Height = 10 };
  5798. tv.InsertText ("\naaa\nbbb");
  5799. PlatformID p = Environment.OSVersion.Platform;
  5800. if (p == PlatformID.Win32NT || p == PlatformID.Win32S || p == PlatformID.Win32Windows)
  5801. {
  5802. Assert.Equal ("\r\naaa\r\nbbb", tv.Text);
  5803. }
  5804. else
  5805. {
  5806. Assert.Equal ("\naaa\nbbb", tv.Text);
  5807. }
  5808. Assert.Equal ($"{Environment.NewLine}aaa{Environment.NewLine}bbb", tv.Text);
  5809. var win = new Window ();
  5810. win.Add (tv);
  5811. var top = new Toplevel ();
  5812. top.Add (win);
  5813. Application.Begin (top);
  5814. ((FakeDriver)Application.Driver!).SetBufferSize (15, 15);
  5815. Application.Refresh ();
  5816. //this passes
  5817. Rectangle pos = TestHelpers.AssertDriverContentsWithFrameAre (
  5818. @"
  5819. ┌─────────────┐
  5820. │ │
  5821. │aaa │
  5822. │bbb │
  5823. │ │
  5824. │ │
  5825. │ │
  5826. │ │
  5827. │ │
  5828. │ │
  5829. │ │
  5830. │ │
  5831. │ │
  5832. │ │
  5833. └─────────────┘",
  5834. _output
  5835. );
  5836. Assert.Equal (new Rectangle (0, 0, 15, 15), pos);
  5837. Assert.True (tv.Used);
  5838. tv.Used = false;
  5839. tv.CursorPosition = Point.Empty;
  5840. tv.InsertText ("\naaa\nbbb");
  5841. Application.Refresh ();
  5842. TestHelpers.AssertDriverContentsWithFrameAre (
  5843. @"
  5844. ┌─────────────┐
  5845. │ │
  5846. │aaa │
  5847. │bbb │
  5848. │aaa │
  5849. │bbb │
  5850. │ │
  5851. │ │
  5852. │ │
  5853. │ │
  5854. │ │
  5855. │ │
  5856. │ │
  5857. │ │
  5858. └─────────────┘",
  5859. _output
  5860. );
  5861. top.Dispose ();
  5862. }
  5863. [Fact]
  5864. public void TextView_MultiLine_But_Without_Tabs ()
  5865. {
  5866. var view = new TextView ();
  5867. // the default for TextView
  5868. Assert.True (view.Multiline);
  5869. view.AllowsTab = false;
  5870. Assert.False (view.AllowsTab);
  5871. Assert.True (view.Multiline);
  5872. }
  5873. [Fact]
  5874. [TextViewTestsAutoInitShutdown]
  5875. public void TextView_SpaceHandling ()
  5876. {
  5877. var tv = new TextView { Width = 10, Text = " " };
  5878. var ev = new MouseEventArgs { Position = new (0, 0), Flags = MouseFlags.Button1DoubleClicked };
  5879. tv.NewMouseEvent (ev);
  5880. Assert.Equal (1, tv.SelectedLength);
  5881. ev = new MouseEventArgs { Position = new (1, 0), Flags = MouseFlags.Button1DoubleClicked };
  5882. tv.NewMouseEvent (ev);
  5883. Assert.Equal (1, tv.SelectedLength);
  5884. }
  5885. [Fact]
  5886. [AutoInitShutdown]
  5887. public void UnwrappedCursorPosition_Event ()
  5888. {
  5889. var cp = Point.Empty;
  5890. var tv = new TextView
  5891. {
  5892. Width = Dim.Fill (), Height = Dim.Fill (), Text = "This is the first line.\nThis is the second line.\n"
  5893. };
  5894. tv.UnwrappedCursorPosition += (s, e) => { cp = e.Point; };
  5895. var top = new Toplevel ();
  5896. top.Add (tv);
  5897. Application.Begin (top);
  5898. Application.Refresh ();
  5899. Assert.False (tv.WordWrap);
  5900. Assert.Equal (Point.Empty, tv.CursorPosition);
  5901. Assert.Equal (Point.Empty, cp);
  5902. TestHelpers.AssertDriverContentsWithFrameAre (
  5903. @"
  5904. This is the first line.
  5905. This is the second line.
  5906. ",
  5907. _output
  5908. );
  5909. tv.WordWrap = true;
  5910. tv.CursorPosition = new Point (12, 0);
  5911. tv.Draw ();
  5912. Assert.Equal (new Point (12, 0), tv.CursorPosition);
  5913. Assert.Equal (new Point (12, 0), cp);
  5914. TestHelpers.AssertDriverContentsWithFrameAre (
  5915. @"
  5916. This is the first line.
  5917. This is the second line.
  5918. ",
  5919. _output
  5920. );
  5921. ((FakeDriver)Application.Driver).SetBufferSize (6, 25);
  5922. tv.SetRelativeLayout (Application.Screen.Size);
  5923. tv.Draw ();
  5924. Assert.Equal (new Point (4, 2), tv.CursorPosition);
  5925. Assert.Equal (new Point (12, 0), cp);
  5926. TestHelpers.AssertDriverContentsWithFrameAre (
  5927. @"
  5928. This
  5929. is
  5930. the
  5931. first
  5932. line.
  5933. This
  5934. is
  5935. the
  5936. secon
  5937. d
  5938. line.
  5939. ",
  5940. _output
  5941. );
  5942. Assert.True (tv.NewKeyDownEvent (Key.CursorRight));
  5943. tv.Draw ();
  5944. Assert.Equal (new Point (0, 3), tv.CursorPosition);
  5945. Assert.Equal (new Point (12, 0), cp);
  5946. TestHelpers.AssertDriverContentsWithFrameAre (
  5947. @"
  5948. This
  5949. is
  5950. the
  5951. first
  5952. line.
  5953. This
  5954. is
  5955. the
  5956. secon
  5957. d
  5958. line.
  5959. ",
  5960. _output
  5961. );
  5962. Assert.True (tv.NewKeyDownEvent (Key.CursorRight));
  5963. tv.Draw ();
  5964. Assert.Equal (new Point (1, 3), tv.CursorPosition);
  5965. Assert.Equal (new Point (13, 0), cp);
  5966. TestHelpers.AssertDriverContentsWithFrameAre (
  5967. @"
  5968. This
  5969. is
  5970. the
  5971. first
  5972. line.
  5973. This
  5974. is
  5975. the
  5976. secon
  5977. d
  5978. line.
  5979. ",
  5980. _output
  5981. );
  5982. Assert.True (tv.NewMouseEvent (new MouseEventArgs { Position = new (0, 3), Flags = MouseFlags.Button1Pressed }));
  5983. tv.Draw ();
  5984. Assert.Equal (new Point (0, 3), tv.CursorPosition);
  5985. Assert.Equal (new Point (13, 0), cp);
  5986. TestHelpers.AssertDriverContentsWithFrameAre (
  5987. @"
  5988. This
  5989. is
  5990. the
  5991. first
  5992. line.
  5993. This
  5994. is
  5995. the
  5996. secon
  5997. d
  5998. line.
  5999. ",
  6000. _output
  6001. );
  6002. top.Dispose ();
  6003. }
  6004. [Fact]
  6005. [TextViewTestsAutoInitShutdown]
  6006. public void Used_Is_False ()
  6007. {
  6008. _textView.Used = false;
  6009. _textView.CursorPosition = new Point (10, 0);
  6010. Assert.Equal ("TAB to jump between text fields.", _textView.Text);
  6011. _textView.NewKeyDownEvent (Key.U); // u
  6012. Assert.Equal ("TAB to jumu between text fields.", _textView.Text);
  6013. _textView.NewKeyDownEvent (Key.S); // s
  6014. Assert.Equal ("TAB to jumusbetween text fields.", _textView.Text);
  6015. _textView.NewKeyDownEvent (Key.E); // e
  6016. Assert.Equal ("TAB to jumuseetween text fields.", _textView.Text);
  6017. _textView.NewKeyDownEvent (Key.D); // d
  6018. Assert.Equal ("TAB to jumusedtween text fields.", _textView.Text);
  6019. }
  6020. [Fact]
  6021. [TextViewTestsAutoInitShutdown]
  6022. public void Used_Is_True_By_Default ()
  6023. {
  6024. _textView.CursorPosition = new Point (10, 0);
  6025. Assert.Equal ("TAB to jump between text fields.", _textView.Text);
  6026. _textView.NewKeyDownEvent (Key.U); // u
  6027. Assert.Equal ("TAB to jumup between text fields.", _textView.Text);
  6028. _textView.NewKeyDownEvent (Key.S); // s
  6029. Assert.Equal ("TAB to jumusp between text fields.", _textView.Text);
  6030. _textView.NewKeyDownEvent (Key.E); // e
  6031. Assert.Equal ("TAB to jumusep between text fields.", _textView.Text);
  6032. _textView.NewKeyDownEvent (Key.D); // d
  6033. Assert.Equal ("TAB to jumusedp between text fields.", _textView.Text);
  6034. }
  6035. [Fact]
  6036. [TextViewTestsAutoInitShutdown]
  6037. public void WordBackward_Multiline_With_Selection ()
  6038. {
  6039. // 4 3 2 1
  6040. // 87654321098765432109876 54321098765432109876543210-Length
  6041. // 1 2 1 2
  6042. // 01234567890123456789012 0123456789012345678901234
  6043. _textView.Text = "This is the first line.\nThis is the second line.";
  6044. _textView.MoveEnd ();
  6045. _textView.SelectionStartColumn = _textView.CurrentColumn;
  6046. _textView.SelectionStartRow = _textView.CurrentRow;
  6047. var iteration = 0;
  6048. var iterationsFinished = false;
  6049. while (!iterationsFinished)
  6050. {
  6051. _textView.NewKeyDownEvent (Key.CursorLeft.WithCtrl.WithShift);
  6052. switch (iteration)
  6053. {
  6054. case 0:
  6055. Assert.Equal (23, _textView.CursorPosition.X);
  6056. Assert.Equal (1, _textView.CursorPosition.Y);
  6057. Assert.Equal (24, _textView.SelectionStartColumn);
  6058. Assert.Equal (1, _textView.SelectionStartRow);
  6059. Assert.Equal (1, _textView.SelectedLength);
  6060. Assert.Equal (".", _textView.SelectedText);
  6061. break;
  6062. case 1:
  6063. Assert.Equal (19, _textView.CursorPosition.X);
  6064. Assert.Equal (1, _textView.CursorPosition.Y);
  6065. Assert.Equal (24, _textView.SelectionStartColumn);
  6066. Assert.Equal (1, _textView.SelectionStartRow);
  6067. Assert.Equal (5, _textView.SelectedLength);
  6068. Assert.Equal ("line.", _textView.SelectedText);
  6069. break;
  6070. case 2:
  6071. Assert.Equal (12, _textView.CursorPosition.X);
  6072. Assert.Equal (1, _textView.CursorPosition.Y);
  6073. Assert.Equal (24, _textView.SelectionStartColumn);
  6074. Assert.Equal (1, _textView.SelectionStartRow);
  6075. Assert.Equal (12, _textView.SelectedLength);
  6076. Assert.Equal ("second line.", _textView.SelectedText);
  6077. break;
  6078. case 3:
  6079. Assert.Equal (8, _textView.CursorPosition.X);
  6080. Assert.Equal (1, _textView.CursorPosition.Y);
  6081. Assert.Equal (24, _textView.SelectionStartColumn);
  6082. Assert.Equal (1, _textView.SelectionStartRow);
  6083. Assert.Equal (16, _textView.SelectedLength);
  6084. Assert.Equal ("the second line.", _textView.SelectedText);
  6085. break;
  6086. case 4:
  6087. Assert.Equal (5, _textView.CursorPosition.X);
  6088. Assert.Equal (1, _textView.CursorPosition.Y);
  6089. Assert.Equal (24, _textView.SelectionStartColumn);
  6090. Assert.Equal (1, _textView.SelectionStartRow);
  6091. Assert.Equal (19, _textView.SelectedLength);
  6092. Assert.Equal ("is the second line.", _textView.SelectedText);
  6093. break;
  6094. case 5:
  6095. Assert.Equal (0, _textView.CursorPosition.X);
  6096. Assert.Equal (1, _textView.CursorPosition.Y);
  6097. Assert.Equal (24, _textView.SelectionStartColumn);
  6098. Assert.Equal (1, _textView.SelectionStartRow);
  6099. Assert.Equal (24, _textView.SelectedLength);
  6100. Assert.Equal ("This is the second line.", _textView.SelectedText);
  6101. break;
  6102. case 6:
  6103. Assert.Equal (23, _textView.CursorPosition.X);
  6104. Assert.Equal (0, _textView.CursorPosition.Y);
  6105. Assert.Equal (24, _textView.SelectionStartColumn);
  6106. Assert.Equal (1, _textView.SelectionStartRow);
  6107. Assert.Equal (24 + Environment.NewLine.Length, _textView.SelectedLength);
  6108. Assert.Equal ($"{Environment.NewLine}This is the second line.", _textView.SelectedText);
  6109. break;
  6110. case 7:
  6111. Assert.Equal (22, _textView.CursorPosition.X);
  6112. Assert.Equal (0, _textView.CursorPosition.Y);
  6113. Assert.Equal (24, _textView.SelectionStartColumn);
  6114. Assert.Equal (1, _textView.SelectionStartRow);
  6115. Assert.Equal (25 + Environment.NewLine.Length, _textView.SelectedLength);
  6116. Assert.Equal (
  6117. $".{Environment.NewLine}This is the second line.",
  6118. _textView.SelectedText
  6119. );
  6120. break;
  6121. case 8:
  6122. Assert.Equal (18, _textView.CursorPosition.X);
  6123. Assert.Equal (0, _textView.CursorPosition.Y);
  6124. Assert.Equal (24, _textView.SelectionStartColumn);
  6125. Assert.Equal (1, _textView.SelectionStartRow);
  6126. Assert.Equal (29 + Environment.NewLine.Length, _textView.SelectedLength);
  6127. Assert.Equal (
  6128. $"line.{Environment.NewLine}This is the second line.",
  6129. _textView.SelectedText
  6130. );
  6131. break;
  6132. case 9:
  6133. Assert.Equal (12, _textView.CursorPosition.X);
  6134. Assert.Equal (0, _textView.CursorPosition.Y);
  6135. Assert.Equal (24, _textView.SelectionStartColumn);
  6136. Assert.Equal (1, _textView.SelectionStartRow);
  6137. Assert.Equal (35 + Environment.NewLine.Length, _textView.SelectedLength);
  6138. Assert.Equal (
  6139. $"first line.{Environment.NewLine}This is the second line.",
  6140. _textView.SelectedText
  6141. );
  6142. break;
  6143. case 10:
  6144. Assert.Equal (8, _textView.CursorPosition.X);
  6145. Assert.Equal (0, _textView.CursorPosition.Y);
  6146. Assert.Equal (24, _textView.SelectionStartColumn);
  6147. Assert.Equal (1, _textView.SelectionStartRow);
  6148. Assert.Equal (39 + Environment.NewLine.Length, _textView.SelectedLength);
  6149. Assert.Equal (
  6150. $"the first line.{Environment.NewLine}This is the second line.",
  6151. _textView.SelectedText
  6152. );
  6153. break;
  6154. case 11:
  6155. Assert.Equal (5, _textView.CursorPosition.X);
  6156. Assert.Equal (0, _textView.CursorPosition.Y);
  6157. Assert.Equal (24, _textView.SelectionStartColumn);
  6158. Assert.Equal (1, _textView.SelectionStartRow);
  6159. Assert.Equal (42 + Environment.NewLine.Length, _textView.SelectedLength);
  6160. Assert.Equal (
  6161. $"is the first line.{Environment.NewLine}This is the second line.",
  6162. _textView.SelectedText
  6163. );
  6164. break;
  6165. case 12:
  6166. Assert.Equal (0, _textView.CursorPosition.X);
  6167. Assert.Equal (0, _textView.CursorPosition.Y);
  6168. Assert.Equal (24, _textView.SelectionStartColumn);
  6169. Assert.Equal (1, _textView.SelectionStartRow);
  6170. Assert.Equal (47 + Environment.NewLine.Length, _textView.SelectedLength);
  6171. Assert.Equal (
  6172. $"This is the first line.{Environment.NewLine}This is the second line.",
  6173. _textView.SelectedText
  6174. );
  6175. break;
  6176. default:
  6177. iterationsFinished = true;
  6178. break;
  6179. }
  6180. iteration++;
  6181. }
  6182. }
  6183. [Fact]
  6184. [TextViewTestsAutoInitShutdown]
  6185. public void WordBackward_With_No_Selection ()
  6186. {
  6187. _textView.CursorPosition = new Point (_textView.Text.Length, 0);
  6188. var iteration = 0;
  6189. while (_textView.CursorPosition.X > 0)
  6190. {
  6191. _textView.NewKeyDownEvent (Key.CursorLeft.WithCtrl);
  6192. switch (iteration)
  6193. {
  6194. case 0:
  6195. Assert.Equal (31, _textView.CursorPosition.X);
  6196. Assert.Equal (0, _textView.CursorPosition.Y);
  6197. Assert.Equal (0, _textView.SelectionStartColumn);
  6198. Assert.Equal (0, _textView.SelectionStartRow);
  6199. Assert.Equal (0, _textView.SelectedLength);
  6200. Assert.Equal ("", _textView.SelectedText);
  6201. break;
  6202. case 1:
  6203. Assert.Equal (25, _textView.CursorPosition.X);
  6204. Assert.Equal (0, _textView.CursorPosition.Y);
  6205. Assert.Equal (0, _textView.SelectionStartColumn);
  6206. Assert.Equal (0, _textView.SelectionStartRow);
  6207. Assert.Equal (0, _textView.SelectedLength);
  6208. Assert.Equal ("", _textView.SelectedText);
  6209. break;
  6210. case 2:
  6211. Assert.Equal (20, _textView.CursorPosition.X);
  6212. Assert.Equal (0, _textView.CursorPosition.Y);
  6213. Assert.Equal (0, _textView.SelectionStartColumn);
  6214. Assert.Equal (0, _textView.SelectionStartRow);
  6215. Assert.Equal (0, _textView.SelectedLength);
  6216. Assert.Equal ("", _textView.SelectedText);
  6217. break;
  6218. case 3:
  6219. Assert.Equal (12, _textView.CursorPosition.X);
  6220. Assert.Equal (0, _textView.CursorPosition.Y);
  6221. Assert.Equal (0, _textView.SelectionStartColumn);
  6222. Assert.Equal (0, _textView.SelectionStartRow);
  6223. Assert.Equal (0, _textView.SelectedLength);
  6224. Assert.Equal ("", _textView.SelectedText);
  6225. break;
  6226. case 4:
  6227. Assert.Equal (7, _textView.CursorPosition.X);
  6228. Assert.Equal (0, _textView.CursorPosition.Y);
  6229. Assert.Equal (0, _textView.SelectionStartColumn);
  6230. Assert.Equal (0, _textView.SelectionStartRow);
  6231. Assert.Equal (0, _textView.SelectedLength);
  6232. Assert.Equal ("", _textView.SelectedText);
  6233. break;
  6234. case 5:
  6235. Assert.Equal (4, _textView.CursorPosition.X);
  6236. Assert.Equal (0, _textView.CursorPosition.Y);
  6237. Assert.Equal (0, _textView.SelectionStartColumn);
  6238. Assert.Equal (0, _textView.SelectionStartRow);
  6239. Assert.Equal (0, _textView.SelectedLength);
  6240. Assert.Equal ("", _textView.SelectedText);
  6241. break;
  6242. case 6:
  6243. Assert.Equal (0, _textView.CursorPosition.X);
  6244. Assert.Equal (0, _textView.CursorPosition.Y);
  6245. Assert.Equal (0, _textView.SelectionStartColumn);
  6246. Assert.Equal (0, _textView.SelectionStartRow);
  6247. Assert.Equal (0, _textView.SelectedLength);
  6248. Assert.Equal ("", _textView.SelectedText);
  6249. break;
  6250. }
  6251. iteration++;
  6252. }
  6253. }
  6254. [Fact]
  6255. [TextViewTestsAutoInitShutdown]
  6256. public void WordBackward_With_No_Selection_And_With_More_Than_Only_One_Whitespace_And_With_Only_One_Letter ()
  6257. {
  6258. // 1 2 3 4 5
  6259. // 0123456789012345678901234567890123456789012345678901234=55 (Length)
  6260. _textView.Text = "TAB t o jump b etween t ext f ields .";
  6261. _textView.CursorPosition = new Point (_textView.Text.Length, 0);
  6262. var iteration = 0;
  6263. while (_textView.CursorPosition.X > 0)
  6264. {
  6265. _textView.NewKeyDownEvent (Key.CursorLeft.WithCtrl);
  6266. switch (iteration)
  6267. {
  6268. case 0:
  6269. Assert.Equal (54, _textView.CursorPosition.X);
  6270. Assert.Equal (0, _textView.CursorPosition.Y);
  6271. Assert.Equal (0, _textView.SelectionStartColumn);
  6272. Assert.Equal (0, _textView.SelectionStartRow);
  6273. Assert.Equal (0, _textView.SelectedLength);
  6274. Assert.Equal ("", _textView.SelectedText);
  6275. break;
  6276. case 1:
  6277. Assert.Equal (48, _textView.CursorPosition.X);
  6278. Assert.Equal (0, _textView.CursorPosition.Y);
  6279. Assert.Equal (0, _textView.SelectionStartColumn);
  6280. Assert.Equal (0, _textView.SelectionStartRow);
  6281. Assert.Equal (0, _textView.SelectedLength);
  6282. Assert.Equal ("", _textView.SelectedText);
  6283. break;
  6284. case 2:
  6285. Assert.Equal (46, _textView.CursorPosition.X);
  6286. Assert.Equal (0, _textView.CursorPosition.Y);
  6287. Assert.Equal (0, _textView.SelectionStartColumn);
  6288. Assert.Equal (0, _textView.SelectionStartRow);
  6289. Assert.Equal (0, _textView.SelectedLength);
  6290. Assert.Equal ("", _textView.SelectedText);
  6291. break;
  6292. case 3:
  6293. Assert.Equal (40, _textView.CursorPosition.X);
  6294. Assert.Equal (0, _textView.CursorPosition.Y);
  6295. Assert.Equal (0, _textView.SelectionStartColumn);
  6296. Assert.Equal (0, _textView.SelectionStartRow);
  6297. Assert.Equal (0, _textView.SelectedLength);
  6298. Assert.Equal ("", _textView.SelectedText);
  6299. break;
  6300. case 4:
  6301. Assert.Equal (38, _textView.CursorPosition.X);
  6302. Assert.Equal (0, _textView.CursorPosition.Y);
  6303. Assert.Equal (0, _textView.SelectionStartColumn);
  6304. Assert.Equal (0, _textView.SelectionStartRow);
  6305. Assert.Equal (0, _textView.SelectedLength);
  6306. Assert.Equal ("", _textView.SelectedText);
  6307. break;
  6308. case 5:
  6309. Assert.Equal (28, _textView.CursorPosition.X);
  6310. Assert.Equal (0, _textView.CursorPosition.Y);
  6311. Assert.Equal (0, _textView.SelectionStartColumn);
  6312. Assert.Equal (0, _textView.SelectionStartRow);
  6313. Assert.Equal (0, _textView.SelectedLength);
  6314. Assert.Equal ("", _textView.SelectedText);
  6315. break;
  6316. case 6:
  6317. Assert.Equal (25, _textView.CursorPosition.X);
  6318. Assert.Equal (0, _textView.CursorPosition.Y);
  6319. Assert.Equal (0, _textView.SelectionStartColumn);
  6320. Assert.Equal (0, _textView.SelectionStartRow);
  6321. Assert.Equal (0, _textView.SelectedLength);
  6322. Assert.Equal ("", _textView.SelectedText);
  6323. break;
  6324. case 7:
  6325. Assert.Equal (12, _textView.CursorPosition.X);
  6326. Assert.Equal (0, _textView.CursorPosition.Y);
  6327. Assert.Equal (0, _textView.SelectionStartColumn);
  6328. Assert.Equal (0, _textView.SelectionStartRow);
  6329. Assert.Equal (0, _textView.SelectedLength);
  6330. Assert.Equal ("", _textView.SelectedText);
  6331. break;
  6332. case 8:
  6333. Assert.Equal (9, _textView.CursorPosition.X);
  6334. Assert.Equal (0, _textView.CursorPosition.Y);
  6335. Assert.Equal (0, _textView.SelectionStartColumn);
  6336. Assert.Equal (0, _textView.SelectionStartRow);
  6337. Assert.Equal (0, _textView.SelectedLength);
  6338. Assert.Equal ("", _textView.SelectedText);
  6339. break;
  6340. case 9:
  6341. Assert.Equal (6, _textView.CursorPosition.X);
  6342. Assert.Equal (0, _textView.CursorPosition.Y);
  6343. Assert.Equal (0, _textView.SelectionStartColumn);
  6344. Assert.Equal (0, _textView.SelectionStartRow);
  6345. Assert.Equal (0, _textView.SelectedLength);
  6346. Assert.Equal ("", _textView.SelectedText);
  6347. break;
  6348. case 10:
  6349. Assert.Equal (0, _textView.CursorPosition.X);
  6350. Assert.Equal (0, _textView.CursorPosition.Y);
  6351. Assert.Equal (0, _textView.SelectionStartColumn);
  6352. Assert.Equal (0, _textView.SelectionStartRow);
  6353. Assert.Equal (0, _textView.SelectedLength);
  6354. Assert.Equal ("", _textView.SelectedText);
  6355. break;
  6356. }
  6357. iteration++;
  6358. }
  6359. }
  6360. [Fact]
  6361. [TextViewTestsAutoInitShutdown]
  6362. public void WordBackward_With_Selection ()
  6363. {
  6364. _textView.CursorPosition = new Point (_textView.Text.Length, 0);
  6365. _textView.SelectionStartColumn = _textView.Text.Length;
  6366. _textView.SelectionStartRow = 0;
  6367. var iteration = 0;
  6368. while (_textView.CursorPosition.X > 0)
  6369. {
  6370. _textView.NewKeyDownEvent (Key.CursorLeft.WithCtrl.WithShift);
  6371. switch (iteration)
  6372. {
  6373. case 0:
  6374. Assert.Equal (31, _textView.CursorPosition.X);
  6375. Assert.Equal (0, _textView.CursorPosition.Y);
  6376. Assert.Equal (32, _textView.SelectionStartColumn);
  6377. Assert.Equal (0, _textView.SelectionStartRow);
  6378. Assert.Equal (1, _textView.SelectedLength);
  6379. Assert.Equal (".", _textView.SelectedText);
  6380. break;
  6381. case 1:
  6382. Assert.Equal (25, _textView.CursorPosition.X);
  6383. Assert.Equal (0, _textView.CursorPosition.Y);
  6384. Assert.Equal (32, _textView.SelectionStartColumn);
  6385. Assert.Equal (0, _textView.SelectionStartRow);
  6386. Assert.Equal (7, _textView.SelectedLength);
  6387. Assert.Equal ("fields.", _textView.SelectedText);
  6388. break;
  6389. case 2:
  6390. Assert.Equal (20, _textView.CursorPosition.X);
  6391. Assert.Equal (0, _textView.CursorPosition.Y);
  6392. Assert.Equal (32, _textView.SelectionStartColumn);
  6393. Assert.Equal (0, _textView.SelectionStartRow);
  6394. Assert.Equal (12, _textView.SelectedLength);
  6395. Assert.Equal ("text fields.", _textView.SelectedText);
  6396. break;
  6397. case 3:
  6398. Assert.Equal (12, _textView.CursorPosition.X);
  6399. Assert.Equal (0, _textView.CursorPosition.Y);
  6400. Assert.Equal (32, _textView.SelectionStartColumn);
  6401. Assert.Equal (0, _textView.SelectionStartRow);
  6402. Assert.Equal (20, _textView.SelectedLength);
  6403. Assert.Equal ("between text fields.", _textView.SelectedText);
  6404. break;
  6405. case 4:
  6406. Assert.Equal (7, _textView.CursorPosition.X);
  6407. Assert.Equal (0, _textView.CursorPosition.Y);
  6408. Assert.Equal (32, _textView.SelectionStartColumn);
  6409. Assert.Equal (0, _textView.SelectionStartRow);
  6410. Assert.Equal (25, _textView.SelectedLength);
  6411. Assert.Equal ("jump between text fields.", _textView.SelectedText);
  6412. break;
  6413. case 5:
  6414. Assert.Equal (4, _textView.CursorPosition.X);
  6415. Assert.Equal (0, _textView.CursorPosition.Y);
  6416. Assert.Equal (32, _textView.SelectionStartColumn);
  6417. Assert.Equal (0, _textView.SelectionStartRow);
  6418. Assert.Equal (28, _textView.SelectedLength);
  6419. Assert.Equal ("to jump between text fields.", _textView.SelectedText);
  6420. break;
  6421. case 6:
  6422. Assert.Equal (0, _textView.CursorPosition.X);
  6423. Assert.Equal (0, _textView.CursorPosition.Y);
  6424. Assert.Equal (32, _textView.SelectionStartColumn);
  6425. Assert.Equal (0, _textView.SelectionStartRow);
  6426. Assert.Equal (32, _textView.SelectedLength);
  6427. Assert.Equal ("TAB to jump between text fields.", _textView.SelectedText);
  6428. break;
  6429. }
  6430. iteration++;
  6431. }
  6432. }
  6433. [Fact]
  6434. [TextViewTestsAutoInitShutdown]
  6435. public void
  6436. WordBackward_With_The_Same_Values_For_SelectedStart_And_CursorPosition_And_Not_Starting_At_Beginning_Of_The_Text ()
  6437. {
  6438. _textView.CursorPosition = new Point (10, 0);
  6439. _textView.SelectionStartColumn = 10;
  6440. _textView.SelectionStartRow = 0;
  6441. var iteration = 0;
  6442. while (_textView.CursorPosition.X > 0)
  6443. {
  6444. _textView.NewKeyDownEvent (Key.CursorLeft.WithCtrl.WithShift);
  6445. switch (iteration)
  6446. {
  6447. case 0:
  6448. Assert.Equal (7, _textView.CursorPosition.X);
  6449. Assert.Equal (0, _textView.CursorPosition.Y);
  6450. Assert.Equal (10, _textView.SelectionStartColumn);
  6451. Assert.Equal (0, _textView.SelectionStartRow);
  6452. Assert.Equal (3, _textView.SelectedLength);
  6453. Assert.Equal ("jum", _textView.SelectedText);
  6454. break;
  6455. case 1:
  6456. Assert.Equal (4, _textView.CursorPosition.X);
  6457. Assert.Equal (0, _textView.CursorPosition.Y);
  6458. Assert.Equal (10, _textView.SelectionStartColumn);
  6459. Assert.Equal (0, _textView.SelectionStartRow);
  6460. Assert.Equal (6, _textView.SelectedLength);
  6461. Assert.Equal ("to jum", _textView.SelectedText);
  6462. break;
  6463. case 2:
  6464. Assert.Equal (0, _textView.CursorPosition.X);
  6465. Assert.Equal (0, _textView.CursorPosition.Y);
  6466. Assert.Equal (10, _textView.SelectionStartColumn);
  6467. Assert.Equal (0, _textView.SelectionStartRow);
  6468. Assert.Equal (10, _textView.SelectedLength);
  6469. Assert.Equal ("TAB to jum", _textView.SelectedText);
  6470. break;
  6471. }
  6472. iteration++;
  6473. }
  6474. }
  6475. [Fact]
  6476. public void WordBackward_WordForward_Limits_Return_Null ()
  6477. {
  6478. var model = new TextModel ();
  6479. model.LoadString ("Test");
  6480. (int col, int row)? newPos = model.WordBackward (0, 0);
  6481. Assert.Null (newPos);
  6482. newPos = model.WordForward (4, 0);
  6483. Assert.Null (newPos);
  6484. }
  6485. [Fact]
  6486. [TextViewTestsAutoInitShutdown]
  6487. public void WordForward_Multiline_With_Selection ()
  6488. {
  6489. // 1 2 3 4
  6490. // 01234567890123456789012 34567890123456789012345678-Length
  6491. // 1 2 1 2
  6492. // 01234567890123456789012 0123456789012345678901234
  6493. _textView.Text = "This is the first line.\nThis is the second line.";
  6494. _textView.SelectionStartColumn = _textView.CurrentColumn;
  6495. _textView.SelectionStartRow = _textView.CurrentRow;
  6496. var iteration = 0;
  6497. var iterationsFinished = false;
  6498. while (!iterationsFinished)
  6499. {
  6500. _textView.NewKeyDownEvent (
  6501. new Key (
  6502. KeyCode.CursorRight | KeyCode.CtrlMask | KeyCode.ShiftMask
  6503. )
  6504. );
  6505. switch (iteration)
  6506. {
  6507. case 0:
  6508. Assert.Equal (5, _textView.CursorPosition.X);
  6509. Assert.Equal (0, _textView.CursorPosition.Y);
  6510. Assert.Equal (0, _textView.SelectionStartColumn);
  6511. Assert.Equal (0, _textView.SelectionStartRow);
  6512. Assert.Equal (5, _textView.SelectedLength);
  6513. Assert.Equal ("This ", _textView.SelectedText);
  6514. break;
  6515. case 1:
  6516. Assert.Equal (8, _textView.CursorPosition.X);
  6517. Assert.Equal (0, _textView.CursorPosition.Y);
  6518. Assert.Equal (0, _textView.SelectionStartColumn);
  6519. Assert.Equal (0, _textView.SelectionStartRow);
  6520. Assert.Equal (8, _textView.SelectedLength);
  6521. Assert.Equal ("This is ", _textView.SelectedText);
  6522. break;
  6523. case 2:
  6524. Assert.Equal (12, _textView.CursorPosition.X);
  6525. Assert.Equal (0, _textView.CursorPosition.Y);
  6526. Assert.Equal (0, _textView.SelectionStartColumn);
  6527. Assert.Equal (0, _textView.SelectionStartRow);
  6528. Assert.Equal (12, _textView.SelectedLength);
  6529. Assert.Equal ("This is the ", _textView.SelectedText);
  6530. break;
  6531. case 3:
  6532. Assert.Equal (18, _textView.CursorPosition.X);
  6533. Assert.Equal (0, _textView.CursorPosition.Y);
  6534. Assert.Equal (0, _textView.SelectionStartColumn);
  6535. Assert.Equal (0, _textView.SelectionStartRow);
  6536. Assert.Equal (18, _textView.SelectedLength);
  6537. Assert.Equal ("This is the first ", _textView.SelectedText);
  6538. break;
  6539. case 4:
  6540. Assert.Equal (23, _textView.CursorPosition.X);
  6541. Assert.Equal (0, _textView.CursorPosition.Y);
  6542. Assert.Equal (0, _textView.SelectionStartColumn);
  6543. Assert.Equal (0, _textView.SelectionStartRow);
  6544. Assert.Equal (23, _textView.SelectedLength);
  6545. Assert.Equal ("This is the first line.", _textView.SelectedText);
  6546. break;
  6547. case 5:
  6548. Assert.Equal (0, _textView.CursorPosition.X);
  6549. Assert.Equal (1, _textView.CursorPosition.Y);
  6550. Assert.Equal (0, _textView.SelectionStartColumn);
  6551. Assert.Equal (0, _textView.SelectionStartRow);
  6552. Assert.Equal (23 + Environment.NewLine.Length, _textView.SelectedLength);
  6553. Assert.Equal ($"This is the first line.{Environment.NewLine}", _textView.SelectedText);
  6554. break;
  6555. case 6:
  6556. Assert.Equal (5, _textView.CursorPosition.X);
  6557. Assert.Equal (1, _textView.CursorPosition.Y);
  6558. Assert.Equal (0, _textView.SelectionStartColumn);
  6559. Assert.Equal (0, _textView.SelectionStartRow);
  6560. Assert.Equal (28 + Environment.NewLine.Length, _textView.SelectedLength);
  6561. Assert.Equal (
  6562. $"This is the first line.{Environment.NewLine}This ",
  6563. _textView.SelectedText
  6564. );
  6565. break;
  6566. case 7:
  6567. Assert.Equal (8, _textView.CursorPosition.X);
  6568. Assert.Equal (1, _textView.CursorPosition.Y);
  6569. Assert.Equal (0, _textView.SelectionStartColumn);
  6570. Assert.Equal (0, _textView.SelectionStartRow);
  6571. Assert.Equal (31 + Environment.NewLine.Length, _textView.SelectedLength);
  6572. Assert.Equal (
  6573. $"This is the first line.{Environment.NewLine}This is ",
  6574. _textView.SelectedText
  6575. );
  6576. break;
  6577. case 8:
  6578. Assert.Equal (12, _textView.CursorPosition.X);
  6579. Assert.Equal (1, _textView.CursorPosition.Y);
  6580. Assert.Equal (0, _textView.SelectionStartColumn);
  6581. Assert.Equal (0, _textView.SelectionStartRow);
  6582. Assert.Equal (35 + Environment.NewLine.Length, _textView.SelectedLength);
  6583. Assert.Equal (
  6584. $"This is the first line.{Environment.NewLine}This is the ",
  6585. _textView.SelectedText
  6586. );
  6587. break;
  6588. case 9:
  6589. Assert.Equal (19, _textView.CursorPosition.X);
  6590. Assert.Equal (1, _textView.CursorPosition.Y);
  6591. Assert.Equal (0, _textView.SelectionStartColumn);
  6592. Assert.Equal (0, _textView.SelectionStartRow);
  6593. Assert.Equal (42 + Environment.NewLine.Length, _textView.SelectedLength);
  6594. Assert.Equal (
  6595. $"This is the first line.{Environment.NewLine}This is the second ",
  6596. _textView.SelectedText
  6597. );
  6598. break;
  6599. case 10:
  6600. Assert.Equal (24, _textView.CursorPosition.X);
  6601. Assert.Equal (1, _textView.CursorPosition.Y);
  6602. Assert.Equal (0, _textView.SelectionStartColumn);
  6603. Assert.Equal (0, _textView.SelectionStartRow);
  6604. Assert.Equal (47 + Environment.NewLine.Length, _textView.SelectedLength);
  6605. Assert.Equal (
  6606. $"This is the first line.{Environment.NewLine}This is the second line.",
  6607. _textView.SelectedText
  6608. );
  6609. break;
  6610. default:
  6611. iterationsFinished = true;
  6612. break;
  6613. }
  6614. iteration++;
  6615. }
  6616. }
  6617. [Fact]
  6618. [TextViewTestsAutoInitShutdown]
  6619. public void WordForward_With_No_Selection ()
  6620. {
  6621. _textView.CursorPosition = Point.Empty;
  6622. var iteration = 0;
  6623. while (_textView.CursorPosition.X < _textView.Text.Length)
  6624. {
  6625. _textView.NewKeyDownEvent (Key.CursorRight.WithCtrl);
  6626. switch (iteration)
  6627. {
  6628. case 0:
  6629. Assert.Equal (4, _textView.CursorPosition.X);
  6630. Assert.Equal (0, _textView.CursorPosition.Y);
  6631. Assert.Equal (0, _textView.SelectionStartColumn);
  6632. Assert.Equal (0, _textView.SelectionStartRow);
  6633. Assert.Equal (0, _textView.SelectedLength);
  6634. Assert.Equal ("", _textView.SelectedText);
  6635. break;
  6636. case 1:
  6637. Assert.Equal (7, _textView.CursorPosition.X);
  6638. Assert.Equal (0, _textView.CursorPosition.Y);
  6639. Assert.Equal (0, _textView.SelectionStartColumn);
  6640. Assert.Equal (0, _textView.SelectionStartRow);
  6641. Assert.Equal (0, _textView.SelectedLength);
  6642. Assert.Equal ("", _textView.SelectedText);
  6643. break;
  6644. case 2:
  6645. Assert.Equal (12, _textView.CursorPosition.X);
  6646. Assert.Equal (0, _textView.CursorPosition.Y);
  6647. Assert.Equal (0, _textView.SelectionStartColumn);
  6648. Assert.Equal (0, _textView.SelectionStartRow);
  6649. Assert.Equal (0, _textView.SelectedLength);
  6650. Assert.Equal ("", _textView.SelectedText);
  6651. break;
  6652. case 3:
  6653. Assert.Equal (20, _textView.CursorPosition.X);
  6654. Assert.Equal (0, _textView.CursorPosition.Y);
  6655. Assert.Equal (0, _textView.SelectionStartColumn);
  6656. Assert.Equal (0, _textView.SelectionStartRow);
  6657. Assert.Equal (0, _textView.SelectedLength);
  6658. Assert.Equal ("", _textView.SelectedText);
  6659. break;
  6660. case 4:
  6661. Assert.Equal (25, _textView.CursorPosition.X);
  6662. Assert.Equal (0, _textView.CursorPosition.Y);
  6663. Assert.Equal (0, _textView.SelectionStartColumn);
  6664. Assert.Equal (0, _textView.SelectionStartRow);
  6665. Assert.Equal (0, _textView.SelectedLength);
  6666. Assert.Equal ("", _textView.SelectedText);
  6667. break;
  6668. case 5:
  6669. Assert.Equal (32, _textView.CursorPosition.X);
  6670. Assert.Equal (0, _textView.CursorPosition.Y);
  6671. Assert.Equal (0, _textView.SelectionStartColumn);
  6672. Assert.Equal (0, _textView.SelectionStartRow);
  6673. Assert.Equal (0, _textView.SelectedLength);
  6674. Assert.Equal ("", _textView.SelectedText);
  6675. break;
  6676. }
  6677. iteration++;
  6678. }
  6679. }
  6680. [Fact]
  6681. [TextViewTestsAutoInitShutdown]
  6682. public void WordForward_With_No_Selection_And_With_More_Than_Only_One_Whitespace_And_With_Only_One_Letter ()
  6683. {
  6684. // 1 2 3 4 5
  6685. // 0123456789012345678901234567890123456789012345678901234=55 (Length)
  6686. _textView.Text = "TAB t o jump b etween t ext f ields .";
  6687. _textView.CursorPosition = Point.Empty;
  6688. var iteration = 0;
  6689. while (_textView.CursorPosition.X < _textView.Text.Length)
  6690. {
  6691. _textView.NewKeyDownEvent (Key.CursorRight.WithCtrl);
  6692. switch (iteration)
  6693. {
  6694. case 0:
  6695. Assert.Equal (6, _textView.CursorPosition.X);
  6696. Assert.Equal (0, _textView.CursorPosition.Y);
  6697. Assert.Equal (0, _textView.SelectionStartColumn);
  6698. Assert.Equal (0, _textView.SelectionStartRow);
  6699. Assert.Equal (0, _textView.SelectedLength);
  6700. Assert.Equal ("", _textView.SelectedText);
  6701. break;
  6702. case 1:
  6703. Assert.Equal (9, _textView.CursorPosition.X);
  6704. Assert.Equal (0, _textView.CursorPosition.Y);
  6705. Assert.Equal (0, _textView.SelectionStartColumn);
  6706. Assert.Equal (0, _textView.SelectionStartRow);
  6707. Assert.Equal (0, _textView.SelectedLength);
  6708. Assert.Equal ("", _textView.SelectedText);
  6709. break;
  6710. case 2:
  6711. Assert.Equal (12, _textView.CursorPosition.X);
  6712. Assert.Equal (0, _textView.CursorPosition.Y);
  6713. Assert.Equal (0, _textView.SelectionStartColumn);
  6714. Assert.Equal (0, _textView.SelectionStartRow);
  6715. Assert.Equal (0, _textView.SelectedLength);
  6716. Assert.Equal ("", _textView.SelectedText);
  6717. break;
  6718. case 3:
  6719. Assert.Equal (25, _textView.CursorPosition.X);
  6720. Assert.Equal (0, _textView.CursorPosition.Y);
  6721. Assert.Equal (0, _textView.SelectionStartColumn);
  6722. Assert.Equal (0, _textView.SelectionStartRow);
  6723. Assert.Equal (0, _textView.SelectedLength);
  6724. Assert.Equal ("", _textView.SelectedText);
  6725. break;
  6726. case 4:
  6727. Assert.Equal (28, _textView.CursorPosition.X);
  6728. Assert.Equal (0, _textView.CursorPosition.Y);
  6729. Assert.Equal (0, _textView.SelectionStartColumn);
  6730. Assert.Equal (0, _textView.SelectionStartRow);
  6731. Assert.Equal (0, _textView.SelectedLength);
  6732. Assert.Equal ("", _textView.SelectedText);
  6733. break;
  6734. case 5:
  6735. Assert.Equal (38, _textView.CursorPosition.X);
  6736. Assert.Equal (0, _textView.CursorPosition.Y);
  6737. Assert.Equal (0, _textView.SelectionStartColumn);
  6738. Assert.Equal (0, _textView.SelectionStartRow);
  6739. Assert.Equal (0, _textView.SelectedLength);
  6740. Assert.Equal ("", _textView.SelectedText);
  6741. break;
  6742. case 6:
  6743. Assert.Equal (40, _textView.CursorPosition.X);
  6744. Assert.Equal (0, _textView.CursorPosition.Y);
  6745. Assert.Equal (0, _textView.SelectionStartColumn);
  6746. Assert.Equal (0, _textView.SelectionStartRow);
  6747. Assert.Equal (0, _textView.SelectedLength);
  6748. Assert.Equal ("", _textView.SelectedText);
  6749. break;
  6750. case 7:
  6751. Assert.Equal (46, _textView.CursorPosition.X);
  6752. Assert.Equal (0, _textView.CursorPosition.Y);
  6753. Assert.Equal (0, _textView.SelectionStartColumn);
  6754. Assert.Equal (0, _textView.SelectionStartRow);
  6755. Assert.Equal (0, _textView.SelectedLength);
  6756. Assert.Equal ("", _textView.SelectedText);
  6757. break;
  6758. case 8:
  6759. Assert.Equal (48, _textView.CursorPosition.X);
  6760. Assert.Equal (0, _textView.CursorPosition.Y);
  6761. Assert.Equal (0, _textView.SelectionStartColumn);
  6762. Assert.Equal (0, _textView.SelectionStartRow);
  6763. Assert.Equal (0, _textView.SelectedLength);
  6764. Assert.Equal ("", _textView.SelectedText);
  6765. break;
  6766. case 9:
  6767. Assert.Equal (54, _textView.CursorPosition.X);
  6768. Assert.Equal (0, _textView.CursorPosition.Y);
  6769. Assert.Equal (0, _textView.SelectionStartColumn);
  6770. Assert.Equal (0, _textView.SelectionStartRow);
  6771. Assert.Equal (0, _textView.SelectedLength);
  6772. Assert.Equal ("", _textView.SelectedText);
  6773. break;
  6774. case 10:
  6775. Assert.Equal (55, _textView.CursorPosition.X);
  6776. Assert.Equal (0, _textView.CursorPosition.Y);
  6777. Assert.Equal (0, _textView.SelectionStartColumn);
  6778. Assert.Equal (0, _textView.SelectionStartRow);
  6779. Assert.Equal (0, _textView.SelectedLength);
  6780. Assert.Equal ("", _textView.SelectedText);
  6781. break;
  6782. }
  6783. iteration++;
  6784. }
  6785. }
  6786. [Fact]
  6787. [TextViewTestsAutoInitShutdown]
  6788. public void WordForward_With_Selection ()
  6789. {
  6790. _textView.CursorPosition = Point.Empty;
  6791. _textView.SelectionStartColumn = 0;
  6792. _textView.SelectionStartRow = 0;
  6793. var iteration = 0;
  6794. while (_textView.CursorPosition.X < _textView.Text.Length)
  6795. {
  6796. _textView.NewKeyDownEvent (
  6797. new Key (
  6798. KeyCode.CursorRight | KeyCode.CtrlMask | KeyCode.ShiftMask
  6799. )
  6800. );
  6801. switch (iteration)
  6802. {
  6803. case 0:
  6804. Assert.Equal (4, _textView.CursorPosition.X);
  6805. Assert.Equal (0, _textView.CursorPosition.Y);
  6806. Assert.Equal (0, _textView.SelectionStartColumn);
  6807. Assert.Equal (0, _textView.SelectionStartRow);
  6808. Assert.Equal (4, _textView.SelectedLength);
  6809. Assert.Equal ("TAB ", _textView.SelectedText);
  6810. break;
  6811. case 1:
  6812. Assert.Equal (7, _textView.CursorPosition.X);
  6813. Assert.Equal (0, _textView.CursorPosition.Y);
  6814. Assert.Equal (0, _textView.SelectionStartColumn);
  6815. Assert.Equal (0, _textView.SelectionStartRow);
  6816. Assert.Equal (7, _textView.SelectedLength);
  6817. Assert.Equal ("TAB to ", _textView.SelectedText);
  6818. break;
  6819. case 2:
  6820. Assert.Equal (12, _textView.CursorPosition.X);
  6821. Assert.Equal (0, _textView.CursorPosition.Y);
  6822. Assert.Equal (0, _textView.SelectionStartColumn);
  6823. Assert.Equal (0, _textView.SelectionStartRow);
  6824. Assert.Equal (12, _textView.SelectedLength);
  6825. Assert.Equal ("TAB to jump ", _textView.SelectedText);
  6826. break;
  6827. case 3:
  6828. Assert.Equal (20, _textView.CursorPosition.X);
  6829. Assert.Equal (0, _textView.CursorPosition.Y);
  6830. Assert.Equal (0, _textView.SelectionStartColumn);
  6831. Assert.Equal (0, _textView.SelectionStartRow);
  6832. Assert.Equal (20, _textView.SelectedLength);
  6833. Assert.Equal ("TAB to jump between ", _textView.SelectedText);
  6834. break;
  6835. case 4:
  6836. Assert.Equal (25, _textView.CursorPosition.X);
  6837. Assert.Equal (0, _textView.CursorPosition.Y);
  6838. Assert.Equal (0, _textView.SelectionStartColumn);
  6839. Assert.Equal (0, _textView.SelectionStartRow);
  6840. Assert.Equal (25, _textView.SelectedLength);
  6841. Assert.Equal ("TAB to jump between text ", _textView.SelectedText);
  6842. break;
  6843. case 5:
  6844. Assert.Equal (32, _textView.CursorPosition.X);
  6845. Assert.Equal (0, _textView.CursorPosition.Y);
  6846. Assert.Equal (0, _textView.SelectionStartColumn);
  6847. Assert.Equal (0, _textView.SelectionStartRow);
  6848. Assert.Equal (32, _textView.SelectedLength);
  6849. Assert.Equal ("TAB to jump between text fields.", _textView.SelectedText);
  6850. break;
  6851. }
  6852. iteration++;
  6853. }
  6854. }
  6855. [Fact]
  6856. [TextViewTestsAutoInitShutdown]
  6857. public void
  6858. WordForward_With_The_Same_Values_For_SelectedStart_And_CursorPosition_And_Not_Starting_At_Beginning_Of_The_Text ()
  6859. {
  6860. _textView.CursorPosition = new Point (10, 0);
  6861. _textView.SelectionStartColumn = 10;
  6862. _textView.SelectionStartRow = 0;
  6863. var iteration = 0;
  6864. while (_textView.CursorPosition.X < _textView.Text.Length)
  6865. {
  6866. _textView.NewKeyDownEvent (
  6867. new Key (
  6868. KeyCode.CursorRight | KeyCode.CtrlMask | KeyCode.ShiftMask
  6869. )
  6870. );
  6871. switch (iteration)
  6872. {
  6873. case 0:
  6874. Assert.Equal (12, _textView.CursorPosition.X);
  6875. Assert.Equal (0, _textView.CursorPosition.Y);
  6876. Assert.Equal (10, _textView.SelectionStartColumn);
  6877. Assert.Equal (0, _textView.SelectionStartRow);
  6878. Assert.Equal (2, _textView.SelectedLength);
  6879. Assert.Equal ("p ", _textView.SelectedText);
  6880. break;
  6881. case 1:
  6882. Assert.Equal (20, _textView.CursorPosition.X);
  6883. Assert.Equal (0, _textView.CursorPosition.Y);
  6884. Assert.Equal (10, _textView.SelectionStartColumn);
  6885. Assert.Equal (0, _textView.SelectionStartRow);
  6886. Assert.Equal (10, _textView.SelectedLength);
  6887. Assert.Equal ("p between ", _textView.SelectedText);
  6888. break;
  6889. case 2:
  6890. Assert.Equal (25, _textView.CursorPosition.X);
  6891. Assert.Equal (0, _textView.CursorPosition.Y);
  6892. Assert.Equal (10, _textView.SelectionStartColumn);
  6893. Assert.Equal (0, _textView.SelectionStartRow);
  6894. Assert.Equal (15, _textView.SelectedLength);
  6895. Assert.Equal ("p between text ", _textView.SelectedText);
  6896. break;
  6897. case 3:
  6898. Assert.Equal (32, _textView.CursorPosition.X);
  6899. Assert.Equal (0, _textView.CursorPosition.Y);
  6900. Assert.Equal (10, _textView.SelectionStartColumn);
  6901. Assert.Equal (0, _textView.SelectionStartRow);
  6902. Assert.Equal (22, _textView.SelectedLength);
  6903. Assert.Equal ("p between text fields.", _textView.SelectedText);
  6904. break;
  6905. }
  6906. iteration++;
  6907. }
  6908. }
  6909. [Fact]
  6910. [AutoInitShutdown]
  6911. public void WordWrap_Deleting_Backwards ()
  6912. {
  6913. var tv = new TextView { Width = 5, Height = 2, WordWrap = true, Text = "aaaa" };
  6914. var top = new Toplevel ();
  6915. top.Add (tv);
  6916. Application.Begin (top);
  6917. Application.Refresh ();
  6918. Assert.Equal (Point.Empty, tv.CursorPosition);
  6919. Assert.Equal (0, tv.LeftColumn);
  6920. TestHelpers.AssertDriverContentsAre (
  6921. @"
  6922. aaaa
  6923. ",
  6924. _output
  6925. );
  6926. tv.CursorPosition = new Point (5, 0);
  6927. Assert.True (tv.NewKeyDownEvent (Key.Backspace));
  6928. Application.Refresh ();
  6929. Assert.Equal (0, tv.LeftColumn);
  6930. TestHelpers.AssertDriverContentsAre (
  6931. @"
  6932. aaa
  6933. ",
  6934. _output
  6935. );
  6936. Assert.True (tv.NewKeyDownEvent (Key.Backspace));
  6937. Application.Refresh ();
  6938. Assert.Equal (0, tv.LeftColumn);
  6939. TestHelpers.AssertDriverContentsAre (
  6940. @"
  6941. aa
  6942. ",
  6943. _output
  6944. );
  6945. Assert.True (tv.NewKeyDownEvent (Key.Backspace));
  6946. Application.Refresh ();
  6947. Assert.Equal (0, tv.LeftColumn);
  6948. TestHelpers.AssertDriverContentsAre (
  6949. @"
  6950. a
  6951. ",
  6952. _output
  6953. );
  6954. Assert.True (tv.NewKeyDownEvent (Key.Backspace));
  6955. Application.Refresh ();
  6956. Assert.Equal (0, tv.LeftColumn);
  6957. TestHelpers.AssertDriverContentsAre (
  6958. @"
  6959. ",
  6960. _output
  6961. );
  6962. Assert.True (tv.NewKeyDownEvent (Key.Backspace));
  6963. Application.Refresh ();
  6964. Assert.Equal (0, tv.LeftColumn);
  6965. TestHelpers.AssertDriverContentsAre (
  6966. @"
  6967. ",
  6968. _output
  6969. );
  6970. top.Dispose ();
  6971. }
  6972. [Theory]
  6973. [TextViewTestsAutoInitShutdown]
  6974. [InlineData (KeyCode.Delete)]
  6975. public void WordWrap_Draw_Typed_Keys_After_Text_Is_Deleted (KeyCode del)
  6976. {
  6977. var top = new Toplevel ();
  6978. top.Add (_textView);
  6979. _textView.Text = "Line 1.\nLine 2.";
  6980. _textView.WordWrap = true;
  6981. Application.Begin (top);
  6982. Application.Refresh ();
  6983. Assert.True (_textView.WordWrap);
  6984. TestHelpers.AssertDriverContentsWithFrameAre (
  6985. @"
  6986. Line 1.
  6987. Line 2.",
  6988. _output
  6989. );
  6990. Assert.True (_textView.NewKeyDownEvent (Key.End.WithShift));
  6991. Assert.Equal ("Line 1.", _textView.SelectedText);
  6992. Assert.True (_textView.NewKeyDownEvent (new Key (del)));
  6993. Application.Refresh ();
  6994. TestHelpers.AssertDriverContentsWithFrameAre ("Line 2.", _output);
  6995. Assert.True (_textView.NewKeyDownEvent (Key.H.WithShift));
  6996. Assert.NotEqual (Rectangle.Empty, _textView._needsDisplayRect);
  6997. Application.Refresh ();
  6998. TestHelpers.AssertDriverContentsWithFrameAre (
  6999. @"
  7000. H
  7001. Line 2.",
  7002. _output
  7003. );
  7004. top.Dispose ();
  7005. }
  7006. [Fact]
  7007. public void WordWrap_Gets_Sets ()
  7008. {
  7009. var tv = new TextView { WordWrap = true };
  7010. Assert.True (tv.WordWrap);
  7011. tv.WordWrap = false;
  7012. Assert.False (tv.WordWrap);
  7013. }
  7014. [Fact]
  7015. [AutoInitShutdown]
  7016. public void WordWrap_Not_Throw_If_Width_Is_Less_Than_Zero ()
  7017. {
  7018. Exception exception = Record.Exception (
  7019. () =>
  7020. {
  7021. var tv = new TextView
  7022. {
  7023. Width = Dim.Fill (),
  7024. Height = Dim.Fill (),
  7025. WordWrap = true,
  7026. Text = "これは、左右のクリップ境界をテストするための非常に長いテキストです。"
  7027. };
  7028. }
  7029. );
  7030. Assert.Null (exception);
  7031. }
  7032. [Fact]
  7033. [AutoInitShutdown]
  7034. public void WordWrap_ReadOnly_CursorPosition_SelectedText_Copy ()
  7035. {
  7036. // 0123456789
  7037. var text = "This is the first line.\nThis is the second line.\n";
  7038. var tv = new TextView { Width = 11, Height = 9 };
  7039. tv.Text = text;
  7040. Assert.Equal (
  7041. $"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}",
  7042. tv.Text
  7043. );
  7044. tv.WordWrap = true;
  7045. var top = new Toplevel ();
  7046. top.Add (tv);
  7047. top.Layout();
  7048. tv.Draw ();
  7049. TestHelpers.AssertDriverContentsWithFrameAre (
  7050. @"
  7051. This is
  7052. the first
  7053. line.
  7054. This is
  7055. the
  7056. second
  7057. line.
  7058. ",
  7059. _output
  7060. );
  7061. tv.ReadOnly = true;
  7062. tv.CursorPosition = new Point (6, 2);
  7063. Assert.Equal (new Point (5, 2), tv.CursorPosition);
  7064. top.LayoutSubviews ();
  7065. tv.Draw ();
  7066. TestHelpers.AssertDriverContentsWithFrameAre (
  7067. @"
  7068. This is
  7069. the first
  7070. line.
  7071. This is
  7072. the second
  7073. line.
  7074. ",
  7075. _output
  7076. );
  7077. tv.SelectionStartRow = 0;
  7078. tv.SelectionStartColumn = 0;
  7079. Assert.Equal ("This is the first line.", tv.SelectedText);
  7080. tv.Copy ();
  7081. Assert.Equal ("This is the first line.", Clipboard.Contents);
  7082. }
  7083. [Fact]
  7084. [TextViewTestsAutoInitShutdown]
  7085. public void WordWrap_True_LoadStream_New_Text ()
  7086. {
  7087. Assert.Equal ("TAB to jump between text fields.", _textView.Text);
  7088. _textView.WordWrap = true;
  7089. Assert.Equal ("TAB to jump between text fields.", _textView.Text);
  7090. var text = "This is the first line.\nThis is the second line.\n";
  7091. using (var stream = new MemoryStream ())
  7092. {
  7093. var writer = new StreamWriter (stream);
  7094. writer.Write (text);
  7095. writer.Flush ();
  7096. stream.Position = 0;
  7097. _textView.Load (stream);
  7098. Assert.Equal (
  7099. $"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}",
  7100. _textView.Text
  7101. );
  7102. Assert.True (_textView.WordWrap);
  7103. }
  7104. }
  7105. [Fact]
  7106. public void WordWrap_True_Text_Always_Returns_Unwrapped ()
  7107. {
  7108. var text = "This is the first line.\nThis is the second line.\n";
  7109. var tv = new TextView { Width = 10 };
  7110. tv.Text = text;
  7111. Assert.Equal (
  7112. $"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}",
  7113. tv.Text
  7114. );
  7115. tv.WordWrap = true;
  7116. Assert.Equal (
  7117. $"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}",
  7118. tv.Text
  7119. );
  7120. }
  7121. [Fact]
  7122. [TextViewTestsAutoInitShutdown]
  7123. public void WordWrap_WrapModel_Output ()
  7124. {
  7125. // 0123456789
  7126. var text = "This is the first line.\nThis is the second line.\n";
  7127. var tv = new TextView { Width = 10, Height = 10 };
  7128. tv.Text = text;
  7129. Assert.Equal (
  7130. $"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}",
  7131. tv.Text
  7132. );
  7133. tv.WordWrap = true;
  7134. var top = new Toplevel ();
  7135. top.Add (tv);
  7136. top.Layout ();
  7137. tv.Draw ();
  7138. TestHelpers.AssertDriverContentsWithFrameAre (
  7139. @"
  7140. This is
  7141. the
  7142. first
  7143. line.
  7144. This is
  7145. the
  7146. second
  7147. line.
  7148. ",
  7149. _output
  7150. );
  7151. }
  7152. private int GetLeftCol (int start)
  7153. {
  7154. string [] lines = _textView.Text.Split (Environment.NewLine);
  7155. if (lines == null || lines.Length == 0)
  7156. {
  7157. return 0;
  7158. }
  7159. if (start == _textView.LeftColumn)
  7160. {
  7161. return start;
  7162. }
  7163. if (_textView.LeftColumn == _textView.CurrentColumn)
  7164. {
  7165. return _textView.CurrentColumn;
  7166. }
  7167. int cCol = _textView.CurrentColumn;
  7168. string line = lines [_textView.CurrentRow];
  7169. int lCount = cCol > line.Length - 1 ? line.Length - 1 : cCol;
  7170. int width = _textView.Frame.Width;
  7171. int tabWidth = _textView.TabWidth;
  7172. var sumLength = 0;
  7173. var col = 0;
  7174. for (int i = lCount; i >= 0; i--)
  7175. {
  7176. char r = line [i];
  7177. sumLength += ((Rune)r).GetColumns ();
  7178. if (r == '\t')
  7179. {
  7180. sumLength += tabWidth + 1;
  7181. }
  7182. if (sumLength > width)
  7183. {
  7184. if (col + width == cCol)
  7185. {
  7186. col++;
  7187. }
  7188. break;
  7189. }
  7190. if ((cCol < line.Length && col > 0 && start < cCol && col == start) || cCol - col == width - 1)
  7191. {
  7192. break;
  7193. }
  7194. col = i;
  7195. }
  7196. return col;
  7197. }
  7198. // This class enables test functions annotated with the [InitShutdown] attribute
  7199. // to have a function called before the test function is called and after.
  7200. //
  7201. // This is necessary because a) Application is a singleton and Init/Shutdown must be called
  7202. // as a pair, and b) all unit test functions should be atomic.
  7203. [AttributeUsage (AttributeTargets.Class | AttributeTargets.Method)]
  7204. public class TextViewTestsAutoInitShutdown : AutoInitShutdownAttribute
  7205. {
  7206. public static string Txt = "TAB to jump between text fields.";
  7207. public TextViewTestsAutoInitShutdown () : base (configLocation: ConfigurationManager.ConfigLocations.DefaultOnly) { }
  7208. public override void After (MethodInfo methodUnderTest)
  7209. {
  7210. _textView = null;
  7211. base.After (methodUnderTest);
  7212. }
  7213. public override void Before (MethodInfo methodUnderTest)
  7214. {
  7215. FakeDriver.FakeBehaviors.UseFakeClipboard = true;
  7216. base.Before (methodUnderTest);
  7217. // 1 2 3
  7218. // 01234567890123456789012345678901=32 (Length)
  7219. byte [] buff = Encoding.Unicode.GetBytes (Txt);
  7220. byte [] ms = new MemoryStream (buff).ToArray ();
  7221. _textView = new TextView { Width = 30, Height = 10, ColorScheme = Colors.ColorSchemes ["Base"] };
  7222. _textView.Text = Encoding.Unicode.GetString (ms);
  7223. }
  7224. }
  7225. [Fact]
  7226. public void HotKey_Command_SetsFocus ()
  7227. {
  7228. var view = new TextView ();
  7229. view.CanFocus = true;
  7230. Assert.False (view.HasFocus);
  7231. view.InvokeCommand (Command.HotKey);
  7232. Assert.True (view.HasFocus);
  7233. }
  7234. [Fact]
  7235. public void HotKey_Command_Does_Not_Accept ()
  7236. {
  7237. var view = new TextView ();
  7238. var accepted = false;
  7239. view.Accepting += OnAccept;
  7240. view.InvokeCommand (Command.HotKey);
  7241. Assert.False (accepted);
  7242. return;
  7243. void OnAccept (object sender, CommandEventArgs e) { accepted = true; }
  7244. }
  7245. [Theory]
  7246. [InlineData (false, 1)]
  7247. [InlineData (true, 1)]
  7248. public void Accepted_Command_Raises_Accepted_Regardles_Of_AllowsReturn (bool allowsReturn, int expectedAcceptEvents)
  7249. {
  7250. var view = new TextView ()
  7251. {
  7252. AllowsReturn = allowsReturn,
  7253. };
  7254. int acceptedEvents = 0;
  7255. view.Accepting += Accept;
  7256. view.InvokeCommand (Command.Accept);
  7257. Assert.Equal (expectedAcceptEvents, acceptedEvents);
  7258. return;
  7259. void Accept (object sender, CommandEventArgs e) { acceptedEvents++; }
  7260. }
  7261. [Theory]
  7262. [InlineData (false, 1)]
  7263. [InlineData (true, 0)]
  7264. public void Enter_Key_Fires_Accepted_BasedOn_AllowsReturn (bool allowsReturn, int expectedAccepts)
  7265. {
  7266. var view = new TextView ()
  7267. {
  7268. Multiline = allowsReturn,
  7269. };
  7270. int accepted = 0;
  7271. view.Accepting += Accept;
  7272. view.NewKeyDownEvent (Key.Enter);
  7273. Assert.Equal (expectedAccepts, accepted);
  7274. return;
  7275. void Accept (object sender, CommandEventArgs e) { accepted++; }
  7276. }
  7277. [Theory]
  7278. [InlineData (false, 1)]
  7279. [InlineData (true, 0)]
  7280. public void Enter_Key_Fires_Accepted_BasedOn_Multiline (bool multiline, int expectedAccepts)
  7281. {
  7282. var view = new TextView ()
  7283. {
  7284. Multiline = multiline,
  7285. };
  7286. int accepted = 0;
  7287. view.Accepting += Accept;
  7288. view.NewKeyDownEvent (Key.Enter);
  7289. Assert.Equal (expectedAccepts, accepted);
  7290. return;
  7291. void Accept (object sender, CommandEventArgs e) { accepted++; }
  7292. }
  7293. [Fact]
  7294. public void Space_Key_Types_Space ()
  7295. {
  7296. var view = new TextView ()
  7297. {
  7298. };
  7299. view.NewKeyDownEvent (Key.Space);
  7300. Assert.Equal (" ", view.Text);
  7301. }
  7302. [Theory]
  7303. [InlineData (false, false, 1, 1)]
  7304. [InlineData (false, true, 1, 0)]
  7305. [InlineData (true, false, 0, 0)]
  7306. [InlineData (true, true, 0, 0)]
  7307. public void Accepted_Event_Handled_Prevents_Default_Button_Accept (bool multiline, bool handleAccept, int expectedAccepts, int expectedButtonAccepts)
  7308. {
  7309. var superView = new Window ();
  7310. var tv = new TextView ()
  7311. {
  7312. Multiline = multiline
  7313. };
  7314. var button = new Button ()
  7315. {
  7316. IsDefault = true,
  7317. };
  7318. superView.Add (tv, button);
  7319. var buttonAccept = 0;
  7320. button.Accepting += ButtonAccept;
  7321. var textViewAccept = 0;
  7322. tv.Accepting += TextViewAccept;
  7323. tv.SetFocus ();
  7324. Assert.True (tv.HasFocus);
  7325. superView.NewKeyDownEvent (Key.Enter);
  7326. Assert.Equal (expectedAccepts, textViewAccept);
  7327. Assert.Equal (expectedButtonAccepts, buttonAccept);
  7328. button.SetFocus ();
  7329. superView.NewKeyDownEvent (Key.Enter);
  7330. Assert.Equal (expectedAccepts, textViewAccept);
  7331. Assert.Equal (expectedButtonAccepts + 1, buttonAccept);
  7332. return;
  7333. void TextViewAccept (object sender, CommandEventArgs e)
  7334. {
  7335. textViewAccept++;
  7336. e.Cancel = handleAccept;
  7337. }
  7338. void ButtonAccept (object sender, CommandEventArgs e)
  7339. {
  7340. buttonAccept++;
  7341. }
  7342. }
  7343. [Theory]
  7344. [InlineData (true, 0)]
  7345. [InlineData (false, 1)]
  7346. public void Accepted_No_Handler_Enables_Default_Button_Accept (bool multiline, int expectedButtonAccept)
  7347. {
  7348. var superView = new Window ();
  7349. var tv = new TextView ()
  7350. {
  7351. Multiline = multiline
  7352. };
  7353. var button = new Button ()
  7354. {
  7355. IsDefault = true,
  7356. };
  7357. superView.Add (tv, button);
  7358. var buttonAccept = 0;
  7359. button.Accepting += ButtonAccept;
  7360. tv.SetFocus ();
  7361. Assert.True (tv.HasFocus);
  7362. superView.NewKeyDownEvent (Key.Enter);
  7363. Assert.Equal (expectedButtonAccept, buttonAccept);
  7364. button.SetFocus ();
  7365. superView.NewKeyDownEvent (Key.Enter);
  7366. Assert.Equal (expectedButtonAccept + 1, buttonAccept);
  7367. return;
  7368. void ButtonAccept (object sender, CommandEventArgs e)
  7369. {
  7370. buttonAccept++;
  7371. }
  7372. }
  7373. [Fact]
  7374. public void Autocomplete_Popup_Added_To_SuperView_On_Init ()
  7375. {
  7376. View superView = new ()
  7377. {
  7378. CanFocus = true,
  7379. };
  7380. TextView t = new ();
  7381. superView.Add (t);
  7382. Assert.Single (superView.Subviews);
  7383. superView.BeginInit ();
  7384. superView.EndInit ();
  7385. Assert.Equal (2, superView.Subviews.Count);
  7386. }
  7387. [Fact]
  7388. public void Autocomplete__Added_To_SuperView_On_Add ()
  7389. {
  7390. View superView = new ()
  7391. {
  7392. CanFocus = true,
  7393. Id = "superView",
  7394. };
  7395. superView.BeginInit ();
  7396. superView.EndInit ();
  7397. Assert.Empty (superView.Subviews);
  7398. TextView t = new ()
  7399. {
  7400. Id = "t"
  7401. };
  7402. superView.Add (t);
  7403. Assert.Equal (2, superView.Subviews.Count);
  7404. }
  7405. [Fact]
  7406. public void Autocomplete_Visible_False_By_Default ()
  7407. {
  7408. View superView = new ()
  7409. {
  7410. CanFocus = true,
  7411. };
  7412. TextView t = new ();
  7413. superView.Add (t);
  7414. superView.BeginInit ();
  7415. superView.EndInit ();
  7416. Assert.Equal (2, superView.Subviews.Count);
  7417. Assert.True (t.Visible);
  7418. Assert.False (t.Autocomplete.Visible);
  7419. }
  7420. [Fact]
  7421. public void Right_CursorAtEnd_WithSelection_ShouldClearSelection ()
  7422. {
  7423. var tv = new TextView
  7424. {
  7425. Text = "Hello",
  7426. };
  7427. tv.SetFocus ();
  7428. tv.NewKeyDownEvent (Key.End.WithShift);
  7429. Assert.Equal (5,tv.CursorPosition.X);
  7430. // When there is selected text and the cursor is at the end of the text field
  7431. Assert.Equal ("Hello", tv.SelectedText);
  7432. // Pressing right should not move focus, instead it should clear selection
  7433. Assert.True (tv.NewKeyDownEvent (Key.CursorRight));
  7434. Assert.Empty (tv.SelectedText);
  7435. // Now that the selection is cleared another right keypress should move focus
  7436. Assert.False (tv.NewKeyDownEvent (Key.CursorRight));
  7437. }
  7438. [Fact]
  7439. public void Left_CursorAtStart_WithSelection_ShouldClearSelection ()
  7440. {
  7441. var tv = new TextView
  7442. {
  7443. Text = "Hello",
  7444. };
  7445. tv.SetFocus ();
  7446. tv.NewKeyDownEvent (Key.CursorRight);
  7447. tv.NewKeyDownEvent (Key.CursorRight);
  7448. Assert.Equal (2,tv.CursorPosition.X);
  7449. Assert.True (tv.NewKeyDownEvent (Key.CursorLeft.WithShift));
  7450. Assert.True (tv.NewKeyDownEvent (Key.CursorLeft.WithShift));
  7451. // When there is selected text and the cursor is at the start of the text field
  7452. Assert.Equal ("He", tv.SelectedText);
  7453. // Pressing left should not move focus, instead it should clear selection
  7454. Assert.True (tv.NewKeyDownEvent (Key.CursorLeft));
  7455. Assert.Empty (tv.SelectedText);
  7456. // When clearing selected text with left the cursor should be at the start of the selection
  7457. Assert.Equal (0, tv.CursorPosition.X);
  7458. // Now that the selection is cleared another left keypress should move focus
  7459. Assert.False (tv.NewKeyDownEvent (Key.CursorLeft));
  7460. }
  7461. [Fact]
  7462. [AutoInitShutdown]
  7463. public void Draw_Esc_Rune ()
  7464. {
  7465. var tv = new TextView { Width = 5, Height = 1, Text = "\u001b" };
  7466. tv.BeginInit ();
  7467. tv.EndInit ();
  7468. tv.Draw ();
  7469. TestHelpers.AssertDriverContentsWithFrameAre ("\u241b", _output);
  7470. tv.Dispose ();
  7471. }
  7472. [Fact]
  7473. public void Equals_True ()
  7474. {
  7475. var c1 = new Cell ();
  7476. var c2 = new Cell ();
  7477. Assert.True (c1.Equals (c2));
  7478. Assert.True (c2.Equals (c1));
  7479. c1.Rune = new ('a');
  7480. c1.Attribute = new ();
  7481. c2.Rune = new ('a');
  7482. c2.Attribute = new ();
  7483. Assert.True (c1.Equals (c2));
  7484. Assert.True (c2.Equals (c1));
  7485. }
  7486. [Fact]
  7487. [AutoInitShutdown]
  7488. public void CellEventArgs_WordWrap_True ()
  7489. {
  7490. var eventCount = 0;
  7491. List<List<Cell>> text =
  7492. [
  7493. Cell.ToCells (
  7494. "This is the first line.".ToRunes ()
  7495. ),
  7496. Cell.ToCells (
  7497. "This is the second line.".ToRunes ()
  7498. )
  7499. ];
  7500. TextView tv = CreateTextView ();
  7501. tv.DrawNormalColor += _textView_DrawColor;
  7502. tv.DrawReadOnlyColor += _textView_DrawColor;
  7503. tv.DrawSelectionColor += _textView_DrawColor;
  7504. tv.DrawUsedColor += _textView_DrawColor;
  7505. void _textView_DrawColor (object sender, CellEventArgs e)
  7506. {
  7507. Assert.Equal (e.Line [e.Col], text [e.UnwrappedPosition.Row] [e.UnwrappedPosition.Col]);
  7508. eventCount++;
  7509. }
  7510. tv.Text = $"{Cell.ToString (text [0])}\n{Cell.ToString (text [1])}\n";
  7511. Assert.False (tv.WordWrap);
  7512. var top = new Toplevel ();
  7513. top.Add (tv);
  7514. Application.Begin (top);
  7515. Application.Refresh ();
  7516. TestHelpers.AssertDriverContentsWithFrameAre (
  7517. @"
  7518. This is the first line.
  7519. This is the second line.",
  7520. _output
  7521. );
  7522. tv.Width = 10;
  7523. tv.Height = 25;
  7524. tv.WordWrap = true;
  7525. Application.Refresh ();
  7526. TestHelpers.AssertDriverContentsWithFrameAre (
  7527. @"
  7528. This is
  7529. the
  7530. first
  7531. line.
  7532. This is
  7533. the
  7534. second
  7535. line. ",
  7536. _output
  7537. );
  7538. Assert.Equal (eventCount, (text [0].Count + text [1].Count) * 2);
  7539. top.Dispose ();
  7540. }
  7541. [Fact]
  7542. [AutoInitShutdown (configLocation: ConfigurationManager.ConfigLocations.DefaultOnly)]
  7543. public void Cell_LoadCells_InheritsPreviousAttribute ()
  7544. {
  7545. List<Cell> cells = [];
  7546. foreach (KeyValuePair<string, ColorScheme> color in Colors.ColorSchemes)
  7547. {
  7548. string csName = color.Key;
  7549. foreach (Rune rune in csName.EnumerateRunes ())
  7550. {
  7551. cells.Add (new () { Rune = rune, Attribute = color.Value.Normal });
  7552. }
  7553. cells.Add (new () { Rune = (Rune)'\n', Attribute = color.Value.Focus });
  7554. }
  7555. TextView tv = CreateTextView ();
  7556. tv.Load (cells);
  7557. var top = new Toplevel ();
  7558. top.Add (tv);
  7559. RunState rs = Application.Begin (top);
  7560. Application.Refresh ();
  7561. Assert.True (tv.InheritsPreviousAttribute);
  7562. var expectedText = @"
  7563. TopLevel
  7564. Base
  7565. Dialog
  7566. Menu
  7567. Error ";
  7568. TestHelpers.AssertDriverContentsWithFrameAre (expectedText, _output);
  7569. Attribute [] attributes =
  7570. {
  7571. // 0
  7572. Colors.ColorSchemes ["TopLevel"].Normal,
  7573. // 1
  7574. Colors.ColorSchemes ["Base"].Normal,
  7575. // 2
  7576. Colors.ColorSchemes ["Dialog"].Normal,
  7577. // 3
  7578. Colors.ColorSchemes ["Menu"].Normal,
  7579. // 4
  7580. Colors.ColorSchemes ["Error"].Normal,
  7581. // 5
  7582. tv.ColorScheme!.Focus
  7583. };
  7584. var expectedColor = @"
  7585. 0000000055
  7586. 1111555555
  7587. 2222225555
  7588. 3333555555
  7589. 4444455555";
  7590. TestHelpers.AssertDriverAttributesAre (expectedColor, _output, Application.Driver, attributes);
  7591. tv.WordWrap = true;
  7592. Application.Refresh ();
  7593. TestHelpers.AssertDriverContentsWithFrameAre (expectedText, _output);
  7594. TestHelpers.AssertDriverAttributesAre (expectedColor, _output, Application.Driver, attributes);
  7595. tv.CursorPosition = new (6, 2);
  7596. tv.SelectionStartColumn = 0;
  7597. tv.SelectionStartRow = 0;
  7598. Assert.Equal ($"TopLevel{Environment.NewLine}Base{Environment.NewLine}Dialog", tv.SelectedText);
  7599. tv.Copy ();
  7600. tv.IsSelecting = false;
  7601. tv.CursorPosition = new (2, 4);
  7602. tv.Paste ();
  7603. Application.Refresh ();
  7604. expectedText = @"
  7605. TopLevel
  7606. Base
  7607. Dialog
  7608. Menu
  7609. ErTopLevel
  7610. Base
  7611. Dialogror ";
  7612. TestHelpers.AssertDriverContentsWithFrameAre (expectedText, _output);
  7613. expectedColor = @"
  7614. 0000000055
  7615. 1111555555
  7616. 2222225555
  7617. 3333555555
  7618. 4400000000
  7619. 1111555555
  7620. 2222224445";
  7621. TestHelpers.AssertDriverAttributesAre (expectedColor, _output, Application.Driver, attributes);
  7622. tv.Undo ();
  7623. tv.CursorPosition = new (0, 3);
  7624. tv.SelectionStartColumn = 0;
  7625. tv.SelectionStartRow = 0;
  7626. Assert.Equal (
  7627. $"TopLevel{Environment.NewLine}Base{Environment.NewLine}Dialog{Environment.NewLine}",
  7628. tv.SelectedText
  7629. );
  7630. tv.Copy ();
  7631. tv.IsSelecting = false;
  7632. tv.CursorPosition = new (2, 4);
  7633. tv.Paste ();
  7634. Application.Refresh ();
  7635. expectedText = @"
  7636. TopLevel
  7637. Base
  7638. Dialog
  7639. Menu
  7640. ErTopLevel
  7641. Base
  7642. Dialog
  7643. ror ";
  7644. TestHelpers.AssertDriverContentsWithFrameAre (expectedText, _output);
  7645. expectedColor = @"
  7646. 0000000055
  7647. 1111555555
  7648. 2222225555
  7649. 3333555555
  7650. 4400000000
  7651. 1111555555
  7652. 2222225555
  7653. 4445555555";
  7654. TestHelpers.AssertDriverAttributesAre (expectedColor, _output, Application.Driver, attributes);
  7655. Application.End (rs);
  7656. top.Dispose ();
  7657. }
  7658. [Fact]
  7659. public void Cell_LoadCells_Without_ColorScheme_Is_Never_Null ()
  7660. {
  7661. List<Cell> cells = new ()
  7662. {
  7663. new() { Rune = new ('T') },
  7664. new() { Rune = new ('e') },
  7665. new() { Rune = new ('s') },
  7666. new() { Rune = new ('t') }
  7667. };
  7668. TextView tv = CreateTextView ();
  7669. var top = new Toplevel ();
  7670. top.Add (tv);
  7671. tv.Load (cells);
  7672. for (var i = 0; i < tv.Lines; i++)
  7673. {
  7674. List<Cell> line = tv.GetLine (i);
  7675. foreach (Cell c in line)
  7676. {
  7677. Assert.NotNull (c.Attribute);
  7678. }
  7679. }
  7680. }
  7681. private TextView CreateTextView () { return new () { Width = 30, Height = 10 }; }
  7682. }