TextViewTests.cs 271 KB

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