TextViewTests.cs 345 KB

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