TextViewTests.cs 266 KB

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