TextViewTests.cs 230 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612
  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.True (_textView.Selecting);
  1273. _textView.Selecting = false;
  1274. _textView.ProcessKey (new KeyEvent (Key.Y | Key.CtrlMask, new KeyModifiers ())); // Paste
  1275. Assert.Equal ("TAB to jump between texttext fields.", _textView.Text);
  1276. _textView.SelectionStartColumn = 24;
  1277. _textView.SelectionStartRow = 0;
  1278. _textView.ProcessKey (new KeyEvent (Key.W | Key.CtrlMask, new KeyModifiers ())); // Cut
  1279. Assert.Equal ("", _textView.SelectedText);
  1280. Assert.Equal ("TAB to jump between text fields.", _textView.Text);
  1281. _textView.SelectionStartColumn = 0;
  1282. _textView.SelectionStartRow = 0;
  1283. Assert.True (_textView.Selecting);
  1284. _textView.Selecting = false;
  1285. _textView.ProcessKey (new KeyEvent (Key.Y | Key.CtrlMask, new KeyModifiers ())); // Paste
  1286. Assert.Equal ("TAB to jump between texttext fields.", _textView.Text);
  1287. }
  1288. [Fact]
  1289. [InitShutdown]
  1290. public void Cut_Not_Allowed_If_ReadOnly_Is_True ()
  1291. {
  1292. _textView.ReadOnly = true;
  1293. _textView.SelectionStartColumn = 20;
  1294. _textView.SelectionStartRow = 0;
  1295. _textView.CursorPosition = new Point (24, 0);
  1296. _textView.ProcessKey (new KeyEvent (Key.C | Key.CtrlMask, new KeyModifiers ())); // Copy
  1297. Assert.Equal ("text", _textView.SelectedText);
  1298. _textView.ProcessKey (new KeyEvent (Key.W | Key.CtrlMask, new KeyModifiers ())); // Selecting is set to false after Cut.
  1299. Assert.Equal ("", _textView.SelectedText);
  1300. _textView.ReadOnly = false;
  1301. Assert.False (_textView.Selecting);
  1302. _textView.Selecting = true; // Needed to set Selecting to true.
  1303. _textView.ProcessKey (new KeyEvent (Key.C | Key.CtrlMask, new KeyModifiers ())); // Copy
  1304. Assert.Equal ("text", _textView.SelectedText);
  1305. _textView.ProcessKey (new KeyEvent (Key.W | Key.CtrlMask, new KeyModifiers ())); // Cut
  1306. Assert.Equal ("", _textView.SelectedText);
  1307. }
  1308. [Fact]
  1309. [InitShutdown]
  1310. public void Paste_Always_Clear_The_SelectedText ()
  1311. {
  1312. _textView.SelectionStartColumn = 20;
  1313. _textView.SelectionStartRow = 0;
  1314. _textView.CursorPosition = new Point (24, 0);
  1315. _textView.ProcessKey (new KeyEvent (Key.C | Key.CtrlMask, new KeyModifiers ())); // Copy
  1316. Assert.Equal ("text", _textView.SelectedText);
  1317. _textView.ProcessKey (new KeyEvent (Key.Y | Key.CtrlMask, new KeyModifiers ())); // Paste
  1318. Assert.Equal ("", _textView.SelectedText);
  1319. }
  1320. [Fact]
  1321. [InitShutdown]
  1322. public void TextChanged_Event ()
  1323. {
  1324. _textView.TextChanged += () => {
  1325. if (_textView.Text == "changing") {
  1326. Assert.Equal ("changing", _textView.Text);
  1327. _textView.Text = "changed";
  1328. }
  1329. };
  1330. _textView.Text = "changing";
  1331. Assert.Equal ("changed", _textView.Text);
  1332. }
  1333. [Fact]
  1334. [InitShutdown]
  1335. public void Used_Is_True_By_Default ()
  1336. {
  1337. _textView.CursorPosition = new Point (10, 0);
  1338. Assert.Equal ("TAB to jump between text fields.", _textView.Text);
  1339. _textView.ProcessKey (new KeyEvent ((Key)0x75, new KeyModifiers ())); // u
  1340. Assert.Equal ("TAB to jumup between text fields.", _textView.Text);
  1341. _textView.ProcessKey (new KeyEvent ((Key)0x73, new KeyModifiers ())); // s
  1342. Assert.Equal ("TAB to jumusp between text fields.", _textView.Text);
  1343. _textView.ProcessKey (new KeyEvent ((Key)0x65, new KeyModifiers ())); // e
  1344. Assert.Equal ("TAB to jumusep between text fields.", _textView.Text);
  1345. _textView.ProcessKey (new KeyEvent ((Key)0x64, new KeyModifiers ())); // d
  1346. Assert.Equal ("TAB to jumusedp between text fields.", _textView.Text);
  1347. }
  1348. [Fact]
  1349. [InitShutdown]
  1350. public void Used_Is_False ()
  1351. {
  1352. _textView.Used = false;
  1353. _textView.CursorPosition = new Point (10, 0);
  1354. Assert.Equal ("TAB to jump between text fields.", _textView.Text);
  1355. _textView.ProcessKey (new KeyEvent ((Key)0x75, new KeyModifiers ())); // u
  1356. Assert.Equal ("TAB to jumu between text fields.", _textView.Text);
  1357. _textView.ProcessKey (new KeyEvent ((Key)0x73, new KeyModifiers ())); // s
  1358. Assert.Equal ("TAB to jumusbetween text fields.", _textView.Text);
  1359. _textView.ProcessKey (new KeyEvent ((Key)0x65, new KeyModifiers ())); // e
  1360. Assert.Equal ("TAB to jumuseetween text fields.", _textView.Text);
  1361. _textView.ProcessKey (new KeyEvent ((Key)0x64, new KeyModifiers ())); // d
  1362. Assert.Equal ("TAB to jumusedtween text fields.", _textView.Text);
  1363. }
  1364. [Fact]
  1365. [InitShutdown]
  1366. public void Copy_Without_Selection ()
  1367. {
  1368. _textView.Text = "This is the first line.\nThis is the second line.\n";
  1369. _textView.CursorPosition = new Point (0, _textView.Lines - 1);
  1370. _textView.ProcessKey (new KeyEvent (Key.C | Key.CtrlMask, new KeyModifiers ())); // Copy
  1371. _textView.ProcessKey (new KeyEvent (Key.Y | Key.CtrlMask, new KeyModifiers ())); // Paste
  1372. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}{Environment.NewLine}", _textView.Text);
  1373. _textView.CursorPosition = new Point (3, 1);
  1374. _textView.ProcessKey (new KeyEvent (Key.C | Key.CtrlMask, new KeyModifiers ())); // Copy
  1375. _textView.ProcessKey (new KeyEvent (Key.Y | Key.CtrlMask, new KeyModifiers ())); // Paste
  1376. 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);
  1377. Assert.Equal (new Point (3, 2), _textView.CursorPosition);
  1378. _textView.ProcessKey (new KeyEvent (Key.Y | Key.CtrlMask, new KeyModifiers ())); // Paste
  1379. 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);
  1380. Assert.Equal (new Point (3, 3), _textView.CursorPosition);
  1381. }
  1382. [Fact]
  1383. [InitShutdown]
  1384. public void TabWidth_Setting_To_Zero_Keeps_AllowsTab ()
  1385. {
  1386. Assert.Equal (4, _textView.TabWidth);
  1387. Assert.True (_textView.AllowsTab);
  1388. Assert.True (_textView.AllowsReturn);
  1389. Assert.True (_textView.Multiline);
  1390. _textView.TabWidth = -1;
  1391. Assert.Equal (0, _textView.TabWidth);
  1392. Assert.True (_textView.AllowsTab);
  1393. Assert.True (_textView.AllowsReturn);
  1394. Assert.True (_textView.Multiline);
  1395. _textView.ProcessKey (new KeyEvent (Key.Tab, new KeyModifiers ()));
  1396. Assert.Equal ("\tTAB to jump between text fields.", _textView.Text);
  1397. _textView.ProcessKey (new KeyEvent (Key.BackTab | Key.ShiftMask, new KeyModifiers ()));
  1398. Assert.Equal ("TAB to jump between text fields.", _textView.Text);
  1399. }
  1400. [Fact]
  1401. [InitShutdown]
  1402. public void AllowsTab_Setting_To_True_Changes_TabWidth_To_Default_If_It_Is_Zero ()
  1403. {
  1404. _textView.TabWidth = 0;
  1405. Assert.Equal (0, _textView.TabWidth);
  1406. Assert.True (_textView.AllowsTab);
  1407. Assert.True (_textView.AllowsReturn);
  1408. Assert.True (_textView.Multiline);
  1409. _textView.AllowsTab = true;
  1410. Assert.True (_textView.AllowsTab);
  1411. Assert.Equal (4, _textView.TabWidth);
  1412. Assert.True (_textView.AllowsReturn);
  1413. Assert.True (_textView.Multiline);
  1414. }
  1415. [Fact]
  1416. [InitShutdown]
  1417. public void AllowsReturn_Setting_To_True_Changes_Multiline_To_True_If_It_Is_False ()
  1418. {
  1419. Assert.True (_textView.AllowsReturn);
  1420. Assert.True (_textView.Multiline);
  1421. Assert.Equal (4, _textView.TabWidth);
  1422. Assert.True (_textView.AllowsTab);
  1423. _textView.ProcessKey (new KeyEvent (Key.Enter, new KeyModifiers ()));
  1424. Assert.Equal (Environment.NewLine +
  1425. "TAB to jump between text fields.", _textView.Text);
  1426. _textView.AllowsReturn = false;
  1427. Assert.False (_textView.AllowsReturn);
  1428. Assert.False (_textView.Multiline);
  1429. Assert.Equal (0, _textView.TabWidth);
  1430. Assert.False (_textView.AllowsTab);
  1431. _textView.ProcessKey (new KeyEvent (Key.Enter, new KeyModifiers ()));
  1432. Assert.Equal (Environment.NewLine +
  1433. "TAB to jump between text fields.", _textView.Text);
  1434. }
  1435. [Fact]
  1436. [InitShutdown]
  1437. public void Multiline_Setting_Changes_AllowsReturn_AllowsTab_Height_WordWrap ()
  1438. {
  1439. Assert.True (_textView.Multiline);
  1440. Assert.True (_textView.AllowsReturn);
  1441. Assert.Equal (4, _textView.TabWidth);
  1442. Assert.True (_textView.AllowsTab);
  1443. Assert.Equal ("Dim.Absolute(30)", _textView.Width.ToString ());
  1444. Assert.Equal ("Dim.Absolute(10)", _textView.Height.ToString ());
  1445. Assert.False (_textView.WordWrap);
  1446. _textView.WordWrap = true;
  1447. Assert.True (_textView.WordWrap);
  1448. _textView.Multiline = false;
  1449. Assert.False (_textView.Multiline);
  1450. Assert.False (_textView.AllowsReturn);
  1451. Assert.Equal (0, _textView.TabWidth);
  1452. Assert.False (_textView.AllowsTab);
  1453. Assert.Equal ("Dim.Absolute(30)", _textView.Width.ToString ());
  1454. Assert.Equal ("Dim.Absolute(1)", _textView.Height.ToString ());
  1455. Assert.False (_textView.WordWrap);
  1456. _textView.WordWrap = true;
  1457. Assert.False (_textView.WordWrap);
  1458. _textView.Multiline = true;
  1459. Assert.True (_textView.Multiline);
  1460. Assert.True (_textView.AllowsReturn);
  1461. Assert.Equal (4, _textView.TabWidth);
  1462. Assert.True (_textView.AllowsTab);
  1463. Assert.Equal ("Dim.Absolute(30)", _textView.Width.ToString ());
  1464. Assert.Equal ("Dim.Absolute(10)", _textView.Height.ToString ());
  1465. Assert.False (_textView.WordWrap);
  1466. }
  1467. [Fact]
  1468. [InitShutdown]
  1469. public void Tab_Test_Follow_By_BackTab ()
  1470. {
  1471. Application.Top.Add (_textView);
  1472. Application.Iteration += () => {
  1473. var width = _textView.Bounds.Width - 1;
  1474. Assert.Equal (30, width + 1);
  1475. Assert.Equal (10, _textView.Height);
  1476. _textView.Text = "";
  1477. var col = 0;
  1478. var leftCol = 0;
  1479. var tabWidth = _textView.TabWidth;
  1480. while (col < 100) {
  1481. col++;
  1482. _textView.ProcessKey (new KeyEvent (Key.Tab, new KeyModifiers ()));
  1483. Assert.Equal (new Point (col, 0), _textView.CursorPosition);
  1484. leftCol = GetLeftCol (leftCol);
  1485. Assert.Equal (leftCol, _textView.LeftColumn);
  1486. }
  1487. while (col > 0) {
  1488. col--;
  1489. _textView.ProcessKey (new KeyEvent (Key.BackTab | Key.ShiftMask, new KeyModifiers ()));
  1490. Assert.Equal (new Point (col, 0), _textView.CursorPosition);
  1491. leftCol = GetLeftCol (leftCol);
  1492. Assert.Equal (leftCol, _textView.LeftColumn);
  1493. }
  1494. Application.Top.Remove (_textView);
  1495. Application.RequestStop ();
  1496. };
  1497. Application.Run ();
  1498. }
  1499. [Fact]
  1500. [InitShutdown]
  1501. public void BackTab_Test_Follow_By_Tab ()
  1502. {
  1503. Application.Top.Add (_textView);
  1504. Application.Iteration += () => {
  1505. var width = _textView.Bounds.Width - 1;
  1506. Assert.Equal (30, width + 1);
  1507. Assert.Equal (10, _textView.Height);
  1508. _textView.Text = "";
  1509. for (int i = 0; i < 100; i++) {
  1510. _textView.Text += "\t";
  1511. }
  1512. var col = 100;
  1513. var tabWidth = _textView.TabWidth;
  1514. var leftCol = _textView.LeftColumn;
  1515. _textView.MoveEnd ();
  1516. Assert.Equal (new Point (col, 0), _textView.CursorPosition);
  1517. leftCol = GetLeftCol (leftCol);
  1518. Assert.Equal (leftCol, _textView.LeftColumn);
  1519. while (col > 0) {
  1520. col--;
  1521. _textView.ProcessKey (new KeyEvent (Key.BackTab | Key.ShiftMask, new KeyModifiers ()));
  1522. Assert.Equal (new Point (col, 0), _textView.CursorPosition);
  1523. leftCol = GetLeftCol (leftCol);
  1524. Assert.Equal (leftCol, _textView.LeftColumn);
  1525. }
  1526. while (col < 100) {
  1527. col++;
  1528. _textView.ProcessKey (new KeyEvent (Key.Tab, new KeyModifiers ()));
  1529. Assert.Equal (new Point (col, 0), _textView.CursorPosition);
  1530. leftCol = GetLeftCol (leftCol);
  1531. Assert.Equal (leftCol, _textView.LeftColumn);
  1532. }
  1533. Application.Top.Remove (_textView);
  1534. Application.RequestStop ();
  1535. };
  1536. Application.Run ();
  1537. }
  1538. [Fact]
  1539. [InitShutdown]
  1540. public void Tab_Test_Follow_By_CursorLeft_And_Then_Follow_By_CursorRight ()
  1541. {
  1542. Application.Top.Add (_textView);
  1543. Application.Iteration += () => {
  1544. var width = _textView.Bounds.Width - 1;
  1545. Assert.Equal (30, width + 1);
  1546. Assert.Equal (10, _textView.Height);
  1547. _textView.Text = "";
  1548. var col = 0;
  1549. var leftCol = 0;
  1550. var tabWidth = _textView.TabWidth;
  1551. while (col < 100) {
  1552. col++;
  1553. _textView.ProcessKey (new KeyEvent (Key.Tab, new KeyModifiers ()));
  1554. Assert.Equal (new Point (col, 0), _textView.CursorPosition);
  1555. leftCol = GetLeftCol (leftCol);
  1556. Assert.Equal (leftCol, _textView.LeftColumn);
  1557. }
  1558. while (col > 0) {
  1559. col--;
  1560. _textView.ProcessKey (new KeyEvent (Key.CursorLeft, new KeyModifiers ()));
  1561. Assert.Equal (new Point (col, 0), _textView.CursorPosition);
  1562. leftCol = GetLeftCol (leftCol);
  1563. Assert.Equal (leftCol, _textView.LeftColumn);
  1564. }
  1565. while (col < 100) {
  1566. col++;
  1567. _textView.ProcessKey (new KeyEvent (Key.CursorRight, new KeyModifiers ()));
  1568. Assert.Equal (new Point (col, 0), _textView.CursorPosition);
  1569. leftCol = GetLeftCol (leftCol);
  1570. Assert.Equal (leftCol, _textView.LeftColumn);
  1571. }
  1572. Application.Top.Remove (_textView);
  1573. Application.RequestStop ();
  1574. };
  1575. Application.Run ();
  1576. }
  1577. [Fact]
  1578. [InitShutdown]
  1579. public void Tab_Test_Follow_By_BackTab_With_Text ()
  1580. {
  1581. Application.Top.Add (_textView);
  1582. Application.Iteration += () => {
  1583. var width = _textView.Bounds.Width - 1;
  1584. Assert.Equal (30, width + 1);
  1585. Assert.Equal (10, _textView.Height);
  1586. var col = 0;
  1587. var leftCol = 0;
  1588. Assert.Equal (new Point (col, 0), _textView.CursorPosition);
  1589. Assert.Equal (leftCol, _textView.LeftColumn);
  1590. while (col < 100) {
  1591. col++;
  1592. _textView.ProcessKey (new KeyEvent (Key.Tab, new KeyModifiers ()));
  1593. Assert.Equal (new Point (col, 0), _textView.CursorPosition);
  1594. leftCol = GetLeftCol (leftCol);
  1595. Assert.Equal (leftCol, _textView.LeftColumn);
  1596. }
  1597. while (col > 0) {
  1598. col--;
  1599. _textView.ProcessKey (new KeyEvent (Key.BackTab | Key.ShiftMask, new KeyModifiers ()));
  1600. Assert.Equal (new Point (col, 0), _textView.CursorPosition);
  1601. leftCol = GetLeftCol (leftCol);
  1602. Assert.Equal (leftCol, _textView.LeftColumn);
  1603. }
  1604. Application.Top.Remove (_textView);
  1605. Application.RequestStop ();
  1606. };
  1607. Application.Run ();
  1608. }
  1609. [Fact]
  1610. [InitShutdown]
  1611. public void Tab_Test_Follow_By_Home_And_Then_Follow_By_End_And_Then_Follow_By_BackTab_With_Text ()
  1612. {
  1613. Application.Top.Add (_textView);
  1614. Application.Iteration += () => {
  1615. var width = _textView.Bounds.Width - 1;
  1616. Assert.Equal (30, width + 1);
  1617. Assert.Equal (10, _textView.Height);
  1618. var col = 0;
  1619. var leftCol = 0;
  1620. Assert.Equal (new Point (col, 0), _textView.CursorPosition);
  1621. Assert.Equal (leftCol, _textView.LeftColumn);
  1622. Assert.Equal ("TAB to jump between text fields.", _textView.Text);
  1623. Assert.Equal (32, _textView.Text.Length);
  1624. while (col < 100) {
  1625. col++;
  1626. _textView.ProcessKey (new KeyEvent (Key.Tab, new KeyModifiers ()));
  1627. Assert.Equal (new Point (col, 0), _textView.CursorPosition);
  1628. leftCol = GetLeftCol (leftCol);
  1629. Assert.Equal (leftCol, _textView.LeftColumn);
  1630. }
  1631. _textView.ProcessKey (new KeyEvent (Key.Home, new KeyModifiers ()));
  1632. col = 0;
  1633. Assert.Equal (new Point (col, 0), _textView.CursorPosition);
  1634. leftCol = 0;
  1635. Assert.Equal (leftCol, _textView.LeftColumn);
  1636. _textView.ProcessKey (new KeyEvent (Key.End, new KeyModifiers ()));
  1637. col = _textView.Text.Length;
  1638. Assert.Equal (132, _textView.Text.Length);
  1639. Assert.Equal (new Point (col, 0), _textView.CursorPosition);
  1640. leftCol = GetLeftCol (leftCol);
  1641. Assert.Equal (leftCol, _textView.LeftColumn);
  1642. var txt = _textView.Text;
  1643. while (col - 1 > 0 && txt [col - 1] != '\t') {
  1644. col--;
  1645. }
  1646. _textView.CursorPosition = new Point (col, 0);
  1647. leftCol = GetLeftCol (leftCol);
  1648. while (col > 0) {
  1649. col--;
  1650. _textView.ProcessKey (new KeyEvent (Key.BackTab | Key.ShiftMask, new KeyModifiers ()));
  1651. Assert.Equal (new Point (col, 0), _textView.CursorPosition);
  1652. leftCol = GetLeftCol (leftCol);
  1653. Assert.Equal (leftCol, _textView.LeftColumn);
  1654. }
  1655. Assert.Equal ("TAB to jump between text fields.", _textView.Text);
  1656. Assert.Equal (32, _textView.Text.Length);
  1657. Application.Top.Remove (_textView);
  1658. Application.RequestStop ();
  1659. };
  1660. Application.Run ();
  1661. }
  1662. [Fact]
  1663. [InitShutdown]
  1664. public void Tab_Test_Follow_By_CursorLeft_And_Then_Follow_By_CursorRight_With_Text ()
  1665. {
  1666. Application.Top.Add (_textView);
  1667. Application.Iteration += () => {
  1668. var width = _textView.Bounds.Width - 1;
  1669. Assert.Equal (30, width + 1);
  1670. Assert.Equal (10, _textView.Height);
  1671. Assert.Equal ("TAB to jump between text fields.", _textView.Text);
  1672. var col = 0;
  1673. var leftCol = 0;
  1674. var tabWidth = _textView.TabWidth;
  1675. while (col < 100) {
  1676. col++;
  1677. _textView.ProcessKey (new KeyEvent (Key.Tab, new KeyModifiers ()));
  1678. Assert.Equal (new Point (col, 0), _textView.CursorPosition);
  1679. leftCol = GetLeftCol (leftCol);
  1680. Assert.Equal (leftCol, _textView.LeftColumn);
  1681. }
  1682. Assert.Equal (132, _textView.Text.Length);
  1683. while (col > 0) {
  1684. col--;
  1685. _textView.ProcessKey (new KeyEvent (Key.CursorLeft, new KeyModifiers ()));
  1686. Assert.Equal (new Point (col, 0), _textView.CursorPosition);
  1687. leftCol = GetLeftCol (leftCol);
  1688. Assert.Equal (leftCol, _textView.LeftColumn);
  1689. }
  1690. while (col < 100) {
  1691. col++;
  1692. _textView.ProcessKey (new KeyEvent (Key.CursorRight, new KeyModifiers ()));
  1693. Assert.Equal (new Point (col, 0), _textView.CursorPosition);
  1694. leftCol = GetLeftCol (leftCol);
  1695. Assert.Equal (leftCol, _textView.LeftColumn);
  1696. }
  1697. Application.Top.Remove (_textView);
  1698. Application.RequestStop ();
  1699. };
  1700. Application.Run ();
  1701. }
  1702. [Fact]
  1703. public void TextView_MultiLine_But_Without_Tabs ()
  1704. {
  1705. var view = new TextView ();
  1706. // the default for TextView
  1707. Assert.True (view.Multiline);
  1708. view.AllowsTab = false;
  1709. Assert.False (view.AllowsTab);
  1710. Assert.True (view.Multiline);
  1711. }
  1712. private int GetLeftCol (int start)
  1713. {
  1714. var lines = _textView.Text.Split (Environment.NewLine);
  1715. if (lines == null || lines.Length == 0) {
  1716. return 0;
  1717. }
  1718. if (start == _textView.LeftColumn) {
  1719. return start;
  1720. }
  1721. if (_textView.LeftColumn == _textView.CurrentColumn) {
  1722. return _textView.CurrentColumn;
  1723. }
  1724. var cCol = _textView.CurrentColumn;
  1725. var line = lines [_textView.CurrentRow];
  1726. var lCount = cCol > line.Length - 1 ? line.Length - 1 : cCol;
  1727. var width = _textView.Frame.Width;
  1728. var tabWidth = _textView.TabWidth;
  1729. var sumLength = 0;
  1730. var col = 0;
  1731. for (int i = lCount; i >= 0; i--) {
  1732. var r = line [i];
  1733. sumLength += Rune.ColumnWidth (r);
  1734. if (r == '\t') {
  1735. sumLength += tabWidth + 1;
  1736. }
  1737. if (sumLength > width) {
  1738. if (col + width == cCol) {
  1739. col++;
  1740. }
  1741. break;
  1742. } else if ((cCol < line.Length && col > 0 && start < cCol && col == start) || (cCol - col == width - 1)) {
  1743. break;
  1744. }
  1745. col = i;
  1746. }
  1747. return col;
  1748. }
  1749. [Fact]
  1750. public void LoadFile_Throws_If_File_Is_Null ()
  1751. {
  1752. var tv = new TextView ();
  1753. Assert.Throws<ArgumentNullException> (() => tv.LoadFile (null));
  1754. }
  1755. [Fact]
  1756. public void LoadFile_Throws_If_File_Is_Empty ()
  1757. {
  1758. var tv = new TextView ();
  1759. Assert.Throws<ArgumentException> (() => tv.LoadFile (""));
  1760. }
  1761. [Fact]
  1762. public void LoadFile_Throws_If_File_Not_Exist ()
  1763. {
  1764. var tv = new TextView ();
  1765. Assert.Throws<System.IO.FileNotFoundException> (() => tv.LoadFile ("blabla"));
  1766. }
  1767. [Fact]
  1768. public void LoadStream_Throws_If_Stream_Is_Null ()
  1769. {
  1770. var tv = new TextView ();
  1771. Assert.Throws<ArgumentNullException> (() => tv.LoadStream (null));
  1772. }
  1773. [Fact]
  1774. public void LoadStream_Stream_Is_Empty ()
  1775. {
  1776. var tv = new TextView ();
  1777. tv.LoadStream (new System.IO.MemoryStream ());
  1778. Assert.Equal ("", tv.Text);
  1779. }
  1780. [Fact]
  1781. public void LoadStream_CRLF ()
  1782. {
  1783. var text = "This is the first line.\r\nThis is the second line.\r\n";
  1784. var tv = new TextView ();
  1785. tv.LoadStream (new System.IO.MemoryStream (System.Text.Encoding.ASCII.GetBytes (text)));
  1786. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}", tv.Text);
  1787. }
  1788. [Fact]
  1789. public void LoadStream_LF ()
  1790. {
  1791. var text = "This is the first line.\nThis is the second line.\n";
  1792. var tv = new TextView ();
  1793. tv.LoadStream (new System.IO.MemoryStream (System.Text.Encoding.ASCII.GetBytes (text)));
  1794. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}", tv.Text);
  1795. }
  1796. [Fact]
  1797. public void StringToRunes_Slipts_CRLF ()
  1798. {
  1799. var text = "This is the first line.\r\nThis is the second line.\r\n";
  1800. var tv = new TextView ();
  1801. tv.Text = text;
  1802. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}", tv.Text);
  1803. }
  1804. [Fact]
  1805. public void StringToRunes_Slipts_LF ()
  1806. {
  1807. var text = "This is the first line.\nThis is the second line.\n";
  1808. var tv = new TextView ();
  1809. tv.Text = text;
  1810. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}", tv.Text);
  1811. }
  1812. [Fact]
  1813. public void CloseFile_Throws_If_FilePath_Is_Null ()
  1814. {
  1815. var tv = new TextView ();
  1816. Assert.Throws<ArgumentNullException> (() => tv.CloseFile ());
  1817. }
  1818. [Fact]
  1819. public void WordWrap_Gets_Sets ()
  1820. {
  1821. var tv = new TextView () { WordWrap = true };
  1822. Assert.True (tv.WordWrap);
  1823. tv.WordWrap = false;
  1824. Assert.False (tv.WordWrap);
  1825. }
  1826. [Fact]
  1827. public void WordWrap_True_Text_Always_Returns_Unwrapped ()
  1828. {
  1829. var text = "This is the first line.\nThis is the second line.\n";
  1830. var tv = new TextView () { Width = 10 };
  1831. tv.Text = text;
  1832. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}", tv.Text);
  1833. tv.WordWrap = true;
  1834. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}", tv.Text);
  1835. }
  1836. [Fact]
  1837. [InitShutdown]
  1838. public void WordWrap_WrapModel_Output ()
  1839. {
  1840. // 0123456789
  1841. var text = "This is the first line.\nThis is the second line.\n";
  1842. var tv = new TextView () { Width = 10, Height = 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. Application.Top.Add (tv);
  1847. tv.Redraw (tv.Bounds);
  1848. string expected = @"
  1849. This is
  1850. the
  1851. first
  1852. line.
  1853. This is
  1854. the
  1855. second
  1856. line.
  1857. ";
  1858. GraphViewTests.AssertDriverContentsAre (expected, output);
  1859. }
  1860. [Fact]
  1861. public void Internal_Tests ()
  1862. {
  1863. var txt = "This is a text.";
  1864. var txtRunes = TextModel.ToRunes (txt);
  1865. Assert.Equal (txt.Length, txtRunes.Count);
  1866. Assert.Equal ('T', txtRunes [0]);
  1867. Assert.Equal ('h', txtRunes [1]);
  1868. Assert.Equal ('i', txtRunes [2]);
  1869. Assert.Equal ('s', txtRunes [3]);
  1870. Assert.Equal (' ', txtRunes [4]);
  1871. Assert.Equal ('i', txtRunes [5]);
  1872. Assert.Equal ('s', txtRunes [6]);
  1873. Assert.Equal (' ', txtRunes [7]);
  1874. Assert.Equal ('a', txtRunes [8]);
  1875. Assert.Equal (' ', txtRunes [9]);
  1876. Assert.Equal ('t', txtRunes [10]);
  1877. Assert.Equal ('e', txtRunes [11]);
  1878. Assert.Equal ('x', txtRunes [12]);
  1879. Assert.Equal ('t', txtRunes [13]);
  1880. Assert.Equal ('.', txtRunes [^1]);
  1881. int col = 0;
  1882. Assert.True (TextModel.SetCol (ref col, 80, 79));
  1883. Assert.False (TextModel.SetCol (ref col, 80, 80));
  1884. Assert.Equal (79, col);
  1885. var start = 0;
  1886. var x = 8;
  1887. Assert.Equal (8, TextModel.GetColFromX (txtRunes, start, x));
  1888. Assert.Equal ('a', txtRunes [start + x]);
  1889. start = 1;
  1890. x = 7;
  1891. Assert.Equal (7, TextModel.GetColFromX (txtRunes, start, x));
  1892. Assert.Equal ('a', txtRunes [start + x]);
  1893. Assert.Equal ((15, 15), TextModel.DisplaySize (txtRunes));
  1894. Assert.Equal ((6, 6), TextModel.DisplaySize (txtRunes, 1, 7));
  1895. Assert.Equal (0, TextModel.CalculateLeftColumn (txtRunes, 0, 7, 8));
  1896. Assert.Equal (1, TextModel.CalculateLeftColumn (txtRunes, 0, 8, 8));
  1897. Assert.Equal (2, TextModel.CalculateLeftColumn (txtRunes, 0, 9, 8));
  1898. var tm = new TextModel ();
  1899. tm.AddLine (0, TextModel.ToRunes ("This is first line."));
  1900. tm.AddLine (1, TextModel.ToRunes ("This is last line."));
  1901. Assert.Equal ((new Point (2, 0), true), tm.FindNextText ("is", out bool gaveFullTurn));
  1902. Assert.False (gaveFullTurn);
  1903. Assert.Equal ((new Point (5, 0), true), tm.FindNextText ("is", out gaveFullTurn));
  1904. Assert.False (gaveFullTurn);
  1905. Assert.Equal ((new Point (2, 1), true), tm.FindNextText ("is", out gaveFullTurn));
  1906. Assert.False (gaveFullTurn);
  1907. Assert.Equal ((new Point (5, 1), true), tm.FindNextText ("is", out gaveFullTurn));
  1908. Assert.False (gaveFullTurn);
  1909. Assert.Equal ((new Point (2, 0), true), tm.FindNextText ("is", out gaveFullTurn));
  1910. Assert.True (gaveFullTurn);
  1911. tm.ResetContinuousFind (new Point (0, 0));
  1912. Assert.Equal ((new Point (5, 1), true), tm.FindPreviousText ("is", out gaveFullTurn));
  1913. Assert.False (gaveFullTurn);
  1914. Assert.Equal ((new Point (2, 1), true), tm.FindPreviousText ("is", out gaveFullTurn));
  1915. Assert.False (gaveFullTurn);
  1916. Assert.Equal ((new Point (5, 0), true), tm.FindPreviousText ("is", out gaveFullTurn));
  1917. Assert.False (gaveFullTurn);
  1918. Assert.Equal ((new Point (2, 0), true), tm.FindPreviousText ("is", out gaveFullTurn));
  1919. Assert.False (gaveFullTurn);
  1920. Assert.Equal ((new Point (5, 1), true), tm.FindPreviousText ("is", out gaveFullTurn));
  1921. Assert.True (gaveFullTurn);
  1922. Assert.Equal ((new Point (9, 1), true), tm.ReplaceAllText ("is", false, false, "really"));
  1923. Assert.Equal (TextModel.ToRunes ("Threally really first line."), tm.GetLine (0));
  1924. Assert.Equal (TextModel.ToRunes ("Threally really last line."), tm.GetLine (1));
  1925. tm = new TextModel ();
  1926. tm.AddLine (0, TextModel.ToRunes ("This is first line."));
  1927. tm.AddLine (1, TextModel.ToRunes ("This is last line."));
  1928. Assert.Equal ((new Point (5, 1), true), tm.ReplaceAllText ("is", false, true, "really"));
  1929. Assert.Equal (TextModel.ToRunes ("This really first line."), tm.GetLine (0));
  1930. Assert.Equal (TextModel.ToRunes ("This really last line."), tm.GetLine (1));
  1931. }
  1932. [Fact]
  1933. [InitShutdown]
  1934. public void BottomOffset_Sets_To_Zero_Adjust_TopRow ()
  1935. {
  1936. string text = "";
  1937. for (int i = 0; i < 12; i++) {
  1938. text += $"This is the line {i}\n";
  1939. }
  1940. var tv = new TextView () { Width = 10, Height = 10, BottomOffset = 1 };
  1941. tv.Text = text;
  1942. tv.ProcessKey (new KeyEvent (Key.CtrlMask | Key.End, new KeyModifiers ()));
  1943. Assert.Equal (4, tv.TopRow);
  1944. Assert.Equal (1, tv.BottomOffset);
  1945. tv.BottomOffset = 0;
  1946. Assert.Equal (3, tv.TopRow);
  1947. Assert.Equal (0, tv.BottomOffset);
  1948. tv.BottomOffset = 2;
  1949. Assert.Equal (5, tv.TopRow);
  1950. Assert.Equal (2, tv.BottomOffset);
  1951. tv.BottomOffset = 0;
  1952. Assert.Equal (3, tv.TopRow);
  1953. Assert.Equal (0, tv.BottomOffset);
  1954. }
  1955. [Fact]
  1956. [InitShutdown]
  1957. public void RightOffset_Sets_To_Zero_Adjust_leftColumn ()
  1958. {
  1959. string text = "";
  1960. for (int i = 0; i < 12; i++) {
  1961. text += $"{i.ToString () [^1]}";
  1962. }
  1963. var tv = new TextView () { Width = 10, Height = 10, RightOffset = 1 };
  1964. tv.Text = text;
  1965. tv.ProcessKey (new KeyEvent (Key.End, new KeyModifiers ()));
  1966. Assert.Equal (4, tv.LeftColumn);
  1967. Assert.Equal (1, tv.RightOffset);
  1968. tv.RightOffset = 0;
  1969. Assert.Equal (3, tv.LeftColumn);
  1970. Assert.Equal (0, tv.RightOffset);
  1971. tv.RightOffset = 2;
  1972. Assert.Equal (5, tv.LeftColumn);
  1973. Assert.Equal (2, tv.RightOffset);
  1974. tv.RightOffset = 0;
  1975. Assert.Equal (3, tv.LeftColumn);
  1976. Assert.Equal (0, tv.RightOffset);
  1977. }
  1978. [Fact]
  1979. [InitShutdown]
  1980. public void TextView_SpaceHandling ()
  1981. {
  1982. var tv = new TextView () {
  1983. Width = 10,
  1984. Text = " "
  1985. };
  1986. MouseEvent ev = new MouseEvent () {
  1987. X = 0,
  1988. Y = 0,
  1989. Flags = MouseFlags.Button1DoubleClicked,
  1990. };
  1991. tv.MouseEvent (ev);
  1992. Assert.Equal (1, tv.SelectedLength);
  1993. ev = new MouseEvent () {
  1994. X = 1,
  1995. Y = 0,
  1996. Flags = MouseFlags.Button1DoubleClicked,
  1997. };
  1998. tv.MouseEvent (ev);
  1999. Assert.Equal (1, tv.SelectedLength);
  2000. }
  2001. [Fact]
  2002. [InitShutdown]
  2003. public void CanFocus_False_Wont_Focus_With_Mouse ()
  2004. {
  2005. var top = Application.Top;
  2006. var tv = new TextView () {
  2007. Width = Dim.Fill (),
  2008. CanFocus = false,
  2009. ReadOnly = true,
  2010. Text = "some text"
  2011. };
  2012. var fv = new FrameView ("I shouldn't get focus") {
  2013. Width = Dim.Fill (),
  2014. Height = Dim.Fill (),
  2015. CanFocus = false,
  2016. };
  2017. fv.Add (tv);
  2018. top.Add (fv);
  2019. Application.Begin (top);
  2020. Assert.False (tv.CanFocus);
  2021. Assert.False (tv.HasFocus);
  2022. Assert.False (fv.CanFocus);
  2023. Assert.False (fv.HasFocus);
  2024. tv.MouseEvent (new MouseEvent () {
  2025. X = 1,
  2026. Y = 0,
  2027. Flags = MouseFlags.Button1DoubleClicked
  2028. });
  2029. Assert.Empty (tv.SelectedText);
  2030. Assert.False (tv.CanFocus);
  2031. Assert.False (tv.HasFocus);
  2032. Assert.False (fv.CanFocus);
  2033. Assert.False (fv.HasFocus);
  2034. Assert.Throws<InvalidOperationException> (() => tv.CanFocus = true);
  2035. fv.CanFocus = true;
  2036. tv.CanFocus = true;
  2037. tv.MouseEvent (new MouseEvent () {
  2038. X = 1,
  2039. Y = 0,
  2040. Flags = MouseFlags.Button1DoubleClicked
  2041. });
  2042. Assert.Equal ("some ", tv.SelectedText);
  2043. Assert.True (tv.CanFocus);
  2044. Assert.True (tv.HasFocus);
  2045. Assert.True (fv.CanFocus);
  2046. Assert.True (fv.HasFocus);
  2047. fv.CanFocus = false;
  2048. tv.MouseEvent (new MouseEvent () {
  2049. X = 1,
  2050. Y = 0,
  2051. Flags = MouseFlags.Button1DoubleClicked
  2052. });
  2053. Assert.Equal ("some ", tv.SelectedText); // Setting CanFocus to false don't change the SelectedText
  2054. Assert.False (tv.CanFocus);
  2055. Assert.False (tv.HasFocus);
  2056. Assert.False (fv.CanFocus);
  2057. Assert.False (fv.HasFocus);
  2058. }
  2059. [Fact]
  2060. [InitShutdown]
  2061. public void DesiredCursorVisibility_Vertical_Navigation ()
  2062. {
  2063. string text = "";
  2064. for (int i = 0; i < 12; i++) {
  2065. text += $"This is the line {i}\n";
  2066. }
  2067. var tv = new TextView () { Width = 10, Height = 10 };
  2068. tv.Text = text;
  2069. Assert.Equal (0, tv.TopRow);
  2070. tv.PositionCursor ();
  2071. Assert.Equal (CursorVisibility.Default, tv.DesiredCursorVisibility);
  2072. for (int i = 0; i < 12; i++) {
  2073. tv.MouseEvent (new MouseEvent () {
  2074. Flags = MouseFlags.WheeledDown
  2075. });
  2076. tv.PositionCursor ();
  2077. Assert.Equal (i + 1, tv.TopRow);
  2078. Assert.Equal (CursorVisibility.Invisible, tv.DesiredCursorVisibility);
  2079. }
  2080. for (int i = 12; i > 0; i--) {
  2081. tv.MouseEvent (new MouseEvent () {
  2082. Flags = MouseFlags.WheeledUp
  2083. });
  2084. tv.PositionCursor ();
  2085. Assert.Equal (i - 1, tv.TopRow);
  2086. if (i - 1 == 0) {
  2087. Assert.Equal (CursorVisibility.Default, tv.DesiredCursorVisibility);
  2088. } else {
  2089. Assert.Equal (CursorVisibility.Invisible, tv.DesiredCursorVisibility);
  2090. }
  2091. }
  2092. }
  2093. [Fact]
  2094. [InitShutdown]
  2095. public void DesiredCursorVisibility_Horizontal_Navigation ()
  2096. {
  2097. string text = "";
  2098. for (int i = 0; i < 12; i++) {
  2099. text += $"{i.ToString () [^1]}";
  2100. }
  2101. var tv = new TextView () { Width = 10, Height = 10 };
  2102. tv.Text = text;
  2103. Assert.Equal (0, tv.LeftColumn);
  2104. tv.PositionCursor ();
  2105. Assert.Equal (CursorVisibility.Default, tv.DesiredCursorVisibility);
  2106. for (int i = 0; i < 12; i++) {
  2107. tv.MouseEvent (new MouseEvent () {
  2108. Flags = MouseFlags.WheeledRight
  2109. });
  2110. tv.PositionCursor ();
  2111. Assert.Equal (Math.Min (i + 1, 11), tv.LeftColumn);
  2112. Assert.Equal (CursorVisibility.Invisible, tv.DesiredCursorVisibility);
  2113. }
  2114. for (int i = 11; i > 0; i--) {
  2115. tv.MouseEvent (new MouseEvent () {
  2116. Flags = MouseFlags.WheeledLeft
  2117. });
  2118. tv.PositionCursor ();
  2119. Assert.Equal (i - 1, tv.LeftColumn);
  2120. if (i - 1 == 0) {
  2121. Assert.Equal (CursorVisibility.Default, tv.DesiredCursorVisibility);
  2122. } else {
  2123. Assert.Equal (CursorVisibility.Invisible, tv.DesiredCursorVisibility);
  2124. }
  2125. }
  2126. }
  2127. [Fact]
  2128. public void LeftColumn_Add_One_If_Text_Length_Is_Equal_To_Width ()
  2129. {
  2130. var tv = new TextView () {
  2131. Width = 10,
  2132. Text = "1234567890"
  2133. };
  2134. Assert.Equal (Point.Empty, tv.CursorPosition);
  2135. Assert.Equal (0, tv.LeftColumn);
  2136. tv.CursorPosition = new Point (9, 0);
  2137. Assert.Equal (new Point (9, 0), tv.CursorPosition);
  2138. Assert.Equal (0, tv.LeftColumn);
  2139. Assert.True (tv.ProcessKey (new KeyEvent (Key.CursorRight, new KeyModifiers ())));
  2140. tv.CursorPosition = new Point (10, 0);
  2141. Assert.Equal (new Point (10, 0), tv.CursorPosition);
  2142. Assert.Equal (1, tv.LeftColumn);
  2143. }
  2144. [Fact]
  2145. [AutoInitShutdown]
  2146. public void KeyBindings_Command ()
  2147. {
  2148. var text = "This is the first line.\nThis is the second line.\nThis is the third line.";
  2149. var tv = new TextView () {
  2150. Width = 10,
  2151. Height = 2,
  2152. Text = text
  2153. };
  2154. var top = Application.Top;
  2155. top.Add (tv);
  2156. Application.Begin (top);
  2157. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  2158. Assert.Equal (3, tv.Lines);
  2159. Assert.Equal (Point.Empty, tv.CursorPosition);
  2160. Assert.False (tv.ReadOnly);
  2161. Assert.True (tv.CanFocus);
  2162. tv.CanFocus = false;
  2163. Assert.True (tv.ProcessKey (new KeyEvent (Key.CursorLeft, new KeyModifiers ())));
  2164. tv.CanFocus = true;
  2165. Assert.False (tv.ProcessKey (new KeyEvent (Key.CursorLeft, new KeyModifiers ())));
  2166. Assert.True (tv.ProcessKey (new KeyEvent (Key.CursorRight, new KeyModifiers ())));
  2167. Assert.Equal (new Point (1, 0), tv.CursorPosition);
  2168. Assert.True (tv.ProcessKey (new KeyEvent (Key.End | Key.CtrlMask, new KeyModifiers ())));
  2169. Assert.Equal (2, tv.CurrentRow);
  2170. Assert.Equal (23, tv.CurrentColumn);
  2171. Assert.Equal (tv.CurrentColumn, tv.GetCurrentLine ().Count);
  2172. Assert.Equal (new Point (23, 2), tv.CursorPosition);
  2173. Assert.False (tv.ProcessKey (new KeyEvent (Key.CursorRight, new KeyModifiers ())));
  2174. Assert.NotNull (tv.Autocomplete);
  2175. Assert.Empty (tv.Autocomplete.AllSuggestions);
  2176. Assert.True (tv.ProcessKey (new KeyEvent (Key.F, new KeyModifiers ())));
  2177. tv.Redraw (tv.Bounds);
  2178. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.F", tv.Text);
  2179. Assert.Equal (new Point (24, 2), tv.CursorPosition);
  2180. Assert.Empty (tv.Autocomplete.Suggestions);
  2181. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  2182. tv.Redraw (tv.Bounds);
  2183. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  2184. Assert.Equal (new Point (23, 2), tv.CursorPosition);
  2185. Assert.Empty (tv.Autocomplete.Suggestions);
  2186. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  2187. tv.Redraw (tv.Bounds);
  2188. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.F", tv.Text);
  2189. Assert.Equal (new Point (24, 2), tv.CursorPosition);
  2190. Assert.Empty (tv.Autocomplete.Suggestions);
  2191. Assert.True (tv.ProcessKey (new KeyEvent (Key.Backspace, new KeyModifiers ())));
  2192. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  2193. Assert.Equal (new Point (23, 2), tv.CursorPosition);
  2194. tv.Autocomplete.AllSuggestions = Regex.Matches (tv.Text.ToString (), "\\w+")
  2195. .Select (s => s.Value)
  2196. .Distinct ().ToList ();
  2197. Assert.Equal (7, tv.Autocomplete.AllSuggestions.Count);
  2198. Assert.Equal ("This", tv.Autocomplete.AllSuggestions [0]);
  2199. Assert.Equal ("is", tv.Autocomplete.AllSuggestions [1]);
  2200. Assert.Equal ("the", tv.Autocomplete.AllSuggestions [2]);
  2201. Assert.Equal ("first", tv.Autocomplete.AllSuggestions [3]);
  2202. Assert.Equal ("line", tv.Autocomplete.AllSuggestions [4]);
  2203. Assert.Equal ("second", tv.Autocomplete.AllSuggestions [5]);
  2204. Assert.Equal ("third", tv.Autocomplete.AllSuggestions [^1]);
  2205. Assert.True (tv.ProcessKey (new KeyEvent (Key.F, new KeyModifiers ())));
  2206. tv.Redraw (tv.Bounds);
  2207. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.F", tv.Text);
  2208. Assert.Equal (new Point (24, 2), tv.CursorPosition);
  2209. Assert.Single (tv.Autocomplete.Suggestions);
  2210. Assert.Equal ("first", tv.Autocomplete.Suggestions [0]);
  2211. Assert.True (tv.ProcessKey (new KeyEvent (Key.Enter, new KeyModifiers ())));
  2212. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first", tv.Text);
  2213. Assert.Equal (new Point (28, 2), tv.CursorPosition);
  2214. Assert.Single (tv.Autocomplete.Suggestions);
  2215. Assert.Equal ("first", tv.Autocomplete.Suggestions [0]);
  2216. tv.Autocomplete.AllSuggestions = new List<string> ();
  2217. tv.Autocomplete.ClearSuggestions ();
  2218. Assert.Empty (tv.Autocomplete.AllSuggestions);
  2219. Assert.Empty (tv.Autocomplete.Suggestions);
  2220. Assert.True (tv.ProcessKey (new KeyEvent (Key.PageUp, new KeyModifiers ())));
  2221. Assert.Equal (24, tv.GetCurrentLine ().Count);
  2222. Assert.Equal (new Point (24, 1), tv.CursorPosition);
  2223. Assert.True (tv.ProcessKey (new KeyEvent (((int)'V' + Key.AltMask), new KeyModifiers ())));
  2224. Assert.Equal (23, tv.GetCurrentLine ().Count);
  2225. Assert.Equal (new Point (23, 0), tv.CursorPosition);
  2226. Assert.True (tv.ProcessKey (new KeyEvent (Key.PageDown, new KeyModifiers ())));
  2227. Assert.Equal (24, tv.GetCurrentLine ().Count);
  2228. Assert.Equal (new Point (23, 1), tv.CursorPosition); // gets the previous length
  2229. Assert.True (tv.ProcessKey (new KeyEvent (Key.V | Key.CtrlMask, new KeyModifiers ())));
  2230. Assert.Equal (28, tv.GetCurrentLine ().Count);
  2231. Assert.Equal (new Point (23, 2), tv.CursorPosition); // gets the previous length
  2232. Assert.Equal (0, tv.SelectedLength);
  2233. Assert.Equal ("", tv.SelectedText);
  2234. Assert.True (tv.ProcessKey (new KeyEvent (Key.PageUp | Key.ShiftMask, new KeyModifiers ())));
  2235. Assert.Equal (24, tv.GetCurrentLine ().Count);
  2236. Assert.Equal (new Point (23, 1), tv.CursorPosition); // gets the previous length
  2237. Assert.Equal (24 + Environment.NewLine.Length, tv.SelectedLength);
  2238. Assert.Equal ($".{Environment.NewLine}This is the third line.", tv.SelectedText);
  2239. Assert.True (tv.ProcessKey (new KeyEvent (Key.PageDown | Key.ShiftMask, new KeyModifiers ())));
  2240. Assert.Equal (28, tv.GetCurrentLine ().Count);
  2241. Assert.Equal (new Point (23, 2), tv.CursorPosition); // gets the previous length
  2242. Assert.Equal (0, tv.SelectedLength);
  2243. Assert.Equal ("", tv.SelectedText);
  2244. Assert.True (tv.ProcessKey (new KeyEvent (Key.Home | Key.CtrlMask, new KeyModifiers ())));
  2245. Assert.Equal (Point.Empty, tv.CursorPosition);
  2246. Assert.True (tv.ProcessKey (new KeyEvent (Key.N | Key.CtrlMask, new KeyModifiers ())));
  2247. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  2248. Assert.Equal (0, tv.SelectedLength);
  2249. Assert.Equal ("", tv.SelectedText);
  2250. Assert.True (tv.ProcessKey (new KeyEvent (Key.P | Key.CtrlMask, new KeyModifiers ())));
  2251. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  2252. Assert.Equal (0, tv.SelectedLength);
  2253. Assert.Equal ("", tv.SelectedText);
  2254. Assert.True (tv.ProcessKey (new KeyEvent (Key.CursorDown, new KeyModifiers ())));
  2255. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  2256. Assert.Equal (0, tv.SelectedLength);
  2257. Assert.Equal ("", tv.SelectedText);
  2258. Assert.True (tv.ProcessKey (new KeyEvent (Key.CursorUp, new KeyModifiers ())));
  2259. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  2260. Assert.Equal (0, tv.SelectedLength);
  2261. Assert.Equal ("", tv.SelectedText);
  2262. Assert.True (tv.ProcessKey (new KeyEvent (Key.CursorDown | Key.ShiftMask, new KeyModifiers ())));
  2263. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  2264. Assert.Equal (23 + Environment.NewLine.Length, tv.SelectedLength);
  2265. Assert.Equal ($"This is the first line.{Environment.NewLine}", tv.SelectedText);
  2266. Assert.True (tv.ProcessKey (new KeyEvent (Key.CursorUp | Key.ShiftMask, new KeyModifiers ())));
  2267. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  2268. Assert.Equal (0, tv.SelectedLength);
  2269. Assert.Equal ("", tv.SelectedText);
  2270. Assert.True (tv.ProcessKey (new KeyEvent (Key.F | Key.CtrlMask, new KeyModifiers ())));
  2271. Assert.Equal (new Point (1, 0), tv.CursorPosition);
  2272. Assert.Equal (0, tv.SelectedLength);
  2273. Assert.Equal ("", tv.SelectedText);
  2274. Assert.True (tv.ProcessKey (new KeyEvent (Key.B | Key.CtrlMask, new KeyModifiers ())));
  2275. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  2276. Assert.Equal (0, tv.SelectedLength);
  2277. Assert.Equal ("", tv.SelectedText);
  2278. Assert.True (tv.ProcessKey (new KeyEvent (Key.CursorRight, new KeyModifiers ())));
  2279. Assert.Equal (new Point (1, 0), tv.CursorPosition);
  2280. Assert.Equal (0, tv.SelectedLength);
  2281. Assert.Equal ("", tv.SelectedText);
  2282. Assert.True (tv.ProcessKey (new KeyEvent (Key.CursorLeft, new KeyModifiers ())));
  2283. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  2284. Assert.Equal (0, tv.SelectedLength);
  2285. Assert.Equal ("", tv.SelectedText);
  2286. Assert.False (tv.Selecting);
  2287. Assert.True (tv.ProcessKey (new KeyEvent (Key.CursorRight | Key.ShiftMask, new KeyModifiers ())));
  2288. Assert.Equal (new Point (1, 0), tv.CursorPosition);
  2289. Assert.Equal (1, tv.SelectedLength);
  2290. Assert.Equal ("T", tv.SelectedText);
  2291. Assert.True (tv.Selecting);
  2292. Assert.True (tv.ProcessKey (new KeyEvent (Key.CursorLeft | Key.ShiftMask, new KeyModifiers ())));
  2293. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  2294. Assert.Equal (0, tv.SelectedLength);
  2295. Assert.Equal ("", tv.SelectedText);
  2296. Assert.True (tv.Selecting);
  2297. Assert.True (tv.ProcessKey (new KeyEvent (Key.DeleteChar, new KeyModifiers ())));
  2298. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first", tv.Text);
  2299. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  2300. Assert.Equal (0, tv.SelectedLength);
  2301. Assert.Equal ("", tv.SelectedText);
  2302. Assert.False (tv.Selecting);
  2303. Assert.True (tv.ProcessKey (new KeyEvent (Key.DeleteChar, new KeyModifiers ())));
  2304. Assert.Equal ($"his is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first", tv.Text);
  2305. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  2306. Assert.Equal (0, tv.SelectedLength);
  2307. Assert.Equal ("", tv.SelectedText);
  2308. Assert.False (tv.Selecting);
  2309. Assert.True (tv.ProcessKey (new KeyEvent (Key.D | Key.CtrlMask, new KeyModifiers ())));
  2310. Assert.Equal ($"is 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 (0, 0), tv.CursorPosition);
  2312. Assert.True (tv.ProcessKey (new KeyEvent (Key.End, new KeyModifiers ())));
  2313. Assert.Equal ($"is is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first", tv.Text);
  2314. Assert.Equal (new Point (21, 0), tv.CursorPosition);
  2315. Assert.True (tv.ProcessKey (new KeyEvent (Key.Delete, new KeyModifiers ())));
  2316. Assert.Equal ($"is is the first line{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first", tv.Text);
  2317. Assert.Equal (new Point (20, 0), tv.CursorPosition);
  2318. Assert.True (tv.ProcessKey (new KeyEvent (Key.Backspace, new KeyModifiers ())));
  2319. Assert.Equal ($"is is the first lin{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first", tv.Text);
  2320. Assert.Equal (new Point (19, 0), tv.CursorPosition);
  2321. Assert.True (tv.ProcessKey (new KeyEvent (Key.Home, new KeyModifiers ())));
  2322. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  2323. Assert.Equal (0, tv.SelectedLength);
  2324. Assert.Equal ("", tv.SelectedText);
  2325. Assert.False (tv.Selecting);
  2326. Assert.True (tv.ProcessKey (new KeyEvent (Key.End | Key.ShiftMask, new KeyModifiers ())));
  2327. Assert.Equal (new Point (19, 0), tv.CursorPosition);
  2328. Assert.Equal (19, tv.SelectedLength);
  2329. Assert.Equal ("is is the first lin", tv.SelectedText);
  2330. Assert.True (tv.Selecting);
  2331. Assert.True (tv.ProcessKey (new KeyEvent (Key.Home | Key.ShiftMask, new KeyModifiers ())));
  2332. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  2333. Assert.Equal (0, tv.SelectedLength);
  2334. Assert.Equal ("", tv.SelectedText);
  2335. Assert.True (tv.Selecting);
  2336. Assert.True (tv.ProcessKey (new KeyEvent (Key.E | Key.CtrlMask, new KeyModifiers ())));
  2337. Assert.Equal (new Point (19, 0), tv.CursorPosition);
  2338. Assert.Equal (0, tv.SelectedLength);
  2339. Assert.Equal ("", tv.SelectedText);
  2340. Assert.False (tv.Selecting);
  2341. Assert.True (tv.ProcessKey (new KeyEvent (Key.A | Key.CtrlMask, new KeyModifiers ())));
  2342. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  2343. Assert.Equal (0, tv.SelectedLength);
  2344. Assert.Equal ("", tv.SelectedText);
  2345. Assert.False (tv.Selecting);
  2346. Assert.True (tv.ProcessKey (new KeyEvent (Key.K | Key.CtrlMask, new KeyModifiers ())));
  2347. Assert.Equal ($"{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first", tv.Text);
  2348. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  2349. Assert.Equal (0, tv.SelectedLength);
  2350. Assert.Equal ("", tv.SelectedText);
  2351. Assert.False (tv.Selecting);
  2352. Assert.Equal ("is is the first lin", Clipboard.Contents);
  2353. Assert.True (tv.ProcessKey (new KeyEvent (Key.Y | Key.CtrlMask, new KeyModifiers ())));
  2354. Assert.Equal ($"is is the first lin{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first", tv.Text);
  2355. Assert.Equal (new Point (19, 0), tv.CursorPosition);
  2356. Assert.Equal (0, tv.SelectedLength);
  2357. Assert.Equal ("", tv.SelectedText);
  2358. Assert.False (tv.Selecting);
  2359. Assert.Equal ("is is the first lin", Clipboard.Contents);
  2360. tv.CursorPosition = Point.Empty;
  2361. Assert.True (tv.ProcessKey (new KeyEvent (Key.DeleteChar | Key.CtrlMask | Key.ShiftMask, new KeyModifiers ())));
  2362. Assert.Equal ($"{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first", tv.Text);
  2363. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  2364. Assert.Equal (0, tv.SelectedLength);
  2365. Assert.Equal ("", tv.SelectedText);
  2366. Assert.False (tv.Selecting);
  2367. Assert.Equal ("is is the first lin", Clipboard.Contents);
  2368. Assert.True (tv.ProcessKey (new KeyEvent (Key.Y | Key.CtrlMask, new KeyModifiers ())));
  2369. Assert.Equal ($"is is the first lin{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first", tv.Text);
  2370. Assert.Equal (new Point (19, 0), tv.CursorPosition);
  2371. Assert.Equal (0, tv.SelectedLength);
  2372. Assert.Equal ("", tv.SelectedText);
  2373. Assert.False (tv.Selecting);
  2374. Assert.Equal ("is is the first lin", Clipboard.Contents);
  2375. Assert.True (tv.ProcessKey (new KeyEvent (Key.K | Key.AltMask, new KeyModifiers ())));
  2376. Assert.Equal ($"{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first", tv.Text);
  2377. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  2378. Assert.Equal (0, tv.SelectedLength);
  2379. Assert.Equal ("", tv.SelectedText);
  2380. Assert.False (tv.Selecting);
  2381. tv.ReadOnly = true;
  2382. Assert.True (tv.ProcessKey (new KeyEvent (Key.Y | Key.CtrlMask, new KeyModifiers ())));
  2383. Assert.Equal ($"{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first", tv.Text);
  2384. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  2385. Assert.Equal (0, tv.SelectedLength);
  2386. Assert.Equal ("", tv.SelectedText);
  2387. Assert.False (tv.Selecting);
  2388. tv.ReadOnly = false;
  2389. Assert.True (tv.ProcessKey (new KeyEvent (Key.Y | Key.CtrlMask, new KeyModifiers ())));
  2390. Assert.Equal ($"is is the first lin{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first", tv.Text);
  2391. Assert.Equal (new Point (19, 0), tv.CursorPosition);
  2392. Assert.Equal (0, tv.SelectedLength);
  2393. Assert.Equal ("", tv.SelectedText);
  2394. Assert.False (tv.Selecting);
  2395. Assert.Equal (0, tv.SelectionStartColumn);
  2396. Assert.Equal (0, tv.SelectionStartRow);
  2397. Assert.True (tv.ProcessKey (new KeyEvent (Key.Space | Key.CtrlMask, new KeyModifiers ())));
  2398. Assert.Equal ($"is is the first lin{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first", tv.Text);
  2399. Assert.Equal (new Point (19, 0), tv.CursorPosition);
  2400. Assert.Equal (0, tv.SelectedLength);
  2401. Assert.Equal ("", tv.SelectedText);
  2402. Assert.True (tv.Selecting);
  2403. Assert.Equal (19, tv.SelectionStartColumn);
  2404. Assert.Equal (0, tv.SelectionStartRow);
  2405. Assert.True (tv.ProcessKey (new KeyEvent (Key.Space | Key.CtrlMask, new KeyModifiers ())));
  2406. Assert.Equal ($"is is the first lin{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first", tv.Text);
  2407. Assert.Equal (new Point (19, 0), tv.CursorPosition);
  2408. Assert.Equal (0, tv.SelectedLength);
  2409. Assert.Equal ("", tv.SelectedText);
  2410. Assert.False (tv.Selecting);
  2411. Assert.Equal (19, tv.SelectionStartColumn);
  2412. Assert.Equal (0, tv.SelectionStartRow);
  2413. tv.SelectionStartColumn = 0;
  2414. Assert.True (tv.ProcessKey (new KeyEvent (((int)'C' + Key.AltMask), new KeyModifiers ())));
  2415. Assert.Equal ($"is is the first lin{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first", tv.Text);
  2416. Assert.Equal (new Point (19, 0), tv.CursorPosition);
  2417. Assert.Equal (19, tv.SelectedLength);
  2418. Assert.Equal ("is is the first lin", tv.SelectedText);
  2419. Assert.True (tv.Selecting);
  2420. Assert.Equal (0, tv.SelectionStartColumn);
  2421. Assert.Equal (0, tv.SelectionStartRow);
  2422. Assert.True (tv.ProcessKey (new KeyEvent (Key.C | Key.CtrlMask, new KeyModifiers ())));
  2423. Assert.Equal ($"is is the first lin{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first", tv.Text);
  2424. Assert.Equal (new Point (19, 0), tv.CursorPosition);
  2425. Assert.Equal (19, tv.SelectedLength);
  2426. Assert.Equal ("is is the first lin", tv.SelectedText);
  2427. Assert.True (tv.Selecting);
  2428. Assert.Equal (0, tv.SelectionStartColumn);
  2429. Assert.Equal (0, tv.SelectionStartRow);
  2430. Assert.True (tv.ProcessKey (new KeyEvent (((int)'W' + Key.AltMask), new KeyModifiers ())));
  2431. Assert.Equal ($"{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first", tv.Text);
  2432. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  2433. Assert.Equal (0, tv.SelectedLength);
  2434. Assert.Equal ("", tv.SelectedText);
  2435. Assert.False (tv.Selecting);
  2436. Assert.Equal (0, tv.SelectionStartColumn);
  2437. Assert.Equal (0, tv.SelectionStartRow);
  2438. Assert.Equal ("is is the first lin", Clipboard.Contents);
  2439. Assert.True (tv.ProcessKey (new KeyEvent (Key.W | Key.CtrlMask, new KeyModifiers ())));
  2440. Assert.Equal ($"{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first", tv.Text);
  2441. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  2442. Assert.Equal (0, tv.SelectedLength);
  2443. Assert.Equal ("", tv.SelectedText);
  2444. Assert.False (tv.Selecting);
  2445. Assert.Equal (0, tv.SelectionStartColumn);
  2446. Assert.Equal (0, tv.SelectionStartRow);
  2447. Assert.Equal ("", Clipboard.Contents);
  2448. Assert.True (tv.ProcessKey (new KeyEvent (Key.X | Key.CtrlMask, new KeyModifiers ())));
  2449. Assert.Equal ($"{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first", tv.Text);
  2450. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  2451. Assert.Equal (0, tv.SelectedLength);
  2452. Assert.Equal ("", tv.SelectedText);
  2453. Assert.False (tv.Selecting);
  2454. Assert.Equal (0, tv.SelectionStartColumn);
  2455. Assert.Equal (0, tv.SelectionStartRow);
  2456. Assert.Equal ("", Clipboard.Contents);
  2457. Assert.True (tv.ProcessKey (new KeyEvent (Key.End | Key.CtrlMask, new KeyModifiers ())));
  2458. Assert.Equal ($"{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first", tv.Text);
  2459. Assert.Equal (new Point (28, 2), tv.CursorPosition);
  2460. Assert.Equal (0, tv.SelectedLength);
  2461. Assert.Equal ("", tv.SelectedText);
  2462. Assert.False (tv.Selecting);
  2463. Assert.True (tv.ProcessKey (new KeyEvent (Key.CtrlMask | Key.CursorLeft, new KeyModifiers ())));
  2464. Assert.Equal ($"{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first", tv.Text);
  2465. Assert.Equal (new Point (18, 2), tv.CursorPosition);
  2466. Assert.Equal (0, tv.SelectedLength);
  2467. Assert.Equal ("", tv.SelectedText);
  2468. Assert.False (tv.Selecting);
  2469. Assert.True (tv.ProcessKey (new KeyEvent (Key.CtrlMask | Key.CursorLeft | Key.ShiftMask, new KeyModifiers ())));
  2470. Assert.Equal ($"{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first", tv.Text);
  2471. Assert.Equal (new Point (12, 2), tv.CursorPosition);
  2472. Assert.Equal (6, tv.SelectedLength);
  2473. Assert.Equal ("third ", tv.SelectedText);
  2474. Assert.True (tv.Selecting);
  2475. Assert.True (tv.ProcessKey (new KeyEvent ((Key)((int)'B' + Key.AltMask), new KeyModifiers ())));
  2476. Assert.Equal ($"{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first", tv.Text);
  2477. Assert.Equal (new Point (8, 2), tv.CursorPosition);
  2478. Assert.Equal (0, tv.SelectedLength);
  2479. Assert.Equal ("", tv.SelectedText);
  2480. Assert.False (tv.Selecting);
  2481. Assert.True (tv.ProcessKey (new KeyEvent (Key.CtrlMask | Key.CursorRight, new KeyModifiers ())));
  2482. Assert.Equal ($"{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first", tv.Text);
  2483. Assert.Equal (new Point (12, 2), tv.CursorPosition);
  2484. Assert.Equal (0, tv.SelectedLength);
  2485. Assert.Equal ("", tv.SelectedText);
  2486. Assert.False (tv.Selecting);
  2487. Assert.True (tv.ProcessKey (new KeyEvent (Key.CtrlMask | Key.CursorRight | Key.ShiftMask, new KeyModifiers ())));
  2488. Assert.Equal ($"{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first", tv.Text);
  2489. Assert.Equal (new Point (18, 2), tv.CursorPosition);
  2490. Assert.Equal (6, tv.SelectedLength);
  2491. Assert.Equal ("third ", tv.SelectedText);
  2492. Assert.True (tv.Selecting);
  2493. Assert.True (tv.ProcessKey (new KeyEvent ((Key)((int)'F' + Key.AltMask), new KeyModifiers ())));
  2494. Assert.Equal ($"{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first", tv.Text);
  2495. Assert.Equal (new Point (28, 2), tv.CursorPosition);
  2496. Assert.Equal (0, tv.SelectedLength);
  2497. Assert.Equal ("", tv.SelectedText);
  2498. Assert.False (tv.Selecting);
  2499. Assert.True (tv.ProcessKey (new KeyEvent (Key.Home | Key.CtrlMask, new KeyModifiers ())));
  2500. Assert.Equal ($"{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first", tv.Text);
  2501. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  2502. Assert.Equal (0, tv.SelectedLength);
  2503. Assert.Equal ("", tv.SelectedText);
  2504. Assert.False (tv.Selecting);
  2505. Assert.True (tv.ProcessKey (new KeyEvent (Key.DeleteChar | Key.CtrlMask, new KeyModifiers ())));
  2506. Assert.Equal ($"This is the second line.{Environment.NewLine}This is the third line.first", tv.Text);
  2507. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  2508. Assert.Equal (0, tv.SelectedLength);
  2509. Assert.Equal ("", tv.SelectedText);
  2510. Assert.False (tv.Selecting); Assert.True (tv.ProcessKey (new KeyEvent (Key.End | Key.CtrlMask, new KeyModifiers ())));
  2511. Assert.Equal ($"This is the second line.{Environment.NewLine}This is the third line.first", tv.Text);
  2512. Assert.Equal (new Point (28, 1), tv.CursorPosition);
  2513. Assert.Equal (0, tv.SelectedLength);
  2514. Assert.Equal ("", tv.SelectedText);
  2515. Assert.False (tv.Selecting);
  2516. Assert.False (tv.Selecting); Assert.True (tv.ProcessKey (new KeyEvent (Key.Backspace | Key.CtrlMask, new KeyModifiers ())));
  2517. Assert.Equal ($"This is the second line.{Environment.NewLine}This is the third ", tv.Text);
  2518. Assert.Equal (new Point (18, 1), tv.CursorPosition);
  2519. Assert.Equal (0, tv.SelectedLength);
  2520. Assert.Equal ("", tv.SelectedText);
  2521. Assert.False (tv.Selecting);
  2522. Assert.True (tv.AllowsReturn);
  2523. tv.AllowsReturn = false;
  2524. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  2525. Assert.False (tv.Selecting);
  2526. Assert.False (tv.ProcessKey (new KeyEvent (Key.Enter, new KeyModifiers ())));
  2527. Assert.Equal ($"This is the second line.{Environment.NewLine}This is the third ", tv.Text);
  2528. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  2529. Assert.Equal (0, tv.SelectedLength);
  2530. Assert.Equal ("", tv.SelectedText);
  2531. Assert.False (tv.Selecting);
  2532. Assert.False (tv.AllowsReturn);
  2533. tv.AllowsReturn = true;
  2534. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  2535. Assert.True (tv.ProcessKey (new KeyEvent (Key.Enter, new KeyModifiers ())));
  2536. Assert.Equal ($"{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third ", tv.Text);
  2537. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  2538. Assert.Equal (0, tv.SelectedLength);
  2539. Assert.Equal ("", tv.SelectedText);
  2540. Assert.False (tv.Selecting);
  2541. Assert.True (tv.AllowsReturn);
  2542. Assert.True (tv.ProcessKey (new KeyEvent (Key.CtrlMask | Key.End | Key.ShiftMask, new KeyModifiers ())));
  2543. Assert.Equal ($"{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third ", tv.Text);
  2544. Assert.Equal (new Point (18, 2), tv.CursorPosition);
  2545. Assert.Equal (42 + Environment.NewLine.Length, tv.SelectedLength);
  2546. Assert.Equal ($"This is the second line.{Environment.NewLine}This is the third ", tv.SelectedText);
  2547. Assert.True (tv.Selecting);
  2548. Assert.True (tv.ProcessKey (new KeyEvent (Key.CtrlMask | Key.Home | Key.ShiftMask, new KeyModifiers ())));
  2549. Assert.Equal ($"{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third ", tv.Text);
  2550. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  2551. Assert.Equal (Environment.NewLine.Length, tv.SelectedLength);
  2552. Assert.Equal ($"{Environment.NewLine}", tv.SelectedText);
  2553. Assert.True (tv.Selecting);
  2554. Assert.True (tv.ProcessKey (new KeyEvent (Key.T | Key.CtrlMask, new KeyModifiers ())));
  2555. Assert.Equal ($"{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third ", tv.Text);
  2556. Assert.Equal (new Point (18, 2), tv.CursorPosition);
  2557. Assert.Equal (42 + Environment.NewLine.Length * 2, tv.SelectedLength);
  2558. Assert.Equal ($"{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third ", tv.SelectedText);
  2559. Assert.True (tv.Selecting);
  2560. Assert.True (tv.Used);
  2561. Assert.True (tv.ProcessKey (new KeyEvent (Key.InsertChar, new KeyModifiers ())));
  2562. Assert.False (tv.Used);
  2563. Assert.True (tv.AllowsTab);
  2564. Assert.Equal (new Point (18, 2), tv.CursorPosition);
  2565. tv.AllowsTab = false;
  2566. Assert.False (tv.ProcessKey (new KeyEvent (Key.Tab, new KeyModifiers ())));
  2567. Assert.Equal ($"{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third ", tv.Text);
  2568. Assert.False (tv.AllowsTab);
  2569. tv.AllowsTab = true;
  2570. Assert.Equal (new Point (18, 2), tv.CursorPosition);
  2571. Assert.True (tv.Selecting);
  2572. tv.Selecting = false;
  2573. Assert.True (tv.ProcessKey (new KeyEvent (Key.Tab, new KeyModifiers ())));
  2574. Assert.Equal ($"{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third \t", tv.Text);
  2575. Assert.True (tv.AllowsTab);
  2576. tv.AllowsTab = false;
  2577. Assert.False (tv.ProcessKey (new KeyEvent (Key.BackTab | Key.ShiftMask, new KeyModifiers ())));
  2578. Assert.Equal ($"{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third \t", tv.Text);
  2579. Assert.False (tv.AllowsTab);
  2580. tv.AllowsTab = true;
  2581. Assert.True (tv.ProcessKey (new KeyEvent (Key.BackTab | Key.ShiftMask, new KeyModifiers ())));
  2582. Assert.Equal ($"{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third ", tv.Text);
  2583. Assert.True (tv.AllowsTab);
  2584. Assert.False (tv.ProcessKey (new KeyEvent (Key.Tab | Key.CtrlMask, new KeyModifiers ())));
  2585. Assert.False (tv.ProcessKey (new KeyEvent (Application.AlternateForwardKey, new KeyModifiers ())));
  2586. Assert.False (tv.ProcessKey (new KeyEvent (Key.Tab | Key.CtrlMask | Key.ShiftMask, new KeyModifiers ())));
  2587. Assert.False (tv.ProcessKey (new KeyEvent (Application.AlternateBackwardKey, new KeyModifiers ())));
  2588. }
  2589. [Fact]
  2590. public void HistoryText_Exceptions ()
  2591. {
  2592. var ht = new HistoryText ();
  2593. foreach (var ls in Enum.GetValues (typeof (HistoryText.LineStatus))) {
  2594. if ((HistoryText.LineStatus)ls != HistoryText.LineStatus.Original) {
  2595. Assert.Throws<ArgumentException> (() => ht.Add (new List<List<Rune>> () { new List<Rune> () }, Point.Empty,
  2596. (HistoryText.LineStatus)ls));
  2597. }
  2598. }
  2599. Assert.Null (Record.Exception (() => ht.Add (new List<List<Rune>> () { new List<Rune> () }, Point.Empty,
  2600. HistoryText.LineStatus.Original)));
  2601. }
  2602. [Fact]
  2603. [AutoInitShutdown]
  2604. public void HistoryText_Undo_Redo_Single_Line_InsertText ()
  2605. {
  2606. var text = "This is the first line.\nThis is the second line.\nThis is the third line.";
  2607. var tv = new TextView () {
  2608. Width = 10,
  2609. Height = 2,
  2610. Text = text
  2611. };
  2612. var top = Application.Top;
  2613. top.Add (tv);
  2614. Application.Begin (top);
  2615. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  2616. Assert.Equal (3, tv.Lines);
  2617. Assert.Equal (Point.Empty, tv.CursorPosition);
  2618. var messy = " messy";
  2619. tv.CursorPosition = new Point (7, 1);
  2620. tv.InsertText (messy);
  2621. Assert.Equal ($"This is the first line.{Environment.NewLine}This is messy the second line.{Environment.NewLine}This is the third line.", tv.Text);
  2622. Assert.Equal (3, tv.Lines);
  2623. Assert.Equal (new Point (13, 1), tv.CursorPosition);
  2624. for (int i = 0; i < messy.Length; i++) {
  2625. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  2626. }
  2627. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  2628. Assert.Equal (3, tv.Lines);
  2629. Assert.Equal (new Point (7, 1), tv.CursorPosition);
  2630. for (int i = 0; i < messy.Length; i++) {
  2631. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  2632. }
  2633. Assert.Equal ($"This is the first line.{Environment.NewLine}This is messy the second line.{Environment.NewLine}This is the third line.", tv.Text);
  2634. Assert.Equal (3, tv.Lines);
  2635. Assert.Equal (new Point (13, 1), tv.CursorPosition);
  2636. }
  2637. [Fact]
  2638. [AutoInitShutdown]
  2639. public void HistoryText_Undo_Redo_Single_Line_DeleteCharLeft ()
  2640. {
  2641. var text = "This is the first line.\nThis is the second line.\nThis is the third line.";
  2642. var tv = new TextView () {
  2643. Width = 10,
  2644. Height = 2,
  2645. Text = text
  2646. };
  2647. var top = Application.Top;
  2648. top.Add (tv);
  2649. Application.Begin (top);
  2650. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  2651. Assert.Equal (3, tv.Lines);
  2652. Assert.Equal (Point.Empty, tv.CursorPosition);
  2653. var ntimes = 3;
  2654. tv.CursorPosition = new Point (7, 1);
  2655. for (int i = 0; i < ntimes; i++) {
  2656. tv.DeleteCharLeft ();
  2657. }
  2658. Assert.Equal ($"This is the first line.{Environment.NewLine}This the second line.{Environment.NewLine}This is the third line.", tv.Text);
  2659. Assert.Equal (3, tv.Lines);
  2660. Assert.Equal (new Point (4, 1), tv.CursorPosition);
  2661. for (int i = 0; i < ntimes; i++) {
  2662. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  2663. }
  2664. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  2665. Assert.Equal (3, tv.Lines);
  2666. Assert.Equal (new Point (7, 1), tv.CursorPosition);
  2667. for (int i = 0; i < ntimes; i++) {
  2668. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  2669. }
  2670. Assert.Equal ($"This is the first line.{Environment.NewLine}This the second line.{Environment.NewLine}This is the third line.", tv.Text);
  2671. Assert.Equal (3, tv.Lines);
  2672. Assert.Equal (new Point (4, 1), tv.CursorPosition);
  2673. }
  2674. [Fact]
  2675. [AutoInitShutdown]
  2676. public void HistoryText_Undo_Redo_Single_Line_DeleteCharRight ()
  2677. {
  2678. var text = "This is the first line.\nThis is the second line.\nThis is the third line.";
  2679. var tv = new TextView () {
  2680. Width = 10,
  2681. Height = 2,
  2682. Text = text
  2683. };
  2684. var top = Application.Top;
  2685. top.Add (tv);
  2686. Application.Begin (top);
  2687. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  2688. Assert.Equal (3, tv.Lines);
  2689. Assert.Equal (Point.Empty, tv.CursorPosition);
  2690. var ntimes = 3;
  2691. tv.CursorPosition = new Point (7, 1);
  2692. for (int i = 0; i < ntimes; i++) {
  2693. tv.DeleteCharRight ();
  2694. }
  2695. Assert.Equal ($"This is the first line.{Environment.NewLine}This ise second line.{Environment.NewLine}This is the third line.", tv.Text);
  2696. Assert.Equal (3, tv.Lines);
  2697. Assert.Equal (new Point (7, 1), tv.CursorPosition);
  2698. for (int i = 0; i < ntimes; i++) {
  2699. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  2700. }
  2701. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  2702. Assert.Equal (3, tv.Lines);
  2703. Assert.Equal (new Point (7, 1), tv.CursorPosition);
  2704. for (int i = 0; i < ntimes; i++) {
  2705. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  2706. }
  2707. Assert.Equal ($"This is the first line.{Environment.NewLine}This ise second line.{Environment.NewLine}This is the third line.", tv.Text);
  2708. Assert.Equal (3, tv.Lines);
  2709. Assert.Equal (new Point (7, 1), tv.CursorPosition);
  2710. }
  2711. [Fact]
  2712. [AutoInitShutdown]
  2713. public void HistoryText_Undo_Redo_Single_Line_Selected_InsertText ()
  2714. {
  2715. var text = "This is the first line.\nThis is the second line.\nThis is the third line.";
  2716. var tv = new TextView () {
  2717. Width = 10,
  2718. Height = 2,
  2719. Text = text
  2720. };
  2721. var top = Application.Top;
  2722. top.Add (tv);
  2723. Application.Begin (top);
  2724. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  2725. Assert.Equal (3, tv.Lines);
  2726. Assert.Equal (Point.Empty, tv.CursorPosition);
  2727. var messy = " messy";
  2728. tv.CursorPosition = new Point (7, 1);
  2729. tv.SelectionStartColumn = 11;
  2730. tv.SelectionStartRow = 1;
  2731. Assert.Equal (4, tv.SelectedLength);
  2732. tv.InsertText (messy);
  2733. Assert.Equal ($"This is the first line.{Environment.NewLine}This is messy second line.{Environment.NewLine}This is the third line.", tv.Text);
  2734. Assert.Equal (3, tv.Lines);
  2735. Assert.Equal (new Point (13, 1), tv.CursorPosition);
  2736. Assert.Equal (11, tv.SelectionStartColumn);
  2737. Assert.Equal (1, tv.SelectionStartRow);
  2738. Assert.Equal (0, tv.SelectedLength);
  2739. for (int i = 0; i < messy.Length; i++) {
  2740. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  2741. }
  2742. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  2743. Assert.Equal (3, tv.Lines);
  2744. Assert.Equal (new Point (7, 1), tv.CursorPosition);
  2745. Assert.Equal (11, tv.SelectionStartColumn);
  2746. Assert.Equal (1, tv.SelectionStartRow);
  2747. Assert.Equal (0, tv.SelectedLength);
  2748. for (int i = 0; i < messy.Length; i++) {
  2749. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  2750. }
  2751. Assert.Equal ($"This is the first line.{Environment.NewLine}This is messy second line.{Environment.NewLine}This is the third line.", tv.Text);
  2752. Assert.Equal (3, tv.Lines);
  2753. Assert.Equal (new Point (13, 1), tv.CursorPosition);
  2754. Assert.Equal (11, tv.SelectionStartColumn);
  2755. Assert.Equal (1, tv.SelectionStartRow);
  2756. Assert.Equal (0, tv.SelectedLength);
  2757. }
  2758. [Fact]
  2759. [AutoInitShutdown]
  2760. public void HistoryText_Undo_Redo_Single_Line_Selected_DeleteCharLeft ()
  2761. {
  2762. var text = "This is the first line.\nThis is the second line.\nThis is the third line.";
  2763. var tv = new TextView () {
  2764. Width = 10,
  2765. Height = 2,
  2766. Text = text
  2767. };
  2768. var top = Application.Top;
  2769. top.Add (tv);
  2770. Application.Begin (top);
  2771. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  2772. Assert.Equal (3, tv.Lines);
  2773. Assert.Equal (Point.Empty, tv.CursorPosition);
  2774. var ntimes = 3;
  2775. tv.CursorPosition = new Point (7, 1);
  2776. tv.SelectionStartColumn = 11;
  2777. tv.SelectionStartRow = 1;
  2778. Assert.Equal (4, tv.SelectedLength);
  2779. for (int i = 0; i < ntimes; i++) {
  2780. tv.DeleteCharLeft ();
  2781. }
  2782. Assert.Equal ($"This is the first line.{Environment.NewLine}This second line.{Environment.NewLine}This is the third line.", tv.Text);
  2783. Assert.Equal (3, tv.Lines);
  2784. Assert.Equal (new Point (5, 1), tv.CursorPosition);
  2785. Assert.Equal (11, tv.SelectionStartColumn);
  2786. Assert.Equal (1, tv.SelectionStartRow);
  2787. Assert.Equal (0, tv.SelectedLength);
  2788. for (int i = 0; i < ntimes; i++) {
  2789. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  2790. }
  2791. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  2792. Assert.Equal (3, tv.Lines);
  2793. Assert.Equal (new Point (7, 1), tv.CursorPosition);
  2794. Assert.Equal (11, tv.SelectionStartColumn);
  2795. Assert.Equal (1, tv.SelectionStartRow);
  2796. Assert.Equal (0, tv.SelectedLength);
  2797. for (int i = 0; i < ntimes; i++) {
  2798. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  2799. }
  2800. Assert.Equal ($"This is the first line.{Environment.NewLine}This second line.{Environment.NewLine}This is the third line.", tv.Text);
  2801. Assert.Equal (3, tv.Lines);
  2802. Assert.Equal (new Point (5, 1), tv.CursorPosition);
  2803. Assert.Equal (11, tv.SelectionStartColumn);
  2804. Assert.Equal (1, tv.SelectionStartRow);
  2805. Assert.Equal (0, tv.SelectedLength);
  2806. }
  2807. [Fact]
  2808. [AutoInitShutdown]
  2809. public void HistoryText_Undo_Redo_Single_Line_Selected_DeleteCharRight ()
  2810. {
  2811. var text = "This is the first line.\nThis is the second line.\nThis is the third line.";
  2812. var tv = new TextView () {
  2813. Width = 10,
  2814. Height = 2,
  2815. Text = text
  2816. };
  2817. var top = Application.Top;
  2818. top.Add (tv);
  2819. Application.Begin (top);
  2820. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  2821. Assert.Equal (3, tv.Lines);
  2822. Assert.Equal (Point.Empty, tv.CursorPosition);
  2823. var ntimes = 3;
  2824. tv.CursorPosition = new Point (7, 1);
  2825. tv.SelectionStartColumn = 11;
  2826. tv.SelectionStartRow = 1;
  2827. Assert.Equal (4, tv.SelectedLength);
  2828. for (int i = 0; i < ntimes; i++) {
  2829. tv.DeleteCharRight ();
  2830. }
  2831. Assert.Equal ($"This is the first line.{Environment.NewLine}This isecond line.{Environment.NewLine}This is the third line.", tv.Text);
  2832. Assert.Equal (3, tv.Lines);
  2833. Assert.Equal (new Point (7, 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 < ntimes; 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 < ntimes; 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 isecond line.{Environment.NewLine}This is the third line.", tv.Text);
  2850. Assert.Equal (3, tv.Lines);
  2851. Assert.Equal (new Point (7, 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_Multi_Line_InsertText ()
  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 messy = " messy";
  2873. tv.CursorPosition = new Point (7, 1);
  2874. tv.InsertText (messy);
  2875. Assert.Equal ($"This is the first line.{Environment.NewLine}This is messy the second line.{Environment.NewLine}This is the third line.", tv.Text);
  2876. Assert.Equal (3, tv.Lines);
  2877. Assert.Equal (new Point (13, 1), tv.CursorPosition);
  2878. tv.CursorPosition = new Point (7, 0);
  2879. tv.InsertText (messy);
  2880. 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);
  2881. Assert.Equal (3, tv.Lines);
  2882. Assert.Equal (new Point (13, 0), tv.CursorPosition);
  2883. tv.CursorPosition = new Point (7, 2);
  2884. tv.InsertText (messy);
  2885. 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);
  2886. Assert.Equal (3, tv.Lines);
  2887. Assert.Equal (new Point (13, 2), tv.CursorPosition);
  2888. for (int i = 0; i < messy.Length; i++) {
  2889. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  2890. }
  2891. Assert.Equal ($"This is messy the first line.{Environment.NewLine}This is messy the second line.{Environment.NewLine}This is the third line.", tv.Text);
  2892. Assert.Equal (3, tv.Lines);
  2893. Assert.Equal (new Point (7, 2), tv.CursorPosition);
  2894. for (int i = 0; i < messy.Length; i++) {
  2895. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  2896. }
  2897. Assert.Equal ($"This is the first line.{Environment.NewLine}This is messy the second line.{Environment.NewLine}This is the third line.", tv.Text);
  2898. Assert.Equal (3, tv.Lines);
  2899. Assert.Equal (new Point (7, 0), tv.CursorPosition);
  2900. for (int i = 0; i < messy.Length; i++) {
  2901. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  2902. }
  2903. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  2904. Assert.Equal (3, tv.Lines);
  2905. Assert.Equal (new Point (7, 1), tv.CursorPosition);
  2906. for (int i = 0; i < messy.Length; i++) {
  2907. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  2908. }
  2909. Assert.Equal ($"This is the first line.{Environment.NewLine}This is messy the second line.{Environment.NewLine}This is the third line.", tv.Text);
  2910. Assert.Equal (3, tv.Lines);
  2911. Assert.Equal (new Point (13, 1), tv.CursorPosition);
  2912. for (int i = 0; i < messy.Length; i++) {
  2913. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  2914. }
  2915. 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);
  2916. Assert.Equal (3, tv.Lines);
  2917. Assert.Equal (new Point (13, 0), tv.CursorPosition);
  2918. for (int i = 0; i < messy.Length; i++) {
  2919. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  2920. }
  2921. 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);
  2922. Assert.Equal (3, tv.Lines);
  2923. Assert.Equal (new Point (13, 2), tv.CursorPosition);
  2924. }
  2925. [Fact]
  2926. [AutoInitShutdown]
  2927. public void HistoryText_Undo_Redo_Multi_Line_DeleteCharLeft ()
  2928. {
  2929. var text = "This is the first line.\nThis is the second line.\nThis is the third line.";
  2930. var tv = new TextView () {
  2931. Width = 10,
  2932. Height = 2,
  2933. Text = text
  2934. };
  2935. var top = Application.Top;
  2936. top.Add (tv);
  2937. Application.Begin (top);
  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 (Point.Empty, tv.CursorPosition);
  2941. var ntimes = 3;
  2942. tv.CursorPosition = new Point (7, 1);
  2943. for (int i = 0; i < ntimes; i++) {
  2944. tv.DeleteCharLeft ();
  2945. }
  2946. Assert.Equal ($"This is the first line.{Environment.NewLine}This the second line.{Environment.NewLine}This is the third line.", tv.Text);
  2947. Assert.Equal (3, tv.Lines);
  2948. Assert.Equal (new Point (4, 1), tv.CursorPosition);
  2949. tv.CursorPosition = new Point (7, 0);
  2950. for (int i = 0; i < ntimes; i++) {
  2951. tv.DeleteCharLeft ();
  2952. }
  2953. Assert.Equal ($"This the first line.{Environment.NewLine}This the second line.{Environment.NewLine}This is the third line.", tv.Text);
  2954. Assert.Equal (3, tv.Lines);
  2955. Assert.Equal (new Point (4, 0), tv.CursorPosition);
  2956. tv.CursorPosition = new Point (7, 2);
  2957. for (int i = 0; i < ntimes; i++) {
  2958. tv.DeleteCharLeft ();
  2959. }
  2960. Assert.Equal ($"This the first line.{Environment.NewLine}This the second line.{Environment.NewLine}This the third line.", tv.Text);
  2961. Assert.Equal (3, tv.Lines);
  2962. Assert.Equal (new Point (4, 2), tv.CursorPosition);
  2963. for (int i = 0; i < ntimes; i++) {
  2964. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  2965. switch (i) {
  2966. case 0:
  2967. Assert.Equal ($"This the first line.{Environment.NewLine}This the second line.{Environment.NewLine}This the third line.", tv.Text);
  2968. Assert.Equal (new Point (5, 2), tv.CursorPosition);
  2969. break;
  2970. case 1:
  2971. Assert.Equal ($"This the first line.{Environment.NewLine}This the second line.{Environment.NewLine}This i the third line.", tv.Text);
  2972. Assert.Equal (new Point (6, 2), tv.CursorPosition);
  2973. break;
  2974. case 2:
  2975. Assert.Equal ($"This the first line.{Environment.NewLine}This the second line.{Environment.NewLine}This is the third line.", tv.Text);
  2976. Assert.Equal (new Point (7, 2), tv.CursorPosition);
  2977. break;
  2978. }
  2979. }
  2980. Assert.Equal ($"This the first line.{Environment.NewLine}This the second line.{Environment.NewLine}This is the third line.", tv.Text);
  2981. Assert.Equal (3, tv.Lines);
  2982. Assert.Equal (new Point (7, 2), tv.CursorPosition);
  2983. for (int i = 0; i < ntimes; i++) {
  2984. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  2985. switch (i) {
  2986. case 0:
  2987. Assert.Equal ($"This the first line.{Environment.NewLine}This the second line.{Environment.NewLine}This is the third line.", tv.Text);
  2988. Assert.Equal (new Point (5, 0), tv.CursorPosition);
  2989. break;
  2990. case 1:
  2991. Assert.Equal ($"This i the first line.{Environment.NewLine}This the second line.{Environment.NewLine}This is the third line.", tv.Text);
  2992. Assert.Equal (new Point (6, 0), tv.CursorPosition);
  2993. break;
  2994. case 2:
  2995. Assert.Equal ($"This is the first line.{Environment.NewLine}This the second line.{Environment.NewLine}This is the third line.", tv.Text);
  2996. Assert.Equal (new Point (7, 0), tv.CursorPosition);
  2997. break;
  2998. }
  2999. }
  3000. Assert.Equal ($"This is the first line.{Environment.NewLine}This the second line.{Environment.NewLine}This is the third line.", tv.Text);
  3001. Assert.Equal (3, tv.Lines);
  3002. Assert.Equal (new Point (7, 0), tv.CursorPosition);
  3003. for (int i = 0; i < ntimes; i++) {
  3004. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  3005. switch (i) {
  3006. case 0:
  3007. Assert.Equal ($"This is the first line.{Environment.NewLine}This the second line.{Environment.NewLine}This is the third line.", tv.Text);
  3008. Assert.Equal (new Point (5, 1), tv.CursorPosition);
  3009. break;
  3010. case 1:
  3011. Assert.Equal ($"This is the first line.{Environment.NewLine}This i the second line.{Environment.NewLine}This is the third line.", tv.Text);
  3012. Assert.Equal (new Point (6, 1), tv.CursorPosition);
  3013. break;
  3014. case 2:
  3015. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  3016. Assert.Equal (new Point (7, 1), tv.CursorPosition);
  3017. break;
  3018. }
  3019. }
  3020. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  3021. Assert.Equal (3, tv.Lines);
  3022. Assert.Equal (new Point (7, 1), tv.CursorPosition);
  3023. for (int i = 0; i < ntimes; i++) {
  3024. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  3025. }
  3026. Assert.Equal ($"This is the first line.{Environment.NewLine}This the second line.{Environment.NewLine}This is the third line.", tv.Text);
  3027. Assert.Equal (3, tv.Lines);
  3028. Assert.Equal (new Point (4, 1), tv.CursorPosition);
  3029. for (int i = 0; i < ntimes; i++) {
  3030. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  3031. }
  3032. Assert.Equal ($"This the first line.{Environment.NewLine}This the second line.{Environment.NewLine}This is the third line.", tv.Text);
  3033. Assert.Equal (3, tv.Lines);
  3034. Assert.Equal (new Point (4, 0), tv.CursorPosition);
  3035. for (int i = 0; i < ntimes; i++) {
  3036. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  3037. }
  3038. Assert.Equal ($"This the first line.{Environment.NewLine}This the second line.{Environment.NewLine}This the third line.", tv.Text);
  3039. Assert.Equal (3, tv.Lines);
  3040. Assert.Equal (new Point (4, 2), tv.CursorPosition);
  3041. }
  3042. [Fact]
  3043. [AutoInitShutdown]
  3044. public void HistoryText_Undo_Redo_Multi_Line_DeleteCharRight ()
  3045. {
  3046. var text = "This is the first line.\nThis is the second line.\nThis is the third line.";
  3047. var tv = new TextView () {
  3048. Width = 10,
  3049. Height = 2,
  3050. Text = text
  3051. };
  3052. var top = Application.Top;
  3053. top.Add (tv);
  3054. Application.Begin (top);
  3055. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  3056. Assert.Equal (3, tv.Lines);
  3057. Assert.Equal (Point.Empty, tv.CursorPosition);
  3058. var ntimes = 3;
  3059. tv.CursorPosition = new Point (7, 1);
  3060. for (int i = 0; i < ntimes; i++) {
  3061. tv.DeleteCharRight ();
  3062. }
  3063. Assert.Equal ($"This is the first line.{Environment.NewLine}This ise second line.{Environment.NewLine}This is the third line.", tv.Text);
  3064. Assert.Equal (3, tv.Lines);
  3065. Assert.Equal (new Point (7, 1), tv.CursorPosition);
  3066. tv.CursorPosition = new Point (7, 0);
  3067. for (int i = 0; i < ntimes; i++) {
  3068. tv.DeleteCharRight ();
  3069. }
  3070. Assert.Equal ($"This ise first line.{Environment.NewLine}This ise second line.{Environment.NewLine}This is the third line.", tv.Text);
  3071. Assert.Equal (3, tv.Lines);
  3072. Assert.Equal (new Point (7, 0), tv.CursorPosition);
  3073. tv.CursorPosition = new Point (7, 2);
  3074. for (int i = 0; i < ntimes; i++) {
  3075. tv.DeleteCharRight ();
  3076. }
  3077. Assert.Equal ($"This ise first line.{Environment.NewLine}This ise second line.{Environment.NewLine}This ise third line.", tv.Text);
  3078. Assert.Equal (3, tv.Lines);
  3079. Assert.Equal (new Point (7, 2), tv.CursorPosition);
  3080. for (int i = 0; i < ntimes; i++) {
  3081. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  3082. }
  3083. Assert.Equal ($"This ise first line.{Environment.NewLine}This ise second line.{Environment.NewLine}This is the third line.", tv.Text);
  3084. Assert.Equal (3, tv.Lines);
  3085. Assert.Equal (new Point (7, 2), tv.CursorPosition);
  3086. for (int i = 0; i < ntimes; i++) {
  3087. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  3088. }
  3089. Assert.Equal ($"This is the first line.{Environment.NewLine}This ise second line.{Environment.NewLine}This is the third line.", tv.Text);
  3090. Assert.Equal (3, tv.Lines);
  3091. Assert.Equal (new Point (7, 0), tv.CursorPosition);
  3092. for (int i = 0; i < ntimes; i++) {
  3093. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  3094. }
  3095. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  3096. Assert.Equal (3, tv.Lines);
  3097. Assert.Equal (new Point (7, 1), tv.CursorPosition);
  3098. for (int i = 0; i < ntimes; i++) {
  3099. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  3100. }
  3101. Assert.Equal ($"This is the first line.{Environment.NewLine}This ise second line.{Environment.NewLine}This is the third line.", tv.Text);
  3102. Assert.Equal (3, tv.Lines);
  3103. Assert.Equal (new Point (7, 1), tv.CursorPosition);
  3104. for (int i = 0; i < ntimes; i++) {
  3105. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  3106. }
  3107. Assert.Equal ($"This ise first line.{Environment.NewLine}This ise second line.{Environment.NewLine}This is the third line.", tv.Text);
  3108. Assert.Equal (3, tv.Lines);
  3109. Assert.Equal (new Point (7, 0), tv.CursorPosition);
  3110. for (int i = 0; i < ntimes; i++) {
  3111. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  3112. }
  3113. Assert.Equal ($"This ise first line.{Environment.NewLine}This ise second line.{Environment.NewLine}This ise third line.", tv.Text);
  3114. Assert.Equal (3, tv.Lines);
  3115. Assert.Equal (new Point (7, 2), tv.CursorPosition);
  3116. }
  3117. [Fact]
  3118. [AutoInitShutdown]
  3119. public void HistoryText_Undo_Redo_Multi_Line_Selected_InsertText ()
  3120. {
  3121. var text = $"This is the first line.{Environment.NewLine}This is the second line.\nThis is the third line.";
  3122. var tv = new TextView () {
  3123. Width = 10,
  3124. Height = 2,
  3125. Text = text
  3126. };
  3127. var top = Application.Top;
  3128. top.Add (tv);
  3129. Application.Begin (top);
  3130. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  3131. Assert.Equal (3, tv.Lines);
  3132. Assert.Equal (Point.Empty, tv.CursorPosition);
  3133. var messy = " messy";
  3134. tv.CursorPosition = new Point (7, 0);
  3135. tv.SelectionStartColumn = 11;
  3136. tv.SelectionStartRow = 2;
  3137. Assert.Equal (51 + Environment.NewLine.Length * 2, tv.SelectedLength);
  3138. for (int i = 0; i < messy.Length; i++) {
  3139. tv.InsertText (messy [i].ToString ());
  3140. switch (i) {
  3141. case 0:
  3142. Assert.Equal ("This is third line.", tv.Text);
  3143. Assert.Equal (new Point (8, 0), tv.CursorPosition);
  3144. break;
  3145. case 1:
  3146. Assert.Equal ("This is m third line.", tv.Text);
  3147. Assert.Equal (new Point (9, 0), tv.CursorPosition);
  3148. break;
  3149. case 2:
  3150. Assert.Equal ("This is me third line.", tv.Text);
  3151. Assert.Equal (new Point (10, 0), tv.CursorPosition);
  3152. break;
  3153. case 3:
  3154. Assert.Equal ("This is mes third line.", tv.Text);
  3155. Assert.Equal (new Point (11, 0), tv.CursorPosition);
  3156. break;
  3157. case 4:
  3158. Assert.Equal ("This is mess third line.", tv.Text);
  3159. Assert.Equal (new Point (12, 0), tv.CursorPosition);
  3160. break;
  3161. case 5:
  3162. Assert.Equal ("This is messy third line.", tv.Text);
  3163. Assert.Equal (new Point (13, 0), tv.CursorPosition);
  3164. break;
  3165. }
  3166. }
  3167. Assert.Equal ($"This is messy third line.", tv.Text);
  3168. Assert.Equal (1, tv.Lines);
  3169. Assert.Equal (new Point (13, 0), tv.CursorPosition);
  3170. Assert.Equal (11, tv.SelectionStartColumn);
  3171. Assert.Equal (2, tv.SelectionStartRow);
  3172. Assert.Equal (0, tv.SelectedLength);
  3173. for (int i = 0; i < messy.Length; i++) {
  3174. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  3175. switch (i) {
  3176. case 0:
  3177. Assert.Equal ("This is mess third line.", tv.Text);
  3178. Assert.Equal (new Point (12, 0), tv.CursorPosition);
  3179. break;
  3180. case 1:
  3181. Assert.Equal ("This is mes third line.", tv.Text);
  3182. Assert.Equal (new Point (11, 0), tv.CursorPosition);
  3183. break;
  3184. case 2:
  3185. Assert.Equal ("This is me third line.", tv.Text);
  3186. Assert.Equal (new Point (10, 0), tv.CursorPosition);
  3187. break;
  3188. case 3:
  3189. Assert.Equal ("This is m third line.", tv.Text);
  3190. Assert.Equal (new Point (9, 0), tv.CursorPosition);
  3191. break;
  3192. case 4:
  3193. Assert.Equal ("This is third line.", tv.Text);
  3194. Assert.Equal (new Point (8, 0), tv.CursorPosition);
  3195. break;
  3196. case 5:
  3197. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  3198. Assert.Equal (new Point (7, 0), tv.CursorPosition);
  3199. break;
  3200. }
  3201. }
  3202. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  3203. Assert.Equal (3, tv.Lines);
  3204. Assert.Equal (new Point (7, 0), tv.CursorPosition);
  3205. Assert.Equal (11, tv.SelectionStartColumn);
  3206. Assert.Equal (2, tv.SelectionStartRow);
  3207. Assert.Equal (0, tv.SelectedLength);
  3208. for (int i = 0; i < messy.Length; i++) {
  3209. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  3210. switch (i) {
  3211. case 0:
  3212. Assert.Equal ("This is third line.", tv.Text);
  3213. Assert.Equal (new Point (8, 0), tv.CursorPosition);
  3214. break;
  3215. case 1:
  3216. Assert.Equal ("This is m third line.", tv.Text);
  3217. Assert.Equal (new Point (9, 0), tv.CursorPosition);
  3218. break;
  3219. case 2:
  3220. Assert.Equal ("This is me third line.", tv.Text);
  3221. Assert.Equal (new Point (10, 0), tv.CursorPosition);
  3222. break;
  3223. case 3:
  3224. Assert.Equal ("This is mes third line.", tv.Text);
  3225. Assert.Equal (new Point (11, 0), tv.CursorPosition);
  3226. break;
  3227. case 4:
  3228. Assert.Equal ("This is mess third line.", tv.Text);
  3229. Assert.Equal (new Point (12, 0), tv.CursorPosition);
  3230. break;
  3231. case 5:
  3232. Assert.Equal ("This is messy third line.", tv.Text);
  3233. Assert.Equal (new Point (13, 0), tv.CursorPosition);
  3234. break;
  3235. }
  3236. }
  3237. Assert.Equal ("This is messy third line.", tv.Text);
  3238. Assert.Equal (1, tv.Lines);
  3239. Assert.Equal (new Point (13, 0), tv.CursorPosition);
  3240. Assert.Equal (11, tv.SelectionStartColumn);
  3241. Assert.Equal (2, tv.SelectionStartRow);
  3242. Assert.Equal (0, tv.SelectedLength);
  3243. }
  3244. [Fact]
  3245. [AutoInitShutdown]
  3246. public void HistoryText_Undo_Redo_Multi_Line_With_Empty_Text ()
  3247. {
  3248. var tv = new TextView () {
  3249. Width = 10,
  3250. Height = 2
  3251. };
  3252. var top = Application.Top;
  3253. top.Add (tv);
  3254. Application.Begin (top);
  3255. Assert.Equal ("", tv.Text);
  3256. Assert.Equal (1, tv.Lines);
  3257. Assert.Equal (Point.Empty, tv.CursorPosition);
  3258. Assert.False (tv.IsDirty);
  3259. Assert.True (tv.ProcessKey (new KeyEvent (Key.O, new KeyModifiers ())));
  3260. Assert.Equal ("O", tv.Text);
  3261. Assert.Equal (1, tv.Lines);
  3262. Assert.Equal (new Point (1, 0), tv.CursorPosition);
  3263. Assert.True (tv.IsDirty);
  3264. Assert.True (tv.ProcessKey (new KeyEvent (Key.n, new KeyModifiers ())));
  3265. Assert.Equal ("On", tv.Text);
  3266. Assert.Equal (1, tv.Lines);
  3267. Assert.Equal (new Point (2, 0), tv.CursorPosition);
  3268. Assert.True (tv.IsDirty);
  3269. Assert.True (tv.ProcessKey (new KeyEvent (Key.e, new KeyModifiers ())));
  3270. Assert.Equal ("One", tv.Text);
  3271. Assert.Equal (1, tv.Lines);
  3272. Assert.Equal (new Point (3, 0), tv.CursorPosition);
  3273. Assert.True (tv.IsDirty);
  3274. Assert.True (tv.ProcessKey (new KeyEvent (Key.Enter, new KeyModifiers ())));
  3275. Assert.Equal ($"One{Environment.NewLine}", tv.Text);
  3276. Assert.Equal (2, tv.Lines);
  3277. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  3278. Assert.True (tv.IsDirty);
  3279. Assert.True (tv.ProcessKey (new KeyEvent (Key.T, new KeyModifiers ())));
  3280. Assert.Equal ($"One{Environment.NewLine}T", tv.Text);
  3281. Assert.Equal (2, tv.Lines);
  3282. Assert.Equal (new Point (1, 1), tv.CursorPosition);
  3283. Assert.True (tv.IsDirty);
  3284. Assert.True (tv.ProcessKey (new KeyEvent (Key.w, new KeyModifiers ())));
  3285. Assert.Equal ($"One{Environment.NewLine}Tw", tv.Text);
  3286. Assert.Equal (2, tv.Lines);
  3287. Assert.Equal (new Point (2, 1), tv.CursorPosition);
  3288. Assert.True (tv.IsDirty);
  3289. Assert.True (tv.ProcessKey (new KeyEvent (Key.o, new KeyModifiers ())));
  3290. Assert.Equal ($"One{Environment.NewLine}Two", tv.Text);
  3291. Assert.Equal (2, tv.Lines);
  3292. Assert.Equal (new Point (3, 1), tv.CursorPosition);
  3293. Assert.True (tv.IsDirty);
  3294. Assert.True (tv.ProcessKey (new KeyEvent (Key.Enter, new KeyModifiers ())));
  3295. Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}", tv.Text);
  3296. Assert.Equal (3, tv.Lines);
  3297. Assert.Equal (new Point (0, 2), tv.CursorPosition);
  3298. Assert.True (tv.IsDirty);
  3299. Assert.True (tv.ProcessKey (new KeyEvent (Key.T, new KeyModifiers ())));
  3300. Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}T", tv.Text);
  3301. Assert.Equal (3, tv.Lines);
  3302. Assert.Equal (new Point (1, 2), tv.CursorPosition);
  3303. Assert.True (tv.IsDirty);
  3304. Assert.True (tv.ProcessKey (new KeyEvent (Key.h, new KeyModifiers ())));
  3305. Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}Th", tv.Text);
  3306. Assert.Equal (3, tv.Lines);
  3307. Assert.Equal (new Point (2, 2), tv.CursorPosition);
  3308. Assert.True (tv.IsDirty);
  3309. Assert.True (tv.ProcessKey (new KeyEvent (Key.r, new KeyModifiers ())));
  3310. Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}Thr", tv.Text);
  3311. Assert.Equal (3, tv.Lines);
  3312. Assert.Equal (new Point (3, 2), tv.CursorPosition);
  3313. Assert.True (tv.IsDirty);
  3314. Assert.True (tv.ProcessKey (new KeyEvent (Key.e, new KeyModifiers ())));
  3315. Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}Thre", tv.Text);
  3316. Assert.Equal (3, tv.Lines);
  3317. Assert.Equal (new Point (4, 2), tv.CursorPosition);
  3318. Assert.True (tv.IsDirty);
  3319. Assert.True (tv.ProcessKey (new KeyEvent (Key.e, new KeyModifiers ())));
  3320. Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}Three", tv.Text);
  3321. Assert.Equal (3, tv.Lines);
  3322. Assert.Equal (new Point (5, 2), tv.CursorPosition);
  3323. Assert.True (tv.IsDirty);
  3324. Assert.True (tv.ProcessKey (new KeyEvent (Key.Enter, new KeyModifiers ())));
  3325. Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}Three{Environment.NewLine}", tv.Text);
  3326. Assert.Equal (4, tv.Lines);
  3327. Assert.Equal (new Point (0, 3), tv.CursorPosition);
  3328. Assert.True (tv.IsDirty);
  3329. // Undoing
  3330. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  3331. Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}Three", tv.Text);
  3332. Assert.Equal (3, tv.Lines);
  3333. Assert.Equal (new Point (5, 2), tv.CursorPosition);
  3334. Assert.True (tv.IsDirty);
  3335. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  3336. Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}Thre", tv.Text);
  3337. Assert.Equal (3, tv.Lines);
  3338. Assert.Equal (new Point (4, 2), tv.CursorPosition);
  3339. Assert.True (tv.IsDirty);
  3340. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  3341. Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}Thr", tv.Text);
  3342. Assert.Equal (3, tv.Lines);
  3343. Assert.Equal (new Point (3, 2), tv.CursorPosition);
  3344. Assert.True (tv.IsDirty);
  3345. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  3346. Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}Th", tv.Text);
  3347. Assert.Equal (3, tv.Lines);
  3348. Assert.Equal (new Point (2, 2), tv.CursorPosition);
  3349. Assert.True (tv.IsDirty);
  3350. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  3351. Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}T", tv.Text);
  3352. Assert.Equal (3, tv.Lines);
  3353. Assert.Equal (new Point (1, 2), tv.CursorPosition);
  3354. Assert.True (tv.IsDirty);
  3355. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  3356. Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}", tv.Text);
  3357. Assert.Equal (3, tv.Lines);
  3358. Assert.Equal (new Point (0, 2), tv.CursorPosition);
  3359. Assert.True (tv.IsDirty);
  3360. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  3361. Assert.Equal ($"One{Environment.NewLine}Two", tv.Text);
  3362. Assert.Equal (2, tv.Lines);
  3363. Assert.Equal (new Point (3, 1), tv.CursorPosition);
  3364. Assert.True (tv.IsDirty);
  3365. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  3366. Assert.Equal ($"One{Environment.NewLine}Tw", tv.Text);
  3367. Assert.Equal (2, tv.Lines);
  3368. Assert.Equal (new Point (2, 1), tv.CursorPosition);
  3369. Assert.True (tv.IsDirty);
  3370. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  3371. Assert.Equal ($"One{Environment.NewLine}T", tv.Text);
  3372. Assert.Equal (2, tv.Lines);
  3373. Assert.Equal (new Point (1, 1), tv.CursorPosition);
  3374. Assert.True (tv.IsDirty);
  3375. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  3376. Assert.Equal ($"One{Environment.NewLine}", tv.Text);
  3377. Assert.Equal (2, tv.Lines);
  3378. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  3379. Assert.True (tv.IsDirty);
  3380. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  3381. Assert.Equal ($"One", tv.Text);
  3382. Assert.Equal (1, tv.Lines);
  3383. Assert.Equal (new Point (3, 0), tv.CursorPosition);
  3384. Assert.True (tv.IsDirty);
  3385. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  3386. Assert.Equal ($"On", tv.Text);
  3387. Assert.Equal (1, tv.Lines);
  3388. Assert.Equal (new Point (2, 0), tv.CursorPosition);
  3389. Assert.True (tv.IsDirty);
  3390. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  3391. Assert.Equal ($"O", tv.Text);
  3392. Assert.Equal (1, tv.Lines);
  3393. Assert.Equal (new Point (1, 0), tv.CursorPosition);
  3394. Assert.True (tv.IsDirty);
  3395. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  3396. Assert.Equal ($"", tv.Text);
  3397. Assert.Equal (1, tv.Lines);
  3398. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  3399. Assert.False (tv.IsDirty);
  3400. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  3401. Assert.Equal ($"", tv.Text);
  3402. Assert.Equal (1, tv.Lines);
  3403. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  3404. Assert.False (tv.IsDirty);
  3405. // Redoing
  3406. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  3407. Assert.Equal ($"O", tv.Text);
  3408. Assert.Equal (1, tv.Lines);
  3409. Assert.Equal (new Point (1, 0), tv.CursorPosition);
  3410. Assert.True (tv.IsDirty);
  3411. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  3412. Assert.Equal ($"On", tv.Text);
  3413. Assert.Equal (1, tv.Lines);
  3414. Assert.Equal (new Point (2, 0), tv.CursorPosition);
  3415. Assert.True (tv.IsDirty);
  3416. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  3417. Assert.Equal ($"One", tv.Text);
  3418. Assert.Equal (1, tv.Lines);
  3419. Assert.Equal (new Point (3, 0), tv.CursorPosition);
  3420. Assert.True (tv.IsDirty);
  3421. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  3422. Assert.Equal ($"One{Environment.NewLine}", tv.Text);
  3423. Assert.Equal (2, tv.Lines);
  3424. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  3425. Assert.True (tv.IsDirty);
  3426. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  3427. Assert.Equal ($"One{Environment.NewLine}T", tv.Text);
  3428. Assert.Equal (2, tv.Lines);
  3429. Assert.Equal (new Point (1, 1), tv.CursorPosition);
  3430. Assert.True (tv.IsDirty);
  3431. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  3432. Assert.Equal ($"One{Environment.NewLine}Tw", tv.Text);
  3433. Assert.Equal (2, tv.Lines);
  3434. Assert.Equal (new Point (2, 1), tv.CursorPosition);
  3435. Assert.True (tv.IsDirty);
  3436. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  3437. Assert.Equal ($"One{Environment.NewLine}Two", tv.Text);
  3438. Assert.Equal (2, tv.Lines);
  3439. Assert.Equal (new Point (3, 1), tv.CursorPosition);
  3440. Assert.True (tv.IsDirty);
  3441. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  3442. Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}", tv.Text);
  3443. Assert.Equal (3, tv.Lines);
  3444. Assert.Equal (new Point (0, 2), tv.CursorPosition);
  3445. Assert.True (tv.IsDirty);
  3446. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  3447. Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}T", tv.Text);
  3448. Assert.Equal (3, tv.Lines);
  3449. Assert.Equal (new Point (1, 2), tv.CursorPosition);
  3450. Assert.True (tv.IsDirty);
  3451. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  3452. Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}Th", tv.Text);
  3453. Assert.Equal (3, tv.Lines);
  3454. Assert.Equal (new Point (2, 2), tv.CursorPosition);
  3455. Assert.True (tv.IsDirty);
  3456. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  3457. Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}Thr", tv.Text);
  3458. Assert.Equal (3, tv.Lines);
  3459. Assert.Equal (new Point (3, 2), tv.CursorPosition);
  3460. Assert.True (tv.IsDirty);
  3461. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  3462. Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}Thre", tv.Text);
  3463. Assert.Equal (3, tv.Lines);
  3464. Assert.Equal (new Point (4, 2), tv.CursorPosition);
  3465. Assert.True (tv.IsDirty);
  3466. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  3467. Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}Three", tv.Text);
  3468. Assert.Equal (3, tv.Lines);
  3469. Assert.Equal (new Point (5, 2), tv.CursorPosition);
  3470. Assert.True (tv.IsDirty);
  3471. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  3472. Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}Three{Environment.NewLine}", tv.Text);
  3473. Assert.Equal (4, tv.Lines);
  3474. Assert.Equal (new Point (0, 3), tv.CursorPosition);
  3475. Assert.True (tv.IsDirty);
  3476. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  3477. Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}Three{Environment.NewLine}", tv.Text);
  3478. Assert.Equal (4, tv.Lines);
  3479. Assert.Equal (new Point (0, 3), tv.CursorPosition);
  3480. Assert.True (tv.IsDirty);
  3481. }
  3482. [Fact]
  3483. [AutoInitShutdown]
  3484. public void HistoryText_Undo_Redo_Multi_Line_Selected_With_Empty_Text ()
  3485. {
  3486. var tv = new TextView () {
  3487. Width = 10,
  3488. Height = 2
  3489. };
  3490. var top = Application.Top;
  3491. top.Add (tv);
  3492. Application.Begin (top);
  3493. Assert.Equal ("", tv.Text);
  3494. Assert.Equal (1, tv.Lines);
  3495. Assert.Equal (Point.Empty, tv.CursorPosition);
  3496. Assert.False (tv.IsDirty);
  3497. Assert.True (tv.ProcessKey (new KeyEvent (Key.O, new KeyModifiers ())));
  3498. Assert.Equal ("O", tv.Text);
  3499. Assert.Equal (1, tv.Lines);
  3500. Assert.Equal (new Point (1, 0), tv.CursorPosition);
  3501. Assert.True (tv.IsDirty);
  3502. Assert.True (tv.ProcessKey (new KeyEvent (Key.n, new KeyModifiers ())));
  3503. Assert.Equal ("On", tv.Text);
  3504. Assert.Equal (1, tv.Lines);
  3505. Assert.Equal (new Point (2, 0), tv.CursorPosition);
  3506. Assert.True (tv.IsDirty);
  3507. Assert.True (tv.ProcessKey (new KeyEvent (Key.e, new KeyModifiers ())));
  3508. Assert.Equal ("One", tv.Text);
  3509. Assert.Equal (1, tv.Lines);
  3510. Assert.Equal (new Point (3, 0), tv.CursorPosition);
  3511. Assert.True (tv.IsDirty);
  3512. Assert.True (tv.ProcessKey (new KeyEvent (Key.Enter, new KeyModifiers ())));
  3513. Assert.Equal ($"One{Environment.NewLine}", tv.Text);
  3514. Assert.Equal (2, tv.Lines);
  3515. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  3516. Assert.True (tv.IsDirty);
  3517. Assert.True (tv.ProcessKey (new KeyEvent (Key.T, new KeyModifiers ())));
  3518. Assert.Equal ($"One{Environment.NewLine}T", tv.Text);
  3519. Assert.Equal (2, tv.Lines);
  3520. Assert.Equal (new Point (1, 1), tv.CursorPosition);
  3521. Assert.True (tv.IsDirty);
  3522. Assert.True (tv.ProcessKey (new KeyEvent (Key.w, new KeyModifiers ())));
  3523. Assert.Equal ($"One{Environment.NewLine}Tw", tv.Text);
  3524. Assert.Equal (2, tv.Lines);
  3525. Assert.Equal (new Point (2, 1), tv.CursorPosition);
  3526. Assert.True (tv.IsDirty);
  3527. Assert.True (tv.ProcessKey (new KeyEvent (Key.o, new KeyModifiers ())));
  3528. Assert.Equal ($"One{Environment.NewLine}Two", tv.Text);
  3529. Assert.Equal (2, tv.Lines);
  3530. Assert.Equal (new Point (3, 1), tv.CursorPosition);
  3531. Assert.True (tv.IsDirty);
  3532. Assert.True (tv.ProcessKey (new KeyEvent (Key.Enter, new KeyModifiers ())));
  3533. Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}", tv.Text);
  3534. Assert.Equal (3, tv.Lines);
  3535. Assert.Equal (new Point (0, 2), tv.CursorPosition);
  3536. Assert.True (tv.IsDirty);
  3537. Assert.True (tv.ProcessKey (new KeyEvent (Key.T, new KeyModifiers ())));
  3538. Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}T", tv.Text);
  3539. Assert.Equal (3, tv.Lines);
  3540. Assert.Equal (new Point (1, 2), tv.CursorPosition);
  3541. Assert.True (tv.IsDirty);
  3542. Assert.True (tv.ProcessKey (new KeyEvent (Key.h, new KeyModifiers ())));
  3543. Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}Th", tv.Text);
  3544. Assert.Equal (3, tv.Lines);
  3545. Assert.Equal (new Point (2, 2), tv.CursorPosition);
  3546. Assert.True (tv.IsDirty);
  3547. Assert.True (tv.ProcessKey (new KeyEvent (Key.r, new KeyModifiers ())));
  3548. Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}Thr", tv.Text);
  3549. Assert.Equal (3, tv.Lines);
  3550. Assert.Equal (new Point (3, 2), tv.CursorPosition);
  3551. Assert.True (tv.IsDirty);
  3552. Assert.True (tv.ProcessKey (new KeyEvent (Key.e, new KeyModifiers ())));
  3553. Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}Thre", tv.Text);
  3554. Assert.Equal (3, tv.Lines);
  3555. Assert.Equal (new Point (4, 2), tv.CursorPosition);
  3556. Assert.True (tv.IsDirty);
  3557. Assert.True (tv.ProcessKey (new KeyEvent (Key.e, new KeyModifiers ())));
  3558. Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}Three", tv.Text);
  3559. Assert.Equal (3, tv.Lines);
  3560. Assert.Equal (new Point (5, 2), tv.CursorPosition);
  3561. Assert.True (tv.IsDirty);
  3562. Assert.True (tv.ProcessKey (new KeyEvent (Key.Enter, new KeyModifiers ())));
  3563. Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}Three{Environment.NewLine}", tv.Text);
  3564. Assert.Equal (4, tv.Lines);
  3565. Assert.Equal (new Point (0, 3), tv.CursorPosition);
  3566. Assert.True (tv.IsDirty);
  3567. tv.SelectionStartColumn = 0;
  3568. tv.SelectionStartRow = 0;
  3569. tv.CursorPosition = new Point (0, 1);
  3570. Assert.Equal (3 + Environment.NewLine.Length, tv.SelectedLength);
  3571. Assert.True (tv.ProcessKey (new KeyEvent (Key.D1, new KeyModifiers ())));
  3572. Assert.Equal ($"1Two{Environment.NewLine}Three{Environment.NewLine}", tv.Text);
  3573. Assert.Equal (3, tv.Lines);
  3574. Assert.Equal (new Point (1, 0), tv.CursorPosition);
  3575. Assert.Equal (0, tv.SelectedLength);
  3576. Assert.True (tv.IsDirty);
  3577. tv.SelectionStartColumn = 1;
  3578. tv.SelectionStartRow = 0;
  3579. tv.CursorPosition = new Point (1, 1);
  3580. Assert.Equal (4 + Environment.NewLine.Length, tv.SelectedLength);
  3581. Assert.True (tv.ProcessKey (new KeyEvent (Key.D2, new KeyModifiers ())));
  3582. Assert.Equal ($"12hree{Environment.NewLine}", tv.Text);
  3583. Assert.Equal (2, tv.Lines);
  3584. Assert.Equal (new Point (2, 0), tv.CursorPosition);
  3585. Assert.Equal (0, tv.SelectedLength);
  3586. Assert.True (tv.IsDirty);
  3587. // Undoing
  3588. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  3589. Assert.Equal ($"1Two{Environment.NewLine}Three{Environment.NewLine}", tv.Text);
  3590. Assert.Equal (3, tv.Lines);
  3591. Assert.Equal (new Point (1, 1), tv.CursorPosition);
  3592. Assert.Equal (0, tv.SelectedLength);
  3593. Assert.True (tv.IsDirty);
  3594. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  3595. Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}Three{Environment.NewLine}", tv.Text);
  3596. Assert.Equal (4, tv.Lines);
  3597. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  3598. Assert.Equal (0, tv.SelectedLength);
  3599. Assert.True (tv.IsDirty);
  3600. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  3601. Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}Three", tv.Text);
  3602. Assert.Equal (3, tv.Lines);
  3603. Assert.Equal (new Point (5, 2), tv.CursorPosition);
  3604. Assert.Equal (0, tv.SelectedLength);
  3605. Assert.True (tv.IsDirty);
  3606. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  3607. Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}Thre", tv.Text);
  3608. Assert.Equal (3, tv.Lines);
  3609. Assert.Equal (new Point (4, 2), tv.CursorPosition);
  3610. Assert.True (tv.IsDirty);
  3611. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  3612. Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}Thr", tv.Text);
  3613. Assert.Equal (3, tv.Lines);
  3614. Assert.Equal (new Point (3, 2), tv.CursorPosition);
  3615. Assert.Equal (0, tv.SelectedLength);
  3616. Assert.True (tv.IsDirty);
  3617. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  3618. Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}Th", tv.Text);
  3619. Assert.Equal (3, tv.Lines);
  3620. Assert.Equal (new Point (2, 2), tv.CursorPosition);
  3621. Assert.Equal (0, tv.SelectedLength);
  3622. Assert.True (tv.IsDirty);
  3623. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  3624. Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}T", tv.Text);
  3625. Assert.Equal (3, tv.Lines);
  3626. Assert.Equal (new Point (1, 2), tv.CursorPosition);
  3627. Assert.Equal (0, tv.SelectedLength);
  3628. Assert.True (tv.IsDirty);
  3629. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  3630. Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}", tv.Text);
  3631. Assert.Equal (3, tv.Lines);
  3632. Assert.Equal (new Point (0, 2), tv.CursorPosition);
  3633. Assert.Equal (0, tv.SelectedLength);
  3634. Assert.True (tv.IsDirty);
  3635. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  3636. Assert.Equal ($"One{Environment.NewLine}Two", tv.Text);
  3637. Assert.Equal (2, tv.Lines);
  3638. Assert.Equal (new Point (3, 1), tv.CursorPosition);
  3639. Assert.Equal (0, tv.SelectedLength);
  3640. Assert.True (tv.IsDirty);
  3641. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  3642. Assert.Equal ($"One{Environment.NewLine}Tw", tv.Text);
  3643. Assert.Equal (2, tv.Lines);
  3644. Assert.Equal (new Point (2, 1), tv.CursorPosition);
  3645. Assert.Equal (0, tv.SelectedLength);
  3646. Assert.True (tv.IsDirty);
  3647. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  3648. Assert.Equal ($"One{Environment.NewLine}T", tv.Text);
  3649. Assert.Equal (2, tv.Lines);
  3650. Assert.Equal (new Point (1, 1), tv.CursorPosition);
  3651. Assert.Equal (0, tv.SelectedLength);
  3652. Assert.True (tv.IsDirty);
  3653. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  3654. Assert.Equal ($"One{Environment.NewLine}", tv.Text);
  3655. Assert.Equal (2, tv.Lines);
  3656. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  3657. Assert.Equal (0, tv.SelectedLength);
  3658. Assert.True (tv.IsDirty);
  3659. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  3660. Assert.Equal ($"One", tv.Text);
  3661. Assert.Equal (1, tv.Lines);
  3662. Assert.Equal (new Point (3, 0), tv.CursorPosition);
  3663. Assert.Equal (0, tv.SelectedLength);
  3664. Assert.True (tv.IsDirty);
  3665. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  3666. Assert.Equal ($"On", tv.Text);
  3667. Assert.Equal (1, tv.Lines);
  3668. Assert.Equal (new Point (2, 0), tv.CursorPosition);
  3669. Assert.Equal (0, tv.SelectedLength);
  3670. Assert.True (tv.IsDirty);
  3671. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  3672. Assert.Equal ($"O", tv.Text);
  3673. Assert.Equal (1, tv.Lines);
  3674. Assert.Equal (new Point (1, 0), tv.CursorPosition);
  3675. Assert.Equal (0, tv.SelectedLength);
  3676. Assert.True (tv.IsDirty);
  3677. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  3678. Assert.Equal ($"", tv.Text);
  3679. Assert.Equal (1, tv.Lines);
  3680. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  3681. Assert.Equal (0, tv.SelectedLength);
  3682. Assert.False (tv.IsDirty);
  3683. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  3684. Assert.Equal ($"", tv.Text);
  3685. Assert.Equal (1, tv.Lines);
  3686. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  3687. Assert.Equal (0, tv.SelectedLength);
  3688. Assert.False (tv.IsDirty);
  3689. // Redoing
  3690. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  3691. Assert.Equal ($"O", tv.Text);
  3692. Assert.Equal (1, tv.Lines);
  3693. Assert.Equal (new Point (1, 0), tv.CursorPosition);
  3694. Assert.Equal (0, tv.SelectedLength);
  3695. Assert.True (tv.IsDirty);
  3696. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  3697. Assert.Equal ($"On", tv.Text);
  3698. Assert.Equal (1, tv.Lines);
  3699. Assert.Equal (new Point (2, 0), tv.CursorPosition);
  3700. Assert.Equal (0, tv.SelectedLength);
  3701. Assert.True (tv.IsDirty);
  3702. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  3703. Assert.Equal ($"One", tv.Text);
  3704. Assert.Equal (1, tv.Lines);
  3705. Assert.Equal (new Point (3, 0), tv.CursorPosition);
  3706. Assert.Equal (0, tv.SelectedLength);
  3707. Assert.True (tv.IsDirty);
  3708. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  3709. Assert.Equal ($"One{Environment.NewLine}", tv.Text);
  3710. Assert.Equal (2, tv.Lines);
  3711. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  3712. Assert.Equal (0, tv.SelectedLength);
  3713. Assert.True (tv.IsDirty);
  3714. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  3715. Assert.Equal ($"One{Environment.NewLine}T", tv.Text);
  3716. Assert.Equal (2, tv.Lines);
  3717. Assert.Equal (new Point (1, 1), tv.CursorPosition);
  3718. Assert.Equal (0, tv.SelectedLength);
  3719. Assert.True (tv.IsDirty);
  3720. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  3721. Assert.Equal ($"One{Environment.NewLine}Tw", tv.Text);
  3722. Assert.Equal (2, tv.Lines);
  3723. Assert.Equal (new Point (2, 1), tv.CursorPosition);
  3724. Assert.Equal (0, tv.SelectedLength);
  3725. Assert.True (tv.IsDirty);
  3726. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  3727. Assert.Equal ($"One{Environment.NewLine}Two", tv.Text);
  3728. Assert.Equal (2, tv.Lines);
  3729. Assert.Equal (new Point (3, 1), tv.CursorPosition);
  3730. Assert.Equal (0, tv.SelectedLength);
  3731. Assert.True (tv.IsDirty);
  3732. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  3733. Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}", tv.Text);
  3734. Assert.Equal (3, tv.Lines);
  3735. Assert.Equal (new Point (0, 2), tv.CursorPosition);
  3736. Assert.Equal (0, tv.SelectedLength);
  3737. Assert.True (tv.IsDirty);
  3738. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  3739. Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}T", tv.Text);
  3740. Assert.Equal (3, tv.Lines);
  3741. Assert.Equal (new Point (1, 2), tv.CursorPosition);
  3742. Assert.Equal (0, tv.SelectedLength);
  3743. Assert.True (tv.IsDirty);
  3744. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  3745. Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}Th", tv.Text);
  3746. Assert.Equal (3, tv.Lines);
  3747. Assert.Equal (new Point (2, 2), tv.CursorPosition);
  3748. Assert.Equal (0, tv.SelectedLength);
  3749. Assert.True (tv.IsDirty);
  3750. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  3751. Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}Thr", tv.Text);
  3752. Assert.Equal (3, tv.Lines);
  3753. Assert.Equal (new Point (3, 2), tv.CursorPosition);
  3754. Assert.Equal (0, tv.SelectedLength);
  3755. Assert.True (tv.IsDirty);
  3756. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  3757. Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}Thre", tv.Text);
  3758. Assert.Equal (3, tv.Lines);
  3759. Assert.Equal (new Point (4, 2), tv.CursorPosition);
  3760. Assert.Equal (0, tv.SelectedLength);
  3761. Assert.True (tv.IsDirty);
  3762. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  3763. Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}Three", tv.Text);
  3764. Assert.Equal (3, tv.Lines);
  3765. Assert.Equal (new Point (5, 2), tv.CursorPosition);
  3766. Assert.Equal (0, tv.SelectedLength);
  3767. Assert.True (tv.IsDirty);
  3768. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  3769. Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}Three{Environment.NewLine}", tv.Text);
  3770. Assert.Equal (4, tv.Lines);
  3771. Assert.Equal (new Point (0, 3), tv.CursorPosition);
  3772. Assert.Equal (0, tv.SelectedLength);
  3773. Assert.True (tv.IsDirty);
  3774. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  3775. Assert.Equal ($"1Two{Environment.NewLine}Three{Environment.NewLine}", tv.Text);
  3776. Assert.Equal (3, tv.Lines);
  3777. Assert.Equal (new Point (1, 0), tv.CursorPosition);
  3778. Assert.Equal (0, tv.SelectedLength);
  3779. Assert.True (tv.IsDirty);
  3780. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  3781. Assert.Equal ($"12hree{Environment.NewLine}", tv.Text);
  3782. Assert.Equal (2, tv.Lines);
  3783. Assert.Equal (new Point (2, 0), tv.CursorPosition);
  3784. Assert.Equal (0, tv.SelectedLength);
  3785. Assert.True (tv.IsDirty);
  3786. }
  3787. [Fact]
  3788. [AutoInitShutdown]
  3789. public void HistoryText_Undo_Redo_Multi_Line_Selected_InsertText_Twice_On_Same_Line ()
  3790. {
  3791. var text = "One\nTwo\nThree";
  3792. var tv = new TextView () {
  3793. Width = 10,
  3794. Height = 2,
  3795. Text = text
  3796. };
  3797. var top = Application.Top;
  3798. top.Add (tv);
  3799. Application.Begin (top);
  3800. Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}Three", tv.Text);
  3801. Assert.Equal (3, tv.Lines);
  3802. Assert.Equal (Point.Empty, tv.CursorPosition);
  3803. Assert.False (tv.IsDirty);
  3804. tv.SelectionStartColumn = 0;
  3805. tv.SelectionStartRow = 0;
  3806. tv.CursorPosition = new Point (0, 1);
  3807. Assert.Equal (3 + Environment.NewLine.Length, tv.SelectedLength);
  3808. Assert.True (tv.ProcessKey (new KeyEvent (Key.D1, new KeyModifiers ())));
  3809. Assert.Equal ($"1Two{Environment.NewLine}Three", tv.Text);
  3810. Assert.Equal (new Point (1, 0), tv.CursorPosition);
  3811. Assert.Equal (0, tv.SelectedLength);
  3812. Assert.True (tv.IsDirty);
  3813. tv.SelectionStartColumn = 1;
  3814. tv.SelectionStartRow = 0;
  3815. tv.CursorPosition = new Point (1, 1);
  3816. Assert.Equal (4 + Environment.NewLine.Length, tv.SelectedLength);
  3817. Assert.True (tv.ProcessKey (new KeyEvent (Key.D2, new KeyModifiers ())));
  3818. Assert.Equal ("12hree", tv.Text);
  3819. Assert.Equal (new Point (2, 0), tv.CursorPosition);
  3820. Assert.Equal (0, tv.SelectedLength);
  3821. Assert.True (tv.IsDirty);
  3822. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  3823. Assert.Equal ($"1Two{Environment.NewLine}Three", tv.Text);
  3824. Assert.Equal (new Point (1, 1), tv.CursorPosition);
  3825. Assert.Equal (0, tv.SelectedLength);
  3826. Assert.True (tv.IsDirty);
  3827. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  3828. Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}Three", tv.Text);
  3829. Assert.Equal (3, tv.Lines);
  3830. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  3831. Assert.Equal (0, tv.SelectedLength);
  3832. Assert.False (tv.IsDirty);
  3833. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  3834. Assert.Equal ($"1Two{Environment.NewLine}Three", tv.Text);
  3835. Assert.Equal (new Point (1, 0), tv.CursorPosition);
  3836. Assert.Equal (0, tv.SelectedLength);
  3837. Assert.True (tv.IsDirty);
  3838. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  3839. Assert.Equal ("12hree", tv.Text);
  3840. Assert.Equal (new Point (2, 0), tv.CursorPosition);
  3841. Assert.Equal (0, tv.SelectedLength);
  3842. Assert.True (tv.IsDirty);
  3843. }
  3844. [Fact]
  3845. [AutoInitShutdown]
  3846. public void HistoryText_Undo_Redo_Multi_Line_Selected_InsertText_Twice_On_Same_Line_With_End_Line ()
  3847. {
  3848. var text = "One\nTwo\nThree\n";
  3849. var tv = new TextView () {
  3850. Width = 10,
  3851. Height = 2,
  3852. Text = text
  3853. };
  3854. var top = Application.Top;
  3855. top.Add (tv);
  3856. Application.Begin (top);
  3857. Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}Three{Environment.NewLine}", tv.Text);
  3858. Assert.Equal (4, tv.Lines);
  3859. Assert.Equal (Point.Empty, tv.CursorPosition);
  3860. Assert.False (tv.IsDirty);
  3861. tv.SelectionStartColumn = 0;
  3862. tv.SelectionStartRow = 0;
  3863. tv.CursorPosition = new Point (0, 1);
  3864. Assert.Equal (3 + Environment.NewLine.Length, tv.SelectedLength);
  3865. Assert.True (tv.ProcessKey (new KeyEvent (Key.D1, new KeyModifiers ())));
  3866. Assert.Equal ($"1Two{Environment.NewLine}Three{Environment.NewLine}", tv.Text);
  3867. Assert.Equal (new Point (1, 0), tv.CursorPosition);
  3868. Assert.Equal (0, tv.SelectedLength);
  3869. Assert.True (tv.IsDirty);
  3870. tv.SelectionStartColumn = 1;
  3871. tv.SelectionStartRow = 0;
  3872. tv.CursorPosition = new Point (1, 1);
  3873. Assert.Equal (4 + Environment.NewLine.Length, tv.SelectedLength);
  3874. Assert.True (tv.ProcessKey (new KeyEvent (Key.D2, new KeyModifiers ())));
  3875. Assert.Equal ($"12hree{Environment.NewLine}", tv.Text);
  3876. Assert.Equal (new Point (2, 0), tv.CursorPosition);
  3877. Assert.Equal (0, tv.SelectedLength);
  3878. Assert.True (tv.IsDirty);
  3879. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  3880. Assert.Equal ($"1Two{Environment.NewLine}Three{Environment.NewLine}", tv.Text);
  3881. Assert.Equal (new Point (1, 1), tv.CursorPosition);
  3882. Assert.Equal (0, tv.SelectedLength);
  3883. Assert.True (tv.IsDirty);
  3884. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  3885. Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}Three{Environment.NewLine}", tv.Text);
  3886. Assert.Equal (4, tv.Lines);
  3887. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  3888. Assert.Equal (0, tv.SelectedLength);
  3889. Assert.False (tv.IsDirty);
  3890. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  3891. Assert.Equal ($"1Two{Environment.NewLine}Three{Environment.NewLine}", tv.Text);
  3892. Assert.Equal (new Point (1, 0), tv.CursorPosition);
  3893. Assert.Equal (0, tv.SelectedLength);
  3894. Assert.True (tv.IsDirty);
  3895. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  3896. Assert.Equal ($"12hree{Environment.NewLine}", tv.Text);
  3897. Assert.Equal (new Point (2, 0), tv.CursorPosition);
  3898. Assert.Equal (0, tv.SelectedLength);
  3899. Assert.True (tv.IsDirty);
  3900. }
  3901. [Fact]
  3902. public void HistoryText_IsDirty_HasHistoryChanges ()
  3903. {
  3904. var tv = new TextView ();
  3905. Assert.Equal ("", tv.Text);
  3906. Assert.Equal (1, tv.Lines);
  3907. Assert.Equal (Point.Empty, tv.CursorPosition);
  3908. Assert.False (tv.IsDirty);
  3909. Assert.False (tv.HasHistoryChanges);
  3910. Assert.True (tv.ProcessKey (new KeyEvent (Key.D1, new KeyModifiers ())));
  3911. Assert.Equal ("1", tv.Text);
  3912. Assert.Equal (1, tv.Lines);
  3913. Assert.Equal (new Point (1, 0), tv.CursorPosition);
  3914. Assert.True (tv.IsDirty);
  3915. Assert.True (tv.HasHistoryChanges);
  3916. Assert.True (tv.ProcessKey (new KeyEvent (Key.Enter, new KeyModifiers ())));
  3917. Assert.Equal ($"1{Environment.NewLine}", tv.Text);
  3918. Assert.Equal (2, tv.Lines);
  3919. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  3920. Assert.True (tv.IsDirty);
  3921. Assert.True (tv.HasHistoryChanges);
  3922. Assert.True (tv.ProcessKey (new KeyEvent (Key.D2, new KeyModifiers ())));
  3923. Assert.Equal ($"1{Environment.NewLine}2", tv.Text);
  3924. Assert.Equal (2, tv.Lines);
  3925. Assert.Equal (new Point (1, 1), tv.CursorPosition);
  3926. Assert.True (tv.IsDirty);
  3927. Assert.True (tv.HasHistoryChanges);
  3928. Assert.True (tv.ProcessKey (new KeyEvent (Key.Backspace, new KeyModifiers ())));
  3929. Assert.Equal ($"1{Environment.NewLine}", tv.Text);
  3930. Assert.Equal (2, tv.Lines);
  3931. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  3932. Assert.True (tv.IsDirty);
  3933. Assert.True (tv.HasHistoryChanges);
  3934. Assert.True (tv.ProcessKey (new KeyEvent (Key.Backspace, new KeyModifiers ())));
  3935. Assert.Equal ($"1", tv.Text);
  3936. Assert.Equal (1, tv.Lines);
  3937. Assert.Equal (new Point (1, 0), tv.CursorPosition);
  3938. Assert.True (tv.IsDirty);
  3939. Assert.True (tv.HasHistoryChanges);
  3940. Assert.True (tv.ProcessKey (new KeyEvent (Key.Backspace, new KeyModifiers ())));
  3941. Assert.Equal ($"", tv.Text);
  3942. Assert.Equal (1, tv.Lines);
  3943. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  3944. // IsDirty cannot be based on HasHistoryChanges because HasHistoryChanges is greater than 0
  3945. // The only way is comparing from the original text
  3946. Assert.False (tv.IsDirty);
  3947. // Still true because HasHistoryChanges is greater than 0
  3948. Assert.True (tv.HasHistoryChanges);
  3949. }
  3950. [Fact]
  3951. public void HistoryText_Undo_Redo_Multi_Line_Selected_DeleteCharLeft_All ()
  3952. {
  3953. var text = "This is the first line.\nThis is the second line.\nThis is the third line.";
  3954. var tv = new TextView () { Text = text };
  3955. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  3956. Assert.Equal (3, tv.Lines);
  3957. Assert.Equal (Point.Empty, tv.CursorPosition);
  3958. Assert.False (tv.IsDirty);
  3959. Assert.False (tv.HasHistoryChanges);
  3960. Assert.True (tv.ProcessKey (new KeyEvent (Key.End | Key.CtrlMask | Key.ShiftMask, new KeyModifiers ())));
  3961. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  3962. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.SelectedText);
  3963. Assert.Equal (3, tv.Lines);
  3964. Assert.Equal (new Point (23, 2), tv.CursorPosition);
  3965. Assert.Equal (70 + Environment.NewLine.Length * 2, tv.SelectedLength);
  3966. Assert.False (tv.IsDirty);
  3967. Assert.False (tv.HasHistoryChanges);
  3968. Assert.True (tv.ProcessKey (new KeyEvent (Key.Backspace, new KeyModifiers ())));
  3969. Assert.Equal ("", tv.Text);
  3970. Assert.Equal ("", tv.SelectedText);
  3971. Assert.Equal (1, tv.Lines);
  3972. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  3973. Assert.Equal (0, tv.SelectedLength);
  3974. Assert.True (tv.IsDirty);
  3975. Assert.True (tv.HasHistoryChanges);
  3976. // Undo
  3977. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  3978. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  3979. Assert.Equal ("", tv.SelectedText);
  3980. Assert.Equal (3, tv.Lines);
  3981. Assert.Equal (new Point (23, 2), tv.CursorPosition);
  3982. Assert.Equal (0, tv.SelectedLength);
  3983. Assert.False (tv.IsDirty);
  3984. Assert.True (tv.HasHistoryChanges);
  3985. // Redo
  3986. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  3987. Assert.Equal ("", tv.Text);
  3988. Assert.Equal ("", tv.SelectedText);
  3989. Assert.Equal (1, tv.Lines);
  3990. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  3991. Assert.Equal (0, tv.SelectedLength);
  3992. Assert.True (tv.IsDirty);
  3993. Assert.True (tv.HasHistoryChanges);
  3994. }
  3995. [Fact]
  3996. public void HistoryText_Undo_Redo_Multi_Line_Selected_DeleteCharRight_All ()
  3997. {
  3998. var text = "This is the first line.\nThis is the second line.\nThis is the third line.";
  3999. var tv = new TextView () { Text = text };
  4000. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  4001. Assert.Equal (3, tv.Lines);
  4002. Assert.Equal (Point.Empty, tv.CursorPosition);
  4003. Assert.False (tv.IsDirty);
  4004. Assert.False (tv.HasHistoryChanges);
  4005. Assert.True (tv.ProcessKey (new KeyEvent (Key.End | Key.CtrlMask | Key.ShiftMask, new KeyModifiers ())));
  4006. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  4007. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.SelectedText);
  4008. Assert.Equal (3, tv.Lines);
  4009. Assert.Equal (new Point (23, 2), tv.CursorPosition);
  4010. Assert.Equal (70 + Environment.NewLine.Length * 2, tv.SelectedLength);
  4011. Assert.False (tv.IsDirty);
  4012. Assert.False (tv.HasHistoryChanges);
  4013. Assert.True (tv.ProcessKey (new KeyEvent (Key.DeleteChar, new KeyModifiers ())));
  4014. Assert.Equal ("", tv.Text);
  4015. Assert.Equal ("", tv.SelectedText);
  4016. Assert.Equal (1, tv.Lines);
  4017. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  4018. Assert.Equal (0, tv.SelectedLength);
  4019. Assert.True (tv.IsDirty);
  4020. Assert.True (tv.HasHistoryChanges);
  4021. // Undo
  4022. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  4023. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  4024. Assert.Equal ("", tv.SelectedText);
  4025. Assert.Equal (3, tv.Lines);
  4026. Assert.Equal (new Point (23, 2), tv.CursorPosition);
  4027. Assert.Equal (0, tv.SelectedLength);
  4028. Assert.False (tv.IsDirty);
  4029. Assert.True (tv.HasHistoryChanges);
  4030. // Redo
  4031. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  4032. Assert.Equal ("", tv.Text);
  4033. Assert.Equal ("", tv.SelectedText);
  4034. Assert.Equal (1, tv.Lines);
  4035. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  4036. Assert.Equal (0, tv.SelectedLength);
  4037. Assert.True (tv.IsDirty);
  4038. Assert.True (tv.HasHistoryChanges);
  4039. }
  4040. [Fact]
  4041. [AutoInitShutdown]
  4042. public void HistoryText_Undo_Redo_Copy_Without_Selection_Multi_Line_Paste ()
  4043. {
  4044. var text = "This is the first line.\nThis is the second line.\nThis is the third line.";
  4045. var tv = new TextView () { Text = text };
  4046. tv.CursorPosition = new Point (23, 0);
  4047. Assert.True (tv.ProcessKey (new KeyEvent (Key.C | Key.CtrlMask, new KeyModifiers ())));
  4048. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  4049. Assert.Equal ("", tv.SelectedText);
  4050. Assert.Equal ("This is the first line.", Clipboard.Contents);
  4051. Assert.Equal (3, tv.Lines);
  4052. Assert.Equal (new Point (23, 0), tv.CursorPosition);
  4053. Assert.True (tv.ProcessKey (new KeyEvent (Key.Y | Key.CtrlMask, new KeyModifiers ())));
  4054. 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);
  4055. Assert.Equal (4, tv.Lines);
  4056. Assert.Equal (new Point (23, 1), tv.CursorPosition);
  4057. // Undo
  4058. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, 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 (3, tv.Lines);
  4061. Assert.Equal (new Point (23, 0), tv.CursorPosition);
  4062. // Redo
  4063. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  4064. 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);
  4065. Assert.Equal (4, tv.Lines);
  4066. Assert.Equal (new Point (23, 1), tv.CursorPosition);
  4067. }
  4068. [Fact]
  4069. [AutoInitShutdown]
  4070. public void HistoryText_Undo_Redo_Simple_Copy_Multi_Line_Selected_Paste ()
  4071. {
  4072. var text = "This is the first line.\nThis is the second line.\nThis is the third line.";
  4073. var tv = new TextView () { Text = text };
  4074. tv.SelectionStartColumn = 12;
  4075. tv.CursorPosition = new Point (17, 0);
  4076. Assert.True (tv.ProcessKey (new KeyEvent (Key.C | Key.CtrlMask, new KeyModifiers ())));
  4077. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  4078. Assert.Equal ("first", tv.SelectedText);
  4079. Assert.Equal (3, tv.Lines);
  4080. Assert.Equal (new Point (17, 0), tv.CursorPosition);
  4081. tv.SelectionStartColumn = 12;
  4082. tv.CursorPosition = new Point (11, 1);
  4083. Assert.True (tv.ProcessKey (new KeyEvent (Key.Y | Key.CtrlMask, new KeyModifiers ())));
  4084. Assert.Equal ($"This is the first second line.{Environment.NewLine}This is the third line.", tv.Text);
  4085. Assert.Equal (2, tv.Lines);
  4086. Assert.Equal (new Point (17, 0), tv.CursorPosition);
  4087. // Undo
  4088. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  4089. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  4090. Assert.Equal (3, tv.Lines);
  4091. Assert.Equal (new Point (12, 0), tv.CursorPosition);
  4092. // Redo
  4093. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  4094. Assert.Equal ($"This is the first second line.{Environment.NewLine}This is the third line.", tv.Text);
  4095. Assert.Equal (2, tv.Lines);
  4096. Assert.Equal (new Point (17, 0), tv.CursorPosition);
  4097. }
  4098. [Fact]
  4099. [AutoInitShutdown]
  4100. public void HistoryText_Undo_Redo_Multi_Line_Selected_Copy_Simple_Paste_Starting_On_Space ()
  4101. {
  4102. var text = "This is the first line.\nThis is the second line.\nThis is the third line.";
  4103. var tv = new TextView () { Text = text };
  4104. tv.SelectionStartColumn = 12;
  4105. tv.CursorPosition = new Point (18, 1);
  4106. Assert.True (tv.ProcessKey (new KeyEvent (Key.C | Key.CtrlMask, new KeyModifiers ())));
  4107. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  4108. Assert.Equal ($"first line.{Environment.NewLine}This is the second", tv.SelectedText);
  4109. Assert.Equal (3, tv.Lines);
  4110. Assert.Equal (new Point (18, 1), tv.CursorPosition);
  4111. tv.Selecting = false;
  4112. Assert.True (tv.ProcessKey (new KeyEvent (Key.Y | Key.CtrlMask, new KeyModifiers ())));
  4113. 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);
  4114. Assert.Equal (4, tv.Lines);
  4115. Assert.Equal (new Point (18, 2), tv.CursorPosition);
  4116. // Undo
  4117. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  4118. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  4119. Assert.Equal (3, tv.Lines);
  4120. Assert.Equal (new Point (18, 1), tv.CursorPosition);
  4121. // Redo
  4122. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  4123. 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);
  4124. Assert.Equal (4, tv.Lines);
  4125. Assert.Equal (new Point (18, 2), tv.CursorPosition);
  4126. }
  4127. [Fact]
  4128. [AutoInitShutdown]
  4129. public void HistoryText_Undo_Redo_Multi_Line_Selected_Copy_Simple_Paste_Starting_On_Letter ()
  4130. {
  4131. var text = "This is the first line.\nThis is the second line.\nThis is the third line.";
  4132. var tv = new TextView () { Text = text };
  4133. tv.SelectionStartColumn = 12;
  4134. tv.CursorPosition = new Point (18, 1);
  4135. Assert.True (tv.ProcessKey (new KeyEvent (Key.C | Key.CtrlMask, new KeyModifiers ())));
  4136. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  4137. Assert.Equal ($"first line.{Environment.NewLine}This is the second", tv.SelectedText);
  4138. Assert.Equal (3, tv.Lines);
  4139. Assert.Equal (new Point (18, 1), tv.CursorPosition);
  4140. tv.Selecting = false;
  4141. tv.CursorPosition = new Point (17, 1);
  4142. Assert.True (tv.ProcessKey (new KeyEvent (Key.Y | Key.CtrlMask, new KeyModifiers ())));
  4143. 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);
  4144. Assert.Equal (4, tv.Lines);
  4145. Assert.Equal (new Point (18, 2), tv.CursorPosition);
  4146. // Undo
  4147. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  4148. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  4149. Assert.Equal (3, tv.Lines);
  4150. Assert.Equal (new Point (17, 1), tv.CursorPosition);
  4151. // Redo
  4152. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  4153. 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);
  4154. Assert.Equal (4, tv.Lines);
  4155. Assert.Equal (new Point (18, 2), tv.CursorPosition);
  4156. }
  4157. [Fact]
  4158. [AutoInitShutdown]
  4159. public void HistoryText_Undo_Redo_Empty_Copy_Without_Selection_Multi_Line_Selected_Paste ()
  4160. {
  4161. var text = "\nThis is the first line.\nThis is the second line.";
  4162. var tv = new TextView () { Text = text };
  4163. Assert.True (tv.ProcessKey (new KeyEvent (Key.C | Key.CtrlMask, new KeyModifiers ())));
  4164. Assert.Equal ($"{Environment.NewLine}This is the first line.{Environment.NewLine}This is the second line.", tv.Text);
  4165. Assert.Equal ("", tv.SelectedText);
  4166. Assert.Equal (3, tv.Lines);
  4167. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  4168. Assert.True (tv.ProcessKey (new KeyEvent (Key.Y | Key.CtrlMask, new KeyModifiers ())));
  4169. Assert.Equal ($"{Environment.NewLine}{Environment.NewLine}This is the first line.{Environment.NewLine}This is the second line.", tv.Text);
  4170. Assert.Equal (4, tv.Lines);
  4171. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  4172. // Undo
  4173. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  4174. Assert.Equal ($"{Environment.NewLine}This is the first line.{Environment.NewLine}This is the second line.", tv.Text);
  4175. Assert.Equal (3, tv.Lines);
  4176. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  4177. // Redo
  4178. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  4179. Assert.Equal ($"{Environment.NewLine}{Environment.NewLine}This is the first line.{Environment.NewLine}This is the second line.", tv.Text);
  4180. Assert.Equal (4, tv.Lines);
  4181. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  4182. }
  4183. [Fact]
  4184. [AutoInitShutdown]
  4185. public void HistoryText_Undo_Redo_Setting_Clipboard_Multi_Line_Selected_Paste ()
  4186. {
  4187. var text = "This is the first line.\nThis is the second line.";
  4188. var tv = new TextView () { Text = text };
  4189. Clipboard.Contents = "Inserted\nNewLine";
  4190. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.", tv.Text);
  4191. Assert.Equal ("", tv.SelectedText);
  4192. Assert.Equal (2, tv.Lines);
  4193. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  4194. Assert.True (tv.ProcessKey (new KeyEvent (Key.Y | Key.CtrlMask, new KeyModifiers ())));
  4195. Assert.Equal ($"Inserted{Environment.NewLine}NewLineThis is the first line.{Environment.NewLine}This is the second line.", tv.Text);
  4196. Assert.Equal (3, tv.Lines);
  4197. Assert.Equal (new Point (7, 1), tv.CursorPosition);
  4198. // Undo
  4199. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  4200. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.", tv.Text);
  4201. Assert.Equal (2, tv.Lines);
  4202. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  4203. // Redo
  4204. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  4205. Assert.Equal ($"Inserted{Environment.NewLine}NewLineThis is the first line.{Environment.NewLine}This is the second line.", tv.Text);
  4206. Assert.Equal (3, tv.Lines);
  4207. Assert.Equal (new Point (7, 1), tv.CursorPosition);
  4208. }
  4209. [Fact]
  4210. [AutoInitShutdown]
  4211. public void HistoryText_Undo_Redo_Cut_Multi_Line_Selected_Paste ()
  4212. {
  4213. var text = "This is the first line.\nThis is the second line.\nThis is the third line.";
  4214. var tv = new TextView () { Text = text };
  4215. tv.SelectionStartColumn = 12;
  4216. tv.CursorPosition = new Point (17, 0);
  4217. Assert.True (tv.ProcessKey (new KeyEvent (Key.W | Key.CtrlMask, new KeyModifiers ())));
  4218. Assert.Equal ($"This is the line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  4219. Assert.Equal ("", tv.SelectedText);
  4220. Assert.Equal (3, tv.Lines);
  4221. Assert.Equal (new Point (12, 0), tv.CursorPosition);
  4222. tv.SelectionStartColumn = 12;
  4223. tv.CursorPosition = new Point (11, 1);
  4224. Assert.True (tv.ProcessKey (new KeyEvent (Key.Y | Key.CtrlMask, new KeyModifiers ())));
  4225. Assert.Equal ($"This is the first second line.{Environment.NewLine}This is the third line.", tv.Text);
  4226. Assert.Equal (2, tv.Lines);
  4227. Assert.Equal (new Point (17, 0), tv.CursorPosition);
  4228. // Undo
  4229. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  4230. Assert.Equal ($"This is the line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  4231. Assert.Equal (3, tv.Lines);
  4232. Assert.Equal (new Point (12, 0), tv.CursorPosition);
  4233. // Redo
  4234. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  4235. Assert.Equal ($"This is the first second line.{Environment.NewLine}This is the third line.", tv.Text);
  4236. Assert.Equal (2, tv.Lines);
  4237. Assert.Equal (new Point (17, 0), tv.CursorPosition);
  4238. }
  4239. [Fact]
  4240. [AutoInitShutdown]
  4241. public void HistoryText_Undo_Redo_Cut_Simple_Paste_Starting ()
  4242. {
  4243. var text = "This is the first line.\nThis is the second line.\nThis is the third line.";
  4244. var tv = new TextView () { Text = text };
  4245. tv.SelectionStartColumn = 12;
  4246. tv.CursorPosition = new Point (18, 1);
  4247. Assert.True (tv.ProcessKey (new KeyEvent (Key.W | Key.CtrlMask, new KeyModifiers ())));
  4248. Assert.Equal ($"This is the line.{Environment.NewLine}This is the third line.", tv.Text);
  4249. Assert.Equal ("", tv.SelectedText);
  4250. Assert.Equal (2, tv.Lines);
  4251. Assert.Equal (new Point (12, 0), tv.CursorPosition);
  4252. tv.Selecting = false;
  4253. Assert.True (tv.ProcessKey (new KeyEvent (Key.Y | Key.CtrlMask, new KeyModifiers ())));
  4254. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  4255. Assert.Equal (3, tv.Lines);
  4256. Assert.Equal (new Point (18, 1), tv.CursorPosition);
  4257. // Undo
  4258. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  4259. Assert.Equal ($"This is the line.{Environment.NewLine}This is the third line.", tv.Text);
  4260. Assert.Equal (2, tv.Lines);
  4261. Assert.Equal (new Point (12, 0), tv.CursorPosition);
  4262. // Redo
  4263. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  4264. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  4265. Assert.Equal (3, tv.Lines);
  4266. Assert.Equal (new Point (18, 1), tv.CursorPosition);
  4267. }
  4268. [Fact]
  4269. [AutoInitShutdown]
  4270. public void HistoryText_Undo_Redo_Cut_Multi_Line_Another_Selected_Paste ()
  4271. {
  4272. var text = "This is the first line.\nThis is the second line.\nThis is the third line.";
  4273. var tv = new TextView () { Text = text };
  4274. tv.SelectionStartColumn = 12;
  4275. tv.CursorPosition = new Point (17, 0);
  4276. Assert.True (tv.ProcessKey (new KeyEvent (Key.W | Key.CtrlMask, new KeyModifiers ())));
  4277. Assert.Equal ($"This is the line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  4278. Assert.Equal ("", tv.SelectedText);
  4279. Assert.Equal (3, tv.Lines);
  4280. Assert.Equal (new Point (12, 0), tv.CursorPosition);
  4281. tv.SelectionStartColumn = 12;
  4282. tv.SelectionStartRow = 1;
  4283. tv.CursorPosition = new Point (18, 1);
  4284. Assert.True (tv.ProcessKey (new KeyEvent (Key.Y | Key.CtrlMask, new KeyModifiers ())));
  4285. Assert.Equal ($"This is the line.{Environment.NewLine}This is the first line.{Environment.NewLine}This is the third line.", tv.Text);
  4286. Assert.Equal (3, tv.Lines);
  4287. Assert.Equal (new Point (17, 1), tv.CursorPosition);
  4288. // Undo
  4289. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  4290. Assert.Equal ($"This is the line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  4291. Assert.Equal (3, tv.Lines);
  4292. Assert.Equal (new Point (12, 1), tv.CursorPosition);
  4293. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  4294. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  4295. Assert.Equal (3, tv.Lines);
  4296. Assert.Equal (new Point (12, 0), tv.CursorPosition);
  4297. // Redo
  4298. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  4299. Assert.Equal ($"This is the line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  4300. Assert.Equal (3, tv.Lines);
  4301. Assert.Equal (new Point (12, 0), tv.CursorPosition);
  4302. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  4303. Assert.Equal ($"This is the line.{Environment.NewLine}This is the first line.{Environment.NewLine}This is the third line.", tv.Text);
  4304. Assert.Equal (3, tv.Lines);
  4305. Assert.Equal (new Point (17, 1), tv.CursorPosition);
  4306. }
  4307. [Fact]
  4308. public void HistoryText_Undo_Redo_KillWordBackward ()
  4309. {
  4310. var text = "First line.\nSecond line.";
  4311. var tv = new TextView () { Text = text };
  4312. Assert.True (tv.ProcessKey (new KeyEvent (Key.End | Key.CtrlMask, new KeyModifiers ())));
  4313. Assert.Equal ($"First line.{Environment.NewLine}Second line.", tv.Text);
  4314. Assert.Equal ("", tv.SelectedText);
  4315. Assert.Equal (2, tv.Lines);
  4316. Assert.Equal (new Point (12, 1), tv.CursorPosition);
  4317. Assert.True (tv.ProcessKey (new KeyEvent (Key.Backspace | Key.CtrlMask, new KeyModifiers ())));
  4318. Assert.Equal ($"First line.{Environment.NewLine}Second ", tv.Text);
  4319. Assert.Equal ("", tv.SelectedText);
  4320. Assert.Equal (2, tv.Lines);
  4321. Assert.Equal (new Point (7, 1), tv.CursorPosition);
  4322. Assert.True (tv.ProcessKey (new KeyEvent (Key.Backspace | Key.CtrlMask, new KeyModifiers ())));
  4323. Assert.Equal ($"First line.{Environment.NewLine}", tv.Text);
  4324. Assert.Equal ("", tv.SelectedText);
  4325. Assert.Equal (2, tv.Lines);
  4326. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  4327. Assert.True (tv.ProcessKey (new KeyEvent (Key.Backspace | Key.CtrlMask, new KeyModifiers ())));
  4328. Assert.Equal ("First line.", tv.Text);
  4329. Assert.Equal ("", tv.SelectedText);
  4330. Assert.Equal (1, tv.Lines);
  4331. Assert.Equal (new Point (11, 0), tv.CursorPosition);
  4332. Assert.True (tv.ProcessKey (new KeyEvent (Key.Backspace | Key.CtrlMask, new KeyModifiers ())));
  4333. Assert.Equal ("First ", tv.Text);
  4334. Assert.Equal ("", tv.SelectedText);
  4335. Assert.Equal (1, tv.Lines);
  4336. Assert.Equal (new Point (6, 0), tv.CursorPosition);
  4337. Assert.True (tv.ProcessKey (new KeyEvent (Key.Backspace | Key.CtrlMask, new KeyModifiers ())));
  4338. Assert.Equal ("", tv.Text);
  4339. Assert.Equal ("", tv.SelectedText);
  4340. Assert.Equal (1, tv.Lines);
  4341. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  4342. // Undo
  4343. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  4344. Assert.Equal ("First ", tv.Text);
  4345. Assert.Equal (1, tv.Lines);
  4346. Assert.Equal (new Point (6, 0), tv.CursorPosition);
  4347. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  4348. Assert.Equal ("First line.", tv.Text);
  4349. Assert.Equal (1, tv.Lines);
  4350. Assert.Equal (new Point (11, 0), tv.CursorPosition);
  4351. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  4352. Assert.Equal ($"First line.{Environment.NewLine}", tv.Text);
  4353. Assert.Equal (2, tv.Lines);
  4354. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  4355. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  4356. Assert.Equal ($"First line.{Environment.NewLine}Second ", tv.Text);
  4357. Assert.Equal (2, tv.Lines);
  4358. Assert.Equal (new Point (7, 1), tv.CursorPosition);
  4359. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  4360. Assert.Equal ($"First line.{Environment.NewLine}Second line.", tv.Text);
  4361. Assert.Equal (2, tv.Lines);
  4362. Assert.Equal (new Point (12, 1), tv.CursorPosition);
  4363. // Redo
  4364. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  4365. Assert.Equal ($"First line.{Environment.NewLine}Second ", tv.Text);
  4366. Assert.Equal (2, tv.Lines);
  4367. Assert.Equal (new Point (7, 1), tv.CursorPosition);
  4368. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  4369. Assert.Equal ($"First line.{Environment.NewLine}", tv.Text);
  4370. Assert.Equal (2, tv.Lines);
  4371. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  4372. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  4373. Assert.Equal ("First line.", tv.Text);
  4374. Assert.Equal (1, tv.Lines);
  4375. Assert.Equal (new Point (11, 0), tv.CursorPosition);
  4376. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  4377. Assert.Equal ("First ", tv.Text);
  4378. Assert.Equal (1, tv.Lines);
  4379. Assert.Equal (new Point (6, 0), tv.CursorPosition);
  4380. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  4381. Assert.Equal ("", tv.Text);
  4382. Assert.Equal (1, tv.Lines);
  4383. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  4384. }
  4385. [Fact]
  4386. public void HistoryText_Undo_Redo_KillWordForward ()
  4387. {
  4388. var text = "First line.\nSecond line.";
  4389. var tv = new TextView () { Text = text };
  4390. Assert.True (tv.ProcessKey (new KeyEvent (Key.DeleteChar | Key.CtrlMask, new KeyModifiers ())));
  4391. Assert.Equal ($"line.{Environment.NewLine}Second line.", tv.Text);
  4392. Assert.Equal ("", tv.SelectedText);
  4393. Assert.Equal (2, tv.Lines);
  4394. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  4395. Assert.True (tv.ProcessKey (new KeyEvent (Key.DeleteChar | Key.CtrlMask, new KeyModifiers ())));
  4396. Assert.Equal ($"{Environment.NewLine}Second line.", tv.Text);
  4397. Assert.Equal (2, tv.Lines);
  4398. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  4399. Assert.True (tv.ProcessKey (new KeyEvent (Key.DeleteChar | Key.CtrlMask, new KeyModifiers ())));
  4400. Assert.Equal ("Second line.", tv.Text);
  4401. Assert.Equal (1, tv.Lines);
  4402. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  4403. Assert.True (tv.ProcessKey (new KeyEvent (Key.DeleteChar | Key.CtrlMask, new KeyModifiers ())));
  4404. Assert.Equal ("line.", tv.Text);
  4405. Assert.Equal (1, tv.Lines);
  4406. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  4407. Assert.True (tv.ProcessKey (new KeyEvent (Key.DeleteChar | Key.CtrlMask, new KeyModifiers ())));
  4408. Assert.Equal ("", tv.Text);
  4409. Assert.Equal (1, tv.Lines);
  4410. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  4411. // Undo
  4412. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  4413. Assert.Equal ("line.", tv.Text);
  4414. Assert.Equal (1, tv.Lines);
  4415. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  4416. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  4417. Assert.Equal ("Second line.", tv.Text);
  4418. Assert.Equal (1, tv.Lines);
  4419. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  4420. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  4421. Assert.Equal ($"{Environment.NewLine}Second line.", tv.Text);
  4422. Assert.Equal (2, tv.Lines);
  4423. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  4424. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  4425. Assert.Equal ($"line.{Environment.NewLine}Second line.", tv.Text);
  4426. Assert.Equal (2, tv.Lines);
  4427. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  4428. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  4429. Assert.Equal ($"First line.{Environment.NewLine}Second line.", tv.Text);
  4430. Assert.Equal (2, tv.Lines);
  4431. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  4432. // Redo
  4433. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  4434. Assert.Equal ($"line.{Environment.NewLine}Second line.", tv.Text);
  4435. Assert.Equal (2, tv.Lines);
  4436. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  4437. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  4438. Assert.Equal ($"{Environment.NewLine}Second line.", tv.Text);
  4439. Assert.Equal (2, tv.Lines);
  4440. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  4441. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  4442. Assert.Equal ("Second line.", tv.Text);
  4443. Assert.Equal (1, tv.Lines);
  4444. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  4445. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  4446. Assert.Equal ("line.", tv.Text);
  4447. Assert.Equal (1, tv.Lines);
  4448. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  4449. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  4450. Assert.Equal ("", tv.Text);
  4451. Assert.Equal (1, tv.Lines);
  4452. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  4453. }
  4454. [Fact]
  4455. [AutoInitShutdown]
  4456. public void HistoryText_Undo_Redo_KillToStartOfLine ()
  4457. {
  4458. var text = "First line.\nSecond line.";
  4459. var tv = new TextView () { Text = text };
  4460. Assert.True (tv.ProcessKey (new KeyEvent (Key.End | Key.CtrlMask, new KeyModifiers ())));
  4461. Assert.Equal ($"First line.{Environment.NewLine}Second line.", tv.Text);
  4462. Assert.Equal ("", tv.SelectedText);
  4463. Assert.Equal (2, tv.Lines);
  4464. Assert.Equal (new Point (12, 1), tv.CursorPosition);
  4465. Assert.True (tv.ProcessKey (new KeyEvent (Key.K | Key.AltMask, new KeyModifiers ())));
  4466. Assert.Equal ($"First line.{Environment.NewLine}", tv.Text);
  4467. Assert.Equal ("", tv.SelectedText);
  4468. Assert.Equal ("Second line.", Clipboard.Contents);
  4469. Assert.Equal (2, tv.Lines);
  4470. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  4471. Assert.True (tv.ProcessKey (new KeyEvent (Key.K | Key.AltMask, new KeyModifiers ())));
  4472. Assert.Equal ("First line.", tv.Text);
  4473. Assert.Equal ("", tv.SelectedText);
  4474. Assert.Equal ($"Second line.{Environment.NewLine}", Clipboard.Contents);
  4475. Assert.Equal (1, tv.Lines);
  4476. Assert.Equal (new Point (11, 0), tv.CursorPosition);
  4477. Assert.True (tv.ProcessKey (new KeyEvent (Key.K | Key.AltMask, new KeyModifiers ())));
  4478. Assert.Equal ("", tv.Text);
  4479. Assert.Equal ("", tv.SelectedText);
  4480. Assert.Equal ($"Second line.{Environment.NewLine}First line.", Clipboard.Contents);
  4481. Assert.Equal (1, tv.Lines);
  4482. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  4483. // Undo
  4484. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  4485. Assert.Equal ("First line.", tv.Text);
  4486. Assert.Equal (1, tv.Lines);
  4487. Assert.Equal (new Point (11, 0), tv.CursorPosition);
  4488. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  4489. Assert.Equal ($"First line.{Environment.NewLine}", tv.Text);
  4490. Assert.Equal (2, tv.Lines);
  4491. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  4492. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  4493. Assert.Equal ($"First line.{Environment.NewLine}Second line.", tv.Text);
  4494. Assert.Equal (2, tv.Lines);
  4495. Assert.Equal (new Point (12, 1), tv.CursorPosition);
  4496. // Redo
  4497. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  4498. Assert.Equal ($"First line.{Environment.NewLine}", tv.Text);
  4499. Assert.Equal (2, tv.Lines);
  4500. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  4501. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  4502. Assert.Equal ($"First line.", tv.Text);
  4503. Assert.Equal (1, tv.Lines);
  4504. Assert.Equal (new Point (11, 0), tv.CursorPosition);
  4505. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | 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. }
  4510. [Fact]
  4511. [AutoInitShutdown]
  4512. public void HistoryText_Undo_Redo_KillToEndOfLine ()
  4513. {
  4514. var text = "First line.\nSecond line.";
  4515. var tv = new TextView () { Text = text };
  4516. Assert.True (tv.ProcessKey (new KeyEvent (Key.K | Key.CtrlMask, new KeyModifiers ())));
  4517. Assert.Equal ($"{Environment.NewLine}Second line.", tv.Text);
  4518. Assert.Equal ("", tv.SelectedText);
  4519. Assert.Equal ("First line.", Clipboard.Contents);
  4520. Assert.Equal (2, tv.Lines);
  4521. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  4522. Assert.True (tv.ProcessKey (new KeyEvent (Key.K | Key.CtrlMask, new KeyModifiers ())));
  4523. Assert.Equal ("Second line.", tv.Text);
  4524. Assert.Equal ("", tv.SelectedText);
  4525. Assert.Equal ($"First line.{Environment.NewLine}", Clipboard.Contents);
  4526. Assert.Equal (1, tv.Lines);
  4527. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  4528. Assert.True (tv.ProcessKey (new KeyEvent (Key.K | Key.CtrlMask, new KeyModifiers ())));
  4529. Assert.Equal ("", tv.Text);
  4530. Assert.Equal ("", tv.SelectedText);
  4531. Assert.Equal ($"First line.{Environment.NewLine}Second line.", Clipboard.Contents);
  4532. Assert.Equal (1, tv.Lines);
  4533. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  4534. // Undo
  4535. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  4536. Assert.Equal ("Second line.", tv.Text);
  4537. Assert.Equal (1, tv.Lines);
  4538. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  4539. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  4540. Assert.Equal ($"{Environment.NewLine}Second line.", tv.Text);
  4541. Assert.Equal (2, tv.Lines);
  4542. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  4543. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  4544. Assert.Equal ($"First line.{Environment.NewLine}Second line.", tv.Text);
  4545. Assert.Equal (2, tv.Lines);
  4546. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  4547. // Redo
  4548. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  4549. Assert.Equal ($"{Environment.NewLine}Second line.", tv.Text);
  4550. Assert.Equal (2, tv.Lines);
  4551. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  4552. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  4553. Assert.Equal ("Second line.", tv.Text);
  4554. Assert.Equal (1, tv.Lines);
  4555. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  4556. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  4557. Assert.Equal ("", tv.Text);
  4558. Assert.Equal (1, tv.Lines);
  4559. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  4560. }
  4561. [Fact]
  4562. public void HistoryText_Undo_Redo_Changing_On_Middle_Clear_History_Forwards ()
  4563. {
  4564. var tv = new TextView ();
  4565. Assert.True (tv.ProcessKey (new KeyEvent (Key.D1, new KeyModifiers ())));
  4566. Assert.Equal ("1", tv.Text);
  4567. Assert.Equal (1, tv.Lines);
  4568. Assert.Equal (new Point (1, 0), tv.CursorPosition);
  4569. Assert.True (tv.ProcessKey (new KeyEvent (Key.D2, new KeyModifiers ())));
  4570. Assert.Equal ("12", tv.Text);
  4571. Assert.Equal (1, tv.Lines);
  4572. Assert.Equal (new Point (2, 0), tv.CursorPosition);
  4573. Assert.True (tv.ProcessKey (new KeyEvent (Key.D3, new KeyModifiers ())));
  4574. Assert.Equal ("123", tv.Text);
  4575. Assert.Equal (1, tv.Lines);
  4576. Assert.Equal (new Point (3, 0), tv.CursorPosition);
  4577. // Undo
  4578. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  4579. Assert.Equal ("12", tv.Text);
  4580. Assert.Equal (1, tv.Lines);
  4581. Assert.Equal (new Point (2, 0), tv.CursorPosition);
  4582. Assert.True (tv.ProcessKey (new KeyEvent (Key.D4, new KeyModifiers ())));
  4583. Assert.Equal ("124", tv.Text);
  4584. Assert.Equal (1, tv.Lines);
  4585. Assert.Equal (new Point (3, 0), tv.CursorPosition);
  4586. // Redo
  4587. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  4588. Assert.Equal ("124", tv.Text);
  4589. Assert.Equal (1, tv.Lines);
  4590. Assert.Equal (new Point (3, 0), tv.CursorPosition);
  4591. }
  4592. [Fact]
  4593. public void HistoryText_Undo_Redo_Single_Line_Selected_Return ()
  4594. {
  4595. var text = "This is the first line.\nThis is the second line.\nThis is the third line.";
  4596. var tv = new TextView () { Text = text };
  4597. tv.SelectionStartColumn = 12;
  4598. tv.CursorPosition = new Point (17, 0);
  4599. Assert.True (tv.ProcessKey (new KeyEvent (Key.Enter, new KeyModifiers ())));
  4600. Assert.Equal ($"This is the {Environment.NewLine} line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  4601. Assert.Equal (4, tv.Lines);
  4602. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  4603. // Undo
  4604. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  4605. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  4606. Assert.Equal (3, tv.Lines);
  4607. Assert.Equal (new Point (17, 0), tv.CursorPosition);
  4608. Assert.False (tv.IsDirty);
  4609. // Redo
  4610. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  4611. Assert.Equal ($"This is the {Environment.NewLine} line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  4612. Assert.Equal (4, tv.Lines);
  4613. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  4614. // Undo
  4615. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  4616. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  4617. Assert.Equal (3, tv.Lines);
  4618. Assert.Equal (new Point (17, 0), tv.CursorPosition);
  4619. Assert.False (tv.IsDirty);
  4620. // Redo
  4621. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  4622. Assert.Equal ($"This is the {Environment.NewLine} line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  4623. Assert.Equal (4, tv.Lines);
  4624. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  4625. }
  4626. [Fact]
  4627. public void HistoryText_Undo_Redo_Two_Line_Selected_Return ()
  4628. {
  4629. var text = "This is the first line.\nThis is the second line.\nThis is the third line.";
  4630. var tv = new TextView () { Text = text };
  4631. tv.SelectionStartColumn = 12;
  4632. tv.CursorPosition = new Point (18, 1);
  4633. Assert.True (tv.ProcessKey (new KeyEvent (Key.Enter, new KeyModifiers ())));
  4634. Assert.Equal ($"This is the {Environment.NewLine} line.{Environment.NewLine}This is the third line.", tv.Text);
  4635. Assert.Equal (3, tv.Lines);
  4636. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  4637. // Undo
  4638. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  4639. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  4640. Assert.Equal (3, tv.Lines);
  4641. Assert.Equal (new Point (18, 1), tv.CursorPosition);
  4642. Assert.False (tv.IsDirty);
  4643. // Redo
  4644. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  4645. Assert.Equal ($"This is the {Environment.NewLine} line.{Environment.NewLine}This is the third line.", tv.Text);
  4646. Assert.Equal (3, tv.Lines);
  4647. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  4648. // Undo
  4649. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  4650. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  4651. Assert.Equal (3, tv.Lines);
  4652. Assert.Equal (new Point (18, 1), tv.CursorPosition);
  4653. Assert.False (tv.IsDirty);
  4654. // Redo
  4655. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  4656. Assert.Equal ($"This is the {Environment.NewLine} line.{Environment.NewLine}This is the third line.", tv.Text);
  4657. Assert.Equal (3, tv.Lines);
  4658. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  4659. }
  4660. [Fact]
  4661. public void HistoryText_Undo_Redo_Three_Line_Selected_Return ()
  4662. {
  4663. var text = "This is the first line.\nThis is the second line.\nThis is the third line.";
  4664. var tv = new TextView () { Text = text };
  4665. tv.SelectionStartColumn = 12;
  4666. tv.CursorPosition = new Point (17, 2);
  4667. Assert.True (tv.ProcessKey (new KeyEvent (Key.Enter, new KeyModifiers ())));
  4668. Assert.Equal ($"This is the {Environment.NewLine} line.", tv.Text);
  4669. Assert.Equal (2, tv.Lines);
  4670. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  4671. // Undo
  4672. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  4673. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  4674. Assert.Equal (3, tv.Lines);
  4675. Assert.Equal (new Point (17, 2), tv.CursorPosition);
  4676. Assert.False (tv.IsDirty);
  4677. // Redo
  4678. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  4679. Assert.Equal ($"This is the {Environment.NewLine} line.", tv.Text);
  4680. Assert.Equal (2, tv.Lines);
  4681. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  4682. // Undo
  4683. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  4684. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  4685. Assert.Equal (3, tv.Lines);
  4686. Assert.Equal (new Point (17, 2), tv.CursorPosition);
  4687. Assert.False (tv.IsDirty);
  4688. // Redo
  4689. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  4690. Assert.Equal ($"This is the {Environment.NewLine} line.", tv.Text);
  4691. Assert.Equal (2, tv.Lines);
  4692. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  4693. }
  4694. [Fact]
  4695. public void HistoryText_Undo_Redo_Single_Second_Line_Selected_Return ()
  4696. {
  4697. var text = "This is the first line.\nThis is the second line.\nThis is the third line.";
  4698. var tv = new TextView () { Text = text };
  4699. tv.SelectionStartColumn = 12;
  4700. tv.SelectionStartRow = 1;
  4701. tv.CursorPosition = new Point (18, 1);
  4702. Assert.True (tv.ProcessKey (new KeyEvent (Key.Enter, new KeyModifiers ())));
  4703. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the {Environment.NewLine} line.{Environment.NewLine}This is the third line.", tv.Text);
  4704. Assert.Equal (4, tv.Lines);
  4705. Assert.Equal (new Point (0, 2), tv.CursorPosition);
  4706. // Undo
  4707. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  4708. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  4709. Assert.Equal (3, tv.Lines);
  4710. Assert.Equal (new Point (18, 1), tv.CursorPosition);
  4711. Assert.False (tv.IsDirty);
  4712. // Redo
  4713. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  4714. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the {Environment.NewLine} line.{Environment.NewLine}This is the third line.", tv.Text);
  4715. Assert.Equal (4, tv.Lines);
  4716. Assert.Equal (new Point (0, 2), tv.CursorPosition);
  4717. // Undo
  4718. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  4719. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  4720. Assert.Equal (3, tv.Lines);
  4721. Assert.Equal (new Point (18, 1), tv.CursorPosition);
  4722. Assert.False (tv.IsDirty);
  4723. // Redo
  4724. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  4725. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the {Environment.NewLine} line.{Environment.NewLine}This is the third line.", tv.Text);
  4726. Assert.Equal (4, tv.Lines);
  4727. Assert.Equal (new Point (0, 2), tv.CursorPosition);
  4728. }
  4729. [Fact]
  4730. public void HistoryText_Undo_Redo_First_Line_Selected_Return_And_InsertText ()
  4731. {
  4732. var text = "This is the first line.\nThis is the second line.\nThis is the third line.";
  4733. var tv = new TextView () { Text = text };
  4734. tv.SelectionStartColumn = 12;
  4735. tv.CursorPosition = new Point (17, 0);
  4736. Assert.True (tv.ProcessKey (new KeyEvent (Key.Enter, new KeyModifiers ())));
  4737. Assert.Equal ($"This is the {Environment.NewLine} line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  4738. Assert.Equal (4, tv.Lines);
  4739. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  4740. Assert.True (tv.ProcessKey (new KeyEvent (Key.a, new KeyModifiers ())));
  4741. 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);
  4742. Assert.Equal (4, tv.Lines);
  4743. Assert.Equal (new Point (1, 1), tv.CursorPosition);
  4744. // Undo
  4745. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  4746. Assert.Equal ($"This is the {Environment.NewLine} line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  4747. Assert.Equal (4, tv.Lines);
  4748. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  4749. Assert.True (tv.IsDirty);
  4750. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  4751. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  4752. Assert.Equal (3, tv.Lines);
  4753. Assert.Equal (new Point (17, 0), tv.CursorPosition);
  4754. Assert.False (tv.IsDirty);
  4755. // Redo
  4756. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  4757. Assert.Equal ($"This is the {Environment.NewLine} line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  4758. Assert.Equal (4, tv.Lines);
  4759. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  4760. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  4761. 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);
  4762. Assert.Equal (4, tv.Lines);
  4763. Assert.Equal (new Point (1, 1), tv.CursorPosition);
  4764. // Undo
  4765. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  4766. Assert.Equal ($"This is the {Environment.NewLine} line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  4767. Assert.Equal (4, tv.Lines);
  4768. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  4769. Assert.True (tv.IsDirty);
  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, 0), 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.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  4778. Assert.Equal (4, tv.Lines);
  4779. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  4780. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  4781. 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);
  4782. Assert.Equal (4, tv.Lines);
  4783. Assert.Equal (new Point (1, 1), tv.CursorPosition);
  4784. }
  4785. [Fact]
  4786. public void HistoryText_Undo_Redo_Single_Second_Line_Selected_Return_And_InsertText ()
  4787. {
  4788. var text = "This is the first line.\nThis is the second line.\nThis is the third line.";
  4789. var tv = new TextView () { Text = text };
  4790. tv.SelectionStartColumn = 12;
  4791. tv.SelectionStartRow = 1;
  4792. tv.CursorPosition = new Point (18, 1);
  4793. Assert.True (tv.ProcessKey (new KeyEvent (Key.Enter, new KeyModifiers ())));
  4794. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the {Environment.NewLine} line.{Environment.NewLine}This is the third line.", tv.Text);
  4795. Assert.Equal (4, tv.Lines);
  4796. Assert.Equal (new Point (0, 2), tv.CursorPosition);
  4797. Assert.True (tv.ProcessKey (new KeyEvent (Key.a, new KeyModifiers ())));
  4798. 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);
  4799. Assert.Equal (4, tv.Lines);
  4800. Assert.Equal (new Point (1, 2), tv.CursorPosition);
  4801. // Undo
  4802. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  4803. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the {Environment.NewLine} line.{Environment.NewLine}This is the third line.", tv.Text);
  4804. Assert.Equal (4, tv.Lines);
  4805. Assert.Equal (new Point (0, 2), tv.CursorPosition);
  4806. Assert.True (tv.IsDirty);
  4807. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  4808. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  4809. Assert.Equal (3, tv.Lines);
  4810. Assert.Equal (new Point (18, 1), tv.CursorPosition);
  4811. Assert.False (tv.IsDirty);
  4812. // Redo
  4813. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  4814. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the {Environment.NewLine} line.{Environment.NewLine}This is the third line.", tv.Text);
  4815. Assert.Equal (4, tv.Lines);
  4816. Assert.Equal (new Point (0, 2), tv.CursorPosition);
  4817. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  4818. 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);
  4819. Assert.Equal (4, tv.Lines);
  4820. Assert.Equal (new Point (1, 2), tv.CursorPosition);
  4821. // Undo
  4822. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | 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. Assert.True (tv.IsDirty);
  4827. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  4828. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  4829. Assert.Equal (3, tv.Lines);
  4830. Assert.Equal (new Point (18, 1), tv.CursorPosition);
  4831. Assert.False (tv.IsDirty);
  4832. // Redo
  4833. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  4834. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the {Environment.NewLine} line.{Environment.NewLine}This is the third line.", tv.Text);
  4835. Assert.Equal (4, tv.Lines);
  4836. Assert.Equal (new Point (0, 2), tv.CursorPosition);
  4837. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  4838. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the {Environment.NewLine}a line.{Environment.NewLine}This is the third line.", tv.Text);
  4839. Assert.Equal (4, tv.Lines);
  4840. Assert.Equal (new Point (1, 2), tv.CursorPosition);
  4841. }
  4842. [Fact]
  4843. public void HistoryText_Undo_Redo_Multi_Line_Selected_All_Return_And_InsertText ()
  4844. {
  4845. var text = "This is the first line.\nThis is the second line.\nThis is the third line.";
  4846. var tv = new TextView () { Text = text };
  4847. Assert.True (tv.ProcessKey (new KeyEvent (Key.End | Key.CtrlMask | Key.ShiftMask, new KeyModifiers ())));
  4848. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  4849. Assert.Equal (3, tv.Lines);
  4850. Assert.Equal (new Point (23, 2), tv.CursorPosition);
  4851. Assert.True (tv.ProcessKey (new KeyEvent (Key.Enter, new KeyModifiers ())));
  4852. Assert.Equal ($"{Environment.NewLine}", tv.Text);
  4853. Assert.Equal (2, tv.Lines);
  4854. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  4855. Assert.True (tv.ProcessKey (new KeyEvent (Key.a, new KeyModifiers ())));
  4856. Assert.Equal ($"{Environment.NewLine}a", tv.Text);
  4857. Assert.Equal (2, tv.Lines);
  4858. Assert.Equal (new Point (1, 1), tv.CursorPosition);
  4859. // Undo
  4860. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  4861. Assert.Equal ($"{Environment.NewLine}", tv.Text);
  4862. Assert.Equal (2, tv.Lines);
  4863. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  4864. Assert.True (tv.IsDirty);
  4865. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  4866. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  4867. Assert.Equal (3, tv.Lines);
  4868. Assert.Equal (new Point (23, 2), tv.CursorPosition);
  4869. Assert.False (tv.IsDirty);
  4870. // Redo
  4871. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  4872. Assert.Equal ($"{Environment.NewLine}", tv.Text);
  4873. Assert.Equal (2, tv.Lines);
  4874. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  4875. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  4876. Assert.Equal ($"{Environment.NewLine}a", tv.Text);
  4877. Assert.Equal (2, tv.Lines);
  4878. Assert.Equal (new Point (1, 1), tv.CursorPosition);
  4879. // Undo
  4880. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  4881. Assert.Equal ($"{Environment.NewLine}", tv.Text);
  4882. Assert.Equal (2, tv.Lines);
  4883. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  4884. Assert.True (tv.IsDirty);
  4885. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  4886. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  4887. Assert.Equal (3, tv.Lines);
  4888. Assert.Equal (new Point (23, 2), tv.CursorPosition);
  4889. Assert.False (tv.IsDirty);
  4890. // Redo
  4891. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  4892. Assert.Equal ($"{Environment.NewLine}", tv.Text);
  4893. Assert.Equal (2, tv.Lines);
  4894. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  4895. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  4896. Assert.Equal ($"{Environment.NewLine}a", tv.Text);
  4897. Assert.Equal (2, tv.Lines);
  4898. Assert.Equal (new Point (1, 1), tv.CursorPosition);
  4899. }
  4900. [Fact]
  4901. public void HistoryText_Undo_Redo_Ending_With_Newline_Multi_Line_Selected_Almost_All_Return_And_InsertText ()
  4902. {
  4903. var text = "This is the first line.\nThis is the second line.\nThis is the third line.\n";
  4904. var tv = new TextView () { Text = text };
  4905. tv.SelectionStartColumn = 12;
  4906. tv.CursorPosition = new Point (12, 2);
  4907. Assert.True (tv.ProcessKey (new KeyEvent (Key.Enter, new KeyModifiers ())));
  4908. Assert.Equal ($"This is the {Environment.NewLine}third line.{Environment.NewLine}", tv.Text);
  4909. Assert.Equal (3, tv.Lines);
  4910. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  4911. Assert.True (tv.ProcessKey (new KeyEvent (Key.a, new KeyModifiers ())));
  4912. Assert.Equal ($"This is the {Environment.NewLine}athird line.{Environment.NewLine}", tv.Text);
  4913. Assert.Equal (3, tv.Lines);
  4914. Assert.Equal (new Point (1, 1), tv.CursorPosition);
  4915. // Undo
  4916. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  4917. Assert.Equal ($"This is the {Environment.NewLine}third line.{Environment.NewLine}", tv.Text);
  4918. Assert.Equal (3, tv.Lines);
  4919. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  4920. Assert.True (tv.IsDirty);
  4921. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  4922. 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);
  4923. Assert.Equal (4, tv.Lines);
  4924. Assert.Equal (new Point (12, 2), tv.CursorPosition);
  4925. Assert.False (tv.IsDirty);
  4926. // Redo
  4927. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  4928. Assert.Equal ($"This is the {Environment.NewLine}third line.{Environment.NewLine}", tv.Text);
  4929. Assert.Equal (3, tv.Lines);
  4930. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  4931. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  4932. Assert.Equal ($"This is the {Environment.NewLine}athird line.{Environment.NewLine}", tv.Text);
  4933. Assert.Equal (3, tv.Lines);
  4934. Assert.Equal (new Point (1, 1), tv.CursorPosition);
  4935. // Undo
  4936. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  4937. Assert.Equal ($"This is the {Environment.NewLine}third line.{Environment.NewLine}", tv.Text);
  4938. Assert.Equal (3, tv.Lines);
  4939. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  4940. Assert.True (tv.IsDirty);
  4941. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  4942. 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);
  4943. Assert.Equal (4, tv.Lines);
  4944. Assert.Equal (new Point (12, 2), tv.CursorPosition);
  4945. Assert.False (tv.IsDirty);
  4946. // Redo
  4947. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  4948. Assert.Equal ($"This is the {Environment.NewLine}third line.{Environment.NewLine}", tv.Text);
  4949. Assert.Equal (3, tv.Lines);
  4950. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  4951. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  4952. Assert.Equal ($"This is the {Environment.NewLine}athird line.{Environment.NewLine}", tv.Text);
  4953. Assert.Equal (3, tv.Lines);
  4954. Assert.Equal (new Point (1, 1), tv.CursorPosition);
  4955. }
  4956. [Fact]
  4957. public void HistoryText_Undo_Redo_Disabled_On_WordWrap ()
  4958. {
  4959. var text = "This is the first line.\nThis is the second line.\nThis is the third line.\n";
  4960. var tv = new TextView () { Width = 80, Height = 5, Text = text };
  4961. Assert.False (tv.WordWrap);
  4962. tv.WordWrap = true;
  4963. tv.SelectionStartColumn = 12;
  4964. tv.CursorPosition = new Point (12, 2);
  4965. Assert.True (tv.ProcessKey (new KeyEvent (Key.Enter, new KeyModifiers ())));
  4966. Assert.Equal ($"This is the {Environment.NewLine}third line.{Environment.NewLine}", tv.Text);
  4967. Assert.Equal (3, tv.Lines);
  4968. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  4969. Assert.True (tv.ProcessKey (new KeyEvent (Key.a, new KeyModifiers ())));
  4970. Assert.Equal ($"This is the {Environment.NewLine}athird line.{Environment.NewLine}", tv.Text);
  4971. Assert.Equal (3, tv.Lines);
  4972. Assert.Equal (new Point (1, 1), tv.CursorPosition);
  4973. // Undo is disabled
  4974. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  4975. Assert.Equal ($"This is the {Environment.NewLine}athird line.{Environment.NewLine}", tv.Text);
  4976. Assert.Equal (3, tv.Lines);
  4977. Assert.Equal (new Point (1, 1), tv.CursorPosition);
  4978. Assert.True (tv.IsDirty);
  4979. // Redo is disabled
  4980. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  4981. Assert.Equal ($"This is the {Environment.NewLine}athird line.{Environment.NewLine}", tv.Text);
  4982. Assert.Equal (3, tv.Lines);
  4983. Assert.Equal (new Point (1, 1), tv.CursorPosition);
  4984. }
  4985. [Fact]
  4986. public void HistoryText_ClearHistoryChanges ()
  4987. {
  4988. var text = "This is the first line.\nThis is the second line.\nThis is the third line.";
  4989. var tv = new TextView () { Text = text };
  4990. Assert.True (tv.ProcessKey (new KeyEvent (Key.Enter, new KeyModifiers ())));
  4991. 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);
  4992. Assert.Equal (4, tv.Lines);
  4993. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  4994. Assert.True (tv.IsDirty);
  4995. Assert.True (tv.HasHistoryChanges);
  4996. tv.ClearHistoryChanges ();
  4997. 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);
  4998. Assert.Equal (4, tv.Lines);
  4999. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  5000. Assert.False (tv.IsDirty);
  5001. Assert.False (tv.HasHistoryChanges);
  5002. }
  5003. [Fact]
  5004. public void GetRegion_StringFromRunes_Environment_NewLine ()
  5005. {
  5006. var tv = new TextView () { Text = $"1{Environment.NewLine}2" };
  5007. Assert.Equal ($"1{Environment.NewLine}2", tv.Text);
  5008. Assert.Equal ("", tv.SelectedText);
  5009. tv.SelectAll ();
  5010. Assert.Equal ($"1{Environment.NewLine}2", tv.Text);
  5011. Assert.Equal ($"1{Environment.NewLine}2", tv.SelectedText);
  5012. }
  5013. }
  5014. }