TextViewTests.cs 345 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115
  1. using System.Reflection;
  2. using System.Text;
  3. using System.Text.RegularExpressions;
  4. using Xunit.Abstractions;
  5. namespace Terminal.Gui.ViewsTests;
  6. public class TextViewTests
  7. {
  8. private static TextView _textView;
  9. private readonly ITestOutputHelper _output;
  10. public TextViewTests (ITestOutputHelper output) { _output = output; }
  11. [Fact]
  12. [TextViewTestsAutoInitShutdown]
  13. public void AllowsReturn_Setting_To_True_Changes_Multiline_To_True_If_It_Is_False ()
  14. {
  15. Assert.True (_textView.AllowsReturn);
  16. Assert.True (_textView.Multiline);
  17. Assert.Equal (4, _textView.TabWidth);
  18. Assert.True (_textView.AllowsTab);
  19. _textView.NewKeyDownEvent (Key.Enter);
  20. Assert.Equal (
  21. Environment.NewLine + "TAB to jump between text fields.",
  22. _textView.Text
  23. );
  24. _textView.AllowsReturn = false;
  25. Assert.False (_textView.AllowsReturn);
  26. Assert.False (_textView.Multiline);
  27. Assert.Equal (0, _textView.TabWidth);
  28. Assert.False (_textView.AllowsTab);
  29. _textView.NewKeyDownEvent (Key.Enter);
  30. Assert.Equal (
  31. Environment.NewLine + "TAB to jump between text fields.",
  32. _textView.Text
  33. );
  34. }
  35. [Fact]
  36. [TextViewTestsAutoInitShutdown]
  37. public void AllowsTab_Setting_To_True_Changes_TabWidth_To_Default_If_It_Is_Zero ()
  38. {
  39. _textView.TabWidth = 0;
  40. Assert.Equal (0, _textView.TabWidth);
  41. Assert.True (_textView.AllowsTab);
  42. Assert.True (_textView.AllowsReturn);
  43. Assert.True (_textView.Multiline);
  44. _textView.AllowsTab = true;
  45. Assert.True (_textView.AllowsTab);
  46. Assert.Equal (4, _textView.TabWidth);
  47. Assert.True (_textView.AllowsReturn);
  48. Assert.True (_textView.Multiline);
  49. }
  50. [Fact]
  51. [TextViewTestsAutoInitShutdown]
  52. public void BackTab_Test_Follow_By_Tab ()
  53. {
  54. var top = new Toplevel ();
  55. top.Add (_textView);
  56. Application.Iteration += (s, a) =>
  57. {
  58. int width = _textView.Viewport.Width - 1;
  59. Assert.Equal (30, width + 1);
  60. Assert.Equal (10, _textView.Height);
  61. _textView.Text = "";
  62. for (var i = 0; i < 100; i++)
  63. {
  64. _textView.Text += "\t";
  65. }
  66. var col = 100;
  67. int tabWidth = _textView.TabWidth;
  68. int leftCol = _textView.LeftColumn;
  69. _textView.MoveEnd ();
  70. Assert.Equal (new Point (col, 0), _textView.CursorPosition);
  71. leftCol = GetLeftCol (leftCol);
  72. Assert.Equal (leftCol, _textView.LeftColumn);
  73. while (col > 0)
  74. {
  75. col--;
  76. _textView.NewKeyDownEvent (Key.Tab.WithShift);
  77. Assert.Equal (new Point (col, 0), _textView.CursorPosition);
  78. leftCol = GetLeftCol (leftCol);
  79. Assert.Equal (leftCol, _textView.LeftColumn);
  80. }
  81. while (col < 100)
  82. {
  83. col++;
  84. _textView.NewKeyDownEvent (Key.Tab);
  85. Assert.Equal (new Point (col, 0), _textView.CursorPosition);
  86. leftCol = GetLeftCol (leftCol);
  87. Assert.Equal (leftCol, _textView.LeftColumn);
  88. }
  89. Application.Top.Remove (_textView);
  90. Application.RequestStop ();
  91. };
  92. Application.Run (top);
  93. top.Dispose ();
  94. }
  95. [Fact]
  96. [TextViewTestsAutoInitShutdown]
  97. public void CanFocus_False_Wont_Focus_With_Mouse ()
  98. {
  99. Toplevel top = new ();
  100. var tv = new TextView { Width = Dim.Fill (), CanFocus = false, ReadOnly = true, Text = "some text" };
  101. var fv = new FrameView
  102. {
  103. Width = Dim.Fill (), Height = Dim.Fill (), CanFocus = false, Title = "I shouldn't get focus"
  104. };
  105. fv.Add (tv);
  106. top.Add (fv);
  107. Application.Begin (top);
  108. Assert.False (tv.CanFocus);
  109. Assert.False (tv.HasFocus);
  110. Assert.False (fv.CanFocus);
  111. Assert.False (fv.HasFocus);
  112. tv.NewMouseEvent (new MouseEventArgs { Position = new (1, 0), Flags = MouseFlags.Button1DoubleClicked });
  113. Assert.Empty (tv.SelectedText);
  114. Assert.False (tv.CanFocus);
  115. Assert.False (tv.HasFocus);
  116. Assert.False (fv.CanFocus);
  117. Assert.False (fv.HasFocus);
  118. fv.CanFocus = true;
  119. tv.CanFocus = true;
  120. tv.NewMouseEvent (new MouseEventArgs { Position = new (1, 0), Flags = MouseFlags.Button1DoubleClicked });
  121. Assert.Equal ("some ", tv.SelectedText);
  122. Assert.True (tv.CanFocus);
  123. Assert.True (tv.HasFocus);
  124. Assert.True (fv.CanFocus);
  125. Assert.True (fv.HasFocus);
  126. fv.CanFocus = false;
  127. tv.NewMouseEvent (new MouseEventArgs { Position = new (1, 0), Flags = MouseFlags.Button1DoubleClicked });
  128. Assert.Equal ("some ", tv.SelectedText); // Setting CanFocus to false don't change the SelectedText
  129. Assert.True (tv.CanFocus); // v2: CanFocus is not longer automatically changed
  130. Assert.False (tv.HasFocus);
  131. Assert.False (fv.CanFocus);
  132. Assert.False (fv.HasFocus);
  133. top.Dispose ();
  134. }
  135. [Fact]
  136. [TextViewTestsAutoInitShutdown]
  137. public void Changing_Selection_Or_CursorPosition_Update_SelectedLength_And_SelectedText ()
  138. {
  139. _textView.SelectionStartColumn = 2;
  140. _textView.SelectionStartRow = 0;
  141. Assert.Equal (0, _textView.CursorPosition.X);
  142. Assert.Equal (0, _textView.CursorPosition.Y);
  143. Assert.Equal (2, _textView.SelectedLength);
  144. Assert.Equal ("TA", _textView.SelectedText);
  145. _textView.CursorPosition = new Point (20, 0);
  146. Assert.Equal (2, _textView.SelectionStartColumn);
  147. Assert.Equal (0, _textView.SelectionStartRow);
  148. Assert.Equal (18, _textView.SelectedLength);
  149. Assert.Equal ("B to jump between ", _textView.SelectedText);
  150. }
  151. [Fact]
  152. public void CloseFile_Throws_If_FilePath_Is_Null ()
  153. {
  154. var tv = new TextView ();
  155. Assert.Throws<ArgumentNullException> (() => tv.CloseFile ());
  156. }
  157. [Fact]
  158. public void ContentsChanged_Event_Fires_ClearHistoryChanges ()
  159. {
  160. var eventcount = 0;
  161. var text = "This is the first line.\nThis is the second line.\nThis is the third line.";
  162. var tv = new TextView { Width = 50, Height = 10, Text = text };
  163. tv.ContentsChanged += (s, e) => { eventcount++; };
  164. Assert.True (tv.NewKeyDownEvent (Key.Enter));
  165. Assert.Equal (
  166. $"{Environment.NewLine}This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.",
  167. tv.Text
  168. );
  169. Assert.Equal (4, tv.Lines);
  170. var expectedEventCount = 1; // for ENTER key
  171. Assert.Equal (expectedEventCount, eventcount);
  172. tv.ClearHistoryChanges ();
  173. expectedEventCount = 2;
  174. Assert.Equal (expectedEventCount, eventcount);
  175. }
  176. [Fact]
  177. public void ContentsChanged_Event_Fires_LoadStream_By_Calling_HistoryText_Clear ()
  178. {
  179. var eventcount = 0;
  180. var tv = new TextView { Width = 50, Height = 10 };
  181. tv.ContentsChanged += (s, e) => { eventcount++; };
  182. var text = "This is the first line.\r\nThis is the second line.\r\n";
  183. tv.Load (new MemoryStream (Encoding.ASCII.GetBytes (text)));
  184. Assert.Equal (
  185. $"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}",
  186. tv.Text
  187. );
  188. Assert.Equal (1, eventcount);
  189. }
  190. [Fact]
  191. [AutoInitShutdown]
  192. public void ContentsChanged_Event_Fires_On_Init ()
  193. {
  194. Application.Iteration += (s, a) => { Application.RequestStop (); };
  195. var expectedRow = 0;
  196. var expectedCol = 0;
  197. var eventcount = 0;
  198. var tv = new TextView { Width = 50, Height = 10 };
  199. tv.ContentsChanged += (s, e) =>
  200. {
  201. eventcount++;
  202. Assert.Equal (expectedRow, e.Row);
  203. Assert.Equal (expectedCol, e.Col);
  204. };
  205. var top = new Toplevel ();
  206. top.Add (tv);
  207. Application.Begin (top);
  208. Assert.Equal (1, eventcount);
  209. top.Dispose ();
  210. }
  211. [Fact]
  212. [AutoInitShutdown]
  213. public void ContentsChanged_Event_Fires_On_InsertText ()
  214. {
  215. var eventcount = 0;
  216. var tv = new TextView { Width = 50, Height = 10 };
  217. tv.CursorPosition = Point.Empty;
  218. tv.ContentsChanged += (s, e) => { eventcount++; };
  219. Assert.Equal (0, eventcount);
  220. tv.InsertText ("a");
  221. Assert.Equal (1, eventcount);
  222. tv.CursorPosition = Point.Empty;
  223. tv.InsertText ("bcd");
  224. Assert.Equal (4, eventcount);
  225. tv.InsertText ("e");
  226. Assert.Equal (5, eventcount);
  227. tv.InsertText ("\n");
  228. Assert.Equal (6, eventcount);
  229. tv.InsertText ("1234");
  230. Assert.Equal (10, eventcount);
  231. }
  232. [Fact]
  233. public void ContentsChanged_Event_Fires_On_LoadFile_By_Calling_HistoryText_Clear ()
  234. {
  235. var eventcount = 0;
  236. var tv = new TextView { Width = 50, Height = 10 };
  237. tv.BeginInit ();
  238. tv.EndInit ();
  239. tv.ContentsChanged += (s, e) => { eventcount++; };
  240. var fileName = "textview.txt";
  241. File.WriteAllText (fileName, "This is the first line.\r\nThis is the second line.\r\n");
  242. tv.Load (fileName);
  243. Assert.Equal (1, eventcount);
  244. Assert.Equal (
  245. $"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}",
  246. tv.Text
  247. );
  248. }
  249. [Fact]
  250. [AutoInitShutdown]
  251. public void ContentsChanged_Event_Fires_On_Set_Text ()
  252. {
  253. Application.Iteration += (s, a) => { Application.RequestStop (); };
  254. var eventcount = 0;
  255. var expectedRow = 0;
  256. var expectedCol = 0;
  257. var tv = new TextView
  258. {
  259. Width = 50,
  260. Height = 10,
  261. // you'd think col would be 3, but it's 0 because TextView sets
  262. // row/col = 0 when you set Text
  263. Text = "abc"
  264. };
  265. tv.ContentsChanged += (s, e) =>
  266. {
  267. eventcount++;
  268. Assert.Equal (expectedRow, e.Row);
  269. Assert.Equal (expectedCol, e.Col);
  270. };
  271. Assert.Equal ("abc", tv.Text);
  272. var top = new Toplevel ();
  273. top.Add (tv);
  274. RunState rs = Application.Begin (top);
  275. Assert.Equal (1, eventcount); // for Initialize
  276. expectedCol = 0;
  277. tv.Text = "defg";
  278. Assert.Equal (2, eventcount); // for set Text = "defg"
  279. top.Dispose ();
  280. }
  281. [Fact]
  282. [AutoInitShutdown]
  283. public void ContentsChanged_Event_Fires_On_Typing ()
  284. {
  285. Application.Iteration += (s, a) => { Application.RequestStop (); };
  286. var eventcount = 0;
  287. var expectedRow = 0;
  288. var expectedCol = 0;
  289. var tv = new TextView { Width = 50, Height = 10 };
  290. tv.ContentsChanged += (s, e) =>
  291. {
  292. eventcount++;
  293. Assert.Equal (expectedRow, e.Row);
  294. Assert.Equal (expectedCol, e.Col);
  295. };
  296. var top = new Toplevel ();
  297. top.Add (tv);
  298. RunState rs = Application.Begin (top);
  299. Assert.Equal (1, eventcount); // for Initialize
  300. expectedCol = 0;
  301. tv.Text = "ay";
  302. Assert.Equal (2, eventcount);
  303. expectedCol = 1;
  304. tv.NewKeyDownEvent (Key.Y.WithShift);
  305. Assert.Equal (3, eventcount);
  306. Assert.Equal ("Yay", tv.Text);
  307. top.Dispose ();
  308. }
  309. [Fact]
  310. [TextViewTestsAutoInitShutdown]
  311. public void ContentsChanged_Event_Fires_On_Undo_Redo ()
  312. {
  313. var eventcount = 0;
  314. var expectedEventCount = 0;
  315. _textView.ContentsChanged += (s, e) => { eventcount++; };
  316. expectedEventCount++;
  317. _textView.Text = "This is the first line.\nThis is the second line.\nThis is the third line.";
  318. Assert.Equal (expectedEventCount, eventcount);
  319. expectedEventCount++;
  320. Assert.True (_textView.NewKeyDownEvent (Key.Enter));
  321. Assert.Equal (expectedEventCount, eventcount);
  322. // Undo
  323. expectedEventCount++;
  324. Assert.True (_textView.NewKeyDownEvent (Key.Z.WithCtrl));
  325. Assert.Equal (expectedEventCount, eventcount);
  326. // Redo
  327. expectedEventCount++;
  328. Assert.True (_textView.NewKeyDownEvent (Key.R.WithCtrl));
  329. Assert.Equal (expectedEventCount, eventcount);
  330. // Undo
  331. expectedEventCount++;
  332. Assert.True (_textView.NewKeyDownEvent (Key.Z.WithCtrl));
  333. Assert.Equal (expectedEventCount, eventcount);
  334. // Redo
  335. expectedEventCount++;
  336. Assert.True (_textView.NewKeyDownEvent (Key.R.WithCtrl));
  337. Assert.Equal (expectedEventCount, eventcount);
  338. }
  339. [Fact]
  340. [TextViewTestsAutoInitShutdown]
  341. public void ContentsChanged_Event_Fires_Using_Copy_Or_Cut_Tests ()
  342. {
  343. var eventcount = 0;
  344. _textView.ContentsChanged += (s, e) => { eventcount++; };
  345. var expectedEventCount = 1;
  346. // reset
  347. _textView.Text = TextViewTestsAutoInitShutdown.Txt;
  348. Assert.Equal (expectedEventCount, eventcount);
  349. expectedEventCount += 3;
  350. Copy_Or_Cut_And_Paste_With_No_Selection ();
  351. Assert.Equal (expectedEventCount, eventcount);
  352. // reset
  353. expectedEventCount += 1;
  354. _textView.Text = TextViewTestsAutoInitShutdown.Txt;
  355. Assert.Equal (expectedEventCount, eventcount);
  356. expectedEventCount += 3;
  357. Copy_Or_Cut_And_Paste_With_Selection ();
  358. Assert.Equal (expectedEventCount, eventcount);
  359. // reset
  360. expectedEventCount += 1;
  361. _textView.Text = TextViewTestsAutoInitShutdown.Txt;
  362. Assert.Equal (expectedEventCount, eventcount);
  363. expectedEventCount += 1;
  364. Copy_Or_Cut_Not_Null_If_Has_Selection ();
  365. Assert.Equal (expectedEventCount, eventcount);
  366. // reset
  367. expectedEventCount += 1;
  368. _textView.Text = TextViewTestsAutoInitShutdown.Txt;
  369. Assert.Equal (expectedEventCount, eventcount);
  370. expectedEventCount += 1;
  371. Copy_Or_Cut_Null_If_No_Selection ();
  372. Assert.Equal (expectedEventCount, eventcount);
  373. // reset
  374. expectedEventCount += 1;
  375. _textView.Text = TextViewTestsAutoInitShutdown.Txt;
  376. Assert.Equal (expectedEventCount, eventcount);
  377. expectedEventCount += 4;
  378. Copy_Without_Selection ();
  379. Assert.Equal (expectedEventCount, eventcount);
  380. // reset
  381. expectedEventCount += 1;
  382. _textView.Text = TextViewTestsAutoInitShutdown.Txt;
  383. Assert.Equal (expectedEventCount, eventcount);
  384. expectedEventCount += 4;
  385. Copy_Without_Selection ();
  386. Assert.Equal (expectedEventCount, eventcount);
  387. }
  388. [Fact]
  389. [TextViewTestsAutoInitShutdown]
  390. public void ContentsChanged_Event_Fires_Using_Kill_Delete_Tests ()
  391. {
  392. var eventcount = 0;
  393. _textView.ContentsChanged += (s, e) => { eventcount++; };
  394. var expectedEventCount = 1;
  395. Kill_Delete_WordForward ();
  396. Assert.Equal (expectedEventCount, eventcount); // for Initialize
  397. expectedEventCount += 1;
  398. Kill_Delete_WordBackward ();
  399. Assert.Equal (expectedEventCount, eventcount);
  400. expectedEventCount += 2;
  401. Kill_To_End_Delete_Forwards_Copy_To_The_Clipboard_And_Paste ();
  402. Assert.Equal (expectedEventCount, eventcount);
  403. expectedEventCount += 2;
  404. Kill_To_Start_Delete_Backwards_Copy_To_The_Clipboard_And_Paste ();
  405. Assert.Equal (expectedEventCount, eventcount);
  406. }
  407. [Fact]
  408. [AutoInitShutdown]
  409. public void ContentsChanged_Event_NoFires_On_CursorPosition ()
  410. {
  411. var eventcount = 0;
  412. var tv = new TextView { Width = 50, Height = 10 };
  413. tv.ContentsChanged += (s, e) => { eventcount++; };
  414. Assert.Equal (0, eventcount);
  415. tv.CursorPosition = Point.Empty;
  416. Assert.Equal (0, eventcount);
  417. }
  418. [Fact]
  419. [TextViewTestsAutoInitShutdown]
  420. public void Copy_Or_Cut_And_Paste_With_No_Selection ()
  421. {
  422. _textView.SelectionStartColumn = 20;
  423. _textView.SelectionStartRow = 0;
  424. _textView.CursorPosition = new Point (24, 0);
  425. _textView.NewKeyDownEvent (Key.C.WithCtrl); // Copy
  426. Assert.Equal ("text", _textView.SelectedText);
  427. Assert.Equal ("TAB to jump between text fields.", _textView.Text);
  428. _textView.SelectionStartColumn = 0;
  429. _textView.SelectionStartRow = 0;
  430. Assert.Equal (new Point (24, 0), _textView.CursorPosition);
  431. Assert.True (_textView.IsSelecting);
  432. _textView.IsSelecting = false;
  433. _textView.NewKeyDownEvent (Key.Y.WithCtrl); // Paste
  434. Assert.Equal (new Point (28, 0), _textView.CursorPosition);
  435. Assert.False (_textView.IsSelecting);
  436. Assert.Equal ("TAB to jump between texttext fields.", _textView.Text);
  437. _textView.SelectionStartColumn = 24;
  438. _textView.SelectionStartRow = 0;
  439. _textView.NewKeyDownEvent (Key.W.WithCtrl); // Cut
  440. Assert.Equal (new Point (24, 0), _textView.CursorPosition);
  441. Assert.False (_textView.IsSelecting);
  442. Assert.Equal ("", _textView.SelectedText);
  443. Assert.Equal ("TAB to jump between text fields.", _textView.Text);
  444. _textView.SelectionStartColumn = 0;
  445. _textView.SelectionStartRow = 0;
  446. _textView.IsSelecting = false;
  447. _textView.NewKeyDownEvent (Key.Y.WithCtrl); // Paste
  448. Assert.Equal (new Point (28, 0), _textView.CursorPosition);
  449. Assert.False (_textView.IsSelecting);
  450. Assert.Equal ("TAB to jump between texttext fields.", _textView.Text);
  451. }
  452. [Fact]
  453. [TextViewTestsAutoInitShutdown]
  454. public void Copy_Or_Cut_And_Paste_With_Selection ()
  455. {
  456. _textView.SelectionStartColumn = 20;
  457. _textView.SelectionStartRow = 0;
  458. _textView.CursorPosition = new Point (24, 0);
  459. _textView.NewKeyDownEvent (Key.C.WithCtrl); // Copy
  460. Assert.Equal ("text", _textView.SelectedText);
  461. Assert.Equal ("TAB to jump between text fields.", _textView.Text);
  462. _textView.NewKeyDownEvent (Key.Y.WithCtrl); // Paste
  463. Assert.Equal ("TAB to jump between text fields.", _textView.Text);
  464. _textView.SelectionStartColumn = 20;
  465. _textView.SelectionStartRow = 0;
  466. _textView.NewKeyDownEvent (Key.W.WithCtrl); // Cut
  467. _textView.NewKeyDownEvent (Key.Y.WithCtrl); // Paste
  468. Assert.Equal ("TAB to jump between text fields.", _textView.Text);
  469. }
  470. [Fact]
  471. [TextViewTestsAutoInitShutdown]
  472. public void Copy_Or_Cut_Not_Null_If_Has_Selection ()
  473. {
  474. _textView.SelectionStartColumn = 20;
  475. _textView.SelectionStartRow = 0;
  476. _textView.CursorPosition = new Point (24, 0);
  477. _textView.NewKeyDownEvent (Key.C.WithCtrl); // Copy
  478. Assert.Equal ("text", _textView.SelectedText);
  479. _textView.NewKeyDownEvent (Key.W.WithCtrl); // Cut
  480. Assert.Equal ("", _textView.SelectedText);
  481. }
  482. [Fact]
  483. [TextViewTestsAutoInitShutdown]
  484. public void Copy_Or_Cut_Null_If_No_Selection ()
  485. {
  486. _textView.SelectionStartColumn = 0;
  487. _textView.SelectionStartRow = 0;
  488. _textView.NewKeyDownEvent (Key.C.WithCtrl); // Copy
  489. Assert.Equal ("", _textView.SelectedText);
  490. _textView.NewKeyDownEvent (Key.W.WithCtrl); // Cut
  491. Assert.Equal ("", _textView.SelectedText);
  492. }
  493. [Fact]
  494. [TextViewTestsAutoInitShutdown]
  495. public void Copy_Paste_Surrogate_Pairs ()
  496. {
  497. _textView.Text = "TextView with some more test text. Unicode shouldn't 𝔹Aℝ𝔽!";
  498. _textView.SelectAll ();
  499. _textView.Cut ();
  500. Assert.Equal (
  501. "TextView with some more test text. Unicode shouldn't 𝔹Aℝ𝔽!",
  502. Application.Driver?.Clipboard.GetClipboardData ()
  503. );
  504. Assert.Equal (string.Empty, _textView.Text);
  505. _textView.Paste ();
  506. Assert.Equal ("TextView with some more test text. Unicode shouldn't 𝔹Aℝ𝔽!", _textView.Text);
  507. }
  508. [Fact]
  509. [TextViewTestsAutoInitShutdown]
  510. public void Copy_Without_Selection ()
  511. {
  512. _textView.Text = "This is the first line.\nThis is the second line.\n";
  513. _textView.CursorPosition = new Point (0, _textView.Lines - 1);
  514. _textView.NewKeyDownEvent (Key.C.WithCtrl); // Copy
  515. _textView.NewKeyDownEvent (Key.Y.WithCtrl); // Paste
  516. Assert.Equal (
  517. $"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}{Environment.NewLine}",
  518. _textView.Text
  519. );
  520. _textView.CursorPosition = new Point (3, 1);
  521. _textView.NewKeyDownEvent (Key.C.WithCtrl); // Copy
  522. _textView.NewKeyDownEvent (Key.Y.WithCtrl); // Paste
  523. Assert.Equal (
  524. $"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the second line.{Environment.NewLine}{Environment.NewLine}",
  525. _textView.Text
  526. );
  527. Assert.Equal (new Point (3, 2), _textView.CursorPosition);
  528. _textView.NewKeyDownEvent (Key.Y.WithCtrl); // Paste
  529. Assert.Equal (
  530. $"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}",
  531. _textView.Text
  532. );
  533. Assert.Equal (new Point (3, 3), _textView.CursorPosition);
  534. }
  535. [Fact]
  536. [TextViewTestsAutoInitShutdown]
  537. public void Cursor_Position_Multiline_False_Initialization ()
  538. {
  539. Assert.False (_textView.IsInitialized);
  540. Assert.True (_textView.Multiline);
  541. _textView.Multiline = false;
  542. Assert.Equal (32, _textView.CursorPosition.X);
  543. Assert.Equal (0, _textView.CursorPosition.Y);
  544. Assert.Equal (0, _textView.SelectedLength);
  545. Assert.Equal ("", _textView.SelectedText);
  546. Assert.Equal ("TAB to jump between text fields.", _textView.Text);
  547. }
  548. [Fact]
  549. [TextViewTestsAutoInitShutdown]
  550. public void CursorPosition_With_Value_Greater_Than_Text_Length_Changes_To_Text_Length ()
  551. {
  552. _textView.CursorPosition = new Point (33, 1);
  553. Assert.Equal (32, _textView.CursorPosition.X);
  554. Assert.Equal (0, _textView.CursorPosition.Y);
  555. Assert.Equal (0, _textView.SelectedLength);
  556. Assert.Equal ("", _textView.SelectedText);
  557. }
  558. [Fact]
  559. [TextViewTestsAutoInitShutdown]
  560. public void CursorPosition_With_Value_Less_Than_Zero_Changes_To_Zero ()
  561. {
  562. _textView.CursorPosition = new Point (-1, -1);
  563. Assert.Equal (0, _textView.CursorPosition.X);
  564. Assert.Equal (0, _textView.CursorPosition.Y);
  565. Assert.Equal (0, _textView.SelectedLength);
  566. Assert.Equal ("", _textView.SelectedText);
  567. }
  568. [Fact]
  569. [TextViewTestsAutoInitShutdown]
  570. public void Cut_Not_Allowed_If_ReadOnly_Is_True ()
  571. {
  572. _textView.ReadOnly = true;
  573. _textView.SelectionStartColumn = 20;
  574. _textView.SelectionStartRow = 0;
  575. _textView.CursorPosition = new Point (24, 0);
  576. _textView.NewKeyDownEvent (Key.C.WithCtrl); // Copy
  577. Assert.Equal ("text", _textView.SelectedText);
  578. _textView.NewKeyDownEvent (
  579. Key.W.WithCtrl
  580. ); // Selecting is set to false after Cut.
  581. Assert.Equal ("", _textView.SelectedText);
  582. _textView.ReadOnly = false;
  583. Assert.False (_textView.IsSelecting);
  584. _textView.IsSelecting = true; // Needed to set Selecting to true.
  585. _textView.NewKeyDownEvent (Key.C.WithCtrl); // Copy
  586. Assert.Equal ("text", _textView.SelectedText);
  587. _textView.NewKeyDownEvent (Key.W.WithCtrl); // Cut
  588. Assert.Equal ("", _textView.SelectedText);
  589. }
  590. [Fact]
  591. [AutoInitShutdown]
  592. public void DeleteTextBackwards_WordWrap_False_Return_Undo ()
  593. {
  594. const string text = "This is the first line.\nThis is the second line.\n";
  595. var tv = new TextView { Width = Dim.Fill (), Height = Dim.Fill (), Text = text };
  596. string envText = tv.Text;
  597. var top = new Toplevel ();
  598. top.Add (tv);
  599. RunState rs = Application.Begin (top);
  600. Application.RunIteration (ref rs);
  601. Assert.False (tv.WordWrap);
  602. Assert.Equal (Point.Empty, tv.CursorPosition);
  603. TestHelpers.AssertDriverContentsWithFrameAre (
  604. @"
  605. This is the first line.
  606. This is the second line.
  607. ",
  608. _output
  609. );
  610. tv.CursorPosition = new Point (3, 0);
  611. Assert.Equal (new Point (3, 0), tv.CursorPosition);
  612. Assert.True (tv.NewKeyDownEvent (Key.Backspace));
  613. Application.RunIteration (ref rs);
  614. Assert.Equal (new Point (2, 0), tv.CursorPosition);
  615. TestHelpers.AssertDriverContentsWithFrameAre (
  616. @"
  617. Ths is the first line.
  618. This is the second line.
  619. ",
  620. _output
  621. );
  622. tv.CursorPosition = new Point (0, 1);
  623. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  624. Assert.True (tv.NewKeyDownEvent (Key.Backspace));
  625. Application.RunIteration (ref rs);
  626. Assert.Equal (new Point (22, 0), tv.CursorPosition);
  627. TestHelpers.AssertDriverContentsWithFrameAre (
  628. @"
  629. Ths is the first line.This is the second line.
  630. ",
  631. _output
  632. );
  633. Assert.True (tv.NewKeyDownEvent (Key.Enter));
  634. Application.RunIteration (ref rs);
  635. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  636. TestHelpers.AssertDriverContentsWithFrameAre (
  637. @"
  638. Ths is the first line.
  639. This is the second line.
  640. ",
  641. _output
  642. );
  643. while (tv.Text != envText)
  644. {
  645. Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl));
  646. }
  647. Application.RunIteration (ref rs);
  648. Assert.Equal (envText, tv.Text);
  649. Assert.Equal (new Point (3, 0), tv.CursorPosition);
  650. Assert.False (tv.IsDirty);
  651. top.Dispose ();
  652. }
  653. [Fact]
  654. [AutoInitShutdown]
  655. public void DeleteTextBackwards_WordWrap_True_Return_Undo ()
  656. {
  657. const string text = "This is the first line.\nThis is the second line.\n";
  658. var tv = new TextView { Width = Dim.Fill (), Height = Dim.Fill (), Text = text, WordWrap = true };
  659. string envText = tv.Text;
  660. var top = new Toplevel ();
  661. top.Add (tv);
  662. RunState rs = Application.Begin (top);
  663. Application.RunIteration (ref rs);
  664. Assert.True (tv.WordWrap);
  665. Assert.Equal (Point.Empty, tv.CursorPosition);
  666. TestHelpers.AssertDriverContentsWithFrameAre (
  667. @"
  668. This is the first line.
  669. This is the second line.
  670. ",
  671. _output
  672. );
  673. tv.CursorPosition = new Point (3, 0);
  674. Assert.Equal (new Point (3, 0), tv.CursorPosition);
  675. Assert.True (tv.NewKeyDownEvent (Key.Backspace));
  676. Application.RunIteration (ref rs);
  677. Assert.Equal (new Point (2, 0), tv.CursorPosition);
  678. TestHelpers.AssertDriverContentsWithFrameAre (
  679. @"
  680. Ths is the first line.
  681. This is the second line.
  682. ",
  683. _output
  684. );
  685. tv.CursorPosition = new Point (0, 1);
  686. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  687. Assert.True (tv.NewKeyDownEvent (Key.Backspace));
  688. Application.RunIteration (ref rs);
  689. Assert.Equal (new Point (22, 0), tv.CursorPosition);
  690. TestHelpers.AssertDriverContentsWithFrameAre (
  691. @"
  692. Ths is the first line.This is the second line.
  693. ",
  694. _output
  695. );
  696. Assert.True (tv.NewKeyDownEvent (Key.Enter));
  697. Application.RunIteration (ref rs);
  698. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  699. TestHelpers.AssertDriverContentsWithFrameAre (
  700. @"
  701. Ths is the first line.
  702. This is the second line.
  703. ",
  704. _output
  705. );
  706. while (tv.Text != envText)
  707. {
  708. Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl));
  709. }
  710. Application.RunIteration (ref rs);
  711. Assert.Equal (envText, tv.Text);
  712. Assert.Equal (new Point (3, 0), tv.CursorPosition);
  713. Assert.False (tv.IsDirty);
  714. top.Dispose ();
  715. }
  716. [Fact]
  717. [AutoInitShutdown]
  718. public void DeleteTextForwards_WordWrap_False_Return_Undo ()
  719. {
  720. const string text = "This is the first line.\nThis is the second line.\n";
  721. var tv = new TextView { Width = Dim.Fill (), Height = Dim.Fill (), Text = text };
  722. string envText = tv.Text;
  723. var top = new Toplevel ();
  724. top.Add (tv);
  725. RunState rs = Application.Begin (top);
  726. Application.RunIteration (ref rs);
  727. Assert.False (tv.WordWrap);
  728. Assert.Equal (Point.Empty, tv.CursorPosition);
  729. TestHelpers.AssertDriverContentsWithFrameAre (
  730. @"
  731. This is the first line.
  732. This is the second line.
  733. ",
  734. _output
  735. );
  736. tv.CursorPosition = new Point (2, 0);
  737. Assert.Equal (new Point (2, 0), tv.CursorPosition);
  738. Assert.True (tv.NewKeyDownEvent (Key.Delete));
  739. Application.RunIteration (ref rs);
  740. Assert.Equal (new Point (2, 0), tv.CursorPosition);
  741. TestHelpers.AssertDriverContentsWithFrameAre (
  742. @"
  743. Ths is the first line.
  744. This is the second line.
  745. ",
  746. _output
  747. );
  748. tv.CursorPosition = new Point (22, 0);
  749. Assert.Equal (new Point (22, 0), tv.CursorPosition);
  750. Assert.True (tv.NewKeyDownEvent (Key.Delete));
  751. Application.RunIteration (ref rs);
  752. Assert.Equal (new Point (22, 0), tv.CursorPosition);
  753. TestHelpers.AssertDriverContentsWithFrameAre (
  754. @"
  755. Ths is the first line.This is the second line.
  756. ",
  757. _output
  758. );
  759. Assert.True (tv.NewKeyDownEvent (Key.Enter));
  760. Application.RunIteration (ref rs);
  761. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  762. TestHelpers.AssertDriverContentsWithFrameAre (
  763. @"
  764. Ths is the first line.
  765. This is the second line.
  766. ",
  767. _output
  768. );
  769. while (tv.Text != envText)
  770. {
  771. Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl));
  772. }
  773. Assert.Equal (envText, tv.Text);
  774. Assert.Equal (new Point (2, 0), tv.CursorPosition);
  775. Assert.False (tv.IsDirty);
  776. top.Dispose ();
  777. }
  778. [Fact]
  779. [AutoInitShutdown]
  780. public void DeleteTextForwards_WordWrap_True_Return_Undo ()
  781. {
  782. const string text = "This is the first line.\nThis is the second line.\n";
  783. var tv = new TextView { Width = Dim.Fill (), Height = Dim.Fill (), Text = text, WordWrap = true };
  784. string envText = tv.Text;
  785. var top = new Toplevel ();
  786. top.Add (tv);
  787. RunState rs = Application.Begin (top);
  788. Application.RunIteration (ref rs);
  789. Assert.True (tv.WordWrap);
  790. Assert.Equal (Point.Empty, tv.CursorPosition);
  791. TestHelpers.AssertDriverContentsWithFrameAre (
  792. @"
  793. This is the first line.
  794. This is the second line.
  795. ",
  796. _output
  797. );
  798. tv.CursorPosition = new Point (2, 0);
  799. Assert.Equal (new Point (2, 0), tv.CursorPosition);
  800. Assert.True (tv.NewKeyDownEvent (Key.Delete));
  801. Application.RunIteration (ref rs);
  802. Assert.Equal (new Point (2, 0), tv.CursorPosition);
  803. TestHelpers.AssertDriverContentsWithFrameAre (
  804. @"
  805. Ths is the first line.
  806. This is the second line.
  807. ",
  808. _output
  809. );
  810. tv.CursorPosition = new Point (22, 0);
  811. Assert.Equal (new Point (22, 0), tv.CursorPosition);
  812. Assert.True (tv.NewKeyDownEvent (Key.Delete));
  813. Application.RunIteration (ref rs);
  814. Assert.Equal (new Point (22, 0), tv.CursorPosition);
  815. TestHelpers.AssertDriverContentsWithFrameAre (
  816. @"
  817. Ths is the first line.This is the second line.
  818. ",
  819. _output
  820. );
  821. Assert.True (tv.NewKeyDownEvent (Key.Enter));
  822. Application.RunIteration (ref rs);
  823. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  824. TestHelpers.AssertDriverContentsWithFrameAre (
  825. @"
  826. Ths is the first line.
  827. This is the second line.
  828. ",
  829. _output
  830. );
  831. while (tv.Text != envText)
  832. {
  833. Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl));
  834. }
  835. Application.RunIteration (ref rs);
  836. Assert.Equal (envText, tv.Text);
  837. Assert.Equal (new Point (2, 0), tv.CursorPosition);
  838. Assert.False (tv.IsDirty);
  839. top.Dispose ();
  840. }
  841. [Fact]
  842. [TextViewTestsAutoInitShutdown]
  843. public void DesiredCursorVisibility_Horizontal_Navigation ()
  844. {
  845. var text = "";
  846. for (var i = 0; i < 12; i++)
  847. {
  848. text += $"{i.ToString () [^1]}";
  849. }
  850. var tv = new TextView { Width = 10, Height = 10 };
  851. tv.Text = text;
  852. var top = new Toplevel ();
  853. top.Add (tv);
  854. Application.Begin (top);
  855. Assert.Equal (0, tv.LeftColumn);
  856. Assert.Equal (Point.Empty, tv.CursorPosition);
  857. Application.PositionCursor ();
  858. Assert.Equal (CursorVisibility.Default, tv.CursorVisibility);
  859. for (var i = 0; i < 12; i++)
  860. {
  861. tv.NewMouseEvent (new MouseEventArgs { Flags = MouseFlags.WheeledRight });
  862. Assert.Equal (Math.Min (i + 1, 11), tv.LeftColumn);
  863. Application.PositionCursor ();
  864. Application.Driver!.GetCursorVisibility (out CursorVisibility cursorVisibility);
  865. Assert.Equal (CursorVisibility.Invisible, cursorVisibility);
  866. }
  867. for (var i = 11; i > 0; i--)
  868. {
  869. tv.NewMouseEvent (new MouseEventArgs { Flags = MouseFlags.WheeledLeft });
  870. Assert.Equal (i - 1, tv.LeftColumn);
  871. Application.PositionCursor ();
  872. Application.Driver!.GetCursorVisibility (out CursorVisibility cursorVisibility);
  873. if (i - 1 == 0)
  874. {
  875. Assert.Equal (CursorVisibility.Default, cursorVisibility);
  876. }
  877. else
  878. {
  879. Assert.Equal (CursorVisibility.Invisible, cursorVisibility);
  880. }
  881. }
  882. top.Dispose ();
  883. Application.Shutdown ();
  884. }
  885. [Fact]
  886. [TextViewTestsAutoInitShutdown]
  887. public void DesiredCursorVisibility_Vertical_Navigation ()
  888. {
  889. var text = "";
  890. for (var i = 0; i < 12; i++)
  891. {
  892. text += $"This is the line {i}\n";
  893. }
  894. var tv = new TextView { Width = 10, Height = 10 };
  895. tv.Text = text;
  896. var top = new Toplevel ();
  897. top.Add (tv);
  898. Application.Begin (top);
  899. Assert.Equal (0, tv.TopRow);
  900. Application.PositionCursor ();
  901. Assert.Equal (CursorVisibility.Default, tv.CursorVisibility);
  902. for (var i = 0; i < 12; i++)
  903. {
  904. tv.NewMouseEvent (new MouseEventArgs { Flags = MouseFlags.WheeledDown });
  905. Application.PositionCursor ();
  906. Assert.Equal (i + 1, tv.TopRow);
  907. Application.Driver!.GetCursorVisibility (out CursorVisibility cursorVisibility);
  908. Assert.Equal (CursorVisibility.Invisible, cursorVisibility);
  909. }
  910. for (var i = 12; i > 0; i--)
  911. {
  912. tv.NewMouseEvent (new MouseEventArgs { Flags = MouseFlags.WheeledUp });
  913. Application.PositionCursor ();
  914. Assert.Equal (i - 1, tv.TopRow);
  915. Application.PositionCursor ();
  916. Application.Driver!.GetCursorVisibility (out CursorVisibility cursorVisibility);
  917. if (i - 1 == 0)
  918. {
  919. Assert.Equal (CursorVisibility.Default, cursorVisibility);
  920. }
  921. else
  922. {
  923. Assert.Equal (CursorVisibility.Invisible, cursorVisibility);
  924. }
  925. }
  926. top.Dispose ();
  927. Application.Shutdown ();
  928. }
  929. [Fact]
  930. public void GetRegion_StringFromRunes_Environment_NewLine ()
  931. {
  932. var tv = new TextView { Text = $"1{Environment.NewLine}2" };
  933. Assert.Equal ($"1{Environment.NewLine}2", tv.Text);
  934. Assert.Equal ("", tv.SelectedText);
  935. tv.SelectAll ();
  936. Assert.Equal ($"1{Environment.NewLine}2", tv.Text);
  937. Assert.Equal ($"1{Environment.NewLine}2", tv.SelectedText);
  938. }
  939. [Fact]
  940. public void HistoryText_ClearHistoryChanges ()
  941. {
  942. var text = "This is the first line.\nThis is the second line.\nThis is the third line.";
  943. var tv = new TextView { Text = text };
  944. Assert.True (tv.NewKeyDownEvent (Key.Enter));
  945. Assert.Equal (
  946. $"{Environment.NewLine}This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.",
  947. tv.Text
  948. );
  949. Assert.Equal (4, tv.Lines);
  950. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  951. Assert.True (tv.IsDirty);
  952. Assert.True (tv.HasHistoryChanges);
  953. tv.ClearHistoryChanges ();
  954. Assert.Equal (
  955. $"{Environment.NewLine}This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.",
  956. tv.Text
  957. );
  958. Assert.Equal (4, tv.Lines);
  959. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  960. Assert.False (tv.IsDirty);
  961. Assert.False (tv.HasHistoryChanges);
  962. }
  963. [Fact]
  964. public void HistoryText_Exceptions ()
  965. {
  966. var ht = new HistoryText ();
  967. foreach (object ls in Enum.GetValues (typeof (HistoryText.LineStatus)))
  968. {
  969. if ((HistoryText.LineStatus)ls != HistoryText.LineStatus.Original)
  970. {
  971. Assert.Throws<ArgumentException> (
  972. () => ht.Add (
  973. new List<List<Cell>> { new () },
  974. Point.Empty,
  975. (HistoryText.LineStatus)ls
  976. )
  977. );
  978. }
  979. }
  980. Assert.Null (Record.Exception (() => ht.Add (new List<List<Cell>> { new () }, Point.Empty)));
  981. }
  982. [Fact]
  983. public void HistoryText_IsDirty_HasHistoryChanges ()
  984. {
  985. var tv = new TextView ();
  986. Assert.Equal ("", tv.Text);
  987. Assert.Equal (1, tv.Lines);
  988. Assert.Equal (Point.Empty, tv.CursorPosition);
  989. Assert.False (tv.IsDirty);
  990. Assert.False (tv.HasHistoryChanges);
  991. Assert.True (tv.NewKeyDownEvent (Key.D1));
  992. Assert.Equal ("1", tv.Text);
  993. Assert.Equal (1, tv.Lines);
  994. Assert.Equal (new Point (1, 0), tv.CursorPosition);
  995. Assert.True (tv.IsDirty);
  996. Assert.True (tv.HasHistoryChanges);
  997. Assert.True (tv.NewKeyDownEvent (Key.Enter));
  998. Assert.Equal ($"1{Environment.NewLine}", tv.Text);
  999. Assert.Equal (2, tv.Lines);
  1000. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  1001. Assert.True (tv.IsDirty);
  1002. Assert.True (tv.HasHistoryChanges);
  1003. Assert.True (tv.NewKeyDownEvent (Key.D2));
  1004. Assert.Equal ($"1{Environment.NewLine}2", tv.Text);
  1005. Assert.Equal (2, tv.Lines);
  1006. Assert.Equal (new Point (1, 1), tv.CursorPosition);
  1007. Assert.True (tv.IsDirty);
  1008. Assert.True (tv.HasHistoryChanges);
  1009. Assert.True (tv.NewKeyDownEvent (Key.Backspace));
  1010. Assert.Equal ($"1{Environment.NewLine}", tv.Text);
  1011. Assert.Equal (2, tv.Lines);
  1012. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  1013. Assert.True (tv.IsDirty);
  1014. Assert.True (tv.HasHistoryChanges);
  1015. Assert.True (tv.NewKeyDownEvent (Key.Backspace));
  1016. Assert.Equal ("1", tv.Text);
  1017. Assert.Equal (1, tv.Lines);
  1018. Assert.Equal (new Point (1, 0), tv.CursorPosition);
  1019. Assert.True (tv.IsDirty);
  1020. Assert.True (tv.HasHistoryChanges);
  1021. Assert.True (tv.NewKeyDownEvent (Key.Backspace));
  1022. Assert.Equal ("", tv.Text);
  1023. Assert.Equal (1, tv.Lines);
  1024. Assert.Equal (Point.Empty, tv.CursorPosition);
  1025. // IsDirty cannot be based on HasHistoryChanges because HasHistoryChanges is greater than 0
  1026. // The only way is comparing from the original text
  1027. Assert.False (tv.IsDirty);
  1028. // Still true because HasHistoryChanges is greater than 0
  1029. Assert.True (tv.HasHistoryChanges);
  1030. }
  1031. [Fact]
  1032. public void HistoryText_Undo_Redo_Changing_On_Middle_Clear_History_Forwards ()
  1033. {
  1034. var tv = new TextView ();
  1035. Assert.True (tv.NewKeyDownEvent (Key.D1));
  1036. Assert.Equal ("1", tv.Text);
  1037. Assert.Equal (1, tv.Lines);
  1038. Assert.Equal (new Point (1, 0), tv.CursorPosition);
  1039. Assert.True (tv.NewKeyDownEvent (Key.D2));
  1040. Assert.Equal ("12", tv.Text);
  1041. Assert.Equal (1, tv.Lines);
  1042. Assert.Equal (new Point (2, 0), tv.CursorPosition);
  1043. Assert.True (tv.NewKeyDownEvent (Key.D3));
  1044. Assert.Equal ("123", tv.Text);
  1045. Assert.Equal (1, tv.Lines);
  1046. Assert.Equal (new Point (3, 0), tv.CursorPosition);
  1047. // Undo
  1048. Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl));
  1049. Assert.Equal ("12", tv.Text);
  1050. Assert.Equal (1, tv.Lines);
  1051. Assert.Equal (new Point (2, 0), tv.CursorPosition);
  1052. Assert.True (tv.NewKeyDownEvent (Key.D4));
  1053. Assert.Equal ("124", tv.Text);
  1054. Assert.Equal (1, tv.Lines);
  1055. Assert.Equal (new Point (3, 0), tv.CursorPosition);
  1056. // Redo
  1057. Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl));
  1058. Assert.Equal ("124", tv.Text);
  1059. Assert.Equal (1, tv.Lines);
  1060. Assert.Equal (new Point (3, 0), tv.CursorPosition);
  1061. }
  1062. [Fact]
  1063. [AutoInitShutdown (useFakeClipboard: true)]
  1064. public void HistoryText_Undo_Redo_Copy_Without_Selection_Multi_Line_Paste ()
  1065. {
  1066. var text = "This is the first line.\nThis is the second line.\nThis is the third line.";
  1067. var tv = new TextView { Text = text };
  1068. tv.CursorPosition = new Point (23, 0);
  1069. Assert.True (tv.NewKeyDownEvent (Key.C.WithCtrl));
  1070. Assert.Equal (
  1071. $"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.",
  1072. tv.Text
  1073. );
  1074. Assert.Equal ("", tv.SelectedText);
  1075. Assert.Equal ("This is the first line.", Clipboard.Contents);
  1076. Assert.Equal (3, tv.Lines);
  1077. Assert.Equal (new Point (23, 0), tv.CursorPosition);
  1078. Assert.True (tv.NewKeyDownEvent (Key.Y.WithCtrl));
  1079. Assert.Equal (
  1080. $"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.",
  1081. tv.Text
  1082. );
  1083. Assert.Equal (4, tv.Lines);
  1084. Assert.Equal (new Point (23, 1), tv.CursorPosition);
  1085. // Undo
  1086. Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl));
  1087. Assert.Equal (
  1088. $"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.",
  1089. tv.Text
  1090. );
  1091. Assert.Equal (3, tv.Lines);
  1092. Assert.Equal (new Point (23, 0), tv.CursorPosition);
  1093. // Redo
  1094. Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl));
  1095. Assert.Equal (
  1096. $"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.",
  1097. tv.Text
  1098. );
  1099. Assert.Equal (4, tv.Lines);
  1100. Assert.Equal (new Point (23, 1), tv.CursorPosition);
  1101. }
  1102. [Fact]
  1103. [AutoInitShutdown]
  1104. public void HistoryText_Undo_Redo_Cut_Multi_Line_Another_Selected_Paste ()
  1105. {
  1106. var text = "This is the first line.\nThis is the second line.\nThis is the third line.";
  1107. var tv = new TextView { Text = text };
  1108. tv.SelectionStartColumn = 12;
  1109. tv.CursorPosition = new Point (17, 0);
  1110. Assert.True (tv.NewKeyDownEvent (Key.W.WithCtrl));
  1111. Assert.Equal (
  1112. $"This is the line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.",
  1113. tv.Text
  1114. );
  1115. Assert.Equal ("", tv.SelectedText);
  1116. Assert.Equal (3, tv.Lines);
  1117. Assert.Equal (new Point (12, 0), tv.CursorPosition);
  1118. tv.SelectionStartColumn = 12;
  1119. tv.SelectionStartRow = 1;
  1120. tv.CursorPosition = new Point (18, 1);
  1121. Assert.True (tv.NewKeyDownEvent (Key.Y.WithCtrl));
  1122. Assert.Equal (
  1123. $"This is the line.{Environment.NewLine}This is the first line.{Environment.NewLine}This is the third line.",
  1124. tv.Text
  1125. );
  1126. Assert.Equal (3, tv.Lines);
  1127. Assert.Equal (new Point (17, 1), tv.CursorPosition);
  1128. // Undo
  1129. Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl));
  1130. Assert.Equal (
  1131. $"This is the line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.",
  1132. tv.Text
  1133. );
  1134. Assert.Equal (3, tv.Lines);
  1135. Assert.Equal (new Point (12, 1), tv.CursorPosition);
  1136. Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl));
  1137. Assert.Equal (
  1138. $"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.",
  1139. tv.Text
  1140. );
  1141. Assert.Equal (3, tv.Lines);
  1142. Assert.Equal (new Point (12, 0), tv.CursorPosition);
  1143. // Redo
  1144. Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl));
  1145. Assert.Equal (
  1146. $"This is the line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.",
  1147. tv.Text
  1148. );
  1149. Assert.Equal (3, tv.Lines);
  1150. Assert.Equal (new Point (12, 0), tv.CursorPosition);
  1151. Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl));
  1152. Assert.Equal (
  1153. $"This is the line.{Environment.NewLine}This is the first line.{Environment.NewLine}This is the third line.",
  1154. tv.Text
  1155. );
  1156. Assert.Equal (3, tv.Lines);
  1157. Assert.Equal (new Point (17, 1), tv.CursorPosition);
  1158. }
  1159. [Fact]
  1160. [AutoInitShutdown]
  1161. public void HistoryText_Undo_Redo_Cut_Multi_Line_Selected_Paste ()
  1162. {
  1163. var text = "This is the first line.\nThis is the second line.\nThis is the third line.";
  1164. var tv = new TextView { Text = text };
  1165. tv.SelectionStartColumn = 12;
  1166. tv.CursorPosition = new Point (17, 0);
  1167. Assert.True (tv.NewKeyDownEvent (Key.W.WithCtrl));
  1168. Assert.Equal (
  1169. $"This is the line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.",
  1170. tv.Text
  1171. );
  1172. Assert.Equal ("", tv.SelectedText);
  1173. Assert.Equal (3, tv.Lines);
  1174. Assert.Equal (new Point (12, 0), tv.CursorPosition);
  1175. tv.SelectionStartColumn = 12;
  1176. tv.CursorPosition = new Point (11, 1);
  1177. Assert.True (tv.NewKeyDownEvent (Key.Y.WithCtrl));
  1178. Assert.Equal ($"This is the first second line.{Environment.NewLine}This is the third line.", tv.Text);
  1179. Assert.Equal (2, tv.Lines);
  1180. Assert.Equal (new Point (17, 0), tv.CursorPosition);
  1181. // Undo
  1182. Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl));
  1183. Assert.Equal (
  1184. $"This is the line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.",
  1185. tv.Text
  1186. );
  1187. Assert.Equal (3, tv.Lines);
  1188. Assert.Equal (new Point (12, 0), tv.CursorPosition);
  1189. // Redo
  1190. Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl));
  1191. Assert.Equal ($"This is the first second line.{Environment.NewLine}This is the third line.", tv.Text);
  1192. Assert.Equal (2, tv.Lines);
  1193. Assert.Equal (new Point (17, 0), tv.CursorPosition);
  1194. }
  1195. [Fact]
  1196. [AutoInitShutdown]
  1197. public void HistoryText_Undo_Redo_Cut_Simple_Paste_Starting ()
  1198. {
  1199. var text = "This is the first line.\nThis is the second line.\nThis is the third line.";
  1200. var tv = new TextView { Text = text };
  1201. tv.SelectionStartColumn = 12;
  1202. tv.CursorPosition = new Point (18, 1);
  1203. Assert.True (tv.NewKeyDownEvent (Key.W.WithCtrl));
  1204. Assert.Equal ($"This is the line.{Environment.NewLine}This is the third line.", tv.Text);
  1205. Assert.Equal ("", tv.SelectedText);
  1206. Assert.Equal (2, tv.Lines);
  1207. Assert.Equal (new Point (12, 0), tv.CursorPosition);
  1208. tv.IsSelecting = false;
  1209. Assert.True (tv.NewKeyDownEvent (Key.Y.WithCtrl));
  1210. Assert.Equal (
  1211. $"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.",
  1212. tv.Text
  1213. );
  1214. Assert.Equal (3, tv.Lines);
  1215. Assert.Equal (new Point (18, 1), tv.CursorPosition);
  1216. // Undo
  1217. Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl));
  1218. Assert.Equal ($"This is the line.{Environment.NewLine}This is the third line.", tv.Text);
  1219. Assert.Equal (2, tv.Lines);
  1220. Assert.Equal (new Point (12, 0), tv.CursorPosition);
  1221. // Redo
  1222. Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl));
  1223. Assert.Equal (
  1224. $"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.",
  1225. tv.Text
  1226. );
  1227. Assert.Equal (3, tv.Lines);
  1228. Assert.Equal (new Point (18, 1), tv.CursorPosition);
  1229. }
  1230. [Fact]
  1231. public void HistoryText_Undo_Redo_Disabled_On_WordWrap ()
  1232. {
  1233. var text = "This is the first line.\nThis is the second line.\nThis is the third line.\n";
  1234. var tv = new TextView { Width = 80, Height = 5, Text = text };
  1235. Assert.False (tv.WordWrap);
  1236. tv.WordWrap = true;
  1237. tv.SelectionStartColumn = 12;
  1238. tv.CursorPosition = new Point (12, 2);
  1239. Assert.True (tv.NewKeyDownEvent (Key.Enter));
  1240. Assert.Equal ($"This is the {Environment.NewLine}third line.{Environment.NewLine}", tv.Text);
  1241. Assert.Equal (3, tv.Lines);
  1242. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  1243. Assert.True (tv.NewKeyDownEvent (Key.A));
  1244. Assert.Equal ($"This is the {Environment.NewLine}athird line.{Environment.NewLine}", tv.Text);
  1245. Assert.Equal (3, tv.Lines);
  1246. Assert.Equal (new Point (1, 1), tv.CursorPosition);
  1247. Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl));
  1248. Assert.Equal ($"This is the {Environment.NewLine}third line.{Environment.NewLine}", tv.Text);
  1249. Assert.Equal (3, tv.Lines);
  1250. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  1251. Assert.True (tv.IsDirty);
  1252. Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl));
  1253. Assert.Equal ($"This is the {Environment.NewLine}athird line.{Environment.NewLine}", tv.Text);
  1254. Assert.Equal (3, tv.Lines);
  1255. Assert.Equal (new Point (1, 1), tv.CursorPosition);
  1256. }
  1257. [Fact]
  1258. [AutoInitShutdown]
  1259. public void HistoryText_Undo_Redo_Empty_Copy_Without_Selection_Multi_Line_Selected_Paste ()
  1260. {
  1261. var text = "\nThis is the first line.\nThis is the second line.";
  1262. var tv = new TextView { Text = text };
  1263. Assert.True (tv.NewKeyDownEvent (Key.C.WithCtrl));
  1264. Assert.Equal (
  1265. $"{Environment.NewLine}This is the first line.{Environment.NewLine}This is the second line.",
  1266. tv.Text
  1267. );
  1268. Assert.Equal ("", tv.SelectedText);
  1269. Assert.Equal (3, tv.Lines);
  1270. Assert.Equal (Point.Empty, tv.CursorPosition);
  1271. Assert.True (tv.NewKeyDownEvent (Key.Y.WithCtrl));
  1272. Assert.Equal (
  1273. $"{Environment.NewLine}{Environment.NewLine}This is the first line.{Environment.NewLine}This is the second line.",
  1274. tv.Text
  1275. );
  1276. Assert.Equal (4, tv.Lines);
  1277. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  1278. // Undo
  1279. Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl));
  1280. Assert.Equal (
  1281. $"{Environment.NewLine}This is the first line.{Environment.NewLine}This is the second line.",
  1282. tv.Text
  1283. );
  1284. Assert.Equal (3, tv.Lines);
  1285. Assert.Equal (Point.Empty, tv.CursorPosition);
  1286. // Redo
  1287. Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl));
  1288. Assert.Equal (
  1289. $"{Environment.NewLine}{Environment.NewLine}This is the first line.{Environment.NewLine}This is the second line.",
  1290. tv.Text
  1291. );
  1292. Assert.Equal (4, tv.Lines);
  1293. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  1294. }
  1295. [Fact]
  1296. public void HistoryText_Undo_Redo_Ending_With_Newline_Multi_Line_Selected_Almost_All_Return_And_InsertText ()
  1297. {
  1298. var text = "This is the first line.\nThis is the second line.\nThis is the third line.\n";
  1299. var tv = new TextView { Text = text };
  1300. tv.SelectionStartColumn = 12;
  1301. tv.CursorPosition = new Point (12, 2);
  1302. Assert.True (tv.NewKeyDownEvent (Key.Enter));
  1303. Assert.Equal ($"This is the {Environment.NewLine}third line.{Environment.NewLine}", tv.Text);
  1304. Assert.Equal (3, tv.Lines);
  1305. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  1306. Assert.True (tv.NewKeyDownEvent (Key.A));
  1307. Assert.Equal ($"This is the {Environment.NewLine}athird line.{Environment.NewLine}", tv.Text);
  1308. Assert.Equal (3, tv.Lines);
  1309. Assert.Equal (new Point (1, 1), tv.CursorPosition);
  1310. // Undo
  1311. Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl));
  1312. Assert.Equal ($"This is the {Environment.NewLine}third line.{Environment.NewLine}", tv.Text);
  1313. Assert.Equal (3, tv.Lines);
  1314. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  1315. Assert.True (tv.IsDirty);
  1316. Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl));
  1317. Assert.Equal (
  1318. $"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.{Environment.NewLine}",
  1319. tv.Text
  1320. );
  1321. Assert.Equal (4, tv.Lines);
  1322. Assert.Equal (new Point (12, 2), tv.CursorPosition);
  1323. Assert.False (tv.IsDirty);
  1324. // Redo
  1325. Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl));
  1326. Assert.Equal ($"This is the {Environment.NewLine}third line.{Environment.NewLine}", tv.Text);
  1327. Assert.Equal (3, tv.Lines);
  1328. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  1329. Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl));
  1330. Assert.Equal ($"This is the {Environment.NewLine}athird line.{Environment.NewLine}", tv.Text);
  1331. Assert.Equal (3, tv.Lines);
  1332. Assert.Equal (new Point (1, 1), tv.CursorPosition);
  1333. // Undo
  1334. Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl));
  1335. Assert.Equal ($"This is the {Environment.NewLine}third line.{Environment.NewLine}", tv.Text);
  1336. Assert.Equal (3, tv.Lines);
  1337. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  1338. Assert.True (tv.IsDirty);
  1339. Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl));
  1340. Assert.Equal (
  1341. $"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.{Environment.NewLine}",
  1342. tv.Text
  1343. );
  1344. Assert.Equal (4, tv.Lines);
  1345. Assert.Equal (new Point (12, 2), tv.CursorPosition);
  1346. Assert.False (tv.IsDirty);
  1347. // Redo
  1348. Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl));
  1349. Assert.Equal ($"This is the {Environment.NewLine}third line.{Environment.NewLine}", tv.Text);
  1350. Assert.Equal (3, tv.Lines);
  1351. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  1352. Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl));
  1353. Assert.Equal ($"This is the {Environment.NewLine}athird line.{Environment.NewLine}", tv.Text);
  1354. Assert.Equal (3, tv.Lines);
  1355. Assert.Equal (new Point (1, 1), tv.CursorPosition);
  1356. }
  1357. [Fact]
  1358. public void HistoryText_Undo_Redo_First_Line_Selected_Return_And_InsertText ()
  1359. {
  1360. var text = "This is the first line.\nThis is the second line.\nThis is the third line.";
  1361. var tv = new TextView { Text = text };
  1362. tv.SelectionStartColumn = 12;
  1363. tv.CursorPosition = new Point (17, 0);
  1364. Assert.True (tv.NewKeyDownEvent (Key.Enter));
  1365. Assert.Equal (
  1366. $"This is the {Environment.NewLine} line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.",
  1367. tv.Text
  1368. );
  1369. Assert.Equal (4, tv.Lines);
  1370. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  1371. Assert.True (tv.NewKeyDownEvent (Key.A));
  1372. Assert.Equal (
  1373. $"This is the {Environment.NewLine}a line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.",
  1374. tv.Text
  1375. );
  1376. Assert.Equal (4, tv.Lines);
  1377. Assert.Equal (new Point (1, 1), tv.CursorPosition);
  1378. // Undo
  1379. Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl));
  1380. Assert.Equal (
  1381. $"This is the {Environment.NewLine} line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.",
  1382. tv.Text
  1383. );
  1384. Assert.Equal (4, tv.Lines);
  1385. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  1386. Assert.True (tv.IsDirty);
  1387. Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl));
  1388. Assert.Equal (
  1389. $"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.",
  1390. tv.Text
  1391. );
  1392. Assert.Equal (3, tv.Lines);
  1393. Assert.Equal (new Point (17, 0), tv.CursorPosition);
  1394. Assert.False (tv.IsDirty);
  1395. // Redo
  1396. Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl));
  1397. Assert.Equal (
  1398. $"This is the {Environment.NewLine} line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.",
  1399. tv.Text
  1400. );
  1401. Assert.Equal (4, tv.Lines);
  1402. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  1403. Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl));
  1404. Assert.Equal (
  1405. $"This is the {Environment.NewLine}a line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.",
  1406. tv.Text
  1407. );
  1408. Assert.Equal (4, tv.Lines);
  1409. Assert.Equal (new Point (1, 1), tv.CursorPosition);
  1410. // Undo
  1411. Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl));
  1412. Assert.Equal (
  1413. $"This is the {Environment.NewLine} line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.",
  1414. tv.Text
  1415. );
  1416. Assert.Equal (4, tv.Lines);
  1417. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  1418. Assert.True (tv.IsDirty);
  1419. Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl));
  1420. Assert.Equal (
  1421. $"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.",
  1422. tv.Text
  1423. );
  1424. Assert.Equal (3, tv.Lines);
  1425. Assert.Equal (new Point (17, 0), tv.CursorPosition);
  1426. Assert.False (tv.IsDirty);
  1427. // Redo
  1428. Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl));
  1429. Assert.Equal (
  1430. $"This is the {Environment.NewLine} line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.",
  1431. tv.Text
  1432. );
  1433. Assert.Equal (4, tv.Lines);
  1434. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  1435. Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl));
  1436. Assert.Equal (
  1437. $"This is the {Environment.NewLine}a line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.",
  1438. tv.Text
  1439. );
  1440. Assert.Equal (4, tv.Lines);
  1441. Assert.Equal (new Point (1, 1), tv.CursorPosition);
  1442. }
  1443. [Fact]
  1444. [AutoInitShutdown]
  1445. public void HistoryText_Undo_Redo_KillToEndOfLine ()
  1446. {
  1447. var text = "First line.\nSecond line.";
  1448. var tv = new TextView { Text = text };
  1449. Assert.True (tv.NewKeyDownEvent (Key.K.WithCtrl));
  1450. Assert.Equal ($"{Environment.NewLine}Second line.", tv.Text);
  1451. Assert.Equal ("", tv.SelectedText);
  1452. Assert.Equal ("First line.", Clipboard.Contents);
  1453. Assert.Equal (2, tv.Lines);
  1454. Assert.Equal (Point.Empty, tv.CursorPosition);
  1455. Assert.True (tv.NewKeyDownEvent (Key.K.WithCtrl));
  1456. Assert.Equal ("Second line.", tv.Text);
  1457. Assert.Equal ("", tv.SelectedText);
  1458. Assert.Equal ($"First line.{Environment.NewLine}", Clipboard.Contents);
  1459. Assert.Equal (1, tv.Lines);
  1460. Assert.Equal (Point.Empty, tv.CursorPosition);
  1461. Assert.True (tv.NewKeyDownEvent (Key.K.WithCtrl));
  1462. Assert.Equal ("", tv.Text);
  1463. Assert.Equal ("", tv.SelectedText);
  1464. Assert.Equal ($"First line.{Environment.NewLine}Second line.", Clipboard.Contents);
  1465. Assert.Equal (1, tv.Lines);
  1466. Assert.Equal (Point.Empty, tv.CursorPosition);
  1467. // Undo
  1468. Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl));
  1469. Assert.Equal ("Second line.", tv.Text);
  1470. Assert.Equal (1, tv.Lines);
  1471. Assert.Equal (Point.Empty, tv.CursorPosition);
  1472. Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl));
  1473. Assert.Equal ($"{Environment.NewLine}Second line.", tv.Text);
  1474. Assert.Equal (2, tv.Lines);
  1475. Assert.Equal (Point.Empty, tv.CursorPosition);
  1476. Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl));
  1477. Assert.Equal ($"First line.{Environment.NewLine}Second line.", tv.Text);
  1478. Assert.Equal (2, tv.Lines);
  1479. Assert.Equal (Point.Empty, tv.CursorPosition);
  1480. // Redo
  1481. Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl));
  1482. Assert.Equal ($"{Environment.NewLine}Second line.", tv.Text);
  1483. Assert.Equal (2, tv.Lines);
  1484. Assert.Equal (Point.Empty, tv.CursorPosition);
  1485. Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl));
  1486. Assert.Equal ("Second line.", tv.Text);
  1487. Assert.Equal (1, tv.Lines);
  1488. Assert.Equal (Point.Empty, tv.CursorPosition);
  1489. Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl));
  1490. Assert.Equal ("", tv.Text);
  1491. Assert.Equal (1, tv.Lines);
  1492. Assert.Equal (Point.Empty, tv.CursorPosition);
  1493. }
  1494. [Fact]
  1495. [AutoInitShutdown]
  1496. public void HistoryText_Undo_Redo_KillToLeftStart ()
  1497. {
  1498. var text = "First line.\nSecond line.";
  1499. var tv = new TextView { Text = text };
  1500. Assert.True (tv.NewKeyDownEvent (Key.End.WithCtrl));
  1501. Assert.Equal ($"First line.{Environment.NewLine}Second line.", tv.Text);
  1502. Assert.Equal ("", tv.SelectedText);
  1503. Assert.Equal (2, tv.Lines);
  1504. Assert.Equal (new Point (12, 1), tv.CursorPosition);
  1505. Assert.True (tv.NewKeyDownEvent (Key.Backspace.WithCtrl.WithShift));
  1506. Assert.Equal ($"First line.{Environment.NewLine}", tv.Text);
  1507. Assert.Equal ("", tv.SelectedText);
  1508. Assert.Equal ("Second line.", Clipboard.Contents);
  1509. Assert.Equal (2, tv.Lines);
  1510. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  1511. Assert.True (tv.NewKeyDownEvent (Key.Backspace.WithCtrl.WithShift));
  1512. Assert.Equal ("First line.", tv.Text);
  1513. Assert.Equal ("", tv.SelectedText);
  1514. Assert.Equal ($"Second line.{Environment.NewLine}", Clipboard.Contents);
  1515. Assert.Equal (1, tv.Lines);
  1516. Assert.Equal (new Point (11, 0), tv.CursorPosition);
  1517. Assert.True (tv.NewKeyDownEvent (Key.Backspace.WithCtrl.WithShift));
  1518. Assert.Equal ("", tv.Text);
  1519. Assert.Equal ("", tv.SelectedText);
  1520. Assert.Equal ($"Second line.{Environment.NewLine}First line.", Clipboard.Contents);
  1521. Assert.Equal (1, tv.Lines);
  1522. Assert.Equal (Point.Empty, tv.CursorPosition);
  1523. // Undo
  1524. Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl));
  1525. Assert.Equal ("First line.", tv.Text);
  1526. Assert.Equal (1, tv.Lines);
  1527. Assert.Equal (new Point (11, 0), tv.CursorPosition);
  1528. Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl));
  1529. Assert.Equal ($"First line.{Environment.NewLine}", tv.Text);
  1530. Assert.Equal (2, tv.Lines);
  1531. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  1532. Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl));
  1533. Assert.Equal ($"First line.{Environment.NewLine}Second line.", tv.Text);
  1534. Assert.Equal (2, tv.Lines);
  1535. Assert.Equal (new Point (12, 1), tv.CursorPosition);
  1536. // Redo
  1537. Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl));
  1538. Assert.Equal ($"First line.{Environment.NewLine}", tv.Text);
  1539. Assert.Equal (2, tv.Lines);
  1540. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  1541. Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl));
  1542. Assert.Equal ("First line.", tv.Text);
  1543. Assert.Equal (1, tv.Lines);
  1544. Assert.Equal (new Point (11, 0), tv.CursorPosition);
  1545. Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl));
  1546. Assert.Equal ("", tv.Text);
  1547. Assert.Equal (1, tv.Lines);
  1548. Assert.Equal (Point.Empty, tv.CursorPosition);
  1549. }
  1550. [Fact]
  1551. public void HistoryText_Undo_Redo_KillWordBackward ()
  1552. {
  1553. var text = "First line.\nSecond line.";
  1554. var tv = new TextView { Text = text };
  1555. Assert.True (tv.NewKeyDownEvent (Key.End.WithCtrl));
  1556. Assert.Equal ($"First line.{Environment.NewLine}Second line.", tv.Text);
  1557. Assert.Equal ("", tv.SelectedText);
  1558. Assert.Equal (2, tv.Lines);
  1559. Assert.Equal (new Point (12, 1), tv.CursorPosition);
  1560. Assert.True (tv.NewKeyDownEvent (Key.Backspace.WithCtrl));
  1561. Assert.Equal ($"First line.{Environment.NewLine}Second line", tv.Text);
  1562. Assert.Equal ("", tv.SelectedText);
  1563. Assert.Equal (2, tv.Lines);
  1564. Assert.Equal (new Point (11, 1), tv.CursorPosition);
  1565. Assert.True (tv.NewKeyDownEvent (Key.Backspace.WithCtrl));
  1566. Assert.Equal ($"First line.{Environment.NewLine}Second ", tv.Text);
  1567. Assert.Equal ("", tv.SelectedText);
  1568. Assert.Equal (2, tv.Lines);
  1569. Assert.Equal (new Point (7, 1), tv.CursorPosition);
  1570. Assert.True (tv.NewKeyDownEvent (Key.Backspace.WithCtrl));
  1571. Assert.Equal ($"First line.{Environment.NewLine}", tv.Text);
  1572. Assert.Equal ("", tv.SelectedText);
  1573. Assert.Equal (2, tv.Lines);
  1574. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  1575. Assert.True (tv.NewKeyDownEvent (Key.Backspace.WithCtrl));
  1576. Assert.Equal ("First line.", tv.Text);
  1577. Assert.Equal ("", tv.SelectedText);
  1578. Assert.Equal (1, tv.Lines);
  1579. Assert.Equal (new Point (11, 0), tv.CursorPosition);
  1580. Assert.True (tv.NewKeyDownEvent (Key.Backspace.WithCtrl));
  1581. Assert.Equal ("First line", tv.Text);
  1582. Assert.Equal ("", tv.SelectedText);
  1583. Assert.Equal (1, tv.Lines);
  1584. Assert.Equal (new Point (10, 0), tv.CursorPosition);
  1585. Assert.True (tv.NewKeyDownEvent (Key.Backspace.WithCtrl));
  1586. Assert.Equal ("First ", tv.Text);
  1587. Assert.Equal ("", tv.SelectedText);
  1588. Assert.Equal (1, tv.Lines);
  1589. Assert.Equal (new Point (6, 0), tv.CursorPosition);
  1590. Assert.True (tv.NewKeyDownEvent (Key.Backspace.WithCtrl));
  1591. Assert.Equal ("", tv.Text);
  1592. Assert.Equal ("", tv.SelectedText);
  1593. Assert.Equal (1, tv.Lines);
  1594. Assert.Equal (Point.Empty, tv.CursorPosition);
  1595. // Undo
  1596. Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl));
  1597. Assert.Equal ("First ", tv.Text);
  1598. Assert.Equal (1, tv.Lines);
  1599. Assert.Equal (new Point (6, 0), tv.CursorPosition);
  1600. Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl));
  1601. Assert.Equal ("First line", tv.Text);
  1602. Assert.Equal (1, tv.Lines);
  1603. Assert.Equal (new Point (10, 0), tv.CursorPosition);
  1604. Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl));
  1605. Assert.Equal ("First line.", tv.Text);
  1606. Assert.Equal (1, tv.Lines);
  1607. Assert.Equal (new Point (11, 0), tv.CursorPosition);
  1608. Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl));
  1609. Assert.Equal ($"First line.{Environment.NewLine}", tv.Text);
  1610. Assert.Equal (2, tv.Lines);
  1611. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  1612. Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl));
  1613. Assert.Equal ($"First line.{Environment.NewLine}Second ", tv.Text);
  1614. Assert.Equal (2, tv.Lines);
  1615. Assert.Equal (new Point (7, 1), tv.CursorPosition);
  1616. Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl));
  1617. Assert.Equal ($"First line.{Environment.NewLine}Second line", tv.Text);
  1618. Assert.Equal (2, tv.Lines);
  1619. Assert.Equal (new Point (11, 1), tv.CursorPosition);
  1620. Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl));
  1621. Assert.Equal ($"First line.{Environment.NewLine}Second line.", tv.Text);
  1622. Assert.Equal (2, tv.Lines);
  1623. Assert.Equal (new Point (12, 1), tv.CursorPosition);
  1624. // Redo
  1625. Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl));
  1626. Assert.Equal ($"First line.{Environment.NewLine}Second line", tv.Text);
  1627. Assert.Equal (2, tv.Lines);
  1628. Assert.Equal (new Point (11, 1), tv.CursorPosition);
  1629. Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl));
  1630. Assert.Equal ($"First line.{Environment.NewLine}Second ", tv.Text);
  1631. Assert.Equal (2, tv.Lines);
  1632. Assert.Equal (new Point (7, 1), tv.CursorPosition);
  1633. Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl));
  1634. Assert.Equal ($"First line.{Environment.NewLine}", tv.Text);
  1635. Assert.Equal (2, tv.Lines);
  1636. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  1637. Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl));
  1638. Assert.Equal ("First line.", tv.Text);
  1639. Assert.Equal (1, tv.Lines);
  1640. Assert.Equal (new Point (11, 0), tv.CursorPosition);
  1641. Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl));
  1642. Assert.Equal ("First line", tv.Text);
  1643. Assert.Equal (1, tv.Lines);
  1644. Assert.Equal (new Point (10, 0), tv.CursorPosition);
  1645. Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl));
  1646. Assert.Equal ("First ", tv.Text);
  1647. Assert.Equal (1, tv.Lines);
  1648. Assert.Equal (new Point (6, 0), tv.CursorPosition);
  1649. Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl));
  1650. Assert.Equal ("", tv.Text);
  1651. Assert.Equal (1, tv.Lines);
  1652. Assert.Equal (Point.Empty, tv.CursorPosition);
  1653. }
  1654. [Fact]
  1655. public void HistoryText_Undo_Redo_KillWordForward ()
  1656. {
  1657. var text = "First line.\nSecond line.";
  1658. var tv = new TextView { Text = text };
  1659. Assert.True (tv.NewKeyDownEvent (Key.Delete.WithCtrl));
  1660. Assert.Equal ($"line.{Environment.NewLine}Second line.", tv.Text);
  1661. Assert.Equal ("", tv.SelectedText);
  1662. Assert.Equal (2, tv.Lines);
  1663. Assert.Equal (Point.Empty, tv.CursorPosition);
  1664. Assert.True (tv.NewKeyDownEvent (Key.Delete.WithCtrl));
  1665. Assert.Equal ($"{Environment.NewLine}Second line.", tv.Text);
  1666. Assert.Equal (2, tv.Lines);
  1667. Assert.Equal (Point.Empty, tv.CursorPosition);
  1668. Assert.True (tv.NewKeyDownEvent (Key.Delete.WithCtrl));
  1669. Assert.Equal ("Second line.", tv.Text);
  1670. Assert.Equal (1, tv.Lines);
  1671. Assert.Equal (Point.Empty, tv.CursorPosition);
  1672. Assert.True (tv.NewKeyDownEvent (Key.Delete.WithCtrl));
  1673. Assert.Equal ("line.", tv.Text);
  1674. Assert.Equal (1, tv.Lines);
  1675. Assert.Equal (Point.Empty, tv.CursorPosition);
  1676. Assert.True (tv.NewKeyDownEvent (Key.Delete.WithCtrl));
  1677. Assert.Equal ("", tv.Text);
  1678. Assert.Equal (1, tv.Lines);
  1679. Assert.Equal (Point.Empty, tv.CursorPosition);
  1680. // Undo
  1681. Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl));
  1682. Assert.Equal ("line.", tv.Text);
  1683. Assert.Equal (1, tv.Lines);
  1684. Assert.Equal (Point.Empty, tv.CursorPosition);
  1685. Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl));
  1686. Assert.Equal ("Second line.", tv.Text);
  1687. Assert.Equal (1, tv.Lines);
  1688. Assert.Equal (Point.Empty, tv.CursorPosition);
  1689. Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl));
  1690. Assert.Equal ($"{Environment.NewLine}Second line.", tv.Text);
  1691. Assert.Equal (2, tv.Lines);
  1692. Assert.Equal (Point.Empty, tv.CursorPosition);
  1693. Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl));
  1694. Assert.Equal ($"line.{Environment.NewLine}Second line.", tv.Text);
  1695. Assert.Equal (2, tv.Lines);
  1696. Assert.Equal (Point.Empty, tv.CursorPosition);
  1697. Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl));
  1698. Assert.Equal ($"First line.{Environment.NewLine}Second line.", tv.Text);
  1699. Assert.Equal (2, tv.Lines);
  1700. Assert.Equal (Point.Empty, tv.CursorPosition);
  1701. // Redo
  1702. Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl));
  1703. Assert.Equal ($"line.{Environment.NewLine}Second line.", tv.Text);
  1704. Assert.Equal (2, tv.Lines);
  1705. Assert.Equal (Point.Empty, tv.CursorPosition);
  1706. Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl));
  1707. Assert.Equal ($"{Environment.NewLine}Second line.", tv.Text);
  1708. Assert.Equal (2, tv.Lines);
  1709. Assert.Equal (Point.Empty, tv.CursorPosition);
  1710. Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl));
  1711. Assert.Equal ("Second line.", tv.Text);
  1712. Assert.Equal (1, tv.Lines);
  1713. Assert.Equal (Point.Empty, tv.CursorPosition);
  1714. Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl));
  1715. Assert.Equal ("line.", tv.Text);
  1716. Assert.Equal (1, tv.Lines);
  1717. Assert.Equal (Point.Empty, tv.CursorPosition);
  1718. Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl));
  1719. Assert.Equal ("", tv.Text);
  1720. Assert.Equal (1, tv.Lines);
  1721. Assert.Equal (Point.Empty, tv.CursorPosition);
  1722. }
  1723. [Fact]
  1724. [AutoInitShutdown]
  1725. public void HistoryText_Undo_Redo_Multi_Line_DeleteCharLeft ()
  1726. {
  1727. var text = "This is the first line.\nThis is the second line.\nThis is the third line.";
  1728. var tv = new TextView { Width = 10, Height = 2, Text = text };
  1729. Toplevel top = new ();
  1730. top.Add (tv);
  1731. Application.Begin (top);
  1732. Assert.Equal (
  1733. $"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.",
  1734. tv.Text
  1735. );
  1736. Assert.Equal (3, tv.Lines);
  1737. Assert.Equal (Point.Empty, tv.CursorPosition);
  1738. var ntimes = 3;
  1739. tv.CursorPosition = new Point (7, 1);
  1740. for (var i = 0; i < ntimes; i++)
  1741. {
  1742. tv.DeleteCharLeft ();
  1743. }
  1744. Assert.Equal (
  1745. $"This is the first line.{Environment.NewLine}This the second line.{Environment.NewLine}This is the third line.",
  1746. tv.Text
  1747. );
  1748. Assert.Equal (3, tv.Lines);
  1749. Assert.Equal (new Point (4, 1), tv.CursorPosition);
  1750. tv.CursorPosition = new Point (7, 0);
  1751. for (var i = 0; i < ntimes; i++)
  1752. {
  1753. tv.DeleteCharLeft ();
  1754. }
  1755. Assert.Equal (
  1756. $"This the first line.{Environment.NewLine}This the second line.{Environment.NewLine}This is the third line.",
  1757. tv.Text
  1758. );
  1759. Assert.Equal (3, tv.Lines);
  1760. Assert.Equal (new Point (4, 0), tv.CursorPosition);
  1761. tv.CursorPosition = new Point (7, 2);
  1762. for (var i = 0; i < ntimes; i++)
  1763. {
  1764. tv.DeleteCharLeft ();
  1765. }
  1766. Assert.Equal (
  1767. $"This the first line.{Environment.NewLine}This the second line.{Environment.NewLine}This the third line.",
  1768. tv.Text
  1769. );
  1770. Assert.Equal (3, tv.Lines);
  1771. Assert.Equal (new Point (4, 2), tv.CursorPosition);
  1772. for (var i = 0; i < ntimes; i++)
  1773. {
  1774. Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl));
  1775. switch (i)
  1776. {
  1777. case 0:
  1778. Assert.Equal (
  1779. $"This the first line.{Environment.NewLine}This the second line.{Environment.NewLine}This the third line.",
  1780. tv.Text
  1781. );
  1782. Assert.Equal (new Point (5, 2), tv.CursorPosition);
  1783. break;
  1784. case 1:
  1785. Assert.Equal (
  1786. $"This the first line.{Environment.NewLine}This the second line.{Environment.NewLine}This i the third line.",
  1787. tv.Text
  1788. );
  1789. Assert.Equal (new Point (6, 2), tv.CursorPosition);
  1790. break;
  1791. case 2:
  1792. Assert.Equal (
  1793. $"This the first line.{Environment.NewLine}This the second line.{Environment.NewLine}This is the third line.",
  1794. tv.Text
  1795. );
  1796. Assert.Equal (new Point (7, 2), tv.CursorPosition);
  1797. break;
  1798. }
  1799. }
  1800. Assert.Equal (
  1801. $"This the first line.{Environment.NewLine}This the second line.{Environment.NewLine}This is the third line.",
  1802. tv.Text
  1803. );
  1804. Assert.Equal (3, tv.Lines);
  1805. Assert.Equal (new Point (7, 2), tv.CursorPosition);
  1806. for (var i = 0; i < ntimes; i++)
  1807. {
  1808. Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl));
  1809. switch (i)
  1810. {
  1811. case 0:
  1812. Assert.Equal (
  1813. $"This the first line.{Environment.NewLine}This the second line.{Environment.NewLine}This is the third line.",
  1814. tv.Text
  1815. );
  1816. Assert.Equal (new Point (5, 0), tv.CursorPosition);
  1817. break;
  1818. case 1:
  1819. Assert.Equal (
  1820. $"This i the first line.{Environment.NewLine}This the second line.{Environment.NewLine}This is the third line.",
  1821. tv.Text
  1822. );
  1823. Assert.Equal (new Point (6, 0), tv.CursorPosition);
  1824. break;
  1825. case 2:
  1826. Assert.Equal (
  1827. $"This is the first line.{Environment.NewLine}This the second line.{Environment.NewLine}This is the third line.",
  1828. tv.Text
  1829. );
  1830. Assert.Equal (new Point (7, 0), tv.CursorPosition);
  1831. break;
  1832. }
  1833. }
  1834. Assert.Equal (
  1835. $"This is the first line.{Environment.NewLine}This the second line.{Environment.NewLine}This is the third line.",
  1836. tv.Text
  1837. );
  1838. Assert.Equal (3, tv.Lines);
  1839. Assert.Equal (new Point (7, 0), tv.CursorPosition);
  1840. for (var i = 0; i < ntimes; i++)
  1841. {
  1842. Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl));
  1843. switch (i)
  1844. {
  1845. case 0:
  1846. Assert.Equal (
  1847. $"This is the first line.{Environment.NewLine}This the second line.{Environment.NewLine}This is the third line.",
  1848. tv.Text
  1849. );
  1850. Assert.Equal (new Point (5, 1), tv.CursorPosition);
  1851. break;
  1852. case 1:
  1853. Assert.Equal (
  1854. $"This is the first line.{Environment.NewLine}This i the second line.{Environment.NewLine}This is the third line.",
  1855. tv.Text
  1856. );
  1857. Assert.Equal (new Point (6, 1), tv.CursorPosition);
  1858. break;
  1859. case 2:
  1860. Assert.Equal (
  1861. $"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.",
  1862. tv.Text
  1863. );
  1864. Assert.Equal (new Point (7, 1), tv.CursorPosition);
  1865. break;
  1866. }
  1867. }
  1868. Assert.Equal (
  1869. $"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.",
  1870. tv.Text
  1871. );
  1872. Assert.Equal (3, tv.Lines);
  1873. Assert.Equal (new Point (7, 1), tv.CursorPosition);
  1874. for (var i = 0; i < ntimes; i++)
  1875. {
  1876. Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl));
  1877. }
  1878. Assert.Equal (
  1879. $"This is the first line.{Environment.NewLine}This the second line.{Environment.NewLine}This is the third line.",
  1880. tv.Text
  1881. );
  1882. Assert.Equal (3, tv.Lines);
  1883. Assert.Equal (new Point (4, 1), tv.CursorPosition);
  1884. for (var i = 0; i < ntimes; i++)
  1885. {
  1886. Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl));
  1887. }
  1888. Assert.Equal (
  1889. $"This the first line.{Environment.NewLine}This the second line.{Environment.NewLine}This is the third line.",
  1890. tv.Text
  1891. );
  1892. Assert.Equal (3, tv.Lines);
  1893. Assert.Equal (new Point (4, 0), tv.CursorPosition);
  1894. for (var i = 0; i < ntimes; i++)
  1895. {
  1896. Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl));
  1897. }
  1898. Assert.Equal (
  1899. $"This the first line.{Environment.NewLine}This the second line.{Environment.NewLine}This the third line.",
  1900. tv.Text
  1901. );
  1902. Assert.Equal (3, tv.Lines);
  1903. Assert.Equal (new Point (4, 2), tv.CursorPosition);
  1904. top.Dispose ();
  1905. }
  1906. [Fact]
  1907. [AutoInitShutdown]
  1908. public void HistoryText_Undo_Redo_Multi_Line_DeleteCharRight ()
  1909. {
  1910. var text = "This is the first line.\nThis is the second line.\nThis is the third line.";
  1911. var tv = new TextView { Width = 10, Height = 2, Text = text };
  1912. Toplevel top = new ();
  1913. top.Add (tv);
  1914. Application.Begin (top);
  1915. Assert.Equal (
  1916. $"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.",
  1917. tv.Text
  1918. );
  1919. Assert.Equal (3, tv.Lines);
  1920. Assert.Equal (Point.Empty, tv.CursorPosition);
  1921. var ntimes = 3;
  1922. tv.CursorPosition = new Point (7, 1);
  1923. for (var i = 0; i < ntimes; i++)
  1924. {
  1925. tv.DeleteCharRight ();
  1926. }
  1927. Assert.Equal (
  1928. $"This is the first line.{Environment.NewLine}This ise second line.{Environment.NewLine}This is the third line.",
  1929. tv.Text
  1930. );
  1931. Assert.Equal (3, tv.Lines);
  1932. Assert.Equal (new Point (7, 1), tv.CursorPosition);
  1933. tv.CursorPosition = new Point (7, 0);
  1934. for (var i = 0; i < ntimes; i++)
  1935. {
  1936. tv.DeleteCharRight ();
  1937. }
  1938. Assert.Equal (
  1939. $"This ise first line.{Environment.NewLine}This ise second line.{Environment.NewLine}This is the third line.",
  1940. tv.Text
  1941. );
  1942. Assert.Equal (3, tv.Lines);
  1943. Assert.Equal (new Point (7, 0), tv.CursorPosition);
  1944. tv.CursorPosition = new Point (7, 2);
  1945. for (var i = 0; i < ntimes; i++)
  1946. {
  1947. tv.DeleteCharRight ();
  1948. }
  1949. Assert.Equal (
  1950. $"This ise first line.{Environment.NewLine}This ise second line.{Environment.NewLine}This ise third line.",
  1951. tv.Text
  1952. );
  1953. Assert.Equal (3, tv.Lines);
  1954. Assert.Equal (new Point (7, 2), tv.CursorPosition);
  1955. for (var i = 0; i < ntimes; i++)
  1956. {
  1957. Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl));
  1958. }
  1959. Assert.Equal (
  1960. $"This ise first line.{Environment.NewLine}This ise second line.{Environment.NewLine}This is the third line.",
  1961. tv.Text
  1962. );
  1963. Assert.Equal (3, tv.Lines);
  1964. Assert.Equal (new Point (7, 2), tv.CursorPosition);
  1965. for (var i = 0; i < ntimes; i++)
  1966. {
  1967. Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl));
  1968. }
  1969. Assert.Equal (
  1970. $"This is the first line.{Environment.NewLine}This ise second line.{Environment.NewLine}This is the third line.",
  1971. tv.Text
  1972. );
  1973. Assert.Equal (3, tv.Lines);
  1974. Assert.Equal (new Point (7, 0), tv.CursorPosition);
  1975. for (var i = 0; i < ntimes; i++)
  1976. {
  1977. Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl));
  1978. }
  1979. Assert.Equal (
  1980. $"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.",
  1981. tv.Text
  1982. );
  1983. Assert.Equal (3, tv.Lines);
  1984. Assert.Equal (new Point (7, 1), tv.CursorPosition);
  1985. for (var i = 0; i < ntimes; i++)
  1986. {
  1987. Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl));
  1988. }
  1989. Assert.Equal (
  1990. $"This is the first line.{Environment.NewLine}This ise second line.{Environment.NewLine}This is the third line.",
  1991. tv.Text
  1992. );
  1993. Assert.Equal (3, tv.Lines);
  1994. Assert.Equal (new Point (7, 1), tv.CursorPosition);
  1995. for (var i = 0; i < ntimes; i++)
  1996. {
  1997. Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl));
  1998. }
  1999. Assert.Equal (
  2000. $"This ise first line.{Environment.NewLine}This ise second line.{Environment.NewLine}This is the third line.",
  2001. tv.Text
  2002. );
  2003. Assert.Equal (3, tv.Lines);
  2004. Assert.Equal (new Point (7, 0), tv.CursorPosition);
  2005. for (var i = 0; i < ntimes; i++)
  2006. {
  2007. Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl));
  2008. }
  2009. Assert.Equal (
  2010. $"This ise first line.{Environment.NewLine}This ise second line.{Environment.NewLine}This ise third line.",
  2011. tv.Text
  2012. );
  2013. Assert.Equal (3, tv.Lines);
  2014. Assert.Equal (new Point (7, 2), tv.CursorPosition);
  2015. top.Dispose ();
  2016. }
  2017. [Fact]
  2018. [AutoInitShutdown]
  2019. public void HistoryText_Undo_Redo_Multi_Line_InsertText ()
  2020. {
  2021. var text = "This is the first line.\nThis is the second line.\nThis is the third line.";
  2022. var tv = new TextView { Width = 10, Height = 2, Text = text };
  2023. Toplevel top = new ();
  2024. top.Add (tv);
  2025. Application.Begin (top);
  2026. Assert.Equal (
  2027. $"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.",
  2028. tv.Text
  2029. );
  2030. Assert.Equal (3, tv.Lines);
  2031. Assert.Equal (Point.Empty, tv.CursorPosition);
  2032. var messy = " messy";
  2033. tv.CursorPosition = new Point (7, 1);
  2034. tv.InsertText (messy);
  2035. Assert.Equal (
  2036. $"This is the first line.{Environment.NewLine}This is messy the second line.{Environment.NewLine}This is the third line.",
  2037. tv.Text
  2038. );
  2039. Assert.Equal (3, tv.Lines);
  2040. Assert.Equal (new Point (13, 1), tv.CursorPosition);
  2041. tv.CursorPosition = new Point (7, 0);
  2042. tv.InsertText (messy);
  2043. Assert.Equal (
  2044. $"This is messy the first line.{Environment.NewLine}This is messy the second line.{Environment.NewLine}This is the third line.",
  2045. tv.Text
  2046. );
  2047. Assert.Equal (3, tv.Lines);
  2048. Assert.Equal (new Point (13, 0), tv.CursorPosition);
  2049. tv.CursorPosition = new Point (7, 2);
  2050. tv.InsertText (messy);
  2051. Assert.Equal (
  2052. $"This is messy the first line.{Environment.NewLine}This is messy the second line.{Environment.NewLine}This is messy the third line.",
  2053. tv.Text
  2054. );
  2055. Assert.Equal (3, tv.Lines);
  2056. Assert.Equal (new Point (13, 2), tv.CursorPosition);
  2057. for (var i = 0; i < messy.Length; i++)
  2058. {
  2059. Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl));
  2060. }
  2061. Assert.Equal (
  2062. $"This is messy the first line.{Environment.NewLine}This is messy the second line.{Environment.NewLine}This is the third line.",
  2063. tv.Text
  2064. );
  2065. Assert.Equal (3, tv.Lines);
  2066. Assert.Equal (new Point (7, 2), tv.CursorPosition);
  2067. for (var i = 0; i < messy.Length; i++)
  2068. {
  2069. Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl));
  2070. }
  2071. Assert.Equal (
  2072. $"This is the first line.{Environment.NewLine}This is messy the second line.{Environment.NewLine}This is the third line.",
  2073. tv.Text
  2074. );
  2075. Assert.Equal (3, tv.Lines);
  2076. Assert.Equal (new Point (7, 0), tv.CursorPosition);
  2077. for (var i = 0; i < messy.Length; i++)
  2078. {
  2079. Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl));
  2080. }
  2081. Assert.Equal (
  2082. $"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.",
  2083. tv.Text
  2084. );
  2085. Assert.Equal (3, tv.Lines);
  2086. Assert.Equal (new Point (7, 1), tv.CursorPosition);
  2087. for (var i = 0; i < messy.Length; i++)
  2088. {
  2089. Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl));
  2090. }
  2091. Assert.Equal (
  2092. $"This is the first line.{Environment.NewLine}This is messy the second line.{Environment.NewLine}This is the third line.",
  2093. tv.Text
  2094. );
  2095. Assert.Equal (3, tv.Lines);
  2096. Assert.Equal (new Point (13, 1), tv.CursorPosition);
  2097. for (var i = 0; i < messy.Length; i++)
  2098. {
  2099. Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl));
  2100. }
  2101. Assert.Equal (
  2102. $"This is messy the first line.{Environment.NewLine}This is messy the second line.{Environment.NewLine}This is the third line.",
  2103. tv.Text
  2104. );
  2105. Assert.Equal (3, tv.Lines);
  2106. Assert.Equal (new Point (13, 0), tv.CursorPosition);
  2107. for (var i = 0; i < messy.Length; i++)
  2108. {
  2109. Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl));
  2110. }
  2111. Assert.Equal (
  2112. $"This is messy the first line.{Environment.NewLine}This is messy the second line.{Environment.NewLine}This is messy the third line.",
  2113. tv.Text
  2114. );
  2115. Assert.Equal (3, tv.Lines);
  2116. Assert.Equal (new Point (13, 2), tv.CursorPosition);
  2117. top.Dispose ();
  2118. }
  2119. [Fact]
  2120. public void HistoryText_Undo_Redo_Multi_Line_Selected_All_Return_And_InsertText ()
  2121. {
  2122. var text = "This is the first line.\nThis is the second line.\nThis is the third line.";
  2123. var tv = new TextView { Text = text };
  2124. Assert.True (tv.NewKeyDownEvent (Key.End.WithCtrl.WithShift));
  2125. Assert.Equal (
  2126. $"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.",
  2127. tv.Text
  2128. );
  2129. Assert.Equal (3, tv.Lines);
  2130. Assert.Equal (new Point (23, 2), tv.CursorPosition);
  2131. Assert.True (tv.NewKeyDownEvent (Key.Enter));
  2132. Assert.Equal ($"{Environment.NewLine}", tv.Text);
  2133. Assert.Equal (2, tv.Lines);
  2134. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  2135. Assert.True (tv.NewKeyDownEvent (Key.A));
  2136. Assert.Equal ($"{Environment.NewLine}a", tv.Text);
  2137. Assert.Equal (2, tv.Lines);
  2138. Assert.Equal (new Point (1, 1), tv.CursorPosition);
  2139. // Undo
  2140. Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl));
  2141. Assert.Equal ($"{Environment.NewLine}", tv.Text);
  2142. Assert.Equal (2, tv.Lines);
  2143. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  2144. Assert.True (tv.IsDirty);
  2145. Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl));
  2146. Assert.Equal (
  2147. $"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.",
  2148. tv.Text
  2149. );
  2150. Assert.Equal (3, tv.Lines);
  2151. Assert.Equal (new Point (23, 2), tv.CursorPosition);
  2152. Assert.False (tv.IsDirty);
  2153. // Redo
  2154. Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl));
  2155. Assert.Equal ($"{Environment.NewLine}", tv.Text);
  2156. Assert.Equal (2, tv.Lines);
  2157. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  2158. Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl));
  2159. Assert.Equal ($"{Environment.NewLine}a", tv.Text);
  2160. Assert.Equal (2, tv.Lines);
  2161. Assert.Equal (new Point (1, 1), tv.CursorPosition);
  2162. // Undo
  2163. Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl));
  2164. Assert.Equal ($"{Environment.NewLine}", tv.Text);
  2165. Assert.Equal (2, tv.Lines);
  2166. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  2167. Assert.True (tv.IsDirty);
  2168. Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl));
  2169. Assert.Equal (
  2170. $"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.",
  2171. tv.Text
  2172. );
  2173. Assert.Equal (3, tv.Lines);
  2174. Assert.Equal (new Point (23, 2), tv.CursorPosition);
  2175. Assert.False (tv.IsDirty);
  2176. // Redo
  2177. Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl));
  2178. Assert.Equal ($"{Environment.NewLine}", tv.Text);
  2179. Assert.Equal (2, tv.Lines);
  2180. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  2181. Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl));
  2182. Assert.Equal ($"{Environment.NewLine}a", tv.Text);
  2183. Assert.Equal (2, tv.Lines);
  2184. Assert.Equal (new Point (1, 1), tv.CursorPosition);
  2185. }
  2186. [Fact]
  2187. [AutoInitShutdown]
  2188. public void HistoryText_Undo_Redo_Multi_Line_Selected_Copy_Simple_Paste_Starting_On_Letter ()
  2189. {
  2190. var text = "This is the first line.\nThis is the second line.\nThis is the third line.";
  2191. var tv = new TextView { Text = text };
  2192. tv.SelectionStartColumn = 12;
  2193. tv.CursorPosition = new Point (18, 1);
  2194. Assert.True (tv.NewKeyDownEvent (Key.C.WithCtrl));
  2195. Assert.Equal (
  2196. $"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.",
  2197. tv.Text
  2198. );
  2199. Assert.Equal ($"first line.{Environment.NewLine}This is the second", tv.SelectedText);
  2200. Assert.Equal (3, tv.Lines);
  2201. Assert.Equal (new Point (18, 1), tv.CursorPosition);
  2202. tv.IsSelecting = false;
  2203. tv.CursorPosition = new Point (17, 1);
  2204. Assert.True (tv.NewKeyDownEvent (Key.Y.WithCtrl));
  2205. Assert.Equal (
  2206. $"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.",
  2207. tv.Text
  2208. );
  2209. Assert.Equal (4, tv.Lines);
  2210. Assert.Equal (new Point (18, 2), tv.CursorPosition);
  2211. // Undo
  2212. Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl));
  2213. Assert.Equal (
  2214. $"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.",
  2215. tv.Text
  2216. );
  2217. Assert.Equal (3, tv.Lines);
  2218. Assert.Equal (new Point (17, 1), tv.CursorPosition);
  2219. // Redo
  2220. Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl));
  2221. Assert.Equal (
  2222. $"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.",
  2223. tv.Text
  2224. );
  2225. Assert.Equal (4, tv.Lines);
  2226. Assert.Equal (new Point (18, 2), tv.CursorPosition);
  2227. }
  2228. [Fact]
  2229. [AutoInitShutdown (useFakeClipboard: true)]
  2230. public void HistoryText_Undo_Redo_Multi_Line_Selected_Copy_Simple_Paste_Starting_On_Space ()
  2231. {
  2232. var text = "This is the first line.\nThis is the second line.\nThis is the third line.";
  2233. var tv = new TextView { Text = text };
  2234. tv.SelectionStartColumn = 12;
  2235. tv.CursorPosition = new Point (18, 1);
  2236. Assert.True (tv.NewKeyDownEvent (Key.C.WithCtrl));
  2237. Assert.Equal (
  2238. $"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.",
  2239. tv.Text
  2240. );
  2241. Assert.Equal ($"first line.{Environment.NewLine}This is the second", tv.SelectedText);
  2242. Assert.Equal (3, tv.Lines);
  2243. Assert.Equal (new Point (18, 1), tv.CursorPosition);
  2244. tv.IsSelecting = false;
  2245. Assert.True (tv.NewKeyDownEvent (Key.Y.WithCtrl));
  2246. Assert.Equal (
  2247. $"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.",
  2248. tv.Text
  2249. );
  2250. Assert.Equal (4, tv.Lines);
  2251. Assert.Equal (new Point (18, 2), tv.CursorPosition);
  2252. // Undo
  2253. Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl));
  2254. Assert.Equal (
  2255. $"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.",
  2256. tv.Text
  2257. );
  2258. Assert.Equal (3, tv.Lines);
  2259. Assert.Equal (new Point (18, 1), tv.CursorPosition);
  2260. // Redo
  2261. Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl));
  2262. Assert.Equal (
  2263. $"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.",
  2264. tv.Text
  2265. );
  2266. Assert.Equal (4, tv.Lines);
  2267. Assert.Equal (new Point (18, 2), tv.CursorPosition);
  2268. }
  2269. [Fact]
  2270. public void HistoryText_Undo_Redo_Multi_Line_Selected_DeleteCharLeft_All ()
  2271. {
  2272. var text = "This is the first line.\nThis is the second line.\nThis is the third line.";
  2273. var tv = new TextView { Text = text };
  2274. Assert.Equal (
  2275. $"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.",
  2276. tv.Text
  2277. );
  2278. Assert.Equal (3, tv.Lines);
  2279. Assert.Equal (Point.Empty, tv.CursorPosition);
  2280. Assert.False (tv.IsDirty);
  2281. Assert.False (tv.HasHistoryChanges);
  2282. Assert.True (tv.NewKeyDownEvent (Key.End.WithCtrl.WithShift));
  2283. Assert.Equal (
  2284. $"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.",
  2285. tv.Text
  2286. );
  2287. Assert.Equal (
  2288. $"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.",
  2289. tv.SelectedText
  2290. );
  2291. Assert.Equal (3, tv.Lines);
  2292. Assert.Equal (new Point (23, 2), tv.CursorPosition);
  2293. Assert.Equal (70 + Environment.NewLine.Length * 2, tv.SelectedLength);
  2294. Assert.False (tv.IsDirty);
  2295. Assert.False (tv.HasHistoryChanges);
  2296. Assert.True (tv.NewKeyDownEvent (Key.Backspace));
  2297. Assert.Equal ("", tv.Text);
  2298. Assert.Equal ("", tv.SelectedText);
  2299. Assert.Equal (1, tv.Lines);
  2300. Assert.Equal (Point.Empty, tv.CursorPosition);
  2301. Assert.Equal (0, tv.SelectedLength);
  2302. Assert.True (tv.IsDirty);
  2303. Assert.True (tv.HasHistoryChanges);
  2304. // Undo
  2305. Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl));
  2306. Assert.Equal (
  2307. $"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.",
  2308. tv.Text
  2309. );
  2310. Assert.Equal ("", tv.SelectedText);
  2311. Assert.Equal (3, tv.Lines);
  2312. Assert.Equal (new Point (23, 2), tv.CursorPosition);
  2313. Assert.Equal (0, tv.SelectedLength);
  2314. Assert.False (tv.IsDirty);
  2315. Assert.True (tv.HasHistoryChanges);
  2316. // Redo
  2317. Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl));
  2318. Assert.Equal ("", tv.Text);
  2319. Assert.Equal ("", tv.SelectedText);
  2320. Assert.Equal (1, tv.Lines);
  2321. Assert.Equal (Point.Empty, tv.CursorPosition);
  2322. Assert.Equal (0, tv.SelectedLength);
  2323. Assert.True (tv.IsDirty);
  2324. Assert.True (tv.HasHistoryChanges);
  2325. }
  2326. [Fact]
  2327. public void HistoryText_Undo_Redo_Multi_Line_Selected_DeleteCharRight_All ()
  2328. {
  2329. var text = "This is the first line.\nThis is the second line.\nThis is the third line.";
  2330. var tv = new TextView { Text = text };
  2331. Assert.Equal (
  2332. $"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.",
  2333. tv.Text
  2334. );
  2335. Assert.Equal (3, tv.Lines);
  2336. Assert.Equal (Point.Empty, tv.CursorPosition);
  2337. Assert.False (tv.IsDirty);
  2338. Assert.False (tv.HasHistoryChanges);
  2339. Assert.True (tv.NewKeyDownEvent (Key.End.WithCtrl.WithShift));
  2340. Assert.Equal (
  2341. $"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.",
  2342. tv.Text
  2343. );
  2344. Assert.Equal (
  2345. $"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.",
  2346. tv.SelectedText
  2347. );
  2348. Assert.Equal (3, tv.Lines);
  2349. Assert.Equal (new Point (23, 2), tv.CursorPosition);
  2350. Assert.Equal (70 + Environment.NewLine.Length * 2, tv.SelectedLength);
  2351. Assert.False (tv.IsDirty);
  2352. Assert.False (tv.HasHistoryChanges);
  2353. Assert.True (tv.NewKeyDownEvent (Key.Delete));
  2354. Assert.Equal ("", tv.Text);
  2355. Assert.Equal ("", tv.SelectedText);
  2356. Assert.Equal (1, tv.Lines);
  2357. Assert.Equal (Point.Empty, tv.CursorPosition);
  2358. Assert.Equal (0, tv.SelectedLength);
  2359. Assert.True (tv.IsDirty);
  2360. Assert.True (tv.HasHistoryChanges);
  2361. // Undo
  2362. Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl));
  2363. Assert.Equal (
  2364. $"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.",
  2365. tv.Text
  2366. );
  2367. Assert.Equal ("", tv.SelectedText);
  2368. Assert.Equal (3, tv.Lines);
  2369. Assert.Equal (new Point (23, 2), tv.CursorPosition);
  2370. Assert.Equal (0, tv.SelectedLength);
  2371. Assert.False (tv.IsDirty);
  2372. Assert.True (tv.HasHistoryChanges);
  2373. // Redo
  2374. Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl));
  2375. Assert.Equal ("", tv.Text);
  2376. Assert.Equal ("", tv.SelectedText);
  2377. Assert.Equal (1, tv.Lines);
  2378. Assert.Equal (Point.Empty, tv.CursorPosition);
  2379. Assert.Equal (0, tv.SelectedLength);
  2380. Assert.True (tv.IsDirty);
  2381. Assert.True (tv.HasHistoryChanges);
  2382. }
  2383. [Fact]
  2384. [AutoInitShutdown]
  2385. public void HistoryText_Undo_Redo_Multi_Line_Selected_InsertText ()
  2386. {
  2387. var text =
  2388. $"This is the first line.{Environment.NewLine}This is the second line.\nThis is the third line.";
  2389. var tv = new TextView { Width = 10, Height = 2, Text = text };
  2390. Toplevel top = new ();
  2391. top.Add (tv);
  2392. Application.Begin (top);
  2393. Assert.Equal (
  2394. $"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.",
  2395. tv.Text
  2396. );
  2397. Assert.Equal (3, tv.Lines);
  2398. Assert.Equal (Point.Empty, tv.CursorPosition);
  2399. var messy = " messy";
  2400. tv.CursorPosition = new Point (7, 0);
  2401. tv.SelectionStartColumn = 11;
  2402. tv.SelectionStartRow = 2;
  2403. Assert.Equal (51 + Environment.NewLine.Length * 2, tv.SelectedLength);
  2404. for (var i = 0; i < messy.Length; i++)
  2405. {
  2406. tv.InsertText (messy [i].ToString ());
  2407. switch (i)
  2408. {
  2409. case 0:
  2410. Assert.Equal ("This is third line.", tv.Text);
  2411. Assert.Equal (new Point (8, 0), tv.CursorPosition);
  2412. break;
  2413. case 1:
  2414. Assert.Equal ("This is m third line.", tv.Text);
  2415. Assert.Equal (new Point (9, 0), tv.CursorPosition);
  2416. break;
  2417. case 2:
  2418. Assert.Equal ("This is me third line.", tv.Text);
  2419. Assert.Equal (new Point (10, 0), tv.CursorPosition);
  2420. break;
  2421. case 3:
  2422. Assert.Equal ("This is mes third line.", tv.Text);
  2423. Assert.Equal (new Point (11, 0), tv.CursorPosition);
  2424. break;
  2425. case 4:
  2426. Assert.Equal ("This is mess third line.", tv.Text);
  2427. Assert.Equal (new Point (12, 0), tv.CursorPosition);
  2428. break;
  2429. case 5:
  2430. Assert.Equal ("This is messy third line.", tv.Text);
  2431. Assert.Equal (new Point (13, 0), tv.CursorPosition);
  2432. break;
  2433. }
  2434. }
  2435. Assert.Equal ("This is messy third line.", tv.Text);
  2436. Assert.Equal (1, tv.Lines);
  2437. Assert.Equal (new Point (13, 0), tv.CursorPosition);
  2438. Assert.Equal (11, tv.SelectionStartColumn);
  2439. Assert.Equal (2, tv.SelectionStartRow);
  2440. Assert.Equal (0, tv.SelectedLength);
  2441. for (var i = 0; i < messy.Length; i++)
  2442. {
  2443. Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl));
  2444. switch (i)
  2445. {
  2446. case 0:
  2447. Assert.Equal ("This is mess third line.", tv.Text);
  2448. Assert.Equal (new Point (12, 0), tv.CursorPosition);
  2449. break;
  2450. case 1:
  2451. Assert.Equal ("This is mes third line.", tv.Text);
  2452. Assert.Equal (new Point (11, 0), tv.CursorPosition);
  2453. break;
  2454. case 2:
  2455. Assert.Equal ("This is me third line.", tv.Text);
  2456. Assert.Equal (new Point (10, 0), tv.CursorPosition);
  2457. break;
  2458. case 3:
  2459. Assert.Equal ("This is m third line.", tv.Text);
  2460. Assert.Equal (new Point (9, 0), tv.CursorPosition);
  2461. break;
  2462. case 4:
  2463. Assert.Equal ("This is third line.", tv.Text);
  2464. Assert.Equal (new Point (8, 0), tv.CursorPosition);
  2465. break;
  2466. case 5:
  2467. Assert.Equal (
  2468. $"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.",
  2469. tv.Text
  2470. );
  2471. Assert.Equal (new Point (7, 0), tv.CursorPosition);
  2472. break;
  2473. }
  2474. }
  2475. Assert.Equal (
  2476. $"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.",
  2477. tv.Text
  2478. );
  2479. Assert.Equal (3, tv.Lines);
  2480. Assert.Equal (new Point (7, 0), tv.CursorPosition);
  2481. Assert.Equal (11, tv.SelectionStartColumn);
  2482. Assert.Equal (2, tv.SelectionStartRow);
  2483. Assert.Equal (0, tv.SelectedLength);
  2484. for (var i = 0; i < messy.Length; i++)
  2485. {
  2486. Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl));
  2487. switch (i)
  2488. {
  2489. case 0:
  2490. Assert.Equal ("This is third line.", tv.Text);
  2491. Assert.Equal (new Point (8, 0), tv.CursorPosition);
  2492. break;
  2493. case 1:
  2494. Assert.Equal ("This is m third line.", tv.Text);
  2495. Assert.Equal (new Point (9, 0), tv.CursorPosition);
  2496. break;
  2497. case 2:
  2498. Assert.Equal ("This is me third line.", tv.Text);
  2499. Assert.Equal (new Point (10, 0), tv.CursorPosition);
  2500. break;
  2501. case 3:
  2502. Assert.Equal ("This is mes third line.", tv.Text);
  2503. Assert.Equal (new Point (11, 0), tv.CursorPosition);
  2504. break;
  2505. case 4:
  2506. Assert.Equal ("This is mess third line.", tv.Text);
  2507. Assert.Equal (new Point (12, 0), tv.CursorPosition);
  2508. break;
  2509. case 5:
  2510. Assert.Equal ("This is messy third line.", tv.Text);
  2511. Assert.Equal (new Point (13, 0), tv.CursorPosition);
  2512. break;
  2513. }
  2514. }
  2515. Assert.Equal ("This is messy third line.", tv.Text);
  2516. Assert.Equal (1, tv.Lines);
  2517. Assert.Equal (new Point (13, 0), tv.CursorPosition);
  2518. Assert.Equal (11, tv.SelectionStartColumn);
  2519. Assert.Equal (2, tv.SelectionStartRow);
  2520. Assert.Equal (0, tv.SelectedLength);
  2521. top.Dispose ();
  2522. }
  2523. [Fact]
  2524. [AutoInitShutdown]
  2525. public void HistoryText_Undo_Redo_Multi_Line_Selected_InsertText_Twice_On_Same_Line ()
  2526. {
  2527. var text = "One\nTwo\nThree";
  2528. var tv = new TextView { Width = 10, Height = 2, Text = text };
  2529. Toplevel top = new ();
  2530. top.Add (tv);
  2531. Application.Begin (top);
  2532. Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}Three", tv.Text);
  2533. Assert.Equal (3, tv.Lines);
  2534. Assert.Equal (Point.Empty, tv.CursorPosition);
  2535. Assert.False (tv.IsDirty);
  2536. tv.SelectionStartColumn = 0;
  2537. tv.SelectionStartRow = 0;
  2538. tv.CursorPosition = new Point (0, 1);
  2539. Assert.Equal (3 + Environment.NewLine.Length, tv.SelectedLength);
  2540. Assert.True (tv.NewKeyDownEvent (Key.D1));
  2541. Assert.Equal ($"1Two{Environment.NewLine}Three", tv.Text);
  2542. Assert.Equal (new Point (1, 0), tv.CursorPosition);
  2543. Assert.Equal (0, tv.SelectedLength);
  2544. Assert.True (tv.IsDirty);
  2545. tv.SelectionStartColumn = 1;
  2546. tv.SelectionStartRow = 0;
  2547. tv.CursorPosition = new Point (1, 1);
  2548. Assert.Equal (4 + Environment.NewLine.Length, tv.SelectedLength);
  2549. Assert.True (tv.NewKeyDownEvent (Key.D2));
  2550. Assert.Equal ("12hree", tv.Text);
  2551. Assert.Equal (new Point (2, 0), tv.CursorPosition);
  2552. Assert.Equal (0, tv.SelectedLength);
  2553. Assert.True (tv.IsDirty);
  2554. Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl));
  2555. Assert.Equal ($"1Two{Environment.NewLine}Three", tv.Text);
  2556. Assert.Equal (new Point (1, 1), tv.CursorPosition);
  2557. Assert.Equal (0, tv.SelectedLength);
  2558. Assert.True (tv.IsDirty);
  2559. Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl));
  2560. Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}Three", tv.Text);
  2561. Assert.Equal (3, tv.Lines);
  2562. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  2563. Assert.Equal (0, tv.SelectedLength);
  2564. Assert.False (tv.IsDirty);
  2565. Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl));
  2566. Assert.Equal ($"1Two{Environment.NewLine}Three", tv.Text);
  2567. Assert.Equal (new Point (1, 0), tv.CursorPosition);
  2568. Assert.Equal (0, tv.SelectedLength);
  2569. Assert.True (tv.IsDirty);
  2570. Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl));
  2571. Assert.Equal ("12hree", tv.Text);
  2572. Assert.Equal (new Point (2, 0), tv.CursorPosition);
  2573. Assert.Equal (0, tv.SelectedLength);
  2574. Assert.True (tv.IsDirty);
  2575. top.Dispose ();
  2576. }
  2577. [Fact]
  2578. [AutoInitShutdown]
  2579. public void HistoryText_Undo_Redo_Multi_Line_Selected_InsertText_Twice_On_Same_Line_With_End_Line ()
  2580. {
  2581. var text = "One\nTwo\nThree\n";
  2582. var tv = new TextView { Width = 10, Height = 2, Text = text };
  2583. Toplevel top = new ();
  2584. top.Add (tv);
  2585. Application.Begin (top);
  2586. Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}Three{Environment.NewLine}", tv.Text);
  2587. Assert.Equal (4, tv.Lines);
  2588. Assert.Equal (Point.Empty, tv.CursorPosition);
  2589. Assert.False (tv.IsDirty);
  2590. tv.SelectionStartColumn = 0;
  2591. tv.SelectionStartRow = 0;
  2592. tv.CursorPosition = new Point (0, 1);
  2593. Assert.Equal (3 + Environment.NewLine.Length, tv.SelectedLength);
  2594. Assert.True (tv.NewKeyDownEvent (Key.D1));
  2595. Assert.Equal ($"1Two{Environment.NewLine}Three{Environment.NewLine}", tv.Text);
  2596. Assert.Equal (new Point (1, 0), tv.CursorPosition);
  2597. Assert.Equal (0, tv.SelectedLength);
  2598. Assert.True (tv.IsDirty);
  2599. tv.SelectionStartColumn = 1;
  2600. tv.SelectionStartRow = 0;
  2601. tv.CursorPosition = new Point (1, 1);
  2602. Assert.Equal (4 + Environment.NewLine.Length, tv.SelectedLength);
  2603. Assert.True (tv.NewKeyDownEvent (Key.D2));
  2604. Assert.Equal ($"12hree{Environment.NewLine}", tv.Text);
  2605. Assert.Equal (new Point (2, 0), tv.CursorPosition);
  2606. Assert.Equal (0, tv.SelectedLength);
  2607. Assert.True (tv.IsDirty);
  2608. Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl));
  2609. Assert.Equal ($"1Two{Environment.NewLine}Three{Environment.NewLine}", tv.Text);
  2610. Assert.Equal (new Point (1, 1), tv.CursorPosition);
  2611. Assert.Equal (0, tv.SelectedLength);
  2612. Assert.True (tv.IsDirty);
  2613. Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl));
  2614. Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}Three{Environment.NewLine}", tv.Text);
  2615. Assert.Equal (4, tv.Lines);
  2616. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  2617. Assert.Equal (0, tv.SelectedLength);
  2618. Assert.False (tv.IsDirty);
  2619. Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl));
  2620. Assert.Equal ($"1Two{Environment.NewLine}Three{Environment.NewLine}", tv.Text);
  2621. Assert.Equal (new Point (1, 0), tv.CursorPosition);
  2622. Assert.Equal (0, tv.SelectedLength);
  2623. Assert.True (tv.IsDirty);
  2624. Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl));
  2625. Assert.Equal ($"12hree{Environment.NewLine}", tv.Text);
  2626. Assert.Equal (new Point (2, 0), tv.CursorPosition);
  2627. Assert.Equal (0, tv.SelectedLength);
  2628. Assert.True (tv.IsDirty);
  2629. top.Dispose ();
  2630. }
  2631. [Fact]
  2632. [AutoInitShutdown]
  2633. public void HistoryText_Undo_Redo_Multi_Line_Selected_With_Empty_Text ()
  2634. {
  2635. var tv = new TextView { Width = 10, Height = 2 };
  2636. Toplevel top = new ();
  2637. top.Add (tv);
  2638. Application.Begin (top);
  2639. Assert.Equal ("", tv.Text);
  2640. Assert.Equal (1, tv.Lines);
  2641. Assert.Equal (Point.Empty, tv.CursorPosition);
  2642. Assert.False (tv.IsDirty);
  2643. Assert.True (tv.NewKeyDownEvent (Key.O.WithShift));
  2644. Assert.Equal ("O", tv.Text);
  2645. Assert.Equal (1, tv.Lines);
  2646. Assert.Equal (new Point (1, 0), tv.CursorPosition);
  2647. Assert.True (tv.IsDirty);
  2648. Assert.True (tv.NewKeyDownEvent (Key.N));
  2649. Assert.Equal ("On", tv.Text);
  2650. Assert.Equal (1, tv.Lines);
  2651. Assert.Equal (new Point (2, 0), tv.CursorPosition);
  2652. Assert.True (tv.IsDirty);
  2653. Assert.True (tv.NewKeyDownEvent (Key.E));
  2654. Assert.Equal ("One", tv.Text);
  2655. Assert.Equal (1, tv.Lines);
  2656. Assert.Equal (new Point (3, 0), tv.CursorPosition);
  2657. Assert.True (tv.IsDirty);
  2658. Assert.True (tv.NewKeyDownEvent (Key.Enter));
  2659. Assert.Equal ($"One{Environment.NewLine}", tv.Text);
  2660. Assert.Equal (2, tv.Lines);
  2661. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  2662. Assert.True (tv.IsDirty);
  2663. Assert.True (tv.NewKeyDownEvent (Key.T.WithShift));
  2664. Assert.Equal ($"One{Environment.NewLine}T", tv.Text);
  2665. Assert.Equal (2, tv.Lines);
  2666. Assert.Equal (new Point (1, 1), tv.CursorPosition);
  2667. Assert.True (tv.IsDirty);
  2668. Assert.True (tv.NewKeyDownEvent (Key.W));
  2669. Assert.Equal ($"One{Environment.NewLine}Tw", tv.Text);
  2670. Assert.Equal (2, tv.Lines);
  2671. Assert.Equal (new Point (2, 1), tv.CursorPosition);
  2672. Assert.True (tv.IsDirty);
  2673. Assert.True (tv.NewKeyDownEvent (Key.O));
  2674. Assert.Equal ($"One{Environment.NewLine}Two", tv.Text);
  2675. Assert.Equal (2, tv.Lines);
  2676. Assert.Equal (new Point (3, 1), tv.CursorPosition);
  2677. Assert.True (tv.IsDirty);
  2678. Assert.True (tv.NewKeyDownEvent (Key.Enter));
  2679. Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}", tv.Text);
  2680. Assert.Equal (3, tv.Lines);
  2681. Assert.Equal (new Point (0, 2), tv.CursorPosition);
  2682. Assert.True (tv.IsDirty);
  2683. Assert.True (tv.NewKeyDownEvent (Key.T.WithShift));
  2684. Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}T", tv.Text);
  2685. Assert.Equal (3, tv.Lines);
  2686. Assert.Equal (new Point (1, 2), tv.CursorPosition);
  2687. Assert.True (tv.IsDirty);
  2688. Assert.True (tv.NewKeyDownEvent (Key.H));
  2689. Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}Th", tv.Text);
  2690. Assert.Equal (3, tv.Lines);
  2691. Assert.Equal (new Point (2, 2), tv.CursorPosition);
  2692. Assert.True (tv.IsDirty);
  2693. Assert.True (tv.NewKeyDownEvent (Key.R));
  2694. Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}Thr", tv.Text);
  2695. Assert.Equal (3, tv.Lines);
  2696. Assert.Equal (new Point (3, 2), tv.CursorPosition);
  2697. Assert.True (tv.IsDirty);
  2698. Assert.True (tv.NewKeyDownEvent (Key.E));
  2699. Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}Thre", tv.Text);
  2700. Assert.Equal (3, tv.Lines);
  2701. Assert.Equal (new Point (4, 2), tv.CursorPosition);
  2702. Assert.True (tv.IsDirty);
  2703. Assert.True (tv.NewKeyDownEvent (Key.E));
  2704. Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}Three", tv.Text);
  2705. Assert.Equal (3, tv.Lines);
  2706. Assert.Equal (new Point (5, 2), tv.CursorPosition);
  2707. Assert.True (tv.IsDirty);
  2708. Assert.True (tv.NewKeyDownEvent (Key.Enter));
  2709. Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}Three{Environment.NewLine}", tv.Text);
  2710. Assert.Equal (4, tv.Lines);
  2711. Assert.Equal (new Point (0, 3), tv.CursorPosition);
  2712. Assert.True (tv.IsDirty);
  2713. tv.SelectionStartColumn = 0;
  2714. tv.SelectionStartRow = 0;
  2715. tv.CursorPosition = new Point (0, 1);
  2716. Assert.Equal (3 + Environment.NewLine.Length, tv.SelectedLength);
  2717. Assert.True (tv.NewKeyDownEvent (Key.D1));
  2718. Assert.Equal ($"1Two{Environment.NewLine}Three{Environment.NewLine}", tv.Text);
  2719. Assert.Equal (3, tv.Lines);
  2720. Assert.Equal (new Point (1, 0), tv.CursorPosition);
  2721. Assert.Equal (0, tv.SelectedLength);
  2722. Assert.True (tv.IsDirty);
  2723. tv.SelectionStartColumn = 1;
  2724. tv.SelectionStartRow = 0;
  2725. tv.CursorPosition = new Point (1, 1);
  2726. Assert.Equal (4 + Environment.NewLine.Length, tv.SelectedLength);
  2727. Assert.True (tv.NewKeyDownEvent (Key.D2));
  2728. Assert.Equal ($"12hree{Environment.NewLine}", tv.Text);
  2729. Assert.Equal (2, tv.Lines);
  2730. Assert.Equal (new Point (2, 0), tv.CursorPosition);
  2731. Assert.Equal (0, tv.SelectedLength);
  2732. Assert.True (tv.IsDirty);
  2733. // Undoing
  2734. Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl));
  2735. Assert.Equal ($"1Two{Environment.NewLine}Three{Environment.NewLine}", tv.Text);
  2736. Assert.Equal (3, tv.Lines);
  2737. Assert.Equal (new Point (1, 1), tv.CursorPosition);
  2738. Assert.Equal (0, tv.SelectedLength);
  2739. Assert.True (tv.IsDirty);
  2740. Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl));
  2741. Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}Three{Environment.NewLine}", tv.Text);
  2742. Assert.Equal (4, tv.Lines);
  2743. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  2744. Assert.Equal (0, tv.SelectedLength);
  2745. Assert.True (tv.IsDirty);
  2746. Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl));
  2747. Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}Three", tv.Text);
  2748. Assert.Equal (3, tv.Lines);
  2749. Assert.Equal (new Point (5, 2), tv.CursorPosition);
  2750. Assert.Equal (0, tv.SelectedLength);
  2751. Assert.True (tv.IsDirty);
  2752. Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl));
  2753. Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}Thre", tv.Text);
  2754. Assert.Equal (3, tv.Lines);
  2755. Assert.Equal (new Point (4, 2), tv.CursorPosition);
  2756. Assert.True (tv.IsDirty);
  2757. Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl));
  2758. Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}Thr", tv.Text);
  2759. Assert.Equal (3, tv.Lines);
  2760. Assert.Equal (new Point (3, 2), tv.CursorPosition);
  2761. Assert.Equal (0, tv.SelectedLength);
  2762. Assert.True (tv.IsDirty);
  2763. Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl));
  2764. Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}Th", tv.Text);
  2765. Assert.Equal (3, tv.Lines);
  2766. Assert.Equal (new Point (2, 2), tv.CursorPosition);
  2767. Assert.Equal (0, tv.SelectedLength);
  2768. Assert.True (tv.IsDirty);
  2769. Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl));
  2770. Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}T", tv.Text);
  2771. Assert.Equal (3, tv.Lines);
  2772. Assert.Equal (new Point (1, 2), tv.CursorPosition);
  2773. Assert.Equal (0, tv.SelectedLength);
  2774. Assert.True (tv.IsDirty);
  2775. Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl));
  2776. Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}", tv.Text);
  2777. Assert.Equal (3, tv.Lines);
  2778. Assert.Equal (new Point (0, 2), tv.CursorPosition);
  2779. Assert.Equal (0, tv.SelectedLength);
  2780. Assert.True (tv.IsDirty);
  2781. Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl));
  2782. Assert.Equal ($"One{Environment.NewLine}Two", tv.Text);
  2783. Assert.Equal (2, tv.Lines);
  2784. Assert.Equal (new Point (3, 1), tv.CursorPosition);
  2785. Assert.Equal (0, tv.SelectedLength);
  2786. Assert.True (tv.IsDirty);
  2787. Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl));
  2788. Assert.Equal ($"One{Environment.NewLine}Tw", tv.Text);
  2789. Assert.Equal (2, tv.Lines);
  2790. Assert.Equal (new Point (2, 1), tv.CursorPosition);
  2791. Assert.Equal (0, tv.SelectedLength);
  2792. Assert.True (tv.IsDirty);
  2793. Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl));
  2794. Assert.Equal ($"One{Environment.NewLine}T", tv.Text);
  2795. Assert.Equal (2, tv.Lines);
  2796. Assert.Equal (new Point (1, 1), tv.CursorPosition);
  2797. Assert.Equal (0, tv.SelectedLength);
  2798. Assert.True (tv.IsDirty);
  2799. Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl));
  2800. Assert.Equal ($"One{Environment.NewLine}", tv.Text);
  2801. Assert.Equal (2, tv.Lines);
  2802. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  2803. Assert.Equal (0, tv.SelectedLength);
  2804. Assert.True (tv.IsDirty);
  2805. Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl));
  2806. Assert.Equal ("One", tv.Text);
  2807. Assert.Equal (1, tv.Lines);
  2808. Assert.Equal (new Point (3, 0), tv.CursorPosition);
  2809. Assert.Equal (0, tv.SelectedLength);
  2810. Assert.True (tv.IsDirty);
  2811. Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl));
  2812. Assert.Equal ("On", tv.Text);
  2813. Assert.Equal (1, tv.Lines);
  2814. Assert.Equal (new Point (2, 0), tv.CursorPosition);
  2815. Assert.Equal (0, tv.SelectedLength);
  2816. Assert.True (tv.IsDirty);
  2817. Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl));
  2818. Assert.Equal ("O", tv.Text);
  2819. Assert.Equal (1, tv.Lines);
  2820. Assert.Equal (new Point (1, 0), tv.CursorPosition);
  2821. Assert.Equal (0, tv.SelectedLength);
  2822. Assert.True (tv.IsDirty);
  2823. Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl));
  2824. Assert.Equal ("", tv.Text);
  2825. Assert.Equal (1, tv.Lines);
  2826. Assert.Equal (Point.Empty, tv.CursorPosition);
  2827. Assert.Equal (0, tv.SelectedLength);
  2828. Assert.False (tv.IsDirty);
  2829. Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl));
  2830. Assert.Equal ("", tv.Text);
  2831. Assert.Equal (1, tv.Lines);
  2832. Assert.Equal (Point.Empty, tv.CursorPosition);
  2833. Assert.Equal (0, tv.SelectedLength);
  2834. Assert.False (tv.IsDirty);
  2835. // Redoing
  2836. Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl));
  2837. Assert.Equal ("O", tv.Text);
  2838. Assert.Equal (1, tv.Lines);
  2839. Assert.Equal (new Point (1, 0), tv.CursorPosition);
  2840. Assert.Equal (0, tv.SelectedLength);
  2841. Assert.True (tv.IsDirty);
  2842. Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl));
  2843. Assert.Equal ("On", tv.Text);
  2844. Assert.Equal (1, tv.Lines);
  2845. Assert.Equal (new Point (2, 0), tv.CursorPosition);
  2846. Assert.Equal (0, tv.SelectedLength);
  2847. Assert.True (tv.IsDirty);
  2848. Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl));
  2849. Assert.Equal ("One", tv.Text);
  2850. Assert.Equal (1, tv.Lines);
  2851. Assert.Equal (new Point (3, 0), tv.CursorPosition);
  2852. Assert.Equal (0, tv.SelectedLength);
  2853. Assert.True (tv.IsDirty);
  2854. Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl));
  2855. Assert.Equal ($"One{Environment.NewLine}", tv.Text);
  2856. Assert.Equal (2, tv.Lines);
  2857. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  2858. Assert.Equal (0, tv.SelectedLength);
  2859. Assert.True (tv.IsDirty);
  2860. Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl));
  2861. Assert.Equal ($"One{Environment.NewLine}T", tv.Text);
  2862. Assert.Equal (2, tv.Lines);
  2863. Assert.Equal (new Point (1, 1), tv.CursorPosition);
  2864. Assert.Equal (0, tv.SelectedLength);
  2865. Assert.True (tv.IsDirty);
  2866. Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl));
  2867. Assert.Equal ($"One{Environment.NewLine}Tw", tv.Text);
  2868. Assert.Equal (2, tv.Lines);
  2869. Assert.Equal (new Point (2, 1), tv.CursorPosition);
  2870. Assert.Equal (0, tv.SelectedLength);
  2871. Assert.True (tv.IsDirty);
  2872. Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl));
  2873. Assert.Equal ($"One{Environment.NewLine}Two", tv.Text);
  2874. Assert.Equal (2, tv.Lines);
  2875. Assert.Equal (new Point (3, 1), tv.CursorPosition);
  2876. Assert.Equal (0, tv.SelectedLength);
  2877. Assert.True (tv.IsDirty);
  2878. Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl));
  2879. Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}", tv.Text);
  2880. Assert.Equal (3, tv.Lines);
  2881. Assert.Equal (new Point (0, 2), tv.CursorPosition);
  2882. Assert.Equal (0, tv.SelectedLength);
  2883. Assert.True (tv.IsDirty);
  2884. Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl));
  2885. Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}T", tv.Text);
  2886. Assert.Equal (3, tv.Lines);
  2887. Assert.Equal (new Point (1, 2), tv.CursorPosition);
  2888. Assert.Equal (0, tv.SelectedLength);
  2889. Assert.True (tv.IsDirty);
  2890. Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl));
  2891. Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}Th", tv.Text);
  2892. Assert.Equal (3, tv.Lines);
  2893. Assert.Equal (new Point (2, 2), tv.CursorPosition);
  2894. Assert.Equal (0, tv.SelectedLength);
  2895. Assert.True (tv.IsDirty);
  2896. Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl));
  2897. Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}Thr", tv.Text);
  2898. Assert.Equal (3, tv.Lines);
  2899. Assert.Equal (new Point (3, 2), tv.CursorPosition);
  2900. Assert.Equal (0, tv.SelectedLength);
  2901. Assert.True (tv.IsDirty);
  2902. Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl));
  2903. Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}Thre", tv.Text);
  2904. Assert.Equal (3, tv.Lines);
  2905. Assert.Equal (new Point (4, 2), tv.CursorPosition);
  2906. Assert.Equal (0, tv.SelectedLength);
  2907. Assert.True (tv.IsDirty);
  2908. Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl));
  2909. Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}Three", tv.Text);
  2910. Assert.Equal (3, tv.Lines);
  2911. Assert.Equal (new Point (5, 2), tv.CursorPosition);
  2912. Assert.Equal (0, tv.SelectedLength);
  2913. Assert.True (tv.IsDirty);
  2914. Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl));
  2915. Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}Three{Environment.NewLine}", tv.Text);
  2916. Assert.Equal (4, tv.Lines);
  2917. Assert.Equal (new Point (0, 3), tv.CursorPosition);
  2918. Assert.Equal (0, tv.SelectedLength);
  2919. Assert.True (tv.IsDirty);
  2920. Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl));
  2921. Assert.Equal ($"1Two{Environment.NewLine}Three{Environment.NewLine}", tv.Text);
  2922. Assert.Equal (3, tv.Lines);
  2923. Assert.Equal (new Point (1, 0), tv.CursorPosition);
  2924. Assert.Equal (0, tv.SelectedLength);
  2925. Assert.True (tv.IsDirty);
  2926. Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl));
  2927. Assert.Equal ($"12hree{Environment.NewLine}", tv.Text);
  2928. Assert.Equal (2, tv.Lines);
  2929. Assert.Equal (new Point (2, 0), tv.CursorPosition);
  2930. Assert.Equal (0, tv.SelectedLength);
  2931. Assert.True (tv.IsDirty);
  2932. top.Dispose ();
  2933. }
  2934. [Fact]
  2935. [AutoInitShutdown]
  2936. public void HistoryText_Undo_Redo_Multi_Line_With_Empty_Text ()
  2937. {
  2938. var tv = new TextView { Width = 10, Height = 2 };
  2939. Toplevel top = new ();
  2940. top.Add (tv);
  2941. Application.Begin (top);
  2942. Assert.Equal ("", tv.Text);
  2943. Assert.Equal (1, tv.Lines);
  2944. Assert.Equal (Point.Empty, tv.CursorPosition);
  2945. Assert.False (tv.IsDirty);
  2946. Assert.True (tv.NewKeyDownEvent (Key.O.WithShift));
  2947. Assert.Equal ("O", tv.Text);
  2948. Assert.Equal (1, tv.Lines);
  2949. Assert.Equal (new Point (1, 0), tv.CursorPosition);
  2950. Assert.True (tv.IsDirty);
  2951. Assert.True (tv.NewKeyDownEvent (Key.N));
  2952. Assert.Equal ("On", tv.Text);
  2953. Assert.Equal (1, tv.Lines);
  2954. Assert.Equal (new Point (2, 0), tv.CursorPosition);
  2955. Assert.True (tv.IsDirty);
  2956. Assert.True (tv.NewKeyDownEvent (Key.E));
  2957. Assert.Equal ("One", tv.Text);
  2958. Assert.Equal (1, tv.Lines);
  2959. Assert.Equal (new Point (3, 0), tv.CursorPosition);
  2960. Assert.True (tv.IsDirty);
  2961. Assert.True (tv.NewKeyDownEvent (Key.Enter));
  2962. Assert.Equal ($"One{Environment.NewLine}", tv.Text);
  2963. Assert.Equal (2, tv.Lines);
  2964. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  2965. Assert.True (tv.IsDirty);
  2966. Assert.True (tv.NewKeyDownEvent (Key.T.WithShift));
  2967. Assert.Equal ($"One{Environment.NewLine}T", tv.Text);
  2968. Assert.Equal (2, tv.Lines);
  2969. Assert.Equal (new Point (1, 1), tv.CursorPosition);
  2970. Assert.True (tv.IsDirty);
  2971. Assert.True (tv.NewKeyDownEvent (Key.W));
  2972. Assert.Equal ($"One{Environment.NewLine}Tw", tv.Text);
  2973. Assert.Equal (2, tv.Lines);
  2974. Assert.Equal (new Point (2, 1), tv.CursorPosition);
  2975. Assert.True (tv.IsDirty);
  2976. Assert.True (tv.NewKeyDownEvent (Key.O));
  2977. Assert.Equal ($"One{Environment.NewLine}Two", tv.Text);
  2978. Assert.Equal (2, tv.Lines);
  2979. Assert.Equal (new Point (3, 1), tv.CursorPosition);
  2980. Assert.True (tv.IsDirty);
  2981. Assert.True (tv.NewKeyDownEvent (Key.Enter));
  2982. Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}", tv.Text);
  2983. Assert.Equal (3, tv.Lines);
  2984. Assert.Equal (new Point (0, 2), tv.CursorPosition);
  2985. Assert.True (tv.IsDirty);
  2986. Assert.True (tv.NewKeyDownEvent (Key.T.WithShift));
  2987. Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}T", tv.Text);
  2988. Assert.Equal (3, tv.Lines);
  2989. Assert.Equal (new Point (1, 2), tv.CursorPosition);
  2990. Assert.True (tv.IsDirty);
  2991. Assert.True (tv.NewKeyDownEvent (Key.H));
  2992. Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}Th", tv.Text);
  2993. Assert.Equal (3, tv.Lines);
  2994. Assert.Equal (new Point (2, 2), tv.CursorPosition);
  2995. Assert.True (tv.IsDirty);
  2996. Assert.True (tv.NewKeyDownEvent (Key.R));
  2997. Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}Thr", tv.Text);
  2998. Assert.Equal (3, tv.Lines);
  2999. Assert.Equal (new Point (3, 2), tv.CursorPosition);
  3000. Assert.True (tv.IsDirty);
  3001. Assert.True (tv.NewKeyDownEvent (Key.E));
  3002. Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}Thre", tv.Text);
  3003. Assert.Equal (3, tv.Lines);
  3004. Assert.Equal (new Point (4, 2), tv.CursorPosition);
  3005. Assert.True (tv.IsDirty);
  3006. Assert.True (tv.NewKeyDownEvent (Key.E));
  3007. Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}Three", tv.Text);
  3008. Assert.Equal (3, tv.Lines);
  3009. Assert.Equal (new Point (5, 2), tv.CursorPosition);
  3010. Assert.True (tv.IsDirty);
  3011. Assert.True (tv.NewKeyDownEvent (Key.Enter));
  3012. Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}Three{Environment.NewLine}", tv.Text);
  3013. Assert.Equal (4, tv.Lines);
  3014. Assert.Equal (new Point (0, 3), tv.CursorPosition);
  3015. Assert.True (tv.IsDirty);
  3016. // Undoing
  3017. Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl));
  3018. Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}Three", tv.Text);
  3019. Assert.Equal (3, tv.Lines);
  3020. Assert.Equal (new Point (5, 2), tv.CursorPosition);
  3021. Assert.True (tv.IsDirty);
  3022. Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl));
  3023. Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}Thre", tv.Text);
  3024. Assert.Equal (3, tv.Lines);
  3025. Assert.Equal (new Point (4, 2), tv.CursorPosition);
  3026. Assert.True (tv.IsDirty);
  3027. Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl));
  3028. Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}Thr", tv.Text);
  3029. Assert.Equal (3, tv.Lines);
  3030. Assert.Equal (new Point (3, 2), tv.CursorPosition);
  3031. Assert.True (tv.IsDirty);
  3032. Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl));
  3033. Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}Th", tv.Text);
  3034. Assert.Equal (3, tv.Lines);
  3035. Assert.Equal (new Point (2, 2), tv.CursorPosition);
  3036. Assert.True (tv.IsDirty);
  3037. Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl));
  3038. Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}T", tv.Text);
  3039. Assert.Equal (3, tv.Lines);
  3040. Assert.Equal (new Point (1, 2), tv.CursorPosition);
  3041. Assert.True (tv.IsDirty);
  3042. Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl));
  3043. Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}", tv.Text);
  3044. Assert.Equal (3, tv.Lines);
  3045. Assert.Equal (new Point (0, 2), tv.CursorPosition);
  3046. Assert.True (tv.IsDirty);
  3047. Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl));
  3048. Assert.Equal ($"One{Environment.NewLine}Two", tv.Text);
  3049. Assert.Equal (2, tv.Lines);
  3050. Assert.Equal (new Point (3, 1), tv.CursorPosition);
  3051. Assert.True (tv.IsDirty);
  3052. Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl));
  3053. Assert.Equal ($"One{Environment.NewLine}Tw", tv.Text);
  3054. Assert.Equal (2, tv.Lines);
  3055. Assert.Equal (new Point (2, 1), tv.CursorPosition);
  3056. Assert.True (tv.IsDirty);
  3057. Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl));
  3058. Assert.Equal ($"One{Environment.NewLine}T", tv.Text);
  3059. Assert.Equal (2, tv.Lines);
  3060. Assert.Equal (new Point (1, 1), tv.CursorPosition);
  3061. Assert.True (tv.IsDirty);
  3062. Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl));
  3063. Assert.Equal ($"One{Environment.NewLine}", tv.Text);
  3064. Assert.Equal (2, tv.Lines);
  3065. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  3066. Assert.True (tv.IsDirty);
  3067. Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl));
  3068. Assert.Equal ("One", tv.Text);
  3069. Assert.Equal (1, tv.Lines);
  3070. Assert.Equal (new Point (3, 0), tv.CursorPosition);
  3071. Assert.True (tv.IsDirty);
  3072. Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl));
  3073. Assert.Equal ("On", tv.Text);
  3074. Assert.Equal (1, tv.Lines);
  3075. Assert.Equal (new Point (2, 0), tv.CursorPosition);
  3076. Assert.True (tv.IsDirty);
  3077. Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl));
  3078. Assert.Equal ("O", tv.Text);
  3079. Assert.Equal (1, tv.Lines);
  3080. Assert.Equal (new Point (1, 0), tv.CursorPosition);
  3081. Assert.True (tv.IsDirty);
  3082. Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl));
  3083. Assert.Equal ("", tv.Text);
  3084. Assert.Equal (1, tv.Lines);
  3085. Assert.Equal (Point.Empty, tv.CursorPosition);
  3086. Assert.False (tv.IsDirty);
  3087. Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl));
  3088. Assert.Equal ("", tv.Text);
  3089. Assert.Equal (1, tv.Lines);
  3090. Assert.Equal (Point.Empty, tv.CursorPosition);
  3091. Assert.False (tv.IsDirty);
  3092. // Redoing
  3093. Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl));
  3094. Assert.Equal ("O", tv.Text);
  3095. Assert.Equal (1, tv.Lines);
  3096. Assert.Equal (new Point (1, 0), tv.CursorPosition);
  3097. Assert.True (tv.IsDirty);
  3098. Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl));
  3099. Assert.Equal ("On", tv.Text);
  3100. Assert.Equal (1, tv.Lines);
  3101. Assert.Equal (new Point (2, 0), tv.CursorPosition);
  3102. Assert.True (tv.IsDirty);
  3103. Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl));
  3104. Assert.Equal ("One", tv.Text);
  3105. Assert.Equal (1, tv.Lines);
  3106. Assert.Equal (new Point (3, 0), tv.CursorPosition);
  3107. Assert.True (tv.IsDirty);
  3108. Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl));
  3109. Assert.Equal ($"One{Environment.NewLine}", tv.Text);
  3110. Assert.Equal (2, tv.Lines);
  3111. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  3112. Assert.True (tv.IsDirty);
  3113. Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl));
  3114. Assert.Equal ($"One{Environment.NewLine}T", tv.Text);
  3115. Assert.Equal (2, tv.Lines);
  3116. Assert.Equal (new Point (1, 1), tv.CursorPosition);
  3117. Assert.True (tv.IsDirty);
  3118. Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl));
  3119. Assert.Equal ($"One{Environment.NewLine}Tw", tv.Text);
  3120. Assert.Equal (2, tv.Lines);
  3121. Assert.Equal (new Point (2, 1), tv.CursorPosition);
  3122. Assert.True (tv.IsDirty);
  3123. Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl));
  3124. Assert.Equal ($"One{Environment.NewLine}Two", tv.Text);
  3125. Assert.Equal (2, tv.Lines);
  3126. Assert.Equal (new Point (3, 1), tv.CursorPosition);
  3127. Assert.True (tv.IsDirty);
  3128. Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl));
  3129. Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}", tv.Text);
  3130. Assert.Equal (3, tv.Lines);
  3131. Assert.Equal (new Point (0, 2), tv.CursorPosition);
  3132. Assert.True (tv.IsDirty);
  3133. Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl));
  3134. Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}T", tv.Text);
  3135. Assert.Equal (3, tv.Lines);
  3136. Assert.Equal (new Point (1, 2), tv.CursorPosition);
  3137. Assert.True (tv.IsDirty);
  3138. Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl));
  3139. Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}Th", tv.Text);
  3140. Assert.Equal (3, tv.Lines);
  3141. Assert.Equal (new Point (2, 2), tv.CursorPosition);
  3142. Assert.True (tv.IsDirty);
  3143. Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl));
  3144. Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}Thr", tv.Text);
  3145. Assert.Equal (3, tv.Lines);
  3146. Assert.Equal (new Point (3, 2), tv.CursorPosition);
  3147. Assert.True (tv.IsDirty);
  3148. Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl));
  3149. Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}Thre", tv.Text);
  3150. Assert.Equal (3, tv.Lines);
  3151. Assert.Equal (new Point (4, 2), tv.CursorPosition);
  3152. Assert.True (tv.IsDirty);
  3153. Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl));
  3154. Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}Three", tv.Text);
  3155. Assert.Equal (3, tv.Lines);
  3156. Assert.Equal (new Point (5, 2), tv.CursorPosition);
  3157. Assert.True (tv.IsDirty);
  3158. Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl));
  3159. Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}Three{Environment.NewLine}", tv.Text);
  3160. Assert.Equal (4, tv.Lines);
  3161. Assert.Equal (new Point (0, 3), tv.CursorPosition);
  3162. Assert.True (tv.IsDirty);
  3163. Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl));
  3164. Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}Three{Environment.NewLine}", tv.Text);
  3165. Assert.Equal (4, tv.Lines);
  3166. Assert.Equal (new Point (0, 3), tv.CursorPosition);
  3167. Assert.True (tv.IsDirty);
  3168. top.Dispose ();
  3169. }
  3170. [Fact]
  3171. public void HistoryText_Undo_Redo_Multiline_Selected_Tab_BackTab ()
  3172. {
  3173. var text = "First line.\nSecond line.\nThird line.";
  3174. var tv = new TextView { Width = 80, Height = 5, Text = text };
  3175. tv.SelectionStartColumn = 6;
  3176. tv.CursorPosition = new Point (6, 2);
  3177. Assert.True (tv.NewKeyDownEvent (Key.Tab));
  3178. Assert.Equal ("First \tline.", tv.Text);
  3179. Assert.Equal (1, tv.Lines);
  3180. Assert.Equal (new Point (7, 0), tv.CursorPosition);
  3181. Assert.True (tv.NewKeyDownEvent (Key.Tab.WithShift));
  3182. Assert.Equal ("First line.", tv.Text);
  3183. Assert.Equal (1, tv.Lines);
  3184. Assert.Equal (new Point (6, 0), tv.CursorPosition);
  3185. // Undo
  3186. Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl));
  3187. Assert.Equal ("First \tline.", tv.Text);
  3188. Assert.Equal (1, tv.Lines);
  3189. Assert.Equal (new Point (7, 0), tv.CursorPosition);
  3190. Assert.True (tv.IsDirty);
  3191. Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl));
  3192. Assert.Equal ($"First line.{Environment.NewLine}Second line.{Environment.NewLine}Third line.", tv.Text);
  3193. Assert.Equal (3, tv.Lines);
  3194. Assert.Equal (new Point (6, 2), tv.CursorPosition);
  3195. Assert.False (tv.IsDirty);
  3196. // Redo
  3197. Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl));
  3198. Assert.Equal ("First \tline.", tv.Text);
  3199. Assert.Equal (1, tv.Lines);
  3200. Assert.Equal (new Point (7, 0), tv.CursorPosition);
  3201. Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl));
  3202. Assert.Equal ("First line.", tv.Text);
  3203. Assert.Equal (1, tv.Lines);
  3204. Assert.Equal (new Point (6, 0), tv.CursorPosition);
  3205. }
  3206. [Fact]
  3207. public void HistoryText_Undo_Redo_Multiline_Simples_Tab_BackTab ()
  3208. {
  3209. var text = "First line.\nSecond line.\nThird line.";
  3210. var tv = new TextView { Width = 80, Height = 5, Text = text };
  3211. Assert.True (tv.NewKeyDownEvent (Key.Tab));
  3212. Assert.Equal (
  3213. $"\tFirst line.{Environment.NewLine}Second line.{Environment.NewLine}Third line.",
  3214. tv.Text
  3215. );
  3216. Assert.Equal (3, tv.Lines);
  3217. Assert.Equal (new Point (1, 0), tv.CursorPosition);
  3218. Assert.True (tv.NewKeyDownEvent (Key.Tab.WithShift));
  3219. Assert.Equal ($"First line.{Environment.NewLine}Second line.{Environment.NewLine}Third line.", tv.Text);
  3220. Assert.Equal (3, tv.Lines);
  3221. Assert.Equal (Point.Empty, tv.CursorPosition);
  3222. // Undo
  3223. Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl));
  3224. Assert.Equal (
  3225. $"\tFirst line.{Environment.NewLine}Second line.{Environment.NewLine}Third line.",
  3226. tv.Text
  3227. );
  3228. Assert.Equal (3, tv.Lines);
  3229. Assert.Equal (new Point (1, 0), tv.CursorPosition);
  3230. Assert.True (tv.IsDirty);
  3231. Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl));
  3232. Assert.Equal ($"First line.{Environment.NewLine}Second line.{Environment.NewLine}Third line.", tv.Text);
  3233. Assert.Equal (3, tv.Lines);
  3234. Assert.Equal (Point.Empty, tv.CursorPosition);
  3235. Assert.False (tv.IsDirty);
  3236. // Redo
  3237. Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl));
  3238. Assert.Equal (
  3239. $"\tFirst line.{Environment.NewLine}Second line.{Environment.NewLine}Third line.",
  3240. tv.Text
  3241. );
  3242. Assert.Equal (3, tv.Lines);
  3243. Assert.Equal (new Point (1, 0), tv.CursorPosition);
  3244. Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl));
  3245. Assert.Equal ($"First line.{Environment.NewLine}Second line.{Environment.NewLine}Third line.", tv.Text);
  3246. Assert.Equal (3, tv.Lines);
  3247. Assert.Equal (Point.Empty, tv.CursorPosition);
  3248. }
  3249. [Fact]
  3250. [AutoInitShutdown]
  3251. public void HistoryText_Undo_Redo_Setting_Clipboard_Multi_Line_Selected_Paste ()
  3252. {
  3253. var text = "This is the first line.\nThis is the second line.";
  3254. var tv = new TextView { Text = text };
  3255. Clipboard.Contents = "Inserted\nNewLine";
  3256. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.", tv.Text);
  3257. Assert.Equal ("", tv.SelectedText);
  3258. Assert.Equal (2, tv.Lines);
  3259. Assert.Equal (Point.Empty, tv.CursorPosition);
  3260. Assert.True (tv.NewKeyDownEvent (Key.Y.WithCtrl));
  3261. Assert.Equal (
  3262. $"Inserted{Environment.NewLine}NewLineThis is the first line.{Environment.NewLine}This is the second line.",
  3263. tv.Text
  3264. );
  3265. Assert.Equal (3, tv.Lines);
  3266. Assert.Equal (new Point (7, 1), tv.CursorPosition);
  3267. // Undo
  3268. Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl));
  3269. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.", tv.Text);
  3270. Assert.Equal (2, tv.Lines);
  3271. Assert.Equal (Point.Empty, tv.CursorPosition);
  3272. // Redo
  3273. Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl));
  3274. Assert.Equal (
  3275. $"Inserted{Environment.NewLine}NewLineThis is the first line.{Environment.NewLine}This is the second line.",
  3276. tv.Text
  3277. );
  3278. Assert.Equal (3, tv.Lines);
  3279. Assert.Equal (new Point (7, 1), tv.CursorPosition);
  3280. }
  3281. [Fact]
  3282. [AutoInitShutdown (useFakeClipboard: true)]
  3283. public void HistoryText_Undo_Redo_Simple_Copy_Multi_Line_Selected_Paste ()
  3284. {
  3285. var text = "This is the first line.\nThis is the second line.\nThis is the third line.";
  3286. var tv = new TextView { Text = text };
  3287. tv.SelectionStartColumn = 12;
  3288. tv.CursorPosition = new Point (17, 0);
  3289. Assert.True (tv.NewKeyDownEvent (Key.C.WithCtrl));
  3290. Assert.Equal (
  3291. $"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.",
  3292. tv.Text
  3293. );
  3294. Assert.Equal ("first", tv.SelectedText);
  3295. Assert.Equal (3, tv.Lines);
  3296. Assert.Equal (new Point (17, 0), tv.CursorPosition);
  3297. tv.SelectionStartColumn = 12;
  3298. tv.CursorPosition = new Point (11, 1);
  3299. Assert.True (tv.NewKeyDownEvent (Key.Y.WithCtrl));
  3300. Assert.Equal ($"This is the first second line.{Environment.NewLine}This is the third line.", tv.Text);
  3301. Assert.Equal (2, tv.Lines);
  3302. Assert.Equal (new Point (17, 0), tv.CursorPosition);
  3303. // Undo
  3304. Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl));
  3305. Assert.Equal (
  3306. $"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.",
  3307. tv.Text
  3308. );
  3309. Assert.Equal (3, tv.Lines);
  3310. Assert.Equal (new Point (12, 0), tv.CursorPosition);
  3311. // Redo
  3312. Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl));
  3313. Assert.Equal ($"This is the first second line.{Environment.NewLine}This is the third line.", tv.Text);
  3314. Assert.Equal (2, tv.Lines);
  3315. Assert.Equal (new Point (17, 0), tv.CursorPosition);
  3316. }
  3317. [Fact]
  3318. [AutoInitShutdown]
  3319. public void HistoryText_Undo_Redo_Single_Line_DeleteCharLeft ()
  3320. {
  3321. var text = "This is the first line.\nThis is the second line.\nThis is the third line.";
  3322. var tv = new TextView { Width = 10, Height = 2, Text = text };
  3323. Toplevel top = new ();
  3324. top.Add (tv);
  3325. Application.Begin (top);
  3326. Assert.Equal (
  3327. $"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.",
  3328. tv.Text
  3329. );
  3330. Assert.Equal (3, tv.Lines);
  3331. Assert.Equal (Point.Empty, tv.CursorPosition);
  3332. var ntimes = 3;
  3333. tv.CursorPosition = new Point (7, 1);
  3334. for (var i = 0; i < ntimes; i++)
  3335. {
  3336. tv.DeleteCharLeft ();
  3337. }
  3338. Assert.Equal (
  3339. $"This is the first line.{Environment.NewLine}This the second line.{Environment.NewLine}This is the third line.",
  3340. tv.Text
  3341. );
  3342. Assert.Equal (3, tv.Lines);
  3343. Assert.Equal (new Point (4, 1), tv.CursorPosition);
  3344. for (var i = 0; i < ntimes; i++)
  3345. {
  3346. Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl));
  3347. }
  3348. Assert.Equal (
  3349. $"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.",
  3350. tv.Text
  3351. );
  3352. Assert.Equal (3, tv.Lines);
  3353. Assert.Equal (new Point (7, 1), tv.CursorPosition);
  3354. for (var i = 0; i < ntimes; i++)
  3355. {
  3356. Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl));
  3357. }
  3358. Assert.Equal (
  3359. $"This is the first line.{Environment.NewLine}This the second line.{Environment.NewLine}This is the third line.",
  3360. tv.Text
  3361. );
  3362. Assert.Equal (3, tv.Lines);
  3363. Assert.Equal (new Point (4, 1), tv.CursorPosition);
  3364. top.Dispose ();
  3365. }
  3366. [Fact]
  3367. [AutoInitShutdown]
  3368. public void HistoryText_Undo_Redo_Single_Line_DeleteCharRight ()
  3369. {
  3370. var text = "This is the first line.\nThis is the second line.\nThis is the third line.";
  3371. var tv = new TextView { Width = 10, Height = 2, Text = text };
  3372. Toplevel top = new ();
  3373. top.Add (tv);
  3374. Application.Begin (top);
  3375. Assert.Equal (
  3376. $"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.",
  3377. tv.Text
  3378. );
  3379. Assert.Equal (3, tv.Lines);
  3380. Assert.Equal (Point.Empty, tv.CursorPosition);
  3381. var ntimes = 3;
  3382. tv.CursorPosition = new Point (7, 1);
  3383. for (var i = 0; i < ntimes; i++)
  3384. {
  3385. tv.DeleteCharRight ();
  3386. }
  3387. Assert.Equal (
  3388. $"This is the first line.{Environment.NewLine}This ise second line.{Environment.NewLine}This is the third line.",
  3389. tv.Text
  3390. );
  3391. Assert.Equal (3, tv.Lines);
  3392. Assert.Equal (new Point (7, 1), tv.CursorPosition);
  3393. for (var i = 0; i < ntimes; i++)
  3394. {
  3395. Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl));
  3396. }
  3397. Assert.Equal (
  3398. $"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.",
  3399. tv.Text
  3400. );
  3401. Assert.Equal (3, tv.Lines);
  3402. Assert.Equal (new Point (7, 1), tv.CursorPosition);
  3403. for (var i = 0; i < ntimes; i++)
  3404. {
  3405. Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl));
  3406. }
  3407. Assert.Equal (
  3408. $"This is the first line.{Environment.NewLine}This ise second line.{Environment.NewLine}This is the third line.",
  3409. tv.Text
  3410. );
  3411. Assert.Equal (3, tv.Lines);
  3412. Assert.Equal (new Point (7, 1), tv.CursorPosition);
  3413. top.Dispose ();
  3414. }
  3415. [Fact]
  3416. [AutoInitShutdown]
  3417. public void HistoryText_Undo_Redo_Single_Line_InsertText ()
  3418. {
  3419. var text = "This is the first line.\nThis is the second line.\nThis is the third line.";
  3420. var tv = new TextView { Width = 10, Height = 2, Text = text };
  3421. Toplevel top = new ();
  3422. top.Add (tv);
  3423. Application.Begin (top);
  3424. Assert.Equal (
  3425. $"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.",
  3426. tv.Text
  3427. );
  3428. Assert.Equal (3, tv.Lines);
  3429. Assert.Equal (Point.Empty, tv.CursorPosition);
  3430. var messy = " messy";
  3431. tv.CursorPosition = new Point (7, 1);
  3432. tv.InsertText (messy);
  3433. Assert.Equal (
  3434. $"This is the first line.{Environment.NewLine}This is messy the second line.{Environment.NewLine}This is the third line.",
  3435. tv.Text
  3436. );
  3437. Assert.Equal (3, tv.Lines);
  3438. Assert.Equal (new Point (13, 1), tv.CursorPosition);
  3439. for (var i = 0; i < messy.Length; i++)
  3440. {
  3441. Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl));
  3442. }
  3443. Assert.Equal (
  3444. $"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.",
  3445. tv.Text
  3446. );
  3447. Assert.Equal (3, tv.Lines);
  3448. Assert.Equal (new Point (7, 1), tv.CursorPosition);
  3449. for (var i = 0; i < messy.Length; i++)
  3450. {
  3451. Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl));
  3452. }
  3453. Assert.Equal (
  3454. $"This is the first line.{Environment.NewLine}This is messy the second line.{Environment.NewLine}This is the third line.",
  3455. tv.Text
  3456. );
  3457. Assert.Equal (3, tv.Lines);
  3458. Assert.Equal (new Point (13, 1), tv.CursorPosition);
  3459. top.Dispose ();
  3460. }
  3461. [Fact]
  3462. [AutoInitShutdown]
  3463. public void HistoryText_Undo_Redo_Single_Line_Selected_DeleteCharLeft ()
  3464. {
  3465. var text = "This is the first line.\nThis is the second line.\nThis is the third line.";
  3466. var tv = new TextView { Width = 10, Height = 2, Text = text };
  3467. Toplevel top = new ();
  3468. top.Add (tv);
  3469. Application.Begin (top);
  3470. Assert.Equal (
  3471. $"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.",
  3472. tv.Text
  3473. );
  3474. Assert.Equal (3, tv.Lines);
  3475. Assert.Equal (Point.Empty, tv.CursorPosition);
  3476. var ntimes = 3;
  3477. tv.CursorPosition = new Point (7, 1);
  3478. tv.SelectionStartColumn = 11;
  3479. tv.SelectionStartRow = 1;
  3480. Assert.Equal (4, tv.SelectedLength);
  3481. for (var i = 0; i < ntimes; i++)
  3482. {
  3483. tv.DeleteCharLeft ();
  3484. }
  3485. Assert.Equal (
  3486. $"This is the first line.{Environment.NewLine}This second line.{Environment.NewLine}This is the third line.",
  3487. tv.Text
  3488. );
  3489. Assert.Equal (3, tv.Lines);
  3490. Assert.Equal (new Point (5, 1), tv.CursorPosition);
  3491. Assert.Equal (11, tv.SelectionStartColumn);
  3492. Assert.Equal (1, tv.SelectionStartRow);
  3493. Assert.Equal (0, tv.SelectedLength);
  3494. for (var i = 0; i < ntimes; i++)
  3495. {
  3496. Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl));
  3497. }
  3498. Assert.Equal (
  3499. $"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.",
  3500. tv.Text
  3501. );
  3502. Assert.Equal (3, tv.Lines);
  3503. Assert.Equal (new Point (7, 1), tv.CursorPosition);
  3504. Assert.Equal (11, tv.SelectionStartColumn);
  3505. Assert.Equal (1, tv.SelectionStartRow);
  3506. Assert.Equal (0, tv.SelectedLength);
  3507. for (var i = 0; i < ntimes; i++)
  3508. {
  3509. Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl));
  3510. }
  3511. Assert.Equal (
  3512. $"This is the first line.{Environment.NewLine}This second line.{Environment.NewLine}This is the third line.",
  3513. tv.Text
  3514. );
  3515. Assert.Equal (3, tv.Lines);
  3516. Assert.Equal (new Point (5, 1), tv.CursorPosition);
  3517. Assert.Equal (11, tv.SelectionStartColumn);
  3518. Assert.Equal (1, tv.SelectionStartRow);
  3519. Assert.Equal (0, tv.SelectedLength);
  3520. top.Dispose ();
  3521. }
  3522. [Fact]
  3523. [AutoInitShutdown]
  3524. public void HistoryText_Undo_Redo_Single_Line_Selected_DeleteCharRight ()
  3525. {
  3526. var text = "This is the first line.\nThis is the second line.\nThis is the third line.";
  3527. var tv = new TextView { Width = 10, Height = 2, Text = text };
  3528. Toplevel top = new ();
  3529. top.Add (tv);
  3530. Application.Begin (top);
  3531. Assert.Equal (
  3532. $"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.",
  3533. tv.Text
  3534. );
  3535. Assert.Equal (3, tv.Lines);
  3536. Assert.Equal (Point.Empty, tv.CursorPosition);
  3537. var ntimes = 3;
  3538. tv.CursorPosition = new Point (7, 1);
  3539. tv.SelectionStartColumn = 11;
  3540. tv.SelectionStartRow = 1;
  3541. Assert.Equal (4, tv.SelectedLength);
  3542. for (var i = 0; i < ntimes; i++)
  3543. {
  3544. tv.DeleteCharRight ();
  3545. }
  3546. Assert.Equal (
  3547. $"This is the first line.{Environment.NewLine}This isecond line.{Environment.NewLine}This is the third line.",
  3548. tv.Text
  3549. );
  3550. Assert.Equal (3, tv.Lines);
  3551. Assert.Equal (new Point (7, 1), tv.CursorPosition);
  3552. Assert.Equal (11, tv.SelectionStartColumn);
  3553. Assert.Equal (1, tv.SelectionStartRow);
  3554. Assert.Equal (0, tv.SelectedLength);
  3555. for (var i = 0; i < ntimes; i++)
  3556. {
  3557. Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl));
  3558. }
  3559. Assert.Equal (
  3560. $"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.",
  3561. tv.Text
  3562. );
  3563. Assert.Equal (3, tv.Lines);
  3564. Assert.Equal (new Point (7, 1), tv.CursorPosition);
  3565. Assert.Equal (11, tv.SelectionStartColumn);
  3566. Assert.Equal (1, tv.SelectionStartRow);
  3567. Assert.Equal (0, tv.SelectedLength);
  3568. for (var i = 0; i < ntimes; i++)
  3569. {
  3570. Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl));
  3571. }
  3572. Assert.Equal (
  3573. $"This is the first line.{Environment.NewLine}This isecond line.{Environment.NewLine}This is the third line.",
  3574. tv.Text
  3575. );
  3576. Assert.Equal (3, tv.Lines);
  3577. Assert.Equal (new Point (7, 1), tv.CursorPosition);
  3578. Assert.Equal (11, tv.SelectionStartColumn);
  3579. Assert.Equal (1, tv.SelectionStartRow);
  3580. Assert.Equal (0, tv.SelectedLength);
  3581. top.Dispose ();
  3582. }
  3583. [Fact]
  3584. [AutoInitShutdown]
  3585. public void HistoryText_Undo_Redo_Single_Line_Selected_InsertText ()
  3586. {
  3587. var text = "This is the first line.\nThis is the second line.\nThis is the third line.";
  3588. var tv = new TextView { Width = 10, Height = 2, Text = text };
  3589. Toplevel top = new ();
  3590. top.Add (tv);
  3591. Application.Begin (top);
  3592. Assert.Equal (
  3593. $"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.",
  3594. tv.Text
  3595. );
  3596. Assert.Equal (3, tv.Lines);
  3597. Assert.Equal (Point.Empty, tv.CursorPosition);
  3598. var messy = " messy";
  3599. tv.CursorPosition = new Point (7, 1);
  3600. tv.SelectionStartColumn = 11;
  3601. tv.SelectionStartRow = 1;
  3602. Assert.Equal (4, tv.SelectedLength);
  3603. tv.InsertText (messy);
  3604. Assert.Equal (
  3605. $"This is the first line.{Environment.NewLine}This is messy second line.{Environment.NewLine}This is the third line.",
  3606. tv.Text
  3607. );
  3608. Assert.Equal (3, tv.Lines);
  3609. Assert.Equal (new Point (13, 1), tv.CursorPosition);
  3610. Assert.Equal (11, tv.SelectionStartColumn);
  3611. Assert.Equal (1, tv.SelectionStartRow);
  3612. Assert.Equal (0, tv.SelectedLength);
  3613. for (var i = 0; i < messy.Length; i++)
  3614. {
  3615. Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl));
  3616. }
  3617. Assert.Equal (
  3618. $"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.",
  3619. tv.Text
  3620. );
  3621. Assert.Equal (3, tv.Lines);
  3622. Assert.Equal (new Point (7, 1), tv.CursorPosition);
  3623. Assert.Equal (11, tv.SelectionStartColumn);
  3624. Assert.Equal (1, tv.SelectionStartRow);
  3625. Assert.Equal (0, tv.SelectedLength);
  3626. for (var i = 0; i < messy.Length; i++)
  3627. {
  3628. Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl));
  3629. }
  3630. Assert.Equal (
  3631. $"This is the first line.{Environment.NewLine}This is messy second line.{Environment.NewLine}This is the third line.",
  3632. tv.Text
  3633. );
  3634. Assert.Equal (3, tv.Lines);
  3635. Assert.Equal (new Point (13, 1), tv.CursorPosition);
  3636. Assert.Equal (11, tv.SelectionStartColumn);
  3637. Assert.Equal (1, tv.SelectionStartRow);
  3638. Assert.Equal (0, tv.SelectedLength);
  3639. top.Dispose ();
  3640. }
  3641. [Fact]
  3642. public void HistoryText_Undo_Redo_Single_Line_Selected_Return ()
  3643. {
  3644. var text = "This is the first line.\nThis is the second line.\nThis is the third line.";
  3645. var tv = new TextView { Text = text };
  3646. tv.SelectionStartColumn = 12;
  3647. tv.CursorPosition = new Point (17, 0);
  3648. Assert.True (tv.NewKeyDownEvent (Key.Enter));
  3649. Assert.Equal (
  3650. $"This is the {Environment.NewLine} line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.",
  3651. tv.Text
  3652. );
  3653. Assert.Equal (4, tv.Lines);
  3654. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  3655. // Undo
  3656. Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl));
  3657. Assert.Equal (
  3658. $"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.",
  3659. tv.Text
  3660. );
  3661. Assert.Equal (3, tv.Lines);
  3662. Assert.Equal (new Point (17, 0), tv.CursorPosition);
  3663. Assert.False (tv.IsDirty);
  3664. // Redo
  3665. Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl));
  3666. Assert.Equal (
  3667. $"This is the {Environment.NewLine} line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.",
  3668. tv.Text
  3669. );
  3670. Assert.Equal (4, tv.Lines);
  3671. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  3672. // Undo
  3673. Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl));
  3674. Assert.Equal (
  3675. $"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.",
  3676. tv.Text
  3677. );
  3678. Assert.Equal (3, tv.Lines);
  3679. Assert.Equal (new Point (17, 0), tv.CursorPosition);
  3680. Assert.False (tv.IsDirty);
  3681. // Redo
  3682. Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl));
  3683. Assert.Equal (
  3684. $"This is the {Environment.NewLine} line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.",
  3685. tv.Text
  3686. );
  3687. Assert.Equal (4, tv.Lines);
  3688. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  3689. }
  3690. [Fact]
  3691. public void HistoryText_Undo_Redo_Single_Second_Line_Selected_Return ()
  3692. {
  3693. var text = "This is the first line.\nThis is the second line.\nThis is the third line.";
  3694. var tv = new TextView { Text = text };
  3695. tv.SelectionStartColumn = 12;
  3696. tv.SelectionStartRow = 1;
  3697. tv.CursorPosition = new Point (18, 1);
  3698. Assert.True (tv.NewKeyDownEvent (Key.Enter));
  3699. Assert.Equal (
  3700. $"This is the first line.{Environment.NewLine}This is the {Environment.NewLine} line.{Environment.NewLine}This is the third line.",
  3701. tv.Text
  3702. );
  3703. Assert.Equal (4, tv.Lines);
  3704. Assert.Equal (new Point (0, 2), tv.CursorPosition);
  3705. // Undo
  3706. Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl));
  3707. Assert.Equal (
  3708. $"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.",
  3709. tv.Text
  3710. );
  3711. Assert.Equal (3, tv.Lines);
  3712. Assert.Equal (new Point (18, 1), tv.CursorPosition);
  3713. Assert.False (tv.IsDirty);
  3714. // Redo
  3715. Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl));
  3716. Assert.Equal (
  3717. $"This is the first line.{Environment.NewLine}This is the {Environment.NewLine} line.{Environment.NewLine}This is the third line.",
  3718. tv.Text
  3719. );
  3720. Assert.Equal (4, tv.Lines);
  3721. Assert.Equal (new Point (0, 2), tv.CursorPosition);
  3722. // Undo
  3723. Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl));
  3724. Assert.Equal (
  3725. $"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.",
  3726. tv.Text
  3727. );
  3728. Assert.Equal (3, tv.Lines);
  3729. Assert.Equal (new Point (18, 1), tv.CursorPosition);
  3730. Assert.False (tv.IsDirty);
  3731. // Redo
  3732. Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl));
  3733. Assert.Equal (
  3734. $"This is the first line.{Environment.NewLine}This is the {Environment.NewLine} line.{Environment.NewLine}This is the third line.",
  3735. tv.Text
  3736. );
  3737. Assert.Equal (4, tv.Lines);
  3738. Assert.Equal (new Point (0, 2), tv.CursorPosition);
  3739. }
  3740. [Fact]
  3741. public void HistoryText_Undo_Redo_Single_Second_Line_Selected_Return_And_InsertText ()
  3742. {
  3743. var text = "This is the first line.\nThis is the second line.\nThis is the third line.";
  3744. var tv = new TextView { Text = text };
  3745. tv.SelectionStartColumn = 12;
  3746. tv.SelectionStartRow = 1;
  3747. tv.CursorPosition = new Point (18, 1);
  3748. Assert.True (tv.NewKeyDownEvent (Key.Enter));
  3749. Assert.Equal (
  3750. $"This is the first line.{Environment.NewLine}This is the {Environment.NewLine} line.{Environment.NewLine}This is the third line.",
  3751. tv.Text
  3752. );
  3753. Assert.Equal (4, tv.Lines);
  3754. Assert.Equal (new Point (0, 2), tv.CursorPosition);
  3755. Assert.True (tv.NewKeyDownEvent (Key.A));
  3756. Assert.Equal (
  3757. $"This is the first line.{Environment.NewLine}This is the {Environment.NewLine}a line.{Environment.NewLine}This is the third line.",
  3758. tv.Text
  3759. );
  3760. Assert.Equal (4, tv.Lines);
  3761. Assert.Equal (new Point (1, 2), tv.CursorPosition);
  3762. // Undo
  3763. Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl));
  3764. Assert.Equal (
  3765. $"This is the first line.{Environment.NewLine}This is the {Environment.NewLine} line.{Environment.NewLine}This is the third line.",
  3766. tv.Text
  3767. );
  3768. Assert.Equal (4, tv.Lines);
  3769. Assert.Equal (new Point (0, 2), tv.CursorPosition);
  3770. Assert.True (tv.IsDirty);
  3771. Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl));
  3772. Assert.Equal (
  3773. $"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.",
  3774. tv.Text
  3775. );
  3776. Assert.Equal (3, tv.Lines);
  3777. Assert.Equal (new Point (18, 1), tv.CursorPosition);
  3778. Assert.False (tv.IsDirty);
  3779. // Redo
  3780. Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl));
  3781. Assert.Equal (
  3782. $"This is the first line.{Environment.NewLine}This is the {Environment.NewLine} line.{Environment.NewLine}This is the third line.",
  3783. tv.Text
  3784. );
  3785. Assert.Equal (4, tv.Lines);
  3786. Assert.Equal (new Point (0, 2), tv.CursorPosition);
  3787. Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl));
  3788. Assert.Equal (
  3789. $"This is the first line.{Environment.NewLine}This is the {Environment.NewLine}a line.{Environment.NewLine}This is the third line.",
  3790. tv.Text
  3791. );
  3792. Assert.Equal (4, tv.Lines);
  3793. Assert.Equal (new Point (1, 2), tv.CursorPosition);
  3794. // Undo
  3795. Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl));
  3796. Assert.Equal (
  3797. $"This is the first line.{Environment.NewLine}This is the {Environment.NewLine} line.{Environment.NewLine}This is the third line.",
  3798. tv.Text
  3799. );
  3800. Assert.Equal (4, tv.Lines);
  3801. Assert.Equal (new Point (0, 2), tv.CursorPosition);
  3802. Assert.True (tv.IsDirty);
  3803. Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl));
  3804. Assert.Equal (
  3805. $"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.",
  3806. tv.Text
  3807. );
  3808. Assert.Equal (3, tv.Lines);
  3809. Assert.Equal (new Point (18, 1), tv.CursorPosition);
  3810. Assert.False (tv.IsDirty);
  3811. // Redo
  3812. Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl));
  3813. Assert.Equal (
  3814. $"This is the first line.{Environment.NewLine}This is the {Environment.NewLine} line.{Environment.NewLine}This is the third line.",
  3815. tv.Text
  3816. );
  3817. Assert.Equal (4, tv.Lines);
  3818. Assert.Equal (new Point (0, 2), tv.CursorPosition);
  3819. Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl));
  3820. Assert.Equal (
  3821. $"This is the first line.{Environment.NewLine}This is the {Environment.NewLine}a line.{Environment.NewLine}This is the third line.",
  3822. tv.Text
  3823. );
  3824. Assert.Equal (4, tv.Lines);
  3825. Assert.Equal (new Point (1, 2), tv.CursorPosition);
  3826. }
  3827. [Fact]
  3828. public void HistoryText_Undo_Redo_Three_Line_Selected_Return ()
  3829. {
  3830. var text = "This is the first line.\nThis is the second line.\nThis is the third line.";
  3831. var tv = new TextView { Text = text };
  3832. tv.SelectionStartColumn = 12;
  3833. tv.CursorPosition = new Point (17, 2);
  3834. Assert.True (tv.NewKeyDownEvent (Key.Enter));
  3835. Assert.Equal ($"This is the {Environment.NewLine} line.", tv.Text);
  3836. Assert.Equal (2, tv.Lines);
  3837. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  3838. // Undo
  3839. Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl));
  3840. Assert.Equal (
  3841. $"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.",
  3842. tv.Text
  3843. );
  3844. Assert.Equal (3, tv.Lines);
  3845. Assert.Equal (new Point (17, 2), tv.CursorPosition);
  3846. Assert.False (tv.IsDirty);
  3847. // Redo
  3848. Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl));
  3849. Assert.Equal ($"This is the {Environment.NewLine} line.", tv.Text);
  3850. Assert.Equal (2, tv.Lines);
  3851. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  3852. // Undo
  3853. Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl));
  3854. Assert.Equal (
  3855. $"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.",
  3856. tv.Text
  3857. );
  3858. Assert.Equal (3, tv.Lines);
  3859. Assert.Equal (new Point (17, 2), tv.CursorPosition);
  3860. Assert.False (tv.IsDirty);
  3861. // Redo
  3862. Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl));
  3863. Assert.Equal ($"This is the {Environment.NewLine} line.", tv.Text);
  3864. Assert.Equal (2, tv.Lines);
  3865. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  3866. }
  3867. [Fact]
  3868. public void HistoryText_Undo_Redo_Two_Line_Selected_Return ()
  3869. {
  3870. var text = "This is the first line.\nThis is the second line.\nThis is the third line.";
  3871. var tv = new TextView { Text = text };
  3872. tv.SelectionStartColumn = 12;
  3873. tv.CursorPosition = new Point (18, 1);
  3874. Assert.True (tv.NewKeyDownEvent (Key.Enter));
  3875. Assert.Equal (
  3876. $"This is the {Environment.NewLine} line.{Environment.NewLine}This is the third line.",
  3877. tv.Text
  3878. );
  3879. Assert.Equal (3, tv.Lines);
  3880. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  3881. // Undo
  3882. Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl));
  3883. Assert.Equal (
  3884. $"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.",
  3885. tv.Text
  3886. );
  3887. Assert.Equal (3, tv.Lines);
  3888. Assert.Equal (new Point (18, 1), tv.CursorPosition);
  3889. Assert.False (tv.IsDirty);
  3890. // Redo
  3891. Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl));
  3892. Assert.Equal (
  3893. $"This is the {Environment.NewLine} line.{Environment.NewLine}This is the third line.",
  3894. tv.Text
  3895. );
  3896. Assert.Equal (3, tv.Lines);
  3897. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  3898. // Undo
  3899. Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl));
  3900. Assert.Equal (
  3901. $"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.",
  3902. tv.Text
  3903. );
  3904. Assert.Equal (3, tv.Lines);
  3905. Assert.Equal (new Point (18, 1), tv.CursorPosition);
  3906. Assert.False (tv.IsDirty);
  3907. // Redo
  3908. Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl));
  3909. Assert.Equal (
  3910. $"This is the {Environment.NewLine} line.{Environment.NewLine}This is the third line.",
  3911. tv.Text
  3912. );
  3913. Assert.Equal (3, tv.Lines);
  3914. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  3915. }
  3916. [Fact]
  3917. public void HistoryText_Undo_Redo_ApplyCellsAttribute ()
  3918. {
  3919. var text = "This is the first line.\nThis is the second line.\nThis is the third line.";
  3920. var tv = new TextView { Text = text };
  3921. tv.SelectionStartColumn = 12;
  3922. tv.CursorPosition = new Point (18, 1);
  3923. if (Environment.NewLine.Length == 2)
  3924. {
  3925. Assert.Equal (31, tv.SelectedLength);
  3926. }
  3927. else
  3928. {
  3929. Assert.Equal (30, tv.SelectedLength);
  3930. }
  3931. Assert.Equal ($"first line.{Environment.NewLine}This is the second", tv.SelectedText);
  3932. Assert.Equal ($"first line.{Environment.NewLine}This is the second", Cell.ToString (tv.SelectedCellsList));
  3933. Assert.Equal (new Point (18, 1), tv.CursorPosition);
  3934. Assert.False (tv.IsDirty);
  3935. AssertNullAttribute ();
  3936. tv.ApplyCellsAttribute (new (Color.Red, Color.Green));
  3937. AssertRedGreenAttribute ();
  3938. Assert.Equal (0, tv.SelectedLength);
  3939. Assert.Equal ("", tv.SelectedText);
  3940. Assert.Equal ($"first line.{Environment.NewLine}This is the second", Cell.ToString (tv.SelectedCellsList));
  3941. Assert.Equal (new Point (18, 1), tv.CursorPosition);
  3942. Assert.True (tv.IsDirty);
  3943. // Undo
  3944. Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl));
  3945. AssertNullAttribute ();
  3946. Assert.Equal (12, tv.SelectionStartColumn);
  3947. Assert.Equal (0, tv.SelectionStartRow);
  3948. Assert.Equal (0, tv.SelectedLength);
  3949. Assert.Equal ("", tv.SelectedText);
  3950. Assert.Empty (tv.SelectedCellsList);
  3951. Assert.Equal (new Point (12, 0), tv.CursorPosition);
  3952. Assert.False (tv.IsDirty);
  3953. // Redo
  3954. Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl));
  3955. AssertRedGreenAttribute ();
  3956. Assert.Equal (12, tv.SelectionStartColumn);
  3957. Assert.Equal (0, tv.SelectionStartRow);
  3958. Assert.Equal (0, tv.SelectedLength);
  3959. Assert.Equal ("", tv.SelectedText);
  3960. Assert.Empty (tv.SelectedCellsList);
  3961. Assert.Equal (new Point (12, 0), tv.CursorPosition);
  3962. Assert.True (tv.IsDirty);
  3963. void AssertNullAttribute ()
  3964. {
  3965. tv.GetRegion (out List<List<Cell>> region, 0, 12, 1, 18);
  3966. foreach (List<Cell> cells in region)
  3967. {
  3968. foreach (Cell cell in cells)
  3969. {
  3970. Assert.Null (cell.Attribute);
  3971. }
  3972. }
  3973. }
  3974. void AssertRedGreenAttribute ()
  3975. {
  3976. tv.GetRegion (out List<List<Cell>> region, 0, 12, 1, 18);
  3977. foreach (List<Cell> cells in region)
  3978. {
  3979. foreach (Cell cell in cells)
  3980. {
  3981. Assert.Equal ("[Red,Green]", cell.Attribute.ToString ());
  3982. }
  3983. }
  3984. }
  3985. }
  3986. [Fact]
  3987. public void Internal_Tests ()
  3988. {
  3989. var txt = "This is a text.";
  3990. List<Cell> txtRunes = Cell.StringToCells (txt);
  3991. Assert.Equal (txt.Length, txtRunes.Count);
  3992. Assert.Equal ('T', txtRunes [0].Rune.Value);
  3993. Assert.Equal ('h', txtRunes [1].Rune.Value);
  3994. Assert.Equal ('i', txtRunes [2].Rune.Value);
  3995. Assert.Equal ('s', txtRunes [3].Rune.Value);
  3996. Assert.Equal (' ', txtRunes [4].Rune.Value);
  3997. Assert.Equal ('i', txtRunes [5].Rune.Value);
  3998. Assert.Equal ('s', txtRunes [6].Rune.Value);
  3999. Assert.Equal (' ', txtRunes [7].Rune.Value);
  4000. Assert.Equal ('a', txtRunes [8].Rune.Value);
  4001. Assert.Equal (' ', txtRunes [9].Rune.Value);
  4002. Assert.Equal ('t', txtRunes [10].Rune.Value);
  4003. Assert.Equal ('e', txtRunes [11].Rune.Value);
  4004. Assert.Equal ('x', txtRunes [12].Rune.Value);
  4005. Assert.Equal ('t', txtRunes [13].Rune.Value);
  4006. Assert.Equal ('.', txtRunes [^1].Rune.Value);
  4007. var col = 0;
  4008. Assert.True (TextModel.SetCol (ref col, 80, 79));
  4009. Assert.False (TextModel.SetCol (ref col, 80, 80));
  4010. Assert.Equal (79, col);
  4011. var start = 0;
  4012. var x = 8;
  4013. Assert.Equal (8, TextModel.GetColFromX (txtRunes, start, x));
  4014. Assert.Equal ('a', txtRunes [start + x].Rune.Value);
  4015. start = 1;
  4016. x = 7;
  4017. Assert.Equal (7, TextModel.GetColFromX (txtRunes, start, x));
  4018. Assert.Equal ('a', txtRunes [start + x].Rune.Value);
  4019. Assert.Equal ((15, 15), TextModel.DisplaySize (txtRunes));
  4020. Assert.Equal ((6, 6), TextModel.DisplaySize (txtRunes, 1, 7));
  4021. Assert.Equal (0, TextModel.CalculateLeftColumn (txtRunes, 0, 7, 8));
  4022. Assert.Equal (1, TextModel.CalculateLeftColumn (txtRunes, 0, 8, 8));
  4023. Assert.Equal (2, TextModel.CalculateLeftColumn (txtRunes, 0, 9, 8));
  4024. var tm = new TextModel ();
  4025. tm.AddLine (0, Cell.StringToCells ("This is first line."));
  4026. tm.AddLine (1, Cell.StringToCells ("This is last line."));
  4027. Assert.Equal ((new Point (2, 0), true), tm.FindNextText ("is", out bool gaveFullTurn));
  4028. Assert.False (gaveFullTurn);
  4029. Assert.Equal ((new Point (5, 0), true), tm.FindNextText ("is", out gaveFullTurn));
  4030. Assert.False (gaveFullTurn);
  4031. Assert.Equal ((new Point (2, 1), true), tm.FindNextText ("is", out gaveFullTurn));
  4032. Assert.False (gaveFullTurn);
  4033. Assert.Equal ((new Point (5, 1), true), tm.FindNextText ("is", out gaveFullTurn));
  4034. Assert.False (gaveFullTurn);
  4035. Assert.Equal ((new Point (2, 0), true), tm.FindNextText ("is", out gaveFullTurn));
  4036. Assert.True (gaveFullTurn);
  4037. tm.ResetContinuousFind (Point.Empty);
  4038. Assert.Equal ((new Point (5, 1), true), tm.FindPreviousText ("is", out gaveFullTurn));
  4039. Assert.False (gaveFullTurn);
  4040. Assert.Equal ((new Point (2, 1), true), tm.FindPreviousText ("is", out gaveFullTurn));
  4041. Assert.False (gaveFullTurn);
  4042. Assert.Equal ((new Point (5, 0), true), tm.FindPreviousText ("is", out gaveFullTurn));
  4043. Assert.False (gaveFullTurn);
  4044. Assert.Equal ((new Point (2, 0), true), tm.FindPreviousText ("is", out gaveFullTurn));
  4045. Assert.False (gaveFullTurn);
  4046. Assert.Equal ((new Point (5, 1), true), tm.FindPreviousText ("is", out gaveFullTurn));
  4047. Assert.True (gaveFullTurn);
  4048. Assert.Equal ((new Point (9, 1), true), tm.ReplaceAllText ("is", false, false, "really"));
  4049. Assert.Equal (Cell.StringToCells ("Threally really first line."), tm.GetLine (0));
  4050. Assert.Equal (Cell.StringToCells ("Threally really last line."), tm.GetLine (1));
  4051. tm = new TextModel ();
  4052. tm.AddLine (0, Cell.StringToCells ("This is first line."));
  4053. tm.AddLine (1, Cell.StringToCells ("This is last line."));
  4054. Assert.Equal ((new Point (5, 1), true), tm.ReplaceAllText ("is", false, true, "really"));
  4055. Assert.Equal (Cell.StringToCells ("This really first line."), tm.GetLine (0));
  4056. Assert.Equal (Cell.StringToCells ("This really last line."), tm.GetLine (1));
  4057. }
  4058. [Fact]
  4059. [AutoInitShutdown (useFakeClipboard: true)]
  4060. public void KeyBindings_Command ()
  4061. {
  4062. var text = "This is the first line.\nThis is the second line.\nThis is the third line.";
  4063. var tv = new TextView { Width = 10, Height = 2, Text = text };
  4064. Toplevel top = new ();
  4065. top.Add (tv);
  4066. Application.Begin (top);
  4067. Assert.Equal (
  4068. $"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.",
  4069. tv.Text
  4070. );
  4071. Assert.Equal (3, tv.Lines);
  4072. Assert.Equal (Point.Empty, tv.CursorPosition);
  4073. Assert.False (tv.ReadOnly);
  4074. Assert.True (tv.CanFocus);
  4075. var g = (SingleWordSuggestionGenerator)tv.Autocomplete.SuggestionGenerator;
  4076. tv.CanFocus = false;
  4077. Assert.True (tv.NewKeyDownEvent (Key.CursorLeft));
  4078. tv.CanFocus = true;
  4079. Assert.False (tv.NewKeyDownEvent (Key.CursorLeft));
  4080. Assert.True (tv.NewKeyDownEvent (Key.CursorRight));
  4081. Assert.Equal (new Point (1, 0), tv.CursorPosition);
  4082. Assert.True (tv.NewKeyDownEvent (Key.End.WithCtrl));
  4083. Assert.Equal (2, tv.CurrentRow);
  4084. Assert.Equal (23, tv.CurrentColumn);
  4085. Assert.Equal (tv.CurrentColumn, tv.GetCurrentLine ().Count);
  4086. Assert.Equal (new Point (23, 2), tv.CursorPosition);
  4087. Assert.False (tv.NewKeyDownEvent (Key.CursorRight));
  4088. Assert.NotNull (tv.Autocomplete);
  4089. Assert.Empty (g.AllSuggestions);
  4090. Assert.True (tv.NewKeyDownEvent (Key.F.WithShift));
  4091. tv.Draw ();
  4092. Assert.Equal (
  4093. $"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.F",
  4094. tv.Text
  4095. );
  4096. Assert.Equal (new Point (24, 2), tv.CursorPosition);
  4097. Assert.Empty (tv.Autocomplete.Suggestions);
  4098. Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl));
  4099. tv.Draw ();
  4100. Assert.Equal (
  4101. $"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.",
  4102. tv.Text
  4103. );
  4104. Assert.Equal (new Point (23, 2), tv.CursorPosition);
  4105. Assert.Empty (tv.Autocomplete.Suggestions);
  4106. Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl));
  4107. tv.Draw ();
  4108. Assert.Equal (
  4109. $"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.F",
  4110. tv.Text
  4111. );
  4112. Assert.Equal (new Point (24, 2), tv.CursorPosition);
  4113. Assert.Empty (tv.Autocomplete.Suggestions);
  4114. Assert.True (tv.NewKeyDownEvent (Key.Backspace));
  4115. Assert.Equal (
  4116. $"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.",
  4117. tv.Text
  4118. );
  4119. Assert.Equal (new Point (23, 2), tv.CursorPosition);
  4120. g.AllSuggestions = Regex.Matches (tv.Text, "\\w+")
  4121. .Select (s => s.Value)
  4122. .Distinct ()
  4123. .ToList ();
  4124. Assert.Equal (7, g.AllSuggestions.Count);
  4125. Assert.Equal ("This", g.AllSuggestions [0]);
  4126. Assert.Equal ("is", g.AllSuggestions [1]);
  4127. Assert.Equal ("the", g.AllSuggestions [2]);
  4128. Assert.Equal ("first", g.AllSuggestions [3]);
  4129. Assert.Equal ("line", g.AllSuggestions [4]);
  4130. Assert.Equal ("second", g.AllSuggestions [5]);
  4131. Assert.Equal ("third", g.AllSuggestions [^1]);
  4132. Assert.True (tv.NewKeyDownEvent (Key.F.WithShift));
  4133. tv.Draw ();
  4134. Assert.Equal (
  4135. $"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.F",
  4136. tv.Text
  4137. );
  4138. Assert.Equal (new Point (24, 2), tv.CursorPosition);
  4139. Assert.Single (tv.Autocomplete.Suggestions);
  4140. Assert.Equal ("first", tv.Autocomplete.Suggestions [0].Replacement);
  4141. Assert.True (tv.NewKeyDownEvent (Key.Enter));
  4142. Assert.Equal (
  4143. $"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first",
  4144. tv.Text
  4145. );
  4146. Assert.Equal (new Point (28, 2), tv.CursorPosition);
  4147. Assert.Empty (tv.Autocomplete.Suggestions);
  4148. Assert.False (tv.Autocomplete.Visible);
  4149. g.AllSuggestions = new List<string> ();
  4150. tv.Autocomplete.ClearSuggestions ();
  4151. Assert.Empty (g.AllSuggestions);
  4152. Assert.Empty (tv.Autocomplete.Suggestions);
  4153. Assert.True (tv.NewKeyDownEvent (Key.PageUp));
  4154. Assert.Equal (24, tv.GetCurrentLine ().Count);
  4155. Assert.Equal (new Point (24, 1), tv.CursorPosition);
  4156. Assert.True (tv.NewKeyDownEvent (new Key (Key.PageUp)));
  4157. Assert.Equal (23, tv.GetCurrentLine ().Count);
  4158. Assert.Equal (new Point (23, 0), tv.CursorPosition);
  4159. Assert.True (tv.NewKeyDownEvent (Key.PageDown));
  4160. Assert.Equal (24, tv.GetCurrentLine ().Count);
  4161. Assert.Equal (new Point (23, 1), tv.CursorPosition); // gets the previous length
  4162. Assert.True (tv.NewKeyDownEvent (Key.V.WithCtrl));
  4163. Assert.Equal (28, tv.GetCurrentLine ().Count);
  4164. Assert.Equal (new Point (23, 2), tv.CursorPosition); // gets the previous length
  4165. Assert.Equal (0, tv.SelectedLength);
  4166. Assert.Equal ("", tv.SelectedText);
  4167. Assert.True (tv.NewKeyDownEvent (Key.PageUp.WithShift));
  4168. Assert.Equal (24, tv.GetCurrentLine ().Count);
  4169. Assert.Equal (new Point (23, 1), tv.CursorPosition); // gets the previous length
  4170. Assert.Equal (24 + Environment.NewLine.Length, tv.SelectedLength);
  4171. Assert.Equal ($".{Environment.NewLine}This is the third line.", tv.SelectedText);
  4172. Assert.True (tv.NewKeyDownEvent (Key.PageDown.WithShift));
  4173. Assert.Equal (28, tv.GetCurrentLine ().Count);
  4174. Assert.Equal (new Point (23, 2), tv.CursorPosition); // gets the previous length
  4175. Assert.Equal (0, tv.SelectedLength);
  4176. Assert.Equal ("", tv.SelectedText);
  4177. Assert.True (tv.NewKeyDownEvent (Key.Home.WithCtrl));
  4178. Assert.Equal (Point.Empty, tv.CursorPosition);
  4179. Assert.True (tv.NewKeyDownEvent (Key.N.WithCtrl));
  4180. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  4181. Assert.Equal (0, tv.SelectedLength);
  4182. Assert.Equal ("", tv.SelectedText);
  4183. Assert.True (tv.NewKeyDownEvent (Key.P.WithCtrl));
  4184. Assert.Equal (Point.Empty, tv.CursorPosition);
  4185. Assert.Equal (0, tv.SelectedLength);
  4186. Assert.Equal ("", tv.SelectedText);
  4187. Assert.True (tv.NewKeyDownEvent (Key.CursorDown));
  4188. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  4189. Assert.Equal (0, tv.SelectedLength);
  4190. Assert.Equal ("", tv.SelectedText);
  4191. Assert.True (tv.NewKeyDownEvent (Key.CursorUp));
  4192. Assert.Equal (Point.Empty, tv.CursorPosition);
  4193. Assert.Equal (0, tv.SelectedLength);
  4194. Assert.Equal ("", tv.SelectedText);
  4195. Assert.True (tv.NewKeyDownEvent (Key.CursorDown.WithShift));
  4196. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  4197. Assert.Equal (23 + Environment.NewLine.Length, tv.SelectedLength);
  4198. Assert.Equal ($"This is the first line.{Environment.NewLine}", tv.SelectedText);
  4199. Assert.True (tv.NewKeyDownEvent (Key.CursorUp.WithShift));
  4200. Assert.Equal (Point.Empty, tv.CursorPosition);
  4201. Assert.Equal (0, tv.SelectedLength);
  4202. Assert.Equal ("", tv.SelectedText);
  4203. Assert.True (tv.NewKeyDownEvent (Key.F.WithCtrl));
  4204. Assert.Equal (new Point (1, 0), tv.CursorPosition);
  4205. Assert.Equal (0, tv.SelectedLength);
  4206. Assert.Equal ("", tv.SelectedText);
  4207. Assert.True (tv.NewKeyDownEvent (Key.B.WithCtrl));
  4208. Assert.Equal (Point.Empty, tv.CursorPosition);
  4209. Assert.Equal (0, tv.SelectedLength);
  4210. Assert.Equal ("", tv.SelectedText);
  4211. Assert.True (tv.NewKeyDownEvent (Key.CursorRight));
  4212. Assert.Equal (new Point (1, 0), tv.CursorPosition);
  4213. Assert.Equal (0, tv.SelectedLength);
  4214. Assert.Equal ("", tv.SelectedText);
  4215. Assert.True (tv.NewKeyDownEvent (Key.CursorLeft));
  4216. Assert.Equal (Point.Empty, tv.CursorPosition);
  4217. Assert.Equal (0, tv.SelectedLength);
  4218. Assert.Equal ("", tv.SelectedText);
  4219. Assert.False (tv.IsSelecting);
  4220. Assert.True (tv.NewKeyDownEvent (Key.CursorRight.WithShift));
  4221. Assert.Equal (new Point (1, 0), tv.CursorPosition);
  4222. Assert.Equal (1, tv.SelectedLength);
  4223. Assert.Equal ("T", tv.SelectedText);
  4224. Assert.True (tv.IsSelecting);
  4225. Assert.True (tv.NewKeyDownEvent (Key.CursorLeft.WithShift));
  4226. Assert.Equal (Point.Empty, tv.CursorPosition);
  4227. Assert.Equal (0, tv.SelectedLength);
  4228. Assert.Equal ("", tv.SelectedText);
  4229. Assert.True (tv.IsSelecting);
  4230. Assert.True (tv.NewKeyDownEvent (Key.Delete));
  4231. Assert.Equal (
  4232. $"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first",
  4233. tv.Text
  4234. );
  4235. Assert.Equal (Point.Empty, tv.CursorPosition);
  4236. Assert.Equal (0, tv.SelectedLength);
  4237. Assert.Equal ("", tv.SelectedText);
  4238. Assert.False (tv.IsSelecting);
  4239. Assert.True (tv.NewKeyDownEvent (Key.Delete));
  4240. Assert.Equal (
  4241. $"his is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first",
  4242. tv.Text
  4243. );
  4244. Assert.Equal (Point.Empty, tv.CursorPosition);
  4245. Assert.Equal (0, tv.SelectedLength);
  4246. Assert.Equal ("", tv.SelectedText);
  4247. Assert.False (tv.IsSelecting);
  4248. Assert.True (tv.NewKeyDownEvent (Key.D.WithCtrl));
  4249. Assert.Equal (
  4250. $"is is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first",
  4251. tv.Text
  4252. );
  4253. Assert.Equal (Point.Empty, tv.CursorPosition);
  4254. Assert.True (tv.NewKeyDownEvent (Key.End));
  4255. Assert.Equal (
  4256. $"is is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first",
  4257. tv.Text
  4258. );
  4259. Assert.Equal (new Point (21, 0), tv.CursorPosition);
  4260. Assert.True (tv.NewKeyDownEvent (Key.Backspace));
  4261. Assert.Equal (
  4262. $"is is the first line{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first",
  4263. tv.Text
  4264. );
  4265. Assert.Equal (new Point (20, 0), tv.CursorPosition);
  4266. Assert.True (tv.NewKeyDownEvent (Key.Backspace));
  4267. Assert.Equal (
  4268. $"is is the first lin{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first",
  4269. tv.Text
  4270. );
  4271. Assert.Equal (new Point (19, 0), tv.CursorPosition);
  4272. Assert.True (tv.NewKeyDownEvent (Key.Home));
  4273. Assert.Equal (Point.Empty, tv.CursorPosition);
  4274. Assert.Equal (0, tv.SelectedLength);
  4275. Assert.Equal ("", tv.SelectedText);
  4276. Assert.False (tv.IsSelecting);
  4277. Assert.True (tv.NewKeyDownEvent (Key.End.WithShift));
  4278. Assert.Equal (new Point (19, 0), tv.CursorPosition);
  4279. Assert.Equal (19, tv.SelectedLength);
  4280. Assert.Equal ("is is the first lin", tv.SelectedText);
  4281. Assert.True (tv.IsSelecting);
  4282. Assert.True (tv.NewKeyDownEvent (Key.Home.WithShift));
  4283. Assert.Equal (Point.Empty, tv.CursorPosition);
  4284. Assert.Equal (0, tv.SelectedLength);
  4285. Assert.Equal ("", tv.SelectedText);
  4286. Assert.True (tv.IsSelecting);
  4287. Assert.True (tv.NewKeyDownEvent (Key.E.WithCtrl));
  4288. Assert.Equal (new Point (19, 0), tv.CursorPosition);
  4289. Assert.Equal (0, tv.SelectedLength);
  4290. Assert.Equal ("", tv.SelectedText);
  4291. Assert.False (tv.IsSelecting);
  4292. Assert.True (tv.NewKeyDownEvent (Key.Home));
  4293. Assert.Equal (Point.Empty, tv.CursorPosition);
  4294. Assert.Equal (0, tv.SelectedLength);
  4295. Assert.Equal ("", tv.SelectedText);
  4296. Assert.False (tv.IsSelecting);
  4297. Assert.True (tv.NewKeyDownEvent (Key.K.WithCtrl));
  4298. Assert.Equal (
  4299. $"{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first",
  4300. tv.Text
  4301. );
  4302. Assert.Equal (Point.Empty, tv.CursorPosition);
  4303. Assert.Equal (0, tv.SelectedLength);
  4304. Assert.Equal ("", tv.SelectedText);
  4305. Assert.False (tv.IsSelecting);
  4306. Assert.Equal ("is is the first lin", Clipboard.Contents);
  4307. Assert.True (tv.NewKeyDownEvent (Key.Y.WithCtrl));
  4308. Assert.Equal (
  4309. $"is is the first lin{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first",
  4310. tv.Text
  4311. );
  4312. Assert.Equal (new Point (19, 0), tv.CursorPosition);
  4313. Assert.Equal (0, tv.SelectedLength);
  4314. Assert.Equal ("", tv.SelectedText);
  4315. Assert.False (tv.IsSelecting);
  4316. Assert.Equal ("is is the first lin", Clipboard.Contents);
  4317. tv.CursorPosition = Point.Empty;
  4318. Assert.True (tv.NewKeyDownEvent (Key.Delete.WithCtrl.WithShift));
  4319. Assert.Equal (
  4320. $"{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first",
  4321. tv.Text
  4322. );
  4323. Assert.Equal (Point.Empty, tv.CursorPosition);
  4324. Assert.Equal (0, tv.SelectedLength);
  4325. Assert.Equal ("", tv.SelectedText);
  4326. Assert.False (tv.IsSelecting);
  4327. Assert.Equal ("is is the first lin", Clipboard.Contents);
  4328. Assert.True (tv.NewKeyDownEvent (Key.Y.WithCtrl));
  4329. Assert.Equal (
  4330. $"is is the first lin{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first",
  4331. tv.Text
  4332. );
  4333. Assert.Equal (new Point (19, 0), tv.CursorPosition);
  4334. Assert.Equal (0, tv.SelectedLength);
  4335. Assert.Equal ("", tv.SelectedText);
  4336. Assert.False (tv.IsSelecting);
  4337. Assert.Equal ("is is the first lin", Clipboard.Contents);
  4338. Assert.True (tv.NewKeyDownEvent (Key.Backspace.WithCtrl.WithShift));
  4339. Assert.Equal (
  4340. $"{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first",
  4341. tv.Text
  4342. );
  4343. Assert.Equal (Point.Empty, tv.CursorPosition);
  4344. Assert.Equal (0, tv.SelectedLength);
  4345. Assert.Equal ("", tv.SelectedText);
  4346. Assert.False (tv.IsSelecting);
  4347. tv.ReadOnly = true;
  4348. Assert.True (tv.NewKeyDownEvent (Key.Y.WithCtrl));
  4349. Assert.Equal (
  4350. $"{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first",
  4351. tv.Text
  4352. );
  4353. Assert.Equal (Point.Empty, tv.CursorPosition);
  4354. Assert.Equal (0, tv.SelectedLength);
  4355. Assert.Equal ("", tv.SelectedText);
  4356. Assert.False (tv.IsSelecting);
  4357. tv.ReadOnly = false;
  4358. Assert.True (tv.NewKeyDownEvent (Key.Y.WithCtrl));
  4359. Assert.Equal (
  4360. $"is is the first lin{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first",
  4361. tv.Text
  4362. );
  4363. Assert.Equal (new Point (19, 0), tv.CursorPosition);
  4364. Assert.Equal (0, tv.SelectedLength);
  4365. Assert.Equal ("", tv.SelectedText);
  4366. Assert.False (tv.IsSelecting);
  4367. Assert.Equal (0, tv.SelectionStartColumn);
  4368. Assert.Equal (0, tv.SelectionStartRow);
  4369. Assert.True (tv.NewKeyDownEvent (Key.Space.WithCtrl));
  4370. Assert.Equal (
  4371. $"is is the first lin{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first",
  4372. tv.Text
  4373. );
  4374. Assert.Equal (new Point (19, 0), tv.CursorPosition);
  4375. Assert.Equal (0, tv.SelectedLength);
  4376. Assert.Equal ("", tv.SelectedText);
  4377. Assert.True (tv.IsSelecting);
  4378. Assert.Equal (19, tv.SelectionStartColumn);
  4379. Assert.Equal (0, tv.SelectionStartRow);
  4380. Assert.True (tv.NewKeyDownEvent (Key.Space.WithCtrl));
  4381. Assert.Equal (
  4382. $"is is the first lin{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first",
  4383. tv.Text
  4384. );
  4385. Assert.Equal (new Point (19, 0), tv.CursorPosition);
  4386. Assert.Equal (0, tv.SelectedLength);
  4387. Assert.Equal ("", tv.SelectedText);
  4388. Assert.False (tv.IsSelecting);
  4389. Assert.Equal (19, tv.SelectionStartColumn);
  4390. Assert.Equal (0, tv.SelectionStartRow);
  4391. tv.SelectionStartColumn = 0;
  4392. Assert.True (tv.NewKeyDownEvent (Key.C.WithCtrl));
  4393. Assert.Equal (
  4394. $"is is the first lin{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first",
  4395. tv.Text
  4396. );
  4397. Assert.Equal (new Point (19, 0), tv.CursorPosition);
  4398. Assert.Equal (19, tv.SelectedLength);
  4399. Assert.Equal ("is is the first lin", tv.SelectedText);
  4400. Assert.True (tv.IsSelecting);
  4401. Assert.Equal (0, tv.SelectionStartColumn);
  4402. Assert.Equal (0, tv.SelectionStartRow);
  4403. Assert.True (tv.NewKeyDownEvent (Key.C.WithCtrl));
  4404. Assert.Equal (
  4405. $"is is the first lin{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first",
  4406. tv.Text
  4407. );
  4408. Assert.Equal (new Point (19, 0), tv.CursorPosition);
  4409. Assert.Equal (19, tv.SelectedLength);
  4410. Assert.Equal ("is is the first lin", tv.SelectedText);
  4411. Assert.True (tv.IsSelecting);
  4412. Assert.Equal (0, tv.SelectionStartColumn);
  4413. Assert.Equal (0, tv.SelectionStartRow);
  4414. Assert.True (tv.NewKeyDownEvent (Key.X.WithCtrl));
  4415. Assert.Equal (
  4416. $"{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first",
  4417. tv.Text
  4418. );
  4419. Assert.Equal (Point.Empty, tv.CursorPosition);
  4420. Assert.Equal (0, tv.SelectedLength);
  4421. Assert.Equal ("", tv.SelectedText);
  4422. Assert.False (tv.IsSelecting);
  4423. Assert.Equal (0, tv.SelectionStartColumn);
  4424. Assert.Equal (0, tv.SelectionStartRow);
  4425. Assert.Equal ("is is the first lin", Clipboard.Contents);
  4426. Assert.True (tv.NewKeyDownEvent (Key.W.WithCtrl));
  4427. Assert.Equal (
  4428. $"{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first",
  4429. tv.Text
  4430. );
  4431. Assert.Equal (Point.Empty, tv.CursorPosition);
  4432. Assert.Equal (0, tv.SelectedLength);
  4433. Assert.Equal ("", tv.SelectedText);
  4434. Assert.False (tv.IsSelecting);
  4435. Assert.Equal (0, tv.SelectionStartColumn);
  4436. Assert.Equal (0, tv.SelectionStartRow);
  4437. Assert.Equal ("", Clipboard.Contents);
  4438. Assert.True (tv.NewKeyDownEvent (Key.X.WithCtrl));
  4439. Assert.Equal (
  4440. $"{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first",
  4441. tv.Text
  4442. );
  4443. Assert.Equal (Point.Empty, tv.CursorPosition);
  4444. Assert.Equal (0, tv.SelectedLength);
  4445. Assert.Equal ("", tv.SelectedText);
  4446. Assert.False (tv.IsSelecting);
  4447. Assert.Equal (0, tv.SelectionStartColumn);
  4448. Assert.Equal (0, tv.SelectionStartRow);
  4449. Assert.Equal ("", Clipboard.Contents);
  4450. Assert.True (tv.NewKeyDownEvent (Key.End.WithCtrl));
  4451. Assert.Equal (
  4452. $"{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first",
  4453. tv.Text
  4454. );
  4455. Assert.Equal (new Point (28, 2), tv.CursorPosition);
  4456. Assert.Equal (0, tv.SelectedLength);
  4457. Assert.Equal ("", tv.SelectedText);
  4458. Assert.False (tv.IsSelecting);
  4459. Assert.True (tv.NewKeyDownEvent (Key.CursorLeft.WithCtrl));
  4460. Assert.Equal (
  4461. $"{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first",
  4462. tv.Text
  4463. );
  4464. Assert.Equal (new Point (18, 2), tv.CursorPosition);
  4465. Assert.Equal (0, tv.SelectedLength);
  4466. Assert.Equal ("", tv.SelectedText);
  4467. Assert.False (tv.IsSelecting);
  4468. Assert.True (tv.NewKeyDownEvent (Key.CursorLeft.WithShift.WithCtrl));
  4469. Assert.Equal (
  4470. $"{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first",
  4471. tv.Text
  4472. );
  4473. Assert.Equal (new Point (12, 2), tv.CursorPosition);
  4474. Assert.Equal (6, tv.SelectedLength);
  4475. Assert.Equal ("third ", tv.SelectedText);
  4476. Assert.True (tv.IsSelecting);
  4477. Assert.True (tv.NewKeyDownEvent (Key.CursorLeft.WithCtrl));
  4478. Assert.Equal (
  4479. $"{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first",
  4480. tv.Text
  4481. );
  4482. Assert.Equal (new Point (8, 2), tv.CursorPosition);
  4483. Assert.Equal (0, tv.SelectedLength);
  4484. Assert.Equal ("", tv.SelectedText);
  4485. Assert.False (tv.IsSelecting);
  4486. Assert.True (tv.NewKeyDownEvent (Key.CursorRight.WithCtrl));
  4487. Assert.Equal (
  4488. $"{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first",
  4489. tv.Text
  4490. );
  4491. Assert.Equal (new Point (12, 2), tv.CursorPosition);
  4492. Assert.Equal (0, tv.SelectedLength);
  4493. Assert.Equal ("", tv.SelectedText);
  4494. Assert.False (tv.IsSelecting);
  4495. Assert.True (tv.NewKeyDownEvent (Key.CursorRight.WithShift.WithCtrl));
  4496. Assert.Equal (
  4497. $"{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first",
  4498. tv.Text
  4499. );
  4500. Assert.Equal (new Point (18, 2), tv.CursorPosition);
  4501. Assert.Equal (6, tv.SelectedLength);
  4502. Assert.Equal ("third ", tv.SelectedText);
  4503. Assert.True (tv.IsSelecting);
  4504. Assert.True (tv.NewKeyDownEvent (Key.CursorRight.WithCtrl));
  4505. Assert.Equal (
  4506. $"{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first",
  4507. tv.Text
  4508. );
  4509. Assert.Equal (new Point (22, 2), tv.CursorPosition);
  4510. Assert.Equal (0, tv.SelectedLength);
  4511. Assert.Equal ("", tv.SelectedText);
  4512. Assert.False (tv.IsSelecting);
  4513. Assert.True (tv.NewKeyDownEvent (Key.CursorRight.WithCtrl));
  4514. Assert.Equal (
  4515. $"{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first",
  4516. tv.Text
  4517. );
  4518. Assert.Equal (new Point (23, 2), tv.CursorPosition);
  4519. Assert.Equal (0, tv.SelectedLength);
  4520. Assert.Equal ("", tv.SelectedText);
  4521. Assert.False (tv.IsSelecting);
  4522. Assert.True (tv.NewKeyDownEvent (Key.CursorRight.WithCtrl));
  4523. Assert.Equal (
  4524. $"{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first",
  4525. tv.Text
  4526. );
  4527. Assert.Equal (new Point (28, 2), tv.CursorPosition);
  4528. Assert.Equal (0, tv.SelectedLength);
  4529. Assert.Equal ("", tv.SelectedText);
  4530. Assert.False (tv.IsSelecting);
  4531. Assert.True (tv.NewKeyDownEvent (Key.Home.WithCtrl));
  4532. Assert.Equal (
  4533. $"{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first",
  4534. tv.Text
  4535. );
  4536. Assert.Equal (Point.Empty, tv.CursorPosition);
  4537. Assert.Equal (0, tv.SelectedLength);
  4538. Assert.Equal ("", tv.SelectedText);
  4539. Assert.False (tv.IsSelecting);
  4540. Assert.True (tv.NewKeyDownEvent (Key.Delete.WithCtrl));
  4541. Assert.Equal ($"This is the second line.{Environment.NewLine}This is the third line.first", tv.Text);
  4542. Assert.Equal (Point.Empty, tv.CursorPosition);
  4543. Assert.Equal (0, tv.SelectedLength);
  4544. Assert.Equal ("", tv.SelectedText);
  4545. Assert.False (tv.IsSelecting);
  4546. Assert.True (tv.NewKeyDownEvent (Key.End.WithCtrl));
  4547. Assert.Equal ($"This is the second line.{Environment.NewLine}This is the third line.first", tv.Text);
  4548. Assert.Equal (new Point (28, 1), tv.CursorPosition);
  4549. Assert.Equal (0, tv.SelectedLength);
  4550. Assert.Equal ("", tv.SelectedText);
  4551. Assert.False (tv.IsSelecting);
  4552. Assert.False (tv.IsSelecting);
  4553. Assert.True (tv.NewKeyDownEvent (Key.Backspace.WithCtrl));
  4554. Assert.Equal ($"This is the second line.{Environment.NewLine}This is the third ", tv.Text);
  4555. Assert.Equal (new Point (18, 1), tv.CursorPosition);
  4556. Assert.Equal (0, tv.SelectedLength);
  4557. Assert.Equal ("", tv.SelectedText);
  4558. Assert.False (tv.IsSelecting);
  4559. Assert.True (tv.AllowsReturn);
  4560. tv.AllowsReturn = false;
  4561. Assert.Equal (Point.Empty, tv.CursorPosition);
  4562. Assert.False (tv.IsSelecting);
  4563. Assert.False (tv.NewKeyDownEvent (Key.Enter)); // Accepted event not handled
  4564. Assert.Equal ($"This is the second line.{Environment.NewLine}This is the third ", tv.Text);
  4565. Assert.Equal (Point.Empty, tv.CursorPosition);
  4566. Assert.Equal (0, tv.SelectedLength);
  4567. Assert.Equal ("", tv.SelectedText);
  4568. Assert.False (tv.IsSelecting);
  4569. Assert.False (tv.AllowsReturn);
  4570. tv.AllowsReturn = true;
  4571. Assert.Equal (Point.Empty, tv.CursorPosition);
  4572. Assert.True (tv.NewKeyDownEvent (Key.Enter));
  4573. Assert.Equal (
  4574. $"{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third ",
  4575. tv.Text
  4576. );
  4577. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  4578. Assert.Equal (0, tv.SelectedLength);
  4579. Assert.Equal ("", tv.SelectedText);
  4580. Assert.False (tv.IsSelecting);
  4581. Assert.True (tv.AllowsReturn);
  4582. Assert.True (tv.NewKeyDownEvent (Key.End.WithShift.WithCtrl));
  4583. Assert.Equal (
  4584. $"{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third ",
  4585. tv.Text
  4586. );
  4587. Assert.Equal (new Point (18, 2), tv.CursorPosition);
  4588. Assert.Equal (42 + Environment.NewLine.Length, tv.SelectedLength);
  4589. Assert.Equal ($"This is the second line.{Environment.NewLine}This is the third ", tv.SelectedText);
  4590. Assert.True (tv.IsSelecting);
  4591. Assert.True (tv.NewKeyDownEvent (Key.Home.WithShift.WithCtrl));
  4592. Assert.Equal (
  4593. $"{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third ",
  4594. tv.Text
  4595. );
  4596. Assert.Equal (Point.Empty, tv.CursorPosition);
  4597. Assert.Equal (Environment.NewLine.Length, tv.SelectedLength);
  4598. Assert.Equal ($"{Environment.NewLine}", tv.SelectedText);
  4599. Assert.True (tv.IsSelecting);
  4600. Assert.True (tv.NewKeyDownEvent (Key.A.WithCtrl));
  4601. Assert.Equal (
  4602. $"{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third ",
  4603. tv.Text
  4604. );
  4605. Assert.Equal (new Point (18, 2), tv.CursorPosition);
  4606. Assert.Equal (42 + Environment.NewLine.Length * 2, tv.SelectedLength);
  4607. Assert.Equal (
  4608. $"{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third ",
  4609. tv.SelectedText
  4610. );
  4611. Assert.True (tv.IsSelecting);
  4612. Assert.True (tv.Used);
  4613. Assert.True (tv.NewKeyDownEvent (Key.InsertChar));
  4614. Assert.False (tv.Used);
  4615. Assert.True (tv.AllowsTab);
  4616. Assert.Equal (new Point (18, 2), tv.CursorPosition);
  4617. tv.AllowsTab = false;
  4618. Assert.False (tv.NewKeyDownEvent (Key.Tab));
  4619. Assert.Equal (
  4620. $"{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third ",
  4621. tv.Text
  4622. );
  4623. Assert.False (tv.AllowsTab);
  4624. tv.AllowsTab = true;
  4625. Assert.Equal (new Point (18, 2), tv.CursorPosition);
  4626. Assert.True (tv.IsSelecting);
  4627. tv.IsSelecting = false;
  4628. Assert.True (tv.NewKeyDownEvent (Key.Tab));
  4629. Assert.Equal (
  4630. $"{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third \t",
  4631. tv.Text
  4632. );
  4633. Assert.True (tv.AllowsTab);
  4634. tv.AllowsTab = false;
  4635. Assert.False (tv.NewKeyDownEvent (Key.Tab.WithShift));
  4636. Assert.Equal (
  4637. $"{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third \t",
  4638. tv.Text
  4639. );
  4640. Assert.False (tv.AllowsTab);
  4641. tv.AllowsTab = true;
  4642. Assert.True (tv.NewKeyDownEvent (Key.Tab.WithShift));
  4643. Assert.Equal (
  4644. $"{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third ",
  4645. tv.Text
  4646. );
  4647. Assert.True (tv.AllowsTab);
  4648. Assert.False (tv.NewKeyDownEvent (Key.F6));
  4649. Assert.False (tv.NewKeyDownEvent (Application.NextTabGroupKey));
  4650. Assert.False (tv.NewKeyDownEvent (Key.F6.WithShift));
  4651. Assert.False (tv.NewKeyDownEvent (Application.PrevTabGroupKey));
  4652. Assert.True (tv.NewKeyDownEvent (ContextMenu.DefaultKey));
  4653. Assert.True (tv.ContextMenu != null && tv.ContextMenu.MenuBar.Visible);
  4654. top.Dispose ();
  4655. }
  4656. [Fact]
  4657. [TextViewTestsAutoInitShutdown]
  4658. public void Kill_Delete_WordBackward ()
  4659. {
  4660. _textView.Text = "This is the first line.";
  4661. _textView.MoveEnd ();
  4662. var iteration = 0;
  4663. var iterationsFinished = false;
  4664. while (!iterationsFinished)
  4665. {
  4666. _textView.NewKeyDownEvent (Key.Backspace.WithCtrl);
  4667. switch (iteration)
  4668. {
  4669. case 0:
  4670. Assert.Equal (22, _textView.CursorPosition.X);
  4671. Assert.Equal (0, _textView.CursorPosition.Y);
  4672. Assert.Equal ("This is the first line", _textView.Text);
  4673. break;
  4674. case 1:
  4675. Assert.Equal (18, _textView.CursorPosition.X);
  4676. Assert.Equal (0, _textView.CursorPosition.Y);
  4677. Assert.Equal ("This is the first ", _textView.Text);
  4678. break;
  4679. case 2:
  4680. Assert.Equal (12, _textView.CursorPosition.X);
  4681. Assert.Equal (0, _textView.CursorPosition.Y);
  4682. Assert.Equal ("This is the ", _textView.Text);
  4683. break;
  4684. case 3:
  4685. Assert.Equal (8, _textView.CursorPosition.X);
  4686. Assert.Equal (0, _textView.CursorPosition.Y);
  4687. Assert.Equal ("This is ", _textView.Text);
  4688. break;
  4689. case 4:
  4690. Assert.Equal (5, _textView.CursorPosition.X);
  4691. Assert.Equal (0, _textView.CursorPosition.Y);
  4692. Assert.Equal ("This ", _textView.Text);
  4693. break;
  4694. case 5:
  4695. Assert.Equal (0, _textView.CursorPosition.X);
  4696. Assert.Equal (0, _textView.CursorPosition.Y);
  4697. Assert.Equal ("", _textView.Text);
  4698. break;
  4699. default:
  4700. iterationsFinished = true;
  4701. break;
  4702. }
  4703. iteration++;
  4704. }
  4705. }
  4706. [Fact]
  4707. [TextViewTestsAutoInitShutdown]
  4708. public void Kill_Delete_WordBackward_Multiline ()
  4709. {
  4710. _textView.Text = "This is the first line.\nThis is the second line.";
  4711. _textView.Width = 4;
  4712. _textView.MoveEnd ();
  4713. var iteration = 0;
  4714. var iterationsFinished = false;
  4715. while (!iterationsFinished)
  4716. {
  4717. _textView.NewKeyDownEvent (Key.Backspace.WithCtrl);
  4718. switch (iteration)
  4719. {
  4720. case 0:
  4721. Assert.Equal (23, _textView.CursorPosition.X);
  4722. Assert.Equal (1, _textView.CursorPosition.Y);
  4723. Assert.Equal (
  4724. "This is the first line."
  4725. + Environment.NewLine
  4726. + "This is the second line",
  4727. _textView.Text
  4728. );
  4729. break;
  4730. case 1:
  4731. Assert.Equal (19, _textView.CursorPosition.X);
  4732. Assert.Equal (1, _textView.CursorPosition.Y);
  4733. Assert.Equal (
  4734. "This is the first line."
  4735. + Environment.NewLine
  4736. + "This is the second ",
  4737. _textView.Text
  4738. );
  4739. break;
  4740. case 2:
  4741. Assert.Equal (12, _textView.CursorPosition.X);
  4742. Assert.Equal (1, _textView.CursorPosition.Y);
  4743. Assert.Equal (
  4744. "This is the first line."
  4745. + Environment.NewLine
  4746. + "This is the ",
  4747. _textView.Text
  4748. );
  4749. break;
  4750. case 3:
  4751. Assert.Equal (8, _textView.CursorPosition.X);
  4752. Assert.Equal (1, _textView.CursorPosition.Y);
  4753. Assert.Equal (
  4754. "This is the first line."
  4755. + Environment.NewLine
  4756. + "This is ",
  4757. _textView.Text
  4758. );
  4759. break;
  4760. case 4:
  4761. Assert.Equal (5, _textView.CursorPosition.X);
  4762. Assert.Equal (1, _textView.CursorPosition.Y);
  4763. Assert.Equal (
  4764. "This is the first line."
  4765. + Environment.NewLine
  4766. + "This ",
  4767. _textView.Text
  4768. );
  4769. break;
  4770. case 5:
  4771. Assert.Equal (0, _textView.CursorPosition.X);
  4772. Assert.Equal (1, _textView.CursorPosition.Y);
  4773. Assert.Equal ("This is the first line." + Environment.NewLine, _textView.Text);
  4774. break;
  4775. case 6:
  4776. Assert.Equal (23, _textView.CursorPosition.X);
  4777. Assert.Equal (0, _textView.CursorPosition.Y);
  4778. Assert.Equal ("This is the first line.", _textView.Text);
  4779. break;
  4780. case 7:
  4781. Assert.Equal (22, _textView.CursorPosition.X);
  4782. Assert.Equal (0, _textView.CursorPosition.Y);
  4783. Assert.Equal ("This is the first line", _textView.Text);
  4784. break;
  4785. case 8:
  4786. Assert.Equal (18, _textView.CursorPosition.X);
  4787. Assert.Equal (0, _textView.CursorPosition.Y);
  4788. Assert.Equal ("This is the first ", _textView.Text);
  4789. break;
  4790. case 9:
  4791. Assert.Equal (12, _textView.CursorPosition.X);
  4792. Assert.Equal (0, _textView.CursorPosition.Y);
  4793. Assert.Equal ("This is the ", _textView.Text);
  4794. break;
  4795. case 10:
  4796. Assert.Equal (8, _textView.CursorPosition.X);
  4797. Assert.Equal (0, _textView.CursorPosition.Y);
  4798. Assert.Equal ("This is ", _textView.Text);
  4799. break;
  4800. case 11:
  4801. Assert.Equal (5, _textView.CursorPosition.X);
  4802. Assert.Equal (0, _textView.CursorPosition.Y);
  4803. Assert.Equal ("This ", _textView.Text);
  4804. break;
  4805. case 12:
  4806. Assert.Equal (0, _textView.CursorPosition.X);
  4807. Assert.Equal (0, _textView.CursorPosition.Y);
  4808. Assert.Equal ("", _textView.Text);
  4809. break;
  4810. default:
  4811. iterationsFinished = true;
  4812. break;
  4813. }
  4814. iteration++;
  4815. }
  4816. }
  4817. [Fact]
  4818. [TextViewTestsAutoInitShutdown]
  4819. public void Kill_Delete_WordForward ()
  4820. {
  4821. _textView.Text = "This is the first line.";
  4822. var iteration = 0;
  4823. var iterationsFinished = false;
  4824. while (!iterationsFinished)
  4825. {
  4826. _textView.NewKeyDownEvent (Key.Delete.WithCtrl);
  4827. switch (iteration)
  4828. {
  4829. case 0:
  4830. Assert.Equal (0, _textView.CursorPosition.X);
  4831. Assert.Equal (0, _textView.CursorPosition.Y);
  4832. Assert.Equal ("is the first line.", _textView.Text);
  4833. break;
  4834. case 1:
  4835. Assert.Equal (0, _textView.CursorPosition.X);
  4836. Assert.Equal (0, _textView.CursorPosition.Y);
  4837. Assert.Equal ("the first line.", _textView.Text);
  4838. break;
  4839. case 2:
  4840. Assert.Equal (0, _textView.CursorPosition.X);
  4841. Assert.Equal (0, _textView.CursorPosition.Y);
  4842. Assert.Equal ("first line.", _textView.Text);
  4843. break;
  4844. case 3:
  4845. Assert.Equal (0, _textView.CursorPosition.X);
  4846. Assert.Equal (0, _textView.CursorPosition.Y);
  4847. Assert.Equal ("line.", _textView.Text);
  4848. break;
  4849. case 4:
  4850. Assert.Equal (0, _textView.CursorPosition.X);
  4851. Assert.Equal (0, _textView.CursorPosition.Y);
  4852. Assert.Equal ("", _textView.Text);
  4853. break;
  4854. default:
  4855. iterationsFinished = true;
  4856. break;
  4857. }
  4858. iteration++;
  4859. }
  4860. }
  4861. [Fact]
  4862. [TextViewTestsAutoInitShutdown]
  4863. public void Kill_Delete_WordForward_Multiline ()
  4864. {
  4865. _textView.Text = "This is the first line.\nThis is the second line.";
  4866. _textView.Width = 4;
  4867. var iteration = 0;
  4868. var iterationsFinished = false;
  4869. while (!iterationsFinished)
  4870. {
  4871. _textView.NewKeyDownEvent (Key.Delete.WithCtrl);
  4872. switch (iteration)
  4873. {
  4874. case 0:
  4875. Assert.Equal (0, _textView.CursorPosition.X);
  4876. Assert.Equal (0, _textView.CursorPosition.Y);
  4877. Assert.Equal (
  4878. "is the first line."
  4879. + Environment.NewLine
  4880. + "This is the second line.",
  4881. _textView.Text
  4882. );
  4883. break;
  4884. case 1:
  4885. Assert.Equal (0, _textView.CursorPosition.X);
  4886. Assert.Equal (0, _textView.CursorPosition.Y);
  4887. Assert.Equal (
  4888. "the first line."
  4889. + Environment.NewLine
  4890. + "This is the second line.",
  4891. _textView.Text
  4892. );
  4893. break;
  4894. case 2:
  4895. Assert.Equal (0, _textView.CursorPosition.X);
  4896. Assert.Equal (0, _textView.CursorPosition.Y);
  4897. Assert.Equal (
  4898. "first line."
  4899. + Environment.NewLine
  4900. + "This is the second line.",
  4901. _textView.Text
  4902. );
  4903. break;
  4904. case 3:
  4905. Assert.Equal (0, _textView.CursorPosition.X);
  4906. Assert.Equal (0, _textView.CursorPosition.Y);
  4907. Assert.Equal (
  4908. "line."
  4909. + Environment.NewLine
  4910. + "This is the second line.",
  4911. _textView.Text
  4912. );
  4913. break;
  4914. case 4:
  4915. Assert.Equal (0, _textView.CursorPosition.X);
  4916. Assert.Equal (0, _textView.CursorPosition.Y);
  4917. Assert.Equal (
  4918. ""
  4919. + Environment.NewLine
  4920. + "This is the second line.",
  4921. _textView.Text
  4922. );
  4923. break;
  4924. case 5:
  4925. Assert.Equal (0, _textView.CursorPosition.X);
  4926. Assert.Equal (0, _textView.CursorPosition.Y);
  4927. Assert.Equal ("This is the second line.", _textView.Text);
  4928. break;
  4929. case 6:
  4930. Assert.Equal (0, _textView.CursorPosition.X);
  4931. Assert.Equal (0, _textView.CursorPosition.Y);
  4932. Assert.Equal ("is the second line.", _textView.Text);
  4933. break;
  4934. case 7:
  4935. Assert.Equal (0, _textView.CursorPosition.X);
  4936. Assert.Equal (0, _textView.CursorPosition.Y);
  4937. Assert.Equal ("the second line.", _textView.Text);
  4938. break;
  4939. case 8:
  4940. Assert.Equal (0, _textView.CursorPosition.X);
  4941. Assert.Equal (0, _textView.CursorPosition.Y);
  4942. Assert.Equal ("second line.", _textView.Text);
  4943. break;
  4944. case 9:
  4945. Assert.Equal (0, _textView.CursorPosition.X);
  4946. Assert.Equal (0, _textView.CursorPosition.Y);
  4947. Assert.Equal ("line.", _textView.Text);
  4948. break;
  4949. case 10:
  4950. Assert.Equal (0, _textView.CursorPosition.X);
  4951. Assert.Equal (0, _textView.CursorPosition.Y);
  4952. Assert.Equal ("", _textView.Text);
  4953. break;
  4954. default:
  4955. iterationsFinished = true;
  4956. break;
  4957. }
  4958. iteration++;
  4959. }
  4960. }
  4961. [Fact]
  4962. [TextViewTestsAutoInitShutdown]
  4963. public void Kill_To_End_Delete_Forwards_Copy_To_The_Clipboard_And_Paste ()
  4964. {
  4965. _textView.Text = "This is the first line.\nThis is the second line.";
  4966. var iteration = 0;
  4967. var iterationsFinished = false;
  4968. while (!iterationsFinished)
  4969. {
  4970. switch (iteration)
  4971. {
  4972. case 0:
  4973. _textView.NewKeyDownEvent (Key.K.WithCtrl);
  4974. Assert.Equal (0, _textView.CursorPosition.X);
  4975. Assert.Equal (0, _textView.CursorPosition.Y);
  4976. Assert.Equal ($"{Environment.NewLine}This is the second line.", _textView.Text);
  4977. Assert.Equal ("This is the first line.", Clipboard.Contents);
  4978. break;
  4979. case 1:
  4980. _textView.NewKeyDownEvent (
  4981. new Key (
  4982. KeyCode.Delete | KeyCode.CtrlMask | KeyCode.ShiftMask
  4983. )
  4984. );
  4985. Assert.Equal (0, _textView.CursorPosition.X);
  4986. Assert.Equal (0, _textView.CursorPosition.Y);
  4987. Assert.Equal ("This is the second line.", _textView.Text);
  4988. Assert.Equal ($"This is the first line.{Environment.NewLine}", Clipboard.Contents);
  4989. break;
  4990. case 2:
  4991. _textView.NewKeyDownEvent (Key.K.WithCtrl);
  4992. Assert.Equal (0, _textView.CursorPosition.X);
  4993. Assert.Equal (0, _textView.CursorPosition.Y);
  4994. Assert.Equal ("", _textView.Text);
  4995. Assert.Equal (
  4996. $"This is the first line.{Environment.NewLine}This is the second line.",
  4997. Clipboard.Contents
  4998. );
  4999. // Paste
  5000. _textView.NewKeyDownEvent (Key.Y.WithCtrl);
  5001. Assert.Equal (
  5002. $"This is the first line.{Environment.NewLine}This is the second line.",
  5003. _textView.Text
  5004. );
  5005. break;
  5006. default:
  5007. iterationsFinished = true;
  5008. break;
  5009. }
  5010. iteration++;
  5011. }
  5012. }
  5013. [Fact]
  5014. [TextViewTestsAutoInitShutdown]
  5015. public void Kill_To_Start_Delete_Backwards_Copy_To_The_Clipboard_And_Paste ()
  5016. {
  5017. _textView.Text = "This is the first line.\nThis is the second line.";
  5018. _textView.MoveEnd ();
  5019. var iteration = 0;
  5020. var iterationsFinished = false;
  5021. while (!iterationsFinished)
  5022. {
  5023. switch (iteration)
  5024. {
  5025. case 0:
  5026. _textView.NewKeyDownEvent (Key.Backspace.WithCtrl.WithShift);
  5027. Assert.Equal (0, _textView.CursorPosition.X);
  5028. Assert.Equal (1, _textView.CursorPosition.Y);
  5029. Assert.Equal ($"This is the first line.{Environment.NewLine}", _textView.Text);
  5030. Assert.Equal ("This is the second line.", Clipboard.Contents);
  5031. break;
  5032. case 1:
  5033. _textView.NewKeyDownEvent (
  5034. new Key (
  5035. KeyCode.Backspace | KeyCode.CtrlMask | KeyCode.ShiftMask
  5036. )
  5037. );
  5038. Assert.Equal (23, _textView.CursorPosition.X);
  5039. Assert.Equal (0, _textView.CursorPosition.Y);
  5040. Assert.Equal ("This is the first line.", _textView.Text);
  5041. Assert.Equal ($"This is the second line.{Environment.NewLine}", Clipboard.Contents);
  5042. break;
  5043. case 2:
  5044. _textView.NewKeyDownEvent (Key.Backspace.WithCtrl.WithShift);
  5045. Assert.Equal (0, _textView.CursorPosition.X);
  5046. Assert.Equal (0, _textView.CursorPosition.Y);
  5047. Assert.Equal ("", _textView.Text);
  5048. Assert.Equal (
  5049. $"This is the second line.{Environment.NewLine}This is the first line.",
  5050. Clipboard.Contents
  5051. );
  5052. // Paste inverted
  5053. _textView.NewKeyDownEvent (Key.Y.WithCtrl);
  5054. Assert.Equal (
  5055. $"This is the second line.{Environment.NewLine}This is the first line.",
  5056. _textView.Text
  5057. );
  5058. break;
  5059. default:
  5060. iterationsFinished = true;
  5061. break;
  5062. }
  5063. iteration++;
  5064. }
  5065. }
  5066. [Fact]
  5067. public void LeftColumn_Add_One_If_Text_Length_Is_Equal_To_Width ()
  5068. {
  5069. var tv = new TextView { Width = 10, Text = "1234567890" };
  5070. Assert.Equal (Point.Empty, tv.CursorPosition);
  5071. Assert.Equal (0, tv.LeftColumn);
  5072. tv.CursorPosition = new Point (9, 0);
  5073. Assert.Equal (new Point (9, 0), tv.CursorPosition);
  5074. Assert.Equal (0, tv.LeftColumn);
  5075. Assert.True (tv.NewKeyDownEvent (Key.CursorRight));
  5076. tv.CursorPosition = new Point (10, 0);
  5077. Assert.Equal (new Point (10, 0), tv.CursorPosition);
  5078. Assert.Equal (1, tv.LeftColumn);
  5079. }
  5080. [Fact]
  5081. public void LoadFile_Throws_If_File_Is_Empty ()
  5082. {
  5083. var result = false;
  5084. var tv = new TextView ();
  5085. Assert.Throws<ArgumentException> (() => result = tv.Load (""));
  5086. Assert.False (result);
  5087. }
  5088. [Fact]
  5089. public void LoadFile_Throws_If_File_Is_Null ()
  5090. {
  5091. var result = false;
  5092. var tv = new TextView ();
  5093. Assert.Throws<ArgumentNullException> (() => result = tv.Load ((string)null));
  5094. Assert.False (result);
  5095. }
  5096. [Fact]
  5097. public void LoadFile_Throws_If_File_Not_Exist ()
  5098. {
  5099. var result = false;
  5100. var tv = new TextView ();
  5101. Assert.Throws<FileNotFoundException> (() => result = tv.Load ("blabla"));
  5102. Assert.False (result);
  5103. }
  5104. [Fact]
  5105. public void LoadStream_CRLF ()
  5106. {
  5107. var text = "This is the first line.\r\nThis is the second line.\r\n";
  5108. var tv = new TextView ();
  5109. tv.Load (new MemoryStream (Encoding.ASCII.GetBytes (text)));
  5110. Assert.Equal (
  5111. $"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}",
  5112. tv.Text
  5113. );
  5114. }
  5115. [Fact]
  5116. public void LoadStream_IsDirty ()
  5117. {
  5118. var text = "Testing";
  5119. using (var stream = new MemoryStream ())
  5120. {
  5121. var writer = new StreamWriter (stream);
  5122. writer.Write (text);
  5123. writer.Flush ();
  5124. stream.Position = 0;
  5125. var tv = new TextView ();
  5126. tv.Load (stream);
  5127. Assert.Equal (7, text.Length);
  5128. Assert.Equal (text.Length, tv.Text.Length);
  5129. Assert.Equal (text, tv.Text);
  5130. Assert.False (tv.IsDirty);
  5131. }
  5132. }
  5133. [Fact]
  5134. public void LoadStream_IsDirty_With_Null_On_The_Text ()
  5135. {
  5136. var text = "Test\0ing";
  5137. using (var stream = new MemoryStream ())
  5138. {
  5139. var writer = new StreamWriter (stream);
  5140. writer.Write (text);
  5141. writer.Flush ();
  5142. stream.Position = 0;
  5143. var tv = new TextView ();
  5144. tv.Load (stream);
  5145. Assert.Equal (8, text.Length);
  5146. Assert.Equal (text.Length, tv.Text.Length);
  5147. Assert.Equal (8, text.Length);
  5148. Assert.Equal (8, tv.Text.Length);
  5149. Assert.Equal (text, tv.Text);
  5150. Assert.False (tv.IsDirty);
  5151. Assert.Equal ((Rune)'\u2400', ((Rune)tv.Text [4]).MakePrintable ());
  5152. }
  5153. }
  5154. [Fact]
  5155. public void LoadStream_LF ()
  5156. {
  5157. var text = "This is the first line.\nThis is the second line.\n";
  5158. var tv = new TextView ();
  5159. tv.Load (new MemoryStream (Encoding.ASCII.GetBytes (text)));
  5160. Assert.Equal (
  5161. $"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}",
  5162. tv.Text
  5163. );
  5164. }
  5165. [Fact]
  5166. public void LoadStream_Stream_Is_Empty ()
  5167. {
  5168. var tv = new TextView ();
  5169. tv.Load (new MemoryStream ());
  5170. Assert.Equal ("", tv.Text);
  5171. }
  5172. [Fact]
  5173. public void LoadStream_Throws_If_Stream_Is_Null ()
  5174. {
  5175. var tv = new TextView ();
  5176. Assert.Throws<ArgumentNullException> (() => tv.Load ((Stream)null));
  5177. }
  5178. [Fact]
  5179. [TextViewTestsAutoInitShutdown]
  5180. public void Mouse_Button_Shift_Preserves_Selection ()
  5181. {
  5182. Assert.Equal ("TAB to jump between text fields.", _textView.Text);
  5183. Assert.True (
  5184. _textView.NewMouseEvent (
  5185. new MouseEventArgs { Position = new (12, 0), Flags = MouseFlags.Button1Pressed | MouseFlags.ButtonShift }
  5186. )
  5187. );
  5188. Assert.Equal (0, _textView.SelectionStartColumn);
  5189. Assert.Equal (0, _textView.SelectionStartRow);
  5190. Assert.Equal (new Point (12, 0), _textView.CursorPosition);
  5191. Assert.True (_textView.IsSelecting);
  5192. Assert.Equal ("TAB to jump ", _textView.SelectedText);
  5193. Assert.True (_textView.NewMouseEvent (new MouseEventArgs { Position = new (12, 0), Flags = MouseFlags.Button1Clicked }));
  5194. Assert.Equal (0, _textView.SelectionStartRow);
  5195. Assert.Equal (0, _textView.SelectionStartRow);
  5196. Assert.Equal (new Point (12, 0), _textView.CursorPosition);
  5197. Assert.True (_textView.IsSelecting);
  5198. Assert.Equal ("TAB to jump ", _textView.SelectedText);
  5199. Assert.True (
  5200. _textView.NewMouseEvent (
  5201. new MouseEventArgs { Position = new (19, 0), Flags = MouseFlags.Button1Pressed | MouseFlags.ButtonShift }
  5202. )
  5203. );
  5204. Assert.Equal (0, _textView.SelectionStartRow);
  5205. Assert.Equal (0, _textView.SelectionStartRow);
  5206. Assert.Equal (new Point (19, 0), _textView.CursorPosition);
  5207. Assert.True (_textView.IsSelecting);
  5208. Assert.Equal ("TAB to jump between", _textView.SelectedText);
  5209. Assert.True (_textView.NewMouseEvent (new MouseEventArgs { Position = new (19, 0), Flags = MouseFlags.Button1Clicked }));
  5210. Assert.Equal (0, _textView.SelectionStartRow);
  5211. Assert.Equal (0, _textView.SelectionStartRow);
  5212. Assert.Equal (new Point (19, 0), _textView.CursorPosition);
  5213. Assert.True (_textView.IsSelecting);
  5214. Assert.Equal ("TAB to jump between", _textView.SelectedText);
  5215. Assert.True (
  5216. _textView.NewMouseEvent (
  5217. new MouseEventArgs { Position = new (24, 0), Flags = MouseFlags.Button1Pressed | MouseFlags.ButtonShift }
  5218. )
  5219. );
  5220. Assert.Equal (0, _textView.SelectionStartRow);
  5221. Assert.Equal (0, _textView.SelectionStartRow);
  5222. Assert.Equal (new Point (24, 0), _textView.CursorPosition);
  5223. Assert.True (_textView.IsSelecting);
  5224. Assert.Equal ("TAB to jump between text", _textView.SelectedText);
  5225. Assert.True (_textView.NewMouseEvent (new MouseEventArgs { Position = new (24, 0), Flags = MouseFlags.Button1Clicked }));
  5226. Assert.Equal (0, _textView.SelectionStartRow);
  5227. Assert.Equal (0, _textView.SelectionStartRow);
  5228. Assert.Equal (new Point (24, 0), _textView.CursorPosition);
  5229. Assert.True (_textView.IsSelecting);
  5230. Assert.Equal ("TAB to jump between text", _textView.SelectedText);
  5231. Assert.True (_textView.NewMouseEvent (new MouseEventArgs { Position = new (24, 0), Flags = MouseFlags.Button1Pressed }));
  5232. Assert.Equal (0, _textView.SelectionStartRow);
  5233. Assert.Equal (0, _textView.SelectionStartRow);
  5234. Assert.Equal (new Point (24, 0), _textView.CursorPosition);
  5235. Assert.True (_textView.IsSelecting);
  5236. Assert.Equal ("", _textView.SelectedText);
  5237. }
  5238. [Fact]
  5239. [AutoInitShutdown]
  5240. public void MoveDown_By_Setting_CursorPosition ()
  5241. {
  5242. var tv = new TextView { Width = 10, Height = 5 };
  5243. // add 100 lines of wide text to view
  5244. for (var i = 0; i < 100; i++)
  5245. {
  5246. tv.Text += new string ('x', 100) + (i == 99 ? "" : Environment.NewLine);
  5247. }
  5248. Assert.Equal (Point.Empty, tv.CursorPosition);
  5249. tv.CursorPosition = new Point (5, 50);
  5250. Assert.Equal (new Point (5, 50), tv.CursorPosition);
  5251. tv.CursorPosition = new Point (200, 200);
  5252. Assert.Equal (new Point (100, 99), tv.CursorPosition);
  5253. }
  5254. [Fact]
  5255. [TextViewTestsAutoInitShutdown]
  5256. public void Multiline_Setting_Changes_AllowsReturn_AllowsTab_Height_WordWrap ()
  5257. {
  5258. Assert.True (_textView.Multiline);
  5259. Assert.True (_textView.AllowsReturn);
  5260. Assert.Equal (4, _textView.TabWidth);
  5261. Assert.True (_textView.AllowsTab);
  5262. Assert.False (_textView.WordWrap);
  5263. _textView.WordWrap = true;
  5264. Assert.True (_textView.WordWrap);
  5265. _textView.Multiline = false;
  5266. Assert.False (_textView.Multiline);
  5267. Assert.False (_textView.AllowsReturn);
  5268. Assert.Equal (0, _textView.TabWidth);
  5269. Assert.False (_textView.AllowsTab);
  5270. Assert.False (_textView.WordWrap);
  5271. _textView.WordWrap = true;
  5272. Assert.False (_textView.WordWrap);
  5273. _textView.Multiline = true;
  5274. Assert.True (_textView.Multiline);
  5275. Assert.True (_textView.AllowsReturn);
  5276. Assert.Equal (4, _textView.TabWidth);
  5277. Assert.True (_textView.AllowsTab);
  5278. Assert.False (_textView.WordWrap);
  5279. }
  5280. [Fact]
  5281. [TextViewTestsAutoInitShutdown]
  5282. public void Paste_Always_Clear_The_SelectedText ()
  5283. {
  5284. _textView.SelectionStartColumn = 20;
  5285. _textView.SelectionStartRow = 0;
  5286. _textView.CursorPosition = new Point (24, 0);
  5287. _textView.NewKeyDownEvent (Key.C.WithCtrl); // Copy
  5288. Assert.Equal ("text", _textView.SelectedText);
  5289. _textView.NewKeyDownEvent (Key.Y.WithCtrl); // Paste
  5290. Assert.Equal ("", _textView.SelectedText);
  5291. }
  5292. [Fact]
  5293. public void ReplaceAllText_Does_Not_Throw_Exception ()
  5294. {
  5295. var textToFind = "hello! hello!";
  5296. var textToReplace = "hello!";
  5297. var tv = new TextView { Width = 20, Height = 3, Text = textToFind };
  5298. Exception exception = Record.Exception (() => tv.ReplaceAllText (textToFind, false, false, textToReplace));
  5299. Assert.Null (exception);
  5300. Assert.Equal (textToReplace, tv.Text);
  5301. }
  5302. [Fact]
  5303. [AutoInitShutdown]
  5304. public void ScrollDownTillCaretOffscreen_ThenType ()
  5305. {
  5306. var tv = new TextView { Width = 10, Height = 5 };
  5307. // add 100 lines of wide text to view
  5308. for (var i = 0; i < 100; i++)
  5309. {
  5310. tv.Text += new string ('x', 100) + Environment.NewLine;
  5311. }
  5312. Assert.Equal (0, tv.CursorPosition.Y);
  5313. tv.ScrollTo (50);
  5314. Assert.Equal (0, tv.CursorPosition.Y);
  5315. tv.NewKeyDownEvent (Key.P);
  5316. }
  5317. [Fact]
  5318. [AutoInitShutdown]
  5319. public void ScrollTo_CursorPosition ()
  5320. {
  5321. var tv = new TextView { Width = 10, Height = 5 };
  5322. // add 100 lines of wide text to view
  5323. for (var i = 0; i < 100; i++)
  5324. {
  5325. tv.Text += new string ('x', 100) + (i == 99 ? "" : Environment.NewLine);
  5326. }
  5327. Assert.Equal (Point.Empty, tv.CursorPosition);
  5328. tv.ScrollTo (50);
  5329. Assert.Equal (Point.Empty, tv.CursorPosition);
  5330. tv.CursorPosition = new Point (tv.LeftColumn, tv.TopRow);
  5331. Assert.Equal (new Point (0, 50), tv.CursorPosition);
  5332. }
  5333. [Fact]
  5334. [TextViewTestsAutoInitShutdown]
  5335. public void Selected_Text_Shows ()
  5336. {
  5337. // Proves #3022 is fixed (TextField selected text does not show in v2)
  5338. var top = new Toplevel ();
  5339. top.Add (_textView);
  5340. RunState rs = Application.Begin (top);
  5341. _textView.CursorPosition = Point.Empty;
  5342. _textView.SelectionStartColumn = 0;
  5343. _textView.SelectionStartRow = 0;
  5344. Attribute [] attributes =
  5345. {
  5346. _textView.ColorScheme.Focus,
  5347. new (_textView.ColorScheme.Focus.Background, _textView.ColorScheme.Focus.Foreground)
  5348. };
  5349. // TAB to jump between text fields.
  5350. TestHelpers.AssertDriverAttributesAre ("0000000", _output, Application.Driver, attributes);
  5351. Assert.Empty (_textView.SelectedCellsList);
  5352. _textView.NewKeyDownEvent (Key.CursorRight.WithCtrl.WithShift);
  5353. Application.RunIteration (ref rs, true);
  5354. Assert.Equal (new Point (4, 0), _textView.CursorPosition);
  5355. // TAB to jump between text fields.
  5356. TestHelpers.AssertDriverAttributesAre ("1111000", _output, Application.Driver, attributes);
  5357. Assert.Equal ("TAB ", Cell.ToString (_textView.SelectedCellsList [^1]));
  5358. top.Dispose ();
  5359. }
  5360. [Fact]
  5361. [TextViewTestsAutoInitShutdown]
  5362. public void Selection_And_CursorPosition_With_Value_Greater_Than_Text_Length_Changes_Both_To_Text_Length ()
  5363. {
  5364. _textView.CursorPosition = new Point (33, 2);
  5365. _textView.SelectionStartColumn = 33;
  5366. _textView.SelectionStartRow = 33;
  5367. Assert.Equal (32, _textView.CursorPosition.X);
  5368. Assert.Equal (0, _textView.CursorPosition.Y);
  5369. Assert.Equal (32, _textView.SelectionStartColumn);
  5370. Assert.Equal (0, _textView.SelectionStartRow);
  5371. Assert.Equal (0, _textView.SelectedLength);
  5372. Assert.Equal ("", _textView.SelectedText);
  5373. }
  5374. [Fact]
  5375. [TextViewTestsAutoInitShutdown]
  5376. public void Selection_With_Empty_Text ()
  5377. {
  5378. _textView = new TextView ();
  5379. _textView.CursorPosition = new Point (2, 0);
  5380. _textView.SelectionStartColumn = 33;
  5381. _textView.SelectionStartRow = 1;
  5382. Assert.Equal (0, _textView.SelectionStartColumn);
  5383. Assert.Equal (0, _textView.SelectionStartRow);
  5384. Assert.Equal (0, _textView.SelectedLength);
  5385. Assert.Equal ("", _textView.SelectedText);
  5386. }
  5387. [Fact]
  5388. [TextViewTestsAutoInitShutdown]
  5389. public void Selection_With_Value_Greater_Than_Text_Length_Changes_To_Text_Length ()
  5390. {
  5391. _textView.CursorPosition = new Point (2, 0);
  5392. _textView.SelectionStartColumn = 33;
  5393. _textView.SelectionStartRow = 1;
  5394. Assert.Equal (32, _textView.SelectionStartColumn);
  5395. Assert.Equal (0, _textView.SelectionStartRow);
  5396. Assert.Equal (30, _textView.SelectedLength);
  5397. Assert.Equal ("B to jump between text fields.", _textView.SelectedText);
  5398. }
  5399. [Fact]
  5400. [TextViewTestsAutoInitShutdown]
  5401. public void Selection_With_Value_Less_Than_Zero_Changes_To_Zero ()
  5402. {
  5403. _textView.SelectionStartColumn = -2;
  5404. _textView.SelectionStartRow = -2;
  5405. Assert.Equal (0, _textView.SelectionStartColumn);
  5406. Assert.Equal (0, _textView.SelectionStartRow);
  5407. Assert.Equal (0, _textView.SelectedLength);
  5408. Assert.Equal ("", _textView.SelectedText);
  5409. }
  5410. [Fact]
  5411. public void StringToRunes_Slipts_CRLF ()
  5412. {
  5413. var text = "This is the first line.\r\nThis is the second line.\r\n";
  5414. var tv = new TextView ();
  5415. tv.Text = text;
  5416. Assert.Equal (
  5417. $"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}",
  5418. tv.Text
  5419. );
  5420. }
  5421. [Fact]
  5422. public void StringToRunes_Slipts_LF ()
  5423. {
  5424. var text = "This is the first line.\nThis is the second line.\n";
  5425. var tv = new TextView ();
  5426. tv.Text = text;
  5427. Assert.Equal (
  5428. $"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}",
  5429. tv.Text
  5430. );
  5431. }
  5432. [Fact]
  5433. [TextViewTestsAutoInitShutdown]
  5434. public void Tab_Test_Follow_By_BackTab ()
  5435. {
  5436. var top = new Toplevel ();
  5437. top.Add (_textView);
  5438. Application.Iteration += (s, a) =>
  5439. {
  5440. int width = _textView.Viewport.Width - 1;
  5441. Assert.Equal (30, width + 1);
  5442. Assert.Equal (10, _textView.Height);
  5443. _textView.Text = "";
  5444. var col = 0;
  5445. var leftCol = 0;
  5446. int tabWidth = _textView.TabWidth;
  5447. while (col < 100)
  5448. {
  5449. col++;
  5450. _textView.NewKeyDownEvent (Key.Tab);
  5451. Assert.Equal (new Point (col, 0), _textView.CursorPosition);
  5452. leftCol = GetLeftCol (leftCol);
  5453. Assert.Equal (leftCol, _textView.LeftColumn);
  5454. }
  5455. while (col > 0)
  5456. {
  5457. col--;
  5458. _textView.NewKeyDownEvent (Key.Tab.WithShift);
  5459. Assert.Equal (new Point (col, 0), _textView.CursorPosition);
  5460. leftCol = GetLeftCol (leftCol);
  5461. Assert.Equal (leftCol, _textView.LeftColumn);
  5462. }
  5463. top.Remove (_textView);
  5464. Application.RequestStop ();
  5465. };
  5466. Application.Run (top);
  5467. top.Dispose ();
  5468. }
  5469. [Fact]
  5470. [TextViewTestsAutoInitShutdown]
  5471. public void Tab_Test_Follow_By_BackTab_With_Text ()
  5472. {
  5473. var top = new Toplevel ();
  5474. top.Add (_textView);
  5475. Application.Iteration += (s, a) =>
  5476. {
  5477. int width = _textView.Viewport.Width - 1;
  5478. Assert.Equal (30, width + 1);
  5479. Assert.Equal (10, _textView.Height);
  5480. var col = 0;
  5481. var leftCol = 0;
  5482. Assert.Equal (new Point (col, 0), _textView.CursorPosition);
  5483. Assert.Equal (leftCol, _textView.LeftColumn);
  5484. while (col < 100)
  5485. {
  5486. col++;
  5487. _textView.NewKeyDownEvent (Key.Tab);
  5488. Assert.Equal (new Point (col, 0), _textView.CursorPosition);
  5489. leftCol = GetLeftCol (leftCol);
  5490. Assert.Equal (leftCol, _textView.LeftColumn);
  5491. }
  5492. while (col > 0)
  5493. {
  5494. col--;
  5495. _textView.NewKeyDownEvent (Key.Tab.WithShift);
  5496. Assert.Equal (new Point (col, 0), _textView.CursorPosition);
  5497. leftCol = GetLeftCol (leftCol);
  5498. Assert.Equal (leftCol, _textView.LeftColumn);
  5499. }
  5500. top.Remove (_textView);
  5501. Application.RequestStop ();
  5502. };
  5503. Application.Run (top);
  5504. top.Dispose ();
  5505. }
  5506. [Fact]
  5507. [TextViewTestsAutoInitShutdown]
  5508. public void Tab_Test_Follow_By_CursorLeft_And_Then_Follow_By_CursorRight ()
  5509. {
  5510. var top = new Toplevel ();
  5511. top.Add (_textView);
  5512. Application.Iteration += (s, a) =>
  5513. {
  5514. int width = _textView.Viewport.Width - 1;
  5515. Assert.Equal (30, width + 1);
  5516. Assert.Equal (10, _textView.Height);
  5517. _textView.Text = "";
  5518. var col = 0;
  5519. var leftCol = 0;
  5520. int tabWidth = _textView.TabWidth;
  5521. while (col < 100)
  5522. {
  5523. col++;
  5524. _textView.NewKeyDownEvent (Key.Tab);
  5525. Assert.Equal (new Point (col, 0), _textView.CursorPosition);
  5526. leftCol = GetLeftCol (leftCol);
  5527. Assert.Equal (leftCol, _textView.LeftColumn);
  5528. }
  5529. while (col > 0)
  5530. {
  5531. col--;
  5532. _textView.NewKeyDownEvent (Key.CursorLeft);
  5533. Assert.Equal (new Point (col, 0), _textView.CursorPosition);
  5534. leftCol = GetLeftCol (leftCol);
  5535. Assert.Equal (leftCol, _textView.LeftColumn);
  5536. }
  5537. while (col < 100)
  5538. {
  5539. col++;
  5540. _textView.NewKeyDownEvent (Key.CursorRight);
  5541. Assert.Equal (new Point (col, 0), _textView.CursorPosition);
  5542. leftCol = GetLeftCol (leftCol);
  5543. Assert.Equal (leftCol, _textView.LeftColumn);
  5544. }
  5545. top.Remove (_textView);
  5546. Application.RequestStop ();
  5547. };
  5548. Application.Run (top);
  5549. top.Dispose ();
  5550. }
  5551. [Fact]
  5552. [TextViewTestsAutoInitShutdown]
  5553. public void Tab_Test_Follow_By_CursorLeft_And_Then_Follow_By_CursorRight_With_Text ()
  5554. {
  5555. var top = new Toplevel ();
  5556. top.Add (_textView);
  5557. Application.Iteration += (s, a) =>
  5558. {
  5559. int width = _textView.Viewport.Width - 1;
  5560. Assert.Equal (30, width + 1);
  5561. Assert.Equal (10, _textView.Height);
  5562. Assert.Equal ("TAB to jump between text fields.", _textView.Text);
  5563. var col = 0;
  5564. var leftCol = 0;
  5565. int tabWidth = _textView.TabWidth;
  5566. while (col < 100)
  5567. {
  5568. col++;
  5569. _textView.NewKeyDownEvent (Key.Tab);
  5570. Assert.Equal (new Point (col, 0), _textView.CursorPosition);
  5571. leftCol = GetLeftCol (leftCol);
  5572. Assert.Equal (leftCol, _textView.LeftColumn);
  5573. }
  5574. Assert.Equal (132, _textView.Text.Length);
  5575. while (col > 0)
  5576. {
  5577. col--;
  5578. _textView.NewKeyDownEvent (Key.CursorLeft);
  5579. Assert.Equal (new Point (col, 0), _textView.CursorPosition);
  5580. leftCol = GetLeftCol (leftCol);
  5581. Assert.Equal (leftCol, _textView.LeftColumn);
  5582. }
  5583. while (col < 100)
  5584. {
  5585. col++;
  5586. _textView.NewKeyDownEvent (Key.CursorRight);
  5587. Assert.Equal (new Point (col, 0), _textView.CursorPosition);
  5588. leftCol = GetLeftCol (leftCol);
  5589. Assert.Equal (leftCol, _textView.LeftColumn);
  5590. }
  5591. top.Remove (_textView);
  5592. Application.RequestStop ();
  5593. };
  5594. Application.Run (top);
  5595. top.Dispose ();
  5596. }
  5597. [Fact]
  5598. [TextViewTestsAutoInitShutdown]
  5599. public void Tab_Test_Follow_By_Home_And_Then_Follow_By_End_And_Then_Follow_By_BackTab_With_Text ()
  5600. {
  5601. var top = new Toplevel ();
  5602. top.Add (_textView);
  5603. Application.Iteration += (s, a) =>
  5604. {
  5605. int width = _textView.Viewport.Width - 1;
  5606. Assert.Equal (30, width + 1);
  5607. Assert.Equal (10, _textView.Height);
  5608. var col = 0;
  5609. var leftCol = 0;
  5610. Assert.Equal (new Point (col, 0), _textView.CursorPosition);
  5611. Assert.Equal (leftCol, _textView.LeftColumn);
  5612. Assert.Equal ("TAB to jump between text fields.", _textView.Text);
  5613. Assert.Equal (32, _textView.Text.Length);
  5614. while (col < 100)
  5615. {
  5616. col++;
  5617. _textView.NewKeyDownEvent (Key.Tab);
  5618. Assert.Equal (new Point (col, 0), _textView.CursorPosition);
  5619. leftCol = GetLeftCol (leftCol);
  5620. Assert.Equal (leftCol, _textView.LeftColumn);
  5621. }
  5622. _textView.NewKeyDownEvent (Key.Home);
  5623. col = 0;
  5624. Assert.Equal (new Point (col, 0), _textView.CursorPosition);
  5625. leftCol = 0;
  5626. Assert.Equal (leftCol, _textView.LeftColumn);
  5627. _textView.NewKeyDownEvent (Key.End);
  5628. col = _textView.Text.Length;
  5629. Assert.Equal (132, _textView.Text.Length);
  5630. Assert.Equal (new Point (col, 0), _textView.CursorPosition);
  5631. leftCol = GetLeftCol (leftCol);
  5632. Assert.Equal (leftCol, _textView.LeftColumn);
  5633. string txt = _textView.Text;
  5634. while (col - 1 > 0 && txt [col - 1] != '\t')
  5635. {
  5636. col--;
  5637. }
  5638. _textView.CursorPosition = new Point (col, 0);
  5639. leftCol = GetLeftCol (leftCol);
  5640. while (col > 0)
  5641. {
  5642. col--;
  5643. _textView.NewKeyDownEvent (Key.Tab.WithShift);
  5644. Assert.Equal (new Point (col, 0), _textView.CursorPosition);
  5645. leftCol = GetLeftCol (leftCol);
  5646. Assert.Equal (leftCol, _textView.LeftColumn);
  5647. }
  5648. Assert.Equal ("TAB to jump between text fields.", _textView.Text);
  5649. Assert.Equal (32, _textView.Text.Length);
  5650. top.Remove (_textView);
  5651. Application.RequestStop ();
  5652. };
  5653. Application.Run (top);
  5654. top.Dispose ();
  5655. }
  5656. [Fact]
  5657. [TextViewTestsAutoInitShutdown]
  5658. public void TabWidth_Setting_To_Zero_Keeps_AllowsTab ()
  5659. {
  5660. var top = new Toplevel ();
  5661. top.Add (_textView);
  5662. Application.Begin (top);
  5663. Assert.Equal (4, _textView.TabWidth);
  5664. Assert.True (_textView.AllowsTab);
  5665. Assert.True (_textView.AllowsReturn);
  5666. Assert.True (_textView.Multiline);
  5667. _textView.TabWidth = -1;
  5668. Assert.Equal (0, _textView.TabWidth);
  5669. Assert.True (_textView.AllowsTab);
  5670. Assert.True (_textView.AllowsReturn);
  5671. Assert.True (_textView.Multiline);
  5672. _textView.NewKeyDownEvent (Key.Tab);
  5673. Assert.Equal ("\tTAB to jump between text fields.", _textView.Text);
  5674. Application.LayoutAndDraw ();
  5675. TestHelpers.AssertDriverContentsWithFrameAre (
  5676. @"
  5677. TAB to jump between text field",
  5678. _output
  5679. );
  5680. _textView.TabWidth = 4;
  5681. Application.LayoutAndDraw ();
  5682. TestHelpers.AssertDriverContentsWithFrameAre (
  5683. @"
  5684. TAB to jump between text f",
  5685. _output
  5686. );
  5687. _textView.NewKeyDownEvent (Key.Tab.WithShift);
  5688. Assert.Equal ("TAB to jump between text fields.", _textView.Text);
  5689. Assert.True (_textView.NeedsDraw);
  5690. Application.LayoutAndDraw ();
  5691. TestHelpers.AssertDriverContentsWithFrameAre (
  5692. @"
  5693. TAB to jump between text field",
  5694. _output
  5695. );
  5696. top.Dispose ();
  5697. }
  5698. [Fact]
  5699. [TextViewTestsAutoInitShutdown]
  5700. public void TextChanged_Event ()
  5701. {
  5702. _textView.TextChanged += (s, e) =>
  5703. {
  5704. if (_textView.Text == "changing")
  5705. {
  5706. Assert.Equal ("changing", _textView.Text);
  5707. _textView.Text = "changed";
  5708. }
  5709. };
  5710. _textView.Text = "changing";
  5711. Assert.Equal ("changed", _textView.Text);
  5712. }
  5713. [Fact]
  5714. [TextViewTestsAutoInitShutdown]
  5715. public void TextChanged_Event_NoFires_OnTyping ()
  5716. {
  5717. var eventcount = 0;
  5718. _textView.TextChanged += (s, e) => { eventcount++; };
  5719. _textView.Text = "ay";
  5720. Assert.Equal (1, eventcount);
  5721. _textView.NewKeyDownEvent (Key.Y.WithShift);
  5722. Assert.Equal (1, eventcount);
  5723. Assert.Equal ("Yay", _textView.Text);
  5724. }
  5725. [Fact]
  5726. [TextViewTestsAutoInitShutdown]
  5727. public void TextView_InsertText_Newline_CRLF ()
  5728. {
  5729. var tv = new TextView { Width = 10, Height = 10 };
  5730. tv.InsertText ("\r\naaa\r\nbbb");
  5731. PlatformID p = Environment.OSVersion.Platform;
  5732. if (p == PlatformID.Win32NT || p == PlatformID.Win32S || p == PlatformID.Win32Windows)
  5733. {
  5734. Assert.Equal ("\r\naaa\r\nbbb", tv.Text);
  5735. }
  5736. else
  5737. {
  5738. Assert.Equal ("\naaa\nbbb", tv.Text);
  5739. }
  5740. Assert.Equal ($"{Environment.NewLine}aaa{Environment.NewLine}bbb", tv.Text);
  5741. var win = new Window ();
  5742. win.Add (tv);
  5743. var top = new Toplevel ();
  5744. top.Add (win);
  5745. Application.Begin (top);
  5746. ((FakeDriver)Application.Driver!).SetBufferSize (15, 15);
  5747. Application.LayoutAndDraw ();
  5748. //this passes
  5749. Rectangle pos = TestHelpers.AssertDriverContentsWithFrameAre (
  5750. @"
  5751. ┌─────────────┐
  5752. │ │
  5753. │aaa │
  5754. │bbb │
  5755. │ │
  5756. │ │
  5757. │ │
  5758. │ │
  5759. │ │
  5760. │ │
  5761. │ │
  5762. │ │
  5763. │ │
  5764. │ │
  5765. └─────────────┘",
  5766. _output
  5767. );
  5768. Assert.Equal (new Rectangle (0, 0, 15, 15), pos);
  5769. Assert.True (tv.Used);
  5770. tv.Used = false;
  5771. tv.CursorPosition = Point.Empty;
  5772. tv.InsertText ("\r\naaa\r\nbbb");
  5773. Application.LayoutAndDraw ();
  5774. TestHelpers.AssertDriverContentsWithFrameAre (
  5775. @"
  5776. ┌─────────────┐
  5777. │ │
  5778. │aaa │
  5779. │bbb │
  5780. │aaa │
  5781. │bbb │
  5782. │ │
  5783. │ │
  5784. │ │
  5785. │ │
  5786. │ │
  5787. │ │
  5788. │ │
  5789. │ │
  5790. └─────────────┘",
  5791. _output
  5792. );
  5793. top.Dispose ();
  5794. }
  5795. [Fact]
  5796. [TextViewTestsAutoInitShutdown]
  5797. public void TextView_InsertText_Newline_LF ()
  5798. {
  5799. var tv = new TextView { Width = 10, Height = 10 };
  5800. tv.InsertText ("\naaa\nbbb");
  5801. PlatformID p = Environment.OSVersion.Platform;
  5802. if (p == PlatformID.Win32NT || p == PlatformID.Win32S || p == PlatformID.Win32Windows)
  5803. {
  5804. Assert.Equal ("\r\naaa\r\nbbb", tv.Text);
  5805. }
  5806. else
  5807. {
  5808. Assert.Equal ("\naaa\nbbb", tv.Text);
  5809. }
  5810. Assert.Equal ($"{Environment.NewLine}aaa{Environment.NewLine}bbb", tv.Text);
  5811. var win = new Window ();
  5812. win.Add (tv);
  5813. var top = new Toplevel ();
  5814. top.Add (win);
  5815. Application.Begin (top);
  5816. ((FakeDriver)Application.Driver!).SetBufferSize (15, 15);
  5817. Application.LayoutAndDraw ();
  5818. //this passes
  5819. Rectangle pos = TestHelpers.AssertDriverContentsWithFrameAre (
  5820. @"
  5821. ┌─────────────┐
  5822. │ │
  5823. │aaa │
  5824. │bbb │
  5825. │ │
  5826. │ │
  5827. │ │
  5828. │ │
  5829. │ │
  5830. │ │
  5831. │ │
  5832. │ │
  5833. │ │
  5834. │ │
  5835. └─────────────┘",
  5836. _output
  5837. );
  5838. Assert.Equal (new Rectangle (0, 0, 15, 15), pos);
  5839. Assert.True (tv.Used);
  5840. tv.Used = false;
  5841. tv.CursorPosition = Point.Empty;
  5842. tv.InsertText ("\naaa\nbbb");
  5843. Application.LayoutAndDraw ();
  5844. TestHelpers.AssertDriverContentsWithFrameAre (
  5845. @"
  5846. ┌─────────────┐
  5847. │ │
  5848. │aaa │
  5849. │bbb │
  5850. │aaa │
  5851. │bbb │
  5852. │ │
  5853. │ │
  5854. │ │
  5855. │ │
  5856. │ │
  5857. │ │
  5858. │ │
  5859. │ │
  5860. └─────────────┘",
  5861. _output
  5862. );
  5863. top.Dispose ();
  5864. }
  5865. [Fact]
  5866. public void TextView_MultiLine_But_Without_Tabs ()
  5867. {
  5868. var view = new TextView ();
  5869. // the default for TextView
  5870. Assert.True (view.Multiline);
  5871. view.AllowsTab = false;
  5872. Assert.False (view.AllowsTab);
  5873. Assert.True (view.Multiline);
  5874. }
  5875. [Fact]
  5876. [TextViewTestsAutoInitShutdown]
  5877. public void TextView_SpaceHandling ()
  5878. {
  5879. var tv = new TextView { Width = 10, Text = " " };
  5880. var ev = new MouseEventArgs { Position = new (0, 0), Flags = MouseFlags.Button1DoubleClicked };
  5881. tv.NewMouseEvent (ev);
  5882. Assert.Equal (1, tv.SelectedLength);
  5883. ev = new MouseEventArgs { Position = new (1, 0), Flags = MouseFlags.Button1DoubleClicked };
  5884. tv.NewMouseEvent (ev);
  5885. Assert.Equal (1, tv.SelectedLength);
  5886. }
  5887. [Fact]
  5888. [AutoInitShutdown]
  5889. public void UnwrappedCursorPosition_Event ()
  5890. {
  5891. var cp = Point.Empty;
  5892. var tv = new TextView
  5893. {
  5894. Width = Dim.Fill (), Height = Dim.Fill (), Text = "This is the first line.\nThis is the second line.\n"
  5895. };
  5896. tv.UnwrappedCursorPosition += (s, e) => { cp = e; };
  5897. var top = new Toplevel ();
  5898. top.Add (tv);
  5899. Application.Begin (top);
  5900. Application.LayoutAndDraw ();
  5901. Assert.False (tv.WordWrap);
  5902. Assert.Equal (Point.Empty, tv.CursorPosition);
  5903. Assert.Equal (Point.Empty, cp);
  5904. TestHelpers.AssertDriverContentsWithFrameAre (
  5905. @"
  5906. This is the first line.
  5907. This is the second line.
  5908. ",
  5909. _output
  5910. );
  5911. tv.WordWrap = true;
  5912. tv.CursorPosition = new Point (12, 0);
  5913. tv.Draw ();
  5914. Assert.Equal (new Point (12, 0), tv.CursorPosition);
  5915. Assert.Equal (new Point (12, 0), cp);
  5916. TestHelpers.AssertDriverContentsWithFrameAre (
  5917. @"
  5918. This is the first line.
  5919. This is the second line.
  5920. ",
  5921. _output
  5922. );
  5923. ((FakeDriver)Application.Driver).SetBufferSize (6, 25);
  5924. tv.SetRelativeLayout (Application.Screen.Size);
  5925. tv.Draw ();
  5926. Assert.Equal (new Point (4, 2), tv.CursorPosition);
  5927. Assert.Equal (new Point (12, 0), cp);
  5928. TestHelpers.AssertDriverContentsWithFrameAre (
  5929. @"
  5930. This
  5931. is
  5932. the
  5933. first
  5934. line.
  5935. This
  5936. is
  5937. the
  5938. secon
  5939. d
  5940. line.
  5941. ",
  5942. _output
  5943. );
  5944. Assert.True (tv.NewKeyDownEvent (Key.CursorRight));
  5945. tv.Draw ();
  5946. Assert.Equal (new Point (0, 3), tv.CursorPosition);
  5947. Assert.Equal (new Point (12, 0), cp);
  5948. TestHelpers.AssertDriverContentsWithFrameAre (
  5949. @"
  5950. This
  5951. is
  5952. the
  5953. first
  5954. line.
  5955. This
  5956. is
  5957. the
  5958. secon
  5959. d
  5960. line.
  5961. ",
  5962. _output
  5963. );
  5964. Assert.True (tv.NewKeyDownEvent (Key.CursorRight));
  5965. tv.Draw ();
  5966. Assert.Equal (new Point (1, 3), tv.CursorPosition);
  5967. Assert.Equal (new Point (13, 0), cp);
  5968. TestHelpers.AssertDriverContentsWithFrameAre (
  5969. @"
  5970. This
  5971. is
  5972. the
  5973. first
  5974. line.
  5975. This
  5976. is
  5977. the
  5978. secon
  5979. d
  5980. line.
  5981. ",
  5982. _output
  5983. );
  5984. Assert.True (tv.NewMouseEvent (new MouseEventArgs { Position = new (0, 3), Flags = MouseFlags.Button1Pressed }));
  5985. tv.Draw ();
  5986. Assert.Equal (new Point (0, 3), tv.CursorPosition);
  5987. Assert.Equal (new Point (13, 0), cp);
  5988. TestHelpers.AssertDriverContentsWithFrameAre (
  5989. @"
  5990. This
  5991. is
  5992. the
  5993. first
  5994. line.
  5995. This
  5996. is
  5997. the
  5998. secon
  5999. d
  6000. line.
  6001. ",
  6002. _output
  6003. );
  6004. top.Dispose ();
  6005. }
  6006. [Fact]
  6007. [TextViewTestsAutoInitShutdown]
  6008. public void Used_Is_False ()
  6009. {
  6010. _textView.Used = false;
  6011. _textView.CursorPosition = new Point (10, 0);
  6012. Assert.Equal ("TAB to jump between text fields.", _textView.Text);
  6013. _textView.NewKeyDownEvent (Key.U); // u
  6014. Assert.Equal ("TAB to jumu between text fields.", _textView.Text);
  6015. _textView.NewKeyDownEvent (Key.S); // s
  6016. Assert.Equal ("TAB to jumusbetween text fields.", _textView.Text);
  6017. _textView.NewKeyDownEvent (Key.E); // e
  6018. Assert.Equal ("TAB to jumuseetween text fields.", _textView.Text);
  6019. _textView.NewKeyDownEvent (Key.D); // d
  6020. Assert.Equal ("TAB to jumusedtween text fields.", _textView.Text);
  6021. }
  6022. [Fact]
  6023. [TextViewTestsAutoInitShutdown]
  6024. public void Used_Is_True_By_Default ()
  6025. {
  6026. _textView.CursorPosition = new Point (10, 0);
  6027. Assert.Equal ("TAB to jump between text fields.", _textView.Text);
  6028. _textView.NewKeyDownEvent (Key.U); // u
  6029. Assert.Equal ("TAB to jumup between text fields.", _textView.Text);
  6030. _textView.NewKeyDownEvent (Key.S); // s
  6031. Assert.Equal ("TAB to jumusp between text fields.", _textView.Text);
  6032. _textView.NewKeyDownEvent (Key.E); // e
  6033. Assert.Equal ("TAB to jumusep between text fields.", _textView.Text);
  6034. _textView.NewKeyDownEvent (Key.D); // d
  6035. Assert.Equal ("TAB to jumusedp between text fields.", _textView.Text);
  6036. }
  6037. [Fact]
  6038. [TextViewTestsAutoInitShutdown]
  6039. public void WordBackward_Multiline_With_Selection ()
  6040. {
  6041. // 4 3 2 1
  6042. // 87654321098765432109876 54321098765432109876543210-Length
  6043. // 1 2 1 2
  6044. // 01234567890123456789012 0123456789012345678901234
  6045. _textView.Text = "This is the first line.\nThis is the second line.";
  6046. _textView.MoveEnd ();
  6047. _textView.SelectionStartColumn = _textView.CurrentColumn;
  6048. _textView.SelectionStartRow = _textView.CurrentRow;
  6049. var iteration = 0;
  6050. var iterationsFinished = false;
  6051. while (!iterationsFinished)
  6052. {
  6053. _textView.NewKeyDownEvent (Key.CursorLeft.WithCtrl.WithShift);
  6054. switch (iteration)
  6055. {
  6056. case 0:
  6057. Assert.Equal (23, _textView.CursorPosition.X);
  6058. Assert.Equal (1, _textView.CursorPosition.Y);
  6059. Assert.Equal (24, _textView.SelectionStartColumn);
  6060. Assert.Equal (1, _textView.SelectionStartRow);
  6061. Assert.Equal (1, _textView.SelectedLength);
  6062. Assert.Equal (".", _textView.SelectedText);
  6063. break;
  6064. case 1:
  6065. Assert.Equal (19, _textView.CursorPosition.X);
  6066. Assert.Equal (1, _textView.CursorPosition.Y);
  6067. Assert.Equal (24, _textView.SelectionStartColumn);
  6068. Assert.Equal (1, _textView.SelectionStartRow);
  6069. Assert.Equal (5, _textView.SelectedLength);
  6070. Assert.Equal ("line.", _textView.SelectedText);
  6071. break;
  6072. case 2:
  6073. Assert.Equal (12, _textView.CursorPosition.X);
  6074. Assert.Equal (1, _textView.CursorPosition.Y);
  6075. Assert.Equal (24, _textView.SelectionStartColumn);
  6076. Assert.Equal (1, _textView.SelectionStartRow);
  6077. Assert.Equal (12, _textView.SelectedLength);
  6078. Assert.Equal ("second line.", _textView.SelectedText);
  6079. break;
  6080. case 3:
  6081. Assert.Equal (8, _textView.CursorPosition.X);
  6082. Assert.Equal (1, _textView.CursorPosition.Y);
  6083. Assert.Equal (24, _textView.SelectionStartColumn);
  6084. Assert.Equal (1, _textView.SelectionStartRow);
  6085. Assert.Equal (16, _textView.SelectedLength);
  6086. Assert.Equal ("the second line.", _textView.SelectedText);
  6087. break;
  6088. case 4:
  6089. Assert.Equal (5, _textView.CursorPosition.X);
  6090. Assert.Equal (1, _textView.CursorPosition.Y);
  6091. Assert.Equal (24, _textView.SelectionStartColumn);
  6092. Assert.Equal (1, _textView.SelectionStartRow);
  6093. Assert.Equal (19, _textView.SelectedLength);
  6094. Assert.Equal ("is the second line.", _textView.SelectedText);
  6095. break;
  6096. case 5:
  6097. Assert.Equal (0, _textView.CursorPosition.X);
  6098. Assert.Equal (1, _textView.CursorPosition.Y);
  6099. Assert.Equal (24, _textView.SelectionStartColumn);
  6100. Assert.Equal (1, _textView.SelectionStartRow);
  6101. Assert.Equal (24, _textView.SelectedLength);
  6102. Assert.Equal ("This is the second line.", _textView.SelectedText);
  6103. break;
  6104. case 6:
  6105. Assert.Equal (23, _textView.CursorPosition.X);
  6106. Assert.Equal (0, _textView.CursorPosition.Y);
  6107. Assert.Equal (24, _textView.SelectionStartColumn);
  6108. Assert.Equal (1, _textView.SelectionStartRow);
  6109. Assert.Equal (24 + Environment.NewLine.Length, _textView.SelectedLength);
  6110. Assert.Equal ($"{Environment.NewLine}This is the second line.", _textView.SelectedText);
  6111. break;
  6112. case 7:
  6113. Assert.Equal (22, _textView.CursorPosition.X);
  6114. Assert.Equal (0, _textView.CursorPosition.Y);
  6115. Assert.Equal (24, _textView.SelectionStartColumn);
  6116. Assert.Equal (1, _textView.SelectionStartRow);
  6117. Assert.Equal (25 + Environment.NewLine.Length, _textView.SelectedLength);
  6118. Assert.Equal (
  6119. $".{Environment.NewLine}This is the second line.",
  6120. _textView.SelectedText
  6121. );
  6122. break;
  6123. case 8:
  6124. Assert.Equal (18, _textView.CursorPosition.X);
  6125. Assert.Equal (0, _textView.CursorPosition.Y);
  6126. Assert.Equal (24, _textView.SelectionStartColumn);
  6127. Assert.Equal (1, _textView.SelectionStartRow);
  6128. Assert.Equal (29 + Environment.NewLine.Length, _textView.SelectedLength);
  6129. Assert.Equal (
  6130. $"line.{Environment.NewLine}This is the second line.",
  6131. _textView.SelectedText
  6132. );
  6133. break;
  6134. case 9:
  6135. Assert.Equal (12, _textView.CursorPosition.X);
  6136. Assert.Equal (0, _textView.CursorPosition.Y);
  6137. Assert.Equal (24, _textView.SelectionStartColumn);
  6138. Assert.Equal (1, _textView.SelectionStartRow);
  6139. Assert.Equal (35 + Environment.NewLine.Length, _textView.SelectedLength);
  6140. Assert.Equal (
  6141. $"first line.{Environment.NewLine}This is the second line.",
  6142. _textView.SelectedText
  6143. );
  6144. break;
  6145. case 10:
  6146. Assert.Equal (8, _textView.CursorPosition.X);
  6147. Assert.Equal (0, _textView.CursorPosition.Y);
  6148. Assert.Equal (24, _textView.SelectionStartColumn);
  6149. Assert.Equal (1, _textView.SelectionStartRow);
  6150. Assert.Equal (39 + Environment.NewLine.Length, _textView.SelectedLength);
  6151. Assert.Equal (
  6152. $"the first line.{Environment.NewLine}This is the second line.",
  6153. _textView.SelectedText
  6154. );
  6155. break;
  6156. case 11:
  6157. Assert.Equal (5, _textView.CursorPosition.X);
  6158. Assert.Equal (0, _textView.CursorPosition.Y);
  6159. Assert.Equal (24, _textView.SelectionStartColumn);
  6160. Assert.Equal (1, _textView.SelectionStartRow);
  6161. Assert.Equal (42 + Environment.NewLine.Length, _textView.SelectedLength);
  6162. Assert.Equal (
  6163. $"is the first line.{Environment.NewLine}This is the second line.",
  6164. _textView.SelectedText
  6165. );
  6166. break;
  6167. case 12:
  6168. Assert.Equal (0, _textView.CursorPosition.X);
  6169. Assert.Equal (0, _textView.CursorPosition.Y);
  6170. Assert.Equal (24, _textView.SelectionStartColumn);
  6171. Assert.Equal (1, _textView.SelectionStartRow);
  6172. Assert.Equal (47 + Environment.NewLine.Length, _textView.SelectedLength);
  6173. Assert.Equal (
  6174. $"This is the first line.{Environment.NewLine}This is the second line.",
  6175. _textView.SelectedText
  6176. );
  6177. break;
  6178. default:
  6179. iterationsFinished = true;
  6180. break;
  6181. }
  6182. iteration++;
  6183. }
  6184. }
  6185. [Fact]
  6186. [TextViewTestsAutoInitShutdown]
  6187. public void WordBackward_With_No_Selection ()
  6188. {
  6189. _textView.CursorPosition = new Point (_textView.Text.Length, 0);
  6190. var iteration = 0;
  6191. while (_textView.CursorPosition.X > 0)
  6192. {
  6193. _textView.NewKeyDownEvent (Key.CursorLeft.WithCtrl);
  6194. switch (iteration)
  6195. {
  6196. case 0:
  6197. Assert.Equal (31, _textView.CursorPosition.X);
  6198. Assert.Equal (0, _textView.CursorPosition.Y);
  6199. Assert.Equal (0, _textView.SelectionStartColumn);
  6200. Assert.Equal (0, _textView.SelectionStartRow);
  6201. Assert.Equal (0, _textView.SelectedLength);
  6202. Assert.Equal ("", _textView.SelectedText);
  6203. break;
  6204. case 1:
  6205. Assert.Equal (25, _textView.CursorPosition.X);
  6206. Assert.Equal (0, _textView.CursorPosition.Y);
  6207. Assert.Equal (0, _textView.SelectionStartColumn);
  6208. Assert.Equal (0, _textView.SelectionStartRow);
  6209. Assert.Equal (0, _textView.SelectedLength);
  6210. Assert.Equal ("", _textView.SelectedText);
  6211. break;
  6212. case 2:
  6213. Assert.Equal (20, _textView.CursorPosition.X);
  6214. Assert.Equal (0, _textView.CursorPosition.Y);
  6215. Assert.Equal (0, _textView.SelectionStartColumn);
  6216. Assert.Equal (0, _textView.SelectionStartRow);
  6217. Assert.Equal (0, _textView.SelectedLength);
  6218. Assert.Equal ("", _textView.SelectedText);
  6219. break;
  6220. case 3:
  6221. Assert.Equal (12, _textView.CursorPosition.X);
  6222. Assert.Equal (0, _textView.CursorPosition.Y);
  6223. Assert.Equal (0, _textView.SelectionStartColumn);
  6224. Assert.Equal (0, _textView.SelectionStartRow);
  6225. Assert.Equal (0, _textView.SelectedLength);
  6226. Assert.Equal ("", _textView.SelectedText);
  6227. break;
  6228. case 4:
  6229. Assert.Equal (7, _textView.CursorPosition.X);
  6230. Assert.Equal (0, _textView.CursorPosition.Y);
  6231. Assert.Equal (0, _textView.SelectionStartColumn);
  6232. Assert.Equal (0, _textView.SelectionStartRow);
  6233. Assert.Equal (0, _textView.SelectedLength);
  6234. Assert.Equal ("", _textView.SelectedText);
  6235. break;
  6236. case 5:
  6237. Assert.Equal (4, _textView.CursorPosition.X);
  6238. Assert.Equal (0, _textView.CursorPosition.Y);
  6239. Assert.Equal (0, _textView.SelectionStartColumn);
  6240. Assert.Equal (0, _textView.SelectionStartRow);
  6241. Assert.Equal (0, _textView.SelectedLength);
  6242. Assert.Equal ("", _textView.SelectedText);
  6243. break;
  6244. case 6:
  6245. Assert.Equal (0, _textView.CursorPosition.X);
  6246. Assert.Equal (0, _textView.CursorPosition.Y);
  6247. Assert.Equal (0, _textView.SelectionStartColumn);
  6248. Assert.Equal (0, _textView.SelectionStartRow);
  6249. Assert.Equal (0, _textView.SelectedLength);
  6250. Assert.Equal ("", _textView.SelectedText);
  6251. break;
  6252. }
  6253. iteration++;
  6254. }
  6255. }
  6256. [Fact]
  6257. [TextViewTestsAutoInitShutdown]
  6258. public void WordBackward_With_No_Selection_And_With_More_Than_Only_One_Whitespace_And_With_Only_One_Letter ()
  6259. {
  6260. // 1 2 3 4 5
  6261. // 0123456789012345678901234567890123456789012345678901234=55 (Length)
  6262. _textView.Text = "TAB t o jump b etween t ext f ields .";
  6263. _textView.CursorPosition = new Point (_textView.Text.Length, 0);
  6264. var iteration = 0;
  6265. while (_textView.CursorPosition.X > 0)
  6266. {
  6267. _textView.NewKeyDownEvent (Key.CursorLeft.WithCtrl);
  6268. switch (iteration)
  6269. {
  6270. case 0:
  6271. Assert.Equal (54, _textView.CursorPosition.X);
  6272. Assert.Equal (0, _textView.CursorPosition.Y);
  6273. Assert.Equal (0, _textView.SelectionStartColumn);
  6274. Assert.Equal (0, _textView.SelectionStartRow);
  6275. Assert.Equal (0, _textView.SelectedLength);
  6276. Assert.Equal ("", _textView.SelectedText);
  6277. break;
  6278. case 1:
  6279. Assert.Equal (48, _textView.CursorPosition.X);
  6280. Assert.Equal (0, _textView.CursorPosition.Y);
  6281. Assert.Equal (0, _textView.SelectionStartColumn);
  6282. Assert.Equal (0, _textView.SelectionStartRow);
  6283. Assert.Equal (0, _textView.SelectedLength);
  6284. Assert.Equal ("", _textView.SelectedText);
  6285. break;
  6286. case 2:
  6287. Assert.Equal (46, _textView.CursorPosition.X);
  6288. Assert.Equal (0, _textView.CursorPosition.Y);
  6289. Assert.Equal (0, _textView.SelectionStartColumn);
  6290. Assert.Equal (0, _textView.SelectionStartRow);
  6291. Assert.Equal (0, _textView.SelectedLength);
  6292. Assert.Equal ("", _textView.SelectedText);
  6293. break;
  6294. case 3:
  6295. Assert.Equal (40, _textView.CursorPosition.X);
  6296. Assert.Equal (0, _textView.CursorPosition.Y);
  6297. Assert.Equal (0, _textView.SelectionStartColumn);
  6298. Assert.Equal (0, _textView.SelectionStartRow);
  6299. Assert.Equal (0, _textView.SelectedLength);
  6300. Assert.Equal ("", _textView.SelectedText);
  6301. break;
  6302. case 4:
  6303. Assert.Equal (38, _textView.CursorPosition.X);
  6304. Assert.Equal (0, _textView.CursorPosition.Y);
  6305. Assert.Equal (0, _textView.SelectionStartColumn);
  6306. Assert.Equal (0, _textView.SelectionStartRow);
  6307. Assert.Equal (0, _textView.SelectedLength);
  6308. Assert.Equal ("", _textView.SelectedText);
  6309. break;
  6310. case 5:
  6311. Assert.Equal (28, _textView.CursorPosition.X);
  6312. Assert.Equal (0, _textView.CursorPosition.Y);
  6313. Assert.Equal (0, _textView.SelectionStartColumn);
  6314. Assert.Equal (0, _textView.SelectionStartRow);
  6315. Assert.Equal (0, _textView.SelectedLength);
  6316. Assert.Equal ("", _textView.SelectedText);
  6317. break;
  6318. case 6:
  6319. Assert.Equal (25, _textView.CursorPosition.X);
  6320. Assert.Equal (0, _textView.CursorPosition.Y);
  6321. Assert.Equal (0, _textView.SelectionStartColumn);
  6322. Assert.Equal (0, _textView.SelectionStartRow);
  6323. Assert.Equal (0, _textView.SelectedLength);
  6324. Assert.Equal ("", _textView.SelectedText);
  6325. break;
  6326. case 7:
  6327. Assert.Equal (12, _textView.CursorPosition.X);
  6328. Assert.Equal (0, _textView.CursorPosition.Y);
  6329. Assert.Equal (0, _textView.SelectionStartColumn);
  6330. Assert.Equal (0, _textView.SelectionStartRow);
  6331. Assert.Equal (0, _textView.SelectedLength);
  6332. Assert.Equal ("", _textView.SelectedText);
  6333. break;
  6334. case 8:
  6335. Assert.Equal (9, _textView.CursorPosition.X);
  6336. Assert.Equal (0, _textView.CursorPosition.Y);
  6337. Assert.Equal (0, _textView.SelectionStartColumn);
  6338. Assert.Equal (0, _textView.SelectionStartRow);
  6339. Assert.Equal (0, _textView.SelectedLength);
  6340. Assert.Equal ("", _textView.SelectedText);
  6341. break;
  6342. case 9:
  6343. Assert.Equal (6, _textView.CursorPosition.X);
  6344. Assert.Equal (0, _textView.CursorPosition.Y);
  6345. Assert.Equal (0, _textView.SelectionStartColumn);
  6346. Assert.Equal (0, _textView.SelectionStartRow);
  6347. Assert.Equal (0, _textView.SelectedLength);
  6348. Assert.Equal ("", _textView.SelectedText);
  6349. break;
  6350. case 10:
  6351. Assert.Equal (0, _textView.CursorPosition.X);
  6352. Assert.Equal (0, _textView.CursorPosition.Y);
  6353. Assert.Equal (0, _textView.SelectionStartColumn);
  6354. Assert.Equal (0, _textView.SelectionStartRow);
  6355. Assert.Equal (0, _textView.SelectedLength);
  6356. Assert.Equal ("", _textView.SelectedText);
  6357. break;
  6358. }
  6359. iteration++;
  6360. }
  6361. }
  6362. [Fact]
  6363. [TextViewTestsAutoInitShutdown]
  6364. public void WordBackward_With_Selection ()
  6365. {
  6366. _textView.CursorPosition = new Point (_textView.Text.Length, 0);
  6367. _textView.SelectionStartColumn = _textView.Text.Length;
  6368. _textView.SelectionStartRow = 0;
  6369. var iteration = 0;
  6370. while (_textView.CursorPosition.X > 0)
  6371. {
  6372. _textView.NewKeyDownEvent (Key.CursorLeft.WithCtrl.WithShift);
  6373. switch (iteration)
  6374. {
  6375. case 0:
  6376. Assert.Equal (31, _textView.CursorPosition.X);
  6377. Assert.Equal (0, _textView.CursorPosition.Y);
  6378. Assert.Equal (32, _textView.SelectionStartColumn);
  6379. Assert.Equal (0, _textView.SelectionStartRow);
  6380. Assert.Equal (1, _textView.SelectedLength);
  6381. Assert.Equal (".", _textView.SelectedText);
  6382. break;
  6383. case 1:
  6384. Assert.Equal (25, _textView.CursorPosition.X);
  6385. Assert.Equal (0, _textView.CursorPosition.Y);
  6386. Assert.Equal (32, _textView.SelectionStartColumn);
  6387. Assert.Equal (0, _textView.SelectionStartRow);
  6388. Assert.Equal (7, _textView.SelectedLength);
  6389. Assert.Equal ("fields.", _textView.SelectedText);
  6390. break;
  6391. case 2:
  6392. Assert.Equal (20, _textView.CursorPosition.X);
  6393. Assert.Equal (0, _textView.CursorPosition.Y);
  6394. Assert.Equal (32, _textView.SelectionStartColumn);
  6395. Assert.Equal (0, _textView.SelectionStartRow);
  6396. Assert.Equal (12, _textView.SelectedLength);
  6397. Assert.Equal ("text fields.", _textView.SelectedText);
  6398. break;
  6399. case 3:
  6400. Assert.Equal (12, _textView.CursorPosition.X);
  6401. Assert.Equal (0, _textView.CursorPosition.Y);
  6402. Assert.Equal (32, _textView.SelectionStartColumn);
  6403. Assert.Equal (0, _textView.SelectionStartRow);
  6404. Assert.Equal (20, _textView.SelectedLength);
  6405. Assert.Equal ("between text fields.", _textView.SelectedText);
  6406. break;
  6407. case 4:
  6408. Assert.Equal (7, _textView.CursorPosition.X);
  6409. Assert.Equal (0, _textView.CursorPosition.Y);
  6410. Assert.Equal (32, _textView.SelectionStartColumn);
  6411. Assert.Equal (0, _textView.SelectionStartRow);
  6412. Assert.Equal (25, _textView.SelectedLength);
  6413. Assert.Equal ("jump between text fields.", _textView.SelectedText);
  6414. break;
  6415. case 5:
  6416. Assert.Equal (4, _textView.CursorPosition.X);
  6417. Assert.Equal (0, _textView.CursorPosition.Y);
  6418. Assert.Equal (32, _textView.SelectionStartColumn);
  6419. Assert.Equal (0, _textView.SelectionStartRow);
  6420. Assert.Equal (28, _textView.SelectedLength);
  6421. Assert.Equal ("to jump between text fields.", _textView.SelectedText);
  6422. break;
  6423. case 6:
  6424. Assert.Equal (0, _textView.CursorPosition.X);
  6425. Assert.Equal (0, _textView.CursorPosition.Y);
  6426. Assert.Equal (32, _textView.SelectionStartColumn);
  6427. Assert.Equal (0, _textView.SelectionStartRow);
  6428. Assert.Equal (32, _textView.SelectedLength);
  6429. Assert.Equal ("TAB to jump between text fields.", _textView.SelectedText);
  6430. break;
  6431. }
  6432. iteration++;
  6433. }
  6434. }
  6435. [Fact]
  6436. [TextViewTestsAutoInitShutdown]
  6437. public void
  6438. WordBackward_With_The_Same_Values_For_SelectedStart_And_CursorPosition_And_Not_Starting_At_Beginning_Of_The_Text ()
  6439. {
  6440. _textView.CursorPosition = new Point (10, 0);
  6441. _textView.SelectionStartColumn = 10;
  6442. _textView.SelectionStartRow = 0;
  6443. var iteration = 0;
  6444. while (_textView.CursorPosition.X > 0)
  6445. {
  6446. _textView.NewKeyDownEvent (Key.CursorLeft.WithCtrl.WithShift);
  6447. switch (iteration)
  6448. {
  6449. case 0:
  6450. Assert.Equal (7, _textView.CursorPosition.X);
  6451. Assert.Equal (0, _textView.CursorPosition.Y);
  6452. Assert.Equal (10, _textView.SelectionStartColumn);
  6453. Assert.Equal (0, _textView.SelectionStartRow);
  6454. Assert.Equal (3, _textView.SelectedLength);
  6455. Assert.Equal ("jum", _textView.SelectedText);
  6456. break;
  6457. case 1:
  6458. Assert.Equal (4, _textView.CursorPosition.X);
  6459. Assert.Equal (0, _textView.CursorPosition.Y);
  6460. Assert.Equal (10, _textView.SelectionStartColumn);
  6461. Assert.Equal (0, _textView.SelectionStartRow);
  6462. Assert.Equal (6, _textView.SelectedLength);
  6463. Assert.Equal ("to jum", _textView.SelectedText);
  6464. break;
  6465. case 2:
  6466. Assert.Equal (0, _textView.CursorPosition.X);
  6467. Assert.Equal (0, _textView.CursorPosition.Y);
  6468. Assert.Equal (10, _textView.SelectionStartColumn);
  6469. Assert.Equal (0, _textView.SelectionStartRow);
  6470. Assert.Equal (10, _textView.SelectedLength);
  6471. Assert.Equal ("TAB to jum", _textView.SelectedText);
  6472. break;
  6473. }
  6474. iteration++;
  6475. }
  6476. }
  6477. [Fact]
  6478. public void WordBackward_WordForward_Limits_Return_Null ()
  6479. {
  6480. var model = new TextModel ();
  6481. model.LoadString ("Test");
  6482. (int col, int row)? newPos = model.WordBackward (0, 0);
  6483. Assert.Null (newPos);
  6484. newPos = model.WordForward (4, 0);
  6485. Assert.Null (newPos);
  6486. }
  6487. [Fact]
  6488. [TextViewTestsAutoInitShutdown]
  6489. public void WordForward_Multiline_With_Selection ()
  6490. {
  6491. // 1 2 3 4
  6492. // 01234567890123456789012 34567890123456789012345678-Length
  6493. // 1 2 1 2
  6494. // 01234567890123456789012 0123456789012345678901234
  6495. _textView.Text = "This is the first line.\nThis is the second line.";
  6496. _textView.SelectionStartColumn = _textView.CurrentColumn;
  6497. _textView.SelectionStartRow = _textView.CurrentRow;
  6498. var iteration = 0;
  6499. var iterationsFinished = false;
  6500. while (!iterationsFinished)
  6501. {
  6502. _textView.NewKeyDownEvent (
  6503. new Key (
  6504. KeyCode.CursorRight | KeyCode.CtrlMask | KeyCode.ShiftMask
  6505. )
  6506. );
  6507. switch (iteration)
  6508. {
  6509. case 0:
  6510. Assert.Equal (5, _textView.CursorPosition.X);
  6511. Assert.Equal (0, _textView.CursorPosition.Y);
  6512. Assert.Equal (0, _textView.SelectionStartColumn);
  6513. Assert.Equal (0, _textView.SelectionStartRow);
  6514. Assert.Equal (5, _textView.SelectedLength);
  6515. Assert.Equal ("This ", _textView.SelectedText);
  6516. break;
  6517. case 1:
  6518. Assert.Equal (8, _textView.CursorPosition.X);
  6519. Assert.Equal (0, _textView.CursorPosition.Y);
  6520. Assert.Equal (0, _textView.SelectionStartColumn);
  6521. Assert.Equal (0, _textView.SelectionStartRow);
  6522. Assert.Equal (8, _textView.SelectedLength);
  6523. Assert.Equal ("This is ", _textView.SelectedText);
  6524. break;
  6525. case 2:
  6526. Assert.Equal (12, _textView.CursorPosition.X);
  6527. Assert.Equal (0, _textView.CursorPosition.Y);
  6528. Assert.Equal (0, _textView.SelectionStartColumn);
  6529. Assert.Equal (0, _textView.SelectionStartRow);
  6530. Assert.Equal (12, _textView.SelectedLength);
  6531. Assert.Equal ("This is the ", _textView.SelectedText);
  6532. break;
  6533. case 3:
  6534. Assert.Equal (18, _textView.CursorPosition.X);
  6535. Assert.Equal (0, _textView.CursorPosition.Y);
  6536. Assert.Equal (0, _textView.SelectionStartColumn);
  6537. Assert.Equal (0, _textView.SelectionStartRow);
  6538. Assert.Equal (18, _textView.SelectedLength);
  6539. Assert.Equal ("This is the first ", _textView.SelectedText);
  6540. break;
  6541. case 4:
  6542. Assert.Equal (23, _textView.CursorPosition.X);
  6543. Assert.Equal (0, _textView.CursorPosition.Y);
  6544. Assert.Equal (0, _textView.SelectionStartColumn);
  6545. Assert.Equal (0, _textView.SelectionStartRow);
  6546. Assert.Equal (23, _textView.SelectedLength);
  6547. Assert.Equal ("This is the first line.", _textView.SelectedText);
  6548. break;
  6549. case 5:
  6550. Assert.Equal (0, _textView.CursorPosition.X);
  6551. Assert.Equal (1, _textView.CursorPosition.Y);
  6552. Assert.Equal (0, _textView.SelectionStartColumn);
  6553. Assert.Equal (0, _textView.SelectionStartRow);
  6554. Assert.Equal (23 + Environment.NewLine.Length, _textView.SelectedLength);
  6555. Assert.Equal ($"This is the first line.{Environment.NewLine}", _textView.SelectedText);
  6556. break;
  6557. case 6:
  6558. Assert.Equal (5, _textView.CursorPosition.X);
  6559. Assert.Equal (1, _textView.CursorPosition.Y);
  6560. Assert.Equal (0, _textView.SelectionStartColumn);
  6561. Assert.Equal (0, _textView.SelectionStartRow);
  6562. Assert.Equal (28 + Environment.NewLine.Length, _textView.SelectedLength);
  6563. Assert.Equal (
  6564. $"This is the first line.{Environment.NewLine}This ",
  6565. _textView.SelectedText
  6566. );
  6567. break;
  6568. case 7:
  6569. Assert.Equal (8, _textView.CursorPosition.X);
  6570. Assert.Equal (1, _textView.CursorPosition.Y);
  6571. Assert.Equal (0, _textView.SelectionStartColumn);
  6572. Assert.Equal (0, _textView.SelectionStartRow);
  6573. Assert.Equal (31 + Environment.NewLine.Length, _textView.SelectedLength);
  6574. Assert.Equal (
  6575. $"This is the first line.{Environment.NewLine}This is ",
  6576. _textView.SelectedText
  6577. );
  6578. break;
  6579. case 8:
  6580. Assert.Equal (12, _textView.CursorPosition.X);
  6581. Assert.Equal (1, _textView.CursorPosition.Y);
  6582. Assert.Equal (0, _textView.SelectionStartColumn);
  6583. Assert.Equal (0, _textView.SelectionStartRow);
  6584. Assert.Equal (35 + Environment.NewLine.Length, _textView.SelectedLength);
  6585. Assert.Equal (
  6586. $"This is the first line.{Environment.NewLine}This is the ",
  6587. _textView.SelectedText
  6588. );
  6589. break;
  6590. case 9:
  6591. Assert.Equal (19, _textView.CursorPosition.X);
  6592. Assert.Equal (1, _textView.CursorPosition.Y);
  6593. Assert.Equal (0, _textView.SelectionStartColumn);
  6594. Assert.Equal (0, _textView.SelectionStartRow);
  6595. Assert.Equal (42 + Environment.NewLine.Length, _textView.SelectedLength);
  6596. Assert.Equal (
  6597. $"This is the first line.{Environment.NewLine}This is the second ",
  6598. _textView.SelectedText
  6599. );
  6600. break;
  6601. case 10:
  6602. Assert.Equal (24, _textView.CursorPosition.X);
  6603. Assert.Equal (1, _textView.CursorPosition.Y);
  6604. Assert.Equal (0, _textView.SelectionStartColumn);
  6605. Assert.Equal (0, _textView.SelectionStartRow);
  6606. Assert.Equal (47 + Environment.NewLine.Length, _textView.SelectedLength);
  6607. Assert.Equal (
  6608. $"This is the first line.{Environment.NewLine}This is the second line.",
  6609. _textView.SelectedText
  6610. );
  6611. break;
  6612. default:
  6613. iterationsFinished = true;
  6614. break;
  6615. }
  6616. iteration++;
  6617. }
  6618. }
  6619. [Fact]
  6620. [TextViewTestsAutoInitShutdown]
  6621. public void WordForward_With_No_Selection ()
  6622. {
  6623. _textView.CursorPosition = Point.Empty;
  6624. var iteration = 0;
  6625. while (_textView.CursorPosition.X < _textView.Text.Length)
  6626. {
  6627. _textView.NewKeyDownEvent (Key.CursorRight.WithCtrl);
  6628. switch (iteration)
  6629. {
  6630. case 0:
  6631. Assert.Equal (4, _textView.CursorPosition.X);
  6632. Assert.Equal (0, _textView.CursorPosition.Y);
  6633. Assert.Equal (0, _textView.SelectionStartColumn);
  6634. Assert.Equal (0, _textView.SelectionStartRow);
  6635. Assert.Equal (0, _textView.SelectedLength);
  6636. Assert.Equal ("", _textView.SelectedText);
  6637. break;
  6638. case 1:
  6639. Assert.Equal (7, _textView.CursorPosition.X);
  6640. Assert.Equal (0, _textView.CursorPosition.Y);
  6641. Assert.Equal (0, _textView.SelectionStartColumn);
  6642. Assert.Equal (0, _textView.SelectionStartRow);
  6643. Assert.Equal (0, _textView.SelectedLength);
  6644. Assert.Equal ("", _textView.SelectedText);
  6645. break;
  6646. case 2:
  6647. Assert.Equal (12, _textView.CursorPosition.X);
  6648. Assert.Equal (0, _textView.CursorPosition.Y);
  6649. Assert.Equal (0, _textView.SelectionStartColumn);
  6650. Assert.Equal (0, _textView.SelectionStartRow);
  6651. Assert.Equal (0, _textView.SelectedLength);
  6652. Assert.Equal ("", _textView.SelectedText);
  6653. break;
  6654. case 3:
  6655. Assert.Equal (20, _textView.CursorPosition.X);
  6656. Assert.Equal (0, _textView.CursorPosition.Y);
  6657. Assert.Equal (0, _textView.SelectionStartColumn);
  6658. Assert.Equal (0, _textView.SelectionStartRow);
  6659. Assert.Equal (0, _textView.SelectedLength);
  6660. Assert.Equal ("", _textView.SelectedText);
  6661. break;
  6662. case 4:
  6663. Assert.Equal (25, _textView.CursorPosition.X);
  6664. Assert.Equal (0, _textView.CursorPosition.Y);
  6665. Assert.Equal (0, _textView.SelectionStartColumn);
  6666. Assert.Equal (0, _textView.SelectionStartRow);
  6667. Assert.Equal (0, _textView.SelectedLength);
  6668. Assert.Equal ("", _textView.SelectedText);
  6669. break;
  6670. case 5:
  6671. Assert.Equal (32, _textView.CursorPosition.X);
  6672. Assert.Equal (0, _textView.CursorPosition.Y);
  6673. Assert.Equal (0, _textView.SelectionStartColumn);
  6674. Assert.Equal (0, _textView.SelectionStartRow);
  6675. Assert.Equal (0, _textView.SelectedLength);
  6676. Assert.Equal ("", _textView.SelectedText);
  6677. break;
  6678. }
  6679. iteration++;
  6680. }
  6681. }
  6682. [Fact]
  6683. [TextViewTestsAutoInitShutdown]
  6684. public void WordForward_With_No_Selection_And_With_More_Than_Only_One_Whitespace_And_With_Only_One_Letter ()
  6685. {
  6686. // 1 2 3 4 5
  6687. // 0123456789012345678901234567890123456789012345678901234=55 (Length)
  6688. _textView.Text = "TAB t o jump b etween t ext f ields .";
  6689. _textView.CursorPosition = Point.Empty;
  6690. var iteration = 0;
  6691. while (_textView.CursorPosition.X < _textView.Text.Length)
  6692. {
  6693. _textView.NewKeyDownEvent (Key.CursorRight.WithCtrl);
  6694. switch (iteration)
  6695. {
  6696. case 0:
  6697. Assert.Equal (6, _textView.CursorPosition.X);
  6698. Assert.Equal (0, _textView.CursorPosition.Y);
  6699. Assert.Equal (0, _textView.SelectionStartColumn);
  6700. Assert.Equal (0, _textView.SelectionStartRow);
  6701. Assert.Equal (0, _textView.SelectedLength);
  6702. Assert.Equal ("", _textView.SelectedText);
  6703. break;
  6704. case 1:
  6705. Assert.Equal (9, _textView.CursorPosition.X);
  6706. Assert.Equal (0, _textView.CursorPosition.Y);
  6707. Assert.Equal (0, _textView.SelectionStartColumn);
  6708. Assert.Equal (0, _textView.SelectionStartRow);
  6709. Assert.Equal (0, _textView.SelectedLength);
  6710. Assert.Equal ("", _textView.SelectedText);
  6711. break;
  6712. case 2:
  6713. Assert.Equal (12, _textView.CursorPosition.X);
  6714. Assert.Equal (0, _textView.CursorPosition.Y);
  6715. Assert.Equal (0, _textView.SelectionStartColumn);
  6716. Assert.Equal (0, _textView.SelectionStartRow);
  6717. Assert.Equal (0, _textView.SelectedLength);
  6718. Assert.Equal ("", _textView.SelectedText);
  6719. break;
  6720. case 3:
  6721. Assert.Equal (25, _textView.CursorPosition.X);
  6722. Assert.Equal (0, _textView.CursorPosition.Y);
  6723. Assert.Equal (0, _textView.SelectionStartColumn);
  6724. Assert.Equal (0, _textView.SelectionStartRow);
  6725. Assert.Equal (0, _textView.SelectedLength);
  6726. Assert.Equal ("", _textView.SelectedText);
  6727. break;
  6728. case 4:
  6729. Assert.Equal (28, _textView.CursorPosition.X);
  6730. Assert.Equal (0, _textView.CursorPosition.Y);
  6731. Assert.Equal (0, _textView.SelectionStartColumn);
  6732. Assert.Equal (0, _textView.SelectionStartRow);
  6733. Assert.Equal (0, _textView.SelectedLength);
  6734. Assert.Equal ("", _textView.SelectedText);
  6735. break;
  6736. case 5:
  6737. Assert.Equal (38, _textView.CursorPosition.X);
  6738. Assert.Equal (0, _textView.CursorPosition.Y);
  6739. Assert.Equal (0, _textView.SelectionStartColumn);
  6740. Assert.Equal (0, _textView.SelectionStartRow);
  6741. Assert.Equal (0, _textView.SelectedLength);
  6742. Assert.Equal ("", _textView.SelectedText);
  6743. break;
  6744. case 6:
  6745. Assert.Equal (40, _textView.CursorPosition.X);
  6746. Assert.Equal (0, _textView.CursorPosition.Y);
  6747. Assert.Equal (0, _textView.SelectionStartColumn);
  6748. Assert.Equal (0, _textView.SelectionStartRow);
  6749. Assert.Equal (0, _textView.SelectedLength);
  6750. Assert.Equal ("", _textView.SelectedText);
  6751. break;
  6752. case 7:
  6753. Assert.Equal (46, _textView.CursorPosition.X);
  6754. Assert.Equal (0, _textView.CursorPosition.Y);
  6755. Assert.Equal (0, _textView.SelectionStartColumn);
  6756. Assert.Equal (0, _textView.SelectionStartRow);
  6757. Assert.Equal (0, _textView.SelectedLength);
  6758. Assert.Equal ("", _textView.SelectedText);
  6759. break;
  6760. case 8:
  6761. Assert.Equal (48, _textView.CursorPosition.X);
  6762. Assert.Equal (0, _textView.CursorPosition.Y);
  6763. Assert.Equal (0, _textView.SelectionStartColumn);
  6764. Assert.Equal (0, _textView.SelectionStartRow);
  6765. Assert.Equal (0, _textView.SelectedLength);
  6766. Assert.Equal ("", _textView.SelectedText);
  6767. break;
  6768. case 9:
  6769. Assert.Equal (54, _textView.CursorPosition.X);
  6770. Assert.Equal (0, _textView.CursorPosition.Y);
  6771. Assert.Equal (0, _textView.SelectionStartColumn);
  6772. Assert.Equal (0, _textView.SelectionStartRow);
  6773. Assert.Equal (0, _textView.SelectedLength);
  6774. Assert.Equal ("", _textView.SelectedText);
  6775. break;
  6776. case 10:
  6777. Assert.Equal (55, _textView.CursorPosition.X);
  6778. Assert.Equal (0, _textView.CursorPosition.Y);
  6779. Assert.Equal (0, _textView.SelectionStartColumn);
  6780. Assert.Equal (0, _textView.SelectionStartRow);
  6781. Assert.Equal (0, _textView.SelectedLength);
  6782. Assert.Equal ("", _textView.SelectedText);
  6783. break;
  6784. }
  6785. iteration++;
  6786. }
  6787. }
  6788. [Fact]
  6789. [TextViewTestsAutoInitShutdown]
  6790. public void WordForward_With_Selection ()
  6791. {
  6792. _textView.CursorPosition = Point.Empty;
  6793. _textView.SelectionStartColumn = 0;
  6794. _textView.SelectionStartRow = 0;
  6795. var iteration = 0;
  6796. while (_textView.CursorPosition.X < _textView.Text.Length)
  6797. {
  6798. _textView.NewKeyDownEvent (
  6799. new Key (
  6800. KeyCode.CursorRight | KeyCode.CtrlMask | KeyCode.ShiftMask
  6801. )
  6802. );
  6803. switch (iteration)
  6804. {
  6805. case 0:
  6806. Assert.Equal (4, _textView.CursorPosition.X);
  6807. Assert.Equal (0, _textView.CursorPosition.Y);
  6808. Assert.Equal (0, _textView.SelectionStartColumn);
  6809. Assert.Equal (0, _textView.SelectionStartRow);
  6810. Assert.Equal (4, _textView.SelectedLength);
  6811. Assert.Equal ("TAB ", _textView.SelectedText);
  6812. break;
  6813. case 1:
  6814. Assert.Equal (7, _textView.CursorPosition.X);
  6815. Assert.Equal (0, _textView.CursorPosition.Y);
  6816. Assert.Equal (0, _textView.SelectionStartColumn);
  6817. Assert.Equal (0, _textView.SelectionStartRow);
  6818. Assert.Equal (7, _textView.SelectedLength);
  6819. Assert.Equal ("TAB to ", _textView.SelectedText);
  6820. break;
  6821. case 2:
  6822. Assert.Equal (12, _textView.CursorPosition.X);
  6823. Assert.Equal (0, _textView.CursorPosition.Y);
  6824. Assert.Equal (0, _textView.SelectionStartColumn);
  6825. Assert.Equal (0, _textView.SelectionStartRow);
  6826. Assert.Equal (12, _textView.SelectedLength);
  6827. Assert.Equal ("TAB to jump ", _textView.SelectedText);
  6828. break;
  6829. case 3:
  6830. Assert.Equal (20, _textView.CursorPosition.X);
  6831. Assert.Equal (0, _textView.CursorPosition.Y);
  6832. Assert.Equal (0, _textView.SelectionStartColumn);
  6833. Assert.Equal (0, _textView.SelectionStartRow);
  6834. Assert.Equal (20, _textView.SelectedLength);
  6835. Assert.Equal ("TAB to jump between ", _textView.SelectedText);
  6836. break;
  6837. case 4:
  6838. Assert.Equal (25, _textView.CursorPosition.X);
  6839. Assert.Equal (0, _textView.CursorPosition.Y);
  6840. Assert.Equal (0, _textView.SelectionStartColumn);
  6841. Assert.Equal (0, _textView.SelectionStartRow);
  6842. Assert.Equal (25, _textView.SelectedLength);
  6843. Assert.Equal ("TAB to jump between text ", _textView.SelectedText);
  6844. break;
  6845. case 5:
  6846. Assert.Equal (32, _textView.CursorPosition.X);
  6847. Assert.Equal (0, _textView.CursorPosition.Y);
  6848. Assert.Equal (0, _textView.SelectionStartColumn);
  6849. Assert.Equal (0, _textView.SelectionStartRow);
  6850. Assert.Equal (32, _textView.SelectedLength);
  6851. Assert.Equal ("TAB to jump between text fields.", _textView.SelectedText);
  6852. break;
  6853. }
  6854. iteration++;
  6855. }
  6856. }
  6857. [Fact]
  6858. [TextViewTestsAutoInitShutdown]
  6859. public void
  6860. WordForward_With_The_Same_Values_For_SelectedStart_And_CursorPosition_And_Not_Starting_At_Beginning_Of_The_Text ()
  6861. {
  6862. _textView.CursorPosition = new Point (10, 0);
  6863. _textView.SelectionStartColumn = 10;
  6864. _textView.SelectionStartRow = 0;
  6865. var iteration = 0;
  6866. while (_textView.CursorPosition.X < _textView.Text.Length)
  6867. {
  6868. _textView.NewKeyDownEvent (
  6869. new Key (
  6870. KeyCode.CursorRight | KeyCode.CtrlMask | KeyCode.ShiftMask
  6871. )
  6872. );
  6873. switch (iteration)
  6874. {
  6875. case 0:
  6876. Assert.Equal (12, _textView.CursorPosition.X);
  6877. Assert.Equal (0, _textView.CursorPosition.Y);
  6878. Assert.Equal (10, _textView.SelectionStartColumn);
  6879. Assert.Equal (0, _textView.SelectionStartRow);
  6880. Assert.Equal (2, _textView.SelectedLength);
  6881. Assert.Equal ("p ", _textView.SelectedText);
  6882. break;
  6883. case 1:
  6884. Assert.Equal (20, _textView.CursorPosition.X);
  6885. Assert.Equal (0, _textView.CursorPosition.Y);
  6886. Assert.Equal (10, _textView.SelectionStartColumn);
  6887. Assert.Equal (0, _textView.SelectionStartRow);
  6888. Assert.Equal (10, _textView.SelectedLength);
  6889. Assert.Equal ("p between ", _textView.SelectedText);
  6890. break;
  6891. case 2:
  6892. Assert.Equal (25, _textView.CursorPosition.X);
  6893. Assert.Equal (0, _textView.CursorPosition.Y);
  6894. Assert.Equal (10, _textView.SelectionStartColumn);
  6895. Assert.Equal (0, _textView.SelectionStartRow);
  6896. Assert.Equal (15, _textView.SelectedLength);
  6897. Assert.Equal ("p between text ", _textView.SelectedText);
  6898. break;
  6899. case 3:
  6900. Assert.Equal (32, _textView.CursorPosition.X);
  6901. Assert.Equal (0, _textView.CursorPosition.Y);
  6902. Assert.Equal (10, _textView.SelectionStartColumn);
  6903. Assert.Equal (0, _textView.SelectionStartRow);
  6904. Assert.Equal (22, _textView.SelectedLength);
  6905. Assert.Equal ("p between text fields.", _textView.SelectedText);
  6906. break;
  6907. }
  6908. iteration++;
  6909. }
  6910. }
  6911. [Fact]
  6912. [AutoInitShutdown]
  6913. public void WordWrap_Deleting_Backwards ()
  6914. {
  6915. var tv = new TextView { Width = 5, Height = 2, WordWrap = true, Text = "aaaa" };
  6916. var top = new Toplevel ();
  6917. top.Add (tv);
  6918. Application.Begin (top);
  6919. Application.LayoutAndDraw ();
  6920. Assert.Equal (Point.Empty, tv.CursorPosition);
  6921. Assert.Equal (0, tv.LeftColumn);
  6922. TestHelpers.AssertDriverContentsAre (
  6923. @"
  6924. aaaa
  6925. ",
  6926. _output
  6927. );
  6928. tv.CursorPosition = new Point (5, 0);
  6929. Assert.True (tv.NewKeyDownEvent (Key.Backspace));
  6930. Application.LayoutAndDraw ();
  6931. Assert.Equal (0, tv.LeftColumn);
  6932. TestHelpers.AssertDriverContentsAre (
  6933. @"
  6934. aaa
  6935. ",
  6936. _output
  6937. );
  6938. Assert.True (tv.NewKeyDownEvent (Key.Backspace));
  6939. Application.LayoutAndDraw ();
  6940. Assert.Equal (0, tv.LeftColumn);
  6941. TestHelpers.AssertDriverContentsAre (
  6942. @"
  6943. aa
  6944. ",
  6945. _output
  6946. );
  6947. Assert.True (tv.NewKeyDownEvent (Key.Backspace));
  6948. Application.LayoutAndDraw ();
  6949. Assert.Equal (0, tv.LeftColumn);
  6950. TestHelpers.AssertDriverContentsAre (
  6951. @"
  6952. a
  6953. ",
  6954. _output
  6955. );
  6956. Assert.True (tv.NewKeyDownEvent (Key.Backspace));
  6957. Application.LayoutAndDraw ();
  6958. Assert.Equal (0, tv.LeftColumn);
  6959. TestHelpers.AssertDriverContentsAre (
  6960. @"
  6961. ",
  6962. _output
  6963. );
  6964. Assert.True (tv.NewKeyDownEvent (Key.Backspace));
  6965. Application.LayoutAndDraw ();
  6966. Assert.Equal (0, tv.LeftColumn);
  6967. TestHelpers.AssertDriverContentsAre (
  6968. @"
  6969. ",
  6970. _output
  6971. );
  6972. top.Dispose ();
  6973. }
  6974. [Theory]
  6975. [TextViewTestsAutoInitShutdown]
  6976. [InlineData (KeyCode.Delete)]
  6977. public void WordWrap_Draw_Typed_Keys_After_Text_Is_Deleted (KeyCode del)
  6978. {
  6979. var top = new Toplevel ();
  6980. top.Add (_textView);
  6981. _textView.Text = "Line 1.\nLine 2.";
  6982. _textView.WordWrap = true;
  6983. Application.Begin (top);
  6984. Application.LayoutAndDraw ();
  6985. Assert.True (_textView.WordWrap);
  6986. TestHelpers.AssertDriverContentsWithFrameAre (
  6987. @"
  6988. Line 1.
  6989. Line 2.",
  6990. _output
  6991. );
  6992. Assert.True (_textView.NewKeyDownEvent (Key.End.WithShift));
  6993. Assert.Equal ("Line 1.", _textView.SelectedText);
  6994. Assert.True (_textView.NewKeyDownEvent (new Key (del)));
  6995. Application.LayoutAndDraw ();
  6996. TestHelpers.AssertDriverContentsWithFrameAre ("Line 2.", _output);
  6997. Assert.True (_textView.NewKeyDownEvent (Key.H.WithShift));
  6998. Assert.NotEqual (Rectangle.Empty, _textView._needsDrawRect);
  6999. Application.LayoutAndDraw ();
  7000. TestHelpers.AssertDriverContentsWithFrameAre (
  7001. @"
  7002. H
  7003. Line 2.",
  7004. _output
  7005. );
  7006. top.Dispose ();
  7007. }
  7008. [Fact]
  7009. public void WordWrap_Gets_Sets ()
  7010. {
  7011. var tv = new TextView { WordWrap = true };
  7012. Assert.True (tv.WordWrap);
  7013. tv.WordWrap = false;
  7014. Assert.False (tv.WordWrap);
  7015. }
  7016. [Fact]
  7017. [AutoInitShutdown]
  7018. public void WordWrap_Not_Throw_If_Width_Is_Less_Than_Zero ()
  7019. {
  7020. Exception exception = Record.Exception (
  7021. () =>
  7022. {
  7023. var tv = new TextView
  7024. {
  7025. Width = Dim.Fill (),
  7026. Height = Dim.Fill (),
  7027. WordWrap = true,
  7028. Text = "これは、左右のクリップ境界をテストするための非常に長いテキストです。"
  7029. };
  7030. }
  7031. );
  7032. Assert.Null (exception);
  7033. }
  7034. [Fact]
  7035. [AutoInitShutdown]
  7036. public void WordWrap_ReadOnly_CursorPosition_SelectedText_Copy ()
  7037. {
  7038. // 0123456789
  7039. var text = "This is the first line.\nThis is the second line.\n";
  7040. var tv = new TextView { Width = 11, Height = 9 };
  7041. tv.Text = text;
  7042. Assert.Equal (
  7043. $"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}",
  7044. tv.Text
  7045. );
  7046. tv.WordWrap = true;
  7047. var top = new Toplevel ();
  7048. top.Add (tv);
  7049. top.Layout ();
  7050. tv.Draw ();
  7051. TestHelpers.AssertDriverContentsWithFrameAre (
  7052. @"
  7053. This is
  7054. the first
  7055. line.
  7056. This is
  7057. the
  7058. second
  7059. line.
  7060. ",
  7061. _output
  7062. );
  7063. tv.ReadOnly = true;
  7064. tv.CursorPosition = new Point (6, 2);
  7065. Assert.Equal (new Point (5, 2), tv.CursorPosition);
  7066. top.LayoutSubviews ();
  7067. View.SetClipToScreen ();
  7068. tv.Draw ();
  7069. TestHelpers.AssertDriverContentsWithFrameAre (
  7070. @"
  7071. This is
  7072. the first
  7073. line.
  7074. This is
  7075. the second
  7076. line.
  7077. ",
  7078. _output
  7079. );
  7080. tv.SelectionStartRow = 0;
  7081. tv.SelectionStartColumn = 0;
  7082. Assert.Equal ("This is the first line.", tv.SelectedText);
  7083. tv.Copy ();
  7084. Assert.Equal ("This is the first line.", Clipboard.Contents);
  7085. }
  7086. [Fact]
  7087. [TextViewTestsAutoInitShutdown]
  7088. public void WordWrap_True_LoadStream_New_Text ()
  7089. {
  7090. Assert.Equal ("TAB to jump between text fields.", _textView.Text);
  7091. _textView.WordWrap = true;
  7092. Assert.Equal ("TAB to jump between text fields.", _textView.Text);
  7093. var text = "This is the first line.\nThis is the second line.\n";
  7094. using (var stream = new MemoryStream ())
  7095. {
  7096. var writer = new StreamWriter (stream);
  7097. writer.Write (text);
  7098. writer.Flush ();
  7099. stream.Position = 0;
  7100. _textView.Load (stream);
  7101. Assert.Equal (
  7102. $"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}",
  7103. _textView.Text
  7104. );
  7105. Assert.True (_textView.WordWrap);
  7106. }
  7107. }
  7108. [Fact]
  7109. public void WordWrap_True_Text_Always_Returns_Unwrapped ()
  7110. {
  7111. var text = "This is the first line.\nThis is the second line.\n";
  7112. var tv = new TextView { Width = 10 };
  7113. tv.Text = text;
  7114. Assert.Equal (
  7115. $"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}",
  7116. tv.Text
  7117. );
  7118. tv.WordWrap = true;
  7119. Assert.Equal (
  7120. $"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}",
  7121. tv.Text
  7122. );
  7123. }
  7124. [Fact]
  7125. [TextViewTestsAutoInitShutdown]
  7126. public void WordWrap_WrapModel_Output ()
  7127. {
  7128. // 0123456789
  7129. var text = "This is the first line.\nThis is the second line.\n";
  7130. var tv = new TextView { Width = 10, Height = 10 };
  7131. tv.Text = text;
  7132. Assert.Equal (
  7133. $"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}",
  7134. tv.Text
  7135. );
  7136. tv.WordWrap = true;
  7137. var top = new Toplevel ();
  7138. top.Add (tv);
  7139. top.Layout ();
  7140. tv.Draw ();
  7141. TestHelpers.AssertDriverContentsWithFrameAre (
  7142. @"
  7143. This is
  7144. the
  7145. first
  7146. line.
  7147. This is
  7148. the
  7149. second
  7150. line.
  7151. ",
  7152. _output
  7153. );
  7154. }
  7155. private int GetLeftCol (int start)
  7156. {
  7157. string [] lines = _textView.Text.Split (Environment.NewLine);
  7158. if (lines == null || lines.Length == 0)
  7159. {
  7160. return 0;
  7161. }
  7162. if (start == _textView.LeftColumn)
  7163. {
  7164. return start;
  7165. }
  7166. if (_textView.LeftColumn == _textView.CurrentColumn)
  7167. {
  7168. return _textView.CurrentColumn;
  7169. }
  7170. int cCol = _textView.CurrentColumn;
  7171. string line = lines [_textView.CurrentRow];
  7172. int lCount = cCol > line.Length - 1 ? line.Length - 1 : cCol;
  7173. int width = _textView.Frame.Width;
  7174. int tabWidth = _textView.TabWidth;
  7175. var sumLength = 0;
  7176. var col = 0;
  7177. for (int i = lCount; i >= 0; i--)
  7178. {
  7179. char r = line [i];
  7180. sumLength += ((Rune)r).GetColumns ();
  7181. if (r == '\t')
  7182. {
  7183. sumLength += tabWidth + 1;
  7184. }
  7185. if (sumLength > width)
  7186. {
  7187. if (col + width == cCol)
  7188. {
  7189. col++;
  7190. }
  7191. break;
  7192. }
  7193. if ((cCol < line.Length && col > 0 && start < cCol && col == start) || cCol - col == width - 1)
  7194. {
  7195. break;
  7196. }
  7197. col = i;
  7198. }
  7199. return col;
  7200. }
  7201. // This class enables test functions annotated with the [InitShutdown] attribute
  7202. // to have a function called before the test function is called and after.
  7203. //
  7204. // This is necessary because a) Application is a singleton and Init/Shutdown must be called
  7205. // as a pair, and b) all unit test functions should be atomic.
  7206. [AttributeUsage (AttributeTargets.Class | AttributeTargets.Method)]
  7207. public class TextViewTestsAutoInitShutdown : AutoInitShutdownAttribute
  7208. {
  7209. public static string Txt = "TAB to jump between text fields.";
  7210. public TextViewTestsAutoInitShutdown () : base (configLocation: ConfigLocations.Default) { }
  7211. public override void After (MethodInfo methodUnderTest)
  7212. {
  7213. _textView = null;
  7214. base.After (methodUnderTest);
  7215. }
  7216. public override void Before (MethodInfo methodUnderTest)
  7217. {
  7218. FakeDriver.FakeBehaviors.UseFakeClipboard = true;
  7219. base.Before (methodUnderTest);
  7220. // 1 2 3
  7221. // 01234567890123456789012345678901=32 (Length)
  7222. byte [] buff = Encoding.Unicode.GetBytes (Txt);
  7223. byte [] ms = new MemoryStream (buff).ToArray ();
  7224. _textView = new TextView { Width = 30, Height = 10, ColorScheme = Colors.ColorSchemes ["Base"] };
  7225. _textView.Text = Encoding.Unicode.GetString (ms);
  7226. }
  7227. }
  7228. [Fact]
  7229. public void HotKey_Command_SetsFocus ()
  7230. {
  7231. var view = new TextView ();
  7232. view.CanFocus = true;
  7233. Assert.False (view.HasFocus);
  7234. view.InvokeCommand (Command.HotKey);
  7235. Assert.True (view.HasFocus);
  7236. }
  7237. [Fact]
  7238. public void HotKey_Command_Does_Not_Accept ()
  7239. {
  7240. var view = new TextView ();
  7241. var accepted = false;
  7242. view.Accepting += OnAccept;
  7243. view.InvokeCommand (Command.HotKey);
  7244. Assert.False (accepted);
  7245. return;
  7246. void OnAccept (object sender, CommandEventArgs e) { accepted = true; }
  7247. }
  7248. [Theory]
  7249. [InlineData (false, 1)]
  7250. [InlineData (true, 1)]
  7251. public void Accepted_Command_Raises_Accepted_Regardles_Of_AllowsReturn (bool allowsReturn, int expectedAcceptEvents)
  7252. {
  7253. var view = new TextView ()
  7254. {
  7255. AllowsReturn = allowsReturn,
  7256. };
  7257. int acceptedEvents = 0;
  7258. view.Accepting += Accept;
  7259. view.InvokeCommand (Command.Accept);
  7260. Assert.Equal (expectedAcceptEvents, acceptedEvents);
  7261. return;
  7262. void Accept (object sender, CommandEventArgs e) { acceptedEvents++; }
  7263. }
  7264. [Theory]
  7265. [InlineData (false, 1)]
  7266. [InlineData (true, 0)]
  7267. public void Enter_Key_Fires_Accepted_BasedOn_AllowsReturn (bool allowsReturn, int expectedAccepts)
  7268. {
  7269. var view = new TextView ()
  7270. {
  7271. Multiline = allowsReturn,
  7272. };
  7273. int accepted = 0;
  7274. view.Accepting += Accept;
  7275. view.NewKeyDownEvent (Key.Enter);
  7276. Assert.Equal (expectedAccepts, accepted);
  7277. return;
  7278. void Accept (object sender, CommandEventArgs e) { accepted++; }
  7279. }
  7280. [Theory]
  7281. [InlineData (false, 1)]
  7282. [InlineData (true, 0)]
  7283. public void Enter_Key_Fires_Accepted_BasedOn_Multiline (bool multiline, int expectedAccepts)
  7284. {
  7285. var view = new TextView ()
  7286. {
  7287. Multiline = multiline,
  7288. };
  7289. int accepted = 0;
  7290. view.Accepting += Accept;
  7291. view.NewKeyDownEvent (Key.Enter);
  7292. Assert.Equal (expectedAccepts, accepted);
  7293. return;
  7294. void Accept (object sender, CommandEventArgs e) { accepted++; }
  7295. }
  7296. [Fact]
  7297. public void Space_Key_Types_Space ()
  7298. {
  7299. var view = new TextView ()
  7300. {
  7301. };
  7302. view.NewKeyDownEvent (Key.Space);
  7303. Assert.Equal (" ", view.Text);
  7304. }
  7305. [Theory]
  7306. [InlineData (false, false, 1, 1)]
  7307. [InlineData (false, true, 1, 0)]
  7308. [InlineData (true, false, 0, 0)]
  7309. [InlineData (true, true, 0, 0)]
  7310. public void Accepted_Event_Handled_Prevents_Default_Button_Accept (bool multiline, bool handleAccept, int expectedAccepts, int expectedButtonAccepts)
  7311. {
  7312. var superView = new Window ();
  7313. var tv = new TextView ()
  7314. {
  7315. Multiline = multiline
  7316. };
  7317. var button = new Button ()
  7318. {
  7319. IsDefault = true,
  7320. };
  7321. superView.Add (tv, button);
  7322. var buttonAccept = 0;
  7323. button.Accepting += ButtonAccept;
  7324. var textViewAccept = 0;
  7325. tv.Accepting += TextViewAccept;
  7326. tv.SetFocus ();
  7327. Assert.True (tv.HasFocus);
  7328. superView.NewKeyDownEvent (Key.Enter);
  7329. Assert.Equal (expectedAccepts, textViewAccept);
  7330. Assert.Equal (expectedButtonAccepts, buttonAccept);
  7331. button.SetFocus ();
  7332. superView.NewKeyDownEvent (Key.Enter);
  7333. Assert.Equal (expectedAccepts, textViewAccept);
  7334. Assert.Equal (expectedButtonAccepts + 1, buttonAccept);
  7335. return;
  7336. void TextViewAccept (object sender, CommandEventArgs e)
  7337. {
  7338. textViewAccept++;
  7339. e.Cancel = handleAccept;
  7340. }
  7341. void ButtonAccept (object sender, CommandEventArgs e)
  7342. {
  7343. buttonAccept++;
  7344. }
  7345. }
  7346. [Theory]
  7347. [InlineData (true, 0)]
  7348. [InlineData (false, 1)]
  7349. public void Accepted_No_Handler_Enables_Default_Button_Accept (bool multiline, int expectedButtonAccept)
  7350. {
  7351. var superView = new Window ();
  7352. var tv = new TextView ()
  7353. {
  7354. Multiline = multiline
  7355. };
  7356. var button = new Button ()
  7357. {
  7358. IsDefault = true,
  7359. };
  7360. superView.Add (tv, button);
  7361. var buttonAccept = 0;
  7362. button.Accepting += ButtonAccept;
  7363. tv.SetFocus ();
  7364. Assert.True (tv.HasFocus);
  7365. superView.NewKeyDownEvent (Key.Enter);
  7366. Assert.Equal (expectedButtonAccept, buttonAccept);
  7367. button.SetFocus ();
  7368. superView.NewKeyDownEvent (Key.Enter);
  7369. Assert.Equal (expectedButtonAccept + 1, buttonAccept);
  7370. return;
  7371. void ButtonAccept (object sender, CommandEventArgs e)
  7372. {
  7373. buttonAccept++;
  7374. }
  7375. }
  7376. [Fact]
  7377. public void Autocomplete_Popup_Added_To_SuperView_On_Init ()
  7378. {
  7379. View superView = new ()
  7380. {
  7381. CanFocus = true,
  7382. };
  7383. TextView t = new ();
  7384. superView.Add (t);
  7385. Assert.Single (superView.Subviews);
  7386. superView.BeginInit ();
  7387. superView.EndInit ();
  7388. Assert.Equal (2, superView.Subviews.Count);
  7389. }
  7390. [Fact]
  7391. public void Autocomplete__Added_To_SuperView_On_Add ()
  7392. {
  7393. View superView = new ()
  7394. {
  7395. CanFocus = true,
  7396. Id = "superView",
  7397. };
  7398. superView.BeginInit ();
  7399. superView.EndInit ();
  7400. Assert.Empty (superView.Subviews);
  7401. TextView t = new ()
  7402. {
  7403. Id = "t"
  7404. };
  7405. superView.Add (t);
  7406. Assert.Equal (2, superView.Subviews.Count);
  7407. }
  7408. [Fact]
  7409. public void Autocomplete_Visible_False_By_Default ()
  7410. {
  7411. View superView = new ()
  7412. {
  7413. CanFocus = true,
  7414. };
  7415. TextView t = new ();
  7416. superView.Add (t);
  7417. superView.BeginInit ();
  7418. superView.EndInit ();
  7419. Assert.Equal (2, superView.Subviews.Count);
  7420. Assert.True (t.Visible);
  7421. Assert.False (t.Autocomplete.Visible);
  7422. }
  7423. [Fact]
  7424. public void Right_CursorAtEnd_WithSelection_ShouldClearSelection ()
  7425. {
  7426. var tv = new TextView
  7427. {
  7428. Text = "Hello",
  7429. };
  7430. tv.SetFocus ();
  7431. tv.NewKeyDownEvent (Key.End.WithShift);
  7432. Assert.Equal (5, tv.CursorPosition.X);
  7433. // When there is selected text and the cursor is at the end of the text field
  7434. Assert.Equal ("Hello", tv.SelectedText);
  7435. // Pressing right should not move focus, instead it should clear selection
  7436. Assert.True (tv.NewKeyDownEvent (Key.CursorRight));
  7437. Assert.Empty (tv.SelectedText);
  7438. // Now that the selection is cleared another right keypress should move focus
  7439. Assert.False (tv.NewKeyDownEvent (Key.CursorRight));
  7440. }
  7441. [Fact]
  7442. public void Left_CursorAtStart_WithSelection_ShouldClearSelection ()
  7443. {
  7444. var tv = new TextView
  7445. {
  7446. Text = "Hello",
  7447. };
  7448. tv.SetFocus ();
  7449. tv.NewKeyDownEvent (Key.CursorRight);
  7450. tv.NewKeyDownEvent (Key.CursorRight);
  7451. Assert.Equal (2, tv.CursorPosition.X);
  7452. Assert.True (tv.NewKeyDownEvent (Key.CursorLeft.WithShift));
  7453. Assert.True (tv.NewKeyDownEvent (Key.CursorLeft.WithShift));
  7454. // When there is selected text and the cursor is at the start of the text field
  7455. Assert.Equal ("He", tv.SelectedText);
  7456. // Pressing left should not move focus, instead it should clear selection
  7457. Assert.True (tv.NewKeyDownEvent (Key.CursorLeft));
  7458. Assert.Empty (tv.SelectedText);
  7459. // When clearing selected text with left the cursor should be at the start of the selection
  7460. Assert.Equal (0, tv.CursorPosition.X);
  7461. // Now that the selection is cleared another left keypress should move focus
  7462. Assert.False (tv.NewKeyDownEvent (Key.CursorLeft));
  7463. }
  7464. [Fact]
  7465. [AutoInitShutdown]
  7466. public void Draw_Esc_Rune ()
  7467. {
  7468. var tv = new TextView { Width = 5, Height = 1, Text = "\u001b" };
  7469. tv.BeginInit ();
  7470. tv.EndInit ();
  7471. tv.Draw ();
  7472. TestHelpers.AssertDriverContentsWithFrameAre ("\u241b", _output);
  7473. tv.Dispose ();
  7474. }
  7475. [Fact]
  7476. public void Equals_True ()
  7477. {
  7478. var c1 = new Cell ();
  7479. var c2 = new Cell ();
  7480. Assert.True (c1.Equals (c2));
  7481. Assert.True (c2.Equals (c1));
  7482. c1.Rune = new ('a');
  7483. c1.Attribute = new ();
  7484. c2.Rune = new ('a');
  7485. c2.Attribute = new ();
  7486. Assert.True (c1.Equals (c2));
  7487. Assert.True (c2.Equals (c1));
  7488. }
  7489. [Fact]
  7490. [AutoInitShutdown]
  7491. public void CellEventArgs_WordWrap_True ()
  7492. {
  7493. var eventCount = 0;
  7494. List<List<Cell>> text =
  7495. [
  7496. Cell.ToCells (
  7497. "This is the first line.".ToRunes ()
  7498. ),
  7499. Cell.ToCells (
  7500. "This is the second line.".ToRunes ()
  7501. )
  7502. ];
  7503. TextView tv = CreateTextView ();
  7504. tv.DrawNormalColor += textView_DrawColor;
  7505. tv.DrawReadOnlyColor += textView_DrawColor;
  7506. tv.DrawSelectionColor += textView_DrawColor;
  7507. tv.DrawUsedColor += textView_DrawColor;
  7508. void textView_DrawColor (object sender, CellEventArgs e)
  7509. {
  7510. Assert.Equal (e.Line [e.Col], text [e.UnwrappedPosition.Row] [e.UnwrappedPosition.Col]);
  7511. eventCount++;
  7512. }
  7513. tv.Text = $"{Cell.ToString (text [0])}\n{Cell.ToString (text [1])}\n";
  7514. Assert.False (tv.WordWrap);
  7515. var top = new Toplevel ();
  7516. top.Add (tv);
  7517. Application.Begin (top);
  7518. Application.LayoutAndDraw ();
  7519. TestHelpers.AssertDriverContentsWithFrameAre (
  7520. @"
  7521. This is the first line.
  7522. This is the second line.",
  7523. _output
  7524. );
  7525. tv.Width = 10;
  7526. tv.Height = 25;
  7527. tv.WordWrap = true;
  7528. Application.LayoutAndDraw ();
  7529. TestHelpers.AssertDriverContentsWithFrameAre (
  7530. @"
  7531. This is
  7532. the
  7533. first
  7534. line.
  7535. This is
  7536. the
  7537. second
  7538. line. ",
  7539. _output
  7540. );
  7541. Assert.Equal (eventCount, (text [0].Count + text [1].Count) * 2);
  7542. top.Dispose ();
  7543. }
  7544. [Fact]
  7545. [AutoInitShutdown (configLocation: ConfigLocations.Default)]
  7546. public void Cell_LoadCells_InheritsPreviousAttribute ()
  7547. {
  7548. List<Cell> cells = [];
  7549. foreach (KeyValuePair<string, ColorScheme> color in Colors.ColorSchemes)
  7550. {
  7551. string csName = color.Key;
  7552. foreach (Rune rune in csName.EnumerateRunes ())
  7553. {
  7554. cells.Add (new () { Rune = rune, Attribute = color.Value.Normal });
  7555. }
  7556. cells.Add (new () { Rune = (Rune)'\n', Attribute = color.Value.Focus });
  7557. }
  7558. TextView tv = CreateTextView ();
  7559. tv.Load (cells);
  7560. var top = new Toplevel ();
  7561. top.Add (tv);
  7562. RunState rs = Application.Begin (top);
  7563. Application.LayoutAndDraw ();
  7564. Assert.True (tv.InheritsPreviousAttribute);
  7565. var expectedText = @"
  7566. TopLevel
  7567. Base
  7568. Dialog
  7569. Menu
  7570. Error ";
  7571. TestHelpers.AssertDriverContentsWithFrameAre (expectedText, _output);
  7572. Attribute [] attributes =
  7573. {
  7574. // 0
  7575. Colors.ColorSchemes ["TopLevel"].Normal,
  7576. // 1
  7577. Colors.ColorSchemes ["Base"].Normal,
  7578. // 2
  7579. Colors.ColorSchemes ["Dialog"].Normal,
  7580. // 3
  7581. Colors.ColorSchemes ["Menu"].Normal,
  7582. // 4
  7583. Colors.ColorSchemes ["Error"].Normal,
  7584. // 5
  7585. tv.ColorScheme!.Focus
  7586. };
  7587. var expectedColor = @"
  7588. 0000000055
  7589. 1111555555
  7590. 2222225555
  7591. 3333555555
  7592. 4444455555";
  7593. TestHelpers.AssertDriverAttributesAre (expectedColor, _output, Application.Driver, attributes);
  7594. tv.WordWrap = true;
  7595. Application.LayoutAndDraw ();
  7596. TestHelpers.AssertDriverContentsWithFrameAre (expectedText, _output);
  7597. TestHelpers.AssertDriverAttributesAre (expectedColor, _output, Application.Driver, attributes);
  7598. tv.CursorPosition = new (6, 2);
  7599. tv.SelectionStartColumn = 0;
  7600. tv.SelectionStartRow = 0;
  7601. Assert.Equal ($"TopLevel{Environment.NewLine}Base{Environment.NewLine}Dialog", tv.SelectedText);
  7602. tv.Copy ();
  7603. tv.IsSelecting = false;
  7604. tv.CursorPosition = new (2, 4);
  7605. tv.Paste ();
  7606. Application.LayoutAndDraw ();
  7607. expectedText = @"
  7608. TopLevel
  7609. Base
  7610. Dialog
  7611. Menu
  7612. ErTopLevel
  7613. Base
  7614. Dialogror ";
  7615. TestHelpers.AssertDriverContentsWithFrameAre (expectedText, _output);
  7616. expectedColor = @"
  7617. 0000000055
  7618. 1111555555
  7619. 2222225555
  7620. 3333555555
  7621. 4400000000
  7622. 1111555555
  7623. 2222224445";
  7624. TestHelpers.AssertDriverAttributesAre (expectedColor, _output, Application.Driver, attributes);
  7625. tv.Undo ();
  7626. tv.CursorPosition = new (0, 3);
  7627. tv.SelectionStartColumn = 0;
  7628. tv.SelectionStartRow = 0;
  7629. Assert.Equal (
  7630. $"TopLevel{Environment.NewLine}Base{Environment.NewLine}Dialog{Environment.NewLine}",
  7631. tv.SelectedText
  7632. );
  7633. tv.Copy ();
  7634. tv.IsSelecting = false;
  7635. tv.CursorPosition = new (2, 4);
  7636. tv.Paste ();
  7637. Application.LayoutAndDraw ();
  7638. expectedText = @"
  7639. TopLevel
  7640. Base
  7641. Dialog
  7642. Menu
  7643. ErTopLevel
  7644. Base
  7645. Dialog
  7646. ror ";
  7647. TestHelpers.AssertDriverContentsWithFrameAre (expectedText, _output);
  7648. expectedColor = @"
  7649. 0000000055
  7650. 1111555555
  7651. 2222225555
  7652. 3333555555
  7653. 4400000000
  7654. 1111555555
  7655. 2222225555
  7656. 4445555555";
  7657. TestHelpers.AssertDriverAttributesAre (expectedColor, _output, Application.Driver, attributes);
  7658. Application.End (rs);
  7659. top.Dispose ();
  7660. }
  7661. [Fact]
  7662. public void Cell_LoadCells_Without_ColorScheme_Is_Never_Null ()
  7663. {
  7664. List<Cell> cells = new ()
  7665. {
  7666. new() { Rune = new ('T') },
  7667. new() { Rune = new ('e') },
  7668. new() { Rune = new ('s') },
  7669. new() { Rune = new ('t') }
  7670. };
  7671. TextView tv = CreateTextView ();
  7672. var top = new Toplevel ();
  7673. top.Add (tv);
  7674. tv.Load (cells);
  7675. for (var i = 0; i < tv.Lines; i++)
  7676. {
  7677. List<Cell> line = tv.GetLine (i);
  7678. foreach (Cell c in line)
  7679. {
  7680. Assert.NotNull (c.Attribute);
  7681. }
  7682. }
  7683. }
  7684. private TextView CreateTextView () { return new () { Width = 30, Height = 10 }; }
  7685. }