TextViewTests.cs 260 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060
  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.Delete | 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.Delete | 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.Delete | 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. Application.Top.Add (_textView);
  1474. Application.Begin (Application.Top);
  1475. Assert.Equal (4, _textView.TabWidth);
  1476. Assert.True (_textView.AllowsTab);
  1477. Assert.True (_textView.AllowsReturn);
  1478. Assert.True (_textView.Multiline);
  1479. _textView.TabWidth = -1;
  1480. Assert.Equal (0, _textView.TabWidth);
  1481. Assert.True (_textView.AllowsTab);
  1482. Assert.True (_textView.AllowsReturn);
  1483. Assert.True (_textView.Multiline);
  1484. _textView.NewKeyDownEvent (new (KeyCode.Tab));
  1485. Assert.Equal ("\tTAB to jump between text fields.", _textView.Text);
  1486. Application.Refresh ();
  1487. TestHelpers.AssertDriverContentsWithFrameAre (@"
  1488. TAB to jump between text field", _output);
  1489. _textView.TabWidth = 4;
  1490. Application.Refresh ();
  1491. TestHelpers.AssertDriverContentsWithFrameAre (@"
  1492. TAB to jump between text f", _output);
  1493. _textView.NewKeyDownEvent (new (KeyCode.Tab | KeyCode.ShiftMask));
  1494. Assert.Equal ("TAB to jump between text fields.", _textView.Text);
  1495. Assert.True (_textView.NeedsDisplay);
  1496. Application.Refresh ();
  1497. TestHelpers.AssertDriverContentsWithFrameAre (@"
  1498. TAB to jump between text field", _output);
  1499. }
  1500. [Fact]
  1501. [TextViewTestsAutoInitShutdown]
  1502. public void AllowsTab_Setting_To_True_Changes_TabWidth_To_Default_If_It_Is_Zero ()
  1503. {
  1504. _textView.TabWidth = 0;
  1505. Assert.Equal (0, _textView.TabWidth);
  1506. Assert.True (_textView.AllowsTab);
  1507. Assert.True (_textView.AllowsReturn);
  1508. Assert.True (_textView.Multiline);
  1509. _textView.AllowsTab = true;
  1510. Assert.True (_textView.AllowsTab);
  1511. Assert.Equal (4, _textView.TabWidth);
  1512. Assert.True (_textView.AllowsReturn);
  1513. Assert.True (_textView.Multiline);
  1514. }
  1515. [Fact]
  1516. [TextViewTestsAutoInitShutdown]
  1517. public void AllowsReturn_Setting_To_True_Changes_Multiline_To_True_If_It_Is_False ()
  1518. {
  1519. Assert.True (_textView.AllowsReturn);
  1520. Assert.True (_textView.Multiline);
  1521. Assert.Equal (4, _textView.TabWidth);
  1522. Assert.True (_textView.AllowsTab);
  1523. _textView.NewKeyDownEvent (new (KeyCode.Enter));
  1524. Assert.Equal (Environment.NewLine +
  1525. "TAB to jump between text fields.", _textView.Text);
  1526. _textView.AllowsReturn = false;
  1527. Assert.False (_textView.AllowsReturn);
  1528. Assert.False (_textView.Multiline);
  1529. Assert.Equal (0, _textView.TabWidth);
  1530. Assert.False (_textView.AllowsTab);
  1531. _textView.NewKeyDownEvent (new (KeyCode.Enter));
  1532. Assert.Equal (Environment.NewLine +
  1533. "TAB to jump between text fields.", _textView.Text);
  1534. }
  1535. [Fact]
  1536. [TextViewTestsAutoInitShutdown]
  1537. public void Multiline_Setting_Changes_AllowsReturn_AllowsTab_Height_WordWrap ()
  1538. {
  1539. Assert.True (_textView.Multiline);
  1540. Assert.True (_textView.AllowsReturn);
  1541. Assert.Equal (4, _textView.TabWidth);
  1542. Assert.True (_textView.AllowsTab);
  1543. Assert.Equal ("Absolute(30)", _textView.Width.ToString ());
  1544. Assert.Equal ("Absolute(10)", _textView.Height.ToString ());
  1545. Assert.False (_textView.WordWrap);
  1546. _textView.WordWrap = true;
  1547. Assert.True (_textView.WordWrap);
  1548. _textView.Multiline = false;
  1549. Assert.False (_textView.Multiline);
  1550. Assert.False (_textView.AllowsReturn);
  1551. Assert.Equal (0, _textView.TabWidth);
  1552. Assert.False (_textView.AllowsTab);
  1553. Assert.Equal ("Absolute(30)", _textView.Width.ToString ());
  1554. Assert.Equal ("Absolute(1)", _textView.Height.ToString ());
  1555. Assert.False (_textView.WordWrap);
  1556. _textView.WordWrap = true;
  1557. Assert.False (_textView.WordWrap);
  1558. _textView.Multiline = true;
  1559. Assert.True (_textView.Multiline);
  1560. Assert.True (_textView.AllowsReturn);
  1561. Assert.Equal (4, _textView.TabWidth);
  1562. Assert.True (_textView.AllowsTab);
  1563. Assert.Equal ("Absolute(30)", _textView.Width.ToString ());
  1564. Assert.Equal ("Absolute(10)", _textView.Height.ToString ());
  1565. Assert.False (_textView.WordWrap);
  1566. }
  1567. [Fact]
  1568. [TextViewTestsAutoInitShutdown]
  1569. public void Tab_Test_Follow_By_BackTab ()
  1570. {
  1571. Application.Top.Add (_textView);
  1572. Application.Iteration += (s, a) => {
  1573. var width = _textView.Bounds.Width - 1;
  1574. Assert.Equal (30, width + 1);
  1575. Assert.Equal (10, _textView.Height);
  1576. _textView.Text = "";
  1577. var col = 0;
  1578. var leftCol = 0;
  1579. var tabWidth = _textView.TabWidth;
  1580. while (col < 100) {
  1581. col++;
  1582. _textView.NewKeyDownEvent (new (KeyCode.Tab));
  1583. Assert.Equal (new Point (col, 0), _textView.CursorPosition);
  1584. leftCol = GetLeftCol (leftCol);
  1585. Assert.Equal (leftCol, _textView.LeftColumn);
  1586. }
  1587. while (col > 0) {
  1588. col--;
  1589. _textView.NewKeyDownEvent (new (KeyCode.Tab | KeyCode.ShiftMask));
  1590. Assert.Equal (new Point (col, 0), _textView.CursorPosition);
  1591. leftCol = GetLeftCol (leftCol);
  1592. Assert.Equal (leftCol, _textView.LeftColumn);
  1593. }
  1594. Application.Top.Remove (_textView);
  1595. Application.RequestStop ();
  1596. };
  1597. Application.Run ();
  1598. }
  1599. [Fact]
  1600. [TextViewTestsAutoInitShutdown]
  1601. public void BackTab_Test_Follow_By_Tab ()
  1602. {
  1603. Application.Top.Add (_textView);
  1604. Application.Iteration += (s, a) => {
  1605. var width = _textView.Bounds.Width - 1;
  1606. Assert.Equal (30, width + 1);
  1607. Assert.Equal (10, _textView.Height);
  1608. _textView.Text = "";
  1609. for (int i = 0; i < 100; i++) {
  1610. _textView.Text += "\t";
  1611. }
  1612. var col = 100;
  1613. var tabWidth = _textView.TabWidth;
  1614. var leftCol = _textView.LeftColumn;
  1615. _textView.MoveEnd ();
  1616. Assert.Equal (new Point (col, 0), _textView.CursorPosition);
  1617. leftCol = GetLeftCol (leftCol);
  1618. Assert.Equal (leftCol, _textView.LeftColumn);
  1619. while (col > 0) {
  1620. col--;
  1621. _textView.NewKeyDownEvent (new (KeyCode.Tab | KeyCode.ShiftMask));
  1622. Assert.Equal (new Point (col, 0), _textView.CursorPosition);
  1623. leftCol = GetLeftCol (leftCol);
  1624. Assert.Equal (leftCol, _textView.LeftColumn);
  1625. }
  1626. while (col < 100) {
  1627. col++;
  1628. _textView.NewKeyDownEvent (new (KeyCode.Tab));
  1629. Assert.Equal (new Point (col, 0), _textView.CursorPosition);
  1630. leftCol = GetLeftCol (leftCol);
  1631. Assert.Equal (leftCol, _textView.LeftColumn);
  1632. }
  1633. Application.Top.Remove (_textView);
  1634. Application.RequestStop ();
  1635. };
  1636. Application.Run ();
  1637. }
  1638. [Fact]
  1639. [TextViewTestsAutoInitShutdown]
  1640. public void Tab_Test_Follow_By_CursorLeft_And_Then_Follow_By_CursorRight ()
  1641. {
  1642. Application.Top.Add (_textView);
  1643. Application.Iteration += (s, a) => {
  1644. var width = _textView.Bounds.Width - 1;
  1645. Assert.Equal (30, width + 1);
  1646. Assert.Equal (10, _textView.Height);
  1647. _textView.Text = "";
  1648. var col = 0;
  1649. var leftCol = 0;
  1650. var tabWidth = _textView.TabWidth;
  1651. while (col < 100) {
  1652. col++;
  1653. _textView.NewKeyDownEvent (new (KeyCode.Tab));
  1654. Assert.Equal (new Point (col, 0), _textView.CursorPosition);
  1655. leftCol = GetLeftCol (leftCol);
  1656. Assert.Equal (leftCol, _textView.LeftColumn);
  1657. }
  1658. while (col > 0) {
  1659. col--;
  1660. _textView.NewKeyDownEvent (new (KeyCode.CursorLeft));
  1661. Assert.Equal (new Point (col, 0), _textView.CursorPosition);
  1662. leftCol = GetLeftCol (leftCol);
  1663. Assert.Equal (leftCol, _textView.LeftColumn);
  1664. }
  1665. while (col < 100) {
  1666. col++;
  1667. _textView.NewKeyDownEvent (new (KeyCode.CursorRight));
  1668. Assert.Equal (new Point (col, 0), _textView.CursorPosition);
  1669. leftCol = GetLeftCol (leftCol);
  1670. Assert.Equal (leftCol, _textView.LeftColumn);
  1671. }
  1672. Application.Top.Remove (_textView);
  1673. Application.RequestStop ();
  1674. };
  1675. Application.Run ();
  1676. }
  1677. [Fact]
  1678. [TextViewTestsAutoInitShutdown]
  1679. public void Tab_Test_Follow_By_BackTab_With_Text ()
  1680. {
  1681. Application.Top.Add (_textView);
  1682. Application.Iteration += (s, a) => {
  1683. var width = _textView.Bounds.Width - 1;
  1684. Assert.Equal (30, width + 1);
  1685. Assert.Equal (10, _textView.Height);
  1686. var col = 0;
  1687. var leftCol = 0;
  1688. Assert.Equal (new Point (col, 0), _textView.CursorPosition);
  1689. Assert.Equal (leftCol, _textView.LeftColumn);
  1690. while (col < 100) {
  1691. col++;
  1692. _textView.NewKeyDownEvent (new (KeyCode.Tab));
  1693. Assert.Equal (new Point (col, 0), _textView.CursorPosition);
  1694. leftCol = GetLeftCol (leftCol);
  1695. Assert.Equal (leftCol, _textView.LeftColumn);
  1696. }
  1697. while (col > 0) {
  1698. col--;
  1699. _textView.NewKeyDownEvent (new (KeyCode.Tab | KeyCode.ShiftMask));
  1700. Assert.Equal (new Point (col, 0), _textView.CursorPosition);
  1701. leftCol = GetLeftCol (leftCol);
  1702. Assert.Equal (leftCol, _textView.LeftColumn);
  1703. }
  1704. Application.Top.Remove (_textView);
  1705. Application.RequestStop ();
  1706. };
  1707. Application.Run ();
  1708. }
  1709. [Fact]
  1710. [TextViewTestsAutoInitShutdown]
  1711. public void Tab_Test_Follow_By_Home_And_Then_Follow_By_End_And_Then_Follow_By_BackTab_With_Text ()
  1712. {
  1713. Application.Top.Add (_textView);
  1714. Application.Iteration += (s, a) => {
  1715. var width = _textView.Bounds.Width - 1;
  1716. Assert.Equal (30, width + 1);
  1717. Assert.Equal (10, _textView.Height);
  1718. var col = 0;
  1719. var leftCol = 0;
  1720. Assert.Equal (new Point (col, 0), _textView.CursorPosition);
  1721. Assert.Equal (leftCol, _textView.LeftColumn);
  1722. Assert.Equal ("TAB to jump between text fields.", _textView.Text);
  1723. Assert.Equal (32, _textView.Text.Length);
  1724. while (col < 100) {
  1725. col++;
  1726. _textView.NewKeyDownEvent (new (KeyCode.Tab));
  1727. Assert.Equal (new Point (col, 0), _textView.CursorPosition);
  1728. leftCol = GetLeftCol (leftCol);
  1729. Assert.Equal (leftCol, _textView.LeftColumn);
  1730. }
  1731. _textView.NewKeyDownEvent (new (KeyCode.Home));
  1732. col = 0;
  1733. Assert.Equal (new Point (col, 0), _textView.CursorPosition);
  1734. leftCol = 0;
  1735. Assert.Equal (leftCol, _textView.LeftColumn);
  1736. _textView.NewKeyDownEvent (new (KeyCode.End));
  1737. col = _textView.Text.Length;
  1738. Assert.Equal (132, _textView.Text.Length);
  1739. Assert.Equal (new Point (col, 0), _textView.CursorPosition);
  1740. leftCol = GetLeftCol (leftCol);
  1741. Assert.Equal (leftCol, _textView.LeftColumn);
  1742. var txt = _textView.Text;
  1743. while (col - 1 > 0 && txt [col - 1] != '\t') {
  1744. col--;
  1745. }
  1746. _textView.CursorPosition = new Point (col, 0);
  1747. leftCol = GetLeftCol (leftCol);
  1748. while (col > 0) {
  1749. col--;
  1750. _textView.NewKeyDownEvent (new (KeyCode.Tab | KeyCode.ShiftMask));
  1751. Assert.Equal (new Point (col, 0), _textView.CursorPosition);
  1752. leftCol = GetLeftCol (leftCol);
  1753. Assert.Equal (leftCol, _textView.LeftColumn);
  1754. }
  1755. Assert.Equal ("TAB to jump between text fields.", _textView.Text);
  1756. Assert.Equal (32, _textView.Text.Length);
  1757. Application.Top.Remove (_textView);
  1758. Application.RequestStop ();
  1759. };
  1760. Application.Run ();
  1761. }
  1762. [Fact]
  1763. [TextViewTestsAutoInitShutdown]
  1764. public void Tab_Test_Follow_By_CursorLeft_And_Then_Follow_By_CursorRight_With_Text ()
  1765. {
  1766. Application.Top.Add (_textView);
  1767. Application.Iteration += (s, a) => {
  1768. var width = _textView.Bounds.Width - 1;
  1769. Assert.Equal (30, width + 1);
  1770. Assert.Equal (10, _textView.Height);
  1771. Assert.Equal ("TAB to jump between text fields.", _textView.Text);
  1772. var col = 0;
  1773. var leftCol = 0;
  1774. var tabWidth = _textView.TabWidth;
  1775. while (col < 100) {
  1776. col++;
  1777. _textView.NewKeyDownEvent (new (KeyCode.Tab));
  1778. Assert.Equal (new Point (col, 0), _textView.CursorPosition);
  1779. leftCol = GetLeftCol (leftCol);
  1780. Assert.Equal (leftCol, _textView.LeftColumn);
  1781. }
  1782. Assert.Equal (132, _textView.Text.Length);
  1783. while (col > 0) {
  1784. col--;
  1785. _textView.NewKeyDownEvent (new (KeyCode.CursorLeft));
  1786. Assert.Equal (new Point (col, 0), _textView.CursorPosition);
  1787. leftCol = GetLeftCol (leftCol);
  1788. Assert.Equal (leftCol, _textView.LeftColumn);
  1789. }
  1790. while (col < 100) {
  1791. col++;
  1792. _textView.NewKeyDownEvent (new (KeyCode.CursorRight));
  1793. Assert.Equal (new Point (col, 0), _textView.CursorPosition);
  1794. leftCol = GetLeftCol (leftCol);
  1795. Assert.Equal (leftCol, _textView.LeftColumn);
  1796. }
  1797. Application.Top.Remove (_textView);
  1798. Application.RequestStop ();
  1799. };
  1800. Application.Run ();
  1801. }
  1802. [Fact]
  1803. public void TextView_MultiLine_But_Without_Tabs ()
  1804. {
  1805. var view = new TextView ();
  1806. // the default for TextView
  1807. Assert.True (view.Multiline);
  1808. view.AllowsTab = false;
  1809. Assert.False (view.AllowsTab);
  1810. Assert.True (view.Multiline);
  1811. }
  1812. private int GetLeftCol (int start)
  1813. {
  1814. var lines = _textView.Text.Split (Environment.NewLine);
  1815. if (lines == null || lines.Length == 0) {
  1816. return 0;
  1817. }
  1818. if (start == _textView.LeftColumn) {
  1819. return start;
  1820. }
  1821. if (_textView.LeftColumn == _textView.CurrentColumn) {
  1822. return _textView.CurrentColumn;
  1823. }
  1824. var cCol = _textView.CurrentColumn;
  1825. var line = lines [_textView.CurrentRow];
  1826. var lCount = cCol > line.Length - 1 ? line.Length - 1 : cCol;
  1827. var width = _textView.Frame.Width;
  1828. var tabWidth = _textView.TabWidth;
  1829. var sumLength = 0;
  1830. var col = 0;
  1831. for (int i = lCount; i >= 0; i--) {
  1832. var r = line [i];
  1833. sumLength += ((Rune)r).GetColumns ();
  1834. if (r == '\t') {
  1835. sumLength += tabWidth + 1;
  1836. }
  1837. if (sumLength > width) {
  1838. if (col + width == cCol) {
  1839. col++;
  1840. }
  1841. break;
  1842. } else if ((cCol < line.Length && col > 0 && start < cCol && col == start) || (cCol - col == width - 1)) {
  1843. break;
  1844. }
  1845. col = i;
  1846. }
  1847. return col;
  1848. }
  1849. [Fact]
  1850. public void LoadFile_Throws_If_File_Is_Null ()
  1851. {
  1852. var result = false;
  1853. var tv = new TextView ();
  1854. Assert.Throws<ArgumentNullException> (() => result = tv.Load ((string)null));
  1855. Assert.False (result);
  1856. }
  1857. [Fact]
  1858. public void LoadFile_Throws_If_File_Is_Empty ()
  1859. {
  1860. var result = false;
  1861. var tv = new TextView ();
  1862. Assert.Throws<ArgumentException> (() => result = tv.Load (""));
  1863. Assert.False (result);
  1864. }
  1865. [Fact]
  1866. public void LoadFile_Throws_If_File_Not_Exist ()
  1867. {
  1868. var result = false;
  1869. var tv = new TextView ();
  1870. Assert.Throws<System.IO.FileNotFoundException> (() => result = tv.Load ("blabla"));
  1871. Assert.False (result);
  1872. }
  1873. [Fact]
  1874. public void LoadStream_Throws_If_Stream_Is_Null ()
  1875. {
  1876. var tv = new TextView ();
  1877. Assert.Throws<ArgumentNullException> (() => tv.Load ((System.IO.Stream)null));
  1878. }
  1879. [Fact]
  1880. public void LoadStream_Stream_Is_Empty ()
  1881. {
  1882. var tv = new TextView ();
  1883. tv.Load (new System.IO.MemoryStream ());
  1884. Assert.Equal ("", tv.Text);
  1885. }
  1886. [Fact]
  1887. public void LoadStream_CRLF ()
  1888. {
  1889. var text = "This is the first line.\r\nThis is the second line.\r\n";
  1890. var tv = new TextView ();
  1891. tv.Load (new System.IO.MemoryStream (System.Text.Encoding.ASCII.GetBytes (text)));
  1892. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}", tv.Text);
  1893. }
  1894. [Fact]
  1895. public void LoadStream_LF ()
  1896. {
  1897. var text = "This is the first line.\nThis is the second line.\n";
  1898. var tv = new TextView ();
  1899. tv.Load (new System.IO.MemoryStream (System.Text.Encoding.ASCII.GetBytes (text)));
  1900. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}", tv.Text);
  1901. }
  1902. [Fact]
  1903. public void LoadStream_IsDirty ()
  1904. {
  1905. var text = "Testing";
  1906. using (System.IO.MemoryStream stream = new System.IO.MemoryStream ()) {
  1907. var writer = new System.IO.StreamWriter (stream);
  1908. writer.Write (text);
  1909. writer.Flush ();
  1910. stream.Position = 0;
  1911. var tv = new TextView ();
  1912. tv.Load (stream);
  1913. Assert.Equal (7, text.Length);
  1914. Assert.Equal (text.Length, tv.Text.Length);
  1915. Assert.Equal (text, tv.Text);
  1916. Assert.False (tv.IsDirty);
  1917. }
  1918. }
  1919. [Fact]
  1920. public void LoadStream_IsDirty_With_Null_On_The_Text ()
  1921. {
  1922. var text = "Test\0ing";
  1923. using (System.IO.MemoryStream stream = new System.IO.MemoryStream ()) {
  1924. var writer = new System.IO.StreamWriter (stream);
  1925. writer.Write (text);
  1926. writer.Flush ();
  1927. stream.Position = 0;
  1928. var tv = new TextView ();
  1929. tv.Load (stream);
  1930. Assert.Equal (8, text.Length);
  1931. Assert.Equal (text.Length, tv.Text.Length);
  1932. Assert.Equal (8, text.Length);
  1933. Assert.Equal (8, tv.Text.Length);
  1934. Assert.Equal (text, tv.Text);
  1935. Assert.False (tv.IsDirty);
  1936. Assert.Equal ((Rune)'\u2400', ((Rune)tv.Text [4]).MakePrintable ());
  1937. }
  1938. }
  1939. [Fact]
  1940. public void StringToRunes_Slipts_CRLF ()
  1941. {
  1942. var text = "This is the first line.\r\nThis is the second line.\r\n";
  1943. var tv = new TextView ();
  1944. tv.Text = text;
  1945. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}", tv.Text);
  1946. }
  1947. [Fact]
  1948. public void StringToRunes_Slipts_LF ()
  1949. {
  1950. var text = "This is the first line.\nThis is the second line.\n";
  1951. var tv = new TextView ();
  1952. tv.Text = text;
  1953. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}", tv.Text);
  1954. }
  1955. [Fact]
  1956. public void CloseFile_Throws_If_FilePath_Is_Null ()
  1957. {
  1958. var tv = new TextView ();
  1959. Assert.Throws<ArgumentNullException> (() => tv.CloseFile ());
  1960. }
  1961. [Fact]
  1962. public void WordWrap_Gets_Sets ()
  1963. {
  1964. var tv = new TextView () { WordWrap = true };
  1965. Assert.True (tv.WordWrap);
  1966. tv.WordWrap = false;
  1967. Assert.False (tv.WordWrap);
  1968. }
  1969. [Fact]
  1970. public void WordWrap_True_Text_Always_Returns_Unwrapped ()
  1971. {
  1972. var text = "This is the first line.\nThis is the second line.\n";
  1973. var tv = new TextView () { Width = 10 };
  1974. tv.Text = text;
  1975. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}", tv.Text);
  1976. tv.WordWrap = true;
  1977. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}", tv.Text);
  1978. }
  1979. [Fact]
  1980. [TextViewTestsAutoInitShutdown]
  1981. public void WordWrap_WrapModel_Output ()
  1982. {
  1983. // 0123456789
  1984. var text = "This is the first line.\nThis is the second line.\n";
  1985. var tv = new TextView () { Width = 10, Height = 10 };
  1986. tv.Text = text;
  1987. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}", tv.Text);
  1988. tv.WordWrap = true;
  1989. Application.Top.Add (tv);
  1990. tv.LayoutSubviews ();
  1991. tv.Draw ();
  1992. TestHelpers.AssertDriverContentsWithFrameAre (@"
  1993. This is
  1994. the
  1995. first
  1996. line.
  1997. This is
  1998. the
  1999. second
  2000. line.
  2001. ", _output);
  2002. }
  2003. [Fact]
  2004. [AutoInitShutdown]
  2005. public void WordWrap_Deleting_Backwards ()
  2006. {
  2007. var tv = new TextView () {
  2008. Width = 5,
  2009. Height = 2,
  2010. WordWrap = true,
  2011. Text = "aaaa"
  2012. };
  2013. Application.Top.Add (tv);
  2014. Application.Begin (Application.Top);
  2015. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  2016. Assert.Equal (0, tv.LeftColumn);
  2017. TestHelpers.AssertDriverContentsAre (@"
  2018. aaaa
  2019. ", _output);
  2020. tv.CursorPosition = new Point (5, 0);
  2021. Assert.True (tv.NewKeyDownEvent (new (KeyCode.Backspace)));
  2022. Application.Refresh ();
  2023. Assert.Equal (0, tv.LeftColumn);
  2024. TestHelpers.AssertDriverContentsAre (@"
  2025. aaa
  2026. ", _output);
  2027. Assert.True (tv.NewKeyDownEvent (new (KeyCode.Backspace)));
  2028. Application.Refresh ();
  2029. Assert.Equal (0, tv.LeftColumn);
  2030. TestHelpers.AssertDriverContentsAre (@"
  2031. aa
  2032. ", _output);
  2033. Assert.True (tv.NewKeyDownEvent (new (KeyCode.Backspace)));
  2034. Application.Refresh ();
  2035. Assert.Equal (0, tv.LeftColumn);
  2036. TestHelpers.AssertDriverContentsAre (@"
  2037. a
  2038. ", _output);
  2039. Assert.True (tv.NewKeyDownEvent (new (KeyCode.Backspace)));
  2040. Application.Refresh ();
  2041. Assert.Equal (0, tv.LeftColumn);
  2042. TestHelpers.AssertDriverContentsAre (@"
  2043. ", _output);
  2044. Assert.True (tv.NewKeyDownEvent (new (KeyCode.Backspace)));
  2045. Application.Refresh ();
  2046. Assert.Equal (0, tv.LeftColumn);
  2047. TestHelpers.AssertDriverContentsAre (@"
  2048. ", _output);
  2049. }
  2050. [Fact]
  2051. [TextViewTestsAutoInitShutdown]
  2052. public void WordWrap_ReadOnly_CursorPosition_SelectedText_Copy ()
  2053. {
  2054. // 0123456789
  2055. var text = "This is the first line.\nThis is the second line.\n";
  2056. var tv = new TextView () { Width = 11, Height = 9 };
  2057. tv.Text = text;
  2058. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}", tv.Text);
  2059. tv.WordWrap = true;
  2060. Application.Top.Add (tv);
  2061. Application.Top.LayoutSubviews ();
  2062. tv.Draw ();
  2063. TestHelpers.AssertDriverContentsWithFrameAre (@"
  2064. This is
  2065. the first
  2066. line.
  2067. This is
  2068. the
  2069. second
  2070. line.
  2071. ", _output);
  2072. tv.ReadOnly = true;
  2073. tv.CursorPosition = new Point (6, 2);
  2074. Assert.Equal (new Point (5, 2), tv.CursorPosition);
  2075. Application.Top.LayoutSubviews ();
  2076. tv.Draw ();
  2077. TestHelpers.AssertDriverContentsWithFrameAre (@"
  2078. This is
  2079. the first
  2080. line.
  2081. This is
  2082. the
  2083. second
  2084. line.
  2085. ", _output);
  2086. tv.SelectionStartRow = 0;
  2087. tv.SelectionStartColumn = 0;
  2088. Assert.Equal ("This is the first line.", tv.SelectedText);
  2089. tv.Copy ();
  2090. Assert.Equal ("This is the first line.", Clipboard.Contents);
  2091. }
  2092. [Fact]
  2093. public void Internal_Tests ()
  2094. {
  2095. var txt = "This is a text.";
  2096. var txtRunes = TextModel.StringToRuneCells (txt);
  2097. Assert.Equal (txt.Length, txtRunes.Count);
  2098. Assert.Equal ('T', txtRunes [0].Rune.Value);
  2099. Assert.Equal ('h', txtRunes [1].Rune.Value);
  2100. Assert.Equal ('i', txtRunes [2].Rune.Value);
  2101. Assert.Equal ('s', txtRunes [3].Rune.Value);
  2102. Assert.Equal (' ', txtRunes [4].Rune.Value);
  2103. Assert.Equal ('i', txtRunes [5].Rune.Value);
  2104. Assert.Equal ('s', txtRunes [6].Rune.Value);
  2105. Assert.Equal (' ', txtRunes [7].Rune.Value);
  2106. Assert.Equal ('a', txtRunes [8].Rune.Value);
  2107. Assert.Equal (' ', txtRunes [9].Rune.Value);
  2108. Assert.Equal ('t', txtRunes [10].Rune.Value);
  2109. Assert.Equal ('e', txtRunes [11].Rune.Value);
  2110. Assert.Equal ('x', txtRunes [12].Rune.Value);
  2111. Assert.Equal ('t', txtRunes [13].Rune.Value);
  2112. Assert.Equal ('.', txtRunes [^1].Rune.Value);
  2113. int col = 0;
  2114. Assert.True (TextModel.SetCol (ref col, 80, 79));
  2115. Assert.False (TextModel.SetCol (ref col, 80, 80));
  2116. Assert.Equal (79, col);
  2117. var start = 0;
  2118. var x = 8;
  2119. Assert.Equal (8, TextModel.GetColFromX (txtRunes, start, x));
  2120. Assert.Equal ('a', txtRunes [start + x].Rune.Value);
  2121. start = 1;
  2122. x = 7;
  2123. Assert.Equal (7, TextModel.GetColFromX (txtRunes, start, x));
  2124. Assert.Equal ('a', txtRunes [start + x].Rune.Value);
  2125. Assert.Equal ((15, 15), TextModel.DisplaySize (txtRunes));
  2126. Assert.Equal ((6, 6), TextModel.DisplaySize (txtRunes, 1, 7));
  2127. Assert.Equal (0, TextModel.CalculateLeftColumn (txtRunes, 0, 7, 8));
  2128. Assert.Equal (1, TextModel.CalculateLeftColumn (txtRunes, 0, 8, 8));
  2129. Assert.Equal (2, TextModel.CalculateLeftColumn (txtRunes, 0, 9, 8));
  2130. var tm = new TextModel ();
  2131. tm.AddLine (0, TextModel.StringToRuneCells ("This is first line."));
  2132. tm.AddLine (1, TextModel.StringToRuneCells ("This is last line."));
  2133. Assert.Equal ((new Point (2, 0), true), tm.FindNextText ("is", out bool gaveFullTurn));
  2134. Assert.False (gaveFullTurn);
  2135. Assert.Equal ((new Point (5, 0), true), tm.FindNextText ("is", out gaveFullTurn));
  2136. Assert.False (gaveFullTurn);
  2137. Assert.Equal ((new Point (2, 1), true), tm.FindNextText ("is", out gaveFullTurn));
  2138. Assert.False (gaveFullTurn);
  2139. Assert.Equal ((new Point (5, 1), true), tm.FindNextText ("is", out gaveFullTurn));
  2140. Assert.False (gaveFullTurn);
  2141. Assert.Equal ((new Point (2, 0), true), tm.FindNextText ("is", out gaveFullTurn));
  2142. Assert.True (gaveFullTurn);
  2143. tm.ResetContinuousFind (new Point (0, 0));
  2144. Assert.Equal ((new Point (5, 1), true), tm.FindPreviousText ("is", out gaveFullTurn));
  2145. Assert.False (gaveFullTurn);
  2146. Assert.Equal ((new Point (2, 1), true), tm.FindPreviousText ("is", out gaveFullTurn));
  2147. Assert.False (gaveFullTurn);
  2148. Assert.Equal ((new Point (5, 0), true), tm.FindPreviousText ("is", out gaveFullTurn));
  2149. Assert.False (gaveFullTurn);
  2150. Assert.Equal ((new Point (2, 0), true), tm.FindPreviousText ("is", out gaveFullTurn));
  2151. Assert.False (gaveFullTurn);
  2152. Assert.Equal ((new Point (5, 1), true), tm.FindPreviousText ("is", out gaveFullTurn));
  2153. Assert.True (gaveFullTurn);
  2154. Assert.Equal ((new Point (9, 1), true), tm.ReplaceAllText ("is", false, false, "really"));
  2155. Assert.Equal (TextModel.StringToRuneCells ("Threally really first line."), tm.GetLine (0));
  2156. Assert.Equal (TextModel.StringToRuneCells ("Threally really last line."), tm.GetLine (1));
  2157. tm = new TextModel ();
  2158. tm.AddLine (0, TextModel.StringToRuneCells ("This is first line."));
  2159. tm.AddLine (1, TextModel.StringToRuneCells ("This is last line."));
  2160. Assert.Equal ((new Point (5, 1), true), tm.ReplaceAllText ("is", false, true, "really"));
  2161. Assert.Equal (TextModel.StringToRuneCells ("This really first line."), tm.GetLine (0));
  2162. Assert.Equal (TextModel.StringToRuneCells ("This really last line."), tm.GetLine (1));
  2163. }
  2164. [Fact]
  2165. [TextViewTestsAutoInitShutdown]
  2166. public void BottomOffset_Sets_To_Zero_Adjust_TopRow ()
  2167. {
  2168. string text = "";
  2169. for (int i = 0; i < 12; i++) {
  2170. text += $"This is the line {i}\n";
  2171. }
  2172. var tv = new TextView () { Width = 10, Height = 10, BottomOffset = 1 };
  2173. tv.Text = text;
  2174. tv.NewKeyDownEvent (new (KeyCode.CtrlMask | KeyCode.End));
  2175. Assert.Equal (4, tv.TopRow);
  2176. Assert.Equal (1, tv.BottomOffset);
  2177. tv.BottomOffset = 0;
  2178. Assert.Equal (3, tv.TopRow);
  2179. Assert.Equal (0, tv.BottomOffset);
  2180. tv.BottomOffset = 2;
  2181. Assert.Equal (5, tv.TopRow);
  2182. Assert.Equal (2, tv.BottomOffset);
  2183. tv.BottomOffset = 0;
  2184. Assert.Equal (3, tv.TopRow);
  2185. Assert.Equal (0, tv.BottomOffset);
  2186. }
  2187. [Fact]
  2188. [TextViewTestsAutoInitShutdown]
  2189. public void RightOffset_Sets_To_Zero_Adjust_leftColumn ()
  2190. {
  2191. string text = "";
  2192. for (int i = 0; i < 12; i++) {
  2193. text += $"{i.ToString () [^1]}";
  2194. }
  2195. var tv = new TextView () { Width = 10, Height = 10, RightOffset = 1 };
  2196. tv.Text = text;
  2197. tv.NewKeyDownEvent (new (KeyCode.End));
  2198. Assert.Equal (4, tv.LeftColumn);
  2199. Assert.Equal (1, tv.RightOffset);
  2200. tv.RightOffset = 0;
  2201. Assert.Equal (3, tv.LeftColumn);
  2202. Assert.Equal (0, tv.RightOffset);
  2203. tv.RightOffset = 2;
  2204. Assert.Equal (5, tv.LeftColumn);
  2205. Assert.Equal (2, tv.RightOffset);
  2206. tv.RightOffset = 0;
  2207. Assert.Equal (3, tv.LeftColumn);
  2208. Assert.Equal (0, tv.RightOffset);
  2209. }
  2210. [Fact]
  2211. [TextViewTestsAutoInitShutdown]
  2212. public void TextView_SpaceHandling ()
  2213. {
  2214. var tv = new TextView () {
  2215. Width = 10,
  2216. Text = " "
  2217. };
  2218. MouseEvent ev = new MouseEvent () {
  2219. X = 0,
  2220. Y = 0,
  2221. Flags = MouseFlags.Button1DoubleClicked,
  2222. };
  2223. tv.MouseEvent (ev);
  2224. Assert.Equal (1, tv.SelectedLength);
  2225. ev = new MouseEvent () {
  2226. X = 1,
  2227. Y = 0,
  2228. Flags = MouseFlags.Button1DoubleClicked,
  2229. };
  2230. tv.MouseEvent (ev);
  2231. Assert.Equal (1, tv.SelectedLength);
  2232. }
  2233. [Fact]
  2234. [TextViewTestsAutoInitShutdown]
  2235. public void CanFocus_False_Wont_Focus_With_Mouse ()
  2236. {
  2237. var top = Application.Top;
  2238. var tv = new TextView () {
  2239. Width = Dim.Fill (),
  2240. CanFocus = false,
  2241. ReadOnly = true,
  2242. Text = "some text"
  2243. };
  2244. var fv = new FrameView ("I shouldn't get focus") {
  2245. Width = Dim.Fill (),
  2246. Height = Dim.Fill (),
  2247. CanFocus = false,
  2248. };
  2249. fv.Add (tv);
  2250. top.Add (fv);
  2251. Application.Begin (top);
  2252. Assert.False (tv.CanFocus);
  2253. Assert.False (tv.HasFocus);
  2254. Assert.False (fv.CanFocus);
  2255. Assert.False (fv.HasFocus);
  2256. tv.MouseEvent (new MouseEvent () {
  2257. X = 1,
  2258. Y = 0,
  2259. Flags = MouseFlags.Button1DoubleClicked
  2260. });
  2261. Assert.Empty (tv.SelectedText);
  2262. Assert.False (tv.CanFocus);
  2263. Assert.False (tv.HasFocus);
  2264. Assert.False (fv.CanFocus);
  2265. Assert.False (fv.HasFocus);
  2266. Assert.Throws<InvalidOperationException> (() => tv.CanFocus = true);
  2267. fv.CanFocus = true;
  2268. tv.CanFocus = true;
  2269. tv.MouseEvent (new MouseEvent () {
  2270. X = 1,
  2271. Y = 0,
  2272. Flags = MouseFlags.Button1DoubleClicked
  2273. });
  2274. Assert.Equal ("some ", tv.SelectedText);
  2275. Assert.True (tv.CanFocus);
  2276. Assert.True (tv.HasFocus);
  2277. Assert.True (fv.CanFocus);
  2278. Assert.True (fv.HasFocus);
  2279. fv.CanFocus = false;
  2280. tv.MouseEvent (new MouseEvent () {
  2281. X = 1,
  2282. Y = 0,
  2283. Flags = MouseFlags.Button1DoubleClicked
  2284. });
  2285. Assert.Equal ("some ", tv.SelectedText); // Setting CanFocus to false don't change the SelectedText
  2286. Assert.False (tv.CanFocus);
  2287. Assert.False (tv.HasFocus);
  2288. Assert.False (fv.CanFocus);
  2289. Assert.False (fv.HasFocus);
  2290. }
  2291. [Fact]
  2292. [TextViewTestsAutoInitShutdown]
  2293. public void DesiredCursorVisibility_Vertical_Navigation ()
  2294. {
  2295. string text = "";
  2296. for (int i = 0; i < 12; i++) {
  2297. text += $"This is the line {i}\n";
  2298. }
  2299. var tv = new TextView () { Width = 10, Height = 10 };
  2300. tv.Text = text;
  2301. Assert.Equal (0, tv.TopRow);
  2302. tv.PositionCursor ();
  2303. Assert.Equal (CursorVisibility.Default, tv.DesiredCursorVisibility);
  2304. for (int i = 0; i < 12; i++) {
  2305. tv.MouseEvent (new MouseEvent () {
  2306. Flags = MouseFlags.WheeledDown
  2307. });
  2308. tv.PositionCursor ();
  2309. Assert.Equal (i + 1, tv.TopRow);
  2310. Assert.Equal (CursorVisibility.Invisible, tv.DesiredCursorVisibility);
  2311. }
  2312. for (int i = 12; i > 0; i--) {
  2313. tv.MouseEvent (new MouseEvent () {
  2314. Flags = MouseFlags.WheeledUp
  2315. });
  2316. tv.PositionCursor ();
  2317. Assert.Equal (i - 1, tv.TopRow);
  2318. if (i - 1 == 0) {
  2319. Assert.Equal (CursorVisibility.Default, tv.DesiredCursorVisibility);
  2320. } else {
  2321. Assert.Equal (CursorVisibility.Invisible, tv.DesiredCursorVisibility);
  2322. }
  2323. }
  2324. }
  2325. [Theory]
  2326. [TextViewTestsAutoInitShutdown]
  2327. [InlineData (KeyCode.Delete)]
  2328. public void WordWrap_Draw_Typed_Keys_After_Text_Is_Deleted (KeyCode del)
  2329. {
  2330. Application.Top.Add (_textView);
  2331. _textView.Text = "Line 1.\nLine 2.";
  2332. _textView.WordWrap = true;
  2333. Application.Begin (Application.Top);
  2334. Assert.True (_textView.WordWrap);
  2335. TestHelpers.AssertDriverContentsWithFrameAre (@"
  2336. Line 1.
  2337. Line 2.", _output);
  2338. Assert.True (_textView.NewKeyDownEvent (new (KeyCode.End | KeyCode.ShiftMask)));
  2339. Assert.Equal ("Line 1.", _textView.SelectedText);
  2340. Assert.True (_textView.NewKeyDownEvent (new (del)));
  2341. Application.Refresh ();
  2342. TestHelpers.AssertDriverContentsWithFrameAre ("Line 2.", _output);
  2343. Assert.True (_textView.NewKeyDownEvent (new (KeyCode.H | KeyCode.ShiftMask)));
  2344. Assert.NotEqual (Rect.Empty, _textView._needsDisplayRect);
  2345. Application.Refresh ();
  2346. TestHelpers.AssertDriverContentsWithFrameAre (@"
  2347. H
  2348. Line 2.", _output);
  2349. }
  2350. [Fact]
  2351. [TextViewTestsAutoInitShutdown]
  2352. public void DesiredCursorVisibility_Horizontal_Navigation ()
  2353. {
  2354. string text = "";
  2355. for (int i = 0; i < 12; i++) {
  2356. text += $"{i.ToString () [^1]}";
  2357. }
  2358. var tv = new TextView () { Width = 10, Height = 10 };
  2359. tv.Text = text;
  2360. Assert.Equal (0, tv.LeftColumn);
  2361. tv.PositionCursor ();
  2362. Assert.Equal (CursorVisibility.Default, tv.DesiredCursorVisibility);
  2363. for (int i = 0; i < 12; i++) {
  2364. tv.MouseEvent (new MouseEvent () {
  2365. Flags = MouseFlags.WheeledRight
  2366. });
  2367. tv.PositionCursor ();
  2368. Assert.Equal (Math.Min (i + 1, 11), tv.LeftColumn);
  2369. Assert.Equal (CursorVisibility.Invisible, tv.DesiredCursorVisibility);
  2370. }
  2371. for (int i = 11; i > 0; i--) {
  2372. tv.MouseEvent (new MouseEvent () {
  2373. Flags = MouseFlags.WheeledLeft
  2374. });
  2375. tv.PositionCursor ();
  2376. Assert.Equal (i - 1, tv.LeftColumn);
  2377. if (i - 1 == 0) {
  2378. Assert.Equal (CursorVisibility.Default, tv.DesiredCursorVisibility);
  2379. } else {
  2380. Assert.Equal (CursorVisibility.Invisible, tv.DesiredCursorVisibility);
  2381. }
  2382. }
  2383. }
  2384. [Fact]
  2385. public void LeftColumn_Add_One_If_Text_Length_Is_Equal_To_Width ()
  2386. {
  2387. var tv = new TextView () {
  2388. Width = 10,
  2389. Text = "1234567890"
  2390. };
  2391. Assert.Equal (Point.Empty, tv.CursorPosition);
  2392. Assert.Equal (0, tv.LeftColumn);
  2393. tv.CursorPosition = new Point (9, 0);
  2394. Assert.Equal (new Point (9, 0), tv.CursorPosition);
  2395. Assert.Equal (0, tv.LeftColumn);
  2396. Assert.True (tv.NewKeyDownEvent (new (KeyCode.CursorRight)));
  2397. tv.CursorPosition = new Point (10, 0);
  2398. Assert.Equal (new Point (10, 0), tv.CursorPosition);
  2399. Assert.Equal (1, tv.LeftColumn);
  2400. }
  2401. [Fact]
  2402. [AutoInitShutdown (useFakeClipboard: true)]
  2403. public void KeyBindings_Command ()
  2404. {
  2405. var text = "This is the first line.\nThis is the second line.\nThis is the third line.";
  2406. var tv = new TextView () {
  2407. Width = 10,
  2408. Height = 2,
  2409. Text = text
  2410. };
  2411. var top = Application.Top;
  2412. top.Add (tv);
  2413. Application.Begin (top);
  2414. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  2415. Assert.Equal (3, tv.Lines);
  2416. Assert.Equal (Point.Empty, tv.CursorPosition);
  2417. Assert.False (tv.ReadOnly);
  2418. Assert.True (tv.CanFocus);
  2419. var g = (SingleWordSuggestionGenerator)tv.Autocomplete.SuggestionGenerator;
  2420. tv.CanFocus = false;
  2421. Assert.True (tv.NewKeyDownEvent (new (KeyCode.CursorLeft)));
  2422. tv.CanFocus = true;
  2423. Assert.False (tv.NewKeyDownEvent (new (KeyCode.CursorLeft)));
  2424. Assert.True (tv.NewKeyDownEvent (new (KeyCode.CursorRight)));
  2425. Assert.Equal (new Point (1, 0), tv.CursorPosition);
  2426. Assert.True (tv.NewKeyDownEvent (new (KeyCode.End | KeyCode.CtrlMask)));
  2427. Assert.Equal (2, tv.CurrentRow);
  2428. Assert.Equal (23, tv.CurrentColumn);
  2429. Assert.Equal (tv.CurrentColumn, tv.GetCurrentLine ().Count);
  2430. Assert.Equal (new Point (23, 2), tv.CursorPosition);
  2431. Assert.False (tv.NewKeyDownEvent (new (KeyCode.CursorRight)));
  2432. Assert.NotNull (tv.Autocomplete);
  2433. Assert.Empty (g.AllSuggestions);
  2434. Assert.True (tv.NewKeyDownEvent (new (KeyCode.F | KeyCode.ShiftMask)));
  2435. tv.Draw ();
  2436. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.F", tv.Text);
  2437. Assert.Equal (new Point (24, 2), tv.CursorPosition);
  2438. Assert.Empty (tv.Autocomplete.Suggestions);
  2439. Assert.True (tv.NewKeyDownEvent (new (KeyCode.Z | KeyCode.CtrlMask)));
  2440. tv.Draw ();
  2441. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  2442. Assert.Equal (new Point (23, 2), tv.CursorPosition);
  2443. Assert.Empty (tv.Autocomplete.Suggestions);
  2444. Assert.True (tv.NewKeyDownEvent (new (KeyCode.R | KeyCode.CtrlMask)));
  2445. tv.Draw ();
  2446. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.F", tv.Text);
  2447. Assert.Equal (new Point (24, 2), tv.CursorPosition);
  2448. Assert.Empty (tv.Autocomplete.Suggestions);
  2449. Assert.True (tv.NewKeyDownEvent (new (KeyCode.Backspace)));
  2450. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  2451. Assert.Equal (new Point (23, 2), tv.CursorPosition);
  2452. g.AllSuggestions = Regex.Matches (tv.Text, "\\w+")
  2453. .Select (s => s.Value)
  2454. .Distinct ().ToList ();
  2455. Assert.Equal (7, g.AllSuggestions.Count);
  2456. Assert.Equal ("This", g.AllSuggestions [0]);
  2457. Assert.Equal ("is", g.AllSuggestions [1]);
  2458. Assert.Equal ("the", g.AllSuggestions [2]);
  2459. Assert.Equal ("first", g.AllSuggestions [3]);
  2460. Assert.Equal ("line", g.AllSuggestions [4]);
  2461. Assert.Equal ("second", g.AllSuggestions [5]);
  2462. Assert.Equal ("third", g.AllSuggestions [^1]);
  2463. Assert.True (tv.NewKeyDownEvent (new (KeyCode.F | KeyCode.ShiftMask)));
  2464. tv.Draw ();
  2465. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.F", tv.Text);
  2466. Assert.Equal (new Point (24, 2), tv.CursorPosition);
  2467. Assert.Single (tv.Autocomplete.Suggestions);
  2468. Assert.Equal ("first", tv.Autocomplete.Suggestions [0].Replacement);
  2469. Assert.True (tv.NewKeyDownEvent (new (KeyCode.Enter)));
  2470. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first", tv.Text);
  2471. Assert.Equal (new Point (28, 2), tv.CursorPosition);
  2472. Assert.Empty (tv.Autocomplete.Suggestions);
  2473. Assert.False (tv.Autocomplete.Visible);
  2474. g.AllSuggestions = new List<string> ();
  2475. tv.Autocomplete.ClearSuggestions ();
  2476. Assert.Empty (g.AllSuggestions);
  2477. Assert.Empty (tv.Autocomplete.Suggestions);
  2478. Assert.True (tv.NewKeyDownEvent (new (KeyCode.PageUp)));
  2479. Assert.Equal (24, tv.GetCurrentLine ().Count);
  2480. Assert.Equal (new Point (24, 1), tv.CursorPosition);
  2481. Assert.True (tv.NewKeyDownEvent (new (((int)'V' + KeyCode.AltMask))));
  2482. Assert.Equal (23, tv.GetCurrentLine ().Count);
  2483. Assert.Equal (new Point (23, 0), tv.CursorPosition);
  2484. Assert.True (tv.NewKeyDownEvent (new (KeyCode.PageDown)));
  2485. Assert.Equal (24, tv.GetCurrentLine ().Count);
  2486. Assert.Equal (new Point (23, 1), tv.CursorPosition); // gets the previous length
  2487. Assert.True (tv.NewKeyDownEvent (new (KeyCode.V | KeyCode.CtrlMask)));
  2488. Assert.Equal (28, tv.GetCurrentLine ().Count);
  2489. Assert.Equal (new Point (23, 2), tv.CursorPosition); // gets the previous length
  2490. Assert.Equal (0, tv.SelectedLength);
  2491. Assert.Equal ("", tv.SelectedText);
  2492. Assert.True (tv.NewKeyDownEvent (new (KeyCode.PageUp | KeyCode.ShiftMask)));
  2493. Assert.Equal (24, tv.GetCurrentLine ().Count);
  2494. Assert.Equal (new Point (23, 1), tv.CursorPosition); // gets the previous length
  2495. Assert.Equal (24 + Environment.NewLine.Length, tv.SelectedLength);
  2496. Assert.Equal ($".{Environment.NewLine}This is the third line.", tv.SelectedText);
  2497. Assert.True (tv.NewKeyDownEvent (new (KeyCode.PageDown | KeyCode.ShiftMask)));
  2498. Assert.Equal (28, tv.GetCurrentLine ().Count);
  2499. Assert.Equal (new Point (23, 2), tv.CursorPosition); // gets the previous length
  2500. Assert.Equal (0, tv.SelectedLength);
  2501. Assert.Equal ("", tv.SelectedText);
  2502. Assert.True (tv.NewKeyDownEvent (new (KeyCode.Home | KeyCode.CtrlMask)));
  2503. Assert.Equal (Point.Empty, tv.CursorPosition);
  2504. Assert.True (tv.NewKeyDownEvent (new (KeyCode.N | KeyCode.CtrlMask)));
  2505. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  2506. Assert.Equal (0, tv.SelectedLength);
  2507. Assert.Equal ("", tv.SelectedText);
  2508. Assert.True (tv.NewKeyDownEvent (new (KeyCode.P | KeyCode.CtrlMask)));
  2509. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  2510. Assert.Equal (0, tv.SelectedLength);
  2511. Assert.Equal ("", tv.SelectedText);
  2512. Assert.True (tv.NewKeyDownEvent (new (KeyCode.CursorDown)));
  2513. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  2514. Assert.Equal (0, tv.SelectedLength);
  2515. Assert.Equal ("", tv.SelectedText);
  2516. Assert.True (tv.NewKeyDownEvent (new (KeyCode.CursorUp)));
  2517. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  2518. Assert.Equal (0, tv.SelectedLength);
  2519. Assert.Equal ("", tv.SelectedText);
  2520. Assert.True (tv.NewKeyDownEvent (new (KeyCode.CursorDown | KeyCode.ShiftMask)));
  2521. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  2522. Assert.Equal (23 + Environment.NewLine.Length, tv.SelectedLength);
  2523. Assert.Equal ($"This is the first line.{Environment.NewLine}", tv.SelectedText);
  2524. Assert.True (tv.NewKeyDownEvent (new (KeyCode.CursorUp | KeyCode.ShiftMask)));
  2525. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  2526. Assert.Equal (0, tv.SelectedLength);
  2527. Assert.Equal ("", tv.SelectedText);
  2528. Assert.True (tv.NewKeyDownEvent (new (KeyCode.F | KeyCode.CtrlMask)));
  2529. Assert.Equal (new Point (1, 0), tv.CursorPosition);
  2530. Assert.Equal (0, tv.SelectedLength);
  2531. Assert.Equal ("", tv.SelectedText);
  2532. Assert.True (tv.NewKeyDownEvent (new (KeyCode.B | KeyCode.CtrlMask)));
  2533. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  2534. Assert.Equal (0, tv.SelectedLength);
  2535. Assert.Equal ("", tv.SelectedText);
  2536. Assert.True (tv.NewKeyDownEvent (new (KeyCode.CursorRight)));
  2537. Assert.Equal (new Point (1, 0), tv.CursorPosition);
  2538. Assert.Equal (0, tv.SelectedLength);
  2539. Assert.Equal ("", tv.SelectedText);
  2540. Assert.True (tv.NewKeyDownEvent (new (KeyCode.CursorLeft)));
  2541. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  2542. Assert.Equal (0, tv.SelectedLength);
  2543. Assert.Equal ("", tv.SelectedText);
  2544. Assert.False (tv.Selecting);
  2545. Assert.True (tv.NewKeyDownEvent (new (KeyCode.CursorRight | KeyCode.ShiftMask)));
  2546. Assert.Equal (new Point (1, 0), tv.CursorPosition);
  2547. Assert.Equal (1, tv.SelectedLength);
  2548. Assert.Equal ("T", tv.SelectedText);
  2549. Assert.True (tv.Selecting);
  2550. Assert.True (tv.NewKeyDownEvent (new (KeyCode.CursorLeft | KeyCode.ShiftMask)));
  2551. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  2552. Assert.Equal (0, tv.SelectedLength);
  2553. Assert.Equal ("", tv.SelectedText);
  2554. Assert.True (tv.Selecting);
  2555. Assert.True (tv.NewKeyDownEvent (new (KeyCode.Delete)));
  2556. Assert.Equal ($"This 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.Equal (0, tv.SelectedLength);
  2559. Assert.Equal ("", tv.SelectedText);
  2560. Assert.False (tv.Selecting);
  2561. Assert.True (tv.NewKeyDownEvent (new (KeyCode.Delete)));
  2562. Assert.Equal ($"his 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 (0, 0), tv.CursorPosition);
  2564. Assert.Equal (0, tv.SelectedLength);
  2565. Assert.Equal ("", tv.SelectedText);
  2566. Assert.False (tv.Selecting);
  2567. Assert.True (tv.NewKeyDownEvent (new (KeyCode.D | KeyCode.CtrlMask)));
  2568. Assert.Equal ($"is is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first", tv.Text);
  2569. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  2570. Assert.True (tv.NewKeyDownEvent (new (KeyCode.End)));
  2571. Assert.Equal ($"is is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first", tv.Text);
  2572. Assert.Equal (new Point (21, 0), tv.CursorPosition);
  2573. Assert.True (tv.NewKeyDownEvent (new (KeyCode.Backspace)));
  2574. Assert.Equal ($"is is the first line{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first", tv.Text);
  2575. Assert.Equal (new Point (20, 0), tv.CursorPosition);
  2576. Assert.True (tv.NewKeyDownEvent (new (KeyCode.Backspace)));
  2577. Assert.Equal ($"is is the first lin{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first", tv.Text);
  2578. Assert.Equal (new Point (19, 0), tv.CursorPosition);
  2579. Assert.True (tv.NewKeyDownEvent (new (KeyCode.Home)));
  2580. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  2581. Assert.Equal (0, tv.SelectedLength);
  2582. Assert.Equal ("", tv.SelectedText);
  2583. Assert.False (tv.Selecting);
  2584. Assert.True (tv.NewKeyDownEvent (new (KeyCode.End | KeyCode.ShiftMask)));
  2585. Assert.Equal (new Point (19, 0), tv.CursorPosition);
  2586. Assert.Equal (19, tv.SelectedLength);
  2587. Assert.Equal ("is is the first lin", tv.SelectedText);
  2588. Assert.True (tv.Selecting);
  2589. Assert.True (tv.NewKeyDownEvent (new (KeyCode.Home | KeyCode.ShiftMask)));
  2590. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  2591. Assert.Equal (0, tv.SelectedLength);
  2592. Assert.Equal ("", tv.SelectedText);
  2593. Assert.True (tv.Selecting);
  2594. Assert.True (tv.NewKeyDownEvent (new (KeyCode.E | KeyCode.CtrlMask)));
  2595. Assert.Equal (new Point (19, 0), tv.CursorPosition);
  2596. Assert.Equal (0, tv.SelectedLength);
  2597. Assert.Equal ("", tv.SelectedText);
  2598. Assert.False (tv.Selecting);
  2599. Assert.True (tv.NewKeyDownEvent (new (KeyCode.A | KeyCode.CtrlMask)));
  2600. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  2601. Assert.Equal (0, tv.SelectedLength);
  2602. Assert.Equal ("", tv.SelectedText);
  2603. Assert.False (tv.Selecting);
  2604. Assert.True (tv.NewKeyDownEvent (new (KeyCode.K | KeyCode.CtrlMask)));
  2605. Assert.Equal ($"{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first", tv.Text);
  2606. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  2607. Assert.Equal (0, tv.SelectedLength);
  2608. Assert.Equal ("", tv.SelectedText);
  2609. Assert.False (tv.Selecting);
  2610. Assert.Equal ("is is the first lin", Clipboard.Contents);
  2611. Assert.True (tv.NewKeyDownEvent (new (KeyCode.Y | KeyCode.CtrlMask)));
  2612. Assert.Equal ($"is is the first lin{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first", tv.Text);
  2613. Assert.Equal (new Point (19, 0), tv.CursorPosition);
  2614. Assert.Equal (0, tv.SelectedLength);
  2615. Assert.Equal ("", tv.SelectedText);
  2616. Assert.False (tv.Selecting);
  2617. Assert.Equal ("is is the first lin", Clipboard.Contents);
  2618. tv.CursorPosition = Point.Empty;
  2619. Assert.True (tv.NewKeyDownEvent (new (KeyCode.Delete | KeyCode.CtrlMask | KeyCode.ShiftMask)));
  2620. Assert.Equal ($"{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first", tv.Text);
  2621. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  2622. Assert.Equal (0, tv.SelectedLength);
  2623. Assert.Equal ("", tv.SelectedText);
  2624. Assert.False (tv.Selecting);
  2625. Assert.Equal ("is is the first lin", Clipboard.Contents);
  2626. Assert.True (tv.NewKeyDownEvent (new (KeyCode.Y | KeyCode.CtrlMask)));
  2627. Assert.Equal ($"is is the first lin{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first", tv.Text);
  2628. Assert.Equal (new Point (19, 0), tv.CursorPosition);
  2629. Assert.Equal (0, tv.SelectedLength);
  2630. Assert.Equal ("", tv.SelectedText);
  2631. Assert.False (tv.Selecting);
  2632. Assert.Equal ("is is the first lin", Clipboard.Contents);
  2633. Assert.True (tv.NewKeyDownEvent (new (KeyCode.K | KeyCode.AltMask)));
  2634. Assert.Equal ($"{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first", tv.Text);
  2635. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  2636. Assert.Equal (0, tv.SelectedLength);
  2637. Assert.Equal ("", tv.SelectedText);
  2638. Assert.False (tv.Selecting);
  2639. tv.ReadOnly = true;
  2640. Assert.True (tv.NewKeyDownEvent (new (KeyCode.Y | KeyCode.CtrlMask)));
  2641. Assert.Equal ($"{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first", tv.Text);
  2642. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  2643. Assert.Equal (0, tv.SelectedLength);
  2644. Assert.Equal ("", tv.SelectedText);
  2645. Assert.False (tv.Selecting);
  2646. tv.ReadOnly = false;
  2647. Assert.True (tv.NewKeyDownEvent (new (KeyCode.Y | KeyCode.CtrlMask)));
  2648. Assert.Equal ($"is is the first lin{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first", tv.Text);
  2649. Assert.Equal (new Point (19, 0), tv.CursorPosition);
  2650. Assert.Equal (0, tv.SelectedLength);
  2651. Assert.Equal ("", tv.SelectedText);
  2652. Assert.False (tv.Selecting);
  2653. Assert.Equal (0, tv.SelectionStartColumn);
  2654. Assert.Equal (0, tv.SelectionStartRow);
  2655. Assert.True (tv.NewKeyDownEvent (new (KeyCode.Space | KeyCode.CtrlMask)));
  2656. Assert.Equal ($"is is the first lin{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first", tv.Text);
  2657. Assert.Equal (new Point (19, 0), tv.CursorPosition);
  2658. Assert.Equal (0, tv.SelectedLength);
  2659. Assert.Equal ("", tv.SelectedText);
  2660. Assert.True (tv.Selecting);
  2661. Assert.Equal (19, tv.SelectionStartColumn);
  2662. Assert.Equal (0, tv.SelectionStartRow);
  2663. Assert.True (tv.NewKeyDownEvent (new (KeyCode.Space | KeyCode.CtrlMask)));
  2664. Assert.Equal ($"is is the first lin{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first", tv.Text);
  2665. Assert.Equal (new Point (19, 0), tv.CursorPosition);
  2666. Assert.Equal (0, tv.SelectedLength);
  2667. Assert.Equal ("", tv.SelectedText);
  2668. Assert.False (tv.Selecting);
  2669. Assert.Equal (19, tv.SelectionStartColumn);
  2670. Assert.Equal (0, tv.SelectionStartRow);
  2671. tv.SelectionStartColumn = 0;
  2672. Assert.True (tv.NewKeyDownEvent (new (((int)'C' + KeyCode.AltMask))));
  2673. Assert.Equal ($"is is the first lin{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first", tv.Text);
  2674. Assert.Equal (new Point (19, 0), tv.CursorPosition);
  2675. Assert.Equal (19, tv.SelectedLength);
  2676. Assert.Equal ("is is the first lin", tv.SelectedText);
  2677. Assert.True (tv.Selecting);
  2678. Assert.Equal (0, tv.SelectionStartColumn);
  2679. Assert.Equal (0, tv.SelectionStartRow);
  2680. Assert.True (tv.NewKeyDownEvent (new (KeyCode.C | KeyCode.CtrlMask)));
  2681. Assert.Equal ($"is is the first lin{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first", tv.Text);
  2682. Assert.Equal (new Point (19, 0), tv.CursorPosition);
  2683. Assert.Equal (19, tv.SelectedLength);
  2684. Assert.Equal ("is is the first lin", tv.SelectedText);
  2685. Assert.True (tv.Selecting);
  2686. Assert.Equal (0, tv.SelectionStartColumn);
  2687. Assert.Equal (0, tv.SelectionStartRow);
  2688. Assert.True (tv.NewKeyDownEvent (new (((int)'W' + KeyCode.AltMask))));
  2689. Assert.Equal ($"{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first", tv.Text);
  2690. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  2691. Assert.Equal (0, tv.SelectedLength);
  2692. Assert.Equal ("", tv.SelectedText);
  2693. Assert.False (tv.Selecting);
  2694. Assert.Equal (0, tv.SelectionStartColumn);
  2695. Assert.Equal (0, tv.SelectionStartRow);
  2696. Assert.Equal ("is is the first lin", Clipboard.Contents);
  2697. Assert.True (tv.NewKeyDownEvent (new (KeyCode.W | KeyCode.CtrlMask)));
  2698. Assert.Equal ($"{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first", tv.Text);
  2699. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  2700. Assert.Equal (0, tv.SelectedLength);
  2701. Assert.Equal ("", tv.SelectedText);
  2702. Assert.False (tv.Selecting);
  2703. Assert.Equal (0, tv.SelectionStartColumn);
  2704. Assert.Equal (0, tv.SelectionStartRow);
  2705. Assert.Equal ("", Clipboard.Contents);
  2706. Assert.True (tv.NewKeyDownEvent (new (KeyCode.X | KeyCode.CtrlMask)));
  2707. Assert.Equal ($"{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first", tv.Text);
  2708. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  2709. Assert.Equal (0, tv.SelectedLength);
  2710. Assert.Equal ("", tv.SelectedText);
  2711. Assert.False (tv.Selecting);
  2712. Assert.Equal (0, tv.SelectionStartColumn);
  2713. Assert.Equal (0, tv.SelectionStartRow);
  2714. Assert.Equal ("", Clipboard.Contents);
  2715. Assert.True (tv.NewKeyDownEvent (new (KeyCode.End | KeyCode.CtrlMask)));
  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 (28, 2), tv.CursorPosition);
  2718. Assert.Equal (0, tv.SelectedLength);
  2719. Assert.Equal ("", tv.SelectedText);
  2720. Assert.False (tv.Selecting);
  2721. Assert.True (tv.NewKeyDownEvent (new (KeyCode.CtrlMask | KeyCode.CursorLeft)));
  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 (18, 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.CursorLeft | KeyCode.ShiftMask)));
  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 (6, tv.SelectedLength);
  2731. Assert.Equal ("third ", tv.SelectedText);
  2732. Assert.True (tv.Selecting);
  2733. Assert.True (tv.NewKeyDownEvent (new ((KeyCode)((int)'B' + KeyCode.AltMask))));
  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 (8, 2), tv.CursorPosition);
  2736. Assert.Equal (0, tv.SelectedLength);
  2737. Assert.Equal ("", tv.SelectedText);
  2738. Assert.False (tv.Selecting);
  2739. Assert.True (tv.NewKeyDownEvent (new (KeyCode.CtrlMask | KeyCode.CursorRight)));
  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 (12, 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.CtrlMask | KeyCode.CursorRight | KeyCode.ShiftMask)));
  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 (18, 2), tv.CursorPosition);
  2748. Assert.Equal (6, tv.SelectedLength);
  2749. Assert.Equal ("third ", tv.SelectedText);
  2750. Assert.True (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 (22, 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)((int)'F' + KeyCode.AltMask))));
  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 (23, 2), 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)((int)'F' + KeyCode.AltMask))));
  2764. Assert.Equal ($"{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first", tv.Text);
  2765. Assert.Equal (new Point (28, 2), tv.CursorPosition);
  2766. Assert.Equal (0, tv.SelectedLength);
  2767. Assert.Equal ("", tv.SelectedText);
  2768. Assert.False (tv.Selecting);
  2769. Assert.True (tv.NewKeyDownEvent (new (KeyCode.Home | KeyCode.CtrlMask)));
  2770. Assert.Equal ($"{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first", tv.Text);
  2771. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  2772. Assert.Equal (0, tv.SelectedLength);
  2773. Assert.Equal ("", tv.SelectedText);
  2774. Assert.False (tv.Selecting);
  2775. Assert.True (tv.NewKeyDownEvent (new (KeyCode.Delete | KeyCode.CtrlMask)));
  2776. Assert.Equal ($"This is the second line.{Environment.NewLine}This is the third line.first", tv.Text);
  2777. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  2778. Assert.Equal (0, tv.SelectedLength);
  2779. Assert.Equal ("", tv.SelectedText);
  2780. Assert.False (tv.Selecting); Assert.True (tv.NewKeyDownEvent (new (KeyCode.End | KeyCode.CtrlMask)));
  2781. Assert.Equal ($"This is the second line.{Environment.NewLine}This is the third line.first", tv.Text);
  2782. Assert.Equal (new Point (28, 1), tv.CursorPosition);
  2783. Assert.Equal (0, tv.SelectedLength);
  2784. Assert.Equal ("", tv.SelectedText);
  2785. Assert.False (tv.Selecting);
  2786. Assert.False (tv.Selecting); Assert.True (tv.NewKeyDownEvent (new (KeyCode.Backspace | KeyCode.CtrlMask)));
  2787. Assert.Equal ($"This is the second line.{Environment.NewLine}This is the third ", tv.Text);
  2788. Assert.Equal (new Point (18, 1), tv.CursorPosition);
  2789. Assert.Equal (0, tv.SelectedLength);
  2790. Assert.Equal ("", tv.SelectedText);
  2791. Assert.False (tv.Selecting);
  2792. Assert.True (tv.AllowsReturn);
  2793. tv.AllowsReturn = false;
  2794. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  2795. Assert.False (tv.Selecting);
  2796. Assert.False (tv.NewKeyDownEvent (new (KeyCode.Enter)));
  2797. Assert.Equal ($"This is the second line.{Environment.NewLine}This is the third ", tv.Text);
  2798. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  2799. Assert.Equal (0, tv.SelectedLength);
  2800. Assert.Equal ("", tv.SelectedText);
  2801. Assert.False (tv.Selecting);
  2802. Assert.False (tv.AllowsReturn);
  2803. tv.AllowsReturn = true;
  2804. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  2805. Assert.True (tv.NewKeyDownEvent (new (KeyCode.Enter)));
  2806. Assert.Equal ($"{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third ", tv.Text);
  2807. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  2808. Assert.Equal (0, tv.SelectedLength);
  2809. Assert.Equal ("", tv.SelectedText);
  2810. Assert.False (tv.Selecting);
  2811. Assert.True (tv.AllowsReturn);
  2812. Assert.True (tv.NewKeyDownEvent (new (KeyCode.CtrlMask | KeyCode.End | KeyCode.ShiftMask)));
  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, tv.SelectedLength);
  2816. Assert.Equal ($"This is the second line.{Environment.NewLine}This is the third ", tv.SelectedText);
  2817. Assert.True (tv.Selecting);
  2818. Assert.True (tv.NewKeyDownEvent (new (KeyCode.CtrlMask | KeyCode.Home | KeyCode.ShiftMask)));
  2819. Assert.Equal ($"{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third ", tv.Text);
  2820. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  2821. Assert.Equal (Environment.NewLine.Length, tv.SelectedLength);
  2822. Assert.Equal ($"{Environment.NewLine}", tv.SelectedText);
  2823. Assert.True (tv.Selecting);
  2824. Assert.True (tv.NewKeyDownEvent (new (KeyCode.T | KeyCode.CtrlMask)));
  2825. Assert.Equal ($"{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third ", tv.Text);
  2826. Assert.Equal (new Point (18, 2), tv.CursorPosition);
  2827. Assert.Equal (42 + Environment.NewLine.Length * 2, tv.SelectedLength);
  2828. Assert.Equal ($"{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third ", tv.SelectedText);
  2829. Assert.True (tv.Selecting);
  2830. Assert.True (tv.Used);
  2831. Assert.True (tv.NewKeyDownEvent (new (KeyCode.Insert)));
  2832. Assert.False (tv.Used);
  2833. Assert.True (tv.AllowsTab);
  2834. Assert.Equal (new Point (18, 2), tv.CursorPosition);
  2835. tv.AllowsTab = false;
  2836. Assert.False (tv.NewKeyDownEvent (new (KeyCode.Tab)));
  2837. Assert.Equal ($"{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third ", tv.Text);
  2838. Assert.False (tv.AllowsTab);
  2839. tv.AllowsTab = true;
  2840. Assert.Equal (new Point (18, 2), tv.CursorPosition);
  2841. Assert.True (tv.Selecting);
  2842. tv.Selecting = false;
  2843. Assert.True (tv.NewKeyDownEvent (new (KeyCode.Tab)));
  2844. Assert.Equal ($"{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third \t", tv.Text);
  2845. Assert.True (tv.AllowsTab);
  2846. tv.AllowsTab = false;
  2847. Assert.False (tv.NewKeyDownEvent (new (KeyCode.Tab | KeyCode.ShiftMask)));
  2848. Assert.Equal ($"{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third \t", tv.Text);
  2849. Assert.False (tv.AllowsTab);
  2850. tv.AllowsTab = true;
  2851. Assert.True (tv.NewKeyDownEvent (new (KeyCode.Tab | KeyCode.ShiftMask)));
  2852. Assert.Equal ($"{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third ", tv.Text);
  2853. Assert.True (tv.AllowsTab);
  2854. Assert.False (tv.NewKeyDownEvent (new (KeyCode.Tab | KeyCode.CtrlMask)));
  2855. Assert.False (tv.NewKeyDownEvent (Application.AlternateForwardKey));
  2856. Assert.False (tv.NewKeyDownEvent (new (KeyCode.Tab | KeyCode.CtrlMask | KeyCode.ShiftMask)));
  2857. Assert.False (tv.NewKeyDownEvent (Application.AlternateBackwardKey));
  2858. Assert.True (tv.NewKeyDownEvent (ContextMenu.DefaultKey));
  2859. Assert.True (tv.ContextMenu != null && tv.ContextMenu.MenuBar.Visible);
  2860. }
  2861. [Fact]
  2862. public void HistoryText_Exceptions ()
  2863. {
  2864. var ht = new HistoryText ();
  2865. foreach (var ls in Enum.GetValues (typeof (HistoryText.LineStatus))) {
  2866. if ((HistoryText.LineStatus)ls != HistoryText.LineStatus.Original) {
  2867. Assert.Throws<ArgumentException> (() => ht.Add (new List<List<RuneCell>> () { new List<RuneCell> () }, Point.Empty,
  2868. (HistoryText.LineStatus)ls));
  2869. }
  2870. }
  2871. Assert.Null (Record.Exception (() => ht.Add (new List<List<RuneCell>> () { new List<RuneCell> () }, Point.Empty,
  2872. HistoryText.LineStatus.Original)));
  2873. }
  2874. [Fact]
  2875. [AutoInitShutdown]
  2876. public void HistoryText_Undo_Redo_Single_Line_InsertText ()
  2877. {
  2878. var text = "This is the first line.\nThis is the second line.\nThis is the third line.";
  2879. var tv = new TextView () {
  2880. Width = 10,
  2881. Height = 2,
  2882. Text = text
  2883. };
  2884. var top = Application.Top;
  2885. top.Add (tv);
  2886. Application.Begin (top);
  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 (Point.Empty, tv.CursorPosition);
  2890. var messy = " messy";
  2891. tv.CursorPosition = new Point (7, 1);
  2892. tv.InsertText (messy);
  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. for (int i = 0; i < messy.Length; i++) {
  2897. Assert.True (tv.NewKeyDownEvent (new (KeyCode.Z | KeyCode.CtrlMask)));
  2898. }
  2899. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  2900. Assert.Equal (3, tv.Lines);
  2901. Assert.Equal (new Point (7, 1), tv.CursorPosition);
  2902. for (int i = 0; i < messy.Length; i++) {
  2903. Assert.True (tv.NewKeyDownEvent (new (KeyCode.R | KeyCode.CtrlMask)));
  2904. }
  2905. Assert.Equal ($"This is the first line.{Environment.NewLine}This is messy the second line.{Environment.NewLine}This is the third line.", tv.Text);
  2906. Assert.Equal (3, tv.Lines);
  2907. Assert.Equal (new Point (13, 1), tv.CursorPosition);
  2908. }
  2909. [Fact]
  2910. [AutoInitShutdown]
  2911. public void HistoryText_Undo_Redo_Single_Line_DeleteCharLeft ()
  2912. {
  2913. var text = "This is the first line.\nThis is the second line.\nThis is the third line.";
  2914. var tv = new TextView () {
  2915. Width = 10,
  2916. Height = 2,
  2917. Text = text
  2918. };
  2919. var top = Application.Top;
  2920. top.Add (tv);
  2921. Application.Begin (top);
  2922. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  2923. Assert.Equal (3, tv.Lines);
  2924. Assert.Equal (Point.Empty, tv.CursorPosition);
  2925. var ntimes = 3;
  2926. tv.CursorPosition = new Point (7, 1);
  2927. for (int i = 0; i < ntimes; i++) {
  2928. tv.DeleteCharLeft ();
  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. for (int i = 0; i < ntimes; i++) {
  2934. Assert.True (tv.NewKeyDownEvent (new (KeyCode.Z | KeyCode.CtrlMask)));
  2935. }
  2936. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  2937. Assert.Equal (3, tv.Lines);
  2938. Assert.Equal (new Point (7, 1), tv.CursorPosition);
  2939. for (int i = 0; i < ntimes; i++) {
  2940. Assert.True (tv.NewKeyDownEvent (new (KeyCode.R | KeyCode.CtrlMask)));
  2941. }
  2942. Assert.Equal ($"This is the first line.{Environment.NewLine}This the second line.{Environment.NewLine}This is the third line.", tv.Text);
  2943. Assert.Equal (3, tv.Lines);
  2944. Assert.Equal (new Point (4, 1), tv.CursorPosition);
  2945. }
  2946. [Fact]
  2947. [AutoInitShutdown]
  2948. public void HistoryText_Undo_Redo_Single_Line_DeleteCharRight ()
  2949. {
  2950. var text = "This is the first line.\nThis is the second line.\nThis is the third line.";
  2951. var tv = new TextView () {
  2952. Width = 10,
  2953. Height = 2,
  2954. Text = text
  2955. };
  2956. var top = Application.Top;
  2957. top.Add (tv);
  2958. Application.Begin (top);
  2959. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  2960. Assert.Equal (3, tv.Lines);
  2961. Assert.Equal (Point.Empty, tv.CursorPosition);
  2962. var ntimes = 3;
  2963. tv.CursorPosition = new Point (7, 1);
  2964. for (int i = 0; i < ntimes; i++) {
  2965. tv.DeleteCharRight ();
  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. for (int i = 0; i < ntimes; i++) {
  2971. Assert.True (tv.NewKeyDownEvent (new (KeyCode.Z | KeyCode.CtrlMask)));
  2972. }
  2973. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  2974. Assert.Equal (3, tv.Lines);
  2975. Assert.Equal (new Point (7, 1), tv.CursorPosition);
  2976. for (int i = 0; i < ntimes; i++) {
  2977. Assert.True (tv.NewKeyDownEvent (new (KeyCode.R | KeyCode.CtrlMask)));
  2978. }
  2979. Assert.Equal ($"This is the first line.{Environment.NewLine}This ise second line.{Environment.NewLine}This is the third line.", tv.Text);
  2980. Assert.Equal (3, tv.Lines);
  2981. Assert.Equal (new Point (7, 1), tv.CursorPosition);
  2982. }
  2983. [Fact]
  2984. [AutoInitShutdown]
  2985. public void HistoryText_Undo_Redo_Single_Line_Selected_InsertText ()
  2986. {
  2987. var text = "This is the first line.\nThis is the second line.\nThis is the third line.";
  2988. var tv = new TextView () {
  2989. Width = 10,
  2990. Height = 2,
  2991. Text = text
  2992. };
  2993. var top = Application.Top;
  2994. top.Add (tv);
  2995. Application.Begin (top);
  2996. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  2997. Assert.Equal (3, tv.Lines);
  2998. Assert.Equal (Point.Empty, tv.CursorPosition);
  2999. var messy = " messy";
  3000. tv.CursorPosition = new Point (7, 1);
  3001. tv.SelectionStartColumn = 11;
  3002. tv.SelectionStartRow = 1;
  3003. Assert.Equal (4, tv.SelectedLength);
  3004. tv.InsertText (messy);
  3005. Assert.Equal ($"This is the first line.{Environment.NewLine}This is messy second line.{Environment.NewLine}This is the third line.", tv.Text);
  3006. Assert.Equal (3, tv.Lines);
  3007. Assert.Equal (new Point (13, 1), tv.CursorPosition);
  3008. Assert.Equal (11, tv.SelectionStartColumn);
  3009. Assert.Equal (1, tv.SelectionStartRow);
  3010. Assert.Equal (0, tv.SelectedLength);
  3011. for (int i = 0; i < messy.Length; i++) {
  3012. Assert.True (tv.NewKeyDownEvent (new (KeyCode.Z | KeyCode.CtrlMask)));
  3013. }
  3014. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  3015. Assert.Equal (3, tv.Lines);
  3016. Assert.Equal (new Point (7, 1), tv.CursorPosition);
  3017. Assert.Equal (11, tv.SelectionStartColumn);
  3018. Assert.Equal (1, tv.SelectionStartRow);
  3019. Assert.Equal (0, tv.SelectedLength);
  3020. for (int i = 0; i < messy.Length; i++) {
  3021. Assert.True (tv.NewKeyDownEvent (new (KeyCode.R | KeyCode.CtrlMask)));
  3022. }
  3023. Assert.Equal ($"This is the first line.{Environment.NewLine}This is messy second line.{Environment.NewLine}This is the third line.", tv.Text);
  3024. Assert.Equal (3, tv.Lines);
  3025. Assert.Equal (new Point (13, 1), tv.CursorPosition);
  3026. Assert.Equal (11, tv.SelectionStartColumn);
  3027. Assert.Equal (1, tv.SelectionStartRow);
  3028. Assert.Equal (0, tv.SelectedLength);
  3029. }
  3030. [Fact]
  3031. [AutoInitShutdown]
  3032. public void HistoryText_Undo_Redo_Single_Line_Selected_DeleteCharLeft ()
  3033. {
  3034. var text = "This is the first line.\nThis is the second line.\nThis is the third line.";
  3035. var tv = new TextView () {
  3036. Width = 10,
  3037. Height = 2,
  3038. Text = text
  3039. };
  3040. var top = Application.Top;
  3041. top.Add (tv);
  3042. Application.Begin (top);
  3043. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  3044. Assert.Equal (3, tv.Lines);
  3045. Assert.Equal (Point.Empty, tv.CursorPosition);
  3046. var ntimes = 3;
  3047. tv.CursorPosition = new Point (7, 1);
  3048. tv.SelectionStartColumn = 11;
  3049. tv.SelectionStartRow = 1;
  3050. Assert.Equal (4, tv.SelectedLength);
  3051. for (int i = 0; i < ntimes; i++) {
  3052. tv.DeleteCharLeft ();
  3053. }
  3054. Assert.Equal ($"This is the first line.{Environment.NewLine}This second line.{Environment.NewLine}This is the third line.", tv.Text);
  3055. Assert.Equal (3, tv.Lines);
  3056. Assert.Equal (new Point (5, 1), tv.CursorPosition);
  3057. Assert.Equal (11, tv.SelectionStartColumn);
  3058. Assert.Equal (1, tv.SelectionStartRow);
  3059. Assert.Equal (0, tv.SelectedLength);
  3060. for (int i = 0; i < ntimes; i++) {
  3061. Assert.True (tv.NewKeyDownEvent (new (KeyCode.Z | KeyCode.CtrlMask)));
  3062. }
  3063. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  3064. Assert.Equal (3, tv.Lines);
  3065. Assert.Equal (new Point (7, 1), tv.CursorPosition);
  3066. Assert.Equal (11, tv.SelectionStartColumn);
  3067. Assert.Equal (1, tv.SelectionStartRow);
  3068. Assert.Equal (0, tv.SelectedLength);
  3069. for (int i = 0; i < ntimes; i++) {
  3070. Assert.True (tv.NewKeyDownEvent (new (KeyCode.R | KeyCode.CtrlMask)));
  3071. }
  3072. Assert.Equal ($"This is the first line.{Environment.NewLine}This second line.{Environment.NewLine}This is the third line.", tv.Text);
  3073. Assert.Equal (3, tv.Lines);
  3074. Assert.Equal (new Point (5, 1), tv.CursorPosition);
  3075. Assert.Equal (11, tv.SelectionStartColumn);
  3076. Assert.Equal (1, tv.SelectionStartRow);
  3077. Assert.Equal (0, tv.SelectedLength);
  3078. }
  3079. [Fact]
  3080. [AutoInitShutdown]
  3081. public void HistoryText_Undo_Redo_Single_Line_Selected_DeleteCharRight ()
  3082. {
  3083. var text = "This is the first line.\nThis is the second line.\nThis is the third line.";
  3084. var tv = new TextView () {
  3085. Width = 10,
  3086. Height = 2,
  3087. Text = text
  3088. };
  3089. var top = Application.Top;
  3090. top.Add (tv);
  3091. Application.Begin (top);
  3092. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  3093. Assert.Equal (3, tv.Lines);
  3094. Assert.Equal (Point.Empty, tv.CursorPosition);
  3095. var ntimes = 3;
  3096. tv.CursorPosition = new Point (7, 1);
  3097. tv.SelectionStartColumn = 11;
  3098. tv.SelectionStartRow = 1;
  3099. Assert.Equal (4, tv.SelectedLength);
  3100. for (int i = 0; i < ntimes; i++) {
  3101. tv.DeleteCharRight ();
  3102. }
  3103. Assert.Equal ($"This is the first line.{Environment.NewLine}This isecond line.{Environment.NewLine}This is the third line.", tv.Text);
  3104. Assert.Equal (3, tv.Lines);
  3105. Assert.Equal (new Point (7, 1), tv.CursorPosition);
  3106. Assert.Equal (11, tv.SelectionStartColumn);
  3107. Assert.Equal (1, tv.SelectionStartRow);
  3108. Assert.Equal (0, tv.SelectedLength);
  3109. for (int i = 0; i < ntimes; i++) {
  3110. Assert.True (tv.NewKeyDownEvent (new (KeyCode.Z | KeyCode.CtrlMask)));
  3111. }
  3112. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  3113. Assert.Equal (3, tv.Lines);
  3114. Assert.Equal (new Point (7, 1), tv.CursorPosition);
  3115. Assert.Equal (11, tv.SelectionStartColumn);
  3116. Assert.Equal (1, tv.SelectionStartRow);
  3117. Assert.Equal (0, tv.SelectedLength);
  3118. for (int i = 0; i < ntimes; i++) {
  3119. Assert.True (tv.NewKeyDownEvent (new (KeyCode.R | KeyCode.CtrlMask)));
  3120. }
  3121. Assert.Equal ($"This is the first line.{Environment.NewLine}This isecond line.{Environment.NewLine}This is the third line.", tv.Text);
  3122. Assert.Equal (3, tv.Lines);
  3123. Assert.Equal (new Point (7, 1), tv.CursorPosition);
  3124. Assert.Equal (11, tv.SelectionStartColumn);
  3125. Assert.Equal (1, tv.SelectionStartRow);
  3126. Assert.Equal (0, tv.SelectedLength);
  3127. }
  3128. [Fact]
  3129. [AutoInitShutdown]
  3130. public void HistoryText_Undo_Redo_Multi_Line_InsertText ()
  3131. {
  3132. var text = "This is the first line.\nThis is the second line.\nThis is the third line.";
  3133. var tv = new TextView () {
  3134. Width = 10,
  3135. Height = 2,
  3136. Text = text
  3137. };
  3138. var top = Application.Top;
  3139. top.Add (tv);
  3140. Application.Begin (top);
  3141. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  3142. Assert.Equal (3, tv.Lines);
  3143. Assert.Equal (Point.Empty, tv.CursorPosition);
  3144. var messy = " messy";
  3145. tv.CursorPosition = new Point (7, 1);
  3146. tv.InsertText (messy);
  3147. Assert.Equal ($"This is the first line.{Environment.NewLine}This is messy the second line.{Environment.NewLine}This is the third line.", tv.Text);
  3148. Assert.Equal (3, tv.Lines);
  3149. Assert.Equal (new Point (13, 1), tv.CursorPosition);
  3150. tv.CursorPosition = new Point (7, 0);
  3151. tv.InsertText (messy);
  3152. 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);
  3153. Assert.Equal (3, tv.Lines);
  3154. Assert.Equal (new Point (13, 0), tv.CursorPosition);
  3155. tv.CursorPosition = new Point (7, 2);
  3156. tv.InsertText (messy);
  3157. 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);
  3158. Assert.Equal (3, tv.Lines);
  3159. Assert.Equal (new Point (13, 2), 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 messy the first line.{Environment.NewLine}This is messy the second line.{Environment.NewLine}This is the third line.", tv.Text);
  3164. Assert.Equal (3, tv.Lines);
  3165. Assert.Equal (new Point (7, 2), tv.CursorPosition);
  3166. for (int i = 0; i < messy.Length; i++) {
  3167. Assert.True (tv.NewKeyDownEvent (new (KeyCode.Z | 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 (7, 0), tv.CursorPosition);
  3172. for (int i = 0; i < messy.Length; i++) {
  3173. Assert.True (tv.NewKeyDownEvent (new (KeyCode.Z | KeyCode.CtrlMask)));
  3174. }
  3175. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  3176. Assert.Equal (3, tv.Lines);
  3177. Assert.Equal (new Point (7, 1), 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 the first line.{Environment.NewLine}This is messy the second line.{Environment.NewLine}This is the third line.", tv.Text);
  3182. Assert.Equal (3, tv.Lines);
  3183. Assert.Equal (new Point (13, 1), tv.CursorPosition);
  3184. for (int i = 0; i < messy.Length; i++) {
  3185. Assert.True (tv.NewKeyDownEvent (new (KeyCode.R | KeyCode.CtrlMask)));
  3186. }
  3187. 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);
  3188. Assert.Equal (3, tv.Lines);
  3189. Assert.Equal (new Point (13, 0), tv.CursorPosition);
  3190. for (int i = 0; i < messy.Length; i++) {
  3191. Assert.True (tv.NewKeyDownEvent (new (KeyCode.R | KeyCode.CtrlMask)));
  3192. }
  3193. 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);
  3194. Assert.Equal (3, tv.Lines);
  3195. Assert.Equal (new Point (13, 2), tv.CursorPosition);
  3196. }
  3197. [Fact]
  3198. [AutoInitShutdown]
  3199. public void HistoryText_Undo_Redo_Multi_Line_DeleteCharLeft ()
  3200. {
  3201. var text = "This is the first line.\nThis is the second line.\nThis is the third line.";
  3202. var tv = new TextView () {
  3203. Width = 10,
  3204. Height = 2,
  3205. Text = text
  3206. };
  3207. var top = Application.Top;
  3208. top.Add (tv);
  3209. Application.Begin (top);
  3210. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  3211. Assert.Equal (3, tv.Lines);
  3212. Assert.Equal (Point.Empty, tv.CursorPosition);
  3213. var ntimes = 3;
  3214. tv.CursorPosition = new Point (7, 1);
  3215. for (int i = 0; i < ntimes; i++) {
  3216. tv.DeleteCharLeft ();
  3217. }
  3218. Assert.Equal ($"This is the first line.{Environment.NewLine}This the second line.{Environment.NewLine}This is the third line.", tv.Text);
  3219. Assert.Equal (3, tv.Lines);
  3220. Assert.Equal (new Point (4, 1), tv.CursorPosition);
  3221. tv.CursorPosition = new Point (7, 0);
  3222. for (int i = 0; i < ntimes; i++) {
  3223. tv.DeleteCharLeft ();
  3224. }
  3225. Assert.Equal ($"This the first line.{Environment.NewLine}This the second line.{Environment.NewLine}This is the third line.", tv.Text);
  3226. Assert.Equal (3, tv.Lines);
  3227. Assert.Equal (new Point (4, 0), tv.CursorPosition);
  3228. tv.CursorPosition = new Point (7, 2);
  3229. for (int i = 0; i < ntimes; i++) {
  3230. tv.DeleteCharLeft ();
  3231. }
  3232. Assert.Equal ($"This the first line.{Environment.NewLine}This the second line.{Environment.NewLine}This the third line.", tv.Text);
  3233. Assert.Equal (3, tv.Lines);
  3234. Assert.Equal (new Point (4, 2), tv.CursorPosition);
  3235. for (int i = 0; i < ntimes; i++) {
  3236. Assert.True (tv.NewKeyDownEvent (new (KeyCode.Z | KeyCode.CtrlMask)));
  3237. switch (i) {
  3238. case 0:
  3239. Assert.Equal ($"This the first line.{Environment.NewLine}This the second line.{Environment.NewLine}This the third line.", tv.Text);
  3240. Assert.Equal (new Point (5, 2), tv.CursorPosition);
  3241. break;
  3242. case 1:
  3243. Assert.Equal ($"This the first line.{Environment.NewLine}This the second line.{Environment.NewLine}This i the third line.", tv.Text);
  3244. Assert.Equal (new Point (6, 2), tv.CursorPosition);
  3245. break;
  3246. case 2:
  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 (7, 2), tv.CursorPosition);
  3249. break;
  3250. }
  3251. }
  3252. Assert.Equal ($"This the first line.{Environment.NewLine}This the second line.{Environment.NewLine}This is the third line.", tv.Text);
  3253. Assert.Equal (3, tv.Lines);
  3254. Assert.Equal (new Point (7, 2), tv.CursorPosition);
  3255. for (int i = 0; i < ntimes; i++) {
  3256. Assert.True (tv.NewKeyDownEvent (new (KeyCode.Z | KeyCode.CtrlMask)));
  3257. switch (i) {
  3258. case 0:
  3259. Assert.Equal ($"This the first line.{Environment.NewLine}This the second line.{Environment.NewLine}This is the third line.", tv.Text);
  3260. Assert.Equal (new Point (5, 0), tv.CursorPosition);
  3261. break;
  3262. case 1:
  3263. Assert.Equal ($"This i the first line.{Environment.NewLine}This the second line.{Environment.NewLine}This is the third line.", tv.Text);
  3264. Assert.Equal (new Point (6, 0), tv.CursorPosition);
  3265. break;
  3266. case 2:
  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 (7, 0), tv.CursorPosition);
  3269. break;
  3270. }
  3271. }
  3272. Assert.Equal ($"This is the first line.{Environment.NewLine}This the second line.{Environment.NewLine}This is the third line.", tv.Text);
  3273. Assert.Equal (3, tv.Lines);
  3274. Assert.Equal (new Point (7, 0), tv.CursorPosition);
  3275. for (int i = 0; i < ntimes; i++) {
  3276. Assert.True (tv.NewKeyDownEvent (new (KeyCode.Z | KeyCode.CtrlMask)));
  3277. switch (i) {
  3278. case 0:
  3279. Assert.Equal ($"This is the first line.{Environment.NewLine}This the second line.{Environment.NewLine}This is the third line.", tv.Text);
  3280. Assert.Equal (new Point (5, 1), tv.CursorPosition);
  3281. break;
  3282. case 1:
  3283. Assert.Equal ($"This is the first line.{Environment.NewLine}This i the second line.{Environment.NewLine}This is the third line.", tv.Text);
  3284. Assert.Equal (new Point (6, 1), tv.CursorPosition);
  3285. break;
  3286. case 2:
  3287. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  3288. Assert.Equal (new Point (7, 1), tv.CursorPosition);
  3289. break;
  3290. }
  3291. }
  3292. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  3293. Assert.Equal (3, tv.Lines);
  3294. Assert.Equal (new Point (7, 1), 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 is the first line.{Environment.NewLine}This the second line.{Environment.NewLine}This is the third line.", tv.Text);
  3299. Assert.Equal (3, tv.Lines);
  3300. Assert.Equal (new Point (4, 1), tv.CursorPosition);
  3301. for (int i = 0; i < ntimes; i++) {
  3302. Assert.True (tv.NewKeyDownEvent (new (KeyCode.R | KeyCode.CtrlMask)));
  3303. }
  3304. Assert.Equal ($"This the first line.{Environment.NewLine}This the second line.{Environment.NewLine}This is the third line.", tv.Text);
  3305. Assert.Equal (3, tv.Lines);
  3306. Assert.Equal (new Point (4, 0), tv.CursorPosition);
  3307. for (int i = 0; i < ntimes; i++) {
  3308. Assert.True (tv.NewKeyDownEvent (new (KeyCode.R | KeyCode.CtrlMask)));
  3309. }
  3310. Assert.Equal ($"This the first line.{Environment.NewLine}This the second line.{Environment.NewLine}This the third line.", tv.Text);
  3311. Assert.Equal (3, tv.Lines);
  3312. Assert.Equal (new Point (4, 2), tv.CursorPosition);
  3313. }
  3314. [Fact]
  3315. [AutoInitShutdown]
  3316. public void HistoryText_Undo_Redo_Multi_Line_DeleteCharRight ()
  3317. {
  3318. var text = "This is the first line.\nThis is the second line.\nThis is the third line.";
  3319. var tv = new TextView () {
  3320. Width = 10,
  3321. Height = 2,
  3322. Text = text
  3323. };
  3324. var top = Application.Top;
  3325. top.Add (tv);
  3326. Application.Begin (top);
  3327. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  3328. Assert.Equal (3, tv.Lines);
  3329. Assert.Equal (Point.Empty, tv.CursorPosition);
  3330. var ntimes = 3;
  3331. tv.CursorPosition = new Point (7, 1);
  3332. for (int i = 0; i < ntimes; i++) {
  3333. tv.DeleteCharRight ();
  3334. }
  3335. Assert.Equal ($"This is the first line.{Environment.NewLine}This ise second line.{Environment.NewLine}This is the third line.", tv.Text);
  3336. Assert.Equal (3, tv.Lines);
  3337. Assert.Equal (new Point (7, 1), tv.CursorPosition);
  3338. tv.CursorPosition = new Point (7, 0);
  3339. for (int i = 0; i < ntimes; i++) {
  3340. tv.DeleteCharRight ();
  3341. }
  3342. Assert.Equal ($"This ise first line.{Environment.NewLine}This ise second line.{Environment.NewLine}This is the third line.", tv.Text);
  3343. Assert.Equal (3, tv.Lines);
  3344. Assert.Equal (new Point (7, 0), tv.CursorPosition);
  3345. tv.CursorPosition = new Point (7, 2);
  3346. for (int i = 0; i < ntimes; i++) {
  3347. tv.DeleteCharRight ();
  3348. }
  3349. Assert.Equal ($"This ise first line.{Environment.NewLine}This ise second line.{Environment.NewLine}This ise third line.", tv.Text);
  3350. Assert.Equal (3, tv.Lines);
  3351. Assert.Equal (new Point (7, 2), 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 ise first line.{Environment.NewLine}This ise second line.{Environment.NewLine}This is the third line.", tv.Text);
  3356. Assert.Equal (3, tv.Lines);
  3357. Assert.Equal (new Point (7, 2), tv.CursorPosition);
  3358. for (int i = 0; i < ntimes; i++) {
  3359. Assert.True (tv.NewKeyDownEvent (new (KeyCode.Z | 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, 0), tv.CursorPosition);
  3364. for (int i = 0; i < ntimes; i++) {
  3365. Assert.True (tv.NewKeyDownEvent (new (KeyCode.Z | KeyCode.CtrlMask)));
  3366. }
  3367. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  3368. Assert.Equal (3, tv.Lines);
  3369. Assert.Equal (new Point (7, 1), 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 is the first line.{Environment.NewLine}This ise second line.{Environment.NewLine}This is the third line.", tv.Text);
  3374. Assert.Equal (3, tv.Lines);
  3375. Assert.Equal (new Point (7, 1), tv.CursorPosition);
  3376. for (int i = 0; i < ntimes; i++) {
  3377. Assert.True (tv.NewKeyDownEvent (new (KeyCode.R | KeyCode.CtrlMask)));
  3378. }
  3379. Assert.Equal ($"This ise first line.{Environment.NewLine}This ise second line.{Environment.NewLine}This is the third line.", tv.Text);
  3380. Assert.Equal (3, tv.Lines);
  3381. Assert.Equal (new Point (7, 0), tv.CursorPosition);
  3382. for (int i = 0; i < ntimes; i++) {
  3383. Assert.True (tv.NewKeyDownEvent (new (KeyCode.R | KeyCode.CtrlMask)));
  3384. }
  3385. Assert.Equal ($"This ise first line.{Environment.NewLine}This ise second line.{Environment.NewLine}This ise third line.", tv.Text);
  3386. Assert.Equal (3, tv.Lines);
  3387. Assert.Equal (new Point (7, 2), tv.CursorPosition);
  3388. }
  3389. [Fact]
  3390. [AutoInitShutdown]
  3391. public void HistoryText_Undo_Redo_Multi_Line_Selected_InsertText ()
  3392. {
  3393. var text = $"This is the first line.{Environment.NewLine}This is the second line.\nThis is the third line.";
  3394. var tv = new TextView () {
  3395. Width = 10,
  3396. Height = 2,
  3397. Text = text
  3398. };
  3399. var top = Application.Top;
  3400. top.Add (tv);
  3401. Application.Begin (top);
  3402. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  3403. Assert.Equal (3, tv.Lines);
  3404. Assert.Equal (Point.Empty, tv.CursorPosition);
  3405. var messy = " messy";
  3406. tv.CursorPosition = new Point (7, 0);
  3407. tv.SelectionStartColumn = 11;
  3408. tv.SelectionStartRow = 2;
  3409. Assert.Equal (51 + Environment.NewLine.Length * 2, tv.SelectedLength);
  3410. for (int i = 0; i < messy.Length; i++) {
  3411. tv.InsertText (messy [i].ToString ());
  3412. switch (i) {
  3413. case 0:
  3414. Assert.Equal ("This is third line.", tv.Text);
  3415. Assert.Equal (new Point (8, 0), tv.CursorPosition);
  3416. break;
  3417. case 1:
  3418. Assert.Equal ("This is m third line.", tv.Text);
  3419. Assert.Equal (new Point (9, 0), tv.CursorPosition);
  3420. break;
  3421. case 2:
  3422. Assert.Equal ("This is me third line.", tv.Text);
  3423. Assert.Equal (new Point (10, 0), tv.CursorPosition);
  3424. break;
  3425. case 3:
  3426. Assert.Equal ("This is mes third line.", tv.Text);
  3427. Assert.Equal (new Point (11, 0), tv.CursorPosition);
  3428. break;
  3429. case 4:
  3430. Assert.Equal ("This is mess third line.", tv.Text);
  3431. Assert.Equal (new Point (12, 0), tv.CursorPosition);
  3432. break;
  3433. case 5:
  3434. Assert.Equal ("This is messy third line.", tv.Text);
  3435. Assert.Equal (new Point (13, 0), tv.CursorPosition);
  3436. break;
  3437. }
  3438. }
  3439. Assert.Equal ($"This is messy third line.", tv.Text);
  3440. Assert.Equal (1, tv.Lines);
  3441. Assert.Equal (new Point (13, 0), tv.CursorPosition);
  3442. Assert.Equal (11, tv.SelectionStartColumn);
  3443. Assert.Equal (2, tv.SelectionStartRow);
  3444. Assert.Equal (0, tv.SelectedLength);
  3445. for (int i = 0; i < messy.Length; i++) {
  3446. Assert.True (tv.NewKeyDownEvent (new (KeyCode.Z | KeyCode.CtrlMask)));
  3447. switch (i) {
  3448. case 0:
  3449. Assert.Equal ("This is mess third line.", tv.Text);
  3450. Assert.Equal (new Point (12, 0), tv.CursorPosition);
  3451. break;
  3452. case 1:
  3453. Assert.Equal ("This is mes third line.", tv.Text);
  3454. Assert.Equal (new Point (11, 0), tv.CursorPosition);
  3455. break;
  3456. case 2:
  3457. Assert.Equal ("This is me third line.", tv.Text);
  3458. Assert.Equal (new Point (10, 0), tv.CursorPosition);
  3459. break;
  3460. case 3:
  3461. Assert.Equal ("This is m third line.", tv.Text);
  3462. Assert.Equal (new Point (9, 0), tv.CursorPosition);
  3463. break;
  3464. case 4:
  3465. Assert.Equal ("This is third line.", tv.Text);
  3466. Assert.Equal (new Point (8, 0), tv.CursorPosition);
  3467. break;
  3468. case 5:
  3469. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  3470. Assert.Equal (new Point (7, 0), tv.CursorPosition);
  3471. break;
  3472. }
  3473. }
  3474. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  3475. Assert.Equal (3, tv.Lines);
  3476. Assert.Equal (new Point (7, 0), tv.CursorPosition);
  3477. Assert.Equal (11, tv.SelectionStartColumn);
  3478. Assert.Equal (2, tv.SelectionStartRow);
  3479. Assert.Equal (0, tv.SelectedLength);
  3480. for (int i = 0; i < messy.Length; i++) {
  3481. Assert.True (tv.NewKeyDownEvent (new (KeyCode.R | KeyCode.CtrlMask)));
  3482. switch (i) {
  3483. case 0:
  3484. Assert.Equal ("This is third line.", tv.Text);
  3485. Assert.Equal (new Point (8, 0), tv.CursorPosition);
  3486. break;
  3487. case 1:
  3488. Assert.Equal ("This is m third line.", tv.Text);
  3489. Assert.Equal (new Point (9, 0), tv.CursorPosition);
  3490. break;
  3491. case 2:
  3492. Assert.Equal ("This is me third line.", tv.Text);
  3493. Assert.Equal (new Point (10, 0), tv.CursorPosition);
  3494. break;
  3495. case 3:
  3496. Assert.Equal ("This is mes third line.", tv.Text);
  3497. Assert.Equal (new Point (11, 0), tv.CursorPosition);
  3498. break;
  3499. case 4:
  3500. Assert.Equal ("This is mess third line.", tv.Text);
  3501. Assert.Equal (new Point (12, 0), tv.CursorPosition);
  3502. break;
  3503. case 5:
  3504. Assert.Equal ("This is messy third line.", tv.Text);
  3505. Assert.Equal (new Point (13, 0), tv.CursorPosition);
  3506. break;
  3507. }
  3508. }
  3509. Assert.Equal ("This is messy third line.", tv.Text);
  3510. Assert.Equal (1, tv.Lines);
  3511. Assert.Equal (new Point (13, 0), tv.CursorPosition);
  3512. Assert.Equal (11, tv.SelectionStartColumn);
  3513. Assert.Equal (2, tv.SelectionStartRow);
  3514. Assert.Equal (0, tv.SelectedLength);
  3515. }
  3516. [Fact]
  3517. [AutoInitShutdown]
  3518. public void HistoryText_Undo_Redo_Multi_Line_With_Empty_Text ()
  3519. {
  3520. var tv = new TextView () {
  3521. Width = 10,
  3522. Height = 2
  3523. };
  3524. var top = Application.Top;
  3525. top.Add (tv);
  3526. Application.Begin (top);
  3527. Assert.Equal ("", tv.Text);
  3528. Assert.Equal (1, tv.Lines);
  3529. Assert.Equal (Point.Empty, tv.CursorPosition);
  3530. Assert.False (tv.IsDirty);
  3531. Assert.True (tv.NewKeyDownEvent (new (KeyCode.O | KeyCode.ShiftMask)));
  3532. Assert.Equal ("O", tv.Text);
  3533. Assert.Equal (1, tv.Lines);
  3534. Assert.Equal (new Point (1, 0), tv.CursorPosition);
  3535. Assert.True (tv.IsDirty);
  3536. Assert.True (tv.NewKeyDownEvent (new ((KeyCode)'n')));
  3537. Assert.Equal ("On", tv.Text);
  3538. Assert.Equal (1, tv.Lines);
  3539. Assert.Equal (new Point (2, 0), tv.CursorPosition);
  3540. Assert.True (tv.IsDirty);
  3541. Assert.True (tv.NewKeyDownEvent (new ((KeyCode)'e')));
  3542. Assert.Equal ("One", tv.Text);
  3543. Assert.Equal (1, tv.Lines);
  3544. Assert.Equal (new Point (3, 0), tv.CursorPosition);
  3545. Assert.True (tv.IsDirty);
  3546. Assert.True (tv.NewKeyDownEvent (new (KeyCode.Enter)));
  3547. Assert.Equal ($"One{Environment.NewLine}", tv.Text);
  3548. Assert.Equal (2, tv.Lines);
  3549. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  3550. Assert.True (tv.IsDirty);
  3551. Assert.True (tv.NewKeyDownEvent (new (KeyCode.T | KeyCode.ShiftMask)));
  3552. Assert.Equal ($"One{Environment.NewLine}T", tv.Text);
  3553. Assert.Equal (2, tv.Lines);
  3554. Assert.Equal (new Point (1, 1), tv.CursorPosition);
  3555. Assert.True (tv.IsDirty);
  3556. Assert.True (tv.NewKeyDownEvent (new ((KeyCode)'w')));
  3557. Assert.Equal ($"One{Environment.NewLine}Tw", tv.Text);
  3558. Assert.Equal (2, tv.Lines);
  3559. Assert.Equal (new Point (2, 1), tv.CursorPosition);
  3560. Assert.True (tv.IsDirty);
  3561. Assert.True (tv.NewKeyDownEvent (new ((KeyCode)'o')));
  3562. Assert.Equal ($"One{Environment.NewLine}Two", tv.Text);
  3563. Assert.Equal (2, tv.Lines);
  3564. Assert.Equal (new Point (3, 1), tv.CursorPosition);
  3565. Assert.True (tv.IsDirty);
  3566. Assert.True (tv.NewKeyDownEvent (new (KeyCode.Enter)));
  3567. Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}", tv.Text);
  3568. Assert.Equal (3, tv.Lines);
  3569. Assert.Equal (new Point (0, 2), tv.CursorPosition);
  3570. Assert.True (tv.IsDirty);
  3571. Assert.True (tv.NewKeyDownEvent (new (KeyCode.T | KeyCode.ShiftMask)));
  3572. Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}T", tv.Text);
  3573. Assert.Equal (3, tv.Lines);
  3574. Assert.Equal (new Point (1, 2), tv.CursorPosition);
  3575. Assert.True (tv.IsDirty);
  3576. Assert.True (tv.NewKeyDownEvent (new ((KeyCode)'h')));
  3577. Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}Th", tv.Text);
  3578. Assert.Equal (3, tv.Lines);
  3579. Assert.Equal (new Point (2, 2), tv.CursorPosition);
  3580. Assert.True (tv.IsDirty);
  3581. Assert.True (tv.NewKeyDownEvent (new ((KeyCode)'r')));
  3582. Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}Thr", tv.Text);
  3583. Assert.Equal (3, tv.Lines);
  3584. Assert.Equal (new Point (3, 2), tv.CursorPosition);
  3585. Assert.True (tv.IsDirty);
  3586. Assert.True (tv.NewKeyDownEvent (new ((KeyCode)'e')));
  3587. Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}Thre", tv.Text);
  3588. Assert.Equal (3, tv.Lines);
  3589. Assert.Equal (new Point (4, 2), tv.CursorPosition);
  3590. Assert.True (tv.IsDirty);
  3591. Assert.True (tv.NewKeyDownEvent (new ((KeyCode)'e')));
  3592. Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}Three", tv.Text);
  3593. Assert.Equal (3, tv.Lines);
  3594. Assert.Equal (new Point (5, 2), tv.CursorPosition);
  3595. Assert.True (tv.IsDirty);
  3596. Assert.True (tv.NewKeyDownEvent (new (KeyCode.Enter)));
  3597. Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}Three{Environment.NewLine}", tv.Text);
  3598. Assert.Equal (4, tv.Lines);
  3599. Assert.Equal (new Point (0, 3), tv.CursorPosition);
  3600. Assert.True (tv.IsDirty);
  3601. // Undoing
  3602. Assert.True (tv.NewKeyDownEvent (new (KeyCode.Z | KeyCode.CtrlMask)));
  3603. Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}Three", tv.Text);
  3604. Assert.Equal (3, tv.Lines);
  3605. Assert.Equal (new Point (5, 2), tv.CursorPosition);
  3606. Assert.True (tv.IsDirty);
  3607. Assert.True (tv.NewKeyDownEvent (new (KeyCode.Z | KeyCode.CtrlMask)));
  3608. Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}Thre", tv.Text);
  3609. Assert.Equal (3, tv.Lines);
  3610. Assert.Equal (new Point (4, 2), tv.CursorPosition);
  3611. Assert.True (tv.IsDirty);
  3612. Assert.True (tv.NewKeyDownEvent (new (KeyCode.Z | KeyCode.CtrlMask)));
  3613. Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}Thr", tv.Text);
  3614. Assert.Equal (3, tv.Lines);
  3615. Assert.Equal (new Point (3, 2), tv.CursorPosition);
  3616. Assert.True (tv.IsDirty);
  3617. Assert.True (tv.NewKeyDownEvent (new (KeyCode.Z | KeyCode.CtrlMask)));
  3618. Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}Th", tv.Text);
  3619. Assert.Equal (3, tv.Lines);
  3620. Assert.Equal (new Point (2, 2), tv.CursorPosition);
  3621. Assert.True (tv.IsDirty);
  3622. Assert.True (tv.NewKeyDownEvent (new (KeyCode.Z | KeyCode.CtrlMask)));
  3623. Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}T", tv.Text);
  3624. Assert.Equal (3, tv.Lines);
  3625. Assert.Equal (new Point (1, 2), tv.CursorPosition);
  3626. Assert.True (tv.IsDirty);
  3627. Assert.True (tv.NewKeyDownEvent (new (KeyCode.Z | KeyCode.CtrlMask)));
  3628. Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}", tv.Text);
  3629. Assert.Equal (3, tv.Lines);
  3630. Assert.Equal (new Point (0, 2), tv.CursorPosition);
  3631. Assert.True (tv.IsDirty);
  3632. Assert.True (tv.NewKeyDownEvent (new (KeyCode.Z | KeyCode.CtrlMask)));
  3633. Assert.Equal ($"One{Environment.NewLine}Two", tv.Text);
  3634. Assert.Equal (2, tv.Lines);
  3635. Assert.Equal (new Point (3, 1), tv.CursorPosition);
  3636. Assert.True (tv.IsDirty);
  3637. Assert.True (tv.NewKeyDownEvent (new (KeyCode.Z | KeyCode.CtrlMask)));
  3638. Assert.Equal ($"One{Environment.NewLine}Tw", tv.Text);
  3639. Assert.Equal (2, tv.Lines);
  3640. Assert.Equal (new Point (2, 1), tv.CursorPosition);
  3641. Assert.True (tv.IsDirty);
  3642. Assert.True (tv.NewKeyDownEvent (new (KeyCode.Z | KeyCode.CtrlMask)));
  3643. Assert.Equal ($"One{Environment.NewLine}T", tv.Text);
  3644. Assert.Equal (2, tv.Lines);
  3645. Assert.Equal (new Point (1, 1), tv.CursorPosition);
  3646. Assert.True (tv.IsDirty);
  3647. Assert.True (tv.NewKeyDownEvent (new (KeyCode.Z | KeyCode.CtrlMask)));
  3648. Assert.Equal ($"One{Environment.NewLine}", tv.Text);
  3649. Assert.Equal (2, tv.Lines);
  3650. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  3651. Assert.True (tv.IsDirty);
  3652. Assert.True (tv.NewKeyDownEvent (new (KeyCode.Z | KeyCode.CtrlMask)));
  3653. Assert.Equal ($"One", tv.Text);
  3654. Assert.Equal (1, tv.Lines);
  3655. Assert.Equal (new Point (3, 0), tv.CursorPosition);
  3656. Assert.True (tv.IsDirty);
  3657. Assert.True (tv.NewKeyDownEvent (new (KeyCode.Z | KeyCode.CtrlMask)));
  3658. Assert.Equal ($"On", tv.Text);
  3659. Assert.Equal (1, tv.Lines);
  3660. Assert.Equal (new Point (2, 0), tv.CursorPosition);
  3661. Assert.True (tv.IsDirty);
  3662. Assert.True (tv.NewKeyDownEvent (new (KeyCode.Z | KeyCode.CtrlMask)));
  3663. Assert.Equal ($"O", tv.Text);
  3664. Assert.Equal (1, tv.Lines);
  3665. Assert.Equal (new Point (1, 0), tv.CursorPosition);
  3666. Assert.True (tv.IsDirty);
  3667. Assert.True (tv.NewKeyDownEvent (new (KeyCode.Z | KeyCode.CtrlMask)));
  3668. Assert.Equal ($"", tv.Text);
  3669. Assert.Equal (1, tv.Lines);
  3670. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  3671. Assert.False (tv.IsDirty);
  3672. Assert.True (tv.NewKeyDownEvent (new (KeyCode.Z | KeyCode.CtrlMask)));
  3673. Assert.Equal ($"", tv.Text);
  3674. Assert.Equal (1, tv.Lines);
  3675. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  3676. Assert.False (tv.IsDirty);
  3677. // Redoing
  3678. Assert.True (tv.NewKeyDownEvent (new (KeyCode.R | KeyCode.CtrlMask)));
  3679. Assert.Equal ($"O", tv.Text);
  3680. Assert.Equal (1, tv.Lines);
  3681. Assert.Equal (new Point (1, 0), tv.CursorPosition);
  3682. Assert.True (tv.IsDirty);
  3683. Assert.True (tv.NewKeyDownEvent (new (KeyCode.R | KeyCode.CtrlMask)));
  3684. Assert.Equal ($"On", tv.Text);
  3685. Assert.Equal (1, tv.Lines);
  3686. Assert.Equal (new Point (2, 0), tv.CursorPosition);
  3687. Assert.True (tv.IsDirty);
  3688. Assert.True (tv.NewKeyDownEvent (new (KeyCode.R | KeyCode.CtrlMask)));
  3689. Assert.Equal ($"One", tv.Text);
  3690. Assert.Equal (1, tv.Lines);
  3691. Assert.Equal (new Point (3, 0), tv.CursorPosition);
  3692. Assert.True (tv.IsDirty);
  3693. Assert.True (tv.NewKeyDownEvent (new (KeyCode.R | KeyCode.CtrlMask)));
  3694. Assert.Equal ($"One{Environment.NewLine}", tv.Text);
  3695. Assert.Equal (2, tv.Lines);
  3696. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  3697. Assert.True (tv.IsDirty);
  3698. Assert.True (tv.NewKeyDownEvent (new (KeyCode.R | KeyCode.CtrlMask)));
  3699. Assert.Equal ($"One{Environment.NewLine}T", tv.Text);
  3700. Assert.Equal (2, tv.Lines);
  3701. Assert.Equal (new Point (1, 1), tv.CursorPosition);
  3702. Assert.True (tv.IsDirty);
  3703. Assert.True (tv.NewKeyDownEvent (new (KeyCode.R | KeyCode.CtrlMask)));
  3704. Assert.Equal ($"One{Environment.NewLine}Tw", tv.Text);
  3705. Assert.Equal (2, tv.Lines);
  3706. Assert.Equal (new Point (2, 1), tv.CursorPosition);
  3707. Assert.True (tv.IsDirty);
  3708. Assert.True (tv.NewKeyDownEvent (new (KeyCode.R | KeyCode.CtrlMask)));
  3709. Assert.Equal ($"One{Environment.NewLine}Two", tv.Text);
  3710. Assert.Equal (2, tv.Lines);
  3711. Assert.Equal (new Point (3, 1), tv.CursorPosition);
  3712. Assert.True (tv.IsDirty);
  3713. Assert.True (tv.NewKeyDownEvent (new (KeyCode.R | KeyCode.CtrlMask)));
  3714. Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}", tv.Text);
  3715. Assert.Equal (3, tv.Lines);
  3716. Assert.Equal (new Point (0, 2), tv.CursorPosition);
  3717. Assert.True (tv.IsDirty);
  3718. Assert.True (tv.NewKeyDownEvent (new (KeyCode.R | KeyCode.CtrlMask)));
  3719. Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}T", tv.Text);
  3720. Assert.Equal (3, tv.Lines);
  3721. Assert.Equal (new Point (1, 2), tv.CursorPosition);
  3722. Assert.True (tv.IsDirty);
  3723. Assert.True (tv.NewKeyDownEvent (new (KeyCode.R | KeyCode.CtrlMask)));
  3724. Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}Th", tv.Text);
  3725. Assert.Equal (3, tv.Lines);
  3726. Assert.Equal (new Point (2, 2), tv.CursorPosition);
  3727. Assert.True (tv.IsDirty);
  3728. Assert.True (tv.NewKeyDownEvent (new (KeyCode.R | KeyCode.CtrlMask)));
  3729. Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}Thr", tv.Text);
  3730. Assert.Equal (3, tv.Lines);
  3731. Assert.Equal (new Point (3, 2), tv.CursorPosition);
  3732. Assert.True (tv.IsDirty);
  3733. Assert.True (tv.NewKeyDownEvent (new (KeyCode.R | KeyCode.CtrlMask)));
  3734. Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}Thre", tv.Text);
  3735. Assert.Equal (3, tv.Lines);
  3736. Assert.Equal (new Point (4, 2), tv.CursorPosition);
  3737. Assert.True (tv.IsDirty);
  3738. Assert.True (tv.NewKeyDownEvent (new (KeyCode.R | KeyCode.CtrlMask)));
  3739. Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}Three", tv.Text);
  3740. Assert.Equal (3, tv.Lines);
  3741. Assert.Equal (new Point (5, 2), tv.CursorPosition);
  3742. Assert.True (tv.IsDirty);
  3743. Assert.True (tv.NewKeyDownEvent (new (KeyCode.R | KeyCode.CtrlMask)));
  3744. Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}Three{Environment.NewLine}", tv.Text);
  3745. Assert.Equal (4, tv.Lines);
  3746. Assert.Equal (new Point (0, 3), tv.CursorPosition);
  3747. Assert.True (tv.IsDirty);
  3748. Assert.True (tv.NewKeyDownEvent (new (KeyCode.R | KeyCode.CtrlMask)));
  3749. Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}Three{Environment.NewLine}", tv.Text);
  3750. Assert.Equal (4, tv.Lines);
  3751. Assert.Equal (new Point (0, 3), tv.CursorPosition);
  3752. Assert.True (tv.IsDirty);
  3753. }
  3754. [Fact]
  3755. [AutoInitShutdown]
  3756. public void HistoryText_Undo_Redo_Multi_Line_Selected_With_Empty_Text ()
  3757. {
  3758. var tv = new TextView () {
  3759. Width = 10,
  3760. Height = 2
  3761. };
  3762. var top = Application.Top;
  3763. top.Add (tv);
  3764. Application.Begin (top);
  3765. Assert.Equal ("", tv.Text);
  3766. Assert.Equal (1, tv.Lines);
  3767. Assert.Equal (Point.Empty, tv.CursorPosition);
  3768. Assert.False (tv.IsDirty);
  3769. Assert.True (tv.NewKeyDownEvent (new (KeyCode.O | KeyCode.ShiftMask)));
  3770. Assert.Equal ("O", tv.Text);
  3771. Assert.Equal (1, tv.Lines);
  3772. Assert.Equal (new Point (1, 0), tv.CursorPosition);
  3773. Assert.True (tv.IsDirty);
  3774. Assert.True (tv.NewKeyDownEvent (new ((KeyCode)'n')));
  3775. Assert.Equal ("On", tv.Text);
  3776. Assert.Equal (1, tv.Lines);
  3777. Assert.Equal (new Point (2, 0), tv.CursorPosition);
  3778. Assert.True (tv.IsDirty);
  3779. Assert.True (tv.NewKeyDownEvent (new ((KeyCode)'e')));
  3780. Assert.Equal ("One", tv.Text);
  3781. Assert.Equal (1, tv.Lines);
  3782. Assert.Equal (new Point (3, 0), tv.CursorPosition);
  3783. Assert.True (tv.IsDirty);
  3784. Assert.True (tv.NewKeyDownEvent (new (KeyCode.Enter)));
  3785. Assert.Equal ($"One{Environment.NewLine}", tv.Text);
  3786. Assert.Equal (2, tv.Lines);
  3787. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  3788. Assert.True (tv.IsDirty);
  3789. Assert.True (tv.NewKeyDownEvent (new (KeyCode.T | KeyCode.ShiftMask)));
  3790. Assert.Equal ($"One{Environment.NewLine}T", tv.Text);
  3791. Assert.Equal (2, tv.Lines);
  3792. Assert.Equal (new Point (1, 1), tv.CursorPosition);
  3793. Assert.True (tv.IsDirty);
  3794. Assert.True (tv.NewKeyDownEvent (new ((KeyCode)'w')));
  3795. Assert.Equal ($"One{Environment.NewLine}Tw", tv.Text);
  3796. Assert.Equal (2, tv.Lines);
  3797. Assert.Equal (new Point (2, 1), tv.CursorPosition);
  3798. Assert.True (tv.IsDirty);
  3799. Assert.True (tv.NewKeyDownEvent (new ((KeyCode)'o')));
  3800. Assert.Equal ($"One{Environment.NewLine}Two", tv.Text);
  3801. Assert.Equal (2, tv.Lines);
  3802. Assert.Equal (new Point (3, 1), tv.CursorPosition);
  3803. Assert.True (tv.IsDirty);
  3804. Assert.True (tv.NewKeyDownEvent (new (KeyCode.Enter)));
  3805. Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}", tv.Text);
  3806. Assert.Equal (3, tv.Lines);
  3807. Assert.Equal (new Point (0, 2), tv.CursorPosition);
  3808. Assert.True (tv.IsDirty);
  3809. Assert.True (tv.NewKeyDownEvent (new (KeyCode.T | KeyCode.ShiftMask)));
  3810. Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}T", tv.Text);
  3811. Assert.Equal (3, tv.Lines);
  3812. Assert.Equal (new Point (1, 2), tv.CursorPosition);
  3813. Assert.True (tv.IsDirty);
  3814. Assert.True (tv.NewKeyDownEvent (new ((KeyCode)'h')));
  3815. Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}Th", tv.Text);
  3816. Assert.Equal (3, tv.Lines);
  3817. Assert.Equal (new Point (2, 2), tv.CursorPosition);
  3818. Assert.True (tv.IsDirty);
  3819. Assert.True (tv.NewKeyDownEvent (new ((KeyCode)'r')));
  3820. Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}Thr", tv.Text);
  3821. Assert.Equal (3, tv.Lines);
  3822. Assert.Equal (new Point (3, 2), tv.CursorPosition);
  3823. Assert.True (tv.IsDirty);
  3824. Assert.True (tv.NewKeyDownEvent (new ((KeyCode)'e')));
  3825. Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}Thre", tv.Text);
  3826. Assert.Equal (3, tv.Lines);
  3827. Assert.Equal (new Point (4, 2), tv.CursorPosition);
  3828. Assert.True (tv.IsDirty);
  3829. Assert.True (tv.NewKeyDownEvent (new ((KeyCode)'e')));
  3830. Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}Three", tv.Text);
  3831. Assert.Equal (3, tv.Lines);
  3832. Assert.Equal (new Point (5, 2), tv.CursorPosition);
  3833. Assert.True (tv.IsDirty);
  3834. Assert.True (tv.NewKeyDownEvent (new (KeyCode.Enter)));
  3835. Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}Three{Environment.NewLine}", tv.Text);
  3836. Assert.Equal (4, tv.Lines);
  3837. Assert.Equal (new Point (0, 3), tv.CursorPosition);
  3838. Assert.True (tv.IsDirty);
  3839. tv.SelectionStartColumn = 0;
  3840. tv.SelectionStartRow = 0;
  3841. tv.CursorPosition = new Point (0, 1);
  3842. Assert.Equal (3 + Environment.NewLine.Length, tv.SelectedLength);
  3843. Assert.True (tv.NewKeyDownEvent (new (KeyCode.D1)));
  3844. Assert.Equal ($"1Two{Environment.NewLine}Three{Environment.NewLine}", tv.Text);
  3845. Assert.Equal (3, tv.Lines);
  3846. Assert.Equal (new Point (1, 0), tv.CursorPosition);
  3847. Assert.Equal (0, tv.SelectedLength);
  3848. Assert.True (tv.IsDirty);
  3849. tv.SelectionStartColumn = 1;
  3850. tv.SelectionStartRow = 0;
  3851. tv.CursorPosition = new Point (1, 1);
  3852. Assert.Equal (4 + Environment.NewLine.Length, tv.SelectedLength);
  3853. Assert.True (tv.NewKeyDownEvent (new (KeyCode.D2)));
  3854. Assert.Equal ($"12hree{Environment.NewLine}", tv.Text);
  3855. Assert.Equal (2, tv.Lines);
  3856. Assert.Equal (new Point (2, 0), tv.CursorPosition);
  3857. Assert.Equal (0, tv.SelectedLength);
  3858. Assert.True (tv.IsDirty);
  3859. // Undoing
  3860. Assert.True (tv.NewKeyDownEvent (new (KeyCode.Z | KeyCode.CtrlMask)));
  3861. Assert.Equal ($"1Two{Environment.NewLine}Three{Environment.NewLine}", tv.Text);
  3862. Assert.Equal (3, tv.Lines);
  3863. Assert.Equal (new Point (1, 1), 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}Three{Environment.NewLine}", tv.Text);
  3868. Assert.Equal (4, tv.Lines);
  3869. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  3870. Assert.Equal (0, tv.SelectedLength);
  3871. Assert.True (tv.IsDirty);
  3872. Assert.True (tv.NewKeyDownEvent (new (KeyCode.Z | KeyCode.CtrlMask)));
  3873. Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}Three", tv.Text);
  3874. Assert.Equal (3, tv.Lines);
  3875. Assert.Equal (new Point (5, 2), tv.CursorPosition);
  3876. Assert.Equal (0, tv.SelectedLength);
  3877. Assert.True (tv.IsDirty);
  3878. Assert.True (tv.NewKeyDownEvent (new (KeyCode.Z | KeyCode.CtrlMask)));
  3879. Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}Thre", tv.Text);
  3880. Assert.Equal (3, tv.Lines);
  3881. Assert.Equal (new Point (4, 2), tv.CursorPosition);
  3882. Assert.True (tv.IsDirty);
  3883. Assert.True (tv.NewKeyDownEvent (new (KeyCode.Z | KeyCode.CtrlMask)));
  3884. Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}Thr", tv.Text);
  3885. Assert.Equal (3, tv.Lines);
  3886. Assert.Equal (new Point (3, 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}Th", tv.Text);
  3891. Assert.Equal (3, tv.Lines);
  3892. Assert.Equal (new Point (2, 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{Environment.NewLine}T", tv.Text);
  3897. Assert.Equal (3, tv.Lines);
  3898. Assert.Equal (new Point (1, 2), 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}Two{Environment.NewLine}", tv.Text);
  3903. Assert.Equal (3, tv.Lines);
  3904. Assert.Equal (new Point (0, 2), 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}Two", tv.Text);
  3909. Assert.Equal (2, tv.Lines);
  3910. Assert.Equal (new Point (3, 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}Tw", tv.Text);
  3915. Assert.Equal (2, tv.Lines);
  3916. Assert.Equal (new Point (2, 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{Environment.NewLine}T", tv.Text);
  3921. Assert.Equal (2, tv.Lines);
  3922. Assert.Equal (new Point (1, 1), 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 ($"One{Environment.NewLine}", tv.Text);
  3927. Assert.Equal (2, tv.Lines);
  3928. Assert.Equal (new Point (0, 1), 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 ($"One", tv.Text);
  3933. Assert.Equal (1, tv.Lines);
  3934. Assert.Equal (new Point (3, 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 ($"On", tv.Text);
  3939. Assert.Equal (1, tv.Lines);
  3940. Assert.Equal (new Point (2, 0), tv.CursorPosition);
  3941. Assert.Equal (0, tv.SelectedLength);
  3942. Assert.True (tv.IsDirty);
  3943. Assert.True (tv.NewKeyDownEvent (new (KeyCode.Z | KeyCode.CtrlMask)));
  3944. Assert.Equal ($"O", tv.Text);
  3945. Assert.Equal (1, tv.Lines);
  3946. Assert.Equal (new Point (1, 0), tv.CursorPosition);
  3947. Assert.Equal (0, tv.SelectedLength);
  3948. Assert.True (tv.IsDirty);
  3949. Assert.True (tv.NewKeyDownEvent (new (KeyCode.Z | KeyCode.CtrlMask)));
  3950. Assert.Equal ($"", tv.Text);
  3951. Assert.Equal (1, tv.Lines);
  3952. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  3953. Assert.Equal (0, tv.SelectedLength);
  3954. Assert.False (tv.IsDirty);
  3955. Assert.True (tv.NewKeyDownEvent (new (KeyCode.Z | KeyCode.CtrlMask)));
  3956. Assert.Equal ($"", tv.Text);
  3957. Assert.Equal (1, tv.Lines);
  3958. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  3959. Assert.Equal (0, tv.SelectedLength);
  3960. Assert.False (tv.IsDirty);
  3961. // Redoing
  3962. Assert.True (tv.NewKeyDownEvent (new (KeyCode.R | KeyCode.CtrlMask)));
  3963. Assert.Equal ($"O", tv.Text);
  3964. Assert.Equal (1, tv.Lines);
  3965. Assert.Equal (new Point (1, 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 ($"On", tv.Text);
  3970. Assert.Equal (1, tv.Lines);
  3971. Assert.Equal (new Point (2, 0), 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", tv.Text);
  3976. Assert.Equal (1, tv.Lines);
  3977. Assert.Equal (new Point (3, 0), 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}", tv.Text);
  3982. Assert.Equal (2, tv.Lines);
  3983. Assert.Equal (new Point (0, 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}T", tv.Text);
  3988. Assert.Equal (2, tv.Lines);
  3989. Assert.Equal (new Point (1, 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}Tw", tv.Text);
  3994. Assert.Equal (2, tv.Lines);
  3995. Assert.Equal (new Point (2, 1), 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", tv.Text);
  4000. Assert.Equal (2, tv.Lines);
  4001. Assert.Equal (new Point (3, 1), 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}", tv.Text);
  4006. Assert.Equal (3, tv.Lines);
  4007. Assert.Equal (new Point (0, 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}T", tv.Text);
  4012. Assert.Equal (3, tv.Lines);
  4013. Assert.Equal (new Point (1, 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}Th", tv.Text);
  4018. Assert.Equal (3, tv.Lines);
  4019. Assert.Equal (new Point (2, 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}Thr", tv.Text);
  4024. Assert.Equal (3, tv.Lines);
  4025. Assert.Equal (new Point (3, 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}Thre", tv.Text);
  4030. Assert.Equal (3, tv.Lines);
  4031. Assert.Equal (new Point (4, 2), 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 ($"One{Environment.NewLine}Two{Environment.NewLine}Three", tv.Text);
  4036. Assert.Equal (3, tv.Lines);
  4037. Assert.Equal (new Point (5, 2), 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 ($"One{Environment.NewLine}Two{Environment.NewLine}Three{Environment.NewLine}", tv.Text);
  4042. Assert.Equal (4, tv.Lines);
  4043. Assert.Equal (new Point (0, 3), tv.CursorPosition);
  4044. Assert.Equal (0, tv.SelectedLength);
  4045. Assert.True (tv.IsDirty);
  4046. Assert.True (tv.NewKeyDownEvent (new (KeyCode.R | KeyCode.CtrlMask)));
  4047. Assert.Equal ($"1Two{Environment.NewLine}Three{Environment.NewLine}", tv.Text);
  4048. Assert.Equal (3, tv.Lines);
  4049. Assert.Equal (new Point (1, 0), tv.CursorPosition);
  4050. Assert.Equal (0, tv.SelectedLength);
  4051. Assert.True (tv.IsDirty);
  4052. Assert.True (tv.NewKeyDownEvent (new (KeyCode.R | KeyCode.CtrlMask)));
  4053. Assert.Equal ($"12hree{Environment.NewLine}", tv.Text);
  4054. Assert.Equal (2, tv.Lines);
  4055. Assert.Equal (new Point (2, 0), tv.CursorPosition);
  4056. Assert.Equal (0, tv.SelectedLength);
  4057. Assert.True (tv.IsDirty);
  4058. }
  4059. [Fact]
  4060. [AutoInitShutdown]
  4061. public void HistoryText_Undo_Redo_Multi_Line_Selected_InsertText_Twice_On_Same_Line ()
  4062. {
  4063. var text = "One\nTwo\nThree";
  4064. var tv = new TextView () {
  4065. Width = 10,
  4066. Height = 2,
  4067. Text = text
  4068. };
  4069. var top = Application.Top;
  4070. top.Add (tv);
  4071. Application.Begin (top);
  4072. Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}Three", tv.Text);
  4073. Assert.Equal (3, tv.Lines);
  4074. Assert.Equal (Point.Empty, tv.CursorPosition);
  4075. Assert.False (tv.IsDirty);
  4076. tv.SelectionStartColumn = 0;
  4077. tv.SelectionStartRow = 0;
  4078. tv.CursorPosition = new Point (0, 1);
  4079. Assert.Equal (3 + Environment.NewLine.Length, tv.SelectedLength);
  4080. Assert.True (tv.NewKeyDownEvent (new (KeyCode.D1)));
  4081. Assert.Equal ($"1Two{Environment.NewLine}Three", tv.Text);
  4082. Assert.Equal (new Point (1, 0), tv.CursorPosition);
  4083. Assert.Equal (0, tv.SelectedLength);
  4084. Assert.True (tv.IsDirty);
  4085. tv.SelectionStartColumn = 1;
  4086. tv.SelectionStartRow = 0;
  4087. tv.CursorPosition = new Point (1, 1);
  4088. Assert.Equal (4 + Environment.NewLine.Length, tv.SelectedLength);
  4089. Assert.True (tv.NewKeyDownEvent (new (KeyCode.D2)));
  4090. Assert.Equal ("12hree", tv.Text);
  4091. Assert.Equal (new Point (2, 0), tv.CursorPosition);
  4092. Assert.Equal (0, tv.SelectedLength);
  4093. Assert.True (tv.IsDirty);
  4094. Assert.True (tv.NewKeyDownEvent (new (KeyCode.Z | KeyCode.CtrlMask)));
  4095. Assert.Equal ($"1Two{Environment.NewLine}Three", tv.Text);
  4096. Assert.Equal (new Point (1, 1), tv.CursorPosition);
  4097. Assert.Equal (0, tv.SelectedLength);
  4098. Assert.True (tv.IsDirty);
  4099. Assert.True (tv.NewKeyDownEvent (new (KeyCode.Z | KeyCode.CtrlMask)));
  4100. Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}Three", tv.Text);
  4101. Assert.Equal (3, tv.Lines);
  4102. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  4103. Assert.Equal (0, tv.SelectedLength);
  4104. Assert.False (tv.IsDirty);
  4105. Assert.True (tv.NewKeyDownEvent (new (KeyCode.R | KeyCode.CtrlMask)));
  4106. Assert.Equal ($"1Two{Environment.NewLine}Three", tv.Text);
  4107. Assert.Equal (new Point (1, 0), tv.CursorPosition);
  4108. Assert.Equal (0, tv.SelectedLength);
  4109. Assert.True (tv.IsDirty);
  4110. Assert.True (tv.NewKeyDownEvent (new (KeyCode.R | KeyCode.CtrlMask)));
  4111. Assert.Equal ("12hree", tv.Text);
  4112. Assert.Equal (new Point (2, 0), tv.CursorPosition);
  4113. Assert.Equal (0, tv.SelectedLength);
  4114. Assert.True (tv.IsDirty);
  4115. }
  4116. [Fact]
  4117. [AutoInitShutdown]
  4118. public void HistoryText_Undo_Redo_Multi_Line_Selected_InsertText_Twice_On_Same_Line_With_End_Line ()
  4119. {
  4120. var text = "One\nTwo\nThree\n";
  4121. var tv = new TextView () {
  4122. Width = 10,
  4123. Height = 2,
  4124. Text = text
  4125. };
  4126. var top = Application.Top;
  4127. top.Add (tv);
  4128. Application.Begin (top);
  4129. Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}Three{Environment.NewLine}", tv.Text);
  4130. Assert.Equal (4, tv.Lines);
  4131. Assert.Equal (Point.Empty, tv.CursorPosition);
  4132. Assert.False (tv.IsDirty);
  4133. tv.SelectionStartColumn = 0;
  4134. tv.SelectionStartRow = 0;
  4135. tv.CursorPosition = new Point (0, 1);
  4136. Assert.Equal (3 + Environment.NewLine.Length, tv.SelectedLength);
  4137. Assert.True (tv.NewKeyDownEvent (new (KeyCode.D1)));
  4138. Assert.Equal ($"1Two{Environment.NewLine}Three{Environment.NewLine}", tv.Text);
  4139. Assert.Equal (new Point (1, 0), tv.CursorPosition);
  4140. Assert.Equal (0, tv.SelectedLength);
  4141. Assert.True (tv.IsDirty);
  4142. tv.SelectionStartColumn = 1;
  4143. tv.SelectionStartRow = 0;
  4144. tv.CursorPosition = new Point (1, 1);
  4145. Assert.Equal (4 + Environment.NewLine.Length, tv.SelectedLength);
  4146. Assert.True (tv.NewKeyDownEvent (new (KeyCode.D2)));
  4147. Assert.Equal ($"12hree{Environment.NewLine}", tv.Text);
  4148. Assert.Equal (new Point (2, 0), tv.CursorPosition);
  4149. Assert.Equal (0, tv.SelectedLength);
  4150. Assert.True (tv.IsDirty);
  4151. Assert.True (tv.NewKeyDownEvent (new (KeyCode.Z | KeyCode.CtrlMask)));
  4152. Assert.Equal ($"1Two{Environment.NewLine}Three{Environment.NewLine}", tv.Text);
  4153. Assert.Equal (new Point (1, 1), tv.CursorPosition);
  4154. Assert.Equal (0, tv.SelectedLength);
  4155. Assert.True (tv.IsDirty);
  4156. Assert.True (tv.NewKeyDownEvent (new (KeyCode.Z | KeyCode.CtrlMask)));
  4157. Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}Three{Environment.NewLine}", tv.Text);
  4158. Assert.Equal (4, tv.Lines);
  4159. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  4160. Assert.Equal (0, tv.SelectedLength);
  4161. Assert.False (tv.IsDirty);
  4162. Assert.True (tv.NewKeyDownEvent (new (KeyCode.R | KeyCode.CtrlMask)));
  4163. Assert.Equal ($"1Two{Environment.NewLine}Three{Environment.NewLine}", tv.Text);
  4164. Assert.Equal (new Point (1, 0), tv.CursorPosition);
  4165. Assert.Equal (0, tv.SelectedLength);
  4166. Assert.True (tv.IsDirty);
  4167. Assert.True (tv.NewKeyDownEvent (new (KeyCode.R | KeyCode.CtrlMask)));
  4168. Assert.Equal ($"12hree{Environment.NewLine}", tv.Text);
  4169. Assert.Equal (new Point (2, 0), tv.CursorPosition);
  4170. Assert.Equal (0, tv.SelectedLength);
  4171. Assert.True (tv.IsDirty);
  4172. }
  4173. [Fact]
  4174. public void HistoryText_IsDirty_HasHistoryChanges ()
  4175. {
  4176. var tv = new TextView ();
  4177. Assert.Equal ("", tv.Text);
  4178. Assert.Equal (1, tv.Lines);
  4179. Assert.Equal (Point.Empty, tv.CursorPosition);
  4180. Assert.False (tv.IsDirty);
  4181. Assert.False (tv.HasHistoryChanges);
  4182. Assert.True (tv.NewKeyDownEvent (new (KeyCode.D1)));
  4183. Assert.Equal ("1", tv.Text);
  4184. Assert.Equal (1, tv.Lines);
  4185. Assert.Equal (new Point (1, 0), tv.CursorPosition);
  4186. Assert.True (tv.IsDirty);
  4187. Assert.True (tv.HasHistoryChanges);
  4188. Assert.True (tv.NewKeyDownEvent (new (KeyCode.Enter)));
  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.D2)));
  4195. Assert.Equal ($"1{Environment.NewLine}2", tv.Text);
  4196. Assert.Equal (2, tv.Lines);
  4197. Assert.Equal (new Point (1, 1), tv.CursorPosition);
  4198. Assert.True (tv.IsDirty);
  4199. Assert.True (tv.HasHistoryChanges);
  4200. Assert.True (tv.NewKeyDownEvent (new (KeyCode.Backspace)));
  4201. Assert.Equal ($"1{Environment.NewLine}", tv.Text);
  4202. Assert.Equal (2, tv.Lines);
  4203. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  4204. Assert.True (tv.IsDirty);
  4205. Assert.True (tv.HasHistoryChanges);
  4206. Assert.True (tv.NewKeyDownEvent (new (KeyCode.Backspace)));
  4207. Assert.Equal ($"1", tv.Text);
  4208. Assert.Equal (1, tv.Lines);
  4209. Assert.Equal (new Point (1, 0), tv.CursorPosition);
  4210. Assert.True (tv.IsDirty);
  4211. Assert.True (tv.HasHistoryChanges);
  4212. Assert.True (tv.NewKeyDownEvent (new (KeyCode.Backspace)));
  4213. Assert.Equal ($"", tv.Text);
  4214. Assert.Equal (1, tv.Lines);
  4215. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  4216. // IsDirty cannot be based on HasHistoryChanges because HasHistoryChanges is greater than 0
  4217. // The only way is comparing from the original text
  4218. Assert.False (tv.IsDirty);
  4219. // Still true because HasHistoryChanges is greater than 0
  4220. Assert.True (tv.HasHistoryChanges);
  4221. }
  4222. [Fact]
  4223. public void HistoryText_Undo_Redo_Multi_Line_Selected_DeleteCharLeft_All ()
  4224. {
  4225. var text = "This is the first line.\nThis is the second line.\nThis is the third line.";
  4226. var tv = new TextView () { Text = text };
  4227. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  4228. Assert.Equal (3, tv.Lines);
  4229. Assert.Equal (Point.Empty, tv.CursorPosition);
  4230. Assert.False (tv.IsDirty);
  4231. Assert.False (tv.HasHistoryChanges);
  4232. Assert.True (tv.NewKeyDownEvent (new (KeyCode.End | KeyCode.CtrlMask | KeyCode.ShiftMask)));
  4233. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  4234. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.SelectedText);
  4235. Assert.Equal (3, tv.Lines);
  4236. Assert.Equal (new Point (23, 2), tv.CursorPosition);
  4237. Assert.Equal (70 + Environment.NewLine.Length * 2, tv.SelectedLength);
  4238. Assert.False (tv.IsDirty);
  4239. Assert.False (tv.HasHistoryChanges);
  4240. Assert.True (tv.NewKeyDownEvent (new (KeyCode.Backspace)));
  4241. Assert.Equal ("", tv.Text);
  4242. Assert.Equal ("", tv.SelectedText);
  4243. Assert.Equal (1, tv.Lines);
  4244. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  4245. Assert.Equal (0, tv.SelectedLength);
  4246. Assert.True (tv.IsDirty);
  4247. Assert.True (tv.HasHistoryChanges);
  4248. // Undo
  4249. Assert.True (tv.NewKeyDownEvent (new (KeyCode.Z | KeyCode.CtrlMask)));
  4250. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  4251. Assert.Equal ("", tv.SelectedText);
  4252. Assert.Equal (3, tv.Lines);
  4253. Assert.Equal (new Point (23, 2), tv.CursorPosition);
  4254. Assert.Equal (0, tv.SelectedLength);
  4255. Assert.False (tv.IsDirty);
  4256. Assert.True (tv.HasHistoryChanges);
  4257. // Redo
  4258. Assert.True (tv.NewKeyDownEvent (new (KeyCode.R | KeyCode.CtrlMask)));
  4259. Assert.Equal ("", tv.Text);
  4260. Assert.Equal ("", tv.SelectedText);
  4261. Assert.Equal (1, tv.Lines);
  4262. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  4263. Assert.Equal (0, tv.SelectedLength);
  4264. Assert.True (tv.IsDirty);
  4265. Assert.True (tv.HasHistoryChanges);
  4266. }
  4267. [Fact]
  4268. public void HistoryText_Undo_Redo_Multi_Line_Selected_DeleteCharRight_All ()
  4269. {
  4270. var text = "This is the first line.\nThis is the second line.\nThis is the third line.";
  4271. var tv = new TextView () { Text = text };
  4272. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  4273. Assert.Equal (3, tv.Lines);
  4274. Assert.Equal (Point.Empty, tv.CursorPosition);
  4275. Assert.False (tv.IsDirty);
  4276. Assert.False (tv.HasHistoryChanges);
  4277. Assert.True (tv.NewKeyDownEvent (new (KeyCode.End | KeyCode.CtrlMask | KeyCode.ShiftMask)));
  4278. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  4279. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.SelectedText);
  4280. Assert.Equal (3, tv.Lines);
  4281. Assert.Equal (new Point (23, 2), tv.CursorPosition);
  4282. Assert.Equal (70 + Environment.NewLine.Length * 2, tv.SelectedLength);
  4283. Assert.False (tv.IsDirty);
  4284. Assert.False (tv.HasHistoryChanges);
  4285. Assert.True (tv.NewKeyDownEvent (new (KeyCode.Delete)));
  4286. Assert.Equal ("", tv.Text);
  4287. Assert.Equal ("", tv.SelectedText);
  4288. Assert.Equal (1, tv.Lines);
  4289. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  4290. Assert.Equal (0, tv.SelectedLength);
  4291. Assert.True (tv.IsDirty);
  4292. Assert.True (tv.HasHistoryChanges);
  4293. // Undo
  4294. Assert.True (tv.NewKeyDownEvent (new (KeyCode.Z | KeyCode.CtrlMask)));
  4295. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  4296. Assert.Equal ("", tv.SelectedText);
  4297. Assert.Equal (3, tv.Lines);
  4298. Assert.Equal (new Point (23, 2), tv.CursorPosition);
  4299. Assert.Equal (0, tv.SelectedLength);
  4300. Assert.False (tv.IsDirty);
  4301. Assert.True (tv.HasHistoryChanges);
  4302. // Redo
  4303. Assert.True (tv.NewKeyDownEvent (new (KeyCode.R | KeyCode.CtrlMask)));
  4304. Assert.Equal ("", tv.Text);
  4305. Assert.Equal ("", tv.SelectedText);
  4306. Assert.Equal (1, tv.Lines);
  4307. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  4308. Assert.Equal (0, tv.SelectedLength);
  4309. Assert.True (tv.IsDirty);
  4310. Assert.True (tv.HasHistoryChanges);
  4311. }
  4312. [Fact]
  4313. [AutoInitShutdown (useFakeClipboard: true)]
  4314. public void HistoryText_Undo_Redo_Copy_Without_Selection_Multi_Line_Paste ()
  4315. {
  4316. var text = "This is the first line.\nThis is the second line.\nThis is the third line.";
  4317. var tv = new TextView () { Text = text };
  4318. tv.CursorPosition = new Point (23, 0);
  4319. Assert.True (tv.NewKeyDownEvent (new (KeyCode.C | KeyCode.CtrlMask)));
  4320. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  4321. Assert.Equal ("", tv.SelectedText);
  4322. Assert.Equal ("This is the first line.", Clipboard.Contents);
  4323. Assert.Equal (3, tv.Lines);
  4324. Assert.Equal (new Point (23, 0), tv.CursorPosition);
  4325. Assert.True (tv.NewKeyDownEvent (new (KeyCode.Y | KeyCode.CtrlMask)));
  4326. 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);
  4327. Assert.Equal (4, tv.Lines);
  4328. Assert.Equal (new Point (23, 1), tv.CursorPosition);
  4329. // Undo
  4330. Assert.True (tv.NewKeyDownEvent (new (KeyCode.Z | KeyCode.CtrlMask)));
  4331. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  4332. Assert.Equal (3, tv.Lines);
  4333. Assert.Equal (new Point (23, 0), tv.CursorPosition);
  4334. // Redo
  4335. Assert.True (tv.NewKeyDownEvent (new (KeyCode.R | KeyCode.CtrlMask)));
  4336. 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);
  4337. Assert.Equal (4, tv.Lines);
  4338. Assert.Equal (new Point (23, 1), tv.CursorPosition);
  4339. }
  4340. [Fact]
  4341. [AutoInitShutdown (useFakeClipboard: true)]
  4342. public void HistoryText_Undo_Redo_Simple_Copy_Multi_Line_Selected_Paste ()
  4343. {
  4344. var text = "This is the first line.\nThis is the second line.\nThis is the third line.";
  4345. var tv = new TextView () { Text = text };
  4346. tv.SelectionStartColumn = 12;
  4347. tv.CursorPosition = new Point (17, 0);
  4348. Assert.True (tv.NewKeyDownEvent (new (KeyCode.C | 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 ("first", tv.SelectedText);
  4351. Assert.Equal (3, tv.Lines);
  4352. Assert.Equal (new Point (17, 0), tv.CursorPosition);
  4353. tv.SelectionStartColumn = 12;
  4354. tv.CursorPosition = new Point (11, 1);
  4355. Assert.True (tv.NewKeyDownEvent (new (KeyCode.Y | KeyCode.CtrlMask)));
  4356. Assert.Equal ($"This is the first second line.{Environment.NewLine}This is the third line.", tv.Text);
  4357. Assert.Equal (2, tv.Lines);
  4358. Assert.Equal (new Point (17, 0), tv.CursorPosition);
  4359. // Undo
  4360. Assert.True (tv.NewKeyDownEvent (new (KeyCode.Z | KeyCode.CtrlMask)));
  4361. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  4362. Assert.Equal (3, tv.Lines);
  4363. Assert.Equal (new Point (12, 0), tv.CursorPosition);
  4364. // Redo
  4365. Assert.True (tv.NewKeyDownEvent (new (KeyCode.R | KeyCode.CtrlMask)));
  4366. Assert.Equal ($"This is the first second line.{Environment.NewLine}This is the third line.", tv.Text);
  4367. Assert.Equal (2, tv.Lines);
  4368. Assert.Equal (new Point (17, 0), tv.CursorPosition);
  4369. }
  4370. [Fact]
  4371. [AutoInitShutdown (useFakeClipboard: true)]
  4372. public void HistoryText_Undo_Redo_Multi_Line_Selected_Copy_Simple_Paste_Starting_On_Space ()
  4373. {
  4374. var text = "This is the first line.\nThis is the second line.\nThis is the third line.";
  4375. var tv = new TextView () { Text = text };
  4376. tv.SelectionStartColumn = 12;
  4377. tv.CursorPosition = new Point (18, 1);
  4378. Assert.True (tv.NewKeyDownEvent (new (KeyCode.C | KeyCode.CtrlMask)));
  4379. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  4380. Assert.Equal ($"first line.{Environment.NewLine}This is the second", tv.SelectedText);
  4381. Assert.Equal (3, tv.Lines);
  4382. Assert.Equal (new Point (18, 1), tv.CursorPosition);
  4383. tv.Selecting = false;
  4384. Assert.True (tv.NewKeyDownEvent (new (KeyCode.Y | KeyCode.CtrlMask)));
  4385. 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);
  4386. Assert.Equal (4, tv.Lines);
  4387. Assert.Equal (new Point (18, 2), tv.CursorPosition);
  4388. // Undo
  4389. Assert.True (tv.NewKeyDownEvent (new (KeyCode.Z | KeyCode.CtrlMask)));
  4390. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  4391. Assert.Equal (3, tv.Lines);
  4392. Assert.Equal (new Point (18, 1), tv.CursorPosition);
  4393. // Redo
  4394. Assert.True (tv.NewKeyDownEvent (new (KeyCode.R | KeyCode.CtrlMask)));
  4395. 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);
  4396. Assert.Equal (4, tv.Lines);
  4397. Assert.Equal (new Point (18, 2), tv.CursorPosition);
  4398. }
  4399. [Fact]
  4400. [AutoInitShutdown]
  4401. public void HistoryText_Undo_Redo_Multi_Line_Selected_Copy_Simple_Paste_Starting_On_Letter ()
  4402. {
  4403. var text = "This is the first line.\nThis is the second line.\nThis is the third line.";
  4404. var tv = new TextView () { Text = text };
  4405. tv.SelectionStartColumn = 12;
  4406. tv.CursorPosition = new Point (18, 1);
  4407. Assert.True (tv.NewKeyDownEvent (new (KeyCode.C | 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 ($"first line.{Environment.NewLine}This is the second", tv.SelectedText);
  4410. Assert.Equal (3, tv.Lines);
  4411. Assert.Equal (new Point (18, 1), tv.CursorPosition);
  4412. tv.Selecting = false;
  4413. tv.CursorPosition = new Point (17, 1);
  4414. Assert.True (tv.NewKeyDownEvent (new (KeyCode.Y | KeyCode.CtrlMask)));
  4415. 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);
  4416. Assert.Equal (4, tv.Lines);
  4417. Assert.Equal (new Point (18, 2), tv.CursorPosition);
  4418. // Undo
  4419. Assert.True (tv.NewKeyDownEvent (new (KeyCode.Z | KeyCode.CtrlMask)));
  4420. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  4421. Assert.Equal (3, tv.Lines);
  4422. Assert.Equal (new Point (17, 1), tv.CursorPosition);
  4423. // Redo
  4424. Assert.True (tv.NewKeyDownEvent (new (KeyCode.R | KeyCode.CtrlMask)));
  4425. 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);
  4426. Assert.Equal (4, tv.Lines);
  4427. Assert.Equal (new Point (18, 2), tv.CursorPosition);
  4428. }
  4429. [Fact]
  4430. [AutoInitShutdown]
  4431. public void HistoryText_Undo_Redo_Empty_Copy_Without_Selection_Multi_Line_Selected_Paste ()
  4432. {
  4433. var text = "\nThis is the first line.\nThis is the second line.";
  4434. var tv = new TextView () { Text = text };
  4435. Assert.True (tv.NewKeyDownEvent (new (KeyCode.C | KeyCode.CtrlMask)));
  4436. Assert.Equal ($"{Environment.NewLine}This is the first line.{Environment.NewLine}This is the second line.", tv.Text);
  4437. Assert.Equal ("", tv.SelectedText);
  4438. Assert.Equal (3, tv.Lines);
  4439. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  4440. Assert.True (tv.NewKeyDownEvent (new (KeyCode.Y | KeyCode.CtrlMask)));
  4441. Assert.Equal ($"{Environment.NewLine}{Environment.NewLine}This is the first line.{Environment.NewLine}This is the second line.", tv.Text);
  4442. Assert.Equal (4, tv.Lines);
  4443. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  4444. // Undo
  4445. Assert.True (tv.NewKeyDownEvent (new (KeyCode.Z | KeyCode.CtrlMask)));
  4446. Assert.Equal ($"{Environment.NewLine}This is the first line.{Environment.NewLine}This is the second line.", tv.Text);
  4447. Assert.Equal (3, tv.Lines);
  4448. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  4449. // Redo
  4450. Assert.True (tv.NewKeyDownEvent (new (KeyCode.R | KeyCode.CtrlMask)));
  4451. Assert.Equal ($"{Environment.NewLine}{Environment.NewLine}This is the first line.{Environment.NewLine}This is the second line.", tv.Text);
  4452. Assert.Equal (4, tv.Lines);
  4453. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  4454. }
  4455. [Fact]
  4456. [AutoInitShutdown]
  4457. public void HistoryText_Undo_Redo_Setting_Clipboard_Multi_Line_Selected_Paste ()
  4458. {
  4459. var text = "This is the first line.\nThis is the second line.";
  4460. var tv = new TextView () { Text = text };
  4461. Clipboard.Contents = "Inserted\nNewLine";
  4462. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.", tv.Text);
  4463. Assert.Equal ("", tv.SelectedText);
  4464. Assert.Equal (2, tv.Lines);
  4465. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  4466. Assert.True (tv.NewKeyDownEvent (new (KeyCode.Y | KeyCode.CtrlMask)));
  4467. Assert.Equal ($"Inserted{Environment.NewLine}NewLineThis is the first line.{Environment.NewLine}This is the second line.", tv.Text);
  4468. Assert.Equal (3, tv.Lines);
  4469. Assert.Equal (new Point (7, 1), tv.CursorPosition);
  4470. // Undo
  4471. Assert.True (tv.NewKeyDownEvent (new (KeyCode.Z | KeyCode.CtrlMask)));
  4472. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.", tv.Text);
  4473. Assert.Equal (2, tv.Lines);
  4474. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  4475. // Redo
  4476. Assert.True (tv.NewKeyDownEvent (new (KeyCode.R | KeyCode.CtrlMask)));
  4477. Assert.Equal ($"Inserted{Environment.NewLine}NewLineThis is the first line.{Environment.NewLine}This is the second line.", tv.Text);
  4478. Assert.Equal (3, tv.Lines);
  4479. Assert.Equal (new Point (7, 1), tv.CursorPosition);
  4480. }
  4481. [Fact]
  4482. [AutoInitShutdown]
  4483. public void HistoryText_Undo_Redo_Cut_Multi_Line_Selected_Paste ()
  4484. {
  4485. var text = "This is the first line.\nThis is the second line.\nThis is the third line.";
  4486. var tv = new TextView () { Text = text };
  4487. tv.SelectionStartColumn = 12;
  4488. tv.CursorPosition = new Point (17, 0);
  4489. Assert.True (tv.NewKeyDownEvent (new (KeyCode.W | 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 ("", tv.SelectedText);
  4492. Assert.Equal (3, tv.Lines);
  4493. Assert.Equal (new Point (12, 0), tv.CursorPosition);
  4494. tv.SelectionStartColumn = 12;
  4495. tv.CursorPosition = new Point (11, 1);
  4496. Assert.True (tv.NewKeyDownEvent (new (KeyCode.Y | KeyCode.CtrlMask)));
  4497. Assert.Equal ($"This is the first second line.{Environment.NewLine}This is the third line.", tv.Text);
  4498. Assert.Equal (2, tv.Lines);
  4499. Assert.Equal (new Point (17, 0), tv.CursorPosition);
  4500. // Undo
  4501. Assert.True (tv.NewKeyDownEvent (new (KeyCode.Z | KeyCode.CtrlMask)));
  4502. Assert.Equal ($"This is the line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  4503. Assert.Equal (3, tv.Lines);
  4504. Assert.Equal (new Point (12, 0), tv.CursorPosition);
  4505. // Redo
  4506. Assert.True (tv.NewKeyDownEvent (new (KeyCode.R | KeyCode.CtrlMask)));
  4507. Assert.Equal ($"This is the first second line.{Environment.NewLine}This is the third line.", tv.Text);
  4508. Assert.Equal (2, tv.Lines);
  4509. Assert.Equal (new Point (17, 0), tv.CursorPosition);
  4510. }
  4511. [Fact]
  4512. [AutoInitShutdown]
  4513. public void HistoryText_Undo_Redo_Cut_Simple_Paste_Starting ()
  4514. {
  4515. var text = "This is the first line.\nThis is the second line.\nThis is the third line.";
  4516. var tv = new TextView () { Text = text };
  4517. tv.SelectionStartColumn = 12;
  4518. tv.CursorPosition = new Point (18, 1);
  4519. Assert.True (tv.NewKeyDownEvent (new (KeyCode.W | KeyCode.CtrlMask)));
  4520. Assert.Equal ($"This is the line.{Environment.NewLine}This is the third line.", tv.Text);
  4521. Assert.Equal ("", tv.SelectedText);
  4522. Assert.Equal (2, tv.Lines);
  4523. Assert.Equal (new Point (12, 0), tv.CursorPosition);
  4524. tv.Selecting = false;
  4525. Assert.True (tv.NewKeyDownEvent (new (KeyCode.Y | KeyCode.CtrlMask)));
  4526. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  4527. Assert.Equal (3, tv.Lines);
  4528. Assert.Equal (new Point (18, 1), tv.CursorPosition);
  4529. // Undo
  4530. Assert.True (tv.NewKeyDownEvent (new (KeyCode.Z | KeyCode.CtrlMask)));
  4531. Assert.Equal ($"This is the line.{Environment.NewLine}This is the third line.", tv.Text);
  4532. Assert.Equal (2, tv.Lines);
  4533. Assert.Equal (new Point (12, 0), tv.CursorPosition);
  4534. // Redo
  4535. Assert.True (tv.NewKeyDownEvent (new (KeyCode.R | KeyCode.CtrlMask)));
  4536. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  4537. Assert.Equal (3, tv.Lines);
  4538. Assert.Equal (new Point (18, 1), tv.CursorPosition);
  4539. }
  4540. [Fact]
  4541. [AutoInitShutdown]
  4542. public void HistoryText_Undo_Redo_Cut_Multi_Line_Another_Selected_Paste ()
  4543. {
  4544. var text = "This is the first line.\nThis is the second line.\nThis is the third line.";
  4545. var tv = new TextView () { Text = text };
  4546. tv.SelectionStartColumn = 12;
  4547. tv.CursorPosition = new Point (17, 0);
  4548. Assert.True (tv.NewKeyDownEvent (new (KeyCode.W | KeyCode.CtrlMask)));
  4549. Assert.Equal ($"This is the line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  4550. Assert.Equal ("", tv.SelectedText);
  4551. Assert.Equal (3, tv.Lines);
  4552. Assert.Equal (new Point (12, 0), tv.CursorPosition);
  4553. tv.SelectionStartColumn = 12;
  4554. tv.SelectionStartRow = 1;
  4555. tv.CursorPosition = new Point (18, 1);
  4556. Assert.True (tv.NewKeyDownEvent (new (KeyCode.Y | KeyCode.CtrlMask)));
  4557. Assert.Equal ($"This is the line.{Environment.NewLine}This is the first line.{Environment.NewLine}This is the third line.", tv.Text);
  4558. Assert.Equal (3, tv.Lines);
  4559. Assert.Equal (new Point (17, 1), tv.CursorPosition);
  4560. // Undo
  4561. Assert.True (tv.NewKeyDownEvent (new (KeyCode.Z | KeyCode.CtrlMask)));
  4562. Assert.Equal ($"This is the line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  4563. Assert.Equal (3, tv.Lines);
  4564. Assert.Equal (new Point (12, 1), tv.CursorPosition);
  4565. Assert.True (tv.NewKeyDownEvent (new (KeyCode.Z | KeyCode.CtrlMask)));
  4566. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  4567. Assert.Equal (3, tv.Lines);
  4568. Assert.Equal (new Point (12, 0), tv.CursorPosition);
  4569. // Redo
  4570. Assert.True (tv.NewKeyDownEvent (new (KeyCode.R | KeyCode.CtrlMask)));
  4571. Assert.Equal ($"This is the line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  4572. Assert.Equal (3, tv.Lines);
  4573. Assert.Equal (new Point (12, 0), tv.CursorPosition);
  4574. Assert.True (tv.NewKeyDownEvent (new (KeyCode.R | KeyCode.CtrlMask)));
  4575. Assert.Equal ($"This is the line.{Environment.NewLine}This is the first line.{Environment.NewLine}This is the third line.", tv.Text);
  4576. Assert.Equal (3, tv.Lines);
  4577. Assert.Equal (new Point (17, 1), tv.CursorPosition);
  4578. }
  4579. [Fact]
  4580. public void HistoryText_Undo_Redo_KillWordBackward ()
  4581. {
  4582. var text = "First line.\nSecond line.";
  4583. var tv = new TextView () { Text = text };
  4584. Assert.True (tv.NewKeyDownEvent (new (KeyCode.End | KeyCode.CtrlMask)));
  4585. Assert.Equal ($"First line.{Environment.NewLine}Second line.", tv.Text);
  4586. Assert.Equal ("", tv.SelectedText);
  4587. Assert.Equal (2, tv.Lines);
  4588. Assert.Equal (new Point (12, 1), tv.CursorPosition);
  4589. Assert.True (tv.NewKeyDownEvent (new (KeyCode.Backspace | KeyCode.CtrlMask)));
  4590. Assert.Equal ($"First line.{Environment.NewLine}Second line", tv.Text);
  4591. Assert.Equal ("", tv.SelectedText);
  4592. Assert.Equal (2, tv.Lines);
  4593. Assert.Equal (new Point (11, 1), tv.CursorPosition);
  4594. Assert.True (tv.NewKeyDownEvent (new (KeyCode.Backspace | KeyCode.CtrlMask)));
  4595. Assert.Equal ($"First line.{Environment.NewLine}Second ", tv.Text);
  4596. Assert.Equal ("", tv.SelectedText);
  4597. Assert.Equal (2, tv.Lines);
  4598. Assert.Equal (new Point (7, 1), tv.CursorPosition);
  4599. Assert.True (tv.NewKeyDownEvent (new (KeyCode.Backspace | KeyCode.CtrlMask)));
  4600. Assert.Equal ($"First line.{Environment.NewLine}", tv.Text);
  4601. Assert.Equal ("", tv.SelectedText);
  4602. Assert.Equal (2, tv.Lines);
  4603. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  4604. Assert.True (tv.NewKeyDownEvent (new (KeyCode.Backspace | KeyCode.CtrlMask)));
  4605. Assert.Equal ("First line.", tv.Text);
  4606. Assert.Equal ("", tv.SelectedText);
  4607. Assert.Equal (1, tv.Lines);
  4608. Assert.Equal (new Point (11, 0), tv.CursorPosition);
  4609. Assert.True (tv.NewKeyDownEvent (new (KeyCode.Backspace | KeyCode.CtrlMask)));
  4610. Assert.Equal ("First line", tv.Text);
  4611. Assert.Equal ("", tv.SelectedText);
  4612. Assert.Equal (1, tv.Lines);
  4613. Assert.Equal (new Point (10, 0), tv.CursorPosition);
  4614. Assert.True (tv.NewKeyDownEvent (new (KeyCode.Backspace | KeyCode.CtrlMask)));
  4615. Assert.Equal ("First ", tv.Text);
  4616. Assert.Equal ("", tv.SelectedText);
  4617. Assert.Equal (1, tv.Lines);
  4618. Assert.Equal (new Point (6, 0), tv.CursorPosition);
  4619. Assert.True (tv.NewKeyDownEvent (new (KeyCode.Backspace | KeyCode.CtrlMask)));
  4620. Assert.Equal ("", tv.Text);
  4621. Assert.Equal ("", tv.SelectedText);
  4622. Assert.Equal (1, tv.Lines);
  4623. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  4624. // Undo
  4625. Assert.True (tv.NewKeyDownEvent (new (KeyCode.Z | KeyCode.CtrlMask)));
  4626. Assert.Equal ("First ", tv.Text);
  4627. Assert.Equal (1, tv.Lines);
  4628. Assert.Equal (new Point (6, 0), tv.CursorPosition);
  4629. Assert.True (tv.NewKeyDownEvent (new (KeyCode.Z | KeyCode.CtrlMask)));
  4630. Assert.Equal ("First line", tv.Text);
  4631. Assert.Equal (1, tv.Lines);
  4632. Assert.Equal (new Point (10, 0), tv.CursorPosition);
  4633. Assert.True (tv.NewKeyDownEvent (new (KeyCode.Z | KeyCode.CtrlMask)));
  4634. Assert.Equal ("First line.", tv.Text);
  4635. Assert.Equal (1, tv.Lines);
  4636. Assert.Equal (new Point (11, 0), tv.CursorPosition);
  4637. Assert.True (tv.NewKeyDownEvent (new (KeyCode.Z | KeyCode.CtrlMask)));
  4638. Assert.Equal ($"First line.{Environment.NewLine}", tv.Text);
  4639. Assert.Equal (2, tv.Lines);
  4640. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  4641. Assert.True (tv.NewKeyDownEvent (new (KeyCode.Z | KeyCode.CtrlMask)));
  4642. Assert.Equal ($"First line.{Environment.NewLine}Second ", tv.Text);
  4643. Assert.Equal (2, tv.Lines);
  4644. Assert.Equal (new Point (7, 1), tv.CursorPosition);
  4645. Assert.True (tv.NewKeyDownEvent (new (KeyCode.Z | KeyCode.CtrlMask)));
  4646. Assert.Equal ($"First line.{Environment.NewLine}Second line", tv.Text);
  4647. Assert.Equal (2, tv.Lines);
  4648. Assert.Equal (new Point (11, 1), tv.CursorPosition);
  4649. Assert.True (tv.NewKeyDownEvent (new (KeyCode.Z | KeyCode.CtrlMask)));
  4650. Assert.Equal ($"First line.{Environment.NewLine}Second line.", tv.Text);
  4651. Assert.Equal (2, tv.Lines);
  4652. Assert.Equal (new Point (12, 1), tv.CursorPosition);
  4653. // Redo
  4654. Assert.True (tv.NewKeyDownEvent (new (KeyCode.R | KeyCode.CtrlMask)));
  4655. Assert.Equal ($"First line.{Environment.NewLine}Second line", tv.Text);
  4656. Assert.Equal (2, tv.Lines);
  4657. Assert.Equal (new Point (11, 1), tv.CursorPosition);
  4658. Assert.True (tv.NewKeyDownEvent (new (KeyCode.R | KeyCode.CtrlMask)));
  4659. Assert.Equal ($"First line.{Environment.NewLine}Second ", tv.Text);
  4660. Assert.Equal (2, tv.Lines);
  4661. Assert.Equal (new Point (7, 1), tv.CursorPosition);
  4662. Assert.True (tv.NewKeyDownEvent (new (KeyCode.R | KeyCode.CtrlMask)));
  4663. Assert.Equal ($"First line.{Environment.NewLine}", tv.Text);
  4664. Assert.Equal (2, tv.Lines);
  4665. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  4666. Assert.True (tv.NewKeyDownEvent (new (KeyCode.R | KeyCode.CtrlMask)));
  4667. Assert.Equal ("First line.", tv.Text);
  4668. Assert.Equal (1, tv.Lines);
  4669. Assert.Equal (new Point (11, 0), tv.CursorPosition);
  4670. Assert.True (tv.NewKeyDownEvent (new (KeyCode.R | KeyCode.CtrlMask)));
  4671. Assert.Equal ("First line", tv.Text);
  4672. Assert.Equal (1, tv.Lines);
  4673. Assert.Equal (new Point (10, 0), tv.CursorPosition);
  4674. Assert.True (tv.NewKeyDownEvent (new (KeyCode.R | KeyCode.CtrlMask)));
  4675. Assert.Equal ("First ", tv.Text);
  4676. Assert.Equal (1, tv.Lines);
  4677. Assert.Equal (new Point (6, 0), tv.CursorPosition);
  4678. Assert.True (tv.NewKeyDownEvent (new (KeyCode.R | KeyCode.CtrlMask)));
  4679. Assert.Equal ("", tv.Text);
  4680. Assert.Equal (1, tv.Lines);
  4681. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  4682. }
  4683. [Fact]
  4684. public void HistoryText_Undo_Redo_KillWordForward ()
  4685. {
  4686. var text = "First line.\nSecond line.";
  4687. var tv = new TextView () { Text = text };
  4688. Assert.True (tv.NewKeyDownEvent (new (KeyCode.Delete | KeyCode.CtrlMask)));
  4689. Assert.Equal ($"line.{Environment.NewLine}Second line.", tv.Text);
  4690. Assert.Equal ("", tv.SelectedText);
  4691. Assert.Equal (2, tv.Lines);
  4692. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  4693. Assert.True (tv.NewKeyDownEvent (new (KeyCode.Delete | KeyCode.CtrlMask)));
  4694. Assert.Equal ($"{Environment.NewLine}Second line.", tv.Text);
  4695. Assert.Equal (2, tv.Lines);
  4696. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  4697. Assert.True (tv.NewKeyDownEvent (new (KeyCode.Delete | KeyCode.CtrlMask)));
  4698. Assert.Equal ("Second line.", tv.Text);
  4699. Assert.Equal (1, tv.Lines);
  4700. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  4701. Assert.True (tv.NewKeyDownEvent (new (KeyCode.Delete | KeyCode.CtrlMask)));
  4702. Assert.Equal ("line.", tv.Text);
  4703. Assert.Equal (1, tv.Lines);
  4704. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  4705. Assert.True (tv.NewKeyDownEvent (new (KeyCode.Delete | KeyCode.CtrlMask)));
  4706. Assert.Equal ("", tv.Text);
  4707. Assert.Equal (1, tv.Lines);
  4708. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  4709. // Undo
  4710. Assert.True (tv.NewKeyDownEvent (new (KeyCode.Z | KeyCode.CtrlMask)));
  4711. Assert.Equal ("line.", tv.Text);
  4712. Assert.Equal (1, tv.Lines);
  4713. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  4714. Assert.True (tv.NewKeyDownEvent (new (KeyCode.Z | KeyCode.CtrlMask)));
  4715. Assert.Equal ("Second line.", tv.Text);
  4716. Assert.Equal (1, tv.Lines);
  4717. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  4718. Assert.True (tv.NewKeyDownEvent (new (KeyCode.Z | KeyCode.CtrlMask)));
  4719. Assert.Equal ($"{Environment.NewLine}Second line.", tv.Text);
  4720. Assert.Equal (2, tv.Lines);
  4721. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  4722. Assert.True (tv.NewKeyDownEvent (new (KeyCode.Z | KeyCode.CtrlMask)));
  4723. Assert.Equal ($"line.{Environment.NewLine}Second line.", tv.Text);
  4724. Assert.Equal (2, tv.Lines);
  4725. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  4726. Assert.True (tv.NewKeyDownEvent (new (KeyCode.Z | KeyCode.CtrlMask)));
  4727. Assert.Equal ($"First line.{Environment.NewLine}Second line.", tv.Text);
  4728. Assert.Equal (2, tv.Lines);
  4729. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  4730. // Redo
  4731. Assert.True (tv.NewKeyDownEvent (new (KeyCode.R | KeyCode.CtrlMask)));
  4732. Assert.Equal ($"line.{Environment.NewLine}Second line.", tv.Text);
  4733. Assert.Equal (2, tv.Lines);
  4734. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  4735. Assert.True (tv.NewKeyDownEvent (new (KeyCode.R | KeyCode.CtrlMask)));
  4736. Assert.Equal ($"{Environment.NewLine}Second line.", tv.Text);
  4737. Assert.Equal (2, tv.Lines);
  4738. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  4739. Assert.True (tv.NewKeyDownEvent (new (KeyCode.R | KeyCode.CtrlMask)));
  4740. Assert.Equal ("Second line.", tv.Text);
  4741. Assert.Equal (1, tv.Lines);
  4742. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  4743. Assert.True (tv.NewKeyDownEvent (new (KeyCode.R | KeyCode.CtrlMask)));
  4744. Assert.Equal ("line.", tv.Text);
  4745. Assert.Equal (1, tv.Lines);
  4746. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  4747. Assert.True (tv.NewKeyDownEvent (new (KeyCode.R | KeyCode.CtrlMask)));
  4748. Assert.Equal ("", tv.Text);
  4749. Assert.Equal (1, tv.Lines);
  4750. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  4751. }
  4752. [Fact]
  4753. [AutoInitShutdown]
  4754. public void HistoryText_Undo_Redo_KillToStartOfLine ()
  4755. {
  4756. var text = "First line.\nSecond line.";
  4757. var tv = new TextView () { Text = text };
  4758. Assert.True (tv.NewKeyDownEvent (new (KeyCode.End | KeyCode.CtrlMask)));
  4759. Assert.Equal ($"First line.{Environment.NewLine}Second line.", tv.Text);
  4760. Assert.Equal ("", tv.SelectedText);
  4761. Assert.Equal (2, tv.Lines);
  4762. Assert.Equal (new Point (12, 1), tv.CursorPosition);
  4763. Assert.True (tv.NewKeyDownEvent (new (KeyCode.K | KeyCode.AltMask)));
  4764. Assert.Equal ($"First line.{Environment.NewLine}", tv.Text);
  4765. Assert.Equal ("", tv.SelectedText);
  4766. Assert.Equal ("Second line.", Clipboard.Contents);
  4767. Assert.Equal (2, tv.Lines);
  4768. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  4769. Assert.True (tv.NewKeyDownEvent (new (KeyCode.K | KeyCode.AltMask)));
  4770. Assert.Equal ("First line.", tv.Text);
  4771. Assert.Equal ("", tv.SelectedText);
  4772. Assert.Equal ($"Second line.{Environment.NewLine}", Clipboard.Contents);
  4773. Assert.Equal (1, tv.Lines);
  4774. Assert.Equal (new Point (11, 0), tv.CursorPosition);
  4775. Assert.True (tv.NewKeyDownEvent (new (KeyCode.K | KeyCode.AltMask)));
  4776. Assert.Equal ("", tv.Text);
  4777. Assert.Equal ("", tv.SelectedText);
  4778. Assert.Equal ($"Second line.{Environment.NewLine}First line.", Clipboard.Contents);
  4779. Assert.Equal (1, tv.Lines);
  4780. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  4781. // Undo
  4782. Assert.True (tv.NewKeyDownEvent (new (KeyCode.Z | KeyCode.CtrlMask)));
  4783. Assert.Equal ("First line.", tv.Text);
  4784. Assert.Equal (1, tv.Lines);
  4785. Assert.Equal (new Point (11, 0), tv.CursorPosition);
  4786. Assert.True (tv.NewKeyDownEvent (new (KeyCode.Z | KeyCode.CtrlMask)));
  4787. Assert.Equal ($"First line.{Environment.NewLine}", tv.Text);
  4788. Assert.Equal (2, tv.Lines);
  4789. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  4790. Assert.True (tv.NewKeyDownEvent (new (KeyCode.Z | KeyCode.CtrlMask)));
  4791. Assert.Equal ($"First line.{Environment.NewLine}Second line.", tv.Text);
  4792. Assert.Equal (2, tv.Lines);
  4793. Assert.Equal (new Point (12, 1), tv.CursorPosition);
  4794. // Redo
  4795. Assert.True (tv.NewKeyDownEvent (new (KeyCode.R | KeyCode.CtrlMask)));
  4796. Assert.Equal ($"First line.{Environment.NewLine}", tv.Text);
  4797. Assert.Equal (2, tv.Lines);
  4798. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  4799. Assert.True (tv.NewKeyDownEvent (new (KeyCode.R | KeyCode.CtrlMask)));
  4800. Assert.Equal ($"First line.", tv.Text);
  4801. Assert.Equal (1, tv.Lines);
  4802. Assert.Equal (new Point (11, 0), tv.CursorPosition);
  4803. Assert.True (tv.NewKeyDownEvent (new (KeyCode.R | KeyCode.CtrlMask)));
  4804. Assert.Equal ("", tv.Text);
  4805. Assert.Equal (1, tv.Lines);
  4806. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  4807. }
  4808. [Fact]
  4809. [AutoInitShutdown]
  4810. public void HistoryText_Undo_Redo_KillToEndOfLine ()
  4811. {
  4812. var text = "First line.\nSecond line.";
  4813. var tv = new TextView () { Text = text };
  4814. Assert.True (tv.NewKeyDownEvent (new (KeyCode.K | KeyCode.CtrlMask)));
  4815. Assert.Equal ($"{Environment.NewLine}Second line.", tv.Text);
  4816. Assert.Equal ("", tv.SelectedText);
  4817. Assert.Equal ("First line.", Clipboard.Contents);
  4818. Assert.Equal (2, tv.Lines);
  4819. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  4820. Assert.True (tv.NewKeyDownEvent (new (KeyCode.K | KeyCode.CtrlMask)));
  4821. Assert.Equal ("Second line.", tv.Text);
  4822. Assert.Equal ("", tv.SelectedText);
  4823. Assert.Equal ($"First line.{Environment.NewLine}", Clipboard.Contents);
  4824. Assert.Equal (1, tv.Lines);
  4825. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  4826. Assert.True (tv.NewKeyDownEvent (new (KeyCode.K | KeyCode.CtrlMask)));
  4827. Assert.Equal ("", tv.Text);
  4828. Assert.Equal ("", tv.SelectedText);
  4829. Assert.Equal ($"First line.{Environment.NewLine}Second line.", Clipboard.Contents);
  4830. Assert.Equal (1, tv.Lines);
  4831. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  4832. // Undo
  4833. Assert.True (tv.NewKeyDownEvent (new (KeyCode.Z | KeyCode.CtrlMask)));
  4834. Assert.Equal ("Second line.", tv.Text);
  4835. Assert.Equal (1, tv.Lines);
  4836. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  4837. Assert.True (tv.NewKeyDownEvent (new (KeyCode.Z | KeyCode.CtrlMask)));
  4838. Assert.Equal ($"{Environment.NewLine}Second line.", tv.Text);
  4839. Assert.Equal (2, tv.Lines);
  4840. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  4841. Assert.True (tv.NewKeyDownEvent (new (KeyCode.Z | KeyCode.CtrlMask)));
  4842. Assert.Equal ($"First line.{Environment.NewLine}Second line.", tv.Text);
  4843. Assert.Equal (2, tv.Lines);
  4844. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  4845. // Redo
  4846. Assert.True (tv.NewKeyDownEvent (new (KeyCode.R | KeyCode.CtrlMask)));
  4847. Assert.Equal ($"{Environment.NewLine}Second line.", tv.Text);
  4848. Assert.Equal (2, tv.Lines);
  4849. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  4850. Assert.True (tv.NewKeyDownEvent (new (KeyCode.R | KeyCode.CtrlMask)));
  4851. Assert.Equal ("Second line.", tv.Text);
  4852. Assert.Equal (1, tv.Lines);
  4853. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  4854. Assert.True (tv.NewKeyDownEvent (new (KeyCode.R | KeyCode.CtrlMask)));
  4855. Assert.Equal ("", tv.Text);
  4856. Assert.Equal (1, tv.Lines);
  4857. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  4858. }
  4859. [Fact]
  4860. public void HistoryText_Undo_Redo_Changing_On_Middle_Clear_History_Forwards ()
  4861. {
  4862. var tv = new TextView ();
  4863. Assert.True (tv.NewKeyDownEvent (new (KeyCode.D1)));
  4864. Assert.Equal ("1", tv.Text);
  4865. Assert.Equal (1, tv.Lines);
  4866. Assert.Equal (new Point (1, 0), tv.CursorPosition);
  4867. Assert.True (tv.NewKeyDownEvent (new (KeyCode.D2)));
  4868. Assert.Equal ("12", tv.Text);
  4869. Assert.Equal (1, tv.Lines);
  4870. Assert.Equal (new Point (2, 0), tv.CursorPosition);
  4871. Assert.True (tv.NewKeyDownEvent (new (KeyCode.D3)));
  4872. Assert.Equal ("123", tv.Text);
  4873. Assert.Equal (1, tv.Lines);
  4874. Assert.Equal (new Point (3, 0), tv.CursorPosition);
  4875. // Undo
  4876. Assert.True (tv.NewKeyDownEvent (new (KeyCode.Z | KeyCode.CtrlMask)));
  4877. Assert.Equal ("12", tv.Text);
  4878. Assert.Equal (1, tv.Lines);
  4879. Assert.Equal (new Point (2, 0), tv.CursorPosition);
  4880. Assert.True (tv.NewKeyDownEvent (new (KeyCode.D4)));
  4881. Assert.Equal ("124", tv.Text);
  4882. Assert.Equal (1, tv.Lines);
  4883. Assert.Equal (new Point (3, 0), tv.CursorPosition);
  4884. // Redo
  4885. Assert.True (tv.NewKeyDownEvent (new (KeyCode.R | KeyCode.CtrlMask)));
  4886. Assert.Equal ("124", tv.Text);
  4887. Assert.Equal (1, tv.Lines);
  4888. Assert.Equal (new Point (3, 0), tv.CursorPosition);
  4889. }
  4890. [Fact]
  4891. public void HistoryText_Undo_Redo_Single_Line_Selected_Return ()
  4892. {
  4893. var text = "This is the first line.\nThis is the second line.\nThis is the third line.";
  4894. var tv = new TextView () { Text = text };
  4895. tv.SelectionStartColumn = 12;
  4896. tv.CursorPosition = new Point (17, 0);
  4897. Assert.True (tv.NewKeyDownEvent (new (KeyCode.Enter)));
  4898. Assert.Equal ($"This is the {Environment.NewLine} line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  4899. Assert.Equal (4, tv.Lines);
  4900. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  4901. // Undo
  4902. Assert.True (tv.NewKeyDownEvent (new (KeyCode.Z | KeyCode.CtrlMask)));
  4903. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  4904. Assert.Equal (3, tv.Lines);
  4905. Assert.Equal (new Point (17, 0), tv.CursorPosition);
  4906. Assert.False (tv.IsDirty);
  4907. // Redo
  4908. Assert.True (tv.NewKeyDownEvent (new (KeyCode.R | KeyCode.CtrlMask)));
  4909. Assert.Equal ($"This is the {Environment.NewLine} line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  4910. Assert.Equal (4, tv.Lines);
  4911. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  4912. // Undo
  4913. Assert.True (tv.NewKeyDownEvent (new (KeyCode.Z | KeyCode.CtrlMask)));
  4914. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  4915. Assert.Equal (3, tv.Lines);
  4916. Assert.Equal (new Point (17, 0), tv.CursorPosition);
  4917. Assert.False (tv.IsDirty);
  4918. // Redo
  4919. Assert.True (tv.NewKeyDownEvent (new (KeyCode.R | KeyCode.CtrlMask)));
  4920. Assert.Equal ($"This is the {Environment.NewLine} line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  4921. Assert.Equal (4, tv.Lines);
  4922. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  4923. }
  4924. [Fact]
  4925. public void HistoryText_Undo_Redo_Two_Line_Selected_Return ()
  4926. {
  4927. var text = "This is the first line.\nThis is the second line.\nThis is the third line.";
  4928. var tv = new TextView () { Text = text };
  4929. tv.SelectionStartColumn = 12;
  4930. tv.CursorPosition = new Point (18, 1);
  4931. Assert.True (tv.NewKeyDownEvent (new (KeyCode.Enter)));
  4932. Assert.Equal ($"This is the {Environment.NewLine} line.{Environment.NewLine}This is the third line.", tv.Text);
  4933. Assert.Equal (3, tv.Lines);
  4934. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  4935. // Undo
  4936. Assert.True (tv.NewKeyDownEvent (new (KeyCode.Z | KeyCode.CtrlMask)));
  4937. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  4938. Assert.Equal (3, tv.Lines);
  4939. Assert.Equal (new Point (18, 1), tv.CursorPosition);
  4940. Assert.False (tv.IsDirty);
  4941. // Redo
  4942. Assert.True (tv.NewKeyDownEvent (new (KeyCode.R | KeyCode.CtrlMask)));
  4943. Assert.Equal ($"This is the {Environment.NewLine} line.{Environment.NewLine}This is the third line.", tv.Text);
  4944. Assert.Equal (3, tv.Lines);
  4945. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  4946. // Undo
  4947. Assert.True (tv.NewKeyDownEvent (new (KeyCode.Z | KeyCode.CtrlMask)));
  4948. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  4949. Assert.Equal (3, tv.Lines);
  4950. Assert.Equal (new Point (18, 1), tv.CursorPosition);
  4951. Assert.False (tv.IsDirty);
  4952. // Redo
  4953. Assert.True (tv.NewKeyDownEvent (new (KeyCode.R | KeyCode.CtrlMask)));
  4954. Assert.Equal ($"This is the {Environment.NewLine} line.{Environment.NewLine}This is the third line.", tv.Text);
  4955. Assert.Equal (3, tv.Lines);
  4956. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  4957. }
  4958. [Fact]
  4959. public void HistoryText_Undo_Redo_Three_Line_Selected_Return ()
  4960. {
  4961. var text = "This is the first line.\nThis is the second line.\nThis is the third line.";
  4962. var tv = new TextView () { Text = text };
  4963. tv.SelectionStartColumn = 12;
  4964. tv.CursorPosition = new Point (17, 2);
  4965. Assert.True (tv.NewKeyDownEvent (new (KeyCode.Enter)));
  4966. Assert.Equal ($"This is the {Environment.NewLine} line.", tv.Text);
  4967. Assert.Equal (2, tv.Lines);
  4968. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  4969. // Undo
  4970. Assert.True (tv.NewKeyDownEvent (new (KeyCode.Z | KeyCode.CtrlMask)));
  4971. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  4972. Assert.Equal (3, tv.Lines);
  4973. Assert.Equal (new Point (17, 2), tv.CursorPosition);
  4974. Assert.False (tv.IsDirty);
  4975. // Redo
  4976. Assert.True (tv.NewKeyDownEvent (new (KeyCode.R | KeyCode.CtrlMask)));
  4977. Assert.Equal ($"This is the {Environment.NewLine} line.", tv.Text);
  4978. Assert.Equal (2, tv.Lines);
  4979. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  4980. // Undo
  4981. Assert.True (tv.NewKeyDownEvent (new (KeyCode.Z | KeyCode.CtrlMask)));
  4982. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  4983. Assert.Equal (3, tv.Lines);
  4984. Assert.Equal (new Point (17, 2), tv.CursorPosition);
  4985. Assert.False (tv.IsDirty);
  4986. // Redo
  4987. Assert.True (tv.NewKeyDownEvent (new (KeyCode.R | KeyCode.CtrlMask)));
  4988. Assert.Equal ($"This is the {Environment.NewLine} line.", tv.Text);
  4989. Assert.Equal (2, tv.Lines);
  4990. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  4991. }
  4992. [Fact]
  4993. public void HistoryText_Undo_Redo_Single_Second_Line_Selected_Return ()
  4994. {
  4995. var text = "This is the first line.\nThis is the second line.\nThis is the third line.";
  4996. var tv = new TextView () { Text = text };
  4997. tv.SelectionStartColumn = 12;
  4998. tv.SelectionStartRow = 1;
  4999. tv.CursorPosition = new Point (18, 1);
  5000. Assert.True (tv.NewKeyDownEvent (new (KeyCode.Enter)));
  5001. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the {Environment.NewLine} line.{Environment.NewLine}This is the third line.", tv.Text);
  5002. Assert.Equal (4, tv.Lines);
  5003. Assert.Equal (new Point (0, 2), tv.CursorPosition);
  5004. // Undo
  5005. Assert.True (tv.NewKeyDownEvent (new (KeyCode.Z | KeyCode.CtrlMask)));
  5006. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  5007. Assert.Equal (3, tv.Lines);
  5008. Assert.Equal (new Point (18, 1), tv.CursorPosition);
  5009. Assert.False (tv.IsDirty);
  5010. // Redo
  5011. Assert.True (tv.NewKeyDownEvent (new (KeyCode.R | KeyCode.CtrlMask)));
  5012. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the {Environment.NewLine} line.{Environment.NewLine}This is the third line.", tv.Text);
  5013. Assert.Equal (4, tv.Lines);
  5014. Assert.Equal (new Point (0, 2), tv.CursorPosition);
  5015. // Undo
  5016. Assert.True (tv.NewKeyDownEvent (new (KeyCode.Z | KeyCode.CtrlMask)));
  5017. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  5018. Assert.Equal (3, tv.Lines);
  5019. Assert.Equal (new Point (18, 1), tv.CursorPosition);
  5020. Assert.False (tv.IsDirty);
  5021. // Redo
  5022. Assert.True (tv.NewKeyDownEvent (new (KeyCode.R | KeyCode.CtrlMask)));
  5023. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the {Environment.NewLine} line.{Environment.NewLine}This is the third line.", tv.Text);
  5024. Assert.Equal (4, tv.Lines);
  5025. Assert.Equal (new Point (0, 2), tv.CursorPosition);
  5026. }
  5027. [Fact]
  5028. public void HistoryText_Undo_Redo_First_Line_Selected_Return_And_InsertText ()
  5029. {
  5030. var text = "This is the first line.\nThis is the second line.\nThis is the third line.";
  5031. var tv = new TextView () { Text = text };
  5032. tv.SelectionStartColumn = 12;
  5033. tv.CursorPosition = new Point (17, 0);
  5034. Assert.True (tv.NewKeyDownEvent (new (KeyCode.Enter)));
  5035. Assert.Equal ($"This is the {Environment.NewLine} line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  5036. Assert.Equal (4, tv.Lines);
  5037. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  5038. Assert.True (tv.NewKeyDownEvent (new ((KeyCode)'a')));
  5039. 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);
  5040. Assert.Equal (4, tv.Lines);
  5041. Assert.Equal (new Point (1, 1), tv.CursorPosition);
  5042. // Undo
  5043. Assert.True (tv.NewKeyDownEvent (new (KeyCode.Z | KeyCode.CtrlMask)));
  5044. Assert.Equal ($"This is the {Environment.NewLine} line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  5045. Assert.Equal (4, tv.Lines);
  5046. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  5047. Assert.True (tv.IsDirty);
  5048. Assert.True (tv.NewKeyDownEvent (new (KeyCode.Z | KeyCode.CtrlMask)));
  5049. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  5050. Assert.Equal (3, tv.Lines);
  5051. Assert.Equal (new Point (17, 0), tv.CursorPosition);
  5052. Assert.False (tv.IsDirty);
  5053. // Redo
  5054. Assert.True (tv.NewKeyDownEvent (new (KeyCode.R | KeyCode.CtrlMask)));
  5055. Assert.Equal ($"This is the {Environment.NewLine} line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  5056. Assert.Equal (4, tv.Lines);
  5057. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  5058. Assert.True (tv.NewKeyDownEvent (new (KeyCode.R | KeyCode.CtrlMask)));
  5059. 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);
  5060. Assert.Equal (4, tv.Lines);
  5061. Assert.Equal (new Point (1, 1), tv.CursorPosition);
  5062. // Undo
  5063. Assert.True (tv.NewKeyDownEvent (new (KeyCode.Z | KeyCode.CtrlMask)));
  5064. Assert.Equal ($"This is the {Environment.NewLine} line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  5065. Assert.Equal (4, tv.Lines);
  5066. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  5067. Assert.True (tv.IsDirty);
  5068. Assert.True (tv.NewKeyDownEvent (new (KeyCode.Z | KeyCode.CtrlMask)));
  5069. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  5070. Assert.Equal (3, tv.Lines);
  5071. Assert.Equal (new Point (17, 0), tv.CursorPosition);
  5072. Assert.False (tv.IsDirty);
  5073. // Redo
  5074. Assert.True (tv.NewKeyDownEvent (new (KeyCode.R | KeyCode.CtrlMask)));
  5075. Assert.Equal ($"This is the {Environment.NewLine} line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  5076. Assert.Equal (4, tv.Lines);
  5077. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  5078. Assert.True (tv.NewKeyDownEvent (new (KeyCode.R | KeyCode.CtrlMask)));
  5079. 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);
  5080. Assert.Equal (4, tv.Lines);
  5081. Assert.Equal (new Point (1, 1), tv.CursorPosition);
  5082. }
  5083. [Fact]
  5084. public void HistoryText_Undo_Redo_Single_Second_Line_Selected_Return_And_InsertText ()
  5085. {
  5086. var text = "This is the first line.\nThis is the second line.\nThis is the third line.";
  5087. var tv = new TextView () { Text = text };
  5088. tv.SelectionStartColumn = 12;
  5089. tv.SelectionStartRow = 1;
  5090. tv.CursorPosition = new Point (18, 1);
  5091. Assert.True (tv.NewKeyDownEvent (new (KeyCode.Enter)));
  5092. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the {Environment.NewLine} line.{Environment.NewLine}This is the third line.", tv.Text);
  5093. Assert.Equal (4, tv.Lines);
  5094. Assert.Equal (new Point (0, 2), tv.CursorPosition);
  5095. Assert.True (tv.NewKeyDownEvent (new ((KeyCode)'a')));
  5096. 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);
  5097. Assert.Equal (4, tv.Lines);
  5098. Assert.Equal (new Point (1, 2), tv.CursorPosition);
  5099. // Undo
  5100. Assert.True (tv.NewKeyDownEvent (new (KeyCode.Z | KeyCode.CtrlMask)));
  5101. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the {Environment.NewLine} line.{Environment.NewLine}This is the third line.", tv.Text);
  5102. Assert.Equal (4, tv.Lines);
  5103. Assert.Equal (new Point (0, 2), tv.CursorPosition);
  5104. Assert.True (tv.IsDirty);
  5105. Assert.True (tv.NewKeyDownEvent (new (KeyCode.Z | KeyCode.CtrlMask)));
  5106. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  5107. Assert.Equal (3, tv.Lines);
  5108. Assert.Equal (new Point (18, 1), tv.CursorPosition);
  5109. Assert.False (tv.IsDirty);
  5110. // Redo
  5111. Assert.True (tv.NewKeyDownEvent (new (KeyCode.R | KeyCode.CtrlMask)));
  5112. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the {Environment.NewLine} line.{Environment.NewLine}This is the third line.", tv.Text);
  5113. Assert.Equal (4, tv.Lines);
  5114. Assert.Equal (new Point (0, 2), tv.CursorPosition);
  5115. Assert.True (tv.NewKeyDownEvent (new (KeyCode.R | KeyCode.CtrlMask)));
  5116. 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);
  5117. Assert.Equal (4, tv.Lines);
  5118. Assert.Equal (new Point (1, 2), tv.CursorPosition);
  5119. // Undo
  5120. Assert.True (tv.NewKeyDownEvent (new (KeyCode.Z | KeyCode.CtrlMask)));
  5121. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the {Environment.NewLine} line.{Environment.NewLine}This is the third line.", tv.Text);
  5122. Assert.Equal (4, tv.Lines);
  5123. Assert.Equal (new Point (0, 2), tv.CursorPosition);
  5124. Assert.True (tv.IsDirty);
  5125. Assert.True (tv.NewKeyDownEvent (new (KeyCode.Z | KeyCode.CtrlMask)));
  5126. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  5127. Assert.Equal (3, tv.Lines);
  5128. Assert.Equal (new Point (18, 1), tv.CursorPosition);
  5129. Assert.False (tv.IsDirty);
  5130. // Redo
  5131. Assert.True (tv.NewKeyDownEvent (new (KeyCode.R | KeyCode.CtrlMask)));
  5132. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the {Environment.NewLine} line.{Environment.NewLine}This is the third line.", tv.Text);
  5133. Assert.Equal (4, tv.Lines);
  5134. Assert.Equal (new Point (0, 2), tv.CursorPosition);
  5135. Assert.True (tv.NewKeyDownEvent (new (KeyCode.R | KeyCode.CtrlMask)));
  5136. 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);
  5137. Assert.Equal (4, tv.Lines);
  5138. Assert.Equal (new Point (1, 2), tv.CursorPosition);
  5139. }
  5140. [Fact]
  5141. public void HistoryText_Undo_Redo_Multi_Line_Selected_All_Return_And_InsertText ()
  5142. {
  5143. var text = "This is the first line.\nThis is the second line.\nThis is the third line.";
  5144. var tv = new TextView () { Text = text };
  5145. Assert.True (tv.NewKeyDownEvent (new (KeyCode.End | KeyCode.CtrlMask | KeyCode.ShiftMask)));
  5146. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  5147. Assert.Equal (3, tv.Lines);
  5148. Assert.Equal (new Point (23, 2), tv.CursorPosition);
  5149. Assert.True (tv.NewKeyDownEvent (new (KeyCode.Enter)));
  5150. Assert.Equal ($"{Environment.NewLine}", tv.Text);
  5151. Assert.Equal (2, tv.Lines);
  5152. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  5153. Assert.True (tv.NewKeyDownEvent (new ((KeyCode)'a')));
  5154. Assert.Equal ($"{Environment.NewLine}a", tv.Text);
  5155. Assert.Equal (2, tv.Lines);
  5156. Assert.Equal (new Point (1, 1), tv.CursorPosition);
  5157. // Undo
  5158. Assert.True (tv.NewKeyDownEvent (new (KeyCode.Z | KeyCode.CtrlMask)));
  5159. Assert.Equal ($"{Environment.NewLine}", tv.Text);
  5160. Assert.Equal (2, tv.Lines);
  5161. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  5162. Assert.True (tv.IsDirty);
  5163. Assert.True (tv.NewKeyDownEvent (new (KeyCode.Z | KeyCode.CtrlMask)));
  5164. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  5165. Assert.Equal (3, tv.Lines);
  5166. Assert.Equal (new Point (23, 2), tv.CursorPosition);
  5167. Assert.False (tv.IsDirty);
  5168. // Redo
  5169. Assert.True (tv.NewKeyDownEvent (new (KeyCode.R | KeyCode.CtrlMask)));
  5170. Assert.Equal ($"{Environment.NewLine}", tv.Text);
  5171. Assert.Equal (2, tv.Lines);
  5172. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  5173. Assert.True (tv.NewKeyDownEvent (new (KeyCode.R | KeyCode.CtrlMask)));
  5174. Assert.Equal ($"{Environment.NewLine}a", tv.Text);
  5175. Assert.Equal (2, tv.Lines);
  5176. Assert.Equal (new Point (1, 1), tv.CursorPosition);
  5177. // Undo
  5178. Assert.True (tv.NewKeyDownEvent (new (KeyCode.Z | KeyCode.CtrlMask)));
  5179. Assert.Equal ($"{Environment.NewLine}", tv.Text);
  5180. Assert.Equal (2, tv.Lines);
  5181. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  5182. Assert.True (tv.IsDirty);
  5183. Assert.True (tv.NewKeyDownEvent (new (KeyCode.Z | KeyCode.CtrlMask)));
  5184. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
  5185. Assert.Equal (3, tv.Lines);
  5186. Assert.Equal (new Point (23, 2), tv.CursorPosition);
  5187. Assert.False (tv.IsDirty);
  5188. // Redo
  5189. Assert.True (tv.NewKeyDownEvent (new (KeyCode.R | KeyCode.CtrlMask)));
  5190. Assert.Equal ($"{Environment.NewLine}", tv.Text);
  5191. Assert.Equal (2, tv.Lines);
  5192. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  5193. Assert.True (tv.NewKeyDownEvent (new (KeyCode.R | KeyCode.CtrlMask)));
  5194. Assert.Equal ($"{Environment.NewLine}a", tv.Text);
  5195. Assert.Equal (2, tv.Lines);
  5196. Assert.Equal (new Point (1, 1), tv.CursorPosition);
  5197. }
  5198. [Fact]
  5199. public void HistoryText_Undo_Redo_Ending_With_Newline_Multi_Line_Selected_Almost_All_Return_And_InsertText ()
  5200. {
  5201. var text = "This is the first line.\nThis is the second line.\nThis is the third line.\n";
  5202. var tv = new TextView () { Text = text };
  5203. tv.SelectionStartColumn = 12;
  5204. tv.CursorPosition = new Point (12, 2);
  5205. Assert.True (tv.NewKeyDownEvent (new (KeyCode.Enter)));
  5206. Assert.Equal ($"This is the {Environment.NewLine}third line.{Environment.NewLine}", tv.Text);
  5207. Assert.Equal (3, tv.Lines);
  5208. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  5209. Assert.True (tv.NewKeyDownEvent (new ((KeyCode)'a')));
  5210. Assert.Equal ($"This is the {Environment.NewLine}athird line.{Environment.NewLine}", tv.Text);
  5211. Assert.Equal (3, tv.Lines);
  5212. Assert.Equal (new Point (1, 1), tv.CursorPosition);
  5213. // Undo
  5214. Assert.True (tv.NewKeyDownEvent (new (KeyCode.Z | KeyCode.CtrlMask)));
  5215. Assert.Equal ($"This is the {Environment.NewLine}third line.{Environment.NewLine}", tv.Text);
  5216. Assert.Equal (3, tv.Lines);
  5217. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  5218. Assert.True (tv.IsDirty);
  5219. Assert.True (tv.NewKeyDownEvent (new (KeyCode.Z | KeyCode.CtrlMask)));
  5220. 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);
  5221. Assert.Equal (4, tv.Lines);
  5222. Assert.Equal (new Point (12, 2), tv.CursorPosition);
  5223. Assert.False (tv.IsDirty);
  5224. // Redo
  5225. Assert.True (tv.NewKeyDownEvent (new (KeyCode.R | KeyCode.CtrlMask)));
  5226. Assert.Equal ($"This is the {Environment.NewLine}third line.{Environment.NewLine}", tv.Text);
  5227. Assert.Equal (3, tv.Lines);
  5228. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  5229. Assert.True (tv.NewKeyDownEvent (new (KeyCode.R | KeyCode.CtrlMask)));
  5230. Assert.Equal ($"This is the {Environment.NewLine}athird line.{Environment.NewLine}", tv.Text);
  5231. Assert.Equal (3, tv.Lines);
  5232. Assert.Equal (new Point (1, 1), tv.CursorPosition);
  5233. // Undo
  5234. Assert.True (tv.NewKeyDownEvent (new (KeyCode.Z | KeyCode.CtrlMask)));
  5235. Assert.Equal ($"This is the {Environment.NewLine}third line.{Environment.NewLine}", tv.Text);
  5236. Assert.Equal (3, tv.Lines);
  5237. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  5238. Assert.True (tv.IsDirty);
  5239. Assert.True (tv.NewKeyDownEvent (new (KeyCode.Z | KeyCode.CtrlMask)));
  5240. 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);
  5241. Assert.Equal (4, tv.Lines);
  5242. Assert.Equal (new Point (12, 2), tv.CursorPosition);
  5243. Assert.False (tv.IsDirty);
  5244. // Redo
  5245. Assert.True (tv.NewKeyDownEvent (new (KeyCode.R | KeyCode.CtrlMask)));
  5246. Assert.Equal ($"This is the {Environment.NewLine}third line.{Environment.NewLine}", tv.Text);
  5247. Assert.Equal (3, tv.Lines);
  5248. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  5249. Assert.True (tv.NewKeyDownEvent (new (KeyCode.R | KeyCode.CtrlMask)));
  5250. Assert.Equal ($"This is the {Environment.NewLine}athird line.{Environment.NewLine}", tv.Text);
  5251. Assert.Equal (3, tv.Lines);
  5252. Assert.Equal (new Point (1, 1), tv.CursorPosition);
  5253. }
  5254. [Fact]
  5255. public void HistoryText_Undo_Redo_Disabled_On_WordWrap ()
  5256. {
  5257. var text = "This is the first line.\nThis is the second line.\nThis is the third line.\n";
  5258. var tv = new TextView () { Width = 80, Height = 5, Text = text };
  5259. Assert.False (tv.WordWrap);
  5260. tv.WordWrap = true;
  5261. tv.SelectionStartColumn = 12;
  5262. tv.CursorPosition = new Point (12, 2);
  5263. Assert.True (tv.NewKeyDownEvent (new (KeyCode.Enter)));
  5264. Assert.Equal ($"This is the {Environment.NewLine}third line.{Environment.NewLine}", tv.Text);
  5265. Assert.Equal (3, tv.Lines);
  5266. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  5267. Assert.True (tv.NewKeyDownEvent (new ((KeyCode)'a')));
  5268. Assert.Equal ($"This is the {Environment.NewLine}athird line.{Environment.NewLine}", tv.Text);
  5269. Assert.Equal (3, tv.Lines);
  5270. Assert.Equal (new Point (1, 1), tv.CursorPosition);
  5271. Assert.True (tv.NewKeyDownEvent (new (KeyCode.Z | KeyCode.CtrlMask)));
  5272. Assert.Equal ($"This is the {Environment.NewLine}third line.{Environment.NewLine}", tv.Text);
  5273. Assert.Equal (3, tv.Lines);
  5274. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  5275. Assert.True (tv.IsDirty);
  5276. Assert.True (tv.NewKeyDownEvent (new (KeyCode.R | KeyCode.CtrlMask)));
  5277. Assert.Equal ($"This is the {Environment.NewLine}athird line.{Environment.NewLine}", tv.Text);
  5278. Assert.Equal (3, tv.Lines);
  5279. Assert.Equal (new Point (1, 1), tv.CursorPosition);
  5280. }
  5281. [Fact]
  5282. public void HistoryText_Undo_Redo_Multiline_Simples_Tab_BackTab ()
  5283. {
  5284. var text = "First line.\nSecond line.\nThird line.";
  5285. var tv = new TextView () { Width = 80, Height = 5, Text = text };
  5286. Assert.True (tv.NewKeyDownEvent (new (KeyCode.Tab)));
  5287. Assert.Equal ($"\tFirst line.{Environment.NewLine}Second line.{Environment.NewLine}Third line.", tv.Text);
  5288. Assert.Equal (3, tv.Lines);
  5289. Assert.Equal (new Point (1, 0), tv.CursorPosition);
  5290. Assert.True (tv.NewKeyDownEvent (new (KeyCode.Tab | KeyCode.ShiftMask)));
  5291. Assert.Equal ($"First line.{Environment.NewLine}Second line.{Environment.NewLine}Third line.", tv.Text);
  5292. Assert.Equal (3, tv.Lines);
  5293. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  5294. // Undo
  5295. Assert.True (tv.NewKeyDownEvent (new (KeyCode.Z | KeyCode.CtrlMask)));
  5296. Assert.Equal ($"\tFirst line.{Environment.NewLine}Second line.{Environment.NewLine}Third line.", tv.Text);
  5297. Assert.Equal (3, tv.Lines);
  5298. Assert.Equal (new Point (1, 0), tv.CursorPosition);
  5299. Assert.True (tv.IsDirty);
  5300. Assert.True (tv.NewKeyDownEvent (new (KeyCode.Z | KeyCode.CtrlMask)));
  5301. Assert.Equal ($"First line.{Environment.NewLine}Second line.{Environment.NewLine}Third line.", tv.Text);
  5302. Assert.Equal (3, tv.Lines);
  5303. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  5304. Assert.False (tv.IsDirty);
  5305. // Redo
  5306. Assert.True (tv.NewKeyDownEvent (new (KeyCode.R | KeyCode.CtrlMask)));
  5307. Assert.Equal ($"\tFirst line.{Environment.NewLine}Second line.{Environment.NewLine}Third line.", tv.Text);
  5308. Assert.Equal (3, tv.Lines);
  5309. Assert.Equal (new Point (1, 0), tv.CursorPosition);
  5310. Assert.True (tv.NewKeyDownEvent (new (KeyCode.R | KeyCode.CtrlMask)));
  5311. Assert.Equal ($"First line.{Environment.NewLine}Second line.{Environment.NewLine}Third line.", tv.Text);
  5312. Assert.Equal (3, tv.Lines);
  5313. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  5314. }
  5315. [Fact]
  5316. public void HistoryText_Undo_Redo_Multiline_Selected_Tab_BackTab ()
  5317. {
  5318. var text = "First line.\nSecond line.\nThird line.";
  5319. var tv = new TextView () { Width = 80, Height = 5, Text = text };
  5320. tv.SelectionStartColumn = 6;
  5321. tv.CursorPosition = new Point (6, 2);
  5322. Assert.True (tv.NewKeyDownEvent (new (KeyCode.Tab)));
  5323. Assert.Equal ("First \tline.", tv.Text);
  5324. Assert.Equal (1, tv.Lines);
  5325. Assert.Equal (new Point (7, 0), tv.CursorPosition);
  5326. Assert.True (tv.NewKeyDownEvent (new (KeyCode.Tab | KeyCode.ShiftMask)));
  5327. Assert.Equal ("First line.", tv.Text);
  5328. Assert.Equal (1, tv.Lines);
  5329. Assert.Equal (new Point (6, 0), tv.CursorPosition);
  5330. // Undo
  5331. Assert.True (tv.NewKeyDownEvent (new (KeyCode.Z | KeyCode.CtrlMask)));
  5332. Assert.Equal ("First \tline.", tv.Text);
  5333. Assert.Equal (1, tv.Lines);
  5334. Assert.Equal (new Point (7, 0), tv.CursorPosition);
  5335. Assert.True (tv.IsDirty);
  5336. Assert.True (tv.NewKeyDownEvent (new (KeyCode.Z | KeyCode.CtrlMask)));
  5337. Assert.Equal ($"First line.{Environment.NewLine}Second line.{Environment.NewLine}Third line.", tv.Text);
  5338. Assert.Equal (3, tv.Lines);
  5339. Assert.Equal (new Point (6, 2), tv.CursorPosition);
  5340. Assert.False (tv.IsDirty);
  5341. // Redo
  5342. Assert.True (tv.NewKeyDownEvent (new (KeyCode.R | KeyCode.CtrlMask)));
  5343. Assert.Equal ("First \tline.", tv.Text);
  5344. Assert.Equal (1, tv.Lines);
  5345. Assert.Equal (new Point (7, 0), tv.CursorPosition);
  5346. Assert.True (tv.NewKeyDownEvent (new (KeyCode.R | KeyCode.CtrlMask)));
  5347. Assert.Equal ("First line.", tv.Text);
  5348. Assert.Equal (1, tv.Lines);
  5349. Assert.Equal (new Point (6, 0), tv.CursorPosition);
  5350. }
  5351. [Fact]
  5352. public void HistoryText_ClearHistoryChanges ()
  5353. {
  5354. var text = "This is the first line.\nThis is the second line.\nThis is the third line.";
  5355. var tv = new TextView () { Text = text };
  5356. Assert.True (tv.NewKeyDownEvent (new (KeyCode.Enter)));
  5357. 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);
  5358. Assert.Equal (4, tv.Lines);
  5359. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  5360. Assert.True (tv.IsDirty);
  5361. Assert.True (tv.HasHistoryChanges);
  5362. tv.ClearHistoryChanges ();
  5363. 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);
  5364. Assert.Equal (4, tv.Lines);
  5365. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  5366. Assert.False (tv.IsDirty);
  5367. Assert.False (tv.HasHistoryChanges);
  5368. }
  5369. [Fact]
  5370. public void GetRegion_StringFromRunes_Environment_NewLine ()
  5371. {
  5372. var tv = new TextView () { Text = $"1{Environment.NewLine}2" };
  5373. Assert.Equal ($"1{Environment.NewLine}2", tv.Text);
  5374. Assert.Equal ("", tv.SelectedText);
  5375. tv.SelectAll ();
  5376. Assert.Equal ($"1{Environment.NewLine}2", tv.Text);
  5377. Assert.Equal ($"1{Environment.NewLine}2", tv.SelectedText);
  5378. }
  5379. [Fact, AutoInitShutdown]
  5380. public void WordWrap_Not_Throw_If_Width_Is_Less_Than_Zero ()
  5381. {
  5382. var exception = Record.Exception (() => {
  5383. var tv = new TextView () {
  5384. Width = Dim.Fill (),
  5385. Height = Dim.Fill (),
  5386. WordWrap = true,
  5387. Text = "これは、左右のクリップ境界をテストするための非常に長いテキストです。"
  5388. };
  5389. });
  5390. Assert.Null (exception);
  5391. }
  5392. [Fact]
  5393. [AutoInitShutdown]
  5394. public void ScrollDownTillCaretOffscreen_ThenType ()
  5395. {
  5396. var tv = new TextView {
  5397. Width = 10,
  5398. Height = 5
  5399. };
  5400. // add 100 lines of wide text to view
  5401. for (int i = 0; i < 100; i++)
  5402. tv.Text += new string ('x', 100) + Environment.NewLine;
  5403. Assert.Equal (0, tv.CursorPosition.Y);
  5404. tv.ScrollTo (50);
  5405. Assert.Equal (0, tv.CursorPosition.Y);
  5406. tv.NewKeyDownEvent (new (KeyCode.P));
  5407. }
  5408. [Fact]
  5409. [AutoInitShutdown]
  5410. public void MoveDown_By_Setting_CursorPosition ()
  5411. {
  5412. var tv = new TextView {
  5413. Width = 10,
  5414. Height = 5
  5415. };
  5416. // add 100 lines of wide text to view
  5417. for (int i = 0; i < 100; i++)
  5418. tv.Text += new string ('x', 100) + (i == 99 ? "" : Environment.NewLine);
  5419. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  5420. tv.CursorPosition = new Point (5, 50);
  5421. Assert.Equal (new Point (5, 50), tv.CursorPosition);
  5422. tv.CursorPosition = new Point (200, 200);
  5423. Assert.Equal (new Point (100, 99), tv.CursorPosition);
  5424. }
  5425. [Fact]
  5426. [AutoInitShutdown]
  5427. public void ScrollTo_CursorPosition ()
  5428. {
  5429. var tv = new TextView {
  5430. Width = 10,
  5431. Height = 5
  5432. };
  5433. // add 100 lines of wide text to view
  5434. for (int i = 0; i < 100; i++)
  5435. tv.Text += new string ('x', 100) + (i == 99 ? "" : Environment.NewLine);
  5436. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  5437. tv.ScrollTo (50);
  5438. Assert.Equal (new Point (0, 0), tv.CursorPosition);
  5439. tv.CursorPosition = new Point (tv.LeftColumn, tv.TopRow);
  5440. Assert.Equal (new Point (0, 50), tv.CursorPosition);
  5441. }
  5442. [Fact]
  5443. [TextViewTestsAutoInitShutdown]
  5444. public void Mouse_Button_Shift_Preserves_Selection ()
  5445. {
  5446. Assert.Equal ("TAB to jump between text fields.", _textView.Text);
  5447. Assert.True (_textView.MouseEvent (new MouseEvent () { X = 12, Y = 0, Flags = MouseFlags.Button1Pressed | MouseFlags.ButtonShift }));
  5448. Assert.Equal (0, _textView.SelectionStartColumn);
  5449. Assert.Equal (0, _textView.SelectionStartRow);
  5450. Assert.Equal (new Point (12, 0), _textView.CursorPosition);
  5451. Assert.True (_textView.Selecting);
  5452. Assert.Equal ("TAB to jump ", _textView.SelectedText);
  5453. Assert.True (_textView.MouseEvent (new MouseEvent () { X = 12, Y = 0, Flags = MouseFlags.Button1Clicked }));
  5454. Assert.Equal (0, _textView.SelectionStartRow);
  5455. Assert.Equal (0, _textView.SelectionStartRow);
  5456. Assert.Equal (new Point (12, 0), _textView.CursorPosition);
  5457. Assert.True (_textView.Selecting);
  5458. Assert.Equal ("TAB to jump ", _textView.SelectedText);
  5459. Assert.True (_textView.MouseEvent (new MouseEvent () { X = 19, Y = 0, Flags = MouseFlags.Button1Pressed | MouseFlags.ButtonShift }));
  5460. Assert.Equal (0, _textView.SelectionStartRow);
  5461. Assert.Equal (0, _textView.SelectionStartRow);
  5462. Assert.Equal (new Point (19, 0), _textView.CursorPosition);
  5463. Assert.True (_textView.Selecting);
  5464. Assert.Equal ("TAB to jump between", _textView.SelectedText);
  5465. Assert.True (_textView.MouseEvent (new MouseEvent () { X = 19, Y = 0, Flags = MouseFlags.Button1Clicked }));
  5466. Assert.Equal (0, _textView.SelectionStartRow);
  5467. Assert.Equal (0, _textView.SelectionStartRow);
  5468. Assert.Equal (new Point (19, 0), _textView.CursorPosition);
  5469. Assert.True (_textView.Selecting);
  5470. Assert.Equal ("TAB to jump between", _textView.SelectedText);
  5471. Assert.True (_textView.MouseEvent (new MouseEvent () { X = 24, Y = 0, Flags = MouseFlags.Button1Pressed | MouseFlags.ButtonShift }));
  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 ("TAB to jump between text", _textView.SelectedText);
  5477. Assert.True (_textView.MouseEvent (new MouseEvent () { X = 24, Y = 0, Flags = MouseFlags.Button1Clicked }));
  5478. Assert.Equal (0, _textView.SelectionStartRow);
  5479. Assert.Equal (0, _textView.SelectionStartRow);
  5480. Assert.Equal (new Point (24, 0), _textView.CursorPosition);
  5481. Assert.True (_textView.Selecting);
  5482. Assert.Equal ("TAB to jump between text", _textView.SelectedText);
  5483. Assert.True (_textView.MouseEvent (new MouseEvent () { X = 24, Y = 0, Flags = MouseFlags.Button1Pressed }));
  5484. Assert.Equal (0, _textView.SelectionStartRow);
  5485. Assert.Equal (0, _textView.SelectionStartRow);
  5486. Assert.Equal (new Point (24, 0), _textView.CursorPosition);
  5487. Assert.True (_textView.Selecting);
  5488. Assert.Equal ("", _textView.SelectedText);
  5489. }
  5490. [Fact, AutoInitShutdown]
  5491. public void UnwrappedCursorPosition_Event ()
  5492. {
  5493. var cp = Point.Empty;
  5494. var tv = new TextView () {
  5495. Width = Dim.Fill (),
  5496. Height = Dim.Fill (),
  5497. Text = "This is the first line.\nThis is the second line.\n"
  5498. };
  5499. tv.UnwrappedCursorPosition += (s, e) => {
  5500. cp = e.Point;
  5501. };
  5502. Application.Top.Add (tv);
  5503. Application.Begin (Application.Top);
  5504. Assert.False (tv.WordWrap);
  5505. Assert.Equal (Point.Empty, tv.CursorPosition);
  5506. Assert.Equal (Point.Empty, cp);
  5507. TestHelpers.AssertDriverContentsWithFrameAre (@"
  5508. This is the first line.
  5509. This is the second line.
  5510. ", _output);
  5511. tv.WordWrap = true;
  5512. tv.CursorPosition = new Point (12, 0);
  5513. tv.Draw ();
  5514. Assert.Equal (new Point (12, 0), tv.CursorPosition);
  5515. Assert.Equal (new Point (12, 0), cp);
  5516. TestHelpers.AssertDriverContentsWithFrameAre (@"
  5517. This is the first line.
  5518. This is the second line.
  5519. ", _output);
  5520. ((FakeDriver)Application.Driver).SetBufferSize (6, 25);
  5521. tv.Draw ();
  5522. Assert.Equal (new Point (4, 2), tv.CursorPosition);
  5523. Assert.Equal (new Point (12, 0), cp);
  5524. TestHelpers.AssertDriverContentsWithFrameAre (@"
  5525. This
  5526. is
  5527. the
  5528. first
  5529. line.
  5530. This
  5531. is
  5532. the
  5533. secon
  5534. d
  5535. line.
  5536. ", _output);
  5537. Assert.True (tv.NewKeyDownEvent (new (KeyCode.CursorRight)));
  5538. tv.Draw ();
  5539. Assert.Equal (new Point (0, 3), tv.CursorPosition);
  5540. Assert.Equal (new Point (12, 0), cp);
  5541. TestHelpers.AssertDriverContentsWithFrameAre (@"
  5542. This
  5543. is
  5544. the
  5545. first
  5546. line.
  5547. This
  5548. is
  5549. the
  5550. secon
  5551. d
  5552. line.
  5553. ", _output);
  5554. Assert.True (tv.NewKeyDownEvent (new (KeyCode.CursorRight)));
  5555. tv.Draw ();
  5556. Assert.Equal (new Point (1, 3), tv.CursorPosition);
  5557. Assert.Equal (new Point (13, 0), cp);
  5558. TestHelpers.AssertDriverContentsWithFrameAre (@"
  5559. This
  5560. is
  5561. the
  5562. first
  5563. line.
  5564. This
  5565. is
  5566. the
  5567. secon
  5568. d
  5569. line.
  5570. ", _output);
  5571. Assert.True (tv.MouseEvent (new MouseEvent () { X = 0, Y = 3, Flags = MouseFlags.Button1Pressed }));
  5572. tv.Draw ();
  5573. Assert.Equal (new Point (0, 3), tv.CursorPosition);
  5574. Assert.Equal (new Point (13, 0), cp);
  5575. TestHelpers.AssertDriverContentsWithFrameAre (@"
  5576. This
  5577. is
  5578. the
  5579. first
  5580. line.
  5581. This
  5582. is
  5583. the
  5584. secon
  5585. d
  5586. line.
  5587. ", _output);
  5588. }
  5589. [Fact]
  5590. [AutoInitShutdown]
  5591. public void DeleteTextBackwards_WordWrap_False_Return_Undo ()
  5592. {
  5593. const string text = "This is the first line.\nThis is the second line.\n";
  5594. var tv = new TextView () {
  5595. Width = Dim.Fill (),
  5596. Height = Dim.Fill (),
  5597. Text = text
  5598. };
  5599. var envText = tv.Text;
  5600. Application.Top.Add (tv);
  5601. Application.Begin (Application.Top);
  5602. Assert.False (tv.WordWrap);
  5603. Assert.Equal (Point.Empty, tv.CursorPosition);
  5604. TestHelpers.AssertDriverContentsWithFrameAre (@"
  5605. This is the first line.
  5606. This is the second line.
  5607. ", _output);
  5608. tv.CursorPosition = new Point (3, 0);
  5609. Assert.Equal (new Point (3, 0), tv.CursorPosition);
  5610. Assert.True (tv.NewKeyDownEvent (new (KeyCode.Backspace)));
  5611. tv.Draw ();
  5612. Assert.Equal (new Point (2, 0), tv.CursorPosition);
  5613. TestHelpers.AssertDriverContentsWithFrameAre (@"
  5614. Ths is the first line.
  5615. This is the second line.
  5616. ", _output);
  5617. tv.CursorPosition = new Point (0, 1);
  5618. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  5619. Assert.True (tv.NewKeyDownEvent (new (KeyCode.Backspace)));
  5620. tv.Draw ();
  5621. Assert.Equal (new Point (22, 0), tv.CursorPosition);
  5622. TestHelpers.AssertDriverContentsWithFrameAre (@"
  5623. Ths is the first line.This is the second line.
  5624. ", _output);
  5625. Assert.True (tv.NewKeyDownEvent (new (KeyCode.Enter)));
  5626. tv.Draw ();
  5627. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  5628. TestHelpers.AssertDriverContentsWithFrameAre (@"
  5629. Ths is the first line.
  5630. This is the second line.
  5631. ", _output);
  5632. while (tv.Text != envText) {
  5633. Assert.True (tv.NewKeyDownEvent (new (KeyCode.Z | KeyCode.CtrlMask)));
  5634. }
  5635. Assert.Equal (envText, tv.Text);
  5636. Assert.Equal (new Point (3, 0), tv.CursorPosition);
  5637. Assert.False (tv.IsDirty);
  5638. }
  5639. [Fact]
  5640. [AutoInitShutdown]
  5641. public void DeleteTextBackwards_WordWrap_True_Return_Undo ()
  5642. {
  5643. const string text = "This is the first line.\nThis is the second line.\n";
  5644. var tv = new TextView () {
  5645. Width = Dim.Fill (),
  5646. Height = Dim.Fill (),
  5647. Text = text,
  5648. WordWrap = true
  5649. };
  5650. var envText = tv.Text;
  5651. Application.Top.Add (tv);
  5652. Application.Begin (Application.Top);
  5653. Assert.True (tv.WordWrap);
  5654. Assert.Equal (Point.Empty, tv.CursorPosition);
  5655. TestHelpers.AssertDriverContentsWithFrameAre (@"
  5656. This is the first line.
  5657. This is the second line.
  5658. ", _output);
  5659. tv.CursorPosition = new Point (3, 0);
  5660. Assert.Equal (new Point (3, 0), tv.CursorPosition);
  5661. Assert.True (tv.NewKeyDownEvent (new (KeyCode.Backspace)));
  5662. tv.Draw ();
  5663. Assert.Equal (new Point (2, 0), tv.CursorPosition);
  5664. TestHelpers.AssertDriverContentsWithFrameAre (@"
  5665. Ths is the first line.
  5666. This is the second line.
  5667. ", _output);
  5668. tv.CursorPosition = new Point (0, 1);
  5669. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  5670. Assert.True (tv.NewKeyDownEvent (new (KeyCode.Backspace)));
  5671. tv.Draw ();
  5672. Assert.Equal (new Point (22, 0), tv.CursorPosition);
  5673. TestHelpers.AssertDriverContentsWithFrameAre (@"
  5674. Ths is the first line.This is the second line.
  5675. ", _output);
  5676. Assert.True (tv.NewKeyDownEvent (new (KeyCode.Enter)));
  5677. tv.Draw ();
  5678. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  5679. TestHelpers.AssertDriverContentsWithFrameAre (@"
  5680. Ths is the first line.
  5681. This is the second line.
  5682. ", _output);
  5683. while (tv.Text != envText) {
  5684. Assert.True (tv.NewKeyDownEvent (new (KeyCode.Z | KeyCode.CtrlMask)));
  5685. }
  5686. Assert.Equal (envText, tv.Text);
  5687. Assert.Equal (new Point (3, 0), tv.CursorPosition);
  5688. Assert.False (tv.IsDirty);
  5689. }
  5690. [Fact]
  5691. [AutoInitShutdown]
  5692. public void DeleteTextForwards_WordWrap_False_Return_Undo ()
  5693. {
  5694. const string text = "This is the first line.\nThis is the second line.\n";
  5695. var tv = new TextView () {
  5696. Width = Dim.Fill (),
  5697. Height = Dim.Fill (),
  5698. Text = text
  5699. };
  5700. var envText = tv.Text;
  5701. Application.Top.Add (tv);
  5702. Application.Begin (Application.Top);
  5703. Assert.False (tv.WordWrap);
  5704. Assert.Equal (Point.Empty, tv.CursorPosition);
  5705. TestHelpers.AssertDriverContentsWithFrameAre (@"
  5706. This is the first line.
  5707. This is the second line.
  5708. ", _output);
  5709. tv.CursorPosition = new Point (2, 0);
  5710. Assert.Equal (new Point (2, 0), tv.CursorPosition);
  5711. Assert.True (tv.NewKeyDownEvent (new (KeyCode.Delete)));
  5712. tv.Draw ();
  5713. Assert.Equal (new Point (2, 0), tv.CursorPosition);
  5714. TestHelpers.AssertDriverContentsWithFrameAre (@"
  5715. Ths is the first line.
  5716. This is the second line.
  5717. ", _output);
  5718. tv.CursorPosition = new Point (22, 0);
  5719. Assert.Equal (new Point (22, 0), tv.CursorPosition);
  5720. Assert.True (tv.NewKeyDownEvent (new (KeyCode.Delete)));
  5721. tv.Draw ();
  5722. Assert.Equal (new Point (22, 0), tv.CursorPosition);
  5723. TestHelpers.AssertDriverContentsWithFrameAre (@"
  5724. Ths is the first line.This is the second line.
  5725. ", _output);
  5726. Assert.True (tv.NewKeyDownEvent (new (KeyCode.Enter)));
  5727. tv.Draw ();
  5728. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  5729. TestHelpers.AssertDriverContentsWithFrameAre (@"
  5730. Ths is the first line.
  5731. This is the second line.
  5732. ", _output);
  5733. while (tv.Text != envText) {
  5734. Assert.True (tv.NewKeyDownEvent (new (KeyCode.Z | KeyCode.CtrlMask)));
  5735. }
  5736. Assert.Equal (envText, tv.Text);
  5737. Assert.Equal (new Point (2, 0), tv.CursorPosition);
  5738. Assert.False (tv.IsDirty);
  5739. }
  5740. [Fact]
  5741. [AutoInitShutdown]
  5742. public void DeleteTextForwards_WordWrap_True_Return_Undo ()
  5743. {
  5744. const string text = "This is the first line.\nThis is the second line.\n";
  5745. var tv = new TextView () {
  5746. Width = Dim.Fill (),
  5747. Height = Dim.Fill (),
  5748. Text = text,
  5749. WordWrap = true
  5750. };
  5751. var envText = tv.Text;
  5752. Application.Top.Add (tv);
  5753. Application.Begin (Application.Top);
  5754. Assert.True (tv.WordWrap);
  5755. Assert.Equal (Point.Empty, tv.CursorPosition);
  5756. TestHelpers.AssertDriverContentsWithFrameAre (@"
  5757. This is the first line.
  5758. This is the second line.
  5759. ", _output);
  5760. tv.CursorPosition = new Point (2, 0);
  5761. Assert.Equal (new Point (2, 0), tv.CursorPosition);
  5762. Assert.True (tv.NewKeyDownEvent (new (KeyCode.Delete)));
  5763. tv.Draw ();
  5764. Assert.Equal (new Point (2, 0), tv.CursorPosition);
  5765. TestHelpers.AssertDriverContentsWithFrameAre (@"
  5766. Ths is the first line.
  5767. This is the second line.
  5768. ", _output);
  5769. tv.CursorPosition = new Point (22, 0);
  5770. Assert.Equal (new Point (22, 0), tv.CursorPosition);
  5771. Assert.True (tv.NewKeyDownEvent (new (KeyCode.Delete)));
  5772. tv.Draw ();
  5773. Assert.Equal (new Point (22, 0), tv.CursorPosition);
  5774. TestHelpers.AssertDriverContentsWithFrameAre (@"
  5775. Ths is the first line.This is the second line.
  5776. ", _output);
  5777. Assert.True (tv.NewKeyDownEvent (new (KeyCode.Enter)));
  5778. tv.Draw ();
  5779. Assert.Equal (new Point (0, 1), tv.CursorPosition);
  5780. TestHelpers.AssertDriverContentsWithFrameAre (@"
  5781. Ths is the first line.
  5782. This is the second line.
  5783. ", _output);
  5784. while (tv.Text != envText) {
  5785. Assert.True (tv.NewKeyDownEvent (new (KeyCode.Z | KeyCode.CtrlMask)));
  5786. }
  5787. Assert.Equal (envText, tv.Text);
  5788. Assert.Equal (new Point (2, 0), tv.CursorPosition);
  5789. Assert.False (tv.IsDirty);
  5790. }
  5791. [Fact]
  5792. [TextViewTestsAutoInitShutdown]
  5793. public void TextView_InsertText_Newline_LF ()
  5794. {
  5795. var tv = new TextView {
  5796. Width = 10,
  5797. Height = 10,
  5798. };
  5799. tv.InsertText ("\naaa\nbbb");
  5800. var p = Environment.OSVersion.Platform;
  5801. if (p == PlatformID.Win32NT || p == PlatformID.Win32S || p == PlatformID.Win32Windows) {
  5802. Assert.Equal ("\r\naaa\r\nbbb", tv.Text);
  5803. } else {
  5804. Assert.Equal ("\naaa\nbbb", tv.Text);
  5805. }
  5806. Assert.Equal ($"{Environment.NewLine}aaa{Environment.NewLine}bbb", tv.Text);
  5807. var win = new Window ();
  5808. win.Add (tv);
  5809. Application.Top.Add (win);
  5810. Application.Begin (Application.Top);
  5811. ((FakeDriver)Application.Driver).SetBufferSize (15, 15);
  5812. Application.Refresh ();
  5813. //this passes
  5814. var pos = TestHelpers.AssertDriverContentsWithFrameAre (
  5815. @"
  5816. ┌─────────────┐
  5817. │ │
  5818. │aaa │
  5819. │bbb │
  5820. │ │
  5821. │ │
  5822. │ │
  5823. │ │
  5824. │ │
  5825. │ │
  5826. │ │
  5827. │ │
  5828. │ │
  5829. │ │
  5830. └─────────────┘", _output);
  5831. Assert.Equal (new Rect (0, 0, 15, 15), pos);
  5832. Assert.True (tv.Used);
  5833. tv.Used = false;
  5834. tv.CursorPosition = new Point (0, 0);
  5835. tv.InsertText ("\naaa\nbbb");
  5836. Application.Refresh ();
  5837. TestHelpers.AssertDriverContentsWithFrameAre (
  5838. @"
  5839. ┌─────────────┐
  5840. │ │
  5841. │aaa │
  5842. │bbb │
  5843. │aaa │
  5844. │bbb │
  5845. │ │
  5846. │ │
  5847. │ │
  5848. │ │
  5849. │ │
  5850. │ │
  5851. │ │
  5852. │ │
  5853. └─────────────┘", _output);
  5854. }
  5855. [Fact]
  5856. [TextViewTestsAutoInitShutdown]
  5857. public void TextView_InsertText_Newline_CRLF ()
  5858. {
  5859. var tv = new TextView {
  5860. Width = 10,
  5861. Height = 10,
  5862. };
  5863. tv.InsertText ("\r\naaa\r\nbbb");
  5864. var p = Environment.OSVersion.Platform;
  5865. if (p == PlatformID.Win32NT || p == PlatformID.Win32S || p == PlatformID.Win32Windows) {
  5866. Assert.Equal ("\r\naaa\r\nbbb", tv.Text);
  5867. } else {
  5868. Assert.Equal ("\naaa\nbbb", tv.Text);
  5869. }
  5870. Assert.Equal ($"{Environment.NewLine}aaa{Environment.NewLine}bbb", tv.Text);
  5871. var win = new Window ();
  5872. win.Add (tv);
  5873. Application.Top.Add (win);
  5874. Application.Begin (Application.Top);
  5875. ((FakeDriver)Application.Driver).SetBufferSize (15, 15);
  5876. Application.Refresh ();
  5877. //this passes
  5878. var pos = TestHelpers.AssertDriverContentsWithFrameAre (
  5879. @"
  5880. ┌─────────────┐
  5881. │ │
  5882. │aaa │
  5883. │bbb │
  5884. │ │
  5885. │ │
  5886. │ │
  5887. │ │
  5888. │ │
  5889. │ │
  5890. │ │
  5891. │ │
  5892. │ │
  5893. │ │
  5894. └─────────────┘", _output);
  5895. Assert.Equal (new Rect (0, 0, 15, 15), pos);
  5896. Assert.True (tv.Used);
  5897. tv.Used = false;
  5898. tv.CursorPosition = new Point (0, 0);
  5899. tv.InsertText ("\r\naaa\r\nbbb");
  5900. Application.Refresh ();
  5901. TestHelpers.AssertDriverContentsWithFrameAre (
  5902. @"
  5903. ┌─────────────┐
  5904. │ │
  5905. │aaa │
  5906. │bbb │
  5907. │aaa │
  5908. │bbb │
  5909. │ │
  5910. │ │
  5911. │ │
  5912. │ │
  5913. │ │
  5914. │ │
  5915. │ │
  5916. │ │
  5917. └─────────────┘", _output);
  5918. }
  5919. [Fact, AutoInitShutdown]
  5920. public void ContentsChanged_Event_NoFires_On_CursorPosition ()
  5921. {
  5922. var eventcount = 0;
  5923. var tv = new TextView {
  5924. Width = 50,
  5925. Height = 10,
  5926. };
  5927. tv.ContentsChanged += (s, e) => {
  5928. eventcount++;
  5929. };
  5930. Assert.Equal (0, eventcount);
  5931. tv.CursorPosition = new Point (0, 0);
  5932. Assert.Equal (0, eventcount);
  5933. }
  5934. [Fact, AutoInitShutdown]
  5935. public void ContentsChanged_Event_Fires_On_InsertText ()
  5936. {
  5937. var eventcount = 0;
  5938. var tv = new TextView {
  5939. Width = 50,
  5940. Height = 10,
  5941. };
  5942. tv.CursorPosition = new Point (0, 0);
  5943. tv.ContentsChanged += (s, e) => {
  5944. eventcount++;
  5945. };
  5946. Assert.Equal (0, eventcount);
  5947. tv.InsertText ("a");
  5948. Assert.Equal (1, eventcount);
  5949. tv.CursorPosition = new Point (0, 0);
  5950. tv.InsertText ("bcd");
  5951. Assert.Equal (4, eventcount);
  5952. tv.InsertText ("e");
  5953. Assert.Equal (5, eventcount);
  5954. tv.InsertText ("\n");
  5955. Assert.Equal (6, eventcount);
  5956. tv.InsertText ("1234");
  5957. Assert.Equal (10, eventcount);
  5958. }
  5959. [Fact, AutoInitShutdown]
  5960. public void ContentsChanged_Event_Fires_On_Init ()
  5961. {
  5962. Application.Iteration += (s, a) => {
  5963. Application.RequestStop ();
  5964. };
  5965. var expectedRow = 0;
  5966. var expectedCol = 0;
  5967. var eventcount = 0;
  5968. var tv = new TextView {
  5969. Width = 50,
  5970. Height = 10,
  5971. };
  5972. tv.ContentsChanged += (s, e) => {
  5973. eventcount++;
  5974. Assert.Equal (expectedRow, e.Row);
  5975. Assert.Equal (expectedCol, e.Col);
  5976. };
  5977. Application.Top.Add (tv);
  5978. Application.Begin (Application.Top);
  5979. Assert.Equal (1, eventcount);
  5980. }
  5981. [Fact, AutoInitShutdown]
  5982. public void ContentsChanged_Event_Fires_On_Set_Text ()
  5983. {
  5984. Application.Iteration += (s, a) => {
  5985. Application.RequestStop ();
  5986. };
  5987. var eventcount = 0;
  5988. var expectedRow = 0;
  5989. var expectedCol = 0;
  5990. var tv = new TextView {
  5991. Width = 50,
  5992. Height = 10,
  5993. // you'd think col would be 3, but it's 0 because TextView sets
  5994. // row/col = 0 when you set Text
  5995. Text = "abc",
  5996. };
  5997. tv.ContentsChanged += (s, e) => {
  5998. eventcount++;
  5999. Assert.Equal (expectedRow, e.Row);
  6000. Assert.Equal (expectedCol, e.Col);
  6001. };
  6002. Assert.Equal ("abc", tv.Text);
  6003. Application.Top.Add (tv);
  6004. var rs = Application.Begin (Application.Top);
  6005. Assert.Equal (1, eventcount); // for Initialize
  6006. expectedCol = 0;
  6007. tv.Text = "defg";
  6008. Assert.Equal (2, eventcount); // for set Text = "defg"
  6009. }
  6010. [Fact, AutoInitShutdown]
  6011. public void ContentsChanged_Event_Fires_On_Typing ()
  6012. {
  6013. Application.Iteration += (s, a) => {
  6014. Application.RequestStop ();
  6015. };
  6016. var eventcount = 0;
  6017. var expectedRow = 0;
  6018. var expectedCol = 0;
  6019. var tv = new TextView {
  6020. Width = 50,
  6021. Height = 10,
  6022. };
  6023. tv.ContentsChanged += (s, e) => {
  6024. eventcount++;
  6025. Assert.Equal (expectedRow, e.Row);
  6026. Assert.Equal (expectedCol, e.Col);
  6027. };
  6028. Application.Top.Add (tv);
  6029. var rs = Application.Begin (Application.Top);
  6030. Assert.Equal (1, eventcount); // for Initialize
  6031. expectedCol = 0;
  6032. tv.Text = "ay";
  6033. Assert.Equal (2, eventcount);
  6034. expectedCol = 1;
  6035. tv.NewKeyDownEvent (new (KeyCode.Y | KeyCode.ShiftMask));
  6036. Assert.Equal (3, eventcount);
  6037. Assert.Equal ("Yay", tv.Text);
  6038. }
  6039. [Fact, TextViewTestsAutoInitShutdown]
  6040. public void ContentsChanged_Event_Fires_Using_Kill_Delete_Tests ()
  6041. {
  6042. var eventcount = 0;
  6043. _textView.ContentsChanged += (s, e) => {
  6044. eventcount++;
  6045. };
  6046. var expectedEventCount = 1;
  6047. Kill_Delete_WordForward ();
  6048. Assert.Equal (expectedEventCount, eventcount); // for Initialize
  6049. expectedEventCount += 1;
  6050. Kill_Delete_WordBackward ();
  6051. Assert.Equal (expectedEventCount, eventcount);
  6052. expectedEventCount += 2;
  6053. Kill_To_End_Delete_Forwards_Copy_To_The_Clipboard_And_Paste ();
  6054. Assert.Equal (expectedEventCount, eventcount);
  6055. expectedEventCount += 2;
  6056. Kill_To_Start_Delete_Backwards_Copy_To_The_Clipboard_And_Paste ();
  6057. Assert.Equal (expectedEventCount, eventcount);
  6058. }
  6059. [Fact, TextViewTestsAutoInitShutdown]
  6060. public void ContentsChanged_Event_Fires_Using_Copy_Or_Cut_Tests ()
  6061. {
  6062. var eventcount = 0;
  6063. _textView.ContentsChanged += (s, e) => {
  6064. eventcount++;
  6065. };
  6066. var expectedEventCount = 1;
  6067. // reset
  6068. _textView.Text = TextViewTestsAutoInitShutdown.txt;
  6069. Assert.Equal (expectedEventCount, eventcount);
  6070. expectedEventCount += 3;
  6071. Copy_Or_Cut_And_Paste_With_No_Selection ();
  6072. Assert.Equal (expectedEventCount, eventcount);
  6073. // reset
  6074. expectedEventCount += 1;
  6075. _textView.Text = TextViewTestsAutoInitShutdown.txt;
  6076. Assert.Equal (expectedEventCount, eventcount);
  6077. expectedEventCount += 3;
  6078. Copy_Or_Cut_And_Paste_With_Selection ();
  6079. Assert.Equal (expectedEventCount, eventcount);
  6080. // reset
  6081. expectedEventCount += 1;
  6082. _textView.Text = TextViewTestsAutoInitShutdown.txt;
  6083. Assert.Equal (expectedEventCount, eventcount);
  6084. expectedEventCount += 1;
  6085. Copy_Or_Cut_Not_Null_If_Has_Selection ();
  6086. Assert.Equal (expectedEventCount, eventcount);
  6087. // reset
  6088. expectedEventCount += 1;
  6089. _textView.Text = TextViewTestsAutoInitShutdown.txt;
  6090. Assert.Equal (expectedEventCount, eventcount);
  6091. expectedEventCount += 1;
  6092. Copy_Or_Cut_Null_If_No_Selection ();
  6093. Assert.Equal (expectedEventCount, eventcount);
  6094. // reset
  6095. expectedEventCount += 1;
  6096. _textView.Text = TextViewTestsAutoInitShutdown.txt;
  6097. Assert.Equal (expectedEventCount, eventcount);
  6098. expectedEventCount += 4;
  6099. Copy_Without_Selection ();
  6100. Assert.Equal (expectedEventCount, eventcount);
  6101. // reset
  6102. expectedEventCount += 1;
  6103. _textView.Text = TextViewTestsAutoInitShutdown.txt;
  6104. Assert.Equal (expectedEventCount, eventcount);
  6105. expectedEventCount += 4;
  6106. Copy_Without_Selection ();
  6107. Assert.Equal (expectedEventCount, eventcount);
  6108. }
  6109. [Fact, TextViewTestsAutoInitShutdown]
  6110. public void ContentsChanged_Event_Fires_On_Undo_Redo ()
  6111. {
  6112. var eventcount = 0;
  6113. var expectedEventCount = 0;
  6114. _textView.ContentsChanged += (s, e) => {
  6115. eventcount++;
  6116. };
  6117. expectedEventCount++;
  6118. _textView.Text = "This is the first line.\nThis is the second line.\nThis is the third line.";
  6119. Assert.Equal (expectedEventCount, eventcount);
  6120. expectedEventCount++;
  6121. Assert.True (_textView.NewKeyDownEvent (new (KeyCode.Enter)));
  6122. Assert.Equal (expectedEventCount, eventcount);
  6123. // Undo
  6124. expectedEventCount++;
  6125. Assert.True (_textView.NewKeyDownEvent (new (KeyCode.Z | KeyCode.CtrlMask)));
  6126. Assert.Equal (expectedEventCount, eventcount);
  6127. // Redo
  6128. expectedEventCount++;
  6129. Assert.True (_textView.NewKeyDownEvent (new (KeyCode.R | KeyCode.CtrlMask)));
  6130. Assert.Equal (expectedEventCount, eventcount);
  6131. // Undo
  6132. expectedEventCount++;
  6133. Assert.True (_textView.NewKeyDownEvent (new (KeyCode.Z | KeyCode.CtrlMask)));
  6134. Assert.Equal (expectedEventCount, eventcount);
  6135. // Redo
  6136. expectedEventCount++;
  6137. Assert.True (_textView.NewKeyDownEvent (new (KeyCode.R | KeyCode.CtrlMask)));
  6138. Assert.Equal (expectedEventCount, eventcount);
  6139. }
  6140. [Fact]
  6141. public void ContentsChanged_Event_Fires_ClearHistoryChanges ()
  6142. {
  6143. var eventcount = 0;
  6144. var text = "This is the first line.\nThis is the second line.\nThis is the third line.";
  6145. var tv = new TextView {
  6146. Width = 50,
  6147. Height = 10,
  6148. Text = text,
  6149. };
  6150. tv.ContentsChanged += (s, e) => {
  6151. eventcount++;
  6152. };
  6153. Assert.True (tv.NewKeyDownEvent (new (KeyCode.Enter)));
  6154. 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);
  6155. Assert.Equal (4, tv.Lines);
  6156. var expectedEventCount = 1; // for ENTER key
  6157. Assert.Equal (expectedEventCount, eventcount);
  6158. tv.ClearHistoryChanges ();
  6159. expectedEventCount = 2;
  6160. Assert.Equal (expectedEventCount, eventcount);
  6161. }
  6162. [Fact]
  6163. public void ContentsChanged_Event_Fires_LoadStream_By_Calling_HistoryText_Clear ()
  6164. {
  6165. var eventcount = 0;
  6166. var tv = new TextView {
  6167. Width = 50,
  6168. Height = 10,
  6169. };
  6170. tv.ContentsChanged += (s, e) => {
  6171. eventcount++;
  6172. };
  6173. var text = "This is the first line.\r\nThis is the second line.\r\n";
  6174. tv.Load (new System.IO.MemoryStream (System.Text.Encoding.ASCII.GetBytes (text)));
  6175. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}", tv.Text);
  6176. Assert.Equal (1, eventcount);
  6177. }
  6178. [Fact]
  6179. public void ContentsChanged_Event_Fires_On_LoadFile_By_Calling_HistoryText_Clear ()
  6180. {
  6181. var eventcount = 0;
  6182. var tv = new TextView {
  6183. Width = 50,
  6184. Height = 10,
  6185. };
  6186. tv.BeginInit (); tv.EndInit ();
  6187. tv.ContentsChanged += (s, e) => {
  6188. eventcount++;
  6189. };
  6190. var fileName = "textview.txt";
  6191. System.IO.File.WriteAllText (fileName, "This is the first line.\r\nThis is the second line.\r\n");
  6192. tv.Load (fileName);
  6193. Assert.Equal (1, eventcount);
  6194. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}", tv.Text);
  6195. }
  6196. [Fact]
  6197. public void ReplaceAllText_Does_Not_Throw_Exception ()
  6198. {
  6199. var textToFind = "hello! hello!";
  6200. var textToReplace = "hello!";
  6201. var tv = new TextView () { Width = 20, Height = 3, Text = textToFind };
  6202. var exception = Record.Exception (() => tv.ReplaceAllText (textToFind, false, false, textToReplace));
  6203. Assert.Null (exception);
  6204. Assert.Equal (textToReplace, tv.Text);
  6205. }
  6206. [Fact]
  6207. public void WordBackward_WordForward_Limits_Return_Null ()
  6208. {
  6209. var model = new TextModel ();
  6210. model.LoadString ("Test");
  6211. var newPos = model.WordBackward (0, 0);
  6212. Assert.Null (newPos);
  6213. newPos = model.WordForward (4, 0);
  6214. Assert.Null (newPos);
  6215. }
  6216. [Fact, TextViewTestsAutoInitShutdown]
  6217. public void Cursor_Position_Multiline_False_Initialization ()
  6218. {
  6219. Assert.False (_textView.IsInitialized);
  6220. Assert.True (_textView.Multiline);
  6221. _textView.Multiline = false;
  6222. Assert.Equal (32, _textView.CursorPosition.X);
  6223. Assert.Equal (0, _textView.CursorPosition.Y);
  6224. Assert.Equal (0, _textView.SelectedLength);
  6225. Assert.Equal ("", _textView.SelectedText);
  6226. Assert.Equal ("TAB to jump between text fields.", _textView.Text);
  6227. }
  6228. [Fact, TextViewTestsAutoInitShutdown]
  6229. public void Copy_Paste_Surrogate_Pairs ()
  6230. {
  6231. _textView.Text = "TextView with some more test text. Unicode shouldn't 𝔹Aℝ𝔽!";
  6232. _textView.SelectAll ();
  6233. _textView.Cut ();
  6234. Assert.Equal ("TextView with some more test text. Unicode shouldn't 𝔹Aℝ𝔽!", Application.Driver.Clipboard.GetClipboardData ());
  6235. Assert.Equal (string.Empty, _textView.Text);
  6236. _textView.Paste ();
  6237. Assert.Equal ("TextView with some more test text. Unicode shouldn't 𝔹Aℝ𝔽!", _textView.Text);
  6238. }
  6239. [Fact, TextViewTestsAutoInitShutdown]
  6240. public void WordWrap_True_LoadStream_New_Text ()
  6241. {
  6242. Assert.Equal ("TAB to jump between text fields.", _textView.Text);
  6243. _textView.WordWrap = true;
  6244. Assert.Equal ("TAB to jump between text fields.", _textView.Text);
  6245. var text = "This is the first line.\nThis is the second line.\n";
  6246. using (System.IO.MemoryStream stream = new System.IO.MemoryStream ()) {
  6247. var writer = new System.IO.StreamWriter (stream);
  6248. writer.Write (text);
  6249. writer.Flush ();
  6250. stream.Position = 0;
  6251. _textView.Load (stream);
  6252. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}", _textView.Text);
  6253. Assert.True (_textView.WordWrap);
  6254. }
  6255. }
  6256. }