TextViewTests.cs 273 KB

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