TextViewTests.cs 266 KB

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