TextViewTests.cs 251 KB

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