TextViewTests.cs 265 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822
  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 ()
  1824. {
  1825. var text = "Testing";
  1826. using (System.IO.MemoryStream stream = new System.IO.MemoryStream ()) {
  1827. var writer = new System.IO.StreamWriter (stream);
  1828. writer.Write (text);
  1829. writer.Flush ();
  1830. stream.Position = 0;
  1831. var tv = new TextView ();
  1832. tv.LoadStream (stream);
  1833. Assert.Equal (7, text.Length);
  1834. Assert.Equal (text.Length, tv.Text.Length);
  1835. Assert.Equal (text, tv.Text);
  1836. Assert.False (tv.IsDirty);
  1837. }
  1838. }
  1839. [Fact]
  1840. public void LoadStream_IsDirty_With_Null_On_The_Text ()
  1841. {
  1842. var text = "Test\0ing";
  1843. using (System.IO.MemoryStream stream = new System.IO.MemoryStream ()) {
  1844. var writer = new System.IO.StreamWriter (stream);
  1845. writer.Write (text);
  1846. writer.Flush ();
  1847. stream.Position = 0;
  1848. var tv = new TextView ();
  1849. tv.LoadStream (stream);
  1850. Assert.Equal (8, text.Length);
  1851. Assert.Equal (text.Length, tv.Text.Length);
  1852. Assert.Equal (8, text.Length);
  1853. Assert.Equal (8, tv.Text.Length);
  1854. Assert.Equal (text, tv.Text);
  1855. Assert.False (tv.IsDirty);
  1856. Assert.Equal ('\u2400', ConsoleDriver.MakePrintable ((Rune)tv.Text [4]));
  1857. }
  1858. }
  1859. [Fact]
  1860. public void StringToRunes_Slipts_CRLF ()
  1861. {
  1862. var text = "This is the first line.\r\nThis is the second line.\r\n";
  1863. var tv = new TextView ();
  1864. tv.Text = text;
  1865. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}", tv.Text);
  1866. }
  1867. [Fact]
  1868. public void StringToRunes_Slipts_LF ()
  1869. {
  1870. var text = "This is the first line.\nThis is the second line.\n";
  1871. var tv = new TextView ();
  1872. tv.Text = text;
  1873. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}", tv.Text);
  1874. }
  1875. [Fact]
  1876. public void CloseFile_Throws_If_FilePath_Is_Null ()
  1877. {
  1878. var tv = new TextView ();
  1879. Assert.Throws<ArgumentNullException> (() => tv.CloseFile ());
  1880. }
  1881. [Fact]
  1882. public void WordWrap_Gets_Sets ()
  1883. {
  1884. var tv = new TextView () { WordWrap = true };
  1885. Assert.True (tv.WordWrap);
  1886. tv.WordWrap = false;
  1887. Assert.False (tv.WordWrap);
  1888. }
  1889. [Fact]
  1890. public void WordWrap_True_Text_Always_Returns_Unwrapped ()
  1891. {
  1892. var text = "This is the first line.\nThis is the second line.\n";
  1893. var tv = new TextView () { Width = 10 };
  1894. tv.Text = text;
  1895. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}", tv.Text);
  1896. tv.WordWrap = true;
  1897. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}", tv.Text);
  1898. }
  1899. [Fact]
  1900. [InitShutdown]
  1901. public void WordWrap_WrapModel_Output ()
  1902. {
  1903. // 0123456789
  1904. var text = "This is the first line.\nThis is the second line.\n";
  1905. var tv = new TextView () { Width = 10, Height = 10 };
  1906. tv.Text = text;
  1907. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}", tv.Text);
  1908. tv.WordWrap = true;
  1909. Application.Top.Add (tv);
  1910. tv.Redraw (tv.Bounds);
  1911. TestHelpers.AssertDriverContentsWithFrameAre (@"
  1912. This is
  1913. the
  1914. first
  1915. line.
  1916. This is
  1917. the
  1918. second
  1919. line.
  1920. ", output);
  1921. }
  1922. [Fact]
  1923. [AutoInitShutdown]
  1924. public void WordWrap_Deleting_Backwards ()
  1925. {
  1926. var tv = new TextView () {
  1927. Width = 5,
  1928. Height = 2,
  1929. WordWrap = true,
  1930. Text = "aaaa"
  1931. };
  1932. Application.Top.Add (tv);
  1933. Application.Begin (Application.Top);
  1934. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  1935. Assert.Equal (0, tv.LeftColumn);
  1936. TestHelpers.AssertDriverContentsAre (@"
  1937. aaaa
  1938. ", output);
  1939. tv.CursorPosition = new Point (5, 0);
  1940. Assert.True (tv.ProcessKey (new KeyEvent (Key.Backspace, new KeyModifiers ())));
  1941. Application.Refresh ();
  1942. Assert.Equal (0, tv.LeftColumn);
  1943. TestHelpers.AssertDriverContentsAre (@"
  1944. aaa
  1945. ", output);
  1946. Assert.True (tv.ProcessKey (new KeyEvent (Key.Backspace, new KeyModifiers ())));
  1947. Application.Refresh ();
  1948. Assert.Equal (0, tv.LeftColumn);
  1949. TestHelpers.AssertDriverContentsAre (@"
  1950. aa
  1951. ", output);
  1952. Assert.True (tv.ProcessKey (new KeyEvent (Key.Backspace, new KeyModifiers ())));
  1953. Application.Refresh ();
  1954. Assert.Equal (0, tv.LeftColumn);
  1955. TestHelpers.AssertDriverContentsAre (@"
  1956. a
  1957. ", output);
  1958. Assert.True (tv.ProcessKey (new KeyEvent (Key.Backspace, new KeyModifiers ())));
  1959. Application.Refresh ();
  1960. Assert.Equal (0, tv.LeftColumn);
  1961. TestHelpers.AssertDriverContentsAre (@"
  1962. ", output);
  1963. Assert.True (tv.ProcessKey (new KeyEvent (Key.Backspace, new KeyModifiers ())));
  1964. Application.Refresh ();
  1965. Assert.Equal (0, tv.LeftColumn);
  1966. TestHelpers.AssertDriverContentsAre (@"
  1967. ", output);
  1968. }
  1969. [Fact]
  1970. [InitShutdown]
  1971. public void WordWrap_ReadOnly_CursorPosition_SelectedText_Copy ()
  1972. {
  1973. // 0123456789
  1974. var text = "This is the first line.\nThis is the second line.\n";
  1975. var tv = new TextView () { Width = 11, Height = 9 };
  1976. tv.Text = text;
  1977. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}", tv.Text);
  1978. tv.WordWrap = true;
  1979. Application.Top.Add (tv);
  1980. tv.Redraw (tv.Bounds);
  1981. TestHelpers.AssertDriverContentsWithFrameAre (@"
  1982. This is
  1983. the first
  1984. line.
  1985. This is
  1986. the
  1987. second
  1988. line.
  1989. ", output);
  1990. tv.ReadOnly = true;
  1991. tv.CursorPosition = new Point (6, 2);
  1992. Assert.Equal (new Point (5, 2), tv.CursorPosition);
  1993. tv.Redraw (tv.Bounds);
  1994. TestHelpers.AssertDriverContentsWithFrameAre (@"
  1995. This is
  1996. the first
  1997. line.
  1998. This is
  1999. the
  2000. second
  2001. line.
  2002. ", output);
  2003. tv.SelectionStartRow = 0;
  2004. tv.SelectionStartColumn = 0;
  2005. Assert.Equal ("This is the first line.", tv.SelectedText);
  2006. tv.Copy ();
  2007. Assert.Equal ("This is the first line.", Clipboard.Contents);
  2008. }
  2009. [Fact]
  2010. public void Internal_Tests ()
  2011. {
  2012. var txt = "This is a text.";
  2013. var txtRunes = TextModel.ToRunes (txt);
  2014. Assert.Equal (txt.Length, txtRunes.Count);
  2015. Assert.Equal ('T', txtRunes [0]);
  2016. Assert.Equal ('h', txtRunes [1]);
  2017. Assert.Equal ('i', txtRunes [2]);
  2018. Assert.Equal ('s', txtRunes [3]);
  2019. Assert.Equal (' ', txtRunes [4]);
  2020. Assert.Equal ('i', txtRunes [5]);
  2021. Assert.Equal ('s', txtRunes [6]);
  2022. Assert.Equal (' ', txtRunes [7]);
  2023. Assert.Equal ('a', txtRunes [8]);
  2024. Assert.Equal (' ', txtRunes [9]);
  2025. Assert.Equal ('t', txtRunes [10]);
  2026. Assert.Equal ('e', txtRunes [11]);
  2027. Assert.Equal ('x', txtRunes [12]);
  2028. Assert.Equal ('t', txtRunes [13]);
  2029. Assert.Equal ('.', txtRunes [^1]);
  2030. int col = 0;
  2031. Assert.True (TextModel.SetCol (ref col, 80, 79));
  2032. Assert.False (TextModel.SetCol (ref col, 80, 80));
  2033. Assert.Equal (79, col);
  2034. var start = 0;
  2035. var x = 8;
  2036. Assert.Equal (8, TextModel.GetColFromX (txtRunes, start, x));
  2037. Assert.Equal ('a', txtRunes [start + x]);
  2038. start = 1;
  2039. x = 7;
  2040. Assert.Equal (7, TextModel.GetColFromX (txtRunes, start, x));
  2041. Assert.Equal ('a', txtRunes [start + x]);
  2042. Assert.Equal ((15, 15), TextModel.DisplaySize (txtRunes));
  2043. Assert.Equal ((6, 6), TextModel.DisplaySize (txtRunes, 1, 7));
  2044. Assert.Equal (0, TextModel.CalculateLeftColumn (txtRunes, 0, 7, 8));
  2045. Assert.Equal (1, TextModel.CalculateLeftColumn (txtRunes, 0, 8, 8));
  2046. Assert.Equal (2, TextModel.CalculateLeftColumn (txtRunes, 0, 9, 8));
  2047. var tm = new TextModel ();
  2048. tm.AddLine (0, TextModel.ToRunes ("This is first line."));
  2049. tm.AddLine (1, TextModel.ToRunes ("This is last line."));
  2050. Assert.Equal ((new Point (2, 0), true), tm.FindNextText ("is", out bool gaveFullTurn));
  2051. Assert.False (gaveFullTurn);
  2052. Assert.Equal ((new Point (5, 0), true), tm.FindNextText ("is", out gaveFullTurn));
  2053. Assert.False (gaveFullTurn);
  2054. Assert.Equal ((new Point (2, 1), true), tm.FindNextText ("is", out gaveFullTurn));
  2055. Assert.False (gaveFullTurn);
  2056. Assert.Equal ((new Point (5, 1), true), tm.FindNextText ("is", out gaveFullTurn));
  2057. Assert.False (gaveFullTurn);
  2058. Assert.Equal ((new Point (2, 0), true), tm.FindNextText ("is", out gaveFullTurn));
  2059. Assert.True (gaveFullTurn);
  2060. tm.ResetContinuousFind (new Point (0, 0));
  2061. Assert.Equal ((new Point (5, 1), true), tm.FindPreviousText ("is", out gaveFullTurn));
  2062. Assert.False (gaveFullTurn);
  2063. Assert.Equal ((new Point (2, 1), true), tm.FindPreviousText ("is", out gaveFullTurn));
  2064. Assert.False (gaveFullTurn);
  2065. Assert.Equal ((new Point (5, 0), true), tm.FindPreviousText ("is", out gaveFullTurn));
  2066. Assert.False (gaveFullTurn);
  2067. Assert.Equal ((new Point (2, 0), true), tm.FindPreviousText ("is", out gaveFullTurn));
  2068. Assert.False (gaveFullTurn);
  2069. Assert.Equal ((new Point (5, 1), true), tm.FindPreviousText ("is", out gaveFullTurn));
  2070. Assert.True (gaveFullTurn);
  2071. Assert.Equal ((new Point (9, 1), true), tm.ReplaceAllText ("is", false, false, "really"));
  2072. Assert.Equal (TextModel.ToRunes ("Threally really first line."), tm.GetLine (0));
  2073. Assert.Equal (TextModel.ToRunes ("Threally really last line."), tm.GetLine (1));
  2074. tm = new TextModel ();
  2075. tm.AddLine (0, TextModel.ToRunes ("This is first line."));
  2076. tm.AddLine (1, TextModel.ToRunes ("This is last line."));
  2077. Assert.Equal ((new Point (5, 1), true), tm.ReplaceAllText ("is", false, true, "really"));
  2078. Assert.Equal (TextModel.ToRunes ("This really first line."), tm.GetLine (0));
  2079. Assert.Equal (TextModel.ToRunes ("This really last line."), tm.GetLine (1));
  2080. }
  2081. [Fact]
  2082. [InitShutdown]
  2083. public void BottomOffset_Sets_To_Zero_Adjust_TopRow ()
  2084. {
  2085. string text = "";
  2086. for (int i = 0; i < 12; i++) {
  2087. text += $"This is the line {i}\n";
  2088. }
  2089. var tv = new TextView () { Width = 10, Height = 10, BottomOffset = 1 };
  2090. tv.Text = text;
  2091. tv.ProcessKey (new KeyEvent (Key.CtrlMask | Key.End, new KeyModifiers ()));
  2092. Assert.Equal (4, tv.TopRow);
  2093. Assert.Equal (1, tv.BottomOffset);
  2094. tv.BottomOffset = 0;
  2095. Assert.Equal (3, tv.TopRow);
  2096. Assert.Equal (0, tv.BottomOffset);
  2097. tv.BottomOffset = 2;
  2098. Assert.Equal (5, tv.TopRow);
  2099. Assert.Equal (2, tv.BottomOffset);
  2100. tv.BottomOffset = 0;
  2101. Assert.Equal (3, tv.TopRow);
  2102. Assert.Equal (0, tv.BottomOffset);
  2103. }
  2104. [Fact]
  2105. [InitShutdown]
  2106. public void RightOffset_Sets_To_Zero_Adjust_leftColumn ()
  2107. {
  2108. string text = "";
  2109. for (int i = 0; i < 12; i++) {
  2110. text += $"{i.ToString () [^1]}";
  2111. }
  2112. var tv = new TextView () { Width = 10, Height = 10, RightOffset = 1 };
  2113. tv.Text = text;
  2114. tv.ProcessKey (new KeyEvent (Key.End, new KeyModifiers ()));
  2115. Assert.Equal (4, tv.LeftColumn);
  2116. Assert.Equal (1, tv.RightOffset);
  2117. tv.RightOffset = 0;
  2118. Assert.Equal (3, tv.LeftColumn);
  2119. Assert.Equal (0, tv.RightOffset);
  2120. tv.RightOffset = 2;
  2121. Assert.Equal (5, tv.LeftColumn);
  2122. Assert.Equal (2, tv.RightOffset);
  2123. tv.RightOffset = 0;
  2124. Assert.Equal (3, tv.LeftColumn);
  2125. Assert.Equal (0, tv.RightOffset);
  2126. }
  2127. [Fact]
  2128. [InitShutdown]
  2129. public void TextView_SpaceHandling ()
  2130. {
  2131. var tv = new TextView () {
  2132. Width = 10,
  2133. Text = " "
  2134. };
  2135. MouseEvent ev = new MouseEvent () {
  2136. X = 0,
  2137. Y = 0,
  2138. Flags = MouseFlags.Button1DoubleClicked,
  2139. };
  2140. tv.MouseEvent (ev);
  2141. Assert.Equal (1, tv.SelectedLength);
  2142. ev = new MouseEvent () {
  2143. X = 1,
  2144. Y = 0,
  2145. Flags = MouseFlags.Button1DoubleClicked,
  2146. };
  2147. tv.MouseEvent (ev);
  2148. Assert.Equal (1, tv.SelectedLength);
  2149. }
  2150. [Fact]
  2151. [InitShutdown]
  2152. public void CanFocus_False_Wont_Focus_With_Mouse ()
  2153. {
  2154. var top = Application.Top;
  2155. var tv = new TextView () {
  2156. Width = Dim.Fill (),
  2157. CanFocus = false,
  2158. ReadOnly = true,
  2159. Text = "some text"
  2160. };
  2161. var fv = new FrameView ("I shouldn't get focus") {
  2162. Width = Dim.Fill (),
  2163. Height = Dim.Fill (),
  2164. CanFocus = false,
  2165. };
  2166. fv.Add (tv);
  2167. top.Add (fv);
  2168. Application.Begin (top);
  2169. Assert.False (tv.CanFocus);
  2170. Assert.False (tv.HasFocus);
  2171. Assert.False (fv.CanFocus);
  2172. Assert.False (fv.HasFocus);
  2173. tv.MouseEvent (new MouseEvent () {
  2174. X = 1,
  2175. Y = 0,
  2176. Flags = MouseFlags.Button1DoubleClicked
  2177. });
  2178. Assert.Empty (tv.SelectedText);
  2179. Assert.False (tv.CanFocus);
  2180. Assert.False (tv.HasFocus);
  2181. Assert.False (fv.CanFocus);
  2182. Assert.False (fv.HasFocus);
  2183. Assert.Throws<InvalidOperationException> (() => tv.CanFocus = true);
  2184. fv.CanFocus = true;
  2185. tv.CanFocus = true;
  2186. tv.MouseEvent (new MouseEvent () {
  2187. X = 1,
  2188. Y = 0,
  2189. Flags = MouseFlags.Button1DoubleClicked
  2190. });
  2191. Assert.Equal ("some ", tv.SelectedText);
  2192. Assert.True (tv.CanFocus);
  2193. Assert.True (tv.HasFocus);
  2194. Assert.True (fv.CanFocus);
  2195. Assert.True (fv.HasFocus);
  2196. fv.CanFocus = false;
  2197. tv.MouseEvent (new MouseEvent () {
  2198. X = 1,
  2199. Y = 0,
  2200. Flags = MouseFlags.Button1DoubleClicked
  2201. });
  2202. Assert.Equal ("some ", tv.SelectedText); // Setting CanFocus to false don't change the SelectedText
  2203. Assert.False (tv.CanFocus);
  2204. Assert.False (tv.HasFocus);
  2205. Assert.False (fv.CanFocus);
  2206. Assert.False (fv.HasFocus);
  2207. }
  2208. [Fact]
  2209. [InitShutdown]
  2210. public void DesiredCursorVisibility_Vertical_Navigation ()
  2211. {
  2212. string text = "";
  2213. for (int i = 0; i < 12; i++) {
  2214. text += $"This is the line {i}\n";
  2215. }
  2216. var tv = new TextView () { Width = 10, Height = 10 };
  2217. tv.Text = text;
  2218. Assert.Equal (0, tv.TopRow);
  2219. tv.PositionCursor ();
  2220. Assert.Equal (CursorVisibility.Default, tv.DesiredCursorVisibility);
  2221. for (int i = 0; i < 12; i++) {
  2222. tv.MouseEvent (new MouseEvent () {
  2223. Flags = MouseFlags.WheeledDown
  2224. });
  2225. tv.PositionCursor ();
  2226. Assert.Equal (i + 1, tv.TopRow);
  2227. Assert.Equal (CursorVisibility.Invisible, tv.DesiredCursorVisibility);
  2228. }
  2229. for (int i = 12; i > 0; i--) {
  2230. tv.MouseEvent (new MouseEvent () {
  2231. Flags = MouseFlags.WheeledUp
  2232. });
  2233. tv.PositionCursor ();
  2234. Assert.Equal (i - 1, tv.TopRow);
  2235. if (i - 1 == 0) {
  2236. Assert.Equal (CursorVisibility.Default, tv.DesiredCursorVisibility);
  2237. } else {
  2238. Assert.Equal (CursorVisibility.Invisible, tv.DesiredCursorVisibility);
  2239. }
  2240. }
  2241. }
  2242. [Fact]
  2243. [InitShutdown]
  2244. public void DesiredCursorVisibility_Horizontal_Navigation ()
  2245. {
  2246. string text = "";
  2247. for (int i = 0; i < 12; i++) {
  2248. text += $"{i.ToString () [^1]}";
  2249. }
  2250. var tv = new TextView () { Width = 10, Height = 10 };
  2251. tv.Text = text;
  2252. Assert.Equal (0, tv.LeftColumn);
  2253. tv.PositionCursor ();
  2254. Assert.Equal (CursorVisibility.Default, tv.DesiredCursorVisibility);
  2255. for (int i = 0; i < 12; i++) {
  2256. tv.MouseEvent (new MouseEvent () {
  2257. Flags = MouseFlags.WheeledRight
  2258. });
  2259. tv.PositionCursor ();
  2260. Assert.Equal (Math.Min (i + 1, 11), tv.LeftColumn);
  2261. Assert.Equal (CursorVisibility.Invisible, tv.DesiredCursorVisibility);
  2262. }
  2263. for (int i = 11; i > 0; i--) {
  2264. tv.MouseEvent (new MouseEvent () {
  2265. Flags = MouseFlags.WheeledLeft
  2266. });
  2267. tv.PositionCursor ();
  2268. Assert.Equal (i - 1, tv.LeftColumn);
  2269. if (i - 1 == 0) {
  2270. Assert.Equal (CursorVisibility.Default, tv.DesiredCursorVisibility);
  2271. } else {
  2272. Assert.Equal (CursorVisibility.Invisible, tv.DesiredCursorVisibility);
  2273. }
  2274. }
  2275. }
  2276. [Fact]
  2277. public void LeftColumn_Add_One_If_Text_Length_Is_Equal_To_Width ()
  2278. {
  2279. var tv = new TextView () {
  2280. Width = 10,
  2281. Text = "1234567890"
  2282. };
  2283. Assert.Equal (Point.Empty, tv.CursorPosition);
  2284. Assert.Equal (0, tv.LeftColumn);
  2285. tv.CursorPosition = new Point (9, 0);
  2286. Assert.Equal (new Point (9, 0), tv.CursorPosition);
  2287. Assert.Equal (0, tv.LeftColumn);
  2288. Assert.True (tv.ProcessKey (new KeyEvent (Key.CursorRight, new KeyModifiers ())));
  2289. tv.CursorPosition = new Point (10, 0);
  2290. Assert.Equal (new Point (10, 0), tv.CursorPosition);
  2291. Assert.Equal (1, tv.LeftColumn);
  2292. }
  2293. [Fact]
  2294. [AutoInitShutdown]
  2295. public void KeyBindings_Command ()
  2296. {
  2297. var text = "This is the first line.\nThis is the second line.\nThis is the third line.";
  2298. var tv = new TextView () {
  2299. Width = 10,
  2300. Height = 2,
  2301. Text = text
  2302. };
  2303. var top = Application.Top;
  2304. top.Add (tv);
  2305. Application.Begin (top);
  2306. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  2307. Assert.Equal (3, tv.Lines);
  2308. Assert.Equal (Point.Empty, tv.CursorPosition);
  2309. Assert.False (tv.ReadOnly);
  2310. Assert.True (tv.CanFocus);
  2311. tv.CanFocus = false;
  2312. Assert.True (tv.ProcessKey (new KeyEvent (Key.CursorLeft, new KeyModifiers ())));
  2313. tv.CanFocus = true;
  2314. Assert.False (tv.ProcessKey (new KeyEvent (Key.CursorLeft, new KeyModifiers ())));
  2315. Assert.True (tv.ProcessKey (new KeyEvent (Key.CursorRight, new KeyModifiers ())));
  2316. Assert.Equal (new Point (1, 0), tv.CursorPosition);
  2317. Assert.True (tv.ProcessKey (new KeyEvent (Key.End | Key.CtrlMask, new KeyModifiers ())));
  2318. Assert.Equal (2, tv.CurrentRow);
  2319. Assert.Equal (23, tv.CurrentColumn);
  2320. Assert.Equal (tv.CurrentColumn, tv.GetCurrentLine ().Count);
  2321. Assert.Equal (new Point (23, 2), tv.CursorPosition);
  2322. Assert.False (tv.ProcessKey (new KeyEvent (Key.CursorRight, new KeyModifiers ())));
  2323. Assert.NotNull (tv.Autocomplete);
  2324. Assert.Empty (tv.Autocomplete.AllSuggestions);
  2325. Assert.True (tv.ProcessKey (new KeyEvent (Key.F, new KeyModifiers ())));
  2326. tv.Redraw (tv.Bounds);
  2327. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.F", tv.Text);
  2328. Assert.Equal (new Point (24, 2), tv.CursorPosition);
  2329. Assert.Empty (tv.Autocomplete.Suggestions);
  2330. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  2331. tv.Redraw (tv.Bounds);
  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. Assert.Empty (tv.Autocomplete.Suggestions);
  2335. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  2336. tv.Redraw (tv.Bounds);
  2337. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.F", tv.Text);
  2338. Assert.Equal (new Point (24, 2), tv.CursorPosition);
  2339. Assert.Empty (tv.Autocomplete.Suggestions);
  2340. Assert.True (tv.ProcessKey (new KeyEvent (Key.Backspace, new KeyModifiers ())));
  2341. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  2342. Assert.Equal (new Point (23, 2), tv.CursorPosition);
  2343. tv.Autocomplete.AllSuggestions = Regex.Matches (tv.Text.ToString (), "\\w+")
  2344. .Select (s => s.Value)
  2345. .Distinct ().ToList ();
  2346. Assert.Equal (7, tv.Autocomplete.AllSuggestions.Count);
  2347. Assert.Equal ("This", tv.Autocomplete.AllSuggestions [0]);
  2348. Assert.Equal ("is", tv.Autocomplete.AllSuggestions [1]);
  2349. Assert.Equal ("the", tv.Autocomplete.AllSuggestions [2]);
  2350. Assert.Equal ("first", tv.Autocomplete.AllSuggestions [3]);
  2351. Assert.Equal ("line", tv.Autocomplete.AllSuggestions [4]);
  2352. Assert.Equal ("second", tv.Autocomplete.AllSuggestions [5]);
  2353. Assert.Equal ("third", tv.Autocomplete.AllSuggestions [^1]);
  2354. Assert.True (tv.ProcessKey (new KeyEvent (Key.F, new KeyModifiers ())));
  2355. tv.Redraw (tv.Bounds);
  2356. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.F", tv.Text);
  2357. Assert.Equal (new Point (24, 2), tv.CursorPosition);
  2358. Assert.Single (tv.Autocomplete.Suggestions);
  2359. Assert.Equal ("first", tv.Autocomplete.Suggestions [0]);
  2360. Assert.True (tv.ProcessKey (new KeyEvent (Key.Enter, new KeyModifiers ())));
  2361. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first", tv.Text);
  2362. Assert.Equal (new Point (28, 2), tv.CursorPosition);
  2363. Assert.Single (tv.Autocomplete.Suggestions);
  2364. Assert.Equal ("first", tv.Autocomplete.Suggestions [0]);
  2365. tv.Autocomplete.AllSuggestions = new List<string> ();
  2366. tv.Autocomplete.ClearSuggestions ();
  2367. Assert.Empty (tv.Autocomplete.AllSuggestions);
  2368. Assert.Empty (tv.Autocomplete.Suggestions);
  2369. Assert.True (tv.ProcessKey (new KeyEvent (Key.PageUp, new KeyModifiers ())));
  2370. Assert.Equal (24, tv.GetCurrentLine ().Count);
  2371. Assert.Equal (new Point (24, 1), tv.CursorPosition);
  2372. Assert.True (tv.ProcessKey (new KeyEvent (((int)'V' + Key.AltMask), new KeyModifiers ())));
  2373. Assert.Equal (23, tv.GetCurrentLine ().Count);
  2374. Assert.Equal (new Point (23, 0), tv.CursorPosition);
  2375. Assert.True (tv.ProcessKey (new KeyEvent (Key.PageDown, new KeyModifiers ())));
  2376. Assert.Equal (24, tv.GetCurrentLine ().Count);
  2377. Assert.Equal (new Point (23, 1), tv.CursorPosition); // gets the previous length
  2378. Assert.True (tv.ProcessKey (new KeyEvent (Key.V | Key.CtrlMask, new KeyModifiers ())));
  2379. Assert.Equal (28, tv.GetCurrentLine ().Count);
  2380. Assert.Equal (new Point (23, 2), tv.CursorPosition); // gets the previous length
  2381. Assert.Equal (0, tv.SelectedLength);
  2382. Assert.Equal ("", tv.SelectedText);
  2383. Assert.True (tv.ProcessKey (new KeyEvent (Key.PageUp | Key.ShiftMask, new KeyModifiers ())));
  2384. Assert.Equal (24, tv.GetCurrentLine ().Count);
  2385. Assert.Equal (new Point (23, 1), tv.CursorPosition); // gets the previous length
  2386. Assert.Equal (24 + Environment.NewLine.Length, tv.SelectedLength);
  2387. Assert.Equal ($".{Environment.NewLine}This is the third line.", tv.SelectedText);
  2388. Assert.True (tv.ProcessKey (new KeyEvent (Key.PageDown | Key.ShiftMask, new KeyModifiers ())));
  2389. Assert.Equal (28, tv.GetCurrentLine ().Count);
  2390. Assert.Equal (new Point (23, 2), tv.CursorPosition); // gets the previous length
  2391. Assert.Equal (0, tv.SelectedLength);
  2392. Assert.Equal ("", tv.SelectedText);
  2393. Assert.True (tv.ProcessKey (new KeyEvent (Key.Home | Key.CtrlMask, new KeyModifiers ())));
  2394. Assert.Equal (Point.Empty, tv.CursorPosition);
  2395. Assert.True (tv.ProcessKey (new KeyEvent (Key.N | Key.CtrlMask, new KeyModifiers ())));
  2396. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  2397. Assert.Equal (0, tv.SelectedLength);
  2398. Assert.Equal ("", tv.SelectedText);
  2399. Assert.True (tv.ProcessKey (new KeyEvent (Key.P | Key.CtrlMask, new KeyModifiers ())));
  2400. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  2401. Assert.Equal (0, tv.SelectedLength);
  2402. Assert.Equal ("", tv.SelectedText);
  2403. Assert.True (tv.ProcessKey (new KeyEvent (Key.CursorDown, new KeyModifiers ())));
  2404. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  2405. Assert.Equal (0, tv.SelectedLength);
  2406. Assert.Equal ("", tv.SelectedText);
  2407. Assert.True (tv.ProcessKey (new KeyEvent (Key.CursorUp, new KeyModifiers ())));
  2408. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  2409. Assert.Equal (0, tv.SelectedLength);
  2410. Assert.Equal ("", tv.SelectedText);
  2411. Assert.True (tv.ProcessKey (new KeyEvent (Key.CursorDown | Key.ShiftMask, new KeyModifiers ())));
  2412. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  2413. Assert.Equal (23 + Environment.NewLine.Length, tv.SelectedLength);
  2414. Assert.Equal ($"This is the first line.{Environment.NewLine}", tv.SelectedText);
  2415. Assert.True (tv.ProcessKey (new KeyEvent (Key.CursorUp | Key.ShiftMask, new KeyModifiers ())));
  2416. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  2417. Assert.Equal (0, tv.SelectedLength);
  2418. Assert.Equal ("", tv.SelectedText);
  2419. Assert.True (tv.ProcessKey (new KeyEvent (Key.F | Key.CtrlMask, new KeyModifiers ())));
  2420. Assert.Equal (new Point (1, 0), tv.CursorPosition);
  2421. Assert.Equal (0, tv.SelectedLength);
  2422. Assert.Equal ("", tv.SelectedText);
  2423. Assert.True (tv.ProcessKey (new KeyEvent (Key.B | Key.CtrlMask, new KeyModifiers ())));
  2424. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  2425. Assert.Equal (0, tv.SelectedLength);
  2426. Assert.Equal ("", tv.SelectedText);
  2427. Assert.True (tv.ProcessKey (new KeyEvent (Key.CursorRight, new KeyModifiers ())));
  2428. Assert.Equal (new Point (1, 0), tv.CursorPosition);
  2429. Assert.Equal (0, tv.SelectedLength);
  2430. Assert.Equal ("", tv.SelectedText);
  2431. Assert.True (tv.ProcessKey (new KeyEvent (Key.CursorLeft, new KeyModifiers ())));
  2432. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  2433. Assert.Equal (0, tv.SelectedLength);
  2434. Assert.Equal ("", tv.SelectedText);
  2435. Assert.False (tv.Selecting);
  2436. Assert.True (tv.ProcessKey (new KeyEvent (Key.CursorRight | Key.ShiftMask, new KeyModifiers ())));
  2437. Assert.Equal (new Point (1, 0), tv.CursorPosition);
  2438. Assert.Equal (1, tv.SelectedLength);
  2439. Assert.Equal ("T", tv.SelectedText);
  2440. Assert.True (tv.Selecting);
  2441. Assert.True (tv.ProcessKey (new KeyEvent (Key.CursorLeft | Key.ShiftMask, new KeyModifiers ())));
  2442. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  2443. Assert.Equal (0, tv.SelectedLength);
  2444. Assert.Equal ("", tv.SelectedText);
  2445. Assert.True (tv.Selecting);
  2446. Assert.True (tv.ProcessKey (new KeyEvent (Key.DeleteChar, new KeyModifiers ())));
  2447. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first", tv.Text);
  2448. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  2449. Assert.Equal (0, tv.SelectedLength);
  2450. Assert.Equal ("", tv.SelectedText);
  2451. Assert.False (tv.Selecting);
  2452. Assert.True (tv.ProcessKey (new KeyEvent (Key.DeleteChar, new KeyModifiers ())));
  2453. Assert.Equal ($"his 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 (0, 0), tv.CursorPosition);
  2455. Assert.Equal (0, tv.SelectedLength);
  2456. Assert.Equal ("", tv.SelectedText);
  2457. Assert.False (tv.Selecting);
  2458. Assert.True (tv.ProcessKey (new KeyEvent (Key.D | Key.CtrlMask, new KeyModifiers ())));
  2459. Assert.Equal ($"is is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first", tv.Text);
  2460. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  2461. Assert.True (tv.ProcessKey (new KeyEvent (Key.End, new KeyModifiers ())));
  2462. Assert.Equal ($"is is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first", tv.Text);
  2463. Assert.Equal (new Point (21, 0), tv.CursorPosition);
  2464. Assert.True (tv.ProcessKey (new KeyEvent (Key.Delete, new KeyModifiers ())));
  2465. Assert.Equal ($"is is the first line{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first", tv.Text);
  2466. Assert.Equal (new Point (20, 0), tv.CursorPosition);
  2467. Assert.True (tv.ProcessKey (new KeyEvent (Key.Backspace, new KeyModifiers ())));
  2468. Assert.Equal ($"is is the first lin{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first", tv.Text);
  2469. Assert.Equal (new Point (19, 0), tv.CursorPosition);
  2470. Assert.True (tv.ProcessKey (new KeyEvent (Key.Home, new KeyModifiers ())));
  2471. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  2472. Assert.Equal (0, tv.SelectedLength);
  2473. Assert.Equal ("", tv.SelectedText);
  2474. Assert.False (tv.Selecting);
  2475. Assert.True (tv.ProcessKey (new KeyEvent (Key.End | Key.ShiftMask, new KeyModifiers ())));
  2476. Assert.Equal (new Point (19, 0), tv.CursorPosition);
  2477. Assert.Equal (19, tv.SelectedLength);
  2478. Assert.Equal ("is is the first lin", tv.SelectedText);
  2479. Assert.True (tv.Selecting);
  2480. Assert.True (tv.ProcessKey (new KeyEvent (Key.Home | Key.ShiftMask, new KeyModifiers ())));
  2481. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  2482. Assert.Equal (0, tv.SelectedLength);
  2483. Assert.Equal ("", tv.SelectedText);
  2484. Assert.True (tv.Selecting);
  2485. Assert.True (tv.ProcessKey (new KeyEvent (Key.E | Key.CtrlMask, new KeyModifiers ())));
  2486. Assert.Equal (new Point (19, 0), tv.CursorPosition);
  2487. Assert.Equal (0, tv.SelectedLength);
  2488. Assert.Equal ("", tv.SelectedText);
  2489. Assert.False (tv.Selecting);
  2490. Assert.True (tv.ProcessKey (new KeyEvent (Key.A | Key.CtrlMask, new KeyModifiers ())));
  2491. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  2492. Assert.Equal (0, tv.SelectedLength);
  2493. Assert.Equal ("", tv.SelectedText);
  2494. Assert.False (tv.Selecting);
  2495. Assert.True (tv.ProcessKey (new KeyEvent (Key.K | Key.CtrlMask, new KeyModifiers ())));
  2496. Assert.Equal ($"{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first", tv.Text);
  2497. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  2498. Assert.Equal (0, tv.SelectedLength);
  2499. Assert.Equal ("", tv.SelectedText);
  2500. Assert.False (tv.Selecting);
  2501. Assert.Equal ("is is the first lin", Clipboard.Contents);
  2502. Assert.True (tv.ProcessKey (new KeyEvent (Key.Y | Key.CtrlMask, new KeyModifiers ())));
  2503. Assert.Equal ($"is is the first lin{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first", tv.Text);
  2504. Assert.Equal (new Point (19, 0), tv.CursorPosition);
  2505. Assert.Equal (0, tv.SelectedLength);
  2506. Assert.Equal ("", tv.SelectedText);
  2507. Assert.False (tv.Selecting);
  2508. Assert.Equal ("is is the first lin", Clipboard.Contents);
  2509. tv.CursorPosition = Point.Empty;
  2510. Assert.True (tv.ProcessKey (new KeyEvent (Key.DeleteChar | Key.CtrlMask | Key.ShiftMask, new KeyModifiers ())));
  2511. Assert.Equal ($"{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first", tv.Text);
  2512. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  2513. Assert.Equal (0, tv.SelectedLength);
  2514. Assert.Equal ("", tv.SelectedText);
  2515. Assert.False (tv.Selecting);
  2516. Assert.Equal ("is is the first lin", Clipboard.Contents);
  2517. Assert.True (tv.ProcessKey (new KeyEvent (Key.Y | Key.CtrlMask, new KeyModifiers ())));
  2518. Assert.Equal ($"is is the first lin{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first", tv.Text);
  2519. Assert.Equal (new Point (19, 0), tv.CursorPosition);
  2520. Assert.Equal (0, tv.SelectedLength);
  2521. Assert.Equal ("", tv.SelectedText);
  2522. Assert.False (tv.Selecting);
  2523. Assert.Equal ("is is the first lin", Clipboard.Contents);
  2524. Assert.True (tv.ProcessKey (new KeyEvent (Key.K | Key.AltMask, new KeyModifiers ())));
  2525. Assert.Equal ($"{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first", tv.Text);
  2526. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  2527. Assert.Equal (0, tv.SelectedLength);
  2528. Assert.Equal ("", tv.SelectedText);
  2529. Assert.False (tv.Selecting);
  2530. tv.ReadOnly = true;
  2531. Assert.True (tv.ProcessKey (new KeyEvent (Key.Y | Key.CtrlMask, new KeyModifiers ())));
  2532. Assert.Equal ($"{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first", tv.Text);
  2533. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  2534. Assert.Equal (0, tv.SelectedLength);
  2535. Assert.Equal ("", tv.SelectedText);
  2536. Assert.False (tv.Selecting);
  2537. tv.ReadOnly = false;
  2538. Assert.True (tv.ProcessKey (new KeyEvent (Key.Y | Key.CtrlMask, new KeyModifiers ())));
  2539. Assert.Equal ($"is is the first lin{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first", tv.Text);
  2540. Assert.Equal (new Point (19, 0), tv.CursorPosition);
  2541. Assert.Equal (0, tv.SelectedLength);
  2542. Assert.Equal ("", tv.SelectedText);
  2543. Assert.False (tv.Selecting);
  2544. Assert.Equal (0, tv.SelectionStartColumn);
  2545. Assert.Equal (0, tv.SelectionStartRow);
  2546. Assert.True (tv.ProcessKey (new KeyEvent (Key.Space | Key.CtrlMask, new KeyModifiers ())));
  2547. Assert.Equal ($"is is the first lin{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first", tv.Text);
  2548. Assert.Equal (new Point (19, 0), tv.CursorPosition);
  2549. Assert.Equal (0, tv.SelectedLength);
  2550. Assert.Equal ("", tv.SelectedText);
  2551. Assert.True (tv.Selecting);
  2552. Assert.Equal (19, tv.SelectionStartColumn);
  2553. Assert.Equal (0, tv.SelectionStartRow);
  2554. Assert.True (tv.ProcessKey (new KeyEvent (Key.Space | Key.CtrlMask, 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 (0, tv.SelectedLength);
  2558. Assert.Equal ("", tv.SelectedText);
  2559. Assert.False (tv.Selecting);
  2560. Assert.Equal (19, tv.SelectionStartColumn);
  2561. Assert.Equal (0, tv.SelectionStartRow);
  2562. tv.SelectionStartColumn = 0;
  2563. Assert.True (tv.ProcessKey (new KeyEvent (((int)'C' + Key.AltMask), new KeyModifiers ())));
  2564. Assert.Equal ($"is is the first lin{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first", tv.Text);
  2565. Assert.Equal (new Point (19, 0), tv.CursorPosition);
  2566. Assert.Equal (19, tv.SelectedLength);
  2567. Assert.Equal ("is is the first lin", tv.SelectedText);
  2568. Assert.True (tv.Selecting);
  2569. Assert.Equal (0, tv.SelectionStartColumn);
  2570. Assert.Equal (0, tv.SelectionStartRow);
  2571. Assert.True (tv.ProcessKey (new KeyEvent (Key.C | Key.CtrlMask, new KeyModifiers ())));
  2572. Assert.Equal ($"is is the first lin{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first", tv.Text);
  2573. Assert.Equal (new Point (19, 0), tv.CursorPosition);
  2574. Assert.Equal (19, tv.SelectedLength);
  2575. Assert.Equal ("is is the first lin", tv.SelectedText);
  2576. Assert.True (tv.Selecting);
  2577. Assert.Equal (0, tv.SelectionStartColumn);
  2578. Assert.Equal (0, tv.SelectionStartRow);
  2579. Assert.True (tv.ProcessKey (new KeyEvent (((int)'W' + Key.AltMask), 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 ("is is the first lin", Clipboard.Contents);
  2588. Assert.True (tv.ProcessKey (new KeyEvent (Key.W | 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.X | Key.CtrlMask, new KeyModifiers ())));
  2598. Assert.Equal ($"{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first", tv.Text);
  2599. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  2600. Assert.Equal (0, tv.SelectedLength);
  2601. Assert.Equal ("", tv.SelectedText);
  2602. Assert.False (tv.Selecting);
  2603. Assert.Equal (0, tv.SelectionStartColumn);
  2604. Assert.Equal (0, tv.SelectionStartRow);
  2605. Assert.Equal ("", Clipboard.Contents);
  2606. Assert.True (tv.ProcessKey (new KeyEvent (Key.End | Key.CtrlMask, new KeyModifiers ())));
  2607. Assert.Equal ($"{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first", tv.Text);
  2608. Assert.Equal (new Point (28, 2), tv.CursorPosition);
  2609. Assert.Equal (0, tv.SelectedLength);
  2610. Assert.Equal ("", tv.SelectedText);
  2611. Assert.False (tv.Selecting);
  2612. Assert.True (tv.ProcessKey (new KeyEvent (Key.CtrlMask | Key.CursorLeft, new KeyModifiers ())));
  2613. Assert.Equal ($"{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first", tv.Text);
  2614. Assert.Equal (new Point (18, 2), tv.CursorPosition);
  2615. Assert.Equal (0, tv.SelectedLength);
  2616. Assert.Equal ("", tv.SelectedText);
  2617. Assert.False (tv.Selecting);
  2618. Assert.True (tv.ProcessKey (new KeyEvent (Key.CtrlMask | Key.CursorLeft | Key.ShiftMask, new KeyModifiers ())));
  2619. Assert.Equal ($"{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first", tv.Text);
  2620. Assert.Equal (new Point (12, 2), tv.CursorPosition);
  2621. Assert.Equal (6, tv.SelectedLength);
  2622. Assert.Equal ("third ", tv.SelectedText);
  2623. Assert.True (tv.Selecting);
  2624. Assert.True (tv.ProcessKey (new KeyEvent ((Key)((int)'B' + Key.AltMask), new KeyModifiers ())));
  2625. Assert.Equal ($"{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first", tv.Text);
  2626. Assert.Equal (new Point (8, 2), tv.CursorPosition);
  2627. Assert.Equal (0, tv.SelectedLength);
  2628. Assert.Equal ("", tv.SelectedText);
  2629. Assert.False (tv.Selecting);
  2630. Assert.True (tv.ProcessKey (new KeyEvent (Key.CtrlMask | Key.CursorRight, new KeyModifiers ())));
  2631. Assert.Equal ($"{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first", tv.Text);
  2632. Assert.Equal (new Point (12, 2), tv.CursorPosition);
  2633. Assert.Equal (0, tv.SelectedLength);
  2634. Assert.Equal ("", tv.SelectedText);
  2635. Assert.False (tv.Selecting);
  2636. Assert.True (tv.ProcessKey (new KeyEvent (Key.CtrlMask | Key.CursorRight | Key.ShiftMask, new KeyModifiers ())));
  2637. Assert.Equal ($"{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first", tv.Text);
  2638. Assert.Equal (new Point (18, 2), tv.CursorPosition);
  2639. Assert.Equal (6, tv.SelectedLength);
  2640. Assert.Equal ("third ", tv.SelectedText);
  2641. Assert.True (tv.Selecting);
  2642. Assert.True (tv.ProcessKey (new KeyEvent ((Key)((int)'F' + Key.AltMask), new KeyModifiers ())));
  2643. Assert.Equal ($"{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first", tv.Text);
  2644. Assert.Equal (new Point (28, 2), tv.CursorPosition);
  2645. Assert.Equal (0, tv.SelectedLength);
  2646. Assert.Equal ("", tv.SelectedText);
  2647. Assert.False (tv.Selecting);
  2648. Assert.True (tv.ProcessKey (new KeyEvent (Key.Home | Key.CtrlMask, new KeyModifiers ())));
  2649. Assert.Equal ($"{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first", tv.Text);
  2650. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  2651. Assert.Equal (0, tv.SelectedLength);
  2652. Assert.Equal ("", tv.SelectedText);
  2653. Assert.False (tv.Selecting);
  2654. Assert.True (tv.ProcessKey (new KeyEvent (Key.DeleteChar | Key.CtrlMask, new KeyModifiers ())));
  2655. Assert.Equal ($"This is the second line.{Environment.NewLine}This is the third line.first", tv.Text);
  2656. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  2657. Assert.Equal (0, tv.SelectedLength);
  2658. Assert.Equal ("", tv.SelectedText);
  2659. Assert.False (tv.Selecting); Assert.True (tv.ProcessKey (new KeyEvent (Key.End | Key.CtrlMask, new KeyModifiers ())));
  2660. Assert.Equal ($"This is the second line.{Environment.NewLine}This is the third line.first", tv.Text);
  2661. Assert.Equal (new Point (28, 1), tv.CursorPosition);
  2662. Assert.Equal (0, tv.SelectedLength);
  2663. Assert.Equal ("", tv.SelectedText);
  2664. Assert.False (tv.Selecting);
  2665. Assert.False (tv.Selecting); Assert.True (tv.ProcessKey (new KeyEvent (Key.Backspace | Key.CtrlMask, new KeyModifiers ())));
  2666. Assert.Equal ($"This is the second line.{Environment.NewLine}This is the third ", tv.Text);
  2667. Assert.Equal (new Point (18, 1), tv.CursorPosition);
  2668. Assert.Equal (0, tv.SelectedLength);
  2669. Assert.Equal ("", tv.SelectedText);
  2670. Assert.False (tv.Selecting);
  2671. Assert.True (tv.AllowsReturn);
  2672. tv.AllowsReturn = false;
  2673. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  2674. Assert.False (tv.Selecting);
  2675. Assert.False (tv.ProcessKey (new KeyEvent (Key.Enter, new KeyModifiers ())));
  2676. Assert.Equal ($"This is the second line.{Environment.NewLine}This is the third ", tv.Text);
  2677. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  2678. Assert.Equal (0, tv.SelectedLength);
  2679. Assert.Equal ("", tv.SelectedText);
  2680. Assert.False (tv.Selecting);
  2681. Assert.False (tv.AllowsReturn);
  2682. tv.AllowsReturn = true;
  2683. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  2684. Assert.True (tv.ProcessKey (new KeyEvent (Key.Enter, new KeyModifiers ())));
  2685. Assert.Equal ($"{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third ", tv.Text);
  2686. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  2687. Assert.Equal (0, tv.SelectedLength);
  2688. Assert.Equal ("", tv.SelectedText);
  2689. Assert.False (tv.Selecting);
  2690. Assert.True (tv.AllowsReturn);
  2691. Assert.True (tv.ProcessKey (new KeyEvent (Key.CtrlMask | Key.End | Key.ShiftMask, new KeyModifiers ())));
  2692. Assert.Equal ($"{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third ", tv.Text);
  2693. Assert.Equal (new Point (18, 2), tv.CursorPosition);
  2694. Assert.Equal (42 + Environment.NewLine.Length, tv.SelectedLength);
  2695. Assert.Equal ($"This is the second line.{Environment.NewLine}This is the third ", tv.SelectedText);
  2696. Assert.True (tv.Selecting);
  2697. Assert.True (tv.ProcessKey (new KeyEvent (Key.CtrlMask | Key.Home | Key.ShiftMask, new KeyModifiers ())));
  2698. Assert.Equal ($"{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third ", tv.Text);
  2699. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  2700. Assert.Equal (Environment.NewLine.Length, tv.SelectedLength);
  2701. Assert.Equal ($"{Environment.NewLine}", tv.SelectedText);
  2702. Assert.True (tv.Selecting);
  2703. Assert.True (tv.ProcessKey (new KeyEvent (Key.T | Key.CtrlMask, new KeyModifiers ())));
  2704. Assert.Equal ($"{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third ", tv.Text);
  2705. Assert.Equal (new Point (18, 2), tv.CursorPosition);
  2706. Assert.Equal (42 + Environment.NewLine.Length * 2, tv.SelectedLength);
  2707. Assert.Equal ($"{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third ", tv.SelectedText);
  2708. Assert.True (tv.Selecting);
  2709. Assert.True (tv.Used);
  2710. Assert.True (tv.ProcessKey (new KeyEvent (Key.InsertChar, new KeyModifiers ())));
  2711. Assert.False (tv.Used);
  2712. Assert.True (tv.AllowsTab);
  2713. Assert.Equal (new Point (18, 2), tv.CursorPosition);
  2714. tv.AllowsTab = false;
  2715. Assert.False (tv.ProcessKey (new KeyEvent (Key.Tab, new KeyModifiers ())));
  2716. Assert.Equal ($"{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third ", tv.Text);
  2717. Assert.False (tv.AllowsTab);
  2718. tv.AllowsTab = true;
  2719. Assert.Equal (new Point (18, 2), tv.CursorPosition);
  2720. Assert.True (tv.Selecting);
  2721. tv.Selecting = false;
  2722. Assert.True (tv.ProcessKey (new KeyEvent (Key.Tab, new KeyModifiers ())));
  2723. Assert.Equal ($"{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third \t", tv.Text);
  2724. Assert.True (tv.AllowsTab);
  2725. tv.AllowsTab = false;
  2726. Assert.False (tv.ProcessKey (new KeyEvent (Key.BackTab | Key.ShiftMask, new KeyModifiers ())));
  2727. Assert.Equal ($"{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third \t", tv.Text);
  2728. Assert.False (tv.AllowsTab);
  2729. tv.AllowsTab = true;
  2730. Assert.True (tv.ProcessKey (new KeyEvent (Key.BackTab | Key.ShiftMask, new KeyModifiers ())));
  2731. Assert.Equal ($"{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third ", tv.Text);
  2732. Assert.True (tv.AllowsTab);
  2733. Assert.False (tv.ProcessKey (new KeyEvent (Key.Tab | Key.CtrlMask, new KeyModifiers ())));
  2734. Assert.False (tv.ProcessKey (new KeyEvent (Application.AlternateForwardKey, new KeyModifiers ())));
  2735. Assert.False (tv.ProcessKey (new KeyEvent (Key.Tab | Key.CtrlMask | Key.ShiftMask, new KeyModifiers ())));
  2736. Assert.False (tv.ProcessKey (new KeyEvent (Application.AlternateBackwardKey, new KeyModifiers ())));
  2737. }
  2738. [Fact]
  2739. public void HistoryText_Exceptions ()
  2740. {
  2741. var ht = new HistoryText ();
  2742. foreach (var ls in Enum.GetValues (typeof (HistoryText.LineStatus))) {
  2743. if ((HistoryText.LineStatus)ls != HistoryText.LineStatus.Original) {
  2744. Assert.Throws<ArgumentException> (() => ht.Add (new List<List<Rune>> () { new List<Rune> () }, Point.Empty,
  2745. (HistoryText.LineStatus)ls));
  2746. }
  2747. }
  2748. Assert.Null (Record.Exception (() => ht.Add (new List<List<Rune>> () { new List<Rune> () }, Point.Empty,
  2749. HistoryText.LineStatus.Original)));
  2750. }
  2751. [Fact]
  2752. [AutoInitShutdown]
  2753. public void HistoryText_Undo_Redo_Single_Line_InsertText ()
  2754. {
  2755. var text = "This is the first line.\nThis is the second line.\nThis is the third line.";
  2756. var tv = new TextView () {
  2757. Width = 10,
  2758. Height = 2,
  2759. Text = text
  2760. };
  2761. var top = Application.Top;
  2762. top.Add (tv);
  2763. Application.Begin (top);
  2764. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  2765. Assert.Equal (3, tv.Lines);
  2766. Assert.Equal (Point.Empty, tv.CursorPosition);
  2767. var messy = " messy";
  2768. tv.CursorPosition = new Point (7, 1);
  2769. tv.InsertText (messy);
  2770. Assert.Equal ($"This is the first line.{Environment.NewLine}This is messy the second line.{Environment.NewLine}This is the third line.", tv.Text);
  2771. Assert.Equal (3, tv.Lines);
  2772. Assert.Equal (new Point (13, 1), tv.CursorPosition);
  2773. for (int i = 0; i < messy.Length; i++) {
  2774. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  2775. }
  2776. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  2777. Assert.Equal (3, tv.Lines);
  2778. Assert.Equal (new Point (7, 1), tv.CursorPosition);
  2779. for (int i = 0; i < messy.Length; i++) {
  2780. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  2781. }
  2782. Assert.Equal ($"This is the first line.{Environment.NewLine}This is messy the second line.{Environment.NewLine}This is the third line.", tv.Text);
  2783. Assert.Equal (3, tv.Lines);
  2784. Assert.Equal (new Point (13, 1), tv.CursorPosition);
  2785. }
  2786. [Fact]
  2787. [AutoInitShutdown]
  2788. public void HistoryText_Undo_Redo_Single_Line_DeleteCharLeft ()
  2789. {
  2790. var text = "This is the first line.\nThis is the second line.\nThis is the third line.";
  2791. var tv = new TextView () {
  2792. Width = 10,
  2793. Height = 2,
  2794. Text = text
  2795. };
  2796. var top = Application.Top;
  2797. top.Add (tv);
  2798. Application.Begin (top);
  2799. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  2800. Assert.Equal (3, tv.Lines);
  2801. Assert.Equal (Point.Empty, tv.CursorPosition);
  2802. var ntimes = 3;
  2803. tv.CursorPosition = new Point (7, 1);
  2804. for (int i = 0; i < ntimes; i++) {
  2805. tv.DeleteCharLeft ();
  2806. }
  2807. Assert.Equal ($"This is the first line.{Environment.NewLine}This the second line.{Environment.NewLine}This is the third line.", tv.Text);
  2808. Assert.Equal (3, tv.Lines);
  2809. Assert.Equal (new Point (4, 1), tv.CursorPosition);
  2810. for (int i = 0; i < ntimes; i++) {
  2811. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  2812. }
  2813. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  2814. Assert.Equal (3, tv.Lines);
  2815. Assert.Equal (new Point (7, 1), tv.CursorPosition);
  2816. for (int i = 0; i < ntimes; i++) {
  2817. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  2818. }
  2819. Assert.Equal ($"This is the first line.{Environment.NewLine}This the second line.{Environment.NewLine}This is the third line.", tv.Text);
  2820. Assert.Equal (3, tv.Lines);
  2821. Assert.Equal (new Point (4, 1), tv.CursorPosition);
  2822. }
  2823. [Fact]
  2824. [AutoInitShutdown]
  2825. public void HistoryText_Undo_Redo_Single_Line_DeleteCharRight ()
  2826. {
  2827. var text = "This is the first line.\nThis is the second line.\nThis is the third line.";
  2828. var tv = new TextView () {
  2829. Width = 10,
  2830. Height = 2,
  2831. Text = text
  2832. };
  2833. var top = Application.Top;
  2834. top.Add (tv);
  2835. Application.Begin (top);
  2836. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  2837. Assert.Equal (3, tv.Lines);
  2838. Assert.Equal (Point.Empty, tv.CursorPosition);
  2839. var ntimes = 3;
  2840. tv.CursorPosition = new Point (7, 1);
  2841. for (int i = 0; i < ntimes; i++) {
  2842. tv.DeleteCharRight ();
  2843. }
  2844. Assert.Equal ($"This is the first line.{Environment.NewLine}This ise second line.{Environment.NewLine}This is the third line.", tv.Text);
  2845. Assert.Equal (3, tv.Lines);
  2846. Assert.Equal (new Point (7, 1), tv.CursorPosition);
  2847. for (int i = 0; i < ntimes; i++) {
  2848. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  2849. }
  2850. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  2851. Assert.Equal (3, tv.Lines);
  2852. Assert.Equal (new Point (7, 1), tv.CursorPosition);
  2853. for (int i = 0; i < ntimes; i++) {
  2854. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  2855. }
  2856. Assert.Equal ($"This is the first line.{Environment.NewLine}This ise second line.{Environment.NewLine}This is the third line.", tv.Text);
  2857. Assert.Equal (3, tv.Lines);
  2858. Assert.Equal (new Point (7, 1), tv.CursorPosition);
  2859. }
  2860. [Fact]
  2861. [AutoInitShutdown]
  2862. public void HistoryText_Undo_Redo_Single_Line_Selected_InsertText ()
  2863. {
  2864. var text = "This is the first line.\nThis is the second line.\nThis is the third line.";
  2865. var tv = new TextView () {
  2866. Width = 10,
  2867. Height = 2,
  2868. Text = text
  2869. };
  2870. var top = Application.Top;
  2871. top.Add (tv);
  2872. Application.Begin (top);
  2873. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  2874. Assert.Equal (3, tv.Lines);
  2875. Assert.Equal (Point.Empty, tv.CursorPosition);
  2876. var messy = " messy";
  2877. tv.CursorPosition = new Point (7, 1);
  2878. tv.SelectionStartColumn = 11;
  2879. tv.SelectionStartRow = 1;
  2880. Assert.Equal (4, tv.SelectedLength);
  2881. tv.InsertText (messy);
  2882. Assert.Equal ($"This is the first line.{Environment.NewLine}This is messy second line.{Environment.NewLine}This is the third line.", tv.Text);
  2883. Assert.Equal (3, tv.Lines);
  2884. Assert.Equal (new Point (13, 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.Z | Key.CtrlMask, new KeyModifiers ())));
  2890. }
  2891. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  2892. Assert.Equal (3, tv.Lines);
  2893. Assert.Equal (new Point (7, 1), tv.CursorPosition);
  2894. Assert.Equal (11, tv.SelectionStartColumn);
  2895. Assert.Equal (1, tv.SelectionStartRow);
  2896. Assert.Equal (0, tv.SelectedLength);
  2897. for (int i = 0; i < messy.Length; i++) {
  2898. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  2899. }
  2900. Assert.Equal ($"This is the first line.{Environment.NewLine}This is messy second line.{Environment.NewLine}This is the third line.", tv.Text);
  2901. Assert.Equal (3, tv.Lines);
  2902. Assert.Equal (new Point (13, 1), tv.CursorPosition);
  2903. Assert.Equal (11, tv.SelectionStartColumn);
  2904. Assert.Equal (1, tv.SelectionStartRow);
  2905. Assert.Equal (0, tv.SelectedLength);
  2906. }
  2907. [Fact]
  2908. [AutoInitShutdown]
  2909. public void HistoryText_Undo_Redo_Single_Line_Selected_DeleteCharLeft ()
  2910. {
  2911. var text = "This is the first line.\nThis is the second line.\nThis is the third line.";
  2912. var tv = new TextView () {
  2913. Width = 10,
  2914. Height = 2,
  2915. Text = text
  2916. };
  2917. var top = Application.Top;
  2918. top.Add (tv);
  2919. Application.Begin (top);
  2920. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  2921. Assert.Equal (3, tv.Lines);
  2922. Assert.Equal (Point.Empty, tv.CursorPosition);
  2923. var ntimes = 3;
  2924. tv.CursorPosition = new Point (7, 1);
  2925. tv.SelectionStartColumn = 11;
  2926. tv.SelectionStartRow = 1;
  2927. Assert.Equal (4, tv.SelectedLength);
  2928. for (int i = 0; i < ntimes; i++) {
  2929. tv.DeleteCharLeft ();
  2930. }
  2931. Assert.Equal ($"This is the first line.{Environment.NewLine}This second line.{Environment.NewLine}This is the third line.", tv.Text);
  2932. Assert.Equal (3, tv.Lines);
  2933. Assert.Equal (new Point (5, 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.Z | Key.CtrlMask, new KeyModifiers ())));
  2939. }
  2940. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  2941. Assert.Equal (3, tv.Lines);
  2942. Assert.Equal (new Point (7, 1), tv.CursorPosition);
  2943. Assert.Equal (11, tv.SelectionStartColumn);
  2944. Assert.Equal (1, tv.SelectionStartRow);
  2945. Assert.Equal (0, tv.SelectedLength);
  2946. for (int i = 0; i < ntimes; i++) {
  2947. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  2948. }
  2949. Assert.Equal ($"This is the first line.{Environment.NewLine}This second line.{Environment.NewLine}This is the third line.", tv.Text);
  2950. Assert.Equal (3, tv.Lines);
  2951. Assert.Equal (new Point (5, 1), tv.CursorPosition);
  2952. Assert.Equal (11, tv.SelectionStartColumn);
  2953. Assert.Equal (1, tv.SelectionStartRow);
  2954. Assert.Equal (0, tv.SelectedLength);
  2955. }
  2956. [Fact]
  2957. [AutoInitShutdown]
  2958. public void HistoryText_Undo_Redo_Single_Line_Selected_DeleteCharRight ()
  2959. {
  2960. var text = "This is the first line.\nThis is the second line.\nThis is the third line.";
  2961. var tv = new TextView () {
  2962. Width = 10,
  2963. Height = 2,
  2964. Text = text
  2965. };
  2966. var top = Application.Top;
  2967. top.Add (tv);
  2968. Application.Begin (top);
  2969. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  2970. Assert.Equal (3, tv.Lines);
  2971. Assert.Equal (Point.Empty, tv.CursorPosition);
  2972. var ntimes = 3;
  2973. tv.CursorPosition = new Point (7, 1);
  2974. tv.SelectionStartColumn = 11;
  2975. tv.SelectionStartRow = 1;
  2976. Assert.Equal (4, tv.SelectedLength);
  2977. for (int i = 0; i < ntimes; i++) {
  2978. tv.DeleteCharRight ();
  2979. }
  2980. Assert.Equal ($"This is the first line.{Environment.NewLine}This isecond 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.Z | Key.CtrlMask, new KeyModifiers ())));
  2988. }
  2989. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second 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. for (int i = 0; i < ntimes; i++) {
  2996. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  2997. }
  2998. Assert.Equal ($"This is the first line.{Environment.NewLine}This isecond line.{Environment.NewLine}This is the third line.", tv.Text);
  2999. Assert.Equal (3, tv.Lines);
  3000. Assert.Equal (new Point (7, 1), tv.CursorPosition);
  3001. Assert.Equal (11, tv.SelectionStartColumn);
  3002. Assert.Equal (1, tv.SelectionStartRow);
  3003. Assert.Equal (0, tv.SelectedLength);
  3004. }
  3005. [Fact]
  3006. [AutoInitShutdown]
  3007. public void HistoryText_Undo_Redo_Multi_Line_InsertText ()
  3008. {
  3009. var text = "This is the first line.\nThis is the second line.\nThis is the third line.";
  3010. var tv = new TextView () {
  3011. Width = 10,
  3012. Height = 2,
  3013. Text = text
  3014. };
  3015. var top = Application.Top;
  3016. top.Add (tv);
  3017. Application.Begin (top);
  3018. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  3019. Assert.Equal (3, tv.Lines);
  3020. Assert.Equal (Point.Empty, tv.CursorPosition);
  3021. var messy = " messy";
  3022. tv.CursorPosition = new Point (7, 1);
  3023. tv.InsertText (messy);
  3024. Assert.Equal ($"This is the first line.{Environment.NewLine}This is messy the second line.{Environment.NewLine}This is the third line.", tv.Text);
  3025. Assert.Equal (3, tv.Lines);
  3026. Assert.Equal (new Point (13, 1), tv.CursorPosition);
  3027. tv.CursorPosition = new Point (7, 0);
  3028. tv.InsertText (messy);
  3029. 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);
  3030. Assert.Equal (3, tv.Lines);
  3031. Assert.Equal (new Point (13, 0), tv.CursorPosition);
  3032. tv.CursorPosition = new Point (7, 2);
  3033. tv.InsertText (messy);
  3034. 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);
  3035. Assert.Equal (3, tv.Lines);
  3036. Assert.Equal (new Point (13, 2), tv.CursorPosition);
  3037. for (int i = 0; i < messy.Length; i++) {
  3038. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  3039. }
  3040. 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);
  3041. Assert.Equal (3, tv.Lines);
  3042. Assert.Equal (new Point (7, 2), tv.CursorPosition);
  3043. for (int i = 0; i < messy.Length; i++) {
  3044. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  3045. }
  3046. Assert.Equal ($"This is the first line.{Environment.NewLine}This is messy the second line.{Environment.NewLine}This is the third line.", tv.Text);
  3047. Assert.Equal (3, tv.Lines);
  3048. Assert.Equal (new Point (7, 0), tv.CursorPosition);
  3049. for (int i = 0; i < messy.Length; i++) {
  3050. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  3051. }
  3052. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  3053. Assert.Equal (3, tv.Lines);
  3054. Assert.Equal (new Point (7, 1), tv.CursorPosition);
  3055. for (int i = 0; i < messy.Length; i++) {
  3056. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  3057. }
  3058. Assert.Equal ($"This is the first line.{Environment.NewLine}This is messy the second line.{Environment.NewLine}This is the third line.", tv.Text);
  3059. Assert.Equal (3, tv.Lines);
  3060. Assert.Equal (new Point (13, 1), tv.CursorPosition);
  3061. for (int i = 0; i < messy.Length; i++) {
  3062. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  3063. }
  3064. 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);
  3065. Assert.Equal (3, tv.Lines);
  3066. Assert.Equal (new Point (13, 0), tv.CursorPosition);
  3067. for (int i = 0; i < messy.Length; i++) {
  3068. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  3069. }
  3070. 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);
  3071. Assert.Equal (3, tv.Lines);
  3072. Assert.Equal (new Point (13, 2), tv.CursorPosition);
  3073. }
  3074. [Fact]
  3075. [AutoInitShutdown]
  3076. public void HistoryText_Undo_Redo_Multi_Line_DeleteCharLeft ()
  3077. {
  3078. var text = "This is the first line.\nThis is the second line.\nThis is the third line.";
  3079. var tv = new TextView () {
  3080. Width = 10,
  3081. Height = 2,
  3082. Text = text
  3083. };
  3084. var top = Application.Top;
  3085. top.Add (tv);
  3086. Application.Begin (top);
  3087. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  3088. Assert.Equal (3, tv.Lines);
  3089. Assert.Equal (Point.Empty, tv.CursorPosition);
  3090. var ntimes = 3;
  3091. tv.CursorPosition = new Point (7, 1);
  3092. for (int i = 0; i < ntimes; i++) {
  3093. tv.DeleteCharLeft ();
  3094. }
  3095. Assert.Equal ($"This is the first line.{Environment.NewLine}This the second line.{Environment.NewLine}This is the third line.", tv.Text);
  3096. Assert.Equal (3, tv.Lines);
  3097. Assert.Equal (new Point (4, 1), tv.CursorPosition);
  3098. tv.CursorPosition = new Point (7, 0);
  3099. for (int i = 0; i < ntimes; i++) {
  3100. tv.DeleteCharLeft ();
  3101. }
  3102. Assert.Equal ($"This the first line.{Environment.NewLine}This the second line.{Environment.NewLine}This is the third line.", tv.Text);
  3103. Assert.Equal (3, tv.Lines);
  3104. Assert.Equal (new Point (4, 0), tv.CursorPosition);
  3105. tv.CursorPosition = new Point (7, 2);
  3106. for (int i = 0; i < ntimes; i++) {
  3107. tv.DeleteCharLeft ();
  3108. }
  3109. Assert.Equal ($"This the first line.{Environment.NewLine}This the second line.{Environment.NewLine}This the third line.", tv.Text);
  3110. Assert.Equal (3, tv.Lines);
  3111. Assert.Equal (new Point (4, 2), tv.CursorPosition);
  3112. for (int i = 0; i < ntimes; i++) {
  3113. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  3114. switch (i) {
  3115. case 0:
  3116. Assert.Equal ($"This the first line.{Environment.NewLine}This the second line.{Environment.NewLine}This the third line.", tv.Text);
  3117. Assert.Equal (new Point (5, 2), tv.CursorPosition);
  3118. break;
  3119. case 1:
  3120. Assert.Equal ($"This the first line.{Environment.NewLine}This the second line.{Environment.NewLine}This i the third line.", tv.Text);
  3121. Assert.Equal (new Point (6, 2), tv.CursorPosition);
  3122. break;
  3123. case 2:
  3124. Assert.Equal ($"This the first line.{Environment.NewLine}This the second line.{Environment.NewLine}This is the third line.", tv.Text);
  3125. Assert.Equal (new Point (7, 2), tv.CursorPosition);
  3126. break;
  3127. }
  3128. }
  3129. Assert.Equal ($"This the first line.{Environment.NewLine}This the second line.{Environment.NewLine}This is the third line.", tv.Text);
  3130. Assert.Equal (3, tv.Lines);
  3131. Assert.Equal (new Point (7, 2), tv.CursorPosition);
  3132. for (int i = 0; i < ntimes; i++) {
  3133. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  3134. switch (i) {
  3135. case 0:
  3136. Assert.Equal ($"This the first line.{Environment.NewLine}This the second line.{Environment.NewLine}This is the third line.", tv.Text);
  3137. Assert.Equal (new Point (5, 0), tv.CursorPosition);
  3138. break;
  3139. case 1:
  3140. Assert.Equal ($"This i the first line.{Environment.NewLine}This the second line.{Environment.NewLine}This is the third line.", tv.Text);
  3141. Assert.Equal (new Point (6, 0), tv.CursorPosition);
  3142. break;
  3143. case 2:
  3144. Assert.Equal ($"This is the first line.{Environment.NewLine}This the second line.{Environment.NewLine}This is the third line.", tv.Text);
  3145. Assert.Equal (new Point (7, 0), tv.CursorPosition);
  3146. break;
  3147. }
  3148. }
  3149. Assert.Equal ($"This is the first line.{Environment.NewLine}This the second line.{Environment.NewLine}This is the third line.", tv.Text);
  3150. Assert.Equal (3, tv.Lines);
  3151. Assert.Equal (new Point (7, 0), tv.CursorPosition);
  3152. for (int i = 0; i < ntimes; i++) {
  3153. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  3154. switch (i) {
  3155. case 0:
  3156. Assert.Equal ($"This is the first line.{Environment.NewLine}This the second line.{Environment.NewLine}This is the third line.", tv.Text);
  3157. Assert.Equal (new Point (5, 1), tv.CursorPosition);
  3158. break;
  3159. case 1:
  3160. Assert.Equal ($"This is the first line.{Environment.NewLine}This i the second line.{Environment.NewLine}This is the third line.", tv.Text);
  3161. Assert.Equal (new Point (6, 1), tv.CursorPosition);
  3162. break;
  3163. case 2:
  3164. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  3165. Assert.Equal (new Point (7, 1), tv.CursorPosition);
  3166. break;
  3167. }
  3168. }
  3169. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  3170. Assert.Equal (3, tv.Lines);
  3171. Assert.Equal (new Point (7, 1), tv.CursorPosition);
  3172. for (int i = 0; i < ntimes; i++) {
  3173. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  3174. }
  3175. Assert.Equal ($"This is the first line.{Environment.NewLine}This the second line.{Environment.NewLine}This is the third line.", tv.Text);
  3176. Assert.Equal (3, tv.Lines);
  3177. Assert.Equal (new Point (4, 1), tv.CursorPosition);
  3178. for (int i = 0; i < ntimes; i++) {
  3179. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  3180. }
  3181. Assert.Equal ($"This the first line.{Environment.NewLine}This the second line.{Environment.NewLine}This is the third line.", tv.Text);
  3182. Assert.Equal (3, tv.Lines);
  3183. Assert.Equal (new Point (4, 0), tv.CursorPosition);
  3184. for (int i = 0; i < ntimes; i++) {
  3185. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  3186. }
  3187. Assert.Equal ($"This the first line.{Environment.NewLine}This the second line.{Environment.NewLine}This the third line.", tv.Text);
  3188. Assert.Equal (3, tv.Lines);
  3189. Assert.Equal (new Point (4, 2), tv.CursorPosition);
  3190. }
  3191. [Fact]
  3192. [AutoInitShutdown]
  3193. public void HistoryText_Undo_Redo_Multi_Line_DeleteCharRight ()
  3194. {
  3195. var text = "This is the first line.\nThis is the second line.\nThis is the third line.";
  3196. var tv = new TextView () {
  3197. Width = 10,
  3198. Height = 2,
  3199. Text = text
  3200. };
  3201. var top = Application.Top;
  3202. top.Add (tv);
  3203. Application.Begin (top);
  3204. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  3205. Assert.Equal (3, tv.Lines);
  3206. Assert.Equal (Point.Empty, tv.CursorPosition);
  3207. var ntimes = 3;
  3208. tv.CursorPosition = new Point (7, 1);
  3209. for (int i = 0; i < ntimes; i++) {
  3210. tv.DeleteCharRight ();
  3211. }
  3212. Assert.Equal ($"This is the first line.{Environment.NewLine}This ise second line.{Environment.NewLine}This is the third line.", tv.Text);
  3213. Assert.Equal (3, tv.Lines);
  3214. Assert.Equal (new Point (7, 1), tv.CursorPosition);
  3215. tv.CursorPosition = new Point (7, 0);
  3216. for (int i = 0; i < ntimes; i++) {
  3217. tv.DeleteCharRight ();
  3218. }
  3219. Assert.Equal ($"This ise first line.{Environment.NewLine}This ise second line.{Environment.NewLine}This is the third line.", tv.Text);
  3220. Assert.Equal (3, tv.Lines);
  3221. Assert.Equal (new Point (7, 0), tv.CursorPosition);
  3222. tv.CursorPosition = new Point (7, 2);
  3223. for (int i = 0; i < ntimes; i++) {
  3224. tv.DeleteCharRight ();
  3225. }
  3226. Assert.Equal ($"This ise first line.{Environment.NewLine}This ise second line.{Environment.NewLine}This ise third line.", tv.Text);
  3227. Assert.Equal (3, tv.Lines);
  3228. Assert.Equal (new Point (7, 2), tv.CursorPosition);
  3229. for (int i = 0; i < ntimes; i++) {
  3230. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  3231. }
  3232. Assert.Equal ($"This ise first line.{Environment.NewLine}This ise second line.{Environment.NewLine}This is the third line.", tv.Text);
  3233. Assert.Equal (3, tv.Lines);
  3234. Assert.Equal (new Point (7, 2), tv.CursorPosition);
  3235. for (int i = 0; i < ntimes; i++) {
  3236. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  3237. }
  3238. Assert.Equal ($"This is the first line.{Environment.NewLine}This ise second line.{Environment.NewLine}This is the third line.", tv.Text);
  3239. Assert.Equal (3, tv.Lines);
  3240. Assert.Equal (new Point (7, 0), tv.CursorPosition);
  3241. for (int i = 0; i < ntimes; i++) {
  3242. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  3243. }
  3244. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  3245. Assert.Equal (3, tv.Lines);
  3246. Assert.Equal (new Point (7, 1), tv.CursorPosition);
  3247. for (int i = 0; i < ntimes; i++) {
  3248. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  3249. }
  3250. Assert.Equal ($"This is the first line.{Environment.NewLine}This ise second line.{Environment.NewLine}This is the third line.", tv.Text);
  3251. Assert.Equal (3, tv.Lines);
  3252. Assert.Equal (new Point (7, 1), tv.CursorPosition);
  3253. for (int i = 0; i < ntimes; i++) {
  3254. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  3255. }
  3256. Assert.Equal ($"This ise first line.{Environment.NewLine}This ise second line.{Environment.NewLine}This is the third line.", tv.Text);
  3257. Assert.Equal (3, tv.Lines);
  3258. Assert.Equal (new Point (7, 0), tv.CursorPosition);
  3259. for (int i = 0; i < ntimes; i++) {
  3260. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  3261. }
  3262. Assert.Equal ($"This ise first line.{Environment.NewLine}This ise second line.{Environment.NewLine}This ise third line.", tv.Text);
  3263. Assert.Equal (3, tv.Lines);
  3264. Assert.Equal (new Point (7, 2), tv.CursorPosition);
  3265. }
  3266. [Fact]
  3267. [AutoInitShutdown]
  3268. public void HistoryText_Undo_Redo_Multi_Line_Selected_InsertText ()
  3269. {
  3270. var text = $"This is the first line.{Environment.NewLine}This is the second line.\nThis is the third line.";
  3271. var tv = new TextView () {
  3272. Width = 10,
  3273. Height = 2,
  3274. Text = text
  3275. };
  3276. var top = Application.Top;
  3277. top.Add (tv);
  3278. Application.Begin (top);
  3279. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  3280. Assert.Equal (3, tv.Lines);
  3281. Assert.Equal (Point.Empty, tv.CursorPosition);
  3282. var messy = " messy";
  3283. tv.CursorPosition = new Point (7, 0);
  3284. tv.SelectionStartColumn = 11;
  3285. tv.SelectionStartRow = 2;
  3286. Assert.Equal (51 + Environment.NewLine.Length * 2, tv.SelectedLength);
  3287. for (int i = 0; i < messy.Length; i++) {
  3288. tv.InsertText (messy [i].ToString ());
  3289. switch (i) {
  3290. case 0:
  3291. Assert.Equal ("This is third line.", tv.Text);
  3292. Assert.Equal (new Point (8, 0), tv.CursorPosition);
  3293. break;
  3294. case 1:
  3295. Assert.Equal ("This is m third line.", tv.Text);
  3296. Assert.Equal (new Point (9, 0), tv.CursorPosition);
  3297. break;
  3298. case 2:
  3299. Assert.Equal ("This is me third line.", tv.Text);
  3300. Assert.Equal (new Point (10, 0), tv.CursorPosition);
  3301. break;
  3302. case 3:
  3303. Assert.Equal ("This is mes third line.", tv.Text);
  3304. Assert.Equal (new Point (11, 0), tv.CursorPosition);
  3305. break;
  3306. case 4:
  3307. Assert.Equal ("This is mess third line.", tv.Text);
  3308. Assert.Equal (new Point (12, 0), tv.CursorPosition);
  3309. break;
  3310. case 5:
  3311. Assert.Equal ("This is messy third line.", tv.Text);
  3312. Assert.Equal (new Point (13, 0), tv.CursorPosition);
  3313. break;
  3314. }
  3315. }
  3316. Assert.Equal ($"This is messy third line.", tv.Text);
  3317. Assert.Equal (1, tv.Lines);
  3318. Assert.Equal (new Point (13, 0), tv.CursorPosition);
  3319. Assert.Equal (11, tv.SelectionStartColumn);
  3320. Assert.Equal (2, tv.SelectionStartRow);
  3321. Assert.Equal (0, tv.SelectedLength);
  3322. for (int i = 0; i < messy.Length; i++) {
  3323. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  3324. switch (i) {
  3325. case 0:
  3326. Assert.Equal ("This is mess third line.", tv.Text);
  3327. Assert.Equal (new Point (12, 0), tv.CursorPosition);
  3328. break;
  3329. case 1:
  3330. Assert.Equal ("This is mes third line.", tv.Text);
  3331. Assert.Equal (new Point (11, 0), tv.CursorPosition);
  3332. break;
  3333. case 2:
  3334. Assert.Equal ("This is me third line.", tv.Text);
  3335. Assert.Equal (new Point (10, 0), tv.CursorPosition);
  3336. break;
  3337. case 3:
  3338. Assert.Equal ("This is m third line.", tv.Text);
  3339. Assert.Equal (new Point (9, 0), tv.CursorPosition);
  3340. break;
  3341. case 4:
  3342. Assert.Equal ("This is third line.", tv.Text);
  3343. Assert.Equal (new Point (8, 0), tv.CursorPosition);
  3344. break;
  3345. case 5:
  3346. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  3347. Assert.Equal (new Point (7, 0), tv.CursorPosition);
  3348. break;
  3349. }
  3350. }
  3351. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  3352. Assert.Equal (3, tv.Lines);
  3353. Assert.Equal (new Point (7, 0), tv.CursorPosition);
  3354. Assert.Equal (11, tv.SelectionStartColumn);
  3355. Assert.Equal (2, tv.SelectionStartRow);
  3356. Assert.Equal (0, tv.SelectedLength);
  3357. for (int i = 0; i < messy.Length; i++) {
  3358. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  3359. switch (i) {
  3360. case 0:
  3361. Assert.Equal ("This is third line.", tv.Text);
  3362. Assert.Equal (new Point (8, 0), tv.CursorPosition);
  3363. break;
  3364. case 1:
  3365. Assert.Equal ("This is m third line.", tv.Text);
  3366. Assert.Equal (new Point (9, 0), tv.CursorPosition);
  3367. break;
  3368. case 2:
  3369. Assert.Equal ("This is me third line.", tv.Text);
  3370. Assert.Equal (new Point (10, 0), tv.CursorPosition);
  3371. break;
  3372. case 3:
  3373. Assert.Equal ("This is mes third line.", tv.Text);
  3374. Assert.Equal (new Point (11, 0), tv.CursorPosition);
  3375. break;
  3376. case 4:
  3377. Assert.Equal ("This is mess third line.", tv.Text);
  3378. Assert.Equal (new Point (12, 0), tv.CursorPosition);
  3379. break;
  3380. case 5:
  3381. Assert.Equal ("This is messy third line.", tv.Text);
  3382. Assert.Equal (new Point (13, 0), tv.CursorPosition);
  3383. break;
  3384. }
  3385. }
  3386. Assert.Equal ("This is messy third line.", tv.Text);
  3387. Assert.Equal (1, tv.Lines);
  3388. Assert.Equal (new Point (13, 0), tv.CursorPosition);
  3389. Assert.Equal (11, tv.SelectionStartColumn);
  3390. Assert.Equal (2, tv.SelectionStartRow);
  3391. Assert.Equal (0, tv.SelectedLength);
  3392. }
  3393. [Fact]
  3394. [AutoInitShutdown]
  3395. public void HistoryText_Undo_Redo_Multi_Line_With_Empty_Text ()
  3396. {
  3397. var tv = new TextView () {
  3398. Width = 10,
  3399. Height = 2
  3400. };
  3401. var top = Application.Top;
  3402. top.Add (tv);
  3403. Application.Begin (top);
  3404. Assert.Equal ("", tv.Text);
  3405. Assert.Equal (1, tv.Lines);
  3406. Assert.Equal (Point.Empty, tv.CursorPosition);
  3407. Assert.False (tv.IsDirty);
  3408. Assert.True (tv.ProcessKey (new KeyEvent (Key.O, new KeyModifiers ())));
  3409. Assert.Equal ("O", tv.Text);
  3410. Assert.Equal (1, tv.Lines);
  3411. Assert.Equal (new Point (1, 0), tv.CursorPosition);
  3412. Assert.True (tv.IsDirty);
  3413. Assert.True (tv.ProcessKey (new KeyEvent (Key.n, new KeyModifiers ())));
  3414. Assert.Equal ("On", tv.Text);
  3415. Assert.Equal (1, tv.Lines);
  3416. Assert.Equal (new Point (2, 0), tv.CursorPosition);
  3417. Assert.True (tv.IsDirty);
  3418. Assert.True (tv.ProcessKey (new KeyEvent (Key.e, new KeyModifiers ())));
  3419. Assert.Equal ("One", tv.Text);
  3420. Assert.Equal (1, tv.Lines);
  3421. Assert.Equal (new Point (3, 0), tv.CursorPosition);
  3422. Assert.True (tv.IsDirty);
  3423. Assert.True (tv.ProcessKey (new KeyEvent (Key.Enter, new KeyModifiers ())));
  3424. Assert.Equal ($"One{Environment.NewLine}", tv.Text);
  3425. Assert.Equal (2, tv.Lines);
  3426. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  3427. Assert.True (tv.IsDirty);
  3428. Assert.True (tv.ProcessKey (new KeyEvent (Key.T, new KeyModifiers ())));
  3429. Assert.Equal ($"One{Environment.NewLine}T", tv.Text);
  3430. Assert.Equal (2, tv.Lines);
  3431. Assert.Equal (new Point (1, 1), tv.CursorPosition);
  3432. Assert.True (tv.IsDirty);
  3433. Assert.True (tv.ProcessKey (new KeyEvent (Key.w, new KeyModifiers ())));
  3434. Assert.Equal ($"One{Environment.NewLine}Tw", tv.Text);
  3435. Assert.Equal (2, tv.Lines);
  3436. Assert.Equal (new Point (2, 1), tv.CursorPosition);
  3437. Assert.True (tv.IsDirty);
  3438. Assert.True (tv.ProcessKey (new KeyEvent (Key.o, new KeyModifiers ())));
  3439. Assert.Equal ($"One{Environment.NewLine}Two", tv.Text);
  3440. Assert.Equal (2, tv.Lines);
  3441. Assert.Equal (new Point (3, 1), tv.CursorPosition);
  3442. Assert.True (tv.IsDirty);
  3443. Assert.True (tv.ProcessKey (new KeyEvent (Key.Enter, new KeyModifiers ())));
  3444. Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}", tv.Text);
  3445. Assert.Equal (3, tv.Lines);
  3446. Assert.Equal (new Point (0, 2), tv.CursorPosition);
  3447. Assert.True (tv.IsDirty);
  3448. Assert.True (tv.ProcessKey (new KeyEvent (Key.T, new KeyModifiers ())));
  3449. Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}T", tv.Text);
  3450. Assert.Equal (3, tv.Lines);
  3451. Assert.Equal (new Point (1, 2), tv.CursorPosition);
  3452. Assert.True (tv.IsDirty);
  3453. Assert.True (tv.ProcessKey (new KeyEvent (Key.h, new KeyModifiers ())));
  3454. Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}Th", tv.Text);
  3455. Assert.Equal (3, tv.Lines);
  3456. Assert.Equal (new Point (2, 2), tv.CursorPosition);
  3457. Assert.True (tv.IsDirty);
  3458. Assert.True (tv.ProcessKey (new KeyEvent (Key.r, new KeyModifiers ())));
  3459. Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}Thr", tv.Text);
  3460. Assert.Equal (3, tv.Lines);
  3461. Assert.Equal (new Point (3, 2), tv.CursorPosition);
  3462. Assert.True (tv.IsDirty);
  3463. Assert.True (tv.ProcessKey (new KeyEvent (Key.e, new KeyModifiers ())));
  3464. Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}Thre", tv.Text);
  3465. Assert.Equal (3, tv.Lines);
  3466. Assert.Equal (new Point (4, 2), tv.CursorPosition);
  3467. Assert.True (tv.IsDirty);
  3468. Assert.True (tv.ProcessKey (new KeyEvent (Key.e, new KeyModifiers ())));
  3469. Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}Three", tv.Text);
  3470. Assert.Equal (3, tv.Lines);
  3471. Assert.Equal (new Point (5, 2), tv.CursorPosition);
  3472. Assert.True (tv.IsDirty);
  3473. Assert.True (tv.ProcessKey (new KeyEvent (Key.Enter, new KeyModifiers ())));
  3474. Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}Three{Environment.NewLine}", tv.Text);
  3475. Assert.Equal (4, tv.Lines);
  3476. Assert.Equal (new Point (0, 3), tv.CursorPosition);
  3477. Assert.True (tv.IsDirty);
  3478. // Undoing
  3479. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  3480. Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}Three", tv.Text);
  3481. Assert.Equal (3, tv.Lines);
  3482. Assert.Equal (new Point (5, 2), tv.CursorPosition);
  3483. Assert.True (tv.IsDirty);
  3484. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  3485. Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}Thre", tv.Text);
  3486. Assert.Equal (3, tv.Lines);
  3487. Assert.Equal (new Point (4, 2), tv.CursorPosition);
  3488. Assert.True (tv.IsDirty);
  3489. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  3490. Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}Thr", tv.Text);
  3491. Assert.Equal (3, tv.Lines);
  3492. Assert.Equal (new Point (3, 2), tv.CursorPosition);
  3493. Assert.True (tv.IsDirty);
  3494. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  3495. Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}Th", tv.Text);
  3496. Assert.Equal (3, tv.Lines);
  3497. Assert.Equal (new Point (2, 2), tv.CursorPosition);
  3498. Assert.True (tv.IsDirty);
  3499. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  3500. Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}T", tv.Text);
  3501. Assert.Equal (3, tv.Lines);
  3502. Assert.Equal (new Point (1, 2), tv.CursorPosition);
  3503. Assert.True (tv.IsDirty);
  3504. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  3505. Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}", tv.Text);
  3506. Assert.Equal (3, tv.Lines);
  3507. Assert.Equal (new Point (0, 2), tv.CursorPosition);
  3508. Assert.True (tv.IsDirty);
  3509. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  3510. Assert.Equal ($"One{Environment.NewLine}Two", tv.Text);
  3511. Assert.Equal (2, tv.Lines);
  3512. Assert.Equal (new Point (3, 1), tv.CursorPosition);
  3513. Assert.True (tv.IsDirty);
  3514. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  3515. Assert.Equal ($"One{Environment.NewLine}Tw", tv.Text);
  3516. Assert.Equal (2, tv.Lines);
  3517. Assert.Equal (new Point (2, 1), tv.CursorPosition);
  3518. Assert.True (tv.IsDirty);
  3519. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  3520. Assert.Equal ($"One{Environment.NewLine}T", tv.Text);
  3521. Assert.Equal (2, tv.Lines);
  3522. Assert.Equal (new Point (1, 1), tv.CursorPosition);
  3523. Assert.True (tv.IsDirty);
  3524. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  3525. Assert.Equal ($"One{Environment.NewLine}", tv.Text);
  3526. Assert.Equal (2, tv.Lines);
  3527. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  3528. Assert.True (tv.IsDirty);
  3529. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  3530. Assert.Equal ($"One", tv.Text);
  3531. Assert.Equal (1, tv.Lines);
  3532. Assert.Equal (new Point (3, 0), tv.CursorPosition);
  3533. Assert.True (tv.IsDirty);
  3534. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  3535. Assert.Equal ($"On", tv.Text);
  3536. Assert.Equal (1, tv.Lines);
  3537. Assert.Equal (new Point (2, 0), tv.CursorPosition);
  3538. Assert.True (tv.IsDirty);
  3539. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  3540. Assert.Equal ($"O", tv.Text);
  3541. Assert.Equal (1, tv.Lines);
  3542. Assert.Equal (new Point (1, 0), tv.CursorPosition);
  3543. Assert.True (tv.IsDirty);
  3544. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  3545. Assert.Equal ($"", tv.Text);
  3546. Assert.Equal (1, tv.Lines);
  3547. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  3548. Assert.False (tv.IsDirty);
  3549. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  3550. Assert.Equal ($"", tv.Text);
  3551. Assert.Equal (1, tv.Lines);
  3552. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  3553. Assert.False (tv.IsDirty);
  3554. // Redoing
  3555. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  3556. Assert.Equal ($"O", tv.Text);
  3557. Assert.Equal (1, tv.Lines);
  3558. Assert.Equal (new Point (1, 0), tv.CursorPosition);
  3559. Assert.True (tv.IsDirty);
  3560. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  3561. Assert.Equal ($"On", tv.Text);
  3562. Assert.Equal (1, tv.Lines);
  3563. Assert.Equal (new Point (2, 0), tv.CursorPosition);
  3564. Assert.True (tv.IsDirty);
  3565. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  3566. Assert.Equal ($"One", tv.Text);
  3567. Assert.Equal (1, tv.Lines);
  3568. Assert.Equal (new Point (3, 0), tv.CursorPosition);
  3569. Assert.True (tv.IsDirty);
  3570. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  3571. Assert.Equal ($"One{Environment.NewLine}", tv.Text);
  3572. Assert.Equal (2, tv.Lines);
  3573. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  3574. Assert.True (tv.IsDirty);
  3575. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  3576. Assert.Equal ($"One{Environment.NewLine}T", tv.Text);
  3577. Assert.Equal (2, tv.Lines);
  3578. Assert.Equal (new Point (1, 1), tv.CursorPosition);
  3579. Assert.True (tv.IsDirty);
  3580. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  3581. Assert.Equal ($"One{Environment.NewLine}Tw", tv.Text);
  3582. Assert.Equal (2, tv.Lines);
  3583. Assert.Equal (new Point (2, 1), tv.CursorPosition);
  3584. Assert.True (tv.IsDirty);
  3585. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  3586. Assert.Equal ($"One{Environment.NewLine}Two", tv.Text);
  3587. Assert.Equal (2, tv.Lines);
  3588. Assert.Equal (new Point (3, 1), tv.CursorPosition);
  3589. Assert.True (tv.IsDirty);
  3590. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  3591. Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}", tv.Text);
  3592. Assert.Equal (3, tv.Lines);
  3593. Assert.Equal (new Point (0, 2), tv.CursorPosition);
  3594. Assert.True (tv.IsDirty);
  3595. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  3596. Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}T", tv.Text);
  3597. Assert.Equal (3, tv.Lines);
  3598. Assert.Equal (new Point (1, 2), tv.CursorPosition);
  3599. Assert.True (tv.IsDirty);
  3600. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  3601. Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}Th", tv.Text);
  3602. Assert.Equal (3, tv.Lines);
  3603. Assert.Equal (new Point (2, 2), tv.CursorPosition);
  3604. Assert.True (tv.IsDirty);
  3605. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  3606. Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}Thr", tv.Text);
  3607. Assert.Equal (3, tv.Lines);
  3608. Assert.Equal (new Point (3, 2), tv.CursorPosition);
  3609. Assert.True (tv.IsDirty);
  3610. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  3611. Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}Thre", tv.Text);
  3612. Assert.Equal (3, tv.Lines);
  3613. Assert.Equal (new Point (4, 2), tv.CursorPosition);
  3614. Assert.True (tv.IsDirty);
  3615. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  3616. Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}Three", tv.Text);
  3617. Assert.Equal (3, tv.Lines);
  3618. Assert.Equal (new Point (5, 2), tv.CursorPosition);
  3619. Assert.True (tv.IsDirty);
  3620. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  3621. Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}Three{Environment.NewLine}", tv.Text);
  3622. Assert.Equal (4, tv.Lines);
  3623. Assert.Equal (new Point (0, 3), tv.CursorPosition);
  3624. Assert.True (tv.IsDirty);
  3625. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  3626. Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}Three{Environment.NewLine}", tv.Text);
  3627. Assert.Equal (4, tv.Lines);
  3628. Assert.Equal (new Point (0, 3), tv.CursorPosition);
  3629. Assert.True (tv.IsDirty);
  3630. }
  3631. [Fact]
  3632. [AutoInitShutdown]
  3633. public void HistoryText_Undo_Redo_Multi_Line_Selected_With_Empty_Text ()
  3634. {
  3635. var tv = new TextView () {
  3636. Width = 10,
  3637. Height = 2
  3638. };
  3639. var top = Application.Top;
  3640. top.Add (tv);
  3641. Application.Begin (top);
  3642. Assert.Equal ("", tv.Text);
  3643. Assert.Equal (1, tv.Lines);
  3644. Assert.Equal (Point.Empty, tv.CursorPosition);
  3645. Assert.False (tv.IsDirty);
  3646. Assert.True (tv.ProcessKey (new KeyEvent (Key.O, new KeyModifiers ())));
  3647. Assert.Equal ("O", tv.Text);
  3648. Assert.Equal (1, tv.Lines);
  3649. Assert.Equal (new Point (1, 0), tv.CursorPosition);
  3650. Assert.True (tv.IsDirty);
  3651. Assert.True (tv.ProcessKey (new KeyEvent (Key.n, new KeyModifiers ())));
  3652. Assert.Equal ("On", tv.Text);
  3653. Assert.Equal (1, tv.Lines);
  3654. Assert.Equal (new Point (2, 0), tv.CursorPosition);
  3655. Assert.True (tv.IsDirty);
  3656. Assert.True (tv.ProcessKey (new KeyEvent (Key.e, new KeyModifiers ())));
  3657. Assert.Equal ("One", tv.Text);
  3658. Assert.Equal (1, tv.Lines);
  3659. Assert.Equal (new Point (3, 0), tv.CursorPosition);
  3660. Assert.True (tv.IsDirty);
  3661. Assert.True (tv.ProcessKey (new KeyEvent (Key.Enter, new KeyModifiers ())));
  3662. Assert.Equal ($"One{Environment.NewLine}", tv.Text);
  3663. Assert.Equal (2, tv.Lines);
  3664. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  3665. Assert.True (tv.IsDirty);
  3666. Assert.True (tv.ProcessKey (new KeyEvent (Key.T, new KeyModifiers ())));
  3667. Assert.Equal ($"One{Environment.NewLine}T", tv.Text);
  3668. Assert.Equal (2, tv.Lines);
  3669. Assert.Equal (new Point (1, 1), tv.CursorPosition);
  3670. Assert.True (tv.IsDirty);
  3671. Assert.True (tv.ProcessKey (new KeyEvent (Key.w, new KeyModifiers ())));
  3672. Assert.Equal ($"One{Environment.NewLine}Tw", tv.Text);
  3673. Assert.Equal (2, tv.Lines);
  3674. Assert.Equal (new Point (2, 1), tv.CursorPosition);
  3675. Assert.True (tv.IsDirty);
  3676. Assert.True (tv.ProcessKey (new KeyEvent (Key.o, new KeyModifiers ())));
  3677. Assert.Equal ($"One{Environment.NewLine}Two", tv.Text);
  3678. Assert.Equal (2, tv.Lines);
  3679. Assert.Equal (new Point (3, 1), tv.CursorPosition);
  3680. Assert.True (tv.IsDirty);
  3681. Assert.True (tv.ProcessKey (new KeyEvent (Key.Enter, new KeyModifiers ())));
  3682. Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}", tv.Text);
  3683. Assert.Equal (3, tv.Lines);
  3684. Assert.Equal (new Point (0, 2), tv.CursorPosition);
  3685. Assert.True (tv.IsDirty);
  3686. Assert.True (tv.ProcessKey (new KeyEvent (Key.T, new KeyModifiers ())));
  3687. Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}T", tv.Text);
  3688. Assert.Equal (3, tv.Lines);
  3689. Assert.Equal (new Point (1, 2), tv.CursorPosition);
  3690. Assert.True (tv.IsDirty);
  3691. Assert.True (tv.ProcessKey (new KeyEvent (Key.h, new KeyModifiers ())));
  3692. Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}Th", tv.Text);
  3693. Assert.Equal (3, tv.Lines);
  3694. Assert.Equal (new Point (2, 2), tv.CursorPosition);
  3695. Assert.True (tv.IsDirty);
  3696. Assert.True (tv.ProcessKey (new KeyEvent (Key.r, new KeyModifiers ())));
  3697. Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}Thr", tv.Text);
  3698. Assert.Equal (3, tv.Lines);
  3699. Assert.Equal (new Point (3, 2), tv.CursorPosition);
  3700. Assert.True (tv.IsDirty);
  3701. Assert.True (tv.ProcessKey (new KeyEvent (Key.e, new KeyModifiers ())));
  3702. Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}Thre", tv.Text);
  3703. Assert.Equal (3, tv.Lines);
  3704. Assert.Equal (new Point (4, 2), tv.CursorPosition);
  3705. Assert.True (tv.IsDirty);
  3706. Assert.True (tv.ProcessKey (new KeyEvent (Key.e, new KeyModifiers ())));
  3707. Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}Three", tv.Text);
  3708. Assert.Equal (3, tv.Lines);
  3709. Assert.Equal (new Point (5, 2), tv.CursorPosition);
  3710. Assert.True (tv.IsDirty);
  3711. Assert.True (tv.ProcessKey (new KeyEvent (Key.Enter, new KeyModifiers ())));
  3712. Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}Three{Environment.NewLine}", tv.Text);
  3713. Assert.Equal (4, tv.Lines);
  3714. Assert.Equal (new Point (0, 3), tv.CursorPosition);
  3715. Assert.True (tv.IsDirty);
  3716. tv.SelectionStartColumn = 0;
  3717. tv.SelectionStartRow = 0;
  3718. tv.CursorPosition = new Point (0, 1);
  3719. Assert.Equal (3 + Environment.NewLine.Length, tv.SelectedLength);
  3720. Assert.True (tv.ProcessKey (new KeyEvent (Key.D1, new KeyModifiers ())));
  3721. Assert.Equal ($"1Two{Environment.NewLine}Three{Environment.NewLine}", tv.Text);
  3722. Assert.Equal (3, tv.Lines);
  3723. Assert.Equal (new Point (1, 0), tv.CursorPosition);
  3724. Assert.Equal (0, tv.SelectedLength);
  3725. Assert.True (tv.IsDirty);
  3726. tv.SelectionStartColumn = 1;
  3727. tv.SelectionStartRow = 0;
  3728. tv.CursorPosition = new Point (1, 1);
  3729. Assert.Equal (4 + Environment.NewLine.Length, tv.SelectedLength);
  3730. Assert.True (tv.ProcessKey (new KeyEvent (Key.D2, new KeyModifiers ())));
  3731. Assert.Equal ($"12hree{Environment.NewLine}", tv.Text);
  3732. Assert.Equal (2, tv.Lines);
  3733. Assert.Equal (new Point (2, 0), tv.CursorPosition);
  3734. Assert.Equal (0, tv.SelectedLength);
  3735. Assert.True (tv.IsDirty);
  3736. // Undoing
  3737. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  3738. Assert.Equal ($"1Two{Environment.NewLine}Three{Environment.NewLine}", tv.Text);
  3739. Assert.Equal (3, tv.Lines);
  3740. Assert.Equal (new Point (1, 1), tv.CursorPosition);
  3741. Assert.Equal (0, tv.SelectedLength);
  3742. Assert.True (tv.IsDirty);
  3743. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  3744. Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}Three{Environment.NewLine}", tv.Text);
  3745. Assert.Equal (4, tv.Lines);
  3746. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  3747. Assert.Equal (0, tv.SelectedLength);
  3748. Assert.True (tv.IsDirty);
  3749. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  3750. Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}Three", tv.Text);
  3751. Assert.Equal (3, tv.Lines);
  3752. Assert.Equal (new Point (5, 2), tv.CursorPosition);
  3753. Assert.Equal (0, tv.SelectedLength);
  3754. Assert.True (tv.IsDirty);
  3755. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  3756. Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}Thre", tv.Text);
  3757. Assert.Equal (3, tv.Lines);
  3758. Assert.Equal (new Point (4, 2), tv.CursorPosition);
  3759. Assert.True (tv.IsDirty);
  3760. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  3761. Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}Thr", tv.Text);
  3762. Assert.Equal (3, tv.Lines);
  3763. Assert.Equal (new Point (3, 2), tv.CursorPosition);
  3764. Assert.Equal (0, tv.SelectedLength);
  3765. Assert.True (tv.IsDirty);
  3766. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  3767. Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}Th", tv.Text);
  3768. Assert.Equal (3, tv.Lines);
  3769. Assert.Equal (new Point (2, 2), tv.CursorPosition);
  3770. Assert.Equal (0, tv.SelectedLength);
  3771. Assert.True (tv.IsDirty);
  3772. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  3773. Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}T", tv.Text);
  3774. Assert.Equal (3, tv.Lines);
  3775. Assert.Equal (new Point (1, 2), tv.CursorPosition);
  3776. Assert.Equal (0, tv.SelectedLength);
  3777. Assert.True (tv.IsDirty);
  3778. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  3779. Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}", tv.Text);
  3780. Assert.Equal (3, tv.Lines);
  3781. Assert.Equal (new Point (0, 2), tv.CursorPosition);
  3782. Assert.Equal (0, tv.SelectedLength);
  3783. Assert.True (tv.IsDirty);
  3784. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  3785. Assert.Equal ($"One{Environment.NewLine}Two", tv.Text);
  3786. Assert.Equal (2, tv.Lines);
  3787. Assert.Equal (new Point (3, 1), tv.CursorPosition);
  3788. Assert.Equal (0, tv.SelectedLength);
  3789. Assert.True (tv.IsDirty);
  3790. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  3791. Assert.Equal ($"One{Environment.NewLine}Tw", tv.Text);
  3792. Assert.Equal (2, tv.Lines);
  3793. Assert.Equal (new Point (2, 1), tv.CursorPosition);
  3794. Assert.Equal (0, tv.SelectedLength);
  3795. Assert.True (tv.IsDirty);
  3796. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  3797. Assert.Equal ($"One{Environment.NewLine}T", tv.Text);
  3798. Assert.Equal (2, tv.Lines);
  3799. Assert.Equal (new Point (1, 1), tv.CursorPosition);
  3800. Assert.Equal (0, tv.SelectedLength);
  3801. Assert.True (tv.IsDirty);
  3802. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  3803. Assert.Equal ($"One{Environment.NewLine}", tv.Text);
  3804. Assert.Equal (2, tv.Lines);
  3805. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  3806. Assert.Equal (0, tv.SelectedLength);
  3807. Assert.True (tv.IsDirty);
  3808. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  3809. Assert.Equal ($"One", tv.Text);
  3810. Assert.Equal (1, tv.Lines);
  3811. Assert.Equal (new Point (3, 0), tv.CursorPosition);
  3812. Assert.Equal (0, tv.SelectedLength);
  3813. Assert.True (tv.IsDirty);
  3814. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  3815. Assert.Equal ($"On", tv.Text);
  3816. Assert.Equal (1, tv.Lines);
  3817. Assert.Equal (new Point (2, 0), tv.CursorPosition);
  3818. Assert.Equal (0, tv.SelectedLength);
  3819. Assert.True (tv.IsDirty);
  3820. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  3821. Assert.Equal ($"O", tv.Text);
  3822. Assert.Equal (1, tv.Lines);
  3823. Assert.Equal (new Point (1, 0), tv.CursorPosition);
  3824. Assert.Equal (0, tv.SelectedLength);
  3825. Assert.True (tv.IsDirty);
  3826. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  3827. Assert.Equal ($"", tv.Text);
  3828. Assert.Equal (1, tv.Lines);
  3829. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  3830. Assert.Equal (0, tv.SelectedLength);
  3831. Assert.False (tv.IsDirty);
  3832. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  3833. Assert.Equal ($"", tv.Text);
  3834. Assert.Equal (1, tv.Lines);
  3835. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  3836. Assert.Equal (0, tv.SelectedLength);
  3837. Assert.False (tv.IsDirty);
  3838. // Redoing
  3839. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  3840. Assert.Equal ($"O", tv.Text);
  3841. Assert.Equal (1, tv.Lines);
  3842. Assert.Equal (new Point (1, 0), tv.CursorPosition);
  3843. Assert.Equal (0, tv.SelectedLength);
  3844. Assert.True (tv.IsDirty);
  3845. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  3846. Assert.Equal ($"On", tv.Text);
  3847. Assert.Equal (1, tv.Lines);
  3848. Assert.Equal (new Point (2, 0), tv.CursorPosition);
  3849. Assert.Equal (0, tv.SelectedLength);
  3850. Assert.True (tv.IsDirty);
  3851. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  3852. Assert.Equal ($"One", tv.Text);
  3853. Assert.Equal (1, tv.Lines);
  3854. Assert.Equal (new Point (3, 0), tv.CursorPosition);
  3855. Assert.Equal (0, tv.SelectedLength);
  3856. Assert.True (tv.IsDirty);
  3857. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  3858. Assert.Equal ($"One{Environment.NewLine}", tv.Text);
  3859. Assert.Equal (2, tv.Lines);
  3860. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  3861. Assert.Equal (0, tv.SelectedLength);
  3862. Assert.True (tv.IsDirty);
  3863. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  3864. Assert.Equal ($"One{Environment.NewLine}T", tv.Text);
  3865. Assert.Equal (2, tv.Lines);
  3866. Assert.Equal (new Point (1, 1), tv.CursorPosition);
  3867. Assert.Equal (0, tv.SelectedLength);
  3868. Assert.True (tv.IsDirty);
  3869. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  3870. Assert.Equal ($"One{Environment.NewLine}Tw", tv.Text);
  3871. Assert.Equal (2, tv.Lines);
  3872. Assert.Equal (new Point (2, 1), tv.CursorPosition);
  3873. Assert.Equal (0, tv.SelectedLength);
  3874. Assert.True (tv.IsDirty);
  3875. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  3876. Assert.Equal ($"One{Environment.NewLine}Two", tv.Text);
  3877. Assert.Equal (2, tv.Lines);
  3878. Assert.Equal (new Point (3, 1), tv.CursorPosition);
  3879. Assert.Equal (0, tv.SelectedLength);
  3880. Assert.True (tv.IsDirty);
  3881. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  3882. Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}", tv.Text);
  3883. Assert.Equal (3, tv.Lines);
  3884. Assert.Equal (new Point (0, 2), tv.CursorPosition);
  3885. Assert.Equal (0, tv.SelectedLength);
  3886. Assert.True (tv.IsDirty);
  3887. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  3888. Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}T", tv.Text);
  3889. Assert.Equal (3, tv.Lines);
  3890. Assert.Equal (new Point (1, 2), tv.CursorPosition);
  3891. Assert.Equal (0, tv.SelectedLength);
  3892. Assert.True (tv.IsDirty);
  3893. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  3894. Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}Th", tv.Text);
  3895. Assert.Equal (3, tv.Lines);
  3896. Assert.Equal (new Point (2, 2), tv.CursorPosition);
  3897. Assert.Equal (0, tv.SelectedLength);
  3898. Assert.True (tv.IsDirty);
  3899. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  3900. Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}Thr", tv.Text);
  3901. Assert.Equal (3, tv.Lines);
  3902. Assert.Equal (new Point (3, 2), tv.CursorPosition);
  3903. Assert.Equal (0, tv.SelectedLength);
  3904. Assert.True (tv.IsDirty);
  3905. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  3906. Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}Thre", tv.Text);
  3907. Assert.Equal (3, tv.Lines);
  3908. Assert.Equal (new Point (4, 2), tv.CursorPosition);
  3909. Assert.Equal (0, tv.SelectedLength);
  3910. Assert.True (tv.IsDirty);
  3911. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  3912. Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}Three", tv.Text);
  3913. Assert.Equal (3, tv.Lines);
  3914. Assert.Equal (new Point (5, 2), tv.CursorPosition);
  3915. Assert.Equal (0, tv.SelectedLength);
  3916. Assert.True (tv.IsDirty);
  3917. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  3918. Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}Three{Environment.NewLine}", tv.Text);
  3919. Assert.Equal (4, tv.Lines);
  3920. Assert.Equal (new Point (0, 3), tv.CursorPosition);
  3921. Assert.Equal (0, tv.SelectedLength);
  3922. Assert.True (tv.IsDirty);
  3923. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  3924. Assert.Equal ($"1Two{Environment.NewLine}Three{Environment.NewLine}", tv.Text);
  3925. Assert.Equal (3, tv.Lines);
  3926. Assert.Equal (new Point (1, 0), tv.CursorPosition);
  3927. Assert.Equal (0, tv.SelectedLength);
  3928. Assert.True (tv.IsDirty);
  3929. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  3930. Assert.Equal ($"12hree{Environment.NewLine}", tv.Text);
  3931. Assert.Equal (2, tv.Lines);
  3932. Assert.Equal (new Point (2, 0), tv.CursorPosition);
  3933. Assert.Equal (0, tv.SelectedLength);
  3934. Assert.True (tv.IsDirty);
  3935. }
  3936. [Fact]
  3937. [AutoInitShutdown]
  3938. public void HistoryText_Undo_Redo_Multi_Line_Selected_InsertText_Twice_On_Same_Line ()
  3939. {
  3940. var text = "One\nTwo\nThree";
  3941. var tv = new TextView () {
  3942. Width = 10,
  3943. Height = 2,
  3944. Text = text
  3945. };
  3946. var top = Application.Top;
  3947. top.Add (tv);
  3948. Application.Begin (top);
  3949. Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}Three", tv.Text);
  3950. Assert.Equal (3, tv.Lines);
  3951. Assert.Equal (Point.Empty, tv.CursorPosition);
  3952. Assert.False (tv.IsDirty);
  3953. tv.SelectionStartColumn = 0;
  3954. tv.SelectionStartRow = 0;
  3955. tv.CursorPosition = new Point (0, 1);
  3956. Assert.Equal (3 + Environment.NewLine.Length, tv.SelectedLength);
  3957. Assert.True (tv.ProcessKey (new KeyEvent (Key.D1, new KeyModifiers ())));
  3958. Assert.Equal ($"1Two{Environment.NewLine}Three", tv.Text);
  3959. Assert.Equal (new Point (1, 0), tv.CursorPosition);
  3960. Assert.Equal (0, tv.SelectedLength);
  3961. Assert.True (tv.IsDirty);
  3962. tv.SelectionStartColumn = 1;
  3963. tv.SelectionStartRow = 0;
  3964. tv.CursorPosition = new Point (1, 1);
  3965. Assert.Equal (4 + Environment.NewLine.Length, tv.SelectedLength);
  3966. Assert.True (tv.ProcessKey (new KeyEvent (Key.D2, new KeyModifiers ())));
  3967. Assert.Equal ("12hree", tv.Text);
  3968. Assert.Equal (new Point (2, 0), tv.CursorPosition);
  3969. Assert.Equal (0, tv.SelectedLength);
  3970. Assert.True (tv.IsDirty);
  3971. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  3972. Assert.Equal ($"1Two{Environment.NewLine}Three", tv.Text);
  3973. Assert.Equal (new Point (1, 1), tv.CursorPosition);
  3974. Assert.Equal (0, tv.SelectedLength);
  3975. Assert.True (tv.IsDirty);
  3976. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  3977. Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}Three", tv.Text);
  3978. Assert.Equal (3, tv.Lines);
  3979. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  3980. Assert.Equal (0, tv.SelectedLength);
  3981. Assert.False (tv.IsDirty);
  3982. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  3983. Assert.Equal ($"1Two{Environment.NewLine}Three", tv.Text);
  3984. Assert.Equal (new Point (1, 0), tv.CursorPosition);
  3985. Assert.Equal (0, tv.SelectedLength);
  3986. Assert.True (tv.IsDirty);
  3987. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  3988. Assert.Equal ("12hree", tv.Text);
  3989. Assert.Equal (new Point (2, 0), tv.CursorPosition);
  3990. Assert.Equal (0, tv.SelectedLength);
  3991. Assert.True (tv.IsDirty);
  3992. }
  3993. [Fact]
  3994. [AutoInitShutdown]
  3995. public void HistoryText_Undo_Redo_Multi_Line_Selected_InsertText_Twice_On_Same_Line_With_End_Line ()
  3996. {
  3997. var text = "One\nTwo\nThree\n";
  3998. var tv = new TextView () {
  3999. Width = 10,
  4000. Height = 2,
  4001. Text = text
  4002. };
  4003. var top = Application.Top;
  4004. top.Add (tv);
  4005. Application.Begin (top);
  4006. Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}Three{Environment.NewLine}", tv.Text);
  4007. Assert.Equal (4, tv.Lines);
  4008. Assert.Equal (Point.Empty, tv.CursorPosition);
  4009. Assert.False (tv.IsDirty);
  4010. tv.SelectionStartColumn = 0;
  4011. tv.SelectionStartRow = 0;
  4012. tv.CursorPosition = new Point (0, 1);
  4013. Assert.Equal (3 + Environment.NewLine.Length, tv.SelectedLength);
  4014. Assert.True (tv.ProcessKey (new KeyEvent (Key.D1, new KeyModifiers ())));
  4015. Assert.Equal ($"1Two{Environment.NewLine}Three{Environment.NewLine}", tv.Text);
  4016. Assert.Equal (new Point (1, 0), tv.CursorPosition);
  4017. Assert.Equal (0, tv.SelectedLength);
  4018. Assert.True (tv.IsDirty);
  4019. tv.SelectionStartColumn = 1;
  4020. tv.SelectionStartRow = 0;
  4021. tv.CursorPosition = new Point (1, 1);
  4022. Assert.Equal (4 + Environment.NewLine.Length, tv.SelectedLength);
  4023. Assert.True (tv.ProcessKey (new KeyEvent (Key.D2, new KeyModifiers ())));
  4024. Assert.Equal ($"12hree{Environment.NewLine}", tv.Text);
  4025. Assert.Equal (new Point (2, 0), tv.CursorPosition);
  4026. Assert.Equal (0, tv.SelectedLength);
  4027. Assert.True (tv.IsDirty);
  4028. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  4029. Assert.Equal ($"1Two{Environment.NewLine}Three{Environment.NewLine}", tv.Text);
  4030. Assert.Equal (new Point (1, 1), tv.CursorPosition);
  4031. Assert.Equal (0, tv.SelectedLength);
  4032. Assert.True (tv.IsDirty);
  4033. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  4034. Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}Three{Environment.NewLine}", tv.Text);
  4035. Assert.Equal (4, tv.Lines);
  4036. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  4037. Assert.Equal (0, tv.SelectedLength);
  4038. Assert.False (tv.IsDirty);
  4039. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  4040. Assert.Equal ($"1Two{Environment.NewLine}Three{Environment.NewLine}", tv.Text);
  4041. Assert.Equal (new Point (1, 0), tv.CursorPosition);
  4042. Assert.Equal (0, tv.SelectedLength);
  4043. Assert.True (tv.IsDirty);
  4044. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  4045. Assert.Equal ($"12hree{Environment.NewLine}", tv.Text);
  4046. Assert.Equal (new Point (2, 0), tv.CursorPosition);
  4047. Assert.Equal (0, tv.SelectedLength);
  4048. Assert.True (tv.IsDirty);
  4049. }
  4050. [Fact]
  4051. public void HistoryText_IsDirty_HasHistoryChanges ()
  4052. {
  4053. var tv = new TextView ();
  4054. Assert.Equal ("", tv.Text);
  4055. Assert.Equal (1, tv.Lines);
  4056. Assert.Equal (Point.Empty, tv.CursorPosition);
  4057. Assert.False (tv.IsDirty);
  4058. Assert.False (tv.HasHistoryChanges);
  4059. Assert.True (tv.ProcessKey (new KeyEvent (Key.D1, new KeyModifiers ())));
  4060. Assert.Equal ("1", tv.Text);
  4061. Assert.Equal (1, tv.Lines);
  4062. Assert.Equal (new Point (1, 0), tv.CursorPosition);
  4063. Assert.True (tv.IsDirty);
  4064. Assert.True (tv.HasHistoryChanges);
  4065. Assert.True (tv.ProcessKey (new KeyEvent (Key.Enter, new KeyModifiers ())));
  4066. Assert.Equal ($"1{Environment.NewLine}", tv.Text);
  4067. Assert.Equal (2, tv.Lines);
  4068. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  4069. Assert.True (tv.IsDirty);
  4070. Assert.True (tv.HasHistoryChanges);
  4071. Assert.True (tv.ProcessKey (new KeyEvent (Key.D2, new KeyModifiers ())));
  4072. Assert.Equal ($"1{Environment.NewLine}2", tv.Text);
  4073. Assert.Equal (2, tv.Lines);
  4074. Assert.Equal (new Point (1, 1), tv.CursorPosition);
  4075. Assert.True (tv.IsDirty);
  4076. Assert.True (tv.HasHistoryChanges);
  4077. Assert.True (tv.ProcessKey (new KeyEvent (Key.Backspace, new KeyModifiers ())));
  4078. Assert.Equal ($"1{Environment.NewLine}", tv.Text);
  4079. Assert.Equal (2, tv.Lines);
  4080. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  4081. Assert.True (tv.IsDirty);
  4082. Assert.True (tv.HasHistoryChanges);
  4083. Assert.True (tv.ProcessKey (new KeyEvent (Key.Backspace, new KeyModifiers ())));
  4084. Assert.Equal ($"1", tv.Text);
  4085. Assert.Equal (1, tv.Lines);
  4086. Assert.Equal (new Point (1, 0), tv.CursorPosition);
  4087. Assert.True (tv.IsDirty);
  4088. Assert.True (tv.HasHistoryChanges);
  4089. Assert.True (tv.ProcessKey (new KeyEvent (Key.Backspace, new KeyModifiers ())));
  4090. Assert.Equal ($"", tv.Text);
  4091. Assert.Equal (1, tv.Lines);
  4092. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  4093. // IsDirty cannot be based on HasHistoryChanges because HasHistoryChanges is greater than 0
  4094. // The only way is comparing from the original text
  4095. Assert.False (tv.IsDirty);
  4096. // Still true because HasHistoryChanges is greater than 0
  4097. Assert.True (tv.HasHistoryChanges);
  4098. }
  4099. [Fact]
  4100. public void HistoryText_Undo_Redo_Multi_Line_Selected_DeleteCharLeft_All ()
  4101. {
  4102. var text = "This is the first line.\nThis is the second line.\nThis is the third line.";
  4103. var tv = new TextView () { Text = text };
  4104. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  4105. Assert.Equal (3, tv.Lines);
  4106. Assert.Equal (Point.Empty, tv.CursorPosition);
  4107. Assert.False (tv.IsDirty);
  4108. Assert.False (tv.HasHistoryChanges);
  4109. Assert.True (tv.ProcessKey (new KeyEvent (Key.End | Key.CtrlMask | Key.ShiftMask, new KeyModifiers ())));
  4110. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  4111. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.SelectedText);
  4112. Assert.Equal (3, tv.Lines);
  4113. Assert.Equal (new Point (23, 2), tv.CursorPosition);
  4114. Assert.Equal (70 + Environment.NewLine.Length * 2, tv.SelectedLength);
  4115. Assert.False (tv.IsDirty);
  4116. Assert.False (tv.HasHistoryChanges);
  4117. Assert.True (tv.ProcessKey (new KeyEvent (Key.Backspace, new KeyModifiers ())));
  4118. Assert.Equal ("", tv.Text);
  4119. Assert.Equal ("", tv.SelectedText);
  4120. Assert.Equal (1, tv.Lines);
  4121. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  4122. Assert.Equal (0, tv.SelectedLength);
  4123. Assert.True (tv.IsDirty);
  4124. Assert.True (tv.HasHistoryChanges);
  4125. // Undo
  4126. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  4127. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  4128. Assert.Equal ("", tv.SelectedText);
  4129. Assert.Equal (3, tv.Lines);
  4130. Assert.Equal (new Point (23, 2), tv.CursorPosition);
  4131. Assert.Equal (0, tv.SelectedLength);
  4132. Assert.False (tv.IsDirty);
  4133. Assert.True (tv.HasHistoryChanges);
  4134. // Redo
  4135. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  4136. Assert.Equal ("", tv.Text);
  4137. Assert.Equal ("", tv.SelectedText);
  4138. Assert.Equal (1, tv.Lines);
  4139. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  4140. Assert.Equal (0, tv.SelectedLength);
  4141. Assert.True (tv.IsDirty);
  4142. Assert.True (tv.HasHistoryChanges);
  4143. }
  4144. [Fact]
  4145. public void HistoryText_Undo_Redo_Multi_Line_Selected_DeleteCharRight_All ()
  4146. {
  4147. var text = "This is the first line.\nThis is the second line.\nThis is the third line.";
  4148. var tv = new TextView () { Text = text };
  4149. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  4150. Assert.Equal (3, tv.Lines);
  4151. Assert.Equal (Point.Empty, tv.CursorPosition);
  4152. Assert.False (tv.IsDirty);
  4153. Assert.False (tv.HasHistoryChanges);
  4154. Assert.True (tv.ProcessKey (new KeyEvent (Key.End | Key.CtrlMask | Key.ShiftMask, new KeyModifiers ())));
  4155. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  4156. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.SelectedText);
  4157. Assert.Equal (3, tv.Lines);
  4158. Assert.Equal (new Point (23, 2), tv.CursorPosition);
  4159. Assert.Equal (70 + Environment.NewLine.Length * 2, tv.SelectedLength);
  4160. Assert.False (tv.IsDirty);
  4161. Assert.False (tv.HasHistoryChanges);
  4162. Assert.True (tv.ProcessKey (new KeyEvent (Key.DeleteChar, new KeyModifiers ())));
  4163. Assert.Equal ("", tv.Text);
  4164. Assert.Equal ("", tv.SelectedText);
  4165. Assert.Equal (1, tv.Lines);
  4166. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  4167. Assert.Equal (0, tv.SelectedLength);
  4168. Assert.True (tv.IsDirty);
  4169. Assert.True (tv.HasHistoryChanges);
  4170. // Undo
  4171. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  4172. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  4173. Assert.Equal ("", tv.SelectedText);
  4174. Assert.Equal (3, tv.Lines);
  4175. Assert.Equal (new Point (23, 2), tv.CursorPosition);
  4176. Assert.Equal (0, tv.SelectedLength);
  4177. Assert.False (tv.IsDirty);
  4178. Assert.True (tv.HasHistoryChanges);
  4179. // Redo
  4180. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  4181. Assert.Equal ("", tv.Text);
  4182. Assert.Equal ("", tv.SelectedText);
  4183. Assert.Equal (1, tv.Lines);
  4184. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  4185. Assert.Equal (0, tv.SelectedLength);
  4186. Assert.True (tv.IsDirty);
  4187. Assert.True (tv.HasHistoryChanges);
  4188. }
  4189. [Fact]
  4190. [AutoInitShutdown]
  4191. public void HistoryText_Undo_Redo_Copy_Without_Selection_Multi_Line_Paste ()
  4192. {
  4193. var text = "This is the first line.\nThis is the second line.\nThis is the third line.";
  4194. var tv = new TextView () { Text = text };
  4195. tv.CursorPosition = new Point (23, 0);
  4196. Assert.True (tv.ProcessKey (new KeyEvent (Key.C | Key.CtrlMask, new KeyModifiers ())));
  4197. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  4198. Assert.Equal ("", tv.SelectedText);
  4199. Assert.Equal ("This is the first line.", Clipboard.Contents);
  4200. Assert.Equal (3, tv.Lines);
  4201. Assert.Equal (new Point (23, 0), tv.CursorPosition);
  4202. Assert.True (tv.ProcessKey (new KeyEvent (Key.Y | Key.CtrlMask, new KeyModifiers ())));
  4203. 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);
  4204. Assert.Equal (4, tv.Lines);
  4205. Assert.Equal (new Point (23, 1), tv.CursorPosition);
  4206. // Undo
  4207. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  4208. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  4209. Assert.Equal (3, tv.Lines);
  4210. Assert.Equal (new Point (23, 0), tv.CursorPosition);
  4211. // Redo
  4212. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  4213. 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);
  4214. Assert.Equal (4, tv.Lines);
  4215. Assert.Equal (new Point (23, 1), tv.CursorPosition);
  4216. }
  4217. [Fact]
  4218. [AutoInitShutdown]
  4219. public void HistoryText_Undo_Redo_Simple_Copy_Multi_Line_Selected_Paste ()
  4220. {
  4221. var text = "This is the first line.\nThis is the second line.\nThis is the third line.";
  4222. var tv = new TextView () { Text = text };
  4223. tv.SelectionStartColumn = 12;
  4224. tv.CursorPosition = new Point (17, 0);
  4225. Assert.True (tv.ProcessKey (new KeyEvent (Key.C | Key.CtrlMask, new KeyModifiers ())));
  4226. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  4227. Assert.Equal ("first", tv.SelectedText);
  4228. Assert.Equal (3, tv.Lines);
  4229. Assert.Equal (new Point (17, 0), tv.CursorPosition);
  4230. tv.SelectionStartColumn = 12;
  4231. tv.CursorPosition = new Point (11, 1);
  4232. Assert.True (tv.ProcessKey (new KeyEvent (Key.Y | Key.CtrlMask, new KeyModifiers ())));
  4233. Assert.Equal ($"This is the first second line.{Environment.NewLine}This is the third line.", tv.Text);
  4234. Assert.Equal (2, tv.Lines);
  4235. Assert.Equal (new Point (17, 0), tv.CursorPosition);
  4236. // Undo
  4237. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  4238. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  4239. Assert.Equal (3, tv.Lines);
  4240. Assert.Equal (new Point (12, 0), tv.CursorPosition);
  4241. // Redo
  4242. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  4243. Assert.Equal ($"This is the first second line.{Environment.NewLine}This is the third line.", tv.Text);
  4244. Assert.Equal (2, tv.Lines);
  4245. Assert.Equal (new Point (17, 0), tv.CursorPosition);
  4246. }
  4247. [Fact]
  4248. [AutoInitShutdown]
  4249. public void HistoryText_Undo_Redo_Multi_Line_Selected_Copy_Simple_Paste_Starting_On_Space ()
  4250. {
  4251. var text = "This is the first line.\nThis is the second line.\nThis is the third line.";
  4252. var tv = new TextView () { Text = text };
  4253. tv.SelectionStartColumn = 12;
  4254. tv.CursorPosition = new Point (18, 1);
  4255. Assert.True (tv.ProcessKey (new KeyEvent (Key.C | Key.CtrlMask, new KeyModifiers ())));
  4256. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  4257. Assert.Equal ($"first line.{Environment.NewLine}This is the second", tv.SelectedText);
  4258. Assert.Equal (3, tv.Lines);
  4259. Assert.Equal (new Point (18, 1), tv.CursorPosition);
  4260. tv.Selecting = false;
  4261. Assert.True (tv.ProcessKey (new KeyEvent (Key.Y | Key.CtrlMask, new KeyModifiers ())));
  4262. 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);
  4263. Assert.Equal (4, tv.Lines);
  4264. Assert.Equal (new Point (18, 2), tv.CursorPosition);
  4265. // Undo
  4266. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  4267. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  4268. Assert.Equal (3, tv.Lines);
  4269. Assert.Equal (new Point (18, 1), tv.CursorPosition);
  4270. // Redo
  4271. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  4272. 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);
  4273. Assert.Equal (4, tv.Lines);
  4274. Assert.Equal (new Point (18, 2), tv.CursorPosition);
  4275. }
  4276. [Fact]
  4277. [AutoInitShutdown]
  4278. public void HistoryText_Undo_Redo_Multi_Line_Selected_Copy_Simple_Paste_Starting_On_Letter ()
  4279. {
  4280. var text = "This is the first line.\nThis is the second line.\nThis is the third line.";
  4281. var tv = new TextView () { Text = text };
  4282. tv.SelectionStartColumn = 12;
  4283. tv.CursorPosition = new Point (18, 1);
  4284. Assert.True (tv.ProcessKey (new KeyEvent (Key.C | Key.CtrlMask, new KeyModifiers ())));
  4285. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  4286. Assert.Equal ($"first line.{Environment.NewLine}This is the second", tv.SelectedText);
  4287. Assert.Equal (3, tv.Lines);
  4288. Assert.Equal (new Point (18, 1), tv.CursorPosition);
  4289. tv.Selecting = false;
  4290. tv.CursorPosition = new Point (17, 1);
  4291. Assert.True (tv.ProcessKey (new KeyEvent (Key.Y | Key.CtrlMask, new KeyModifiers ())));
  4292. 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);
  4293. Assert.Equal (4, tv.Lines);
  4294. Assert.Equal (new Point (18, 2), tv.CursorPosition);
  4295. // Undo
  4296. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  4297. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  4298. Assert.Equal (3, tv.Lines);
  4299. Assert.Equal (new Point (17, 1), tv.CursorPosition);
  4300. // Redo
  4301. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  4302. 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);
  4303. Assert.Equal (4, tv.Lines);
  4304. Assert.Equal (new Point (18, 2), tv.CursorPosition);
  4305. }
  4306. [Fact]
  4307. [AutoInitShutdown]
  4308. public void HistoryText_Undo_Redo_Empty_Copy_Without_Selection_Multi_Line_Selected_Paste ()
  4309. {
  4310. var text = "\nThis is the first line.\nThis is the second line.";
  4311. var tv = new TextView () { Text = text };
  4312. Assert.True (tv.ProcessKey (new KeyEvent (Key.C | Key.CtrlMask, new KeyModifiers ())));
  4313. Assert.Equal ($"{Environment.NewLine}This is the first line.{Environment.NewLine}This is the second line.", tv.Text);
  4314. Assert.Equal ("", tv.SelectedText);
  4315. Assert.Equal (3, tv.Lines);
  4316. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  4317. Assert.True (tv.ProcessKey (new KeyEvent (Key.Y | Key.CtrlMask, new KeyModifiers ())));
  4318. Assert.Equal ($"{Environment.NewLine}{Environment.NewLine}This is the first line.{Environment.NewLine}This is the second line.", tv.Text);
  4319. Assert.Equal (4, tv.Lines);
  4320. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  4321. // Undo
  4322. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  4323. Assert.Equal ($"{Environment.NewLine}This is the first line.{Environment.NewLine}This is the second line.", tv.Text);
  4324. Assert.Equal (3, tv.Lines);
  4325. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  4326. // Redo
  4327. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  4328. Assert.Equal ($"{Environment.NewLine}{Environment.NewLine}This is the first line.{Environment.NewLine}This is the second line.", tv.Text);
  4329. Assert.Equal (4, tv.Lines);
  4330. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  4331. }
  4332. [Fact]
  4333. [AutoInitShutdown]
  4334. public void HistoryText_Undo_Redo_Setting_Clipboard_Multi_Line_Selected_Paste ()
  4335. {
  4336. var text = "This is the first line.\nThis is the second line.";
  4337. var tv = new TextView () { Text = text };
  4338. Clipboard.Contents = "Inserted\nNewLine";
  4339. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.", tv.Text);
  4340. Assert.Equal ("", tv.SelectedText);
  4341. Assert.Equal (2, tv.Lines);
  4342. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  4343. Assert.True (tv.ProcessKey (new KeyEvent (Key.Y | Key.CtrlMask, new KeyModifiers ())));
  4344. Assert.Equal ($"Inserted{Environment.NewLine}NewLineThis is the first line.{Environment.NewLine}This is the second line.", tv.Text);
  4345. Assert.Equal (3, tv.Lines);
  4346. Assert.Equal (new Point (7, 1), tv.CursorPosition);
  4347. // Undo
  4348. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  4349. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.", tv.Text);
  4350. Assert.Equal (2, tv.Lines);
  4351. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  4352. // Redo
  4353. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  4354. Assert.Equal ($"Inserted{Environment.NewLine}NewLineThis is the first line.{Environment.NewLine}This is the second line.", tv.Text);
  4355. Assert.Equal (3, tv.Lines);
  4356. Assert.Equal (new Point (7, 1), tv.CursorPosition);
  4357. }
  4358. [Fact]
  4359. [AutoInitShutdown]
  4360. public void HistoryText_Undo_Redo_Cut_Multi_Line_Selected_Paste ()
  4361. {
  4362. var text = "This is the first line.\nThis is the second line.\nThis is the third line.";
  4363. var tv = new TextView () { Text = text };
  4364. tv.SelectionStartColumn = 12;
  4365. tv.CursorPosition = new Point (17, 0);
  4366. Assert.True (tv.ProcessKey (new KeyEvent (Key.W | Key.CtrlMask, new KeyModifiers ())));
  4367. Assert.Equal ($"This is the line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  4368. Assert.Equal ("", tv.SelectedText);
  4369. Assert.Equal (3, tv.Lines);
  4370. Assert.Equal (new Point (12, 0), tv.CursorPosition);
  4371. tv.SelectionStartColumn = 12;
  4372. tv.CursorPosition = new Point (11, 1);
  4373. Assert.True (tv.ProcessKey (new KeyEvent (Key.Y | Key.CtrlMask, new KeyModifiers ())));
  4374. Assert.Equal ($"This is the first second line.{Environment.NewLine}This is the third line.", tv.Text);
  4375. Assert.Equal (2, tv.Lines);
  4376. Assert.Equal (new Point (17, 0), tv.CursorPosition);
  4377. // Undo
  4378. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  4379. Assert.Equal ($"This is the line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  4380. Assert.Equal (3, tv.Lines);
  4381. Assert.Equal (new Point (12, 0), tv.CursorPosition);
  4382. // Redo
  4383. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  4384. Assert.Equal ($"This is the first second line.{Environment.NewLine}This is the third line.", tv.Text);
  4385. Assert.Equal (2, tv.Lines);
  4386. Assert.Equal (new Point (17, 0), tv.CursorPosition);
  4387. }
  4388. [Fact]
  4389. [AutoInitShutdown]
  4390. public void HistoryText_Undo_Redo_Cut_Simple_Paste_Starting ()
  4391. {
  4392. var text = "This is the first line.\nThis is the second line.\nThis is the third line.";
  4393. var tv = new TextView () { Text = text };
  4394. tv.SelectionStartColumn = 12;
  4395. tv.CursorPosition = new Point (18, 1);
  4396. Assert.True (tv.ProcessKey (new KeyEvent (Key.W | Key.CtrlMask, new KeyModifiers ())));
  4397. Assert.Equal ($"This is the line.{Environment.NewLine}This is the third line.", tv.Text);
  4398. Assert.Equal ("", tv.SelectedText);
  4399. Assert.Equal (2, tv.Lines);
  4400. Assert.Equal (new Point (12, 0), tv.CursorPosition);
  4401. tv.Selecting = false;
  4402. Assert.True (tv.ProcessKey (new KeyEvent (Key.Y | Key.CtrlMask, new KeyModifiers ())));
  4403. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  4404. Assert.Equal (3, tv.Lines);
  4405. Assert.Equal (new Point (18, 1), tv.CursorPosition);
  4406. // Undo
  4407. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  4408. Assert.Equal ($"This is the line.{Environment.NewLine}This is the third line.", tv.Text);
  4409. Assert.Equal (2, tv.Lines);
  4410. Assert.Equal (new Point (12, 0), tv.CursorPosition);
  4411. // Redo
  4412. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  4413. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  4414. Assert.Equal (3, tv.Lines);
  4415. Assert.Equal (new Point (18, 1), tv.CursorPosition);
  4416. }
  4417. [Fact]
  4418. [AutoInitShutdown]
  4419. public void HistoryText_Undo_Redo_Cut_Multi_Line_Another_Selected_Paste ()
  4420. {
  4421. var text = "This is the first line.\nThis is the second line.\nThis is the third line.";
  4422. var tv = new TextView () { Text = text };
  4423. tv.SelectionStartColumn = 12;
  4424. tv.CursorPosition = new Point (17, 0);
  4425. Assert.True (tv.ProcessKey (new KeyEvent (Key.W | Key.CtrlMask, new KeyModifiers ())));
  4426. Assert.Equal ($"This is the line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  4427. Assert.Equal ("", tv.SelectedText);
  4428. Assert.Equal (3, tv.Lines);
  4429. Assert.Equal (new Point (12, 0), tv.CursorPosition);
  4430. tv.SelectionStartColumn = 12;
  4431. tv.SelectionStartRow = 1;
  4432. tv.CursorPosition = new Point (18, 1);
  4433. Assert.True (tv.ProcessKey (new KeyEvent (Key.Y | Key.CtrlMask, new KeyModifiers ())));
  4434. Assert.Equal ($"This is the line.{Environment.NewLine}This is the first line.{Environment.NewLine}This is the third line.", tv.Text);
  4435. Assert.Equal (3, tv.Lines);
  4436. Assert.Equal (new Point (17, 1), tv.CursorPosition);
  4437. // Undo
  4438. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | 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, 1), tv.CursorPosition);
  4442. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  4443. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  4444. Assert.Equal (3, tv.Lines);
  4445. Assert.Equal (new Point (12, 0), tv.CursorPosition);
  4446. // Redo
  4447. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  4448. Assert.Equal ($"This is the line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  4449. Assert.Equal (3, tv.Lines);
  4450. Assert.Equal (new Point (12, 0), tv.CursorPosition);
  4451. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  4452. Assert.Equal ($"This is the line.{Environment.NewLine}This is the first line.{Environment.NewLine}This is the third line.", tv.Text);
  4453. Assert.Equal (3, tv.Lines);
  4454. Assert.Equal (new Point (17, 1), tv.CursorPosition);
  4455. }
  4456. [Fact]
  4457. public void HistoryText_Undo_Redo_KillWordBackward ()
  4458. {
  4459. var text = "First line.\nSecond line.";
  4460. var tv = new TextView () { Text = text };
  4461. Assert.True (tv.ProcessKey (new KeyEvent (Key.End | Key.CtrlMask, new KeyModifiers ())));
  4462. Assert.Equal ($"First line.{Environment.NewLine}Second line.", tv.Text);
  4463. Assert.Equal ("", tv.SelectedText);
  4464. Assert.Equal (2, tv.Lines);
  4465. Assert.Equal (new Point (12, 1), tv.CursorPosition);
  4466. Assert.True (tv.ProcessKey (new KeyEvent (Key.Backspace | Key.CtrlMask, new KeyModifiers ())));
  4467. Assert.Equal ($"First line.{Environment.NewLine}Second ", tv.Text);
  4468. Assert.Equal ("", tv.SelectedText);
  4469. Assert.Equal (2, tv.Lines);
  4470. Assert.Equal (new Point (7, 1), tv.CursorPosition);
  4471. Assert.True (tv.ProcessKey (new KeyEvent (Key.Backspace | Key.CtrlMask, new KeyModifiers ())));
  4472. Assert.Equal ($"First line.{Environment.NewLine}", tv.Text);
  4473. Assert.Equal ("", tv.SelectedText);
  4474. Assert.Equal (2, tv.Lines);
  4475. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  4476. Assert.True (tv.ProcessKey (new KeyEvent (Key.Backspace | Key.CtrlMask, new KeyModifiers ())));
  4477. Assert.Equal ("First line.", tv.Text);
  4478. Assert.Equal ("", tv.SelectedText);
  4479. Assert.Equal (1, tv.Lines);
  4480. Assert.Equal (new Point (11, 0), tv.CursorPosition);
  4481. Assert.True (tv.ProcessKey (new KeyEvent (Key.Backspace | Key.CtrlMask, new KeyModifiers ())));
  4482. Assert.Equal ("First ", tv.Text);
  4483. Assert.Equal ("", tv.SelectedText);
  4484. Assert.Equal (1, tv.Lines);
  4485. Assert.Equal (new Point (6, 0), tv.CursorPosition);
  4486. Assert.True (tv.ProcessKey (new KeyEvent (Key.Backspace | Key.CtrlMask, new KeyModifiers ())));
  4487. Assert.Equal ("", tv.Text);
  4488. Assert.Equal ("", tv.SelectedText);
  4489. Assert.Equal (1, tv.Lines);
  4490. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  4491. // Undo
  4492. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  4493. Assert.Equal ("First ", tv.Text);
  4494. Assert.Equal (1, tv.Lines);
  4495. Assert.Equal (new Point (6, 0), tv.CursorPosition);
  4496. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  4497. Assert.Equal ("First line.", tv.Text);
  4498. Assert.Equal (1, tv.Lines);
  4499. Assert.Equal (new Point (11, 0), tv.CursorPosition);
  4500. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  4501. Assert.Equal ($"First line.{Environment.NewLine}", tv.Text);
  4502. Assert.Equal (2, tv.Lines);
  4503. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  4504. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | 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.Z | Key.CtrlMask, new KeyModifiers ())));
  4509. Assert.Equal ($"First line.{Environment.NewLine}Second line.", tv.Text);
  4510. Assert.Equal (2, tv.Lines);
  4511. Assert.Equal (new Point (12, 1), tv.CursorPosition);
  4512. // Redo
  4513. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  4514. Assert.Equal ($"First line.{Environment.NewLine}Second ", tv.Text);
  4515. Assert.Equal (2, tv.Lines);
  4516. Assert.Equal (new Point (7, 1), tv.CursorPosition);
  4517. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  4518. Assert.Equal ($"First line.{Environment.NewLine}", tv.Text);
  4519. Assert.Equal (2, tv.Lines);
  4520. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  4521. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  4522. Assert.Equal ("First line.", tv.Text);
  4523. Assert.Equal (1, tv.Lines);
  4524. Assert.Equal (new Point (11, 0), tv.CursorPosition);
  4525. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  4526. Assert.Equal ("First ", tv.Text);
  4527. Assert.Equal (1, tv.Lines);
  4528. Assert.Equal (new Point (6, 0), tv.CursorPosition);
  4529. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  4530. Assert.Equal ("", tv.Text);
  4531. Assert.Equal (1, tv.Lines);
  4532. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  4533. }
  4534. [Fact]
  4535. public void HistoryText_Undo_Redo_KillWordForward ()
  4536. {
  4537. var text = "First line.\nSecond line.";
  4538. var tv = new TextView () { Text = text };
  4539. Assert.True (tv.ProcessKey (new KeyEvent (Key.DeleteChar | Key.CtrlMask, new KeyModifiers ())));
  4540. Assert.Equal ($"line.{Environment.NewLine}Second line.", tv.Text);
  4541. Assert.Equal ("", tv.SelectedText);
  4542. Assert.Equal (2, tv.Lines);
  4543. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  4544. Assert.True (tv.ProcessKey (new KeyEvent (Key.DeleteChar | Key.CtrlMask, new KeyModifiers ())));
  4545. Assert.Equal ($"{Environment.NewLine}Second line.", tv.Text);
  4546. Assert.Equal (2, tv.Lines);
  4547. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  4548. Assert.True (tv.ProcessKey (new KeyEvent (Key.DeleteChar | Key.CtrlMask, new KeyModifiers ())));
  4549. Assert.Equal ("Second line.", tv.Text);
  4550. Assert.Equal (1, tv.Lines);
  4551. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  4552. Assert.True (tv.ProcessKey (new KeyEvent (Key.DeleteChar | 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.DeleteChar | Key.CtrlMask, new KeyModifiers ())));
  4557. Assert.Equal ("", tv.Text);
  4558. Assert.Equal (1, tv.Lines);
  4559. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  4560. // Undo
  4561. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  4562. Assert.Equal ("line.", tv.Text);
  4563. Assert.Equal (1, tv.Lines);
  4564. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  4565. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  4566. Assert.Equal ("Second line.", tv.Text);
  4567. Assert.Equal (1, tv.Lines);
  4568. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  4569. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  4570. Assert.Equal ($"{Environment.NewLine}Second line.", tv.Text);
  4571. Assert.Equal (2, tv.Lines);
  4572. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  4573. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | 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.Z | Key.CtrlMask, new KeyModifiers ())));
  4578. Assert.Equal ($"First line.{Environment.NewLine}Second line.", tv.Text);
  4579. Assert.Equal (2, tv.Lines);
  4580. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  4581. // Redo
  4582. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  4583. Assert.Equal ($"line.{Environment.NewLine}Second line.", tv.Text);
  4584. Assert.Equal (2, tv.Lines);
  4585. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  4586. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  4587. Assert.Equal ($"{Environment.NewLine}Second line.", tv.Text);
  4588. Assert.Equal (2, tv.Lines);
  4589. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  4590. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  4591. Assert.Equal ("Second line.", tv.Text);
  4592. Assert.Equal (1, tv.Lines);
  4593. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  4594. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  4595. Assert.Equal ("line.", tv.Text);
  4596. Assert.Equal (1, tv.Lines);
  4597. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  4598. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  4599. Assert.Equal ("", tv.Text);
  4600. Assert.Equal (1, tv.Lines);
  4601. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  4602. }
  4603. [Fact]
  4604. [AutoInitShutdown]
  4605. public void HistoryText_Undo_Redo_KillToStartOfLine ()
  4606. {
  4607. var text = "First line.\nSecond line.";
  4608. var tv = new TextView () { Text = text };
  4609. Assert.True (tv.ProcessKey (new KeyEvent (Key.End | Key.CtrlMask, new KeyModifiers ())));
  4610. Assert.Equal ($"First line.{Environment.NewLine}Second line.", tv.Text);
  4611. Assert.Equal ("", tv.SelectedText);
  4612. Assert.Equal (2, tv.Lines);
  4613. Assert.Equal (new Point (12, 1), tv.CursorPosition);
  4614. Assert.True (tv.ProcessKey (new KeyEvent (Key.K | Key.AltMask, new KeyModifiers ())));
  4615. Assert.Equal ($"First line.{Environment.NewLine}", tv.Text);
  4616. Assert.Equal ("", tv.SelectedText);
  4617. Assert.Equal ("Second line.", Clipboard.Contents);
  4618. Assert.Equal (2, tv.Lines);
  4619. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  4620. Assert.True (tv.ProcessKey (new KeyEvent (Key.K | Key.AltMask, new KeyModifiers ())));
  4621. Assert.Equal ("First line.", tv.Text);
  4622. Assert.Equal ("", tv.SelectedText);
  4623. Assert.Equal ($"Second line.{Environment.NewLine}", Clipboard.Contents);
  4624. Assert.Equal (1, tv.Lines);
  4625. Assert.Equal (new Point (11, 0), tv.CursorPosition);
  4626. Assert.True (tv.ProcessKey (new KeyEvent (Key.K | Key.AltMask, new KeyModifiers ())));
  4627. Assert.Equal ("", tv.Text);
  4628. Assert.Equal ("", tv.SelectedText);
  4629. Assert.Equal ($"Second line.{Environment.NewLine}First line.", Clipboard.Contents);
  4630. Assert.Equal (1, tv.Lines);
  4631. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  4632. // Undo
  4633. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  4634. Assert.Equal ("First line.", tv.Text);
  4635. Assert.Equal (1, tv.Lines);
  4636. Assert.Equal (new Point (11, 0), tv.CursorPosition);
  4637. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | 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.Z | Key.CtrlMask, new KeyModifiers ())));
  4642. Assert.Equal ($"First line.{Environment.NewLine}Second line.", tv.Text);
  4643. Assert.Equal (2, tv.Lines);
  4644. Assert.Equal (new Point (12, 1), tv.CursorPosition);
  4645. // Redo
  4646. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  4647. Assert.Equal ($"First line.{Environment.NewLine}", tv.Text);
  4648. Assert.Equal (2, tv.Lines);
  4649. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  4650. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  4651. Assert.Equal ($"First line.", tv.Text);
  4652. Assert.Equal (1, tv.Lines);
  4653. Assert.Equal (new Point (11, 0), tv.CursorPosition);
  4654. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  4655. Assert.Equal ("", tv.Text);
  4656. Assert.Equal (1, tv.Lines);
  4657. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  4658. }
  4659. [Fact]
  4660. [AutoInitShutdown]
  4661. public void HistoryText_Undo_Redo_KillToEndOfLine ()
  4662. {
  4663. var text = "First line.\nSecond line.";
  4664. var tv = new TextView () { Text = text };
  4665. Assert.True (tv.ProcessKey (new KeyEvent (Key.K | Key.CtrlMask, new KeyModifiers ())));
  4666. Assert.Equal ($"{Environment.NewLine}Second line.", tv.Text);
  4667. Assert.Equal ("", tv.SelectedText);
  4668. Assert.Equal ("First line.", Clipboard.Contents);
  4669. Assert.Equal (2, tv.Lines);
  4670. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  4671. Assert.True (tv.ProcessKey (new KeyEvent (Key.K | Key.CtrlMask, new KeyModifiers ())));
  4672. Assert.Equal ("Second line.", tv.Text);
  4673. Assert.Equal ("", tv.SelectedText);
  4674. Assert.Equal ($"First line.{Environment.NewLine}", Clipboard.Contents);
  4675. Assert.Equal (1, tv.Lines);
  4676. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  4677. Assert.True (tv.ProcessKey (new KeyEvent (Key.K | Key.CtrlMask, new KeyModifiers ())));
  4678. Assert.Equal ("", tv.Text);
  4679. Assert.Equal ("", tv.SelectedText);
  4680. Assert.Equal ($"First line.{Environment.NewLine}Second line.", Clipboard.Contents);
  4681. Assert.Equal (1, tv.Lines);
  4682. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  4683. // Undo
  4684. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  4685. Assert.Equal ("Second line.", tv.Text);
  4686. Assert.Equal (1, tv.Lines);
  4687. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  4688. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | 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.Z | Key.CtrlMask, new KeyModifiers ())));
  4693. Assert.Equal ($"First line.{Environment.NewLine}Second line.", tv.Text);
  4694. Assert.Equal (2, tv.Lines);
  4695. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  4696. // Redo
  4697. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  4698. Assert.Equal ($"{Environment.NewLine}Second line.", tv.Text);
  4699. Assert.Equal (2, tv.Lines);
  4700. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  4701. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  4702. Assert.Equal ("Second line.", tv.Text);
  4703. Assert.Equal (1, tv.Lines);
  4704. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  4705. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  4706. Assert.Equal ("", tv.Text);
  4707. Assert.Equal (1, tv.Lines);
  4708. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  4709. }
  4710. [Fact]
  4711. public void HistoryText_Undo_Redo_Changing_On_Middle_Clear_History_Forwards ()
  4712. {
  4713. var tv = new TextView ();
  4714. Assert.True (tv.ProcessKey (new KeyEvent (Key.D1, new KeyModifiers ())));
  4715. Assert.Equal ("1", tv.Text);
  4716. Assert.Equal (1, tv.Lines);
  4717. Assert.Equal (new Point (1, 0), tv.CursorPosition);
  4718. Assert.True (tv.ProcessKey (new KeyEvent (Key.D2, 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.D3, new KeyModifiers ())));
  4723. Assert.Equal ("123", tv.Text);
  4724. Assert.Equal (1, tv.Lines);
  4725. Assert.Equal (new Point (3, 0), tv.CursorPosition);
  4726. // Undo
  4727. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  4728. Assert.Equal ("12", tv.Text);
  4729. Assert.Equal (1, tv.Lines);
  4730. Assert.Equal (new Point (2, 0), tv.CursorPosition);
  4731. Assert.True (tv.ProcessKey (new KeyEvent (Key.D4, new KeyModifiers ())));
  4732. Assert.Equal ("124", tv.Text);
  4733. Assert.Equal (1, tv.Lines);
  4734. Assert.Equal (new Point (3, 0), tv.CursorPosition);
  4735. // Redo
  4736. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  4737. Assert.Equal ("124", tv.Text);
  4738. Assert.Equal (1, tv.Lines);
  4739. Assert.Equal (new Point (3, 0), tv.CursorPosition);
  4740. }
  4741. [Fact]
  4742. public void HistoryText_Undo_Redo_Single_Line_Selected_Return ()
  4743. {
  4744. var text = "This is the first line.\nThis is the second line.\nThis is the third line.";
  4745. var tv = new TextView () { Text = text };
  4746. tv.SelectionStartColumn = 12;
  4747. tv.CursorPosition = new Point (17, 0);
  4748. Assert.True (tv.ProcessKey (new KeyEvent (Key.Enter, new KeyModifiers ())));
  4749. Assert.Equal ($"This is the {Environment.NewLine} line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  4750. Assert.Equal (4, tv.Lines);
  4751. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  4752. // Undo
  4753. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  4754. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  4755. Assert.Equal (3, tv.Lines);
  4756. Assert.Equal (new Point (17, 0), tv.CursorPosition);
  4757. Assert.False (tv.IsDirty);
  4758. // Redo
  4759. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  4760. Assert.Equal ($"This is the {Environment.NewLine} line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  4761. Assert.Equal (4, tv.Lines);
  4762. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  4763. // Undo
  4764. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  4765. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  4766. Assert.Equal (3, tv.Lines);
  4767. Assert.Equal (new Point (17, 0), tv.CursorPosition);
  4768. Assert.False (tv.IsDirty);
  4769. // Redo
  4770. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  4771. Assert.Equal ($"This is the {Environment.NewLine} line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  4772. Assert.Equal (4, tv.Lines);
  4773. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  4774. }
  4775. [Fact]
  4776. public void HistoryText_Undo_Redo_Two_Line_Selected_Return ()
  4777. {
  4778. var text = "This is the first line.\nThis is the second line.\nThis is the third line.";
  4779. var tv = new TextView () { Text = text };
  4780. tv.SelectionStartColumn = 12;
  4781. tv.CursorPosition = new Point (18, 1);
  4782. Assert.True (tv.ProcessKey (new KeyEvent (Key.Enter, new KeyModifiers ())));
  4783. Assert.Equal ($"This is the {Environment.NewLine} line.{Environment.NewLine}This is the third line.", tv.Text);
  4784. Assert.Equal (3, tv.Lines);
  4785. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  4786. // Undo
  4787. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  4788. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  4789. Assert.Equal (3, tv.Lines);
  4790. Assert.Equal (new Point (18, 1), tv.CursorPosition);
  4791. Assert.False (tv.IsDirty);
  4792. // Redo
  4793. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  4794. Assert.Equal ($"This is the {Environment.NewLine} line.{Environment.NewLine}This is the third line.", tv.Text);
  4795. Assert.Equal (3, tv.Lines);
  4796. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  4797. // Undo
  4798. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  4799. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  4800. Assert.Equal (3, tv.Lines);
  4801. Assert.Equal (new Point (18, 1), tv.CursorPosition);
  4802. Assert.False (tv.IsDirty);
  4803. // Redo
  4804. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  4805. Assert.Equal ($"This is the {Environment.NewLine} line.{Environment.NewLine}This is the third line.", tv.Text);
  4806. Assert.Equal (3, tv.Lines);
  4807. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  4808. }
  4809. [Fact]
  4810. public void HistoryText_Undo_Redo_Three_Line_Selected_Return ()
  4811. {
  4812. var text = "This is the first line.\nThis is the second line.\nThis is the third line.";
  4813. var tv = new TextView () { Text = text };
  4814. tv.SelectionStartColumn = 12;
  4815. tv.CursorPosition = new Point (17, 2);
  4816. Assert.True (tv.ProcessKey (new KeyEvent (Key.Enter, new KeyModifiers ())));
  4817. Assert.Equal ($"This is the {Environment.NewLine} line.", tv.Text);
  4818. Assert.Equal (2, tv.Lines);
  4819. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  4820. // Undo
  4821. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  4822. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  4823. Assert.Equal (3, tv.Lines);
  4824. Assert.Equal (new Point (17, 2), tv.CursorPosition);
  4825. Assert.False (tv.IsDirty);
  4826. // Redo
  4827. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  4828. Assert.Equal ($"This is the {Environment.NewLine} line.", tv.Text);
  4829. Assert.Equal (2, tv.Lines);
  4830. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  4831. // Undo
  4832. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  4833. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  4834. Assert.Equal (3, tv.Lines);
  4835. Assert.Equal (new Point (17, 2), tv.CursorPosition);
  4836. Assert.False (tv.IsDirty);
  4837. // Redo
  4838. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  4839. Assert.Equal ($"This is the {Environment.NewLine} line.", tv.Text);
  4840. Assert.Equal (2, tv.Lines);
  4841. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  4842. }
  4843. [Fact]
  4844. public void HistoryText_Undo_Redo_Single_Second_Line_Selected_Return ()
  4845. {
  4846. var text = "This is the first line.\nThis is the second line.\nThis is the third line.";
  4847. var tv = new TextView () { Text = text };
  4848. tv.SelectionStartColumn = 12;
  4849. tv.SelectionStartRow = 1;
  4850. tv.CursorPosition = new Point (18, 1);
  4851. Assert.True (tv.ProcessKey (new KeyEvent (Key.Enter, new KeyModifiers ())));
  4852. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the {Environment.NewLine} line.{Environment.NewLine}This is the third line.", tv.Text);
  4853. Assert.Equal (4, tv.Lines);
  4854. Assert.Equal (new Point (0, 2), tv.CursorPosition);
  4855. // Undo
  4856. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  4857. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  4858. Assert.Equal (3, tv.Lines);
  4859. Assert.Equal (new Point (18, 1), tv.CursorPosition);
  4860. Assert.False (tv.IsDirty);
  4861. // Redo
  4862. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  4863. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the {Environment.NewLine} line.{Environment.NewLine}This is the third line.", tv.Text);
  4864. Assert.Equal (4, tv.Lines);
  4865. Assert.Equal (new Point (0, 2), tv.CursorPosition);
  4866. // Undo
  4867. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  4868. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  4869. Assert.Equal (3, tv.Lines);
  4870. Assert.Equal (new Point (18, 1), tv.CursorPosition);
  4871. Assert.False (tv.IsDirty);
  4872. // Redo
  4873. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  4874. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the {Environment.NewLine} line.{Environment.NewLine}This is the third line.", tv.Text);
  4875. Assert.Equal (4, tv.Lines);
  4876. Assert.Equal (new Point (0, 2), tv.CursorPosition);
  4877. }
  4878. [Fact]
  4879. public void HistoryText_Undo_Redo_First_Line_Selected_Return_And_InsertText ()
  4880. {
  4881. var text = "This is the first line.\nThis is the second line.\nThis is the third line.";
  4882. var tv = new TextView () { Text = text };
  4883. tv.SelectionStartColumn = 12;
  4884. tv.CursorPosition = new Point (17, 0);
  4885. Assert.True (tv.ProcessKey (new KeyEvent (Key.Enter, 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.ProcessKey (new KeyEvent (Key.a, new KeyModifiers ())));
  4890. 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);
  4891. Assert.Equal (4, tv.Lines);
  4892. Assert.Equal (new Point (1, 1), tv.CursorPosition);
  4893. // Undo
  4894. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  4895. Assert.Equal ($"This is the {Environment.NewLine} line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  4896. Assert.Equal (4, tv.Lines);
  4897. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  4898. Assert.True (tv.IsDirty);
  4899. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  4900. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  4901. Assert.Equal (3, tv.Lines);
  4902. Assert.Equal (new Point (17, 0), tv.CursorPosition);
  4903. Assert.False (tv.IsDirty);
  4904. // Redo
  4905. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  4906. Assert.Equal ($"This is the {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.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  4910. 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);
  4911. Assert.Equal (4, tv.Lines);
  4912. Assert.Equal (new Point (1, 1), tv.CursorPosition);
  4913. // Undo
  4914. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  4915. Assert.Equal ($"This is the {Environment.NewLine} line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  4916. Assert.Equal (4, tv.Lines);
  4917. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  4918. Assert.True (tv.IsDirty);
  4919. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  4920. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  4921. Assert.Equal (3, tv.Lines);
  4922. Assert.Equal (new Point (17, 0), tv.CursorPosition);
  4923. Assert.False (tv.IsDirty);
  4924. // Redo
  4925. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  4926. Assert.Equal ($"This is the {Environment.NewLine} line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  4927. Assert.Equal (4, tv.Lines);
  4928. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  4929. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  4930. 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);
  4931. Assert.Equal (4, tv.Lines);
  4932. Assert.Equal (new Point (1, 1), tv.CursorPosition);
  4933. }
  4934. [Fact]
  4935. public void HistoryText_Undo_Redo_Single_Second_Line_Selected_Return_And_InsertText ()
  4936. {
  4937. var text = "This is the first line.\nThis is the second line.\nThis is the third line.";
  4938. var tv = new TextView () { Text = text };
  4939. tv.SelectionStartColumn = 12;
  4940. tv.SelectionStartRow = 1;
  4941. tv.CursorPosition = new Point (18, 1);
  4942. Assert.True (tv.ProcessKey (new KeyEvent (Key.Enter, 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.ProcessKey (new KeyEvent (Key.a, new KeyModifiers ())));
  4947. 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);
  4948. Assert.Equal (4, tv.Lines);
  4949. Assert.Equal (new Point (1, 2), tv.CursorPosition);
  4950. // Undo
  4951. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  4952. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the {Environment.NewLine} line.{Environment.NewLine}This is the third line.", tv.Text);
  4953. Assert.Equal (4, tv.Lines);
  4954. Assert.Equal (new Point (0, 2), tv.CursorPosition);
  4955. Assert.True (tv.IsDirty);
  4956. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  4957. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  4958. Assert.Equal (3, tv.Lines);
  4959. Assert.Equal (new Point (18, 1), tv.CursorPosition);
  4960. Assert.False (tv.IsDirty);
  4961. // Redo
  4962. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | 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.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  4967. 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);
  4968. Assert.Equal (4, tv.Lines);
  4969. Assert.Equal (new Point (1, 2), tv.CursorPosition);
  4970. // Undo
  4971. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  4972. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the {Environment.NewLine} line.{Environment.NewLine}This is the third line.", tv.Text);
  4973. Assert.Equal (4, tv.Lines);
  4974. Assert.Equal (new Point (0, 2), tv.CursorPosition);
  4975. Assert.True (tv.IsDirty);
  4976. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  4977. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  4978. Assert.Equal (3, tv.Lines);
  4979. Assert.Equal (new Point (18, 1), tv.CursorPosition);
  4980. Assert.False (tv.IsDirty);
  4981. // Redo
  4982. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  4983. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the {Environment.NewLine} line.{Environment.NewLine}This is the third line.", tv.Text);
  4984. Assert.Equal (4, tv.Lines);
  4985. Assert.Equal (new Point (0, 2), tv.CursorPosition);
  4986. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  4987. 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);
  4988. Assert.Equal (4, tv.Lines);
  4989. Assert.Equal (new Point (1, 2), tv.CursorPosition);
  4990. }
  4991. [Fact]
  4992. public void HistoryText_Undo_Redo_Multi_Line_Selected_All_Return_And_InsertText ()
  4993. {
  4994. var text = "This is the first line.\nThis is the second line.\nThis is the third line.";
  4995. var tv = new TextView () { Text = text };
  4996. Assert.True (tv.ProcessKey (new KeyEvent (Key.End | Key.CtrlMask | Key.ShiftMask, new KeyModifiers ())));
  4997. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  4998. Assert.Equal (3, tv.Lines);
  4999. Assert.Equal (new Point (23, 2), tv.CursorPosition);
  5000. Assert.True (tv.ProcessKey (new KeyEvent (Key.Enter, 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.ProcessKey (new KeyEvent (Key.a, new KeyModifiers ())));
  5005. Assert.Equal ($"{Environment.NewLine}a", tv.Text);
  5006. Assert.Equal (2, tv.Lines);
  5007. Assert.Equal (new Point (1, 1), tv.CursorPosition);
  5008. // Undo
  5009. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  5010. Assert.Equal ($"{Environment.NewLine}", tv.Text);
  5011. Assert.Equal (2, tv.Lines);
  5012. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  5013. Assert.True (tv.IsDirty);
  5014. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  5015. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  5016. Assert.Equal (3, tv.Lines);
  5017. Assert.Equal (new Point (23, 2), tv.CursorPosition);
  5018. Assert.False (tv.IsDirty);
  5019. // Redo
  5020. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | 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.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  5025. Assert.Equal ($"{Environment.NewLine}a", tv.Text);
  5026. Assert.Equal (2, tv.Lines);
  5027. Assert.Equal (new Point (1, 1), tv.CursorPosition);
  5028. // Undo
  5029. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  5030. Assert.Equal ($"{Environment.NewLine}", tv.Text);
  5031. Assert.Equal (2, tv.Lines);
  5032. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  5033. Assert.True (tv.IsDirty);
  5034. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  5035. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  5036. Assert.Equal (3, tv.Lines);
  5037. Assert.Equal (new Point (23, 2), tv.CursorPosition);
  5038. Assert.False (tv.IsDirty);
  5039. // Redo
  5040. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  5041. Assert.Equal ($"{Environment.NewLine}", tv.Text);
  5042. Assert.Equal (2, tv.Lines);
  5043. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  5044. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  5045. Assert.Equal ($"{Environment.NewLine}a", tv.Text);
  5046. Assert.Equal (2, tv.Lines);
  5047. Assert.Equal (new Point (1, 1), tv.CursorPosition);
  5048. }
  5049. [Fact]
  5050. public void HistoryText_Undo_Redo_Ending_With_Newline_Multi_Line_Selected_Almost_All_Return_And_InsertText ()
  5051. {
  5052. var text = "This is the first line.\nThis is the second line.\nThis is the third line.\n";
  5053. var tv = new TextView () { Text = text };
  5054. tv.SelectionStartColumn = 12;
  5055. tv.CursorPosition = new Point (12, 2);
  5056. Assert.True (tv.ProcessKey (new KeyEvent (Key.Enter, 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.ProcessKey (new KeyEvent (Key.a, new KeyModifiers ())));
  5061. Assert.Equal ($"This is the {Environment.NewLine}athird line.{Environment.NewLine}", tv.Text);
  5062. Assert.Equal (3, tv.Lines);
  5063. Assert.Equal (new Point (1, 1), tv.CursorPosition);
  5064. // Undo
  5065. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  5066. Assert.Equal ($"This is the {Environment.NewLine}third line.{Environment.NewLine}", tv.Text);
  5067. Assert.Equal (3, tv.Lines);
  5068. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  5069. Assert.True (tv.IsDirty);
  5070. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  5071. 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);
  5072. Assert.Equal (4, tv.Lines);
  5073. Assert.Equal (new Point (12, 2), tv.CursorPosition);
  5074. Assert.False (tv.IsDirty);
  5075. // Redo
  5076. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | 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.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  5081. Assert.Equal ($"This is the {Environment.NewLine}athird line.{Environment.NewLine}", tv.Text);
  5082. Assert.Equal (3, tv.Lines);
  5083. Assert.Equal (new Point (1, 1), tv.CursorPosition);
  5084. // Undo
  5085. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  5086. Assert.Equal ($"This is the {Environment.NewLine}third line.{Environment.NewLine}", tv.Text);
  5087. Assert.Equal (3, tv.Lines);
  5088. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  5089. Assert.True (tv.IsDirty);
  5090. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  5091. 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);
  5092. Assert.Equal (4, tv.Lines);
  5093. Assert.Equal (new Point (12, 2), tv.CursorPosition);
  5094. Assert.False (tv.IsDirty);
  5095. // Redo
  5096. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  5097. Assert.Equal ($"This is the {Environment.NewLine}third line.{Environment.NewLine}", tv.Text);
  5098. Assert.Equal (3, tv.Lines);
  5099. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  5100. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  5101. Assert.Equal ($"This is the {Environment.NewLine}athird line.{Environment.NewLine}", tv.Text);
  5102. Assert.Equal (3, tv.Lines);
  5103. Assert.Equal (new Point (1, 1), tv.CursorPosition);
  5104. }
  5105. [Fact]
  5106. public void HistoryText_Undo_Redo_Disabled_On_WordWrap ()
  5107. {
  5108. var text = "This is the first line.\nThis is the second line.\nThis is the third line.\n";
  5109. var tv = new TextView () { Width = 80, Height = 5, Text = text };
  5110. Assert.False (tv.WordWrap);
  5111. tv.WordWrap = true;
  5112. tv.SelectionStartColumn = 12;
  5113. tv.CursorPosition = new Point (12, 2);
  5114. Assert.True (tv.ProcessKey (new KeyEvent (Key.Enter, new KeyModifiers ())));
  5115. Assert.Equal ($"This is the {Environment.NewLine}third line.{Environment.NewLine}", tv.Text);
  5116. Assert.Equal (3, tv.Lines);
  5117. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  5118. Assert.True (tv.ProcessKey (new KeyEvent (Key.a, 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. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  5123. Assert.Equal ($"This is the {Environment.NewLine}third line.{Environment.NewLine}", tv.Text);
  5124. Assert.Equal (3, tv.Lines);
  5125. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  5126. Assert.True (tv.IsDirty);
  5127. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  5128. Assert.Equal ($"This is the {Environment.NewLine}athird line.{Environment.NewLine}", tv.Text);
  5129. Assert.Equal (3, tv.Lines);
  5130. Assert.Equal (new Point (1, 1), tv.CursorPosition);
  5131. }
  5132. [Fact]
  5133. public void HistoryText_Undo_Redo_Multiline_Simples_Tab_BackTab ()
  5134. {
  5135. var text = "First line.\nSecond line.\nThird line.";
  5136. var tv = new TextView () { Width = 80, Height = 5, Text = text };
  5137. Assert.True (tv.ProcessKey (new KeyEvent (Key.Tab, 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.ProcessKey (new KeyEvent (Key.BackTab, new KeyModifiers ())));
  5142. Assert.Equal ($"First line.{Environment.NewLine}Second line.{Environment.NewLine}Third line.", tv.Text);
  5143. Assert.Equal (3, tv.Lines);
  5144. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  5145. // Undo
  5146. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  5147. Assert.Equal ($"\tFirst line.{Environment.NewLine}Second line.{Environment.NewLine}Third line.", tv.Text);
  5148. Assert.Equal (3, tv.Lines);
  5149. Assert.Equal (new Point (1, 0), tv.CursorPosition);
  5150. Assert.True (tv.IsDirty);
  5151. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  5152. Assert.Equal ($"First line.{Environment.NewLine}Second line.{Environment.NewLine}Third line.", tv.Text);
  5153. Assert.Equal (3, tv.Lines);
  5154. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  5155. Assert.False (tv.IsDirty);
  5156. // Redo
  5157. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  5158. Assert.Equal ($"\tFirst line.{Environment.NewLine}Second line.{Environment.NewLine}Third line.", tv.Text);
  5159. Assert.Equal (3, tv.Lines);
  5160. Assert.Equal (new Point (1, 0), tv.CursorPosition);
  5161. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  5162. Assert.Equal ($"First line.{Environment.NewLine}Second line.{Environment.NewLine}Third line.", tv.Text);
  5163. Assert.Equal (3, tv.Lines);
  5164. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  5165. }
  5166. [Fact]
  5167. public void HistoryText_Undo_Redo_Multiline_Selected_Tab_BackTab ()
  5168. {
  5169. var text = "First line.\nSecond line.\nThird line.";
  5170. var tv = new TextView () { Width = 80, Height = 5, Text = text };
  5171. tv.SelectionStartColumn = 6;
  5172. tv.CursorPosition = new Point (6, 2);
  5173. Assert.True (tv.ProcessKey (new KeyEvent (Key.Tab, 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.ProcessKey (new KeyEvent (Key.BackTab, new KeyModifiers ())));
  5178. Assert.Equal ("First line.", tv.Text);
  5179. Assert.Equal (1, tv.Lines);
  5180. Assert.Equal (new Point (6, 0), tv.CursorPosition);
  5181. // Undo
  5182. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  5183. Assert.Equal ("First \tline.", tv.Text);
  5184. Assert.Equal (1, tv.Lines);
  5185. Assert.Equal (new Point (7, 0), tv.CursorPosition);
  5186. Assert.True (tv.IsDirty);
  5187. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  5188. Assert.Equal ($"First line.{Environment.NewLine}Second line.{Environment.NewLine}Third line.", tv.Text);
  5189. Assert.Equal (3, tv.Lines);
  5190. Assert.Equal (new Point (6, 2), tv.CursorPosition);
  5191. Assert.False (tv.IsDirty);
  5192. // Redo
  5193. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  5194. Assert.Equal ("First \tline.", tv.Text);
  5195. Assert.Equal (1, tv.Lines);
  5196. Assert.Equal (new Point (7, 0), tv.CursorPosition);
  5197. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  5198. Assert.Equal ("First line.", tv.Text);
  5199. Assert.Equal (1, tv.Lines);
  5200. Assert.Equal (new Point (6, 0), tv.CursorPosition);
  5201. }
  5202. [Fact]
  5203. public void HistoryText_ClearHistoryChanges ()
  5204. {
  5205. var text = "This is the first line.\nThis is the second line.\nThis is the third line.";
  5206. var tv = new TextView () { Text = text };
  5207. Assert.True (tv.ProcessKey (new KeyEvent (Key.Enter, new KeyModifiers ())));
  5208. 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);
  5209. Assert.Equal (4, tv.Lines);
  5210. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  5211. Assert.True (tv.IsDirty);
  5212. Assert.True (tv.HasHistoryChanges);
  5213. tv.ClearHistoryChanges ();
  5214. 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);
  5215. Assert.Equal (4, tv.Lines);
  5216. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  5217. Assert.False (tv.IsDirty);
  5218. Assert.False (tv.HasHistoryChanges);
  5219. }
  5220. [Fact]
  5221. public void GetRegion_StringFromRunes_Environment_NewLine ()
  5222. {
  5223. var tv = new TextView () { Text = $"1{Environment.NewLine}2" };
  5224. Assert.Equal ($"1{Environment.NewLine}2", tv.Text);
  5225. Assert.Equal ("", tv.SelectedText);
  5226. tv.SelectAll ();
  5227. Assert.Equal ($"1{Environment.NewLine}2", tv.Text);
  5228. Assert.Equal ($"1{Environment.NewLine}2", tv.SelectedText);
  5229. }
  5230. [Fact, AutoInitShutdown]
  5231. public void WordWrap_Not_Throw_If_Width_Is_Less_Than_Zero ()
  5232. {
  5233. var exception = Record.Exception (() => {
  5234. var tv = new TextView () {
  5235. Width = Dim.Fill (),
  5236. Height = Dim.Fill (),
  5237. WordWrap = true,
  5238. Text = "これは、左右のクリップ境界をテストするための非常に長いテキストです。"
  5239. };
  5240. });
  5241. Assert.Null (exception);
  5242. }
  5243. [Fact]
  5244. [AutoInitShutdown]
  5245. public void ScrollDownTillCaretOffscreen_ThenType ()
  5246. {
  5247. var tv = new TextView {
  5248. Width = 10,
  5249. Height = 5
  5250. };
  5251. // add 100 lines of wide text to view
  5252. for (int i = 0; i < 100; i++)
  5253. tv.Text += new string ('x', 100) + Environment.NewLine;
  5254. Assert.Equal (0, tv.CursorPosition.Y);
  5255. tv.ScrollTo (50);
  5256. Assert.Equal (0, tv.CursorPosition.Y);
  5257. tv.ProcessKey (new KeyEvent (Key.p, new KeyModifiers ()));
  5258. }
  5259. [Fact]
  5260. [AutoInitShutdown]
  5261. public void MoveDown_By_Setting_CursorPosition ()
  5262. {
  5263. var tv = new TextView {
  5264. Width = 10,
  5265. Height = 5
  5266. };
  5267. // add 100 lines of wide text to view
  5268. for (int i = 0; i < 100; i++)
  5269. tv.Text += new string ('x', 100) + (i == 99 ? "" : Environment.NewLine);
  5270. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  5271. tv.CursorPosition = new Point (5, 50);
  5272. Assert.Equal (new Point (5, 50), tv.CursorPosition);
  5273. tv.CursorPosition = new Point (200, 200);
  5274. Assert.Equal (new Point (100, 99), tv.CursorPosition);
  5275. }
  5276. [Fact]
  5277. [AutoInitShutdown]
  5278. public void ScrollTo_CursorPosition ()
  5279. {
  5280. var tv = new TextView {
  5281. Width = 10,
  5282. Height = 5
  5283. };
  5284. // add 100 lines of wide text to view
  5285. for (int i = 0; i < 100; i++)
  5286. tv.Text += new string ('x', 100) + (i == 99 ? "" : Environment.NewLine);
  5287. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  5288. tv.ScrollTo (50);
  5289. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  5290. tv.CursorPosition = new Point (tv.LeftColumn, tv.TopRow);
  5291. Assert.Equal (new Point (0, 50), tv.CursorPosition);
  5292. }
  5293. [Fact]
  5294. [InitShutdown]
  5295. public void Mouse_Button_Shift_Preserves_Selection ()
  5296. {
  5297. Assert.Equal ("TAB to jump between text fields.", _textView.Text);
  5298. Assert.True (_textView.MouseEvent (new MouseEvent () { X = 12, Y = 0, Flags = MouseFlags.Button1Pressed | MouseFlags.ButtonShift }));
  5299. Assert.Equal (0, _textView.SelectionStartColumn);
  5300. Assert.Equal (0, _textView.SelectionStartRow);
  5301. Assert.Equal (new Point (12, 0), _textView.CursorPosition);
  5302. Assert.True (_textView.Selecting);
  5303. Assert.Equal ("TAB to jump ", _textView.SelectedText);
  5304. Assert.True (_textView.MouseEvent (new MouseEvent () { X = 12, Y = 0, Flags = MouseFlags.Button1Clicked }));
  5305. Assert.Equal (0, _textView.SelectionStartRow);
  5306. Assert.Equal (0, _textView.SelectionStartRow);
  5307. Assert.Equal (new Point (12, 0), _textView.CursorPosition);
  5308. Assert.True (_textView.Selecting);
  5309. Assert.Equal ("TAB to jump ", _textView.SelectedText);
  5310. Assert.True (_textView.MouseEvent (new MouseEvent () { X = 19, Y = 0, Flags = MouseFlags.Button1Pressed | MouseFlags.ButtonShift }));
  5311. Assert.Equal (0, _textView.SelectionStartRow);
  5312. Assert.Equal (0, _textView.SelectionStartRow);
  5313. Assert.Equal (new Point (19, 0), _textView.CursorPosition);
  5314. Assert.True (_textView.Selecting);
  5315. Assert.Equal ("TAB to jump between", _textView.SelectedText);
  5316. Assert.True (_textView.MouseEvent (new MouseEvent () { X = 19, Y = 0, Flags = MouseFlags.Button1Clicked }));
  5317. Assert.Equal (0, _textView.SelectionStartRow);
  5318. Assert.Equal (0, _textView.SelectionStartRow);
  5319. Assert.Equal (new Point (19, 0), _textView.CursorPosition);
  5320. Assert.True (_textView.Selecting);
  5321. Assert.Equal ("TAB to jump between", _textView.SelectedText);
  5322. Assert.True (_textView.MouseEvent (new MouseEvent () { X = 24, Y = 0, Flags = MouseFlags.Button1Pressed | MouseFlags.ButtonShift }));
  5323. Assert.Equal (0, _textView.SelectionStartRow);
  5324. Assert.Equal (0, _textView.SelectionStartRow);
  5325. Assert.Equal (new Point (24, 0), _textView.CursorPosition);
  5326. Assert.True (_textView.Selecting);
  5327. Assert.Equal ("TAB to jump between text", _textView.SelectedText);
  5328. Assert.True (_textView.MouseEvent (new MouseEvent () { X = 24, Y = 0, Flags = MouseFlags.Button1Clicked }));
  5329. Assert.Equal (0, _textView.SelectionStartRow);
  5330. Assert.Equal (0, _textView.SelectionStartRow);
  5331. Assert.Equal (new Point (24, 0), _textView.CursorPosition);
  5332. Assert.True (_textView.Selecting);
  5333. Assert.Equal ("TAB to jump between text", _textView.SelectedText);
  5334. Assert.True (_textView.MouseEvent (new MouseEvent () { X = 24, Y = 0, Flags = MouseFlags.Button1Pressed }));
  5335. Assert.Equal (0, _textView.SelectionStartRow);
  5336. Assert.Equal (0, _textView.SelectionStartRow);
  5337. Assert.Equal (new Point (24, 0), _textView.CursorPosition);
  5338. Assert.True (_textView.Selecting);
  5339. Assert.Equal ("", _textView.SelectedText);
  5340. }
  5341. [Fact, AutoInitShutdown]
  5342. public void UnwrappedCursorPosition_Event ()
  5343. {
  5344. var cp = Point.Empty;
  5345. var tv = new TextView () {
  5346. Width = Dim.Fill (),
  5347. Height = Dim.Fill (),
  5348. Text = "This is the first line.\nThis is the second line.\n"
  5349. };
  5350. tv.UnwrappedCursorPosition += (e) => {
  5351. cp = e;
  5352. };
  5353. Application.Top.Add (tv);
  5354. Application.Begin (Application.Top);
  5355. Assert.False (tv.WordWrap);
  5356. Assert.Equal (Point.Empty, tv.CursorPosition);
  5357. Assert.Equal (Point.Empty, cp);
  5358. TestHelpers.AssertDriverContentsWithFrameAre (@"
  5359. This is the first line.
  5360. This is the second line.
  5361. ", output);
  5362. tv.WordWrap = true;
  5363. tv.CursorPosition = new Point (12, 0);
  5364. tv.Redraw (tv.Bounds);
  5365. Assert.Equal (new Point (12, 0), tv.CursorPosition);
  5366. Assert.Equal (new Point (12, 0), cp);
  5367. TestHelpers.AssertDriverContentsWithFrameAre (@"
  5368. This is the first line.
  5369. This is the second line.
  5370. ", output);
  5371. ((FakeDriver)Application.Driver).SetBufferSize (6, 25);
  5372. tv.Redraw (tv.Bounds);
  5373. Assert.Equal (new Point (4, 2), tv.CursorPosition);
  5374. Assert.Equal (new Point (12, 0), cp);
  5375. TestHelpers.AssertDriverContentsWithFrameAre (@"
  5376. This
  5377. is
  5378. the
  5379. first
  5380. line.
  5381. This
  5382. is
  5383. the
  5384. secon
  5385. d
  5386. line.
  5387. ", output);
  5388. Assert.True (tv.ProcessKey (new KeyEvent (Key.CursorRight, new KeyModifiers ())));
  5389. tv.Redraw (tv.Bounds);
  5390. Assert.Equal (new Point (0, 3), tv.CursorPosition);
  5391. Assert.Equal (new Point (12, 0), cp);
  5392. TestHelpers.AssertDriverContentsWithFrameAre (@"
  5393. This
  5394. is
  5395. the
  5396. first
  5397. line.
  5398. This
  5399. is
  5400. the
  5401. secon
  5402. d
  5403. line.
  5404. ", output);
  5405. Assert.True (tv.ProcessKey (new KeyEvent (Key.CursorRight, new KeyModifiers ())));
  5406. tv.Redraw (tv.Bounds);
  5407. Assert.Equal (new Point (1, 3), tv.CursorPosition);
  5408. Assert.Equal (new Point (13, 0), cp);
  5409. TestHelpers.AssertDriverContentsWithFrameAre (@"
  5410. This
  5411. is
  5412. the
  5413. first
  5414. line.
  5415. This
  5416. is
  5417. the
  5418. secon
  5419. d
  5420. line.
  5421. ", output);
  5422. Assert.True (tv.MouseEvent (new MouseEvent () { X = 0, Y = 3, Flags = MouseFlags.Button1Pressed }));
  5423. tv.Redraw (tv.Bounds);
  5424. Assert.Equal (new Point (0, 3), tv.CursorPosition);
  5425. Assert.Equal (new Point (12, 0), cp);
  5426. TestHelpers.AssertDriverContentsWithFrameAre (@"
  5427. This
  5428. is
  5429. the
  5430. first
  5431. line.
  5432. This
  5433. is
  5434. the
  5435. secon
  5436. d
  5437. line.
  5438. ", output);
  5439. }
  5440. [Fact]
  5441. [AutoInitShutdown]
  5442. public void DeleteTextBackwards_WordWrap_False_Return_Undo ()
  5443. {
  5444. const string text = "This is the first line.\nThis is the second line.\n";
  5445. var tv = new TextView () {
  5446. Width = Dim.Fill (),
  5447. Height = Dim.Fill (),
  5448. Text = text
  5449. };
  5450. var envText = tv.Text;
  5451. Application.Top.Add (tv);
  5452. Application.Begin (Application.Top);
  5453. Assert.False (tv.WordWrap);
  5454. Assert.Equal (Point.Empty, tv.CursorPosition);
  5455. TestHelpers.AssertDriverContentsWithFrameAre (@"
  5456. This is the first line.
  5457. This is the second line.
  5458. ", output);
  5459. tv.CursorPosition = new Point (3, 0);
  5460. Assert.Equal (new Point (3, 0), tv.CursorPosition);
  5461. Assert.True (tv.ProcessKey (new KeyEvent (Key.Backspace, new KeyModifiers ())));
  5462. tv.Redraw (tv.Bounds);
  5463. Assert.Equal (new Point (2, 0), tv.CursorPosition);
  5464. TestHelpers.AssertDriverContentsWithFrameAre (@"
  5465. Ths is the first line.
  5466. This is the second line.
  5467. ", output);
  5468. tv.CursorPosition = new Point (0, 1);
  5469. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  5470. Assert.True (tv.ProcessKey (new KeyEvent (Key.Backspace, new KeyModifiers ())));
  5471. tv.Redraw (tv.Bounds);
  5472. Assert.Equal (new Point (22, 0), tv.CursorPosition);
  5473. TestHelpers.AssertDriverContentsWithFrameAre (@"
  5474. Ths is the first line.This is the second line.
  5475. ", output);
  5476. Assert.True (tv.ProcessKey (new KeyEvent (Key.Enter, new KeyModifiers ())));
  5477. tv.Redraw (tv.Bounds);
  5478. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  5479. TestHelpers.AssertDriverContentsWithFrameAre (@"
  5480. Ths is the first line.
  5481. This is the second line.
  5482. ", output);
  5483. while (tv.Text != envText) {
  5484. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  5485. }
  5486. Assert.Equal (envText, tv.Text);
  5487. Assert.Equal (new Point (3, 0), tv.CursorPosition);
  5488. Assert.False (tv.IsDirty);
  5489. }
  5490. [Fact]
  5491. [AutoInitShutdown]
  5492. public void DeleteTextBackwards_WordWrap_True_Return_Undo ()
  5493. {
  5494. const string text = "This is the first line.\nThis is the second line.\n";
  5495. var tv = new TextView () {
  5496. Width = Dim.Fill (),
  5497. Height = Dim.Fill (),
  5498. Text = text,
  5499. WordWrap = true
  5500. };
  5501. var envText = tv.Text;
  5502. Application.Top.Add (tv);
  5503. Application.Begin (Application.Top);
  5504. Assert.True (tv.WordWrap);
  5505. Assert.Equal (Point.Empty, tv.CursorPosition);
  5506. TestHelpers.AssertDriverContentsWithFrameAre (@"
  5507. This is the first line.
  5508. This is the second line.
  5509. ", output);
  5510. tv.CursorPosition = new Point (3, 0);
  5511. Assert.Equal (new Point (3, 0), tv.CursorPosition);
  5512. Assert.True (tv.ProcessKey (new KeyEvent (Key.Backspace, new KeyModifiers ())));
  5513. tv.Redraw (tv.Bounds);
  5514. Assert.Equal (new Point (2, 0), tv.CursorPosition);
  5515. TestHelpers.AssertDriverContentsWithFrameAre (@"
  5516. Ths is the first line.
  5517. This is the second line.
  5518. ", output);
  5519. tv.CursorPosition = new Point (0, 1);
  5520. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  5521. Assert.True (tv.ProcessKey (new KeyEvent (Key.Backspace, new KeyModifiers ())));
  5522. tv.Redraw (tv.Bounds);
  5523. Assert.Equal (new Point (22, 0), tv.CursorPosition);
  5524. TestHelpers.AssertDriverContentsWithFrameAre (@"
  5525. Ths is the first line.This is the second line.
  5526. ", output);
  5527. Assert.True (tv.ProcessKey (new KeyEvent (Key.Enter, new KeyModifiers ())));
  5528. tv.Redraw (tv.Bounds);
  5529. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  5530. TestHelpers.AssertDriverContentsWithFrameAre (@"
  5531. Ths is the first line.
  5532. This is the second line.
  5533. ", output);
  5534. while (tv.Text != envText) {
  5535. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  5536. }
  5537. Assert.Equal (envText, tv.Text);
  5538. Assert.Equal (new Point (3, 0), tv.CursorPosition);
  5539. Assert.False (tv.IsDirty);
  5540. }
  5541. [Fact]
  5542. [AutoInitShutdown]
  5543. public void DeleteTextForwards_WordWrap_False_Return_Undo ()
  5544. {
  5545. const string text = "This is the first line.\nThis is the second line.\n";
  5546. var tv = new TextView () {
  5547. Width = Dim.Fill (),
  5548. Height = Dim.Fill (),
  5549. Text = text
  5550. };
  5551. var envText = tv.Text;
  5552. Application.Top.Add (tv);
  5553. Application.Begin (Application.Top);
  5554. Assert.False (tv.WordWrap);
  5555. Assert.Equal (Point.Empty, tv.CursorPosition);
  5556. TestHelpers.AssertDriverContentsWithFrameAre (@"
  5557. This is the first line.
  5558. This is the second line.
  5559. ", output);
  5560. tv.CursorPosition = new Point (2, 0);
  5561. Assert.Equal (new Point (2, 0), tv.CursorPosition);
  5562. Assert.True (tv.ProcessKey (new KeyEvent (Key.DeleteChar, new KeyModifiers ())));
  5563. tv.Redraw (tv.Bounds);
  5564. Assert.Equal (new Point (2, 0), tv.CursorPosition);
  5565. TestHelpers.AssertDriverContentsWithFrameAre (@"
  5566. Ths is the first line.
  5567. This is the second line.
  5568. ", output);
  5569. tv.CursorPosition = new Point (22, 0);
  5570. Assert.Equal (new Point (22, 0), tv.CursorPosition);
  5571. Assert.True (tv.ProcessKey (new KeyEvent (Key.DeleteChar, new KeyModifiers ())));
  5572. tv.Redraw (tv.Bounds);
  5573. Assert.Equal (new Point (22, 0), tv.CursorPosition);
  5574. TestHelpers.AssertDriverContentsWithFrameAre (@"
  5575. Ths is the first line.This is the second line.
  5576. ", output);
  5577. Assert.True (tv.ProcessKey (new KeyEvent (Key.Enter, new KeyModifiers ())));
  5578. tv.Redraw (tv.Bounds);
  5579. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  5580. TestHelpers.AssertDriverContentsWithFrameAre (@"
  5581. Ths is the first line.
  5582. This is the second line.
  5583. ", output);
  5584. while (tv.Text != envText) {
  5585. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  5586. }
  5587. Assert.Equal (envText, tv.Text);
  5588. Assert.Equal (new Point (2, 0), tv.CursorPosition);
  5589. Assert.False (tv.IsDirty);
  5590. }
  5591. [Fact]
  5592. [AutoInitShutdown]
  5593. public void DeleteTextForwards_WordWrap_True_Return_Undo ()
  5594. {
  5595. const string text = "This is the first line.\nThis is the second line.\n";
  5596. var tv = new TextView () {
  5597. Width = Dim.Fill (),
  5598. Height = Dim.Fill (),
  5599. Text = text,
  5600. WordWrap = true
  5601. };
  5602. var envText = tv.Text;
  5603. Application.Top.Add (tv);
  5604. Application.Begin (Application.Top);
  5605. Assert.True (tv.WordWrap);
  5606. Assert.Equal (Point.Empty, tv.CursorPosition);
  5607. TestHelpers.AssertDriverContentsWithFrameAre (@"
  5608. This is the first line.
  5609. This is the second line.
  5610. ", output);
  5611. tv.CursorPosition = new Point (2, 0);
  5612. Assert.Equal (new Point (2, 0), tv.CursorPosition);
  5613. Assert.True (tv.ProcessKey (new KeyEvent (Key.DeleteChar, new KeyModifiers ())));
  5614. tv.Redraw (tv.Bounds);
  5615. Assert.Equal (new Point (2, 0), tv.CursorPosition);
  5616. TestHelpers.AssertDriverContentsWithFrameAre (@"
  5617. Ths is the first line.
  5618. This is the second line.
  5619. ", output);
  5620. tv.CursorPosition = new Point (22, 0);
  5621. Assert.Equal (new Point (22, 0), tv.CursorPosition);
  5622. Assert.True (tv.ProcessKey (new KeyEvent (Key.DeleteChar, new KeyModifiers ())));
  5623. tv.Redraw (tv.Bounds);
  5624. Assert.Equal (new Point (22, 0), tv.CursorPosition);
  5625. TestHelpers.AssertDriverContentsWithFrameAre (@"
  5626. Ths is the first line.This is the second line.
  5627. ", output);
  5628. Assert.True (tv.ProcessKey (new KeyEvent (Key.Enter, new KeyModifiers ())));
  5629. tv.Redraw (tv.Bounds);
  5630. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  5631. TestHelpers.AssertDriverContentsWithFrameAre (@"
  5632. Ths is the first line.
  5633. This is the second line.
  5634. ", output);
  5635. while (tv.Text != envText) {
  5636. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  5637. }
  5638. Assert.Equal (envText, tv.Text);
  5639. Assert.Equal (new Point (2, 0), tv.CursorPosition);
  5640. Assert.False (tv.IsDirty);
  5641. }
  5642. [Fact]
  5643. [InitShutdown]
  5644. public void TextView_InsertText_Newline_LF ()
  5645. {
  5646. var tv = new TextView {
  5647. Width = 10,
  5648. Height = 10,
  5649. };
  5650. tv.InsertText ("\naaa\nbbb");
  5651. var p = Environment.OSVersion.Platform;
  5652. if (p == PlatformID.Win32NT || p == PlatformID.Win32S || p == PlatformID.Win32Windows) {
  5653. Assert.Equal ("\r\naaa\r\nbbb", tv.Text);
  5654. } else {
  5655. Assert.Equal ("\naaa\nbbb", tv.Text);
  5656. }
  5657. Assert.Equal ($"{Environment.NewLine}aaa{Environment.NewLine}bbb", tv.Text);
  5658. var win = new Window ();
  5659. win.Add (tv);
  5660. Application.Top.Add (win);
  5661. Application.Begin (Application.Top);
  5662. ((FakeDriver)Application.Driver).SetBufferSize (15, 15);
  5663. Application.Refresh ();
  5664. //this passes
  5665. var pos = TestHelpers.AssertDriverContentsWithFrameAre (
  5666. @"
  5667. ┌─────────────┐
  5668. │ │
  5669. │aaa │
  5670. │bbb │
  5671. │ │
  5672. │ │
  5673. │ │
  5674. │ │
  5675. │ │
  5676. │ │
  5677. │ │
  5678. │ │
  5679. │ │
  5680. │ │
  5681. └─────────────┘", output);
  5682. Assert.Equal (new Rect (0, 0, 15, 15), pos);
  5683. Assert.True (tv.Used);
  5684. tv.Used = false;
  5685. tv.CursorPosition = new Point (0, 0);
  5686. tv.InsertText ("\naaa\nbbb");
  5687. Application.Refresh ();
  5688. TestHelpers.AssertDriverContentsWithFrameAre (
  5689. @"
  5690. ┌─────────────┐
  5691. │ │
  5692. │aaa │
  5693. │bbb │
  5694. │aaa │
  5695. │bbb │
  5696. │ │
  5697. │ │
  5698. │ │
  5699. │ │
  5700. │ │
  5701. │ │
  5702. │ │
  5703. │ │
  5704. └─────────────┘", output);
  5705. }
  5706. [Fact]
  5707. [InitShutdown]
  5708. public void TextView_InsertText_Newline_CRLF ()
  5709. {
  5710. var tv = new TextView {
  5711. Width = 10,
  5712. Height = 10,
  5713. };
  5714. tv.InsertText ("\r\naaa\r\nbbb");
  5715. var p = Environment.OSVersion.Platform;
  5716. if (p == PlatformID.Win32NT || p == PlatformID.Win32S || p == PlatformID.Win32Windows) {
  5717. Assert.Equal ("\r\naaa\r\nbbb", tv.Text);
  5718. } else {
  5719. Assert.Equal ("\naaa\nbbb", tv.Text);
  5720. }
  5721. Assert.Equal ($"{Environment.NewLine}aaa{Environment.NewLine}bbb", tv.Text);
  5722. var win = new Window ();
  5723. win.Add (tv);
  5724. Application.Top.Add (win);
  5725. Application.Begin (Application.Top);
  5726. ((FakeDriver)Application.Driver).SetBufferSize (15, 15);
  5727. Application.Refresh ();
  5728. //this passes
  5729. var pos = TestHelpers.AssertDriverContentsWithFrameAre (
  5730. @"
  5731. ┌─────────────┐
  5732. │ │
  5733. │aaa │
  5734. │bbb │
  5735. │ │
  5736. │ │
  5737. │ │
  5738. │ │
  5739. │ │
  5740. │ │
  5741. │ │
  5742. │ │
  5743. │ │
  5744. │ │
  5745. └─────────────┘", output);
  5746. Assert.Equal (new Rect (0, 0, 15, 15), pos);
  5747. Assert.True (tv.Used);
  5748. tv.Used = false;
  5749. tv.CursorPosition = new Point (0, 0);
  5750. tv.InsertText ("\r\naaa\r\nbbb");
  5751. Application.Refresh ();
  5752. TestHelpers.AssertDriverContentsWithFrameAre (
  5753. @"
  5754. ┌─────────────┐
  5755. │ │
  5756. │aaa │
  5757. │bbb │
  5758. │aaa │
  5759. │bbb │
  5760. │ │
  5761. │ │
  5762. │ │
  5763. │ │
  5764. │ │
  5765. │ │
  5766. │ │
  5767. │ │
  5768. └─────────────┘", output);
  5769. }
  5770. [Fact, AutoInitShutdown]
  5771. public void ContentsChanged_Event_NoFires_On_CursorPosition ()
  5772. {
  5773. var eventcount = 0;
  5774. var tv = new TextView {
  5775. Width = 50,
  5776. Height = 10,
  5777. };
  5778. tv.ContentsChanged += (e) => {
  5779. eventcount++;
  5780. };
  5781. Assert.Equal (0, eventcount);
  5782. tv.CursorPosition = new Point (0, 0);
  5783. Assert.Equal (0, eventcount);
  5784. }
  5785. [Fact, AutoInitShutdown]
  5786. public void ContentsChanged_Event_Fires_On_InsertText ()
  5787. {
  5788. var eventcount = 0;
  5789. var tv = new TextView {
  5790. Width = 50,
  5791. Height = 10,
  5792. };
  5793. tv.CursorPosition = new Point (0, 0);
  5794. tv.ContentsChanged += (e) => {
  5795. eventcount++;
  5796. };
  5797. Assert.Equal (0, eventcount);
  5798. tv.InsertText ("a");
  5799. Assert.Equal (1, eventcount);
  5800. tv.CursorPosition = new Point (0, 0);
  5801. tv.InsertText ("bcd");
  5802. Assert.Equal (4, eventcount);
  5803. tv.InsertText ("e");
  5804. Assert.Equal (5, eventcount);
  5805. tv.InsertText ("\n");
  5806. Assert.Equal (6, eventcount);
  5807. tv.InsertText ("1234");
  5808. Assert.Equal (10, eventcount);
  5809. }
  5810. [Fact, AutoInitShutdown]
  5811. public void ContentsChanged_Event_Fires_On_Init ()
  5812. {
  5813. Application.Iteration += () => {
  5814. Application.RequestStop ();
  5815. };
  5816. var expectedRow = 0;
  5817. var expectedCol = 0;
  5818. var eventcount = 0;
  5819. var tv = new TextView {
  5820. Width = 50,
  5821. Height = 10,
  5822. };
  5823. tv.ContentsChanged += (e) => {
  5824. eventcount++;
  5825. Assert.Equal (expectedRow, e.Row);
  5826. Assert.Equal (expectedCol, e.Col);
  5827. };
  5828. Application.Top.Add (tv);
  5829. Application.Begin (Application.Top);
  5830. Assert.Equal (1, eventcount);
  5831. }
  5832. [Fact, AutoInitShutdown]
  5833. public void ContentsChanged_Event_Fires_On_Set_Text ()
  5834. {
  5835. Application.Iteration += () => {
  5836. Application.RequestStop ();
  5837. };
  5838. var eventcount = 0;
  5839. var expectedRow = 0;
  5840. var expectedCol = 0;
  5841. var tv = new TextView {
  5842. Width = 50,
  5843. Height = 10,
  5844. // you'd think col would be 3, but it's 0 because TextView sets
  5845. // row/col = 0 when you set Text
  5846. Text = "abc",
  5847. };
  5848. tv.ContentsChanged += (e) => {
  5849. eventcount++;
  5850. Assert.Equal (expectedRow, e.Row);
  5851. Assert.Equal (expectedCol, e.Col);
  5852. };
  5853. Assert.Equal ("abc", tv.Text);
  5854. Application.Top.Add (tv);
  5855. var rs = Application.Begin (Application.Top);
  5856. Assert.Equal (1, eventcount); // for Initialize
  5857. expectedCol = 0;
  5858. tv.Text = "defg";
  5859. Assert.Equal (2, eventcount); // for set Text = "defg"
  5860. }
  5861. [Fact, AutoInitShutdown]
  5862. public void ContentsChanged_Event_Fires_On_Typing ()
  5863. {
  5864. Application.Iteration += () => {
  5865. Application.RequestStop ();
  5866. };
  5867. var eventcount = 0;
  5868. var expectedRow = 0;
  5869. var expectedCol = 0;
  5870. var tv = new TextView {
  5871. Width = 50,
  5872. Height = 10,
  5873. };
  5874. tv.ContentsChanged += (e) => {
  5875. eventcount++;
  5876. Assert.Equal (expectedRow, e.Row);
  5877. Assert.Equal (expectedCol, e.Col);
  5878. };
  5879. Application.Top.Add (tv);
  5880. var rs = Application.Begin (Application.Top);
  5881. Assert.Equal (1, eventcount); // for Initialize
  5882. expectedCol = 0;
  5883. tv.Text = "ay";
  5884. Assert.Equal (2, eventcount);
  5885. expectedCol = 1;
  5886. tv.ProcessKey (new KeyEvent (Key.Y, new KeyModifiers ()));
  5887. Assert.Equal (3, eventcount);
  5888. Assert.Equal ("Yay", tv.Text.ToString ());
  5889. }
  5890. [Fact, InitShutdown]
  5891. public void ContentsChanged_Event_Fires_Using_Kill_Delete_Tests ()
  5892. {
  5893. var eventcount = 0;
  5894. _textView.ContentsChanged += (e) => {
  5895. eventcount++;
  5896. };
  5897. var expectedEventCount = 1;
  5898. Kill_Delete_WordForward ();
  5899. Assert.Equal (expectedEventCount, eventcount); // for Initialize
  5900. expectedEventCount += 1;
  5901. Kill_Delete_WordBackward ();
  5902. Assert.Equal (expectedEventCount, eventcount);
  5903. expectedEventCount += 1;
  5904. Kill_To_End_Delete_Forwards_And_Copy_To_The_Clipboard ();
  5905. Assert.Equal (expectedEventCount, eventcount);
  5906. expectedEventCount += 1;
  5907. Kill_To_Start_Delete_Backwards_And_Copy_To_The_Clipboard ();
  5908. Assert.Equal (expectedEventCount, eventcount);
  5909. }
  5910. [Fact, InitShutdown]
  5911. public void ContentsChanged_Event_Fires_Using_Copy_Or_Cut_Tests ()
  5912. {
  5913. var eventcount = 0;
  5914. _textView.ContentsChanged += (e) => {
  5915. eventcount++;
  5916. };
  5917. var expectedEventCount = 1;
  5918. // reset
  5919. _textView.Text = InitShutdown.txt;
  5920. Assert.Equal (expectedEventCount, eventcount);
  5921. expectedEventCount += 3;
  5922. Copy_Or_Cut_And_Paste_With_No_Selection ();
  5923. Assert.Equal (expectedEventCount, eventcount);
  5924. // reset
  5925. expectedEventCount += 1;
  5926. _textView.Text = InitShutdown.txt;
  5927. Assert.Equal (expectedEventCount, eventcount);
  5928. expectedEventCount += 3;
  5929. Copy_Or_Cut_And_Paste_With_Selection ();
  5930. Assert.Equal (expectedEventCount, eventcount);
  5931. // reset
  5932. expectedEventCount += 1;
  5933. _textView.Text = InitShutdown.txt;
  5934. Assert.Equal (expectedEventCount, eventcount);
  5935. expectedEventCount += 1;
  5936. Copy_Or_Cut_Not_Null_If_Has_Selection ();
  5937. Assert.Equal (expectedEventCount, eventcount);
  5938. // reset
  5939. expectedEventCount += 1;
  5940. _textView.Text = InitShutdown.txt;
  5941. Assert.Equal (expectedEventCount, eventcount);
  5942. expectedEventCount += 1;
  5943. Copy_Or_Cut_Null_If_No_Selection ();
  5944. Assert.Equal (expectedEventCount, eventcount);
  5945. // reset
  5946. expectedEventCount += 1;
  5947. _textView.Text = InitShutdown.txt;
  5948. Assert.Equal (expectedEventCount, eventcount);
  5949. expectedEventCount += 4;
  5950. Copy_Without_Selection ();
  5951. Assert.Equal (expectedEventCount, eventcount);
  5952. // reset
  5953. expectedEventCount += 1;
  5954. _textView.Text = InitShutdown.txt;
  5955. Assert.Equal (expectedEventCount, eventcount);
  5956. expectedEventCount += 4;
  5957. Copy_Without_Selection ();
  5958. Assert.Equal (expectedEventCount, eventcount);
  5959. }
  5960. [Fact, InitShutdown]
  5961. public void ContentsChanged_Event_Fires_On_Undo_Redo ()
  5962. {
  5963. var eventcount = 0;
  5964. var expectedEventCount = 0;
  5965. _textView.ContentsChanged += (e) => {
  5966. eventcount++;
  5967. };
  5968. expectedEventCount++;
  5969. _textView.Text = "This is the first line.\nThis is the second line.\nThis is the third line.";
  5970. Assert.Equal (expectedEventCount, eventcount);
  5971. expectedEventCount++;
  5972. Assert.True (_textView.ProcessKey (new KeyEvent (Key.Enter, new KeyModifiers ())));
  5973. Assert.Equal (expectedEventCount, eventcount);
  5974. // Undo
  5975. expectedEventCount++;
  5976. Assert.True (_textView.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  5977. Assert.Equal (expectedEventCount, eventcount);
  5978. // Redo
  5979. expectedEventCount++;
  5980. Assert.True (_textView.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  5981. Assert.Equal (expectedEventCount, eventcount);
  5982. // Undo
  5983. expectedEventCount++;
  5984. Assert.True (_textView.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  5985. Assert.Equal (expectedEventCount, eventcount);
  5986. // Redo
  5987. expectedEventCount++;
  5988. Assert.True (_textView.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  5989. Assert.Equal (expectedEventCount, eventcount);
  5990. }
  5991. [Fact]
  5992. public void ContentsChanged_Event_Fires_ClearHistoryChanges ()
  5993. {
  5994. var eventcount = 0;
  5995. var text = "This is the first line.\nThis is the second line.\nThis is the third line.";
  5996. var tv = new TextView {
  5997. Width = 50,
  5998. Height = 10,
  5999. Text = text,
  6000. };
  6001. tv.ContentsChanged += (e) => {
  6002. eventcount++;
  6003. };
  6004. Assert.True (tv.ProcessKey (new KeyEvent (Key.Enter, new KeyModifiers ())));
  6005. 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);
  6006. Assert.Equal (4, tv.Lines);
  6007. var expectedEventCount = 1; // for ENTER key
  6008. Assert.Equal (expectedEventCount, eventcount);
  6009. tv.ClearHistoryChanges ();
  6010. expectedEventCount = 2;
  6011. Assert.Equal (expectedEventCount, eventcount);
  6012. }
  6013. [Fact]
  6014. public void ContentsChanged_Event_Fires_LoadStream_By_Calling_HistoryText_Clear ()
  6015. {
  6016. var eventcount = 0;
  6017. var tv = new TextView {
  6018. Width = 50,
  6019. Height = 10,
  6020. };
  6021. tv.ContentsChanged += (e) => {
  6022. eventcount++;
  6023. };
  6024. var text = "This is the first line.\r\nThis is the second line.\r\n";
  6025. tv.LoadStream (new System.IO.MemoryStream (System.Text.Encoding.ASCII.GetBytes (text)));
  6026. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}", tv.Text);
  6027. Assert.Equal (1, eventcount);
  6028. }
  6029. [Fact]
  6030. public void ContentsChanged_Event_Fires_On_LoadFile_By_Calling_HistoryText_Clear ()
  6031. {
  6032. var eventcount = 0;
  6033. var tv = new TextView {
  6034. Width = 50,
  6035. Height = 10,
  6036. };
  6037. tv.ContentsChanged += (e) => {
  6038. eventcount++;
  6039. };
  6040. var fileName = "textview.txt";
  6041. System.IO.File.WriteAllText (fileName, "This is the first line.\r\nThis is the second line.\r\n");
  6042. tv.LoadFile (fileName);
  6043. Assert.Equal (1, eventcount);
  6044. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}", tv.Text);
  6045. }
  6046. }
  6047. }