TextViewTests.cs 235 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731
  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_Undo_Redo_Multiline_Simples_Tab_BackTab ()
  4987. {
  4988. var text = "First line.\nSecond line.\nThird line.";
  4989. var tv = new TextView () { Width = 80, Height = 5, Text = text };
  4990. Assert.True (tv.ProcessKey (new KeyEvent (Key.Tab, new KeyModifiers ())));
  4991. Assert.Equal ($"\tFirst line.{Environment.NewLine}Second line.{Environment.NewLine}Third line.", tv.Text);
  4992. Assert.Equal (3, tv.Lines);
  4993. Assert.Equal (new Point (1, 0), tv.CursorPosition);
  4994. Assert.True (tv.ProcessKey (new KeyEvent (Key.BackTab, new KeyModifiers ())));
  4995. Assert.Equal ($"First line.{Environment.NewLine}Second line.{Environment.NewLine}Third line.", tv.Text);
  4996. Assert.Equal (3, tv.Lines);
  4997. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  4998. // Undo
  4999. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  5000. Assert.Equal ($"\tFirst line.{Environment.NewLine}Second line.{Environment.NewLine}Third line.", tv.Text);
  5001. Assert.Equal (3, tv.Lines);
  5002. Assert.Equal (new Point (1, 0), tv.CursorPosition);
  5003. Assert.True (tv.IsDirty);
  5004. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  5005. Assert.Equal ($"First line.{Environment.NewLine}Second line.{Environment.NewLine}Third line.", tv.Text);
  5006. Assert.Equal (3, tv.Lines);
  5007. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  5008. Assert.False (tv.IsDirty);
  5009. // Redo
  5010. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  5011. Assert.Equal ($"\tFirst line.{Environment.NewLine}Second line.{Environment.NewLine}Third line.", tv.Text);
  5012. Assert.Equal (3, tv.Lines);
  5013. Assert.Equal (new Point (1, 0), tv.CursorPosition);
  5014. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  5015. Assert.Equal ($"First line.{Environment.NewLine}Second line.{Environment.NewLine}Third line.", tv.Text);
  5016. Assert.Equal (3, tv.Lines);
  5017. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  5018. }
  5019. [Fact]
  5020. public void HistoryText_Undo_Redo_Multiline_Selected_Tab_BackTab ()
  5021. {
  5022. var text = "First line.\nSecond line.\nThird line.";
  5023. var tv = new TextView () { Width = 80, Height = 5, Text = text };
  5024. tv.SelectionStartColumn = 6;
  5025. tv.CursorPosition = new Point (6, 2);
  5026. Assert.True (tv.ProcessKey (new KeyEvent (Key.Tab, new KeyModifiers ())));
  5027. Assert.Equal ("First \tline.", tv.Text);
  5028. Assert.Equal (1, tv.Lines);
  5029. Assert.Equal (new Point (7, 0), tv.CursorPosition);
  5030. Assert.True (tv.ProcessKey (new KeyEvent (Key.BackTab, new KeyModifiers ())));
  5031. Assert.Equal ("First line.", tv.Text);
  5032. Assert.Equal (1, tv.Lines);
  5033. Assert.Equal (new Point (6, 0), tv.CursorPosition);
  5034. // Undo
  5035. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  5036. Assert.Equal ("First \tline.", tv.Text);
  5037. Assert.Equal (1, tv.Lines);
  5038. Assert.Equal (new Point (7, 0), tv.CursorPosition);
  5039. Assert.True (tv.IsDirty);
  5040. Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  5041. Assert.Equal ($"First line.{Environment.NewLine}Second line.{Environment.NewLine}Third line.", tv.Text);
  5042. Assert.Equal (3, tv.Lines);
  5043. Assert.Equal (new Point (6, 2), tv.CursorPosition);
  5044. Assert.False (tv.IsDirty);
  5045. // Redo
  5046. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  5047. Assert.Equal ("First \tline.", tv.Text);
  5048. Assert.Equal (1, tv.Lines);
  5049. Assert.Equal (new Point (7, 0), tv.CursorPosition);
  5050. Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
  5051. Assert.Equal ("First line.", tv.Text);
  5052. Assert.Equal (1, tv.Lines);
  5053. Assert.Equal (new Point (6, 0), tv.CursorPosition);
  5054. }
  5055. [Fact]
  5056. public void HistoryText_ClearHistoryChanges ()
  5057. {
  5058. var text = "This is the first line.\nThis is the second line.\nThis is the third line.";
  5059. var tv = new TextView () { Text = text };
  5060. Assert.True (tv.ProcessKey (new KeyEvent (Key.Enter, new KeyModifiers ())));
  5061. 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);
  5062. Assert.Equal (4, tv.Lines);
  5063. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  5064. Assert.True (tv.IsDirty);
  5065. Assert.True (tv.HasHistoryChanges);
  5066. tv.ClearHistoryChanges ();
  5067. 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);
  5068. Assert.Equal (4, tv.Lines);
  5069. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  5070. Assert.False (tv.IsDirty);
  5071. Assert.False (tv.HasHistoryChanges);
  5072. }
  5073. [Fact]
  5074. public void GetRegion_StringFromRunes_Environment_NewLine ()
  5075. {
  5076. var tv = new TextView () { Text = $"1{Environment.NewLine}2" };
  5077. Assert.Equal ($"1{Environment.NewLine}2", tv.Text);
  5078. Assert.Equal ("", tv.SelectedText);
  5079. tv.SelectAll ();
  5080. Assert.Equal ($"1{Environment.NewLine}2", tv.Text);
  5081. Assert.Equal ($"1{Environment.NewLine}2", tv.SelectedText);
  5082. }
  5083. [Fact, AutoInitShutdown]
  5084. public void WordWrap_Not_Throw_If_Width_Is_Less_Than_Zero ()
  5085. {
  5086. var exception = Record.Exception (() => {
  5087. var tv = new TextView () {
  5088. Width = Dim.Fill (),
  5089. Height = Dim.Fill (),
  5090. WordWrap = true,
  5091. Text = "これは、左右のクリップ境界をテストするための非常に長いテキストです。"
  5092. };
  5093. });
  5094. Assert.Null (exception);
  5095. }
  5096. [Fact]
  5097. [AutoInitShutdown]
  5098. public void ScrollDownTillCaretOffscreen_ThenType ()
  5099. {
  5100. var tv = new TextView {
  5101. Width = 10,
  5102. Height = 5
  5103. };
  5104. // add 100 lines of wide text to view
  5105. for (int i = 0; i < 100; i++)
  5106. tv.Text += new string ('x', 100) + Environment.NewLine;
  5107. Assert.Equal (0, tv.CursorPosition.Y);
  5108. tv.ScrollTo (50);
  5109. Assert.Equal (0, tv.CursorPosition.Y);
  5110. tv.ProcessKey (new KeyEvent (Key.p, new KeyModifiers ()));
  5111. }
  5112. }
  5113. }