TextViewTests.cs 260 KB

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