TextViewTests.cs 266 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836
  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.LayoutSubviews ();
  1908. tv.Redraw (tv.Bounds);
  1909. TestHelpers.AssertDriverContentsWithFrameAre (@"
  1910. This is
  1911. the
  1912. first
  1913. line.
  1914. This is
  1915. the
  1916. second
  1917. line.
  1918. ", output);
  1919. }
  1920. [Fact]
  1921. [AutoInitShutdown]
  1922. public void WordWrap_Deleting_Backwards ()
  1923. {
  1924. var tv = new TextView () {
  1925. Width = 5,
  1926. Height = 2,
  1927. WordWrap = true,
  1928. Text = "aaaa"
  1929. };
  1930. Application.Top.Add (tv);
  1931. Application.Begin (Application.Top);
  1932. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  1933. Assert.Equal (0, tv.LeftColumn);
  1934. TestHelpers.AssertDriverContentsAre (@"
  1935. aaaa
  1936. ", output);
  1937. tv.CursorPosition = new Point (5, 0);
  1938. Assert.True (tv.ProcessKey (new KeyEvent (Key.Backspace, new KeyModifiers ())));
  1939. Application.Refresh ();
  1940. Assert.Equal (0, tv.LeftColumn);
  1941. TestHelpers.AssertDriverContentsAre (@"
  1942. aaa
  1943. ", output);
  1944. Assert.True (tv.ProcessKey (new KeyEvent (Key.Backspace, new KeyModifiers ())));
  1945. Application.Refresh ();
  1946. Assert.Equal (0, tv.LeftColumn);
  1947. TestHelpers.AssertDriverContentsAre (@"
  1948. aa
  1949. ", output);
  1950. Assert.True (tv.ProcessKey (new KeyEvent (Key.Backspace, new KeyModifiers ())));
  1951. Application.Refresh ();
  1952. Assert.Equal (0, tv.LeftColumn);
  1953. TestHelpers.AssertDriverContentsAre (@"
  1954. a
  1955. ", output);
  1956. Assert.True (tv.ProcessKey (new KeyEvent (Key.Backspace, new KeyModifiers ())));
  1957. Application.Refresh ();
  1958. Assert.Equal (0, tv.LeftColumn);
  1959. TestHelpers.AssertDriverContentsAre (@"
  1960. ", output);
  1961. Assert.True (tv.ProcessKey (new KeyEvent (Key.Backspace, new KeyModifiers ())));
  1962. Application.Refresh ();
  1963. Assert.Equal (0, tv.LeftColumn);
  1964. TestHelpers.AssertDriverContentsAre (@"
  1965. ", output);
  1966. }
  1967. [Fact]
  1968. [TextViewTestsAutoInitShutdown]
  1969. public void WordWrap_ReadOnly_CursorPosition_SelectedText_Copy ()
  1970. {
  1971. // 0123456789
  1972. var text = "This is the first line.\nThis is the second line.\n";
  1973. var tv = new TextView () { Width = 11, Height = 9 };
  1974. tv.Text = text;
  1975. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}", tv.Text);
  1976. tv.WordWrap = true;
  1977. Application.Top.Add (tv);
  1978. Application.Top.LayoutSubviews ();
  1979. tv.Redraw (tv.Bounds);
  1980. TestHelpers.AssertDriverContentsWithFrameAre (@"
  1981. This is
  1982. the first
  1983. line.
  1984. This is
  1985. the
  1986. second
  1987. line.
  1988. ", output);
  1989. tv.ReadOnly = true;
  1990. tv.CursorPosition = new Point (6, 2);
  1991. Assert.Equal (new Point (5, 2), tv.CursorPosition);
  1992. Application.Top.LayoutSubviews ();
  1993. tv.Redraw (tv.Bounds);
  1994. TestHelpers.AssertDriverContentsWithFrameAre (@"
  1995. This is
  1996. the first
  1997. line.
  1998. This is
  1999. the
  2000. second
  2001. line.
  2002. ", output);
  2003. tv.SelectionStartRow = 0;
  2004. tv.SelectionStartColumn = 0;
  2005. Assert.Equal ("This is the first line.", tv.SelectedText);
  2006. tv.Copy ();
  2007. Assert.Equal ("This is the first line.", Clipboard.Contents);
  2008. }
  2009. [Fact]
  2010. public void Internal_Tests ()
  2011. {
  2012. var txt = "This is a text.";
  2013. var txtRunes = TextModel.ToRunes (txt);
  2014. Assert.Equal (txt.Length, txtRunes.Count);
  2015. Assert.Equal ('T', txtRunes [0]);
  2016. Assert.Equal ('h', txtRunes [1]);
  2017. Assert.Equal ('i', txtRunes [2]);
  2018. Assert.Equal ('s', txtRunes [3]);
  2019. Assert.Equal (' ', txtRunes [4]);
  2020. Assert.Equal ('i', txtRunes [5]);
  2021. Assert.Equal ('s', txtRunes [6]);
  2022. Assert.Equal (' ', txtRunes [7]);
  2023. Assert.Equal ('a', txtRunes [8]);
  2024. Assert.Equal (' ', txtRunes [9]);
  2025. Assert.Equal ('t', txtRunes [10]);
  2026. Assert.Equal ('e', txtRunes [11]);
  2027. Assert.Equal ('x', txtRunes [12]);
  2028. Assert.Equal ('t', txtRunes [13]);
  2029. Assert.Equal ('.', txtRunes [^1]);
  2030. int col = 0;
  2031. Assert.True (TextModel.SetCol (ref col, 80, 79));
  2032. Assert.False (TextModel.SetCol (ref col, 80, 80));
  2033. Assert.Equal (79, col);
  2034. var start = 0;
  2035. var x = 8;
  2036. Assert.Equal (8, TextModel.GetColFromX (txtRunes, start, x));
  2037. Assert.Equal ('a', txtRunes [start + x]);
  2038. start = 1;
  2039. x = 7;
  2040. Assert.Equal (7, TextModel.GetColFromX (txtRunes, start, x));
  2041. Assert.Equal ('a', txtRunes [start + x]);
  2042. Assert.Equal ((15, 15), TextModel.DisplaySize (txtRunes));
  2043. Assert.Equal ((6, 6), TextModel.DisplaySize (txtRunes, 1, 7));
  2044. Assert.Equal (0, TextModel.CalculateLeftColumn (txtRunes, 0, 7, 8));
  2045. Assert.Equal (1, TextModel.CalculateLeftColumn (txtRunes, 0, 8, 8));
  2046. Assert.Equal (2, TextModel.CalculateLeftColumn (txtRunes, 0, 9, 8));
  2047. var tm = new TextModel ();
  2048. tm.AddLine (0, TextModel.ToRunes ("This is first line."));
  2049. tm.AddLine (1, TextModel.ToRunes ("This is last line."));
  2050. Assert.Equal ((new Point (2, 0), true), tm.FindNextText ("is", out bool gaveFullTurn));
  2051. Assert.False (gaveFullTurn);
  2052. Assert.Equal ((new Point (5, 0), true), tm.FindNextText ("is", out gaveFullTurn));
  2053. Assert.False (gaveFullTurn);
  2054. Assert.Equal ((new Point (2, 1), true), tm.FindNextText ("is", out gaveFullTurn));
  2055. Assert.False (gaveFullTurn);
  2056. Assert.Equal ((new Point (5, 1), true), tm.FindNextText ("is", out gaveFullTurn));
  2057. Assert.False (gaveFullTurn);
  2058. Assert.Equal ((new Point (2, 0), true), tm.FindNextText ("is", out gaveFullTurn));
  2059. Assert.True (gaveFullTurn);
  2060. tm.ResetContinuousFind (new Point (0, 0));
  2061. Assert.Equal ((new Point (5, 1), true), tm.FindPreviousText ("is", out gaveFullTurn));
  2062. Assert.False (gaveFullTurn);
  2063. Assert.Equal ((new Point (2, 1), true), tm.FindPreviousText ("is", out gaveFullTurn));
  2064. Assert.False (gaveFullTurn);
  2065. Assert.Equal ((new Point (5, 0), true), tm.FindPreviousText ("is", out gaveFullTurn));
  2066. Assert.False (gaveFullTurn);
  2067. Assert.Equal ((new Point (2, 0), true), tm.FindPreviousText ("is", out gaveFullTurn));
  2068. Assert.False (gaveFullTurn);
  2069. Assert.Equal ((new Point (5, 1), true), tm.FindPreviousText ("is", out gaveFullTurn));
  2070. Assert.True (gaveFullTurn);
  2071. Assert.Equal ((new Point (9, 1), true), tm.ReplaceAllText ("is", false, false, "really"));
  2072. Assert.Equal (TextModel.ToRunes ("Threally really first line."), tm.GetLine (0));
  2073. Assert.Equal (TextModel.ToRunes ("Threally really last line."), tm.GetLine (1));
  2074. tm = new TextModel ();
  2075. tm.AddLine (0, TextModel.ToRunes ("This is first line."));
  2076. tm.AddLine (1, TextModel.ToRunes ("This is last line."));
  2077. Assert.Equal ((new Point (5, 1), true), tm.ReplaceAllText ("is", false, true, "really"));
  2078. Assert.Equal (TextModel.ToRunes ("This really first line."), tm.GetLine (0));
  2079. Assert.Equal (TextModel.ToRunes ("This really last line."), tm.GetLine (1));
  2080. }
  2081. [Fact]
  2082. [TextViewTestsAutoInitShutdown]
  2083. public void BottomOffset_Sets_To_Zero_Adjust_TopRow ()
  2084. {
  2085. string text = "";
  2086. for (int i = 0; i < 12; i++) {
  2087. text += $"This is the line {i}\n";
  2088. }
  2089. var tv = new TextView () { Width = 10, Height = 10, BottomOffset = 1 };
  2090. tv.Text = text;
  2091. tv.ProcessKey (new KeyEvent (Key.CtrlMask | Key.End, new KeyModifiers ()));
  2092. Assert.Equal (4, tv.TopRow);
  2093. Assert.Equal (1, tv.BottomOffset);
  2094. tv.BottomOffset = 0;
  2095. Assert.Equal (3, tv.TopRow);
  2096. Assert.Equal (0, tv.BottomOffset);
  2097. tv.BottomOffset = 2;
  2098. Assert.Equal (5, tv.TopRow);
  2099. Assert.Equal (2, tv.BottomOffset);
  2100. tv.BottomOffset = 0;
  2101. Assert.Equal (3, tv.TopRow);
  2102. Assert.Equal (0, tv.BottomOffset);
  2103. }
  2104. [Fact]
  2105. [TextViewTestsAutoInitShutdown]
  2106. public void RightOffset_Sets_To_Zero_Adjust_leftColumn ()
  2107. {
  2108. string text = "";
  2109. for (int i = 0; i < 12; i++) {
  2110. text += $"{i.ToString () [^1]}";
  2111. }
  2112. var tv = new TextView () { Width = 10, Height = 10, RightOffset = 1 };
  2113. tv.Text = text;
  2114. tv.ProcessKey (new KeyEvent (Key.End, new KeyModifiers ()));
  2115. Assert.Equal (4, tv.LeftColumn);
  2116. Assert.Equal (1, tv.RightOffset);
  2117. tv.RightOffset = 0;
  2118. Assert.Equal (3, tv.LeftColumn);
  2119. Assert.Equal (0, tv.RightOffset);
  2120. tv.RightOffset = 2;
  2121. Assert.Equal (5, tv.LeftColumn);
  2122. Assert.Equal (2, tv.RightOffset);
  2123. tv.RightOffset = 0;
  2124. Assert.Equal (3, tv.LeftColumn);
  2125. Assert.Equal (0, tv.RightOffset);
  2126. }
  2127. [Fact]
  2128. [TextViewTestsAutoInitShutdown]
  2129. public void TextView_SpaceHandling ()
  2130. {
  2131. var tv = new TextView () {
  2132. Width = 10,
  2133. Text = " "
  2134. };
  2135. MouseEvent ev = new MouseEvent () {
  2136. X = 0,
  2137. Y = 0,
  2138. Flags = MouseFlags.Button1DoubleClicked,
  2139. };
  2140. tv.MouseEvent (ev);
  2141. Assert.Equal (1, tv.SelectedLength);
  2142. ev = new MouseEvent () {
  2143. X = 1,
  2144. Y = 0,
  2145. Flags = MouseFlags.Button1DoubleClicked,
  2146. };
  2147. tv.MouseEvent (ev);
  2148. Assert.Equal (1, tv.SelectedLength);
  2149. }
  2150. [Fact]
  2151. [TextViewTestsAutoInitShutdown]
  2152. public void CanFocus_False_Wont_Focus_With_Mouse ()
  2153. {
  2154. var top = Application.Top;
  2155. var tv = new TextView () {
  2156. Width = Dim.Fill (),
  2157. CanFocus = false,
  2158. ReadOnly = true,
  2159. Text = "some text"
  2160. };
  2161. var fv = new FrameView ("I shouldn't get focus") {
  2162. Width = Dim.Fill (),
  2163. Height = Dim.Fill (),
  2164. CanFocus = false,
  2165. };
  2166. fv.Add (tv);
  2167. top.Add (fv);
  2168. Application.Begin (top);
  2169. Assert.False (tv.CanFocus);
  2170. Assert.False (tv.HasFocus);
  2171. Assert.False (fv.CanFocus);
  2172. Assert.False (fv.HasFocus);
  2173. tv.MouseEvent (new MouseEvent () {
  2174. X = 1,
  2175. Y = 0,
  2176. Flags = MouseFlags.Button1DoubleClicked
  2177. });
  2178. Assert.Empty (tv.SelectedText);
  2179. Assert.False (tv.CanFocus);
  2180. Assert.False (tv.HasFocus);
  2181. Assert.False (fv.CanFocus);
  2182. Assert.False (fv.HasFocus);
  2183. Assert.Throws<InvalidOperationException> (() => tv.CanFocus = true);
  2184. fv.CanFocus = true;
  2185. tv.CanFocus = true;
  2186. tv.MouseEvent (new MouseEvent () {
  2187. X = 1,
  2188. Y = 0,
  2189. Flags = MouseFlags.Button1DoubleClicked
  2190. });
  2191. Assert.Equal ("some ", tv.SelectedText);
  2192. Assert.True (tv.CanFocus);
  2193. Assert.True (tv.HasFocus);
  2194. Assert.True (fv.CanFocus);
  2195. Assert.True (fv.HasFocus);
  2196. fv.CanFocus = false;
  2197. tv.MouseEvent (new MouseEvent () {
  2198. X = 1,
  2199. Y = 0,
  2200. Flags = MouseFlags.Button1DoubleClicked
  2201. });
  2202. Assert.Equal ("some ", tv.SelectedText); // Setting CanFocus to false don't change the SelectedText
  2203. Assert.False (tv.CanFocus);
  2204. Assert.False (tv.HasFocus);
  2205. Assert.False (fv.CanFocus);
  2206. Assert.False (fv.HasFocus);
  2207. }
  2208. [Fact]
  2209. [TextViewTestsAutoInitShutdown]
  2210. public void DesiredCursorVisibility_Vertical_Navigation ()
  2211. {
  2212. string text = "";
  2213. for (int i = 0; i < 12; i++) {
  2214. text += $"This is the line {i}\n";
  2215. }
  2216. var tv = new TextView () { Width = 10, Height = 10 };
  2217. tv.Text = text;
  2218. Assert.Equal (0, tv.TopRow);
  2219. tv.PositionCursor ();
  2220. Assert.Equal (CursorVisibility.Default, tv.DesiredCursorVisibility);
  2221. for (int i = 0; i < 12; i++) {
  2222. tv.MouseEvent (new MouseEvent () {
  2223. Flags = MouseFlags.WheeledDown
  2224. });
  2225. tv.PositionCursor ();
  2226. Assert.Equal (i + 1, tv.TopRow);
  2227. Assert.Equal (CursorVisibility.Invisible, tv.DesiredCursorVisibility);
  2228. }
  2229. for (int i = 12; i > 0; i--) {
  2230. tv.MouseEvent (new MouseEvent () {
  2231. Flags = MouseFlags.WheeledUp
  2232. });
  2233. tv.PositionCursor ();
  2234. Assert.Equal (i - 1, tv.TopRow);
  2235. if (i - 1 == 0) {
  2236. Assert.Equal (CursorVisibility.Default, tv.DesiredCursorVisibility);
  2237. } else {
  2238. Assert.Equal (CursorVisibility.Invisible, tv.DesiredCursorVisibility);
  2239. }
  2240. }
  2241. }
  2242. [Fact]
  2243. [TextViewTestsAutoInitShutdown]
  2244. public void DesiredCursorVisibility_Horizontal_Navigation ()
  2245. {
  2246. string text = "";
  2247. for (int i = 0; i < 12; i++) {
  2248. text += $"{i.ToString () [^1]}";
  2249. }
  2250. var tv = new TextView () { Width = 10, Height = 10 };
  2251. tv.Text = text;
  2252. Assert.Equal (0, tv.LeftColumn);
  2253. tv.PositionCursor ();
  2254. Assert.Equal (CursorVisibility.Default, tv.DesiredCursorVisibility);
  2255. for (int i = 0; i < 12; i++) {
  2256. tv.MouseEvent (new MouseEvent () {
  2257. Flags = MouseFlags.WheeledRight
  2258. });
  2259. tv.PositionCursor ();
  2260. Assert.Equal (Math.Min (i + 1, 11), tv.LeftColumn);
  2261. Assert.Equal (CursorVisibility.Invisible, tv.DesiredCursorVisibility);
  2262. }
  2263. for (int i = 11; i > 0; i--) {
  2264. tv.MouseEvent (new MouseEvent () {
  2265. Flags = MouseFlags.WheeledLeft
  2266. });
  2267. tv.PositionCursor ();
  2268. Assert.Equal (i - 1, tv.LeftColumn);
  2269. if (i - 1 == 0) {
  2270. Assert.Equal (CursorVisibility.Default, tv.DesiredCursorVisibility);
  2271. } else {
  2272. Assert.Equal (CursorVisibility.Invisible, tv.DesiredCursorVisibility);
  2273. }
  2274. }
  2275. }
  2276. [Fact]
  2277. public void LeftColumn_Add_One_If_Text_Length_Is_Equal_To_Width ()
  2278. {
  2279. var tv = new TextView () {
  2280. Width = 10,
  2281. Text = "1234567890"
  2282. };
  2283. Assert.Equal (Point.Empty, tv.CursorPosition);
  2284. Assert.Equal (0, tv.LeftColumn);
  2285. tv.CursorPosition = new Point (9, 0);
  2286. Assert.Equal (new Point (9, 0), tv.CursorPosition);
  2287. Assert.Equal (0, tv.LeftColumn);
  2288. Assert.True (tv.ProcessKey (new KeyEvent (Key.CursorRight, new KeyModifiers ())));
  2289. tv.CursorPosition = new Point (10, 0);
  2290. Assert.Equal (new Point (10, 0), tv.CursorPosition);
  2291. Assert.Equal (1, tv.LeftColumn);
  2292. }
  2293. [Fact]
  2294. [AutoInitShutdown]
  2295. public void KeyBindings_Command ()
  2296. {
  2297. var text = "This is the first line.\nThis is the second line.\nThis is the third line.";
  2298. var tv = new TextView () {
  2299. Width = 10,
  2300. Height = 2,
  2301. Text = text
  2302. };
  2303. var top = Application.Top;
  2304. top.Add (tv);
  2305. Application.Begin (top);
  2306. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  2307. Assert.Equal (3, tv.Lines);
  2308. Assert.Equal (Point.Empty, tv.CursorPosition);
  2309. Assert.False (tv.ReadOnly);
  2310. Assert.True (tv.CanFocus);
  2311. tv.CanFocus = false;
  2312. Assert.True (tv.ProcessKey (new KeyEvent (Key.CursorLeft, new KeyModifiers ())));
  2313. tv.CanFocus = true;
  2314. Assert.False (tv.ProcessKey (new KeyEvent (Key.CursorLeft, new KeyModifiers ())));
  2315. Assert.True (tv.ProcessKey (new KeyEvent (Key.CursorRight, new KeyModifiers ())));
  2316. Assert.Equal (new Point (1, 0), tv.CursorPosition);
  2317. Assert.True (tv.ProcessKey (new KeyEvent (Key.End | Key.CtrlMask, new KeyModifiers ())));
  2318. Assert.Equal (2, tv.CurrentRow);
  2319. Assert.Equal (23, tv.CurrentColumn);
  2320. Assert.Equal (tv.CurrentColumn, tv.GetCurrentLine ().Count);
  2321. Assert.Equal (new Point (23, 2), tv.CursorPosition);
  2322. Assert.False (tv.ProcessKey (new KeyEvent (Key.CursorRight, new KeyModifiers ())));
  2323. Assert.NotNull (tv.Autocomplete);
  2324. Assert.Empty (tv.Autocomplete.AllSuggestions);
  2325. Assert.True (tv.ProcessKey (new KeyEvent (Key.F, new KeyModifiers ())));
  2326. tv.Redraw (tv.Bounds);
  2327. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.F", tv.Text);
  2328. Assert.Equal (new Point (24, 2), tv.CursorPosition);
  2329. Assert.Empty (tv.Autocomplete.Suggestions);
  2330. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  2331. tv.Redraw (tv.Bounds);
  2332. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  2333. Assert.Equal (new Point (23, 2), tv.CursorPosition);
  2334. Assert.Empty (tv.Autocomplete.Suggestions);
  2335. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  2336. tv.Redraw (tv.Bounds);
  2337. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.F", tv.Text);
  2338. Assert.Equal (new Point (24, 2), tv.CursorPosition);
  2339. Assert.Empty (tv.Autocomplete.Suggestions);
  2340. Assert.True (tv.ProcessKey (new KeyEvent (Key.Backspace, new KeyModifiers ())));
  2341. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  2342. Assert.Equal (new Point (23, 2), tv.CursorPosition);
  2343. tv.Autocomplete.AllSuggestions = Regex.Matches (tv.Text.ToString (), "\\w+")
  2344. .Select (s => s.Value)
  2345. .Distinct ().ToList ();
  2346. Assert.Equal (7, tv.Autocomplete.AllSuggestions.Count);
  2347. Assert.Equal ("This", tv.Autocomplete.AllSuggestions [0]);
  2348. Assert.Equal ("is", tv.Autocomplete.AllSuggestions [1]);
  2349. Assert.Equal ("the", tv.Autocomplete.AllSuggestions [2]);
  2350. Assert.Equal ("first", tv.Autocomplete.AllSuggestions [3]);
  2351. Assert.Equal ("line", tv.Autocomplete.AllSuggestions [4]);
  2352. Assert.Equal ("second", tv.Autocomplete.AllSuggestions [5]);
  2353. Assert.Equal ("third", tv.Autocomplete.AllSuggestions [^1]);
  2354. Assert.True (tv.ProcessKey (new KeyEvent (Key.F, new KeyModifiers ())));
  2355. tv.Redraw (tv.Bounds);
  2356. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.F", tv.Text);
  2357. Assert.Equal (new Point (24, 2), tv.CursorPosition);
  2358. Assert.Single (tv.Autocomplete.Suggestions);
  2359. Assert.Equal ("first", tv.Autocomplete.Suggestions [0]);
  2360. Assert.True (tv.ProcessKey (new KeyEvent (Key.Enter, new KeyModifiers ())));
  2361. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first", tv.Text);
  2362. Assert.Equal (new Point (28, 2), tv.CursorPosition);
  2363. Assert.Single (tv.Autocomplete.Suggestions);
  2364. Assert.Equal ("first", tv.Autocomplete.Suggestions [0]);
  2365. tv.Autocomplete.AllSuggestions = new List<string> ();
  2366. tv.Autocomplete.ClearSuggestions ();
  2367. Assert.Empty (tv.Autocomplete.AllSuggestions);
  2368. Assert.Empty (tv.Autocomplete.Suggestions);
  2369. Assert.True (tv.ProcessKey (new KeyEvent (Key.PageUp, new KeyModifiers ())));
  2370. Assert.Equal (24, tv.GetCurrentLine ().Count);
  2371. Assert.Equal (new Point (24, 1), tv.CursorPosition);
  2372. Assert.True (tv.ProcessKey (new KeyEvent (((int)'V' + Key.AltMask), new KeyModifiers ())));
  2373. Assert.Equal (23, tv.GetCurrentLine ().Count);
  2374. Assert.Equal (new Point (23, 0), tv.CursorPosition);
  2375. Assert.True (tv.ProcessKey (new KeyEvent (Key.PageDown, new KeyModifiers ())));
  2376. Assert.Equal (24, tv.GetCurrentLine ().Count);
  2377. Assert.Equal (new Point (23, 1), tv.CursorPosition); // gets the previous length
  2378. Assert.True (tv.ProcessKey (new KeyEvent (Key.V | Key.CtrlMask, new KeyModifiers ())));
  2379. Assert.Equal (28, tv.GetCurrentLine ().Count);
  2380. Assert.Equal (new Point (23, 2), tv.CursorPosition); // gets the previous length
  2381. Assert.Equal (0, tv.SelectedLength);
  2382. Assert.Equal ("", tv.SelectedText);
  2383. Assert.True (tv.ProcessKey (new KeyEvent (Key.PageUp | Key.ShiftMask, new KeyModifiers ())));
  2384. Assert.Equal (24, tv.GetCurrentLine ().Count);
  2385. Assert.Equal (new Point (23, 1), tv.CursorPosition); // gets the previous length
  2386. Assert.Equal (24 + Environment.NewLine.Length, tv.SelectedLength);
  2387. Assert.Equal ($".{Environment.NewLine}This is the third line.", tv.SelectedText);
  2388. Assert.True (tv.ProcessKey (new KeyEvent (Key.PageDown | Key.ShiftMask, new KeyModifiers ())));
  2389. Assert.Equal (28, tv.GetCurrentLine ().Count);
  2390. Assert.Equal (new Point (23, 2), tv.CursorPosition); // gets the previous length
  2391. Assert.Equal (0, tv.SelectedLength);
  2392. Assert.Equal ("", tv.SelectedText);
  2393. Assert.True (tv.ProcessKey (new KeyEvent (Key.Home | Key.CtrlMask, new KeyModifiers ())));
  2394. Assert.Equal (Point.Empty, tv.CursorPosition);
  2395. Assert.True (tv.ProcessKey (new KeyEvent (Key.N | Key.CtrlMask, new KeyModifiers ())));
  2396. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  2397. Assert.Equal (0, tv.SelectedLength);
  2398. Assert.Equal ("", tv.SelectedText);
  2399. Assert.True (tv.ProcessKey (new KeyEvent (Key.P | Key.CtrlMask, new KeyModifiers ())));
  2400. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  2401. Assert.Equal (0, tv.SelectedLength);
  2402. Assert.Equal ("", tv.SelectedText);
  2403. Assert.True (tv.ProcessKey (new KeyEvent (Key.CursorDown, new KeyModifiers ())));
  2404. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  2405. Assert.Equal (0, tv.SelectedLength);
  2406. Assert.Equal ("", tv.SelectedText);
  2407. Assert.True (tv.ProcessKey (new KeyEvent (Key.CursorUp, new KeyModifiers ())));
  2408. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  2409. Assert.Equal (0, tv.SelectedLength);
  2410. Assert.Equal ("", tv.SelectedText);
  2411. Assert.True (tv.ProcessKey (new KeyEvent (Key.CursorDown | Key.ShiftMask, new KeyModifiers ())));
  2412. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  2413. Assert.Equal (23 + Environment.NewLine.Length, tv.SelectedLength);
  2414. Assert.Equal ($"This is the first line.{Environment.NewLine}", tv.SelectedText);
  2415. Assert.True (tv.ProcessKey (new KeyEvent (Key.CursorUp | Key.ShiftMask, new KeyModifiers ())));
  2416. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  2417. Assert.Equal (0, tv.SelectedLength);
  2418. Assert.Equal ("", tv.SelectedText);
  2419. Assert.True (tv.ProcessKey (new KeyEvent (Key.F | Key.CtrlMask, new KeyModifiers ())));
  2420. Assert.Equal (new Point (1, 0), tv.CursorPosition);
  2421. Assert.Equal (0, tv.SelectedLength);
  2422. Assert.Equal ("", tv.SelectedText);
  2423. Assert.True (tv.ProcessKey (new KeyEvent (Key.B | Key.CtrlMask, new KeyModifiers ())));
  2424. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  2425. Assert.Equal (0, tv.SelectedLength);
  2426. Assert.Equal ("", tv.SelectedText);
  2427. Assert.True (tv.ProcessKey (new KeyEvent (Key.CursorRight, new KeyModifiers ())));
  2428. Assert.Equal (new Point (1, 0), tv.CursorPosition);
  2429. Assert.Equal (0, tv.SelectedLength);
  2430. Assert.Equal ("", tv.SelectedText);
  2431. Assert.True (tv.ProcessKey (new KeyEvent (Key.CursorLeft, new KeyModifiers ())));
  2432. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  2433. Assert.Equal (0, tv.SelectedLength);
  2434. Assert.Equal ("", tv.SelectedText);
  2435. Assert.False (tv.Selecting);
  2436. Assert.True (tv.ProcessKey (new KeyEvent (Key.CursorRight | Key.ShiftMask, new KeyModifiers ())));
  2437. Assert.Equal (new Point (1, 0), tv.CursorPosition);
  2438. Assert.Equal (1, tv.SelectedLength);
  2439. Assert.Equal ("T", tv.SelectedText);
  2440. Assert.True (tv.Selecting);
  2441. Assert.True (tv.ProcessKey (new KeyEvent (Key.CursorLeft | Key.ShiftMask, new KeyModifiers ())));
  2442. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  2443. Assert.Equal (0, tv.SelectedLength);
  2444. Assert.Equal ("", tv.SelectedText);
  2445. Assert.True (tv.Selecting);
  2446. Assert.True (tv.ProcessKey (new KeyEvent (Key.DeleteChar, new KeyModifiers ())));
  2447. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first", tv.Text);
  2448. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  2449. Assert.Equal (0, tv.SelectedLength);
  2450. Assert.Equal ("", tv.SelectedText);
  2451. Assert.False (tv.Selecting);
  2452. Assert.True (tv.ProcessKey (new KeyEvent (Key.DeleteChar, new KeyModifiers ())));
  2453. Assert.Equal ($"his is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first", tv.Text);
  2454. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  2455. Assert.Equal (0, tv.SelectedLength);
  2456. Assert.Equal ("", tv.SelectedText);
  2457. Assert.False (tv.Selecting);
  2458. Assert.True (tv.ProcessKey (new KeyEvent (Key.D | Key.CtrlMask, new KeyModifiers ())));
  2459. Assert.Equal ($"is is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first", tv.Text);
  2460. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  2461. Assert.True (tv.ProcessKey (new KeyEvent (Key.End, new KeyModifiers ())));
  2462. Assert.Equal ($"is is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first", tv.Text);
  2463. Assert.Equal (new Point (21, 0), tv.CursorPosition);
  2464. Assert.True (tv.ProcessKey (new KeyEvent (Key.Delete, new KeyModifiers ())));
  2465. Assert.Equal ($"is is the first line{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first", tv.Text);
  2466. Assert.Equal (new Point (20, 0), tv.CursorPosition);
  2467. Assert.True (tv.ProcessKey (new KeyEvent (Key.Backspace, new KeyModifiers ())));
  2468. Assert.Equal ($"is is the first lin{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first", tv.Text);
  2469. Assert.Equal (new Point (19, 0), tv.CursorPosition);
  2470. Assert.True (tv.ProcessKey (new KeyEvent (Key.Home, new KeyModifiers ())));
  2471. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  2472. Assert.Equal (0, tv.SelectedLength);
  2473. Assert.Equal ("", tv.SelectedText);
  2474. Assert.False (tv.Selecting);
  2475. Assert.True (tv.ProcessKey (new KeyEvent (Key.End | Key.ShiftMask, new KeyModifiers ())));
  2476. Assert.Equal (new Point (19, 0), tv.CursorPosition);
  2477. Assert.Equal (19, tv.SelectedLength);
  2478. Assert.Equal ("is is the first lin", tv.SelectedText);
  2479. Assert.True (tv.Selecting);
  2480. Assert.True (tv.ProcessKey (new KeyEvent (Key.Home | Key.ShiftMask, new KeyModifiers ())));
  2481. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  2482. Assert.Equal (0, tv.SelectedLength);
  2483. Assert.Equal ("", tv.SelectedText);
  2484. Assert.True (tv.Selecting);
  2485. Assert.True (tv.ProcessKey (new KeyEvent (Key.E | Key.CtrlMask, new KeyModifiers ())));
  2486. Assert.Equal (new Point (19, 0), tv.CursorPosition);
  2487. Assert.Equal (0, tv.SelectedLength);
  2488. Assert.Equal ("", tv.SelectedText);
  2489. Assert.False (tv.Selecting);
  2490. Assert.True (tv.ProcessKey (new KeyEvent (Key.A | Key.CtrlMask, new KeyModifiers ())));
  2491. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  2492. Assert.Equal (0, tv.SelectedLength);
  2493. Assert.Equal ("", tv.SelectedText);
  2494. Assert.False (tv.Selecting);
  2495. Assert.True (tv.ProcessKey (new KeyEvent (Key.K | Key.CtrlMask, new KeyModifiers ())));
  2496. Assert.Equal ($"{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first", tv.Text);
  2497. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  2498. Assert.Equal (0, tv.SelectedLength);
  2499. Assert.Equal ("", tv.SelectedText);
  2500. Assert.False (tv.Selecting);
  2501. Assert.Equal ("is is the first lin", Clipboard.Contents);
  2502. Assert.True (tv.ProcessKey (new KeyEvent (Key.Y | Key.CtrlMask, new KeyModifiers ())));
  2503. Assert.Equal ($"is is the first lin{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first", tv.Text);
  2504. Assert.Equal (new Point (19, 0), tv.CursorPosition);
  2505. Assert.Equal (0, tv.SelectedLength);
  2506. Assert.Equal ("", tv.SelectedText);
  2507. Assert.False (tv.Selecting);
  2508. Assert.Equal ("is is the first lin", Clipboard.Contents);
  2509. tv.CursorPosition = Point.Empty;
  2510. Assert.True (tv.ProcessKey (new KeyEvent (Key.DeleteChar | Key.CtrlMask | Key.ShiftMask, new KeyModifiers ())));
  2511. Assert.Equal ($"{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first", tv.Text);
  2512. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  2513. Assert.Equal (0, tv.SelectedLength);
  2514. Assert.Equal ("", tv.SelectedText);
  2515. Assert.False (tv.Selecting);
  2516. Assert.Equal ("is is the first lin", Clipboard.Contents);
  2517. Assert.True (tv.ProcessKey (new KeyEvent (Key.Y | Key.CtrlMask, new KeyModifiers ())));
  2518. Assert.Equal ($"is is the first lin{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first", tv.Text);
  2519. Assert.Equal (new Point (19, 0), tv.CursorPosition);
  2520. Assert.Equal (0, tv.SelectedLength);
  2521. Assert.Equal ("", tv.SelectedText);
  2522. Assert.False (tv.Selecting);
  2523. Assert.Equal ("is is the first lin", Clipboard.Contents);
  2524. Assert.True (tv.ProcessKey (new KeyEvent (Key.K | Key.AltMask, new KeyModifiers ())));
  2525. Assert.Equal ($"{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first", tv.Text);
  2526. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  2527. Assert.Equal (0, tv.SelectedLength);
  2528. Assert.Equal ("", tv.SelectedText);
  2529. Assert.False (tv.Selecting);
  2530. tv.ReadOnly = true;
  2531. Assert.True (tv.ProcessKey (new KeyEvent (Key.Y | Key.CtrlMask, new KeyModifiers ())));
  2532. Assert.Equal ($"{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first", tv.Text);
  2533. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  2534. Assert.Equal (0, tv.SelectedLength);
  2535. Assert.Equal ("", tv.SelectedText);
  2536. Assert.False (tv.Selecting);
  2537. tv.ReadOnly = false;
  2538. Assert.True (tv.ProcessKey (new KeyEvent (Key.Y | Key.CtrlMask, new KeyModifiers ())));
  2539. Assert.Equal ($"is is the first lin{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first", tv.Text);
  2540. Assert.Equal (new Point (19, 0), tv.CursorPosition);
  2541. Assert.Equal (0, tv.SelectedLength);
  2542. Assert.Equal ("", tv.SelectedText);
  2543. Assert.False (tv.Selecting);
  2544. Assert.Equal (0, tv.SelectionStartColumn);
  2545. Assert.Equal (0, tv.SelectionStartRow);
  2546. Assert.True (tv.ProcessKey (new KeyEvent (Key.Space | Key.CtrlMask, new KeyModifiers ())));
  2547. Assert.Equal ($"is is the first lin{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first", tv.Text);
  2548. Assert.Equal (new Point (19, 0), tv.CursorPosition);
  2549. Assert.Equal (0, tv.SelectedLength);
  2550. Assert.Equal ("", tv.SelectedText);
  2551. Assert.True (tv.Selecting);
  2552. Assert.Equal (19, tv.SelectionStartColumn);
  2553. Assert.Equal (0, tv.SelectionStartRow);
  2554. Assert.True (tv.ProcessKey (new KeyEvent (Key.Space | Key.CtrlMask, new KeyModifiers ())));
  2555. Assert.Equal ($"is is the first lin{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first", tv.Text);
  2556. Assert.Equal (new Point (19, 0), tv.CursorPosition);
  2557. Assert.Equal (0, tv.SelectedLength);
  2558. Assert.Equal ("", tv.SelectedText);
  2559. Assert.False (tv.Selecting);
  2560. Assert.Equal (19, tv.SelectionStartColumn);
  2561. Assert.Equal (0, tv.SelectionStartRow);
  2562. tv.SelectionStartColumn = 0;
  2563. Assert.True (tv.ProcessKey (new KeyEvent (((int)'C' + Key.AltMask), new KeyModifiers ())));
  2564. Assert.Equal ($"is is the first lin{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first", tv.Text);
  2565. Assert.Equal (new Point (19, 0), tv.CursorPosition);
  2566. Assert.Equal (19, tv.SelectedLength);
  2567. Assert.Equal ("is is the first lin", tv.SelectedText);
  2568. Assert.True (tv.Selecting);
  2569. Assert.Equal (0, tv.SelectionStartColumn);
  2570. Assert.Equal (0, tv.SelectionStartRow);
  2571. Assert.True (tv.ProcessKey (new KeyEvent (Key.C | Key.CtrlMask, new KeyModifiers ())));
  2572. Assert.Equal ($"is is the first lin{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first", tv.Text);
  2573. Assert.Equal (new Point (19, 0), tv.CursorPosition);
  2574. Assert.Equal (19, tv.SelectedLength);
  2575. Assert.Equal ("is is the first lin", tv.SelectedText);
  2576. Assert.True (tv.Selecting);
  2577. Assert.Equal (0, tv.SelectionStartColumn);
  2578. Assert.Equal (0, tv.SelectionStartRow);
  2579. Assert.True (tv.ProcessKey (new KeyEvent (((int)'W' + Key.AltMask), new KeyModifiers ())));
  2580. Assert.Equal ($"{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first", tv.Text);
  2581. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  2582. Assert.Equal (0, tv.SelectedLength);
  2583. Assert.Equal ("", tv.SelectedText);
  2584. Assert.False (tv.Selecting);
  2585. Assert.Equal (0, tv.SelectionStartColumn);
  2586. Assert.Equal (0, tv.SelectionStartRow);
  2587. Assert.Equal ("is is the first lin", Clipboard.Contents);
  2588. Assert.True (tv.ProcessKey (new KeyEvent (Key.W | Key.CtrlMask, new KeyModifiers ())));
  2589. Assert.Equal ($"{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first", tv.Text);
  2590. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  2591. Assert.Equal (0, tv.SelectedLength);
  2592. Assert.Equal ("", tv.SelectedText);
  2593. Assert.False (tv.Selecting);
  2594. Assert.Equal (0, tv.SelectionStartColumn);
  2595. Assert.Equal (0, tv.SelectionStartRow);
  2596. Assert.Equal ("", Clipboard.Contents);
  2597. Assert.True (tv.ProcessKey (new KeyEvent (Key.X | Key.CtrlMask, new KeyModifiers ())));
  2598. Assert.Equal ($"{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first", tv.Text);
  2599. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  2600. Assert.Equal (0, tv.SelectedLength);
  2601. Assert.Equal ("", tv.SelectedText);
  2602. Assert.False (tv.Selecting);
  2603. Assert.Equal (0, tv.SelectionStartColumn);
  2604. Assert.Equal (0, tv.SelectionStartRow);
  2605. Assert.Equal ("", Clipboard.Contents);
  2606. Assert.True (tv.ProcessKey (new KeyEvent (Key.End | Key.CtrlMask, new KeyModifiers ())));
  2607. Assert.Equal ($"{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first", tv.Text);
  2608. Assert.Equal (new Point (28, 2), tv.CursorPosition);
  2609. Assert.Equal (0, tv.SelectedLength);
  2610. Assert.Equal ("", tv.SelectedText);
  2611. Assert.False (tv.Selecting);
  2612. Assert.True (tv.ProcessKey (new KeyEvent (Key.CtrlMask | Key.CursorLeft, new KeyModifiers ())));
  2613. Assert.Equal ($"{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first", tv.Text);
  2614. Assert.Equal (new Point (18, 2), tv.CursorPosition);
  2615. Assert.Equal (0, tv.SelectedLength);
  2616. Assert.Equal ("", tv.SelectedText);
  2617. Assert.False (tv.Selecting);
  2618. Assert.True (tv.ProcessKey (new KeyEvent (Key.CtrlMask | Key.CursorLeft | Key.ShiftMask, new KeyModifiers ())));
  2619. Assert.Equal ($"{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first", tv.Text);
  2620. Assert.Equal (new Point (12, 2), tv.CursorPosition);
  2621. Assert.Equal (6, tv.SelectedLength);
  2622. Assert.Equal ("third ", tv.SelectedText);
  2623. Assert.True (tv.Selecting);
  2624. Assert.True (tv.ProcessKey (new KeyEvent ((Key)((int)'B' + Key.AltMask), new KeyModifiers ())));
  2625. Assert.Equal ($"{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first", tv.Text);
  2626. Assert.Equal (new Point (8, 2), tv.CursorPosition);
  2627. Assert.Equal (0, tv.SelectedLength);
  2628. Assert.Equal ("", tv.SelectedText);
  2629. Assert.False (tv.Selecting);
  2630. Assert.True (tv.ProcessKey (new KeyEvent (Key.CtrlMask | Key.CursorRight, new KeyModifiers ())));
  2631. Assert.Equal ($"{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first", tv.Text);
  2632. Assert.Equal (new Point (12, 2), tv.CursorPosition);
  2633. Assert.Equal (0, tv.SelectedLength);
  2634. Assert.Equal ("", tv.SelectedText);
  2635. Assert.False (tv.Selecting);
  2636. Assert.True (tv.ProcessKey (new KeyEvent (Key.CtrlMask | Key.CursorRight | Key.ShiftMask, new KeyModifiers ())));
  2637. Assert.Equal ($"{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first", tv.Text);
  2638. Assert.Equal (new Point (18, 2), tv.CursorPosition);
  2639. Assert.Equal (6, tv.SelectedLength);
  2640. Assert.Equal ("third ", tv.SelectedText);
  2641. Assert.True (tv.Selecting);
  2642. Assert.True (tv.ProcessKey (new KeyEvent ((Key)((int)'F' + Key.AltMask), new KeyModifiers ())));
  2643. Assert.Equal ($"{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first", tv.Text);
  2644. Assert.Equal (new Point (28, 2), tv.CursorPosition);
  2645. Assert.Equal (0, tv.SelectedLength);
  2646. Assert.Equal ("", tv.SelectedText);
  2647. Assert.False (tv.Selecting);
  2648. Assert.True (tv.ProcessKey (new KeyEvent (Key.Home | Key.CtrlMask, new KeyModifiers ())));
  2649. Assert.Equal ($"{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first", tv.Text);
  2650. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  2651. Assert.Equal (0, tv.SelectedLength);
  2652. Assert.Equal ("", tv.SelectedText);
  2653. Assert.False (tv.Selecting);
  2654. Assert.True (tv.ProcessKey (new KeyEvent (Key.DeleteChar | Key.CtrlMask, new KeyModifiers ())));
  2655. Assert.Equal ($"This is the second line.{Environment.NewLine}This is the third line.first", tv.Text);
  2656. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  2657. Assert.Equal (0, tv.SelectedLength);
  2658. Assert.Equal ("", tv.SelectedText);
  2659. Assert.False (tv.Selecting); Assert.True (tv.ProcessKey (new KeyEvent (Key.End | Key.CtrlMask, new KeyModifiers ())));
  2660. Assert.Equal ($"This is the second line.{Environment.NewLine}This is the third line.first", tv.Text);
  2661. Assert.Equal (new Point (28, 1), tv.CursorPosition);
  2662. Assert.Equal (0, tv.SelectedLength);
  2663. Assert.Equal ("", tv.SelectedText);
  2664. Assert.False (tv.Selecting);
  2665. Assert.False (tv.Selecting); Assert.True (tv.ProcessKey (new KeyEvent (Key.Backspace | Key.CtrlMask, new KeyModifiers ())));
  2666. Assert.Equal ($"This is the second line.{Environment.NewLine}This is the third ", tv.Text);
  2667. Assert.Equal (new Point (18, 1), tv.CursorPosition);
  2668. Assert.Equal (0, tv.SelectedLength);
  2669. Assert.Equal ("", tv.SelectedText);
  2670. Assert.False (tv.Selecting);
  2671. Assert.True (tv.AllowsReturn);
  2672. tv.AllowsReturn = false;
  2673. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  2674. Assert.False (tv.Selecting);
  2675. Assert.False (tv.ProcessKey (new KeyEvent (Key.Enter, new KeyModifiers ())));
  2676. Assert.Equal ($"This is the second line.{Environment.NewLine}This is the third ", tv.Text);
  2677. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  2678. Assert.Equal (0, tv.SelectedLength);
  2679. Assert.Equal ("", tv.SelectedText);
  2680. Assert.False (tv.Selecting);
  2681. Assert.False (tv.AllowsReturn);
  2682. tv.AllowsReturn = true;
  2683. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  2684. Assert.True (tv.ProcessKey (new KeyEvent (Key.Enter, new KeyModifiers ())));
  2685. Assert.Equal ($"{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third ", tv.Text);
  2686. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  2687. Assert.Equal (0, tv.SelectedLength);
  2688. Assert.Equal ("", tv.SelectedText);
  2689. Assert.False (tv.Selecting);
  2690. Assert.True (tv.AllowsReturn);
  2691. Assert.True (tv.ProcessKey (new KeyEvent (Key.CtrlMask | Key.End | Key.ShiftMask, new KeyModifiers ())));
  2692. Assert.Equal ($"{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third ", tv.Text);
  2693. Assert.Equal (new Point (18, 2), tv.CursorPosition);
  2694. Assert.Equal (42 + Environment.NewLine.Length, tv.SelectedLength);
  2695. Assert.Equal ($"This is the second line.{Environment.NewLine}This is the third ", tv.SelectedText);
  2696. Assert.True (tv.Selecting);
  2697. Assert.True (tv.ProcessKey (new KeyEvent (Key.CtrlMask | Key.Home | Key.ShiftMask, new KeyModifiers ())));
  2698. Assert.Equal ($"{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third ", tv.Text);
  2699. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  2700. Assert.Equal (Environment.NewLine.Length, tv.SelectedLength);
  2701. Assert.Equal ($"{Environment.NewLine}", tv.SelectedText);
  2702. Assert.True (tv.Selecting);
  2703. Assert.True (tv.ProcessKey (new KeyEvent (Key.T | Key.CtrlMask, new KeyModifiers ())));
  2704. Assert.Equal ($"{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third ", tv.Text);
  2705. Assert.Equal (new Point (18, 2), tv.CursorPosition);
  2706. Assert.Equal (42 + Environment.NewLine.Length * 2, tv.SelectedLength);
  2707. Assert.Equal ($"{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third ", tv.SelectedText);
  2708. Assert.True (tv.Selecting);
  2709. Assert.True (tv.Used);
  2710. Assert.True (tv.ProcessKey (new KeyEvent (Key.InsertChar, new KeyModifiers ())));
  2711. Assert.False (tv.Used);
  2712. Assert.True (tv.AllowsTab);
  2713. Assert.Equal (new Point (18, 2), tv.CursorPosition);
  2714. tv.AllowsTab = false;
  2715. Assert.False (tv.ProcessKey (new KeyEvent (Key.Tab, new KeyModifiers ())));
  2716. Assert.Equal ($"{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third ", tv.Text);
  2717. Assert.False (tv.AllowsTab);
  2718. tv.AllowsTab = true;
  2719. Assert.Equal (new Point (18, 2), tv.CursorPosition);
  2720. Assert.True (tv.Selecting);
  2721. tv.Selecting = false;
  2722. Assert.True (tv.ProcessKey (new KeyEvent (Key.Tab, new KeyModifiers ())));
  2723. Assert.Equal ($"{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third \t", tv.Text);
  2724. Assert.True (tv.AllowsTab);
  2725. tv.AllowsTab = false;
  2726. Assert.False (tv.ProcessKey (new KeyEvent (Key.BackTab | Key.ShiftMask, new KeyModifiers ())));
  2727. Assert.Equal ($"{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third \t", tv.Text);
  2728. Assert.False (tv.AllowsTab);
  2729. tv.AllowsTab = true;
  2730. Assert.True (tv.ProcessKey (new KeyEvent (Key.BackTab | Key.ShiftMask, new KeyModifiers ())));
  2731. Assert.Equal ($"{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third ", tv.Text);
  2732. Assert.True (tv.AllowsTab);
  2733. Assert.False (tv.ProcessKey (new KeyEvent (Key.Tab | Key.CtrlMask, new KeyModifiers ())));
  2734. Assert.False (tv.ProcessKey (new KeyEvent (Application.AlternateForwardKey, new KeyModifiers ())));
  2735. Assert.False (tv.ProcessKey (new KeyEvent (Key.Tab | Key.CtrlMask | Key.ShiftMask, new KeyModifiers ())));
  2736. Assert.False (tv.ProcessKey (new KeyEvent (Application.AlternateBackwardKey, new KeyModifiers ())));
  2737. }
  2738. [Fact]
  2739. public void HistoryText_Exceptions ()
  2740. {
  2741. var ht = new HistoryText ();
  2742. foreach (var ls in Enum.GetValues (typeof (HistoryText.LineStatus))) {
  2743. if ((HistoryText.LineStatus)ls != HistoryText.LineStatus.Original) {
  2744. Assert.Throws<ArgumentException> (() => ht.Add (new List<List<Rune>> () { new List<Rune> () }, Point.Empty,
  2745. (HistoryText.LineStatus)ls));
  2746. }
  2747. }
  2748. Assert.Null (Record.Exception (() => ht.Add (new List<List<Rune>> () { new List<Rune> () }, Point.Empty,
  2749. HistoryText.LineStatus.Original)));
  2750. }
  2751. [Fact]
  2752. [AutoInitShutdown]
  2753. public void HistoryText_Undo_Redo_Single_Line_InsertText ()
  2754. {
  2755. var text = "This is the first line.\nThis is the second line.\nThis is the third line.";
  2756. var tv = new TextView () {
  2757. Width = 10,
  2758. Height = 2,
  2759. Text = text
  2760. };
  2761. var top = Application.Top;
  2762. top.Add (tv);
  2763. Application.Begin (top);
  2764. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  2765. Assert.Equal (3, tv.Lines);
  2766. Assert.Equal (Point.Empty, tv.CursorPosition);
  2767. var messy = " messy";
  2768. tv.CursorPosition = new Point (7, 1);
  2769. tv.InsertText (messy);
  2770. Assert.Equal ($"This is the first line.{Environment.NewLine}This is messy the second line.{Environment.NewLine}This is the third line.", tv.Text);
  2771. Assert.Equal (3, tv.Lines);
  2772. Assert.Equal (new Point (13, 1), tv.CursorPosition);
  2773. for (int i = 0; i < messy.Length; i++) {
  2774. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  2775. }
  2776. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  2777. Assert.Equal (3, tv.Lines);
  2778. Assert.Equal (new Point (7, 1), tv.CursorPosition);
  2779. for (int i = 0; i < messy.Length; i++) {
  2780. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  2781. }
  2782. Assert.Equal ($"This is the first line.{Environment.NewLine}This is messy the second line.{Environment.NewLine}This is the third line.", tv.Text);
  2783. Assert.Equal (3, tv.Lines);
  2784. Assert.Equal (new Point (13, 1), tv.CursorPosition);
  2785. }
  2786. [Fact]
  2787. [AutoInitShutdown]
  2788. public void HistoryText_Undo_Redo_Single_Line_DeleteCharLeft ()
  2789. {
  2790. var text = "This is the first line.\nThis is the second line.\nThis is the third line.";
  2791. var tv = new TextView () {
  2792. Width = 10,
  2793. Height = 2,
  2794. Text = text
  2795. };
  2796. var top = Application.Top;
  2797. top.Add (tv);
  2798. Application.Begin (top);
  2799. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  2800. Assert.Equal (3, tv.Lines);
  2801. Assert.Equal (Point.Empty, tv.CursorPosition);
  2802. var ntimes = 3;
  2803. tv.CursorPosition = new Point (7, 1);
  2804. for (int i = 0; i < ntimes; i++) {
  2805. tv.DeleteCharLeft ();
  2806. }
  2807. Assert.Equal ($"This is the first line.{Environment.NewLine}This the second line.{Environment.NewLine}This is the third line.", tv.Text);
  2808. Assert.Equal (3, tv.Lines);
  2809. Assert.Equal (new Point (4, 1), tv.CursorPosition);
  2810. for (int i = 0; i < ntimes; i++) {
  2811. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  2812. }
  2813. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  2814. Assert.Equal (3, tv.Lines);
  2815. Assert.Equal (new Point (7, 1), tv.CursorPosition);
  2816. for (int i = 0; i < ntimes; i++) {
  2817. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  2818. }
  2819. Assert.Equal ($"This is the first line.{Environment.NewLine}This the second line.{Environment.NewLine}This is the third line.", tv.Text);
  2820. Assert.Equal (3, tv.Lines);
  2821. Assert.Equal (new Point (4, 1), tv.CursorPosition);
  2822. }
  2823. [Fact]
  2824. [AutoInitShutdown]
  2825. public void HistoryText_Undo_Redo_Single_Line_DeleteCharRight ()
  2826. {
  2827. var text = "This is the first line.\nThis is the second line.\nThis is the third line.";
  2828. var tv = new TextView () {
  2829. Width = 10,
  2830. Height = 2,
  2831. Text = text
  2832. };
  2833. var top = Application.Top;
  2834. top.Add (tv);
  2835. Application.Begin (top);
  2836. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  2837. Assert.Equal (3, tv.Lines);
  2838. Assert.Equal (Point.Empty, tv.CursorPosition);
  2839. var ntimes = 3;
  2840. tv.CursorPosition = new Point (7, 1);
  2841. for (int i = 0; i < ntimes; i++) {
  2842. tv.DeleteCharRight ();
  2843. }
  2844. Assert.Equal ($"This is the first line.{Environment.NewLine}This ise second line.{Environment.NewLine}This is the third line.", tv.Text);
  2845. Assert.Equal (3, tv.Lines);
  2846. Assert.Equal (new Point (7, 1), tv.CursorPosition);
  2847. for (int i = 0; i < ntimes; i++) {
  2848. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  2849. }
  2850. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  2851. Assert.Equal (3, tv.Lines);
  2852. Assert.Equal (new Point (7, 1), tv.CursorPosition);
  2853. for (int i = 0; i < ntimes; i++) {
  2854. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  2855. }
  2856. Assert.Equal ($"This is the first line.{Environment.NewLine}This ise second line.{Environment.NewLine}This is the third line.", tv.Text);
  2857. Assert.Equal (3, tv.Lines);
  2858. Assert.Equal (new Point (7, 1), tv.CursorPosition);
  2859. }
  2860. [Fact]
  2861. [AutoInitShutdown]
  2862. public void HistoryText_Undo_Redo_Single_Line_Selected_InsertText ()
  2863. {
  2864. var text = "This is the first line.\nThis is the second line.\nThis is the third line.";
  2865. var tv = new TextView () {
  2866. Width = 10,
  2867. Height = 2,
  2868. Text = text
  2869. };
  2870. var top = Application.Top;
  2871. top.Add (tv);
  2872. Application.Begin (top);
  2873. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  2874. Assert.Equal (3, tv.Lines);
  2875. Assert.Equal (Point.Empty, tv.CursorPosition);
  2876. var messy = " messy";
  2877. tv.CursorPosition = new Point (7, 1);
  2878. tv.SelectionStartColumn = 11;
  2879. tv.SelectionStartRow = 1;
  2880. Assert.Equal (4, tv.SelectedLength);
  2881. tv.InsertText (messy);
  2882. Assert.Equal ($"This is the first line.{Environment.NewLine}This is messy second line.{Environment.NewLine}This is the third line.", tv.Text);
  2883. Assert.Equal (3, tv.Lines);
  2884. Assert.Equal (new Point (13, 1), tv.CursorPosition);
  2885. Assert.Equal (11, tv.SelectionStartColumn);
  2886. Assert.Equal (1, tv.SelectionStartRow);
  2887. Assert.Equal (0, tv.SelectedLength);
  2888. for (int i = 0; i < messy.Length; i++) {
  2889. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  2890. }
  2891. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  2892. Assert.Equal (3, tv.Lines);
  2893. Assert.Equal (new Point (7, 1), tv.CursorPosition);
  2894. Assert.Equal (11, tv.SelectionStartColumn);
  2895. Assert.Equal (1, tv.SelectionStartRow);
  2896. Assert.Equal (0, tv.SelectedLength);
  2897. for (int i = 0; i < messy.Length; i++) {
  2898. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  2899. }
  2900. Assert.Equal ($"This is the first line.{Environment.NewLine}This is messy second line.{Environment.NewLine}This is the third line.", tv.Text);
  2901. Assert.Equal (3, tv.Lines);
  2902. Assert.Equal (new Point (13, 1), tv.CursorPosition);
  2903. Assert.Equal (11, tv.SelectionStartColumn);
  2904. Assert.Equal (1, tv.SelectionStartRow);
  2905. Assert.Equal (0, tv.SelectedLength);
  2906. }
  2907. [Fact]
  2908. [AutoInitShutdown]
  2909. public void HistoryText_Undo_Redo_Single_Line_Selected_DeleteCharLeft ()
  2910. {
  2911. var text = "This is the first line.\nThis is the second line.\nThis is the third line.";
  2912. var tv = new TextView () {
  2913. Width = 10,
  2914. Height = 2,
  2915. Text = text
  2916. };
  2917. var top = Application.Top;
  2918. top.Add (tv);
  2919. Application.Begin (top);
  2920. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  2921. Assert.Equal (3, tv.Lines);
  2922. Assert.Equal (Point.Empty, tv.CursorPosition);
  2923. var ntimes = 3;
  2924. tv.CursorPosition = new Point (7, 1);
  2925. tv.SelectionStartColumn = 11;
  2926. tv.SelectionStartRow = 1;
  2927. Assert.Equal (4, tv.SelectedLength);
  2928. for (int i = 0; i < ntimes; i++) {
  2929. tv.DeleteCharLeft ();
  2930. }
  2931. Assert.Equal ($"This is the first line.{Environment.NewLine}This second line.{Environment.NewLine}This is the third line.", tv.Text);
  2932. Assert.Equal (3, tv.Lines);
  2933. Assert.Equal (new Point (5, 1), tv.CursorPosition);
  2934. Assert.Equal (11, tv.SelectionStartColumn);
  2935. Assert.Equal (1, tv.SelectionStartRow);
  2936. Assert.Equal (0, tv.SelectedLength);
  2937. for (int i = 0; i < ntimes; i++) {
  2938. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  2939. }
  2940. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  2941. Assert.Equal (3, tv.Lines);
  2942. Assert.Equal (new Point (7, 1), tv.CursorPosition);
  2943. Assert.Equal (11, tv.SelectionStartColumn);
  2944. Assert.Equal (1, tv.SelectionStartRow);
  2945. Assert.Equal (0, tv.SelectedLength);
  2946. for (int i = 0; i < ntimes; i++) {
  2947. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  2948. }
  2949. Assert.Equal ($"This is the first line.{Environment.NewLine}This second line.{Environment.NewLine}This is the third line.", tv.Text);
  2950. Assert.Equal (3, tv.Lines);
  2951. Assert.Equal (new Point (5, 1), tv.CursorPosition);
  2952. Assert.Equal (11, tv.SelectionStartColumn);
  2953. Assert.Equal (1, tv.SelectionStartRow);
  2954. Assert.Equal (0, tv.SelectedLength);
  2955. }
  2956. [Fact]
  2957. [AutoInitShutdown]
  2958. public void HistoryText_Undo_Redo_Single_Line_Selected_DeleteCharRight ()
  2959. {
  2960. var text = "This is the first line.\nThis is the second line.\nThis is the third line.";
  2961. var tv = new TextView () {
  2962. Width = 10,
  2963. Height = 2,
  2964. Text = text
  2965. };
  2966. var top = Application.Top;
  2967. top.Add (tv);
  2968. Application.Begin (top);
  2969. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  2970. Assert.Equal (3, tv.Lines);
  2971. Assert.Equal (Point.Empty, tv.CursorPosition);
  2972. var ntimes = 3;
  2973. tv.CursorPosition = new Point (7, 1);
  2974. tv.SelectionStartColumn = 11;
  2975. tv.SelectionStartRow = 1;
  2976. Assert.Equal (4, tv.SelectedLength);
  2977. for (int i = 0; i < ntimes; i++) {
  2978. tv.DeleteCharRight ();
  2979. }
  2980. Assert.Equal ($"This is the first line.{Environment.NewLine}This isecond line.{Environment.NewLine}This is the third line.", tv.Text);
  2981. Assert.Equal (3, tv.Lines);
  2982. Assert.Equal (new Point (7, 1), tv.CursorPosition);
  2983. Assert.Equal (11, tv.SelectionStartColumn);
  2984. Assert.Equal (1, tv.SelectionStartRow);
  2985. Assert.Equal (0, tv.SelectedLength);
  2986. for (int i = 0; i < ntimes; i++) {
  2987. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  2988. }
  2989. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  2990. Assert.Equal (3, tv.Lines);
  2991. Assert.Equal (new Point (7, 1), tv.CursorPosition);
  2992. Assert.Equal (11, tv.SelectionStartColumn);
  2993. Assert.Equal (1, tv.SelectionStartRow);
  2994. Assert.Equal (0, tv.SelectedLength);
  2995. for (int i = 0; i < ntimes; i++) {
  2996. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  2997. }
  2998. Assert.Equal ($"This is the first line.{Environment.NewLine}This isecond line.{Environment.NewLine}This is the third line.", tv.Text);
  2999. Assert.Equal (3, tv.Lines);
  3000. Assert.Equal (new Point (7, 1), tv.CursorPosition);
  3001. Assert.Equal (11, tv.SelectionStartColumn);
  3002. Assert.Equal (1, tv.SelectionStartRow);
  3003. Assert.Equal (0, tv.SelectedLength);
  3004. }
  3005. [Fact]
  3006. [AutoInitShutdown]
  3007. public void HistoryText_Undo_Redo_Multi_Line_InsertText ()
  3008. {
  3009. var text = "This is the first line.\nThis is the second line.\nThis is the third line.";
  3010. var tv = new TextView () {
  3011. Width = 10,
  3012. Height = 2,
  3013. Text = text
  3014. };
  3015. var top = Application.Top;
  3016. top.Add (tv);
  3017. Application.Begin (top);
  3018. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  3019. Assert.Equal (3, tv.Lines);
  3020. Assert.Equal (Point.Empty, tv.CursorPosition);
  3021. var messy = " messy";
  3022. tv.CursorPosition = new Point (7, 1);
  3023. tv.InsertText (messy);
  3024. Assert.Equal ($"This is the first line.{Environment.NewLine}This is messy the second line.{Environment.NewLine}This is the third line.", tv.Text);
  3025. Assert.Equal (3, tv.Lines);
  3026. Assert.Equal (new Point (13, 1), tv.CursorPosition);
  3027. tv.CursorPosition = new Point (7, 0);
  3028. tv.InsertText (messy);
  3029. 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);
  3030. Assert.Equal (3, tv.Lines);
  3031. Assert.Equal (new Point (13, 0), tv.CursorPosition);
  3032. tv.CursorPosition = new Point (7, 2);
  3033. tv.InsertText (messy);
  3034. 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);
  3035. Assert.Equal (3, tv.Lines);
  3036. Assert.Equal (new Point (13, 2), tv.CursorPosition);
  3037. for (int i = 0; i < messy.Length; i++) {
  3038. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  3039. }
  3040. 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);
  3041. Assert.Equal (3, tv.Lines);
  3042. Assert.Equal (new Point (7, 2), tv.CursorPosition);
  3043. for (int i = 0; i < messy.Length; i++) {
  3044. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  3045. }
  3046. Assert.Equal ($"This is the first line.{Environment.NewLine}This is messy the second line.{Environment.NewLine}This is the third line.", tv.Text);
  3047. Assert.Equal (3, tv.Lines);
  3048. Assert.Equal (new Point (7, 0), tv.CursorPosition);
  3049. for (int i = 0; i < messy.Length; i++) {
  3050. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  3051. }
  3052. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  3053. Assert.Equal (3, tv.Lines);
  3054. Assert.Equal (new Point (7, 1), tv.CursorPosition);
  3055. for (int i = 0; i < messy.Length; i++) {
  3056. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  3057. }
  3058. Assert.Equal ($"This is the first line.{Environment.NewLine}This is messy the second line.{Environment.NewLine}This is the third line.", tv.Text);
  3059. Assert.Equal (3, tv.Lines);
  3060. Assert.Equal (new Point (13, 1), tv.CursorPosition);
  3061. for (int i = 0; i < messy.Length; i++) {
  3062. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  3063. }
  3064. 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);
  3065. Assert.Equal (3, tv.Lines);
  3066. Assert.Equal (new Point (13, 0), tv.CursorPosition);
  3067. for (int i = 0; i < messy.Length; i++) {
  3068. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  3069. }
  3070. 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);
  3071. Assert.Equal (3, tv.Lines);
  3072. Assert.Equal (new Point (13, 2), tv.CursorPosition);
  3073. }
  3074. [Fact]
  3075. [AutoInitShutdown]
  3076. public void HistoryText_Undo_Redo_Multi_Line_DeleteCharLeft ()
  3077. {
  3078. var text = "This is the first line.\nThis is the second line.\nThis is the third line.";
  3079. var tv = new TextView () {
  3080. Width = 10,
  3081. Height = 2,
  3082. Text = text
  3083. };
  3084. var top = Application.Top;
  3085. top.Add (tv);
  3086. Application.Begin (top);
  3087. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  3088. Assert.Equal (3, tv.Lines);
  3089. Assert.Equal (Point.Empty, tv.CursorPosition);
  3090. var ntimes = 3;
  3091. tv.CursorPosition = new Point (7, 1);
  3092. for (int i = 0; i < ntimes; i++) {
  3093. tv.DeleteCharLeft ();
  3094. }
  3095. Assert.Equal ($"This is the first line.{Environment.NewLine}This the second line.{Environment.NewLine}This is the third line.", tv.Text);
  3096. Assert.Equal (3, tv.Lines);
  3097. Assert.Equal (new Point (4, 1), tv.CursorPosition);
  3098. tv.CursorPosition = new Point (7, 0);
  3099. for (int i = 0; i < ntimes; i++) {
  3100. tv.DeleteCharLeft ();
  3101. }
  3102. Assert.Equal ($"This the first line.{Environment.NewLine}This the second line.{Environment.NewLine}This is the third line.", tv.Text);
  3103. Assert.Equal (3, tv.Lines);
  3104. Assert.Equal (new Point (4, 0), tv.CursorPosition);
  3105. tv.CursorPosition = new Point (7, 2);
  3106. for (int i = 0; i < ntimes; i++) {
  3107. tv.DeleteCharLeft ();
  3108. }
  3109. Assert.Equal ($"This the first line.{Environment.NewLine}This the second line.{Environment.NewLine}This the third line.", tv.Text);
  3110. Assert.Equal (3, tv.Lines);
  3111. Assert.Equal (new Point (4, 2), tv.CursorPosition);
  3112. for (int i = 0; i < ntimes; i++) {
  3113. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  3114. switch (i) {
  3115. case 0:
  3116. Assert.Equal ($"This the first line.{Environment.NewLine}This the second line.{Environment.NewLine}This the third line.", tv.Text);
  3117. Assert.Equal (new Point (5, 2), tv.CursorPosition);
  3118. break;
  3119. case 1:
  3120. Assert.Equal ($"This the first line.{Environment.NewLine}This the second line.{Environment.NewLine}This i the third line.", tv.Text);
  3121. Assert.Equal (new Point (6, 2), tv.CursorPosition);
  3122. break;
  3123. case 2:
  3124. Assert.Equal ($"This the first line.{Environment.NewLine}This the second line.{Environment.NewLine}This is the third line.", tv.Text);
  3125. Assert.Equal (new Point (7, 2), tv.CursorPosition);
  3126. break;
  3127. }
  3128. }
  3129. Assert.Equal ($"This the first line.{Environment.NewLine}This the second line.{Environment.NewLine}This is the third line.", tv.Text);
  3130. Assert.Equal (3, tv.Lines);
  3131. Assert.Equal (new Point (7, 2), tv.CursorPosition);
  3132. for (int i = 0; i < ntimes; i++) {
  3133. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  3134. switch (i) {
  3135. case 0:
  3136. Assert.Equal ($"This the first line.{Environment.NewLine}This the second line.{Environment.NewLine}This is the third line.", tv.Text);
  3137. Assert.Equal (new Point (5, 0), tv.CursorPosition);
  3138. break;
  3139. case 1:
  3140. Assert.Equal ($"This i the first line.{Environment.NewLine}This the second line.{Environment.NewLine}This is the third line.", tv.Text);
  3141. Assert.Equal (new Point (6, 0), tv.CursorPosition);
  3142. break;
  3143. case 2:
  3144. Assert.Equal ($"This is the first line.{Environment.NewLine}This the second line.{Environment.NewLine}This is the third line.", tv.Text);
  3145. Assert.Equal (new Point (7, 0), tv.CursorPosition);
  3146. break;
  3147. }
  3148. }
  3149. Assert.Equal ($"This is the first line.{Environment.NewLine}This the second line.{Environment.NewLine}This is the third line.", tv.Text);
  3150. Assert.Equal (3, tv.Lines);
  3151. Assert.Equal (new Point (7, 0), tv.CursorPosition);
  3152. for (int i = 0; i < ntimes; i++) {
  3153. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  3154. switch (i) {
  3155. case 0:
  3156. Assert.Equal ($"This is the first line.{Environment.NewLine}This the second line.{Environment.NewLine}This is the third line.", tv.Text);
  3157. Assert.Equal (new Point (5, 1), tv.CursorPosition);
  3158. break;
  3159. case 1:
  3160. Assert.Equal ($"This is the first line.{Environment.NewLine}This i the second line.{Environment.NewLine}This is the third line.", tv.Text);
  3161. Assert.Equal (new Point (6, 1), tv.CursorPosition);
  3162. break;
  3163. case 2:
  3164. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  3165. Assert.Equal (new Point (7, 1), tv.CursorPosition);
  3166. break;
  3167. }
  3168. }
  3169. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  3170. Assert.Equal (3, tv.Lines);
  3171. Assert.Equal (new Point (7, 1), tv.CursorPosition);
  3172. for (int i = 0; i < ntimes; i++) {
  3173. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  3174. }
  3175. Assert.Equal ($"This is the first line.{Environment.NewLine}This the second line.{Environment.NewLine}This is the third line.", tv.Text);
  3176. Assert.Equal (3, tv.Lines);
  3177. Assert.Equal (new Point (4, 1), tv.CursorPosition);
  3178. for (int i = 0; i < ntimes; i++) {
  3179. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  3180. }
  3181. Assert.Equal ($"This the first line.{Environment.NewLine}This the second line.{Environment.NewLine}This is the third line.", tv.Text);
  3182. Assert.Equal (3, tv.Lines);
  3183. Assert.Equal (new Point (4, 0), tv.CursorPosition);
  3184. for (int i = 0; i < ntimes; i++) {
  3185. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  3186. }
  3187. Assert.Equal ($"This the first line.{Environment.NewLine}This the second line.{Environment.NewLine}This the third line.", tv.Text);
  3188. Assert.Equal (3, tv.Lines);
  3189. Assert.Equal (new Point (4, 2), tv.CursorPosition);
  3190. }
  3191. [Fact]
  3192. [AutoInitShutdown]
  3193. public void HistoryText_Undo_Redo_Multi_Line_DeleteCharRight ()
  3194. {
  3195. var text = "This is the first line.\nThis is the second line.\nThis is the third line.";
  3196. var tv = new TextView () {
  3197. Width = 10,
  3198. Height = 2,
  3199. Text = text
  3200. };
  3201. var top = Application.Top;
  3202. top.Add (tv);
  3203. Application.Begin (top);
  3204. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  3205. Assert.Equal (3, tv.Lines);
  3206. Assert.Equal (Point.Empty, tv.CursorPosition);
  3207. var ntimes = 3;
  3208. tv.CursorPosition = new Point (7, 1);
  3209. for (int i = 0; i < ntimes; i++) {
  3210. tv.DeleteCharRight ();
  3211. }
  3212. Assert.Equal ($"This is the first line.{Environment.NewLine}This ise second line.{Environment.NewLine}This is the third line.", tv.Text);
  3213. Assert.Equal (3, tv.Lines);
  3214. Assert.Equal (new Point (7, 1), tv.CursorPosition);
  3215. tv.CursorPosition = new Point (7, 0);
  3216. for (int i = 0; i < ntimes; i++) {
  3217. tv.DeleteCharRight ();
  3218. }
  3219. Assert.Equal ($"This ise first line.{Environment.NewLine}This ise second line.{Environment.NewLine}This is the third line.", tv.Text);
  3220. Assert.Equal (3, tv.Lines);
  3221. Assert.Equal (new Point (7, 0), tv.CursorPosition);
  3222. tv.CursorPosition = new Point (7, 2);
  3223. for (int i = 0; i < ntimes; i++) {
  3224. tv.DeleteCharRight ();
  3225. }
  3226. Assert.Equal ($"This ise first line.{Environment.NewLine}This ise second line.{Environment.NewLine}This ise third line.", tv.Text);
  3227. Assert.Equal (3, tv.Lines);
  3228. Assert.Equal (new Point (7, 2), tv.CursorPosition);
  3229. for (int i = 0; i < ntimes; i++) {
  3230. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  3231. }
  3232. Assert.Equal ($"This ise first line.{Environment.NewLine}This ise second line.{Environment.NewLine}This is the third line.", tv.Text);
  3233. Assert.Equal (3, tv.Lines);
  3234. Assert.Equal (new Point (7, 2), tv.CursorPosition);
  3235. for (int i = 0; i < ntimes; i++) {
  3236. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  3237. }
  3238. Assert.Equal ($"This is the first line.{Environment.NewLine}This ise second line.{Environment.NewLine}This is the third line.", tv.Text);
  3239. Assert.Equal (3, tv.Lines);
  3240. Assert.Equal (new Point (7, 0), tv.CursorPosition);
  3241. for (int i = 0; i < ntimes; i++) {
  3242. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  3243. }
  3244. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  3245. Assert.Equal (3, tv.Lines);
  3246. Assert.Equal (new Point (7, 1), tv.CursorPosition);
  3247. for (int i = 0; i < ntimes; i++) {
  3248. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  3249. }
  3250. Assert.Equal ($"This is the first line.{Environment.NewLine}This ise second line.{Environment.NewLine}This is the third line.", tv.Text);
  3251. Assert.Equal (3, tv.Lines);
  3252. Assert.Equal (new Point (7, 1), tv.CursorPosition);
  3253. for (int i = 0; i < ntimes; i++) {
  3254. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  3255. }
  3256. Assert.Equal ($"This ise first line.{Environment.NewLine}This ise second line.{Environment.NewLine}This is the third line.", tv.Text);
  3257. Assert.Equal (3, tv.Lines);
  3258. Assert.Equal (new Point (7, 0), tv.CursorPosition);
  3259. for (int i = 0; i < ntimes; i++) {
  3260. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  3261. }
  3262. Assert.Equal ($"This ise first line.{Environment.NewLine}This ise second line.{Environment.NewLine}This ise third line.", tv.Text);
  3263. Assert.Equal (3, tv.Lines);
  3264. Assert.Equal (new Point (7, 2), tv.CursorPosition);
  3265. }
  3266. [Fact]
  3267. [AutoInitShutdown]
  3268. public void HistoryText_Undo_Redo_Multi_Line_Selected_InsertText ()
  3269. {
  3270. var text = $"This is the first line.{Environment.NewLine}This is the second line.\nThis is the third line.";
  3271. var tv = new TextView () {
  3272. Width = 10,
  3273. Height = 2,
  3274. Text = text
  3275. };
  3276. var top = Application.Top;
  3277. top.Add (tv);
  3278. Application.Begin (top);
  3279. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  3280. Assert.Equal (3, tv.Lines);
  3281. Assert.Equal (Point.Empty, tv.CursorPosition);
  3282. var messy = " messy";
  3283. tv.CursorPosition = new Point (7, 0);
  3284. tv.SelectionStartColumn = 11;
  3285. tv.SelectionStartRow = 2;
  3286. Assert.Equal (51 + Environment.NewLine.Length * 2, tv.SelectedLength);
  3287. for (int i = 0; i < messy.Length; i++) {
  3288. tv.InsertText (messy [i].ToString ());
  3289. switch (i) {
  3290. case 0:
  3291. Assert.Equal ("This is third line.", tv.Text);
  3292. Assert.Equal (new Point (8, 0), tv.CursorPosition);
  3293. break;
  3294. case 1:
  3295. Assert.Equal ("This is m third line.", tv.Text);
  3296. Assert.Equal (new Point (9, 0), tv.CursorPosition);
  3297. break;
  3298. case 2:
  3299. Assert.Equal ("This is me third line.", tv.Text);
  3300. Assert.Equal (new Point (10, 0), tv.CursorPosition);
  3301. break;
  3302. case 3:
  3303. Assert.Equal ("This is mes third line.", tv.Text);
  3304. Assert.Equal (new Point (11, 0), tv.CursorPosition);
  3305. break;
  3306. case 4:
  3307. Assert.Equal ("This is mess third line.", tv.Text);
  3308. Assert.Equal (new Point (12, 0), tv.CursorPosition);
  3309. break;
  3310. case 5:
  3311. Assert.Equal ("This is messy third line.", tv.Text);
  3312. Assert.Equal (new Point (13, 0), tv.CursorPosition);
  3313. break;
  3314. }
  3315. }
  3316. Assert.Equal ($"This is messy third line.", tv.Text);
  3317. Assert.Equal (1, tv.Lines);
  3318. Assert.Equal (new Point (13, 0), tv.CursorPosition);
  3319. Assert.Equal (11, tv.SelectionStartColumn);
  3320. Assert.Equal (2, tv.SelectionStartRow);
  3321. Assert.Equal (0, tv.SelectedLength);
  3322. for (int i = 0; i < messy.Length; i++) {
  3323. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  3324. switch (i) {
  3325. case 0:
  3326. Assert.Equal ("This is mess third line.", tv.Text);
  3327. Assert.Equal (new Point (12, 0), tv.CursorPosition);
  3328. break;
  3329. case 1:
  3330. Assert.Equal ("This is mes third line.", tv.Text);
  3331. Assert.Equal (new Point (11, 0), tv.CursorPosition);
  3332. break;
  3333. case 2:
  3334. Assert.Equal ("This is me third line.", tv.Text);
  3335. Assert.Equal (new Point (10, 0), tv.CursorPosition);
  3336. break;
  3337. case 3:
  3338. Assert.Equal ("This is m third line.", tv.Text);
  3339. Assert.Equal (new Point (9, 0), tv.CursorPosition);
  3340. break;
  3341. case 4:
  3342. Assert.Equal ("This is third line.", tv.Text);
  3343. Assert.Equal (new Point (8, 0), tv.CursorPosition);
  3344. break;
  3345. case 5:
  3346. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  3347. Assert.Equal (new Point (7, 0), tv.CursorPosition);
  3348. break;
  3349. }
  3350. }
  3351. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  3352. Assert.Equal (3, tv.Lines);
  3353. Assert.Equal (new Point (7, 0), tv.CursorPosition);
  3354. Assert.Equal (11, tv.SelectionStartColumn);
  3355. Assert.Equal (2, tv.SelectionStartRow);
  3356. Assert.Equal (0, tv.SelectedLength);
  3357. for (int i = 0; i < messy.Length; i++) {
  3358. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  3359. switch (i) {
  3360. case 0:
  3361. Assert.Equal ("This is third line.", tv.Text);
  3362. Assert.Equal (new Point (8, 0), tv.CursorPosition);
  3363. break;
  3364. case 1:
  3365. Assert.Equal ("This is m third line.", tv.Text);
  3366. Assert.Equal (new Point (9, 0), tv.CursorPosition);
  3367. break;
  3368. case 2:
  3369. Assert.Equal ("This is me third line.", tv.Text);
  3370. Assert.Equal (new Point (10, 0), tv.CursorPosition);
  3371. break;
  3372. case 3:
  3373. Assert.Equal ("This is mes third line.", tv.Text);
  3374. Assert.Equal (new Point (11, 0), tv.CursorPosition);
  3375. break;
  3376. case 4:
  3377. Assert.Equal ("This is mess third line.", tv.Text);
  3378. Assert.Equal (new Point (12, 0), tv.CursorPosition);
  3379. break;
  3380. case 5:
  3381. Assert.Equal ("This is messy third line.", tv.Text);
  3382. Assert.Equal (new Point (13, 0), tv.CursorPosition);
  3383. break;
  3384. }
  3385. }
  3386. Assert.Equal ("This is messy third line.", tv.Text);
  3387. Assert.Equal (1, tv.Lines);
  3388. Assert.Equal (new Point (13, 0), tv.CursorPosition);
  3389. Assert.Equal (11, tv.SelectionStartColumn);
  3390. Assert.Equal (2, tv.SelectionStartRow);
  3391. Assert.Equal (0, tv.SelectedLength);
  3392. }
  3393. [Fact]
  3394. [AutoInitShutdown]
  3395. public void HistoryText_Undo_Redo_Multi_Line_With_Empty_Text ()
  3396. {
  3397. var tv = new TextView () {
  3398. Width = 10,
  3399. Height = 2
  3400. };
  3401. var top = Application.Top;
  3402. top.Add (tv);
  3403. Application.Begin (top);
  3404. Assert.Equal ("", tv.Text);
  3405. Assert.Equal (1, tv.Lines);
  3406. Assert.Equal (Point.Empty, tv.CursorPosition);
  3407. Assert.False (tv.IsDirty);
  3408. Assert.True (tv.ProcessKey (new KeyEvent (Key.O, new KeyModifiers ())));
  3409. Assert.Equal ("O", tv.Text);
  3410. Assert.Equal (1, tv.Lines);
  3411. Assert.Equal (new Point (1, 0), tv.CursorPosition);
  3412. Assert.True (tv.IsDirty);
  3413. Assert.True (tv.ProcessKey (new KeyEvent (Key.n, new KeyModifiers ())));
  3414. Assert.Equal ("On", tv.Text);
  3415. Assert.Equal (1, tv.Lines);
  3416. Assert.Equal (new Point (2, 0), tv.CursorPosition);
  3417. Assert.True (tv.IsDirty);
  3418. Assert.True (tv.ProcessKey (new KeyEvent (Key.e, new KeyModifiers ())));
  3419. Assert.Equal ("One", tv.Text);
  3420. Assert.Equal (1, tv.Lines);
  3421. Assert.Equal (new Point (3, 0), tv.CursorPosition);
  3422. Assert.True (tv.IsDirty);
  3423. Assert.True (tv.ProcessKey (new KeyEvent (Key.Enter, new KeyModifiers ())));
  3424. Assert.Equal ($"One{Environment.NewLine}", tv.Text);
  3425. Assert.Equal (2, tv.Lines);
  3426. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  3427. Assert.True (tv.IsDirty);
  3428. Assert.True (tv.ProcessKey (new KeyEvent (Key.T, new KeyModifiers ())));
  3429. Assert.Equal ($"One{Environment.NewLine}T", tv.Text);
  3430. Assert.Equal (2, tv.Lines);
  3431. Assert.Equal (new Point (1, 1), tv.CursorPosition);
  3432. Assert.True (tv.IsDirty);
  3433. Assert.True (tv.ProcessKey (new KeyEvent (Key.w, new KeyModifiers ())));
  3434. Assert.Equal ($"One{Environment.NewLine}Tw", tv.Text);
  3435. Assert.Equal (2, tv.Lines);
  3436. Assert.Equal (new Point (2, 1), tv.CursorPosition);
  3437. Assert.True (tv.IsDirty);
  3438. Assert.True (tv.ProcessKey (new KeyEvent (Key.o, new KeyModifiers ())));
  3439. Assert.Equal ($"One{Environment.NewLine}Two", tv.Text);
  3440. Assert.Equal (2, tv.Lines);
  3441. Assert.Equal (new Point (3, 1), tv.CursorPosition);
  3442. Assert.True (tv.IsDirty);
  3443. Assert.True (tv.ProcessKey (new KeyEvent (Key.Enter, new KeyModifiers ())));
  3444. Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}", tv.Text);
  3445. Assert.Equal (3, tv.Lines);
  3446. Assert.Equal (new Point (0, 2), tv.CursorPosition);
  3447. Assert.True (tv.IsDirty);
  3448. Assert.True (tv.ProcessKey (new KeyEvent (Key.T, new KeyModifiers ())));
  3449. Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}T", tv.Text);
  3450. Assert.Equal (3, tv.Lines);
  3451. Assert.Equal (new Point (1, 2), tv.CursorPosition);
  3452. Assert.True (tv.IsDirty);
  3453. Assert.True (tv.ProcessKey (new KeyEvent (Key.h, new KeyModifiers ())));
  3454. Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}Th", tv.Text);
  3455. Assert.Equal (3, tv.Lines);
  3456. Assert.Equal (new Point (2, 2), tv.CursorPosition);
  3457. Assert.True (tv.IsDirty);
  3458. Assert.True (tv.ProcessKey (new KeyEvent (Key.r, new KeyModifiers ())));
  3459. Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}Thr", tv.Text);
  3460. Assert.Equal (3, tv.Lines);
  3461. Assert.Equal (new Point (3, 2), tv.CursorPosition);
  3462. Assert.True (tv.IsDirty);
  3463. Assert.True (tv.ProcessKey (new KeyEvent (Key.e, new KeyModifiers ())));
  3464. Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}Thre", tv.Text);
  3465. Assert.Equal (3, tv.Lines);
  3466. Assert.Equal (new Point (4, 2), tv.CursorPosition);
  3467. Assert.True (tv.IsDirty);
  3468. Assert.True (tv.ProcessKey (new KeyEvent (Key.e, new KeyModifiers ())));
  3469. Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}Three", tv.Text);
  3470. Assert.Equal (3, tv.Lines);
  3471. Assert.Equal (new Point (5, 2), tv.CursorPosition);
  3472. Assert.True (tv.IsDirty);
  3473. Assert.True (tv.ProcessKey (new KeyEvent (Key.Enter, new KeyModifiers ())));
  3474. Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}Three{Environment.NewLine}", tv.Text);
  3475. Assert.Equal (4, tv.Lines);
  3476. Assert.Equal (new Point (0, 3), tv.CursorPosition);
  3477. Assert.True (tv.IsDirty);
  3478. // Undoing
  3479. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  3480. Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}Three", tv.Text);
  3481. Assert.Equal (3, tv.Lines);
  3482. Assert.Equal (new Point (5, 2), tv.CursorPosition);
  3483. Assert.True (tv.IsDirty);
  3484. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  3485. Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}Thre", tv.Text);
  3486. Assert.Equal (3, tv.Lines);
  3487. Assert.Equal (new Point (4, 2), tv.CursorPosition);
  3488. Assert.True (tv.IsDirty);
  3489. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  3490. Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}Thr", tv.Text);
  3491. Assert.Equal (3, tv.Lines);
  3492. Assert.Equal (new Point (3, 2), tv.CursorPosition);
  3493. Assert.True (tv.IsDirty);
  3494. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  3495. Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}Th", tv.Text);
  3496. Assert.Equal (3, tv.Lines);
  3497. Assert.Equal (new Point (2, 2), tv.CursorPosition);
  3498. Assert.True (tv.IsDirty);
  3499. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  3500. Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}T", tv.Text);
  3501. Assert.Equal (3, tv.Lines);
  3502. Assert.Equal (new Point (1, 2), tv.CursorPosition);
  3503. Assert.True (tv.IsDirty);
  3504. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  3505. Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}", tv.Text);
  3506. Assert.Equal (3, tv.Lines);
  3507. Assert.Equal (new Point (0, 2), tv.CursorPosition);
  3508. Assert.True (tv.IsDirty);
  3509. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  3510. Assert.Equal ($"One{Environment.NewLine}Two", tv.Text);
  3511. Assert.Equal (2, tv.Lines);
  3512. Assert.Equal (new Point (3, 1), tv.CursorPosition);
  3513. Assert.True (tv.IsDirty);
  3514. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  3515. Assert.Equal ($"One{Environment.NewLine}Tw", tv.Text);
  3516. Assert.Equal (2, tv.Lines);
  3517. Assert.Equal (new Point (2, 1), tv.CursorPosition);
  3518. Assert.True (tv.IsDirty);
  3519. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  3520. Assert.Equal ($"One{Environment.NewLine}T", tv.Text);
  3521. Assert.Equal (2, tv.Lines);
  3522. Assert.Equal (new Point (1, 1), tv.CursorPosition);
  3523. Assert.True (tv.IsDirty);
  3524. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  3525. Assert.Equal ($"One{Environment.NewLine}", tv.Text);
  3526. Assert.Equal (2, tv.Lines);
  3527. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  3528. Assert.True (tv.IsDirty);
  3529. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  3530. Assert.Equal ($"One", tv.Text);
  3531. Assert.Equal (1, tv.Lines);
  3532. Assert.Equal (new Point (3, 0), tv.CursorPosition);
  3533. Assert.True (tv.IsDirty);
  3534. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  3535. Assert.Equal ($"On", tv.Text);
  3536. Assert.Equal (1, tv.Lines);
  3537. Assert.Equal (new Point (2, 0), tv.CursorPosition);
  3538. Assert.True (tv.IsDirty);
  3539. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  3540. Assert.Equal ($"O", tv.Text);
  3541. Assert.Equal (1, tv.Lines);
  3542. Assert.Equal (new Point (1, 0), tv.CursorPosition);
  3543. Assert.True (tv.IsDirty);
  3544. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  3545. Assert.Equal ($"", tv.Text);
  3546. Assert.Equal (1, tv.Lines);
  3547. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  3548. Assert.False (tv.IsDirty);
  3549. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  3550. Assert.Equal ($"", tv.Text);
  3551. Assert.Equal (1, tv.Lines);
  3552. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  3553. Assert.False (tv.IsDirty);
  3554. // Redoing
  3555. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  3556. Assert.Equal ($"O", tv.Text);
  3557. Assert.Equal (1, tv.Lines);
  3558. Assert.Equal (new Point (1, 0), tv.CursorPosition);
  3559. Assert.True (tv.IsDirty);
  3560. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  3561. Assert.Equal ($"On", tv.Text);
  3562. Assert.Equal (1, tv.Lines);
  3563. Assert.Equal (new Point (2, 0), tv.CursorPosition);
  3564. Assert.True (tv.IsDirty);
  3565. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  3566. Assert.Equal ($"One", tv.Text);
  3567. Assert.Equal (1, tv.Lines);
  3568. Assert.Equal (new Point (3, 0), tv.CursorPosition);
  3569. Assert.True (tv.IsDirty);
  3570. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  3571. Assert.Equal ($"One{Environment.NewLine}", tv.Text);
  3572. Assert.Equal (2, tv.Lines);
  3573. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  3574. Assert.True (tv.IsDirty);
  3575. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  3576. Assert.Equal ($"One{Environment.NewLine}T", tv.Text);
  3577. Assert.Equal (2, tv.Lines);
  3578. Assert.Equal (new Point (1, 1), tv.CursorPosition);
  3579. Assert.True (tv.IsDirty);
  3580. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  3581. Assert.Equal ($"One{Environment.NewLine}Tw", tv.Text);
  3582. Assert.Equal (2, tv.Lines);
  3583. Assert.Equal (new Point (2, 1), tv.CursorPosition);
  3584. Assert.True (tv.IsDirty);
  3585. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  3586. Assert.Equal ($"One{Environment.NewLine}Two", tv.Text);
  3587. Assert.Equal (2, tv.Lines);
  3588. Assert.Equal (new Point (3, 1), tv.CursorPosition);
  3589. Assert.True (tv.IsDirty);
  3590. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  3591. Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}", tv.Text);
  3592. Assert.Equal (3, tv.Lines);
  3593. Assert.Equal (new Point (0, 2), tv.CursorPosition);
  3594. Assert.True (tv.IsDirty);
  3595. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  3596. Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}T", tv.Text);
  3597. Assert.Equal (3, tv.Lines);
  3598. Assert.Equal (new Point (1, 2), tv.CursorPosition);
  3599. Assert.True (tv.IsDirty);
  3600. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  3601. Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}Th", tv.Text);
  3602. Assert.Equal (3, tv.Lines);
  3603. Assert.Equal (new Point (2, 2), tv.CursorPosition);
  3604. Assert.True (tv.IsDirty);
  3605. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  3606. Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}Thr", tv.Text);
  3607. Assert.Equal (3, tv.Lines);
  3608. Assert.Equal (new Point (3, 2), tv.CursorPosition);
  3609. Assert.True (tv.IsDirty);
  3610. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  3611. Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}Thre", tv.Text);
  3612. Assert.Equal (3, tv.Lines);
  3613. Assert.Equal (new Point (4, 2), tv.CursorPosition);
  3614. Assert.True (tv.IsDirty);
  3615. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  3616. Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}Three", tv.Text);
  3617. Assert.Equal (3, tv.Lines);
  3618. Assert.Equal (new Point (5, 2), tv.CursorPosition);
  3619. Assert.True (tv.IsDirty);
  3620. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  3621. Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}Three{Environment.NewLine}", tv.Text);
  3622. Assert.Equal (4, tv.Lines);
  3623. Assert.Equal (new Point (0, 3), tv.CursorPosition);
  3624. Assert.True (tv.IsDirty);
  3625. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  3626. Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}Three{Environment.NewLine}", tv.Text);
  3627. Assert.Equal (4, tv.Lines);
  3628. Assert.Equal (new Point (0, 3), tv.CursorPosition);
  3629. Assert.True (tv.IsDirty);
  3630. }
  3631. [Fact]
  3632. [AutoInitShutdown]
  3633. public void HistoryText_Undo_Redo_Multi_Line_Selected_With_Empty_Text ()
  3634. {
  3635. var tv = new TextView () {
  3636. Width = 10,
  3637. Height = 2
  3638. };
  3639. var top = Application.Top;
  3640. top.Add (tv);
  3641. Application.Begin (top);
  3642. Assert.Equal ("", tv.Text);
  3643. Assert.Equal (1, tv.Lines);
  3644. Assert.Equal (Point.Empty, tv.CursorPosition);
  3645. Assert.False (tv.IsDirty);
  3646. Assert.True (tv.ProcessKey (new KeyEvent (Key.O, new KeyModifiers ())));
  3647. Assert.Equal ("O", tv.Text);
  3648. Assert.Equal (1, tv.Lines);
  3649. Assert.Equal (new Point (1, 0), tv.CursorPosition);
  3650. Assert.True (tv.IsDirty);
  3651. Assert.True (tv.ProcessKey (new KeyEvent (Key.n, new KeyModifiers ())));
  3652. Assert.Equal ("On", tv.Text);
  3653. Assert.Equal (1, tv.Lines);
  3654. Assert.Equal (new Point (2, 0), tv.CursorPosition);
  3655. Assert.True (tv.IsDirty);
  3656. Assert.True (tv.ProcessKey (new KeyEvent (Key.e, new KeyModifiers ())));
  3657. Assert.Equal ("One", tv.Text);
  3658. Assert.Equal (1, tv.Lines);
  3659. Assert.Equal (new Point (3, 0), tv.CursorPosition);
  3660. Assert.True (tv.IsDirty);
  3661. Assert.True (tv.ProcessKey (new KeyEvent (Key.Enter, new KeyModifiers ())));
  3662. Assert.Equal ($"One{Environment.NewLine}", tv.Text);
  3663. Assert.Equal (2, tv.Lines);
  3664. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  3665. Assert.True (tv.IsDirty);
  3666. Assert.True (tv.ProcessKey (new KeyEvent (Key.T, new KeyModifiers ())));
  3667. Assert.Equal ($"One{Environment.NewLine}T", tv.Text);
  3668. Assert.Equal (2, tv.Lines);
  3669. Assert.Equal (new Point (1, 1), tv.CursorPosition);
  3670. Assert.True (tv.IsDirty);
  3671. Assert.True (tv.ProcessKey (new KeyEvent (Key.w, new KeyModifiers ())));
  3672. Assert.Equal ($"One{Environment.NewLine}Tw", tv.Text);
  3673. Assert.Equal (2, tv.Lines);
  3674. Assert.Equal (new Point (2, 1), tv.CursorPosition);
  3675. Assert.True (tv.IsDirty);
  3676. Assert.True (tv.ProcessKey (new KeyEvent (Key.o, new KeyModifiers ())));
  3677. Assert.Equal ($"One{Environment.NewLine}Two", tv.Text);
  3678. Assert.Equal (2, tv.Lines);
  3679. Assert.Equal (new Point (3, 1), tv.CursorPosition);
  3680. Assert.True (tv.IsDirty);
  3681. Assert.True (tv.ProcessKey (new KeyEvent (Key.Enter, new KeyModifiers ())));
  3682. Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}", tv.Text);
  3683. Assert.Equal (3, tv.Lines);
  3684. Assert.Equal (new Point (0, 2), tv.CursorPosition);
  3685. Assert.True (tv.IsDirty);
  3686. Assert.True (tv.ProcessKey (new KeyEvent (Key.T, new KeyModifiers ())));
  3687. Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}T", tv.Text);
  3688. Assert.Equal (3, tv.Lines);
  3689. Assert.Equal (new Point (1, 2), tv.CursorPosition);
  3690. Assert.True (tv.IsDirty);
  3691. Assert.True (tv.ProcessKey (new KeyEvent (Key.h, new KeyModifiers ())));
  3692. Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}Th", tv.Text);
  3693. Assert.Equal (3, tv.Lines);
  3694. Assert.Equal (new Point (2, 2), tv.CursorPosition);
  3695. Assert.True (tv.IsDirty);
  3696. Assert.True (tv.ProcessKey (new KeyEvent (Key.r, new KeyModifiers ())));
  3697. Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}Thr", tv.Text);
  3698. Assert.Equal (3, tv.Lines);
  3699. Assert.Equal (new Point (3, 2), tv.CursorPosition);
  3700. Assert.True (tv.IsDirty);
  3701. Assert.True (tv.ProcessKey (new KeyEvent (Key.e, new KeyModifiers ())));
  3702. Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}Thre", tv.Text);
  3703. Assert.Equal (3, tv.Lines);
  3704. Assert.Equal (new Point (4, 2), tv.CursorPosition);
  3705. Assert.True (tv.IsDirty);
  3706. Assert.True (tv.ProcessKey (new KeyEvent (Key.e, new KeyModifiers ())));
  3707. Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}Three", tv.Text);
  3708. Assert.Equal (3, tv.Lines);
  3709. Assert.Equal (new Point (5, 2), tv.CursorPosition);
  3710. Assert.True (tv.IsDirty);
  3711. Assert.True (tv.ProcessKey (new KeyEvent (Key.Enter, new KeyModifiers ())));
  3712. Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}Three{Environment.NewLine}", tv.Text);
  3713. Assert.Equal (4, tv.Lines);
  3714. Assert.Equal (new Point (0, 3), tv.CursorPosition);
  3715. Assert.True (tv.IsDirty);
  3716. tv.SelectionStartColumn = 0;
  3717. tv.SelectionStartRow = 0;
  3718. tv.CursorPosition = new Point (0, 1);
  3719. Assert.Equal (3 + Environment.NewLine.Length, tv.SelectedLength);
  3720. Assert.True (tv.ProcessKey (new KeyEvent (Key.D1, new KeyModifiers ())));
  3721. Assert.Equal ($"1Two{Environment.NewLine}Three{Environment.NewLine}", tv.Text);
  3722. Assert.Equal (3, tv.Lines);
  3723. Assert.Equal (new Point (1, 0), tv.CursorPosition);
  3724. Assert.Equal (0, tv.SelectedLength);
  3725. Assert.True (tv.IsDirty);
  3726. tv.SelectionStartColumn = 1;
  3727. tv.SelectionStartRow = 0;
  3728. tv.CursorPosition = new Point (1, 1);
  3729. Assert.Equal (4 + Environment.NewLine.Length, tv.SelectedLength);
  3730. Assert.True (tv.ProcessKey (new KeyEvent (Key.D2, new KeyModifiers ())));
  3731. Assert.Equal ($"12hree{Environment.NewLine}", tv.Text);
  3732. Assert.Equal (2, tv.Lines);
  3733. Assert.Equal (new Point (2, 0), tv.CursorPosition);
  3734. Assert.Equal (0, tv.SelectedLength);
  3735. Assert.True (tv.IsDirty);
  3736. // Undoing
  3737. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  3738. Assert.Equal ($"1Two{Environment.NewLine}Three{Environment.NewLine}", tv.Text);
  3739. Assert.Equal (3, tv.Lines);
  3740. Assert.Equal (new Point (1, 1), tv.CursorPosition);
  3741. Assert.Equal (0, tv.SelectedLength);
  3742. Assert.True (tv.IsDirty);
  3743. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  3744. Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}Three{Environment.NewLine}", tv.Text);
  3745. Assert.Equal (4, tv.Lines);
  3746. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  3747. Assert.Equal (0, tv.SelectedLength);
  3748. Assert.True (tv.IsDirty);
  3749. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  3750. Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}Three", tv.Text);
  3751. Assert.Equal (3, tv.Lines);
  3752. Assert.Equal (new Point (5, 2), tv.CursorPosition);
  3753. Assert.Equal (0, tv.SelectedLength);
  3754. Assert.True (tv.IsDirty);
  3755. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  3756. Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}Thre", tv.Text);
  3757. Assert.Equal (3, tv.Lines);
  3758. Assert.Equal (new Point (4, 2), tv.CursorPosition);
  3759. Assert.True (tv.IsDirty);
  3760. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  3761. Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}Thr", tv.Text);
  3762. Assert.Equal (3, tv.Lines);
  3763. Assert.Equal (new Point (3, 2), tv.CursorPosition);
  3764. Assert.Equal (0, tv.SelectedLength);
  3765. Assert.True (tv.IsDirty);
  3766. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  3767. Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}Th", tv.Text);
  3768. Assert.Equal (3, tv.Lines);
  3769. Assert.Equal (new Point (2, 2), tv.CursorPosition);
  3770. Assert.Equal (0, tv.SelectedLength);
  3771. Assert.True (tv.IsDirty);
  3772. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  3773. Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}T", tv.Text);
  3774. Assert.Equal (3, tv.Lines);
  3775. Assert.Equal (new Point (1, 2), tv.CursorPosition);
  3776. Assert.Equal (0, tv.SelectedLength);
  3777. Assert.True (tv.IsDirty);
  3778. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  3779. Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}", tv.Text);
  3780. Assert.Equal (3, tv.Lines);
  3781. Assert.Equal (new Point (0, 2), tv.CursorPosition);
  3782. Assert.Equal (0, tv.SelectedLength);
  3783. Assert.True (tv.IsDirty);
  3784. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  3785. Assert.Equal ($"One{Environment.NewLine}Two", tv.Text);
  3786. Assert.Equal (2, tv.Lines);
  3787. Assert.Equal (new Point (3, 1), tv.CursorPosition);
  3788. Assert.Equal (0, tv.SelectedLength);
  3789. Assert.True (tv.IsDirty);
  3790. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  3791. Assert.Equal ($"One{Environment.NewLine}Tw", tv.Text);
  3792. Assert.Equal (2, tv.Lines);
  3793. Assert.Equal (new Point (2, 1), tv.CursorPosition);
  3794. Assert.Equal (0, tv.SelectedLength);
  3795. Assert.True (tv.IsDirty);
  3796. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  3797. Assert.Equal ($"One{Environment.NewLine}T", tv.Text);
  3798. Assert.Equal (2, tv.Lines);
  3799. Assert.Equal (new Point (1, 1), tv.CursorPosition);
  3800. Assert.Equal (0, tv.SelectedLength);
  3801. Assert.True (tv.IsDirty);
  3802. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  3803. Assert.Equal ($"One{Environment.NewLine}", tv.Text);
  3804. Assert.Equal (2, tv.Lines);
  3805. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  3806. Assert.Equal (0, tv.SelectedLength);
  3807. Assert.True (tv.IsDirty);
  3808. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  3809. Assert.Equal ($"One", tv.Text);
  3810. Assert.Equal (1, tv.Lines);
  3811. Assert.Equal (new Point (3, 0), tv.CursorPosition);
  3812. Assert.Equal (0, tv.SelectedLength);
  3813. Assert.True (tv.IsDirty);
  3814. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  3815. Assert.Equal ($"On", tv.Text);
  3816. Assert.Equal (1, tv.Lines);
  3817. Assert.Equal (new Point (2, 0), tv.CursorPosition);
  3818. Assert.Equal (0, tv.SelectedLength);
  3819. Assert.True (tv.IsDirty);
  3820. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  3821. Assert.Equal ($"O", tv.Text);
  3822. Assert.Equal (1, tv.Lines);
  3823. Assert.Equal (new Point (1, 0), tv.CursorPosition);
  3824. Assert.Equal (0, tv.SelectedLength);
  3825. Assert.True (tv.IsDirty);
  3826. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  3827. Assert.Equal ($"", tv.Text);
  3828. Assert.Equal (1, tv.Lines);
  3829. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  3830. Assert.Equal (0, tv.SelectedLength);
  3831. Assert.False (tv.IsDirty);
  3832. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  3833. Assert.Equal ($"", tv.Text);
  3834. Assert.Equal (1, tv.Lines);
  3835. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  3836. Assert.Equal (0, tv.SelectedLength);
  3837. Assert.False (tv.IsDirty);
  3838. // Redoing
  3839. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  3840. Assert.Equal ($"O", tv.Text);
  3841. Assert.Equal (1, tv.Lines);
  3842. Assert.Equal (new Point (1, 0), tv.CursorPosition);
  3843. Assert.Equal (0, tv.SelectedLength);
  3844. Assert.True (tv.IsDirty);
  3845. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  3846. Assert.Equal ($"On", tv.Text);
  3847. Assert.Equal (1, tv.Lines);
  3848. Assert.Equal (new Point (2, 0), tv.CursorPosition);
  3849. Assert.Equal (0, tv.SelectedLength);
  3850. Assert.True (tv.IsDirty);
  3851. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  3852. Assert.Equal ($"One", tv.Text);
  3853. Assert.Equal (1, tv.Lines);
  3854. Assert.Equal (new Point (3, 0), tv.CursorPosition);
  3855. Assert.Equal (0, tv.SelectedLength);
  3856. Assert.True (tv.IsDirty);
  3857. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  3858. Assert.Equal ($"One{Environment.NewLine}", tv.Text);
  3859. Assert.Equal (2, tv.Lines);
  3860. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  3861. Assert.Equal (0, tv.SelectedLength);
  3862. Assert.True (tv.IsDirty);
  3863. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  3864. Assert.Equal ($"One{Environment.NewLine}T", tv.Text);
  3865. Assert.Equal (2, tv.Lines);
  3866. Assert.Equal (new Point (1, 1), tv.CursorPosition);
  3867. Assert.Equal (0, tv.SelectedLength);
  3868. Assert.True (tv.IsDirty);
  3869. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  3870. Assert.Equal ($"One{Environment.NewLine}Tw", tv.Text);
  3871. Assert.Equal (2, tv.Lines);
  3872. Assert.Equal (new Point (2, 1), tv.CursorPosition);
  3873. Assert.Equal (0, tv.SelectedLength);
  3874. Assert.True (tv.IsDirty);
  3875. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  3876. Assert.Equal ($"One{Environment.NewLine}Two", tv.Text);
  3877. Assert.Equal (2, tv.Lines);
  3878. Assert.Equal (new Point (3, 1), tv.CursorPosition);
  3879. Assert.Equal (0, tv.SelectedLength);
  3880. Assert.True (tv.IsDirty);
  3881. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  3882. Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}", tv.Text);
  3883. Assert.Equal (3, tv.Lines);
  3884. Assert.Equal (new Point (0, 2), tv.CursorPosition);
  3885. Assert.Equal (0, tv.SelectedLength);
  3886. Assert.True (tv.IsDirty);
  3887. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  3888. Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}T", tv.Text);
  3889. Assert.Equal (3, tv.Lines);
  3890. Assert.Equal (new Point (1, 2), tv.CursorPosition);
  3891. Assert.Equal (0, tv.SelectedLength);
  3892. Assert.True (tv.IsDirty);
  3893. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  3894. Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}Th", tv.Text);
  3895. Assert.Equal (3, tv.Lines);
  3896. Assert.Equal (new Point (2, 2), tv.CursorPosition);
  3897. Assert.Equal (0, tv.SelectedLength);
  3898. Assert.True (tv.IsDirty);
  3899. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  3900. Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}Thr", tv.Text);
  3901. Assert.Equal (3, tv.Lines);
  3902. Assert.Equal (new Point (3, 2), tv.CursorPosition);
  3903. Assert.Equal (0, tv.SelectedLength);
  3904. Assert.True (tv.IsDirty);
  3905. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  3906. Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}Thre", tv.Text);
  3907. Assert.Equal (3, tv.Lines);
  3908. Assert.Equal (new Point (4, 2), tv.CursorPosition);
  3909. Assert.Equal (0, tv.SelectedLength);
  3910. Assert.True (tv.IsDirty);
  3911. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  3912. Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}Three", tv.Text);
  3913. Assert.Equal (3, tv.Lines);
  3914. Assert.Equal (new Point (5, 2), tv.CursorPosition);
  3915. Assert.Equal (0, tv.SelectedLength);
  3916. Assert.True (tv.IsDirty);
  3917. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  3918. Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}Three{Environment.NewLine}", tv.Text);
  3919. Assert.Equal (4, tv.Lines);
  3920. Assert.Equal (new Point (0, 3), tv.CursorPosition);
  3921. Assert.Equal (0, tv.SelectedLength);
  3922. Assert.True (tv.IsDirty);
  3923. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  3924. Assert.Equal ($"1Two{Environment.NewLine}Three{Environment.NewLine}", tv.Text);
  3925. Assert.Equal (3, tv.Lines);
  3926. Assert.Equal (new Point (1, 0), tv.CursorPosition);
  3927. Assert.Equal (0, tv.SelectedLength);
  3928. Assert.True (tv.IsDirty);
  3929. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  3930. Assert.Equal ($"12hree{Environment.NewLine}", tv.Text);
  3931. Assert.Equal (2, tv.Lines);
  3932. Assert.Equal (new Point (2, 0), tv.CursorPosition);
  3933. Assert.Equal (0, tv.SelectedLength);
  3934. Assert.True (tv.IsDirty);
  3935. }
  3936. [Fact]
  3937. [AutoInitShutdown]
  3938. public void HistoryText_Undo_Redo_Multi_Line_Selected_InsertText_Twice_On_Same_Line ()
  3939. {
  3940. var text = "One\nTwo\nThree";
  3941. var tv = new TextView () {
  3942. Width = 10,
  3943. Height = 2,
  3944. Text = text
  3945. };
  3946. var top = Application.Top;
  3947. top.Add (tv);
  3948. Application.Begin (top);
  3949. Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}Three", tv.Text);
  3950. Assert.Equal (3, tv.Lines);
  3951. Assert.Equal (Point.Empty, tv.CursorPosition);
  3952. Assert.False (tv.IsDirty);
  3953. tv.SelectionStartColumn = 0;
  3954. tv.SelectionStartRow = 0;
  3955. tv.CursorPosition = new Point (0, 1);
  3956. Assert.Equal (3 + Environment.NewLine.Length, tv.SelectedLength);
  3957. Assert.True (tv.ProcessKey (new KeyEvent (Key.D1, new KeyModifiers ())));
  3958. Assert.Equal ($"1Two{Environment.NewLine}Three", tv.Text);
  3959. Assert.Equal (new Point (1, 0), tv.CursorPosition);
  3960. Assert.Equal (0, tv.SelectedLength);
  3961. Assert.True (tv.IsDirty);
  3962. tv.SelectionStartColumn = 1;
  3963. tv.SelectionStartRow = 0;
  3964. tv.CursorPosition = new Point (1, 1);
  3965. Assert.Equal (4 + Environment.NewLine.Length, tv.SelectedLength);
  3966. Assert.True (tv.ProcessKey (new KeyEvent (Key.D2, new KeyModifiers ())));
  3967. Assert.Equal ("12hree", tv.Text);
  3968. Assert.Equal (new Point (2, 0), tv.CursorPosition);
  3969. Assert.Equal (0, tv.SelectedLength);
  3970. Assert.True (tv.IsDirty);
  3971. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  3972. Assert.Equal ($"1Two{Environment.NewLine}Three", tv.Text);
  3973. Assert.Equal (new Point (1, 1), tv.CursorPosition);
  3974. Assert.Equal (0, tv.SelectedLength);
  3975. Assert.True (tv.IsDirty);
  3976. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  3977. Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}Three", tv.Text);
  3978. Assert.Equal (3, tv.Lines);
  3979. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  3980. Assert.Equal (0, tv.SelectedLength);
  3981. Assert.False (tv.IsDirty);
  3982. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  3983. Assert.Equal ($"1Two{Environment.NewLine}Three", tv.Text);
  3984. Assert.Equal (new Point (1, 0), tv.CursorPosition);
  3985. Assert.Equal (0, tv.SelectedLength);
  3986. Assert.True (tv.IsDirty);
  3987. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  3988. Assert.Equal ("12hree", tv.Text);
  3989. Assert.Equal (new Point (2, 0), tv.CursorPosition);
  3990. Assert.Equal (0, tv.SelectedLength);
  3991. Assert.True (tv.IsDirty);
  3992. }
  3993. [Fact]
  3994. [AutoInitShutdown]
  3995. public void HistoryText_Undo_Redo_Multi_Line_Selected_InsertText_Twice_On_Same_Line_With_End_Line ()
  3996. {
  3997. var text = "One\nTwo\nThree\n";
  3998. var tv = new TextView () {
  3999. Width = 10,
  4000. Height = 2,
  4001. Text = text
  4002. };
  4003. var top = Application.Top;
  4004. top.Add (tv);
  4005. Application.Begin (top);
  4006. Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}Three{Environment.NewLine}", tv.Text);
  4007. Assert.Equal (4, tv.Lines);
  4008. Assert.Equal (Point.Empty, tv.CursorPosition);
  4009. Assert.False (tv.IsDirty);
  4010. tv.SelectionStartColumn = 0;
  4011. tv.SelectionStartRow = 0;
  4012. tv.CursorPosition = new Point (0, 1);
  4013. Assert.Equal (3 + Environment.NewLine.Length, tv.SelectedLength);
  4014. Assert.True (tv.ProcessKey (new KeyEvent (Key.D1, new KeyModifiers ())));
  4015. Assert.Equal ($"1Two{Environment.NewLine}Three{Environment.NewLine}", tv.Text);
  4016. Assert.Equal (new Point (1, 0), tv.CursorPosition);
  4017. Assert.Equal (0, tv.SelectedLength);
  4018. Assert.True (tv.IsDirty);
  4019. tv.SelectionStartColumn = 1;
  4020. tv.SelectionStartRow = 0;
  4021. tv.CursorPosition = new Point (1, 1);
  4022. Assert.Equal (4 + Environment.NewLine.Length, tv.SelectedLength);
  4023. Assert.True (tv.ProcessKey (new KeyEvent (Key.D2, new KeyModifiers ())));
  4024. Assert.Equal ($"12hree{Environment.NewLine}", tv.Text);
  4025. Assert.Equal (new Point (2, 0), tv.CursorPosition);
  4026. Assert.Equal (0, tv.SelectedLength);
  4027. Assert.True (tv.IsDirty);
  4028. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  4029. Assert.Equal ($"1Two{Environment.NewLine}Three{Environment.NewLine}", tv.Text);
  4030. Assert.Equal (new Point (1, 1), tv.CursorPosition);
  4031. Assert.Equal (0, tv.SelectedLength);
  4032. Assert.True (tv.IsDirty);
  4033. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  4034. Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}Three{Environment.NewLine}", tv.Text);
  4035. Assert.Equal (4, tv.Lines);
  4036. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  4037. Assert.Equal (0, tv.SelectedLength);
  4038. Assert.False (tv.IsDirty);
  4039. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  4040. Assert.Equal ($"1Two{Environment.NewLine}Three{Environment.NewLine}", tv.Text);
  4041. Assert.Equal (new Point (1, 0), tv.CursorPosition);
  4042. Assert.Equal (0, tv.SelectedLength);
  4043. Assert.True (tv.IsDirty);
  4044. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  4045. Assert.Equal ($"12hree{Environment.NewLine}", tv.Text);
  4046. Assert.Equal (new Point (2, 0), tv.CursorPosition);
  4047. Assert.Equal (0, tv.SelectedLength);
  4048. Assert.True (tv.IsDirty);
  4049. }
  4050. [Fact]
  4051. public void HistoryText_IsDirty_HasHistoryChanges ()
  4052. {
  4053. var tv = new TextView ();
  4054. Assert.Equal ("", tv.Text);
  4055. Assert.Equal (1, tv.Lines);
  4056. Assert.Equal (Point.Empty, tv.CursorPosition);
  4057. Assert.False (tv.IsDirty);
  4058. Assert.False (tv.HasHistoryChanges);
  4059. Assert.True (tv.ProcessKey (new KeyEvent (Key.D1, new KeyModifiers ())));
  4060. Assert.Equal ("1", tv.Text);
  4061. Assert.Equal (1, tv.Lines);
  4062. Assert.Equal (new Point (1, 0), tv.CursorPosition);
  4063. Assert.True (tv.IsDirty);
  4064. Assert.True (tv.HasHistoryChanges);
  4065. Assert.True (tv.ProcessKey (new KeyEvent (Key.Enter, new KeyModifiers ())));
  4066. Assert.Equal ($"1{Environment.NewLine}", tv.Text);
  4067. Assert.Equal (2, tv.Lines);
  4068. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  4069. Assert.True (tv.IsDirty);
  4070. Assert.True (tv.HasHistoryChanges);
  4071. Assert.True (tv.ProcessKey (new KeyEvent (Key.D2, new KeyModifiers ())));
  4072. Assert.Equal ($"1{Environment.NewLine}2", tv.Text);
  4073. Assert.Equal (2, tv.Lines);
  4074. Assert.Equal (new Point (1, 1), tv.CursorPosition);
  4075. Assert.True (tv.IsDirty);
  4076. Assert.True (tv.HasHistoryChanges);
  4077. Assert.True (tv.ProcessKey (new KeyEvent (Key.Backspace, new KeyModifiers ())));
  4078. Assert.Equal ($"1{Environment.NewLine}", tv.Text);
  4079. Assert.Equal (2, tv.Lines);
  4080. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  4081. Assert.True (tv.IsDirty);
  4082. Assert.True (tv.HasHistoryChanges);
  4083. Assert.True (tv.ProcessKey (new KeyEvent (Key.Backspace, new KeyModifiers ())));
  4084. Assert.Equal ($"1", tv.Text);
  4085. Assert.Equal (1, tv.Lines);
  4086. Assert.Equal (new Point (1, 0), tv.CursorPosition);
  4087. Assert.True (tv.IsDirty);
  4088. Assert.True (tv.HasHistoryChanges);
  4089. Assert.True (tv.ProcessKey (new KeyEvent (Key.Backspace, new KeyModifiers ())));
  4090. Assert.Equal ($"", tv.Text);
  4091. Assert.Equal (1, tv.Lines);
  4092. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  4093. // IsDirty cannot be based on HasHistoryChanges because HasHistoryChanges is greater than 0
  4094. // The only way is comparing from the original text
  4095. Assert.False (tv.IsDirty);
  4096. // Still true because HasHistoryChanges is greater than 0
  4097. Assert.True (tv.HasHistoryChanges);
  4098. }
  4099. [Fact]
  4100. public void HistoryText_Undo_Redo_Multi_Line_Selected_DeleteCharLeft_All ()
  4101. {
  4102. var text = "This is the first line.\nThis is the second line.\nThis is the third line.";
  4103. var tv = new TextView () { Text = text };
  4104. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  4105. Assert.Equal (3, tv.Lines);
  4106. Assert.Equal (Point.Empty, tv.CursorPosition);
  4107. Assert.False (tv.IsDirty);
  4108. Assert.False (tv.HasHistoryChanges);
  4109. Assert.True (tv.ProcessKey (new KeyEvent (Key.End | Key.CtrlMask | Key.ShiftMask, new KeyModifiers ())));
  4110. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  4111. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.SelectedText);
  4112. Assert.Equal (3, tv.Lines);
  4113. Assert.Equal (new Point (23, 2), tv.CursorPosition);
  4114. Assert.Equal (70 + Environment.NewLine.Length * 2, tv.SelectedLength);
  4115. Assert.False (tv.IsDirty);
  4116. Assert.False (tv.HasHistoryChanges);
  4117. Assert.True (tv.ProcessKey (new KeyEvent (Key.Backspace, new KeyModifiers ())));
  4118. Assert.Equal ("", tv.Text);
  4119. Assert.Equal ("", tv.SelectedText);
  4120. Assert.Equal (1, tv.Lines);
  4121. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  4122. Assert.Equal (0, tv.SelectedLength);
  4123. Assert.True (tv.IsDirty);
  4124. Assert.True (tv.HasHistoryChanges);
  4125. // Undo
  4126. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  4127. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  4128. Assert.Equal ("", tv.SelectedText);
  4129. Assert.Equal (3, tv.Lines);
  4130. Assert.Equal (new Point (23, 2), tv.CursorPosition);
  4131. Assert.Equal (0, tv.SelectedLength);
  4132. Assert.False (tv.IsDirty);
  4133. Assert.True (tv.HasHistoryChanges);
  4134. // Redo
  4135. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  4136. Assert.Equal ("", tv.Text);
  4137. Assert.Equal ("", tv.SelectedText);
  4138. Assert.Equal (1, tv.Lines);
  4139. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  4140. Assert.Equal (0, tv.SelectedLength);
  4141. Assert.True (tv.IsDirty);
  4142. Assert.True (tv.HasHistoryChanges);
  4143. }
  4144. [Fact]
  4145. public void HistoryText_Undo_Redo_Multi_Line_Selected_DeleteCharRight_All ()
  4146. {
  4147. var text = "This is the first line.\nThis is the second line.\nThis is the third line.";
  4148. var tv = new TextView () { Text = text };
  4149. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  4150. Assert.Equal (3, tv.Lines);
  4151. Assert.Equal (Point.Empty, tv.CursorPosition);
  4152. Assert.False (tv.IsDirty);
  4153. Assert.False (tv.HasHistoryChanges);
  4154. Assert.True (tv.ProcessKey (new KeyEvent (Key.End | Key.CtrlMask | Key.ShiftMask, new KeyModifiers ())));
  4155. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  4156. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.SelectedText);
  4157. Assert.Equal (3, tv.Lines);
  4158. Assert.Equal (new Point (23, 2), tv.CursorPosition);
  4159. Assert.Equal (70 + Environment.NewLine.Length * 2, tv.SelectedLength);
  4160. Assert.False (tv.IsDirty);
  4161. Assert.False (tv.HasHistoryChanges);
  4162. Assert.True (tv.ProcessKey (new KeyEvent (Key.DeleteChar, new KeyModifiers ())));
  4163. Assert.Equal ("", tv.Text);
  4164. Assert.Equal ("", tv.SelectedText);
  4165. Assert.Equal (1, tv.Lines);
  4166. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  4167. Assert.Equal (0, tv.SelectedLength);
  4168. Assert.True (tv.IsDirty);
  4169. Assert.True (tv.HasHistoryChanges);
  4170. // Undo
  4171. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  4172. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  4173. Assert.Equal ("", tv.SelectedText);
  4174. Assert.Equal (3, tv.Lines);
  4175. Assert.Equal (new Point (23, 2), tv.CursorPosition);
  4176. Assert.Equal (0, tv.SelectedLength);
  4177. Assert.False (tv.IsDirty);
  4178. Assert.True (tv.HasHistoryChanges);
  4179. // Redo
  4180. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  4181. Assert.Equal ("", tv.Text);
  4182. Assert.Equal ("", tv.SelectedText);
  4183. Assert.Equal (1, tv.Lines);
  4184. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  4185. Assert.Equal (0, tv.SelectedLength);
  4186. Assert.True (tv.IsDirty);
  4187. Assert.True (tv.HasHistoryChanges);
  4188. }
  4189. [Fact]
  4190. [AutoInitShutdown]
  4191. public void HistoryText_Undo_Redo_Copy_Without_Selection_Multi_Line_Paste ()
  4192. {
  4193. var text = "This is the first line.\nThis is the second line.\nThis is the third line.";
  4194. var tv = new TextView () { Text = text };
  4195. tv.CursorPosition = new Point (23, 0);
  4196. Assert.True (tv.ProcessKey (new KeyEvent (Key.C | Key.CtrlMask, new KeyModifiers ())));
  4197. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  4198. Assert.Equal ("", tv.SelectedText);
  4199. Assert.Equal ("This is the first line.", Clipboard.Contents);
  4200. Assert.Equal (3, tv.Lines);
  4201. Assert.Equal (new Point (23, 0), tv.CursorPosition);
  4202. Assert.True (tv.ProcessKey (new KeyEvent (Key.Y | Key.CtrlMask, new KeyModifiers ())));
  4203. 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);
  4204. Assert.Equal (4, tv.Lines);
  4205. Assert.Equal (new Point (23, 1), tv.CursorPosition);
  4206. // Undo
  4207. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  4208. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  4209. Assert.Equal (3, tv.Lines);
  4210. Assert.Equal (new Point (23, 0), tv.CursorPosition);
  4211. // Redo
  4212. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  4213. 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);
  4214. Assert.Equal (4, tv.Lines);
  4215. Assert.Equal (new Point (23, 1), tv.CursorPosition);
  4216. }
  4217. [Fact]
  4218. [AutoInitShutdown]
  4219. public void HistoryText_Undo_Redo_Simple_Copy_Multi_Line_Selected_Paste ()
  4220. {
  4221. var text = "This is the first line.\nThis is the second line.\nThis is the third line.";
  4222. var tv = new TextView () { Text = text };
  4223. tv.SelectionStartColumn = 12;
  4224. tv.CursorPosition = new Point (17, 0);
  4225. Assert.True (tv.ProcessKey (new KeyEvent (Key.C | Key.CtrlMask, new KeyModifiers ())));
  4226. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  4227. Assert.Equal ("first", tv.SelectedText);
  4228. Assert.Equal (3, tv.Lines);
  4229. Assert.Equal (new Point (17, 0), tv.CursorPosition);
  4230. tv.SelectionStartColumn = 12;
  4231. tv.CursorPosition = new Point (11, 1);
  4232. Assert.True (tv.ProcessKey (new KeyEvent (Key.Y | Key.CtrlMask, new KeyModifiers ())));
  4233. Assert.Equal ($"This is the first second line.{Environment.NewLine}This is the third line.", tv.Text);
  4234. Assert.Equal (2, tv.Lines);
  4235. Assert.Equal (new Point (17, 0), tv.CursorPosition);
  4236. // Undo
  4237. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  4238. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  4239. Assert.Equal (3, tv.Lines);
  4240. Assert.Equal (new Point (12, 0), tv.CursorPosition);
  4241. // Redo
  4242. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  4243. Assert.Equal ($"This is the first second line.{Environment.NewLine}This is the third line.", tv.Text);
  4244. Assert.Equal (2, tv.Lines);
  4245. Assert.Equal (new Point (17, 0), tv.CursorPosition);
  4246. }
  4247. [Fact]
  4248. [AutoInitShutdown]
  4249. public void HistoryText_Undo_Redo_Multi_Line_Selected_Copy_Simple_Paste_Starting_On_Space ()
  4250. {
  4251. var text = "This is the first line.\nThis is the second line.\nThis is the third line.";
  4252. var tv = new TextView () { Text = text };
  4253. tv.SelectionStartColumn = 12;
  4254. tv.CursorPosition = new Point (18, 1);
  4255. Assert.True (tv.ProcessKey (new KeyEvent (Key.C | Key.CtrlMask, new KeyModifiers ())));
  4256. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  4257. Assert.Equal ($"first line.{Environment.NewLine}This is the second", tv.SelectedText);
  4258. Assert.Equal (3, tv.Lines);
  4259. Assert.Equal (new Point (18, 1), tv.CursorPosition);
  4260. tv.Selecting = false;
  4261. Assert.True (tv.ProcessKey (new KeyEvent (Key.Y | Key.CtrlMask, new KeyModifiers ())));
  4262. 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);
  4263. Assert.Equal (4, tv.Lines);
  4264. Assert.Equal (new Point (18, 2), tv.CursorPosition);
  4265. // Undo
  4266. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  4267. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  4268. Assert.Equal (3, tv.Lines);
  4269. Assert.Equal (new Point (18, 1), tv.CursorPosition);
  4270. // Redo
  4271. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  4272. 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);
  4273. Assert.Equal (4, tv.Lines);
  4274. Assert.Equal (new Point (18, 2), tv.CursorPosition);
  4275. }
  4276. [Fact]
  4277. [AutoInitShutdown]
  4278. public void HistoryText_Undo_Redo_Multi_Line_Selected_Copy_Simple_Paste_Starting_On_Letter ()
  4279. {
  4280. var text = "This is the first line.\nThis is the second line.\nThis is the third line.";
  4281. var tv = new TextView () { Text = text };
  4282. tv.SelectionStartColumn = 12;
  4283. tv.CursorPosition = new Point (18, 1);
  4284. Assert.True (tv.ProcessKey (new KeyEvent (Key.C | Key.CtrlMask, new KeyModifiers ())));
  4285. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  4286. Assert.Equal ($"first line.{Environment.NewLine}This is the second", tv.SelectedText);
  4287. Assert.Equal (3, tv.Lines);
  4288. Assert.Equal (new Point (18, 1), tv.CursorPosition);
  4289. tv.Selecting = false;
  4290. tv.CursorPosition = new Point (17, 1);
  4291. Assert.True (tv.ProcessKey (new KeyEvent (Key.Y | Key.CtrlMask, new KeyModifiers ())));
  4292. 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);
  4293. Assert.Equal (4, tv.Lines);
  4294. Assert.Equal (new Point (18, 2), tv.CursorPosition);
  4295. // Undo
  4296. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  4297. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  4298. Assert.Equal (3, tv.Lines);
  4299. Assert.Equal (new Point (17, 1), tv.CursorPosition);
  4300. // Redo
  4301. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  4302. 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);
  4303. Assert.Equal (4, tv.Lines);
  4304. Assert.Equal (new Point (18, 2), tv.CursorPosition);
  4305. }
  4306. [Fact]
  4307. [AutoInitShutdown]
  4308. public void HistoryText_Undo_Redo_Empty_Copy_Without_Selection_Multi_Line_Selected_Paste ()
  4309. {
  4310. var text = "\nThis is the first line.\nThis is the second line.";
  4311. var tv = new TextView () { Text = text };
  4312. Assert.True (tv.ProcessKey (new KeyEvent (Key.C | Key.CtrlMask, new KeyModifiers ())));
  4313. Assert.Equal ($"{Environment.NewLine}This is the first line.{Environment.NewLine}This is the second line.", tv.Text);
  4314. Assert.Equal ("", tv.SelectedText);
  4315. Assert.Equal (3, tv.Lines);
  4316. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  4317. Assert.True (tv.ProcessKey (new KeyEvent (Key.Y | Key.CtrlMask, new KeyModifiers ())));
  4318. Assert.Equal ($"{Environment.NewLine}{Environment.NewLine}This is the first line.{Environment.NewLine}This is the second line.", tv.Text);
  4319. Assert.Equal (4, tv.Lines);
  4320. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  4321. // Undo
  4322. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  4323. Assert.Equal ($"{Environment.NewLine}This is the first line.{Environment.NewLine}This is the second line.", tv.Text);
  4324. Assert.Equal (3, tv.Lines);
  4325. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  4326. // Redo
  4327. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  4328. Assert.Equal ($"{Environment.NewLine}{Environment.NewLine}This is the first line.{Environment.NewLine}This is the second line.", tv.Text);
  4329. Assert.Equal (4, tv.Lines);
  4330. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  4331. }
  4332. [Fact]
  4333. [AutoInitShutdown]
  4334. public void HistoryText_Undo_Redo_Setting_Clipboard_Multi_Line_Selected_Paste ()
  4335. {
  4336. var text = "This is the first line.\nThis is the second line.";
  4337. var tv = new TextView () { Text = text };
  4338. Clipboard.Contents = "Inserted\nNewLine";
  4339. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.", tv.Text);
  4340. Assert.Equal ("", tv.SelectedText);
  4341. Assert.Equal (2, tv.Lines);
  4342. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  4343. Assert.True (tv.ProcessKey (new KeyEvent (Key.Y | Key.CtrlMask, new KeyModifiers ())));
  4344. Assert.Equal ($"Inserted{Environment.NewLine}NewLineThis is the first line.{Environment.NewLine}This is the second line.", tv.Text);
  4345. Assert.Equal (3, tv.Lines);
  4346. Assert.Equal (new Point (7, 1), tv.CursorPosition);
  4347. // Undo
  4348. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  4349. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.", tv.Text);
  4350. Assert.Equal (2, tv.Lines);
  4351. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  4352. // Redo
  4353. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  4354. Assert.Equal ($"Inserted{Environment.NewLine}NewLineThis is the first line.{Environment.NewLine}This is the second line.", tv.Text);
  4355. Assert.Equal (3, tv.Lines);
  4356. Assert.Equal (new Point (7, 1), tv.CursorPosition);
  4357. }
  4358. [Fact]
  4359. [AutoInitShutdown]
  4360. public void HistoryText_Undo_Redo_Cut_Multi_Line_Selected_Paste ()
  4361. {
  4362. var text = "This is the first line.\nThis is the second line.\nThis is the third line.";
  4363. var tv = new TextView () { Text = text };
  4364. tv.SelectionStartColumn = 12;
  4365. tv.CursorPosition = new Point (17, 0);
  4366. Assert.True (tv.ProcessKey (new KeyEvent (Key.W | Key.CtrlMask, new KeyModifiers ())));
  4367. Assert.Equal ($"This is the line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  4368. Assert.Equal ("", tv.SelectedText);
  4369. Assert.Equal (3, tv.Lines);
  4370. Assert.Equal (new Point (12, 0), tv.CursorPosition);
  4371. tv.SelectionStartColumn = 12;
  4372. tv.CursorPosition = new Point (11, 1);
  4373. Assert.True (tv.ProcessKey (new KeyEvent (Key.Y | Key.CtrlMask, new KeyModifiers ())));
  4374. Assert.Equal ($"This is the first second line.{Environment.NewLine}This is the third line.", tv.Text);
  4375. Assert.Equal (2, tv.Lines);
  4376. Assert.Equal (new Point (17, 0), tv.CursorPosition);
  4377. // Undo
  4378. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  4379. Assert.Equal ($"This is the line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  4380. Assert.Equal (3, tv.Lines);
  4381. Assert.Equal (new Point (12, 0), tv.CursorPosition);
  4382. // Redo
  4383. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  4384. Assert.Equal ($"This is the first second line.{Environment.NewLine}This is the third line.", tv.Text);
  4385. Assert.Equal (2, tv.Lines);
  4386. Assert.Equal (new Point (17, 0), tv.CursorPosition);
  4387. }
  4388. [Fact]
  4389. [AutoInitShutdown]
  4390. public void HistoryText_Undo_Redo_Cut_Simple_Paste_Starting ()
  4391. {
  4392. var text = "This is the first line.\nThis is the second line.\nThis is the third line.";
  4393. var tv = new TextView () { Text = text };
  4394. tv.SelectionStartColumn = 12;
  4395. tv.CursorPosition = new Point (18, 1);
  4396. Assert.True (tv.ProcessKey (new KeyEvent (Key.W | Key.CtrlMask, new KeyModifiers ())));
  4397. Assert.Equal ($"This is the line.{Environment.NewLine}This is the third line.", tv.Text);
  4398. Assert.Equal ("", tv.SelectedText);
  4399. Assert.Equal (2, tv.Lines);
  4400. Assert.Equal (new Point (12, 0), tv.CursorPosition);
  4401. tv.Selecting = false;
  4402. Assert.True (tv.ProcessKey (new KeyEvent (Key.Y | Key.CtrlMask, new KeyModifiers ())));
  4403. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  4404. Assert.Equal (3, tv.Lines);
  4405. Assert.Equal (new Point (18, 1), tv.CursorPosition);
  4406. // Undo
  4407. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  4408. Assert.Equal ($"This is the line.{Environment.NewLine}This is the third line.", tv.Text);
  4409. Assert.Equal (2, tv.Lines);
  4410. Assert.Equal (new Point (12, 0), tv.CursorPosition);
  4411. // Redo
  4412. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  4413. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  4414. Assert.Equal (3, tv.Lines);
  4415. Assert.Equal (new Point (18, 1), tv.CursorPosition);
  4416. }
  4417. [Fact]
  4418. [AutoInitShutdown]
  4419. public void HistoryText_Undo_Redo_Cut_Multi_Line_Another_Selected_Paste ()
  4420. {
  4421. var text = "This is the first line.\nThis is the second line.\nThis is the third line.";
  4422. var tv = new TextView () { Text = text };
  4423. tv.SelectionStartColumn = 12;
  4424. tv.CursorPosition = new Point (17, 0);
  4425. Assert.True (tv.ProcessKey (new KeyEvent (Key.W | Key.CtrlMask, new KeyModifiers ())));
  4426. Assert.Equal ($"This is the line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  4427. Assert.Equal ("", tv.SelectedText);
  4428. Assert.Equal (3, tv.Lines);
  4429. Assert.Equal (new Point (12, 0), tv.CursorPosition);
  4430. tv.SelectionStartColumn = 12;
  4431. tv.SelectionStartRow = 1;
  4432. tv.CursorPosition = new Point (18, 1);
  4433. Assert.True (tv.ProcessKey (new KeyEvent (Key.Y | Key.CtrlMask, new KeyModifiers ())));
  4434. Assert.Equal ($"This is the line.{Environment.NewLine}This is the first line.{Environment.NewLine}This is the third line.", tv.Text);
  4435. Assert.Equal (3, tv.Lines);
  4436. Assert.Equal (new Point (17, 1), tv.CursorPosition);
  4437. // Undo
  4438. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  4439. Assert.Equal ($"This is the line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  4440. Assert.Equal (3, tv.Lines);
  4441. Assert.Equal (new Point (12, 1), tv.CursorPosition);
  4442. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  4443. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  4444. Assert.Equal (3, tv.Lines);
  4445. Assert.Equal (new Point (12, 0), tv.CursorPosition);
  4446. // Redo
  4447. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  4448. Assert.Equal ($"This is the line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  4449. Assert.Equal (3, tv.Lines);
  4450. Assert.Equal (new Point (12, 0), tv.CursorPosition);
  4451. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  4452. Assert.Equal ($"This is the line.{Environment.NewLine}This is the first line.{Environment.NewLine}This is the third line.", tv.Text);
  4453. Assert.Equal (3, tv.Lines);
  4454. Assert.Equal (new Point (17, 1), tv.CursorPosition);
  4455. }
  4456. [Fact]
  4457. public void HistoryText_Undo_Redo_KillWordBackward ()
  4458. {
  4459. var text = "First line.\nSecond line.";
  4460. var tv = new TextView () { Text = text };
  4461. Assert.True (tv.ProcessKey (new KeyEvent (Key.End | Key.CtrlMask, new KeyModifiers ())));
  4462. Assert.Equal ($"First line.{Environment.NewLine}Second line.", tv.Text);
  4463. Assert.Equal ("", tv.SelectedText);
  4464. Assert.Equal (2, tv.Lines);
  4465. Assert.Equal (new Point (12, 1), tv.CursorPosition);
  4466. Assert.True (tv.ProcessKey (new KeyEvent (Key.Backspace | Key.CtrlMask, new KeyModifiers ())));
  4467. Assert.Equal ($"First line.{Environment.NewLine}Second ", tv.Text);
  4468. Assert.Equal ("", tv.SelectedText);
  4469. Assert.Equal (2, tv.Lines);
  4470. Assert.Equal (new Point (7, 1), tv.CursorPosition);
  4471. Assert.True (tv.ProcessKey (new KeyEvent (Key.Backspace | Key.CtrlMask, new KeyModifiers ())));
  4472. Assert.Equal ($"First line.{Environment.NewLine}", tv.Text);
  4473. Assert.Equal ("", tv.SelectedText);
  4474. Assert.Equal (2, tv.Lines);
  4475. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  4476. Assert.True (tv.ProcessKey (new KeyEvent (Key.Backspace | Key.CtrlMask, new KeyModifiers ())));
  4477. Assert.Equal ("First line.", tv.Text);
  4478. Assert.Equal ("", tv.SelectedText);
  4479. Assert.Equal (1, tv.Lines);
  4480. Assert.Equal (new Point (11, 0), tv.CursorPosition);
  4481. Assert.True (tv.ProcessKey (new KeyEvent (Key.Backspace | Key.CtrlMask, new KeyModifiers ())));
  4482. Assert.Equal ("First ", tv.Text);
  4483. Assert.Equal ("", tv.SelectedText);
  4484. Assert.Equal (1, tv.Lines);
  4485. Assert.Equal (new Point (6, 0), tv.CursorPosition);
  4486. Assert.True (tv.ProcessKey (new KeyEvent (Key.Backspace | Key.CtrlMask, new KeyModifiers ())));
  4487. Assert.Equal ("", tv.Text);
  4488. Assert.Equal ("", tv.SelectedText);
  4489. Assert.Equal (1, tv.Lines);
  4490. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  4491. // Undo
  4492. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  4493. Assert.Equal ("First ", tv.Text);
  4494. Assert.Equal (1, tv.Lines);
  4495. Assert.Equal (new Point (6, 0), tv.CursorPosition);
  4496. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  4497. Assert.Equal ("First line.", tv.Text);
  4498. Assert.Equal (1, tv.Lines);
  4499. Assert.Equal (new Point (11, 0), tv.CursorPosition);
  4500. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  4501. Assert.Equal ($"First line.{Environment.NewLine}", tv.Text);
  4502. Assert.Equal (2, tv.Lines);
  4503. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  4504. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  4505. Assert.Equal ($"First line.{Environment.NewLine}Second ", tv.Text);
  4506. Assert.Equal (2, tv.Lines);
  4507. Assert.Equal (new Point (7, 1), tv.CursorPosition);
  4508. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  4509. Assert.Equal ($"First line.{Environment.NewLine}Second line.", tv.Text);
  4510. Assert.Equal (2, tv.Lines);
  4511. Assert.Equal (new Point (12, 1), tv.CursorPosition);
  4512. // Redo
  4513. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  4514. Assert.Equal ($"First line.{Environment.NewLine}Second ", tv.Text);
  4515. Assert.Equal (2, tv.Lines);
  4516. Assert.Equal (new Point (7, 1), tv.CursorPosition);
  4517. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  4518. Assert.Equal ($"First line.{Environment.NewLine}", tv.Text);
  4519. Assert.Equal (2, tv.Lines);
  4520. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  4521. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  4522. Assert.Equal ("First line.", tv.Text);
  4523. Assert.Equal (1, tv.Lines);
  4524. Assert.Equal (new Point (11, 0), tv.CursorPosition);
  4525. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  4526. Assert.Equal ("First ", tv.Text);
  4527. Assert.Equal (1, tv.Lines);
  4528. Assert.Equal (new Point (6, 0), tv.CursorPosition);
  4529. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  4530. Assert.Equal ("", tv.Text);
  4531. Assert.Equal (1, tv.Lines);
  4532. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  4533. }
  4534. [Fact]
  4535. public void HistoryText_Undo_Redo_KillWordForward ()
  4536. {
  4537. var text = "First line.\nSecond line.";
  4538. var tv = new TextView () { Text = text };
  4539. Assert.True (tv.ProcessKey (new KeyEvent (Key.DeleteChar | Key.CtrlMask, new KeyModifiers ())));
  4540. Assert.Equal ($"line.{Environment.NewLine}Second line.", tv.Text);
  4541. Assert.Equal ("", tv.SelectedText);
  4542. Assert.Equal (2, tv.Lines);
  4543. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  4544. Assert.True (tv.ProcessKey (new KeyEvent (Key.DeleteChar | Key.CtrlMask, new KeyModifiers ())));
  4545. Assert.Equal ($"{Environment.NewLine}Second line.", tv.Text);
  4546. Assert.Equal (2, tv.Lines);
  4547. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  4548. Assert.True (tv.ProcessKey (new KeyEvent (Key.DeleteChar | Key.CtrlMask, new KeyModifiers ())));
  4549. Assert.Equal ("Second line.", tv.Text);
  4550. Assert.Equal (1, tv.Lines);
  4551. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  4552. Assert.True (tv.ProcessKey (new KeyEvent (Key.DeleteChar | Key.CtrlMask, new KeyModifiers ())));
  4553. Assert.Equal ("line.", tv.Text);
  4554. Assert.Equal (1, tv.Lines);
  4555. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  4556. Assert.True (tv.ProcessKey (new KeyEvent (Key.DeleteChar | Key.CtrlMask, new KeyModifiers ())));
  4557. Assert.Equal ("", tv.Text);
  4558. Assert.Equal (1, tv.Lines);
  4559. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  4560. // Undo
  4561. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  4562. Assert.Equal ("line.", tv.Text);
  4563. Assert.Equal (1, tv.Lines);
  4564. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  4565. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  4566. Assert.Equal ("Second line.", tv.Text);
  4567. Assert.Equal (1, tv.Lines);
  4568. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  4569. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  4570. Assert.Equal ($"{Environment.NewLine}Second line.", tv.Text);
  4571. Assert.Equal (2, tv.Lines);
  4572. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  4573. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  4574. Assert.Equal ($"line.{Environment.NewLine}Second line.", tv.Text);
  4575. Assert.Equal (2, tv.Lines);
  4576. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  4577. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  4578. Assert.Equal ($"First line.{Environment.NewLine}Second line.", tv.Text);
  4579. Assert.Equal (2, tv.Lines);
  4580. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  4581. // Redo
  4582. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  4583. Assert.Equal ($"line.{Environment.NewLine}Second line.", tv.Text);
  4584. Assert.Equal (2, tv.Lines);
  4585. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  4586. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  4587. Assert.Equal ($"{Environment.NewLine}Second line.", tv.Text);
  4588. Assert.Equal (2, tv.Lines);
  4589. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  4590. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  4591. Assert.Equal ("Second line.", tv.Text);
  4592. Assert.Equal (1, tv.Lines);
  4593. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  4594. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  4595. Assert.Equal ("line.", tv.Text);
  4596. Assert.Equal (1, tv.Lines);
  4597. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  4598. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  4599. Assert.Equal ("", tv.Text);
  4600. Assert.Equal (1, tv.Lines);
  4601. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  4602. }
  4603. [Fact]
  4604. [AutoInitShutdown]
  4605. public void HistoryText_Undo_Redo_KillToStartOfLine ()
  4606. {
  4607. var text = "First line.\nSecond line.";
  4608. var tv = new TextView () { Text = text };
  4609. Assert.True (tv.ProcessKey (new KeyEvent (Key.End | Key.CtrlMask, new KeyModifiers ())));
  4610. Assert.Equal ($"First line.{Environment.NewLine}Second line.", tv.Text);
  4611. Assert.Equal ("", tv.SelectedText);
  4612. Assert.Equal (2, tv.Lines);
  4613. Assert.Equal (new Point (12, 1), tv.CursorPosition);
  4614. Assert.True (tv.ProcessKey (new KeyEvent (Key.K | Key.AltMask, new KeyModifiers ())));
  4615. Assert.Equal ($"First line.{Environment.NewLine}", tv.Text);
  4616. Assert.Equal ("", tv.SelectedText);
  4617. Assert.Equal ("Second line.", Clipboard.Contents);
  4618. Assert.Equal (2, tv.Lines);
  4619. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  4620. Assert.True (tv.ProcessKey (new KeyEvent (Key.K | Key.AltMask, new KeyModifiers ())));
  4621. Assert.Equal ("First line.", tv.Text);
  4622. Assert.Equal ("", tv.SelectedText);
  4623. Assert.Equal ($"Second line.{Environment.NewLine}", Clipboard.Contents);
  4624. Assert.Equal (1, tv.Lines);
  4625. Assert.Equal (new Point (11, 0), tv.CursorPosition);
  4626. Assert.True (tv.ProcessKey (new KeyEvent (Key.K | Key.AltMask, new KeyModifiers ())));
  4627. Assert.Equal ("", tv.Text);
  4628. Assert.Equal ("", tv.SelectedText);
  4629. Assert.Equal ($"Second line.{Environment.NewLine}First line.", Clipboard.Contents);
  4630. Assert.Equal (1, tv.Lines);
  4631. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  4632. // Undo
  4633. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  4634. Assert.Equal ("First line.", tv.Text);
  4635. Assert.Equal (1, tv.Lines);
  4636. Assert.Equal (new Point (11, 0), tv.CursorPosition);
  4637. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  4638. Assert.Equal ($"First line.{Environment.NewLine}", tv.Text);
  4639. Assert.Equal (2, tv.Lines);
  4640. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  4641. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  4642. Assert.Equal ($"First line.{Environment.NewLine}Second line.", tv.Text);
  4643. Assert.Equal (2, tv.Lines);
  4644. Assert.Equal (new Point (12, 1), tv.CursorPosition);
  4645. // Redo
  4646. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  4647. Assert.Equal ($"First line.{Environment.NewLine}", tv.Text);
  4648. Assert.Equal (2, tv.Lines);
  4649. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  4650. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  4651. Assert.Equal ($"First line.", tv.Text);
  4652. Assert.Equal (1, tv.Lines);
  4653. Assert.Equal (new Point (11, 0), tv.CursorPosition);
  4654. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  4655. Assert.Equal ("", tv.Text);
  4656. Assert.Equal (1, tv.Lines);
  4657. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  4658. }
  4659. [Fact]
  4660. [AutoInitShutdown]
  4661. public void HistoryText_Undo_Redo_KillToEndOfLine ()
  4662. {
  4663. var text = "First line.\nSecond line.";
  4664. var tv = new TextView () { Text = text };
  4665. Assert.True (tv.ProcessKey (new KeyEvent (Key.K | Key.CtrlMask, new KeyModifiers ())));
  4666. Assert.Equal ($"{Environment.NewLine}Second line.", tv.Text);
  4667. Assert.Equal ("", tv.SelectedText);
  4668. Assert.Equal ("First line.", Clipboard.Contents);
  4669. Assert.Equal (2, tv.Lines);
  4670. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  4671. Assert.True (tv.ProcessKey (new KeyEvent (Key.K | Key.CtrlMask, new KeyModifiers ())));
  4672. Assert.Equal ("Second line.", tv.Text);
  4673. Assert.Equal ("", tv.SelectedText);
  4674. Assert.Equal ($"First line.{Environment.NewLine}", Clipboard.Contents);
  4675. Assert.Equal (1, tv.Lines);
  4676. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  4677. Assert.True (tv.ProcessKey (new KeyEvent (Key.K | Key.CtrlMask, new KeyModifiers ())));
  4678. Assert.Equal ("", tv.Text);
  4679. Assert.Equal ("", tv.SelectedText);
  4680. Assert.Equal ($"First line.{Environment.NewLine}Second line.", Clipboard.Contents);
  4681. Assert.Equal (1, tv.Lines);
  4682. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  4683. // Undo
  4684. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  4685. Assert.Equal ("Second line.", tv.Text);
  4686. Assert.Equal (1, tv.Lines);
  4687. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  4688. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  4689. Assert.Equal ($"{Environment.NewLine}Second line.", tv.Text);
  4690. Assert.Equal (2, tv.Lines);
  4691. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  4692. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  4693. Assert.Equal ($"First line.{Environment.NewLine}Second line.", tv.Text);
  4694. Assert.Equal (2, tv.Lines);
  4695. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  4696. // Redo
  4697. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  4698. Assert.Equal ($"{Environment.NewLine}Second line.", tv.Text);
  4699. Assert.Equal (2, tv.Lines);
  4700. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  4701. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  4702. Assert.Equal ("Second line.", tv.Text);
  4703. Assert.Equal (1, tv.Lines);
  4704. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  4705. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  4706. Assert.Equal ("", tv.Text);
  4707. Assert.Equal (1, tv.Lines);
  4708. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  4709. }
  4710. [Fact]
  4711. public void HistoryText_Undo_Redo_Changing_On_Middle_Clear_History_Forwards ()
  4712. {
  4713. var tv = new TextView ();
  4714. Assert.True (tv.ProcessKey (new KeyEvent (Key.D1, new KeyModifiers ())));
  4715. Assert.Equal ("1", tv.Text);
  4716. Assert.Equal (1, tv.Lines);
  4717. Assert.Equal (new Point (1, 0), tv.CursorPosition);
  4718. Assert.True (tv.ProcessKey (new KeyEvent (Key.D2, new KeyModifiers ())));
  4719. Assert.Equal ("12", tv.Text);
  4720. Assert.Equal (1, tv.Lines);
  4721. Assert.Equal (new Point (2, 0), tv.CursorPosition);
  4722. Assert.True (tv.ProcessKey (new KeyEvent (Key.D3, new KeyModifiers ())));
  4723. Assert.Equal ("123", tv.Text);
  4724. Assert.Equal (1, tv.Lines);
  4725. Assert.Equal (new Point (3, 0), tv.CursorPosition);
  4726. // Undo
  4727. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  4728. Assert.Equal ("12", tv.Text);
  4729. Assert.Equal (1, tv.Lines);
  4730. Assert.Equal (new Point (2, 0), tv.CursorPosition);
  4731. Assert.True (tv.ProcessKey (new KeyEvent (Key.D4, new KeyModifiers ())));
  4732. Assert.Equal ("124", tv.Text);
  4733. Assert.Equal (1, tv.Lines);
  4734. Assert.Equal (new Point (3, 0), tv.CursorPosition);
  4735. // Redo
  4736. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  4737. Assert.Equal ("124", tv.Text);
  4738. Assert.Equal (1, tv.Lines);
  4739. Assert.Equal (new Point (3, 0), tv.CursorPosition);
  4740. }
  4741. [Fact]
  4742. public void HistoryText_Undo_Redo_Single_Line_Selected_Return ()
  4743. {
  4744. var text = "This is the first line.\nThis is the second line.\nThis is the third line.";
  4745. var tv = new TextView () { Text = text };
  4746. tv.SelectionStartColumn = 12;
  4747. tv.CursorPosition = new Point (17, 0);
  4748. Assert.True (tv.ProcessKey (new KeyEvent (Key.Enter, new KeyModifiers ())));
  4749. Assert.Equal ($"This is the {Environment.NewLine} line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  4750. Assert.Equal (4, tv.Lines);
  4751. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  4752. // Undo
  4753. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  4754. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  4755. Assert.Equal (3, tv.Lines);
  4756. Assert.Equal (new Point (17, 0), tv.CursorPosition);
  4757. Assert.False (tv.IsDirty);
  4758. // Redo
  4759. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  4760. Assert.Equal ($"This is the {Environment.NewLine} line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  4761. Assert.Equal (4, tv.Lines);
  4762. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  4763. // Undo
  4764. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  4765. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  4766. Assert.Equal (3, tv.Lines);
  4767. Assert.Equal (new Point (17, 0), tv.CursorPosition);
  4768. Assert.False (tv.IsDirty);
  4769. // Redo
  4770. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  4771. Assert.Equal ($"This is the {Environment.NewLine} line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  4772. Assert.Equal (4, tv.Lines);
  4773. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  4774. }
  4775. [Fact]
  4776. public void HistoryText_Undo_Redo_Two_Line_Selected_Return ()
  4777. {
  4778. var text = "This is the first line.\nThis is the second line.\nThis is the third line.";
  4779. var tv = new TextView () { Text = text };
  4780. tv.SelectionStartColumn = 12;
  4781. tv.CursorPosition = new Point (18, 1);
  4782. Assert.True (tv.ProcessKey (new KeyEvent (Key.Enter, new KeyModifiers ())));
  4783. Assert.Equal ($"This is the {Environment.NewLine} line.{Environment.NewLine}This is the third line.", tv.Text);
  4784. Assert.Equal (3, tv.Lines);
  4785. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  4786. // Undo
  4787. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  4788. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  4789. Assert.Equal (3, tv.Lines);
  4790. Assert.Equal (new Point (18, 1), tv.CursorPosition);
  4791. Assert.False (tv.IsDirty);
  4792. // Redo
  4793. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  4794. Assert.Equal ($"This is the {Environment.NewLine} line.{Environment.NewLine}This is the third line.", tv.Text);
  4795. Assert.Equal (3, tv.Lines);
  4796. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  4797. // Undo
  4798. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  4799. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  4800. Assert.Equal (3, tv.Lines);
  4801. Assert.Equal (new Point (18, 1), tv.CursorPosition);
  4802. Assert.False (tv.IsDirty);
  4803. // Redo
  4804. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  4805. Assert.Equal ($"This is the {Environment.NewLine} line.{Environment.NewLine}This is the third line.", tv.Text);
  4806. Assert.Equal (3, tv.Lines);
  4807. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  4808. }
  4809. [Fact]
  4810. public void HistoryText_Undo_Redo_Three_Line_Selected_Return ()
  4811. {
  4812. var text = "This is the first line.\nThis is the second line.\nThis is the third line.";
  4813. var tv = new TextView () { Text = text };
  4814. tv.SelectionStartColumn = 12;
  4815. tv.CursorPosition = new Point (17, 2);
  4816. Assert.True (tv.ProcessKey (new KeyEvent (Key.Enter, new KeyModifiers ())));
  4817. Assert.Equal ($"This is the {Environment.NewLine} line.", tv.Text);
  4818. Assert.Equal (2, tv.Lines);
  4819. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  4820. // Undo
  4821. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  4822. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  4823. Assert.Equal (3, tv.Lines);
  4824. Assert.Equal (new Point (17, 2), tv.CursorPosition);
  4825. Assert.False (tv.IsDirty);
  4826. // Redo
  4827. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  4828. Assert.Equal ($"This is the {Environment.NewLine} line.", tv.Text);
  4829. Assert.Equal (2, tv.Lines);
  4830. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  4831. // Undo
  4832. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  4833. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  4834. Assert.Equal (3, tv.Lines);
  4835. Assert.Equal (new Point (17, 2), tv.CursorPosition);
  4836. Assert.False (tv.IsDirty);
  4837. // Redo
  4838. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  4839. Assert.Equal ($"This is the {Environment.NewLine} line.", tv.Text);
  4840. Assert.Equal (2, tv.Lines);
  4841. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  4842. }
  4843. [Fact]
  4844. public void HistoryText_Undo_Redo_Single_Second_Line_Selected_Return ()
  4845. {
  4846. var text = "This is the first line.\nThis is the second line.\nThis is the third line.";
  4847. var tv = new TextView () { Text = text };
  4848. tv.SelectionStartColumn = 12;
  4849. tv.SelectionStartRow = 1;
  4850. tv.CursorPosition = new Point (18, 1);
  4851. Assert.True (tv.ProcessKey (new KeyEvent (Key.Enter, new KeyModifiers ())));
  4852. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the {Environment.NewLine} line.{Environment.NewLine}This is the third line.", tv.Text);
  4853. Assert.Equal (4, tv.Lines);
  4854. Assert.Equal (new Point (0, 2), tv.CursorPosition);
  4855. // Undo
  4856. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  4857. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  4858. Assert.Equal (3, tv.Lines);
  4859. Assert.Equal (new Point (18, 1), tv.CursorPosition);
  4860. Assert.False (tv.IsDirty);
  4861. // Redo
  4862. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  4863. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the {Environment.NewLine} line.{Environment.NewLine}This is the third line.", tv.Text);
  4864. Assert.Equal (4, tv.Lines);
  4865. Assert.Equal (new Point (0, 2), tv.CursorPosition);
  4866. // Undo
  4867. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  4868. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  4869. Assert.Equal (3, tv.Lines);
  4870. Assert.Equal (new Point (18, 1), tv.CursorPosition);
  4871. Assert.False (tv.IsDirty);
  4872. // Redo
  4873. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  4874. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the {Environment.NewLine} line.{Environment.NewLine}This is the third line.", tv.Text);
  4875. Assert.Equal (4, tv.Lines);
  4876. Assert.Equal (new Point (0, 2), tv.CursorPosition);
  4877. }
  4878. [Fact]
  4879. public void HistoryText_Undo_Redo_First_Line_Selected_Return_And_InsertText ()
  4880. {
  4881. var text = "This is the first line.\nThis is the second line.\nThis is the third line.";
  4882. var tv = new TextView () { Text = text };
  4883. tv.SelectionStartColumn = 12;
  4884. tv.CursorPosition = new Point (17, 0);
  4885. Assert.True (tv.ProcessKey (new KeyEvent (Key.Enter, new KeyModifiers ())));
  4886. Assert.Equal ($"This is the {Environment.NewLine} line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  4887. Assert.Equal (4, tv.Lines);
  4888. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  4889. Assert.True (tv.ProcessKey (new KeyEvent (Key.a, new KeyModifiers ())));
  4890. 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);
  4891. Assert.Equal (4, tv.Lines);
  4892. Assert.Equal (new Point (1, 1), tv.CursorPosition);
  4893. // Undo
  4894. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  4895. Assert.Equal ($"This is the {Environment.NewLine} line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  4896. Assert.Equal (4, tv.Lines);
  4897. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  4898. Assert.True (tv.IsDirty);
  4899. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  4900. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  4901. Assert.Equal (3, tv.Lines);
  4902. Assert.Equal (new Point (17, 0), tv.CursorPosition);
  4903. Assert.False (tv.IsDirty);
  4904. // Redo
  4905. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  4906. Assert.Equal ($"This is the {Environment.NewLine} line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  4907. Assert.Equal (4, tv.Lines);
  4908. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  4909. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  4910. 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);
  4911. Assert.Equal (4, tv.Lines);
  4912. Assert.Equal (new Point (1, 1), tv.CursorPosition);
  4913. // Undo
  4914. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  4915. Assert.Equal ($"This is the {Environment.NewLine} line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  4916. Assert.Equal (4, tv.Lines);
  4917. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  4918. Assert.True (tv.IsDirty);
  4919. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  4920. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  4921. Assert.Equal (3, tv.Lines);
  4922. Assert.Equal (new Point (17, 0), tv.CursorPosition);
  4923. Assert.False (tv.IsDirty);
  4924. // Redo
  4925. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  4926. Assert.Equal ($"This is the {Environment.NewLine} line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  4927. Assert.Equal (4, tv.Lines);
  4928. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  4929. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  4930. 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);
  4931. Assert.Equal (4, tv.Lines);
  4932. Assert.Equal (new Point (1, 1), tv.CursorPosition);
  4933. }
  4934. [Fact]
  4935. public void HistoryText_Undo_Redo_Single_Second_Line_Selected_Return_And_InsertText ()
  4936. {
  4937. var text = "This is the first line.\nThis is the second line.\nThis is the third line.";
  4938. var tv = new TextView () { Text = text };
  4939. tv.SelectionStartColumn = 12;
  4940. tv.SelectionStartRow = 1;
  4941. tv.CursorPosition = new Point (18, 1);
  4942. Assert.True (tv.ProcessKey (new KeyEvent (Key.Enter, new KeyModifiers ())));
  4943. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the {Environment.NewLine} line.{Environment.NewLine}This is the third line.", tv.Text);
  4944. Assert.Equal (4, tv.Lines);
  4945. Assert.Equal (new Point (0, 2), tv.CursorPosition);
  4946. Assert.True (tv.ProcessKey (new KeyEvent (Key.a, new KeyModifiers ())));
  4947. 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);
  4948. Assert.Equal (4, tv.Lines);
  4949. Assert.Equal (new Point (1, 2), tv.CursorPosition);
  4950. // Undo
  4951. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  4952. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the {Environment.NewLine} line.{Environment.NewLine}This is the third line.", tv.Text);
  4953. Assert.Equal (4, tv.Lines);
  4954. Assert.Equal (new Point (0, 2), tv.CursorPosition);
  4955. Assert.True (tv.IsDirty);
  4956. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  4957. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  4958. Assert.Equal (3, tv.Lines);
  4959. Assert.Equal (new Point (18, 1), tv.CursorPosition);
  4960. Assert.False (tv.IsDirty);
  4961. // Redo
  4962. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  4963. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the {Environment.NewLine} line.{Environment.NewLine}This is the third line.", tv.Text);
  4964. Assert.Equal (4, tv.Lines);
  4965. Assert.Equal (new Point (0, 2), tv.CursorPosition);
  4966. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  4967. 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);
  4968. Assert.Equal (4, tv.Lines);
  4969. Assert.Equal (new Point (1, 2), tv.CursorPosition);
  4970. // Undo
  4971. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  4972. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the {Environment.NewLine} line.{Environment.NewLine}This is the third line.", tv.Text);
  4973. Assert.Equal (4, tv.Lines);
  4974. Assert.Equal (new Point (0, 2), tv.CursorPosition);
  4975. Assert.True (tv.IsDirty);
  4976. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  4977. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  4978. Assert.Equal (3, tv.Lines);
  4979. Assert.Equal (new Point (18, 1), tv.CursorPosition);
  4980. Assert.False (tv.IsDirty);
  4981. // Redo
  4982. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  4983. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the {Environment.NewLine} line.{Environment.NewLine}This is the third line.", tv.Text);
  4984. Assert.Equal (4, tv.Lines);
  4985. Assert.Equal (new Point (0, 2), tv.CursorPosition);
  4986. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  4987. 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);
  4988. Assert.Equal (4, tv.Lines);
  4989. Assert.Equal (new Point (1, 2), tv.CursorPosition);
  4990. }
  4991. [Fact]
  4992. public void HistoryText_Undo_Redo_Multi_Line_Selected_All_Return_And_InsertText ()
  4993. {
  4994. var text = "This is the first line.\nThis is the second line.\nThis is the third line.";
  4995. var tv = new TextView () { Text = text };
  4996. Assert.True (tv.ProcessKey (new KeyEvent (Key.End | Key.CtrlMask | Key.ShiftMask, new KeyModifiers ())));
  4997. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  4998. Assert.Equal (3, tv.Lines);
  4999. Assert.Equal (new Point (23, 2), tv.CursorPosition);
  5000. Assert.True (tv.ProcessKey (new KeyEvent (Key.Enter, new KeyModifiers ())));
  5001. Assert.Equal ($"{Environment.NewLine}", tv.Text);
  5002. Assert.Equal (2, tv.Lines);
  5003. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  5004. Assert.True (tv.ProcessKey (new KeyEvent (Key.a, new KeyModifiers ())));
  5005. Assert.Equal ($"{Environment.NewLine}a", tv.Text);
  5006. Assert.Equal (2, tv.Lines);
  5007. Assert.Equal (new Point (1, 1), tv.CursorPosition);
  5008. // Undo
  5009. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  5010. Assert.Equal ($"{Environment.NewLine}", tv.Text);
  5011. Assert.Equal (2, tv.Lines);
  5012. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  5013. Assert.True (tv.IsDirty);
  5014. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  5015. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  5016. Assert.Equal (3, tv.Lines);
  5017. Assert.Equal (new Point (23, 2), tv.CursorPosition);
  5018. Assert.False (tv.IsDirty);
  5019. // Redo
  5020. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  5021. Assert.Equal ($"{Environment.NewLine}", tv.Text);
  5022. Assert.Equal (2, tv.Lines);
  5023. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  5024. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  5025. Assert.Equal ($"{Environment.NewLine}a", tv.Text);
  5026. Assert.Equal (2, tv.Lines);
  5027. Assert.Equal (new Point (1, 1), tv.CursorPosition);
  5028. // Undo
  5029. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  5030. Assert.Equal ($"{Environment.NewLine}", tv.Text);
  5031. Assert.Equal (2, tv.Lines);
  5032. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  5033. Assert.True (tv.IsDirty);
  5034. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  5035. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  5036. Assert.Equal (3, tv.Lines);
  5037. Assert.Equal (new Point (23, 2), tv.CursorPosition);
  5038. Assert.False (tv.IsDirty);
  5039. // Redo
  5040. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  5041. Assert.Equal ($"{Environment.NewLine}", tv.Text);
  5042. Assert.Equal (2, tv.Lines);
  5043. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  5044. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  5045. Assert.Equal ($"{Environment.NewLine}a", tv.Text);
  5046. Assert.Equal (2, tv.Lines);
  5047. Assert.Equal (new Point (1, 1), tv.CursorPosition);
  5048. }
  5049. [Fact]
  5050. public void HistoryText_Undo_Redo_Ending_With_Newline_Multi_Line_Selected_Almost_All_Return_And_InsertText ()
  5051. {
  5052. var text = "This is the first line.\nThis is the second line.\nThis is the third line.\n";
  5053. var tv = new TextView () { Text = text };
  5054. tv.SelectionStartColumn = 12;
  5055. tv.CursorPosition = new Point (12, 2);
  5056. Assert.True (tv.ProcessKey (new KeyEvent (Key.Enter, new KeyModifiers ())));
  5057. Assert.Equal ($"This is the {Environment.NewLine}third line.{Environment.NewLine}", tv.Text);
  5058. Assert.Equal (3, tv.Lines);
  5059. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  5060. Assert.True (tv.ProcessKey (new KeyEvent (Key.a, new KeyModifiers ())));
  5061. Assert.Equal ($"This is the {Environment.NewLine}athird line.{Environment.NewLine}", tv.Text);
  5062. Assert.Equal (3, tv.Lines);
  5063. Assert.Equal (new Point (1, 1), tv.CursorPosition);
  5064. // Undo
  5065. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  5066. Assert.Equal ($"This is the {Environment.NewLine}third line.{Environment.NewLine}", tv.Text);
  5067. Assert.Equal (3, tv.Lines);
  5068. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  5069. Assert.True (tv.IsDirty);
  5070. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  5071. 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);
  5072. Assert.Equal (4, tv.Lines);
  5073. Assert.Equal (new Point (12, 2), tv.CursorPosition);
  5074. Assert.False (tv.IsDirty);
  5075. // Redo
  5076. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  5077. Assert.Equal ($"This is the {Environment.NewLine}third line.{Environment.NewLine}", tv.Text);
  5078. Assert.Equal (3, tv.Lines);
  5079. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  5080. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  5081. Assert.Equal ($"This is the {Environment.NewLine}athird line.{Environment.NewLine}", tv.Text);
  5082. Assert.Equal (3, tv.Lines);
  5083. Assert.Equal (new Point (1, 1), tv.CursorPosition);
  5084. // Undo
  5085. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  5086. Assert.Equal ($"This is the {Environment.NewLine}third line.{Environment.NewLine}", tv.Text);
  5087. Assert.Equal (3, tv.Lines);
  5088. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  5089. Assert.True (tv.IsDirty);
  5090. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  5091. 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);
  5092. Assert.Equal (4, tv.Lines);
  5093. Assert.Equal (new Point (12, 2), tv.CursorPosition);
  5094. Assert.False (tv.IsDirty);
  5095. // Redo
  5096. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  5097. Assert.Equal ($"This is the {Environment.NewLine}third line.{Environment.NewLine}", tv.Text);
  5098. Assert.Equal (3, tv.Lines);
  5099. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  5100. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  5101. Assert.Equal ($"This is the {Environment.NewLine}athird line.{Environment.NewLine}", tv.Text);
  5102. Assert.Equal (3, tv.Lines);
  5103. Assert.Equal (new Point (1, 1), tv.CursorPosition);
  5104. }
  5105. [Fact]
  5106. public void HistoryText_Undo_Redo_Disabled_On_WordWrap ()
  5107. {
  5108. var text = "This is the first line.\nThis is the second line.\nThis is the third line.\n";
  5109. var tv = new TextView () { Width = 80, Height = 5, Text = text };
  5110. Assert.False (tv.WordWrap);
  5111. tv.WordWrap = true;
  5112. tv.SelectionStartColumn = 12;
  5113. tv.CursorPosition = new Point (12, 2);
  5114. Assert.True (tv.ProcessKey (new KeyEvent (Key.Enter, new KeyModifiers ())));
  5115. Assert.Equal ($"This is the {Environment.NewLine}third line.{Environment.NewLine}", tv.Text);
  5116. Assert.Equal (3, tv.Lines);
  5117. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  5118. Assert.True (tv.ProcessKey (new KeyEvent (Key.a, new KeyModifiers ())));
  5119. Assert.Equal ($"This is the {Environment.NewLine}athird line.{Environment.NewLine}", tv.Text);
  5120. Assert.Equal (3, tv.Lines);
  5121. Assert.Equal (new Point (1, 1), tv.CursorPosition);
  5122. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  5123. Assert.Equal ($"This is the {Environment.NewLine}third line.{Environment.NewLine}", tv.Text);
  5124. Assert.Equal (3, tv.Lines);
  5125. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  5126. Assert.True (tv.IsDirty);
  5127. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  5128. Assert.Equal ($"This is the {Environment.NewLine}athird line.{Environment.NewLine}", tv.Text);
  5129. Assert.Equal (3, tv.Lines);
  5130. Assert.Equal (new Point (1, 1), tv.CursorPosition);
  5131. }
  5132. [Fact]
  5133. public void HistoryText_Undo_Redo_Multiline_Simples_Tab_BackTab ()
  5134. {
  5135. var text = "First line.\nSecond line.\nThird line.";
  5136. var tv = new TextView () { Width = 80, Height = 5, Text = text };
  5137. Assert.True (tv.ProcessKey (new KeyEvent (Key.Tab, new KeyModifiers ())));
  5138. Assert.Equal ($"\tFirst line.{Environment.NewLine}Second line.{Environment.NewLine}Third line.", tv.Text);
  5139. Assert.Equal (3, tv.Lines);
  5140. Assert.Equal (new Point (1, 0), tv.CursorPosition);
  5141. Assert.True (tv.ProcessKey (new KeyEvent (Key.BackTab, new KeyModifiers ())));
  5142. Assert.Equal ($"First line.{Environment.NewLine}Second line.{Environment.NewLine}Third line.", tv.Text);
  5143. Assert.Equal (3, tv.Lines);
  5144. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  5145. // Undo
  5146. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  5147. Assert.Equal ($"\tFirst line.{Environment.NewLine}Second line.{Environment.NewLine}Third line.", tv.Text);
  5148. Assert.Equal (3, tv.Lines);
  5149. Assert.Equal (new Point (1, 0), tv.CursorPosition);
  5150. Assert.True (tv.IsDirty);
  5151. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  5152. Assert.Equal ($"First line.{Environment.NewLine}Second line.{Environment.NewLine}Third line.", tv.Text);
  5153. Assert.Equal (3, tv.Lines);
  5154. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  5155. Assert.False (tv.IsDirty);
  5156. // Redo
  5157. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  5158. Assert.Equal ($"\tFirst line.{Environment.NewLine}Second line.{Environment.NewLine}Third line.", tv.Text);
  5159. Assert.Equal (3, tv.Lines);
  5160. Assert.Equal (new Point (1, 0), tv.CursorPosition);
  5161. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  5162. Assert.Equal ($"First line.{Environment.NewLine}Second line.{Environment.NewLine}Third line.", tv.Text);
  5163. Assert.Equal (3, tv.Lines);
  5164. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  5165. }
  5166. [Fact]
  5167. public void HistoryText_Undo_Redo_Multiline_Selected_Tab_BackTab ()
  5168. {
  5169. var text = "First line.\nSecond line.\nThird line.";
  5170. var tv = new TextView () { Width = 80, Height = 5, Text = text };
  5171. tv.SelectionStartColumn = 6;
  5172. tv.CursorPosition = new Point (6, 2);
  5173. Assert.True (tv.ProcessKey (new KeyEvent (Key.Tab, new KeyModifiers ())));
  5174. Assert.Equal ("First \tline.", tv.Text);
  5175. Assert.Equal (1, tv.Lines);
  5176. Assert.Equal (new Point (7, 0), tv.CursorPosition);
  5177. Assert.True (tv.ProcessKey (new KeyEvent (Key.BackTab, new KeyModifiers ())));
  5178. Assert.Equal ("First line.", tv.Text);
  5179. Assert.Equal (1, tv.Lines);
  5180. Assert.Equal (new Point (6, 0), tv.CursorPosition);
  5181. // Undo
  5182. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  5183. Assert.Equal ("First \tline.", tv.Text);
  5184. Assert.Equal (1, tv.Lines);
  5185. Assert.Equal (new Point (7, 0), tv.CursorPosition);
  5186. Assert.True (tv.IsDirty);
  5187. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  5188. Assert.Equal ($"First line.{Environment.NewLine}Second line.{Environment.NewLine}Third line.", tv.Text);
  5189. Assert.Equal (3, tv.Lines);
  5190. Assert.Equal (new Point (6, 2), tv.CursorPosition);
  5191. Assert.False (tv.IsDirty);
  5192. // Redo
  5193. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  5194. Assert.Equal ("First \tline.", tv.Text);
  5195. Assert.Equal (1, tv.Lines);
  5196. Assert.Equal (new Point (7, 0), tv.CursorPosition);
  5197. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  5198. Assert.Equal ("First line.", tv.Text);
  5199. Assert.Equal (1, tv.Lines);
  5200. Assert.Equal (new Point (6, 0), tv.CursorPosition);
  5201. }
  5202. [Fact]
  5203. public void HistoryText_ClearHistoryChanges ()
  5204. {
  5205. var text = "This is the first line.\nThis is the second line.\nThis is the third line.";
  5206. var tv = new TextView () { Text = text };
  5207. Assert.True (tv.ProcessKey (new KeyEvent (Key.Enter, new KeyModifiers ())));
  5208. 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);
  5209. Assert.Equal (4, tv.Lines);
  5210. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  5211. Assert.True (tv.IsDirty);
  5212. Assert.True (tv.HasHistoryChanges);
  5213. tv.ClearHistoryChanges ();
  5214. 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);
  5215. Assert.Equal (4, tv.Lines);
  5216. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  5217. Assert.False (tv.IsDirty);
  5218. Assert.False (tv.HasHistoryChanges);
  5219. }
  5220. [Fact]
  5221. public void GetRegion_StringFromRunes_Environment_NewLine ()
  5222. {
  5223. var tv = new TextView () { Text = $"1{Environment.NewLine}2" };
  5224. Assert.Equal ($"1{Environment.NewLine}2", tv.Text);
  5225. Assert.Equal ("", tv.SelectedText);
  5226. tv.SelectAll ();
  5227. Assert.Equal ($"1{Environment.NewLine}2", tv.Text);
  5228. Assert.Equal ($"1{Environment.NewLine}2", tv.SelectedText);
  5229. }
  5230. [Fact, AutoInitShutdown]
  5231. public void WordWrap_Not_Throw_If_Width_Is_Less_Than_Zero ()
  5232. {
  5233. var exception = Record.Exception (() => {
  5234. var tv = new TextView () {
  5235. Width = Dim.Fill (),
  5236. Height = Dim.Fill (),
  5237. WordWrap = true,
  5238. Text = "これは、左右のクリップ境界をテストするための非常に長いテキストです。"
  5239. };
  5240. });
  5241. Assert.Null (exception);
  5242. }
  5243. [Fact]
  5244. [AutoInitShutdown]
  5245. public void ScrollDownTillCaretOffscreen_ThenType ()
  5246. {
  5247. var tv = new TextView {
  5248. Width = 10,
  5249. Height = 5
  5250. };
  5251. // add 100 lines of wide text to view
  5252. for (int i = 0; i < 100; i++)
  5253. tv.Text += new string ('x', 100) + Environment.NewLine;
  5254. Assert.Equal (0, tv.CursorPosition.Y);
  5255. tv.ScrollTo (50);
  5256. Assert.Equal (0, tv.CursorPosition.Y);
  5257. tv.ProcessKey (new KeyEvent (Key.p, new KeyModifiers ()));
  5258. }
  5259. [Fact]
  5260. [AutoInitShutdown]
  5261. public void MoveDown_By_Setting_CursorPosition ()
  5262. {
  5263. var tv = new TextView {
  5264. Width = 10,
  5265. Height = 5
  5266. };
  5267. // add 100 lines of wide text to view
  5268. for (int i = 0; i < 100; i++)
  5269. tv.Text += new string ('x', 100) + (i == 99 ? "" : Environment.NewLine);
  5270. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  5271. tv.CursorPosition = new Point (5, 50);
  5272. Assert.Equal (new Point (5, 50), tv.CursorPosition);
  5273. tv.CursorPosition = new Point (200, 200);
  5274. Assert.Equal (new Point (100, 99), tv.CursorPosition);
  5275. }
  5276. [Fact]
  5277. [AutoInitShutdown]
  5278. public void ScrollTo_CursorPosition ()
  5279. {
  5280. var tv = new TextView {
  5281. Width = 10,
  5282. Height = 5
  5283. };
  5284. // add 100 lines of wide text to view
  5285. for (int i = 0; i < 100; i++)
  5286. tv.Text += new string ('x', 100) + (i == 99 ? "" : Environment.NewLine);
  5287. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  5288. tv.ScrollTo (50);
  5289. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  5290. tv.CursorPosition = new Point (tv.LeftColumn, tv.TopRow);
  5291. Assert.Equal (new Point (0, 50), tv.CursorPosition);
  5292. }
  5293. [Fact]
  5294. [TextViewTestsAutoInitShutdown]
  5295. public void Mouse_Button_Shift_Preserves_Selection ()
  5296. {
  5297. Assert.Equal ("TAB to jump between text fields.", _textView.Text);
  5298. Assert.True (_textView.MouseEvent (new MouseEvent () { X = 12, Y = 0, Flags = MouseFlags.Button1Pressed | MouseFlags.ButtonShift }));
  5299. Assert.Equal (0, _textView.SelectionStartColumn);
  5300. Assert.Equal (0, _textView.SelectionStartRow);
  5301. Assert.Equal (new Point (12, 0), _textView.CursorPosition);
  5302. Assert.True (_textView.Selecting);
  5303. Assert.Equal ("TAB to jump ", _textView.SelectedText);
  5304. Assert.True (_textView.MouseEvent (new MouseEvent () { X = 12, Y = 0, Flags = MouseFlags.Button1Clicked }));
  5305. Assert.Equal (0, _textView.SelectionStartRow);
  5306. Assert.Equal (0, _textView.SelectionStartRow);
  5307. Assert.Equal (new Point (12, 0), _textView.CursorPosition);
  5308. Assert.True (_textView.Selecting);
  5309. Assert.Equal ("TAB to jump ", _textView.SelectedText);
  5310. Assert.True (_textView.MouseEvent (new MouseEvent () { X = 19, Y = 0, Flags = MouseFlags.Button1Pressed | MouseFlags.ButtonShift }));
  5311. Assert.Equal (0, _textView.SelectionStartRow);
  5312. Assert.Equal (0, _textView.SelectionStartRow);
  5313. Assert.Equal (new Point (19, 0), _textView.CursorPosition);
  5314. Assert.True (_textView.Selecting);
  5315. Assert.Equal ("TAB to jump between", _textView.SelectedText);
  5316. Assert.True (_textView.MouseEvent (new MouseEvent () { X = 19, Y = 0, Flags = MouseFlags.Button1Clicked }));
  5317. Assert.Equal (0, _textView.SelectionStartRow);
  5318. Assert.Equal (0, _textView.SelectionStartRow);
  5319. Assert.Equal (new Point (19, 0), _textView.CursorPosition);
  5320. Assert.True (_textView.Selecting);
  5321. Assert.Equal ("TAB to jump between", _textView.SelectedText);
  5322. Assert.True (_textView.MouseEvent (new MouseEvent () { X = 24, Y = 0, Flags = MouseFlags.Button1Pressed | MouseFlags.ButtonShift }));
  5323. Assert.Equal (0, _textView.SelectionStartRow);
  5324. Assert.Equal (0, _textView.SelectionStartRow);
  5325. Assert.Equal (new Point (24, 0), _textView.CursorPosition);
  5326. Assert.True (_textView.Selecting);
  5327. Assert.Equal ("TAB to jump between text", _textView.SelectedText);
  5328. Assert.True (_textView.MouseEvent (new MouseEvent () { X = 24, Y = 0, Flags = MouseFlags.Button1Clicked }));
  5329. Assert.Equal (0, _textView.SelectionStartRow);
  5330. Assert.Equal (0, _textView.SelectionStartRow);
  5331. Assert.Equal (new Point (24, 0), _textView.CursorPosition);
  5332. Assert.True (_textView.Selecting);
  5333. Assert.Equal ("TAB to jump between text", _textView.SelectedText);
  5334. Assert.True (_textView.MouseEvent (new MouseEvent () { X = 24, Y = 0, Flags = MouseFlags.Button1Pressed }));
  5335. Assert.Equal (0, _textView.SelectionStartRow);
  5336. Assert.Equal (0, _textView.SelectionStartRow);
  5337. Assert.Equal (new Point (24, 0), _textView.CursorPosition);
  5338. Assert.True (_textView.Selecting);
  5339. Assert.Equal ("", _textView.SelectedText);
  5340. }
  5341. [Fact, AutoInitShutdown]
  5342. public void UnwrappedCursorPosition_Event ()
  5343. {
  5344. var cp = Point.Empty;
  5345. var tv = new TextView () {
  5346. Width = Dim.Fill (),
  5347. Height = Dim.Fill (),
  5348. Text = "This is the first line.\nThis is the second line.\n"
  5349. };
  5350. tv.UnwrappedCursorPosition += (s, e) => {
  5351. cp = e.Point;
  5352. };
  5353. Application.Top.Add (tv);
  5354. Application.Begin (Application.Top);
  5355. Assert.False (tv.WordWrap);
  5356. Assert.Equal (Point.Empty, tv.CursorPosition);
  5357. Assert.Equal (Point.Empty, cp);
  5358. TestHelpers.AssertDriverContentsWithFrameAre (@"
  5359. This is the first line.
  5360. This is the second line.
  5361. ", output);
  5362. tv.WordWrap = true;
  5363. tv.CursorPosition = new Point (12, 0);
  5364. tv.Redraw (tv.Bounds);
  5365. Assert.Equal (new Point (12, 0), tv.CursorPosition);
  5366. Assert.Equal (new Point (12, 0), cp);
  5367. TestHelpers.AssertDriverContentsWithFrameAre (@"
  5368. This is the first line.
  5369. This is the second line.
  5370. ", output);
  5371. ((FakeDriver)Application.Driver).SetBufferSize (6, 25);
  5372. tv.Redraw (tv.Bounds);
  5373. Assert.Equal (new Point (4, 2), tv.CursorPosition);
  5374. Assert.Equal (new Point (12, 0), cp);
  5375. TestHelpers.AssertDriverContentsWithFrameAre (@"
  5376. This
  5377. is
  5378. the
  5379. first
  5380. line.
  5381. This
  5382. is
  5383. the
  5384. secon
  5385. d
  5386. line.
  5387. ", output);
  5388. Assert.True (tv.ProcessKey (new KeyEvent (Key.CursorRight, new KeyModifiers ())));
  5389. tv.Redraw (tv.Bounds);
  5390. Assert.Equal (new Point (0, 3), tv.CursorPosition);
  5391. Assert.Equal (new Point (12, 0), cp);
  5392. TestHelpers.AssertDriverContentsWithFrameAre (@"
  5393. This
  5394. is
  5395. the
  5396. first
  5397. line.
  5398. This
  5399. is
  5400. the
  5401. secon
  5402. d
  5403. line.
  5404. ", output);
  5405. Assert.True (tv.ProcessKey (new KeyEvent (Key.CursorRight, new KeyModifiers ())));
  5406. tv.Redraw (tv.Bounds);
  5407. Assert.Equal (new Point (1, 3), tv.CursorPosition);
  5408. Assert.Equal (new Point (13, 0), cp);
  5409. TestHelpers.AssertDriverContentsWithFrameAre (@"
  5410. This
  5411. is
  5412. the
  5413. first
  5414. line.
  5415. This
  5416. is
  5417. the
  5418. secon
  5419. d
  5420. line.
  5421. ", output);
  5422. Assert.True (tv.MouseEvent (new MouseEvent () { X = 0, Y = 3, Flags = MouseFlags.Button1Pressed }));
  5423. tv.Redraw (tv.Bounds);
  5424. Assert.Equal (new Point (0, 3), tv.CursorPosition);
  5425. Assert.Equal (new Point (12, 0), cp);
  5426. TestHelpers.AssertDriverContentsWithFrameAre (@"
  5427. This
  5428. is
  5429. the
  5430. first
  5431. line.
  5432. This
  5433. is
  5434. the
  5435. secon
  5436. d
  5437. line.
  5438. ", output);
  5439. }
  5440. [Fact]
  5441. [AutoInitShutdown]
  5442. public void DeleteTextBackwards_WordWrap_False_Return_Undo ()
  5443. {
  5444. const string text = "This is the first line.\nThis is the second line.\n";
  5445. var tv = new TextView () {
  5446. Width = Dim.Fill (),
  5447. Height = Dim.Fill (),
  5448. Text = text
  5449. };
  5450. var envText = tv.Text;
  5451. Application.Top.Add (tv);
  5452. Application.Begin (Application.Top);
  5453. Assert.False (tv.WordWrap);
  5454. Assert.Equal (Point.Empty, tv.CursorPosition);
  5455. TestHelpers.AssertDriverContentsWithFrameAre (@"
  5456. This is the first line.
  5457. This is the second line.
  5458. ", output);
  5459. tv.CursorPosition = new Point (3, 0);
  5460. Assert.Equal (new Point (3, 0), tv.CursorPosition);
  5461. Assert.True (tv.ProcessKey (new KeyEvent (Key.Backspace, new KeyModifiers ())));
  5462. tv.Redraw (tv.Bounds);
  5463. Assert.Equal (new Point (2, 0), tv.CursorPosition);
  5464. TestHelpers.AssertDriverContentsWithFrameAre (@"
  5465. Ths is the first line.
  5466. This is the second line.
  5467. ", output);
  5468. tv.CursorPosition = new Point (0, 1);
  5469. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  5470. Assert.True (tv.ProcessKey (new KeyEvent (Key.Backspace, new KeyModifiers ())));
  5471. tv.Redraw (tv.Bounds);
  5472. Assert.Equal (new Point (22, 0), tv.CursorPosition);
  5473. TestHelpers.AssertDriverContentsWithFrameAre (@"
  5474. Ths is the first line.This is the second line.
  5475. ", output);
  5476. Assert.True (tv.ProcessKey (new KeyEvent (Key.Enter, new KeyModifiers ())));
  5477. tv.Redraw (tv.Bounds);
  5478. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  5479. TestHelpers.AssertDriverContentsWithFrameAre (@"
  5480. Ths is the first line.
  5481. This is the second line.
  5482. ", output);
  5483. while (tv.Text != envText) {
  5484. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  5485. }
  5486. Assert.Equal (envText, tv.Text);
  5487. Assert.Equal (new Point (3, 0), tv.CursorPosition);
  5488. Assert.False (tv.IsDirty);
  5489. }
  5490. [Fact]
  5491. [AutoInitShutdown]
  5492. public void DeleteTextBackwards_WordWrap_True_Return_Undo ()
  5493. {
  5494. const string text = "This is the first line.\nThis is the second line.\n";
  5495. var tv = new TextView () {
  5496. Width = Dim.Fill (),
  5497. Height = Dim.Fill (),
  5498. Text = text,
  5499. WordWrap = true
  5500. };
  5501. var envText = tv.Text;
  5502. Application.Top.Add (tv);
  5503. Application.Begin (Application.Top);
  5504. Assert.True (tv.WordWrap);
  5505. Assert.Equal (Point.Empty, tv.CursorPosition);
  5506. TestHelpers.AssertDriverContentsWithFrameAre (@"
  5507. This is the first line.
  5508. This is the second line.
  5509. ", output);
  5510. tv.CursorPosition = new Point (3, 0);
  5511. Assert.Equal (new Point (3, 0), tv.CursorPosition);
  5512. Assert.True (tv.ProcessKey (new KeyEvent (Key.Backspace, new KeyModifiers ())));
  5513. tv.Redraw (tv.Bounds);
  5514. Assert.Equal (new Point (2, 0), tv.CursorPosition);
  5515. TestHelpers.AssertDriverContentsWithFrameAre (@"
  5516. Ths is the first line.
  5517. This is the second line.
  5518. ", output);
  5519. tv.CursorPosition = new Point (0, 1);
  5520. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  5521. Assert.True (tv.ProcessKey (new KeyEvent (Key.Backspace, new KeyModifiers ())));
  5522. tv.Redraw (tv.Bounds);
  5523. Assert.Equal (new Point (22, 0), tv.CursorPosition);
  5524. TestHelpers.AssertDriverContentsWithFrameAre (@"
  5525. Ths is the first line.This is the second line.
  5526. ", output);
  5527. Assert.True (tv.ProcessKey (new KeyEvent (Key.Enter, new KeyModifiers ())));
  5528. tv.Redraw (tv.Bounds);
  5529. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  5530. TestHelpers.AssertDriverContentsWithFrameAre (@"
  5531. Ths is the first line.
  5532. This is the second line.
  5533. ", output);
  5534. while (tv.Text != envText) {
  5535. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  5536. }
  5537. Assert.Equal (envText, tv.Text);
  5538. Assert.Equal (new Point (3, 0), tv.CursorPosition);
  5539. Assert.False (tv.IsDirty);
  5540. }
  5541. [Fact]
  5542. [AutoInitShutdown]
  5543. public void DeleteTextForwards_WordWrap_False_Return_Undo ()
  5544. {
  5545. const string text = "This is the first line.\nThis is the second line.\n";
  5546. var tv = new TextView () {
  5547. Width = Dim.Fill (),
  5548. Height = Dim.Fill (),
  5549. Text = text
  5550. };
  5551. var envText = tv.Text;
  5552. Application.Top.Add (tv);
  5553. Application.Begin (Application.Top);
  5554. Assert.False (tv.WordWrap);
  5555. Assert.Equal (Point.Empty, tv.CursorPosition);
  5556. TestHelpers.AssertDriverContentsWithFrameAre (@"
  5557. This is the first line.
  5558. This is the second line.
  5559. ", output);
  5560. tv.CursorPosition = new Point (2, 0);
  5561. Assert.Equal (new Point (2, 0), tv.CursorPosition);
  5562. Assert.True (tv.ProcessKey (new KeyEvent (Key.DeleteChar, new KeyModifiers ())));
  5563. tv.Redraw (tv.Bounds);
  5564. Assert.Equal (new Point (2, 0), tv.CursorPosition);
  5565. TestHelpers.AssertDriverContentsWithFrameAre (@"
  5566. Ths is the first line.
  5567. This is the second line.
  5568. ", output);
  5569. tv.CursorPosition = new Point (22, 0);
  5570. Assert.Equal (new Point (22, 0), tv.CursorPosition);
  5571. Assert.True (tv.ProcessKey (new KeyEvent (Key.DeleteChar, new KeyModifiers ())));
  5572. tv.Redraw (tv.Bounds);
  5573. Assert.Equal (new Point (22, 0), tv.CursorPosition);
  5574. TestHelpers.AssertDriverContentsWithFrameAre (@"
  5575. Ths is the first line.This is the second line.
  5576. ", output);
  5577. Assert.True (tv.ProcessKey (new KeyEvent (Key.Enter, new KeyModifiers ())));
  5578. tv.Redraw (tv.Bounds);
  5579. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  5580. TestHelpers.AssertDriverContentsWithFrameAre (@"
  5581. Ths is the first line.
  5582. This is the second line.
  5583. ", output);
  5584. while (tv.Text != envText) {
  5585. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  5586. }
  5587. Assert.Equal (envText, tv.Text);
  5588. Assert.Equal (new Point (2, 0), tv.CursorPosition);
  5589. Assert.False (tv.IsDirty);
  5590. }
  5591. [Fact]
  5592. [AutoInitShutdown]
  5593. public void DeleteTextForwards_WordWrap_True_Return_Undo ()
  5594. {
  5595. const string text = "This is the first line.\nThis is the second line.\n";
  5596. var tv = new TextView () {
  5597. Width = Dim.Fill (),
  5598. Height = Dim.Fill (),
  5599. Text = text,
  5600. WordWrap = true
  5601. };
  5602. var envText = tv.Text;
  5603. Application.Top.Add (tv);
  5604. Application.Begin (Application.Top);
  5605. Assert.True (tv.WordWrap);
  5606. Assert.Equal (Point.Empty, tv.CursorPosition);
  5607. TestHelpers.AssertDriverContentsWithFrameAre (@"
  5608. This is the first line.
  5609. This is the second line.
  5610. ", output);
  5611. tv.CursorPosition = new Point (2, 0);
  5612. Assert.Equal (new Point (2, 0), tv.CursorPosition);
  5613. Assert.True (tv.ProcessKey (new KeyEvent (Key.DeleteChar, new KeyModifiers ())));
  5614. tv.Redraw (tv.Bounds);
  5615. Assert.Equal (new Point (2, 0), tv.CursorPosition);
  5616. TestHelpers.AssertDriverContentsWithFrameAre (@"
  5617. Ths is the first line.
  5618. This is the second line.
  5619. ", output);
  5620. tv.CursorPosition = new Point (22, 0);
  5621. Assert.Equal (new Point (22, 0), tv.CursorPosition);
  5622. Assert.True (tv.ProcessKey (new KeyEvent (Key.DeleteChar, new KeyModifiers ())));
  5623. tv.Redraw (tv.Bounds);
  5624. Assert.Equal (new Point (22, 0), tv.CursorPosition);
  5625. TestHelpers.AssertDriverContentsWithFrameAre (@"
  5626. Ths is the first line.This is the second line.
  5627. ", output);
  5628. Assert.True (tv.ProcessKey (new KeyEvent (Key.Enter, new KeyModifiers ())));
  5629. tv.Redraw (tv.Bounds);
  5630. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  5631. TestHelpers.AssertDriverContentsWithFrameAre (@"
  5632. Ths is the first line.
  5633. This is the second line.
  5634. ", output);
  5635. while (tv.Text != envText) {
  5636. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  5637. }
  5638. Assert.Equal (envText, tv.Text);
  5639. Assert.Equal (new Point (2, 0), tv.CursorPosition);
  5640. Assert.False (tv.IsDirty);
  5641. }
  5642. [Fact]
  5643. [TextViewTestsAutoInitShutdown]
  5644. public void TextView_InsertText_Newline_LF ()
  5645. {
  5646. var tv = new TextView {
  5647. Width = 10,
  5648. Height = 10,
  5649. };
  5650. tv.InsertText ("\naaa\nbbb");
  5651. var p = Environment.OSVersion.Platform;
  5652. if (p == PlatformID.Win32NT || p == PlatformID.Win32S || p == PlatformID.Win32Windows) {
  5653. Assert.Equal ("\r\naaa\r\nbbb", tv.Text);
  5654. } else {
  5655. Assert.Equal ("\naaa\nbbb", tv.Text);
  5656. }
  5657. Assert.Equal ($"{Environment.NewLine}aaa{Environment.NewLine}bbb", tv.Text);
  5658. var win = new Window ();
  5659. win.Add (tv);
  5660. Application.Top.Add (win);
  5661. Application.Begin (Application.Top);
  5662. ((FakeDriver)Application.Driver).SetBufferSize (15, 15);
  5663. Application.Refresh ();
  5664. //this passes
  5665. var pos = TestHelpers.AssertDriverContentsWithFrameAre (
  5666. @"
  5667. ┌─────────────┐
  5668. │ │
  5669. │aaa │
  5670. │bbb │
  5671. │ │
  5672. │ │
  5673. │ │
  5674. │ │
  5675. │ │
  5676. │ │
  5677. │ │
  5678. │ │
  5679. │ │
  5680. │ │
  5681. └─────────────┘", output);
  5682. Assert.Equal (new Rect (0, 0, 15, 15), pos);
  5683. Assert.True (tv.Used);
  5684. tv.Used = false;
  5685. tv.CursorPosition = new Point (0, 0);
  5686. tv.InsertText ("\naaa\nbbb");
  5687. Application.Refresh ();
  5688. TestHelpers.AssertDriverContentsWithFrameAre (
  5689. @"
  5690. ┌─────────────┐
  5691. │ │
  5692. │aaa │
  5693. │bbb │
  5694. │aaa │
  5695. │bbb │
  5696. │ │
  5697. │ │
  5698. │ │
  5699. │ │
  5700. │ │
  5701. │ │
  5702. │ │
  5703. │ │
  5704. └─────────────┘", output);
  5705. }
  5706. [Fact]
  5707. [TextViewTestsAutoInitShutdown]
  5708. public void TextView_InsertText_Newline_CRLF ()
  5709. {
  5710. var tv = new TextView {
  5711. Width = 10,
  5712. Height = 10,
  5713. };
  5714. tv.InsertText ("\r\naaa\r\nbbb");
  5715. var p = Environment.OSVersion.Platform;
  5716. if (p == PlatformID.Win32NT || p == PlatformID.Win32S || p == PlatformID.Win32Windows) {
  5717. Assert.Equal ("\r\naaa\r\nbbb", tv.Text);
  5718. } else {
  5719. Assert.Equal ("\naaa\nbbb", tv.Text);
  5720. }
  5721. Assert.Equal ($"{Environment.NewLine}aaa{Environment.NewLine}bbb", tv.Text);
  5722. var win = new Window ();
  5723. win.Add (tv);
  5724. Application.Top.Add (win);
  5725. Application.Begin (Application.Top);
  5726. ((FakeDriver)Application.Driver).SetBufferSize (15, 15);
  5727. Application.Refresh ();
  5728. //this passes
  5729. var pos = TestHelpers.AssertDriverContentsWithFrameAre (
  5730. @"
  5731. ┌─────────────┐
  5732. │ │
  5733. │aaa │
  5734. │bbb │
  5735. │ │
  5736. │ │
  5737. │ │
  5738. │ │
  5739. │ │
  5740. │ │
  5741. │ │
  5742. │ │
  5743. │ │
  5744. │ │
  5745. └─────────────┘", output);
  5746. Assert.Equal (new Rect (0, 0, 15, 15), pos);
  5747. Assert.True (tv.Used);
  5748. tv.Used = false;
  5749. tv.CursorPosition = new Point (0, 0);
  5750. tv.InsertText ("\r\naaa\r\nbbb");
  5751. Application.Refresh ();
  5752. TestHelpers.AssertDriverContentsWithFrameAre (
  5753. @"
  5754. ┌─────────────┐
  5755. │ │
  5756. │aaa │
  5757. │bbb │
  5758. │aaa │
  5759. │bbb │
  5760. │ │
  5761. │ │
  5762. │ │
  5763. │ │
  5764. │ │
  5765. │ │
  5766. │ │
  5767. │ │
  5768. └─────────────┘", output);
  5769. }
  5770. [Fact, AutoInitShutdown]
  5771. public void ContentsChanged_Event_NoFires_On_CursorPosition ()
  5772. {
  5773. var eventcount = 0;
  5774. var tv = new TextView {
  5775. Width = 50,
  5776. Height = 10,
  5777. };
  5778. tv.ContentsChanged += (s, e) => {
  5779. eventcount++;
  5780. };
  5781. Assert.Equal (0, eventcount);
  5782. tv.CursorPosition = new Point (0, 0);
  5783. Assert.Equal (0, eventcount);
  5784. }
  5785. [Fact, AutoInitShutdown]
  5786. public void ContentsChanged_Event_Fires_On_InsertText ()
  5787. {
  5788. var eventcount = 0;
  5789. var tv = new TextView {
  5790. Width = 50,
  5791. Height = 10,
  5792. };
  5793. tv.CursorPosition = new Point (0, 0);
  5794. tv.ContentsChanged += (s, e) => {
  5795. eventcount++;
  5796. };
  5797. Assert.Equal (0, eventcount);
  5798. tv.InsertText ("a");
  5799. Assert.Equal (1, eventcount);
  5800. tv.CursorPosition = new Point (0, 0);
  5801. tv.InsertText ("bcd");
  5802. Assert.Equal (4, eventcount);
  5803. tv.InsertText ("e");
  5804. Assert.Equal (5, eventcount);
  5805. tv.InsertText ("\n");
  5806. Assert.Equal (6, eventcount);
  5807. tv.InsertText ("1234");
  5808. Assert.Equal (10, eventcount);
  5809. }
  5810. [Fact, AutoInitShutdown]
  5811. public void ContentsChanged_Event_Fires_On_Init ()
  5812. {
  5813. Application.Iteration += () => {
  5814. Application.RequestStop ();
  5815. };
  5816. var expectedRow = 0;
  5817. var expectedCol = 0;
  5818. var eventcount = 0;
  5819. var tv = new TextView {
  5820. Width = 50,
  5821. Height = 10,
  5822. };
  5823. tv.ContentsChanged += (s, e) => {
  5824. eventcount++;
  5825. Assert.Equal (expectedRow, e.Row);
  5826. Assert.Equal (expectedCol, e.Col);
  5827. };
  5828. Application.Top.Add (tv);
  5829. Application.Begin (Application.Top);
  5830. Assert.Equal (1, eventcount);
  5831. }
  5832. [Fact, AutoInitShutdown]
  5833. public void ContentsChanged_Event_Fires_On_Set_Text ()
  5834. {
  5835. Application.Iteration += () => {
  5836. Application.RequestStop ();
  5837. };
  5838. var eventcount = 0;
  5839. var expectedRow = 0;
  5840. var expectedCol = 0;
  5841. var tv = new TextView {
  5842. Width = 50,
  5843. Height = 10,
  5844. // you'd think col would be 3, but it's 0 because TextView sets
  5845. // row/col = 0 when you set Text
  5846. Text = "abc",
  5847. };
  5848. tv.ContentsChanged += (s, e) => {
  5849. eventcount++;
  5850. Assert.Equal (expectedRow, e.Row);
  5851. Assert.Equal (expectedCol, e.Col);
  5852. };
  5853. Assert.Equal ("abc", tv.Text);
  5854. Application.Top.Add (tv);
  5855. var rs = Application.Begin (Application.Top);
  5856. Assert.Equal (1, eventcount); // for Initialize
  5857. expectedCol = 0;
  5858. tv.Text = "defg";
  5859. Assert.Equal (2, eventcount); // for set Text = "defg"
  5860. }
  5861. [Fact, AutoInitShutdown]
  5862. public void ContentsChanged_Event_Fires_On_Typing ()
  5863. {
  5864. Application.Iteration += () => {
  5865. Application.RequestStop ();
  5866. };
  5867. var eventcount = 0;
  5868. var expectedRow = 0;
  5869. var expectedCol = 0;
  5870. var tv = new TextView {
  5871. Width = 50,
  5872. Height = 10,
  5873. };
  5874. tv.ContentsChanged += (s, e) => {
  5875. eventcount++;
  5876. Assert.Equal (expectedRow, e.Row);
  5877. Assert.Equal (expectedCol, e.Col);
  5878. };
  5879. Application.Top.Add (tv);
  5880. var rs = Application.Begin (Application.Top);
  5881. Assert.Equal (1, eventcount); // for Initialize
  5882. expectedCol = 0;
  5883. tv.Text = "ay";
  5884. Assert.Equal (2, eventcount);
  5885. expectedCol = 1;
  5886. tv.ProcessKey (new KeyEvent (Key.Y, new KeyModifiers ()));
  5887. Assert.Equal (3, eventcount);
  5888. Assert.Equal ("Yay", tv.Text.ToString ());
  5889. }
  5890. [Fact, TextViewTestsAutoInitShutdown]
  5891. public void ContentsChanged_Event_Fires_Using_Kill_Delete_Tests ()
  5892. {
  5893. var eventcount = 0;
  5894. _textView.ContentsChanged += (s, e) => {
  5895. eventcount++;
  5896. };
  5897. var expectedEventCount = 1;
  5898. Kill_Delete_WordForward ();
  5899. Assert.Equal (expectedEventCount, eventcount); // for Initialize
  5900. expectedEventCount += 1;
  5901. Kill_Delete_WordBackward ();
  5902. Assert.Equal (expectedEventCount, eventcount);
  5903. expectedEventCount += 1;
  5904. Kill_To_End_Delete_Forwards_And_Copy_To_The_Clipboard ();
  5905. Assert.Equal (expectedEventCount, eventcount);
  5906. expectedEventCount += 1;
  5907. Kill_To_Start_Delete_Backwards_And_Copy_To_The_Clipboard ();
  5908. Assert.Equal (expectedEventCount, eventcount);
  5909. }
  5910. [Fact, TextViewTestsAutoInitShutdown]
  5911. public void ContentsChanged_Event_Fires_Using_Copy_Or_Cut_Tests ()
  5912. {
  5913. var eventcount = 0;
  5914. _textView.ContentsChanged += (s, e) => {
  5915. eventcount++;
  5916. };
  5917. var expectedEventCount = 1;
  5918. // reset
  5919. _textView.Text = TextViewTestsAutoInitShutdown.txt;
  5920. Assert.Equal (expectedEventCount, eventcount);
  5921. expectedEventCount += 3;
  5922. Copy_Or_Cut_And_Paste_With_No_Selection ();
  5923. Assert.Equal (expectedEventCount, eventcount);
  5924. // reset
  5925. expectedEventCount += 1;
  5926. _textView.Text = TextViewTestsAutoInitShutdown.txt;
  5927. Assert.Equal (expectedEventCount, eventcount);
  5928. expectedEventCount += 3;
  5929. Copy_Or_Cut_And_Paste_With_Selection ();
  5930. Assert.Equal (expectedEventCount, eventcount);
  5931. // reset
  5932. expectedEventCount += 1;
  5933. _textView.Text = TextViewTestsAutoInitShutdown.txt;
  5934. Assert.Equal (expectedEventCount, eventcount);
  5935. expectedEventCount += 1;
  5936. Copy_Or_Cut_Not_Null_If_Has_Selection ();
  5937. Assert.Equal (expectedEventCount, eventcount);
  5938. // reset
  5939. expectedEventCount += 1;
  5940. _textView.Text = TextViewTestsAutoInitShutdown.txt;
  5941. Assert.Equal (expectedEventCount, eventcount);
  5942. expectedEventCount += 1;
  5943. Copy_Or_Cut_Null_If_No_Selection ();
  5944. Assert.Equal (expectedEventCount, eventcount);
  5945. // reset
  5946. expectedEventCount += 1;
  5947. _textView.Text = TextViewTestsAutoInitShutdown.txt;
  5948. Assert.Equal (expectedEventCount, eventcount);
  5949. expectedEventCount += 4;
  5950. Copy_Without_Selection ();
  5951. Assert.Equal (expectedEventCount, eventcount);
  5952. // reset
  5953. expectedEventCount += 1;
  5954. _textView.Text = TextViewTestsAutoInitShutdown.txt;
  5955. Assert.Equal (expectedEventCount, eventcount);
  5956. expectedEventCount += 4;
  5957. Copy_Without_Selection ();
  5958. Assert.Equal (expectedEventCount, eventcount);
  5959. }
  5960. [Fact, TextViewTestsAutoInitShutdown]
  5961. public void ContentsChanged_Event_Fires_On_Undo_Redo ()
  5962. {
  5963. var eventcount = 0;
  5964. var expectedEventCount = 0;
  5965. _textView.ContentsChanged += (s, e) => {
  5966. eventcount++;
  5967. };
  5968. expectedEventCount++;
  5969. _textView.Text = "This is the first line.\nThis is the second line.\nThis is the third line.";
  5970. Assert.Equal (expectedEventCount, eventcount);
  5971. expectedEventCount++;
  5972. Assert.True (_textView.ProcessKey (new KeyEvent (Key.Enter, new KeyModifiers ())));
  5973. Assert.Equal (expectedEventCount, eventcount);
  5974. // Undo
  5975. expectedEventCount++;
  5976. Assert.True (_textView.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  5977. Assert.Equal (expectedEventCount, eventcount);
  5978. // Redo
  5979. expectedEventCount++;
  5980. Assert.True (_textView.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  5981. Assert.Equal (expectedEventCount, eventcount);
  5982. // Undo
  5983. expectedEventCount++;
  5984. Assert.True (_textView.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  5985. Assert.Equal (expectedEventCount, eventcount);
  5986. // Redo
  5987. expectedEventCount++;
  5988. Assert.True (_textView.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  5989. Assert.Equal (expectedEventCount, eventcount);
  5990. }
  5991. [Fact]
  5992. public void ContentsChanged_Event_Fires_ClearHistoryChanges ()
  5993. {
  5994. var eventcount = 0;
  5995. var text = "This is the first line.\nThis is the second line.\nThis is the third line.";
  5996. var tv = new TextView {
  5997. Width = 50,
  5998. Height = 10,
  5999. Text = text,
  6000. };
  6001. tv.ContentsChanged += (s, e) => {
  6002. eventcount++;
  6003. };
  6004. Assert.True (tv.ProcessKey (new KeyEvent (Key.Enter, new KeyModifiers ())));
  6005. 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);
  6006. Assert.Equal (4, tv.Lines);
  6007. var expectedEventCount = 1; // for ENTER key
  6008. Assert.Equal (expectedEventCount, eventcount);
  6009. tv.ClearHistoryChanges ();
  6010. expectedEventCount = 2;
  6011. Assert.Equal (expectedEventCount, eventcount);
  6012. }
  6013. [Fact]
  6014. public void ContentsChanged_Event_Fires_LoadStream_By_Calling_HistoryText_Clear ()
  6015. {
  6016. var eventcount = 0;
  6017. var tv = new TextView {
  6018. Width = 50,
  6019. Height = 10,
  6020. };
  6021. tv.ContentsChanged += (s, e) => {
  6022. eventcount++;
  6023. };
  6024. var text = "This is the first line.\r\nThis is the second line.\r\n";
  6025. tv.LoadStream (new System.IO.MemoryStream (System.Text.Encoding.ASCII.GetBytes (text)));
  6026. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}", tv.Text);
  6027. Assert.Equal (1, eventcount);
  6028. }
  6029. [Fact]
  6030. public void ContentsChanged_Event_Fires_On_LoadFile_By_Calling_HistoryText_Clear ()
  6031. {
  6032. var eventcount = 0;
  6033. var tv = new TextView {
  6034. Width = 50,
  6035. Height = 10,
  6036. };
  6037. // BUGBUG: v2 - views must be initialzed before doing things.
  6038. tv.BeginInit (); tv.EndInit ();
  6039. tv.ContentsChanged += (s, e) => {
  6040. eventcount++;
  6041. };
  6042. var fileName = "textview.txt";
  6043. System.IO.File.WriteAllText (fileName, "This is the first line.\r\nThis is the second line.\r\n");
  6044. tv.LoadFile (fileName);
  6045. Assert.Equal (1, eventcount);
  6046. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}", tv.Text);
  6047. }
  6048. [Fact]
  6049. public void ReplaceAllText_Does_Not_Throw_Exception ()
  6050. {
  6051. var textToFind = "hello! hello!";
  6052. var textToReplace = "hello!";
  6053. var tv = new TextView () { Width = 20, Height = 3, Text = textToFind };
  6054. var exception = Record.Exception (() => tv.ReplaceAllText (textToFind, false, false, textToReplace));
  6055. Assert.Null (exception);
  6056. Assert.Equal (textToReplace, tv.Text);
  6057. }
  6058. }
  6059. }