2
0

TextViewTests.cs 243 KB

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