TextViewTests.cs 271 KB

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