TextViewTests.cs 244 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Reflection;
  5. using System.Text.RegularExpressions;
  6. using Xunit;
  7. using Xunit.Abstractions;
  8. namespace Terminal.Gui.Views {
  9. public class TextViewTests {
  10. private static TextView _textView;
  11. readonly ITestOutputHelper output;
  12. public TextViewTests (ITestOutputHelper output)
  13. {
  14. this.output = output;
  15. }
  16. // This class enables test functions annotated with the [InitShutdown] attribute
  17. // to have a function called before the test function is called and after.
  18. //
  19. // This is necessary because a) Application is a singleton and Init/Shutdown must be called
  20. // as a pair, and b) all unit test functions should be atomic.
  21. [AttributeUsage (AttributeTargets.Class | AttributeTargets.Method, AllowMultiple = false, Inherited = true)]
  22. public class InitShutdown : Xunit.Sdk.BeforeAfterTestAttribute {
  23. public override void Before (MethodInfo methodUnderTest)
  24. {
  25. if (_textView != null) {
  26. throw new InvalidOperationException ("After did not run.");
  27. }
  28. Application.Init (new FakeDriver (), new FakeMainLoop (() => FakeConsole.ReadKey (true)));
  29. // 1 2 3
  30. // 01234567890123456789012345678901=32 (Length)
  31. var txt = "TAB to jump between text fields.";
  32. var buff = new byte [txt.Length];
  33. for (int i = 0; i < txt.Length; i++) {
  34. buff [i] = (byte)txt [i];
  35. }
  36. var ms = new System.IO.MemoryStream (buff).ToArray ();
  37. _textView = new TextView () { Width = 30, Height = 10 };
  38. _textView.Text = ms;
  39. }
  40. public override void After (MethodInfo methodUnderTest)
  41. {
  42. _textView = null;
  43. Application.Shutdown ();
  44. }
  45. }
  46. [Fact]
  47. [InitShutdown]
  48. public void Changing_Selection_Or_CursorPosition_Update_SelectedLength_And_SelectedText ()
  49. {
  50. _textView.SelectionStartColumn = 2;
  51. _textView.SelectionStartRow = 0;
  52. Assert.Equal (0, _textView.CursorPosition.X);
  53. Assert.Equal (0, _textView.CursorPosition.Y);
  54. Assert.Equal (2, _textView.SelectedLength);
  55. Assert.Equal ("TA", _textView.SelectedText);
  56. _textView.CursorPosition = new Point (20, 0);
  57. Assert.Equal (2, _textView.SelectionStartColumn);
  58. Assert.Equal (0, _textView.SelectionStartRow);
  59. Assert.Equal (18, _textView.SelectedLength);
  60. Assert.Equal ("B to jump between ", _textView.SelectedText);
  61. }
  62. [Fact]
  63. [InitShutdown]
  64. public void Selection_With_Value_Less_Than_Zero_Changes_To_Zero ()
  65. {
  66. _textView.SelectionStartColumn = -2;
  67. _textView.SelectionStartRow = -2;
  68. Assert.Equal (0, _textView.SelectionStartColumn);
  69. Assert.Equal (0, _textView.SelectionStartRow);
  70. Assert.Equal (0, _textView.SelectedLength);
  71. Assert.Equal ("", _textView.SelectedText);
  72. }
  73. [Fact]
  74. [InitShutdown]
  75. public void Selection_With_Value_Greater_Than_Text_Length_Changes_To_Text_Length ()
  76. {
  77. _textView.CursorPosition = new Point (2, 0);
  78. _textView.SelectionStartColumn = 33;
  79. _textView.SelectionStartRow = 1;
  80. Assert.Equal (32, _textView.SelectionStartColumn);
  81. Assert.Equal (0, _textView.SelectionStartRow);
  82. Assert.Equal (30, _textView.SelectedLength);
  83. Assert.Equal ("B to jump between text fields.", _textView.SelectedText);
  84. }
  85. [Fact]
  86. [InitShutdown]
  87. public void Selection_With_Empty_Text ()
  88. {
  89. _textView = new TextView ();
  90. _textView.CursorPosition = new Point (2, 0);
  91. _textView.SelectionStartColumn = 33;
  92. _textView.SelectionStartRow = 1;
  93. Assert.Equal (0, _textView.SelectionStartColumn);
  94. Assert.Equal (0, _textView.SelectionStartRow);
  95. Assert.Equal (0, _textView.SelectedLength);
  96. Assert.Equal ("", _textView.SelectedText);
  97. }
  98. [Fact]
  99. [InitShutdown]
  100. public void Selection_And_CursorPosition_With_Value_Greater_Than_Text_Length_Changes_Both_To_Text_Length ()
  101. {
  102. _textView.CursorPosition = new Point (33, 2);
  103. _textView.SelectionStartColumn = 33;
  104. _textView.SelectionStartRow = 33;
  105. Assert.Equal (32, _textView.CursorPosition.X);
  106. Assert.Equal (0, _textView.CursorPosition.Y);
  107. Assert.Equal (32, _textView.SelectionStartColumn);
  108. Assert.Equal (0, _textView.SelectionStartRow);
  109. Assert.Equal (0, _textView.SelectedLength);
  110. Assert.Equal ("", _textView.SelectedText);
  111. }
  112. [Fact]
  113. [InitShutdown]
  114. public void CursorPosition_With_Value_Less_Than_Zero_Changes_To_Zero ()
  115. {
  116. _textView.CursorPosition = new Point (-1, -1);
  117. Assert.Equal (0, _textView.CursorPosition.X);
  118. Assert.Equal (0, _textView.CursorPosition.Y);
  119. Assert.Equal (0, _textView.SelectedLength);
  120. Assert.Equal ("", _textView.SelectedText);
  121. }
  122. [Fact]
  123. [InitShutdown]
  124. public void CursorPosition_With_Value_Greater_Than_Text_Length_Changes_To_Text_Length ()
  125. {
  126. _textView.CursorPosition = new Point (33, 1);
  127. Assert.Equal (32, _textView.CursorPosition.X);
  128. Assert.Equal (0, _textView.CursorPosition.Y);
  129. Assert.Equal (0, _textView.SelectedLength);
  130. Assert.Equal ("", _textView.SelectedText);
  131. }
  132. [Fact]
  133. [InitShutdown]
  134. public void WordForward_With_No_Selection ()
  135. {
  136. _textView.CursorPosition = new Point (0, 0);
  137. var iteration = 0;
  138. while (_textView.CursorPosition.X < _textView.Text.Length) {
  139. _textView.ProcessKey (new KeyEvent (Key.CursorRight | Key.CtrlMask, new KeyModifiers ()));
  140. switch (iteration) {
  141. case 0:
  142. Assert.Equal (4, _textView.CursorPosition.X);
  143. Assert.Equal (0, _textView.CursorPosition.Y);
  144. Assert.Equal (0, _textView.SelectionStartColumn);
  145. Assert.Equal (0, _textView.SelectionStartRow);
  146. Assert.Equal (0, _textView.SelectedLength);
  147. Assert.Equal ("", _textView.SelectedText);
  148. break;
  149. case 1:
  150. Assert.Equal (7, _textView.CursorPosition.X);
  151. Assert.Equal (0, _textView.CursorPosition.Y);
  152. Assert.Equal (0, _textView.SelectionStartColumn);
  153. Assert.Equal (0, _textView.SelectionStartRow);
  154. Assert.Equal (0, _textView.SelectedLength);
  155. Assert.Equal ("", _textView.SelectedText);
  156. break;
  157. case 2:
  158. Assert.Equal (12, _textView.CursorPosition.X);
  159. Assert.Equal (0, _textView.CursorPosition.Y);
  160. Assert.Equal (0, _textView.SelectionStartColumn);
  161. Assert.Equal (0, _textView.SelectionStartRow);
  162. Assert.Equal (0, _textView.SelectedLength);
  163. Assert.Equal ("", _textView.SelectedText);
  164. break;
  165. case 3:
  166. Assert.Equal (20, _textView.CursorPosition.X);
  167. Assert.Equal (0, _textView.CursorPosition.Y);
  168. Assert.Equal (0, _textView.SelectionStartColumn);
  169. Assert.Equal (0, _textView.SelectionStartRow);
  170. Assert.Equal (0, _textView.SelectedLength);
  171. Assert.Equal ("", _textView.SelectedText);
  172. break;
  173. case 4:
  174. Assert.Equal (25, _textView.CursorPosition.X);
  175. Assert.Equal (0, _textView.CursorPosition.Y);
  176. Assert.Equal (0, _textView.SelectionStartColumn);
  177. Assert.Equal (0, _textView.SelectionStartRow);
  178. Assert.Equal (0, _textView.SelectedLength);
  179. Assert.Equal ("", _textView.SelectedText);
  180. break;
  181. case 5:
  182. Assert.Equal (32, _textView.CursorPosition.X);
  183. Assert.Equal (0, _textView.CursorPosition.Y);
  184. Assert.Equal (0, _textView.SelectionStartColumn);
  185. Assert.Equal (0, _textView.SelectionStartRow);
  186. Assert.Equal (0, _textView.SelectedLength);
  187. Assert.Equal ("", _textView.SelectedText);
  188. break;
  189. }
  190. iteration++;
  191. }
  192. }
  193. [Fact]
  194. [InitShutdown]
  195. public void WordBackward_With_No_Selection ()
  196. {
  197. _textView.CursorPosition = new Point (_textView.Text.Length, 0);
  198. var iteration = 0;
  199. while (_textView.CursorPosition.X > 0) {
  200. _textView.ProcessKey (new KeyEvent (Key.CursorLeft | Key.CtrlMask, new KeyModifiers ()));
  201. switch (iteration) {
  202. case 0:
  203. Assert.Equal (25, _textView.CursorPosition.X);
  204. Assert.Equal (0, _textView.CursorPosition.Y);
  205. Assert.Equal (0, _textView.SelectionStartColumn);
  206. Assert.Equal (0, _textView.SelectionStartRow);
  207. Assert.Equal (0, _textView.SelectedLength);
  208. Assert.Equal ("", _textView.SelectedText);
  209. break;
  210. case 1:
  211. Assert.Equal (20, _textView.CursorPosition.X);
  212. Assert.Equal (0, _textView.CursorPosition.Y);
  213. Assert.Equal (0, _textView.SelectionStartColumn);
  214. Assert.Equal (0, _textView.SelectionStartRow);
  215. Assert.Equal (0, _textView.SelectedLength);
  216. Assert.Equal ("", _textView.SelectedText);
  217. break;
  218. case 2:
  219. Assert.Equal (12, _textView.CursorPosition.X);
  220. Assert.Equal (0, _textView.CursorPosition.Y);
  221. Assert.Equal (0, _textView.SelectionStartColumn);
  222. Assert.Equal (0, _textView.SelectionStartRow);
  223. Assert.Equal (0, _textView.SelectedLength);
  224. Assert.Equal ("", _textView.SelectedText);
  225. break;
  226. case 3:
  227. Assert.Equal (7, _textView.CursorPosition.X);
  228. Assert.Equal (0, _textView.CursorPosition.Y);
  229. Assert.Equal (0, _textView.SelectionStartColumn);
  230. Assert.Equal (0, _textView.SelectionStartRow);
  231. Assert.Equal (0, _textView.SelectedLength);
  232. Assert.Equal ("", _textView.SelectedText);
  233. break;
  234. case 4:
  235. Assert.Equal (4, _textView.CursorPosition.X);
  236. Assert.Equal (0, _textView.CursorPosition.Y);
  237. Assert.Equal (0, _textView.SelectionStartColumn);
  238. Assert.Equal (0, _textView.SelectionStartRow);
  239. Assert.Equal (0, _textView.SelectedLength);
  240. Assert.Equal ("", _textView.SelectedText);
  241. break;
  242. case 5:
  243. Assert.Equal (0, _textView.CursorPosition.X);
  244. Assert.Equal (0, _textView.CursorPosition.Y);
  245. Assert.Equal (0, _textView.SelectionStartColumn);
  246. Assert.Equal (0, _textView.SelectionStartRow);
  247. Assert.Equal (0, _textView.SelectedLength);
  248. Assert.Equal ("", _textView.SelectedText);
  249. break;
  250. }
  251. iteration++;
  252. }
  253. }
  254. [Fact]
  255. [InitShutdown]
  256. public void WordForward_With_Selection ()
  257. {
  258. _textView.CursorPosition = new Point (0, 0);
  259. _textView.SelectionStartColumn = 0;
  260. _textView.SelectionStartRow = 0;
  261. var iteration = 0;
  262. while (_textView.CursorPosition.X < _textView.Text.Length) {
  263. _textView.ProcessKey (new KeyEvent (Key.CursorRight | Key.CtrlMask | Key.ShiftMask, new KeyModifiers ()));
  264. switch (iteration) {
  265. case 0:
  266. Assert.Equal (4, _textView.CursorPosition.X);
  267. Assert.Equal (0, _textView.CursorPosition.Y);
  268. Assert.Equal (0, _textView.SelectionStartColumn);
  269. Assert.Equal (0, _textView.SelectionStartRow);
  270. Assert.Equal (4, _textView.SelectedLength);
  271. Assert.Equal ("TAB ", _textView.SelectedText);
  272. break;
  273. case 1:
  274. Assert.Equal (7, _textView.CursorPosition.X);
  275. Assert.Equal (0, _textView.CursorPosition.Y);
  276. Assert.Equal (0, _textView.SelectionStartColumn);
  277. Assert.Equal (0, _textView.SelectionStartRow);
  278. Assert.Equal (7, _textView.SelectedLength);
  279. Assert.Equal ("TAB to ", _textView.SelectedText);
  280. break;
  281. case 2:
  282. Assert.Equal (12, _textView.CursorPosition.X);
  283. Assert.Equal (0, _textView.CursorPosition.Y);
  284. Assert.Equal (0, _textView.SelectionStartColumn);
  285. Assert.Equal (0, _textView.SelectionStartRow);
  286. Assert.Equal (12, _textView.SelectedLength);
  287. Assert.Equal ("TAB to jump ", _textView.SelectedText);
  288. break;
  289. case 3:
  290. Assert.Equal (20, _textView.CursorPosition.X);
  291. Assert.Equal (0, _textView.CursorPosition.Y);
  292. Assert.Equal (0, _textView.SelectionStartColumn);
  293. Assert.Equal (0, _textView.SelectionStartRow);
  294. Assert.Equal (20, _textView.SelectedLength);
  295. Assert.Equal ("TAB to jump between ", _textView.SelectedText);
  296. break;
  297. case 4:
  298. Assert.Equal (25, _textView.CursorPosition.X);
  299. Assert.Equal (0, _textView.CursorPosition.Y);
  300. Assert.Equal (0, _textView.SelectionStartColumn);
  301. Assert.Equal (0, _textView.SelectionStartRow);
  302. Assert.Equal (25, _textView.SelectedLength);
  303. Assert.Equal ("TAB to jump between text ", _textView.SelectedText);
  304. break;
  305. case 5:
  306. Assert.Equal (32, _textView.CursorPosition.X);
  307. Assert.Equal (0, _textView.CursorPosition.Y);
  308. Assert.Equal (0, _textView.SelectionStartColumn);
  309. Assert.Equal (0, _textView.SelectionStartRow);
  310. Assert.Equal (32, _textView.SelectedLength);
  311. Assert.Equal ("TAB to jump between text fields.", _textView.SelectedText);
  312. break;
  313. }
  314. iteration++;
  315. }
  316. }
  317. [Fact]
  318. [InitShutdown]
  319. public void WordBackward_With_Selection ()
  320. {
  321. _textView.CursorPosition = new Point (_textView.Text.Length, 0);
  322. _textView.SelectionStartColumn = _textView.Text.Length;
  323. _textView.SelectionStartRow = 0;
  324. var iteration = 0;
  325. while (_textView.CursorPosition.X > 0) {
  326. _textView.ProcessKey (new KeyEvent (Key.CursorLeft | Key.CtrlMask | Key.ShiftMask, new KeyModifiers ()));
  327. switch (iteration) {
  328. case 0:
  329. Assert.Equal (25, _textView.CursorPosition.X);
  330. Assert.Equal (0, _textView.CursorPosition.Y);
  331. Assert.Equal (32, _textView.SelectionStartColumn);
  332. Assert.Equal (0, _textView.SelectionStartRow);
  333. Assert.Equal (7, _textView.SelectedLength);
  334. Assert.Equal ("fields.", _textView.SelectedText);
  335. break;
  336. case 1:
  337. Assert.Equal (20, _textView.CursorPosition.X);
  338. Assert.Equal (0, _textView.CursorPosition.Y);
  339. Assert.Equal (32, _textView.SelectionStartColumn);
  340. Assert.Equal (0, _textView.SelectionStartRow);
  341. Assert.Equal (12, _textView.SelectedLength);
  342. Assert.Equal ("text fields.", _textView.SelectedText);
  343. break;
  344. case 2:
  345. Assert.Equal (12, _textView.CursorPosition.X);
  346. Assert.Equal (0, _textView.CursorPosition.Y);
  347. Assert.Equal (32, _textView.SelectionStartColumn);
  348. Assert.Equal (0, _textView.SelectionStartRow);
  349. Assert.Equal (20, _textView.SelectedLength);
  350. Assert.Equal ("between text fields.", _textView.SelectedText);
  351. break;
  352. case 3:
  353. Assert.Equal (7, _textView.CursorPosition.X);
  354. Assert.Equal (0, _textView.CursorPosition.Y);
  355. Assert.Equal (32, _textView.SelectionStartColumn);
  356. Assert.Equal (0, _textView.SelectionStartRow);
  357. Assert.Equal (25, _textView.SelectedLength);
  358. Assert.Equal ("jump between text fields.", _textView.SelectedText);
  359. break;
  360. case 4:
  361. Assert.Equal (4, _textView.CursorPosition.X);
  362. Assert.Equal (0, _textView.CursorPosition.Y);
  363. Assert.Equal (32, _textView.SelectionStartColumn);
  364. Assert.Equal (0, _textView.SelectionStartRow);
  365. Assert.Equal (28, _textView.SelectedLength);
  366. Assert.Equal ("to jump between text fields.", _textView.SelectedText);
  367. break;
  368. case 5:
  369. Assert.Equal (0, _textView.CursorPosition.X);
  370. Assert.Equal (0, _textView.CursorPosition.Y);
  371. Assert.Equal (32, _textView.SelectionStartColumn);
  372. Assert.Equal (0, _textView.SelectionStartRow);
  373. Assert.Equal (32, _textView.SelectedLength);
  374. Assert.Equal ("TAB to jump between text fields.", _textView.SelectedText);
  375. break;
  376. }
  377. iteration++;
  378. }
  379. }
  380. [Fact]
  381. [InitShutdown]
  382. public void WordForward_With_The_Same_Values_For_SelectedStart_And_CursorPosition_And_Not_Starting_At_Beginning_Of_The_Text ()
  383. {
  384. _textView.CursorPosition = new Point (10, 0);
  385. _textView.SelectionStartColumn = 10;
  386. _textView.SelectionStartRow = 0;
  387. var iteration = 0;
  388. while (_textView.CursorPosition.X < _textView.Text.Length) {
  389. _textView.ProcessKey (new KeyEvent (Key.CursorRight | Key.CtrlMask | Key.ShiftMask, new KeyModifiers ()));
  390. switch (iteration) {
  391. case 0:
  392. Assert.Equal (12, _textView.CursorPosition.X);
  393. Assert.Equal (0, _textView.CursorPosition.Y);
  394. Assert.Equal (10, _textView.SelectionStartColumn);
  395. Assert.Equal (0, _textView.SelectionStartRow);
  396. Assert.Equal (2, _textView.SelectedLength);
  397. Assert.Equal ("p ", _textView.SelectedText);
  398. break;
  399. case 1:
  400. Assert.Equal (20, _textView.CursorPosition.X);
  401. Assert.Equal (0, _textView.CursorPosition.Y);
  402. Assert.Equal (10, _textView.SelectionStartColumn);
  403. Assert.Equal (0, _textView.SelectionStartRow);
  404. Assert.Equal (10, _textView.SelectedLength);
  405. Assert.Equal ("p between ", _textView.SelectedText);
  406. break;
  407. case 2:
  408. Assert.Equal (25, _textView.CursorPosition.X);
  409. Assert.Equal (0, _textView.CursorPosition.Y);
  410. Assert.Equal (10, _textView.SelectionStartColumn);
  411. Assert.Equal (0, _textView.SelectionStartRow);
  412. Assert.Equal (15, _textView.SelectedLength);
  413. Assert.Equal ("p between text ", _textView.SelectedText);
  414. break;
  415. case 3:
  416. Assert.Equal (32, _textView.CursorPosition.X);
  417. Assert.Equal (0, _textView.CursorPosition.Y);
  418. Assert.Equal (10, _textView.SelectionStartColumn);
  419. Assert.Equal (0, _textView.SelectionStartRow);
  420. Assert.Equal (22, _textView.SelectedLength);
  421. Assert.Equal ("p between text fields.", _textView.SelectedText);
  422. break;
  423. }
  424. iteration++;
  425. }
  426. }
  427. [Fact]
  428. [InitShutdown]
  429. public void WordBackward_With_The_Same_Values_For_SelectedStart_And_CursorPosition_And_Not_Starting_At_Beginning_Of_The_Text ()
  430. {
  431. _textView.CursorPosition = new Point (10, 0);
  432. _textView.SelectionStartColumn = 10;
  433. _textView.SelectionStartRow = 0;
  434. var iteration = 0;
  435. while (_textView.CursorPosition.X > 0) {
  436. _textView.ProcessKey (new KeyEvent (Key.CursorLeft | Key.CtrlMask | Key.ShiftMask, new KeyModifiers ()));
  437. switch (iteration) {
  438. case 0:
  439. Assert.Equal (7, _textView.CursorPosition.X);
  440. Assert.Equal (0, _textView.CursorPosition.Y);
  441. Assert.Equal (10, _textView.SelectionStartColumn);
  442. Assert.Equal (0, _textView.SelectionStartRow);
  443. Assert.Equal (3, _textView.SelectedLength);
  444. Assert.Equal ("jum", _textView.SelectedText);
  445. break;
  446. case 1:
  447. Assert.Equal (4, _textView.CursorPosition.X);
  448. Assert.Equal (0, _textView.CursorPosition.Y);
  449. Assert.Equal (10, _textView.SelectionStartColumn);
  450. Assert.Equal (0, _textView.SelectionStartRow);
  451. Assert.Equal (6, _textView.SelectedLength);
  452. Assert.Equal ("to jum", _textView.SelectedText);
  453. break;
  454. case 2:
  455. Assert.Equal (0, _textView.CursorPosition.X);
  456. Assert.Equal (0, _textView.CursorPosition.Y);
  457. Assert.Equal (10, _textView.SelectionStartColumn);
  458. Assert.Equal (0, _textView.SelectionStartRow);
  459. Assert.Equal (10, _textView.SelectedLength);
  460. Assert.Equal ("TAB to jum", _textView.SelectedText);
  461. break;
  462. }
  463. iteration++;
  464. }
  465. }
  466. [Fact]
  467. [InitShutdown]
  468. public void WordForward_With_No_Selection_And_With_More_Than_Only_One_Whitespace_And_With_Only_One_Letter ()
  469. {
  470. // 1 2 3 4 5
  471. // 0123456789012345678901234567890123456789012345678901234=55 (Length)
  472. _textView.Text = "TAB t o jump b etween t ext f ields .";
  473. _textView.CursorPosition = new Point (0, 0);
  474. var iteration = 0;
  475. while (_textView.CursorPosition.X < _textView.Text.Length) {
  476. _textView.ProcessKey (new KeyEvent (Key.CursorRight | Key.CtrlMask, new KeyModifiers ()));
  477. switch (iteration) {
  478. case 0:
  479. Assert.Equal (6, _textView.CursorPosition.X);
  480. Assert.Equal (0, _textView.CursorPosition.Y);
  481. Assert.Equal (0, _textView.SelectionStartColumn);
  482. Assert.Equal (0, _textView.SelectionStartRow);
  483. Assert.Equal (0, _textView.SelectedLength);
  484. Assert.Equal ("", _textView.SelectedText);
  485. break;
  486. case 1:
  487. Assert.Equal (9, _textView.CursorPosition.X);
  488. Assert.Equal (0, _textView.CursorPosition.Y);
  489. Assert.Equal (0, _textView.SelectionStartColumn);
  490. Assert.Equal (0, _textView.SelectionStartRow);
  491. Assert.Equal (0, _textView.SelectedLength);
  492. Assert.Equal ("", _textView.SelectedText);
  493. break;
  494. case 2:
  495. Assert.Equal (12, _textView.CursorPosition.X);
  496. Assert.Equal (0, _textView.CursorPosition.Y);
  497. Assert.Equal (0, _textView.SelectionStartColumn);
  498. Assert.Equal (0, _textView.SelectionStartRow);
  499. Assert.Equal (0, _textView.SelectedLength);
  500. Assert.Equal ("", _textView.SelectedText);
  501. break;
  502. case 3:
  503. Assert.Equal (25, _textView.CursorPosition.X);
  504. Assert.Equal (0, _textView.CursorPosition.Y);
  505. Assert.Equal (0, _textView.SelectionStartColumn);
  506. Assert.Equal (0, _textView.SelectionStartRow);
  507. Assert.Equal (0, _textView.SelectedLength);
  508. Assert.Equal ("", _textView.SelectedText);
  509. break;
  510. case 4:
  511. Assert.Equal (28, _textView.CursorPosition.X);
  512. Assert.Equal (0, _textView.CursorPosition.Y);
  513. Assert.Equal (0, _textView.SelectionStartColumn);
  514. Assert.Equal (0, _textView.SelectionStartRow);
  515. Assert.Equal (0, _textView.SelectedLength);
  516. Assert.Equal ("", _textView.SelectedText);
  517. break;
  518. case 5:
  519. Assert.Equal (38, _textView.CursorPosition.X);
  520. Assert.Equal (0, _textView.CursorPosition.Y);
  521. Assert.Equal (0, _textView.SelectionStartColumn);
  522. Assert.Equal (0, _textView.SelectionStartRow);
  523. Assert.Equal (0, _textView.SelectedLength);
  524. Assert.Equal ("", _textView.SelectedText);
  525. break;
  526. case 6:
  527. Assert.Equal (40, _textView.CursorPosition.X);
  528. Assert.Equal (0, _textView.CursorPosition.Y);
  529. Assert.Equal (0, _textView.SelectionStartColumn);
  530. Assert.Equal (0, _textView.SelectionStartRow);
  531. Assert.Equal (0, _textView.SelectedLength);
  532. Assert.Equal ("", _textView.SelectedText);
  533. break;
  534. case 7:
  535. Assert.Equal (46, _textView.CursorPosition.X);
  536. Assert.Equal (0, _textView.CursorPosition.Y);
  537. Assert.Equal (0, _textView.SelectionStartColumn);
  538. Assert.Equal (0, _textView.SelectionStartRow);
  539. Assert.Equal (0, _textView.SelectedLength);
  540. Assert.Equal ("", _textView.SelectedText);
  541. break;
  542. case 8:
  543. Assert.Equal (48, _textView.CursorPosition.X);
  544. Assert.Equal (0, _textView.CursorPosition.Y);
  545. Assert.Equal (0, _textView.SelectionStartColumn);
  546. Assert.Equal (0, _textView.SelectionStartRow);
  547. Assert.Equal (0, _textView.SelectedLength);
  548. Assert.Equal ("", _textView.SelectedText);
  549. break;
  550. case 9:
  551. Assert.Equal (54, _textView.CursorPosition.X);
  552. Assert.Equal (0, _textView.CursorPosition.Y);
  553. Assert.Equal (0, _textView.SelectionStartColumn);
  554. Assert.Equal (0, _textView.SelectionStartRow);
  555. Assert.Equal (0, _textView.SelectedLength);
  556. Assert.Equal ("", _textView.SelectedText);
  557. break;
  558. case 10:
  559. Assert.Equal (55, _textView.CursorPosition.X);
  560. Assert.Equal (0, _textView.CursorPosition.Y);
  561. Assert.Equal (0, _textView.SelectionStartColumn);
  562. Assert.Equal (0, _textView.SelectionStartRow);
  563. Assert.Equal (0, _textView.SelectedLength);
  564. Assert.Equal ("", _textView.SelectedText);
  565. break;
  566. }
  567. iteration++;
  568. }
  569. }
  570. [Fact]
  571. [InitShutdown]
  572. public void WordBackward_With_No_Selection_And_With_More_Than_Only_One_Whitespace_And_With_Only_One_Letter ()
  573. {
  574. // 1 2 3 4 5
  575. // 0123456789012345678901234567890123456789012345678901234=55 (Length)
  576. _textView.Text = "TAB t o jump b etween t ext f ields .";
  577. _textView.CursorPosition = new Point (_textView.Text.Length, 0);
  578. var iteration = 0;
  579. while (_textView.CursorPosition.X > 0) {
  580. _textView.ProcessKey (new KeyEvent (Key.CursorLeft | Key.CtrlMask, new KeyModifiers ()));
  581. switch (iteration) {
  582. case 0:
  583. Assert.Equal (54, _textView.CursorPosition.X);
  584. Assert.Equal (0, _textView.CursorPosition.Y);
  585. Assert.Equal (0, _textView.SelectionStartColumn);
  586. Assert.Equal (0, _textView.SelectionStartRow);
  587. Assert.Equal (0, _textView.SelectedLength);
  588. Assert.Equal ("", _textView.SelectedText);
  589. break;
  590. case 1:
  591. Assert.Equal (48, _textView.CursorPosition.X);
  592. Assert.Equal (0, _textView.CursorPosition.Y);
  593. Assert.Equal (0, _textView.SelectionStartColumn);
  594. Assert.Equal (0, _textView.SelectionStartRow);
  595. Assert.Equal (0, _textView.SelectedLength);
  596. Assert.Equal ("", _textView.SelectedText);
  597. break;
  598. case 2:
  599. Assert.Equal (46, _textView.CursorPosition.X);
  600. Assert.Equal (0, _textView.CursorPosition.Y);
  601. Assert.Equal (0, _textView.SelectionStartColumn);
  602. Assert.Equal (0, _textView.SelectionStartRow);
  603. Assert.Equal (0, _textView.SelectedLength);
  604. Assert.Equal ("", _textView.SelectedText);
  605. break;
  606. case 3:
  607. Assert.Equal (40, _textView.CursorPosition.X);
  608. Assert.Equal (0, _textView.CursorPosition.Y);
  609. Assert.Equal (0, _textView.SelectionStartColumn);
  610. Assert.Equal (0, _textView.SelectionStartRow);
  611. Assert.Equal (0, _textView.SelectedLength);
  612. Assert.Equal ("", _textView.SelectedText);
  613. break;
  614. case 4:
  615. Assert.Equal (38, _textView.CursorPosition.X);
  616. Assert.Equal (0, _textView.CursorPosition.Y);
  617. Assert.Equal (0, _textView.SelectionStartColumn);
  618. Assert.Equal (0, _textView.SelectionStartRow);
  619. Assert.Equal (0, _textView.SelectedLength);
  620. Assert.Equal ("", _textView.SelectedText);
  621. break;
  622. case 5:
  623. Assert.Equal (28, _textView.CursorPosition.X);
  624. Assert.Equal (0, _textView.CursorPosition.Y);
  625. Assert.Equal (0, _textView.SelectionStartColumn);
  626. Assert.Equal (0, _textView.SelectionStartRow);
  627. Assert.Equal (0, _textView.SelectedLength);
  628. Assert.Equal ("", _textView.SelectedText);
  629. break;
  630. case 6:
  631. Assert.Equal (25, _textView.CursorPosition.X);
  632. Assert.Equal (0, _textView.CursorPosition.Y);
  633. Assert.Equal (0, _textView.SelectionStartColumn);
  634. Assert.Equal (0, _textView.SelectionStartRow);
  635. Assert.Equal (0, _textView.SelectedLength);
  636. Assert.Equal ("", _textView.SelectedText);
  637. break;
  638. case 7:
  639. Assert.Equal (12, _textView.CursorPosition.X);
  640. Assert.Equal (0, _textView.CursorPosition.Y);
  641. Assert.Equal (0, _textView.SelectionStartColumn);
  642. Assert.Equal (0, _textView.SelectionStartRow);
  643. Assert.Equal (0, _textView.SelectedLength);
  644. Assert.Equal ("", _textView.SelectedText);
  645. break;
  646. case 8:
  647. Assert.Equal (9, _textView.CursorPosition.X);
  648. Assert.Equal (0, _textView.CursorPosition.Y);
  649. Assert.Equal (0, _textView.SelectionStartColumn);
  650. Assert.Equal (0, _textView.SelectionStartRow);
  651. Assert.Equal (0, _textView.SelectedLength);
  652. Assert.Equal ("", _textView.SelectedText);
  653. break;
  654. case 9:
  655. Assert.Equal (6, _textView.CursorPosition.X);
  656. Assert.Equal (0, _textView.CursorPosition.Y);
  657. Assert.Equal (0, _textView.SelectionStartColumn);
  658. Assert.Equal (0, _textView.SelectionStartRow);
  659. Assert.Equal (0, _textView.SelectedLength);
  660. Assert.Equal ("", _textView.SelectedText);
  661. break;
  662. case 10:
  663. Assert.Equal (0, _textView.CursorPosition.X);
  664. Assert.Equal (0, _textView.CursorPosition.Y);
  665. Assert.Equal (0, _textView.SelectionStartColumn);
  666. Assert.Equal (0, _textView.SelectionStartRow);
  667. Assert.Equal (0, _textView.SelectedLength);
  668. Assert.Equal ("", _textView.SelectedText);
  669. break;
  670. }
  671. iteration++;
  672. }
  673. }
  674. [Fact]
  675. [InitShutdown]
  676. public void WordBackward_Multiline_With_Selection ()
  677. {
  678. // 4 3 2 1
  679. // 87654321098765432109876 54321098765432109876543210-Length
  680. // 1 2 1 2
  681. // 01234567890123456789012 0123456789012345678901234
  682. _textView.Text = "This is the first line.\nThis is the second line.";
  683. _textView.MoveEnd ();
  684. _textView.SelectionStartColumn = _textView.CurrentColumn;
  685. _textView.SelectionStartRow = _textView.CurrentRow;
  686. var iteration = 0;
  687. bool iterationsFinished = false;
  688. while (!iterationsFinished) {
  689. _textView.ProcessKey (new KeyEvent (Key.CursorLeft | Key.CtrlMask | Key.ShiftMask, new KeyModifiers ()));
  690. switch (iteration) {
  691. case 0:
  692. Assert.Equal (19, _textView.CursorPosition.X);
  693. Assert.Equal (1, _textView.CursorPosition.Y);
  694. Assert.Equal (24, _textView.SelectionStartColumn);
  695. Assert.Equal (1, _textView.SelectionStartRow);
  696. Assert.Equal (5, _textView.SelectedLength);
  697. Assert.Equal ("line.", _textView.SelectedText);
  698. break;
  699. case 1:
  700. Assert.Equal (12, _textView.CursorPosition.X);
  701. Assert.Equal (1, _textView.CursorPosition.Y);
  702. Assert.Equal (24, _textView.SelectionStartColumn);
  703. Assert.Equal (1, _textView.SelectionStartRow);
  704. Assert.Equal (12, _textView.SelectedLength);
  705. Assert.Equal ("second line.", _textView.SelectedText);
  706. break;
  707. case 2:
  708. Assert.Equal (8, _textView.CursorPosition.X);
  709. Assert.Equal (1, _textView.CursorPosition.Y);
  710. Assert.Equal (24, _textView.SelectionStartColumn);
  711. Assert.Equal (1, _textView.SelectionStartRow);
  712. Assert.Equal (16, _textView.SelectedLength);
  713. Assert.Equal ("the second line.", _textView.SelectedText);
  714. break;
  715. case 3:
  716. Assert.Equal (5, _textView.CursorPosition.X);
  717. Assert.Equal (1, _textView.CursorPosition.Y);
  718. Assert.Equal (24, _textView.SelectionStartColumn);
  719. Assert.Equal (1, _textView.SelectionStartRow);
  720. Assert.Equal (19, _textView.SelectedLength);
  721. Assert.Equal ("is the second line.", _textView.SelectedText);
  722. break;
  723. case 4:
  724. Assert.Equal (0, _textView.CursorPosition.X);
  725. Assert.Equal (1, _textView.CursorPosition.Y);
  726. Assert.Equal (24, _textView.SelectionStartColumn);
  727. Assert.Equal (1, _textView.SelectionStartRow);
  728. Assert.Equal (24, _textView.SelectedLength);
  729. Assert.Equal ("This is the second line.", _textView.SelectedText);
  730. break;
  731. case 5:
  732. Assert.Equal (23, _textView.CursorPosition.X);
  733. Assert.Equal (0, _textView.CursorPosition.Y);
  734. Assert.Equal (24, _textView.SelectionStartColumn);
  735. Assert.Equal (1, _textView.SelectionStartRow);
  736. Assert.Equal (24 + Environment.NewLine.Length, _textView.SelectedLength);
  737. Assert.Equal ($"{Environment.NewLine}This is the second line.", _textView.SelectedText);
  738. break;
  739. case 6:
  740. Assert.Equal (18, _textView.CursorPosition.X);
  741. Assert.Equal (0, _textView.CursorPosition.Y);
  742. Assert.Equal (24, _textView.SelectionStartColumn);
  743. Assert.Equal (1, _textView.SelectionStartRow);
  744. Assert.Equal (29 + Environment.NewLine.Length, _textView.SelectedLength);
  745. Assert.Equal ($"line.{Environment.NewLine}This is the second line.", _textView.SelectedText);
  746. break;
  747. case 7:
  748. Assert.Equal (12, _textView.CursorPosition.X);
  749. Assert.Equal (0, _textView.CursorPosition.Y);
  750. Assert.Equal (24, _textView.SelectionStartColumn);
  751. Assert.Equal (1, _textView.SelectionStartRow);
  752. Assert.Equal (35 + Environment.NewLine.Length, _textView.SelectedLength);
  753. Assert.Equal ($"first line.{Environment.NewLine}This is the second line.", _textView.SelectedText);
  754. break;
  755. case 8:
  756. Assert.Equal (8, _textView.CursorPosition.X);
  757. Assert.Equal (0, _textView.CursorPosition.Y);
  758. Assert.Equal (24, _textView.SelectionStartColumn);
  759. Assert.Equal (1, _textView.SelectionStartRow);
  760. Assert.Equal (39 + Environment.NewLine.Length, _textView.SelectedLength);
  761. Assert.Equal ($"the first line.{Environment.NewLine}This is the second line.", _textView.SelectedText);
  762. break;
  763. case 9:
  764. Assert.Equal (5, _textView.CursorPosition.X);
  765. Assert.Equal (0, _textView.CursorPosition.Y);
  766. Assert.Equal (24, _textView.SelectionStartColumn);
  767. Assert.Equal (1, _textView.SelectionStartRow);
  768. Assert.Equal (42 + Environment.NewLine.Length, _textView.SelectedLength);
  769. Assert.Equal ($"is the first line.{Environment.NewLine}This is the second line.", _textView.SelectedText);
  770. break;
  771. case 10:
  772. Assert.Equal (0, _textView.CursorPosition.X);
  773. Assert.Equal (0, _textView.CursorPosition.Y);
  774. Assert.Equal (24, _textView.SelectionStartColumn);
  775. Assert.Equal (1, _textView.SelectionStartRow);
  776. Assert.Equal (47 + Environment.NewLine.Length, _textView.SelectedLength);
  777. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.", _textView.SelectedText);
  778. break;
  779. default:
  780. iterationsFinished = true;
  781. break;
  782. }
  783. iteration++;
  784. }
  785. }
  786. [Fact]
  787. [InitShutdown]
  788. public void WordForward_Multiline_With_Selection ()
  789. {
  790. // 1 2 3 4
  791. // 01234567890123456789012 34567890123456789012345678-Length
  792. // 1 2 1 2
  793. // 01234567890123456789012 0123456789012345678901234
  794. _textView.Text = "This is the first line.\nThis is the second line.";
  795. _textView.SelectionStartColumn = _textView.CurrentColumn;
  796. _textView.SelectionStartRow = _textView.CurrentRow;
  797. var iteration = 0;
  798. bool iterationsFinished = false;
  799. while (!iterationsFinished) {
  800. _textView.ProcessKey (new KeyEvent (Key.CursorRight | Key.CtrlMask | Key.ShiftMask, new KeyModifiers ()));
  801. switch (iteration) {
  802. case 0:
  803. Assert.Equal (5, _textView.CursorPosition.X);
  804. Assert.Equal (0, _textView.CursorPosition.Y);
  805. Assert.Equal (0, _textView.SelectionStartColumn);
  806. Assert.Equal (0, _textView.SelectionStartRow);
  807. Assert.Equal (5, _textView.SelectedLength);
  808. Assert.Equal ("This ", _textView.SelectedText);
  809. break;
  810. case 1:
  811. Assert.Equal (8, _textView.CursorPosition.X);
  812. Assert.Equal (0, _textView.CursorPosition.Y);
  813. Assert.Equal (0, _textView.SelectionStartColumn);
  814. Assert.Equal (0, _textView.SelectionStartRow);
  815. Assert.Equal (8, _textView.SelectedLength);
  816. Assert.Equal ("This is ", _textView.SelectedText);
  817. break;
  818. case 2:
  819. Assert.Equal (12, _textView.CursorPosition.X);
  820. Assert.Equal (0, _textView.CursorPosition.Y);
  821. Assert.Equal (0, _textView.SelectionStartColumn);
  822. Assert.Equal (0, _textView.SelectionStartRow);
  823. Assert.Equal (12, _textView.SelectedLength);
  824. Assert.Equal ("This is the ", _textView.SelectedText);
  825. break;
  826. case 3:
  827. Assert.Equal (18, _textView.CursorPosition.X);
  828. Assert.Equal (0, _textView.CursorPosition.Y);
  829. Assert.Equal (0, _textView.SelectionStartColumn);
  830. Assert.Equal (0, _textView.SelectionStartRow);
  831. Assert.Equal (18, _textView.SelectedLength);
  832. Assert.Equal ("This is the first ", _textView.SelectedText);
  833. break;
  834. case 4:
  835. Assert.Equal (23, _textView.CursorPosition.X);
  836. Assert.Equal (0, _textView.CursorPosition.Y);
  837. Assert.Equal (0, _textView.SelectionStartColumn);
  838. Assert.Equal (0, _textView.SelectionStartRow);
  839. Assert.Equal (23, _textView.SelectedLength);
  840. Assert.Equal ("This is the first line.", _textView.SelectedText);
  841. break;
  842. case 5:
  843. Assert.Equal (0, _textView.CursorPosition.X);
  844. Assert.Equal (1, _textView.CursorPosition.Y);
  845. Assert.Equal (0, _textView.SelectionStartColumn);
  846. Assert.Equal (0, _textView.SelectionStartRow);
  847. Assert.Equal (23 + Environment.NewLine.Length, _textView.SelectedLength);
  848. Assert.Equal ($"This is the first line.{Environment.NewLine}", _textView.SelectedText);
  849. break;
  850. case 6:
  851. Assert.Equal (5, _textView.CursorPosition.X);
  852. Assert.Equal (1, _textView.CursorPosition.Y);
  853. Assert.Equal (0, _textView.SelectionStartColumn);
  854. Assert.Equal (0, _textView.SelectionStartRow);
  855. Assert.Equal (28 + Environment.NewLine.Length, _textView.SelectedLength);
  856. Assert.Equal ($"This is the first line.{Environment.NewLine}This ", _textView.SelectedText);
  857. break;
  858. case 7:
  859. Assert.Equal (8, _textView.CursorPosition.X);
  860. Assert.Equal (1, _textView.CursorPosition.Y);
  861. Assert.Equal (0, _textView.SelectionStartColumn);
  862. Assert.Equal (0, _textView.SelectionStartRow);
  863. Assert.Equal (31 + Environment.NewLine.Length, _textView.SelectedLength);
  864. Assert.Equal ($"This is the first line.{Environment.NewLine}This is ", _textView.SelectedText);
  865. break;
  866. case 8:
  867. Assert.Equal (12, _textView.CursorPosition.X);
  868. Assert.Equal (1, _textView.CursorPosition.Y);
  869. Assert.Equal (0, _textView.SelectionStartColumn);
  870. Assert.Equal (0, _textView.SelectionStartRow);
  871. Assert.Equal (35 + Environment.NewLine.Length, _textView.SelectedLength);
  872. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the ", _textView.SelectedText);
  873. break;
  874. case 9:
  875. Assert.Equal (19, _textView.CursorPosition.X);
  876. Assert.Equal (1, _textView.CursorPosition.Y);
  877. Assert.Equal (0, _textView.SelectionStartColumn);
  878. Assert.Equal (0, _textView.SelectionStartRow);
  879. Assert.Equal (42 + Environment.NewLine.Length, _textView.SelectedLength);
  880. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second ", _textView.SelectedText);
  881. break;
  882. case 10:
  883. Assert.Equal (24, _textView.CursorPosition.X);
  884. Assert.Equal (1, _textView.CursorPosition.Y);
  885. Assert.Equal (0, _textView.SelectionStartColumn);
  886. Assert.Equal (0, _textView.SelectionStartRow);
  887. Assert.Equal (47 + Environment.NewLine.Length, _textView.SelectedLength);
  888. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.", _textView.SelectedText);
  889. break;
  890. default:
  891. iterationsFinished = true;
  892. break;
  893. }
  894. iteration++;
  895. }
  896. }
  897. [Fact]
  898. [InitShutdown]
  899. public void Kill_To_End_Delete_Forwards_And_Copy_To_The_Clipboard ()
  900. {
  901. _textView.Text = "This is the first line.\nThis is the second line.";
  902. var iteration = 0;
  903. bool iterationsFinished = false;
  904. while (!iterationsFinished) {
  905. switch (iteration) {
  906. case 0:
  907. _textView.ProcessKey (new KeyEvent (Key.K | Key.CtrlMask, new KeyModifiers ()));
  908. Assert.Equal (0, _textView.CursorPosition.X);
  909. Assert.Equal (0, _textView.CursorPosition.Y);
  910. Assert.Equal ($"{Environment.NewLine}This is the second line.", _textView.Text);
  911. Assert.Equal ("This is the first line.", Clipboard.Contents);
  912. break;
  913. case 1:
  914. _textView.ProcessKey (new KeyEvent (Key.DeleteChar | Key.CtrlMask | Key.ShiftMask, new KeyModifiers ()));
  915. Assert.Equal (0, _textView.CursorPosition.X);
  916. Assert.Equal (0, _textView.CursorPosition.Y);
  917. Assert.Equal ("This is the second line.", _textView.Text);
  918. Assert.Equal ($"This is the first line.{Environment.NewLine}", Clipboard.Contents);
  919. break;
  920. case 2:
  921. _textView.ProcessKey (new KeyEvent (Key.K | Key.CtrlMask, new KeyModifiers ()));
  922. Assert.Equal (0, _textView.CursorPosition.X);
  923. Assert.Equal (0, _textView.CursorPosition.Y);
  924. Assert.Equal ("", _textView.Text);
  925. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.", Clipboard.Contents);
  926. // Paste
  927. _textView.ProcessKey (new KeyEvent (Key.Y | Key.CtrlMask, new KeyModifiers ()));
  928. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.", _textView.Text);
  929. break;
  930. default:
  931. iterationsFinished = true;
  932. break;
  933. }
  934. iteration++;
  935. }
  936. }
  937. [Fact]
  938. [InitShutdown]
  939. public void Kill_To_Start_Delete_Backwards_And_Copy_To_The_Clipboard ()
  940. {
  941. _textView.Text = "This is the first line.\nThis is the second line.";
  942. _textView.MoveEnd ();
  943. var iteration = 0;
  944. bool iterationsFinished = false;
  945. while (!iterationsFinished) {
  946. switch (iteration) {
  947. case 0:
  948. _textView.ProcessKey (new KeyEvent (Key.K | Key.AltMask, new KeyModifiers ()));
  949. Assert.Equal (0, _textView.CursorPosition.X);
  950. Assert.Equal (1, _textView.CursorPosition.Y);
  951. Assert.Equal ($"This is the first line.{Environment.NewLine}", _textView.Text);
  952. Assert.Equal ($"This is the second line.", Clipboard.Contents);
  953. break;
  954. case 1:
  955. _textView.ProcessKey (new KeyEvent (Key.Backspace | Key.CtrlMask | Key.ShiftMask, new KeyModifiers ()));
  956. Assert.Equal (23, _textView.CursorPosition.X);
  957. Assert.Equal (0, _textView.CursorPosition.Y);
  958. Assert.Equal ("This is the first line.", _textView.Text);
  959. Assert.Equal ($"This is the second line.{Environment.NewLine}", Clipboard.Contents);
  960. break;
  961. case 2:
  962. _textView.ProcessKey (new KeyEvent (Key.K | Key.AltMask, new KeyModifiers ()));
  963. Assert.Equal (0, _textView.CursorPosition.X);
  964. Assert.Equal (0, _textView.CursorPosition.Y);
  965. Assert.Equal ("", _textView.Text);
  966. Assert.Equal ($"This is the second line.{Environment.NewLine}This is the first line.", Clipboard.Contents);
  967. // Paste inverted
  968. _textView.ProcessKey (new KeyEvent (Key.Y | Key.CtrlMask, new KeyModifiers ()));
  969. Assert.Equal ($"This is the second line.{Environment.NewLine}This is the first line.", _textView.Text);
  970. break;
  971. default:
  972. iterationsFinished = true;
  973. break;
  974. }
  975. iteration++;
  976. }
  977. }
  978. [Fact]
  979. [InitShutdown]
  980. public void Kill_Delete_WordForward ()
  981. {
  982. _textView.Text = "This is the first line.";
  983. var iteration = 0;
  984. bool iterationsFinished = false;
  985. while (!iterationsFinished) {
  986. _textView.ProcessKey (new KeyEvent (Key.DeleteChar | Key.CtrlMask, new KeyModifiers ()));
  987. switch (iteration) {
  988. case 0:
  989. Assert.Equal (0, _textView.CursorPosition.X);
  990. Assert.Equal (0, _textView.CursorPosition.Y);
  991. Assert.Equal ("is the first line.", _textView.Text);
  992. break;
  993. case 1:
  994. Assert.Equal (0, _textView.CursorPosition.X);
  995. Assert.Equal (0, _textView.CursorPosition.Y);
  996. Assert.Equal ("the first line.", _textView.Text);
  997. break;
  998. case 2:
  999. Assert.Equal (0, _textView.CursorPosition.X);
  1000. Assert.Equal (0, _textView.CursorPosition.Y);
  1001. Assert.Equal ("first line.", _textView.Text);
  1002. break;
  1003. case 3:
  1004. Assert.Equal (0, _textView.CursorPosition.X);
  1005. Assert.Equal (0, _textView.CursorPosition.Y);
  1006. Assert.Equal ("line.", _textView.Text);
  1007. break;
  1008. case 4:
  1009. Assert.Equal (0, _textView.CursorPosition.X);
  1010. Assert.Equal (0, _textView.CursorPosition.Y);
  1011. Assert.Equal ("", _textView.Text);
  1012. break;
  1013. default:
  1014. iterationsFinished = true;
  1015. break;
  1016. }
  1017. iteration++;
  1018. }
  1019. }
  1020. [Fact]
  1021. [InitShutdown]
  1022. public void Kill_Delete_WordBackward ()
  1023. {
  1024. _textView.Text = "This is the first line.";
  1025. _textView.MoveEnd ();
  1026. var iteration = 0;
  1027. bool iterationsFinished = false;
  1028. while (!iterationsFinished) {
  1029. _textView.ProcessKey (new KeyEvent (Key.Backspace | Key.CtrlMask, new KeyModifiers ()));
  1030. switch (iteration) {
  1031. case 0:
  1032. Assert.Equal (18, _textView.CursorPosition.X);
  1033. Assert.Equal (0, _textView.CursorPosition.Y);
  1034. Assert.Equal ("This is the first ", _textView.Text);
  1035. break;
  1036. case 1:
  1037. Assert.Equal (12, _textView.CursorPosition.X);
  1038. Assert.Equal (0, _textView.CursorPosition.Y);
  1039. Assert.Equal ("This is the ", _textView.Text);
  1040. break;
  1041. case 2:
  1042. Assert.Equal (8, _textView.CursorPosition.X);
  1043. Assert.Equal (0, _textView.CursorPosition.Y);
  1044. Assert.Equal ("This is ", _textView.Text);
  1045. break;
  1046. case 3:
  1047. Assert.Equal (5, _textView.CursorPosition.X);
  1048. Assert.Equal (0, _textView.CursorPosition.Y);
  1049. Assert.Equal ("This ", _textView.Text);
  1050. break;
  1051. case 4:
  1052. Assert.Equal (0, _textView.CursorPosition.X);
  1053. Assert.Equal (0, _textView.CursorPosition.Y);
  1054. Assert.Equal ("", _textView.Text);
  1055. break;
  1056. default:
  1057. iterationsFinished = true;
  1058. break;
  1059. }
  1060. iteration++;
  1061. }
  1062. }
  1063. [Fact]
  1064. [InitShutdown]
  1065. public void Kill_Delete_WordForward_Multiline ()
  1066. {
  1067. _textView.Text = "This is the first line.\nThis is the second line.";
  1068. _textView.Width = 4;
  1069. var iteration = 0;
  1070. bool iterationsFinished = false;
  1071. while (!iterationsFinished) {
  1072. _textView.ProcessKey (new KeyEvent (Key.DeleteChar | Key.CtrlMask, new KeyModifiers ()));
  1073. switch (iteration) {
  1074. case 0:
  1075. Assert.Equal (0, _textView.CursorPosition.X);
  1076. Assert.Equal (0, _textView.CursorPosition.Y);
  1077. Assert.Equal ("is the first line." + Environment.NewLine
  1078. + "This is the second line.", _textView.Text);
  1079. break;
  1080. case 1:
  1081. Assert.Equal (0, _textView.CursorPosition.X);
  1082. Assert.Equal (0, _textView.CursorPosition.Y);
  1083. Assert.Equal ("the first line." + Environment.NewLine
  1084. + "This is the second line.", _textView.Text);
  1085. break;
  1086. case 2:
  1087. Assert.Equal (0, _textView.CursorPosition.X);
  1088. Assert.Equal (0, _textView.CursorPosition.Y);
  1089. Assert.Equal ("first line." + Environment.NewLine
  1090. + "This is the second line.", _textView.Text);
  1091. break;
  1092. case 3:
  1093. Assert.Equal (0, _textView.CursorPosition.X);
  1094. Assert.Equal (0, _textView.CursorPosition.Y);
  1095. Assert.Equal ("line." + Environment.NewLine
  1096. + "This is the second line.", _textView.Text);
  1097. break;
  1098. case 4:
  1099. Assert.Equal (0, _textView.CursorPosition.X);
  1100. Assert.Equal (0, _textView.CursorPosition.Y);
  1101. Assert.Equal ("" + Environment.NewLine
  1102. + "This is the second line.", _textView.Text);
  1103. break;
  1104. case 5:
  1105. Assert.Equal (0, _textView.CursorPosition.X);
  1106. Assert.Equal (0, _textView.CursorPosition.Y);
  1107. Assert.Equal ("This is the second line.", _textView.Text);
  1108. break;
  1109. case 6:
  1110. Assert.Equal (0, _textView.CursorPosition.X);
  1111. Assert.Equal (0, _textView.CursorPosition.Y);
  1112. Assert.Equal ("is the second line.", _textView.Text);
  1113. break;
  1114. case 7:
  1115. Assert.Equal (0, _textView.CursorPosition.X);
  1116. Assert.Equal (0, _textView.CursorPosition.Y);
  1117. Assert.Equal ("the second line.", _textView.Text);
  1118. break;
  1119. case 8:
  1120. Assert.Equal (0, _textView.CursorPosition.X);
  1121. Assert.Equal (0, _textView.CursorPosition.Y);
  1122. Assert.Equal ("second line.", _textView.Text);
  1123. break;
  1124. case 9:
  1125. Assert.Equal (0, _textView.CursorPosition.X);
  1126. Assert.Equal (0, _textView.CursorPosition.Y);
  1127. Assert.Equal ("line.", _textView.Text);
  1128. break;
  1129. case 10:
  1130. Assert.Equal (0, _textView.CursorPosition.X);
  1131. Assert.Equal (0, _textView.CursorPosition.Y);
  1132. Assert.Equal ("", _textView.Text);
  1133. break;
  1134. default:
  1135. iterationsFinished = true;
  1136. break;
  1137. }
  1138. iteration++;
  1139. }
  1140. }
  1141. [Fact]
  1142. [InitShutdown]
  1143. public void Kill_Delete_WordBackward_Multiline ()
  1144. {
  1145. _textView.Text = "This is the first line.\nThis is the second line.";
  1146. _textView.Width = 4;
  1147. _textView.MoveEnd ();
  1148. var iteration = 0;
  1149. bool iterationsFinished = false;
  1150. while (!iterationsFinished) {
  1151. _textView.ProcessKey (new KeyEvent (Key.Backspace | Key.CtrlMask, new KeyModifiers ()));
  1152. switch (iteration) {
  1153. case 0:
  1154. Assert.Equal (19, _textView.CursorPosition.X);
  1155. Assert.Equal (1, _textView.CursorPosition.Y);
  1156. Assert.Equal ("This is the first line." + Environment.NewLine
  1157. + "This is the second ", _textView.Text);
  1158. break;
  1159. case 1:
  1160. Assert.Equal (12, _textView.CursorPosition.X);
  1161. Assert.Equal (1, _textView.CursorPosition.Y);
  1162. Assert.Equal ("This is the first line." + Environment.NewLine
  1163. + "This is the ", _textView.Text);
  1164. break;
  1165. case 2:
  1166. Assert.Equal (8, _textView.CursorPosition.X);
  1167. Assert.Equal (1, _textView.CursorPosition.Y);
  1168. Assert.Equal ("This is the first line." + Environment.NewLine
  1169. + "This is ", _textView.Text);
  1170. break;
  1171. case 3:
  1172. Assert.Equal (5, _textView.CursorPosition.X);
  1173. Assert.Equal (1, _textView.CursorPosition.Y);
  1174. Assert.Equal ("This is the first line." + Environment.NewLine
  1175. + "This ", _textView.Text);
  1176. break;
  1177. case 4:
  1178. Assert.Equal (0, _textView.CursorPosition.X);
  1179. Assert.Equal (1, _textView.CursorPosition.Y);
  1180. Assert.Equal ("This is the first line." + Environment.NewLine, _textView.Text);
  1181. break;
  1182. case 5:
  1183. Assert.Equal (23, _textView.CursorPosition.X);
  1184. Assert.Equal (0, _textView.CursorPosition.Y);
  1185. Assert.Equal ("This is the first line.", _textView.Text);
  1186. break;
  1187. case 6:
  1188. Assert.Equal (18, _textView.CursorPosition.X);
  1189. Assert.Equal (0, _textView.CursorPosition.Y);
  1190. Assert.Equal ("This is the first ", _textView.Text);
  1191. break;
  1192. case 7:
  1193. Assert.Equal (12, _textView.CursorPosition.X);
  1194. Assert.Equal (0, _textView.CursorPosition.Y);
  1195. Assert.Equal ("This is the ", _textView.Text);
  1196. break;
  1197. case 8:
  1198. Assert.Equal (8, _textView.CursorPosition.X);
  1199. Assert.Equal (0, _textView.CursorPosition.Y);
  1200. Assert.Equal ("This is ", _textView.Text);
  1201. break;
  1202. case 9:
  1203. Assert.Equal (5, _textView.CursorPosition.X);
  1204. Assert.Equal (0, _textView.CursorPosition.Y);
  1205. Assert.Equal ("This ", _textView.Text);
  1206. break;
  1207. case 10:
  1208. Assert.Equal (0, _textView.CursorPosition.X);
  1209. Assert.Equal (0, _textView.CursorPosition.Y);
  1210. Assert.Equal ("", _textView.Text);
  1211. break;
  1212. default:
  1213. iterationsFinished = true;
  1214. break;
  1215. }
  1216. iteration++;
  1217. }
  1218. }
  1219. [Fact]
  1220. [InitShutdown]
  1221. public void Copy_Or_Cut_Null_If_No_Selection ()
  1222. {
  1223. _textView.SelectionStartColumn = 0;
  1224. _textView.SelectionStartRow = 0;
  1225. _textView.ProcessKey (new KeyEvent (Key.C | Key.CtrlMask, new KeyModifiers ())); // Copy
  1226. Assert.Equal ("", _textView.SelectedText);
  1227. _textView.ProcessKey (new KeyEvent (Key.W | Key.CtrlMask, new KeyModifiers ())); // Cut
  1228. Assert.Equal ("", _textView.SelectedText);
  1229. }
  1230. [Fact]
  1231. [InitShutdown]
  1232. public void Copy_Or_Cut_Not_Null_If_Has_Selection ()
  1233. {
  1234. _textView.SelectionStartColumn = 20;
  1235. _textView.SelectionStartRow = 0;
  1236. _textView.CursorPosition = new Point (24, 0);
  1237. _textView.ProcessKey (new KeyEvent (Key.C | Key.CtrlMask, new KeyModifiers ())); // Copy
  1238. Assert.Equal ("text", _textView.SelectedText);
  1239. _textView.ProcessKey (new KeyEvent (Key.W | Key.CtrlMask, new KeyModifiers ())); // Cut
  1240. Assert.Equal ("", _textView.SelectedText);
  1241. }
  1242. [Fact]
  1243. [InitShutdown]
  1244. public void Copy_Or_Cut_And_Paste_With_Selection ()
  1245. {
  1246. _textView.SelectionStartColumn = 20;
  1247. _textView.SelectionStartRow = 0;
  1248. _textView.CursorPosition = new Point (24, 0);
  1249. _textView.ProcessKey (new KeyEvent (Key.C | Key.CtrlMask, new KeyModifiers ())); // Copy
  1250. Assert.Equal ("text", _textView.SelectedText);
  1251. Assert.Equal ("TAB to jump between text fields.", _textView.Text);
  1252. _textView.ProcessKey (new KeyEvent (Key.Y | Key.CtrlMask, new KeyModifiers ())); // Paste
  1253. Assert.Equal ("TAB to jump between text fields.", _textView.Text);
  1254. _textView.SelectionStartColumn = 20;
  1255. _textView.SelectionStartRow = 0;
  1256. _textView.ProcessKey (new KeyEvent (Key.W | Key.CtrlMask, new KeyModifiers ())); // Cut
  1257. _textView.ProcessKey (new KeyEvent (Key.Y | Key.CtrlMask, new KeyModifiers ())); // Paste
  1258. Assert.Equal ("TAB to jump between text fields.", _textView.Text);
  1259. }
  1260. [Fact]
  1261. [InitShutdown]
  1262. public void Copy_Or_Cut_And_Paste_With_No_Selection ()
  1263. {
  1264. _textView.SelectionStartColumn = 20;
  1265. _textView.SelectionStartRow = 0;
  1266. _textView.CursorPosition = new Point (24, 0);
  1267. _textView.ProcessKey (new KeyEvent (Key.C | Key.CtrlMask, new KeyModifiers ())); // Copy
  1268. Assert.Equal ("text", _textView.SelectedText);
  1269. Assert.Equal ("TAB to jump between text fields.", _textView.Text);
  1270. _textView.SelectionStartColumn = 0;
  1271. _textView.SelectionStartRow = 0;
  1272. Assert.Equal (new Point (24, 0), _textView.CursorPosition);
  1273. Assert.True (_textView.Selecting);
  1274. _textView.Selecting = false;
  1275. _textView.ProcessKey (new KeyEvent (Key.Y | Key.CtrlMask, new KeyModifiers ())); // Paste
  1276. Assert.Equal (new Point (28, 0), _textView.CursorPosition);
  1277. Assert.False (_textView.Selecting);
  1278. Assert.Equal ("TAB to jump between texttext fields.", _textView.Text);
  1279. _textView.SelectionStartColumn = 24;
  1280. _textView.SelectionStartRow = 0;
  1281. _textView.ProcessKey (new KeyEvent (Key.W | Key.CtrlMask, new KeyModifiers ())); // Cut
  1282. Assert.Equal (new Point (24, 0), _textView.CursorPosition);
  1283. Assert.False (_textView.Selecting);
  1284. Assert.Equal ("", _textView.SelectedText);
  1285. Assert.Equal ("TAB to jump between text fields.", _textView.Text);
  1286. _textView.SelectionStartColumn = 0;
  1287. _textView.SelectionStartRow = 0;
  1288. _textView.Selecting = false;
  1289. _textView.ProcessKey (new KeyEvent (Key.Y | Key.CtrlMask, new KeyModifiers ())); // Paste
  1290. Assert.Equal (new Point (28, 0), _textView.CursorPosition);
  1291. Assert.False (_textView.Selecting);
  1292. Assert.Equal ("TAB to jump between texttext fields.", _textView.Text);
  1293. }
  1294. [Fact]
  1295. [InitShutdown]
  1296. public void Cut_Not_Allowed_If_ReadOnly_Is_True ()
  1297. {
  1298. _textView.ReadOnly = true;
  1299. _textView.SelectionStartColumn = 20;
  1300. _textView.SelectionStartRow = 0;
  1301. _textView.CursorPosition = new Point (24, 0);
  1302. _textView.ProcessKey (new KeyEvent (Key.C | Key.CtrlMask, new KeyModifiers ())); // Copy
  1303. Assert.Equal ("text", _textView.SelectedText);
  1304. _textView.ProcessKey (new KeyEvent (Key.W | Key.CtrlMask, new KeyModifiers ())); // Selecting is set to false after Cut.
  1305. Assert.Equal ("", _textView.SelectedText);
  1306. _textView.ReadOnly = false;
  1307. Assert.False (_textView.Selecting);
  1308. _textView.Selecting = true; // Needed to set Selecting to true.
  1309. _textView.ProcessKey (new KeyEvent (Key.C | Key.CtrlMask, new KeyModifiers ())); // Copy
  1310. Assert.Equal ("text", _textView.SelectedText);
  1311. _textView.ProcessKey (new KeyEvent (Key.W | Key.CtrlMask, new KeyModifiers ())); // Cut
  1312. Assert.Equal ("", _textView.SelectedText);
  1313. }
  1314. [Fact]
  1315. [InitShutdown]
  1316. public void Paste_Always_Clear_The_SelectedText ()
  1317. {
  1318. _textView.SelectionStartColumn = 20;
  1319. _textView.SelectionStartRow = 0;
  1320. _textView.CursorPosition = new Point (24, 0);
  1321. _textView.ProcessKey (new KeyEvent (Key.C | Key.CtrlMask, new KeyModifiers ())); // Copy
  1322. Assert.Equal ("text", _textView.SelectedText);
  1323. _textView.ProcessKey (new KeyEvent (Key.Y | Key.CtrlMask, new KeyModifiers ())); // Paste
  1324. Assert.Equal ("", _textView.SelectedText);
  1325. }
  1326. [Fact]
  1327. [InitShutdown]
  1328. public void TextChanged_Event ()
  1329. {
  1330. _textView.TextChanged += () => {
  1331. if (_textView.Text == "changing") {
  1332. Assert.Equal ("changing", _textView.Text);
  1333. _textView.Text = "changed";
  1334. }
  1335. };
  1336. _textView.Text = "changing";
  1337. Assert.Equal ("changed", _textView.Text);
  1338. }
  1339. [Fact]
  1340. [InitShutdown]
  1341. public void Used_Is_True_By_Default ()
  1342. {
  1343. _textView.CursorPosition = new Point (10, 0);
  1344. Assert.Equal ("TAB to jump between text fields.", _textView.Text);
  1345. _textView.ProcessKey (new KeyEvent ((Key)0x75, new KeyModifiers ())); // u
  1346. Assert.Equal ("TAB to jumup between text fields.", _textView.Text);
  1347. _textView.ProcessKey (new KeyEvent ((Key)0x73, new KeyModifiers ())); // s
  1348. Assert.Equal ("TAB to jumusp between text fields.", _textView.Text);
  1349. _textView.ProcessKey (new KeyEvent ((Key)0x65, new KeyModifiers ())); // e
  1350. Assert.Equal ("TAB to jumusep between text fields.", _textView.Text);
  1351. _textView.ProcessKey (new KeyEvent ((Key)0x64, new KeyModifiers ())); // d
  1352. Assert.Equal ("TAB to jumusedp between text fields.", _textView.Text);
  1353. }
  1354. [Fact]
  1355. [InitShutdown]
  1356. public void Used_Is_False ()
  1357. {
  1358. _textView.Used = false;
  1359. _textView.CursorPosition = new Point (10, 0);
  1360. Assert.Equal ("TAB to jump between text fields.", _textView.Text);
  1361. _textView.ProcessKey (new KeyEvent ((Key)0x75, new KeyModifiers ())); // u
  1362. Assert.Equal ("TAB to jumu between text fields.", _textView.Text);
  1363. _textView.ProcessKey (new KeyEvent ((Key)0x73, new KeyModifiers ())); // s
  1364. Assert.Equal ("TAB to jumusbetween text fields.", _textView.Text);
  1365. _textView.ProcessKey (new KeyEvent ((Key)0x65, new KeyModifiers ())); // e
  1366. Assert.Equal ("TAB to jumuseetween text fields.", _textView.Text);
  1367. _textView.ProcessKey (new KeyEvent ((Key)0x64, new KeyModifiers ())); // d
  1368. Assert.Equal ("TAB to jumusedtween text fields.", _textView.Text);
  1369. }
  1370. [Fact]
  1371. [InitShutdown]
  1372. public void Copy_Without_Selection ()
  1373. {
  1374. _textView.Text = "This is the first line.\nThis is the second line.\n";
  1375. _textView.CursorPosition = new Point (0, _textView.Lines - 1);
  1376. _textView.ProcessKey (new KeyEvent (Key.C | Key.CtrlMask, new KeyModifiers ())); // Copy
  1377. _textView.ProcessKey (new KeyEvent (Key.Y | Key.CtrlMask, new KeyModifiers ())); // Paste
  1378. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}{Environment.NewLine}", _textView.Text);
  1379. _textView.CursorPosition = new Point (3, 1);
  1380. _textView.ProcessKey (new KeyEvent (Key.C | Key.CtrlMask, new KeyModifiers ())); // Copy
  1381. _textView.ProcessKey (new KeyEvent (Key.Y | Key.CtrlMask, new KeyModifiers ())); // Paste
  1382. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the second line.{Environment.NewLine}{Environment.NewLine}", _textView.Text);
  1383. Assert.Equal (new Point (3, 2), _textView.CursorPosition);
  1384. _textView.ProcessKey (new KeyEvent (Key.Y | Key.CtrlMask, new KeyModifiers ())); // Paste
  1385. Assert.Equal ($"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}", _textView.Text);
  1386. Assert.Equal (new Point (3, 3), _textView.CursorPosition);
  1387. }
  1388. [Fact]
  1389. [InitShutdown]
  1390. public void TabWidth_Setting_To_Zero_Keeps_AllowsTab ()
  1391. {
  1392. Assert.Equal (4, _textView.TabWidth);
  1393. Assert.True (_textView.AllowsTab);
  1394. Assert.True (_textView.AllowsReturn);
  1395. Assert.True (_textView.Multiline);
  1396. _textView.TabWidth = -1;
  1397. Assert.Equal (0, _textView.TabWidth);
  1398. Assert.True (_textView.AllowsTab);
  1399. Assert.True (_textView.AllowsReturn);
  1400. Assert.True (_textView.Multiline);
  1401. _textView.ProcessKey (new KeyEvent (Key.Tab, new KeyModifiers ()));
  1402. Assert.Equal ("\tTAB to jump between text fields.", _textView.Text);
  1403. _textView.ProcessKey (new KeyEvent (Key.BackTab | Key.ShiftMask, new KeyModifiers ()));
  1404. Assert.Equal ("TAB to jump between text fields.", _textView.Text);
  1405. }
  1406. [Fact]
  1407. [InitShutdown]
  1408. public void AllowsTab_Setting_To_True_Changes_TabWidth_To_Default_If_It_Is_Zero ()
  1409. {
  1410. _textView.TabWidth = 0;
  1411. Assert.Equal (0, _textView.TabWidth);
  1412. Assert.True (_textView.AllowsTab);
  1413. Assert.True (_textView.AllowsReturn);
  1414. Assert.True (_textView.Multiline);
  1415. _textView.AllowsTab = true;
  1416. Assert.True (_textView.AllowsTab);
  1417. Assert.Equal (4, _textView.TabWidth);
  1418. Assert.True (_textView.AllowsReturn);
  1419. Assert.True (_textView.Multiline);
  1420. }
  1421. [Fact]
  1422. [InitShutdown]
  1423. public void AllowsReturn_Setting_To_True_Changes_Multiline_To_True_If_It_Is_False ()
  1424. {
  1425. Assert.True (_textView.AllowsReturn);
  1426. Assert.True (_textView.Multiline);
  1427. Assert.Equal (4, _textView.TabWidth);
  1428. Assert.True (_textView.AllowsTab);
  1429. _textView.ProcessKey (new KeyEvent (Key.Enter, new KeyModifiers ()));
  1430. Assert.Equal (Environment.NewLine +
  1431. "TAB to jump between text fields.", _textView.Text);
  1432. _textView.AllowsReturn = false;
  1433. Assert.False (_textView.AllowsReturn);
  1434. Assert.False (_textView.Multiline);
  1435. Assert.Equal (0, _textView.TabWidth);
  1436. Assert.False (_textView.AllowsTab);
  1437. _textView.ProcessKey (new KeyEvent (Key.Enter, new KeyModifiers ()));
  1438. Assert.Equal (Environment.NewLine +
  1439. "TAB to jump between text fields.", _textView.Text);
  1440. }
  1441. [Fact]
  1442. [InitShutdown]
  1443. public void Multiline_Setting_Changes_AllowsReturn_AllowsTab_Height_WordWrap ()
  1444. {
  1445. Assert.True (_textView.Multiline);
  1446. Assert.True (_textView.AllowsReturn);
  1447. Assert.Equal (4, _textView.TabWidth);
  1448. Assert.True (_textView.AllowsTab);
  1449. Assert.Equal ("Dim.Absolute(30)", _textView.Width.ToString ());
  1450. Assert.Equal ("Dim.Absolute(10)", _textView.Height.ToString ());
  1451. Assert.False (_textView.WordWrap);
  1452. _textView.WordWrap = true;
  1453. Assert.True (_textView.WordWrap);
  1454. _textView.Multiline = false;
  1455. Assert.False (_textView.Multiline);
  1456. Assert.False (_textView.AllowsReturn);
  1457. Assert.Equal (0, _textView.TabWidth);
  1458. Assert.False (_textView.AllowsTab);
  1459. Assert.Equal ("Dim.Absolute(30)", _textView.Width.ToString ());
  1460. Assert.Equal ("Dim.Absolute(1)", _textView.Height.ToString ());
  1461. Assert.False (_textView.WordWrap);
  1462. _textView.WordWrap = true;
  1463. Assert.False (_textView.WordWrap);
  1464. _textView.Multiline = true;
  1465. Assert.True (_textView.Multiline);
  1466. Assert.True (_textView.AllowsReturn);
  1467. Assert.Equal (4, _textView.TabWidth);
  1468. Assert.True (_textView.AllowsTab);
  1469. Assert.Equal ("Dim.Absolute(30)", _textView.Width.ToString ());
  1470. Assert.Equal ("Dim.Absolute(10)", _textView.Height.ToString ());
  1471. Assert.False (_textView.WordWrap);
  1472. }
  1473. [Fact]
  1474. [InitShutdown]
  1475. public void Tab_Test_Follow_By_BackTab ()
  1476. {
  1477. Application.Top.Add (_textView);
  1478. Application.Iteration += () => {
  1479. var width = _textView.Bounds.Width - 1;
  1480. Assert.Equal (30, width + 1);
  1481. Assert.Equal (10, _textView.Height);
  1482. _textView.Text = "";
  1483. var col = 0;
  1484. var leftCol = 0;
  1485. var tabWidth = _textView.TabWidth;
  1486. while (col < 100) {
  1487. col++;
  1488. _textView.ProcessKey (new KeyEvent (Key.Tab, new KeyModifiers ()));
  1489. Assert.Equal (new Point (col, 0), _textView.CursorPosition);
  1490. leftCol = GetLeftCol (leftCol);
  1491. Assert.Equal (leftCol, _textView.LeftColumn);
  1492. }
  1493. while (col > 0) {
  1494. col--;
  1495. _textView.ProcessKey (new KeyEvent (Key.BackTab | Key.ShiftMask, new KeyModifiers ()));
  1496. Assert.Equal (new Point (col, 0), _textView.CursorPosition);
  1497. leftCol = GetLeftCol (leftCol);
  1498. Assert.Equal (leftCol, _textView.LeftColumn);
  1499. }
  1500. Application.Top.Remove (_textView);
  1501. Application.RequestStop ();
  1502. };
  1503. Application.Run ();
  1504. }
  1505. [Fact]
  1506. [InitShutdown]
  1507. public void BackTab_Test_Follow_By_Tab ()
  1508. {
  1509. Application.Top.Add (_textView);
  1510. Application.Iteration += () => {
  1511. var width = _textView.Bounds.Width - 1;
  1512. Assert.Equal (30, width + 1);
  1513. Assert.Equal (10, _textView.Height);
  1514. _textView.Text = "";
  1515. for (int i = 0; i < 100; i++) {
  1516. _textView.Text += "\t";
  1517. }
  1518. var col = 100;
  1519. var tabWidth = _textView.TabWidth;
  1520. var leftCol = _textView.LeftColumn;
  1521. _textView.MoveEnd ();
  1522. Assert.Equal (new Point (col, 0), _textView.CursorPosition);
  1523. leftCol = GetLeftCol (leftCol);
  1524. Assert.Equal (leftCol, _textView.LeftColumn);
  1525. while (col > 0) {
  1526. col--;
  1527. _textView.ProcessKey (new KeyEvent (Key.BackTab | Key.ShiftMask, new KeyModifiers ()));
  1528. Assert.Equal (new Point (col, 0), _textView.CursorPosition);
  1529. leftCol = GetLeftCol (leftCol);
  1530. Assert.Equal (leftCol, _textView.LeftColumn);
  1531. }
  1532. while (col < 100) {
  1533. col++;
  1534. _textView.ProcessKey (new KeyEvent (Key.Tab, new KeyModifiers ()));
  1535. Assert.Equal (new Point (col, 0), _textView.CursorPosition);
  1536. leftCol = GetLeftCol (leftCol);
  1537. Assert.Equal (leftCol, _textView.LeftColumn);
  1538. }
  1539. Application.Top.Remove (_textView);
  1540. Application.RequestStop ();
  1541. };
  1542. Application.Run ();
  1543. }
  1544. [Fact]
  1545. [InitShutdown]
  1546. public void Tab_Test_Follow_By_CursorLeft_And_Then_Follow_By_CursorRight ()
  1547. {
  1548. Application.Top.Add (_textView);
  1549. Application.Iteration += () => {
  1550. var width = _textView.Bounds.Width - 1;
  1551. Assert.Equal (30, width + 1);
  1552. Assert.Equal (10, _textView.Height);
  1553. _textView.Text = "";
  1554. var col = 0;
  1555. var leftCol = 0;
  1556. var tabWidth = _textView.TabWidth;
  1557. while (col < 100) {
  1558. col++;
  1559. _textView.ProcessKey (new KeyEvent (Key.Tab, new KeyModifiers ()));
  1560. Assert.Equal (new Point (col, 0), _textView.CursorPosition);
  1561. leftCol = GetLeftCol (leftCol);
  1562. Assert.Equal (leftCol, _textView.LeftColumn);
  1563. }
  1564. while (col > 0) {
  1565. col--;
  1566. _textView.ProcessKey (new KeyEvent (Key.CursorLeft, new KeyModifiers ()));
  1567. Assert.Equal (new Point (col, 0), _textView.CursorPosition);
  1568. leftCol = GetLeftCol (leftCol);
  1569. Assert.Equal (leftCol, _textView.LeftColumn);
  1570. }
  1571. while (col < 100) {
  1572. col++;
  1573. _textView.ProcessKey (new KeyEvent (Key.CursorRight, new KeyModifiers ()));
  1574. Assert.Equal (new Point (col, 0), _textView.CursorPosition);
  1575. leftCol = GetLeftCol (leftCol);
  1576. Assert.Equal (leftCol, _textView.LeftColumn);
  1577. }
  1578. Application.Top.Remove (_textView);
  1579. Application.RequestStop ();
  1580. };
  1581. Application.Run ();
  1582. }
  1583. [Fact]
  1584. [InitShutdown]
  1585. public void Tab_Test_Follow_By_BackTab_With_Text ()
  1586. {
  1587. Application.Top.Add (_textView);
  1588. Application.Iteration += () => {
  1589. var width = _textView.Bounds.Width - 1;
  1590. Assert.Equal (30, width + 1);
  1591. Assert.Equal (10, _textView.Height);
  1592. var col = 0;
  1593. var leftCol = 0;
  1594. Assert.Equal (new Point (col, 0), _textView.CursorPosition);
  1595. Assert.Equal (leftCol, _textView.LeftColumn);
  1596. while (col < 100) {
  1597. col++;
  1598. _textView.ProcessKey (new KeyEvent (Key.Tab, new KeyModifiers ()));
  1599. Assert.Equal (new Point (col, 0), _textView.CursorPosition);
  1600. leftCol = GetLeftCol (leftCol);
  1601. Assert.Equal (leftCol, _textView.LeftColumn);
  1602. }
  1603. while (col > 0) {
  1604. col--;
  1605. _textView.ProcessKey (new KeyEvent (Key.BackTab | Key.ShiftMask, new KeyModifiers ()));
  1606. Assert.Equal (new Point (col, 0), _textView.CursorPosition);
  1607. leftCol = GetLeftCol (leftCol);
  1608. Assert.Equal (leftCol, _textView.LeftColumn);
  1609. }
  1610. Application.Top.Remove (_textView);
  1611. Application.RequestStop ();
  1612. };
  1613. Application.Run ();
  1614. }
  1615. [Fact]
  1616. [InitShutdown]
  1617. public void Tab_Test_Follow_By_Home_And_Then_Follow_By_End_And_Then_Follow_By_BackTab_With_Text ()
  1618. {
  1619. Application.Top.Add (_textView);
  1620. Application.Iteration += () => {
  1621. var width = _textView.Bounds.Width - 1;
  1622. Assert.Equal (30, width + 1);
  1623. Assert.Equal (10, _textView.Height);
  1624. var col = 0;
  1625. var leftCol = 0;
  1626. Assert.Equal (new Point (col, 0), _textView.CursorPosition);
  1627. Assert.Equal (leftCol, _textView.LeftColumn);
  1628. Assert.Equal ("TAB to jump between text fields.", _textView.Text);
  1629. Assert.Equal (32, _textView.Text.Length);
  1630. while (col < 100) {
  1631. col++;
  1632. _textView.ProcessKey (new KeyEvent (Key.Tab, new KeyModifiers ()));
  1633. Assert.Equal (new Point (col, 0), _textView.CursorPosition);
  1634. leftCol = GetLeftCol (leftCol);
  1635. Assert.Equal (leftCol, _textView.LeftColumn);
  1636. }
  1637. _textView.ProcessKey (new KeyEvent (Key.Home, new KeyModifiers ()));
  1638. col = 0;
  1639. Assert.Equal (new Point (col, 0), _textView.CursorPosition);
  1640. leftCol = 0;
  1641. Assert.Equal (leftCol, _textView.LeftColumn);
  1642. _textView.ProcessKey (new KeyEvent (Key.End, new KeyModifiers ()));
  1643. col = _textView.Text.Length;
  1644. Assert.Equal (132, _textView.Text.Length);
  1645. Assert.Equal (new Point (col, 0), _textView.CursorPosition);
  1646. leftCol = GetLeftCol (leftCol);
  1647. Assert.Equal (leftCol, _textView.LeftColumn);
  1648. var txt = _textView.Text;
  1649. while (col - 1 > 0 && txt [col - 1] != '\t') {
  1650. col--;
  1651. }
  1652. _textView.CursorPosition = new Point (col, 0);
  1653. leftCol = GetLeftCol (leftCol);
  1654. while (col > 0) {
  1655. col--;
  1656. _textView.ProcessKey (new KeyEvent (Key.BackTab | Key.ShiftMask, new KeyModifiers ()));
  1657. Assert.Equal (new Point (col, 0), _textView.CursorPosition);
  1658. leftCol = GetLeftCol (leftCol);
  1659. Assert.Equal (leftCol, _textView.LeftColumn);
  1660. }
  1661. Assert.Equal ("TAB to jump between text fields.", _textView.Text);
  1662. Assert.Equal (32, _textView.Text.Length);
  1663. Application.Top.Remove (_textView);
  1664. Application.RequestStop ();
  1665. };
  1666. Application.Run ();
  1667. }
  1668. [Fact]
  1669. [InitShutdown]
  1670. public void Tab_Test_Follow_By_CursorLeft_And_Then_Follow_By_CursorRight_With_Text ()
  1671. {
  1672. Application.Top.Add (_textView);
  1673. Application.Iteration += () => {
  1674. var width = _textView.Bounds.Width - 1;
  1675. Assert.Equal (30, width + 1);
  1676. Assert.Equal (10, _textView.Height);
  1677. Assert.Equal ("TAB to jump between text fields.", _textView.Text);
  1678. var col = 0;
  1679. var leftCol = 0;
  1680. var tabWidth = _textView.TabWidth;
  1681. while (col < 100) {
  1682. col++;
  1683. _textView.ProcessKey (new KeyEvent (Key.Tab, new KeyModifiers ()));
  1684. Assert.Equal (new Point (col, 0), _textView.CursorPosition);
  1685. leftCol = GetLeftCol (leftCol);
  1686. Assert.Equal (leftCol, _textView.LeftColumn);
  1687. }
  1688. Assert.Equal (132, _textView.Text.Length);
  1689. while (col > 0) {
  1690. col--;
  1691. _textView.ProcessKey (new KeyEvent (Key.CursorLeft, new KeyModifiers ()));
  1692. Assert.Equal (new Point (col, 0), _textView.CursorPosition);
  1693. leftCol = GetLeftCol (leftCol);
  1694. Assert.Equal (leftCol, _textView.LeftColumn);
  1695. }
  1696. while (col < 100) {
  1697. col++;
  1698. _textView.ProcessKey (new KeyEvent (Key.CursorRight, new KeyModifiers ()));
  1699. Assert.Equal (new Point (col, 0), _textView.CursorPosition);
  1700. leftCol = GetLeftCol (leftCol);
  1701. Assert.Equal (leftCol, _textView.LeftColumn);
  1702. }
  1703. Application.Top.Remove (_textView);
  1704. Application.RequestStop ();
  1705. };
  1706. Application.Run ();
  1707. }
  1708. [Fact]
  1709. public void TextView_MultiLine_But_Without_Tabs ()
  1710. {
  1711. var view = new TextView ();
  1712. // the default for TextView
  1713. Assert.True (view.Multiline);
  1714. view.AllowsTab = false;
  1715. Assert.False (view.AllowsTab);
  1716. Assert.True (view.Multiline);
  1717. }
  1718. private int GetLeftCol (int start)
  1719. {
  1720. var lines = _textView.Text.Split (Environment.NewLine);
  1721. if (lines == null || lines.Length == 0) {
  1722. return 0;
  1723. }
  1724. if (start == _textView.LeftColumn) {
  1725. return start;
  1726. }
  1727. if (_textView.LeftColumn == _textView.CurrentColumn) {
  1728. return _textView.CurrentColumn;
  1729. }
  1730. var cCol = _textView.CurrentColumn;
  1731. var line = lines [_textView.CurrentRow];
  1732. var lCount = cCol > line.Length - 1 ? line.Length - 1 : cCol;
  1733. var width = _textView.Frame.Width;
  1734. var tabWidth = _textView.TabWidth;
  1735. var sumLength = 0;
  1736. var col = 0;
  1737. for (int i = lCount; i >= 0; i--) {
  1738. var r = line [i];
  1739. sumLength += Rune.ColumnWidth (r);
  1740. if (r == '\t') {
  1741. sumLength += tabWidth + 1;
  1742. }
  1743. if (sumLength > width) {
  1744. if (col + width == cCol) {
  1745. col++;
  1746. }
  1747. break;
  1748. } else if ((cCol < line.Length && col > 0 && start < cCol && col == start) || (cCol - col == width - 1)) {
  1749. break;
  1750. }
  1751. col = i;
  1752. }
  1753. return col;
  1754. }
  1755. [Fact]
  1756. public void LoadFile_Throws_If_File_Is_Null ()
  1757. {
  1758. var result = false;
  1759. var tv = new TextView ();
  1760. Assert.Throws<ArgumentNullException> (() => result = tv.LoadFile (null));
  1761. Assert.False (result);
  1762. }
  1763. [Fact]
  1764. public void LoadFile_Throws_If_File_Is_Empty ()
  1765. {
  1766. var result = false;
  1767. var tv = new TextView ();
  1768. Assert.Throws<ArgumentException> (() => result = tv.LoadFile (""));
  1769. Assert.False (result);
  1770. }
  1771. [Fact]
  1772. public void LoadFile_Throws_If_File_Not_Exist ()
  1773. {
  1774. var result = false;
  1775. var tv = new TextView ();
  1776. Assert.Throws<System.IO.FileNotFoundException> (() => result = tv.LoadFile ("blabla"));
  1777. Assert.False (result);
  1778. }
  1779. [Fact]
  1780. public void LoadStream_Throws_If_Stream_Is_Null ()
  1781. {
  1782. var tv = new TextView ();
  1783. Assert.Throws<ArgumentNullException> (() => tv.LoadStream (null));
  1784. }
  1785. [Fact]
  1786. public void LoadStream_Stream_Is_Empty ()
  1787. {
  1788. var tv = new TextView ();
  1789. tv.LoadStream (new System.IO.MemoryStream ());
  1790. Assert.Equal ("", tv.Text);
  1791. }
  1792. [Fact]
  1793. public void LoadStream_CRLF ()
  1794. {
  1795. var text = "This is the first line.\r\nThis is the second line.\r\n";
  1796. var tv = new TextView ();
  1797. tv.LoadStream (new System.IO.MemoryStream (System.Text.Encoding.ASCII.GetBytes (text)));
  1798. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}", tv.Text);
  1799. }
  1800. [Fact]
  1801. public void LoadStream_LF ()
  1802. {
  1803. var text = "This is the first line.\nThis is the second line.\n";
  1804. var tv = new TextView ();
  1805. tv.LoadStream (new System.IO.MemoryStream (System.Text.Encoding.ASCII.GetBytes (text)));
  1806. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}", tv.Text);
  1807. }
  1808. [Fact]
  1809. public void StringToRunes_Slipts_CRLF ()
  1810. {
  1811. var text = "This is the first line.\r\nThis is the second line.\r\n";
  1812. var tv = new TextView ();
  1813. tv.Text = text;
  1814. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}", tv.Text);
  1815. }
  1816. [Fact]
  1817. public void StringToRunes_Slipts_LF ()
  1818. {
  1819. var text = "This is the first line.\nThis is the second line.\n";
  1820. var tv = new TextView ();
  1821. tv.Text = text;
  1822. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}", tv.Text);
  1823. }
  1824. [Fact]
  1825. public void CloseFile_Throws_If_FilePath_Is_Null ()
  1826. {
  1827. var tv = new TextView ();
  1828. Assert.Throws<ArgumentNullException> (() => tv.CloseFile ());
  1829. }
  1830. [Fact]
  1831. public void WordWrap_Gets_Sets ()
  1832. {
  1833. var tv = new TextView () { WordWrap = true };
  1834. Assert.True (tv.WordWrap);
  1835. tv.WordWrap = false;
  1836. Assert.False (tv.WordWrap);
  1837. }
  1838. [Fact]
  1839. public void WordWrap_True_Text_Always_Returns_Unwrapped ()
  1840. {
  1841. var text = "This is the first line.\nThis is the second line.\n";
  1842. var tv = new TextView () { Width = 10 };
  1843. tv.Text = text;
  1844. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}", tv.Text);
  1845. tv.WordWrap = true;
  1846. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}", tv.Text);
  1847. }
  1848. [Fact]
  1849. [InitShutdown]
  1850. public void WordWrap_WrapModel_Output ()
  1851. {
  1852. // 0123456789
  1853. var text = "This is the first line.\nThis is the second line.\n";
  1854. var tv = new TextView () { Width = 10, Height = 10 };
  1855. tv.Text = text;
  1856. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}", tv.Text);
  1857. tv.WordWrap = true;
  1858. Application.Top.Add (tv);
  1859. tv.Redraw (tv.Bounds);
  1860. GraphViewTests.AssertDriverContentsWithFrameAre (@"
  1861. This is
  1862. the
  1863. first
  1864. line.
  1865. This is
  1866. the
  1867. second
  1868. line.
  1869. ", output);
  1870. }
  1871. [Fact]
  1872. [AutoInitShutdown]
  1873. public void WordWrap_Deleting_Backwards ()
  1874. {
  1875. var tv = new TextView () {
  1876. Width = 5,
  1877. Height = 2,
  1878. WordWrap = true,
  1879. Text = "aaaa"
  1880. };
  1881. Application.Top.Add (tv);
  1882. Application.Begin (Application.Top);
  1883. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  1884. Assert.Equal (0, tv.LeftColumn);
  1885. GraphViewTests.AssertDriverContentsAre (@"
  1886. aaaa
  1887. ", output);
  1888. tv.CursorPosition = new Point (5, 0);
  1889. Assert.True (tv.ProcessKey (new KeyEvent (Key.Backspace, new KeyModifiers ())));
  1890. Application.Refresh ();
  1891. Assert.Equal (0, tv.LeftColumn);
  1892. GraphViewTests.AssertDriverContentsAre (@"
  1893. aaa
  1894. ", output);
  1895. Assert.True (tv.ProcessKey (new KeyEvent (Key.Backspace, new KeyModifiers ())));
  1896. Application.Refresh ();
  1897. Assert.Equal (0, tv.LeftColumn);
  1898. GraphViewTests.AssertDriverContentsAre (@"
  1899. aa
  1900. ", output);
  1901. Assert.True (tv.ProcessKey (new KeyEvent (Key.Backspace, new KeyModifiers ())));
  1902. Application.Refresh ();
  1903. Assert.Equal (0, tv.LeftColumn);
  1904. GraphViewTests.AssertDriverContentsAre (@"
  1905. a
  1906. ", output);
  1907. Assert.True (tv.ProcessKey (new KeyEvent (Key.Backspace, new KeyModifiers ())));
  1908. Application.Refresh ();
  1909. Assert.Equal (0, tv.LeftColumn);
  1910. GraphViewTests.AssertDriverContentsAre (@"
  1911. ", output);
  1912. Assert.True (tv.ProcessKey (new KeyEvent (Key.Backspace, new KeyModifiers ())));
  1913. Application.Refresh ();
  1914. Assert.Equal (0, tv.LeftColumn);
  1915. GraphViewTests.AssertDriverContentsAre (@"
  1916. ", output);
  1917. }
  1918. [Fact]
  1919. [InitShutdown]
  1920. public void WordWrap_ReadOnly_CursorPosition_SelectedText_Copy ()
  1921. {
  1922. // 0123456789
  1923. var text = "This is the first line.\nThis is the second line.\n";
  1924. var tv = new TextView () { Width = 11, Height = 9 };
  1925. tv.Text = text;
  1926. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}", tv.Text);
  1927. tv.WordWrap = true;
  1928. Application.Top.Add (tv);
  1929. tv.Redraw (tv.Bounds);
  1930. GraphViewTests.AssertDriverContentsWithFrameAre (@"
  1931. This is
  1932. the first
  1933. line.
  1934. This is
  1935. the
  1936. second
  1937. line.
  1938. ", output);
  1939. tv.ReadOnly = true;
  1940. tv.CursorPosition = new Point (6, 2);
  1941. Assert.Equal (new Point (5, 2), tv.CursorPosition);
  1942. tv.Redraw (tv.Bounds);
  1943. GraphViewTests.AssertDriverContentsWithFrameAre (@"
  1944. This is
  1945. the first
  1946. line.
  1947. This is
  1948. the
  1949. second
  1950. line.
  1951. ", output);
  1952. tv.SelectionStartRow = 0;
  1953. tv.SelectionStartColumn = 0;
  1954. Assert.Equal ("This is the first line.", tv.SelectedText);
  1955. tv.Copy ();
  1956. Assert.Equal ("This is the first line.", Clipboard.Contents);
  1957. }
  1958. [Fact]
  1959. public void Internal_Tests ()
  1960. {
  1961. var txt = "This is a text.";
  1962. var txtRunes = TextModel.ToRunes (txt);
  1963. Assert.Equal (txt.Length, txtRunes.Count);
  1964. Assert.Equal ('T', txtRunes [0]);
  1965. Assert.Equal ('h', txtRunes [1]);
  1966. Assert.Equal ('i', txtRunes [2]);
  1967. Assert.Equal ('s', txtRunes [3]);
  1968. Assert.Equal (' ', txtRunes [4]);
  1969. Assert.Equal ('i', txtRunes [5]);
  1970. Assert.Equal ('s', txtRunes [6]);
  1971. Assert.Equal (' ', txtRunes [7]);
  1972. Assert.Equal ('a', txtRunes [8]);
  1973. Assert.Equal (' ', txtRunes [9]);
  1974. Assert.Equal ('t', txtRunes [10]);
  1975. Assert.Equal ('e', txtRunes [11]);
  1976. Assert.Equal ('x', txtRunes [12]);
  1977. Assert.Equal ('t', txtRunes [13]);
  1978. Assert.Equal ('.', txtRunes [^1]);
  1979. int col = 0;
  1980. Assert.True (TextModel.SetCol (ref col, 80, 79));
  1981. Assert.False (TextModel.SetCol (ref col, 80, 80));
  1982. Assert.Equal (79, col);
  1983. var start = 0;
  1984. var x = 8;
  1985. Assert.Equal (8, TextModel.GetColFromX (txtRunes, start, x));
  1986. Assert.Equal ('a', txtRunes [start + x]);
  1987. start = 1;
  1988. x = 7;
  1989. Assert.Equal (7, TextModel.GetColFromX (txtRunes, start, x));
  1990. Assert.Equal ('a', txtRunes [start + x]);
  1991. Assert.Equal ((15, 15), TextModel.DisplaySize (txtRunes));
  1992. Assert.Equal ((6, 6), TextModel.DisplaySize (txtRunes, 1, 7));
  1993. Assert.Equal (0, TextModel.CalculateLeftColumn (txtRunes, 0, 7, 8));
  1994. Assert.Equal (1, TextModel.CalculateLeftColumn (txtRunes, 0, 8, 8));
  1995. Assert.Equal (2, TextModel.CalculateLeftColumn (txtRunes, 0, 9, 8));
  1996. var tm = new TextModel ();
  1997. tm.AddLine (0, TextModel.ToRunes ("This is first line."));
  1998. tm.AddLine (1, TextModel.ToRunes ("This is last line."));
  1999. Assert.Equal ((new Point (2, 0), true), tm.FindNextText ("is", out bool gaveFullTurn));
  2000. Assert.False (gaveFullTurn);
  2001. Assert.Equal ((new Point (5, 0), true), tm.FindNextText ("is", out gaveFullTurn));
  2002. Assert.False (gaveFullTurn);
  2003. Assert.Equal ((new Point (2, 1), true), tm.FindNextText ("is", out gaveFullTurn));
  2004. Assert.False (gaveFullTurn);
  2005. Assert.Equal ((new Point (5, 1), true), tm.FindNextText ("is", out gaveFullTurn));
  2006. Assert.False (gaveFullTurn);
  2007. Assert.Equal ((new Point (2, 0), true), tm.FindNextText ("is", out gaveFullTurn));
  2008. Assert.True (gaveFullTurn);
  2009. tm.ResetContinuousFind (new Point (0, 0));
  2010. Assert.Equal ((new Point (5, 1), true), tm.FindPreviousText ("is", out gaveFullTurn));
  2011. Assert.False (gaveFullTurn);
  2012. Assert.Equal ((new Point (2, 1), true), tm.FindPreviousText ("is", out gaveFullTurn));
  2013. Assert.False (gaveFullTurn);
  2014. Assert.Equal ((new Point (5, 0), true), tm.FindPreviousText ("is", out gaveFullTurn));
  2015. Assert.False (gaveFullTurn);
  2016. Assert.Equal ((new Point (2, 0), true), tm.FindPreviousText ("is", out gaveFullTurn));
  2017. Assert.False (gaveFullTurn);
  2018. Assert.Equal ((new Point (5, 1), true), tm.FindPreviousText ("is", out gaveFullTurn));
  2019. Assert.True (gaveFullTurn);
  2020. Assert.Equal ((new Point (9, 1), true), tm.ReplaceAllText ("is", false, false, "really"));
  2021. Assert.Equal (TextModel.ToRunes ("Threally really first line."), tm.GetLine (0));
  2022. Assert.Equal (TextModel.ToRunes ("Threally really last line."), tm.GetLine (1));
  2023. tm = new TextModel ();
  2024. tm.AddLine (0, TextModel.ToRunes ("This is first line."));
  2025. tm.AddLine (1, TextModel.ToRunes ("This is last line."));
  2026. Assert.Equal ((new Point (5, 1), true), tm.ReplaceAllText ("is", false, true, "really"));
  2027. Assert.Equal (TextModel.ToRunes ("This really first line."), tm.GetLine (0));
  2028. Assert.Equal (TextModel.ToRunes ("This really last line."), tm.GetLine (1));
  2029. }
  2030. [Fact]
  2031. [InitShutdown]
  2032. public void BottomOffset_Sets_To_Zero_Adjust_TopRow ()
  2033. {
  2034. string text = "";
  2035. for (int i = 0; i < 12; i++) {
  2036. text += $"This is the line {i}\n";
  2037. }
  2038. var tv = new TextView () { Width = 10, Height = 10, BottomOffset = 1 };
  2039. tv.Text = text;
  2040. tv.ProcessKey (new KeyEvent (Key.CtrlMask | Key.End, new KeyModifiers ()));
  2041. Assert.Equal (4, tv.TopRow);
  2042. Assert.Equal (1, tv.BottomOffset);
  2043. tv.BottomOffset = 0;
  2044. Assert.Equal (3, tv.TopRow);
  2045. Assert.Equal (0, tv.BottomOffset);
  2046. tv.BottomOffset = 2;
  2047. Assert.Equal (5, tv.TopRow);
  2048. Assert.Equal (2, tv.BottomOffset);
  2049. tv.BottomOffset = 0;
  2050. Assert.Equal (3, tv.TopRow);
  2051. Assert.Equal (0, tv.BottomOffset);
  2052. }
  2053. [Fact]
  2054. [InitShutdown]
  2055. public void RightOffset_Sets_To_Zero_Adjust_leftColumn ()
  2056. {
  2057. string text = "";
  2058. for (int i = 0; i < 12; i++) {
  2059. text += $"{i.ToString () [^1]}";
  2060. }
  2061. var tv = new TextView () { Width = 10, Height = 10, RightOffset = 1 };
  2062. tv.Text = text;
  2063. tv.ProcessKey (new KeyEvent (Key.End, new KeyModifiers ()));
  2064. Assert.Equal (4, tv.LeftColumn);
  2065. Assert.Equal (1, tv.RightOffset);
  2066. tv.RightOffset = 0;
  2067. Assert.Equal (3, tv.LeftColumn);
  2068. Assert.Equal (0, tv.RightOffset);
  2069. tv.RightOffset = 2;
  2070. Assert.Equal (5, tv.LeftColumn);
  2071. Assert.Equal (2, tv.RightOffset);
  2072. tv.RightOffset = 0;
  2073. Assert.Equal (3, tv.LeftColumn);
  2074. Assert.Equal (0, tv.RightOffset);
  2075. }
  2076. [Fact]
  2077. [InitShutdown]
  2078. public void TextView_SpaceHandling ()
  2079. {
  2080. var tv = new TextView () {
  2081. Width = 10,
  2082. Text = " "
  2083. };
  2084. MouseEvent ev = new MouseEvent () {
  2085. X = 0,
  2086. Y = 0,
  2087. Flags = MouseFlags.Button1DoubleClicked,
  2088. };
  2089. tv.MouseEvent (ev);
  2090. Assert.Equal (1, tv.SelectedLength);
  2091. ev = new MouseEvent () {
  2092. X = 1,
  2093. Y = 0,
  2094. Flags = MouseFlags.Button1DoubleClicked,
  2095. };
  2096. tv.MouseEvent (ev);
  2097. Assert.Equal (1, tv.SelectedLength);
  2098. }
  2099. [Fact]
  2100. [InitShutdown]
  2101. public void CanFocus_False_Wont_Focus_With_Mouse ()
  2102. {
  2103. var top = Application.Top;
  2104. var tv = new TextView () {
  2105. Width = Dim.Fill (),
  2106. CanFocus = false,
  2107. ReadOnly = true,
  2108. Text = "some text"
  2109. };
  2110. var fv = new FrameView ("I shouldn't get focus") {
  2111. Width = Dim.Fill (),
  2112. Height = Dim.Fill (),
  2113. CanFocus = false,
  2114. };
  2115. fv.Add (tv);
  2116. top.Add (fv);
  2117. Application.Begin (top);
  2118. Assert.False (tv.CanFocus);
  2119. Assert.False (tv.HasFocus);
  2120. Assert.False (fv.CanFocus);
  2121. Assert.False (fv.HasFocus);
  2122. tv.MouseEvent (new MouseEvent () {
  2123. X = 1,
  2124. Y = 0,
  2125. Flags = MouseFlags.Button1DoubleClicked
  2126. });
  2127. Assert.Empty (tv.SelectedText);
  2128. Assert.False (tv.CanFocus);
  2129. Assert.False (tv.HasFocus);
  2130. Assert.False (fv.CanFocus);
  2131. Assert.False (fv.HasFocus);
  2132. Assert.Throws<InvalidOperationException> (() => tv.CanFocus = true);
  2133. fv.CanFocus = true;
  2134. tv.CanFocus = true;
  2135. tv.MouseEvent (new MouseEvent () {
  2136. X = 1,
  2137. Y = 0,
  2138. Flags = MouseFlags.Button1DoubleClicked
  2139. });
  2140. Assert.Equal ("some ", tv.SelectedText);
  2141. Assert.True (tv.CanFocus);
  2142. Assert.True (tv.HasFocus);
  2143. Assert.True (fv.CanFocus);
  2144. Assert.True (fv.HasFocus);
  2145. fv.CanFocus = false;
  2146. tv.MouseEvent (new MouseEvent () {
  2147. X = 1,
  2148. Y = 0,
  2149. Flags = MouseFlags.Button1DoubleClicked
  2150. });
  2151. Assert.Equal ("some ", tv.SelectedText); // Setting CanFocus to false don't change the SelectedText
  2152. Assert.False (tv.CanFocus);
  2153. Assert.False (tv.HasFocus);
  2154. Assert.False (fv.CanFocus);
  2155. Assert.False (fv.HasFocus);
  2156. }
  2157. [Fact]
  2158. [InitShutdown]
  2159. public void DesiredCursorVisibility_Vertical_Navigation ()
  2160. {
  2161. string text = "";
  2162. for (int i = 0; i < 12; i++) {
  2163. text += $"This is the line {i}\n";
  2164. }
  2165. var tv = new TextView () { Width = 10, Height = 10 };
  2166. tv.Text = text;
  2167. Assert.Equal (0, tv.TopRow);
  2168. tv.PositionCursor ();
  2169. Assert.Equal (CursorVisibility.Default, tv.DesiredCursorVisibility);
  2170. for (int i = 0; i < 12; i++) {
  2171. tv.MouseEvent (new MouseEvent () {
  2172. Flags = MouseFlags.WheeledDown
  2173. });
  2174. tv.PositionCursor ();
  2175. Assert.Equal (i + 1, tv.TopRow);
  2176. Assert.Equal (CursorVisibility.Invisible, tv.DesiredCursorVisibility);
  2177. }
  2178. for (int i = 12; i > 0; i--) {
  2179. tv.MouseEvent (new MouseEvent () {
  2180. Flags = MouseFlags.WheeledUp
  2181. });
  2182. tv.PositionCursor ();
  2183. Assert.Equal (i - 1, tv.TopRow);
  2184. if (i - 1 == 0) {
  2185. Assert.Equal (CursorVisibility.Default, tv.DesiredCursorVisibility);
  2186. } else {
  2187. Assert.Equal (CursorVisibility.Invisible, tv.DesiredCursorVisibility);
  2188. }
  2189. }
  2190. }
  2191. [Fact]
  2192. [InitShutdown]
  2193. public void DesiredCursorVisibility_Horizontal_Navigation ()
  2194. {
  2195. string text = "";
  2196. for (int i = 0; i < 12; i++) {
  2197. text += $"{i.ToString () [^1]}";
  2198. }
  2199. var tv = new TextView () { Width = 10, Height = 10 };
  2200. tv.Text = text;
  2201. Assert.Equal (0, tv.LeftColumn);
  2202. tv.PositionCursor ();
  2203. Assert.Equal (CursorVisibility.Default, tv.DesiredCursorVisibility);
  2204. for (int i = 0; i < 12; i++) {
  2205. tv.MouseEvent (new MouseEvent () {
  2206. Flags = MouseFlags.WheeledRight
  2207. });
  2208. tv.PositionCursor ();
  2209. Assert.Equal (Math.Min (i + 1, 11), tv.LeftColumn);
  2210. Assert.Equal (CursorVisibility.Invisible, tv.DesiredCursorVisibility);
  2211. }
  2212. for (int i = 11; i > 0; i--) {
  2213. tv.MouseEvent (new MouseEvent () {
  2214. Flags = MouseFlags.WheeledLeft
  2215. });
  2216. tv.PositionCursor ();
  2217. Assert.Equal (i - 1, tv.LeftColumn);
  2218. if (i - 1 == 0) {
  2219. Assert.Equal (CursorVisibility.Default, tv.DesiredCursorVisibility);
  2220. } else {
  2221. Assert.Equal (CursorVisibility.Invisible, tv.DesiredCursorVisibility);
  2222. }
  2223. }
  2224. }
  2225. [Fact]
  2226. public void LeftColumn_Add_One_If_Text_Length_Is_Equal_To_Width ()
  2227. {
  2228. var tv = new TextView () {
  2229. Width = 10,
  2230. Text = "1234567890"
  2231. };
  2232. Assert.Equal (Point.Empty, tv.CursorPosition);
  2233. Assert.Equal (0, tv.LeftColumn);
  2234. tv.CursorPosition = new Point (9, 0);
  2235. Assert.Equal (new Point (9, 0), tv.CursorPosition);
  2236. Assert.Equal (0, tv.LeftColumn);
  2237. Assert.True (tv.ProcessKey (new KeyEvent (Key.CursorRight, new KeyModifiers ())));
  2238. tv.CursorPosition = new Point (10, 0);
  2239. Assert.Equal (new Point (10, 0), tv.CursorPosition);
  2240. Assert.Equal (1, tv.LeftColumn);
  2241. }
  2242. [Fact]
  2243. [AutoInitShutdown]
  2244. public void KeyBindings_Command ()
  2245. {
  2246. var text = "This is the first line.\nThis is the second line.\nThis is the third line.";
  2247. var tv = new TextView () {
  2248. Width = 10,
  2249. Height = 2,
  2250. Text = text
  2251. };
  2252. var top = Application.Top;
  2253. top.Add (tv);
  2254. Application.Begin (top);
  2255. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  2256. Assert.Equal (3, tv.Lines);
  2257. Assert.Equal (Point.Empty, tv.CursorPosition);
  2258. Assert.False (tv.ReadOnly);
  2259. Assert.True (tv.CanFocus);
  2260. tv.CanFocus = false;
  2261. Assert.True (tv.ProcessKey (new KeyEvent (Key.CursorLeft, new KeyModifiers ())));
  2262. tv.CanFocus = true;
  2263. Assert.False (tv.ProcessKey (new KeyEvent (Key.CursorLeft, new KeyModifiers ())));
  2264. Assert.True (tv.ProcessKey (new KeyEvent (Key.CursorRight, new KeyModifiers ())));
  2265. Assert.Equal (new Point (1, 0), tv.CursorPosition);
  2266. Assert.True (tv.ProcessKey (new KeyEvent (Key.End | Key.CtrlMask, new KeyModifiers ())));
  2267. Assert.Equal (2, tv.CurrentRow);
  2268. Assert.Equal (23, tv.CurrentColumn);
  2269. Assert.Equal (tv.CurrentColumn, tv.GetCurrentLine ().Count);
  2270. Assert.Equal (new Point (23, 2), tv.CursorPosition);
  2271. Assert.False (tv.ProcessKey (new KeyEvent (Key.CursorRight, new KeyModifiers ())));
  2272. Assert.NotNull (tv.Autocomplete);
  2273. Assert.Empty (tv.Autocomplete.AllSuggestions);
  2274. Assert.True (tv.ProcessKey (new KeyEvent (Key.F, new KeyModifiers ())));
  2275. tv.Redraw (tv.Bounds);
  2276. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.F", tv.Text);
  2277. Assert.Equal (new Point (24, 2), tv.CursorPosition);
  2278. Assert.Empty (tv.Autocomplete.Suggestions);
  2279. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  2280. tv.Redraw (tv.Bounds);
  2281. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  2282. Assert.Equal (new Point (23, 2), tv.CursorPosition);
  2283. Assert.Empty (tv.Autocomplete.Suggestions);
  2284. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  2285. tv.Redraw (tv.Bounds);
  2286. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.F", tv.Text);
  2287. Assert.Equal (new Point (24, 2), tv.CursorPosition);
  2288. Assert.Empty (tv.Autocomplete.Suggestions);
  2289. Assert.True (tv.ProcessKey (new KeyEvent (Key.Backspace, new KeyModifiers ())));
  2290. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  2291. Assert.Equal (new Point (23, 2), tv.CursorPosition);
  2292. tv.Autocomplete.AllSuggestions = Regex.Matches (tv.Text.ToString (), "\\w+")
  2293. .Select (s => s.Value)
  2294. .Distinct ().ToList ();
  2295. Assert.Equal (7, tv.Autocomplete.AllSuggestions.Count);
  2296. Assert.Equal ("This", tv.Autocomplete.AllSuggestions [0]);
  2297. Assert.Equal ("is", tv.Autocomplete.AllSuggestions [1]);
  2298. Assert.Equal ("the", tv.Autocomplete.AllSuggestions [2]);
  2299. Assert.Equal ("first", tv.Autocomplete.AllSuggestions [3]);
  2300. Assert.Equal ("line", tv.Autocomplete.AllSuggestions [4]);
  2301. Assert.Equal ("second", tv.Autocomplete.AllSuggestions [5]);
  2302. Assert.Equal ("third", tv.Autocomplete.AllSuggestions [^1]);
  2303. Assert.True (tv.ProcessKey (new KeyEvent (Key.F, new KeyModifiers ())));
  2304. tv.Redraw (tv.Bounds);
  2305. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.F", tv.Text);
  2306. Assert.Equal (new Point (24, 2), tv.CursorPosition);
  2307. Assert.Single (tv.Autocomplete.Suggestions);
  2308. Assert.Equal ("first", tv.Autocomplete.Suggestions [0]);
  2309. Assert.True (tv.ProcessKey (new KeyEvent (Key.Enter, new KeyModifiers ())));
  2310. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first", tv.Text);
  2311. Assert.Equal (new Point (28, 2), tv.CursorPosition);
  2312. Assert.Single (tv.Autocomplete.Suggestions);
  2313. Assert.Equal ("first", tv.Autocomplete.Suggestions [0]);
  2314. tv.Autocomplete.AllSuggestions = new List<string> ();
  2315. tv.Autocomplete.ClearSuggestions ();
  2316. Assert.Empty (tv.Autocomplete.AllSuggestions);
  2317. Assert.Empty (tv.Autocomplete.Suggestions);
  2318. Assert.True (tv.ProcessKey (new KeyEvent (Key.PageUp, new KeyModifiers ())));
  2319. Assert.Equal (24, tv.GetCurrentLine ().Count);
  2320. Assert.Equal (new Point (24, 1), tv.CursorPosition);
  2321. Assert.True (tv.ProcessKey (new KeyEvent (((int)'V' + Key.AltMask), new KeyModifiers ())));
  2322. Assert.Equal (23, tv.GetCurrentLine ().Count);
  2323. Assert.Equal (new Point (23, 0), tv.CursorPosition);
  2324. Assert.True (tv.ProcessKey (new KeyEvent (Key.PageDown, new KeyModifiers ())));
  2325. Assert.Equal (24, tv.GetCurrentLine ().Count);
  2326. Assert.Equal (new Point (23, 1), tv.CursorPosition); // gets the previous length
  2327. Assert.True (tv.ProcessKey (new KeyEvent (Key.V | Key.CtrlMask, new KeyModifiers ())));
  2328. Assert.Equal (28, tv.GetCurrentLine ().Count);
  2329. Assert.Equal (new Point (23, 2), tv.CursorPosition); // gets the previous length
  2330. Assert.Equal (0, tv.SelectedLength);
  2331. Assert.Equal ("", tv.SelectedText);
  2332. Assert.True (tv.ProcessKey (new KeyEvent (Key.PageUp | Key.ShiftMask, new KeyModifiers ())));
  2333. Assert.Equal (24, tv.GetCurrentLine ().Count);
  2334. Assert.Equal (new Point (23, 1), tv.CursorPosition); // gets the previous length
  2335. Assert.Equal (24 + Environment.NewLine.Length, tv.SelectedLength);
  2336. Assert.Equal ($".{Environment.NewLine}This is the third line.", tv.SelectedText);
  2337. Assert.True (tv.ProcessKey (new KeyEvent (Key.PageDown | Key.ShiftMask, new KeyModifiers ())));
  2338. Assert.Equal (28, tv.GetCurrentLine ().Count);
  2339. Assert.Equal (new Point (23, 2), tv.CursorPosition); // gets the previous length
  2340. Assert.Equal (0, tv.SelectedLength);
  2341. Assert.Equal ("", tv.SelectedText);
  2342. Assert.True (tv.ProcessKey (new KeyEvent (Key.Home | Key.CtrlMask, new KeyModifiers ())));
  2343. Assert.Equal (Point.Empty, tv.CursorPosition);
  2344. Assert.True (tv.ProcessKey (new KeyEvent (Key.N | Key.CtrlMask, new KeyModifiers ())));
  2345. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  2346. Assert.Equal (0, tv.SelectedLength);
  2347. Assert.Equal ("", tv.SelectedText);
  2348. Assert.True (tv.ProcessKey (new KeyEvent (Key.P | Key.CtrlMask, new KeyModifiers ())));
  2349. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  2350. Assert.Equal (0, tv.SelectedLength);
  2351. Assert.Equal ("", tv.SelectedText);
  2352. Assert.True (tv.ProcessKey (new KeyEvent (Key.CursorDown, new KeyModifiers ())));
  2353. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  2354. Assert.Equal (0, tv.SelectedLength);
  2355. Assert.Equal ("", tv.SelectedText);
  2356. Assert.True (tv.ProcessKey (new KeyEvent (Key.CursorUp, new KeyModifiers ())));
  2357. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  2358. Assert.Equal (0, tv.SelectedLength);
  2359. Assert.Equal ("", tv.SelectedText);
  2360. Assert.True (tv.ProcessKey (new KeyEvent (Key.CursorDown | Key.ShiftMask, new KeyModifiers ())));
  2361. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  2362. Assert.Equal (23 + Environment.NewLine.Length, tv.SelectedLength);
  2363. Assert.Equal ($"This is the first line.{Environment.NewLine}", tv.SelectedText);
  2364. Assert.True (tv.ProcessKey (new KeyEvent (Key.CursorUp | Key.ShiftMask, new KeyModifiers ())));
  2365. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  2366. Assert.Equal (0, tv.SelectedLength);
  2367. Assert.Equal ("", tv.SelectedText);
  2368. Assert.True (tv.ProcessKey (new KeyEvent (Key.F | Key.CtrlMask, new KeyModifiers ())));
  2369. Assert.Equal (new Point (1, 0), tv.CursorPosition);
  2370. Assert.Equal (0, tv.SelectedLength);
  2371. Assert.Equal ("", tv.SelectedText);
  2372. Assert.True (tv.ProcessKey (new KeyEvent (Key.B | Key.CtrlMask, new KeyModifiers ())));
  2373. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  2374. Assert.Equal (0, tv.SelectedLength);
  2375. Assert.Equal ("", tv.SelectedText);
  2376. Assert.True (tv.ProcessKey (new KeyEvent (Key.CursorRight, new KeyModifiers ())));
  2377. Assert.Equal (new Point (1, 0), tv.CursorPosition);
  2378. Assert.Equal (0, tv.SelectedLength);
  2379. Assert.Equal ("", tv.SelectedText);
  2380. Assert.True (tv.ProcessKey (new KeyEvent (Key.CursorLeft, new KeyModifiers ())));
  2381. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  2382. Assert.Equal (0, tv.SelectedLength);
  2383. Assert.Equal ("", tv.SelectedText);
  2384. Assert.False (tv.Selecting);
  2385. Assert.True (tv.ProcessKey (new KeyEvent (Key.CursorRight | Key.ShiftMask, new KeyModifiers ())));
  2386. Assert.Equal (new Point (1, 0), tv.CursorPosition);
  2387. Assert.Equal (1, tv.SelectedLength);
  2388. Assert.Equal ("T", tv.SelectedText);
  2389. Assert.True (tv.Selecting);
  2390. Assert.True (tv.ProcessKey (new KeyEvent (Key.CursorLeft | Key.ShiftMask, new KeyModifiers ())));
  2391. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  2392. Assert.Equal (0, tv.SelectedLength);
  2393. Assert.Equal ("", tv.SelectedText);
  2394. Assert.True (tv.Selecting);
  2395. Assert.True (tv.ProcessKey (new KeyEvent (Key.DeleteChar, new KeyModifiers ())));
  2396. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first", tv.Text);
  2397. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  2398. Assert.Equal (0, tv.SelectedLength);
  2399. Assert.Equal ("", tv.SelectedText);
  2400. Assert.False (tv.Selecting);
  2401. Assert.True (tv.ProcessKey (new KeyEvent (Key.DeleteChar, new KeyModifiers ())));
  2402. Assert.Equal ($"his is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first", tv.Text);
  2403. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  2404. Assert.Equal (0, tv.SelectedLength);
  2405. Assert.Equal ("", tv.SelectedText);
  2406. Assert.False (tv.Selecting);
  2407. Assert.True (tv.ProcessKey (new KeyEvent (Key.D | Key.CtrlMask, new KeyModifiers ())));
  2408. Assert.Equal ($"is is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first", tv.Text);
  2409. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  2410. Assert.True (tv.ProcessKey (new KeyEvent (Key.End, new KeyModifiers ())));
  2411. Assert.Equal ($"is is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first", tv.Text);
  2412. Assert.Equal (new Point (21, 0), tv.CursorPosition);
  2413. Assert.True (tv.ProcessKey (new KeyEvent (Key.Delete, new KeyModifiers ())));
  2414. Assert.Equal ($"is is the first line{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first", tv.Text);
  2415. Assert.Equal (new Point (20, 0), tv.CursorPosition);
  2416. Assert.True (tv.ProcessKey (new KeyEvent (Key.Backspace, new KeyModifiers ())));
  2417. Assert.Equal ($"is is the first lin{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first", tv.Text);
  2418. Assert.Equal (new Point (19, 0), tv.CursorPosition);
  2419. Assert.True (tv.ProcessKey (new KeyEvent (Key.Home, new KeyModifiers ())));
  2420. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  2421. Assert.Equal (0, tv.SelectedLength);
  2422. Assert.Equal ("", tv.SelectedText);
  2423. Assert.False (tv.Selecting);
  2424. Assert.True (tv.ProcessKey (new KeyEvent (Key.End | Key.ShiftMask, new KeyModifiers ())));
  2425. Assert.Equal (new Point (19, 0), tv.CursorPosition);
  2426. Assert.Equal (19, tv.SelectedLength);
  2427. Assert.Equal ("is is the first lin", tv.SelectedText);
  2428. Assert.True (tv.Selecting);
  2429. Assert.True (tv.ProcessKey (new KeyEvent (Key.Home | Key.ShiftMask, new KeyModifiers ())));
  2430. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  2431. Assert.Equal (0, tv.SelectedLength);
  2432. Assert.Equal ("", tv.SelectedText);
  2433. Assert.True (tv.Selecting);
  2434. Assert.True (tv.ProcessKey (new KeyEvent (Key.E | Key.CtrlMask, new KeyModifiers ())));
  2435. Assert.Equal (new Point (19, 0), tv.CursorPosition);
  2436. Assert.Equal (0, tv.SelectedLength);
  2437. Assert.Equal ("", tv.SelectedText);
  2438. Assert.False (tv.Selecting);
  2439. Assert.True (tv.ProcessKey (new KeyEvent (Key.A | Key.CtrlMask, new KeyModifiers ())));
  2440. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  2441. Assert.Equal (0, tv.SelectedLength);
  2442. Assert.Equal ("", tv.SelectedText);
  2443. Assert.False (tv.Selecting);
  2444. Assert.True (tv.ProcessKey (new KeyEvent (Key.K | Key.CtrlMask, new KeyModifiers ())));
  2445. Assert.Equal ($"{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first", tv.Text);
  2446. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  2447. Assert.Equal (0, tv.SelectedLength);
  2448. Assert.Equal ("", tv.SelectedText);
  2449. Assert.False (tv.Selecting);
  2450. Assert.Equal ("is is the first lin", Clipboard.Contents);
  2451. Assert.True (tv.ProcessKey (new KeyEvent (Key.Y | Key.CtrlMask, new KeyModifiers ())));
  2452. Assert.Equal ($"is is the first lin{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first", tv.Text);
  2453. Assert.Equal (new Point (19, 0), tv.CursorPosition);
  2454. Assert.Equal (0, tv.SelectedLength);
  2455. Assert.Equal ("", tv.SelectedText);
  2456. Assert.False (tv.Selecting);
  2457. Assert.Equal ("is is the first lin", Clipboard.Contents);
  2458. tv.CursorPosition = Point.Empty;
  2459. Assert.True (tv.ProcessKey (new KeyEvent (Key.DeleteChar | Key.CtrlMask | Key.ShiftMask, new KeyModifiers ())));
  2460. Assert.Equal ($"{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first", tv.Text);
  2461. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  2462. Assert.Equal (0, tv.SelectedLength);
  2463. Assert.Equal ("", tv.SelectedText);
  2464. Assert.False (tv.Selecting);
  2465. Assert.Equal ("is is the first lin", Clipboard.Contents);
  2466. Assert.True (tv.ProcessKey (new KeyEvent (Key.Y | Key.CtrlMask, new KeyModifiers ())));
  2467. Assert.Equal ($"is is the first lin{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first", tv.Text);
  2468. Assert.Equal (new Point (19, 0), tv.CursorPosition);
  2469. Assert.Equal (0, tv.SelectedLength);
  2470. Assert.Equal ("", tv.SelectedText);
  2471. Assert.False (tv.Selecting);
  2472. Assert.Equal ("is is the first lin", Clipboard.Contents);
  2473. Assert.True (tv.ProcessKey (new KeyEvent (Key.K | Key.AltMask, new KeyModifiers ())));
  2474. Assert.Equal ($"{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first", tv.Text);
  2475. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  2476. Assert.Equal (0, tv.SelectedLength);
  2477. Assert.Equal ("", tv.SelectedText);
  2478. Assert.False (tv.Selecting);
  2479. tv.ReadOnly = true;
  2480. Assert.True (tv.ProcessKey (new KeyEvent (Key.Y | Key.CtrlMask, new KeyModifiers ())));
  2481. Assert.Equal ($"{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first", tv.Text);
  2482. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  2483. Assert.Equal (0, tv.SelectedLength);
  2484. Assert.Equal ("", tv.SelectedText);
  2485. Assert.False (tv.Selecting);
  2486. tv.ReadOnly = false;
  2487. Assert.True (tv.ProcessKey (new KeyEvent (Key.Y | Key.CtrlMask, new KeyModifiers ())));
  2488. Assert.Equal ($"is is the first lin{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first", tv.Text);
  2489. Assert.Equal (new Point (19, 0), tv.CursorPosition);
  2490. Assert.Equal (0, tv.SelectedLength);
  2491. Assert.Equal ("", tv.SelectedText);
  2492. Assert.False (tv.Selecting);
  2493. Assert.Equal (0, tv.SelectionStartColumn);
  2494. Assert.Equal (0, tv.SelectionStartRow);
  2495. Assert.True (tv.ProcessKey (new KeyEvent (Key.Space | Key.CtrlMask, new KeyModifiers ())));
  2496. Assert.Equal ($"is is the first lin{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first", tv.Text);
  2497. Assert.Equal (new Point (19, 0), tv.CursorPosition);
  2498. Assert.Equal (0, tv.SelectedLength);
  2499. Assert.Equal ("", tv.SelectedText);
  2500. Assert.True (tv.Selecting);
  2501. Assert.Equal (19, tv.SelectionStartColumn);
  2502. Assert.Equal (0, tv.SelectionStartRow);
  2503. Assert.True (tv.ProcessKey (new KeyEvent (Key.Space | Key.CtrlMask, new KeyModifiers ())));
  2504. Assert.Equal ($"is is the first lin{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first", tv.Text);
  2505. Assert.Equal (new Point (19, 0), tv.CursorPosition);
  2506. Assert.Equal (0, tv.SelectedLength);
  2507. Assert.Equal ("", tv.SelectedText);
  2508. Assert.False (tv.Selecting);
  2509. Assert.Equal (19, tv.SelectionStartColumn);
  2510. Assert.Equal (0, tv.SelectionStartRow);
  2511. tv.SelectionStartColumn = 0;
  2512. Assert.True (tv.ProcessKey (new KeyEvent (((int)'C' + Key.AltMask), new KeyModifiers ())));
  2513. Assert.Equal ($"is is the first lin{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first", tv.Text);
  2514. Assert.Equal (new Point (19, 0), tv.CursorPosition);
  2515. Assert.Equal (19, tv.SelectedLength);
  2516. Assert.Equal ("is is the first lin", tv.SelectedText);
  2517. Assert.True (tv.Selecting);
  2518. Assert.Equal (0, tv.SelectionStartColumn);
  2519. Assert.Equal (0, tv.SelectionStartRow);
  2520. Assert.True (tv.ProcessKey (new KeyEvent (Key.C | Key.CtrlMask, new KeyModifiers ())));
  2521. Assert.Equal ($"is is the first lin{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first", tv.Text);
  2522. Assert.Equal (new Point (19, 0), tv.CursorPosition);
  2523. Assert.Equal (19, tv.SelectedLength);
  2524. Assert.Equal ("is is the first lin", tv.SelectedText);
  2525. Assert.True (tv.Selecting);
  2526. Assert.Equal (0, tv.SelectionStartColumn);
  2527. Assert.Equal (0, tv.SelectionStartRow);
  2528. Assert.True (tv.ProcessKey (new KeyEvent (((int)'W' + Key.AltMask), new KeyModifiers ())));
  2529. Assert.Equal ($"{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first", tv.Text);
  2530. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  2531. Assert.Equal (0, tv.SelectedLength);
  2532. Assert.Equal ("", tv.SelectedText);
  2533. Assert.False (tv.Selecting);
  2534. Assert.Equal (0, tv.SelectionStartColumn);
  2535. Assert.Equal (0, tv.SelectionStartRow);
  2536. Assert.Equal ("is is the first lin", Clipboard.Contents);
  2537. Assert.True (tv.ProcessKey (new KeyEvent (Key.W | Key.CtrlMask, new KeyModifiers ())));
  2538. Assert.Equal ($"{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first", tv.Text);
  2539. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  2540. Assert.Equal (0, tv.SelectedLength);
  2541. Assert.Equal ("", tv.SelectedText);
  2542. Assert.False (tv.Selecting);
  2543. Assert.Equal (0, tv.SelectionStartColumn);
  2544. Assert.Equal (0, tv.SelectionStartRow);
  2545. Assert.Equal ("", Clipboard.Contents);
  2546. Assert.True (tv.ProcessKey (new KeyEvent (Key.X | Key.CtrlMask, new KeyModifiers ())));
  2547. Assert.Equal ($"{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first", tv.Text);
  2548. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  2549. Assert.Equal (0, tv.SelectedLength);
  2550. Assert.Equal ("", tv.SelectedText);
  2551. Assert.False (tv.Selecting);
  2552. Assert.Equal (0, tv.SelectionStartColumn);
  2553. Assert.Equal (0, tv.SelectionStartRow);
  2554. Assert.Equal ("", Clipboard.Contents);
  2555. Assert.True (tv.ProcessKey (new KeyEvent (Key.End | Key.CtrlMask, new KeyModifiers ())));
  2556. Assert.Equal ($"{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first", tv.Text);
  2557. Assert.Equal (new Point (28, 2), tv.CursorPosition);
  2558. Assert.Equal (0, tv.SelectedLength);
  2559. Assert.Equal ("", tv.SelectedText);
  2560. Assert.False (tv.Selecting);
  2561. Assert.True (tv.ProcessKey (new KeyEvent (Key.CtrlMask | Key.CursorLeft, new KeyModifiers ())));
  2562. Assert.Equal ($"{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first", tv.Text);
  2563. Assert.Equal (new Point (18, 2), tv.CursorPosition);
  2564. Assert.Equal (0, tv.SelectedLength);
  2565. Assert.Equal ("", tv.SelectedText);
  2566. Assert.False (tv.Selecting);
  2567. Assert.True (tv.ProcessKey (new KeyEvent (Key.CtrlMask | Key.CursorLeft | Key.ShiftMask, new KeyModifiers ())));
  2568. Assert.Equal ($"{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first", tv.Text);
  2569. Assert.Equal (new Point (12, 2), tv.CursorPosition);
  2570. Assert.Equal (6, tv.SelectedLength);
  2571. Assert.Equal ("third ", tv.SelectedText);
  2572. Assert.True (tv.Selecting);
  2573. Assert.True (tv.ProcessKey (new KeyEvent ((Key)((int)'B' + Key.AltMask), new KeyModifiers ())));
  2574. Assert.Equal ($"{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first", tv.Text);
  2575. Assert.Equal (new Point (8, 2), tv.CursorPosition);
  2576. Assert.Equal (0, tv.SelectedLength);
  2577. Assert.Equal ("", tv.SelectedText);
  2578. Assert.False (tv.Selecting);
  2579. Assert.True (tv.ProcessKey (new KeyEvent (Key.CtrlMask | Key.CursorRight, new KeyModifiers ())));
  2580. Assert.Equal ($"{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first", tv.Text);
  2581. Assert.Equal (new Point (12, 2), tv.CursorPosition);
  2582. Assert.Equal (0, tv.SelectedLength);
  2583. Assert.Equal ("", tv.SelectedText);
  2584. Assert.False (tv.Selecting);
  2585. Assert.True (tv.ProcessKey (new KeyEvent (Key.CtrlMask | Key.CursorRight | Key.ShiftMask, new KeyModifiers ())));
  2586. Assert.Equal ($"{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first", tv.Text);
  2587. Assert.Equal (new Point (18, 2), tv.CursorPosition);
  2588. Assert.Equal (6, tv.SelectedLength);
  2589. Assert.Equal ("third ", tv.SelectedText);
  2590. Assert.True (tv.Selecting);
  2591. Assert.True (tv.ProcessKey (new KeyEvent ((Key)((int)'F' + Key.AltMask), new KeyModifiers ())));
  2592. Assert.Equal ($"{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first", tv.Text);
  2593. Assert.Equal (new Point (28, 2), tv.CursorPosition);
  2594. Assert.Equal (0, tv.SelectedLength);
  2595. Assert.Equal ("", tv.SelectedText);
  2596. Assert.False (tv.Selecting);
  2597. Assert.True (tv.ProcessKey (new KeyEvent (Key.Home | Key.CtrlMask, new KeyModifiers ())));
  2598. Assert.Equal ($"{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first", tv.Text);
  2599. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  2600. Assert.Equal (0, tv.SelectedLength);
  2601. Assert.Equal ("", tv.SelectedText);
  2602. Assert.False (tv.Selecting);
  2603. Assert.True (tv.ProcessKey (new KeyEvent (Key.DeleteChar | Key.CtrlMask, new KeyModifiers ())));
  2604. Assert.Equal ($"This is the second line.{Environment.NewLine}This is the third line.first", tv.Text);
  2605. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  2606. Assert.Equal (0, tv.SelectedLength);
  2607. Assert.Equal ("", tv.SelectedText);
  2608. Assert.False (tv.Selecting); Assert.True (tv.ProcessKey (new KeyEvent (Key.End | Key.CtrlMask, new KeyModifiers ())));
  2609. Assert.Equal ($"This is the second line.{Environment.NewLine}This is the third line.first", tv.Text);
  2610. Assert.Equal (new Point (28, 1), tv.CursorPosition);
  2611. Assert.Equal (0, tv.SelectedLength);
  2612. Assert.Equal ("", tv.SelectedText);
  2613. Assert.False (tv.Selecting);
  2614. Assert.False (tv.Selecting); Assert.True (tv.ProcessKey (new KeyEvent (Key.Backspace | Key.CtrlMask, new KeyModifiers ())));
  2615. Assert.Equal ($"This is the second line.{Environment.NewLine}This is the third ", tv.Text);
  2616. Assert.Equal (new Point (18, 1), tv.CursorPosition);
  2617. Assert.Equal (0, tv.SelectedLength);
  2618. Assert.Equal ("", tv.SelectedText);
  2619. Assert.False (tv.Selecting);
  2620. Assert.True (tv.AllowsReturn);
  2621. tv.AllowsReturn = false;
  2622. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  2623. Assert.False (tv.Selecting);
  2624. Assert.False (tv.ProcessKey (new KeyEvent (Key.Enter, new KeyModifiers ())));
  2625. Assert.Equal ($"This is the second line.{Environment.NewLine}This is the third ", tv.Text);
  2626. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  2627. Assert.Equal (0, tv.SelectedLength);
  2628. Assert.Equal ("", tv.SelectedText);
  2629. Assert.False (tv.Selecting);
  2630. Assert.False (tv.AllowsReturn);
  2631. tv.AllowsReturn = true;
  2632. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  2633. Assert.True (tv.ProcessKey (new KeyEvent (Key.Enter, new KeyModifiers ())));
  2634. Assert.Equal ($"{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third ", tv.Text);
  2635. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  2636. Assert.Equal (0, tv.SelectedLength);
  2637. Assert.Equal ("", tv.SelectedText);
  2638. Assert.False (tv.Selecting);
  2639. Assert.True (tv.AllowsReturn);
  2640. Assert.True (tv.ProcessKey (new KeyEvent (Key.CtrlMask | Key.End | Key.ShiftMask, new KeyModifiers ())));
  2641. Assert.Equal ($"{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third ", tv.Text);
  2642. Assert.Equal (new Point (18, 2), tv.CursorPosition);
  2643. Assert.Equal (42 + Environment.NewLine.Length, tv.SelectedLength);
  2644. Assert.Equal ($"This is the second line.{Environment.NewLine}This is the third ", tv.SelectedText);
  2645. Assert.True (tv.Selecting);
  2646. Assert.True (tv.ProcessKey (new KeyEvent (Key.CtrlMask | Key.Home | Key.ShiftMask, new KeyModifiers ())));
  2647. Assert.Equal ($"{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third ", tv.Text);
  2648. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  2649. Assert.Equal (Environment.NewLine.Length, tv.SelectedLength);
  2650. Assert.Equal ($"{Environment.NewLine}", tv.SelectedText);
  2651. Assert.True (tv.Selecting);
  2652. Assert.True (tv.ProcessKey (new KeyEvent (Key.T | Key.CtrlMask, new KeyModifiers ())));
  2653. Assert.Equal ($"{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third ", tv.Text);
  2654. Assert.Equal (new Point (18, 2), tv.CursorPosition);
  2655. Assert.Equal (42 + Environment.NewLine.Length * 2, tv.SelectedLength);
  2656. Assert.Equal ($"{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third ", tv.SelectedText);
  2657. Assert.True (tv.Selecting);
  2658. Assert.True (tv.Used);
  2659. Assert.True (tv.ProcessKey (new KeyEvent (Key.InsertChar, new KeyModifiers ())));
  2660. Assert.False (tv.Used);
  2661. Assert.True (tv.AllowsTab);
  2662. Assert.Equal (new Point (18, 2), tv.CursorPosition);
  2663. tv.AllowsTab = false;
  2664. Assert.False (tv.ProcessKey (new KeyEvent (Key.Tab, new KeyModifiers ())));
  2665. Assert.Equal ($"{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third ", tv.Text);
  2666. Assert.False (tv.AllowsTab);
  2667. tv.AllowsTab = true;
  2668. Assert.Equal (new Point (18, 2), tv.CursorPosition);
  2669. Assert.True (tv.Selecting);
  2670. tv.Selecting = false;
  2671. Assert.True (tv.ProcessKey (new KeyEvent (Key.Tab, new KeyModifiers ())));
  2672. Assert.Equal ($"{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third \t", tv.Text);
  2673. Assert.True (tv.AllowsTab);
  2674. tv.AllowsTab = false;
  2675. Assert.False (tv.ProcessKey (new KeyEvent (Key.BackTab | Key.ShiftMask, new KeyModifiers ())));
  2676. Assert.Equal ($"{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third \t", tv.Text);
  2677. Assert.False (tv.AllowsTab);
  2678. tv.AllowsTab = true;
  2679. Assert.True (tv.ProcessKey (new KeyEvent (Key.BackTab | Key.ShiftMask, new KeyModifiers ())));
  2680. Assert.Equal ($"{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third ", tv.Text);
  2681. Assert.True (tv.AllowsTab);
  2682. Assert.False (tv.ProcessKey (new KeyEvent (Key.Tab | Key.CtrlMask, new KeyModifiers ())));
  2683. Assert.False (tv.ProcessKey (new KeyEvent (Application.AlternateForwardKey, new KeyModifiers ())));
  2684. Assert.False (tv.ProcessKey (new KeyEvent (Key.Tab | Key.CtrlMask | Key.ShiftMask, new KeyModifiers ())));
  2685. Assert.False (tv.ProcessKey (new KeyEvent (Application.AlternateBackwardKey, new KeyModifiers ())));
  2686. }
  2687. [Fact]
  2688. public void HistoryText_Exceptions ()
  2689. {
  2690. var ht = new HistoryText ();
  2691. foreach (var ls in Enum.GetValues (typeof (HistoryText.LineStatus))) {
  2692. if ((HistoryText.LineStatus)ls != HistoryText.LineStatus.Original) {
  2693. Assert.Throws<ArgumentException> (() => ht.Add (new List<List<Rune>> () { new List<Rune> () }, Point.Empty,
  2694. (HistoryText.LineStatus)ls));
  2695. }
  2696. }
  2697. Assert.Null (Record.Exception (() => ht.Add (new List<List<Rune>> () { new List<Rune> () }, Point.Empty,
  2698. HistoryText.LineStatus.Original)));
  2699. }
  2700. [Fact]
  2701. [AutoInitShutdown]
  2702. public void HistoryText_Undo_Redo_Single_Line_InsertText ()
  2703. {
  2704. var text = "This is the first line.\nThis is the second line.\nThis is the third line.";
  2705. var tv = new TextView () {
  2706. Width = 10,
  2707. Height = 2,
  2708. Text = text
  2709. };
  2710. var top = Application.Top;
  2711. top.Add (tv);
  2712. Application.Begin (top);
  2713. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  2714. Assert.Equal (3, tv.Lines);
  2715. Assert.Equal (Point.Empty, tv.CursorPosition);
  2716. var messy = " messy";
  2717. tv.CursorPosition = new Point (7, 1);
  2718. tv.InsertText (messy);
  2719. Assert.Equal ($"This is the first line.{Environment.NewLine}This is messy the second line.{Environment.NewLine}This is the third line.", tv.Text);
  2720. Assert.Equal (3, tv.Lines);
  2721. Assert.Equal (new Point (13, 1), tv.CursorPosition);
  2722. for (int i = 0; i < messy.Length; i++) {
  2723. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  2724. }
  2725. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  2726. Assert.Equal (3, tv.Lines);
  2727. Assert.Equal (new Point (7, 1), tv.CursorPosition);
  2728. for (int i = 0; i < messy.Length; i++) {
  2729. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  2730. }
  2731. Assert.Equal ($"This is the first line.{Environment.NewLine}This is messy the second line.{Environment.NewLine}This is the third line.", tv.Text);
  2732. Assert.Equal (3, tv.Lines);
  2733. Assert.Equal (new Point (13, 1), tv.CursorPosition);
  2734. }
  2735. [Fact]
  2736. [AutoInitShutdown]
  2737. public void HistoryText_Undo_Redo_Single_Line_DeleteCharLeft ()
  2738. {
  2739. var text = "This is the first line.\nThis is the second line.\nThis is the third line.";
  2740. var tv = new TextView () {
  2741. Width = 10,
  2742. Height = 2,
  2743. Text = text
  2744. };
  2745. var top = Application.Top;
  2746. top.Add (tv);
  2747. Application.Begin (top);
  2748. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  2749. Assert.Equal (3, tv.Lines);
  2750. Assert.Equal (Point.Empty, tv.CursorPosition);
  2751. var ntimes = 3;
  2752. tv.CursorPosition = new Point (7, 1);
  2753. for (int i = 0; i < ntimes; i++) {
  2754. tv.DeleteCharLeft ();
  2755. }
  2756. Assert.Equal ($"This is the first line.{Environment.NewLine}This the second line.{Environment.NewLine}This is the third line.", tv.Text);
  2757. Assert.Equal (3, tv.Lines);
  2758. Assert.Equal (new Point (4, 1), tv.CursorPosition);
  2759. for (int i = 0; i < ntimes; i++) {
  2760. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  2761. }
  2762. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  2763. Assert.Equal (3, tv.Lines);
  2764. Assert.Equal (new Point (7, 1), tv.CursorPosition);
  2765. for (int i = 0; i < ntimes; i++) {
  2766. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  2767. }
  2768. Assert.Equal ($"This is the first line.{Environment.NewLine}This the second line.{Environment.NewLine}This is the third line.", tv.Text);
  2769. Assert.Equal (3, tv.Lines);
  2770. Assert.Equal (new Point (4, 1), tv.CursorPosition);
  2771. }
  2772. [Fact]
  2773. [AutoInitShutdown]
  2774. public void HistoryText_Undo_Redo_Single_Line_DeleteCharRight ()
  2775. {
  2776. var text = "This is the first line.\nThis is the second line.\nThis is the third line.";
  2777. var tv = new TextView () {
  2778. Width = 10,
  2779. Height = 2,
  2780. Text = text
  2781. };
  2782. var top = Application.Top;
  2783. top.Add (tv);
  2784. Application.Begin (top);
  2785. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  2786. Assert.Equal (3, tv.Lines);
  2787. Assert.Equal (Point.Empty, tv.CursorPosition);
  2788. var ntimes = 3;
  2789. tv.CursorPosition = new Point (7, 1);
  2790. for (int i = 0; i < ntimes; i++) {
  2791. tv.DeleteCharRight ();
  2792. }
  2793. Assert.Equal ($"This is the first line.{Environment.NewLine}This ise second line.{Environment.NewLine}This is the third line.", tv.Text);
  2794. Assert.Equal (3, tv.Lines);
  2795. Assert.Equal (new Point (7, 1), tv.CursorPosition);
  2796. for (int i = 0; i < ntimes; i++) {
  2797. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  2798. }
  2799. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  2800. Assert.Equal (3, tv.Lines);
  2801. Assert.Equal (new Point (7, 1), tv.CursorPosition);
  2802. for (int i = 0; i < ntimes; i++) {
  2803. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  2804. }
  2805. Assert.Equal ($"This is the first line.{Environment.NewLine}This ise second line.{Environment.NewLine}This is the third line.", tv.Text);
  2806. Assert.Equal (3, tv.Lines);
  2807. Assert.Equal (new Point (7, 1), tv.CursorPosition);
  2808. }
  2809. [Fact]
  2810. [AutoInitShutdown]
  2811. public void HistoryText_Undo_Redo_Single_Line_Selected_InsertText ()
  2812. {
  2813. var text = "This is the first line.\nThis is the second line.\nThis is the third line.";
  2814. var tv = new TextView () {
  2815. Width = 10,
  2816. Height = 2,
  2817. Text = text
  2818. };
  2819. var top = Application.Top;
  2820. top.Add (tv);
  2821. Application.Begin (top);
  2822. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  2823. Assert.Equal (3, tv.Lines);
  2824. Assert.Equal (Point.Empty, tv.CursorPosition);
  2825. var messy = " messy";
  2826. tv.CursorPosition = new Point (7, 1);
  2827. tv.SelectionStartColumn = 11;
  2828. tv.SelectionStartRow = 1;
  2829. Assert.Equal (4, tv.SelectedLength);
  2830. tv.InsertText (messy);
  2831. Assert.Equal ($"This is the first line.{Environment.NewLine}This is messy second line.{Environment.NewLine}This is the third line.", tv.Text);
  2832. Assert.Equal (3, tv.Lines);
  2833. Assert.Equal (new Point (13, 1), tv.CursorPosition);
  2834. Assert.Equal (11, tv.SelectionStartColumn);
  2835. Assert.Equal (1, tv.SelectionStartRow);
  2836. Assert.Equal (0, tv.SelectedLength);
  2837. for (int i = 0; i < messy.Length; i++) {
  2838. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  2839. }
  2840. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  2841. Assert.Equal (3, tv.Lines);
  2842. Assert.Equal (new Point (7, 1), tv.CursorPosition);
  2843. Assert.Equal (11, tv.SelectionStartColumn);
  2844. Assert.Equal (1, tv.SelectionStartRow);
  2845. Assert.Equal (0, tv.SelectedLength);
  2846. for (int i = 0; i < messy.Length; i++) {
  2847. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  2848. }
  2849. Assert.Equal ($"This is the first line.{Environment.NewLine}This is messy second line.{Environment.NewLine}This is the third line.", tv.Text);
  2850. Assert.Equal (3, tv.Lines);
  2851. Assert.Equal (new Point (13, 1), tv.CursorPosition);
  2852. Assert.Equal (11, tv.SelectionStartColumn);
  2853. Assert.Equal (1, tv.SelectionStartRow);
  2854. Assert.Equal (0, tv.SelectedLength);
  2855. }
  2856. [Fact]
  2857. [AutoInitShutdown]
  2858. public void HistoryText_Undo_Redo_Single_Line_Selected_DeleteCharLeft ()
  2859. {
  2860. var text = "This is the first line.\nThis is the second line.\nThis is the third line.";
  2861. var tv = new TextView () {
  2862. Width = 10,
  2863. Height = 2,
  2864. Text = text
  2865. };
  2866. var top = Application.Top;
  2867. top.Add (tv);
  2868. Application.Begin (top);
  2869. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  2870. Assert.Equal (3, tv.Lines);
  2871. Assert.Equal (Point.Empty, tv.CursorPosition);
  2872. var ntimes = 3;
  2873. tv.CursorPosition = new Point (7, 1);
  2874. tv.SelectionStartColumn = 11;
  2875. tv.SelectionStartRow = 1;
  2876. Assert.Equal (4, tv.SelectedLength);
  2877. for (int i = 0; i < ntimes; i++) {
  2878. tv.DeleteCharLeft ();
  2879. }
  2880. Assert.Equal ($"This is the first line.{Environment.NewLine}This second line.{Environment.NewLine}This is the third line.", tv.Text);
  2881. Assert.Equal (3, tv.Lines);
  2882. Assert.Equal (new Point (5, 1), tv.CursorPosition);
  2883. Assert.Equal (11, tv.SelectionStartColumn);
  2884. Assert.Equal (1, tv.SelectionStartRow);
  2885. Assert.Equal (0, tv.SelectedLength);
  2886. for (int i = 0; i < ntimes; i++) {
  2887. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  2888. }
  2889. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  2890. Assert.Equal (3, tv.Lines);
  2891. Assert.Equal (new Point (7, 1), tv.CursorPosition);
  2892. Assert.Equal (11, tv.SelectionStartColumn);
  2893. Assert.Equal (1, tv.SelectionStartRow);
  2894. Assert.Equal (0, tv.SelectedLength);
  2895. for (int i = 0; i < ntimes; i++) {
  2896. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  2897. }
  2898. Assert.Equal ($"This is the first line.{Environment.NewLine}This second line.{Environment.NewLine}This is the third line.", tv.Text);
  2899. Assert.Equal (3, tv.Lines);
  2900. Assert.Equal (new Point (5, 1), tv.CursorPosition);
  2901. Assert.Equal (11, tv.SelectionStartColumn);
  2902. Assert.Equal (1, tv.SelectionStartRow);
  2903. Assert.Equal (0, tv.SelectedLength);
  2904. }
  2905. [Fact]
  2906. [AutoInitShutdown]
  2907. public void HistoryText_Undo_Redo_Single_Line_Selected_DeleteCharRight ()
  2908. {
  2909. var text = "This is the first line.\nThis is the second line.\nThis is the third line.";
  2910. var tv = new TextView () {
  2911. Width = 10,
  2912. Height = 2,
  2913. Text = text
  2914. };
  2915. var top = Application.Top;
  2916. top.Add (tv);
  2917. Application.Begin (top);
  2918. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  2919. Assert.Equal (3, tv.Lines);
  2920. Assert.Equal (Point.Empty, tv.CursorPosition);
  2921. var ntimes = 3;
  2922. tv.CursorPosition = new Point (7, 1);
  2923. tv.SelectionStartColumn = 11;
  2924. tv.SelectionStartRow = 1;
  2925. Assert.Equal (4, tv.SelectedLength);
  2926. for (int i = 0; i < ntimes; i++) {
  2927. tv.DeleteCharRight ();
  2928. }
  2929. Assert.Equal ($"This is the first line.{Environment.NewLine}This isecond line.{Environment.NewLine}This is the third line.", tv.Text);
  2930. Assert.Equal (3, tv.Lines);
  2931. Assert.Equal (new Point (7, 1), tv.CursorPosition);
  2932. Assert.Equal (11, tv.SelectionStartColumn);
  2933. Assert.Equal (1, tv.SelectionStartRow);
  2934. Assert.Equal (0, tv.SelectedLength);
  2935. for (int i = 0; i < ntimes; i++) {
  2936. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  2937. }
  2938. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  2939. Assert.Equal (3, tv.Lines);
  2940. Assert.Equal (new Point (7, 1), tv.CursorPosition);
  2941. Assert.Equal (11, tv.SelectionStartColumn);
  2942. Assert.Equal (1, tv.SelectionStartRow);
  2943. Assert.Equal (0, tv.SelectedLength);
  2944. for (int i = 0; i < ntimes; i++) {
  2945. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  2946. }
  2947. Assert.Equal ($"This is the first line.{Environment.NewLine}This isecond line.{Environment.NewLine}This is the third line.", tv.Text);
  2948. Assert.Equal (3, tv.Lines);
  2949. Assert.Equal (new Point (7, 1), tv.CursorPosition);
  2950. Assert.Equal (11, tv.SelectionStartColumn);
  2951. Assert.Equal (1, tv.SelectionStartRow);
  2952. Assert.Equal (0, tv.SelectedLength);
  2953. }
  2954. [Fact]
  2955. [AutoInitShutdown]
  2956. public void HistoryText_Undo_Redo_Multi_Line_InsertText ()
  2957. {
  2958. var text = "This is the first line.\nThis is the second line.\nThis is the third line.";
  2959. var tv = new TextView () {
  2960. Width = 10,
  2961. Height = 2,
  2962. Text = text
  2963. };
  2964. var top = Application.Top;
  2965. top.Add (tv);
  2966. Application.Begin (top);
  2967. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  2968. Assert.Equal (3, tv.Lines);
  2969. Assert.Equal (Point.Empty, tv.CursorPosition);
  2970. var messy = " messy";
  2971. tv.CursorPosition = new Point (7, 1);
  2972. tv.InsertText (messy);
  2973. Assert.Equal ($"This is the first line.{Environment.NewLine}This is messy the second line.{Environment.NewLine}This is the third line.", tv.Text);
  2974. Assert.Equal (3, tv.Lines);
  2975. Assert.Equal (new Point (13, 1), tv.CursorPosition);
  2976. tv.CursorPosition = new Point (7, 0);
  2977. tv.InsertText (messy);
  2978. Assert.Equal ($"This is messy the first line.{Environment.NewLine}This is messy the second line.{Environment.NewLine}This is the third line.", tv.Text);
  2979. Assert.Equal (3, tv.Lines);
  2980. Assert.Equal (new Point (13, 0), tv.CursorPosition);
  2981. tv.CursorPosition = new Point (7, 2);
  2982. tv.InsertText (messy);
  2983. Assert.Equal ($"This is messy the first line.{Environment.NewLine}This is messy the second line.{Environment.NewLine}This is messy the third line.", tv.Text);
  2984. Assert.Equal (3, tv.Lines);
  2985. Assert.Equal (new Point (13, 2), tv.CursorPosition);
  2986. for (int i = 0; i < messy.Length; i++) {
  2987. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  2988. }
  2989. Assert.Equal ($"This is messy the first line.{Environment.NewLine}This is messy the second line.{Environment.NewLine}This is the third line.", tv.Text);
  2990. Assert.Equal (3, tv.Lines);
  2991. Assert.Equal (new Point (7, 2), tv.CursorPosition);
  2992. for (int i = 0; i < messy.Length; i++) {
  2993. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  2994. }
  2995. Assert.Equal ($"This is the first line.{Environment.NewLine}This is messy the second line.{Environment.NewLine}This is the third line.", tv.Text);
  2996. Assert.Equal (3, tv.Lines);
  2997. Assert.Equal (new Point (7, 0), tv.CursorPosition);
  2998. for (int i = 0; i < messy.Length; i++) {
  2999. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  3000. }
  3001. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  3002. Assert.Equal (3, tv.Lines);
  3003. Assert.Equal (new Point (7, 1), tv.CursorPosition);
  3004. for (int i = 0; i < messy.Length; i++) {
  3005. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  3006. }
  3007. Assert.Equal ($"This is the first line.{Environment.NewLine}This is messy the second line.{Environment.NewLine}This is the third line.", tv.Text);
  3008. Assert.Equal (3, tv.Lines);
  3009. Assert.Equal (new Point (13, 1), tv.CursorPosition);
  3010. for (int i = 0; i < messy.Length; i++) {
  3011. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  3012. }
  3013. Assert.Equal ($"This is messy the first line.{Environment.NewLine}This is messy the second line.{Environment.NewLine}This is the third line.", tv.Text);
  3014. Assert.Equal (3, tv.Lines);
  3015. Assert.Equal (new Point (13, 0), tv.CursorPosition);
  3016. for (int i = 0; i < messy.Length; i++) {
  3017. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  3018. }
  3019. Assert.Equal ($"This is messy the first line.{Environment.NewLine}This is messy the second line.{Environment.NewLine}This is messy the third line.", tv.Text);
  3020. Assert.Equal (3, tv.Lines);
  3021. Assert.Equal (new Point (13, 2), tv.CursorPosition);
  3022. }
  3023. [Fact]
  3024. [AutoInitShutdown]
  3025. public void HistoryText_Undo_Redo_Multi_Line_DeleteCharLeft ()
  3026. {
  3027. var text = "This is the first line.\nThis is the second line.\nThis is the third line.";
  3028. var tv = new TextView () {
  3029. Width = 10,
  3030. Height = 2,
  3031. Text = text
  3032. };
  3033. var top = Application.Top;
  3034. top.Add (tv);
  3035. Application.Begin (top);
  3036. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  3037. Assert.Equal (3, tv.Lines);
  3038. Assert.Equal (Point.Empty, tv.CursorPosition);
  3039. var ntimes = 3;
  3040. tv.CursorPosition = new Point (7, 1);
  3041. for (int i = 0; i < ntimes; i++) {
  3042. tv.DeleteCharLeft ();
  3043. }
  3044. Assert.Equal ($"This is the first line.{Environment.NewLine}This the second line.{Environment.NewLine}This is the third line.", tv.Text);
  3045. Assert.Equal (3, tv.Lines);
  3046. Assert.Equal (new Point (4, 1), tv.CursorPosition);
  3047. tv.CursorPosition = new Point (7, 0);
  3048. for (int i = 0; i < ntimes; i++) {
  3049. tv.DeleteCharLeft ();
  3050. }
  3051. Assert.Equal ($"This the first line.{Environment.NewLine}This the second line.{Environment.NewLine}This is the third line.", tv.Text);
  3052. Assert.Equal (3, tv.Lines);
  3053. Assert.Equal (new Point (4, 0), tv.CursorPosition);
  3054. tv.CursorPosition = new Point (7, 2);
  3055. for (int i = 0; i < ntimes; i++) {
  3056. tv.DeleteCharLeft ();
  3057. }
  3058. Assert.Equal ($"This the first line.{Environment.NewLine}This the second line.{Environment.NewLine}This the third line.", tv.Text);
  3059. Assert.Equal (3, tv.Lines);
  3060. Assert.Equal (new Point (4, 2), tv.CursorPosition);
  3061. for (int i = 0; i < ntimes; i++) {
  3062. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  3063. switch (i) {
  3064. case 0:
  3065. Assert.Equal ($"This the first line.{Environment.NewLine}This the second line.{Environment.NewLine}This the third line.", tv.Text);
  3066. Assert.Equal (new Point (5, 2), tv.CursorPosition);
  3067. break;
  3068. case 1:
  3069. Assert.Equal ($"This the first line.{Environment.NewLine}This the second line.{Environment.NewLine}This i the third line.", tv.Text);
  3070. Assert.Equal (new Point (6, 2), tv.CursorPosition);
  3071. break;
  3072. case 2:
  3073. Assert.Equal ($"This the first line.{Environment.NewLine}This the second line.{Environment.NewLine}This is the third line.", tv.Text);
  3074. Assert.Equal (new Point (7, 2), tv.CursorPosition);
  3075. break;
  3076. }
  3077. }
  3078. Assert.Equal ($"This the first line.{Environment.NewLine}This the second line.{Environment.NewLine}This is the third line.", tv.Text);
  3079. Assert.Equal (3, tv.Lines);
  3080. Assert.Equal (new Point (7, 2), tv.CursorPosition);
  3081. for (int i = 0; i < ntimes; i++) {
  3082. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  3083. switch (i) {
  3084. case 0:
  3085. Assert.Equal ($"This the first line.{Environment.NewLine}This the second line.{Environment.NewLine}This is the third line.", tv.Text);
  3086. Assert.Equal (new Point (5, 0), tv.CursorPosition);
  3087. break;
  3088. case 1:
  3089. Assert.Equal ($"This i the first line.{Environment.NewLine}This the second line.{Environment.NewLine}This is the third line.", tv.Text);
  3090. Assert.Equal (new Point (6, 0), tv.CursorPosition);
  3091. break;
  3092. case 2:
  3093. Assert.Equal ($"This is the first line.{Environment.NewLine}This the second line.{Environment.NewLine}This is the third line.", tv.Text);
  3094. Assert.Equal (new Point (7, 0), tv.CursorPosition);
  3095. break;
  3096. }
  3097. }
  3098. Assert.Equal ($"This is the first line.{Environment.NewLine}This the second line.{Environment.NewLine}This is the third line.", tv.Text);
  3099. Assert.Equal (3, tv.Lines);
  3100. Assert.Equal (new Point (7, 0), tv.CursorPosition);
  3101. for (int i = 0; i < ntimes; i++) {
  3102. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  3103. switch (i) {
  3104. case 0:
  3105. Assert.Equal ($"This is the first line.{Environment.NewLine}This the second line.{Environment.NewLine}This is the third line.", tv.Text);
  3106. Assert.Equal (new Point (5, 1), tv.CursorPosition);
  3107. break;
  3108. case 1:
  3109. Assert.Equal ($"This is the first line.{Environment.NewLine}This i the second line.{Environment.NewLine}This is the third line.", tv.Text);
  3110. Assert.Equal (new Point (6, 1), tv.CursorPosition);
  3111. break;
  3112. case 2:
  3113. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  3114. Assert.Equal (new Point (7, 1), tv.CursorPosition);
  3115. break;
  3116. }
  3117. }
  3118. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  3119. Assert.Equal (3, tv.Lines);
  3120. Assert.Equal (new Point (7, 1), tv.CursorPosition);
  3121. for (int i = 0; i < ntimes; i++) {
  3122. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  3123. }
  3124. Assert.Equal ($"This is the first line.{Environment.NewLine}This the second line.{Environment.NewLine}This is the third line.", tv.Text);
  3125. Assert.Equal (3, tv.Lines);
  3126. Assert.Equal (new Point (4, 1), tv.CursorPosition);
  3127. for (int i = 0; i < ntimes; i++) {
  3128. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  3129. }
  3130. Assert.Equal ($"This the first line.{Environment.NewLine}This the second line.{Environment.NewLine}This is the third line.", tv.Text);
  3131. Assert.Equal (3, tv.Lines);
  3132. Assert.Equal (new Point (4, 0), tv.CursorPosition);
  3133. for (int i = 0; i < ntimes; i++) {
  3134. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  3135. }
  3136. Assert.Equal ($"This the first line.{Environment.NewLine}This the second line.{Environment.NewLine}This the third line.", tv.Text);
  3137. Assert.Equal (3, tv.Lines);
  3138. Assert.Equal (new Point (4, 2), tv.CursorPosition);
  3139. }
  3140. [Fact]
  3141. [AutoInitShutdown]
  3142. public void HistoryText_Undo_Redo_Multi_Line_DeleteCharRight ()
  3143. {
  3144. var text = "This is the first line.\nThis is the second line.\nThis is the third line.";
  3145. var tv = new TextView () {
  3146. Width = 10,
  3147. Height = 2,
  3148. Text = text
  3149. };
  3150. var top = Application.Top;
  3151. top.Add (tv);
  3152. Application.Begin (top);
  3153. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  3154. Assert.Equal (3, tv.Lines);
  3155. Assert.Equal (Point.Empty, tv.CursorPosition);
  3156. var ntimes = 3;
  3157. tv.CursorPosition = new Point (7, 1);
  3158. for (int i = 0; i < ntimes; i++) {
  3159. tv.DeleteCharRight ();
  3160. }
  3161. Assert.Equal ($"This is the first line.{Environment.NewLine}This ise second line.{Environment.NewLine}This is the third line.", tv.Text);
  3162. Assert.Equal (3, tv.Lines);
  3163. Assert.Equal (new Point (7, 1), tv.CursorPosition);
  3164. tv.CursorPosition = new Point (7, 0);
  3165. for (int i = 0; i < ntimes; i++) {
  3166. tv.DeleteCharRight ();
  3167. }
  3168. Assert.Equal ($"This ise first line.{Environment.NewLine}This ise second line.{Environment.NewLine}This is the third line.", tv.Text);
  3169. Assert.Equal (3, tv.Lines);
  3170. Assert.Equal (new Point (7, 0), tv.CursorPosition);
  3171. tv.CursorPosition = new Point (7, 2);
  3172. for (int i = 0; i < ntimes; i++) {
  3173. tv.DeleteCharRight ();
  3174. }
  3175. Assert.Equal ($"This ise first line.{Environment.NewLine}This ise second line.{Environment.NewLine}This ise third line.", tv.Text);
  3176. Assert.Equal (3, tv.Lines);
  3177. Assert.Equal (new Point (7, 2), tv.CursorPosition);
  3178. for (int i = 0; i < ntimes; i++) {
  3179. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  3180. }
  3181. Assert.Equal ($"This ise first line.{Environment.NewLine}This ise second line.{Environment.NewLine}This is the third line.", tv.Text);
  3182. Assert.Equal (3, tv.Lines);
  3183. Assert.Equal (new Point (7, 2), tv.CursorPosition);
  3184. for (int i = 0; i < ntimes; i++) {
  3185. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  3186. }
  3187. Assert.Equal ($"This is the first line.{Environment.NewLine}This ise second line.{Environment.NewLine}This is the third line.", tv.Text);
  3188. Assert.Equal (3, tv.Lines);
  3189. Assert.Equal (new Point (7, 0), tv.CursorPosition);
  3190. for (int i = 0; i < ntimes; i++) {
  3191. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  3192. }
  3193. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  3194. Assert.Equal (3, tv.Lines);
  3195. Assert.Equal (new Point (7, 1), tv.CursorPosition);
  3196. for (int i = 0; i < ntimes; i++) {
  3197. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  3198. }
  3199. Assert.Equal ($"This is the first line.{Environment.NewLine}This ise second line.{Environment.NewLine}This is the third line.", tv.Text);
  3200. Assert.Equal (3, tv.Lines);
  3201. Assert.Equal (new Point (7, 1), tv.CursorPosition);
  3202. for (int i = 0; i < ntimes; i++) {
  3203. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  3204. }
  3205. Assert.Equal ($"This ise first line.{Environment.NewLine}This ise second line.{Environment.NewLine}This is the third line.", tv.Text);
  3206. Assert.Equal (3, tv.Lines);
  3207. Assert.Equal (new Point (7, 0), tv.CursorPosition);
  3208. for (int i = 0; i < ntimes; i++) {
  3209. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  3210. }
  3211. Assert.Equal ($"This ise first line.{Environment.NewLine}This ise second line.{Environment.NewLine}This ise third line.", tv.Text);
  3212. Assert.Equal (3, tv.Lines);
  3213. Assert.Equal (new Point (7, 2), tv.CursorPosition);
  3214. }
  3215. [Fact]
  3216. [AutoInitShutdown]
  3217. public void HistoryText_Undo_Redo_Multi_Line_Selected_InsertText ()
  3218. {
  3219. var text = $"This is the first line.{Environment.NewLine}This is the second line.\nThis is the third line.";
  3220. var tv = new TextView () {
  3221. Width = 10,
  3222. Height = 2,
  3223. Text = text
  3224. };
  3225. var top = Application.Top;
  3226. top.Add (tv);
  3227. Application.Begin (top);
  3228. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  3229. Assert.Equal (3, tv.Lines);
  3230. Assert.Equal (Point.Empty, tv.CursorPosition);
  3231. var messy = " messy";
  3232. tv.CursorPosition = new Point (7, 0);
  3233. tv.SelectionStartColumn = 11;
  3234. tv.SelectionStartRow = 2;
  3235. Assert.Equal (51 + Environment.NewLine.Length * 2, tv.SelectedLength);
  3236. for (int i = 0; i < messy.Length; i++) {
  3237. tv.InsertText (messy [i].ToString ());
  3238. switch (i) {
  3239. case 0:
  3240. Assert.Equal ("This is third line.", tv.Text);
  3241. Assert.Equal (new Point (8, 0), tv.CursorPosition);
  3242. break;
  3243. case 1:
  3244. Assert.Equal ("This is m third line.", tv.Text);
  3245. Assert.Equal (new Point (9, 0), tv.CursorPosition);
  3246. break;
  3247. case 2:
  3248. Assert.Equal ("This is me third line.", tv.Text);
  3249. Assert.Equal (new Point (10, 0), tv.CursorPosition);
  3250. break;
  3251. case 3:
  3252. Assert.Equal ("This is mes third line.", tv.Text);
  3253. Assert.Equal (new Point (11, 0), tv.CursorPosition);
  3254. break;
  3255. case 4:
  3256. Assert.Equal ("This is mess third line.", tv.Text);
  3257. Assert.Equal (new Point (12, 0), tv.CursorPosition);
  3258. break;
  3259. case 5:
  3260. Assert.Equal ("This is messy third line.", tv.Text);
  3261. Assert.Equal (new Point (13, 0), tv.CursorPosition);
  3262. break;
  3263. }
  3264. }
  3265. Assert.Equal ($"This is messy third line.", tv.Text);
  3266. Assert.Equal (1, tv.Lines);
  3267. Assert.Equal (new Point (13, 0), tv.CursorPosition);
  3268. Assert.Equal (11, tv.SelectionStartColumn);
  3269. Assert.Equal (2, tv.SelectionStartRow);
  3270. Assert.Equal (0, tv.SelectedLength);
  3271. for (int i = 0; i < messy.Length; i++) {
  3272. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  3273. switch (i) {
  3274. case 0:
  3275. Assert.Equal ("This is mess third line.", tv.Text);
  3276. Assert.Equal (new Point (12, 0), tv.CursorPosition);
  3277. break;
  3278. case 1:
  3279. Assert.Equal ("This is mes third line.", tv.Text);
  3280. Assert.Equal (new Point (11, 0), tv.CursorPosition);
  3281. break;
  3282. case 2:
  3283. Assert.Equal ("This is me third line.", tv.Text);
  3284. Assert.Equal (new Point (10, 0), tv.CursorPosition);
  3285. break;
  3286. case 3:
  3287. Assert.Equal ("This is m third line.", tv.Text);
  3288. Assert.Equal (new Point (9, 0), tv.CursorPosition);
  3289. break;
  3290. case 4:
  3291. Assert.Equal ("This is third line.", tv.Text);
  3292. Assert.Equal (new Point (8, 0), tv.CursorPosition);
  3293. break;
  3294. case 5:
  3295. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  3296. Assert.Equal (new Point (7, 0), tv.CursorPosition);
  3297. break;
  3298. }
  3299. }
  3300. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  3301. Assert.Equal (3, tv.Lines);
  3302. Assert.Equal (new Point (7, 0), tv.CursorPosition);
  3303. Assert.Equal (11, tv.SelectionStartColumn);
  3304. Assert.Equal (2, tv.SelectionStartRow);
  3305. Assert.Equal (0, tv.SelectedLength);
  3306. for (int i = 0; i < messy.Length; i++) {
  3307. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  3308. switch (i) {
  3309. case 0:
  3310. Assert.Equal ("This is third line.", tv.Text);
  3311. Assert.Equal (new Point (8, 0), tv.CursorPosition);
  3312. break;
  3313. case 1:
  3314. Assert.Equal ("This is m third line.", tv.Text);
  3315. Assert.Equal (new Point (9, 0), tv.CursorPosition);
  3316. break;
  3317. case 2:
  3318. Assert.Equal ("This is me third line.", tv.Text);
  3319. Assert.Equal (new Point (10, 0), tv.CursorPosition);
  3320. break;
  3321. case 3:
  3322. Assert.Equal ("This is mes third line.", tv.Text);
  3323. Assert.Equal (new Point (11, 0), tv.CursorPosition);
  3324. break;
  3325. case 4:
  3326. Assert.Equal ("This is mess third line.", tv.Text);
  3327. Assert.Equal (new Point (12, 0), tv.CursorPosition);
  3328. break;
  3329. case 5:
  3330. Assert.Equal ("This is messy third line.", tv.Text);
  3331. Assert.Equal (new Point (13, 0), tv.CursorPosition);
  3332. break;
  3333. }
  3334. }
  3335. Assert.Equal ("This is messy third line.", tv.Text);
  3336. Assert.Equal (1, tv.Lines);
  3337. Assert.Equal (new Point (13, 0), tv.CursorPosition);
  3338. Assert.Equal (11, tv.SelectionStartColumn);
  3339. Assert.Equal (2, tv.SelectionStartRow);
  3340. Assert.Equal (0, tv.SelectedLength);
  3341. }
  3342. [Fact]
  3343. [AutoInitShutdown]
  3344. public void HistoryText_Undo_Redo_Multi_Line_With_Empty_Text ()
  3345. {
  3346. var tv = new TextView () {
  3347. Width = 10,
  3348. Height = 2
  3349. };
  3350. var top = Application.Top;
  3351. top.Add (tv);
  3352. Application.Begin (top);
  3353. Assert.Equal ("", tv.Text);
  3354. Assert.Equal (1, tv.Lines);
  3355. Assert.Equal (Point.Empty, tv.CursorPosition);
  3356. Assert.False (tv.IsDirty);
  3357. Assert.True (tv.ProcessKey (new KeyEvent (Key.O, new KeyModifiers ())));
  3358. Assert.Equal ("O", tv.Text);
  3359. Assert.Equal (1, tv.Lines);
  3360. Assert.Equal (new Point (1, 0), tv.CursorPosition);
  3361. Assert.True (tv.IsDirty);
  3362. Assert.True (tv.ProcessKey (new KeyEvent (Key.n, new KeyModifiers ())));
  3363. Assert.Equal ("On", tv.Text);
  3364. Assert.Equal (1, tv.Lines);
  3365. Assert.Equal (new Point (2, 0), tv.CursorPosition);
  3366. Assert.True (tv.IsDirty);
  3367. Assert.True (tv.ProcessKey (new KeyEvent (Key.e, new KeyModifiers ())));
  3368. Assert.Equal ("One", tv.Text);
  3369. Assert.Equal (1, tv.Lines);
  3370. Assert.Equal (new Point (3, 0), tv.CursorPosition);
  3371. Assert.True (tv.IsDirty);
  3372. Assert.True (tv.ProcessKey (new KeyEvent (Key.Enter, new KeyModifiers ())));
  3373. Assert.Equal ($"One{Environment.NewLine}", tv.Text);
  3374. Assert.Equal (2, tv.Lines);
  3375. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  3376. Assert.True (tv.IsDirty);
  3377. Assert.True (tv.ProcessKey (new KeyEvent (Key.T, new KeyModifiers ())));
  3378. Assert.Equal ($"One{Environment.NewLine}T", tv.Text);
  3379. Assert.Equal (2, tv.Lines);
  3380. Assert.Equal (new Point (1, 1), tv.CursorPosition);
  3381. Assert.True (tv.IsDirty);
  3382. Assert.True (tv.ProcessKey (new KeyEvent (Key.w, new KeyModifiers ())));
  3383. Assert.Equal ($"One{Environment.NewLine}Tw", tv.Text);
  3384. Assert.Equal (2, tv.Lines);
  3385. Assert.Equal (new Point (2, 1), tv.CursorPosition);
  3386. Assert.True (tv.IsDirty);
  3387. Assert.True (tv.ProcessKey (new KeyEvent (Key.o, new KeyModifiers ())));
  3388. Assert.Equal ($"One{Environment.NewLine}Two", tv.Text);
  3389. Assert.Equal (2, tv.Lines);
  3390. Assert.Equal (new Point (3, 1), tv.CursorPosition);
  3391. Assert.True (tv.IsDirty);
  3392. Assert.True (tv.ProcessKey (new KeyEvent (Key.Enter, new KeyModifiers ())));
  3393. Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}", tv.Text);
  3394. Assert.Equal (3, tv.Lines);
  3395. Assert.Equal (new Point (0, 2), tv.CursorPosition);
  3396. Assert.True (tv.IsDirty);
  3397. Assert.True (tv.ProcessKey (new KeyEvent (Key.T, new KeyModifiers ())));
  3398. Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}T", tv.Text);
  3399. Assert.Equal (3, tv.Lines);
  3400. Assert.Equal (new Point (1, 2), tv.CursorPosition);
  3401. Assert.True (tv.IsDirty);
  3402. Assert.True (tv.ProcessKey (new KeyEvent (Key.h, new KeyModifiers ())));
  3403. Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}Th", tv.Text);
  3404. Assert.Equal (3, tv.Lines);
  3405. Assert.Equal (new Point (2, 2), tv.CursorPosition);
  3406. Assert.True (tv.IsDirty);
  3407. Assert.True (tv.ProcessKey (new KeyEvent (Key.r, new KeyModifiers ())));
  3408. Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}Thr", tv.Text);
  3409. Assert.Equal (3, tv.Lines);
  3410. Assert.Equal (new Point (3, 2), tv.CursorPosition);
  3411. Assert.True (tv.IsDirty);
  3412. Assert.True (tv.ProcessKey (new KeyEvent (Key.e, new KeyModifiers ())));
  3413. Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}Thre", tv.Text);
  3414. Assert.Equal (3, tv.Lines);
  3415. Assert.Equal (new Point (4, 2), tv.CursorPosition);
  3416. Assert.True (tv.IsDirty);
  3417. Assert.True (tv.ProcessKey (new KeyEvent (Key.e, new KeyModifiers ())));
  3418. Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}Three", tv.Text);
  3419. Assert.Equal (3, tv.Lines);
  3420. Assert.Equal (new Point (5, 2), tv.CursorPosition);
  3421. Assert.True (tv.IsDirty);
  3422. Assert.True (tv.ProcessKey (new KeyEvent (Key.Enter, new KeyModifiers ())));
  3423. Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}Three{Environment.NewLine}", tv.Text);
  3424. Assert.Equal (4, tv.Lines);
  3425. Assert.Equal (new Point (0, 3), tv.CursorPosition);
  3426. Assert.True (tv.IsDirty);
  3427. // Undoing
  3428. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  3429. Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}Three", tv.Text);
  3430. Assert.Equal (3, tv.Lines);
  3431. Assert.Equal (new Point (5, 2), tv.CursorPosition);
  3432. Assert.True (tv.IsDirty);
  3433. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  3434. Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}Thre", tv.Text);
  3435. Assert.Equal (3, tv.Lines);
  3436. Assert.Equal (new Point (4, 2), tv.CursorPosition);
  3437. Assert.True (tv.IsDirty);
  3438. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  3439. Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}Thr", tv.Text);
  3440. Assert.Equal (3, tv.Lines);
  3441. Assert.Equal (new Point (3, 2), tv.CursorPosition);
  3442. Assert.True (tv.IsDirty);
  3443. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  3444. Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}Th", tv.Text);
  3445. Assert.Equal (3, tv.Lines);
  3446. Assert.Equal (new Point (2, 2), tv.CursorPosition);
  3447. Assert.True (tv.IsDirty);
  3448. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  3449. Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}T", tv.Text);
  3450. Assert.Equal (3, tv.Lines);
  3451. Assert.Equal (new Point (1, 2), tv.CursorPosition);
  3452. Assert.True (tv.IsDirty);
  3453. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  3454. Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}", tv.Text);
  3455. Assert.Equal (3, tv.Lines);
  3456. Assert.Equal (new Point (0, 2), tv.CursorPosition);
  3457. Assert.True (tv.IsDirty);
  3458. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  3459. Assert.Equal ($"One{Environment.NewLine}Two", tv.Text);
  3460. Assert.Equal (2, tv.Lines);
  3461. Assert.Equal (new Point (3, 1), tv.CursorPosition);
  3462. Assert.True (tv.IsDirty);
  3463. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  3464. Assert.Equal ($"One{Environment.NewLine}Tw", tv.Text);
  3465. Assert.Equal (2, tv.Lines);
  3466. Assert.Equal (new Point (2, 1), tv.CursorPosition);
  3467. Assert.True (tv.IsDirty);
  3468. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  3469. Assert.Equal ($"One{Environment.NewLine}T", tv.Text);
  3470. Assert.Equal (2, tv.Lines);
  3471. Assert.Equal (new Point (1, 1), tv.CursorPosition);
  3472. Assert.True (tv.IsDirty);
  3473. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  3474. Assert.Equal ($"One{Environment.NewLine}", tv.Text);
  3475. Assert.Equal (2, tv.Lines);
  3476. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  3477. Assert.True (tv.IsDirty);
  3478. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  3479. Assert.Equal ($"One", tv.Text);
  3480. Assert.Equal (1, tv.Lines);
  3481. Assert.Equal (new Point (3, 0), tv.CursorPosition);
  3482. Assert.True (tv.IsDirty);
  3483. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  3484. Assert.Equal ($"On", tv.Text);
  3485. Assert.Equal (1, tv.Lines);
  3486. Assert.Equal (new Point (2, 0), tv.CursorPosition);
  3487. Assert.True (tv.IsDirty);
  3488. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  3489. Assert.Equal ($"O", tv.Text);
  3490. Assert.Equal (1, tv.Lines);
  3491. Assert.Equal (new Point (1, 0), tv.CursorPosition);
  3492. Assert.True (tv.IsDirty);
  3493. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  3494. Assert.Equal ($"", tv.Text);
  3495. Assert.Equal (1, tv.Lines);
  3496. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  3497. Assert.False (tv.IsDirty);
  3498. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  3499. Assert.Equal ($"", tv.Text);
  3500. Assert.Equal (1, tv.Lines);
  3501. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  3502. Assert.False (tv.IsDirty);
  3503. // Redoing
  3504. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  3505. Assert.Equal ($"O", tv.Text);
  3506. Assert.Equal (1, tv.Lines);
  3507. Assert.Equal (new Point (1, 0), tv.CursorPosition);
  3508. Assert.True (tv.IsDirty);
  3509. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  3510. Assert.Equal ($"On", tv.Text);
  3511. Assert.Equal (1, tv.Lines);
  3512. Assert.Equal (new Point (2, 0), tv.CursorPosition);
  3513. Assert.True (tv.IsDirty);
  3514. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  3515. Assert.Equal ($"One", tv.Text);
  3516. Assert.Equal (1, tv.Lines);
  3517. Assert.Equal (new Point (3, 0), tv.CursorPosition);
  3518. Assert.True (tv.IsDirty);
  3519. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  3520. Assert.Equal ($"One{Environment.NewLine}", tv.Text);
  3521. Assert.Equal (2, tv.Lines);
  3522. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  3523. Assert.True (tv.IsDirty);
  3524. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  3525. Assert.Equal ($"One{Environment.NewLine}T", tv.Text);
  3526. Assert.Equal (2, tv.Lines);
  3527. Assert.Equal (new Point (1, 1), tv.CursorPosition);
  3528. Assert.True (tv.IsDirty);
  3529. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  3530. Assert.Equal ($"One{Environment.NewLine}Tw", tv.Text);
  3531. Assert.Equal (2, tv.Lines);
  3532. Assert.Equal (new Point (2, 1), tv.CursorPosition);
  3533. Assert.True (tv.IsDirty);
  3534. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  3535. Assert.Equal ($"One{Environment.NewLine}Two", tv.Text);
  3536. Assert.Equal (2, tv.Lines);
  3537. Assert.Equal (new Point (3, 1), tv.CursorPosition);
  3538. Assert.True (tv.IsDirty);
  3539. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  3540. Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}", tv.Text);
  3541. Assert.Equal (3, tv.Lines);
  3542. Assert.Equal (new Point (0, 2), tv.CursorPosition);
  3543. Assert.True (tv.IsDirty);
  3544. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  3545. Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}T", tv.Text);
  3546. Assert.Equal (3, tv.Lines);
  3547. Assert.Equal (new Point (1, 2), tv.CursorPosition);
  3548. Assert.True (tv.IsDirty);
  3549. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  3550. Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}Th", tv.Text);
  3551. Assert.Equal (3, tv.Lines);
  3552. Assert.Equal (new Point (2, 2), tv.CursorPosition);
  3553. Assert.True (tv.IsDirty);
  3554. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  3555. Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}Thr", tv.Text);
  3556. Assert.Equal (3, tv.Lines);
  3557. Assert.Equal (new Point (3, 2), tv.CursorPosition);
  3558. Assert.True (tv.IsDirty);
  3559. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  3560. Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}Thre", tv.Text);
  3561. Assert.Equal (3, tv.Lines);
  3562. Assert.Equal (new Point (4, 2), tv.CursorPosition);
  3563. Assert.True (tv.IsDirty);
  3564. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  3565. Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}Three", tv.Text);
  3566. Assert.Equal (3, tv.Lines);
  3567. Assert.Equal (new Point (5, 2), tv.CursorPosition);
  3568. Assert.True (tv.IsDirty);
  3569. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  3570. Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}Three{Environment.NewLine}", tv.Text);
  3571. Assert.Equal (4, tv.Lines);
  3572. Assert.Equal (new Point (0, 3), tv.CursorPosition);
  3573. Assert.True (tv.IsDirty);
  3574. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  3575. Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}Three{Environment.NewLine}", tv.Text);
  3576. Assert.Equal (4, tv.Lines);
  3577. Assert.Equal (new Point (0, 3), tv.CursorPosition);
  3578. Assert.True (tv.IsDirty);
  3579. }
  3580. [Fact]
  3581. [AutoInitShutdown]
  3582. public void HistoryText_Undo_Redo_Multi_Line_Selected_With_Empty_Text ()
  3583. {
  3584. var tv = new TextView () {
  3585. Width = 10,
  3586. Height = 2
  3587. };
  3588. var top = Application.Top;
  3589. top.Add (tv);
  3590. Application.Begin (top);
  3591. Assert.Equal ("", tv.Text);
  3592. Assert.Equal (1, tv.Lines);
  3593. Assert.Equal (Point.Empty, tv.CursorPosition);
  3594. Assert.False (tv.IsDirty);
  3595. Assert.True (tv.ProcessKey (new KeyEvent (Key.O, new KeyModifiers ())));
  3596. Assert.Equal ("O", tv.Text);
  3597. Assert.Equal (1, tv.Lines);
  3598. Assert.Equal (new Point (1, 0), tv.CursorPosition);
  3599. Assert.True (tv.IsDirty);
  3600. Assert.True (tv.ProcessKey (new KeyEvent (Key.n, new KeyModifiers ())));
  3601. Assert.Equal ("On", tv.Text);
  3602. Assert.Equal (1, tv.Lines);
  3603. Assert.Equal (new Point (2, 0), tv.CursorPosition);
  3604. Assert.True (tv.IsDirty);
  3605. Assert.True (tv.ProcessKey (new KeyEvent (Key.e, new KeyModifiers ())));
  3606. Assert.Equal ("One", tv.Text);
  3607. Assert.Equal (1, tv.Lines);
  3608. Assert.Equal (new Point (3, 0), tv.CursorPosition);
  3609. Assert.True (tv.IsDirty);
  3610. Assert.True (tv.ProcessKey (new KeyEvent (Key.Enter, new KeyModifiers ())));
  3611. Assert.Equal ($"One{Environment.NewLine}", tv.Text);
  3612. Assert.Equal (2, tv.Lines);
  3613. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  3614. Assert.True (tv.IsDirty);
  3615. Assert.True (tv.ProcessKey (new KeyEvent (Key.T, new KeyModifiers ())));
  3616. Assert.Equal ($"One{Environment.NewLine}T", tv.Text);
  3617. Assert.Equal (2, tv.Lines);
  3618. Assert.Equal (new Point (1, 1), tv.CursorPosition);
  3619. Assert.True (tv.IsDirty);
  3620. Assert.True (tv.ProcessKey (new KeyEvent (Key.w, new KeyModifiers ())));
  3621. Assert.Equal ($"One{Environment.NewLine}Tw", tv.Text);
  3622. Assert.Equal (2, tv.Lines);
  3623. Assert.Equal (new Point (2, 1), tv.CursorPosition);
  3624. Assert.True (tv.IsDirty);
  3625. Assert.True (tv.ProcessKey (new KeyEvent (Key.o, new KeyModifiers ())));
  3626. Assert.Equal ($"One{Environment.NewLine}Two", tv.Text);
  3627. Assert.Equal (2, tv.Lines);
  3628. Assert.Equal (new Point (3, 1), tv.CursorPosition);
  3629. Assert.True (tv.IsDirty);
  3630. Assert.True (tv.ProcessKey (new KeyEvent (Key.Enter, new KeyModifiers ())));
  3631. Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}", tv.Text);
  3632. Assert.Equal (3, tv.Lines);
  3633. Assert.Equal (new Point (0, 2), tv.CursorPosition);
  3634. Assert.True (tv.IsDirty);
  3635. Assert.True (tv.ProcessKey (new KeyEvent (Key.T, new KeyModifiers ())));
  3636. Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}T", tv.Text);
  3637. Assert.Equal (3, tv.Lines);
  3638. Assert.Equal (new Point (1, 2), tv.CursorPosition);
  3639. Assert.True (tv.IsDirty);
  3640. Assert.True (tv.ProcessKey (new KeyEvent (Key.h, new KeyModifiers ())));
  3641. Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}Th", tv.Text);
  3642. Assert.Equal (3, tv.Lines);
  3643. Assert.Equal (new Point (2, 2), tv.CursorPosition);
  3644. Assert.True (tv.IsDirty);
  3645. Assert.True (tv.ProcessKey (new KeyEvent (Key.r, new KeyModifiers ())));
  3646. Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}Thr", tv.Text);
  3647. Assert.Equal (3, tv.Lines);
  3648. Assert.Equal (new Point (3, 2), tv.CursorPosition);
  3649. Assert.True (tv.IsDirty);
  3650. Assert.True (tv.ProcessKey (new KeyEvent (Key.e, new KeyModifiers ())));
  3651. Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}Thre", tv.Text);
  3652. Assert.Equal (3, tv.Lines);
  3653. Assert.Equal (new Point (4, 2), tv.CursorPosition);
  3654. Assert.True (tv.IsDirty);
  3655. Assert.True (tv.ProcessKey (new KeyEvent (Key.e, new KeyModifiers ())));
  3656. Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}Three", tv.Text);
  3657. Assert.Equal (3, tv.Lines);
  3658. Assert.Equal (new Point (5, 2), tv.CursorPosition);
  3659. Assert.True (tv.IsDirty);
  3660. Assert.True (tv.ProcessKey (new KeyEvent (Key.Enter, new KeyModifiers ())));
  3661. Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}Three{Environment.NewLine}", tv.Text);
  3662. Assert.Equal (4, tv.Lines);
  3663. Assert.Equal (new Point (0, 3), tv.CursorPosition);
  3664. Assert.True (tv.IsDirty);
  3665. tv.SelectionStartColumn = 0;
  3666. tv.SelectionStartRow = 0;
  3667. tv.CursorPosition = new Point (0, 1);
  3668. Assert.Equal (3 + Environment.NewLine.Length, tv.SelectedLength);
  3669. Assert.True (tv.ProcessKey (new KeyEvent (Key.D1, new KeyModifiers ())));
  3670. Assert.Equal ($"1Two{Environment.NewLine}Three{Environment.NewLine}", tv.Text);
  3671. Assert.Equal (3, tv.Lines);
  3672. Assert.Equal (new Point (1, 0), tv.CursorPosition);
  3673. Assert.Equal (0, tv.SelectedLength);
  3674. Assert.True (tv.IsDirty);
  3675. tv.SelectionStartColumn = 1;
  3676. tv.SelectionStartRow = 0;
  3677. tv.CursorPosition = new Point (1, 1);
  3678. Assert.Equal (4 + Environment.NewLine.Length, tv.SelectedLength);
  3679. Assert.True (tv.ProcessKey (new KeyEvent (Key.D2, new KeyModifiers ())));
  3680. Assert.Equal ($"12hree{Environment.NewLine}", tv.Text);
  3681. Assert.Equal (2, tv.Lines);
  3682. Assert.Equal (new Point (2, 0), tv.CursorPosition);
  3683. Assert.Equal (0, tv.SelectedLength);
  3684. Assert.True (tv.IsDirty);
  3685. // Undoing
  3686. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  3687. Assert.Equal ($"1Two{Environment.NewLine}Three{Environment.NewLine}", tv.Text);
  3688. Assert.Equal (3, tv.Lines);
  3689. Assert.Equal (new Point (1, 1), tv.CursorPosition);
  3690. Assert.Equal (0, tv.SelectedLength);
  3691. Assert.True (tv.IsDirty);
  3692. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  3693. Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}Three{Environment.NewLine}", tv.Text);
  3694. Assert.Equal (4, tv.Lines);
  3695. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  3696. Assert.Equal (0, tv.SelectedLength);
  3697. Assert.True (tv.IsDirty);
  3698. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  3699. Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}Three", tv.Text);
  3700. Assert.Equal (3, tv.Lines);
  3701. Assert.Equal (new Point (5, 2), tv.CursorPosition);
  3702. Assert.Equal (0, tv.SelectedLength);
  3703. Assert.True (tv.IsDirty);
  3704. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  3705. Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}Thre", tv.Text);
  3706. Assert.Equal (3, tv.Lines);
  3707. Assert.Equal (new Point (4, 2), tv.CursorPosition);
  3708. Assert.True (tv.IsDirty);
  3709. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  3710. Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}Thr", tv.Text);
  3711. Assert.Equal (3, tv.Lines);
  3712. Assert.Equal (new Point (3, 2), tv.CursorPosition);
  3713. Assert.Equal (0, tv.SelectedLength);
  3714. Assert.True (tv.IsDirty);
  3715. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  3716. Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}Th", tv.Text);
  3717. Assert.Equal (3, tv.Lines);
  3718. Assert.Equal (new Point (2, 2), tv.CursorPosition);
  3719. Assert.Equal (0, tv.SelectedLength);
  3720. Assert.True (tv.IsDirty);
  3721. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  3722. Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}T", tv.Text);
  3723. Assert.Equal (3, tv.Lines);
  3724. Assert.Equal (new Point (1, 2), tv.CursorPosition);
  3725. Assert.Equal (0, tv.SelectedLength);
  3726. Assert.True (tv.IsDirty);
  3727. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  3728. Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}", tv.Text);
  3729. Assert.Equal (3, tv.Lines);
  3730. Assert.Equal (new Point (0, 2), tv.CursorPosition);
  3731. Assert.Equal (0, tv.SelectedLength);
  3732. Assert.True (tv.IsDirty);
  3733. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  3734. Assert.Equal ($"One{Environment.NewLine}Two", tv.Text);
  3735. Assert.Equal (2, tv.Lines);
  3736. Assert.Equal (new Point (3, 1), tv.CursorPosition);
  3737. Assert.Equal (0, tv.SelectedLength);
  3738. Assert.True (tv.IsDirty);
  3739. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  3740. Assert.Equal ($"One{Environment.NewLine}Tw", tv.Text);
  3741. Assert.Equal (2, tv.Lines);
  3742. Assert.Equal (new Point (2, 1), tv.CursorPosition);
  3743. Assert.Equal (0, tv.SelectedLength);
  3744. Assert.True (tv.IsDirty);
  3745. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  3746. Assert.Equal ($"One{Environment.NewLine}T", tv.Text);
  3747. Assert.Equal (2, tv.Lines);
  3748. Assert.Equal (new Point (1, 1), tv.CursorPosition);
  3749. Assert.Equal (0, tv.SelectedLength);
  3750. Assert.True (tv.IsDirty);
  3751. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  3752. Assert.Equal ($"One{Environment.NewLine}", tv.Text);
  3753. Assert.Equal (2, tv.Lines);
  3754. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  3755. Assert.Equal (0, tv.SelectedLength);
  3756. Assert.True (tv.IsDirty);
  3757. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  3758. Assert.Equal ($"One", tv.Text);
  3759. Assert.Equal (1, tv.Lines);
  3760. Assert.Equal (new Point (3, 0), tv.CursorPosition);
  3761. Assert.Equal (0, tv.SelectedLength);
  3762. Assert.True (tv.IsDirty);
  3763. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  3764. Assert.Equal ($"On", tv.Text);
  3765. Assert.Equal (1, tv.Lines);
  3766. Assert.Equal (new Point (2, 0), tv.CursorPosition);
  3767. Assert.Equal (0, tv.SelectedLength);
  3768. Assert.True (tv.IsDirty);
  3769. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  3770. Assert.Equal ($"O", tv.Text);
  3771. Assert.Equal (1, tv.Lines);
  3772. Assert.Equal (new Point (1, 0), tv.CursorPosition);
  3773. Assert.Equal (0, tv.SelectedLength);
  3774. Assert.True (tv.IsDirty);
  3775. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  3776. Assert.Equal ($"", tv.Text);
  3777. Assert.Equal (1, tv.Lines);
  3778. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  3779. Assert.Equal (0, tv.SelectedLength);
  3780. Assert.False (tv.IsDirty);
  3781. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  3782. Assert.Equal ($"", tv.Text);
  3783. Assert.Equal (1, tv.Lines);
  3784. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  3785. Assert.Equal (0, tv.SelectedLength);
  3786. Assert.False (tv.IsDirty);
  3787. // Redoing
  3788. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  3789. Assert.Equal ($"O", tv.Text);
  3790. Assert.Equal (1, tv.Lines);
  3791. Assert.Equal (new Point (1, 0), tv.CursorPosition);
  3792. Assert.Equal (0, tv.SelectedLength);
  3793. Assert.True (tv.IsDirty);
  3794. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  3795. Assert.Equal ($"On", tv.Text);
  3796. Assert.Equal (1, tv.Lines);
  3797. Assert.Equal (new Point (2, 0), tv.CursorPosition);
  3798. Assert.Equal (0, tv.SelectedLength);
  3799. Assert.True (tv.IsDirty);
  3800. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  3801. Assert.Equal ($"One", tv.Text);
  3802. Assert.Equal (1, tv.Lines);
  3803. Assert.Equal (new Point (3, 0), tv.CursorPosition);
  3804. Assert.Equal (0, tv.SelectedLength);
  3805. Assert.True (tv.IsDirty);
  3806. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  3807. Assert.Equal ($"One{Environment.NewLine}", tv.Text);
  3808. Assert.Equal (2, tv.Lines);
  3809. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  3810. Assert.Equal (0, tv.SelectedLength);
  3811. Assert.True (tv.IsDirty);
  3812. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  3813. Assert.Equal ($"One{Environment.NewLine}T", tv.Text);
  3814. Assert.Equal (2, tv.Lines);
  3815. Assert.Equal (new Point (1, 1), tv.CursorPosition);
  3816. Assert.Equal (0, tv.SelectedLength);
  3817. Assert.True (tv.IsDirty);
  3818. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  3819. Assert.Equal ($"One{Environment.NewLine}Tw", tv.Text);
  3820. Assert.Equal (2, tv.Lines);
  3821. Assert.Equal (new Point (2, 1), tv.CursorPosition);
  3822. Assert.Equal (0, tv.SelectedLength);
  3823. Assert.True (tv.IsDirty);
  3824. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  3825. Assert.Equal ($"One{Environment.NewLine}Two", tv.Text);
  3826. Assert.Equal (2, tv.Lines);
  3827. Assert.Equal (new Point (3, 1), tv.CursorPosition);
  3828. Assert.Equal (0, tv.SelectedLength);
  3829. Assert.True (tv.IsDirty);
  3830. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  3831. Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}", tv.Text);
  3832. Assert.Equal (3, tv.Lines);
  3833. Assert.Equal (new Point (0, 2), tv.CursorPosition);
  3834. Assert.Equal (0, tv.SelectedLength);
  3835. Assert.True (tv.IsDirty);
  3836. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  3837. Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}T", tv.Text);
  3838. Assert.Equal (3, tv.Lines);
  3839. Assert.Equal (new Point (1, 2), tv.CursorPosition);
  3840. Assert.Equal (0, tv.SelectedLength);
  3841. Assert.True (tv.IsDirty);
  3842. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  3843. Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}Th", tv.Text);
  3844. Assert.Equal (3, tv.Lines);
  3845. Assert.Equal (new Point (2, 2), tv.CursorPosition);
  3846. Assert.Equal (0, tv.SelectedLength);
  3847. Assert.True (tv.IsDirty);
  3848. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  3849. Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}Thr", tv.Text);
  3850. Assert.Equal (3, tv.Lines);
  3851. Assert.Equal (new Point (3, 2), tv.CursorPosition);
  3852. Assert.Equal (0, tv.SelectedLength);
  3853. Assert.True (tv.IsDirty);
  3854. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  3855. Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}Thre", tv.Text);
  3856. Assert.Equal (3, tv.Lines);
  3857. Assert.Equal (new Point (4, 2), tv.CursorPosition);
  3858. Assert.Equal (0, tv.SelectedLength);
  3859. Assert.True (tv.IsDirty);
  3860. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  3861. Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}Three", tv.Text);
  3862. Assert.Equal (3, tv.Lines);
  3863. Assert.Equal (new Point (5, 2), tv.CursorPosition);
  3864. Assert.Equal (0, tv.SelectedLength);
  3865. Assert.True (tv.IsDirty);
  3866. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  3867. Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}Three{Environment.NewLine}", tv.Text);
  3868. Assert.Equal (4, tv.Lines);
  3869. Assert.Equal (new Point (0, 3), tv.CursorPosition);
  3870. Assert.Equal (0, tv.SelectedLength);
  3871. Assert.True (tv.IsDirty);
  3872. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  3873. Assert.Equal ($"1Two{Environment.NewLine}Three{Environment.NewLine}", tv.Text);
  3874. Assert.Equal (3, tv.Lines);
  3875. Assert.Equal (new Point (1, 0), tv.CursorPosition);
  3876. Assert.Equal (0, tv.SelectedLength);
  3877. Assert.True (tv.IsDirty);
  3878. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  3879. Assert.Equal ($"12hree{Environment.NewLine}", tv.Text);
  3880. Assert.Equal (2, tv.Lines);
  3881. Assert.Equal (new Point (2, 0), tv.CursorPosition);
  3882. Assert.Equal (0, tv.SelectedLength);
  3883. Assert.True (tv.IsDirty);
  3884. }
  3885. [Fact]
  3886. [AutoInitShutdown]
  3887. public void HistoryText_Undo_Redo_Multi_Line_Selected_InsertText_Twice_On_Same_Line ()
  3888. {
  3889. var text = "One\nTwo\nThree";
  3890. var tv = new TextView () {
  3891. Width = 10,
  3892. Height = 2,
  3893. Text = text
  3894. };
  3895. var top = Application.Top;
  3896. top.Add (tv);
  3897. Application.Begin (top);
  3898. Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}Three", tv.Text);
  3899. Assert.Equal (3, tv.Lines);
  3900. Assert.Equal (Point.Empty, tv.CursorPosition);
  3901. Assert.False (tv.IsDirty);
  3902. tv.SelectionStartColumn = 0;
  3903. tv.SelectionStartRow = 0;
  3904. tv.CursorPosition = new Point (0, 1);
  3905. Assert.Equal (3 + Environment.NewLine.Length, tv.SelectedLength);
  3906. Assert.True (tv.ProcessKey (new KeyEvent (Key.D1, new KeyModifiers ())));
  3907. Assert.Equal ($"1Two{Environment.NewLine}Three", tv.Text);
  3908. Assert.Equal (new Point (1, 0), tv.CursorPosition);
  3909. Assert.Equal (0, tv.SelectedLength);
  3910. Assert.True (tv.IsDirty);
  3911. tv.SelectionStartColumn = 1;
  3912. tv.SelectionStartRow = 0;
  3913. tv.CursorPosition = new Point (1, 1);
  3914. Assert.Equal (4 + Environment.NewLine.Length, tv.SelectedLength);
  3915. Assert.True (tv.ProcessKey (new KeyEvent (Key.D2, new KeyModifiers ())));
  3916. Assert.Equal ("12hree", tv.Text);
  3917. Assert.Equal (new Point (2, 0), tv.CursorPosition);
  3918. Assert.Equal (0, tv.SelectedLength);
  3919. Assert.True (tv.IsDirty);
  3920. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  3921. Assert.Equal ($"1Two{Environment.NewLine}Three", tv.Text);
  3922. Assert.Equal (new Point (1, 1), tv.CursorPosition);
  3923. Assert.Equal (0, tv.SelectedLength);
  3924. Assert.True (tv.IsDirty);
  3925. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  3926. Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}Three", tv.Text);
  3927. Assert.Equal (3, tv.Lines);
  3928. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  3929. Assert.Equal (0, tv.SelectedLength);
  3930. Assert.False (tv.IsDirty);
  3931. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  3932. Assert.Equal ($"1Two{Environment.NewLine}Three", tv.Text);
  3933. Assert.Equal (new Point (1, 0), tv.CursorPosition);
  3934. Assert.Equal (0, tv.SelectedLength);
  3935. Assert.True (tv.IsDirty);
  3936. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  3937. Assert.Equal ("12hree", tv.Text);
  3938. Assert.Equal (new Point (2, 0), tv.CursorPosition);
  3939. Assert.Equal (0, tv.SelectedLength);
  3940. Assert.True (tv.IsDirty);
  3941. }
  3942. [Fact]
  3943. [AutoInitShutdown]
  3944. public void HistoryText_Undo_Redo_Multi_Line_Selected_InsertText_Twice_On_Same_Line_With_End_Line ()
  3945. {
  3946. var text = "One\nTwo\nThree\n";
  3947. var tv = new TextView () {
  3948. Width = 10,
  3949. Height = 2,
  3950. Text = text
  3951. };
  3952. var top = Application.Top;
  3953. top.Add (tv);
  3954. Application.Begin (top);
  3955. Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}Three{Environment.NewLine}", tv.Text);
  3956. Assert.Equal (4, tv.Lines);
  3957. Assert.Equal (Point.Empty, tv.CursorPosition);
  3958. Assert.False (tv.IsDirty);
  3959. tv.SelectionStartColumn = 0;
  3960. tv.SelectionStartRow = 0;
  3961. tv.CursorPosition = new Point (0, 1);
  3962. Assert.Equal (3 + Environment.NewLine.Length, tv.SelectedLength);
  3963. Assert.True (tv.ProcessKey (new KeyEvent (Key.D1, new KeyModifiers ())));
  3964. Assert.Equal ($"1Two{Environment.NewLine}Three{Environment.NewLine}", tv.Text);
  3965. Assert.Equal (new Point (1, 0), tv.CursorPosition);
  3966. Assert.Equal (0, tv.SelectedLength);
  3967. Assert.True (tv.IsDirty);
  3968. tv.SelectionStartColumn = 1;
  3969. tv.SelectionStartRow = 0;
  3970. tv.CursorPosition = new Point (1, 1);
  3971. Assert.Equal (4 + Environment.NewLine.Length, tv.SelectedLength);
  3972. Assert.True (tv.ProcessKey (new KeyEvent (Key.D2, new KeyModifiers ())));
  3973. Assert.Equal ($"12hree{Environment.NewLine}", tv.Text);
  3974. Assert.Equal (new Point (2, 0), tv.CursorPosition);
  3975. Assert.Equal (0, tv.SelectedLength);
  3976. Assert.True (tv.IsDirty);
  3977. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  3978. Assert.Equal ($"1Two{Environment.NewLine}Three{Environment.NewLine}", tv.Text);
  3979. Assert.Equal (new Point (1, 1), tv.CursorPosition);
  3980. Assert.Equal (0, tv.SelectedLength);
  3981. Assert.True (tv.IsDirty);
  3982. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  3983. Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}Three{Environment.NewLine}", tv.Text);
  3984. Assert.Equal (4, tv.Lines);
  3985. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  3986. Assert.Equal (0, tv.SelectedLength);
  3987. Assert.False (tv.IsDirty);
  3988. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  3989. Assert.Equal ($"1Two{Environment.NewLine}Three{Environment.NewLine}", tv.Text);
  3990. Assert.Equal (new Point (1, 0), tv.CursorPosition);
  3991. Assert.Equal (0, tv.SelectedLength);
  3992. Assert.True (tv.IsDirty);
  3993. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  3994. Assert.Equal ($"12hree{Environment.NewLine}", tv.Text);
  3995. Assert.Equal (new Point (2, 0), tv.CursorPosition);
  3996. Assert.Equal (0, tv.SelectedLength);
  3997. Assert.True (tv.IsDirty);
  3998. }
  3999. [Fact]
  4000. public void HistoryText_IsDirty_HasHistoryChanges ()
  4001. {
  4002. var tv = new TextView ();
  4003. Assert.Equal ("", tv.Text);
  4004. Assert.Equal (1, tv.Lines);
  4005. Assert.Equal (Point.Empty, tv.CursorPosition);
  4006. Assert.False (tv.IsDirty);
  4007. Assert.False (tv.HasHistoryChanges);
  4008. Assert.True (tv.ProcessKey (new KeyEvent (Key.D1, new KeyModifiers ())));
  4009. Assert.Equal ("1", tv.Text);
  4010. Assert.Equal (1, tv.Lines);
  4011. Assert.Equal (new Point (1, 0), tv.CursorPosition);
  4012. Assert.True (tv.IsDirty);
  4013. Assert.True (tv.HasHistoryChanges);
  4014. Assert.True (tv.ProcessKey (new KeyEvent (Key.Enter, new KeyModifiers ())));
  4015. Assert.Equal ($"1{Environment.NewLine}", tv.Text);
  4016. Assert.Equal (2, tv.Lines);
  4017. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  4018. Assert.True (tv.IsDirty);
  4019. Assert.True (tv.HasHistoryChanges);
  4020. Assert.True (tv.ProcessKey (new KeyEvent (Key.D2, new KeyModifiers ())));
  4021. Assert.Equal ($"1{Environment.NewLine}2", tv.Text);
  4022. Assert.Equal (2, tv.Lines);
  4023. Assert.Equal (new Point (1, 1), tv.CursorPosition);
  4024. Assert.True (tv.IsDirty);
  4025. Assert.True (tv.HasHistoryChanges);
  4026. Assert.True (tv.ProcessKey (new KeyEvent (Key.Backspace, new KeyModifiers ())));
  4027. Assert.Equal ($"1{Environment.NewLine}", tv.Text);
  4028. Assert.Equal (2, tv.Lines);
  4029. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  4030. Assert.True (tv.IsDirty);
  4031. Assert.True (tv.HasHistoryChanges);
  4032. Assert.True (tv.ProcessKey (new KeyEvent (Key.Backspace, new KeyModifiers ())));
  4033. Assert.Equal ($"1", tv.Text);
  4034. Assert.Equal (1, tv.Lines);
  4035. Assert.Equal (new Point (1, 0), tv.CursorPosition);
  4036. Assert.True (tv.IsDirty);
  4037. Assert.True (tv.HasHistoryChanges);
  4038. Assert.True (tv.ProcessKey (new KeyEvent (Key.Backspace, new KeyModifiers ())));
  4039. Assert.Equal ($"", tv.Text);
  4040. Assert.Equal (1, tv.Lines);
  4041. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  4042. // IsDirty cannot be based on HasHistoryChanges because HasHistoryChanges is greater than 0
  4043. // The only way is comparing from the original text
  4044. Assert.False (tv.IsDirty);
  4045. // Still true because HasHistoryChanges is greater than 0
  4046. Assert.True (tv.HasHistoryChanges);
  4047. }
  4048. [Fact]
  4049. public void HistoryText_Undo_Redo_Multi_Line_Selected_DeleteCharLeft_All ()
  4050. {
  4051. var text = "This is the first line.\nThis is the second line.\nThis is the third line.";
  4052. var tv = new TextView () { Text = text };
  4053. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  4054. Assert.Equal (3, tv.Lines);
  4055. Assert.Equal (Point.Empty, tv.CursorPosition);
  4056. Assert.False (tv.IsDirty);
  4057. Assert.False (tv.HasHistoryChanges);
  4058. Assert.True (tv.ProcessKey (new KeyEvent (Key.End | Key.CtrlMask | Key.ShiftMask, new KeyModifiers ())));
  4059. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  4060. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.SelectedText);
  4061. Assert.Equal (3, tv.Lines);
  4062. Assert.Equal (new Point (23, 2), tv.CursorPosition);
  4063. Assert.Equal (70 + Environment.NewLine.Length * 2, tv.SelectedLength);
  4064. Assert.False (tv.IsDirty);
  4065. Assert.False (tv.HasHistoryChanges);
  4066. Assert.True (tv.ProcessKey (new KeyEvent (Key.Backspace, new KeyModifiers ())));
  4067. Assert.Equal ("", tv.Text);
  4068. Assert.Equal ("", tv.SelectedText);
  4069. Assert.Equal (1, tv.Lines);
  4070. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  4071. Assert.Equal (0, tv.SelectedLength);
  4072. Assert.True (tv.IsDirty);
  4073. Assert.True (tv.HasHistoryChanges);
  4074. // Undo
  4075. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  4076. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  4077. Assert.Equal ("", tv.SelectedText);
  4078. Assert.Equal (3, tv.Lines);
  4079. Assert.Equal (new Point (23, 2), tv.CursorPosition);
  4080. Assert.Equal (0, tv.SelectedLength);
  4081. Assert.False (tv.IsDirty);
  4082. Assert.True (tv.HasHistoryChanges);
  4083. // Redo
  4084. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  4085. Assert.Equal ("", tv.Text);
  4086. Assert.Equal ("", tv.SelectedText);
  4087. Assert.Equal (1, tv.Lines);
  4088. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  4089. Assert.Equal (0, tv.SelectedLength);
  4090. Assert.True (tv.IsDirty);
  4091. Assert.True (tv.HasHistoryChanges);
  4092. }
  4093. [Fact]
  4094. public void HistoryText_Undo_Redo_Multi_Line_Selected_DeleteCharRight_All ()
  4095. {
  4096. var text = "This is the first line.\nThis is the second line.\nThis is the third line.";
  4097. var tv = new TextView () { Text = text };
  4098. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  4099. Assert.Equal (3, tv.Lines);
  4100. Assert.Equal (Point.Empty, tv.CursorPosition);
  4101. Assert.False (tv.IsDirty);
  4102. Assert.False (tv.HasHistoryChanges);
  4103. Assert.True (tv.ProcessKey (new KeyEvent (Key.End | Key.CtrlMask | Key.ShiftMask, new KeyModifiers ())));
  4104. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  4105. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.SelectedText);
  4106. Assert.Equal (3, tv.Lines);
  4107. Assert.Equal (new Point (23, 2), tv.CursorPosition);
  4108. Assert.Equal (70 + Environment.NewLine.Length * 2, tv.SelectedLength);
  4109. Assert.False (tv.IsDirty);
  4110. Assert.False (tv.HasHistoryChanges);
  4111. Assert.True (tv.ProcessKey (new KeyEvent (Key.DeleteChar, new KeyModifiers ())));
  4112. Assert.Equal ("", tv.Text);
  4113. Assert.Equal ("", tv.SelectedText);
  4114. Assert.Equal (1, tv.Lines);
  4115. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  4116. Assert.Equal (0, tv.SelectedLength);
  4117. Assert.True (tv.IsDirty);
  4118. Assert.True (tv.HasHistoryChanges);
  4119. // Undo
  4120. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  4121. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  4122. Assert.Equal ("", tv.SelectedText);
  4123. Assert.Equal (3, tv.Lines);
  4124. Assert.Equal (new Point (23, 2), tv.CursorPosition);
  4125. Assert.Equal (0, tv.SelectedLength);
  4126. Assert.False (tv.IsDirty);
  4127. Assert.True (tv.HasHistoryChanges);
  4128. // Redo
  4129. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  4130. Assert.Equal ("", tv.Text);
  4131. Assert.Equal ("", tv.SelectedText);
  4132. Assert.Equal (1, tv.Lines);
  4133. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  4134. Assert.Equal (0, tv.SelectedLength);
  4135. Assert.True (tv.IsDirty);
  4136. Assert.True (tv.HasHistoryChanges);
  4137. }
  4138. [Fact]
  4139. [AutoInitShutdown]
  4140. public void HistoryText_Undo_Redo_Copy_Without_Selection_Multi_Line_Paste ()
  4141. {
  4142. var text = "This is the first line.\nThis is the second line.\nThis is the third line.";
  4143. var tv = new TextView () { Text = text };
  4144. tv.CursorPosition = new Point (23, 0);
  4145. Assert.True (tv.ProcessKey (new KeyEvent (Key.C | Key.CtrlMask, new KeyModifiers ())));
  4146. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  4147. Assert.Equal ("", tv.SelectedText);
  4148. Assert.Equal ("This is the first line.", Clipboard.Contents);
  4149. Assert.Equal (3, tv.Lines);
  4150. Assert.Equal (new Point (23, 0), tv.CursorPosition);
  4151. Assert.True (tv.ProcessKey (new KeyEvent (Key.Y | Key.CtrlMask, new KeyModifiers ())));
  4152. Assert.Equal ($"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.", tv.Text);
  4153. Assert.Equal (4, tv.Lines);
  4154. Assert.Equal (new Point (23, 1), tv.CursorPosition);
  4155. // Undo
  4156. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  4157. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  4158. Assert.Equal (3, tv.Lines);
  4159. Assert.Equal (new Point (23, 0), tv.CursorPosition);
  4160. // Redo
  4161. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  4162. Assert.Equal ($"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.", tv.Text);
  4163. Assert.Equal (4, tv.Lines);
  4164. Assert.Equal (new Point (23, 1), tv.CursorPosition);
  4165. }
  4166. [Fact]
  4167. [AutoInitShutdown]
  4168. public void HistoryText_Undo_Redo_Simple_Copy_Multi_Line_Selected_Paste ()
  4169. {
  4170. var text = "This is the first line.\nThis is the second line.\nThis is the third line.";
  4171. var tv = new TextView () { Text = text };
  4172. tv.SelectionStartColumn = 12;
  4173. tv.CursorPosition = new Point (17, 0);
  4174. Assert.True (tv.ProcessKey (new KeyEvent (Key.C | Key.CtrlMask, new KeyModifiers ())));
  4175. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  4176. Assert.Equal ("first", tv.SelectedText);
  4177. Assert.Equal (3, tv.Lines);
  4178. Assert.Equal (new Point (17, 0), tv.CursorPosition);
  4179. tv.SelectionStartColumn = 12;
  4180. tv.CursorPosition = new Point (11, 1);
  4181. Assert.True (tv.ProcessKey (new KeyEvent (Key.Y | Key.CtrlMask, new KeyModifiers ())));
  4182. Assert.Equal ($"This is the first second line.{Environment.NewLine}This is the third line.", tv.Text);
  4183. Assert.Equal (2, tv.Lines);
  4184. Assert.Equal (new Point (17, 0), tv.CursorPosition);
  4185. // Undo
  4186. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  4187. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  4188. Assert.Equal (3, tv.Lines);
  4189. Assert.Equal (new Point (12, 0), tv.CursorPosition);
  4190. // Redo
  4191. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  4192. Assert.Equal ($"This is the first second line.{Environment.NewLine}This is the third line.", tv.Text);
  4193. Assert.Equal (2, tv.Lines);
  4194. Assert.Equal (new Point (17, 0), tv.CursorPosition);
  4195. }
  4196. [Fact]
  4197. [AutoInitShutdown]
  4198. public void HistoryText_Undo_Redo_Multi_Line_Selected_Copy_Simple_Paste_Starting_On_Space ()
  4199. {
  4200. var text = "This is the first line.\nThis is the second line.\nThis is the third line.";
  4201. var tv = new TextView () { Text = text };
  4202. tv.SelectionStartColumn = 12;
  4203. tv.CursorPosition = new Point (18, 1);
  4204. Assert.True (tv.ProcessKey (new KeyEvent (Key.C | Key.CtrlMask, new KeyModifiers ())));
  4205. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  4206. Assert.Equal ($"first line.{Environment.NewLine}This is the second", tv.SelectedText);
  4207. Assert.Equal (3, tv.Lines);
  4208. Assert.Equal (new Point (18, 1), tv.CursorPosition);
  4209. tv.Selecting = false;
  4210. Assert.True (tv.ProcessKey (new KeyEvent (Key.Y | Key.CtrlMask, new KeyModifiers ())));
  4211. Assert.Equal ($"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.", tv.Text);
  4212. Assert.Equal (4, tv.Lines);
  4213. Assert.Equal (new Point (18, 2), tv.CursorPosition);
  4214. // Undo
  4215. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  4216. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  4217. Assert.Equal (3, tv.Lines);
  4218. Assert.Equal (new Point (18, 1), tv.CursorPosition);
  4219. // Redo
  4220. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  4221. Assert.Equal ($"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.", tv.Text);
  4222. Assert.Equal (4, tv.Lines);
  4223. Assert.Equal (new Point (18, 2), tv.CursorPosition);
  4224. }
  4225. [Fact]
  4226. [AutoInitShutdown]
  4227. public void HistoryText_Undo_Redo_Multi_Line_Selected_Copy_Simple_Paste_Starting_On_Letter ()
  4228. {
  4229. var text = "This is the first line.\nThis is the second line.\nThis is the third line.";
  4230. var tv = new TextView () { Text = text };
  4231. tv.SelectionStartColumn = 12;
  4232. tv.CursorPosition = new Point (18, 1);
  4233. Assert.True (tv.ProcessKey (new KeyEvent (Key.C | Key.CtrlMask, new KeyModifiers ())));
  4234. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  4235. Assert.Equal ($"first line.{Environment.NewLine}This is the second", tv.SelectedText);
  4236. Assert.Equal (3, tv.Lines);
  4237. Assert.Equal (new Point (18, 1), tv.CursorPosition);
  4238. tv.Selecting = false;
  4239. tv.CursorPosition = new Point (17, 1);
  4240. Assert.True (tv.ProcessKey (new KeyEvent (Key.Y | Key.CtrlMask, new KeyModifiers ())));
  4241. Assert.Equal ($"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.", tv.Text);
  4242. Assert.Equal (4, tv.Lines);
  4243. Assert.Equal (new Point (18, 2), tv.CursorPosition);
  4244. // Undo
  4245. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  4246. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  4247. Assert.Equal (3, tv.Lines);
  4248. Assert.Equal (new Point (17, 1), tv.CursorPosition);
  4249. // Redo
  4250. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  4251. Assert.Equal ($"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.", tv.Text);
  4252. Assert.Equal (4, tv.Lines);
  4253. Assert.Equal (new Point (18, 2), tv.CursorPosition);
  4254. }
  4255. [Fact]
  4256. [AutoInitShutdown]
  4257. public void HistoryText_Undo_Redo_Empty_Copy_Without_Selection_Multi_Line_Selected_Paste ()
  4258. {
  4259. var text = "\nThis is the first line.\nThis is the second line.";
  4260. var tv = new TextView () { Text = text };
  4261. Assert.True (tv.ProcessKey (new KeyEvent (Key.C | Key.CtrlMask, new KeyModifiers ())));
  4262. Assert.Equal ($"{Environment.NewLine}This is the first line.{Environment.NewLine}This is the second line.", tv.Text);
  4263. Assert.Equal ("", tv.SelectedText);
  4264. Assert.Equal (3, tv.Lines);
  4265. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  4266. Assert.True (tv.ProcessKey (new KeyEvent (Key.Y | Key.CtrlMask, new KeyModifiers ())));
  4267. Assert.Equal ($"{Environment.NewLine}{Environment.NewLine}This is the first line.{Environment.NewLine}This is the second line.", tv.Text);
  4268. Assert.Equal (4, tv.Lines);
  4269. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  4270. // Undo
  4271. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  4272. Assert.Equal ($"{Environment.NewLine}This is the first line.{Environment.NewLine}This is the second line.", tv.Text);
  4273. Assert.Equal (3, tv.Lines);
  4274. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  4275. // Redo
  4276. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  4277. Assert.Equal ($"{Environment.NewLine}{Environment.NewLine}This is the first line.{Environment.NewLine}This is the second line.", tv.Text);
  4278. Assert.Equal (4, tv.Lines);
  4279. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  4280. }
  4281. [Fact]
  4282. [AutoInitShutdown]
  4283. public void HistoryText_Undo_Redo_Setting_Clipboard_Multi_Line_Selected_Paste ()
  4284. {
  4285. var text = "This is the first line.\nThis is the second line.";
  4286. var tv = new TextView () { Text = text };
  4287. Clipboard.Contents = "Inserted\nNewLine";
  4288. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.", tv.Text);
  4289. Assert.Equal ("", tv.SelectedText);
  4290. Assert.Equal (2, tv.Lines);
  4291. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  4292. Assert.True (tv.ProcessKey (new KeyEvent (Key.Y | Key.CtrlMask, new KeyModifiers ())));
  4293. Assert.Equal ($"Inserted{Environment.NewLine}NewLineThis is the first line.{Environment.NewLine}This is the second line.", tv.Text);
  4294. Assert.Equal (3, tv.Lines);
  4295. Assert.Equal (new Point (7, 1), tv.CursorPosition);
  4296. // Undo
  4297. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  4298. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.", tv.Text);
  4299. Assert.Equal (2, tv.Lines);
  4300. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  4301. // Redo
  4302. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  4303. Assert.Equal ($"Inserted{Environment.NewLine}NewLineThis is the first line.{Environment.NewLine}This is the second line.", tv.Text);
  4304. Assert.Equal (3, tv.Lines);
  4305. Assert.Equal (new Point (7, 1), tv.CursorPosition);
  4306. }
  4307. [Fact]
  4308. [AutoInitShutdown]
  4309. public void HistoryText_Undo_Redo_Cut_Multi_Line_Selected_Paste ()
  4310. {
  4311. var text = "This is the first line.\nThis is the second line.\nThis is the third line.";
  4312. var tv = new TextView () { Text = text };
  4313. tv.SelectionStartColumn = 12;
  4314. tv.CursorPosition = new Point (17, 0);
  4315. Assert.True (tv.ProcessKey (new KeyEvent (Key.W | Key.CtrlMask, new KeyModifiers ())));
  4316. Assert.Equal ($"This is the line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  4317. Assert.Equal ("", tv.SelectedText);
  4318. Assert.Equal (3, tv.Lines);
  4319. Assert.Equal (new Point (12, 0), tv.CursorPosition);
  4320. tv.SelectionStartColumn = 12;
  4321. tv.CursorPosition = new Point (11, 1);
  4322. Assert.True (tv.ProcessKey (new KeyEvent (Key.Y | Key.CtrlMask, new KeyModifiers ())));
  4323. Assert.Equal ($"This is the first second line.{Environment.NewLine}This is the third line.", tv.Text);
  4324. Assert.Equal (2, tv.Lines);
  4325. Assert.Equal (new Point (17, 0), tv.CursorPosition);
  4326. // Undo
  4327. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  4328. Assert.Equal ($"This is the line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  4329. Assert.Equal (3, tv.Lines);
  4330. Assert.Equal (new Point (12, 0), tv.CursorPosition);
  4331. // Redo
  4332. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  4333. Assert.Equal ($"This is the first second line.{Environment.NewLine}This is the third line.", tv.Text);
  4334. Assert.Equal (2, tv.Lines);
  4335. Assert.Equal (new Point (17, 0), tv.CursorPosition);
  4336. }
  4337. [Fact]
  4338. [AutoInitShutdown]
  4339. public void HistoryText_Undo_Redo_Cut_Simple_Paste_Starting ()
  4340. {
  4341. var text = "This is the first line.\nThis is the second line.\nThis is the third line.";
  4342. var tv = new TextView () { Text = text };
  4343. tv.SelectionStartColumn = 12;
  4344. tv.CursorPosition = new Point (18, 1);
  4345. Assert.True (tv.ProcessKey (new KeyEvent (Key.W | Key.CtrlMask, new KeyModifiers ())));
  4346. Assert.Equal ($"This is the line.{Environment.NewLine}This is the third line.", tv.Text);
  4347. Assert.Equal ("", tv.SelectedText);
  4348. Assert.Equal (2, tv.Lines);
  4349. Assert.Equal (new Point (12, 0), tv.CursorPosition);
  4350. tv.Selecting = false;
  4351. Assert.True (tv.ProcessKey (new KeyEvent (Key.Y | Key.CtrlMask, new KeyModifiers ())));
  4352. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  4353. Assert.Equal (3, tv.Lines);
  4354. Assert.Equal (new Point (18, 1), tv.CursorPosition);
  4355. // Undo
  4356. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  4357. Assert.Equal ($"This is the line.{Environment.NewLine}This is the third line.", tv.Text);
  4358. Assert.Equal (2, tv.Lines);
  4359. Assert.Equal (new Point (12, 0), tv.CursorPosition);
  4360. // Redo
  4361. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  4362. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  4363. Assert.Equal (3, tv.Lines);
  4364. Assert.Equal (new Point (18, 1), tv.CursorPosition);
  4365. }
  4366. [Fact]
  4367. [AutoInitShutdown]
  4368. public void HistoryText_Undo_Redo_Cut_Multi_Line_Another_Selected_Paste ()
  4369. {
  4370. var text = "This is the first line.\nThis is the second line.\nThis is the third line.";
  4371. var tv = new TextView () { Text = text };
  4372. tv.SelectionStartColumn = 12;
  4373. tv.CursorPosition = new Point (17, 0);
  4374. Assert.True (tv.ProcessKey (new KeyEvent (Key.W | Key.CtrlMask, new KeyModifiers ())));
  4375. Assert.Equal ($"This is the line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  4376. Assert.Equal ("", tv.SelectedText);
  4377. Assert.Equal (3, tv.Lines);
  4378. Assert.Equal (new Point (12, 0), tv.CursorPosition);
  4379. tv.SelectionStartColumn = 12;
  4380. tv.SelectionStartRow = 1;
  4381. tv.CursorPosition = new Point (18, 1);
  4382. Assert.True (tv.ProcessKey (new KeyEvent (Key.Y | Key.CtrlMask, new KeyModifiers ())));
  4383. Assert.Equal ($"This is the line.{Environment.NewLine}This is the first line.{Environment.NewLine}This is the third line.", tv.Text);
  4384. Assert.Equal (3, tv.Lines);
  4385. Assert.Equal (new Point (17, 1), tv.CursorPosition);
  4386. // Undo
  4387. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  4388. Assert.Equal ($"This is the line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  4389. Assert.Equal (3, tv.Lines);
  4390. Assert.Equal (new Point (12, 1), tv.CursorPosition);
  4391. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  4392. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  4393. Assert.Equal (3, tv.Lines);
  4394. Assert.Equal (new Point (12, 0), tv.CursorPosition);
  4395. // Redo
  4396. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  4397. Assert.Equal ($"This is the line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  4398. Assert.Equal (3, tv.Lines);
  4399. Assert.Equal (new Point (12, 0), tv.CursorPosition);
  4400. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  4401. Assert.Equal ($"This is the line.{Environment.NewLine}This is the first line.{Environment.NewLine}This is the third line.", tv.Text);
  4402. Assert.Equal (3, tv.Lines);
  4403. Assert.Equal (new Point (17, 1), tv.CursorPosition);
  4404. }
  4405. [Fact]
  4406. public void HistoryText_Undo_Redo_KillWordBackward ()
  4407. {
  4408. var text = "First line.\nSecond line.";
  4409. var tv = new TextView () { Text = text };
  4410. Assert.True (tv.ProcessKey (new KeyEvent (Key.End | Key.CtrlMask, new KeyModifiers ())));
  4411. Assert.Equal ($"First line.{Environment.NewLine}Second line.", tv.Text);
  4412. Assert.Equal ("", tv.SelectedText);
  4413. Assert.Equal (2, tv.Lines);
  4414. Assert.Equal (new Point (12, 1), tv.CursorPosition);
  4415. Assert.True (tv.ProcessKey (new KeyEvent (Key.Backspace | Key.CtrlMask, new KeyModifiers ())));
  4416. Assert.Equal ($"First line.{Environment.NewLine}Second ", tv.Text);
  4417. Assert.Equal ("", tv.SelectedText);
  4418. Assert.Equal (2, tv.Lines);
  4419. Assert.Equal (new Point (7, 1), tv.CursorPosition);
  4420. Assert.True (tv.ProcessKey (new KeyEvent (Key.Backspace | Key.CtrlMask, new KeyModifiers ())));
  4421. Assert.Equal ($"First line.{Environment.NewLine}", tv.Text);
  4422. Assert.Equal ("", tv.SelectedText);
  4423. Assert.Equal (2, tv.Lines);
  4424. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  4425. Assert.True (tv.ProcessKey (new KeyEvent (Key.Backspace | Key.CtrlMask, new KeyModifiers ())));
  4426. Assert.Equal ("First line.", tv.Text);
  4427. Assert.Equal ("", tv.SelectedText);
  4428. Assert.Equal (1, tv.Lines);
  4429. Assert.Equal (new Point (11, 0), tv.CursorPosition);
  4430. Assert.True (tv.ProcessKey (new KeyEvent (Key.Backspace | Key.CtrlMask, new KeyModifiers ())));
  4431. Assert.Equal ("First ", tv.Text);
  4432. Assert.Equal ("", tv.SelectedText);
  4433. Assert.Equal (1, tv.Lines);
  4434. Assert.Equal (new Point (6, 0), tv.CursorPosition);
  4435. Assert.True (tv.ProcessKey (new KeyEvent (Key.Backspace | Key.CtrlMask, new KeyModifiers ())));
  4436. Assert.Equal ("", tv.Text);
  4437. Assert.Equal ("", tv.SelectedText);
  4438. Assert.Equal (1, tv.Lines);
  4439. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  4440. // Undo
  4441. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  4442. Assert.Equal ("First ", tv.Text);
  4443. Assert.Equal (1, tv.Lines);
  4444. Assert.Equal (new Point (6, 0), tv.CursorPosition);
  4445. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  4446. Assert.Equal ("First line.", tv.Text);
  4447. Assert.Equal (1, tv.Lines);
  4448. Assert.Equal (new Point (11, 0), tv.CursorPosition);
  4449. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  4450. Assert.Equal ($"First line.{Environment.NewLine}", tv.Text);
  4451. Assert.Equal (2, tv.Lines);
  4452. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  4453. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  4454. Assert.Equal ($"First line.{Environment.NewLine}Second ", tv.Text);
  4455. Assert.Equal (2, tv.Lines);
  4456. Assert.Equal (new Point (7, 1), tv.CursorPosition);
  4457. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  4458. Assert.Equal ($"First line.{Environment.NewLine}Second line.", tv.Text);
  4459. Assert.Equal (2, tv.Lines);
  4460. Assert.Equal (new Point (12, 1), tv.CursorPosition);
  4461. // Redo
  4462. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  4463. Assert.Equal ($"First line.{Environment.NewLine}Second ", tv.Text);
  4464. Assert.Equal (2, tv.Lines);
  4465. Assert.Equal (new Point (7, 1), tv.CursorPosition);
  4466. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  4467. Assert.Equal ($"First line.{Environment.NewLine}", tv.Text);
  4468. Assert.Equal (2, tv.Lines);
  4469. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  4470. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  4471. Assert.Equal ("First line.", tv.Text);
  4472. Assert.Equal (1, tv.Lines);
  4473. Assert.Equal (new Point (11, 0), tv.CursorPosition);
  4474. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  4475. Assert.Equal ("First ", tv.Text);
  4476. Assert.Equal (1, tv.Lines);
  4477. Assert.Equal (new Point (6, 0), tv.CursorPosition);
  4478. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  4479. Assert.Equal ("", tv.Text);
  4480. Assert.Equal (1, tv.Lines);
  4481. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  4482. }
  4483. [Fact]
  4484. public void HistoryText_Undo_Redo_KillWordForward ()
  4485. {
  4486. var text = "First line.\nSecond line.";
  4487. var tv = new TextView () { Text = text };
  4488. Assert.True (tv.ProcessKey (new KeyEvent (Key.DeleteChar | Key.CtrlMask, new KeyModifiers ())));
  4489. Assert.Equal ($"line.{Environment.NewLine}Second line.", tv.Text);
  4490. Assert.Equal ("", tv.SelectedText);
  4491. Assert.Equal (2, tv.Lines);
  4492. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  4493. Assert.True (tv.ProcessKey (new KeyEvent (Key.DeleteChar | Key.CtrlMask, new KeyModifiers ())));
  4494. Assert.Equal ($"{Environment.NewLine}Second line.", tv.Text);
  4495. Assert.Equal (2, tv.Lines);
  4496. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  4497. Assert.True (tv.ProcessKey (new KeyEvent (Key.DeleteChar | Key.CtrlMask, new KeyModifiers ())));
  4498. Assert.Equal ("Second line.", tv.Text);
  4499. Assert.Equal (1, tv.Lines);
  4500. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  4501. Assert.True (tv.ProcessKey (new KeyEvent (Key.DeleteChar | Key.CtrlMask, new KeyModifiers ())));
  4502. Assert.Equal ("line.", tv.Text);
  4503. Assert.Equal (1, tv.Lines);
  4504. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  4505. Assert.True (tv.ProcessKey (new KeyEvent (Key.DeleteChar | Key.CtrlMask, new KeyModifiers ())));
  4506. Assert.Equal ("", tv.Text);
  4507. Assert.Equal (1, tv.Lines);
  4508. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  4509. // Undo
  4510. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  4511. Assert.Equal ("line.", tv.Text);
  4512. Assert.Equal (1, tv.Lines);
  4513. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  4514. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  4515. Assert.Equal ("Second line.", tv.Text);
  4516. Assert.Equal (1, tv.Lines);
  4517. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  4518. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  4519. Assert.Equal ($"{Environment.NewLine}Second line.", tv.Text);
  4520. Assert.Equal (2, tv.Lines);
  4521. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  4522. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  4523. Assert.Equal ($"line.{Environment.NewLine}Second line.", tv.Text);
  4524. Assert.Equal (2, tv.Lines);
  4525. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  4526. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  4527. Assert.Equal ($"First line.{Environment.NewLine}Second line.", tv.Text);
  4528. Assert.Equal (2, tv.Lines);
  4529. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  4530. // Redo
  4531. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  4532. Assert.Equal ($"line.{Environment.NewLine}Second line.", tv.Text);
  4533. Assert.Equal (2, tv.Lines);
  4534. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  4535. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  4536. Assert.Equal ($"{Environment.NewLine}Second line.", tv.Text);
  4537. Assert.Equal (2, tv.Lines);
  4538. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  4539. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  4540. Assert.Equal ("Second line.", tv.Text);
  4541. Assert.Equal (1, tv.Lines);
  4542. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  4543. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  4544. Assert.Equal ("line.", tv.Text);
  4545. Assert.Equal (1, tv.Lines);
  4546. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  4547. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  4548. Assert.Equal ("", tv.Text);
  4549. Assert.Equal (1, tv.Lines);
  4550. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  4551. }
  4552. [Fact]
  4553. [AutoInitShutdown]
  4554. public void HistoryText_Undo_Redo_KillToStartOfLine ()
  4555. {
  4556. var text = "First line.\nSecond line.";
  4557. var tv = new TextView () { Text = text };
  4558. Assert.True (tv.ProcessKey (new KeyEvent (Key.End | Key.CtrlMask, new KeyModifiers ())));
  4559. Assert.Equal ($"First line.{Environment.NewLine}Second line.", tv.Text);
  4560. Assert.Equal ("", tv.SelectedText);
  4561. Assert.Equal (2, tv.Lines);
  4562. Assert.Equal (new Point (12, 1), tv.CursorPosition);
  4563. Assert.True (tv.ProcessKey (new KeyEvent (Key.K | Key.AltMask, new KeyModifiers ())));
  4564. Assert.Equal ($"First line.{Environment.NewLine}", tv.Text);
  4565. Assert.Equal ("", tv.SelectedText);
  4566. Assert.Equal ("Second line.", Clipboard.Contents);
  4567. Assert.Equal (2, tv.Lines);
  4568. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  4569. Assert.True (tv.ProcessKey (new KeyEvent (Key.K | Key.AltMask, new KeyModifiers ())));
  4570. Assert.Equal ("First line.", tv.Text);
  4571. Assert.Equal ("", tv.SelectedText);
  4572. Assert.Equal ($"Second line.{Environment.NewLine}", Clipboard.Contents);
  4573. Assert.Equal (1, tv.Lines);
  4574. Assert.Equal (new Point (11, 0), tv.CursorPosition);
  4575. Assert.True (tv.ProcessKey (new KeyEvent (Key.K | Key.AltMask, new KeyModifiers ())));
  4576. Assert.Equal ("", tv.Text);
  4577. Assert.Equal ("", tv.SelectedText);
  4578. Assert.Equal ($"Second line.{Environment.NewLine}First line.", Clipboard.Contents);
  4579. Assert.Equal (1, tv.Lines);
  4580. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  4581. // Undo
  4582. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  4583. Assert.Equal ("First line.", tv.Text);
  4584. Assert.Equal (1, tv.Lines);
  4585. Assert.Equal (new Point (11, 0), tv.CursorPosition);
  4586. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  4587. Assert.Equal ($"First line.{Environment.NewLine}", tv.Text);
  4588. Assert.Equal (2, tv.Lines);
  4589. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  4590. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  4591. Assert.Equal ($"First line.{Environment.NewLine}Second line.", tv.Text);
  4592. Assert.Equal (2, tv.Lines);
  4593. Assert.Equal (new Point (12, 1), tv.CursorPosition);
  4594. // Redo
  4595. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  4596. Assert.Equal ($"First line.{Environment.NewLine}", tv.Text);
  4597. Assert.Equal (2, tv.Lines);
  4598. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  4599. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  4600. Assert.Equal ($"First line.", tv.Text);
  4601. Assert.Equal (1, tv.Lines);
  4602. Assert.Equal (new Point (11, 0), tv.CursorPosition);
  4603. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  4604. Assert.Equal ("", tv.Text);
  4605. Assert.Equal (1, tv.Lines);
  4606. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  4607. }
  4608. [Fact]
  4609. [AutoInitShutdown]
  4610. public void HistoryText_Undo_Redo_KillToEndOfLine ()
  4611. {
  4612. var text = "First line.\nSecond line.";
  4613. var tv = new TextView () { Text = text };
  4614. Assert.True (tv.ProcessKey (new KeyEvent (Key.K | Key.CtrlMask, new KeyModifiers ())));
  4615. Assert.Equal ($"{Environment.NewLine}Second line.", tv.Text);
  4616. Assert.Equal ("", tv.SelectedText);
  4617. Assert.Equal ("First line.", Clipboard.Contents);
  4618. Assert.Equal (2, tv.Lines);
  4619. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  4620. Assert.True (tv.ProcessKey (new KeyEvent (Key.K | Key.CtrlMask, new KeyModifiers ())));
  4621. Assert.Equal ("Second line.", tv.Text);
  4622. Assert.Equal ("", tv.SelectedText);
  4623. Assert.Equal ($"First line.{Environment.NewLine}", Clipboard.Contents);
  4624. Assert.Equal (1, tv.Lines);
  4625. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  4626. Assert.True (tv.ProcessKey (new KeyEvent (Key.K | Key.CtrlMask, new KeyModifiers ())));
  4627. Assert.Equal ("", tv.Text);
  4628. Assert.Equal ("", tv.SelectedText);
  4629. Assert.Equal ($"First line.{Environment.NewLine}Second line.", Clipboard.Contents);
  4630. Assert.Equal (1, tv.Lines);
  4631. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  4632. // Undo
  4633. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  4634. Assert.Equal ("Second line.", tv.Text);
  4635. Assert.Equal (1, tv.Lines);
  4636. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  4637. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  4638. Assert.Equal ($"{Environment.NewLine}Second line.", tv.Text);
  4639. Assert.Equal (2, tv.Lines);
  4640. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  4641. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  4642. Assert.Equal ($"First line.{Environment.NewLine}Second line.", tv.Text);
  4643. Assert.Equal (2, tv.Lines);
  4644. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  4645. // Redo
  4646. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  4647. Assert.Equal ($"{Environment.NewLine}Second line.", tv.Text);
  4648. Assert.Equal (2, tv.Lines);
  4649. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  4650. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  4651. Assert.Equal ("Second line.", tv.Text);
  4652. Assert.Equal (1, tv.Lines);
  4653. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  4654. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  4655. Assert.Equal ("", tv.Text);
  4656. Assert.Equal (1, tv.Lines);
  4657. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  4658. }
  4659. [Fact]
  4660. public void HistoryText_Undo_Redo_Changing_On_Middle_Clear_History_Forwards ()
  4661. {
  4662. var tv = new TextView ();
  4663. Assert.True (tv.ProcessKey (new KeyEvent (Key.D1, new KeyModifiers ())));
  4664. Assert.Equal ("1", tv.Text);
  4665. Assert.Equal (1, tv.Lines);
  4666. Assert.Equal (new Point (1, 0), tv.CursorPosition);
  4667. Assert.True (tv.ProcessKey (new KeyEvent (Key.D2, new KeyModifiers ())));
  4668. Assert.Equal ("12", tv.Text);
  4669. Assert.Equal (1, tv.Lines);
  4670. Assert.Equal (new Point (2, 0), tv.CursorPosition);
  4671. Assert.True (tv.ProcessKey (new KeyEvent (Key.D3, new KeyModifiers ())));
  4672. Assert.Equal ("123", tv.Text);
  4673. Assert.Equal (1, tv.Lines);
  4674. Assert.Equal (new Point (3, 0), tv.CursorPosition);
  4675. // Undo
  4676. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  4677. Assert.Equal ("12", tv.Text);
  4678. Assert.Equal (1, tv.Lines);
  4679. Assert.Equal (new Point (2, 0), tv.CursorPosition);
  4680. Assert.True (tv.ProcessKey (new KeyEvent (Key.D4, new KeyModifiers ())));
  4681. Assert.Equal ("124", tv.Text);
  4682. Assert.Equal (1, tv.Lines);
  4683. Assert.Equal (new Point (3, 0), tv.CursorPosition);
  4684. // Redo
  4685. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  4686. Assert.Equal ("124", tv.Text);
  4687. Assert.Equal (1, tv.Lines);
  4688. Assert.Equal (new Point (3, 0), tv.CursorPosition);
  4689. }
  4690. [Fact]
  4691. public void HistoryText_Undo_Redo_Single_Line_Selected_Return ()
  4692. {
  4693. var text = "This is the first line.\nThis is the second line.\nThis is the third line.";
  4694. var tv = new TextView () { Text = text };
  4695. tv.SelectionStartColumn = 12;
  4696. tv.CursorPosition = new Point (17, 0);
  4697. Assert.True (tv.ProcessKey (new KeyEvent (Key.Enter, new KeyModifiers ())));
  4698. Assert.Equal ($"This is the {Environment.NewLine} line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  4699. Assert.Equal (4, tv.Lines);
  4700. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  4701. // Undo
  4702. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  4703. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  4704. Assert.Equal (3, tv.Lines);
  4705. Assert.Equal (new Point (17, 0), tv.CursorPosition);
  4706. Assert.False (tv.IsDirty);
  4707. // Redo
  4708. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  4709. Assert.Equal ($"This is the {Environment.NewLine} line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  4710. Assert.Equal (4, tv.Lines);
  4711. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  4712. // Undo
  4713. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  4714. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  4715. Assert.Equal (3, tv.Lines);
  4716. Assert.Equal (new Point (17, 0), tv.CursorPosition);
  4717. Assert.False (tv.IsDirty);
  4718. // Redo
  4719. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  4720. Assert.Equal ($"This is the {Environment.NewLine} line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  4721. Assert.Equal (4, tv.Lines);
  4722. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  4723. }
  4724. [Fact]
  4725. public void HistoryText_Undo_Redo_Two_Line_Selected_Return ()
  4726. {
  4727. var text = "This is the first line.\nThis is the second line.\nThis is the third line.";
  4728. var tv = new TextView () { Text = text };
  4729. tv.SelectionStartColumn = 12;
  4730. tv.CursorPosition = new Point (18, 1);
  4731. Assert.True (tv.ProcessKey (new KeyEvent (Key.Enter, new KeyModifiers ())));
  4732. Assert.Equal ($"This is the {Environment.NewLine} line.{Environment.NewLine}This is the third line.", tv.Text);
  4733. Assert.Equal (3, tv.Lines);
  4734. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  4735. // Undo
  4736. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  4737. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  4738. Assert.Equal (3, tv.Lines);
  4739. Assert.Equal (new Point (18, 1), tv.CursorPosition);
  4740. Assert.False (tv.IsDirty);
  4741. // Redo
  4742. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  4743. Assert.Equal ($"This is the {Environment.NewLine} line.{Environment.NewLine}This is the third line.", tv.Text);
  4744. Assert.Equal (3, tv.Lines);
  4745. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  4746. // Undo
  4747. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  4748. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  4749. Assert.Equal (3, tv.Lines);
  4750. Assert.Equal (new Point (18, 1), tv.CursorPosition);
  4751. Assert.False (tv.IsDirty);
  4752. // Redo
  4753. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  4754. Assert.Equal ($"This is the {Environment.NewLine} line.{Environment.NewLine}This is the third line.", tv.Text);
  4755. Assert.Equal (3, tv.Lines);
  4756. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  4757. }
  4758. [Fact]
  4759. public void HistoryText_Undo_Redo_Three_Line_Selected_Return ()
  4760. {
  4761. var text = "This is the first line.\nThis is the second line.\nThis is the third line.";
  4762. var tv = new TextView () { Text = text };
  4763. tv.SelectionStartColumn = 12;
  4764. tv.CursorPosition = new Point (17, 2);
  4765. Assert.True (tv.ProcessKey (new KeyEvent (Key.Enter, new KeyModifiers ())));
  4766. Assert.Equal ($"This is the {Environment.NewLine} line.", tv.Text);
  4767. Assert.Equal (2, tv.Lines);
  4768. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  4769. // Undo
  4770. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  4771. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  4772. Assert.Equal (3, tv.Lines);
  4773. Assert.Equal (new Point (17, 2), tv.CursorPosition);
  4774. Assert.False (tv.IsDirty);
  4775. // Redo
  4776. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  4777. Assert.Equal ($"This is the {Environment.NewLine} line.", tv.Text);
  4778. Assert.Equal (2, tv.Lines);
  4779. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  4780. // Undo
  4781. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  4782. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  4783. Assert.Equal (3, tv.Lines);
  4784. Assert.Equal (new Point (17, 2), tv.CursorPosition);
  4785. Assert.False (tv.IsDirty);
  4786. // Redo
  4787. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  4788. Assert.Equal ($"This is the {Environment.NewLine} line.", tv.Text);
  4789. Assert.Equal (2, tv.Lines);
  4790. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  4791. }
  4792. [Fact]
  4793. public void HistoryText_Undo_Redo_Single_Second_Line_Selected_Return ()
  4794. {
  4795. var text = "This is the first line.\nThis is the second line.\nThis is the third line.";
  4796. var tv = new TextView () { Text = text };
  4797. tv.SelectionStartColumn = 12;
  4798. tv.SelectionStartRow = 1;
  4799. tv.CursorPosition = new Point (18, 1);
  4800. Assert.True (tv.ProcessKey (new KeyEvent (Key.Enter, new KeyModifiers ())));
  4801. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the {Environment.NewLine} line.{Environment.NewLine}This is the third line.", tv.Text);
  4802. Assert.Equal (4, tv.Lines);
  4803. Assert.Equal (new Point (0, 2), tv.CursorPosition);
  4804. // Undo
  4805. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  4806. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  4807. Assert.Equal (3, tv.Lines);
  4808. Assert.Equal (new Point (18, 1), tv.CursorPosition);
  4809. Assert.False (tv.IsDirty);
  4810. // Redo
  4811. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  4812. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the {Environment.NewLine} line.{Environment.NewLine}This is the third line.", tv.Text);
  4813. Assert.Equal (4, tv.Lines);
  4814. Assert.Equal (new Point (0, 2), tv.CursorPosition);
  4815. // Undo
  4816. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  4817. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  4818. Assert.Equal (3, tv.Lines);
  4819. Assert.Equal (new Point (18, 1), tv.CursorPosition);
  4820. Assert.False (tv.IsDirty);
  4821. // Redo
  4822. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  4823. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the {Environment.NewLine} line.{Environment.NewLine}This is the third line.", tv.Text);
  4824. Assert.Equal (4, tv.Lines);
  4825. Assert.Equal (new Point (0, 2), tv.CursorPosition);
  4826. }
  4827. [Fact]
  4828. public void HistoryText_Undo_Redo_First_Line_Selected_Return_And_InsertText ()
  4829. {
  4830. var text = "This is the first line.\nThis is the second line.\nThis is the third line.";
  4831. var tv = new TextView () { Text = text };
  4832. tv.SelectionStartColumn = 12;
  4833. tv.CursorPosition = new Point (17, 0);
  4834. Assert.True (tv.ProcessKey (new KeyEvent (Key.Enter, new KeyModifiers ())));
  4835. Assert.Equal ($"This is the {Environment.NewLine} line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  4836. Assert.Equal (4, tv.Lines);
  4837. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  4838. Assert.True (tv.ProcessKey (new KeyEvent (Key.a, new KeyModifiers ())));
  4839. Assert.Equal ($"This is the {Environment.NewLine}a line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  4840. Assert.Equal (4, tv.Lines);
  4841. Assert.Equal (new Point (1, 1), tv.CursorPosition);
  4842. // Undo
  4843. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  4844. Assert.Equal ($"This is the {Environment.NewLine} line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  4845. Assert.Equal (4, tv.Lines);
  4846. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  4847. Assert.True (tv.IsDirty);
  4848. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  4849. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  4850. Assert.Equal (3, tv.Lines);
  4851. Assert.Equal (new Point (17, 0), tv.CursorPosition);
  4852. Assert.False (tv.IsDirty);
  4853. // Redo
  4854. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  4855. Assert.Equal ($"This is the {Environment.NewLine} line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  4856. Assert.Equal (4, tv.Lines);
  4857. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  4858. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  4859. Assert.Equal ($"This is the {Environment.NewLine}a line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  4860. Assert.Equal (4, tv.Lines);
  4861. Assert.Equal (new Point (1, 1), tv.CursorPosition);
  4862. // Undo
  4863. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  4864. Assert.Equal ($"This is the {Environment.NewLine} line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  4865. Assert.Equal (4, tv.Lines);
  4866. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  4867. Assert.True (tv.IsDirty);
  4868. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  4869. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  4870. Assert.Equal (3, tv.Lines);
  4871. Assert.Equal (new Point (17, 0), tv.CursorPosition);
  4872. Assert.False (tv.IsDirty);
  4873. // Redo
  4874. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  4875. Assert.Equal ($"This is the {Environment.NewLine} line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  4876. Assert.Equal (4, tv.Lines);
  4877. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  4878. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  4879. Assert.Equal ($"This is the {Environment.NewLine}a line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  4880. Assert.Equal (4, tv.Lines);
  4881. Assert.Equal (new Point (1, 1), tv.CursorPosition);
  4882. }
  4883. [Fact]
  4884. public void HistoryText_Undo_Redo_Single_Second_Line_Selected_Return_And_InsertText ()
  4885. {
  4886. var text = "This is the first line.\nThis is the second line.\nThis is the third line.";
  4887. var tv = new TextView () { Text = text };
  4888. tv.SelectionStartColumn = 12;
  4889. tv.SelectionStartRow = 1;
  4890. tv.CursorPosition = new Point (18, 1);
  4891. Assert.True (tv.ProcessKey (new KeyEvent (Key.Enter, new KeyModifiers ())));
  4892. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the {Environment.NewLine} line.{Environment.NewLine}This is the third line.", tv.Text);
  4893. Assert.Equal (4, tv.Lines);
  4894. Assert.Equal (new Point (0, 2), tv.CursorPosition);
  4895. Assert.True (tv.ProcessKey (new KeyEvent (Key.a, new KeyModifiers ())));
  4896. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the {Environment.NewLine}a line.{Environment.NewLine}This is the third line.", tv.Text);
  4897. Assert.Equal (4, tv.Lines);
  4898. Assert.Equal (new Point (1, 2), tv.CursorPosition);
  4899. // Undo
  4900. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  4901. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the {Environment.NewLine} line.{Environment.NewLine}This is the third line.", tv.Text);
  4902. Assert.Equal (4, tv.Lines);
  4903. Assert.Equal (new Point (0, 2), tv.CursorPosition);
  4904. Assert.True (tv.IsDirty);
  4905. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  4906. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  4907. Assert.Equal (3, tv.Lines);
  4908. Assert.Equal (new Point (18, 1), tv.CursorPosition);
  4909. Assert.False (tv.IsDirty);
  4910. // Redo
  4911. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  4912. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the {Environment.NewLine} line.{Environment.NewLine}This is the third line.", tv.Text);
  4913. Assert.Equal (4, tv.Lines);
  4914. Assert.Equal (new Point (0, 2), tv.CursorPosition);
  4915. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  4916. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the {Environment.NewLine}a line.{Environment.NewLine}This is the third line.", tv.Text);
  4917. Assert.Equal (4, tv.Lines);
  4918. Assert.Equal (new Point (1, 2), tv.CursorPosition);
  4919. // Undo
  4920. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  4921. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the {Environment.NewLine} line.{Environment.NewLine}This is the third line.", tv.Text);
  4922. Assert.Equal (4, tv.Lines);
  4923. Assert.Equal (new Point (0, 2), tv.CursorPosition);
  4924. Assert.True (tv.IsDirty);
  4925. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  4926. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  4927. Assert.Equal (3, tv.Lines);
  4928. Assert.Equal (new Point (18, 1), tv.CursorPosition);
  4929. Assert.False (tv.IsDirty);
  4930. // Redo
  4931. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  4932. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the {Environment.NewLine} line.{Environment.NewLine}This is the third line.", tv.Text);
  4933. Assert.Equal (4, tv.Lines);
  4934. Assert.Equal (new Point (0, 2), tv.CursorPosition);
  4935. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  4936. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the {Environment.NewLine}a line.{Environment.NewLine}This is the third line.", tv.Text);
  4937. Assert.Equal (4, tv.Lines);
  4938. Assert.Equal (new Point (1, 2), tv.CursorPosition);
  4939. }
  4940. [Fact]
  4941. public void HistoryText_Undo_Redo_Multi_Line_Selected_All_Return_And_InsertText ()
  4942. {
  4943. var text = "This is the first line.\nThis is the second line.\nThis is the third line.";
  4944. var tv = new TextView () { Text = text };
  4945. Assert.True (tv.ProcessKey (new KeyEvent (Key.End | Key.CtrlMask | Key.ShiftMask, new KeyModifiers ())));
  4946. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  4947. Assert.Equal (3, tv.Lines);
  4948. Assert.Equal (new Point (23, 2), tv.CursorPosition);
  4949. Assert.True (tv.ProcessKey (new KeyEvent (Key.Enter, new KeyModifiers ())));
  4950. Assert.Equal ($"{Environment.NewLine}", tv.Text);
  4951. Assert.Equal (2, tv.Lines);
  4952. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  4953. Assert.True (tv.ProcessKey (new KeyEvent (Key.a, new KeyModifiers ())));
  4954. Assert.Equal ($"{Environment.NewLine}a", tv.Text);
  4955. Assert.Equal (2, tv.Lines);
  4956. Assert.Equal (new Point (1, 1), tv.CursorPosition);
  4957. // Undo
  4958. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  4959. Assert.Equal ($"{Environment.NewLine}", tv.Text);
  4960. Assert.Equal (2, tv.Lines);
  4961. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  4962. Assert.True (tv.IsDirty);
  4963. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  4964. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  4965. Assert.Equal (3, tv.Lines);
  4966. Assert.Equal (new Point (23, 2), tv.CursorPosition);
  4967. Assert.False (tv.IsDirty);
  4968. // Redo
  4969. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  4970. Assert.Equal ($"{Environment.NewLine}", tv.Text);
  4971. Assert.Equal (2, tv.Lines);
  4972. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  4973. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  4974. Assert.Equal ($"{Environment.NewLine}a", tv.Text);
  4975. Assert.Equal (2, tv.Lines);
  4976. Assert.Equal (new Point (1, 1), tv.CursorPosition);
  4977. // Undo
  4978. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  4979. Assert.Equal ($"{Environment.NewLine}", tv.Text);
  4980. Assert.Equal (2, tv.Lines);
  4981. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  4982. Assert.True (tv.IsDirty);
  4983. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  4984. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  4985. Assert.Equal (3, tv.Lines);
  4986. Assert.Equal (new Point (23, 2), tv.CursorPosition);
  4987. Assert.False (tv.IsDirty);
  4988. // Redo
  4989. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  4990. Assert.Equal ($"{Environment.NewLine}", tv.Text);
  4991. Assert.Equal (2, tv.Lines);
  4992. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  4993. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  4994. Assert.Equal ($"{Environment.NewLine}a", tv.Text);
  4995. Assert.Equal (2, tv.Lines);
  4996. Assert.Equal (new Point (1, 1), tv.CursorPosition);
  4997. }
  4998. [Fact]
  4999. public void HistoryText_Undo_Redo_Ending_With_Newline_Multi_Line_Selected_Almost_All_Return_And_InsertText ()
  5000. {
  5001. var text = "This is the first line.\nThis is the second line.\nThis is the third line.\n";
  5002. var tv = new TextView () { Text = text };
  5003. tv.SelectionStartColumn = 12;
  5004. tv.CursorPosition = new Point (12, 2);
  5005. Assert.True (tv.ProcessKey (new KeyEvent (Key.Enter, new KeyModifiers ())));
  5006. Assert.Equal ($"This is the {Environment.NewLine}third line.{Environment.NewLine}", tv.Text);
  5007. Assert.Equal (3, tv.Lines);
  5008. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  5009. Assert.True (tv.ProcessKey (new KeyEvent (Key.a, new KeyModifiers ())));
  5010. Assert.Equal ($"This is the {Environment.NewLine}athird line.{Environment.NewLine}", tv.Text);
  5011. Assert.Equal (3, tv.Lines);
  5012. Assert.Equal (new Point (1, 1), tv.CursorPosition);
  5013. // Undo
  5014. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  5015. Assert.Equal ($"This is the {Environment.NewLine}third line.{Environment.NewLine}", tv.Text);
  5016. Assert.Equal (3, tv.Lines);
  5017. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  5018. Assert.True (tv.IsDirty);
  5019. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  5020. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.{Environment.NewLine}", tv.Text);
  5021. Assert.Equal (4, tv.Lines);
  5022. Assert.Equal (new Point (12, 2), tv.CursorPosition);
  5023. Assert.False (tv.IsDirty);
  5024. // Redo
  5025. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  5026. Assert.Equal ($"This is the {Environment.NewLine}third line.{Environment.NewLine}", tv.Text);
  5027. Assert.Equal (3, tv.Lines);
  5028. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  5029. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  5030. Assert.Equal ($"This is the {Environment.NewLine}athird line.{Environment.NewLine}", tv.Text);
  5031. Assert.Equal (3, tv.Lines);
  5032. Assert.Equal (new Point (1, 1), tv.CursorPosition);
  5033. // Undo
  5034. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  5035. Assert.Equal ($"This is the {Environment.NewLine}third line.{Environment.NewLine}", tv.Text);
  5036. Assert.Equal (3, tv.Lines);
  5037. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  5038. Assert.True (tv.IsDirty);
  5039. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  5040. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.{Environment.NewLine}", tv.Text);
  5041. Assert.Equal (4, tv.Lines);
  5042. Assert.Equal (new Point (12, 2), tv.CursorPosition);
  5043. Assert.False (tv.IsDirty);
  5044. // Redo
  5045. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  5046. Assert.Equal ($"This is the {Environment.NewLine}third line.{Environment.NewLine}", tv.Text);
  5047. Assert.Equal (3, tv.Lines);
  5048. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  5049. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  5050. Assert.Equal ($"This is the {Environment.NewLine}athird line.{Environment.NewLine}", tv.Text);
  5051. Assert.Equal (3, tv.Lines);
  5052. Assert.Equal (new Point (1, 1), tv.CursorPosition);
  5053. }
  5054. [Fact]
  5055. public void HistoryText_Undo_Redo_Disabled_On_WordWrap ()
  5056. {
  5057. var text = "This is the first line.\nThis is the second line.\nThis is the third line.\n";
  5058. var tv = new TextView () { Width = 80, Height = 5, Text = text };
  5059. Assert.False (tv.WordWrap);
  5060. tv.WordWrap = true;
  5061. tv.SelectionStartColumn = 12;
  5062. tv.CursorPosition = new Point (12, 2);
  5063. Assert.True (tv.ProcessKey (new KeyEvent (Key.Enter, new KeyModifiers ())));
  5064. Assert.Equal ($"This is the {Environment.NewLine}third line.{Environment.NewLine}", tv.Text);
  5065. Assert.Equal (3, tv.Lines);
  5066. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  5067. Assert.True (tv.ProcessKey (new KeyEvent (Key.a, new KeyModifiers ())));
  5068. Assert.Equal ($"This is the {Environment.NewLine}athird line.{Environment.NewLine}", tv.Text);
  5069. Assert.Equal (3, tv.Lines);
  5070. Assert.Equal (new Point (1, 1), tv.CursorPosition);
  5071. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  5072. Assert.Equal ($"This is the {Environment.NewLine}third line.{Environment.NewLine}", tv.Text);
  5073. Assert.Equal (3, tv.Lines);
  5074. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  5075. Assert.True (tv.IsDirty);
  5076. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  5077. Assert.Equal ($"This is the {Environment.NewLine}athird line.{Environment.NewLine}", tv.Text);
  5078. Assert.Equal (3, tv.Lines);
  5079. Assert.Equal (new Point (1, 1), tv.CursorPosition);
  5080. }
  5081. [Fact]
  5082. public void HistoryText_Undo_Redo_Multiline_Simples_Tab_BackTab ()
  5083. {
  5084. var text = "First line.\nSecond line.\nThird line.";
  5085. var tv = new TextView () { Width = 80, Height = 5, Text = text };
  5086. Assert.True (tv.ProcessKey (new KeyEvent (Key.Tab, new KeyModifiers ())));
  5087. Assert.Equal ($"\tFirst line.{Environment.NewLine}Second line.{Environment.NewLine}Third line.", tv.Text);
  5088. Assert.Equal (3, tv.Lines);
  5089. Assert.Equal (new Point (1, 0), tv.CursorPosition);
  5090. Assert.True (tv.ProcessKey (new KeyEvent (Key.BackTab, new KeyModifiers ())));
  5091. Assert.Equal ($"First line.{Environment.NewLine}Second line.{Environment.NewLine}Third line.", tv.Text);
  5092. Assert.Equal (3, tv.Lines);
  5093. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  5094. // Undo
  5095. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  5096. Assert.Equal ($"\tFirst line.{Environment.NewLine}Second line.{Environment.NewLine}Third line.", tv.Text);
  5097. Assert.Equal (3, tv.Lines);
  5098. Assert.Equal (new Point (1, 0), tv.CursorPosition);
  5099. Assert.True (tv.IsDirty);
  5100. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  5101. Assert.Equal ($"First line.{Environment.NewLine}Second line.{Environment.NewLine}Third line.", tv.Text);
  5102. Assert.Equal (3, tv.Lines);
  5103. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  5104. Assert.False (tv.IsDirty);
  5105. // Redo
  5106. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  5107. Assert.Equal ($"\tFirst line.{Environment.NewLine}Second line.{Environment.NewLine}Third line.", tv.Text);
  5108. Assert.Equal (3, tv.Lines);
  5109. Assert.Equal (new Point (1, 0), tv.CursorPosition);
  5110. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  5111. Assert.Equal ($"First line.{Environment.NewLine}Second line.{Environment.NewLine}Third line.", tv.Text);
  5112. Assert.Equal (3, tv.Lines);
  5113. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  5114. }
  5115. [Fact]
  5116. public void HistoryText_Undo_Redo_Multiline_Selected_Tab_BackTab ()
  5117. {
  5118. var text = "First line.\nSecond line.\nThird line.";
  5119. var tv = new TextView () { Width = 80, Height = 5, Text = text };
  5120. tv.SelectionStartColumn = 6;
  5121. tv.CursorPosition = new Point (6, 2);
  5122. Assert.True (tv.ProcessKey (new KeyEvent (Key.Tab, new KeyModifiers ())));
  5123. Assert.Equal ("First \tline.", tv.Text);
  5124. Assert.Equal (1, tv.Lines);
  5125. Assert.Equal (new Point (7, 0), tv.CursorPosition);
  5126. Assert.True (tv.ProcessKey (new KeyEvent (Key.BackTab, new KeyModifiers ())));
  5127. Assert.Equal ("First line.", tv.Text);
  5128. Assert.Equal (1, tv.Lines);
  5129. Assert.Equal (new Point (6, 0), tv.CursorPosition);
  5130. // Undo
  5131. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  5132. Assert.Equal ("First \tline.", tv.Text);
  5133. Assert.Equal (1, tv.Lines);
  5134. Assert.Equal (new Point (7, 0), tv.CursorPosition);
  5135. Assert.True (tv.IsDirty);
  5136. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  5137. Assert.Equal ($"First line.{Environment.NewLine}Second line.{Environment.NewLine}Third line.", tv.Text);
  5138. Assert.Equal (3, tv.Lines);
  5139. Assert.Equal (new Point (6, 2), tv.CursorPosition);
  5140. Assert.False (tv.IsDirty);
  5141. // Redo
  5142. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  5143. Assert.Equal ("First \tline.", tv.Text);
  5144. Assert.Equal (1, tv.Lines);
  5145. Assert.Equal (new Point (7, 0), tv.CursorPosition);
  5146. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  5147. Assert.Equal ("First line.", tv.Text);
  5148. Assert.Equal (1, tv.Lines);
  5149. Assert.Equal (new Point (6, 0), tv.CursorPosition);
  5150. }
  5151. [Fact]
  5152. public void HistoryText_ClearHistoryChanges ()
  5153. {
  5154. var text = "This is the first line.\nThis is the second line.\nThis is the third line.";
  5155. var tv = new TextView () { Text = text };
  5156. Assert.True (tv.ProcessKey (new KeyEvent (Key.Enter, new KeyModifiers ())));
  5157. Assert.Equal ($"{Environment.NewLine}This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  5158. Assert.Equal (4, tv.Lines);
  5159. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  5160. Assert.True (tv.IsDirty);
  5161. Assert.True (tv.HasHistoryChanges);
  5162. tv.ClearHistoryChanges ();
  5163. Assert.Equal ($"{Environment.NewLine}This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  5164. Assert.Equal (4, tv.Lines);
  5165. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  5166. Assert.False (tv.IsDirty);
  5167. Assert.False (tv.HasHistoryChanges);
  5168. }
  5169. [Fact]
  5170. public void GetRegion_StringFromRunes_Environment_NewLine ()
  5171. {
  5172. var tv = new TextView () { Text = $"1{Environment.NewLine}2" };
  5173. Assert.Equal ($"1{Environment.NewLine}2", tv.Text);
  5174. Assert.Equal ("", tv.SelectedText);
  5175. tv.SelectAll ();
  5176. Assert.Equal ($"1{Environment.NewLine}2", tv.Text);
  5177. Assert.Equal ($"1{Environment.NewLine}2", tv.SelectedText);
  5178. }
  5179. [Fact, AutoInitShutdown]
  5180. public void WordWrap_Not_Throw_If_Width_Is_Less_Than_Zero ()
  5181. {
  5182. var exception = Record.Exception (() => {
  5183. var tv = new TextView () {
  5184. Width = Dim.Fill (),
  5185. Height = Dim.Fill (),
  5186. WordWrap = true,
  5187. Text = "これは、左右のクリップ境界をテストするための非常に長いテキストです。"
  5188. };
  5189. });
  5190. Assert.Null (exception);
  5191. }
  5192. [Fact]
  5193. [AutoInitShutdown]
  5194. public void ScrollDownTillCaretOffscreen_ThenType ()
  5195. {
  5196. var tv = new TextView {
  5197. Width = 10,
  5198. Height = 5
  5199. };
  5200. // add 100 lines of wide text to view
  5201. for (int i = 0; i < 100; i++)
  5202. tv.Text += new string ('x', 100) + Environment.NewLine;
  5203. Assert.Equal (0, tv.CursorPosition.Y);
  5204. tv.ScrollTo (50);
  5205. Assert.Equal (0, tv.CursorPosition.Y);
  5206. tv.ProcessKey (new KeyEvent (Key.p, new KeyModifiers ()));
  5207. }
  5208. [Fact]
  5209. [AutoInitShutdown]
  5210. public void MoveDown_By_Setting_CursorPosition ()
  5211. {
  5212. var tv = new TextView {
  5213. Width = 10,
  5214. Height = 5
  5215. };
  5216. // add 100 lines of wide text to view
  5217. for (int i = 0; i < 100; i++)
  5218. tv.Text += new string ('x', 100) + (i == 99 ? "" : Environment.NewLine);
  5219. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  5220. tv.CursorPosition = new Point (5, 50);
  5221. Assert.Equal (new Point (5, 50), tv.CursorPosition);
  5222. tv.CursorPosition = new Point (200, 200);
  5223. Assert.Equal (new Point (100, 99), tv.CursorPosition);
  5224. }
  5225. [Fact]
  5226. [AutoInitShutdown]
  5227. public void ScrollTo_CursorPosition ()
  5228. {
  5229. var tv = new TextView {
  5230. Width = 10,
  5231. Height = 5
  5232. };
  5233. // add 100 lines of wide text to view
  5234. for (int i = 0; i < 100; i++)
  5235. tv.Text += new string ('x', 100) + (i == 99 ? "" : Environment.NewLine);
  5236. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  5237. tv.ScrollTo (50);
  5238. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  5239. tv.CursorPosition = new Point (tv.LeftColumn, tv.TopRow);
  5240. Assert.Equal (new Point (0, 50), tv.CursorPosition);
  5241. }
  5242. [Fact]
  5243. [InitShutdown]
  5244. public void Mouse_Button_Shift_Preserves_Selection ()
  5245. {
  5246. Assert.Equal ("TAB to jump between text fields.", _textView.Text);
  5247. Assert.True (_textView.MouseEvent (new MouseEvent () { X = 12, Y = 0, Flags = MouseFlags.Button1Pressed | MouseFlags.ButtonShift }));
  5248. Assert.Equal (0, _textView.SelectionStartColumn);
  5249. Assert.Equal (0, _textView.SelectionStartRow);
  5250. Assert.Equal (new Point (12, 0), _textView.CursorPosition);
  5251. Assert.True (_textView.Selecting);
  5252. Assert.Equal ("TAB to jump ", _textView.SelectedText);
  5253. Assert.True (_textView.MouseEvent (new MouseEvent () { X = 12, Y = 0, Flags = MouseFlags.Button1Clicked }));
  5254. Assert.Equal (0, _textView.SelectionStartRow);
  5255. Assert.Equal (0, _textView.SelectionStartRow);
  5256. Assert.Equal (new Point (12, 0), _textView.CursorPosition);
  5257. Assert.True (_textView.Selecting);
  5258. Assert.Equal ("TAB to jump ", _textView.SelectedText);
  5259. Assert.True (_textView.MouseEvent (new MouseEvent () { X = 19, Y = 0, Flags = MouseFlags.Button1Pressed | MouseFlags.ButtonShift }));
  5260. Assert.Equal (0, _textView.SelectionStartRow);
  5261. Assert.Equal (0, _textView.SelectionStartRow);
  5262. Assert.Equal (new Point (19, 0), _textView.CursorPosition);
  5263. Assert.True (_textView.Selecting);
  5264. Assert.Equal ("TAB to jump between", _textView.SelectedText);
  5265. Assert.True (_textView.MouseEvent (new MouseEvent () { X = 19, Y = 0, Flags = MouseFlags.Button1Clicked }));
  5266. Assert.Equal (0, _textView.SelectionStartRow);
  5267. Assert.Equal (0, _textView.SelectionStartRow);
  5268. Assert.Equal (new Point (19, 0), _textView.CursorPosition);
  5269. Assert.True (_textView.Selecting);
  5270. Assert.Equal ("TAB to jump between", _textView.SelectedText);
  5271. Assert.True (_textView.MouseEvent (new MouseEvent () { X = 24, Y = 0, Flags = MouseFlags.Button1Pressed | MouseFlags.ButtonShift }));
  5272. Assert.Equal (0, _textView.SelectionStartRow);
  5273. Assert.Equal (0, _textView.SelectionStartRow);
  5274. Assert.Equal (new Point (24, 0), _textView.CursorPosition);
  5275. Assert.True (_textView.Selecting);
  5276. Assert.Equal ("TAB to jump between text", _textView.SelectedText);
  5277. Assert.True (_textView.MouseEvent (new MouseEvent () { X = 24, Y = 0, Flags = MouseFlags.Button1Clicked }));
  5278. Assert.Equal (0, _textView.SelectionStartRow);
  5279. Assert.Equal (0, _textView.SelectionStartRow);
  5280. Assert.Equal (new Point (24, 0), _textView.CursorPosition);
  5281. Assert.True (_textView.Selecting);
  5282. Assert.Equal ("TAB to jump between text", _textView.SelectedText);
  5283. Assert.True (_textView.MouseEvent (new MouseEvent () { X = 24, Y = 0, Flags = MouseFlags.Button1Pressed }));
  5284. Assert.Equal (0, _textView.SelectionStartRow);
  5285. Assert.Equal (0, _textView.SelectionStartRow);
  5286. Assert.Equal (new Point (24, 0), _textView.CursorPosition);
  5287. Assert.True (_textView.Selecting);
  5288. Assert.Equal ("", _textView.SelectedText);
  5289. }
  5290. [Fact, AutoInitShutdown]
  5291. public void UnwrappedCursorPosition_Event ()
  5292. {
  5293. var cp = Point.Empty;
  5294. var tv = new TextView () {
  5295. Width = Dim.Fill (),
  5296. Height = Dim.Fill (),
  5297. Text = "This is the first line.\nThis is the second line.\n"
  5298. };
  5299. tv.UnwrappedCursorPosition += (e) => {
  5300. cp = e;
  5301. };
  5302. Application.Top.Add (tv);
  5303. Application.Begin (Application.Top);
  5304. Assert.False (tv.WordWrap);
  5305. Assert.Equal (Point.Empty, tv.CursorPosition);
  5306. Assert.Equal (Point.Empty, cp);
  5307. GraphViewTests.AssertDriverContentsWithFrameAre (@"
  5308. This is the first line.
  5309. This is the second line.
  5310. ", output);
  5311. tv.WordWrap = true;
  5312. tv.CursorPosition = new Point (12, 0);
  5313. tv.Redraw (tv.Bounds);
  5314. Assert.Equal (new Point (12, 0), tv.CursorPosition);
  5315. Assert.Equal (new Point (12, 0), cp);
  5316. GraphViewTests.AssertDriverContentsWithFrameAre (@"
  5317. This is the first line.
  5318. This is the second line.
  5319. ", output);
  5320. ((FakeDriver)Application.Driver).SetBufferSize (6, 25);
  5321. tv.Redraw (tv.Bounds);
  5322. Assert.Equal (new Point (4, 2), tv.CursorPosition);
  5323. Assert.Equal (new Point (12, 0), cp);
  5324. GraphViewTests.AssertDriverContentsWithFrameAre (@"
  5325. This
  5326. is
  5327. the
  5328. first
  5329. line.
  5330. This
  5331. is
  5332. the
  5333. secon
  5334. d
  5335. line.
  5336. ", output);
  5337. Assert.True (tv.ProcessKey (new KeyEvent (Key.CursorRight, new KeyModifiers ())));
  5338. tv.Redraw (tv.Bounds);
  5339. Assert.Equal (new Point (0, 3), tv.CursorPosition);
  5340. Assert.Equal (new Point (12, 0), cp);
  5341. GraphViewTests.AssertDriverContentsWithFrameAre (@"
  5342. This
  5343. is
  5344. the
  5345. first
  5346. line.
  5347. This
  5348. is
  5349. the
  5350. secon
  5351. d
  5352. line.
  5353. ", output);
  5354. Assert.True (tv.ProcessKey (new KeyEvent (Key.CursorRight, new KeyModifiers ())));
  5355. tv.Redraw (tv.Bounds);
  5356. Assert.Equal (new Point (1, 3), tv.CursorPosition);
  5357. Assert.Equal (new Point (13, 0), cp);
  5358. GraphViewTests.AssertDriverContentsWithFrameAre (@"
  5359. This
  5360. is
  5361. the
  5362. first
  5363. line.
  5364. This
  5365. is
  5366. the
  5367. secon
  5368. d
  5369. line.
  5370. ", output);
  5371. Assert.True (tv.MouseEvent (new MouseEvent () { X = 0, Y = 3, Flags = MouseFlags.Button1Pressed }));
  5372. tv.Redraw (tv.Bounds);
  5373. Assert.Equal (new Point (0, 3), tv.CursorPosition);
  5374. Assert.Equal (new Point (12, 0), cp);
  5375. GraphViewTests.AssertDriverContentsWithFrameAre (@"
  5376. This
  5377. is
  5378. the
  5379. first
  5380. line.
  5381. This
  5382. is
  5383. the
  5384. secon
  5385. d
  5386. line.
  5387. ", output);
  5388. }
  5389. }
  5390. }