TextViewTests.cs 266 KB

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