TextViewTests.cs 263 KB

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