TextViewTests.cs 265 KB

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