TextViewTests.cs 260 KB

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