TextViewTests.cs 238 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877
  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.True (_textView.Selecting);
  1273. _textView.Selecting = false;
  1274. _textView.ProcessKey (new KeyEvent (Key.Y | Key.CtrlMask, new KeyModifiers ())); // Paste
  1275. Assert.Equal ("TAB to jump between texttext fields.", _textView.Text);
  1276. _textView.SelectionStartColumn = 24;
  1277. _textView.SelectionStartRow = 0;
  1278. _textView.ProcessKey (new KeyEvent (Key.W | Key.CtrlMask, new KeyModifiers ())); // Cut
  1279. Assert.Equal ("", _textView.SelectedText);
  1280. Assert.Equal ("TAB to jump between text fields.", _textView.Text);
  1281. _textView.SelectionStartColumn = 0;
  1282. _textView.SelectionStartRow = 0;
  1283. Assert.True (_textView.Selecting);
  1284. _textView.Selecting = false;
  1285. _textView.ProcessKey (new KeyEvent (Key.Y | Key.CtrlMask, new KeyModifiers ())); // Paste
  1286. Assert.Equal ("TAB to jump between texttext fields.", _textView.Text);
  1287. }
  1288. [Fact]
  1289. [InitShutdown]
  1290. public void Cut_Not_Allowed_If_ReadOnly_Is_True ()
  1291. {
  1292. _textView.ReadOnly = true;
  1293. _textView.SelectionStartColumn = 20;
  1294. _textView.SelectionStartRow = 0;
  1295. _textView.CursorPosition = new Point (24, 0);
  1296. _textView.ProcessKey (new KeyEvent (Key.C | Key.CtrlMask, new KeyModifiers ())); // Copy
  1297. Assert.Equal ("text", _textView.SelectedText);
  1298. _textView.ProcessKey (new KeyEvent (Key.W | Key.CtrlMask, new KeyModifiers ())); // Selecting is set to false after Cut.
  1299. Assert.Equal ("", _textView.SelectedText);
  1300. _textView.ReadOnly = false;
  1301. Assert.False (_textView.Selecting);
  1302. _textView.Selecting = true; // Needed to set Selecting to true.
  1303. _textView.ProcessKey (new KeyEvent (Key.C | Key.CtrlMask, new KeyModifiers ())); // Copy
  1304. Assert.Equal ("text", _textView.SelectedText);
  1305. _textView.ProcessKey (new KeyEvent (Key.W | Key.CtrlMask, new KeyModifiers ())); // Cut
  1306. Assert.Equal ("", _textView.SelectedText);
  1307. }
  1308. [Fact]
  1309. [InitShutdown]
  1310. public void Paste_Always_Clear_The_SelectedText ()
  1311. {
  1312. _textView.SelectionStartColumn = 20;
  1313. _textView.SelectionStartRow = 0;
  1314. _textView.CursorPosition = new Point (24, 0);
  1315. _textView.ProcessKey (new KeyEvent (Key.C | Key.CtrlMask, new KeyModifiers ())); // Copy
  1316. Assert.Equal ("text", _textView.SelectedText);
  1317. _textView.ProcessKey (new KeyEvent (Key.Y | Key.CtrlMask, new KeyModifiers ())); // Paste
  1318. Assert.Equal ("", _textView.SelectedText);
  1319. }
  1320. [Fact]
  1321. [InitShutdown]
  1322. public void TextChanged_Event ()
  1323. {
  1324. _textView.TextChanged += () => {
  1325. if (_textView.Text == "changing") {
  1326. Assert.Equal ("changing", _textView.Text);
  1327. _textView.Text = "changed";
  1328. }
  1329. };
  1330. _textView.Text = "changing";
  1331. Assert.Equal ("changed", _textView.Text);
  1332. }
  1333. [Fact]
  1334. [InitShutdown]
  1335. public void Used_Is_True_By_Default ()
  1336. {
  1337. _textView.CursorPosition = new Point (10, 0);
  1338. Assert.Equal ("TAB to jump between text fields.", _textView.Text);
  1339. _textView.ProcessKey (new KeyEvent ((Key)0x75, new KeyModifiers ())); // u
  1340. Assert.Equal ("TAB to jumup between text fields.", _textView.Text);
  1341. _textView.ProcessKey (new KeyEvent ((Key)0x73, new KeyModifiers ())); // s
  1342. Assert.Equal ("TAB to jumusp between text fields.", _textView.Text);
  1343. _textView.ProcessKey (new KeyEvent ((Key)0x65, new KeyModifiers ())); // e
  1344. Assert.Equal ("TAB to jumusep between text fields.", _textView.Text);
  1345. _textView.ProcessKey (new KeyEvent ((Key)0x64, new KeyModifiers ())); // d
  1346. Assert.Equal ("TAB to jumusedp between text fields.", _textView.Text);
  1347. }
  1348. [Fact]
  1349. [InitShutdown]
  1350. public void Used_Is_False ()
  1351. {
  1352. _textView.Used = false;
  1353. _textView.CursorPosition = new Point (10, 0);
  1354. Assert.Equal ("TAB to jump between text fields.", _textView.Text);
  1355. _textView.ProcessKey (new KeyEvent ((Key)0x75, new KeyModifiers ())); // u
  1356. Assert.Equal ("TAB to jumu between text fields.", _textView.Text);
  1357. _textView.ProcessKey (new KeyEvent ((Key)0x73, new KeyModifiers ())); // s
  1358. Assert.Equal ("TAB to jumusbetween text fields.", _textView.Text);
  1359. _textView.ProcessKey (new KeyEvent ((Key)0x65, new KeyModifiers ())); // e
  1360. Assert.Equal ("TAB to jumuseetween text fields.", _textView.Text);
  1361. _textView.ProcessKey (new KeyEvent ((Key)0x64, new KeyModifiers ())); // d
  1362. Assert.Equal ("TAB to jumusedtween text fields.", _textView.Text);
  1363. }
  1364. [Fact]
  1365. [InitShutdown]
  1366. public void Copy_Without_Selection ()
  1367. {
  1368. _textView.Text = "This is the first line.\nThis is the second line.\n";
  1369. _textView.CursorPosition = new Point (0, _textView.Lines - 1);
  1370. _textView.ProcessKey (new KeyEvent (Key.C | Key.CtrlMask, new KeyModifiers ())); // Copy
  1371. _textView.ProcessKey (new KeyEvent (Key.Y | Key.CtrlMask, new KeyModifiers ())); // Paste
  1372. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}{Environment.NewLine}", _textView.Text);
  1373. _textView.CursorPosition = new Point (3, 1);
  1374. _textView.ProcessKey (new KeyEvent (Key.C | Key.CtrlMask, new KeyModifiers ())); // Copy
  1375. _textView.ProcessKey (new KeyEvent (Key.Y | Key.CtrlMask, new KeyModifiers ())); // Paste
  1376. 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);
  1377. Assert.Equal (new Point (3, 2), _textView.CursorPosition);
  1378. _textView.ProcessKey (new KeyEvent (Key.Y | Key.CtrlMask, new KeyModifiers ())); // Paste
  1379. 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);
  1380. Assert.Equal (new Point (3, 3), _textView.CursorPosition);
  1381. }
  1382. [Fact]
  1383. [InitShutdown]
  1384. public void TabWidth_Setting_To_Zero_Keeps_AllowsTab ()
  1385. {
  1386. Assert.Equal (4, _textView.TabWidth);
  1387. Assert.True (_textView.AllowsTab);
  1388. Assert.True (_textView.AllowsReturn);
  1389. Assert.True (_textView.Multiline);
  1390. _textView.TabWidth = -1;
  1391. Assert.Equal (0, _textView.TabWidth);
  1392. Assert.True (_textView.AllowsTab);
  1393. Assert.True (_textView.AllowsReturn);
  1394. Assert.True (_textView.Multiline);
  1395. _textView.ProcessKey (new KeyEvent (Key.Tab, new KeyModifiers ()));
  1396. Assert.Equal ("\tTAB to jump between text fields.", _textView.Text);
  1397. _textView.ProcessKey (new KeyEvent (Key.BackTab | Key.ShiftMask, new KeyModifiers ()));
  1398. Assert.Equal ("TAB to jump between text fields.", _textView.Text);
  1399. }
  1400. [Fact]
  1401. [InitShutdown]
  1402. public void AllowsTab_Setting_To_True_Changes_TabWidth_To_Default_If_It_Is_Zero ()
  1403. {
  1404. _textView.TabWidth = 0;
  1405. Assert.Equal (0, _textView.TabWidth);
  1406. Assert.True (_textView.AllowsTab);
  1407. Assert.True (_textView.AllowsReturn);
  1408. Assert.True (_textView.Multiline);
  1409. _textView.AllowsTab = true;
  1410. Assert.True (_textView.AllowsTab);
  1411. Assert.Equal (4, _textView.TabWidth);
  1412. Assert.True (_textView.AllowsReturn);
  1413. Assert.True (_textView.Multiline);
  1414. }
  1415. [Fact]
  1416. [InitShutdown]
  1417. public void AllowsReturn_Setting_To_True_Changes_Multiline_To_True_If_It_Is_False ()
  1418. {
  1419. Assert.True (_textView.AllowsReturn);
  1420. Assert.True (_textView.Multiline);
  1421. Assert.Equal (4, _textView.TabWidth);
  1422. Assert.True (_textView.AllowsTab);
  1423. _textView.ProcessKey (new KeyEvent (Key.Enter, new KeyModifiers ()));
  1424. Assert.Equal (Environment.NewLine +
  1425. "TAB to jump between text fields.", _textView.Text);
  1426. _textView.AllowsReturn = false;
  1427. Assert.False (_textView.AllowsReturn);
  1428. Assert.False (_textView.Multiline);
  1429. Assert.Equal (0, _textView.TabWidth);
  1430. Assert.False (_textView.AllowsTab);
  1431. _textView.ProcessKey (new KeyEvent (Key.Enter, new KeyModifiers ()));
  1432. Assert.Equal (Environment.NewLine +
  1433. "TAB to jump between text fields.", _textView.Text);
  1434. }
  1435. [Fact]
  1436. [InitShutdown]
  1437. public void Multiline_Setting_Changes_AllowsReturn_AllowsTab_Height_WordWrap ()
  1438. {
  1439. Assert.True (_textView.Multiline);
  1440. Assert.True (_textView.AllowsReturn);
  1441. Assert.Equal (4, _textView.TabWidth);
  1442. Assert.True (_textView.AllowsTab);
  1443. Assert.Equal ("Dim.Absolute(30)", _textView.Width.ToString ());
  1444. Assert.Equal ("Dim.Absolute(10)", _textView.Height.ToString ());
  1445. Assert.False (_textView.WordWrap);
  1446. _textView.WordWrap = true;
  1447. Assert.True (_textView.WordWrap);
  1448. _textView.Multiline = false;
  1449. Assert.False (_textView.Multiline);
  1450. Assert.False (_textView.AllowsReturn);
  1451. Assert.Equal (0, _textView.TabWidth);
  1452. Assert.False (_textView.AllowsTab);
  1453. Assert.Equal ("Dim.Absolute(30)", _textView.Width.ToString ());
  1454. Assert.Equal ("Dim.Absolute(1)", _textView.Height.ToString ());
  1455. Assert.False (_textView.WordWrap);
  1456. _textView.WordWrap = true;
  1457. Assert.False (_textView.WordWrap);
  1458. _textView.Multiline = true;
  1459. Assert.True (_textView.Multiline);
  1460. Assert.True (_textView.AllowsReturn);
  1461. Assert.Equal (4, _textView.TabWidth);
  1462. Assert.True (_textView.AllowsTab);
  1463. Assert.Equal ("Dim.Absolute(30)", _textView.Width.ToString ());
  1464. Assert.Equal ("Dim.Absolute(10)", _textView.Height.ToString ());
  1465. Assert.False (_textView.WordWrap);
  1466. }
  1467. [Fact]
  1468. [InitShutdown]
  1469. public void Tab_Test_Follow_By_BackTab ()
  1470. {
  1471. Application.Top.Add (_textView);
  1472. Application.Iteration += () => {
  1473. var width = _textView.Bounds.Width - 1;
  1474. Assert.Equal (30, width + 1);
  1475. Assert.Equal (10, _textView.Height);
  1476. _textView.Text = "";
  1477. var col = 0;
  1478. var leftCol = 0;
  1479. var tabWidth = _textView.TabWidth;
  1480. while (col < 100) {
  1481. col++;
  1482. _textView.ProcessKey (new KeyEvent (Key.Tab, new KeyModifiers ()));
  1483. Assert.Equal (new Point (col, 0), _textView.CursorPosition);
  1484. leftCol = GetLeftCol (leftCol);
  1485. Assert.Equal (leftCol, _textView.LeftColumn);
  1486. }
  1487. while (col > 0) {
  1488. col--;
  1489. _textView.ProcessKey (new KeyEvent (Key.BackTab | Key.ShiftMask, new KeyModifiers ()));
  1490. Assert.Equal (new Point (col, 0), _textView.CursorPosition);
  1491. leftCol = GetLeftCol (leftCol);
  1492. Assert.Equal (leftCol, _textView.LeftColumn);
  1493. }
  1494. Application.Top.Remove (_textView);
  1495. Application.RequestStop ();
  1496. };
  1497. Application.Run ();
  1498. }
  1499. [Fact]
  1500. [InitShutdown]
  1501. public void BackTab_Test_Follow_By_Tab ()
  1502. {
  1503. Application.Top.Add (_textView);
  1504. Application.Iteration += () => {
  1505. var width = _textView.Bounds.Width - 1;
  1506. Assert.Equal (30, width + 1);
  1507. Assert.Equal (10, _textView.Height);
  1508. _textView.Text = "";
  1509. for (int i = 0; i < 100; i++) {
  1510. _textView.Text += "\t";
  1511. }
  1512. var col = 100;
  1513. var tabWidth = _textView.TabWidth;
  1514. var leftCol = _textView.LeftColumn;
  1515. _textView.MoveEnd ();
  1516. Assert.Equal (new Point (col, 0), _textView.CursorPosition);
  1517. leftCol = GetLeftCol (leftCol);
  1518. Assert.Equal (leftCol, _textView.LeftColumn);
  1519. while (col > 0) {
  1520. col--;
  1521. _textView.ProcessKey (new KeyEvent (Key.BackTab | Key.ShiftMask, new KeyModifiers ()));
  1522. Assert.Equal (new Point (col, 0), _textView.CursorPosition);
  1523. leftCol = GetLeftCol (leftCol);
  1524. Assert.Equal (leftCol, _textView.LeftColumn);
  1525. }
  1526. while (col < 100) {
  1527. col++;
  1528. _textView.ProcessKey (new KeyEvent (Key.Tab, new KeyModifiers ()));
  1529. Assert.Equal (new Point (col, 0), _textView.CursorPosition);
  1530. leftCol = GetLeftCol (leftCol);
  1531. Assert.Equal (leftCol, _textView.LeftColumn);
  1532. }
  1533. Application.Top.Remove (_textView);
  1534. Application.RequestStop ();
  1535. };
  1536. Application.Run ();
  1537. }
  1538. [Fact]
  1539. [InitShutdown]
  1540. public void Tab_Test_Follow_By_CursorLeft_And_Then_Follow_By_CursorRight ()
  1541. {
  1542. Application.Top.Add (_textView);
  1543. Application.Iteration += () => {
  1544. var width = _textView.Bounds.Width - 1;
  1545. Assert.Equal (30, width + 1);
  1546. Assert.Equal (10, _textView.Height);
  1547. _textView.Text = "";
  1548. var col = 0;
  1549. var leftCol = 0;
  1550. var tabWidth = _textView.TabWidth;
  1551. while (col < 100) {
  1552. col++;
  1553. _textView.ProcessKey (new KeyEvent (Key.Tab, new KeyModifiers ()));
  1554. Assert.Equal (new Point (col, 0), _textView.CursorPosition);
  1555. leftCol = GetLeftCol (leftCol);
  1556. Assert.Equal (leftCol, _textView.LeftColumn);
  1557. }
  1558. while (col > 0) {
  1559. col--;
  1560. _textView.ProcessKey (new KeyEvent (Key.CursorLeft, new KeyModifiers ()));
  1561. Assert.Equal (new Point (col, 0), _textView.CursorPosition);
  1562. leftCol = GetLeftCol (leftCol);
  1563. Assert.Equal (leftCol, _textView.LeftColumn);
  1564. }
  1565. while (col < 100) {
  1566. col++;
  1567. _textView.ProcessKey (new KeyEvent (Key.CursorRight, new KeyModifiers ()));
  1568. Assert.Equal (new Point (col, 0), _textView.CursorPosition);
  1569. leftCol = GetLeftCol (leftCol);
  1570. Assert.Equal (leftCol, _textView.LeftColumn);
  1571. }
  1572. Application.Top.Remove (_textView);
  1573. Application.RequestStop ();
  1574. };
  1575. Application.Run ();
  1576. }
  1577. [Fact]
  1578. [InitShutdown]
  1579. public void Tab_Test_Follow_By_BackTab_With_Text ()
  1580. {
  1581. Application.Top.Add (_textView);
  1582. Application.Iteration += () => {
  1583. var width = _textView.Bounds.Width - 1;
  1584. Assert.Equal (30, width + 1);
  1585. Assert.Equal (10, _textView.Height);
  1586. var col = 0;
  1587. var leftCol = 0;
  1588. Assert.Equal (new Point (col, 0), _textView.CursorPosition);
  1589. Assert.Equal (leftCol, _textView.LeftColumn);
  1590. while (col < 100) {
  1591. col++;
  1592. _textView.ProcessKey (new KeyEvent (Key.Tab, new KeyModifiers ()));
  1593. Assert.Equal (new Point (col, 0), _textView.CursorPosition);
  1594. leftCol = GetLeftCol (leftCol);
  1595. Assert.Equal (leftCol, _textView.LeftColumn);
  1596. }
  1597. while (col > 0) {
  1598. col--;
  1599. _textView.ProcessKey (new KeyEvent (Key.BackTab | Key.ShiftMask, new KeyModifiers ()));
  1600. Assert.Equal (new Point (col, 0), _textView.CursorPosition);
  1601. leftCol = GetLeftCol (leftCol);
  1602. Assert.Equal (leftCol, _textView.LeftColumn);
  1603. }
  1604. Application.Top.Remove (_textView);
  1605. Application.RequestStop ();
  1606. };
  1607. Application.Run ();
  1608. }
  1609. [Fact]
  1610. [InitShutdown]
  1611. public void Tab_Test_Follow_By_Home_And_Then_Follow_By_End_And_Then_Follow_By_BackTab_With_Text ()
  1612. {
  1613. Application.Top.Add (_textView);
  1614. Application.Iteration += () => {
  1615. var width = _textView.Bounds.Width - 1;
  1616. Assert.Equal (30, width + 1);
  1617. Assert.Equal (10, _textView.Height);
  1618. var col = 0;
  1619. var leftCol = 0;
  1620. Assert.Equal (new Point (col, 0), _textView.CursorPosition);
  1621. Assert.Equal (leftCol, _textView.LeftColumn);
  1622. Assert.Equal ("TAB to jump between text fields.", _textView.Text);
  1623. Assert.Equal (32, _textView.Text.Length);
  1624. while (col < 100) {
  1625. col++;
  1626. _textView.ProcessKey (new KeyEvent (Key.Tab, new KeyModifiers ()));
  1627. Assert.Equal (new Point (col, 0), _textView.CursorPosition);
  1628. leftCol = GetLeftCol (leftCol);
  1629. Assert.Equal (leftCol, _textView.LeftColumn);
  1630. }
  1631. _textView.ProcessKey (new KeyEvent (Key.Home, new KeyModifiers ()));
  1632. col = 0;
  1633. Assert.Equal (new Point (col, 0), _textView.CursorPosition);
  1634. leftCol = 0;
  1635. Assert.Equal (leftCol, _textView.LeftColumn);
  1636. _textView.ProcessKey (new KeyEvent (Key.End, new KeyModifiers ()));
  1637. col = _textView.Text.Length;
  1638. Assert.Equal (132, _textView.Text.Length);
  1639. Assert.Equal (new Point (col, 0), _textView.CursorPosition);
  1640. leftCol = GetLeftCol (leftCol);
  1641. Assert.Equal (leftCol, _textView.LeftColumn);
  1642. var txt = _textView.Text;
  1643. while (col - 1 > 0 && txt [col - 1] != '\t') {
  1644. col--;
  1645. }
  1646. _textView.CursorPosition = new Point (col, 0);
  1647. leftCol = GetLeftCol (leftCol);
  1648. while (col > 0) {
  1649. col--;
  1650. _textView.ProcessKey (new KeyEvent (Key.BackTab | Key.ShiftMask, new KeyModifiers ()));
  1651. Assert.Equal (new Point (col, 0), _textView.CursorPosition);
  1652. leftCol = GetLeftCol (leftCol);
  1653. Assert.Equal (leftCol, _textView.LeftColumn);
  1654. }
  1655. Assert.Equal ("TAB to jump between text fields.", _textView.Text);
  1656. Assert.Equal (32, _textView.Text.Length);
  1657. Application.Top.Remove (_textView);
  1658. Application.RequestStop ();
  1659. };
  1660. Application.Run ();
  1661. }
  1662. [Fact]
  1663. [InitShutdown]
  1664. public void Tab_Test_Follow_By_CursorLeft_And_Then_Follow_By_CursorRight_With_Text ()
  1665. {
  1666. Application.Top.Add (_textView);
  1667. Application.Iteration += () => {
  1668. var width = _textView.Bounds.Width - 1;
  1669. Assert.Equal (30, width + 1);
  1670. Assert.Equal (10, _textView.Height);
  1671. Assert.Equal ("TAB to jump between text fields.", _textView.Text);
  1672. var col = 0;
  1673. var leftCol = 0;
  1674. var tabWidth = _textView.TabWidth;
  1675. while (col < 100) {
  1676. col++;
  1677. _textView.ProcessKey (new KeyEvent (Key.Tab, new KeyModifiers ()));
  1678. Assert.Equal (new Point (col, 0), _textView.CursorPosition);
  1679. leftCol = GetLeftCol (leftCol);
  1680. Assert.Equal (leftCol, _textView.LeftColumn);
  1681. }
  1682. Assert.Equal (132, _textView.Text.Length);
  1683. while (col > 0) {
  1684. col--;
  1685. _textView.ProcessKey (new KeyEvent (Key.CursorLeft, new KeyModifiers ()));
  1686. Assert.Equal (new Point (col, 0), _textView.CursorPosition);
  1687. leftCol = GetLeftCol (leftCol);
  1688. Assert.Equal (leftCol, _textView.LeftColumn);
  1689. }
  1690. while (col < 100) {
  1691. col++;
  1692. _textView.ProcessKey (new KeyEvent (Key.CursorRight, new KeyModifiers ()));
  1693. Assert.Equal (new Point (col, 0), _textView.CursorPosition);
  1694. leftCol = GetLeftCol (leftCol);
  1695. Assert.Equal (leftCol, _textView.LeftColumn);
  1696. }
  1697. Application.Top.Remove (_textView);
  1698. Application.RequestStop ();
  1699. };
  1700. Application.Run ();
  1701. }
  1702. [Fact]
  1703. public void TextView_MultiLine_But_Without_Tabs ()
  1704. {
  1705. var view = new TextView ();
  1706. // the default for TextView
  1707. Assert.True (view.Multiline);
  1708. view.AllowsTab = false;
  1709. Assert.False (view.AllowsTab);
  1710. Assert.True (view.Multiline);
  1711. }
  1712. private int GetLeftCol (int start)
  1713. {
  1714. var lines = _textView.Text.Split (Environment.NewLine);
  1715. if (lines == null || lines.Length == 0) {
  1716. return 0;
  1717. }
  1718. if (start == _textView.LeftColumn) {
  1719. return start;
  1720. }
  1721. if (_textView.LeftColumn == _textView.CurrentColumn) {
  1722. return _textView.CurrentColumn;
  1723. }
  1724. var cCol = _textView.CurrentColumn;
  1725. var line = lines [_textView.CurrentRow];
  1726. var lCount = cCol > line.Length - 1 ? line.Length - 1 : cCol;
  1727. var width = _textView.Frame.Width;
  1728. var tabWidth = _textView.TabWidth;
  1729. var sumLength = 0;
  1730. var col = 0;
  1731. for (int i = lCount; i >= 0; i--) {
  1732. var r = line [i];
  1733. sumLength += Rune.ColumnWidth (r);
  1734. if (r == '\t') {
  1735. sumLength += tabWidth + 1;
  1736. }
  1737. if (sumLength > width) {
  1738. if (col + width == cCol) {
  1739. col++;
  1740. }
  1741. break;
  1742. } else if ((cCol < line.Length && col > 0 && start < cCol && col == start) || (cCol - col == width - 1)) {
  1743. break;
  1744. }
  1745. col = i;
  1746. }
  1747. return col;
  1748. }
  1749. [Fact]
  1750. public void LoadFile_Throws_If_File_Is_Null ()
  1751. {
  1752. var result = false;
  1753. var tv = new TextView ();
  1754. Assert.Throws<ArgumentNullException> (() => result = tv.LoadFile (null));
  1755. Assert.False (result);
  1756. }
  1757. [Fact]
  1758. public void LoadFile_Throws_If_File_Is_Empty ()
  1759. {
  1760. var result = false;
  1761. var tv = new TextView ();
  1762. Assert.Throws<ArgumentException> (() => result = tv.LoadFile (""));
  1763. Assert.False (result);
  1764. }
  1765. [Fact]
  1766. public void LoadFile_Throws_If_File_Not_Exist ()
  1767. {
  1768. var result = false;
  1769. var tv = new TextView ();
  1770. Assert.Throws<System.IO.FileNotFoundException> (() => result = tv.LoadFile ("blabla"));
  1771. Assert.False (result);
  1772. }
  1773. [Fact]
  1774. public void LoadStream_Throws_If_Stream_Is_Null ()
  1775. {
  1776. var tv = new TextView ();
  1777. Assert.Throws<ArgumentNullException> (() => tv.LoadStream (null));
  1778. }
  1779. [Fact]
  1780. public void LoadStream_Stream_Is_Empty ()
  1781. {
  1782. var tv = new TextView ();
  1783. tv.LoadStream (new System.IO.MemoryStream ());
  1784. Assert.Equal ("", tv.Text);
  1785. }
  1786. [Fact]
  1787. public void LoadStream_CRLF ()
  1788. {
  1789. var text = "This is the first line.\r\nThis is the second line.\r\n";
  1790. var tv = new TextView ();
  1791. tv.LoadStream (new System.IO.MemoryStream (System.Text.Encoding.ASCII.GetBytes (text)));
  1792. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}", tv.Text);
  1793. }
  1794. [Fact]
  1795. public void LoadStream_LF ()
  1796. {
  1797. var text = "This is the first line.\nThis is the second line.\n";
  1798. var tv = new TextView ();
  1799. tv.LoadStream (new System.IO.MemoryStream (System.Text.Encoding.ASCII.GetBytes (text)));
  1800. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}", tv.Text);
  1801. }
  1802. [Fact]
  1803. public void StringToRunes_Slipts_CRLF ()
  1804. {
  1805. var text = "This is the first line.\r\nThis is the second line.\r\n";
  1806. var tv = new TextView ();
  1807. tv.Text = text;
  1808. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}", tv.Text);
  1809. }
  1810. [Fact]
  1811. public void StringToRunes_Slipts_LF ()
  1812. {
  1813. var text = "This is the first line.\nThis is the second line.\n";
  1814. var tv = new TextView ();
  1815. tv.Text = text;
  1816. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}", tv.Text);
  1817. }
  1818. [Fact]
  1819. public void CloseFile_Throws_If_FilePath_Is_Null ()
  1820. {
  1821. var tv = new TextView ();
  1822. Assert.Throws<ArgumentNullException> (() => tv.CloseFile ());
  1823. }
  1824. [Fact]
  1825. public void WordWrap_Gets_Sets ()
  1826. {
  1827. var tv = new TextView () { WordWrap = true };
  1828. Assert.True (tv.WordWrap);
  1829. tv.WordWrap = false;
  1830. Assert.False (tv.WordWrap);
  1831. }
  1832. [Fact]
  1833. public void WordWrap_True_Text_Always_Returns_Unwrapped ()
  1834. {
  1835. var text = "This is the first line.\nThis is the second line.\n";
  1836. var tv = new TextView () { Width = 10 };
  1837. tv.Text = text;
  1838. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}", tv.Text);
  1839. tv.WordWrap = true;
  1840. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}", tv.Text);
  1841. }
  1842. [Fact]
  1843. [InitShutdown]
  1844. public void WordWrap_WrapModel_Output ()
  1845. {
  1846. // 0123456789
  1847. var text = "This is the first line.\nThis is the second line.\n";
  1848. var tv = new TextView () { Width = 10, Height = 10 };
  1849. tv.Text = text;
  1850. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}", tv.Text);
  1851. tv.WordWrap = true;
  1852. Application.Top.Add (tv);
  1853. tv.Redraw (tv.Bounds);
  1854. GraphViewTests.AssertDriverContentsWithFrameAre (@"
  1855. This is
  1856. the
  1857. first
  1858. line.
  1859. This is
  1860. the
  1861. second
  1862. line.
  1863. ", output);
  1864. }
  1865. [Fact]
  1866. [AutoInitShutdown]
  1867. public void WordWrap_Deleting_Backwards ()
  1868. {
  1869. var tv = new TextView () {
  1870. Width = 5,
  1871. Height = 2,
  1872. WordWrap = true,
  1873. Text = "aaaa"
  1874. };
  1875. Application.Top.Add (tv);
  1876. Application.Begin (Application.Top);
  1877. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  1878. Assert.Equal (0, tv.LeftColumn);
  1879. GraphViewTests.AssertDriverContentsAre (@"
  1880. aaaa
  1881. ", output);
  1882. tv.CursorPosition = new Point (5, 0);
  1883. Assert.True (tv.ProcessKey (new KeyEvent (Key.Backspace, new KeyModifiers ())));
  1884. Application.Refresh ();
  1885. Assert.Equal (0, tv.LeftColumn);
  1886. GraphViewTests.AssertDriverContentsAre (@"
  1887. aaa
  1888. ", output);
  1889. Assert.True (tv.ProcessKey (new KeyEvent (Key.Backspace, new KeyModifiers ())));
  1890. Application.Refresh ();
  1891. Assert.Equal (0, tv.LeftColumn);
  1892. GraphViewTests.AssertDriverContentsAre (@"
  1893. aa
  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. a
  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. ", output);
  1906. Assert.True (tv.ProcessKey (new KeyEvent (Key.Backspace, new KeyModifiers ())));
  1907. Application.Refresh ();
  1908. Assert.Equal (0, tv.LeftColumn);
  1909. GraphViewTests.AssertDriverContentsAre (@"
  1910. ", output);
  1911. }
  1912. [Fact]
  1913. [InitShutdown]
  1914. public void WordWrap_ReadOnly_CursorPosition_SelectedText_Copy ()
  1915. {
  1916. // 0123456789
  1917. var text = "This is the first line.\nThis is the second line.\n";
  1918. var tv = new TextView () { Width = 11, Height = 9 };
  1919. tv.Text = text;
  1920. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}", tv.Text);
  1921. tv.WordWrap = true;
  1922. Application.Top.Add (tv);
  1923. tv.Redraw (tv.Bounds);
  1924. GraphViewTests.AssertDriverContentsWithFrameAre (@"
  1925. This is
  1926. the first
  1927. line.
  1928. This is
  1929. the
  1930. second
  1931. line.
  1932. ", output);
  1933. tv.ReadOnly = true;
  1934. tv.CursorPosition = new Point (6, 2);
  1935. Assert.Equal (new Point (5, 2), tv.CursorPosition);
  1936. tv.Redraw (tv.Bounds);
  1937. GraphViewTests.AssertDriverContentsWithFrameAre (@"
  1938. This is
  1939. the first
  1940. line.
  1941. This is
  1942. the
  1943. second
  1944. line.
  1945. ", output);
  1946. tv.SelectionStartRow = 0;
  1947. tv.SelectionStartColumn = 0;
  1948. Assert.Equal ("This is the first line.", tv.SelectedText);
  1949. tv.Copy ();
  1950. Assert.Equal ("This is the first line.", Clipboard.Contents);
  1951. }
  1952. [Fact]
  1953. public void Internal_Tests ()
  1954. {
  1955. var txt = "This is a text.";
  1956. var txtRunes = TextModel.ToRunes (txt);
  1957. Assert.Equal (txt.Length, txtRunes.Count);
  1958. Assert.Equal ('T', txtRunes [0]);
  1959. Assert.Equal ('h', txtRunes [1]);
  1960. Assert.Equal ('i', txtRunes [2]);
  1961. Assert.Equal ('s', txtRunes [3]);
  1962. Assert.Equal (' ', txtRunes [4]);
  1963. Assert.Equal ('i', txtRunes [5]);
  1964. Assert.Equal ('s', txtRunes [6]);
  1965. Assert.Equal (' ', txtRunes [7]);
  1966. Assert.Equal ('a', txtRunes [8]);
  1967. Assert.Equal (' ', txtRunes [9]);
  1968. Assert.Equal ('t', txtRunes [10]);
  1969. Assert.Equal ('e', txtRunes [11]);
  1970. Assert.Equal ('x', txtRunes [12]);
  1971. Assert.Equal ('t', txtRunes [13]);
  1972. Assert.Equal ('.', txtRunes [^1]);
  1973. int col = 0;
  1974. Assert.True (TextModel.SetCol (ref col, 80, 79));
  1975. Assert.False (TextModel.SetCol (ref col, 80, 80));
  1976. Assert.Equal (79, col);
  1977. var start = 0;
  1978. var x = 8;
  1979. Assert.Equal (8, TextModel.GetColFromX (txtRunes, start, x));
  1980. Assert.Equal ('a', txtRunes [start + x]);
  1981. start = 1;
  1982. x = 7;
  1983. Assert.Equal (7, TextModel.GetColFromX (txtRunes, start, x));
  1984. Assert.Equal ('a', txtRunes [start + x]);
  1985. Assert.Equal ((15, 15), TextModel.DisplaySize (txtRunes));
  1986. Assert.Equal ((6, 6), TextModel.DisplaySize (txtRunes, 1, 7));
  1987. Assert.Equal (0, TextModel.CalculateLeftColumn (txtRunes, 0, 7, 8));
  1988. Assert.Equal (1, TextModel.CalculateLeftColumn (txtRunes, 0, 8, 8));
  1989. Assert.Equal (2, TextModel.CalculateLeftColumn (txtRunes, 0, 9, 8));
  1990. var tm = new TextModel ();
  1991. tm.AddLine (0, TextModel.ToRunes ("This is first line."));
  1992. tm.AddLine (1, TextModel.ToRunes ("This is last line."));
  1993. Assert.Equal ((new Point (2, 0), true), tm.FindNextText ("is", out bool gaveFullTurn));
  1994. Assert.False (gaveFullTurn);
  1995. Assert.Equal ((new Point (5, 0), true), tm.FindNextText ("is", out gaveFullTurn));
  1996. Assert.False (gaveFullTurn);
  1997. Assert.Equal ((new Point (2, 1), true), tm.FindNextText ("is", out gaveFullTurn));
  1998. Assert.False (gaveFullTurn);
  1999. Assert.Equal ((new Point (5, 1), true), tm.FindNextText ("is", out gaveFullTurn));
  2000. Assert.False (gaveFullTurn);
  2001. Assert.Equal ((new Point (2, 0), true), tm.FindNextText ("is", out gaveFullTurn));
  2002. Assert.True (gaveFullTurn);
  2003. tm.ResetContinuousFind (new Point (0, 0));
  2004. Assert.Equal ((new Point (5, 1), true), tm.FindPreviousText ("is", out gaveFullTurn));
  2005. Assert.False (gaveFullTurn);
  2006. Assert.Equal ((new Point (2, 1), true), tm.FindPreviousText ("is", out gaveFullTurn));
  2007. Assert.False (gaveFullTurn);
  2008. Assert.Equal ((new Point (5, 0), true), tm.FindPreviousText ("is", out gaveFullTurn));
  2009. Assert.False (gaveFullTurn);
  2010. Assert.Equal ((new Point (2, 0), true), tm.FindPreviousText ("is", out gaveFullTurn));
  2011. Assert.False (gaveFullTurn);
  2012. Assert.Equal ((new Point (5, 1), true), tm.FindPreviousText ("is", out gaveFullTurn));
  2013. Assert.True (gaveFullTurn);
  2014. Assert.Equal ((new Point (9, 1), true), tm.ReplaceAllText ("is", false, false, "really"));
  2015. Assert.Equal (TextModel.ToRunes ("Threally really first line."), tm.GetLine (0));
  2016. Assert.Equal (TextModel.ToRunes ("Threally really last line."), tm.GetLine (1));
  2017. tm = new TextModel ();
  2018. tm.AddLine (0, TextModel.ToRunes ("This is first line."));
  2019. tm.AddLine (1, TextModel.ToRunes ("This is last line."));
  2020. Assert.Equal ((new Point (5, 1), true), tm.ReplaceAllText ("is", false, true, "really"));
  2021. Assert.Equal (TextModel.ToRunes ("This really first line."), tm.GetLine (0));
  2022. Assert.Equal (TextModel.ToRunes ("This really last line."), tm.GetLine (1));
  2023. }
  2024. [Fact]
  2025. [InitShutdown]
  2026. public void BottomOffset_Sets_To_Zero_Adjust_TopRow ()
  2027. {
  2028. string text = "";
  2029. for (int i = 0; i < 12; i++) {
  2030. text += $"This is the line {i}\n";
  2031. }
  2032. var tv = new TextView () { Width = 10, Height = 10, BottomOffset = 1 };
  2033. tv.Text = text;
  2034. tv.ProcessKey (new KeyEvent (Key.CtrlMask | Key.End, new KeyModifiers ()));
  2035. Assert.Equal (4, tv.TopRow);
  2036. Assert.Equal (1, tv.BottomOffset);
  2037. tv.BottomOffset = 0;
  2038. Assert.Equal (3, tv.TopRow);
  2039. Assert.Equal (0, tv.BottomOffset);
  2040. tv.BottomOffset = 2;
  2041. Assert.Equal (5, tv.TopRow);
  2042. Assert.Equal (2, tv.BottomOffset);
  2043. tv.BottomOffset = 0;
  2044. Assert.Equal (3, tv.TopRow);
  2045. Assert.Equal (0, tv.BottomOffset);
  2046. }
  2047. [Fact]
  2048. [InitShutdown]
  2049. public void RightOffset_Sets_To_Zero_Adjust_leftColumn ()
  2050. {
  2051. string text = "";
  2052. for (int i = 0; i < 12; i++) {
  2053. text += $"{i.ToString () [^1]}";
  2054. }
  2055. var tv = new TextView () { Width = 10, Height = 10, RightOffset = 1 };
  2056. tv.Text = text;
  2057. tv.ProcessKey (new KeyEvent (Key.End, new KeyModifiers ()));
  2058. Assert.Equal (4, tv.LeftColumn);
  2059. Assert.Equal (1, tv.RightOffset);
  2060. tv.RightOffset = 0;
  2061. Assert.Equal (3, tv.LeftColumn);
  2062. Assert.Equal (0, tv.RightOffset);
  2063. tv.RightOffset = 2;
  2064. Assert.Equal (5, tv.LeftColumn);
  2065. Assert.Equal (2, tv.RightOffset);
  2066. tv.RightOffset = 0;
  2067. Assert.Equal (3, tv.LeftColumn);
  2068. Assert.Equal (0, tv.RightOffset);
  2069. }
  2070. [Fact]
  2071. [InitShutdown]
  2072. public void TextView_SpaceHandling ()
  2073. {
  2074. var tv = new TextView () {
  2075. Width = 10,
  2076. Text = " "
  2077. };
  2078. MouseEvent ev = new MouseEvent () {
  2079. X = 0,
  2080. Y = 0,
  2081. Flags = MouseFlags.Button1DoubleClicked,
  2082. };
  2083. tv.MouseEvent (ev);
  2084. Assert.Equal (1, tv.SelectedLength);
  2085. ev = new MouseEvent () {
  2086. X = 1,
  2087. Y = 0,
  2088. Flags = MouseFlags.Button1DoubleClicked,
  2089. };
  2090. tv.MouseEvent (ev);
  2091. Assert.Equal (1, tv.SelectedLength);
  2092. }
  2093. [Fact]
  2094. [InitShutdown]
  2095. public void CanFocus_False_Wont_Focus_With_Mouse ()
  2096. {
  2097. var top = Application.Top;
  2098. var tv = new TextView () {
  2099. Width = Dim.Fill (),
  2100. CanFocus = false,
  2101. ReadOnly = true,
  2102. Text = "some text"
  2103. };
  2104. var fv = new FrameView ("I shouldn't get focus") {
  2105. Width = Dim.Fill (),
  2106. Height = Dim.Fill (),
  2107. CanFocus = false,
  2108. };
  2109. fv.Add (tv);
  2110. top.Add (fv);
  2111. Application.Begin (top);
  2112. Assert.False (tv.CanFocus);
  2113. Assert.False (tv.HasFocus);
  2114. Assert.False (fv.CanFocus);
  2115. Assert.False (fv.HasFocus);
  2116. tv.MouseEvent (new MouseEvent () {
  2117. X = 1,
  2118. Y = 0,
  2119. Flags = MouseFlags.Button1DoubleClicked
  2120. });
  2121. Assert.Empty (tv.SelectedText);
  2122. Assert.False (tv.CanFocus);
  2123. Assert.False (tv.HasFocus);
  2124. Assert.False (fv.CanFocus);
  2125. Assert.False (fv.HasFocus);
  2126. Assert.Throws<InvalidOperationException> (() => tv.CanFocus = true);
  2127. fv.CanFocus = true;
  2128. tv.CanFocus = true;
  2129. tv.MouseEvent (new MouseEvent () {
  2130. X = 1,
  2131. Y = 0,
  2132. Flags = MouseFlags.Button1DoubleClicked
  2133. });
  2134. Assert.Equal ("some ", tv.SelectedText);
  2135. Assert.True (tv.CanFocus);
  2136. Assert.True (tv.HasFocus);
  2137. Assert.True (fv.CanFocus);
  2138. Assert.True (fv.HasFocus);
  2139. fv.CanFocus = false;
  2140. tv.MouseEvent (new MouseEvent () {
  2141. X = 1,
  2142. Y = 0,
  2143. Flags = MouseFlags.Button1DoubleClicked
  2144. });
  2145. Assert.Equal ("some ", tv.SelectedText); // Setting CanFocus to false don't change the SelectedText
  2146. Assert.False (tv.CanFocus);
  2147. Assert.False (tv.HasFocus);
  2148. Assert.False (fv.CanFocus);
  2149. Assert.False (fv.HasFocus);
  2150. }
  2151. [Fact]
  2152. [InitShutdown]
  2153. public void DesiredCursorVisibility_Vertical_Navigation ()
  2154. {
  2155. string text = "";
  2156. for (int i = 0; i < 12; i++) {
  2157. text += $"This is the line {i}\n";
  2158. }
  2159. var tv = new TextView () { Width = 10, Height = 10 };
  2160. tv.Text = text;
  2161. Assert.Equal (0, tv.TopRow);
  2162. tv.PositionCursor ();
  2163. Assert.Equal (CursorVisibility.Default, tv.DesiredCursorVisibility);
  2164. for (int i = 0; i < 12; i++) {
  2165. tv.MouseEvent (new MouseEvent () {
  2166. Flags = MouseFlags.WheeledDown
  2167. });
  2168. tv.PositionCursor ();
  2169. Assert.Equal (i + 1, tv.TopRow);
  2170. Assert.Equal (CursorVisibility.Invisible, tv.DesiredCursorVisibility);
  2171. }
  2172. for (int i = 12; i > 0; i--) {
  2173. tv.MouseEvent (new MouseEvent () {
  2174. Flags = MouseFlags.WheeledUp
  2175. });
  2176. tv.PositionCursor ();
  2177. Assert.Equal (i - 1, tv.TopRow);
  2178. if (i - 1 == 0) {
  2179. Assert.Equal (CursorVisibility.Default, tv.DesiredCursorVisibility);
  2180. } else {
  2181. Assert.Equal (CursorVisibility.Invisible, tv.DesiredCursorVisibility);
  2182. }
  2183. }
  2184. }
  2185. [Fact]
  2186. [InitShutdown]
  2187. public void DesiredCursorVisibility_Horizontal_Navigation ()
  2188. {
  2189. string text = "";
  2190. for (int i = 0; i < 12; i++) {
  2191. text += $"{i.ToString () [^1]}";
  2192. }
  2193. var tv = new TextView () { Width = 10, Height = 10 };
  2194. tv.Text = text;
  2195. Assert.Equal (0, tv.LeftColumn);
  2196. tv.PositionCursor ();
  2197. Assert.Equal (CursorVisibility.Default, tv.DesiredCursorVisibility);
  2198. for (int i = 0; i < 12; i++) {
  2199. tv.MouseEvent (new MouseEvent () {
  2200. Flags = MouseFlags.WheeledRight
  2201. });
  2202. tv.PositionCursor ();
  2203. Assert.Equal (Math.Min (i + 1, 11), tv.LeftColumn);
  2204. Assert.Equal (CursorVisibility.Invisible, tv.DesiredCursorVisibility);
  2205. }
  2206. for (int i = 11; i > 0; i--) {
  2207. tv.MouseEvent (new MouseEvent () {
  2208. Flags = MouseFlags.WheeledLeft
  2209. });
  2210. tv.PositionCursor ();
  2211. Assert.Equal (i - 1, tv.LeftColumn);
  2212. if (i - 1 == 0) {
  2213. Assert.Equal (CursorVisibility.Default, tv.DesiredCursorVisibility);
  2214. } else {
  2215. Assert.Equal (CursorVisibility.Invisible, tv.DesiredCursorVisibility);
  2216. }
  2217. }
  2218. }
  2219. [Fact]
  2220. public void LeftColumn_Add_One_If_Text_Length_Is_Equal_To_Width ()
  2221. {
  2222. var tv = new TextView () {
  2223. Width = 10,
  2224. Text = "1234567890"
  2225. };
  2226. Assert.Equal (Point.Empty, tv.CursorPosition);
  2227. Assert.Equal (0, tv.LeftColumn);
  2228. tv.CursorPosition = new Point (9, 0);
  2229. Assert.Equal (new Point (9, 0), tv.CursorPosition);
  2230. Assert.Equal (0, tv.LeftColumn);
  2231. Assert.True (tv.ProcessKey (new KeyEvent (Key.CursorRight, new KeyModifiers ())));
  2232. tv.CursorPosition = new Point (10, 0);
  2233. Assert.Equal (new Point (10, 0), tv.CursorPosition);
  2234. Assert.Equal (1, tv.LeftColumn);
  2235. }
  2236. [Fact]
  2237. [AutoInitShutdown]
  2238. public void KeyBindings_Command ()
  2239. {
  2240. var text = "This is the first line.\nThis is the second line.\nThis is the third line.";
  2241. var tv = new TextView () {
  2242. Width = 10,
  2243. Height = 2,
  2244. Text = text
  2245. };
  2246. var top = Application.Top;
  2247. top.Add (tv);
  2248. Application.Begin (top);
  2249. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  2250. Assert.Equal (3, tv.Lines);
  2251. Assert.Equal (Point.Empty, tv.CursorPosition);
  2252. Assert.False (tv.ReadOnly);
  2253. Assert.True (tv.CanFocus);
  2254. tv.CanFocus = false;
  2255. Assert.True (tv.ProcessKey (new KeyEvent (Key.CursorLeft, new KeyModifiers ())));
  2256. tv.CanFocus = true;
  2257. Assert.False (tv.ProcessKey (new KeyEvent (Key.CursorLeft, new KeyModifiers ())));
  2258. Assert.True (tv.ProcessKey (new KeyEvent (Key.CursorRight, new KeyModifiers ())));
  2259. Assert.Equal (new Point (1, 0), tv.CursorPosition);
  2260. Assert.True (tv.ProcessKey (new KeyEvent (Key.End | Key.CtrlMask, new KeyModifiers ())));
  2261. Assert.Equal (2, tv.CurrentRow);
  2262. Assert.Equal (23, tv.CurrentColumn);
  2263. Assert.Equal (tv.CurrentColumn, tv.GetCurrentLine ().Count);
  2264. Assert.Equal (new Point (23, 2), tv.CursorPosition);
  2265. Assert.False (tv.ProcessKey (new KeyEvent (Key.CursorRight, new KeyModifiers ())));
  2266. Assert.NotNull (tv.Autocomplete);
  2267. Assert.Empty (tv.Autocomplete.AllSuggestions);
  2268. Assert.True (tv.ProcessKey (new KeyEvent (Key.F, new KeyModifiers ())));
  2269. tv.Redraw (tv.Bounds);
  2270. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.F", tv.Text);
  2271. Assert.Equal (new Point (24, 2), tv.CursorPosition);
  2272. Assert.Empty (tv.Autocomplete.Suggestions);
  2273. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  2274. tv.Redraw (tv.Bounds);
  2275. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  2276. Assert.Equal (new Point (23, 2), tv.CursorPosition);
  2277. Assert.Empty (tv.Autocomplete.Suggestions);
  2278. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  2279. tv.Redraw (tv.Bounds);
  2280. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.F", tv.Text);
  2281. Assert.Equal (new Point (24, 2), tv.CursorPosition);
  2282. Assert.Empty (tv.Autocomplete.Suggestions);
  2283. Assert.True (tv.ProcessKey (new KeyEvent (Key.Backspace, new KeyModifiers ())));
  2284. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  2285. Assert.Equal (new Point (23, 2), tv.CursorPosition);
  2286. tv.Autocomplete.AllSuggestions = Regex.Matches (tv.Text.ToString (), "\\w+")
  2287. .Select (s => s.Value)
  2288. .Distinct ().ToList ();
  2289. Assert.Equal (7, tv.Autocomplete.AllSuggestions.Count);
  2290. Assert.Equal ("This", tv.Autocomplete.AllSuggestions [0]);
  2291. Assert.Equal ("is", tv.Autocomplete.AllSuggestions [1]);
  2292. Assert.Equal ("the", tv.Autocomplete.AllSuggestions [2]);
  2293. Assert.Equal ("first", tv.Autocomplete.AllSuggestions [3]);
  2294. Assert.Equal ("line", tv.Autocomplete.AllSuggestions [4]);
  2295. Assert.Equal ("second", tv.Autocomplete.AllSuggestions [5]);
  2296. Assert.Equal ("third", tv.Autocomplete.AllSuggestions [^1]);
  2297. Assert.True (tv.ProcessKey (new KeyEvent (Key.F, new KeyModifiers ())));
  2298. tv.Redraw (tv.Bounds);
  2299. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.F", tv.Text);
  2300. Assert.Equal (new Point (24, 2), tv.CursorPosition);
  2301. Assert.Single (tv.Autocomplete.Suggestions);
  2302. Assert.Equal ("first", tv.Autocomplete.Suggestions [0]);
  2303. Assert.True (tv.ProcessKey (new KeyEvent (Key.Enter, new KeyModifiers ())));
  2304. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first", tv.Text);
  2305. Assert.Equal (new Point (28, 2), tv.CursorPosition);
  2306. Assert.Single (tv.Autocomplete.Suggestions);
  2307. Assert.Equal ("first", tv.Autocomplete.Suggestions [0]);
  2308. tv.Autocomplete.AllSuggestions = new List<string> ();
  2309. tv.Autocomplete.ClearSuggestions ();
  2310. Assert.Empty (tv.Autocomplete.AllSuggestions);
  2311. Assert.Empty (tv.Autocomplete.Suggestions);
  2312. Assert.True (tv.ProcessKey (new KeyEvent (Key.PageUp, new KeyModifiers ())));
  2313. Assert.Equal (24, tv.GetCurrentLine ().Count);
  2314. Assert.Equal (new Point (24, 1), tv.CursorPosition);
  2315. Assert.True (tv.ProcessKey (new KeyEvent (((int)'V' + Key.AltMask), new KeyModifiers ())));
  2316. Assert.Equal (23, tv.GetCurrentLine ().Count);
  2317. Assert.Equal (new Point (23, 0), tv.CursorPosition);
  2318. Assert.True (tv.ProcessKey (new KeyEvent (Key.PageDown, new KeyModifiers ())));
  2319. Assert.Equal (24, tv.GetCurrentLine ().Count);
  2320. Assert.Equal (new Point (23, 1), tv.CursorPosition); // gets the previous length
  2321. Assert.True (tv.ProcessKey (new KeyEvent (Key.V | Key.CtrlMask, new KeyModifiers ())));
  2322. Assert.Equal (28, tv.GetCurrentLine ().Count);
  2323. Assert.Equal (new Point (23, 2), tv.CursorPosition); // gets the previous length
  2324. Assert.Equal (0, tv.SelectedLength);
  2325. Assert.Equal ("", tv.SelectedText);
  2326. Assert.True (tv.ProcessKey (new KeyEvent (Key.PageUp | Key.ShiftMask, new KeyModifiers ())));
  2327. Assert.Equal (24, tv.GetCurrentLine ().Count);
  2328. Assert.Equal (new Point (23, 1), tv.CursorPosition); // gets the previous length
  2329. Assert.Equal (24 + Environment.NewLine.Length, tv.SelectedLength);
  2330. Assert.Equal ($".{Environment.NewLine}This is the third line.", tv.SelectedText);
  2331. Assert.True (tv.ProcessKey (new KeyEvent (Key.PageDown | Key.ShiftMask, new KeyModifiers ())));
  2332. Assert.Equal (28, tv.GetCurrentLine ().Count);
  2333. Assert.Equal (new Point (23, 2), tv.CursorPosition); // gets the previous length
  2334. Assert.Equal (0, tv.SelectedLength);
  2335. Assert.Equal ("", tv.SelectedText);
  2336. Assert.True (tv.ProcessKey (new KeyEvent (Key.Home | Key.CtrlMask, new KeyModifiers ())));
  2337. Assert.Equal (Point.Empty, tv.CursorPosition);
  2338. Assert.True (tv.ProcessKey (new KeyEvent (Key.N | Key.CtrlMask, new KeyModifiers ())));
  2339. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  2340. Assert.Equal (0, tv.SelectedLength);
  2341. Assert.Equal ("", tv.SelectedText);
  2342. Assert.True (tv.ProcessKey (new KeyEvent (Key.P | Key.CtrlMask, new KeyModifiers ())));
  2343. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  2344. Assert.Equal (0, tv.SelectedLength);
  2345. Assert.Equal ("", tv.SelectedText);
  2346. Assert.True (tv.ProcessKey (new KeyEvent (Key.CursorDown, new KeyModifiers ())));
  2347. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  2348. Assert.Equal (0, tv.SelectedLength);
  2349. Assert.Equal ("", tv.SelectedText);
  2350. Assert.True (tv.ProcessKey (new KeyEvent (Key.CursorUp, new KeyModifiers ())));
  2351. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  2352. Assert.Equal (0, tv.SelectedLength);
  2353. Assert.Equal ("", tv.SelectedText);
  2354. Assert.True (tv.ProcessKey (new KeyEvent (Key.CursorDown | Key.ShiftMask, new KeyModifiers ())));
  2355. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  2356. Assert.Equal (23 + Environment.NewLine.Length, tv.SelectedLength);
  2357. Assert.Equal ($"This is the first line.{Environment.NewLine}", tv.SelectedText);
  2358. Assert.True (tv.ProcessKey (new KeyEvent (Key.CursorUp | Key.ShiftMask, new KeyModifiers ())));
  2359. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  2360. Assert.Equal (0, tv.SelectedLength);
  2361. Assert.Equal ("", tv.SelectedText);
  2362. Assert.True (tv.ProcessKey (new KeyEvent (Key.F | Key.CtrlMask, new KeyModifiers ())));
  2363. Assert.Equal (new Point (1, 0), tv.CursorPosition);
  2364. Assert.Equal (0, tv.SelectedLength);
  2365. Assert.Equal ("", tv.SelectedText);
  2366. Assert.True (tv.ProcessKey (new KeyEvent (Key.B | Key.CtrlMask, new KeyModifiers ())));
  2367. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  2368. Assert.Equal (0, tv.SelectedLength);
  2369. Assert.Equal ("", tv.SelectedText);
  2370. Assert.True (tv.ProcessKey (new KeyEvent (Key.CursorRight, new KeyModifiers ())));
  2371. Assert.Equal (new Point (1, 0), tv.CursorPosition);
  2372. Assert.Equal (0, tv.SelectedLength);
  2373. Assert.Equal ("", tv.SelectedText);
  2374. Assert.True (tv.ProcessKey (new KeyEvent (Key.CursorLeft, new KeyModifiers ())));
  2375. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  2376. Assert.Equal (0, tv.SelectedLength);
  2377. Assert.Equal ("", tv.SelectedText);
  2378. Assert.False (tv.Selecting);
  2379. Assert.True (tv.ProcessKey (new KeyEvent (Key.CursorRight | Key.ShiftMask, new KeyModifiers ())));
  2380. Assert.Equal (new Point (1, 0), tv.CursorPosition);
  2381. Assert.Equal (1, tv.SelectedLength);
  2382. Assert.Equal ("T", tv.SelectedText);
  2383. Assert.True (tv.Selecting);
  2384. Assert.True (tv.ProcessKey (new KeyEvent (Key.CursorLeft | Key.ShiftMask, new KeyModifiers ())));
  2385. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  2386. Assert.Equal (0, tv.SelectedLength);
  2387. Assert.Equal ("", tv.SelectedText);
  2388. Assert.True (tv.Selecting);
  2389. Assert.True (tv.ProcessKey (new KeyEvent (Key.DeleteChar, new KeyModifiers ())));
  2390. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first", tv.Text);
  2391. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  2392. Assert.Equal (0, tv.SelectedLength);
  2393. Assert.Equal ("", tv.SelectedText);
  2394. Assert.False (tv.Selecting);
  2395. Assert.True (tv.ProcessKey (new KeyEvent (Key.DeleteChar, new KeyModifiers ())));
  2396. Assert.Equal ($"his 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.D | Key.CtrlMask, new KeyModifiers ())));
  2402. Assert.Equal ($"is 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.True (tv.ProcessKey (new KeyEvent (Key.End, new KeyModifiers ())));
  2405. Assert.Equal ($"is is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first", tv.Text);
  2406. Assert.Equal (new Point (21, 0), tv.CursorPosition);
  2407. Assert.True (tv.ProcessKey (new KeyEvent (Key.Delete, 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 (20, 0), tv.CursorPosition);
  2410. Assert.True (tv.ProcessKey (new KeyEvent (Key.Backspace, new KeyModifiers ())));
  2411. Assert.Equal ($"is is the first lin{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first", tv.Text);
  2412. Assert.Equal (new Point (19, 0), tv.CursorPosition);
  2413. Assert.True (tv.ProcessKey (new KeyEvent (Key.Home, new KeyModifiers ())));
  2414. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  2415. Assert.Equal (0, tv.SelectedLength);
  2416. Assert.Equal ("", tv.SelectedText);
  2417. Assert.False (tv.Selecting);
  2418. Assert.True (tv.ProcessKey (new KeyEvent (Key.End | Key.ShiftMask, new KeyModifiers ())));
  2419. Assert.Equal (new Point (19, 0), tv.CursorPosition);
  2420. Assert.Equal (19, tv.SelectedLength);
  2421. Assert.Equal ("is is the first lin", tv.SelectedText);
  2422. Assert.True (tv.Selecting);
  2423. Assert.True (tv.ProcessKey (new KeyEvent (Key.Home | Key.ShiftMask, new KeyModifiers ())));
  2424. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  2425. Assert.Equal (0, tv.SelectedLength);
  2426. Assert.Equal ("", tv.SelectedText);
  2427. Assert.True (tv.Selecting);
  2428. Assert.True (tv.ProcessKey (new KeyEvent (Key.E | Key.CtrlMask, new KeyModifiers ())));
  2429. Assert.Equal (new Point (19, 0), tv.CursorPosition);
  2430. Assert.Equal (0, tv.SelectedLength);
  2431. Assert.Equal ("", tv.SelectedText);
  2432. Assert.False (tv.Selecting);
  2433. Assert.True (tv.ProcessKey (new KeyEvent (Key.A | Key.CtrlMask, new KeyModifiers ())));
  2434. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  2435. Assert.Equal (0, tv.SelectedLength);
  2436. Assert.Equal ("", tv.SelectedText);
  2437. Assert.False (tv.Selecting);
  2438. Assert.True (tv.ProcessKey (new KeyEvent (Key.K | Key.CtrlMask, new KeyModifiers ())));
  2439. Assert.Equal ($"{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first", tv.Text);
  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.Equal ("is is the first lin", Clipboard.Contents);
  2445. Assert.True (tv.ProcessKey (new KeyEvent (Key.Y | Key.CtrlMask, new KeyModifiers ())));
  2446. Assert.Equal ($"is is the first lin{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first", tv.Text);
  2447. Assert.Equal (new Point (19, 0), tv.CursorPosition);
  2448. Assert.Equal (0, tv.SelectedLength);
  2449. Assert.Equal ("", tv.SelectedText);
  2450. Assert.False (tv.Selecting);
  2451. Assert.Equal ("is is the first lin", Clipboard.Contents);
  2452. tv.CursorPosition = Point.Empty;
  2453. Assert.True (tv.ProcessKey (new KeyEvent (Key.DeleteChar | Key.CtrlMask | Key.ShiftMask, new KeyModifiers ())));
  2454. Assert.Equal ($"{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first", tv.Text);
  2455. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  2456. Assert.Equal (0, tv.SelectedLength);
  2457. Assert.Equal ("", tv.SelectedText);
  2458. Assert.False (tv.Selecting);
  2459. Assert.Equal ("is is the first lin", Clipboard.Contents);
  2460. Assert.True (tv.ProcessKey (new KeyEvent (Key.Y | Key.CtrlMask, new KeyModifiers ())));
  2461. Assert.Equal ($"is is the first lin{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first", tv.Text);
  2462. Assert.Equal (new Point (19, 0), tv.CursorPosition);
  2463. Assert.Equal (0, tv.SelectedLength);
  2464. Assert.Equal ("", tv.SelectedText);
  2465. Assert.False (tv.Selecting);
  2466. Assert.Equal ("is is the first lin", Clipboard.Contents);
  2467. Assert.True (tv.ProcessKey (new KeyEvent (Key.K | Key.AltMask, new KeyModifiers ())));
  2468. Assert.Equal ($"{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first", tv.Text);
  2469. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  2470. Assert.Equal (0, tv.SelectedLength);
  2471. Assert.Equal ("", tv.SelectedText);
  2472. Assert.False (tv.Selecting);
  2473. tv.ReadOnly = true;
  2474. Assert.True (tv.ProcessKey (new KeyEvent (Key.Y | Key.CtrlMask, new KeyModifiers ())));
  2475. Assert.Equal ($"{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first", tv.Text);
  2476. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  2477. Assert.Equal (0, tv.SelectedLength);
  2478. Assert.Equal ("", tv.SelectedText);
  2479. Assert.False (tv.Selecting);
  2480. tv.ReadOnly = false;
  2481. Assert.True (tv.ProcessKey (new KeyEvent (Key.Y | Key.CtrlMask, new KeyModifiers ())));
  2482. Assert.Equal ($"is is the first lin{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first", tv.Text);
  2483. Assert.Equal (new Point (19, 0), tv.CursorPosition);
  2484. Assert.Equal (0, tv.SelectedLength);
  2485. Assert.Equal ("", tv.SelectedText);
  2486. Assert.False (tv.Selecting);
  2487. Assert.Equal (0, tv.SelectionStartColumn);
  2488. Assert.Equal (0, tv.SelectionStartRow);
  2489. Assert.True (tv.ProcessKey (new KeyEvent (Key.Space | Key.CtrlMask, new KeyModifiers ())));
  2490. Assert.Equal ($"is is the first lin{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first", tv.Text);
  2491. Assert.Equal (new Point (19, 0), tv.CursorPosition);
  2492. Assert.Equal (0, tv.SelectedLength);
  2493. Assert.Equal ("", tv.SelectedText);
  2494. Assert.True (tv.Selecting);
  2495. Assert.Equal (19, tv.SelectionStartColumn);
  2496. Assert.Equal (0, tv.SelectionStartRow);
  2497. Assert.True (tv.ProcessKey (new KeyEvent (Key.Space | Key.CtrlMask, new KeyModifiers ())));
  2498. Assert.Equal ($"is is the first lin{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first", tv.Text);
  2499. Assert.Equal (new Point (19, 0), tv.CursorPosition);
  2500. Assert.Equal (0, tv.SelectedLength);
  2501. Assert.Equal ("", tv.SelectedText);
  2502. Assert.False (tv.Selecting);
  2503. Assert.Equal (19, tv.SelectionStartColumn);
  2504. Assert.Equal (0, tv.SelectionStartRow);
  2505. tv.SelectionStartColumn = 0;
  2506. Assert.True (tv.ProcessKey (new KeyEvent (((int)'C' + Key.AltMask), new KeyModifiers ())));
  2507. Assert.Equal ($"is is the first lin{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first", tv.Text);
  2508. Assert.Equal (new Point (19, 0), tv.CursorPosition);
  2509. Assert.Equal (19, tv.SelectedLength);
  2510. Assert.Equal ("is is the first lin", tv.SelectedText);
  2511. Assert.True (tv.Selecting);
  2512. Assert.Equal (0, tv.SelectionStartColumn);
  2513. Assert.Equal (0, tv.SelectionStartRow);
  2514. Assert.True (tv.ProcessKey (new KeyEvent (Key.C | Key.CtrlMask, new KeyModifiers ())));
  2515. Assert.Equal ($"is is the first lin{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first", tv.Text);
  2516. Assert.Equal (new Point (19, 0), tv.CursorPosition);
  2517. Assert.Equal (19, tv.SelectedLength);
  2518. Assert.Equal ("is is the first lin", tv.SelectedText);
  2519. Assert.True (tv.Selecting);
  2520. Assert.Equal (0, tv.SelectionStartColumn);
  2521. Assert.Equal (0, tv.SelectionStartRow);
  2522. Assert.True (tv.ProcessKey (new KeyEvent (((int)'W' + Key.AltMask), new KeyModifiers ())));
  2523. Assert.Equal ($"{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first", tv.Text);
  2524. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  2525. Assert.Equal (0, tv.SelectedLength);
  2526. Assert.Equal ("", tv.SelectedText);
  2527. Assert.False (tv.Selecting);
  2528. Assert.Equal (0, tv.SelectionStartColumn);
  2529. Assert.Equal (0, tv.SelectionStartRow);
  2530. Assert.Equal ("is is the first lin", Clipboard.Contents);
  2531. Assert.True (tv.ProcessKey (new KeyEvent (Key.W | Key.CtrlMask, new KeyModifiers ())));
  2532. Assert.Equal ($"{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first", tv.Text);
  2533. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  2534. Assert.Equal (0, tv.SelectedLength);
  2535. Assert.Equal ("", tv.SelectedText);
  2536. Assert.False (tv.Selecting);
  2537. Assert.Equal (0, tv.SelectionStartColumn);
  2538. Assert.Equal (0, tv.SelectionStartRow);
  2539. Assert.Equal ("", Clipboard.Contents);
  2540. Assert.True (tv.ProcessKey (new KeyEvent (Key.X | Key.CtrlMask, new KeyModifiers ())));
  2541. Assert.Equal ($"{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first", tv.Text);
  2542. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  2543. Assert.Equal (0, tv.SelectedLength);
  2544. Assert.Equal ("", tv.SelectedText);
  2545. Assert.False (tv.Selecting);
  2546. Assert.Equal (0, tv.SelectionStartColumn);
  2547. Assert.Equal (0, tv.SelectionStartRow);
  2548. Assert.Equal ("", Clipboard.Contents);
  2549. Assert.True (tv.ProcessKey (new KeyEvent (Key.End | Key.CtrlMask, new KeyModifiers ())));
  2550. Assert.Equal ($"{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first", tv.Text);
  2551. Assert.Equal (new Point (28, 2), tv.CursorPosition);
  2552. Assert.Equal (0, tv.SelectedLength);
  2553. Assert.Equal ("", tv.SelectedText);
  2554. Assert.False (tv.Selecting);
  2555. Assert.True (tv.ProcessKey (new KeyEvent (Key.CtrlMask | Key.CursorLeft, 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 (18, 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 | Key.ShiftMask, 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 (12, 2), tv.CursorPosition);
  2564. Assert.Equal (6, tv.SelectedLength);
  2565. Assert.Equal ("third ", tv.SelectedText);
  2566. Assert.True (tv.Selecting);
  2567. Assert.True (tv.ProcessKey (new KeyEvent ((Key)((int)'B' + Key.AltMask), 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 (8, 2), tv.CursorPosition);
  2570. Assert.Equal (0, tv.SelectedLength);
  2571. Assert.Equal ("", tv.SelectedText);
  2572. Assert.False (tv.Selecting);
  2573. Assert.True (tv.ProcessKey (new KeyEvent (Key.CtrlMask | Key.CursorRight, 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 (12, 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 | Key.ShiftMask, 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 (18, 2), tv.CursorPosition);
  2582. Assert.Equal (6, tv.SelectedLength);
  2583. Assert.Equal ("third ", tv.SelectedText);
  2584. Assert.True (tv.Selecting);
  2585. Assert.True (tv.ProcessKey (new KeyEvent ((Key)((int)'F' + Key.AltMask), 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 (28, 2), tv.CursorPosition);
  2588. Assert.Equal (0, tv.SelectedLength);
  2589. Assert.Equal ("", tv.SelectedText);
  2590. Assert.False (tv.Selecting);
  2591. Assert.True (tv.ProcessKey (new KeyEvent (Key.Home | Key.CtrlMask, 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 (0, 0), 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.DeleteChar | Key.CtrlMask, new KeyModifiers ())));
  2598. Assert.Equal ($"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); Assert.True (tv.ProcessKey (new KeyEvent (Key.End | Key.CtrlMask, new KeyModifiers ())));
  2603. Assert.Equal ($"This is the second line.{Environment.NewLine}This is the third line.first", tv.Text);
  2604. Assert.Equal (new Point (28, 1), tv.CursorPosition);
  2605. Assert.Equal (0, tv.SelectedLength);
  2606. Assert.Equal ("", tv.SelectedText);
  2607. Assert.False (tv.Selecting);
  2608. Assert.False (tv.Selecting); Assert.True (tv.ProcessKey (new KeyEvent (Key.Backspace | Key.CtrlMask, new KeyModifiers ())));
  2609. Assert.Equal ($"This is the second line.{Environment.NewLine}This is the third ", tv.Text);
  2610. Assert.Equal (new Point (18, 1), tv.CursorPosition);
  2611. Assert.Equal (0, tv.SelectedLength);
  2612. Assert.Equal ("", tv.SelectedText);
  2613. Assert.False (tv.Selecting);
  2614. Assert.True (tv.AllowsReturn);
  2615. tv.AllowsReturn = false;
  2616. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  2617. Assert.False (tv.Selecting);
  2618. Assert.False (tv.ProcessKey (new KeyEvent (Key.Enter, new KeyModifiers ())));
  2619. Assert.Equal ($"This is the second line.{Environment.NewLine}This is the third ", tv.Text);
  2620. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  2621. Assert.Equal (0, tv.SelectedLength);
  2622. Assert.Equal ("", tv.SelectedText);
  2623. Assert.False (tv.Selecting);
  2624. Assert.False (tv.AllowsReturn);
  2625. tv.AllowsReturn = true;
  2626. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  2627. Assert.True (tv.ProcessKey (new KeyEvent (Key.Enter, new KeyModifiers ())));
  2628. Assert.Equal ($"{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third ", tv.Text);
  2629. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  2630. Assert.Equal (0, tv.SelectedLength);
  2631. Assert.Equal ("", tv.SelectedText);
  2632. Assert.False (tv.Selecting);
  2633. Assert.True (tv.AllowsReturn);
  2634. Assert.True (tv.ProcessKey (new KeyEvent (Key.CtrlMask | Key.End | Key.ShiftMask, new KeyModifiers ())));
  2635. Assert.Equal ($"{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third ", tv.Text);
  2636. Assert.Equal (new Point (18, 2), tv.CursorPosition);
  2637. Assert.Equal (42 + Environment.NewLine.Length, tv.SelectedLength);
  2638. Assert.Equal ($"This is the second line.{Environment.NewLine}This is the third ", tv.SelectedText);
  2639. Assert.True (tv.Selecting);
  2640. Assert.True (tv.ProcessKey (new KeyEvent (Key.CtrlMask | Key.Home | 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 (0, 0), tv.CursorPosition);
  2643. Assert.Equal (Environment.NewLine.Length, tv.SelectedLength);
  2644. Assert.Equal ($"{Environment.NewLine}", tv.SelectedText);
  2645. Assert.True (tv.Selecting);
  2646. Assert.True (tv.ProcessKey (new KeyEvent (Key.T | Key.CtrlMask, 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 (18, 2), tv.CursorPosition);
  2649. Assert.Equal (42 + Environment.NewLine.Length * 2, tv.SelectedLength);
  2650. Assert.Equal ($"{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third ", tv.SelectedText);
  2651. Assert.True (tv.Selecting);
  2652. Assert.True (tv.Used);
  2653. Assert.True (tv.ProcessKey (new KeyEvent (Key.InsertChar, new KeyModifiers ())));
  2654. Assert.False (tv.Used);
  2655. Assert.True (tv.AllowsTab);
  2656. Assert.Equal (new Point (18, 2), tv.CursorPosition);
  2657. tv.AllowsTab = false;
  2658. Assert.False (tv.ProcessKey (new KeyEvent (Key.Tab, new KeyModifiers ())));
  2659. Assert.Equal ($"{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third ", tv.Text);
  2660. Assert.False (tv.AllowsTab);
  2661. tv.AllowsTab = true;
  2662. Assert.Equal (new Point (18, 2), tv.CursorPosition);
  2663. Assert.True (tv.Selecting);
  2664. tv.Selecting = false;
  2665. Assert.True (tv.ProcessKey (new KeyEvent (Key.Tab, new KeyModifiers ())));
  2666. Assert.Equal ($"{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third \t", tv.Text);
  2667. Assert.True (tv.AllowsTab);
  2668. tv.AllowsTab = false;
  2669. Assert.False (tv.ProcessKey (new KeyEvent (Key.BackTab | Key.ShiftMask, new KeyModifiers ())));
  2670. Assert.Equal ($"{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third \t", tv.Text);
  2671. Assert.False (tv.AllowsTab);
  2672. tv.AllowsTab = true;
  2673. Assert.True (tv.ProcessKey (new KeyEvent (Key.BackTab | Key.ShiftMask, new KeyModifiers ())));
  2674. Assert.Equal ($"{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third ", tv.Text);
  2675. Assert.True (tv.AllowsTab);
  2676. Assert.False (tv.ProcessKey (new KeyEvent (Key.Tab | Key.CtrlMask, new KeyModifiers ())));
  2677. Assert.False (tv.ProcessKey (new KeyEvent (Application.AlternateForwardKey, new KeyModifiers ())));
  2678. Assert.False (tv.ProcessKey (new KeyEvent (Key.Tab | Key.CtrlMask | Key.ShiftMask, new KeyModifiers ())));
  2679. Assert.False (tv.ProcessKey (new KeyEvent (Application.AlternateBackwardKey, new KeyModifiers ())));
  2680. }
  2681. [Fact]
  2682. public void HistoryText_Exceptions ()
  2683. {
  2684. var ht = new HistoryText ();
  2685. foreach (var ls in Enum.GetValues (typeof (HistoryText.LineStatus))) {
  2686. if ((HistoryText.LineStatus)ls != HistoryText.LineStatus.Original) {
  2687. Assert.Throws<ArgumentException> (() => ht.Add (new List<List<Rune>> () { new List<Rune> () }, Point.Empty,
  2688. (HistoryText.LineStatus)ls));
  2689. }
  2690. }
  2691. Assert.Null (Record.Exception (() => ht.Add (new List<List<Rune>> () { new List<Rune> () }, Point.Empty,
  2692. HistoryText.LineStatus.Original)));
  2693. }
  2694. [Fact]
  2695. [AutoInitShutdown]
  2696. public void HistoryText_Undo_Redo_Single_Line_InsertText ()
  2697. {
  2698. var text = "This is the first line.\nThis is the second line.\nThis is the third line.";
  2699. var tv = new TextView () {
  2700. Width = 10,
  2701. Height = 2,
  2702. Text = text
  2703. };
  2704. var top = Application.Top;
  2705. top.Add (tv);
  2706. Application.Begin (top);
  2707. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  2708. Assert.Equal (3, tv.Lines);
  2709. Assert.Equal (Point.Empty, tv.CursorPosition);
  2710. var messy = " messy";
  2711. tv.CursorPosition = new Point (7, 1);
  2712. tv.InsertText (messy);
  2713. Assert.Equal ($"This is the first line.{Environment.NewLine}This is messy the second line.{Environment.NewLine}This is the third line.", tv.Text);
  2714. Assert.Equal (3, tv.Lines);
  2715. Assert.Equal (new Point (13, 1), tv.CursorPosition);
  2716. for (int i = 0; i < messy.Length; i++) {
  2717. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  2718. }
  2719. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  2720. Assert.Equal (3, tv.Lines);
  2721. Assert.Equal (new Point (7, 1), tv.CursorPosition);
  2722. for (int i = 0; i < messy.Length; i++) {
  2723. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  2724. }
  2725. Assert.Equal ($"This is the first line.{Environment.NewLine}This is messy the second line.{Environment.NewLine}This is the third line.", tv.Text);
  2726. Assert.Equal (3, tv.Lines);
  2727. Assert.Equal (new Point (13, 1), tv.CursorPosition);
  2728. }
  2729. [Fact]
  2730. [AutoInitShutdown]
  2731. public void HistoryText_Undo_Redo_Single_Line_DeleteCharLeft ()
  2732. {
  2733. var text = "This is the first line.\nThis is the second line.\nThis is the third line.";
  2734. var tv = new TextView () {
  2735. Width = 10,
  2736. Height = 2,
  2737. Text = text
  2738. };
  2739. var top = Application.Top;
  2740. top.Add (tv);
  2741. Application.Begin (top);
  2742. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  2743. Assert.Equal (3, tv.Lines);
  2744. Assert.Equal (Point.Empty, tv.CursorPosition);
  2745. var ntimes = 3;
  2746. tv.CursorPosition = new Point (7, 1);
  2747. for (int i = 0; i < ntimes; i++) {
  2748. tv.DeleteCharLeft ();
  2749. }
  2750. Assert.Equal ($"This is the first line.{Environment.NewLine}This the second line.{Environment.NewLine}This is the third line.", tv.Text);
  2751. Assert.Equal (3, tv.Lines);
  2752. Assert.Equal (new Point (4, 1), tv.CursorPosition);
  2753. for (int i = 0; i < ntimes; i++) {
  2754. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  2755. }
  2756. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  2757. Assert.Equal (3, tv.Lines);
  2758. Assert.Equal (new Point (7, 1), tv.CursorPosition);
  2759. for (int i = 0; i < ntimes; i++) {
  2760. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  2761. }
  2762. Assert.Equal ($"This is the first line.{Environment.NewLine}This the second line.{Environment.NewLine}This is the third line.", tv.Text);
  2763. Assert.Equal (3, tv.Lines);
  2764. Assert.Equal (new Point (4, 1), tv.CursorPosition);
  2765. }
  2766. [Fact]
  2767. [AutoInitShutdown]
  2768. public void HistoryText_Undo_Redo_Single_Line_DeleteCharRight ()
  2769. {
  2770. var text = "This is the first line.\nThis is the second line.\nThis is the third line.";
  2771. var tv = new TextView () {
  2772. Width = 10,
  2773. Height = 2,
  2774. Text = text
  2775. };
  2776. var top = Application.Top;
  2777. top.Add (tv);
  2778. Application.Begin (top);
  2779. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  2780. Assert.Equal (3, tv.Lines);
  2781. Assert.Equal (Point.Empty, tv.CursorPosition);
  2782. var ntimes = 3;
  2783. tv.CursorPosition = new Point (7, 1);
  2784. for (int i = 0; i < ntimes; i++) {
  2785. tv.DeleteCharRight ();
  2786. }
  2787. Assert.Equal ($"This is the first line.{Environment.NewLine}This ise second line.{Environment.NewLine}This is the third line.", tv.Text);
  2788. Assert.Equal (3, tv.Lines);
  2789. Assert.Equal (new Point (7, 1), tv.CursorPosition);
  2790. for (int i = 0; i < ntimes; i++) {
  2791. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  2792. }
  2793. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the 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.R | Key.CtrlMask, new KeyModifiers ())));
  2798. }
  2799. Assert.Equal ($"This is the first line.{Environment.NewLine}This ise 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. }
  2803. [Fact]
  2804. [AutoInitShutdown]
  2805. public void HistoryText_Undo_Redo_Single_Line_Selected_InsertText ()
  2806. {
  2807. var text = "This is the first line.\nThis is the second line.\nThis is the third line.";
  2808. var tv = new TextView () {
  2809. Width = 10,
  2810. Height = 2,
  2811. Text = text
  2812. };
  2813. var top = Application.Top;
  2814. top.Add (tv);
  2815. Application.Begin (top);
  2816. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  2817. Assert.Equal (3, tv.Lines);
  2818. Assert.Equal (Point.Empty, tv.CursorPosition);
  2819. var messy = " messy";
  2820. tv.CursorPosition = new Point (7, 1);
  2821. tv.SelectionStartColumn = 11;
  2822. tv.SelectionStartRow = 1;
  2823. Assert.Equal (4, tv.SelectedLength);
  2824. tv.InsertText (messy);
  2825. Assert.Equal ($"This is the first line.{Environment.NewLine}This is messy second line.{Environment.NewLine}This is the third line.", tv.Text);
  2826. Assert.Equal (3, tv.Lines);
  2827. Assert.Equal (new Point (13, 1), tv.CursorPosition);
  2828. Assert.Equal (11, tv.SelectionStartColumn);
  2829. Assert.Equal (1, tv.SelectionStartRow);
  2830. Assert.Equal (0, tv.SelectedLength);
  2831. for (int i = 0; i < messy.Length; i++) {
  2832. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  2833. }
  2834. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  2835. Assert.Equal (3, tv.Lines);
  2836. Assert.Equal (new Point (7, 1), tv.CursorPosition);
  2837. Assert.Equal (11, tv.SelectionStartColumn);
  2838. Assert.Equal (1, tv.SelectionStartRow);
  2839. Assert.Equal (0, tv.SelectedLength);
  2840. for (int i = 0; i < messy.Length; i++) {
  2841. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  2842. }
  2843. Assert.Equal ($"This is the first line.{Environment.NewLine}This is messy second line.{Environment.NewLine}This is the third line.", tv.Text);
  2844. Assert.Equal (3, tv.Lines);
  2845. Assert.Equal (new Point (13, 1), tv.CursorPosition);
  2846. Assert.Equal (11, tv.SelectionStartColumn);
  2847. Assert.Equal (1, tv.SelectionStartRow);
  2848. Assert.Equal (0, tv.SelectedLength);
  2849. }
  2850. [Fact]
  2851. [AutoInitShutdown]
  2852. public void HistoryText_Undo_Redo_Single_Line_Selected_DeleteCharLeft ()
  2853. {
  2854. var text = "This is the first line.\nThis is the second line.\nThis is the third line.";
  2855. var tv = new TextView () {
  2856. Width = 10,
  2857. Height = 2,
  2858. Text = text
  2859. };
  2860. var top = Application.Top;
  2861. top.Add (tv);
  2862. Application.Begin (top);
  2863. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  2864. Assert.Equal (3, tv.Lines);
  2865. Assert.Equal (Point.Empty, tv.CursorPosition);
  2866. var ntimes = 3;
  2867. tv.CursorPosition = new Point (7, 1);
  2868. tv.SelectionStartColumn = 11;
  2869. tv.SelectionStartRow = 1;
  2870. Assert.Equal (4, tv.SelectedLength);
  2871. for (int i = 0; i < ntimes; i++) {
  2872. tv.DeleteCharLeft ();
  2873. }
  2874. Assert.Equal ($"This is the first line.{Environment.NewLine}This second line.{Environment.NewLine}This is the third line.", tv.Text);
  2875. Assert.Equal (3, tv.Lines);
  2876. Assert.Equal (new Point (5, 1), tv.CursorPosition);
  2877. Assert.Equal (11, tv.SelectionStartColumn);
  2878. Assert.Equal (1, tv.SelectionStartRow);
  2879. Assert.Equal (0, tv.SelectedLength);
  2880. for (int i = 0; i < ntimes; i++) {
  2881. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  2882. }
  2883. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  2884. Assert.Equal (3, tv.Lines);
  2885. Assert.Equal (new Point (7, 1), tv.CursorPosition);
  2886. Assert.Equal (11, tv.SelectionStartColumn);
  2887. Assert.Equal (1, tv.SelectionStartRow);
  2888. Assert.Equal (0, tv.SelectedLength);
  2889. for (int i = 0; i < ntimes; i++) {
  2890. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  2891. }
  2892. Assert.Equal ($"This is the first line.{Environment.NewLine}This second line.{Environment.NewLine}This is the third line.", tv.Text);
  2893. Assert.Equal (3, tv.Lines);
  2894. Assert.Equal (new Point (5, 1), tv.CursorPosition);
  2895. Assert.Equal (11, tv.SelectionStartColumn);
  2896. Assert.Equal (1, tv.SelectionStartRow);
  2897. Assert.Equal (0, tv.SelectedLength);
  2898. }
  2899. [Fact]
  2900. [AutoInitShutdown]
  2901. public void HistoryText_Undo_Redo_Single_Line_Selected_DeleteCharRight ()
  2902. {
  2903. var text = "This is the first line.\nThis is the second line.\nThis is the third line.";
  2904. var tv = new TextView () {
  2905. Width = 10,
  2906. Height = 2,
  2907. Text = text
  2908. };
  2909. var top = Application.Top;
  2910. top.Add (tv);
  2911. Application.Begin (top);
  2912. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  2913. Assert.Equal (3, tv.Lines);
  2914. Assert.Equal (Point.Empty, tv.CursorPosition);
  2915. var ntimes = 3;
  2916. tv.CursorPosition = new Point (7, 1);
  2917. tv.SelectionStartColumn = 11;
  2918. tv.SelectionStartRow = 1;
  2919. Assert.Equal (4, tv.SelectedLength);
  2920. for (int i = 0; i < ntimes; i++) {
  2921. tv.DeleteCharRight ();
  2922. }
  2923. Assert.Equal ($"This is the first line.{Environment.NewLine}This isecond line.{Environment.NewLine}This is the third line.", tv.Text);
  2924. Assert.Equal (3, tv.Lines);
  2925. Assert.Equal (new Point (7, 1), tv.CursorPosition);
  2926. Assert.Equal (11, tv.SelectionStartColumn);
  2927. Assert.Equal (1, tv.SelectionStartRow);
  2928. Assert.Equal (0, tv.SelectedLength);
  2929. for (int i = 0; i < ntimes; i++) {
  2930. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  2931. }
  2932. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  2933. Assert.Equal (3, tv.Lines);
  2934. Assert.Equal (new Point (7, 1), tv.CursorPosition);
  2935. Assert.Equal (11, tv.SelectionStartColumn);
  2936. Assert.Equal (1, tv.SelectionStartRow);
  2937. Assert.Equal (0, tv.SelectedLength);
  2938. for (int i = 0; i < ntimes; i++) {
  2939. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  2940. }
  2941. Assert.Equal ($"This is the first line.{Environment.NewLine}This isecond line.{Environment.NewLine}This is the third line.", tv.Text);
  2942. Assert.Equal (3, tv.Lines);
  2943. Assert.Equal (new Point (7, 1), tv.CursorPosition);
  2944. Assert.Equal (11, tv.SelectionStartColumn);
  2945. Assert.Equal (1, tv.SelectionStartRow);
  2946. Assert.Equal (0, tv.SelectedLength);
  2947. }
  2948. [Fact]
  2949. [AutoInitShutdown]
  2950. public void HistoryText_Undo_Redo_Multi_Line_InsertText ()
  2951. {
  2952. var text = "This is the first line.\nThis is the second line.\nThis is the third line.";
  2953. var tv = new TextView () {
  2954. Width = 10,
  2955. Height = 2,
  2956. Text = text
  2957. };
  2958. var top = Application.Top;
  2959. top.Add (tv);
  2960. Application.Begin (top);
  2961. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  2962. Assert.Equal (3, tv.Lines);
  2963. Assert.Equal (Point.Empty, tv.CursorPosition);
  2964. var messy = " messy";
  2965. tv.CursorPosition = new Point (7, 1);
  2966. tv.InsertText (messy);
  2967. Assert.Equal ($"This is the first line.{Environment.NewLine}This is messy the second line.{Environment.NewLine}This is the third line.", tv.Text);
  2968. Assert.Equal (3, tv.Lines);
  2969. Assert.Equal (new Point (13, 1), tv.CursorPosition);
  2970. tv.CursorPosition = new Point (7, 0);
  2971. tv.InsertText (messy);
  2972. 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);
  2973. Assert.Equal (3, tv.Lines);
  2974. Assert.Equal (new Point (13, 0), tv.CursorPosition);
  2975. tv.CursorPosition = new Point (7, 2);
  2976. tv.InsertText (messy);
  2977. 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);
  2978. Assert.Equal (3, tv.Lines);
  2979. Assert.Equal (new Point (13, 2), tv.CursorPosition);
  2980. for (int i = 0; i < messy.Length; i++) {
  2981. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  2982. }
  2983. 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);
  2984. Assert.Equal (3, tv.Lines);
  2985. Assert.Equal (new Point (7, 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 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, 0), 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 the second line.{Environment.NewLine}This is the third line.", tv.Text);
  2996. Assert.Equal (3, tv.Lines);
  2997. Assert.Equal (new Point (7, 1), tv.CursorPosition);
  2998. for (int i = 0; i < messy.Length; i++) {
  2999. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  3000. }
  3001. Assert.Equal ($"This is the first line.{Environment.NewLine}This is messy the second line.{Environment.NewLine}This is the third line.", tv.Text);
  3002. Assert.Equal (3, tv.Lines);
  3003. Assert.Equal (new Point (13, 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 messy 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, 0), 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 messy the third line.", tv.Text);
  3014. Assert.Equal (3, tv.Lines);
  3015. Assert.Equal (new Point (13, 2), tv.CursorPosition);
  3016. }
  3017. [Fact]
  3018. [AutoInitShutdown]
  3019. public void HistoryText_Undo_Redo_Multi_Line_DeleteCharLeft ()
  3020. {
  3021. var text = "This is the first line.\nThis is the second line.\nThis is the third line.";
  3022. var tv = new TextView () {
  3023. Width = 10,
  3024. Height = 2,
  3025. Text = text
  3026. };
  3027. var top = Application.Top;
  3028. top.Add (tv);
  3029. Application.Begin (top);
  3030. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  3031. Assert.Equal (3, tv.Lines);
  3032. Assert.Equal (Point.Empty, tv.CursorPosition);
  3033. var ntimes = 3;
  3034. tv.CursorPosition = new Point (7, 1);
  3035. for (int i = 0; i < ntimes; i++) {
  3036. tv.DeleteCharLeft ();
  3037. }
  3038. Assert.Equal ($"This is the first line.{Environment.NewLine}This the second line.{Environment.NewLine}This is the third line.", tv.Text);
  3039. Assert.Equal (3, tv.Lines);
  3040. Assert.Equal (new Point (4, 1), tv.CursorPosition);
  3041. tv.CursorPosition = new Point (7, 0);
  3042. for (int i = 0; i < ntimes; i++) {
  3043. tv.DeleteCharLeft ();
  3044. }
  3045. Assert.Equal ($"This the first line.{Environment.NewLine}This the second line.{Environment.NewLine}This is the third line.", tv.Text);
  3046. Assert.Equal (3, tv.Lines);
  3047. Assert.Equal (new Point (4, 0), tv.CursorPosition);
  3048. tv.CursorPosition = new Point (7, 2);
  3049. for (int i = 0; i < ntimes; i++) {
  3050. tv.DeleteCharLeft ();
  3051. }
  3052. Assert.Equal ($"This the first line.{Environment.NewLine}This the second line.{Environment.NewLine}This the third line.", tv.Text);
  3053. Assert.Equal (3, tv.Lines);
  3054. Assert.Equal (new Point (4, 2), tv.CursorPosition);
  3055. for (int i = 0; i < ntimes; i++) {
  3056. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  3057. switch (i) {
  3058. case 0:
  3059. Assert.Equal ($"This the first line.{Environment.NewLine}This the second line.{Environment.NewLine}This the third line.", tv.Text);
  3060. Assert.Equal (new Point (5, 2), tv.CursorPosition);
  3061. break;
  3062. case 1:
  3063. Assert.Equal ($"This the first line.{Environment.NewLine}This the second line.{Environment.NewLine}This i the third line.", tv.Text);
  3064. Assert.Equal (new Point (6, 2), tv.CursorPosition);
  3065. break;
  3066. case 2:
  3067. Assert.Equal ($"This the first line.{Environment.NewLine}This the second line.{Environment.NewLine}This is the third line.", tv.Text);
  3068. Assert.Equal (new Point (7, 2), tv.CursorPosition);
  3069. break;
  3070. }
  3071. }
  3072. Assert.Equal ($"This the first line.{Environment.NewLine}This the second line.{Environment.NewLine}This is the third line.", tv.Text);
  3073. Assert.Equal (3, tv.Lines);
  3074. Assert.Equal (new Point (7, 2), tv.CursorPosition);
  3075. for (int i = 0; i < ntimes; i++) {
  3076. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  3077. switch (i) {
  3078. case 0:
  3079. Assert.Equal ($"This the first line.{Environment.NewLine}This the second line.{Environment.NewLine}This is the third line.", tv.Text);
  3080. Assert.Equal (new Point (5, 0), tv.CursorPosition);
  3081. break;
  3082. case 1:
  3083. Assert.Equal ($"This i the first line.{Environment.NewLine}This the second line.{Environment.NewLine}This is the third line.", tv.Text);
  3084. Assert.Equal (new Point (6, 0), tv.CursorPosition);
  3085. break;
  3086. case 2:
  3087. Assert.Equal ($"This is the first line.{Environment.NewLine}This the second line.{Environment.NewLine}This is the third line.", tv.Text);
  3088. Assert.Equal (new Point (7, 0), tv.CursorPosition);
  3089. break;
  3090. }
  3091. }
  3092. Assert.Equal ($"This is the first line.{Environment.NewLine}This the second line.{Environment.NewLine}This is the third line.", tv.Text);
  3093. Assert.Equal (3, tv.Lines);
  3094. Assert.Equal (new Point (7, 0), tv.CursorPosition);
  3095. for (int i = 0; i < ntimes; i++) {
  3096. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  3097. switch (i) {
  3098. case 0:
  3099. Assert.Equal ($"This is the first line.{Environment.NewLine}This the second line.{Environment.NewLine}This is the third line.", tv.Text);
  3100. Assert.Equal (new Point (5, 1), tv.CursorPosition);
  3101. break;
  3102. case 1:
  3103. Assert.Equal ($"This is the first line.{Environment.NewLine}This i the second line.{Environment.NewLine}This is the third line.", tv.Text);
  3104. Assert.Equal (new Point (6, 1), tv.CursorPosition);
  3105. break;
  3106. case 2:
  3107. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  3108. Assert.Equal (new Point (7, 1), tv.CursorPosition);
  3109. break;
  3110. }
  3111. }
  3112. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  3113. Assert.Equal (3, tv.Lines);
  3114. Assert.Equal (new Point (7, 1), tv.CursorPosition);
  3115. for (int i = 0; i < ntimes; i++) {
  3116. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  3117. }
  3118. Assert.Equal ($"This is the first line.{Environment.NewLine}This the second line.{Environment.NewLine}This is the third line.", tv.Text);
  3119. Assert.Equal (3, tv.Lines);
  3120. Assert.Equal (new Point (4, 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 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, 0), 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 the third line.", tv.Text);
  3131. Assert.Equal (3, tv.Lines);
  3132. Assert.Equal (new Point (4, 2), tv.CursorPosition);
  3133. }
  3134. [Fact]
  3135. [AutoInitShutdown]
  3136. public void HistoryText_Undo_Redo_Multi_Line_DeleteCharRight ()
  3137. {
  3138. var text = "This is the first line.\nThis is the second line.\nThis is the third line.";
  3139. var tv = new TextView () {
  3140. Width = 10,
  3141. Height = 2,
  3142. Text = text
  3143. };
  3144. var top = Application.Top;
  3145. top.Add (tv);
  3146. Application.Begin (top);
  3147. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  3148. Assert.Equal (3, tv.Lines);
  3149. Assert.Equal (Point.Empty, tv.CursorPosition);
  3150. var ntimes = 3;
  3151. tv.CursorPosition = new Point (7, 1);
  3152. for (int i = 0; i < ntimes; i++) {
  3153. tv.DeleteCharRight ();
  3154. }
  3155. Assert.Equal ($"This is the first line.{Environment.NewLine}This ise second line.{Environment.NewLine}This is the third line.", tv.Text);
  3156. Assert.Equal (3, tv.Lines);
  3157. Assert.Equal (new Point (7, 1), tv.CursorPosition);
  3158. tv.CursorPosition = new Point (7, 0);
  3159. for (int i = 0; i < ntimes; i++) {
  3160. tv.DeleteCharRight ();
  3161. }
  3162. Assert.Equal ($"This ise first line.{Environment.NewLine}This ise second line.{Environment.NewLine}This is the third line.", tv.Text);
  3163. Assert.Equal (3, tv.Lines);
  3164. Assert.Equal (new Point (7, 0), tv.CursorPosition);
  3165. tv.CursorPosition = new Point (7, 2);
  3166. for (int i = 0; i < ntimes; i++) {
  3167. tv.DeleteCharRight ();
  3168. }
  3169. Assert.Equal ($"This ise first line.{Environment.NewLine}This ise second line.{Environment.NewLine}This ise third line.", tv.Text);
  3170. Assert.Equal (3, tv.Lines);
  3171. Assert.Equal (new Point (7, 2), tv.CursorPosition);
  3172. for (int i = 0; i < ntimes; i++) {
  3173. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  3174. }
  3175. Assert.Equal ($"This ise first line.{Environment.NewLine}This ise second line.{Environment.NewLine}This is the 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 is the 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, 0), 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 is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  3188. Assert.Equal (3, tv.Lines);
  3189. Assert.Equal (new Point (7, 1), tv.CursorPosition);
  3190. for (int i = 0; i < ntimes; i++) {
  3191. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  3192. }
  3193. Assert.Equal ($"This is the first line.{Environment.NewLine}This ise 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 ise 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, 0), 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 ise third line.", tv.Text);
  3206. Assert.Equal (3, tv.Lines);
  3207. Assert.Equal (new Point (7, 2), tv.CursorPosition);
  3208. }
  3209. [Fact]
  3210. [AutoInitShutdown]
  3211. public void HistoryText_Undo_Redo_Multi_Line_Selected_InsertText ()
  3212. {
  3213. var text = $"This is the first line.{Environment.NewLine}This is the second line.\nThis is the third line.";
  3214. var tv = new TextView () {
  3215. Width = 10,
  3216. Height = 2,
  3217. Text = text
  3218. };
  3219. var top = Application.Top;
  3220. top.Add (tv);
  3221. Application.Begin (top);
  3222. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  3223. Assert.Equal (3, tv.Lines);
  3224. Assert.Equal (Point.Empty, tv.CursorPosition);
  3225. var messy = " messy";
  3226. tv.CursorPosition = new Point (7, 0);
  3227. tv.SelectionStartColumn = 11;
  3228. tv.SelectionStartRow = 2;
  3229. Assert.Equal (51 + Environment.NewLine.Length * 2, tv.SelectedLength);
  3230. for (int i = 0; i < messy.Length; i++) {
  3231. tv.InsertText (messy [i].ToString ());
  3232. switch (i) {
  3233. case 0:
  3234. Assert.Equal ("This is third line.", tv.Text);
  3235. Assert.Equal (new Point (8, 0), tv.CursorPosition);
  3236. break;
  3237. case 1:
  3238. Assert.Equal ("This is m third line.", tv.Text);
  3239. Assert.Equal (new Point (9, 0), tv.CursorPosition);
  3240. break;
  3241. case 2:
  3242. Assert.Equal ("This is me third line.", tv.Text);
  3243. Assert.Equal (new Point (10, 0), tv.CursorPosition);
  3244. break;
  3245. case 3:
  3246. Assert.Equal ("This is mes third line.", tv.Text);
  3247. Assert.Equal (new Point (11, 0), tv.CursorPosition);
  3248. break;
  3249. case 4:
  3250. Assert.Equal ("This is mess third line.", tv.Text);
  3251. Assert.Equal (new Point (12, 0), tv.CursorPosition);
  3252. break;
  3253. case 5:
  3254. Assert.Equal ("This is messy third line.", tv.Text);
  3255. Assert.Equal (new Point (13, 0), tv.CursorPosition);
  3256. break;
  3257. }
  3258. }
  3259. Assert.Equal ($"This is messy third line.", tv.Text);
  3260. Assert.Equal (1, tv.Lines);
  3261. Assert.Equal (new Point (13, 0), tv.CursorPosition);
  3262. Assert.Equal (11, tv.SelectionStartColumn);
  3263. Assert.Equal (2, tv.SelectionStartRow);
  3264. Assert.Equal (0, tv.SelectedLength);
  3265. for (int i = 0; i < messy.Length; i++) {
  3266. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  3267. switch (i) {
  3268. case 0:
  3269. Assert.Equal ("This is mess third line.", tv.Text);
  3270. Assert.Equal (new Point (12, 0), tv.CursorPosition);
  3271. break;
  3272. case 1:
  3273. Assert.Equal ("This is mes third line.", tv.Text);
  3274. Assert.Equal (new Point (11, 0), tv.CursorPosition);
  3275. break;
  3276. case 2:
  3277. Assert.Equal ("This is me third line.", tv.Text);
  3278. Assert.Equal (new Point (10, 0), tv.CursorPosition);
  3279. break;
  3280. case 3:
  3281. Assert.Equal ("This is m third line.", tv.Text);
  3282. Assert.Equal (new Point (9, 0), tv.CursorPosition);
  3283. break;
  3284. case 4:
  3285. Assert.Equal ("This is third line.", tv.Text);
  3286. Assert.Equal (new Point (8, 0), tv.CursorPosition);
  3287. break;
  3288. case 5:
  3289. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  3290. Assert.Equal (new Point (7, 0), tv.CursorPosition);
  3291. break;
  3292. }
  3293. }
  3294. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  3295. Assert.Equal (3, tv.Lines);
  3296. Assert.Equal (new Point (7, 0), tv.CursorPosition);
  3297. Assert.Equal (11, tv.SelectionStartColumn);
  3298. Assert.Equal (2, tv.SelectionStartRow);
  3299. Assert.Equal (0, tv.SelectedLength);
  3300. for (int i = 0; i < messy.Length; i++) {
  3301. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  3302. switch (i) {
  3303. case 0:
  3304. Assert.Equal ("This is third line.", tv.Text);
  3305. Assert.Equal (new Point (8, 0), tv.CursorPosition);
  3306. break;
  3307. case 1:
  3308. Assert.Equal ("This is m third line.", tv.Text);
  3309. Assert.Equal (new Point (9, 0), tv.CursorPosition);
  3310. break;
  3311. case 2:
  3312. Assert.Equal ("This is me third line.", tv.Text);
  3313. Assert.Equal (new Point (10, 0), tv.CursorPosition);
  3314. break;
  3315. case 3:
  3316. Assert.Equal ("This is mes third line.", tv.Text);
  3317. Assert.Equal (new Point (11, 0), tv.CursorPosition);
  3318. break;
  3319. case 4:
  3320. Assert.Equal ("This is mess third line.", tv.Text);
  3321. Assert.Equal (new Point (12, 0), tv.CursorPosition);
  3322. break;
  3323. case 5:
  3324. Assert.Equal ("This is messy third line.", tv.Text);
  3325. Assert.Equal (new Point (13, 0), tv.CursorPosition);
  3326. break;
  3327. }
  3328. }
  3329. Assert.Equal ("This is messy third line.", tv.Text);
  3330. Assert.Equal (1, tv.Lines);
  3331. Assert.Equal (new Point (13, 0), tv.CursorPosition);
  3332. Assert.Equal (11, tv.SelectionStartColumn);
  3333. Assert.Equal (2, tv.SelectionStartRow);
  3334. Assert.Equal (0, tv.SelectedLength);
  3335. }
  3336. [Fact]
  3337. [AutoInitShutdown]
  3338. public void HistoryText_Undo_Redo_Multi_Line_With_Empty_Text ()
  3339. {
  3340. var tv = new TextView () {
  3341. Width = 10,
  3342. Height = 2
  3343. };
  3344. var top = Application.Top;
  3345. top.Add (tv);
  3346. Application.Begin (top);
  3347. Assert.Equal ("", tv.Text);
  3348. Assert.Equal (1, tv.Lines);
  3349. Assert.Equal (Point.Empty, tv.CursorPosition);
  3350. Assert.False (tv.IsDirty);
  3351. Assert.True (tv.ProcessKey (new KeyEvent (Key.O, new KeyModifiers ())));
  3352. Assert.Equal ("O", tv.Text);
  3353. Assert.Equal (1, tv.Lines);
  3354. Assert.Equal (new Point (1, 0), tv.CursorPosition);
  3355. Assert.True (tv.IsDirty);
  3356. Assert.True (tv.ProcessKey (new KeyEvent (Key.n, new KeyModifiers ())));
  3357. Assert.Equal ("On", tv.Text);
  3358. Assert.Equal (1, tv.Lines);
  3359. Assert.Equal (new Point (2, 0), tv.CursorPosition);
  3360. Assert.True (tv.IsDirty);
  3361. Assert.True (tv.ProcessKey (new KeyEvent (Key.e, new KeyModifiers ())));
  3362. Assert.Equal ("One", tv.Text);
  3363. Assert.Equal (1, tv.Lines);
  3364. Assert.Equal (new Point (3, 0), tv.CursorPosition);
  3365. Assert.True (tv.IsDirty);
  3366. Assert.True (tv.ProcessKey (new KeyEvent (Key.Enter, new KeyModifiers ())));
  3367. Assert.Equal ($"One{Environment.NewLine}", tv.Text);
  3368. Assert.Equal (2, tv.Lines);
  3369. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  3370. Assert.True (tv.IsDirty);
  3371. Assert.True (tv.ProcessKey (new KeyEvent (Key.T, new KeyModifiers ())));
  3372. Assert.Equal ($"One{Environment.NewLine}T", tv.Text);
  3373. Assert.Equal (2, tv.Lines);
  3374. Assert.Equal (new Point (1, 1), tv.CursorPosition);
  3375. Assert.True (tv.IsDirty);
  3376. Assert.True (tv.ProcessKey (new KeyEvent (Key.w, new KeyModifiers ())));
  3377. Assert.Equal ($"One{Environment.NewLine}Tw", tv.Text);
  3378. Assert.Equal (2, tv.Lines);
  3379. Assert.Equal (new Point (2, 1), tv.CursorPosition);
  3380. Assert.True (tv.IsDirty);
  3381. Assert.True (tv.ProcessKey (new KeyEvent (Key.o, new KeyModifiers ())));
  3382. Assert.Equal ($"One{Environment.NewLine}Two", tv.Text);
  3383. Assert.Equal (2, tv.Lines);
  3384. Assert.Equal (new Point (3, 1), tv.CursorPosition);
  3385. Assert.True (tv.IsDirty);
  3386. Assert.True (tv.ProcessKey (new KeyEvent (Key.Enter, new KeyModifiers ())));
  3387. Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}", tv.Text);
  3388. Assert.Equal (3, tv.Lines);
  3389. Assert.Equal (new Point (0, 2), tv.CursorPosition);
  3390. Assert.True (tv.IsDirty);
  3391. Assert.True (tv.ProcessKey (new KeyEvent (Key.T, new KeyModifiers ())));
  3392. Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}T", tv.Text);
  3393. Assert.Equal (3, tv.Lines);
  3394. Assert.Equal (new Point (1, 2), tv.CursorPosition);
  3395. Assert.True (tv.IsDirty);
  3396. Assert.True (tv.ProcessKey (new KeyEvent (Key.h, new KeyModifiers ())));
  3397. Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}Th", tv.Text);
  3398. Assert.Equal (3, tv.Lines);
  3399. Assert.Equal (new Point (2, 2), tv.CursorPosition);
  3400. Assert.True (tv.IsDirty);
  3401. Assert.True (tv.ProcessKey (new KeyEvent (Key.r, new KeyModifiers ())));
  3402. Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}Thr", tv.Text);
  3403. Assert.Equal (3, tv.Lines);
  3404. Assert.Equal (new Point (3, 2), tv.CursorPosition);
  3405. Assert.True (tv.IsDirty);
  3406. Assert.True (tv.ProcessKey (new KeyEvent (Key.e, new KeyModifiers ())));
  3407. Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}Thre", tv.Text);
  3408. Assert.Equal (3, tv.Lines);
  3409. Assert.Equal (new Point (4, 2), tv.CursorPosition);
  3410. Assert.True (tv.IsDirty);
  3411. Assert.True (tv.ProcessKey (new KeyEvent (Key.e, new KeyModifiers ())));
  3412. Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}Three", tv.Text);
  3413. Assert.Equal (3, tv.Lines);
  3414. Assert.Equal (new Point (5, 2), tv.CursorPosition);
  3415. Assert.True (tv.IsDirty);
  3416. Assert.True (tv.ProcessKey (new KeyEvent (Key.Enter, new KeyModifiers ())));
  3417. Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}Three{Environment.NewLine}", tv.Text);
  3418. Assert.Equal (4, tv.Lines);
  3419. Assert.Equal (new Point (0, 3), tv.CursorPosition);
  3420. Assert.True (tv.IsDirty);
  3421. // Undoing
  3422. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  3423. Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}Three", tv.Text);
  3424. Assert.Equal (3, tv.Lines);
  3425. Assert.Equal (new Point (5, 2), tv.CursorPosition);
  3426. Assert.True (tv.IsDirty);
  3427. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  3428. Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}Thre", tv.Text);
  3429. Assert.Equal (3, tv.Lines);
  3430. Assert.Equal (new Point (4, 2), tv.CursorPosition);
  3431. Assert.True (tv.IsDirty);
  3432. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  3433. Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}Thr", tv.Text);
  3434. Assert.Equal (3, tv.Lines);
  3435. Assert.Equal (new Point (3, 2), tv.CursorPosition);
  3436. Assert.True (tv.IsDirty);
  3437. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  3438. Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}Th", tv.Text);
  3439. Assert.Equal (3, tv.Lines);
  3440. Assert.Equal (new Point (2, 2), tv.CursorPosition);
  3441. Assert.True (tv.IsDirty);
  3442. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  3443. Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}T", tv.Text);
  3444. Assert.Equal (3, tv.Lines);
  3445. Assert.Equal (new Point (1, 2), tv.CursorPosition);
  3446. Assert.True (tv.IsDirty);
  3447. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  3448. Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}", tv.Text);
  3449. Assert.Equal (3, tv.Lines);
  3450. Assert.Equal (new Point (0, 2), tv.CursorPosition);
  3451. Assert.True (tv.IsDirty);
  3452. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  3453. Assert.Equal ($"One{Environment.NewLine}Two", tv.Text);
  3454. Assert.Equal (2, tv.Lines);
  3455. Assert.Equal (new Point (3, 1), tv.CursorPosition);
  3456. Assert.True (tv.IsDirty);
  3457. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  3458. Assert.Equal ($"One{Environment.NewLine}Tw", tv.Text);
  3459. Assert.Equal (2, tv.Lines);
  3460. Assert.Equal (new Point (2, 1), tv.CursorPosition);
  3461. Assert.True (tv.IsDirty);
  3462. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  3463. Assert.Equal ($"One{Environment.NewLine}T", tv.Text);
  3464. Assert.Equal (2, tv.Lines);
  3465. Assert.Equal (new Point (1, 1), tv.CursorPosition);
  3466. Assert.True (tv.IsDirty);
  3467. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  3468. Assert.Equal ($"One{Environment.NewLine}", tv.Text);
  3469. Assert.Equal (2, tv.Lines);
  3470. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  3471. Assert.True (tv.IsDirty);
  3472. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  3473. Assert.Equal ($"One", tv.Text);
  3474. Assert.Equal (1, tv.Lines);
  3475. Assert.Equal (new Point (3, 0), tv.CursorPosition);
  3476. Assert.True (tv.IsDirty);
  3477. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  3478. Assert.Equal ($"On", tv.Text);
  3479. Assert.Equal (1, tv.Lines);
  3480. Assert.Equal (new Point (2, 0), tv.CursorPosition);
  3481. Assert.True (tv.IsDirty);
  3482. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  3483. Assert.Equal ($"O", tv.Text);
  3484. Assert.Equal (1, tv.Lines);
  3485. Assert.Equal (new Point (1, 0), tv.CursorPosition);
  3486. Assert.True (tv.IsDirty);
  3487. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  3488. Assert.Equal ($"", tv.Text);
  3489. Assert.Equal (1, tv.Lines);
  3490. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  3491. Assert.False (tv.IsDirty);
  3492. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  3493. Assert.Equal ($"", tv.Text);
  3494. Assert.Equal (1, tv.Lines);
  3495. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  3496. Assert.False (tv.IsDirty);
  3497. // Redoing
  3498. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  3499. Assert.Equal ($"O", tv.Text);
  3500. Assert.Equal (1, tv.Lines);
  3501. Assert.Equal (new Point (1, 0), tv.CursorPosition);
  3502. Assert.True (tv.IsDirty);
  3503. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  3504. Assert.Equal ($"On", tv.Text);
  3505. Assert.Equal (1, tv.Lines);
  3506. Assert.Equal (new Point (2, 0), tv.CursorPosition);
  3507. Assert.True (tv.IsDirty);
  3508. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  3509. Assert.Equal ($"One", tv.Text);
  3510. Assert.Equal (1, tv.Lines);
  3511. Assert.Equal (new Point (3, 0), tv.CursorPosition);
  3512. Assert.True (tv.IsDirty);
  3513. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  3514. Assert.Equal ($"One{Environment.NewLine}", tv.Text);
  3515. Assert.Equal (2, tv.Lines);
  3516. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  3517. Assert.True (tv.IsDirty);
  3518. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  3519. Assert.Equal ($"One{Environment.NewLine}T", tv.Text);
  3520. Assert.Equal (2, tv.Lines);
  3521. Assert.Equal (new Point (1, 1), tv.CursorPosition);
  3522. Assert.True (tv.IsDirty);
  3523. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  3524. Assert.Equal ($"One{Environment.NewLine}Tw", tv.Text);
  3525. Assert.Equal (2, tv.Lines);
  3526. Assert.Equal (new Point (2, 1), tv.CursorPosition);
  3527. Assert.True (tv.IsDirty);
  3528. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  3529. Assert.Equal ($"One{Environment.NewLine}Two", tv.Text);
  3530. Assert.Equal (2, tv.Lines);
  3531. Assert.Equal (new Point (3, 1), tv.CursorPosition);
  3532. Assert.True (tv.IsDirty);
  3533. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  3534. Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}", tv.Text);
  3535. Assert.Equal (3, tv.Lines);
  3536. Assert.Equal (new Point (0, 2), tv.CursorPosition);
  3537. Assert.True (tv.IsDirty);
  3538. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  3539. Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}T", tv.Text);
  3540. Assert.Equal (3, tv.Lines);
  3541. Assert.Equal (new Point (1, 2), tv.CursorPosition);
  3542. Assert.True (tv.IsDirty);
  3543. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  3544. Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}Th", tv.Text);
  3545. Assert.Equal (3, tv.Lines);
  3546. Assert.Equal (new Point (2, 2), tv.CursorPosition);
  3547. Assert.True (tv.IsDirty);
  3548. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  3549. Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}Thr", tv.Text);
  3550. Assert.Equal (3, tv.Lines);
  3551. Assert.Equal (new Point (3, 2), tv.CursorPosition);
  3552. Assert.True (tv.IsDirty);
  3553. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  3554. Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}Thre", tv.Text);
  3555. Assert.Equal (3, tv.Lines);
  3556. Assert.Equal (new Point (4, 2), tv.CursorPosition);
  3557. Assert.True (tv.IsDirty);
  3558. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  3559. Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}Three", tv.Text);
  3560. Assert.Equal (3, tv.Lines);
  3561. Assert.Equal (new Point (5, 2), tv.CursorPosition);
  3562. Assert.True (tv.IsDirty);
  3563. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  3564. Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}Three{Environment.NewLine}", tv.Text);
  3565. Assert.Equal (4, tv.Lines);
  3566. Assert.Equal (new Point (0, 3), tv.CursorPosition);
  3567. Assert.True (tv.IsDirty);
  3568. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  3569. Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}Three{Environment.NewLine}", tv.Text);
  3570. Assert.Equal (4, tv.Lines);
  3571. Assert.Equal (new Point (0, 3), tv.CursorPosition);
  3572. Assert.True (tv.IsDirty);
  3573. }
  3574. [Fact]
  3575. [AutoInitShutdown]
  3576. public void HistoryText_Undo_Redo_Multi_Line_Selected_With_Empty_Text ()
  3577. {
  3578. var tv = new TextView () {
  3579. Width = 10,
  3580. Height = 2
  3581. };
  3582. var top = Application.Top;
  3583. top.Add (tv);
  3584. Application.Begin (top);
  3585. Assert.Equal ("", tv.Text);
  3586. Assert.Equal (1, tv.Lines);
  3587. Assert.Equal (Point.Empty, tv.CursorPosition);
  3588. Assert.False (tv.IsDirty);
  3589. Assert.True (tv.ProcessKey (new KeyEvent (Key.O, new KeyModifiers ())));
  3590. Assert.Equal ("O", tv.Text);
  3591. Assert.Equal (1, tv.Lines);
  3592. Assert.Equal (new Point (1, 0), tv.CursorPosition);
  3593. Assert.True (tv.IsDirty);
  3594. Assert.True (tv.ProcessKey (new KeyEvent (Key.n, new KeyModifiers ())));
  3595. Assert.Equal ("On", tv.Text);
  3596. Assert.Equal (1, tv.Lines);
  3597. Assert.Equal (new Point (2, 0), tv.CursorPosition);
  3598. Assert.True (tv.IsDirty);
  3599. Assert.True (tv.ProcessKey (new KeyEvent (Key.e, new KeyModifiers ())));
  3600. Assert.Equal ("One", tv.Text);
  3601. Assert.Equal (1, tv.Lines);
  3602. Assert.Equal (new Point (3, 0), tv.CursorPosition);
  3603. Assert.True (tv.IsDirty);
  3604. Assert.True (tv.ProcessKey (new KeyEvent (Key.Enter, new KeyModifiers ())));
  3605. Assert.Equal ($"One{Environment.NewLine}", tv.Text);
  3606. Assert.Equal (2, tv.Lines);
  3607. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  3608. Assert.True (tv.IsDirty);
  3609. Assert.True (tv.ProcessKey (new KeyEvent (Key.T, new KeyModifiers ())));
  3610. Assert.Equal ($"One{Environment.NewLine}T", tv.Text);
  3611. Assert.Equal (2, tv.Lines);
  3612. Assert.Equal (new Point (1, 1), tv.CursorPosition);
  3613. Assert.True (tv.IsDirty);
  3614. Assert.True (tv.ProcessKey (new KeyEvent (Key.w, new KeyModifiers ())));
  3615. Assert.Equal ($"One{Environment.NewLine}Tw", tv.Text);
  3616. Assert.Equal (2, tv.Lines);
  3617. Assert.Equal (new Point (2, 1), tv.CursorPosition);
  3618. Assert.True (tv.IsDirty);
  3619. Assert.True (tv.ProcessKey (new KeyEvent (Key.o, new KeyModifiers ())));
  3620. Assert.Equal ($"One{Environment.NewLine}Two", tv.Text);
  3621. Assert.Equal (2, tv.Lines);
  3622. Assert.Equal (new Point (3, 1), tv.CursorPosition);
  3623. Assert.True (tv.IsDirty);
  3624. Assert.True (tv.ProcessKey (new KeyEvent (Key.Enter, new KeyModifiers ())));
  3625. Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}", tv.Text);
  3626. Assert.Equal (3, tv.Lines);
  3627. Assert.Equal (new Point (0, 2), tv.CursorPosition);
  3628. Assert.True (tv.IsDirty);
  3629. Assert.True (tv.ProcessKey (new KeyEvent (Key.T, new KeyModifiers ())));
  3630. Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}T", tv.Text);
  3631. Assert.Equal (3, tv.Lines);
  3632. Assert.Equal (new Point (1, 2), tv.CursorPosition);
  3633. Assert.True (tv.IsDirty);
  3634. Assert.True (tv.ProcessKey (new KeyEvent (Key.h, new KeyModifiers ())));
  3635. Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}Th", tv.Text);
  3636. Assert.Equal (3, tv.Lines);
  3637. Assert.Equal (new Point (2, 2), tv.CursorPosition);
  3638. Assert.True (tv.IsDirty);
  3639. Assert.True (tv.ProcessKey (new KeyEvent (Key.r, new KeyModifiers ())));
  3640. Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}Thr", tv.Text);
  3641. Assert.Equal (3, tv.Lines);
  3642. Assert.Equal (new Point (3, 2), tv.CursorPosition);
  3643. Assert.True (tv.IsDirty);
  3644. Assert.True (tv.ProcessKey (new KeyEvent (Key.e, new KeyModifiers ())));
  3645. Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}Thre", tv.Text);
  3646. Assert.Equal (3, tv.Lines);
  3647. Assert.Equal (new Point (4, 2), tv.CursorPosition);
  3648. Assert.True (tv.IsDirty);
  3649. Assert.True (tv.ProcessKey (new KeyEvent (Key.e, new KeyModifiers ())));
  3650. Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}Three", tv.Text);
  3651. Assert.Equal (3, tv.Lines);
  3652. Assert.Equal (new Point (5, 2), tv.CursorPosition);
  3653. Assert.True (tv.IsDirty);
  3654. Assert.True (tv.ProcessKey (new KeyEvent (Key.Enter, new KeyModifiers ())));
  3655. Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}Three{Environment.NewLine}", tv.Text);
  3656. Assert.Equal (4, tv.Lines);
  3657. Assert.Equal (new Point (0, 3), tv.CursorPosition);
  3658. Assert.True (tv.IsDirty);
  3659. tv.SelectionStartColumn = 0;
  3660. tv.SelectionStartRow = 0;
  3661. tv.CursorPosition = new Point (0, 1);
  3662. Assert.Equal (3 + Environment.NewLine.Length, tv.SelectedLength);
  3663. Assert.True (tv.ProcessKey (new KeyEvent (Key.D1, new KeyModifiers ())));
  3664. Assert.Equal ($"1Two{Environment.NewLine}Three{Environment.NewLine}", tv.Text);
  3665. Assert.Equal (3, tv.Lines);
  3666. Assert.Equal (new Point (1, 0), tv.CursorPosition);
  3667. Assert.Equal (0, tv.SelectedLength);
  3668. Assert.True (tv.IsDirty);
  3669. tv.SelectionStartColumn = 1;
  3670. tv.SelectionStartRow = 0;
  3671. tv.CursorPosition = new Point (1, 1);
  3672. Assert.Equal (4 + Environment.NewLine.Length, tv.SelectedLength);
  3673. Assert.True (tv.ProcessKey (new KeyEvent (Key.D2, new KeyModifiers ())));
  3674. Assert.Equal ($"12hree{Environment.NewLine}", tv.Text);
  3675. Assert.Equal (2, tv.Lines);
  3676. Assert.Equal (new Point (2, 0), tv.CursorPosition);
  3677. Assert.Equal (0, tv.SelectedLength);
  3678. Assert.True (tv.IsDirty);
  3679. // Undoing
  3680. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  3681. Assert.Equal ($"1Two{Environment.NewLine}Three{Environment.NewLine}", tv.Text);
  3682. Assert.Equal (3, tv.Lines);
  3683. Assert.Equal (new Point (1, 1), tv.CursorPosition);
  3684. Assert.Equal (0, tv.SelectedLength);
  3685. Assert.True (tv.IsDirty);
  3686. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  3687. Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}Three{Environment.NewLine}", tv.Text);
  3688. Assert.Equal (4, tv.Lines);
  3689. Assert.Equal (new Point (0, 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", tv.Text);
  3694. Assert.Equal (3, tv.Lines);
  3695. Assert.Equal (new Point (5, 2), 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}Thre", tv.Text);
  3700. Assert.Equal (3, tv.Lines);
  3701. Assert.Equal (new Point (4, 2), tv.CursorPosition);
  3702. Assert.True (tv.IsDirty);
  3703. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  3704. Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}Thr", tv.Text);
  3705. Assert.Equal (3, tv.Lines);
  3706. Assert.Equal (new Point (3, 2), tv.CursorPosition);
  3707. Assert.Equal (0, tv.SelectedLength);
  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}Th", tv.Text);
  3711. Assert.Equal (3, tv.Lines);
  3712. Assert.Equal (new Point (2, 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}T", tv.Text);
  3717. Assert.Equal (3, tv.Lines);
  3718. Assert.Equal (new Point (1, 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}", tv.Text);
  3723. Assert.Equal (3, tv.Lines);
  3724. Assert.Equal (new Point (0, 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", tv.Text);
  3729. Assert.Equal (2, tv.Lines);
  3730. Assert.Equal (new Point (3, 1), 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}Tw", tv.Text);
  3735. Assert.Equal (2, tv.Lines);
  3736. Assert.Equal (new Point (2, 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}T", tv.Text);
  3741. Assert.Equal (2, tv.Lines);
  3742. Assert.Equal (new Point (1, 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}", tv.Text);
  3747. Assert.Equal (2, tv.Lines);
  3748. Assert.Equal (new Point (0, 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", tv.Text);
  3753. Assert.Equal (1, tv.Lines);
  3754. Assert.Equal (new Point (3, 0), 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 ($"On", tv.Text);
  3759. Assert.Equal (1, tv.Lines);
  3760. Assert.Equal (new Point (2, 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 ($"O", tv.Text);
  3765. Assert.Equal (1, tv.Lines);
  3766. Assert.Equal (new Point (1, 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 ($"", tv.Text);
  3771. Assert.Equal (1, tv.Lines);
  3772. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  3773. Assert.Equal (0, tv.SelectedLength);
  3774. Assert.False (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. // Redoing
  3782. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  3783. Assert.Equal ($"O", tv.Text);
  3784. Assert.Equal (1, tv.Lines);
  3785. Assert.Equal (new Point (1, 0), tv.CursorPosition);
  3786. Assert.Equal (0, tv.SelectedLength);
  3787. Assert.True (tv.IsDirty);
  3788. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  3789. Assert.Equal ($"On", tv.Text);
  3790. Assert.Equal (1, tv.Lines);
  3791. Assert.Equal (new Point (2, 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 ($"One", tv.Text);
  3796. Assert.Equal (1, tv.Lines);
  3797. Assert.Equal (new Point (3, 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{Environment.NewLine}", tv.Text);
  3802. Assert.Equal (2, tv.Lines);
  3803. Assert.Equal (new Point (0, 1), 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}T", tv.Text);
  3808. Assert.Equal (2, tv.Lines);
  3809. Assert.Equal (new Point (1, 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}Tw", tv.Text);
  3814. Assert.Equal (2, tv.Lines);
  3815. Assert.Equal (new Point (2, 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}Two", tv.Text);
  3820. Assert.Equal (2, tv.Lines);
  3821. Assert.Equal (new Point (3, 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{Environment.NewLine}", tv.Text);
  3826. Assert.Equal (3, tv.Lines);
  3827. Assert.Equal (new Point (0, 2), 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}T", tv.Text);
  3832. Assert.Equal (3, tv.Lines);
  3833. Assert.Equal (new Point (1, 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}Th", tv.Text);
  3838. Assert.Equal (3, tv.Lines);
  3839. Assert.Equal (new Point (2, 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}Thr", tv.Text);
  3844. Assert.Equal (3, tv.Lines);
  3845. Assert.Equal (new Point (3, 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}Thre", tv.Text);
  3850. Assert.Equal (3, tv.Lines);
  3851. Assert.Equal (new Point (4, 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}Three", tv.Text);
  3856. Assert.Equal (3, tv.Lines);
  3857. Assert.Equal (new Point (5, 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{Environment.NewLine}", tv.Text);
  3862. Assert.Equal (4, tv.Lines);
  3863. Assert.Equal (new Point (0, 3), 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 ($"1Two{Environment.NewLine}Three{Environment.NewLine}", tv.Text);
  3868. Assert.Equal (3, tv.Lines);
  3869. Assert.Equal (new Point (1, 0), 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 ($"12hree{Environment.NewLine}", tv.Text);
  3874. Assert.Equal (2, tv.Lines);
  3875. Assert.Equal (new Point (2, 0), tv.CursorPosition);
  3876. Assert.Equal (0, tv.SelectedLength);
  3877. Assert.True (tv.IsDirty);
  3878. }
  3879. [Fact]
  3880. [AutoInitShutdown]
  3881. public void HistoryText_Undo_Redo_Multi_Line_Selected_InsertText_Twice_On_Same_Line ()
  3882. {
  3883. var text = "One\nTwo\nThree";
  3884. var tv = new TextView () {
  3885. Width = 10,
  3886. Height = 2,
  3887. Text = text
  3888. };
  3889. var top = Application.Top;
  3890. top.Add (tv);
  3891. Application.Begin (top);
  3892. Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}Three", tv.Text);
  3893. Assert.Equal (3, tv.Lines);
  3894. Assert.Equal (Point.Empty, tv.CursorPosition);
  3895. Assert.False (tv.IsDirty);
  3896. tv.SelectionStartColumn = 0;
  3897. tv.SelectionStartRow = 0;
  3898. tv.CursorPosition = new Point (0, 1);
  3899. Assert.Equal (3 + Environment.NewLine.Length, tv.SelectedLength);
  3900. Assert.True (tv.ProcessKey (new KeyEvent (Key.D1, new KeyModifiers ())));
  3901. Assert.Equal ($"1Two{Environment.NewLine}Three", tv.Text);
  3902. Assert.Equal (new Point (1, 0), tv.CursorPosition);
  3903. Assert.Equal (0, tv.SelectedLength);
  3904. Assert.True (tv.IsDirty);
  3905. tv.SelectionStartColumn = 1;
  3906. tv.SelectionStartRow = 0;
  3907. tv.CursorPosition = new Point (1, 1);
  3908. Assert.Equal (4 + Environment.NewLine.Length, tv.SelectedLength);
  3909. Assert.True (tv.ProcessKey (new KeyEvent (Key.D2, new KeyModifiers ())));
  3910. Assert.Equal ("12hree", tv.Text);
  3911. Assert.Equal (new Point (2, 0), tv.CursorPosition);
  3912. Assert.Equal (0, tv.SelectedLength);
  3913. Assert.True (tv.IsDirty);
  3914. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  3915. Assert.Equal ($"1Two{Environment.NewLine}Three", tv.Text);
  3916. Assert.Equal (new Point (1, 1), tv.CursorPosition);
  3917. Assert.Equal (0, tv.SelectedLength);
  3918. Assert.True (tv.IsDirty);
  3919. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  3920. Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}Three", tv.Text);
  3921. Assert.Equal (3, tv.Lines);
  3922. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  3923. Assert.Equal (0, tv.SelectedLength);
  3924. Assert.False (tv.IsDirty);
  3925. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  3926. Assert.Equal ($"1Two{Environment.NewLine}Three", tv.Text);
  3927. Assert.Equal (new Point (1, 0), tv.CursorPosition);
  3928. Assert.Equal (0, tv.SelectedLength);
  3929. Assert.True (tv.IsDirty);
  3930. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  3931. Assert.Equal ("12hree", tv.Text);
  3932. Assert.Equal (new Point (2, 0), tv.CursorPosition);
  3933. Assert.Equal (0, tv.SelectedLength);
  3934. Assert.True (tv.IsDirty);
  3935. }
  3936. [Fact]
  3937. [AutoInitShutdown]
  3938. public void HistoryText_Undo_Redo_Multi_Line_Selected_InsertText_Twice_On_Same_Line_With_End_Line ()
  3939. {
  3940. var text = "One\nTwo\nThree\n";
  3941. var tv = new TextView () {
  3942. Width = 10,
  3943. Height = 2,
  3944. Text = text
  3945. };
  3946. var top = Application.Top;
  3947. top.Add (tv);
  3948. Application.Begin (top);
  3949. Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}Three{Environment.NewLine}", tv.Text);
  3950. Assert.Equal (4, tv.Lines);
  3951. Assert.Equal (Point.Empty, tv.CursorPosition);
  3952. Assert.False (tv.IsDirty);
  3953. tv.SelectionStartColumn = 0;
  3954. tv.SelectionStartRow = 0;
  3955. tv.CursorPosition = new Point (0, 1);
  3956. Assert.Equal (3 + Environment.NewLine.Length, tv.SelectedLength);
  3957. Assert.True (tv.ProcessKey (new KeyEvent (Key.D1, new KeyModifiers ())));
  3958. Assert.Equal ($"1Two{Environment.NewLine}Three{Environment.NewLine}", tv.Text);
  3959. Assert.Equal (new Point (1, 0), tv.CursorPosition);
  3960. Assert.Equal (0, tv.SelectedLength);
  3961. Assert.True (tv.IsDirty);
  3962. tv.SelectionStartColumn = 1;
  3963. tv.SelectionStartRow = 0;
  3964. tv.CursorPosition = new Point (1, 1);
  3965. Assert.Equal (4 + Environment.NewLine.Length, tv.SelectedLength);
  3966. Assert.True (tv.ProcessKey (new KeyEvent (Key.D2, new KeyModifiers ())));
  3967. Assert.Equal ($"12hree{Environment.NewLine}", tv.Text);
  3968. Assert.Equal (new Point (2, 0), tv.CursorPosition);
  3969. Assert.Equal (0, tv.SelectedLength);
  3970. Assert.True (tv.IsDirty);
  3971. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  3972. Assert.Equal ($"1Two{Environment.NewLine}Three{Environment.NewLine}", tv.Text);
  3973. Assert.Equal (new Point (1, 1), tv.CursorPosition);
  3974. Assert.Equal (0, tv.SelectedLength);
  3975. Assert.True (tv.IsDirty);
  3976. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  3977. Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}Three{Environment.NewLine}", tv.Text);
  3978. Assert.Equal (4, tv.Lines);
  3979. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  3980. Assert.Equal (0, tv.SelectedLength);
  3981. Assert.False (tv.IsDirty);
  3982. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  3983. Assert.Equal ($"1Two{Environment.NewLine}Three{Environment.NewLine}", tv.Text);
  3984. Assert.Equal (new Point (1, 0), tv.CursorPosition);
  3985. Assert.Equal (0, tv.SelectedLength);
  3986. Assert.True (tv.IsDirty);
  3987. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  3988. Assert.Equal ($"12hree{Environment.NewLine}", tv.Text);
  3989. Assert.Equal (new Point (2, 0), tv.CursorPosition);
  3990. Assert.Equal (0, tv.SelectedLength);
  3991. Assert.True (tv.IsDirty);
  3992. }
  3993. [Fact]
  3994. public void HistoryText_IsDirty_HasHistoryChanges ()
  3995. {
  3996. var tv = new TextView ();
  3997. Assert.Equal ("", tv.Text);
  3998. Assert.Equal (1, tv.Lines);
  3999. Assert.Equal (Point.Empty, tv.CursorPosition);
  4000. Assert.False (tv.IsDirty);
  4001. Assert.False (tv.HasHistoryChanges);
  4002. Assert.True (tv.ProcessKey (new KeyEvent (Key.D1, new KeyModifiers ())));
  4003. Assert.Equal ("1", tv.Text);
  4004. Assert.Equal (1, tv.Lines);
  4005. Assert.Equal (new Point (1, 0), tv.CursorPosition);
  4006. Assert.True (tv.IsDirty);
  4007. Assert.True (tv.HasHistoryChanges);
  4008. Assert.True (tv.ProcessKey (new KeyEvent (Key.Enter, new KeyModifiers ())));
  4009. Assert.Equal ($"1{Environment.NewLine}", tv.Text);
  4010. Assert.Equal (2, tv.Lines);
  4011. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  4012. Assert.True (tv.IsDirty);
  4013. Assert.True (tv.HasHistoryChanges);
  4014. Assert.True (tv.ProcessKey (new KeyEvent (Key.D2, new KeyModifiers ())));
  4015. Assert.Equal ($"1{Environment.NewLine}2", tv.Text);
  4016. Assert.Equal (2, tv.Lines);
  4017. Assert.Equal (new Point (1, 1), tv.CursorPosition);
  4018. Assert.True (tv.IsDirty);
  4019. Assert.True (tv.HasHistoryChanges);
  4020. Assert.True (tv.ProcessKey (new KeyEvent (Key.Backspace, new KeyModifiers ())));
  4021. Assert.Equal ($"1{Environment.NewLine}", tv.Text);
  4022. Assert.Equal (2, tv.Lines);
  4023. Assert.Equal (new Point (0, 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", tv.Text);
  4028. Assert.Equal (1, tv.Lines);
  4029. Assert.Equal (new Point (1, 0), 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 ($"", tv.Text);
  4034. Assert.Equal (1, tv.Lines);
  4035. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  4036. // IsDirty cannot be based on HasHistoryChanges because HasHistoryChanges is greater than 0
  4037. // The only way is comparing from the original text
  4038. Assert.False (tv.IsDirty);
  4039. // Still true because HasHistoryChanges is greater than 0
  4040. Assert.True (tv.HasHistoryChanges);
  4041. }
  4042. [Fact]
  4043. public void HistoryText_Undo_Redo_Multi_Line_Selected_DeleteCharLeft_All ()
  4044. {
  4045. var text = "This is the first line.\nThis is the second line.\nThis is the third line.";
  4046. var tv = new TextView () { Text = text };
  4047. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  4048. Assert.Equal (3, tv.Lines);
  4049. Assert.Equal (Point.Empty, tv.CursorPosition);
  4050. Assert.False (tv.IsDirty);
  4051. Assert.False (tv.HasHistoryChanges);
  4052. Assert.True (tv.ProcessKey (new KeyEvent (Key.End | Key.CtrlMask | Key.ShiftMask, new KeyModifiers ())));
  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 ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.SelectedText);
  4055. Assert.Equal (3, tv.Lines);
  4056. Assert.Equal (new Point (23, 2), tv.CursorPosition);
  4057. Assert.Equal (70 + Environment.NewLine.Length * 2, tv.SelectedLength);
  4058. Assert.False (tv.IsDirty);
  4059. Assert.False (tv.HasHistoryChanges);
  4060. Assert.True (tv.ProcessKey (new KeyEvent (Key.Backspace, new KeyModifiers ())));
  4061. Assert.Equal ("", tv.Text);
  4062. Assert.Equal ("", tv.SelectedText);
  4063. Assert.Equal (1, tv.Lines);
  4064. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  4065. Assert.Equal (0, tv.SelectedLength);
  4066. Assert.True (tv.IsDirty);
  4067. Assert.True (tv.HasHistoryChanges);
  4068. // Undo
  4069. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  4070. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  4071. Assert.Equal ("", tv.SelectedText);
  4072. Assert.Equal (3, tv.Lines);
  4073. Assert.Equal (new Point (23, 2), tv.CursorPosition);
  4074. Assert.Equal (0, tv.SelectedLength);
  4075. Assert.False (tv.IsDirty);
  4076. Assert.True (tv.HasHistoryChanges);
  4077. // Redo
  4078. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  4079. Assert.Equal ("", tv.Text);
  4080. Assert.Equal ("", tv.SelectedText);
  4081. Assert.Equal (1, tv.Lines);
  4082. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  4083. Assert.Equal (0, tv.SelectedLength);
  4084. Assert.True (tv.IsDirty);
  4085. Assert.True (tv.HasHistoryChanges);
  4086. }
  4087. [Fact]
  4088. public void HistoryText_Undo_Redo_Multi_Line_Selected_DeleteCharRight_All ()
  4089. {
  4090. var text = "This is the first line.\nThis is the second line.\nThis is the third line.";
  4091. var tv = new TextView () { Text = text };
  4092. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  4093. Assert.Equal (3, tv.Lines);
  4094. Assert.Equal (Point.Empty, tv.CursorPosition);
  4095. Assert.False (tv.IsDirty);
  4096. Assert.False (tv.HasHistoryChanges);
  4097. Assert.True (tv.ProcessKey (new KeyEvent (Key.End | Key.CtrlMask | Key.ShiftMask, new KeyModifiers ())));
  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 ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.SelectedText);
  4100. Assert.Equal (3, tv.Lines);
  4101. Assert.Equal (new Point (23, 2), tv.CursorPosition);
  4102. Assert.Equal (70 + Environment.NewLine.Length * 2, tv.SelectedLength);
  4103. Assert.False (tv.IsDirty);
  4104. Assert.False (tv.HasHistoryChanges);
  4105. Assert.True (tv.ProcessKey (new KeyEvent (Key.DeleteChar, new KeyModifiers ())));
  4106. Assert.Equal ("", tv.Text);
  4107. Assert.Equal ("", tv.SelectedText);
  4108. Assert.Equal (1, tv.Lines);
  4109. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  4110. Assert.Equal (0, tv.SelectedLength);
  4111. Assert.True (tv.IsDirty);
  4112. Assert.True (tv.HasHistoryChanges);
  4113. // Undo
  4114. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  4115. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  4116. Assert.Equal ("", tv.SelectedText);
  4117. Assert.Equal (3, tv.Lines);
  4118. Assert.Equal (new Point (23, 2), tv.CursorPosition);
  4119. Assert.Equal (0, tv.SelectedLength);
  4120. Assert.False (tv.IsDirty);
  4121. Assert.True (tv.HasHistoryChanges);
  4122. // Redo
  4123. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  4124. Assert.Equal ("", tv.Text);
  4125. Assert.Equal ("", tv.SelectedText);
  4126. Assert.Equal (1, tv.Lines);
  4127. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  4128. Assert.Equal (0, tv.SelectedLength);
  4129. Assert.True (tv.IsDirty);
  4130. Assert.True (tv.HasHistoryChanges);
  4131. }
  4132. [Fact]
  4133. [AutoInitShutdown]
  4134. public void HistoryText_Undo_Redo_Copy_Without_Selection_Multi_Line_Paste ()
  4135. {
  4136. var text = "This is the first line.\nThis is the second line.\nThis is the third line.";
  4137. var tv = new TextView () { Text = text };
  4138. tv.CursorPosition = new Point (23, 0);
  4139. Assert.True (tv.ProcessKey (new KeyEvent (Key.C | Key.CtrlMask, new KeyModifiers ())));
  4140. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  4141. Assert.Equal ("", tv.SelectedText);
  4142. Assert.Equal ("This is the first line.", Clipboard.Contents);
  4143. Assert.Equal (3, tv.Lines);
  4144. Assert.Equal (new Point (23, 0), tv.CursorPosition);
  4145. Assert.True (tv.ProcessKey (new KeyEvent (Key.Y | Key.CtrlMask, new KeyModifiers ())));
  4146. 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);
  4147. Assert.Equal (4, tv.Lines);
  4148. Assert.Equal (new Point (23, 1), tv.CursorPosition);
  4149. // Undo
  4150. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  4151. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  4152. Assert.Equal (3, tv.Lines);
  4153. Assert.Equal (new Point (23, 0), tv.CursorPosition);
  4154. // Redo
  4155. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  4156. 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);
  4157. Assert.Equal (4, tv.Lines);
  4158. Assert.Equal (new Point (23, 1), tv.CursorPosition);
  4159. }
  4160. [Fact]
  4161. [AutoInitShutdown]
  4162. public void HistoryText_Undo_Redo_Simple_Copy_Multi_Line_Selected_Paste ()
  4163. {
  4164. var text = "This is the first line.\nThis is the second line.\nThis is the third line.";
  4165. var tv = new TextView () { Text = text };
  4166. tv.SelectionStartColumn = 12;
  4167. tv.CursorPosition = new Point (17, 0);
  4168. Assert.True (tv.ProcessKey (new KeyEvent (Key.C | Key.CtrlMask, new KeyModifiers ())));
  4169. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  4170. Assert.Equal ("first", tv.SelectedText);
  4171. Assert.Equal (3, tv.Lines);
  4172. Assert.Equal (new Point (17, 0), tv.CursorPosition);
  4173. tv.SelectionStartColumn = 12;
  4174. tv.CursorPosition = new Point (11, 1);
  4175. Assert.True (tv.ProcessKey (new KeyEvent (Key.Y | Key.CtrlMask, new KeyModifiers ())));
  4176. Assert.Equal ($"This is the first second line.{Environment.NewLine}This is the third line.", tv.Text);
  4177. Assert.Equal (2, tv.Lines);
  4178. Assert.Equal (new Point (17, 0), tv.CursorPosition);
  4179. // Undo
  4180. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  4181. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  4182. Assert.Equal (3, tv.Lines);
  4183. Assert.Equal (new Point (12, 0), tv.CursorPosition);
  4184. // Redo
  4185. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  4186. Assert.Equal ($"This is the first second line.{Environment.NewLine}This is the third line.", tv.Text);
  4187. Assert.Equal (2, tv.Lines);
  4188. Assert.Equal (new Point (17, 0), tv.CursorPosition);
  4189. }
  4190. [Fact]
  4191. [AutoInitShutdown]
  4192. public void HistoryText_Undo_Redo_Multi_Line_Selected_Copy_Simple_Paste_Starting_On_Space ()
  4193. {
  4194. var text = "This is the first line.\nThis is the second line.\nThis is the third line.";
  4195. var tv = new TextView () { Text = text };
  4196. tv.SelectionStartColumn = 12;
  4197. tv.CursorPosition = new Point (18, 1);
  4198. Assert.True (tv.ProcessKey (new KeyEvent (Key.C | Key.CtrlMask, new KeyModifiers ())));
  4199. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  4200. Assert.Equal ($"first line.{Environment.NewLine}This is the second", tv.SelectedText);
  4201. Assert.Equal (3, tv.Lines);
  4202. Assert.Equal (new Point (18, 1), tv.CursorPosition);
  4203. tv.Selecting = false;
  4204. Assert.True (tv.ProcessKey (new KeyEvent (Key.Y | Key.CtrlMask, new KeyModifiers ())));
  4205. 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);
  4206. Assert.Equal (4, tv.Lines);
  4207. Assert.Equal (new Point (18, 2), tv.CursorPosition);
  4208. // Undo
  4209. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  4210. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  4211. Assert.Equal (3, tv.Lines);
  4212. Assert.Equal (new Point (18, 1), tv.CursorPosition);
  4213. // Redo
  4214. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  4215. 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);
  4216. Assert.Equal (4, tv.Lines);
  4217. Assert.Equal (new Point (18, 2), tv.CursorPosition);
  4218. }
  4219. [Fact]
  4220. [AutoInitShutdown]
  4221. public void HistoryText_Undo_Redo_Multi_Line_Selected_Copy_Simple_Paste_Starting_On_Letter ()
  4222. {
  4223. var text = "This is the first line.\nThis is the second line.\nThis is the third line.";
  4224. var tv = new TextView () { Text = text };
  4225. tv.SelectionStartColumn = 12;
  4226. tv.CursorPosition = new Point (18, 1);
  4227. Assert.True (tv.ProcessKey (new KeyEvent (Key.C | Key.CtrlMask, new KeyModifiers ())));
  4228. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  4229. Assert.Equal ($"first line.{Environment.NewLine}This is the second", tv.SelectedText);
  4230. Assert.Equal (3, tv.Lines);
  4231. Assert.Equal (new Point (18, 1), tv.CursorPosition);
  4232. tv.Selecting = false;
  4233. tv.CursorPosition = new Point (17, 1);
  4234. Assert.True (tv.ProcessKey (new KeyEvent (Key.Y | Key.CtrlMask, new KeyModifiers ())));
  4235. 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);
  4236. Assert.Equal (4, tv.Lines);
  4237. Assert.Equal (new Point (18, 2), tv.CursorPosition);
  4238. // Undo
  4239. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  4240. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  4241. Assert.Equal (3, tv.Lines);
  4242. Assert.Equal (new Point (17, 1), tv.CursorPosition);
  4243. // Redo
  4244. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  4245. 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);
  4246. Assert.Equal (4, tv.Lines);
  4247. Assert.Equal (new Point (18, 2), tv.CursorPosition);
  4248. }
  4249. [Fact]
  4250. [AutoInitShutdown]
  4251. public void HistoryText_Undo_Redo_Empty_Copy_Without_Selection_Multi_Line_Selected_Paste ()
  4252. {
  4253. var text = "\nThis is the first line.\nThis is the second line.";
  4254. var tv = new TextView () { Text = text };
  4255. Assert.True (tv.ProcessKey (new KeyEvent (Key.C | Key.CtrlMask, new KeyModifiers ())));
  4256. Assert.Equal ($"{Environment.NewLine}This is the first line.{Environment.NewLine}This is the second line.", tv.Text);
  4257. Assert.Equal ("", tv.SelectedText);
  4258. Assert.Equal (3, tv.Lines);
  4259. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  4260. Assert.True (tv.ProcessKey (new KeyEvent (Key.Y | Key.CtrlMask, new KeyModifiers ())));
  4261. Assert.Equal ($"{Environment.NewLine}{Environment.NewLine}This is the first line.{Environment.NewLine}This is the second line.", tv.Text);
  4262. Assert.Equal (4, tv.Lines);
  4263. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  4264. // Undo
  4265. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  4266. Assert.Equal ($"{Environment.NewLine}This is the first line.{Environment.NewLine}This is the second line.", tv.Text);
  4267. Assert.Equal (3, tv.Lines);
  4268. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  4269. // Redo
  4270. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  4271. Assert.Equal ($"{Environment.NewLine}{Environment.NewLine}This is the first line.{Environment.NewLine}This is the second line.", tv.Text);
  4272. Assert.Equal (4, tv.Lines);
  4273. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  4274. }
  4275. [Fact]
  4276. [AutoInitShutdown]
  4277. public void HistoryText_Undo_Redo_Setting_Clipboard_Multi_Line_Selected_Paste ()
  4278. {
  4279. var text = "This is the first line.\nThis is the second line.";
  4280. var tv = new TextView () { Text = text };
  4281. Clipboard.Contents = "Inserted\nNewLine";
  4282. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.", tv.Text);
  4283. Assert.Equal ("", tv.SelectedText);
  4284. Assert.Equal (2, tv.Lines);
  4285. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  4286. Assert.True (tv.ProcessKey (new KeyEvent (Key.Y | Key.CtrlMask, new KeyModifiers ())));
  4287. Assert.Equal ($"Inserted{Environment.NewLine}NewLineThis is the first line.{Environment.NewLine}This is the second line.", tv.Text);
  4288. Assert.Equal (3, tv.Lines);
  4289. Assert.Equal (new Point (7, 1), tv.CursorPosition);
  4290. // Undo
  4291. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  4292. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.", tv.Text);
  4293. Assert.Equal (2, tv.Lines);
  4294. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  4295. // Redo
  4296. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  4297. Assert.Equal ($"Inserted{Environment.NewLine}NewLineThis is the first line.{Environment.NewLine}This is the second line.", tv.Text);
  4298. Assert.Equal (3, tv.Lines);
  4299. Assert.Equal (new Point (7, 1), tv.CursorPosition);
  4300. }
  4301. [Fact]
  4302. [AutoInitShutdown]
  4303. public void HistoryText_Undo_Redo_Cut_Multi_Line_Selected_Paste ()
  4304. {
  4305. var text = "This is the first line.\nThis is the second line.\nThis is the third line.";
  4306. var tv = new TextView () { Text = text };
  4307. tv.SelectionStartColumn = 12;
  4308. tv.CursorPosition = new Point (17, 0);
  4309. Assert.True (tv.ProcessKey (new KeyEvent (Key.W | Key.CtrlMask, new KeyModifiers ())));
  4310. Assert.Equal ($"This is the line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  4311. Assert.Equal ("", tv.SelectedText);
  4312. Assert.Equal (3, tv.Lines);
  4313. Assert.Equal (new Point (12, 0), tv.CursorPosition);
  4314. tv.SelectionStartColumn = 12;
  4315. tv.CursorPosition = new Point (11, 1);
  4316. Assert.True (tv.ProcessKey (new KeyEvent (Key.Y | Key.CtrlMask, new KeyModifiers ())));
  4317. Assert.Equal ($"This is the first second line.{Environment.NewLine}This is the third line.", tv.Text);
  4318. Assert.Equal (2, tv.Lines);
  4319. Assert.Equal (new Point (17, 0), tv.CursorPosition);
  4320. // Undo
  4321. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  4322. Assert.Equal ($"This is the line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  4323. Assert.Equal (3, tv.Lines);
  4324. Assert.Equal (new Point (12, 0), tv.CursorPosition);
  4325. // Redo
  4326. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  4327. Assert.Equal ($"This is the first second line.{Environment.NewLine}This is the third line.", tv.Text);
  4328. Assert.Equal (2, tv.Lines);
  4329. Assert.Equal (new Point (17, 0), tv.CursorPosition);
  4330. }
  4331. [Fact]
  4332. [AutoInitShutdown]
  4333. public void HistoryText_Undo_Redo_Cut_Simple_Paste_Starting ()
  4334. {
  4335. var text = "This is the first line.\nThis is the second line.\nThis is the third line.";
  4336. var tv = new TextView () { Text = text };
  4337. tv.SelectionStartColumn = 12;
  4338. tv.CursorPosition = new Point (18, 1);
  4339. Assert.True (tv.ProcessKey (new KeyEvent (Key.W | Key.CtrlMask, new KeyModifiers ())));
  4340. Assert.Equal ($"This is the line.{Environment.NewLine}This is the third line.", tv.Text);
  4341. Assert.Equal ("", tv.SelectedText);
  4342. Assert.Equal (2, tv.Lines);
  4343. Assert.Equal (new Point (12, 0), tv.CursorPosition);
  4344. tv.Selecting = false;
  4345. Assert.True (tv.ProcessKey (new KeyEvent (Key.Y | Key.CtrlMask, new KeyModifiers ())));
  4346. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  4347. Assert.Equal (3, tv.Lines);
  4348. Assert.Equal (new Point (18, 1), tv.CursorPosition);
  4349. // Undo
  4350. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  4351. Assert.Equal ($"This is the line.{Environment.NewLine}This is the third line.", tv.Text);
  4352. Assert.Equal (2, tv.Lines);
  4353. Assert.Equal (new Point (12, 0), tv.CursorPosition);
  4354. // Redo
  4355. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  4356. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  4357. Assert.Equal (3, tv.Lines);
  4358. Assert.Equal (new Point (18, 1), tv.CursorPosition);
  4359. }
  4360. [Fact]
  4361. [AutoInitShutdown]
  4362. public void HistoryText_Undo_Redo_Cut_Multi_Line_Another_Selected_Paste ()
  4363. {
  4364. var text = "This is the first line.\nThis is the second line.\nThis is the third line.";
  4365. var tv = new TextView () { Text = text };
  4366. tv.SelectionStartColumn = 12;
  4367. tv.CursorPosition = new Point (17, 0);
  4368. Assert.True (tv.ProcessKey (new KeyEvent (Key.W | Key.CtrlMask, new KeyModifiers ())));
  4369. Assert.Equal ($"This is the line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  4370. Assert.Equal ("", tv.SelectedText);
  4371. Assert.Equal (3, tv.Lines);
  4372. Assert.Equal (new Point (12, 0), tv.CursorPosition);
  4373. tv.SelectionStartColumn = 12;
  4374. tv.SelectionStartRow = 1;
  4375. tv.CursorPosition = new Point (18, 1);
  4376. Assert.True (tv.ProcessKey (new KeyEvent (Key.Y | Key.CtrlMask, new KeyModifiers ())));
  4377. Assert.Equal ($"This is the line.{Environment.NewLine}This is the first line.{Environment.NewLine}This is the third line.", tv.Text);
  4378. Assert.Equal (3, tv.Lines);
  4379. Assert.Equal (new Point (17, 1), tv.CursorPosition);
  4380. // Undo
  4381. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  4382. Assert.Equal ($"This is the line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  4383. Assert.Equal (3, tv.Lines);
  4384. Assert.Equal (new Point (12, 1), tv.CursorPosition);
  4385. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  4386. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  4387. Assert.Equal (3, tv.Lines);
  4388. Assert.Equal (new Point (12, 0), tv.CursorPosition);
  4389. // Redo
  4390. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  4391. Assert.Equal ($"This is the line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  4392. Assert.Equal (3, tv.Lines);
  4393. Assert.Equal (new Point (12, 0), tv.CursorPosition);
  4394. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  4395. Assert.Equal ($"This is the line.{Environment.NewLine}This is the first line.{Environment.NewLine}This is the third line.", tv.Text);
  4396. Assert.Equal (3, tv.Lines);
  4397. Assert.Equal (new Point (17, 1), tv.CursorPosition);
  4398. }
  4399. [Fact]
  4400. public void HistoryText_Undo_Redo_KillWordBackward ()
  4401. {
  4402. var text = "First line.\nSecond line.";
  4403. var tv = new TextView () { Text = text };
  4404. Assert.True (tv.ProcessKey (new KeyEvent (Key.End | Key.CtrlMask, new KeyModifiers ())));
  4405. Assert.Equal ($"First line.{Environment.NewLine}Second line.", tv.Text);
  4406. Assert.Equal ("", tv.SelectedText);
  4407. Assert.Equal (2, tv.Lines);
  4408. Assert.Equal (new Point (12, 1), tv.CursorPosition);
  4409. Assert.True (tv.ProcessKey (new KeyEvent (Key.Backspace | Key.CtrlMask, new KeyModifiers ())));
  4410. Assert.Equal ($"First line.{Environment.NewLine}Second ", tv.Text);
  4411. Assert.Equal ("", tv.SelectedText);
  4412. Assert.Equal (2, tv.Lines);
  4413. Assert.Equal (new Point (7, 1), tv.CursorPosition);
  4414. Assert.True (tv.ProcessKey (new KeyEvent (Key.Backspace | Key.CtrlMask, new KeyModifiers ())));
  4415. Assert.Equal ($"First line.{Environment.NewLine}", tv.Text);
  4416. Assert.Equal ("", tv.SelectedText);
  4417. Assert.Equal (2, tv.Lines);
  4418. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  4419. Assert.True (tv.ProcessKey (new KeyEvent (Key.Backspace | Key.CtrlMask, new KeyModifiers ())));
  4420. Assert.Equal ("First line.", tv.Text);
  4421. Assert.Equal ("", tv.SelectedText);
  4422. Assert.Equal (1, tv.Lines);
  4423. Assert.Equal (new Point (11, 0), tv.CursorPosition);
  4424. Assert.True (tv.ProcessKey (new KeyEvent (Key.Backspace | Key.CtrlMask, new KeyModifiers ())));
  4425. Assert.Equal ("First ", tv.Text);
  4426. Assert.Equal ("", tv.SelectedText);
  4427. Assert.Equal (1, tv.Lines);
  4428. Assert.Equal (new Point (6, 0), tv.CursorPosition);
  4429. Assert.True (tv.ProcessKey (new KeyEvent (Key.Backspace | Key.CtrlMask, new KeyModifiers ())));
  4430. Assert.Equal ("", tv.Text);
  4431. Assert.Equal ("", tv.SelectedText);
  4432. Assert.Equal (1, tv.Lines);
  4433. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  4434. // Undo
  4435. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  4436. Assert.Equal ("First ", tv.Text);
  4437. Assert.Equal (1, tv.Lines);
  4438. Assert.Equal (new Point (6, 0), tv.CursorPosition);
  4439. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  4440. Assert.Equal ("First line.", tv.Text);
  4441. Assert.Equal (1, tv.Lines);
  4442. Assert.Equal (new Point (11, 0), tv.CursorPosition);
  4443. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  4444. Assert.Equal ($"First line.{Environment.NewLine}", tv.Text);
  4445. Assert.Equal (2, tv.Lines);
  4446. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  4447. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  4448. Assert.Equal ($"First line.{Environment.NewLine}Second ", tv.Text);
  4449. Assert.Equal (2, tv.Lines);
  4450. Assert.Equal (new Point (7, 1), tv.CursorPosition);
  4451. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  4452. Assert.Equal ($"First line.{Environment.NewLine}Second line.", tv.Text);
  4453. Assert.Equal (2, tv.Lines);
  4454. Assert.Equal (new Point (12, 1), tv.CursorPosition);
  4455. // Redo
  4456. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  4457. Assert.Equal ($"First line.{Environment.NewLine}Second ", tv.Text);
  4458. Assert.Equal (2, tv.Lines);
  4459. Assert.Equal (new Point (7, 1), tv.CursorPosition);
  4460. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  4461. Assert.Equal ($"First line.{Environment.NewLine}", tv.Text);
  4462. Assert.Equal (2, tv.Lines);
  4463. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  4464. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  4465. Assert.Equal ("First line.", tv.Text);
  4466. Assert.Equal (1, tv.Lines);
  4467. Assert.Equal (new Point (11, 0), tv.CursorPosition);
  4468. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  4469. Assert.Equal ("First ", tv.Text);
  4470. Assert.Equal (1, tv.Lines);
  4471. Assert.Equal (new Point (6, 0), tv.CursorPosition);
  4472. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  4473. Assert.Equal ("", tv.Text);
  4474. Assert.Equal (1, tv.Lines);
  4475. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  4476. }
  4477. [Fact]
  4478. public void HistoryText_Undo_Redo_KillWordForward ()
  4479. {
  4480. var text = "First line.\nSecond line.";
  4481. var tv = new TextView () { Text = text };
  4482. Assert.True (tv.ProcessKey (new KeyEvent (Key.DeleteChar | Key.CtrlMask, new KeyModifiers ())));
  4483. Assert.Equal ($"line.{Environment.NewLine}Second line.", tv.Text);
  4484. Assert.Equal ("", tv.SelectedText);
  4485. Assert.Equal (2, tv.Lines);
  4486. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  4487. Assert.True (tv.ProcessKey (new KeyEvent (Key.DeleteChar | Key.CtrlMask, new KeyModifiers ())));
  4488. Assert.Equal ($"{Environment.NewLine}Second line.", tv.Text);
  4489. Assert.Equal (2, tv.Lines);
  4490. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  4491. Assert.True (tv.ProcessKey (new KeyEvent (Key.DeleteChar | Key.CtrlMask, new KeyModifiers ())));
  4492. Assert.Equal ("Second line.", tv.Text);
  4493. Assert.Equal (1, tv.Lines);
  4494. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  4495. Assert.True (tv.ProcessKey (new KeyEvent (Key.DeleteChar | Key.CtrlMask, new KeyModifiers ())));
  4496. Assert.Equal ("line.", tv.Text);
  4497. Assert.Equal (1, tv.Lines);
  4498. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  4499. Assert.True (tv.ProcessKey (new KeyEvent (Key.DeleteChar | Key.CtrlMask, new KeyModifiers ())));
  4500. Assert.Equal ("", tv.Text);
  4501. Assert.Equal (1, tv.Lines);
  4502. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  4503. // Undo
  4504. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  4505. Assert.Equal ("line.", tv.Text);
  4506. Assert.Equal (1, tv.Lines);
  4507. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  4508. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  4509. Assert.Equal ("Second line.", tv.Text);
  4510. Assert.Equal (1, tv.Lines);
  4511. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  4512. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  4513. Assert.Equal ($"{Environment.NewLine}Second line.", tv.Text);
  4514. Assert.Equal (2, tv.Lines);
  4515. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  4516. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  4517. Assert.Equal ($"line.{Environment.NewLine}Second line.", tv.Text);
  4518. Assert.Equal (2, tv.Lines);
  4519. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  4520. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  4521. Assert.Equal ($"First line.{Environment.NewLine}Second line.", tv.Text);
  4522. Assert.Equal (2, tv.Lines);
  4523. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  4524. // Redo
  4525. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  4526. Assert.Equal ($"line.{Environment.NewLine}Second line.", tv.Text);
  4527. Assert.Equal (2, tv.Lines);
  4528. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  4529. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  4530. Assert.Equal ($"{Environment.NewLine}Second line.", tv.Text);
  4531. Assert.Equal (2, tv.Lines);
  4532. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  4533. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  4534. Assert.Equal ("Second line.", tv.Text);
  4535. Assert.Equal (1, tv.Lines);
  4536. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  4537. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  4538. Assert.Equal ("line.", tv.Text);
  4539. Assert.Equal (1, tv.Lines);
  4540. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  4541. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  4542. Assert.Equal ("", tv.Text);
  4543. Assert.Equal (1, tv.Lines);
  4544. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  4545. }
  4546. [Fact]
  4547. [AutoInitShutdown]
  4548. public void HistoryText_Undo_Redo_KillToStartOfLine ()
  4549. {
  4550. var text = "First line.\nSecond line.";
  4551. var tv = new TextView () { Text = text };
  4552. Assert.True (tv.ProcessKey (new KeyEvent (Key.End | Key.CtrlMask, new KeyModifiers ())));
  4553. Assert.Equal ($"First line.{Environment.NewLine}Second line.", tv.Text);
  4554. Assert.Equal ("", tv.SelectedText);
  4555. Assert.Equal (2, tv.Lines);
  4556. Assert.Equal (new Point (12, 1), tv.CursorPosition);
  4557. Assert.True (tv.ProcessKey (new KeyEvent (Key.K | Key.AltMask, new KeyModifiers ())));
  4558. Assert.Equal ($"First line.{Environment.NewLine}", tv.Text);
  4559. Assert.Equal ("", tv.SelectedText);
  4560. Assert.Equal ("Second line.", Clipboard.Contents);
  4561. Assert.Equal (2, tv.Lines);
  4562. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  4563. Assert.True (tv.ProcessKey (new KeyEvent (Key.K | Key.AltMask, new KeyModifiers ())));
  4564. Assert.Equal ("First line.", tv.Text);
  4565. Assert.Equal ("", tv.SelectedText);
  4566. Assert.Equal ($"Second line.{Environment.NewLine}", Clipboard.Contents);
  4567. Assert.Equal (1, tv.Lines);
  4568. Assert.Equal (new Point (11, 0), tv.CursorPosition);
  4569. Assert.True (tv.ProcessKey (new KeyEvent (Key.K | Key.AltMask, new KeyModifiers ())));
  4570. Assert.Equal ("", tv.Text);
  4571. Assert.Equal ("", tv.SelectedText);
  4572. Assert.Equal ($"Second line.{Environment.NewLine}First line.", Clipboard.Contents);
  4573. Assert.Equal (1, tv.Lines);
  4574. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  4575. // Undo
  4576. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  4577. Assert.Equal ("First line.", tv.Text);
  4578. Assert.Equal (1, tv.Lines);
  4579. Assert.Equal (new Point (11, 0), tv.CursorPosition);
  4580. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  4581. Assert.Equal ($"First line.{Environment.NewLine}", tv.Text);
  4582. Assert.Equal (2, tv.Lines);
  4583. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  4584. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  4585. Assert.Equal ($"First line.{Environment.NewLine}Second line.", tv.Text);
  4586. Assert.Equal (2, tv.Lines);
  4587. Assert.Equal (new Point (12, 1), tv.CursorPosition);
  4588. // Redo
  4589. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  4590. Assert.Equal ($"First line.{Environment.NewLine}", tv.Text);
  4591. Assert.Equal (2, tv.Lines);
  4592. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  4593. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  4594. Assert.Equal ($"First line.", tv.Text);
  4595. Assert.Equal (1, tv.Lines);
  4596. Assert.Equal (new Point (11, 0), tv.CursorPosition);
  4597. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  4598. Assert.Equal ("", tv.Text);
  4599. Assert.Equal (1, tv.Lines);
  4600. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  4601. }
  4602. [Fact]
  4603. [AutoInitShutdown]
  4604. public void HistoryText_Undo_Redo_KillToEndOfLine ()
  4605. {
  4606. var text = "First line.\nSecond line.";
  4607. var tv = new TextView () { Text = text };
  4608. Assert.True (tv.ProcessKey (new KeyEvent (Key.K | Key.CtrlMask, new KeyModifiers ())));
  4609. Assert.Equal ($"{Environment.NewLine}Second line.", tv.Text);
  4610. Assert.Equal ("", tv.SelectedText);
  4611. Assert.Equal ("First line.", Clipboard.Contents);
  4612. Assert.Equal (2, tv.Lines);
  4613. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  4614. Assert.True (tv.ProcessKey (new KeyEvent (Key.K | Key.CtrlMask, new KeyModifiers ())));
  4615. Assert.Equal ("Second line.", tv.Text);
  4616. Assert.Equal ("", tv.SelectedText);
  4617. Assert.Equal ($"First line.{Environment.NewLine}", Clipboard.Contents);
  4618. Assert.Equal (1, 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 ("", tv.Text);
  4622. Assert.Equal ("", tv.SelectedText);
  4623. Assert.Equal ($"First line.{Environment.NewLine}Second line.", Clipboard.Contents);
  4624. Assert.Equal (1, tv.Lines);
  4625. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  4626. // Undo
  4627. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  4628. Assert.Equal ("Second line.", tv.Text);
  4629. Assert.Equal (1, tv.Lines);
  4630. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  4631. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  4632. Assert.Equal ($"{Environment.NewLine}Second line.", tv.Text);
  4633. Assert.Equal (2, tv.Lines);
  4634. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  4635. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  4636. Assert.Equal ($"First line.{Environment.NewLine}Second line.", tv.Text);
  4637. Assert.Equal (2, tv.Lines);
  4638. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  4639. // Redo
  4640. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  4641. Assert.Equal ($"{Environment.NewLine}Second line.", tv.Text);
  4642. Assert.Equal (2, tv.Lines);
  4643. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  4644. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  4645. Assert.Equal ("Second line.", tv.Text);
  4646. Assert.Equal (1, tv.Lines);
  4647. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  4648. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  4649. Assert.Equal ("", tv.Text);
  4650. Assert.Equal (1, tv.Lines);
  4651. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  4652. }
  4653. [Fact]
  4654. public void HistoryText_Undo_Redo_Changing_On_Middle_Clear_History_Forwards ()
  4655. {
  4656. var tv = new TextView ();
  4657. Assert.True (tv.ProcessKey (new KeyEvent (Key.D1, new KeyModifiers ())));
  4658. Assert.Equal ("1", tv.Text);
  4659. Assert.Equal (1, tv.Lines);
  4660. Assert.Equal (new Point (1, 0), tv.CursorPosition);
  4661. Assert.True (tv.ProcessKey (new KeyEvent (Key.D2, new KeyModifiers ())));
  4662. Assert.Equal ("12", tv.Text);
  4663. Assert.Equal (1, tv.Lines);
  4664. Assert.Equal (new Point (2, 0), tv.CursorPosition);
  4665. Assert.True (tv.ProcessKey (new KeyEvent (Key.D3, new KeyModifiers ())));
  4666. Assert.Equal ("123", tv.Text);
  4667. Assert.Equal (1, tv.Lines);
  4668. Assert.Equal (new Point (3, 0), tv.CursorPosition);
  4669. // Undo
  4670. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  4671. Assert.Equal ("12", tv.Text);
  4672. Assert.Equal (1, tv.Lines);
  4673. Assert.Equal (new Point (2, 0), tv.CursorPosition);
  4674. Assert.True (tv.ProcessKey (new KeyEvent (Key.D4, new KeyModifiers ())));
  4675. Assert.Equal ("124", tv.Text);
  4676. Assert.Equal (1, tv.Lines);
  4677. Assert.Equal (new Point (3, 0), tv.CursorPosition);
  4678. // Redo
  4679. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  4680. Assert.Equal ("124", tv.Text);
  4681. Assert.Equal (1, tv.Lines);
  4682. Assert.Equal (new Point (3, 0), tv.CursorPosition);
  4683. }
  4684. [Fact]
  4685. public void HistoryText_Undo_Redo_Single_Line_Selected_Return ()
  4686. {
  4687. var text = "This is the first line.\nThis is the second line.\nThis is the third line.";
  4688. var tv = new TextView () { Text = text };
  4689. tv.SelectionStartColumn = 12;
  4690. tv.CursorPosition = new Point (17, 0);
  4691. Assert.True (tv.ProcessKey (new KeyEvent (Key.Enter, new KeyModifiers ())));
  4692. Assert.Equal ($"This is the {Environment.NewLine} line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  4693. Assert.Equal (4, tv.Lines);
  4694. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  4695. // Undo
  4696. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  4697. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  4698. Assert.Equal (3, tv.Lines);
  4699. Assert.Equal (new Point (17, 0), tv.CursorPosition);
  4700. Assert.False (tv.IsDirty);
  4701. // Redo
  4702. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  4703. Assert.Equal ($"This is the {Environment.NewLine} line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  4704. Assert.Equal (4, tv.Lines);
  4705. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  4706. // Undo
  4707. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  4708. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  4709. Assert.Equal (3, tv.Lines);
  4710. Assert.Equal (new Point (17, 0), tv.CursorPosition);
  4711. Assert.False (tv.IsDirty);
  4712. // Redo
  4713. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  4714. Assert.Equal ($"This is the {Environment.NewLine} line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  4715. Assert.Equal (4, tv.Lines);
  4716. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  4717. }
  4718. [Fact]
  4719. public void HistoryText_Undo_Redo_Two_Line_Selected_Return ()
  4720. {
  4721. var text = "This is the first line.\nThis is the second line.\nThis is the third line.";
  4722. var tv = new TextView () { Text = text };
  4723. tv.SelectionStartColumn = 12;
  4724. tv.CursorPosition = new Point (18, 1);
  4725. Assert.True (tv.ProcessKey (new KeyEvent (Key.Enter, new KeyModifiers ())));
  4726. Assert.Equal ($"This is the {Environment.NewLine} line.{Environment.NewLine}This is the third line.", tv.Text);
  4727. Assert.Equal (3, tv.Lines);
  4728. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  4729. // Undo
  4730. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  4731. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  4732. Assert.Equal (3, tv.Lines);
  4733. Assert.Equal (new Point (18, 1), tv.CursorPosition);
  4734. Assert.False (tv.IsDirty);
  4735. // Redo
  4736. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  4737. Assert.Equal ($"This is the {Environment.NewLine} line.{Environment.NewLine}This is the third line.", tv.Text);
  4738. Assert.Equal (3, tv.Lines);
  4739. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  4740. // Undo
  4741. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  4742. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  4743. Assert.Equal (3, tv.Lines);
  4744. Assert.Equal (new Point (18, 1), tv.CursorPosition);
  4745. Assert.False (tv.IsDirty);
  4746. // Redo
  4747. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  4748. Assert.Equal ($"This is the {Environment.NewLine} line.{Environment.NewLine}This is the third line.", tv.Text);
  4749. Assert.Equal (3, tv.Lines);
  4750. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  4751. }
  4752. [Fact]
  4753. public void HistoryText_Undo_Redo_Three_Line_Selected_Return ()
  4754. {
  4755. var text = "This is the first line.\nThis is the second line.\nThis is the third line.";
  4756. var tv = new TextView () { Text = text };
  4757. tv.SelectionStartColumn = 12;
  4758. tv.CursorPosition = new Point (17, 2);
  4759. Assert.True (tv.ProcessKey (new KeyEvent (Key.Enter, new KeyModifiers ())));
  4760. Assert.Equal ($"This is the {Environment.NewLine} line.", tv.Text);
  4761. Assert.Equal (2, tv.Lines);
  4762. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  4763. // Undo
  4764. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  4765. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  4766. Assert.Equal (3, tv.Lines);
  4767. Assert.Equal (new Point (17, 2), tv.CursorPosition);
  4768. Assert.False (tv.IsDirty);
  4769. // Redo
  4770. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  4771. Assert.Equal ($"This is the {Environment.NewLine} line.", tv.Text);
  4772. Assert.Equal (2, tv.Lines);
  4773. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  4774. // Undo
  4775. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  4776. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  4777. Assert.Equal (3, tv.Lines);
  4778. Assert.Equal (new Point (17, 2), tv.CursorPosition);
  4779. Assert.False (tv.IsDirty);
  4780. // Redo
  4781. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  4782. Assert.Equal ($"This is the {Environment.NewLine} line.", tv.Text);
  4783. Assert.Equal (2, tv.Lines);
  4784. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  4785. }
  4786. [Fact]
  4787. public void HistoryText_Undo_Redo_Single_Second_Line_Selected_Return ()
  4788. {
  4789. var text = "This is the first line.\nThis is the second line.\nThis is the third line.";
  4790. var tv = new TextView () { Text = text };
  4791. tv.SelectionStartColumn = 12;
  4792. tv.SelectionStartRow = 1;
  4793. tv.CursorPosition = new Point (18, 1);
  4794. Assert.True (tv.ProcessKey (new KeyEvent (Key.Enter, new KeyModifiers ())));
  4795. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the {Environment.NewLine} line.{Environment.NewLine}This is the third line.", tv.Text);
  4796. Assert.Equal (4, tv.Lines);
  4797. Assert.Equal (new Point (0, 2), tv.CursorPosition);
  4798. // Undo
  4799. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  4800. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  4801. Assert.Equal (3, tv.Lines);
  4802. Assert.Equal (new Point (18, 1), tv.CursorPosition);
  4803. Assert.False (tv.IsDirty);
  4804. // Redo
  4805. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  4806. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the {Environment.NewLine} line.{Environment.NewLine}This is the third line.", tv.Text);
  4807. Assert.Equal (4, tv.Lines);
  4808. Assert.Equal (new Point (0, 2), tv.CursorPosition);
  4809. // Undo
  4810. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  4811. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  4812. Assert.Equal (3, tv.Lines);
  4813. Assert.Equal (new Point (18, 1), tv.CursorPosition);
  4814. Assert.False (tv.IsDirty);
  4815. // Redo
  4816. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  4817. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the {Environment.NewLine} line.{Environment.NewLine}This is the third line.", tv.Text);
  4818. Assert.Equal (4, tv.Lines);
  4819. Assert.Equal (new Point (0, 2), tv.CursorPosition);
  4820. }
  4821. [Fact]
  4822. public void HistoryText_Undo_Redo_First_Line_Selected_Return_And_InsertText ()
  4823. {
  4824. var text = "This is the first line.\nThis is the second line.\nThis is the third line.";
  4825. var tv = new TextView () { Text = text };
  4826. tv.SelectionStartColumn = 12;
  4827. tv.CursorPosition = new Point (17, 0);
  4828. Assert.True (tv.ProcessKey (new KeyEvent (Key.Enter, new KeyModifiers ())));
  4829. Assert.Equal ($"This is the {Environment.NewLine} line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  4830. Assert.Equal (4, tv.Lines);
  4831. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  4832. Assert.True (tv.ProcessKey (new KeyEvent (Key.a, new KeyModifiers ())));
  4833. 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);
  4834. Assert.Equal (4, tv.Lines);
  4835. Assert.Equal (new Point (1, 1), tv.CursorPosition);
  4836. // Undo
  4837. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  4838. Assert.Equal ($"This is the {Environment.NewLine} line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  4839. Assert.Equal (4, tv.Lines);
  4840. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  4841. Assert.True (tv.IsDirty);
  4842. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  4843. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  4844. Assert.Equal (3, tv.Lines);
  4845. Assert.Equal (new Point (17, 0), tv.CursorPosition);
  4846. Assert.False (tv.IsDirty);
  4847. // Redo
  4848. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  4849. Assert.Equal ($"This is the {Environment.NewLine} line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  4850. Assert.Equal (4, tv.Lines);
  4851. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  4852. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  4853. 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);
  4854. Assert.Equal (4, tv.Lines);
  4855. Assert.Equal (new Point (1, 1), tv.CursorPosition);
  4856. // Undo
  4857. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  4858. Assert.Equal ($"This is the {Environment.NewLine} line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  4859. Assert.Equal (4, tv.Lines);
  4860. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  4861. Assert.True (tv.IsDirty);
  4862. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  4863. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  4864. Assert.Equal (3, tv.Lines);
  4865. Assert.Equal (new Point (17, 0), tv.CursorPosition);
  4866. Assert.False (tv.IsDirty);
  4867. // Redo
  4868. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  4869. Assert.Equal ($"This is the {Environment.NewLine} line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  4870. Assert.Equal (4, tv.Lines);
  4871. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  4872. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  4873. 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);
  4874. Assert.Equal (4, tv.Lines);
  4875. Assert.Equal (new Point (1, 1), tv.CursorPosition);
  4876. }
  4877. [Fact]
  4878. public void HistoryText_Undo_Redo_Single_Second_Line_Selected_Return_And_InsertText ()
  4879. {
  4880. var text = "This is the first line.\nThis is the second line.\nThis is the third line.";
  4881. var tv = new TextView () { Text = text };
  4882. tv.SelectionStartColumn = 12;
  4883. tv.SelectionStartRow = 1;
  4884. tv.CursorPosition = new Point (18, 1);
  4885. Assert.True (tv.ProcessKey (new KeyEvent (Key.Enter, new KeyModifiers ())));
  4886. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the {Environment.NewLine} line.{Environment.NewLine}This is the third line.", tv.Text);
  4887. Assert.Equal (4, tv.Lines);
  4888. Assert.Equal (new Point (0, 2), tv.CursorPosition);
  4889. Assert.True (tv.ProcessKey (new KeyEvent (Key.a, new KeyModifiers ())));
  4890. 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);
  4891. Assert.Equal (4, tv.Lines);
  4892. Assert.Equal (new Point (1, 2), tv.CursorPosition);
  4893. // Undo
  4894. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  4895. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the {Environment.NewLine} line.{Environment.NewLine}This is the third line.", tv.Text);
  4896. Assert.Equal (4, tv.Lines);
  4897. Assert.Equal (new Point (0, 2), tv.CursorPosition);
  4898. Assert.True (tv.IsDirty);
  4899. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  4900. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  4901. Assert.Equal (3, tv.Lines);
  4902. Assert.Equal (new Point (18, 1), tv.CursorPosition);
  4903. Assert.False (tv.IsDirty);
  4904. // Redo
  4905. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  4906. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the {Environment.NewLine} line.{Environment.NewLine}This is the third line.", tv.Text);
  4907. Assert.Equal (4, tv.Lines);
  4908. Assert.Equal (new Point (0, 2), tv.CursorPosition);
  4909. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  4910. 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);
  4911. Assert.Equal (4, tv.Lines);
  4912. Assert.Equal (new Point (1, 2), tv.CursorPosition);
  4913. // Undo
  4914. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  4915. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the {Environment.NewLine} line.{Environment.NewLine}This is the third line.", tv.Text);
  4916. Assert.Equal (4, tv.Lines);
  4917. Assert.Equal (new Point (0, 2), tv.CursorPosition);
  4918. Assert.True (tv.IsDirty);
  4919. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  4920. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  4921. Assert.Equal (3, tv.Lines);
  4922. Assert.Equal (new Point (18, 1), tv.CursorPosition);
  4923. Assert.False (tv.IsDirty);
  4924. // Redo
  4925. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  4926. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the {Environment.NewLine} line.{Environment.NewLine}This is the third line.", tv.Text);
  4927. Assert.Equal (4, tv.Lines);
  4928. Assert.Equal (new Point (0, 2), tv.CursorPosition);
  4929. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  4930. 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);
  4931. Assert.Equal (4, tv.Lines);
  4932. Assert.Equal (new Point (1, 2), tv.CursorPosition);
  4933. }
  4934. [Fact]
  4935. public void HistoryText_Undo_Redo_Multi_Line_Selected_All_Return_And_InsertText ()
  4936. {
  4937. var text = "This is the first line.\nThis is the second line.\nThis is the third line.";
  4938. var tv = new TextView () { Text = text };
  4939. Assert.True (tv.ProcessKey (new KeyEvent (Key.End | Key.CtrlMask | Key.ShiftMask, new KeyModifiers ())));
  4940. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  4941. Assert.Equal (3, tv.Lines);
  4942. Assert.Equal (new Point (23, 2), tv.CursorPosition);
  4943. Assert.True (tv.ProcessKey (new KeyEvent (Key.Enter, new KeyModifiers ())));
  4944. Assert.Equal ($"{Environment.NewLine}", tv.Text);
  4945. Assert.Equal (2, tv.Lines);
  4946. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  4947. Assert.True (tv.ProcessKey (new KeyEvent (Key.a, new KeyModifiers ())));
  4948. Assert.Equal ($"{Environment.NewLine}a", tv.Text);
  4949. Assert.Equal (2, tv.Lines);
  4950. Assert.Equal (new Point (1, 1), tv.CursorPosition);
  4951. // Undo
  4952. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  4953. Assert.Equal ($"{Environment.NewLine}", tv.Text);
  4954. Assert.Equal (2, tv.Lines);
  4955. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  4956. Assert.True (tv.IsDirty);
  4957. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  4958. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  4959. Assert.Equal (3, tv.Lines);
  4960. Assert.Equal (new Point (23, 2), tv.CursorPosition);
  4961. Assert.False (tv.IsDirty);
  4962. // Redo
  4963. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  4964. Assert.Equal ($"{Environment.NewLine}", tv.Text);
  4965. Assert.Equal (2, tv.Lines);
  4966. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  4967. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  4968. Assert.Equal ($"{Environment.NewLine}a", tv.Text);
  4969. Assert.Equal (2, tv.Lines);
  4970. Assert.Equal (new Point (1, 1), tv.CursorPosition);
  4971. // Undo
  4972. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  4973. Assert.Equal ($"{Environment.NewLine}", tv.Text);
  4974. Assert.Equal (2, tv.Lines);
  4975. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  4976. Assert.True (tv.IsDirty);
  4977. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  4978. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  4979. Assert.Equal (3, tv.Lines);
  4980. Assert.Equal (new Point (23, 2), tv.CursorPosition);
  4981. Assert.False (tv.IsDirty);
  4982. // Redo
  4983. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  4984. Assert.Equal ($"{Environment.NewLine}", tv.Text);
  4985. Assert.Equal (2, tv.Lines);
  4986. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  4987. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  4988. Assert.Equal ($"{Environment.NewLine}a", tv.Text);
  4989. Assert.Equal (2, tv.Lines);
  4990. Assert.Equal (new Point (1, 1), tv.CursorPosition);
  4991. }
  4992. [Fact]
  4993. public void HistoryText_Undo_Redo_Ending_With_Newline_Multi_Line_Selected_Almost_All_Return_And_InsertText ()
  4994. {
  4995. var text = "This is the first line.\nThis is the second line.\nThis is the third line.\n";
  4996. var tv = new TextView () { Text = text };
  4997. tv.SelectionStartColumn = 12;
  4998. tv.CursorPosition = new Point (12, 2);
  4999. Assert.True (tv.ProcessKey (new KeyEvent (Key.Enter, new KeyModifiers ())));
  5000. Assert.Equal ($"This is the {Environment.NewLine}third line.{Environment.NewLine}", tv.Text);
  5001. Assert.Equal (3, tv.Lines);
  5002. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  5003. Assert.True (tv.ProcessKey (new KeyEvent (Key.a, new KeyModifiers ())));
  5004. Assert.Equal ($"This is the {Environment.NewLine}athird line.{Environment.NewLine}", tv.Text);
  5005. Assert.Equal (3, tv.Lines);
  5006. Assert.Equal (new Point (1, 1), tv.CursorPosition);
  5007. // Undo
  5008. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  5009. Assert.Equal ($"This is the {Environment.NewLine}third line.{Environment.NewLine}", tv.Text);
  5010. Assert.Equal (3, tv.Lines);
  5011. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  5012. Assert.True (tv.IsDirty);
  5013. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  5014. 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);
  5015. Assert.Equal (4, tv.Lines);
  5016. Assert.Equal (new Point (12, 2), tv.CursorPosition);
  5017. Assert.False (tv.IsDirty);
  5018. // Redo
  5019. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  5020. Assert.Equal ($"This is the {Environment.NewLine}third line.{Environment.NewLine}", tv.Text);
  5021. Assert.Equal (3, tv.Lines);
  5022. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  5023. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  5024. Assert.Equal ($"This is the {Environment.NewLine}athird line.{Environment.NewLine}", tv.Text);
  5025. Assert.Equal (3, tv.Lines);
  5026. Assert.Equal (new Point (1, 1), tv.CursorPosition);
  5027. // Undo
  5028. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  5029. Assert.Equal ($"This is the {Environment.NewLine}third line.{Environment.NewLine}", tv.Text);
  5030. Assert.Equal (3, tv.Lines);
  5031. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  5032. Assert.True (tv.IsDirty);
  5033. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  5034. 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);
  5035. Assert.Equal (4, tv.Lines);
  5036. Assert.Equal (new Point (12, 2), tv.CursorPosition);
  5037. Assert.False (tv.IsDirty);
  5038. // Redo
  5039. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  5040. Assert.Equal ($"This is the {Environment.NewLine}third line.{Environment.NewLine}", tv.Text);
  5041. Assert.Equal (3, tv.Lines);
  5042. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  5043. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  5044. Assert.Equal ($"This is the {Environment.NewLine}athird line.{Environment.NewLine}", tv.Text);
  5045. Assert.Equal (3, tv.Lines);
  5046. Assert.Equal (new Point (1, 1), tv.CursorPosition);
  5047. }
  5048. [Fact]
  5049. public void HistoryText_Undo_Redo_Disabled_On_WordWrap ()
  5050. {
  5051. var text = "This is the first line.\nThis is the second line.\nThis is the third line.\n";
  5052. var tv = new TextView () { Width = 80, Height = 5, Text = text };
  5053. Assert.False (tv.WordWrap);
  5054. tv.WordWrap = true;
  5055. tv.SelectionStartColumn = 12;
  5056. tv.CursorPosition = new Point (12, 2);
  5057. Assert.True (tv.ProcessKey (new KeyEvent (Key.Enter, new KeyModifiers ())));
  5058. Assert.Equal ($"This is the {Environment.NewLine}third line.{Environment.NewLine}", tv.Text);
  5059. Assert.Equal (3, tv.Lines);
  5060. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  5061. Assert.True (tv.ProcessKey (new KeyEvent (Key.a, new KeyModifiers ())));
  5062. Assert.Equal ($"This is the {Environment.NewLine}athird line.{Environment.NewLine}", tv.Text);
  5063. Assert.Equal (3, tv.Lines);
  5064. Assert.Equal (new Point (1, 1), tv.CursorPosition);
  5065. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  5066. Assert.Equal ($"This is the {Environment.NewLine}third line.{Environment.NewLine}", tv.Text);
  5067. Assert.Equal (3, tv.Lines);
  5068. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  5069. Assert.True (tv.IsDirty);
  5070. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  5071. Assert.Equal ($"This is the {Environment.NewLine}athird line.{Environment.NewLine}", tv.Text);
  5072. Assert.Equal (3, tv.Lines);
  5073. Assert.Equal (new Point (1, 1), tv.CursorPosition);
  5074. }
  5075. [Fact]
  5076. public void HistoryText_Undo_Redo_Multiline_Simples_Tab_BackTab ()
  5077. {
  5078. var text = "First line.\nSecond line.\nThird line.";
  5079. var tv = new TextView () { Width = 80, Height = 5, Text = text };
  5080. Assert.True (tv.ProcessKey (new KeyEvent (Key.Tab, new KeyModifiers ())));
  5081. Assert.Equal ($"\tFirst line.{Environment.NewLine}Second line.{Environment.NewLine}Third line.", tv.Text);
  5082. Assert.Equal (3, tv.Lines);
  5083. Assert.Equal (new Point (1, 0), tv.CursorPosition);
  5084. Assert.True (tv.ProcessKey (new KeyEvent (Key.BackTab, new KeyModifiers ())));
  5085. Assert.Equal ($"First line.{Environment.NewLine}Second line.{Environment.NewLine}Third line.", tv.Text);
  5086. Assert.Equal (3, tv.Lines);
  5087. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  5088. // Undo
  5089. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  5090. Assert.Equal ($"\tFirst line.{Environment.NewLine}Second line.{Environment.NewLine}Third line.", tv.Text);
  5091. Assert.Equal (3, tv.Lines);
  5092. Assert.Equal (new Point (1, 0), tv.CursorPosition);
  5093. Assert.True (tv.IsDirty);
  5094. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  5095. Assert.Equal ($"First line.{Environment.NewLine}Second line.{Environment.NewLine}Third line.", tv.Text);
  5096. Assert.Equal (3, tv.Lines);
  5097. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  5098. Assert.False (tv.IsDirty);
  5099. // Redo
  5100. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  5101. Assert.Equal ($"\tFirst line.{Environment.NewLine}Second line.{Environment.NewLine}Third line.", tv.Text);
  5102. Assert.Equal (3, tv.Lines);
  5103. Assert.Equal (new Point (1, 0), tv.CursorPosition);
  5104. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  5105. Assert.Equal ($"First line.{Environment.NewLine}Second line.{Environment.NewLine}Third line.", tv.Text);
  5106. Assert.Equal (3, tv.Lines);
  5107. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  5108. }
  5109. [Fact]
  5110. public void HistoryText_Undo_Redo_Multiline_Selected_Tab_BackTab ()
  5111. {
  5112. var text = "First line.\nSecond line.\nThird line.";
  5113. var tv = new TextView () { Width = 80, Height = 5, Text = text };
  5114. tv.SelectionStartColumn = 6;
  5115. tv.CursorPosition = new Point (6, 2);
  5116. Assert.True (tv.ProcessKey (new KeyEvent (Key.Tab, new KeyModifiers ())));
  5117. Assert.Equal ("First \tline.", tv.Text);
  5118. Assert.Equal (1, tv.Lines);
  5119. Assert.Equal (new Point (7, 0), tv.CursorPosition);
  5120. Assert.True (tv.ProcessKey (new KeyEvent (Key.BackTab, new KeyModifiers ())));
  5121. Assert.Equal ("First line.", tv.Text);
  5122. Assert.Equal (1, tv.Lines);
  5123. Assert.Equal (new Point (6, 0), tv.CursorPosition);
  5124. // Undo
  5125. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  5126. Assert.Equal ("First \tline.", tv.Text);
  5127. Assert.Equal (1, tv.Lines);
  5128. Assert.Equal (new Point (7, 0), tv.CursorPosition);
  5129. Assert.True (tv.IsDirty);
  5130. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  5131. Assert.Equal ($"First line.{Environment.NewLine}Second line.{Environment.NewLine}Third line.", tv.Text);
  5132. Assert.Equal (3, tv.Lines);
  5133. Assert.Equal (new Point (6, 2), tv.CursorPosition);
  5134. Assert.False (tv.IsDirty);
  5135. // Redo
  5136. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  5137. Assert.Equal ("First \tline.", tv.Text);
  5138. Assert.Equal (1, tv.Lines);
  5139. Assert.Equal (new Point (7, 0), tv.CursorPosition);
  5140. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  5141. Assert.Equal ("First line.", tv.Text);
  5142. Assert.Equal (1, tv.Lines);
  5143. Assert.Equal (new Point (6, 0), tv.CursorPosition);
  5144. }
  5145. [Fact]
  5146. public void HistoryText_ClearHistoryChanges ()
  5147. {
  5148. var text = "This is the first line.\nThis is the second line.\nThis is the third line.";
  5149. var tv = new TextView () { Text = text };
  5150. Assert.True (tv.ProcessKey (new KeyEvent (Key.Enter, new KeyModifiers ())));
  5151. 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);
  5152. Assert.Equal (4, tv.Lines);
  5153. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  5154. Assert.True (tv.IsDirty);
  5155. Assert.True (tv.HasHistoryChanges);
  5156. tv.ClearHistoryChanges ();
  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.False (tv.IsDirty);
  5161. Assert.False (tv.HasHistoryChanges);
  5162. }
  5163. [Fact]
  5164. public void GetRegion_StringFromRunes_Environment_NewLine ()
  5165. {
  5166. var tv = new TextView () { Text = $"1{Environment.NewLine}2" };
  5167. Assert.Equal ($"1{Environment.NewLine}2", tv.Text);
  5168. Assert.Equal ("", tv.SelectedText);
  5169. tv.SelectAll ();
  5170. Assert.Equal ($"1{Environment.NewLine}2", tv.Text);
  5171. Assert.Equal ($"1{Environment.NewLine}2", tv.SelectedText);
  5172. }
  5173. [Fact, AutoInitShutdown]
  5174. public void WordWrap_Not_Throw_If_Width_Is_Less_Than_Zero ()
  5175. {
  5176. var exception = Record.Exception (() => {
  5177. var tv = new TextView () {
  5178. Width = Dim.Fill (),
  5179. Height = Dim.Fill (),
  5180. WordWrap = true,
  5181. Text = "これは、左右のクリップ境界をテストするための非常に長いテキストです。"
  5182. };
  5183. });
  5184. Assert.Null (exception);
  5185. }
  5186. [Fact]
  5187. [AutoInitShutdown]
  5188. public void ScrollDownTillCaretOffscreen_ThenType ()
  5189. {
  5190. var tv = new TextView {
  5191. Width = 10,
  5192. Height = 5
  5193. };
  5194. // add 100 lines of wide text to view
  5195. for (int i = 0; i < 100; i++)
  5196. tv.Text += new string ('x', 100) + Environment.NewLine;
  5197. Assert.Equal (0, tv.CursorPosition.Y);
  5198. tv.ScrollTo (50);
  5199. Assert.Equal (0, tv.CursorPosition.Y);
  5200. tv.ProcessKey (new KeyEvent (Key.p, new KeyModifiers ()));
  5201. }
  5202. [Fact]
  5203. [AutoInitShutdown]
  5204. public void MoveDown_By_Setting_CursorPosition ()
  5205. {
  5206. var tv = new TextView {
  5207. Width = 10,
  5208. Height = 5
  5209. };
  5210. // add 100 lines of wide text to view
  5211. for (int i = 0; i < 100; i++)
  5212. tv.Text += new string ('x', 100) + (i == 99 ? "" : Environment.NewLine);
  5213. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  5214. tv.CursorPosition = new Point (5, 50);
  5215. Assert.Equal (new Point (5, 50), tv.CursorPosition);
  5216. tv.CursorPosition = new Point (200, 200);
  5217. Assert.Equal (new Point (100, 99), tv.CursorPosition);
  5218. }
  5219. [Fact]
  5220. [AutoInitShutdown]
  5221. public void ScrollTo_CursorPosition ()
  5222. {
  5223. var tv = new TextView {
  5224. Width = 10,
  5225. Height = 5
  5226. };
  5227. // add 100 lines of wide text to view
  5228. for (int i = 0; i < 100; i++)
  5229. tv.Text += new string ('x', 100) + (i == 99 ? "" : Environment.NewLine);
  5230. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  5231. tv.ScrollTo (50);
  5232. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  5233. tv.CursorPosition = new Point (tv.LeftColumn, tv.TopRow);
  5234. Assert.Equal (new Point (0, 50), tv.CursorPosition);
  5235. }
  5236. }
  5237. }