TextViewTests.cs 260 KB

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