TextViewTests.cs 265 KB

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