TextViewTests.cs 266 KB

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