chunk-SPLH5WDX.js 396 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751
  1. import {
  2. __commonJS
  3. } from "./chunk-2LSFTFF7.js";
  4. // node_modules/.pnpm/codemirror@5.65.12/node_modules/codemirror/lib/codemirror.js
  5. var require_codemirror = __commonJS({
  6. "node_modules/.pnpm/codemirror@5.65.12/node_modules/codemirror/lib/codemirror.js"(exports, module) {
  7. (function(global, factory) {
  8. typeof exports === "object" && typeof module !== "undefined" ? module.exports = factory() : typeof define === "function" && define.amd ? define(factory) : (global = global || self, global.CodeMirror = factory());
  9. })(exports, function() {
  10. "use strict";
  11. var userAgent = navigator.userAgent;
  12. var platform = navigator.platform;
  13. var gecko = /gecko\/\d/i.test(userAgent);
  14. var ie_upto10 = /MSIE \d/.test(userAgent);
  15. var ie_11up = /Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(userAgent);
  16. var edge = /Edge\/(\d+)/.exec(userAgent);
  17. var ie = ie_upto10 || ie_11up || edge;
  18. var ie_version = ie && (ie_upto10 ? document.documentMode || 6 : +(edge || ie_11up)[1]);
  19. var webkit = !edge && /WebKit\//.test(userAgent);
  20. var qtwebkit = webkit && /Qt\/\d+\.\d+/.test(userAgent);
  21. var chrome = !edge && /Chrome\/(\d+)/.exec(userAgent);
  22. var chrome_version = chrome && +chrome[1];
  23. var presto = /Opera\//.test(userAgent);
  24. var safari = /Apple Computer/.test(navigator.vendor);
  25. var mac_geMountainLion = /Mac OS X 1\d\D([8-9]|\d\d)\D/.test(userAgent);
  26. var phantom = /PhantomJS/.test(userAgent);
  27. var ios = safari && (/Mobile\/\w+/.test(userAgent) || navigator.maxTouchPoints > 2);
  28. var android = /Android/.test(userAgent);
  29. var mobile = ios || android || /webOS|BlackBerry|Opera Mini|Opera Mobi|IEMobile/i.test(userAgent);
  30. var mac = ios || /Mac/.test(platform);
  31. var chromeOS = /\bCrOS\b/.test(userAgent);
  32. var windows = /win/i.test(platform);
  33. var presto_version = presto && userAgent.match(/Version\/(\d*\.\d*)/);
  34. if (presto_version) {
  35. presto_version = Number(presto_version[1]);
  36. }
  37. if (presto_version && presto_version >= 15) {
  38. presto = false;
  39. webkit = true;
  40. }
  41. var flipCtrlCmd = mac && (qtwebkit || presto && (presto_version == null || presto_version < 12.11));
  42. var captureRightClick = gecko || ie && ie_version >= 9;
  43. function classTest(cls) {
  44. return new RegExp("(^|\\s)" + cls + "(?:$|\\s)\\s*");
  45. }
  46. var rmClass = function(node, cls) {
  47. var current = node.className;
  48. var match = classTest(cls).exec(current);
  49. if (match) {
  50. var after = current.slice(match.index + match[0].length);
  51. node.className = current.slice(0, match.index) + (after ? match[1] + after : "");
  52. }
  53. };
  54. function removeChildren(e) {
  55. for (var count = e.childNodes.length; count > 0; --count) {
  56. e.removeChild(e.firstChild);
  57. }
  58. return e;
  59. }
  60. function removeChildrenAndAdd(parent, e) {
  61. return removeChildren(parent).appendChild(e);
  62. }
  63. function elt(tag, content, className, style) {
  64. var e = document.createElement(tag);
  65. if (className) {
  66. e.className = className;
  67. }
  68. if (style) {
  69. e.style.cssText = style;
  70. }
  71. if (typeof content == "string") {
  72. e.appendChild(document.createTextNode(content));
  73. } else if (content) {
  74. for (var i2 = 0; i2 < content.length; ++i2) {
  75. e.appendChild(content[i2]);
  76. }
  77. }
  78. return e;
  79. }
  80. function eltP(tag, content, className, style) {
  81. var e = elt(tag, content, className, style);
  82. e.setAttribute("role", "presentation");
  83. return e;
  84. }
  85. var range;
  86. if (document.createRange) {
  87. range = function(node, start, end, endNode) {
  88. var r = document.createRange();
  89. r.setEnd(endNode || node, end);
  90. r.setStart(node, start);
  91. return r;
  92. };
  93. } else {
  94. range = function(node, start, end) {
  95. var r = document.body.createTextRange();
  96. try {
  97. r.moveToElementText(node.parentNode);
  98. } catch (e) {
  99. return r;
  100. }
  101. r.collapse(true);
  102. r.moveEnd("character", end);
  103. r.moveStart("character", start);
  104. return r;
  105. };
  106. }
  107. function contains(parent, child) {
  108. if (child.nodeType == 3) {
  109. child = child.parentNode;
  110. }
  111. if (parent.contains) {
  112. return parent.contains(child);
  113. }
  114. do {
  115. if (child.nodeType == 11) {
  116. child = child.host;
  117. }
  118. if (child == parent) {
  119. return true;
  120. }
  121. } while (child = child.parentNode);
  122. }
  123. function activeElt(doc2) {
  124. var activeElement;
  125. try {
  126. activeElement = doc2.activeElement;
  127. } catch (e) {
  128. activeElement = doc2.body || null;
  129. }
  130. while (activeElement && activeElement.shadowRoot && activeElement.shadowRoot.activeElement) {
  131. activeElement = activeElement.shadowRoot.activeElement;
  132. }
  133. return activeElement;
  134. }
  135. function addClass(node, cls) {
  136. var current = node.className;
  137. if (!classTest(cls).test(current)) {
  138. node.className += (current ? " " : "") + cls;
  139. }
  140. }
  141. function joinClasses(a, b) {
  142. var as = a.split(" ");
  143. for (var i2 = 0; i2 < as.length; i2++) {
  144. if (as[i2] && !classTest(as[i2]).test(b)) {
  145. b += " " + as[i2];
  146. }
  147. }
  148. return b;
  149. }
  150. var selectInput = function(node) {
  151. node.select();
  152. };
  153. if (ios) {
  154. selectInput = function(node) {
  155. node.selectionStart = 0;
  156. node.selectionEnd = node.value.length;
  157. };
  158. } else if (ie) {
  159. selectInput = function(node) {
  160. try {
  161. node.select();
  162. } catch (_e) {
  163. }
  164. };
  165. }
  166. function doc(cm) {
  167. return cm.display.wrapper.ownerDocument;
  168. }
  169. function win(cm) {
  170. return doc(cm).defaultView;
  171. }
  172. function bind(f) {
  173. var args = Array.prototype.slice.call(arguments, 1);
  174. return function() {
  175. return f.apply(null, args);
  176. };
  177. }
  178. function copyObj(obj, target, overwrite) {
  179. if (!target) {
  180. target = {};
  181. }
  182. for (var prop2 in obj) {
  183. if (obj.hasOwnProperty(prop2) && (overwrite !== false || !target.hasOwnProperty(prop2))) {
  184. target[prop2] = obj[prop2];
  185. }
  186. }
  187. return target;
  188. }
  189. function countColumn(string, end, tabSize, startIndex, startValue) {
  190. if (end == null) {
  191. end = string.search(/[^\s\u00a0]/);
  192. if (end == -1) {
  193. end = string.length;
  194. }
  195. }
  196. for (var i2 = startIndex || 0, n = startValue || 0; ; ) {
  197. var nextTab = string.indexOf(" ", i2);
  198. if (nextTab < 0 || nextTab >= end) {
  199. return n + (end - i2);
  200. }
  201. n += nextTab - i2;
  202. n += tabSize - n % tabSize;
  203. i2 = nextTab + 1;
  204. }
  205. }
  206. var Delayed = function() {
  207. this.id = null;
  208. this.f = null;
  209. this.time = 0;
  210. this.handler = bind(this.onTimeout, this);
  211. };
  212. Delayed.prototype.onTimeout = function(self2) {
  213. self2.id = 0;
  214. if (self2.time <= +/* @__PURE__ */ new Date()) {
  215. self2.f();
  216. } else {
  217. setTimeout(self2.handler, self2.time - +/* @__PURE__ */ new Date());
  218. }
  219. };
  220. Delayed.prototype.set = function(ms, f) {
  221. this.f = f;
  222. var time = +/* @__PURE__ */ new Date() + ms;
  223. if (!this.id || time < this.time) {
  224. clearTimeout(this.id);
  225. this.id = setTimeout(this.handler, ms);
  226. this.time = time;
  227. }
  228. };
  229. function indexOf(array, elt2) {
  230. for (var i2 = 0; i2 < array.length; ++i2) {
  231. if (array[i2] == elt2) {
  232. return i2;
  233. }
  234. }
  235. return -1;
  236. }
  237. var scrollerGap = 50;
  238. var Pass = { toString: function() {
  239. return "CodeMirror.Pass";
  240. } };
  241. var sel_dontScroll = { scroll: false }, sel_mouse = { origin: "*mouse" }, sel_move = { origin: "+move" };
  242. function findColumn(string, goal, tabSize) {
  243. for (var pos = 0, col = 0; ; ) {
  244. var nextTab = string.indexOf(" ", pos);
  245. if (nextTab == -1) {
  246. nextTab = string.length;
  247. }
  248. var skipped = nextTab - pos;
  249. if (nextTab == string.length || col + skipped >= goal) {
  250. return pos + Math.min(skipped, goal - col);
  251. }
  252. col += nextTab - pos;
  253. col += tabSize - col % tabSize;
  254. pos = nextTab + 1;
  255. if (col >= goal) {
  256. return pos;
  257. }
  258. }
  259. }
  260. var spaceStrs = [""];
  261. function spaceStr(n) {
  262. while (spaceStrs.length <= n) {
  263. spaceStrs.push(lst(spaceStrs) + " ");
  264. }
  265. return spaceStrs[n];
  266. }
  267. function lst(arr) {
  268. return arr[arr.length - 1];
  269. }
  270. function map(array, f) {
  271. var out = [];
  272. for (var i2 = 0; i2 < array.length; i2++) {
  273. out[i2] = f(array[i2], i2);
  274. }
  275. return out;
  276. }
  277. function insertSorted(array, value, score) {
  278. var pos = 0, priority = score(value);
  279. while (pos < array.length && score(array[pos]) <= priority) {
  280. pos++;
  281. }
  282. array.splice(pos, 0, value);
  283. }
  284. function nothing() {
  285. }
  286. function createObj(base, props) {
  287. var inst;
  288. if (Object.create) {
  289. inst = Object.create(base);
  290. } else {
  291. nothing.prototype = base;
  292. inst = new nothing();
  293. }
  294. if (props) {
  295. copyObj(props, inst);
  296. }
  297. return inst;
  298. }
  299. var nonASCIISingleCaseWordChar = /[\u00df\u0587\u0590-\u05f4\u0600-\u06ff\u3040-\u309f\u30a0-\u30ff\u3400-\u4db5\u4e00-\u9fcc\uac00-\ud7af]/;
  300. function isWordCharBasic(ch) {
  301. return /\w/.test(ch) || ch > "€" && (ch.toUpperCase() != ch.toLowerCase() || nonASCIISingleCaseWordChar.test(ch));
  302. }
  303. function isWordChar(ch, helper) {
  304. if (!helper) {
  305. return isWordCharBasic(ch);
  306. }
  307. if (helper.source.indexOf("\\w") > -1 && isWordCharBasic(ch)) {
  308. return true;
  309. }
  310. return helper.test(ch);
  311. }
  312. function isEmpty(obj) {
  313. for (var n in obj) {
  314. if (obj.hasOwnProperty(n) && obj[n]) {
  315. return false;
  316. }
  317. }
  318. return true;
  319. }
  320. var extendingChars = /[\u0300-\u036f\u0483-\u0489\u0591-\u05bd\u05bf\u05c1\u05c2\u05c4\u05c5\u05c7\u0610-\u061a\u064b-\u065e\u0670\u06d6-\u06dc\u06de-\u06e4\u06e7\u06e8\u06ea-\u06ed\u0711\u0730-\u074a\u07a6-\u07b0\u07eb-\u07f3\u0816-\u0819\u081b-\u0823\u0825-\u0827\u0829-\u082d\u0900-\u0902\u093c\u0941-\u0948\u094d\u0951-\u0955\u0962\u0963\u0981\u09bc\u09be\u09c1-\u09c4\u09cd\u09d7\u09e2\u09e3\u0a01\u0a02\u0a3c\u0a41\u0a42\u0a47\u0a48\u0a4b-\u0a4d\u0a51\u0a70\u0a71\u0a75\u0a81\u0a82\u0abc\u0ac1-\u0ac5\u0ac7\u0ac8\u0acd\u0ae2\u0ae3\u0b01\u0b3c\u0b3e\u0b3f\u0b41-\u0b44\u0b4d\u0b56\u0b57\u0b62\u0b63\u0b82\u0bbe\u0bc0\u0bcd\u0bd7\u0c3e-\u0c40\u0c46-\u0c48\u0c4a-\u0c4d\u0c55\u0c56\u0c62\u0c63\u0cbc\u0cbf\u0cc2\u0cc6\u0ccc\u0ccd\u0cd5\u0cd6\u0ce2\u0ce3\u0d3e\u0d41-\u0d44\u0d4d\u0d57\u0d62\u0d63\u0dca\u0dcf\u0dd2-\u0dd4\u0dd6\u0ddf\u0e31\u0e34-\u0e3a\u0e47-\u0e4e\u0eb1\u0eb4-\u0eb9\u0ebb\u0ebc\u0ec8-\u0ecd\u0f18\u0f19\u0f35\u0f37\u0f39\u0f71-\u0f7e\u0f80-\u0f84\u0f86\u0f87\u0f90-\u0f97\u0f99-\u0fbc\u0fc6\u102d-\u1030\u1032-\u1037\u1039\u103a\u103d\u103e\u1058\u1059\u105e-\u1060\u1071-\u1074\u1082\u1085\u1086\u108d\u109d\u135f\u1712-\u1714\u1732-\u1734\u1752\u1753\u1772\u1773\u17b7-\u17bd\u17c6\u17c9-\u17d3\u17dd\u180b-\u180d\u18a9\u1920-\u1922\u1927\u1928\u1932\u1939-\u193b\u1a17\u1a18\u1a56\u1a58-\u1a5e\u1a60\u1a62\u1a65-\u1a6c\u1a73-\u1a7c\u1a7f\u1b00-\u1b03\u1b34\u1b36-\u1b3a\u1b3c\u1b42\u1b6b-\u1b73\u1b80\u1b81\u1ba2-\u1ba5\u1ba8\u1ba9\u1c2c-\u1c33\u1c36\u1c37\u1cd0-\u1cd2\u1cd4-\u1ce0\u1ce2-\u1ce8\u1ced\u1dc0-\u1de6\u1dfd-\u1dff\u200c\u200d\u20d0-\u20f0\u2cef-\u2cf1\u2de0-\u2dff\u302a-\u302f\u3099\u309a\ua66f-\ua672\ua67c\ua67d\ua6f0\ua6f1\ua802\ua806\ua80b\ua825\ua826\ua8c4\ua8e0-\ua8f1\ua926-\ua92d\ua947-\ua951\ua980-\ua982\ua9b3\ua9b6-\ua9b9\ua9bc\uaa29-\uaa2e\uaa31\uaa32\uaa35\uaa36\uaa43\uaa4c\uaab0\uaab2-\uaab4\uaab7\uaab8\uaabe\uaabf\uaac1\uabe5\uabe8\uabed\udc00-\udfff\ufb1e\ufe00-\ufe0f\ufe20-\ufe26\uff9e\uff9f]/;
  321. function isExtendingChar(ch) {
  322. return ch.charCodeAt(0) >= 768 && extendingChars.test(ch);
  323. }
  324. function skipExtendingChars(str, pos, dir) {
  325. while ((dir < 0 ? pos > 0 : pos < str.length) && isExtendingChar(str.charAt(pos))) {
  326. pos += dir;
  327. }
  328. return pos;
  329. }
  330. function findFirst(pred, from, to) {
  331. var dir = from > to ? -1 : 1;
  332. for (; ; ) {
  333. if (from == to) {
  334. return from;
  335. }
  336. var midF = (from + to) / 2, mid = dir < 0 ? Math.ceil(midF) : Math.floor(midF);
  337. if (mid == from) {
  338. return pred(mid) ? from : to;
  339. }
  340. if (pred(mid)) {
  341. to = mid;
  342. } else {
  343. from = mid + dir;
  344. }
  345. }
  346. }
  347. function iterateBidiSections(order, from, to, f) {
  348. if (!order) {
  349. return f(from, to, "ltr", 0);
  350. }
  351. var found = false;
  352. for (var i2 = 0; i2 < order.length; ++i2) {
  353. var part = order[i2];
  354. if (part.from < to && part.to > from || from == to && part.to == from) {
  355. f(Math.max(part.from, from), Math.min(part.to, to), part.level == 1 ? "rtl" : "ltr", i2);
  356. found = true;
  357. }
  358. }
  359. if (!found) {
  360. f(from, to, "ltr");
  361. }
  362. }
  363. var bidiOther = null;
  364. function getBidiPartAt(order, ch, sticky) {
  365. var found;
  366. bidiOther = null;
  367. for (var i2 = 0; i2 < order.length; ++i2) {
  368. var cur = order[i2];
  369. if (cur.from < ch && cur.to > ch) {
  370. return i2;
  371. }
  372. if (cur.to == ch) {
  373. if (cur.from != cur.to && sticky == "before") {
  374. found = i2;
  375. } else {
  376. bidiOther = i2;
  377. }
  378. }
  379. if (cur.from == ch) {
  380. if (cur.from != cur.to && sticky != "before") {
  381. found = i2;
  382. } else {
  383. bidiOther = i2;
  384. }
  385. }
  386. }
  387. return found != null ? found : bidiOther;
  388. }
  389. var bidiOrdering = function() {
  390. var lowTypes = "bbbbbbbbbtstwsbbbbbbbbbbbbbbssstwNN%%%NNNNNN,N,N1111111111NNNNNNNLLLLLLLLLLLLLLLLLLLLLLLLLLNNNNNNLLLLLLLLLLLLLLLLLLLLLLLLLLNNNNbbbbbbsbbbbbbbbbbbbbbbbbbbbbbbbbb,N%%%%NNNNLNNNNN%%11NLNNN1LNNNNNLLLLLLLLLLLLLLLLLLLLLLLNLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLN";
  391. var arabicTypes = "nnnnnnNNr%%r,rNNmmmmmmmmmmmrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrmmmmmmmmmmmmmmmmmmmmmnnnnnnnnnn%nnrrrmrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrmmmmmmmnNmmmmmmrrmmNmmmmrr1111111111";
  392. function charType(code) {
  393. if (code <= 247) {
  394. return lowTypes.charAt(code);
  395. } else if (1424 <= code && code <= 1524) {
  396. return "R";
  397. } else if (1536 <= code && code <= 1785) {
  398. return arabicTypes.charAt(code - 1536);
  399. } else if (1774 <= code && code <= 2220) {
  400. return "r";
  401. } else if (8192 <= code && code <= 8203) {
  402. return "w";
  403. } else if (code == 8204) {
  404. return "b";
  405. } else {
  406. return "L";
  407. }
  408. }
  409. var bidiRE = /[\u0590-\u05f4\u0600-\u06ff\u0700-\u08ac]/;
  410. var isNeutral = /[stwN]/, isStrong = /[LRr]/, countsAsLeft = /[Lb1n]/, countsAsNum = /[1n]/;
  411. function BidiSpan(level, from, to) {
  412. this.level = level;
  413. this.from = from;
  414. this.to = to;
  415. }
  416. return function(str, direction) {
  417. var outerType = direction == "ltr" ? "L" : "R";
  418. if (str.length == 0 || direction == "ltr" && !bidiRE.test(str)) {
  419. return false;
  420. }
  421. var len = str.length, types = [];
  422. for (var i2 = 0; i2 < len; ++i2) {
  423. types.push(charType(str.charCodeAt(i2)));
  424. }
  425. for (var i$12 = 0, prev = outerType; i$12 < len; ++i$12) {
  426. var type = types[i$12];
  427. if (type == "m") {
  428. types[i$12] = prev;
  429. } else {
  430. prev = type;
  431. }
  432. }
  433. for (var i$22 = 0, cur = outerType; i$22 < len; ++i$22) {
  434. var type$1 = types[i$22];
  435. if (type$1 == "1" && cur == "r") {
  436. types[i$22] = "n";
  437. } else if (isStrong.test(type$1)) {
  438. cur = type$1;
  439. if (type$1 == "r") {
  440. types[i$22] = "R";
  441. }
  442. }
  443. }
  444. for (var i$3 = 1, prev$1 = types[0]; i$3 < len - 1; ++i$3) {
  445. var type$2 = types[i$3];
  446. if (type$2 == "+" && prev$1 == "1" && types[i$3 + 1] == "1") {
  447. types[i$3] = "1";
  448. } else if (type$2 == "," && prev$1 == types[i$3 + 1] && (prev$1 == "1" || prev$1 == "n")) {
  449. types[i$3] = prev$1;
  450. }
  451. prev$1 = type$2;
  452. }
  453. for (var i$4 = 0; i$4 < len; ++i$4) {
  454. var type$3 = types[i$4];
  455. if (type$3 == ",") {
  456. types[i$4] = "N";
  457. } else if (type$3 == "%") {
  458. var end = void 0;
  459. for (end = i$4 + 1; end < len && types[end] == "%"; ++end) {
  460. }
  461. var replace = i$4 && types[i$4 - 1] == "!" || end < len && types[end] == "1" ? "1" : "N";
  462. for (var j = i$4; j < end; ++j) {
  463. types[j] = replace;
  464. }
  465. i$4 = end - 1;
  466. }
  467. }
  468. for (var i$5 = 0, cur$1 = outerType; i$5 < len; ++i$5) {
  469. var type$4 = types[i$5];
  470. if (cur$1 == "L" && type$4 == "1") {
  471. types[i$5] = "L";
  472. } else if (isStrong.test(type$4)) {
  473. cur$1 = type$4;
  474. }
  475. }
  476. for (var i$6 = 0; i$6 < len; ++i$6) {
  477. if (isNeutral.test(types[i$6])) {
  478. var end$1 = void 0;
  479. for (end$1 = i$6 + 1; end$1 < len && isNeutral.test(types[end$1]); ++end$1) {
  480. }
  481. var before = (i$6 ? types[i$6 - 1] : outerType) == "L";
  482. var after = (end$1 < len ? types[end$1] : outerType) == "L";
  483. var replace$1 = before == after ? before ? "L" : "R" : outerType;
  484. for (var j$1 = i$6; j$1 < end$1; ++j$1) {
  485. types[j$1] = replace$1;
  486. }
  487. i$6 = end$1 - 1;
  488. }
  489. }
  490. var order = [], m;
  491. for (var i$7 = 0; i$7 < len; ) {
  492. if (countsAsLeft.test(types[i$7])) {
  493. var start = i$7;
  494. for (++i$7; i$7 < len && countsAsLeft.test(types[i$7]); ++i$7) {
  495. }
  496. order.push(new BidiSpan(0, start, i$7));
  497. } else {
  498. var pos = i$7, at = order.length, isRTL = direction == "rtl" ? 1 : 0;
  499. for (++i$7; i$7 < len && types[i$7] != "L"; ++i$7) {
  500. }
  501. for (var j$2 = pos; j$2 < i$7; ) {
  502. if (countsAsNum.test(types[j$2])) {
  503. if (pos < j$2) {
  504. order.splice(at, 0, new BidiSpan(1, pos, j$2));
  505. at += isRTL;
  506. }
  507. var nstart = j$2;
  508. for (++j$2; j$2 < i$7 && countsAsNum.test(types[j$2]); ++j$2) {
  509. }
  510. order.splice(at, 0, new BidiSpan(2, nstart, j$2));
  511. at += isRTL;
  512. pos = j$2;
  513. } else {
  514. ++j$2;
  515. }
  516. }
  517. if (pos < i$7) {
  518. order.splice(at, 0, new BidiSpan(1, pos, i$7));
  519. }
  520. }
  521. }
  522. if (direction == "ltr") {
  523. if (order[0].level == 1 && (m = str.match(/^\s+/))) {
  524. order[0].from = m[0].length;
  525. order.unshift(new BidiSpan(0, 0, m[0].length));
  526. }
  527. if (lst(order).level == 1 && (m = str.match(/\s+$/))) {
  528. lst(order).to -= m[0].length;
  529. order.push(new BidiSpan(0, len - m[0].length, len));
  530. }
  531. }
  532. return direction == "rtl" ? order.reverse() : order;
  533. };
  534. }();
  535. function getOrder(line, direction) {
  536. var order = line.order;
  537. if (order == null) {
  538. order = line.order = bidiOrdering(line.text, direction);
  539. }
  540. return order;
  541. }
  542. var noHandlers = [];
  543. var on = function(emitter, type, f) {
  544. if (emitter.addEventListener) {
  545. emitter.addEventListener(type, f, false);
  546. } else if (emitter.attachEvent) {
  547. emitter.attachEvent("on" + type, f);
  548. } else {
  549. var map2 = emitter._handlers || (emitter._handlers = {});
  550. map2[type] = (map2[type] || noHandlers).concat(f);
  551. }
  552. };
  553. function getHandlers(emitter, type) {
  554. return emitter._handlers && emitter._handlers[type] || noHandlers;
  555. }
  556. function off(emitter, type, f) {
  557. if (emitter.removeEventListener) {
  558. emitter.removeEventListener(type, f, false);
  559. } else if (emitter.detachEvent) {
  560. emitter.detachEvent("on" + type, f);
  561. } else {
  562. var map2 = emitter._handlers, arr = map2 && map2[type];
  563. if (arr) {
  564. var index = indexOf(arr, f);
  565. if (index > -1) {
  566. map2[type] = arr.slice(0, index).concat(arr.slice(index + 1));
  567. }
  568. }
  569. }
  570. }
  571. function signal(emitter, type) {
  572. var handlers = getHandlers(emitter, type);
  573. if (!handlers.length) {
  574. return;
  575. }
  576. var args = Array.prototype.slice.call(arguments, 2);
  577. for (var i2 = 0; i2 < handlers.length; ++i2) {
  578. handlers[i2].apply(null, args);
  579. }
  580. }
  581. function signalDOMEvent(cm, e, override) {
  582. if (typeof e == "string") {
  583. e = { type: e, preventDefault: function() {
  584. this.defaultPrevented = true;
  585. } };
  586. }
  587. signal(cm, override || e.type, cm, e);
  588. return e_defaultPrevented(e) || e.codemirrorIgnore;
  589. }
  590. function signalCursorActivity(cm) {
  591. var arr = cm._handlers && cm._handlers.cursorActivity;
  592. if (!arr) {
  593. return;
  594. }
  595. var set = cm.curOp.cursorActivityHandlers || (cm.curOp.cursorActivityHandlers = []);
  596. for (var i2 = 0; i2 < arr.length; ++i2) {
  597. if (indexOf(set, arr[i2]) == -1) {
  598. set.push(arr[i2]);
  599. }
  600. }
  601. }
  602. function hasHandler(emitter, type) {
  603. return getHandlers(emitter, type).length > 0;
  604. }
  605. function eventMixin(ctor) {
  606. ctor.prototype.on = function(type, f) {
  607. on(this, type, f);
  608. };
  609. ctor.prototype.off = function(type, f) {
  610. off(this, type, f);
  611. };
  612. }
  613. function e_preventDefault(e) {
  614. if (e.preventDefault) {
  615. e.preventDefault();
  616. } else {
  617. e.returnValue = false;
  618. }
  619. }
  620. function e_stopPropagation(e) {
  621. if (e.stopPropagation) {
  622. e.stopPropagation();
  623. } else {
  624. e.cancelBubble = true;
  625. }
  626. }
  627. function e_defaultPrevented(e) {
  628. return e.defaultPrevented != null ? e.defaultPrevented : e.returnValue == false;
  629. }
  630. function e_stop(e) {
  631. e_preventDefault(e);
  632. e_stopPropagation(e);
  633. }
  634. function e_target(e) {
  635. return e.target || e.srcElement;
  636. }
  637. function e_button(e) {
  638. var b = e.which;
  639. if (b == null) {
  640. if (e.button & 1) {
  641. b = 1;
  642. } else if (e.button & 2) {
  643. b = 3;
  644. } else if (e.button & 4) {
  645. b = 2;
  646. }
  647. }
  648. if (mac && e.ctrlKey && b == 1) {
  649. b = 3;
  650. }
  651. return b;
  652. }
  653. var dragAndDrop = function() {
  654. if (ie && ie_version < 9) {
  655. return false;
  656. }
  657. var div = elt("div");
  658. return "draggable" in div || "dragDrop" in div;
  659. }();
  660. var zwspSupported;
  661. function zeroWidthElement(measure) {
  662. if (zwspSupported == null) {
  663. var test = elt("span", "​");
  664. removeChildrenAndAdd(measure, elt("span", [test, document.createTextNode("x")]));
  665. if (measure.firstChild.offsetHeight != 0) {
  666. zwspSupported = test.offsetWidth <= 1 && test.offsetHeight > 2 && !(ie && ie_version < 8);
  667. }
  668. }
  669. var node = zwspSupported ? elt("span", "​") : elt("span", " ", null, "display: inline-block; width: 1px; margin-right: -1px");
  670. node.setAttribute("cm-text", "");
  671. return node;
  672. }
  673. var badBidiRects;
  674. function hasBadBidiRects(measure) {
  675. if (badBidiRects != null) {
  676. return badBidiRects;
  677. }
  678. var txt = removeChildrenAndAdd(measure, document.createTextNode("AخA"));
  679. var r0 = range(txt, 0, 1).getBoundingClientRect();
  680. var r1 = range(txt, 1, 2).getBoundingClientRect();
  681. removeChildren(measure);
  682. if (!r0 || r0.left == r0.right) {
  683. return false;
  684. }
  685. return badBidiRects = r1.right - r0.right < 3;
  686. }
  687. var splitLinesAuto = "\n\nb".split(/\n/).length != 3 ? function(string) {
  688. var pos = 0, result = [], l = string.length;
  689. while (pos <= l) {
  690. var nl = string.indexOf("\n", pos);
  691. if (nl == -1) {
  692. nl = string.length;
  693. }
  694. var line = string.slice(pos, string.charAt(nl - 1) == "\r" ? nl - 1 : nl);
  695. var rt = line.indexOf("\r");
  696. if (rt != -1) {
  697. result.push(line.slice(0, rt));
  698. pos += rt + 1;
  699. } else {
  700. result.push(line);
  701. pos = nl + 1;
  702. }
  703. }
  704. return result;
  705. } : function(string) {
  706. return string.split(/\r\n?|\n/);
  707. };
  708. var hasSelection = window.getSelection ? function(te) {
  709. try {
  710. return te.selectionStart != te.selectionEnd;
  711. } catch (e) {
  712. return false;
  713. }
  714. } : function(te) {
  715. var range2;
  716. try {
  717. range2 = te.ownerDocument.selection.createRange();
  718. } catch (e) {
  719. }
  720. if (!range2 || range2.parentElement() != te) {
  721. return false;
  722. }
  723. return range2.compareEndPoints("StartToEnd", range2) != 0;
  724. };
  725. var hasCopyEvent = function() {
  726. var e = elt("div");
  727. if ("oncopy" in e) {
  728. return true;
  729. }
  730. e.setAttribute("oncopy", "return;");
  731. return typeof e.oncopy == "function";
  732. }();
  733. var badZoomedRects = null;
  734. function hasBadZoomedRects(measure) {
  735. if (badZoomedRects != null) {
  736. return badZoomedRects;
  737. }
  738. var node = removeChildrenAndAdd(measure, elt("span", "x"));
  739. var normal = node.getBoundingClientRect();
  740. var fromRange = range(node, 0, 1).getBoundingClientRect();
  741. return badZoomedRects = Math.abs(normal.left - fromRange.left) > 1;
  742. }
  743. var modes = {}, mimeModes = {};
  744. function defineMode(name, mode) {
  745. if (arguments.length > 2) {
  746. mode.dependencies = Array.prototype.slice.call(arguments, 2);
  747. }
  748. modes[name] = mode;
  749. }
  750. function defineMIME(mime, spec) {
  751. mimeModes[mime] = spec;
  752. }
  753. function resolveMode(spec) {
  754. if (typeof spec == "string" && mimeModes.hasOwnProperty(spec)) {
  755. spec = mimeModes[spec];
  756. } else if (spec && typeof spec.name == "string" && mimeModes.hasOwnProperty(spec.name)) {
  757. var found = mimeModes[spec.name];
  758. if (typeof found == "string") {
  759. found = { name: found };
  760. }
  761. spec = createObj(found, spec);
  762. spec.name = found.name;
  763. } else if (typeof spec == "string" && /^[\w\-]+\/[\w\-]+\+xml$/.test(spec)) {
  764. return resolveMode("application/xml");
  765. } else if (typeof spec == "string" && /^[\w\-]+\/[\w\-]+\+json$/.test(spec)) {
  766. return resolveMode("application/json");
  767. }
  768. if (typeof spec == "string") {
  769. return { name: spec };
  770. } else {
  771. return spec || { name: "null" };
  772. }
  773. }
  774. function getMode(options, spec) {
  775. spec = resolveMode(spec);
  776. var mfactory = modes[spec.name];
  777. if (!mfactory) {
  778. return getMode(options, "text/plain");
  779. }
  780. var modeObj = mfactory(options, spec);
  781. if (modeExtensions.hasOwnProperty(spec.name)) {
  782. var exts = modeExtensions[spec.name];
  783. for (var prop2 in exts) {
  784. if (!exts.hasOwnProperty(prop2)) {
  785. continue;
  786. }
  787. if (modeObj.hasOwnProperty(prop2)) {
  788. modeObj["_" + prop2] = modeObj[prop2];
  789. }
  790. modeObj[prop2] = exts[prop2];
  791. }
  792. }
  793. modeObj.name = spec.name;
  794. if (spec.helperType) {
  795. modeObj.helperType = spec.helperType;
  796. }
  797. if (spec.modeProps) {
  798. for (var prop$1 in spec.modeProps) {
  799. modeObj[prop$1] = spec.modeProps[prop$1];
  800. }
  801. }
  802. return modeObj;
  803. }
  804. var modeExtensions = {};
  805. function extendMode(mode, properties) {
  806. var exts = modeExtensions.hasOwnProperty(mode) ? modeExtensions[mode] : modeExtensions[mode] = {};
  807. copyObj(properties, exts);
  808. }
  809. function copyState(mode, state) {
  810. if (state === true) {
  811. return state;
  812. }
  813. if (mode.copyState) {
  814. return mode.copyState(state);
  815. }
  816. var nstate = {};
  817. for (var n in state) {
  818. var val = state[n];
  819. if (val instanceof Array) {
  820. val = val.concat([]);
  821. }
  822. nstate[n] = val;
  823. }
  824. return nstate;
  825. }
  826. function innerMode(mode, state) {
  827. var info;
  828. while (mode.innerMode) {
  829. info = mode.innerMode(state);
  830. if (!info || info.mode == mode) {
  831. break;
  832. }
  833. state = info.state;
  834. mode = info.mode;
  835. }
  836. return info || { mode, state };
  837. }
  838. function startState(mode, a1, a2) {
  839. return mode.startState ? mode.startState(a1, a2) : true;
  840. }
  841. var StringStream = function(string, tabSize, lineOracle) {
  842. this.pos = this.start = 0;
  843. this.string = string;
  844. this.tabSize = tabSize || 8;
  845. this.lastColumnPos = this.lastColumnValue = 0;
  846. this.lineStart = 0;
  847. this.lineOracle = lineOracle;
  848. };
  849. StringStream.prototype.eol = function() {
  850. return this.pos >= this.string.length;
  851. };
  852. StringStream.prototype.sol = function() {
  853. return this.pos == this.lineStart;
  854. };
  855. StringStream.prototype.peek = function() {
  856. return this.string.charAt(this.pos) || void 0;
  857. };
  858. StringStream.prototype.next = function() {
  859. if (this.pos < this.string.length) {
  860. return this.string.charAt(this.pos++);
  861. }
  862. };
  863. StringStream.prototype.eat = function(match) {
  864. var ch = this.string.charAt(this.pos);
  865. var ok;
  866. if (typeof match == "string") {
  867. ok = ch == match;
  868. } else {
  869. ok = ch && (match.test ? match.test(ch) : match(ch));
  870. }
  871. if (ok) {
  872. ++this.pos;
  873. return ch;
  874. }
  875. };
  876. StringStream.prototype.eatWhile = function(match) {
  877. var start = this.pos;
  878. while (this.eat(match)) {
  879. }
  880. return this.pos > start;
  881. };
  882. StringStream.prototype.eatSpace = function() {
  883. var start = this.pos;
  884. while (/[\s\u00a0]/.test(this.string.charAt(this.pos))) {
  885. ++this.pos;
  886. }
  887. return this.pos > start;
  888. };
  889. StringStream.prototype.skipToEnd = function() {
  890. this.pos = this.string.length;
  891. };
  892. StringStream.prototype.skipTo = function(ch) {
  893. var found = this.string.indexOf(ch, this.pos);
  894. if (found > -1) {
  895. this.pos = found;
  896. return true;
  897. }
  898. };
  899. StringStream.prototype.backUp = function(n) {
  900. this.pos -= n;
  901. };
  902. StringStream.prototype.column = function() {
  903. if (this.lastColumnPos < this.start) {
  904. this.lastColumnValue = countColumn(this.string, this.start, this.tabSize, this.lastColumnPos, this.lastColumnValue);
  905. this.lastColumnPos = this.start;
  906. }
  907. return this.lastColumnValue - (this.lineStart ? countColumn(this.string, this.lineStart, this.tabSize) : 0);
  908. };
  909. StringStream.prototype.indentation = function() {
  910. return countColumn(this.string, null, this.tabSize) - (this.lineStart ? countColumn(this.string, this.lineStart, this.tabSize) : 0);
  911. };
  912. StringStream.prototype.match = function(pattern, consume, caseInsensitive) {
  913. if (typeof pattern == "string") {
  914. var cased = function(str) {
  915. return caseInsensitive ? str.toLowerCase() : str;
  916. };
  917. var substr = this.string.substr(this.pos, pattern.length);
  918. if (cased(substr) == cased(pattern)) {
  919. if (consume !== false) {
  920. this.pos += pattern.length;
  921. }
  922. return true;
  923. }
  924. } else {
  925. var match = this.string.slice(this.pos).match(pattern);
  926. if (match && match.index > 0) {
  927. return null;
  928. }
  929. if (match && consume !== false) {
  930. this.pos += match[0].length;
  931. }
  932. return match;
  933. }
  934. };
  935. StringStream.prototype.current = function() {
  936. return this.string.slice(this.start, this.pos);
  937. };
  938. StringStream.prototype.hideFirstChars = function(n, inner) {
  939. this.lineStart += n;
  940. try {
  941. return inner();
  942. } finally {
  943. this.lineStart -= n;
  944. }
  945. };
  946. StringStream.prototype.lookAhead = function(n) {
  947. var oracle = this.lineOracle;
  948. return oracle && oracle.lookAhead(n);
  949. };
  950. StringStream.prototype.baseToken = function() {
  951. var oracle = this.lineOracle;
  952. return oracle && oracle.baseToken(this.pos);
  953. };
  954. function getLine(doc2, n) {
  955. n -= doc2.first;
  956. if (n < 0 || n >= doc2.size) {
  957. throw new Error("There is no line " + (n + doc2.first) + " in the document.");
  958. }
  959. var chunk = doc2;
  960. while (!chunk.lines) {
  961. for (var i2 = 0; ; ++i2) {
  962. var child = chunk.children[i2], sz = child.chunkSize();
  963. if (n < sz) {
  964. chunk = child;
  965. break;
  966. }
  967. n -= sz;
  968. }
  969. }
  970. return chunk.lines[n];
  971. }
  972. function getBetween(doc2, start, end) {
  973. var out = [], n = start.line;
  974. doc2.iter(start.line, end.line + 1, function(line) {
  975. var text = line.text;
  976. if (n == end.line) {
  977. text = text.slice(0, end.ch);
  978. }
  979. if (n == start.line) {
  980. text = text.slice(start.ch);
  981. }
  982. out.push(text);
  983. ++n;
  984. });
  985. return out;
  986. }
  987. function getLines(doc2, from, to) {
  988. var out = [];
  989. doc2.iter(from, to, function(line) {
  990. out.push(line.text);
  991. });
  992. return out;
  993. }
  994. function updateLineHeight(line, height) {
  995. var diff = height - line.height;
  996. if (diff) {
  997. for (var n = line; n; n = n.parent) {
  998. n.height += diff;
  999. }
  1000. }
  1001. }
  1002. function lineNo(line) {
  1003. if (line.parent == null) {
  1004. return null;
  1005. }
  1006. var cur = line.parent, no = indexOf(cur.lines, line);
  1007. for (var chunk = cur.parent; chunk; cur = chunk, chunk = chunk.parent) {
  1008. for (var i2 = 0; ; ++i2) {
  1009. if (chunk.children[i2] == cur) {
  1010. break;
  1011. }
  1012. no += chunk.children[i2].chunkSize();
  1013. }
  1014. }
  1015. return no + cur.first;
  1016. }
  1017. function lineAtHeight(chunk, h) {
  1018. var n = chunk.first;
  1019. outer:
  1020. do {
  1021. for (var i$12 = 0; i$12 < chunk.children.length; ++i$12) {
  1022. var child = chunk.children[i$12], ch = child.height;
  1023. if (h < ch) {
  1024. chunk = child;
  1025. continue outer;
  1026. }
  1027. h -= ch;
  1028. n += child.chunkSize();
  1029. }
  1030. return n;
  1031. } while (!chunk.lines);
  1032. var i2 = 0;
  1033. for (; i2 < chunk.lines.length; ++i2) {
  1034. var line = chunk.lines[i2], lh = line.height;
  1035. if (h < lh) {
  1036. break;
  1037. }
  1038. h -= lh;
  1039. }
  1040. return n + i2;
  1041. }
  1042. function isLine(doc2, l) {
  1043. return l >= doc2.first && l < doc2.first + doc2.size;
  1044. }
  1045. function lineNumberFor(options, i2) {
  1046. return String(options.lineNumberFormatter(i2 + options.firstLineNumber));
  1047. }
  1048. function Pos(line, ch, sticky) {
  1049. if (sticky === void 0)
  1050. sticky = null;
  1051. if (!(this instanceof Pos)) {
  1052. return new Pos(line, ch, sticky);
  1053. }
  1054. this.line = line;
  1055. this.ch = ch;
  1056. this.sticky = sticky;
  1057. }
  1058. function cmp(a, b) {
  1059. return a.line - b.line || a.ch - b.ch;
  1060. }
  1061. function equalCursorPos(a, b) {
  1062. return a.sticky == b.sticky && cmp(a, b) == 0;
  1063. }
  1064. function copyPos(x) {
  1065. return Pos(x.line, x.ch);
  1066. }
  1067. function maxPos(a, b) {
  1068. return cmp(a, b) < 0 ? b : a;
  1069. }
  1070. function minPos(a, b) {
  1071. return cmp(a, b) < 0 ? a : b;
  1072. }
  1073. function clipLine(doc2, n) {
  1074. return Math.max(doc2.first, Math.min(n, doc2.first + doc2.size - 1));
  1075. }
  1076. function clipPos(doc2, pos) {
  1077. if (pos.line < doc2.first) {
  1078. return Pos(doc2.first, 0);
  1079. }
  1080. var last = doc2.first + doc2.size - 1;
  1081. if (pos.line > last) {
  1082. return Pos(last, getLine(doc2, last).text.length);
  1083. }
  1084. return clipToLen(pos, getLine(doc2, pos.line).text.length);
  1085. }
  1086. function clipToLen(pos, linelen) {
  1087. var ch = pos.ch;
  1088. if (ch == null || ch > linelen) {
  1089. return Pos(pos.line, linelen);
  1090. } else if (ch < 0) {
  1091. return Pos(pos.line, 0);
  1092. } else {
  1093. return pos;
  1094. }
  1095. }
  1096. function clipPosArray(doc2, array) {
  1097. var out = [];
  1098. for (var i2 = 0; i2 < array.length; i2++) {
  1099. out[i2] = clipPos(doc2, array[i2]);
  1100. }
  1101. return out;
  1102. }
  1103. var SavedContext = function(state, lookAhead) {
  1104. this.state = state;
  1105. this.lookAhead = lookAhead;
  1106. };
  1107. var Context = function(doc2, state, line, lookAhead) {
  1108. this.state = state;
  1109. this.doc = doc2;
  1110. this.line = line;
  1111. this.maxLookAhead = lookAhead || 0;
  1112. this.baseTokens = null;
  1113. this.baseTokenPos = 1;
  1114. };
  1115. Context.prototype.lookAhead = function(n) {
  1116. var line = this.doc.getLine(this.line + n);
  1117. if (line != null && n > this.maxLookAhead) {
  1118. this.maxLookAhead = n;
  1119. }
  1120. return line;
  1121. };
  1122. Context.prototype.baseToken = function(n) {
  1123. if (!this.baseTokens) {
  1124. return null;
  1125. }
  1126. while (this.baseTokens[this.baseTokenPos] <= n) {
  1127. this.baseTokenPos += 2;
  1128. }
  1129. var type = this.baseTokens[this.baseTokenPos + 1];
  1130. return {
  1131. type: type && type.replace(/( |^)overlay .*/, ""),
  1132. size: this.baseTokens[this.baseTokenPos] - n
  1133. };
  1134. };
  1135. Context.prototype.nextLine = function() {
  1136. this.line++;
  1137. if (this.maxLookAhead > 0) {
  1138. this.maxLookAhead--;
  1139. }
  1140. };
  1141. Context.fromSaved = function(doc2, saved, line) {
  1142. if (saved instanceof SavedContext) {
  1143. return new Context(doc2, copyState(doc2.mode, saved.state), line, saved.lookAhead);
  1144. } else {
  1145. return new Context(doc2, copyState(doc2.mode, saved), line);
  1146. }
  1147. };
  1148. Context.prototype.save = function(copy) {
  1149. var state = copy !== false ? copyState(this.doc.mode, this.state) : this.state;
  1150. return this.maxLookAhead > 0 ? new SavedContext(state, this.maxLookAhead) : state;
  1151. };
  1152. function highlightLine(cm, line, context, forceToEnd) {
  1153. var st = [cm.state.modeGen], lineClasses = {};
  1154. runMode(
  1155. cm,
  1156. line.text,
  1157. cm.doc.mode,
  1158. context,
  1159. function(end, style) {
  1160. return st.push(end, style);
  1161. },
  1162. lineClasses,
  1163. forceToEnd
  1164. );
  1165. var state = context.state;
  1166. var loop = function(o2) {
  1167. context.baseTokens = st;
  1168. var overlay = cm.state.overlays[o2], i2 = 1, at = 0;
  1169. context.state = true;
  1170. runMode(cm, line.text, overlay.mode, context, function(end, style) {
  1171. var start = i2;
  1172. while (at < end) {
  1173. var i_end = st[i2];
  1174. if (i_end > end) {
  1175. st.splice(i2, 1, end, st[i2 + 1], i_end);
  1176. }
  1177. i2 += 2;
  1178. at = Math.min(end, i_end);
  1179. }
  1180. if (!style) {
  1181. return;
  1182. }
  1183. if (overlay.opaque) {
  1184. st.splice(start, i2 - start, end, "overlay " + style);
  1185. i2 = start + 2;
  1186. } else {
  1187. for (; start < i2; start += 2) {
  1188. var cur = st[start + 1];
  1189. st[start + 1] = (cur ? cur + " " : "") + "overlay " + style;
  1190. }
  1191. }
  1192. }, lineClasses);
  1193. context.state = state;
  1194. context.baseTokens = null;
  1195. context.baseTokenPos = 1;
  1196. };
  1197. for (var o = 0; o < cm.state.overlays.length; ++o)
  1198. loop(o);
  1199. return { styles: st, classes: lineClasses.bgClass || lineClasses.textClass ? lineClasses : null };
  1200. }
  1201. function getLineStyles(cm, line, updateFrontier) {
  1202. if (!line.styles || line.styles[0] != cm.state.modeGen) {
  1203. var context = getContextBefore(cm, lineNo(line));
  1204. var resetState = line.text.length > cm.options.maxHighlightLength && copyState(cm.doc.mode, context.state);
  1205. var result = highlightLine(cm, line, context);
  1206. if (resetState) {
  1207. context.state = resetState;
  1208. }
  1209. line.stateAfter = context.save(!resetState);
  1210. line.styles = result.styles;
  1211. if (result.classes) {
  1212. line.styleClasses = result.classes;
  1213. } else if (line.styleClasses) {
  1214. line.styleClasses = null;
  1215. }
  1216. if (updateFrontier === cm.doc.highlightFrontier) {
  1217. cm.doc.modeFrontier = Math.max(cm.doc.modeFrontier, ++cm.doc.highlightFrontier);
  1218. }
  1219. }
  1220. return line.styles;
  1221. }
  1222. function getContextBefore(cm, n, precise) {
  1223. var doc2 = cm.doc, display = cm.display;
  1224. if (!doc2.mode.startState) {
  1225. return new Context(doc2, true, n);
  1226. }
  1227. var start = findStartLine(cm, n, precise);
  1228. var saved = start > doc2.first && getLine(doc2, start - 1).stateAfter;
  1229. var context = saved ? Context.fromSaved(doc2, saved, start) : new Context(doc2, startState(doc2.mode), start);
  1230. doc2.iter(start, n, function(line) {
  1231. processLine(cm, line.text, context);
  1232. var pos = context.line;
  1233. line.stateAfter = pos == n - 1 || pos % 5 == 0 || pos >= display.viewFrom && pos < display.viewTo ? context.save() : null;
  1234. context.nextLine();
  1235. });
  1236. if (precise) {
  1237. doc2.modeFrontier = context.line;
  1238. }
  1239. return context;
  1240. }
  1241. function processLine(cm, text, context, startAt) {
  1242. var mode = cm.doc.mode;
  1243. var stream = new StringStream(text, cm.options.tabSize, context);
  1244. stream.start = stream.pos = startAt || 0;
  1245. if (text == "") {
  1246. callBlankLine(mode, context.state);
  1247. }
  1248. while (!stream.eol()) {
  1249. readToken(mode, stream, context.state);
  1250. stream.start = stream.pos;
  1251. }
  1252. }
  1253. function callBlankLine(mode, state) {
  1254. if (mode.blankLine) {
  1255. return mode.blankLine(state);
  1256. }
  1257. if (!mode.innerMode) {
  1258. return;
  1259. }
  1260. var inner = innerMode(mode, state);
  1261. if (inner.mode.blankLine) {
  1262. return inner.mode.blankLine(inner.state);
  1263. }
  1264. }
  1265. function readToken(mode, stream, state, inner) {
  1266. for (var i2 = 0; i2 < 10; i2++) {
  1267. if (inner) {
  1268. inner[0] = innerMode(mode, state).mode;
  1269. }
  1270. var style = mode.token(stream, state);
  1271. if (stream.pos > stream.start) {
  1272. return style;
  1273. }
  1274. }
  1275. throw new Error("Mode " + mode.name + " failed to advance stream.");
  1276. }
  1277. var Token = function(stream, type, state) {
  1278. this.start = stream.start;
  1279. this.end = stream.pos;
  1280. this.string = stream.current();
  1281. this.type = type || null;
  1282. this.state = state;
  1283. };
  1284. function takeToken(cm, pos, precise, asArray) {
  1285. var doc2 = cm.doc, mode = doc2.mode, style;
  1286. pos = clipPos(doc2, pos);
  1287. var line = getLine(doc2, pos.line), context = getContextBefore(cm, pos.line, precise);
  1288. var stream = new StringStream(line.text, cm.options.tabSize, context), tokens;
  1289. if (asArray) {
  1290. tokens = [];
  1291. }
  1292. while ((asArray || stream.pos < pos.ch) && !stream.eol()) {
  1293. stream.start = stream.pos;
  1294. style = readToken(mode, stream, context.state);
  1295. if (asArray) {
  1296. tokens.push(new Token(stream, style, copyState(doc2.mode, context.state)));
  1297. }
  1298. }
  1299. return asArray ? tokens : new Token(stream, style, context.state);
  1300. }
  1301. function extractLineClasses(type, output) {
  1302. if (type) {
  1303. for (; ; ) {
  1304. var lineClass = type.match(/(?:^|\s+)line-(background-)?(\S+)/);
  1305. if (!lineClass) {
  1306. break;
  1307. }
  1308. type = type.slice(0, lineClass.index) + type.slice(lineClass.index + lineClass[0].length);
  1309. var prop2 = lineClass[1] ? "bgClass" : "textClass";
  1310. if (output[prop2] == null) {
  1311. output[prop2] = lineClass[2];
  1312. } else if (!new RegExp("(?:^|\\s)" + lineClass[2] + "(?:$|\\s)").test(output[prop2])) {
  1313. output[prop2] += " " + lineClass[2];
  1314. }
  1315. }
  1316. }
  1317. return type;
  1318. }
  1319. function runMode(cm, text, mode, context, f, lineClasses, forceToEnd) {
  1320. var flattenSpans = mode.flattenSpans;
  1321. if (flattenSpans == null) {
  1322. flattenSpans = cm.options.flattenSpans;
  1323. }
  1324. var curStart = 0, curStyle = null;
  1325. var stream = new StringStream(text, cm.options.tabSize, context), style;
  1326. var inner = cm.options.addModeClass && [null];
  1327. if (text == "") {
  1328. extractLineClasses(callBlankLine(mode, context.state), lineClasses);
  1329. }
  1330. while (!stream.eol()) {
  1331. if (stream.pos > cm.options.maxHighlightLength) {
  1332. flattenSpans = false;
  1333. if (forceToEnd) {
  1334. processLine(cm, text, context, stream.pos);
  1335. }
  1336. stream.pos = text.length;
  1337. style = null;
  1338. } else {
  1339. style = extractLineClasses(readToken(mode, stream, context.state, inner), lineClasses);
  1340. }
  1341. if (inner) {
  1342. var mName = inner[0].name;
  1343. if (mName) {
  1344. style = "m-" + (style ? mName + " " + style : mName);
  1345. }
  1346. }
  1347. if (!flattenSpans || curStyle != style) {
  1348. while (curStart < stream.start) {
  1349. curStart = Math.min(stream.start, curStart + 5e3);
  1350. f(curStart, curStyle);
  1351. }
  1352. curStyle = style;
  1353. }
  1354. stream.start = stream.pos;
  1355. }
  1356. while (curStart < stream.pos) {
  1357. var pos = Math.min(stream.pos, curStart + 5e3);
  1358. f(pos, curStyle);
  1359. curStart = pos;
  1360. }
  1361. }
  1362. function findStartLine(cm, n, precise) {
  1363. var minindent, minline, doc2 = cm.doc;
  1364. var lim = precise ? -1 : n - (cm.doc.mode.innerMode ? 1e3 : 100);
  1365. for (var search = n; search > lim; --search) {
  1366. if (search <= doc2.first) {
  1367. return doc2.first;
  1368. }
  1369. var line = getLine(doc2, search - 1), after = line.stateAfter;
  1370. if (after && (!precise || search + (after instanceof SavedContext ? after.lookAhead : 0) <= doc2.modeFrontier)) {
  1371. return search;
  1372. }
  1373. var indented = countColumn(line.text, null, cm.options.tabSize);
  1374. if (minline == null || minindent > indented) {
  1375. minline = search - 1;
  1376. minindent = indented;
  1377. }
  1378. }
  1379. return minline;
  1380. }
  1381. function retreatFrontier(doc2, n) {
  1382. doc2.modeFrontier = Math.min(doc2.modeFrontier, n);
  1383. if (doc2.highlightFrontier < n - 10) {
  1384. return;
  1385. }
  1386. var start = doc2.first;
  1387. for (var line = n - 1; line > start; line--) {
  1388. var saved = getLine(doc2, line).stateAfter;
  1389. if (saved && (!(saved instanceof SavedContext) || line + saved.lookAhead < n)) {
  1390. start = line + 1;
  1391. break;
  1392. }
  1393. }
  1394. doc2.highlightFrontier = Math.min(doc2.highlightFrontier, start);
  1395. }
  1396. var sawReadOnlySpans = false, sawCollapsedSpans = false;
  1397. function seeReadOnlySpans() {
  1398. sawReadOnlySpans = true;
  1399. }
  1400. function seeCollapsedSpans() {
  1401. sawCollapsedSpans = true;
  1402. }
  1403. function MarkedSpan(marker, from, to) {
  1404. this.marker = marker;
  1405. this.from = from;
  1406. this.to = to;
  1407. }
  1408. function getMarkedSpanFor(spans, marker) {
  1409. if (spans) {
  1410. for (var i2 = 0; i2 < spans.length; ++i2) {
  1411. var span = spans[i2];
  1412. if (span.marker == marker) {
  1413. return span;
  1414. }
  1415. }
  1416. }
  1417. }
  1418. function removeMarkedSpan(spans, span) {
  1419. var r;
  1420. for (var i2 = 0; i2 < spans.length; ++i2) {
  1421. if (spans[i2] != span) {
  1422. (r || (r = [])).push(spans[i2]);
  1423. }
  1424. }
  1425. return r;
  1426. }
  1427. function addMarkedSpan(line, span, op) {
  1428. var inThisOp = op && window.WeakSet && (op.markedSpans || (op.markedSpans = /* @__PURE__ */ new WeakSet()));
  1429. if (inThisOp && line.markedSpans && inThisOp.has(line.markedSpans)) {
  1430. line.markedSpans.push(span);
  1431. } else {
  1432. line.markedSpans = line.markedSpans ? line.markedSpans.concat([span]) : [span];
  1433. if (inThisOp) {
  1434. inThisOp.add(line.markedSpans);
  1435. }
  1436. }
  1437. span.marker.attachLine(line);
  1438. }
  1439. function markedSpansBefore(old, startCh, isInsert) {
  1440. var nw;
  1441. if (old) {
  1442. for (var i2 = 0; i2 < old.length; ++i2) {
  1443. var span = old[i2], marker = span.marker;
  1444. var startsBefore = span.from == null || (marker.inclusiveLeft ? span.from <= startCh : span.from < startCh);
  1445. if (startsBefore || span.from == startCh && marker.type == "bookmark" && (!isInsert || !span.marker.insertLeft)) {
  1446. var endsAfter = span.to == null || (marker.inclusiveRight ? span.to >= startCh : span.to > startCh);
  1447. (nw || (nw = [])).push(new MarkedSpan(marker, span.from, endsAfter ? null : span.to));
  1448. }
  1449. }
  1450. }
  1451. return nw;
  1452. }
  1453. function markedSpansAfter(old, endCh, isInsert) {
  1454. var nw;
  1455. if (old) {
  1456. for (var i2 = 0; i2 < old.length; ++i2) {
  1457. var span = old[i2], marker = span.marker;
  1458. var endsAfter = span.to == null || (marker.inclusiveRight ? span.to >= endCh : span.to > endCh);
  1459. if (endsAfter || span.from == endCh && marker.type == "bookmark" && (!isInsert || span.marker.insertLeft)) {
  1460. var startsBefore = span.from == null || (marker.inclusiveLeft ? span.from <= endCh : span.from < endCh);
  1461. (nw || (nw = [])).push(new MarkedSpan(
  1462. marker,
  1463. startsBefore ? null : span.from - endCh,
  1464. span.to == null ? null : span.to - endCh
  1465. ));
  1466. }
  1467. }
  1468. }
  1469. return nw;
  1470. }
  1471. function stretchSpansOverChange(doc2, change) {
  1472. if (change.full) {
  1473. return null;
  1474. }
  1475. var oldFirst = isLine(doc2, change.from.line) && getLine(doc2, change.from.line).markedSpans;
  1476. var oldLast = isLine(doc2, change.to.line) && getLine(doc2, change.to.line).markedSpans;
  1477. if (!oldFirst && !oldLast) {
  1478. return null;
  1479. }
  1480. var startCh = change.from.ch, endCh = change.to.ch, isInsert = cmp(change.from, change.to) == 0;
  1481. var first = markedSpansBefore(oldFirst, startCh, isInsert);
  1482. var last = markedSpansAfter(oldLast, endCh, isInsert);
  1483. var sameLine = change.text.length == 1, offset = lst(change.text).length + (sameLine ? startCh : 0);
  1484. if (first) {
  1485. for (var i2 = 0; i2 < first.length; ++i2) {
  1486. var span = first[i2];
  1487. if (span.to == null) {
  1488. var found = getMarkedSpanFor(last, span.marker);
  1489. if (!found) {
  1490. span.to = startCh;
  1491. } else if (sameLine) {
  1492. span.to = found.to == null ? null : found.to + offset;
  1493. }
  1494. }
  1495. }
  1496. }
  1497. if (last) {
  1498. for (var i$12 = 0; i$12 < last.length; ++i$12) {
  1499. var span$1 = last[i$12];
  1500. if (span$1.to != null) {
  1501. span$1.to += offset;
  1502. }
  1503. if (span$1.from == null) {
  1504. var found$1 = getMarkedSpanFor(first, span$1.marker);
  1505. if (!found$1) {
  1506. span$1.from = offset;
  1507. if (sameLine) {
  1508. (first || (first = [])).push(span$1);
  1509. }
  1510. }
  1511. } else {
  1512. span$1.from += offset;
  1513. if (sameLine) {
  1514. (first || (first = [])).push(span$1);
  1515. }
  1516. }
  1517. }
  1518. }
  1519. if (first) {
  1520. first = clearEmptySpans(first);
  1521. }
  1522. if (last && last != first) {
  1523. last = clearEmptySpans(last);
  1524. }
  1525. var newMarkers = [first];
  1526. if (!sameLine) {
  1527. var gap = change.text.length - 2, gapMarkers;
  1528. if (gap > 0 && first) {
  1529. for (var i$22 = 0; i$22 < first.length; ++i$22) {
  1530. if (first[i$22].to == null) {
  1531. (gapMarkers || (gapMarkers = [])).push(new MarkedSpan(first[i$22].marker, null, null));
  1532. }
  1533. }
  1534. }
  1535. for (var i$3 = 0; i$3 < gap; ++i$3) {
  1536. newMarkers.push(gapMarkers);
  1537. }
  1538. newMarkers.push(last);
  1539. }
  1540. return newMarkers;
  1541. }
  1542. function clearEmptySpans(spans) {
  1543. for (var i2 = 0; i2 < spans.length; ++i2) {
  1544. var span = spans[i2];
  1545. if (span.from != null && span.from == span.to && span.marker.clearWhenEmpty !== false) {
  1546. spans.splice(i2--, 1);
  1547. }
  1548. }
  1549. if (!spans.length) {
  1550. return null;
  1551. }
  1552. return spans;
  1553. }
  1554. function removeReadOnlyRanges(doc2, from, to) {
  1555. var markers = null;
  1556. doc2.iter(from.line, to.line + 1, function(line) {
  1557. if (line.markedSpans) {
  1558. for (var i3 = 0; i3 < line.markedSpans.length; ++i3) {
  1559. var mark = line.markedSpans[i3].marker;
  1560. if (mark.readOnly && (!markers || indexOf(markers, mark) == -1)) {
  1561. (markers || (markers = [])).push(mark);
  1562. }
  1563. }
  1564. }
  1565. });
  1566. if (!markers) {
  1567. return null;
  1568. }
  1569. var parts = [{ from, to }];
  1570. for (var i2 = 0; i2 < markers.length; ++i2) {
  1571. var mk = markers[i2], m = mk.find(0);
  1572. for (var j = 0; j < parts.length; ++j) {
  1573. var p = parts[j];
  1574. if (cmp(p.to, m.from) < 0 || cmp(p.from, m.to) > 0) {
  1575. continue;
  1576. }
  1577. var newParts = [j, 1], dfrom = cmp(p.from, m.from), dto = cmp(p.to, m.to);
  1578. if (dfrom < 0 || !mk.inclusiveLeft && !dfrom) {
  1579. newParts.push({ from: p.from, to: m.from });
  1580. }
  1581. if (dto > 0 || !mk.inclusiveRight && !dto) {
  1582. newParts.push({ from: m.to, to: p.to });
  1583. }
  1584. parts.splice.apply(parts, newParts);
  1585. j += newParts.length - 3;
  1586. }
  1587. }
  1588. return parts;
  1589. }
  1590. function detachMarkedSpans(line) {
  1591. var spans = line.markedSpans;
  1592. if (!spans) {
  1593. return;
  1594. }
  1595. for (var i2 = 0; i2 < spans.length; ++i2) {
  1596. spans[i2].marker.detachLine(line);
  1597. }
  1598. line.markedSpans = null;
  1599. }
  1600. function attachMarkedSpans(line, spans) {
  1601. if (!spans) {
  1602. return;
  1603. }
  1604. for (var i2 = 0; i2 < spans.length; ++i2) {
  1605. spans[i2].marker.attachLine(line);
  1606. }
  1607. line.markedSpans = spans;
  1608. }
  1609. function extraLeft(marker) {
  1610. return marker.inclusiveLeft ? -1 : 0;
  1611. }
  1612. function extraRight(marker) {
  1613. return marker.inclusiveRight ? 1 : 0;
  1614. }
  1615. function compareCollapsedMarkers(a, b) {
  1616. var lenDiff = a.lines.length - b.lines.length;
  1617. if (lenDiff != 0) {
  1618. return lenDiff;
  1619. }
  1620. var aPos = a.find(), bPos = b.find();
  1621. var fromCmp = cmp(aPos.from, bPos.from) || extraLeft(a) - extraLeft(b);
  1622. if (fromCmp) {
  1623. return -fromCmp;
  1624. }
  1625. var toCmp = cmp(aPos.to, bPos.to) || extraRight(a) - extraRight(b);
  1626. if (toCmp) {
  1627. return toCmp;
  1628. }
  1629. return b.id - a.id;
  1630. }
  1631. function collapsedSpanAtSide(line, start) {
  1632. var sps = sawCollapsedSpans && line.markedSpans, found;
  1633. if (sps) {
  1634. for (var sp = void 0, i2 = 0; i2 < sps.length; ++i2) {
  1635. sp = sps[i2];
  1636. if (sp.marker.collapsed && (start ? sp.from : sp.to) == null && (!found || compareCollapsedMarkers(found, sp.marker) < 0)) {
  1637. found = sp.marker;
  1638. }
  1639. }
  1640. }
  1641. return found;
  1642. }
  1643. function collapsedSpanAtStart(line) {
  1644. return collapsedSpanAtSide(line, true);
  1645. }
  1646. function collapsedSpanAtEnd(line) {
  1647. return collapsedSpanAtSide(line, false);
  1648. }
  1649. function collapsedSpanAround(line, ch) {
  1650. var sps = sawCollapsedSpans && line.markedSpans, found;
  1651. if (sps) {
  1652. for (var i2 = 0; i2 < sps.length; ++i2) {
  1653. var sp = sps[i2];
  1654. if (sp.marker.collapsed && (sp.from == null || sp.from < ch) && (sp.to == null || sp.to > ch) && (!found || compareCollapsedMarkers(found, sp.marker) < 0)) {
  1655. found = sp.marker;
  1656. }
  1657. }
  1658. }
  1659. return found;
  1660. }
  1661. function conflictingCollapsedRange(doc2, lineNo2, from, to, marker) {
  1662. var line = getLine(doc2, lineNo2);
  1663. var sps = sawCollapsedSpans && line.markedSpans;
  1664. if (sps) {
  1665. for (var i2 = 0; i2 < sps.length; ++i2) {
  1666. var sp = sps[i2];
  1667. if (!sp.marker.collapsed) {
  1668. continue;
  1669. }
  1670. var found = sp.marker.find(0);
  1671. var fromCmp = cmp(found.from, from) || extraLeft(sp.marker) - extraLeft(marker);
  1672. var toCmp = cmp(found.to, to) || extraRight(sp.marker) - extraRight(marker);
  1673. if (fromCmp >= 0 && toCmp <= 0 || fromCmp <= 0 && toCmp >= 0) {
  1674. continue;
  1675. }
  1676. if (fromCmp <= 0 && (sp.marker.inclusiveRight && marker.inclusiveLeft ? cmp(found.to, from) >= 0 : cmp(found.to, from) > 0) || fromCmp >= 0 && (sp.marker.inclusiveRight && marker.inclusiveLeft ? cmp(found.from, to) <= 0 : cmp(found.from, to) < 0)) {
  1677. return true;
  1678. }
  1679. }
  1680. }
  1681. }
  1682. function visualLine(line) {
  1683. var merged;
  1684. while (merged = collapsedSpanAtStart(line)) {
  1685. line = merged.find(-1, true).line;
  1686. }
  1687. return line;
  1688. }
  1689. function visualLineEnd(line) {
  1690. var merged;
  1691. while (merged = collapsedSpanAtEnd(line)) {
  1692. line = merged.find(1, true).line;
  1693. }
  1694. return line;
  1695. }
  1696. function visualLineContinued(line) {
  1697. var merged, lines;
  1698. while (merged = collapsedSpanAtEnd(line)) {
  1699. line = merged.find(1, true).line;
  1700. (lines || (lines = [])).push(line);
  1701. }
  1702. return lines;
  1703. }
  1704. function visualLineNo(doc2, lineN) {
  1705. var line = getLine(doc2, lineN), vis = visualLine(line);
  1706. if (line == vis) {
  1707. return lineN;
  1708. }
  1709. return lineNo(vis);
  1710. }
  1711. function visualLineEndNo(doc2, lineN) {
  1712. if (lineN > doc2.lastLine()) {
  1713. return lineN;
  1714. }
  1715. var line = getLine(doc2, lineN), merged;
  1716. if (!lineIsHidden(doc2, line)) {
  1717. return lineN;
  1718. }
  1719. while (merged = collapsedSpanAtEnd(line)) {
  1720. line = merged.find(1, true).line;
  1721. }
  1722. return lineNo(line) + 1;
  1723. }
  1724. function lineIsHidden(doc2, line) {
  1725. var sps = sawCollapsedSpans && line.markedSpans;
  1726. if (sps) {
  1727. for (var sp = void 0, i2 = 0; i2 < sps.length; ++i2) {
  1728. sp = sps[i2];
  1729. if (!sp.marker.collapsed) {
  1730. continue;
  1731. }
  1732. if (sp.from == null) {
  1733. return true;
  1734. }
  1735. if (sp.marker.widgetNode) {
  1736. continue;
  1737. }
  1738. if (sp.from == 0 && sp.marker.inclusiveLeft && lineIsHiddenInner(doc2, line, sp)) {
  1739. return true;
  1740. }
  1741. }
  1742. }
  1743. }
  1744. function lineIsHiddenInner(doc2, line, span) {
  1745. if (span.to == null) {
  1746. var end = span.marker.find(1, true);
  1747. return lineIsHiddenInner(doc2, end.line, getMarkedSpanFor(end.line.markedSpans, span.marker));
  1748. }
  1749. if (span.marker.inclusiveRight && span.to == line.text.length) {
  1750. return true;
  1751. }
  1752. for (var sp = void 0, i2 = 0; i2 < line.markedSpans.length; ++i2) {
  1753. sp = line.markedSpans[i2];
  1754. if (sp.marker.collapsed && !sp.marker.widgetNode && sp.from == span.to && (sp.to == null || sp.to != span.from) && (sp.marker.inclusiveLeft || span.marker.inclusiveRight) && lineIsHiddenInner(doc2, line, sp)) {
  1755. return true;
  1756. }
  1757. }
  1758. }
  1759. function heightAtLine(lineObj) {
  1760. lineObj = visualLine(lineObj);
  1761. var h = 0, chunk = lineObj.parent;
  1762. for (var i2 = 0; i2 < chunk.lines.length; ++i2) {
  1763. var line = chunk.lines[i2];
  1764. if (line == lineObj) {
  1765. break;
  1766. } else {
  1767. h += line.height;
  1768. }
  1769. }
  1770. for (var p = chunk.parent; p; chunk = p, p = chunk.parent) {
  1771. for (var i$12 = 0; i$12 < p.children.length; ++i$12) {
  1772. var cur = p.children[i$12];
  1773. if (cur == chunk) {
  1774. break;
  1775. } else {
  1776. h += cur.height;
  1777. }
  1778. }
  1779. }
  1780. return h;
  1781. }
  1782. function lineLength(line) {
  1783. if (line.height == 0) {
  1784. return 0;
  1785. }
  1786. var len = line.text.length, merged, cur = line;
  1787. while (merged = collapsedSpanAtStart(cur)) {
  1788. var found = merged.find(0, true);
  1789. cur = found.from.line;
  1790. len += found.from.ch - found.to.ch;
  1791. }
  1792. cur = line;
  1793. while (merged = collapsedSpanAtEnd(cur)) {
  1794. var found$1 = merged.find(0, true);
  1795. len -= cur.text.length - found$1.from.ch;
  1796. cur = found$1.to.line;
  1797. len += cur.text.length - found$1.to.ch;
  1798. }
  1799. return len;
  1800. }
  1801. function findMaxLine(cm) {
  1802. var d = cm.display, doc2 = cm.doc;
  1803. d.maxLine = getLine(doc2, doc2.first);
  1804. d.maxLineLength = lineLength(d.maxLine);
  1805. d.maxLineChanged = true;
  1806. doc2.iter(function(line) {
  1807. var len = lineLength(line);
  1808. if (len > d.maxLineLength) {
  1809. d.maxLineLength = len;
  1810. d.maxLine = line;
  1811. }
  1812. });
  1813. }
  1814. var Line = function(text, markedSpans, estimateHeight2) {
  1815. this.text = text;
  1816. attachMarkedSpans(this, markedSpans);
  1817. this.height = estimateHeight2 ? estimateHeight2(this) : 1;
  1818. };
  1819. Line.prototype.lineNo = function() {
  1820. return lineNo(this);
  1821. };
  1822. eventMixin(Line);
  1823. function updateLine(line, text, markedSpans, estimateHeight2) {
  1824. line.text = text;
  1825. if (line.stateAfter) {
  1826. line.stateAfter = null;
  1827. }
  1828. if (line.styles) {
  1829. line.styles = null;
  1830. }
  1831. if (line.order != null) {
  1832. line.order = null;
  1833. }
  1834. detachMarkedSpans(line);
  1835. attachMarkedSpans(line, markedSpans);
  1836. var estHeight = estimateHeight2 ? estimateHeight2(line) : 1;
  1837. if (estHeight != line.height) {
  1838. updateLineHeight(line, estHeight);
  1839. }
  1840. }
  1841. function cleanUpLine(line) {
  1842. line.parent = null;
  1843. detachMarkedSpans(line);
  1844. }
  1845. var styleToClassCache = {}, styleToClassCacheWithMode = {};
  1846. function interpretTokenStyle(style, options) {
  1847. if (!style || /^\s*$/.test(style)) {
  1848. return null;
  1849. }
  1850. var cache = options.addModeClass ? styleToClassCacheWithMode : styleToClassCache;
  1851. return cache[style] || (cache[style] = style.replace(/\S+/g, "cm-$&"));
  1852. }
  1853. function buildLineContent(cm, lineView) {
  1854. var content = eltP("span", null, null, webkit ? "padding-right: .1px" : null);
  1855. var builder = {
  1856. pre: eltP("pre", [content], "CodeMirror-line"),
  1857. content,
  1858. col: 0,
  1859. pos: 0,
  1860. cm,
  1861. trailingSpace: false,
  1862. splitSpaces: cm.getOption("lineWrapping")
  1863. };
  1864. lineView.measure = {};
  1865. for (var i2 = 0; i2 <= (lineView.rest ? lineView.rest.length : 0); i2++) {
  1866. var line = i2 ? lineView.rest[i2 - 1] : lineView.line, order = void 0;
  1867. builder.pos = 0;
  1868. builder.addToken = buildToken;
  1869. if (hasBadBidiRects(cm.display.measure) && (order = getOrder(line, cm.doc.direction))) {
  1870. builder.addToken = buildTokenBadBidi(builder.addToken, order);
  1871. }
  1872. builder.map = [];
  1873. var allowFrontierUpdate = lineView != cm.display.externalMeasured && lineNo(line);
  1874. insertLineContent(line, builder, getLineStyles(cm, line, allowFrontierUpdate));
  1875. if (line.styleClasses) {
  1876. if (line.styleClasses.bgClass) {
  1877. builder.bgClass = joinClasses(line.styleClasses.bgClass, builder.bgClass || "");
  1878. }
  1879. if (line.styleClasses.textClass) {
  1880. builder.textClass = joinClasses(line.styleClasses.textClass, builder.textClass || "");
  1881. }
  1882. }
  1883. if (builder.map.length == 0) {
  1884. builder.map.push(0, 0, builder.content.appendChild(zeroWidthElement(cm.display.measure)));
  1885. }
  1886. if (i2 == 0) {
  1887. lineView.measure.map = builder.map;
  1888. lineView.measure.cache = {};
  1889. } else {
  1890. (lineView.measure.maps || (lineView.measure.maps = [])).push(builder.map);
  1891. (lineView.measure.caches || (lineView.measure.caches = [])).push({});
  1892. }
  1893. }
  1894. if (webkit) {
  1895. var last = builder.content.lastChild;
  1896. if (/\bcm-tab\b/.test(last.className) || last.querySelector && last.querySelector(".cm-tab")) {
  1897. builder.content.className = "cm-tab-wrap-hack";
  1898. }
  1899. }
  1900. signal(cm, "renderLine", cm, lineView.line, builder.pre);
  1901. if (builder.pre.className) {
  1902. builder.textClass = joinClasses(builder.pre.className, builder.textClass || "");
  1903. }
  1904. return builder;
  1905. }
  1906. function defaultSpecialCharPlaceholder(ch) {
  1907. var token = elt("span", "•", "cm-invalidchar");
  1908. token.title = "\\u" + ch.charCodeAt(0).toString(16);
  1909. token.setAttribute("aria-label", token.title);
  1910. return token;
  1911. }
  1912. function buildToken(builder, text, style, startStyle, endStyle, css, attributes) {
  1913. if (!text) {
  1914. return;
  1915. }
  1916. var displayText = builder.splitSpaces ? splitSpaces(text, builder.trailingSpace) : text;
  1917. var special = builder.cm.state.specialChars, mustWrap = false;
  1918. var content;
  1919. if (!special.test(text)) {
  1920. builder.col += text.length;
  1921. content = document.createTextNode(displayText);
  1922. builder.map.push(builder.pos, builder.pos + text.length, content);
  1923. if (ie && ie_version < 9) {
  1924. mustWrap = true;
  1925. }
  1926. builder.pos += text.length;
  1927. } else {
  1928. content = document.createDocumentFragment();
  1929. var pos = 0;
  1930. while (true) {
  1931. special.lastIndex = pos;
  1932. var m = special.exec(text);
  1933. var skipped = m ? m.index - pos : text.length - pos;
  1934. if (skipped) {
  1935. var txt = document.createTextNode(displayText.slice(pos, pos + skipped));
  1936. if (ie && ie_version < 9) {
  1937. content.appendChild(elt("span", [txt]));
  1938. } else {
  1939. content.appendChild(txt);
  1940. }
  1941. builder.map.push(builder.pos, builder.pos + skipped, txt);
  1942. builder.col += skipped;
  1943. builder.pos += skipped;
  1944. }
  1945. if (!m) {
  1946. break;
  1947. }
  1948. pos += skipped + 1;
  1949. var txt$1 = void 0;
  1950. if (m[0] == " ") {
  1951. var tabSize = builder.cm.options.tabSize, tabWidth = tabSize - builder.col % tabSize;
  1952. txt$1 = content.appendChild(elt("span", spaceStr(tabWidth), "cm-tab"));
  1953. txt$1.setAttribute("role", "presentation");
  1954. txt$1.setAttribute("cm-text", " ");
  1955. builder.col += tabWidth;
  1956. } else if (m[0] == "\r" || m[0] == "\n") {
  1957. txt$1 = content.appendChild(elt("span", m[0] == "\r" ? "␍" : "␤", "cm-invalidchar"));
  1958. txt$1.setAttribute("cm-text", m[0]);
  1959. builder.col += 1;
  1960. } else {
  1961. txt$1 = builder.cm.options.specialCharPlaceholder(m[0]);
  1962. txt$1.setAttribute("cm-text", m[0]);
  1963. if (ie && ie_version < 9) {
  1964. content.appendChild(elt("span", [txt$1]));
  1965. } else {
  1966. content.appendChild(txt$1);
  1967. }
  1968. builder.col += 1;
  1969. }
  1970. builder.map.push(builder.pos, builder.pos + 1, txt$1);
  1971. builder.pos++;
  1972. }
  1973. }
  1974. builder.trailingSpace = displayText.charCodeAt(text.length - 1) == 32;
  1975. if (style || startStyle || endStyle || mustWrap || css || attributes) {
  1976. var fullStyle = style || "";
  1977. if (startStyle) {
  1978. fullStyle += startStyle;
  1979. }
  1980. if (endStyle) {
  1981. fullStyle += endStyle;
  1982. }
  1983. var token = elt("span", [content], fullStyle, css);
  1984. if (attributes) {
  1985. for (var attr in attributes) {
  1986. if (attributes.hasOwnProperty(attr) && attr != "style" && attr != "class") {
  1987. token.setAttribute(attr, attributes[attr]);
  1988. }
  1989. }
  1990. }
  1991. return builder.content.appendChild(token);
  1992. }
  1993. builder.content.appendChild(content);
  1994. }
  1995. function splitSpaces(text, trailingBefore) {
  1996. if (text.length > 1 && !/ /.test(text)) {
  1997. return text;
  1998. }
  1999. var spaceBefore = trailingBefore, result = "";
  2000. for (var i2 = 0; i2 < text.length; i2++) {
  2001. var ch = text.charAt(i2);
  2002. if (ch == " " && spaceBefore && (i2 == text.length - 1 || text.charCodeAt(i2 + 1) == 32)) {
  2003. ch = " ";
  2004. }
  2005. result += ch;
  2006. spaceBefore = ch == " ";
  2007. }
  2008. return result;
  2009. }
  2010. function buildTokenBadBidi(inner, order) {
  2011. return function(builder, text, style, startStyle, endStyle, css, attributes) {
  2012. style = style ? style + " cm-force-border" : "cm-force-border";
  2013. var start = builder.pos, end = start + text.length;
  2014. for (; ; ) {
  2015. var part = void 0;
  2016. for (var i2 = 0; i2 < order.length; i2++) {
  2017. part = order[i2];
  2018. if (part.to > start && part.from <= start) {
  2019. break;
  2020. }
  2021. }
  2022. if (part.to >= end) {
  2023. return inner(builder, text, style, startStyle, endStyle, css, attributes);
  2024. }
  2025. inner(builder, text.slice(0, part.to - start), style, startStyle, null, css, attributes);
  2026. startStyle = null;
  2027. text = text.slice(part.to - start);
  2028. start = part.to;
  2029. }
  2030. };
  2031. }
  2032. function buildCollapsedSpan(builder, size, marker, ignoreWidget) {
  2033. var widget = !ignoreWidget && marker.widgetNode;
  2034. if (widget) {
  2035. builder.map.push(builder.pos, builder.pos + size, widget);
  2036. }
  2037. if (!ignoreWidget && builder.cm.display.input.needsContentAttribute) {
  2038. if (!widget) {
  2039. widget = builder.content.appendChild(document.createElement("span"));
  2040. }
  2041. widget.setAttribute("cm-marker", marker.id);
  2042. }
  2043. if (widget) {
  2044. builder.cm.display.input.setUneditable(widget);
  2045. builder.content.appendChild(widget);
  2046. }
  2047. builder.pos += size;
  2048. builder.trailingSpace = false;
  2049. }
  2050. function insertLineContent(line, builder, styles) {
  2051. var spans = line.markedSpans, allText = line.text, at = 0;
  2052. if (!spans) {
  2053. for (var i$12 = 1; i$12 < styles.length; i$12 += 2) {
  2054. builder.addToken(builder, allText.slice(at, at = styles[i$12]), interpretTokenStyle(styles[i$12 + 1], builder.cm.options));
  2055. }
  2056. return;
  2057. }
  2058. var len = allText.length, pos = 0, i2 = 1, text = "", style, css;
  2059. var nextChange = 0, spanStyle, spanEndStyle, spanStartStyle, collapsed, attributes;
  2060. for (; ; ) {
  2061. if (nextChange == pos) {
  2062. spanStyle = spanEndStyle = spanStartStyle = css = "";
  2063. attributes = null;
  2064. collapsed = null;
  2065. nextChange = Infinity;
  2066. var foundBookmarks = [], endStyles = void 0;
  2067. for (var j = 0; j < spans.length; ++j) {
  2068. var sp = spans[j], m = sp.marker;
  2069. if (m.type == "bookmark" && sp.from == pos && m.widgetNode) {
  2070. foundBookmarks.push(m);
  2071. } else if (sp.from <= pos && (sp.to == null || sp.to > pos || m.collapsed && sp.to == pos && sp.from == pos)) {
  2072. if (sp.to != null && sp.to != pos && nextChange > sp.to) {
  2073. nextChange = sp.to;
  2074. spanEndStyle = "";
  2075. }
  2076. if (m.className) {
  2077. spanStyle += " " + m.className;
  2078. }
  2079. if (m.css) {
  2080. css = (css ? css + ";" : "") + m.css;
  2081. }
  2082. if (m.startStyle && sp.from == pos) {
  2083. spanStartStyle += " " + m.startStyle;
  2084. }
  2085. if (m.endStyle && sp.to == nextChange) {
  2086. (endStyles || (endStyles = [])).push(m.endStyle, sp.to);
  2087. }
  2088. if (m.title) {
  2089. (attributes || (attributes = {})).title = m.title;
  2090. }
  2091. if (m.attributes) {
  2092. for (var attr in m.attributes) {
  2093. (attributes || (attributes = {}))[attr] = m.attributes[attr];
  2094. }
  2095. }
  2096. if (m.collapsed && (!collapsed || compareCollapsedMarkers(collapsed.marker, m) < 0)) {
  2097. collapsed = sp;
  2098. }
  2099. } else if (sp.from > pos && nextChange > sp.from) {
  2100. nextChange = sp.from;
  2101. }
  2102. }
  2103. if (endStyles) {
  2104. for (var j$1 = 0; j$1 < endStyles.length; j$1 += 2) {
  2105. if (endStyles[j$1 + 1] == nextChange) {
  2106. spanEndStyle += " " + endStyles[j$1];
  2107. }
  2108. }
  2109. }
  2110. if (!collapsed || collapsed.from == pos) {
  2111. for (var j$2 = 0; j$2 < foundBookmarks.length; ++j$2) {
  2112. buildCollapsedSpan(builder, 0, foundBookmarks[j$2]);
  2113. }
  2114. }
  2115. if (collapsed && (collapsed.from || 0) == pos) {
  2116. buildCollapsedSpan(
  2117. builder,
  2118. (collapsed.to == null ? len + 1 : collapsed.to) - pos,
  2119. collapsed.marker,
  2120. collapsed.from == null
  2121. );
  2122. if (collapsed.to == null) {
  2123. return;
  2124. }
  2125. if (collapsed.to == pos) {
  2126. collapsed = false;
  2127. }
  2128. }
  2129. }
  2130. if (pos >= len) {
  2131. break;
  2132. }
  2133. var upto = Math.min(len, nextChange);
  2134. while (true) {
  2135. if (text) {
  2136. var end = pos + text.length;
  2137. if (!collapsed) {
  2138. var tokenText = end > upto ? text.slice(0, upto - pos) : text;
  2139. builder.addToken(
  2140. builder,
  2141. tokenText,
  2142. style ? style + spanStyle : spanStyle,
  2143. spanStartStyle,
  2144. pos + tokenText.length == nextChange ? spanEndStyle : "",
  2145. css,
  2146. attributes
  2147. );
  2148. }
  2149. if (end >= upto) {
  2150. text = text.slice(upto - pos);
  2151. pos = upto;
  2152. break;
  2153. }
  2154. pos = end;
  2155. spanStartStyle = "";
  2156. }
  2157. text = allText.slice(at, at = styles[i2++]);
  2158. style = interpretTokenStyle(styles[i2++], builder.cm.options);
  2159. }
  2160. }
  2161. }
  2162. function LineView(doc2, line, lineN) {
  2163. this.line = line;
  2164. this.rest = visualLineContinued(line);
  2165. this.size = this.rest ? lineNo(lst(this.rest)) - lineN + 1 : 1;
  2166. this.node = this.text = null;
  2167. this.hidden = lineIsHidden(doc2, line);
  2168. }
  2169. function buildViewArray(cm, from, to) {
  2170. var array = [], nextPos;
  2171. for (var pos = from; pos < to; pos = nextPos) {
  2172. var view = new LineView(cm.doc, getLine(cm.doc, pos), pos);
  2173. nextPos = pos + view.size;
  2174. array.push(view);
  2175. }
  2176. return array;
  2177. }
  2178. var operationGroup = null;
  2179. function pushOperation(op) {
  2180. if (operationGroup) {
  2181. operationGroup.ops.push(op);
  2182. } else {
  2183. op.ownsGroup = operationGroup = {
  2184. ops: [op],
  2185. delayedCallbacks: []
  2186. };
  2187. }
  2188. }
  2189. function fireCallbacksForOps(group) {
  2190. var callbacks = group.delayedCallbacks, i2 = 0;
  2191. do {
  2192. for (; i2 < callbacks.length; i2++) {
  2193. callbacks[i2].call(null);
  2194. }
  2195. for (var j = 0; j < group.ops.length; j++) {
  2196. var op = group.ops[j];
  2197. if (op.cursorActivityHandlers) {
  2198. while (op.cursorActivityCalled < op.cursorActivityHandlers.length) {
  2199. op.cursorActivityHandlers[op.cursorActivityCalled++].call(null, op.cm);
  2200. }
  2201. }
  2202. }
  2203. } while (i2 < callbacks.length);
  2204. }
  2205. function finishOperation(op, endCb) {
  2206. var group = op.ownsGroup;
  2207. if (!group) {
  2208. return;
  2209. }
  2210. try {
  2211. fireCallbacksForOps(group);
  2212. } finally {
  2213. operationGroup = null;
  2214. endCb(group);
  2215. }
  2216. }
  2217. var orphanDelayedCallbacks = null;
  2218. function signalLater(emitter, type) {
  2219. var arr = getHandlers(emitter, type);
  2220. if (!arr.length) {
  2221. return;
  2222. }
  2223. var args = Array.prototype.slice.call(arguments, 2), list;
  2224. if (operationGroup) {
  2225. list = operationGroup.delayedCallbacks;
  2226. } else if (orphanDelayedCallbacks) {
  2227. list = orphanDelayedCallbacks;
  2228. } else {
  2229. list = orphanDelayedCallbacks = [];
  2230. setTimeout(fireOrphanDelayed, 0);
  2231. }
  2232. var loop = function(i3) {
  2233. list.push(function() {
  2234. return arr[i3].apply(null, args);
  2235. });
  2236. };
  2237. for (var i2 = 0; i2 < arr.length; ++i2)
  2238. loop(i2);
  2239. }
  2240. function fireOrphanDelayed() {
  2241. var delayed = orphanDelayedCallbacks;
  2242. orphanDelayedCallbacks = null;
  2243. for (var i2 = 0; i2 < delayed.length; ++i2) {
  2244. delayed[i2]();
  2245. }
  2246. }
  2247. function updateLineForChanges(cm, lineView, lineN, dims) {
  2248. for (var j = 0; j < lineView.changes.length; j++) {
  2249. var type = lineView.changes[j];
  2250. if (type == "text") {
  2251. updateLineText(cm, lineView);
  2252. } else if (type == "gutter") {
  2253. updateLineGutter(cm, lineView, lineN, dims);
  2254. } else if (type == "class") {
  2255. updateLineClasses(cm, lineView);
  2256. } else if (type == "widget") {
  2257. updateLineWidgets(cm, lineView, dims);
  2258. }
  2259. }
  2260. lineView.changes = null;
  2261. }
  2262. function ensureLineWrapped(lineView) {
  2263. if (lineView.node == lineView.text) {
  2264. lineView.node = elt("div", null, null, "position: relative");
  2265. if (lineView.text.parentNode) {
  2266. lineView.text.parentNode.replaceChild(lineView.node, lineView.text);
  2267. }
  2268. lineView.node.appendChild(lineView.text);
  2269. if (ie && ie_version < 8) {
  2270. lineView.node.style.zIndex = 2;
  2271. }
  2272. }
  2273. return lineView.node;
  2274. }
  2275. function updateLineBackground(cm, lineView) {
  2276. var cls = lineView.bgClass ? lineView.bgClass + " " + (lineView.line.bgClass || "") : lineView.line.bgClass;
  2277. if (cls) {
  2278. cls += " CodeMirror-linebackground";
  2279. }
  2280. if (lineView.background) {
  2281. if (cls) {
  2282. lineView.background.className = cls;
  2283. } else {
  2284. lineView.background.parentNode.removeChild(lineView.background);
  2285. lineView.background = null;
  2286. }
  2287. } else if (cls) {
  2288. var wrap = ensureLineWrapped(lineView);
  2289. lineView.background = wrap.insertBefore(elt("div", null, cls), wrap.firstChild);
  2290. cm.display.input.setUneditable(lineView.background);
  2291. }
  2292. }
  2293. function getLineContent(cm, lineView) {
  2294. var ext = cm.display.externalMeasured;
  2295. if (ext && ext.line == lineView.line) {
  2296. cm.display.externalMeasured = null;
  2297. lineView.measure = ext.measure;
  2298. return ext.built;
  2299. }
  2300. return buildLineContent(cm, lineView);
  2301. }
  2302. function updateLineText(cm, lineView) {
  2303. var cls = lineView.text.className;
  2304. var built = getLineContent(cm, lineView);
  2305. if (lineView.text == lineView.node) {
  2306. lineView.node = built.pre;
  2307. }
  2308. lineView.text.parentNode.replaceChild(built.pre, lineView.text);
  2309. lineView.text = built.pre;
  2310. if (built.bgClass != lineView.bgClass || built.textClass != lineView.textClass) {
  2311. lineView.bgClass = built.bgClass;
  2312. lineView.textClass = built.textClass;
  2313. updateLineClasses(cm, lineView);
  2314. } else if (cls) {
  2315. lineView.text.className = cls;
  2316. }
  2317. }
  2318. function updateLineClasses(cm, lineView) {
  2319. updateLineBackground(cm, lineView);
  2320. if (lineView.line.wrapClass) {
  2321. ensureLineWrapped(lineView).className = lineView.line.wrapClass;
  2322. } else if (lineView.node != lineView.text) {
  2323. lineView.node.className = "";
  2324. }
  2325. var textClass = lineView.textClass ? lineView.textClass + " " + (lineView.line.textClass || "") : lineView.line.textClass;
  2326. lineView.text.className = textClass || "";
  2327. }
  2328. function updateLineGutter(cm, lineView, lineN, dims) {
  2329. if (lineView.gutter) {
  2330. lineView.node.removeChild(lineView.gutter);
  2331. lineView.gutter = null;
  2332. }
  2333. if (lineView.gutterBackground) {
  2334. lineView.node.removeChild(lineView.gutterBackground);
  2335. lineView.gutterBackground = null;
  2336. }
  2337. if (lineView.line.gutterClass) {
  2338. var wrap = ensureLineWrapped(lineView);
  2339. lineView.gutterBackground = elt(
  2340. "div",
  2341. null,
  2342. "CodeMirror-gutter-background " + lineView.line.gutterClass,
  2343. "left: " + (cm.options.fixedGutter ? dims.fixedPos : -dims.gutterTotalWidth) + "px; width: " + dims.gutterTotalWidth + "px"
  2344. );
  2345. cm.display.input.setUneditable(lineView.gutterBackground);
  2346. wrap.insertBefore(lineView.gutterBackground, lineView.text);
  2347. }
  2348. var markers = lineView.line.gutterMarkers;
  2349. if (cm.options.lineNumbers || markers) {
  2350. var wrap$1 = ensureLineWrapped(lineView);
  2351. var gutterWrap = lineView.gutter = elt("div", null, "CodeMirror-gutter-wrapper", "left: " + (cm.options.fixedGutter ? dims.fixedPos : -dims.gutterTotalWidth) + "px");
  2352. gutterWrap.setAttribute("aria-hidden", "true");
  2353. cm.display.input.setUneditable(gutterWrap);
  2354. wrap$1.insertBefore(gutterWrap, lineView.text);
  2355. if (lineView.line.gutterClass) {
  2356. gutterWrap.className += " " + lineView.line.gutterClass;
  2357. }
  2358. if (cm.options.lineNumbers && (!markers || !markers["CodeMirror-linenumbers"])) {
  2359. lineView.lineNumber = gutterWrap.appendChild(
  2360. elt(
  2361. "div",
  2362. lineNumberFor(cm.options, lineN),
  2363. "CodeMirror-linenumber CodeMirror-gutter-elt",
  2364. "left: " + dims.gutterLeft["CodeMirror-linenumbers"] + "px; width: " + cm.display.lineNumInnerWidth + "px"
  2365. )
  2366. );
  2367. }
  2368. if (markers) {
  2369. for (var k = 0; k < cm.display.gutterSpecs.length; ++k) {
  2370. var id = cm.display.gutterSpecs[k].className, found = markers.hasOwnProperty(id) && markers[id];
  2371. if (found) {
  2372. gutterWrap.appendChild(elt(
  2373. "div",
  2374. [found],
  2375. "CodeMirror-gutter-elt",
  2376. "left: " + dims.gutterLeft[id] + "px; width: " + dims.gutterWidth[id] + "px"
  2377. ));
  2378. }
  2379. }
  2380. }
  2381. }
  2382. }
  2383. function updateLineWidgets(cm, lineView, dims) {
  2384. if (lineView.alignable) {
  2385. lineView.alignable = null;
  2386. }
  2387. var isWidget = classTest("CodeMirror-linewidget");
  2388. for (var node = lineView.node.firstChild, next = void 0; node; node = next) {
  2389. next = node.nextSibling;
  2390. if (isWidget.test(node.className)) {
  2391. lineView.node.removeChild(node);
  2392. }
  2393. }
  2394. insertLineWidgets(cm, lineView, dims);
  2395. }
  2396. function buildLineElement(cm, lineView, lineN, dims) {
  2397. var built = getLineContent(cm, lineView);
  2398. lineView.text = lineView.node = built.pre;
  2399. if (built.bgClass) {
  2400. lineView.bgClass = built.bgClass;
  2401. }
  2402. if (built.textClass) {
  2403. lineView.textClass = built.textClass;
  2404. }
  2405. updateLineClasses(cm, lineView);
  2406. updateLineGutter(cm, lineView, lineN, dims);
  2407. insertLineWidgets(cm, lineView, dims);
  2408. return lineView.node;
  2409. }
  2410. function insertLineWidgets(cm, lineView, dims) {
  2411. insertLineWidgetsFor(cm, lineView.line, lineView, dims, true);
  2412. if (lineView.rest) {
  2413. for (var i2 = 0; i2 < lineView.rest.length; i2++) {
  2414. insertLineWidgetsFor(cm, lineView.rest[i2], lineView, dims, false);
  2415. }
  2416. }
  2417. }
  2418. function insertLineWidgetsFor(cm, line, lineView, dims, allowAbove) {
  2419. if (!line.widgets) {
  2420. return;
  2421. }
  2422. var wrap = ensureLineWrapped(lineView);
  2423. for (var i2 = 0, ws = line.widgets; i2 < ws.length; ++i2) {
  2424. var widget = ws[i2], node = elt("div", [widget.node], "CodeMirror-linewidget" + (widget.className ? " " + widget.className : ""));
  2425. if (!widget.handleMouseEvents) {
  2426. node.setAttribute("cm-ignore-events", "true");
  2427. }
  2428. positionLineWidget(widget, node, lineView, dims);
  2429. cm.display.input.setUneditable(node);
  2430. if (allowAbove && widget.above) {
  2431. wrap.insertBefore(node, lineView.gutter || lineView.text);
  2432. } else {
  2433. wrap.appendChild(node);
  2434. }
  2435. signalLater(widget, "redraw");
  2436. }
  2437. }
  2438. function positionLineWidget(widget, node, lineView, dims) {
  2439. if (widget.noHScroll) {
  2440. (lineView.alignable || (lineView.alignable = [])).push(node);
  2441. var width = dims.wrapperWidth;
  2442. node.style.left = dims.fixedPos + "px";
  2443. if (!widget.coverGutter) {
  2444. width -= dims.gutterTotalWidth;
  2445. node.style.paddingLeft = dims.gutterTotalWidth + "px";
  2446. }
  2447. node.style.width = width + "px";
  2448. }
  2449. if (widget.coverGutter) {
  2450. node.style.zIndex = 5;
  2451. node.style.position = "relative";
  2452. if (!widget.noHScroll) {
  2453. node.style.marginLeft = -dims.gutterTotalWidth + "px";
  2454. }
  2455. }
  2456. }
  2457. function widgetHeight(widget) {
  2458. if (widget.height != null) {
  2459. return widget.height;
  2460. }
  2461. var cm = widget.doc.cm;
  2462. if (!cm) {
  2463. return 0;
  2464. }
  2465. if (!contains(document.body, widget.node)) {
  2466. var parentStyle = "position: relative;";
  2467. if (widget.coverGutter) {
  2468. parentStyle += "margin-left: -" + cm.display.gutters.offsetWidth + "px;";
  2469. }
  2470. if (widget.noHScroll) {
  2471. parentStyle += "width: " + cm.display.wrapper.clientWidth + "px;";
  2472. }
  2473. removeChildrenAndAdd(cm.display.measure, elt("div", [widget.node], null, parentStyle));
  2474. }
  2475. return widget.height = widget.node.parentNode.offsetHeight;
  2476. }
  2477. function eventInWidget(display, e) {
  2478. for (var n = e_target(e); n != display.wrapper; n = n.parentNode) {
  2479. if (!n || n.nodeType == 1 && n.getAttribute("cm-ignore-events") == "true" || n.parentNode == display.sizer && n != display.mover) {
  2480. return true;
  2481. }
  2482. }
  2483. }
  2484. function paddingTop(display) {
  2485. return display.lineSpace.offsetTop;
  2486. }
  2487. function paddingVert(display) {
  2488. return display.mover.offsetHeight - display.lineSpace.offsetHeight;
  2489. }
  2490. function paddingH(display) {
  2491. if (display.cachedPaddingH) {
  2492. return display.cachedPaddingH;
  2493. }
  2494. var e = removeChildrenAndAdd(display.measure, elt("pre", "x", "CodeMirror-line-like"));
  2495. var style = window.getComputedStyle ? window.getComputedStyle(e) : e.currentStyle;
  2496. var data = { left: parseInt(style.paddingLeft), right: parseInt(style.paddingRight) };
  2497. if (!isNaN(data.left) && !isNaN(data.right)) {
  2498. display.cachedPaddingH = data;
  2499. }
  2500. return data;
  2501. }
  2502. function scrollGap(cm) {
  2503. return scrollerGap - cm.display.nativeBarWidth;
  2504. }
  2505. function displayWidth(cm) {
  2506. return cm.display.scroller.clientWidth - scrollGap(cm) - cm.display.barWidth;
  2507. }
  2508. function displayHeight(cm) {
  2509. return cm.display.scroller.clientHeight - scrollGap(cm) - cm.display.barHeight;
  2510. }
  2511. function ensureLineHeights(cm, lineView, rect) {
  2512. var wrapping = cm.options.lineWrapping;
  2513. var curWidth = wrapping && displayWidth(cm);
  2514. if (!lineView.measure.heights || wrapping && lineView.measure.width != curWidth) {
  2515. var heights = lineView.measure.heights = [];
  2516. if (wrapping) {
  2517. lineView.measure.width = curWidth;
  2518. var rects = lineView.text.firstChild.getClientRects();
  2519. for (var i2 = 0; i2 < rects.length - 1; i2++) {
  2520. var cur = rects[i2], next = rects[i2 + 1];
  2521. if (Math.abs(cur.bottom - next.bottom) > 2) {
  2522. heights.push((cur.bottom + next.top) / 2 - rect.top);
  2523. }
  2524. }
  2525. }
  2526. heights.push(rect.bottom - rect.top);
  2527. }
  2528. }
  2529. function mapFromLineView(lineView, line, lineN) {
  2530. if (lineView.line == line) {
  2531. return { map: lineView.measure.map, cache: lineView.measure.cache };
  2532. }
  2533. if (lineView.rest) {
  2534. for (var i2 = 0; i2 < lineView.rest.length; i2++) {
  2535. if (lineView.rest[i2] == line) {
  2536. return { map: lineView.measure.maps[i2], cache: lineView.measure.caches[i2] };
  2537. }
  2538. }
  2539. for (var i$12 = 0; i$12 < lineView.rest.length; i$12++) {
  2540. if (lineNo(lineView.rest[i$12]) > lineN) {
  2541. return { map: lineView.measure.maps[i$12], cache: lineView.measure.caches[i$12], before: true };
  2542. }
  2543. }
  2544. }
  2545. }
  2546. function updateExternalMeasurement(cm, line) {
  2547. line = visualLine(line);
  2548. var lineN = lineNo(line);
  2549. var view = cm.display.externalMeasured = new LineView(cm.doc, line, lineN);
  2550. view.lineN = lineN;
  2551. var built = view.built = buildLineContent(cm, view);
  2552. view.text = built.pre;
  2553. removeChildrenAndAdd(cm.display.lineMeasure, built.pre);
  2554. return view;
  2555. }
  2556. function measureChar(cm, line, ch, bias) {
  2557. return measureCharPrepared(cm, prepareMeasureForLine(cm, line), ch, bias);
  2558. }
  2559. function findViewForLine(cm, lineN) {
  2560. if (lineN >= cm.display.viewFrom && lineN < cm.display.viewTo) {
  2561. return cm.display.view[findViewIndex(cm, lineN)];
  2562. }
  2563. var ext = cm.display.externalMeasured;
  2564. if (ext && lineN >= ext.lineN && lineN < ext.lineN + ext.size) {
  2565. return ext;
  2566. }
  2567. }
  2568. function prepareMeasureForLine(cm, line) {
  2569. var lineN = lineNo(line);
  2570. var view = findViewForLine(cm, lineN);
  2571. if (view && !view.text) {
  2572. view = null;
  2573. } else if (view && view.changes) {
  2574. updateLineForChanges(cm, view, lineN, getDimensions(cm));
  2575. cm.curOp.forceUpdate = true;
  2576. }
  2577. if (!view) {
  2578. view = updateExternalMeasurement(cm, line);
  2579. }
  2580. var info = mapFromLineView(view, line, lineN);
  2581. return {
  2582. line,
  2583. view,
  2584. rect: null,
  2585. map: info.map,
  2586. cache: info.cache,
  2587. before: info.before,
  2588. hasHeights: false
  2589. };
  2590. }
  2591. function measureCharPrepared(cm, prepared, ch, bias, varHeight) {
  2592. if (prepared.before) {
  2593. ch = -1;
  2594. }
  2595. var key = ch + (bias || ""), found;
  2596. if (prepared.cache.hasOwnProperty(key)) {
  2597. found = prepared.cache[key];
  2598. } else {
  2599. if (!prepared.rect) {
  2600. prepared.rect = prepared.view.text.getBoundingClientRect();
  2601. }
  2602. if (!prepared.hasHeights) {
  2603. ensureLineHeights(cm, prepared.view, prepared.rect);
  2604. prepared.hasHeights = true;
  2605. }
  2606. found = measureCharInner(cm, prepared, ch, bias);
  2607. if (!found.bogus) {
  2608. prepared.cache[key] = found;
  2609. }
  2610. }
  2611. return {
  2612. left: found.left,
  2613. right: found.right,
  2614. top: varHeight ? found.rtop : found.top,
  2615. bottom: varHeight ? found.rbottom : found.bottom
  2616. };
  2617. }
  2618. var nullRect = { left: 0, right: 0, top: 0, bottom: 0 };
  2619. function nodeAndOffsetInLineMap(map2, ch, bias) {
  2620. var node, start, end, collapse, mStart, mEnd;
  2621. for (var i2 = 0; i2 < map2.length; i2 += 3) {
  2622. mStart = map2[i2];
  2623. mEnd = map2[i2 + 1];
  2624. if (ch < mStart) {
  2625. start = 0;
  2626. end = 1;
  2627. collapse = "left";
  2628. } else if (ch < mEnd) {
  2629. start = ch - mStart;
  2630. end = start + 1;
  2631. } else if (i2 == map2.length - 3 || ch == mEnd && map2[i2 + 3] > ch) {
  2632. end = mEnd - mStart;
  2633. start = end - 1;
  2634. if (ch >= mEnd) {
  2635. collapse = "right";
  2636. }
  2637. }
  2638. if (start != null) {
  2639. node = map2[i2 + 2];
  2640. if (mStart == mEnd && bias == (node.insertLeft ? "left" : "right")) {
  2641. collapse = bias;
  2642. }
  2643. if (bias == "left" && start == 0) {
  2644. while (i2 && map2[i2 - 2] == map2[i2 - 3] && map2[i2 - 1].insertLeft) {
  2645. node = map2[(i2 -= 3) + 2];
  2646. collapse = "left";
  2647. }
  2648. }
  2649. if (bias == "right" && start == mEnd - mStart) {
  2650. while (i2 < map2.length - 3 && map2[i2 + 3] == map2[i2 + 4] && !map2[i2 + 5].insertLeft) {
  2651. node = map2[(i2 += 3) + 2];
  2652. collapse = "right";
  2653. }
  2654. }
  2655. break;
  2656. }
  2657. }
  2658. return { node, start, end, collapse, coverStart: mStart, coverEnd: mEnd };
  2659. }
  2660. function getUsefulRect(rects, bias) {
  2661. var rect = nullRect;
  2662. if (bias == "left") {
  2663. for (var i2 = 0; i2 < rects.length; i2++) {
  2664. if ((rect = rects[i2]).left != rect.right) {
  2665. break;
  2666. }
  2667. }
  2668. } else {
  2669. for (var i$12 = rects.length - 1; i$12 >= 0; i$12--) {
  2670. if ((rect = rects[i$12]).left != rect.right) {
  2671. break;
  2672. }
  2673. }
  2674. }
  2675. return rect;
  2676. }
  2677. function measureCharInner(cm, prepared, ch, bias) {
  2678. var place = nodeAndOffsetInLineMap(prepared.map, ch, bias);
  2679. var node = place.node, start = place.start, end = place.end, collapse = place.collapse;
  2680. var rect;
  2681. if (node.nodeType == 3) {
  2682. for (var i$12 = 0; i$12 < 4; i$12++) {
  2683. while (start && isExtendingChar(prepared.line.text.charAt(place.coverStart + start))) {
  2684. --start;
  2685. }
  2686. while (place.coverStart + end < place.coverEnd && isExtendingChar(prepared.line.text.charAt(place.coverStart + end))) {
  2687. ++end;
  2688. }
  2689. if (ie && ie_version < 9 && start == 0 && end == place.coverEnd - place.coverStart) {
  2690. rect = node.parentNode.getBoundingClientRect();
  2691. } else {
  2692. rect = getUsefulRect(range(node, start, end).getClientRects(), bias);
  2693. }
  2694. if (rect.left || rect.right || start == 0) {
  2695. break;
  2696. }
  2697. end = start;
  2698. start = start - 1;
  2699. collapse = "right";
  2700. }
  2701. if (ie && ie_version < 11) {
  2702. rect = maybeUpdateRectForZooming(cm.display.measure, rect);
  2703. }
  2704. } else {
  2705. if (start > 0) {
  2706. collapse = bias = "right";
  2707. }
  2708. var rects;
  2709. if (cm.options.lineWrapping && (rects = node.getClientRects()).length > 1) {
  2710. rect = rects[bias == "right" ? rects.length - 1 : 0];
  2711. } else {
  2712. rect = node.getBoundingClientRect();
  2713. }
  2714. }
  2715. if (ie && ie_version < 9 && !start && (!rect || !rect.left && !rect.right)) {
  2716. var rSpan = node.parentNode.getClientRects()[0];
  2717. if (rSpan) {
  2718. rect = { left: rSpan.left, right: rSpan.left + charWidth(cm.display), top: rSpan.top, bottom: rSpan.bottom };
  2719. } else {
  2720. rect = nullRect;
  2721. }
  2722. }
  2723. var rtop = rect.top - prepared.rect.top, rbot = rect.bottom - prepared.rect.top;
  2724. var mid = (rtop + rbot) / 2;
  2725. var heights = prepared.view.measure.heights;
  2726. var i2 = 0;
  2727. for (; i2 < heights.length - 1; i2++) {
  2728. if (mid < heights[i2]) {
  2729. break;
  2730. }
  2731. }
  2732. var top = i2 ? heights[i2 - 1] : 0, bot = heights[i2];
  2733. var result = {
  2734. left: (collapse == "right" ? rect.right : rect.left) - prepared.rect.left,
  2735. right: (collapse == "left" ? rect.left : rect.right) - prepared.rect.left,
  2736. top,
  2737. bottom: bot
  2738. };
  2739. if (!rect.left && !rect.right) {
  2740. result.bogus = true;
  2741. }
  2742. if (!cm.options.singleCursorHeightPerLine) {
  2743. result.rtop = rtop;
  2744. result.rbottom = rbot;
  2745. }
  2746. return result;
  2747. }
  2748. function maybeUpdateRectForZooming(measure, rect) {
  2749. if (!window.screen || screen.logicalXDPI == null || screen.logicalXDPI == screen.deviceXDPI || !hasBadZoomedRects(measure)) {
  2750. return rect;
  2751. }
  2752. var scaleX = screen.logicalXDPI / screen.deviceXDPI;
  2753. var scaleY = screen.logicalYDPI / screen.deviceYDPI;
  2754. return {
  2755. left: rect.left * scaleX,
  2756. right: rect.right * scaleX,
  2757. top: rect.top * scaleY,
  2758. bottom: rect.bottom * scaleY
  2759. };
  2760. }
  2761. function clearLineMeasurementCacheFor(lineView) {
  2762. if (lineView.measure) {
  2763. lineView.measure.cache = {};
  2764. lineView.measure.heights = null;
  2765. if (lineView.rest) {
  2766. for (var i2 = 0; i2 < lineView.rest.length; i2++) {
  2767. lineView.measure.caches[i2] = {};
  2768. }
  2769. }
  2770. }
  2771. }
  2772. function clearLineMeasurementCache(cm) {
  2773. cm.display.externalMeasure = null;
  2774. removeChildren(cm.display.lineMeasure);
  2775. for (var i2 = 0; i2 < cm.display.view.length; i2++) {
  2776. clearLineMeasurementCacheFor(cm.display.view[i2]);
  2777. }
  2778. }
  2779. function clearCaches(cm) {
  2780. clearLineMeasurementCache(cm);
  2781. cm.display.cachedCharWidth = cm.display.cachedTextHeight = cm.display.cachedPaddingH = null;
  2782. if (!cm.options.lineWrapping) {
  2783. cm.display.maxLineChanged = true;
  2784. }
  2785. cm.display.lineNumChars = null;
  2786. }
  2787. function pageScrollX(doc2) {
  2788. if (chrome && android) {
  2789. return -(doc2.body.getBoundingClientRect().left - parseInt(getComputedStyle(doc2.body).marginLeft));
  2790. }
  2791. return doc2.defaultView.pageXOffset || (doc2.documentElement || doc2.body).scrollLeft;
  2792. }
  2793. function pageScrollY(doc2) {
  2794. if (chrome && android) {
  2795. return -(doc2.body.getBoundingClientRect().top - parseInt(getComputedStyle(doc2.body).marginTop));
  2796. }
  2797. return doc2.defaultView.pageYOffset || (doc2.documentElement || doc2.body).scrollTop;
  2798. }
  2799. function widgetTopHeight(lineObj) {
  2800. var ref = visualLine(lineObj);
  2801. var widgets = ref.widgets;
  2802. var height = 0;
  2803. if (widgets) {
  2804. for (var i2 = 0; i2 < widgets.length; ++i2) {
  2805. if (widgets[i2].above) {
  2806. height += widgetHeight(widgets[i2]);
  2807. }
  2808. }
  2809. }
  2810. return height;
  2811. }
  2812. function intoCoordSystem(cm, lineObj, rect, context, includeWidgets) {
  2813. if (!includeWidgets) {
  2814. var height = widgetTopHeight(lineObj);
  2815. rect.top += height;
  2816. rect.bottom += height;
  2817. }
  2818. if (context == "line") {
  2819. return rect;
  2820. }
  2821. if (!context) {
  2822. context = "local";
  2823. }
  2824. var yOff = heightAtLine(lineObj);
  2825. if (context == "local") {
  2826. yOff += paddingTop(cm.display);
  2827. } else {
  2828. yOff -= cm.display.viewOffset;
  2829. }
  2830. if (context == "page" || context == "window") {
  2831. var lOff = cm.display.lineSpace.getBoundingClientRect();
  2832. yOff += lOff.top + (context == "window" ? 0 : pageScrollY(doc(cm)));
  2833. var xOff = lOff.left + (context == "window" ? 0 : pageScrollX(doc(cm)));
  2834. rect.left += xOff;
  2835. rect.right += xOff;
  2836. }
  2837. rect.top += yOff;
  2838. rect.bottom += yOff;
  2839. return rect;
  2840. }
  2841. function fromCoordSystem(cm, coords, context) {
  2842. if (context == "div") {
  2843. return coords;
  2844. }
  2845. var left = coords.left, top = coords.top;
  2846. if (context == "page") {
  2847. left -= pageScrollX(doc(cm));
  2848. top -= pageScrollY(doc(cm));
  2849. } else if (context == "local" || !context) {
  2850. var localBox = cm.display.sizer.getBoundingClientRect();
  2851. left += localBox.left;
  2852. top += localBox.top;
  2853. }
  2854. var lineSpaceBox = cm.display.lineSpace.getBoundingClientRect();
  2855. return { left: left - lineSpaceBox.left, top: top - lineSpaceBox.top };
  2856. }
  2857. function charCoords(cm, pos, context, lineObj, bias) {
  2858. if (!lineObj) {
  2859. lineObj = getLine(cm.doc, pos.line);
  2860. }
  2861. return intoCoordSystem(cm, lineObj, measureChar(cm, lineObj, pos.ch, bias), context);
  2862. }
  2863. function cursorCoords(cm, pos, context, lineObj, preparedMeasure, varHeight) {
  2864. lineObj = lineObj || getLine(cm.doc, pos.line);
  2865. if (!preparedMeasure) {
  2866. preparedMeasure = prepareMeasureForLine(cm, lineObj);
  2867. }
  2868. function get(ch2, right) {
  2869. var m = measureCharPrepared(cm, preparedMeasure, ch2, right ? "right" : "left", varHeight);
  2870. if (right) {
  2871. m.left = m.right;
  2872. } else {
  2873. m.right = m.left;
  2874. }
  2875. return intoCoordSystem(cm, lineObj, m, context);
  2876. }
  2877. var order = getOrder(lineObj, cm.doc.direction), ch = pos.ch, sticky = pos.sticky;
  2878. if (ch >= lineObj.text.length) {
  2879. ch = lineObj.text.length;
  2880. sticky = "before";
  2881. } else if (ch <= 0) {
  2882. ch = 0;
  2883. sticky = "after";
  2884. }
  2885. if (!order) {
  2886. return get(sticky == "before" ? ch - 1 : ch, sticky == "before");
  2887. }
  2888. function getBidi(ch2, partPos2, invert) {
  2889. var part = order[partPos2], right = part.level == 1;
  2890. return get(invert ? ch2 - 1 : ch2, right != invert);
  2891. }
  2892. var partPos = getBidiPartAt(order, ch, sticky);
  2893. var other = bidiOther;
  2894. var val = getBidi(ch, partPos, sticky == "before");
  2895. if (other != null) {
  2896. val.other = getBidi(ch, other, sticky != "before");
  2897. }
  2898. return val;
  2899. }
  2900. function estimateCoords(cm, pos) {
  2901. var left = 0;
  2902. pos = clipPos(cm.doc, pos);
  2903. if (!cm.options.lineWrapping) {
  2904. left = charWidth(cm.display) * pos.ch;
  2905. }
  2906. var lineObj = getLine(cm.doc, pos.line);
  2907. var top = heightAtLine(lineObj) + paddingTop(cm.display);
  2908. return { left, right: left, top, bottom: top + lineObj.height };
  2909. }
  2910. function PosWithInfo(line, ch, sticky, outside, xRel) {
  2911. var pos = Pos(line, ch, sticky);
  2912. pos.xRel = xRel;
  2913. if (outside) {
  2914. pos.outside = outside;
  2915. }
  2916. return pos;
  2917. }
  2918. function coordsChar(cm, x, y) {
  2919. var doc2 = cm.doc;
  2920. y += cm.display.viewOffset;
  2921. if (y < 0) {
  2922. return PosWithInfo(doc2.first, 0, null, -1, -1);
  2923. }
  2924. var lineN = lineAtHeight(doc2, y), last = doc2.first + doc2.size - 1;
  2925. if (lineN > last) {
  2926. return PosWithInfo(doc2.first + doc2.size - 1, getLine(doc2, last).text.length, null, 1, 1);
  2927. }
  2928. if (x < 0) {
  2929. x = 0;
  2930. }
  2931. var lineObj = getLine(doc2, lineN);
  2932. for (; ; ) {
  2933. var found = coordsCharInner(cm, lineObj, lineN, x, y);
  2934. var collapsed = collapsedSpanAround(lineObj, found.ch + (found.xRel > 0 || found.outside > 0 ? 1 : 0));
  2935. if (!collapsed) {
  2936. return found;
  2937. }
  2938. var rangeEnd = collapsed.find(1);
  2939. if (rangeEnd.line == lineN) {
  2940. return rangeEnd;
  2941. }
  2942. lineObj = getLine(doc2, lineN = rangeEnd.line);
  2943. }
  2944. }
  2945. function wrappedLineExtent(cm, lineObj, preparedMeasure, y) {
  2946. y -= widgetTopHeight(lineObj);
  2947. var end = lineObj.text.length;
  2948. var begin = findFirst(function(ch) {
  2949. return measureCharPrepared(cm, preparedMeasure, ch - 1).bottom <= y;
  2950. }, end, 0);
  2951. end = findFirst(function(ch) {
  2952. return measureCharPrepared(cm, preparedMeasure, ch).top > y;
  2953. }, begin, end);
  2954. return { begin, end };
  2955. }
  2956. function wrappedLineExtentChar(cm, lineObj, preparedMeasure, target) {
  2957. if (!preparedMeasure) {
  2958. preparedMeasure = prepareMeasureForLine(cm, lineObj);
  2959. }
  2960. var targetTop = intoCoordSystem(cm, lineObj, measureCharPrepared(cm, preparedMeasure, target), "line").top;
  2961. return wrappedLineExtent(cm, lineObj, preparedMeasure, targetTop);
  2962. }
  2963. function boxIsAfter(box, x, y, left) {
  2964. return box.bottom <= y ? false : box.top > y ? true : (left ? box.left : box.right) > x;
  2965. }
  2966. function coordsCharInner(cm, lineObj, lineNo2, x, y) {
  2967. y -= heightAtLine(lineObj);
  2968. var preparedMeasure = prepareMeasureForLine(cm, lineObj);
  2969. var widgetHeight2 = widgetTopHeight(lineObj);
  2970. var begin = 0, end = lineObj.text.length, ltr = true;
  2971. var order = getOrder(lineObj, cm.doc.direction);
  2972. if (order) {
  2973. var part = (cm.options.lineWrapping ? coordsBidiPartWrapped : coordsBidiPart)(cm, lineObj, lineNo2, preparedMeasure, order, x, y);
  2974. ltr = part.level != 1;
  2975. begin = ltr ? part.from : part.to - 1;
  2976. end = ltr ? part.to : part.from - 1;
  2977. }
  2978. var chAround = null, boxAround = null;
  2979. var ch = findFirst(function(ch2) {
  2980. var box = measureCharPrepared(cm, preparedMeasure, ch2);
  2981. box.top += widgetHeight2;
  2982. box.bottom += widgetHeight2;
  2983. if (!boxIsAfter(box, x, y, false)) {
  2984. return false;
  2985. }
  2986. if (box.top <= y && box.left <= x) {
  2987. chAround = ch2;
  2988. boxAround = box;
  2989. }
  2990. return true;
  2991. }, begin, end);
  2992. var baseX, sticky, outside = false;
  2993. if (boxAround) {
  2994. var atLeft = x - boxAround.left < boxAround.right - x, atStart = atLeft == ltr;
  2995. ch = chAround + (atStart ? 0 : 1);
  2996. sticky = atStart ? "after" : "before";
  2997. baseX = atLeft ? boxAround.left : boxAround.right;
  2998. } else {
  2999. if (!ltr && (ch == end || ch == begin)) {
  3000. ch++;
  3001. }
  3002. sticky = ch == 0 ? "after" : ch == lineObj.text.length ? "before" : measureCharPrepared(cm, preparedMeasure, ch - (ltr ? 1 : 0)).bottom + widgetHeight2 <= y == ltr ? "after" : "before";
  3003. var coords = cursorCoords(cm, Pos(lineNo2, ch, sticky), "line", lineObj, preparedMeasure);
  3004. baseX = coords.left;
  3005. outside = y < coords.top ? -1 : y >= coords.bottom ? 1 : 0;
  3006. }
  3007. ch = skipExtendingChars(lineObj.text, ch, 1);
  3008. return PosWithInfo(lineNo2, ch, sticky, outside, x - baseX);
  3009. }
  3010. function coordsBidiPart(cm, lineObj, lineNo2, preparedMeasure, order, x, y) {
  3011. var index = findFirst(function(i2) {
  3012. var part2 = order[i2], ltr2 = part2.level != 1;
  3013. return boxIsAfter(cursorCoords(
  3014. cm,
  3015. Pos(lineNo2, ltr2 ? part2.to : part2.from, ltr2 ? "before" : "after"),
  3016. "line",
  3017. lineObj,
  3018. preparedMeasure
  3019. ), x, y, true);
  3020. }, 0, order.length - 1);
  3021. var part = order[index];
  3022. if (index > 0) {
  3023. var ltr = part.level != 1;
  3024. var start = cursorCoords(
  3025. cm,
  3026. Pos(lineNo2, ltr ? part.from : part.to, ltr ? "after" : "before"),
  3027. "line",
  3028. lineObj,
  3029. preparedMeasure
  3030. );
  3031. if (boxIsAfter(start, x, y, true) && start.top > y) {
  3032. part = order[index - 1];
  3033. }
  3034. }
  3035. return part;
  3036. }
  3037. function coordsBidiPartWrapped(cm, lineObj, _lineNo, preparedMeasure, order, x, y) {
  3038. var ref = wrappedLineExtent(cm, lineObj, preparedMeasure, y);
  3039. var begin = ref.begin;
  3040. var end = ref.end;
  3041. if (/\s/.test(lineObj.text.charAt(end - 1))) {
  3042. end--;
  3043. }
  3044. var part = null, closestDist = null;
  3045. for (var i2 = 0; i2 < order.length; i2++) {
  3046. var p = order[i2];
  3047. if (p.from >= end || p.to <= begin) {
  3048. continue;
  3049. }
  3050. var ltr = p.level != 1;
  3051. var endX = measureCharPrepared(cm, preparedMeasure, ltr ? Math.min(end, p.to) - 1 : Math.max(begin, p.from)).right;
  3052. var dist = endX < x ? x - endX + 1e9 : endX - x;
  3053. if (!part || closestDist > dist) {
  3054. part = p;
  3055. closestDist = dist;
  3056. }
  3057. }
  3058. if (!part) {
  3059. part = order[order.length - 1];
  3060. }
  3061. if (part.from < begin) {
  3062. part = { from: begin, to: part.to, level: part.level };
  3063. }
  3064. if (part.to > end) {
  3065. part = { from: part.from, to: end, level: part.level };
  3066. }
  3067. return part;
  3068. }
  3069. var measureText;
  3070. function textHeight(display) {
  3071. if (display.cachedTextHeight != null) {
  3072. return display.cachedTextHeight;
  3073. }
  3074. if (measureText == null) {
  3075. measureText = elt("pre", null, "CodeMirror-line-like");
  3076. for (var i2 = 0; i2 < 49; ++i2) {
  3077. measureText.appendChild(document.createTextNode("x"));
  3078. measureText.appendChild(elt("br"));
  3079. }
  3080. measureText.appendChild(document.createTextNode("x"));
  3081. }
  3082. removeChildrenAndAdd(display.measure, measureText);
  3083. var height = measureText.offsetHeight / 50;
  3084. if (height > 3) {
  3085. display.cachedTextHeight = height;
  3086. }
  3087. removeChildren(display.measure);
  3088. return height || 1;
  3089. }
  3090. function charWidth(display) {
  3091. if (display.cachedCharWidth != null) {
  3092. return display.cachedCharWidth;
  3093. }
  3094. var anchor = elt("span", "xxxxxxxxxx");
  3095. var pre = elt("pre", [anchor], "CodeMirror-line-like");
  3096. removeChildrenAndAdd(display.measure, pre);
  3097. var rect = anchor.getBoundingClientRect(), width = (rect.right - rect.left) / 10;
  3098. if (width > 2) {
  3099. display.cachedCharWidth = width;
  3100. }
  3101. return width || 10;
  3102. }
  3103. function getDimensions(cm) {
  3104. var d = cm.display, left = {}, width = {};
  3105. var gutterLeft = d.gutters.clientLeft;
  3106. for (var n = d.gutters.firstChild, i2 = 0; n; n = n.nextSibling, ++i2) {
  3107. var id = cm.display.gutterSpecs[i2].className;
  3108. left[id] = n.offsetLeft + n.clientLeft + gutterLeft;
  3109. width[id] = n.clientWidth;
  3110. }
  3111. return {
  3112. fixedPos: compensateForHScroll(d),
  3113. gutterTotalWidth: d.gutters.offsetWidth,
  3114. gutterLeft: left,
  3115. gutterWidth: width,
  3116. wrapperWidth: d.wrapper.clientWidth
  3117. };
  3118. }
  3119. function compensateForHScroll(display) {
  3120. return display.scroller.getBoundingClientRect().left - display.sizer.getBoundingClientRect().left;
  3121. }
  3122. function estimateHeight(cm) {
  3123. var th = textHeight(cm.display), wrapping = cm.options.lineWrapping;
  3124. var perLine = wrapping && Math.max(5, cm.display.scroller.clientWidth / charWidth(cm.display) - 3);
  3125. return function(line) {
  3126. if (lineIsHidden(cm.doc, line)) {
  3127. return 0;
  3128. }
  3129. var widgetsHeight = 0;
  3130. if (line.widgets) {
  3131. for (var i2 = 0; i2 < line.widgets.length; i2++) {
  3132. if (line.widgets[i2].height) {
  3133. widgetsHeight += line.widgets[i2].height;
  3134. }
  3135. }
  3136. }
  3137. if (wrapping) {
  3138. return widgetsHeight + (Math.ceil(line.text.length / perLine) || 1) * th;
  3139. } else {
  3140. return widgetsHeight + th;
  3141. }
  3142. };
  3143. }
  3144. function estimateLineHeights(cm) {
  3145. var doc2 = cm.doc, est = estimateHeight(cm);
  3146. doc2.iter(function(line) {
  3147. var estHeight = est(line);
  3148. if (estHeight != line.height) {
  3149. updateLineHeight(line, estHeight);
  3150. }
  3151. });
  3152. }
  3153. function posFromMouse(cm, e, liberal, forRect) {
  3154. var display = cm.display;
  3155. if (!liberal && e_target(e).getAttribute("cm-not-content") == "true") {
  3156. return null;
  3157. }
  3158. var x, y, space = display.lineSpace.getBoundingClientRect();
  3159. try {
  3160. x = e.clientX - space.left;
  3161. y = e.clientY - space.top;
  3162. } catch (e$1) {
  3163. return null;
  3164. }
  3165. var coords = coordsChar(cm, x, y), line;
  3166. if (forRect && coords.xRel > 0 && (line = getLine(cm.doc, coords.line).text).length == coords.ch) {
  3167. var colDiff = countColumn(line, line.length, cm.options.tabSize) - line.length;
  3168. coords = Pos(coords.line, Math.max(0, Math.round((x - paddingH(cm.display).left) / charWidth(cm.display)) - colDiff));
  3169. }
  3170. return coords;
  3171. }
  3172. function findViewIndex(cm, n) {
  3173. if (n >= cm.display.viewTo) {
  3174. return null;
  3175. }
  3176. n -= cm.display.viewFrom;
  3177. if (n < 0) {
  3178. return null;
  3179. }
  3180. var view = cm.display.view;
  3181. for (var i2 = 0; i2 < view.length; i2++) {
  3182. n -= view[i2].size;
  3183. if (n < 0) {
  3184. return i2;
  3185. }
  3186. }
  3187. }
  3188. function regChange(cm, from, to, lendiff) {
  3189. if (from == null) {
  3190. from = cm.doc.first;
  3191. }
  3192. if (to == null) {
  3193. to = cm.doc.first + cm.doc.size;
  3194. }
  3195. if (!lendiff) {
  3196. lendiff = 0;
  3197. }
  3198. var display = cm.display;
  3199. if (lendiff && to < display.viewTo && (display.updateLineNumbers == null || display.updateLineNumbers > from)) {
  3200. display.updateLineNumbers = from;
  3201. }
  3202. cm.curOp.viewChanged = true;
  3203. if (from >= display.viewTo) {
  3204. if (sawCollapsedSpans && visualLineNo(cm.doc, from) < display.viewTo) {
  3205. resetView(cm);
  3206. }
  3207. } else if (to <= display.viewFrom) {
  3208. if (sawCollapsedSpans && visualLineEndNo(cm.doc, to + lendiff) > display.viewFrom) {
  3209. resetView(cm);
  3210. } else {
  3211. display.viewFrom += lendiff;
  3212. display.viewTo += lendiff;
  3213. }
  3214. } else if (from <= display.viewFrom && to >= display.viewTo) {
  3215. resetView(cm);
  3216. } else if (from <= display.viewFrom) {
  3217. var cut = viewCuttingPoint(cm, to, to + lendiff, 1);
  3218. if (cut) {
  3219. display.view = display.view.slice(cut.index);
  3220. display.viewFrom = cut.lineN;
  3221. display.viewTo += lendiff;
  3222. } else {
  3223. resetView(cm);
  3224. }
  3225. } else if (to >= display.viewTo) {
  3226. var cut$1 = viewCuttingPoint(cm, from, from, -1);
  3227. if (cut$1) {
  3228. display.view = display.view.slice(0, cut$1.index);
  3229. display.viewTo = cut$1.lineN;
  3230. } else {
  3231. resetView(cm);
  3232. }
  3233. } else {
  3234. var cutTop = viewCuttingPoint(cm, from, from, -1);
  3235. var cutBot = viewCuttingPoint(cm, to, to + lendiff, 1);
  3236. if (cutTop && cutBot) {
  3237. display.view = display.view.slice(0, cutTop.index).concat(buildViewArray(cm, cutTop.lineN, cutBot.lineN)).concat(display.view.slice(cutBot.index));
  3238. display.viewTo += lendiff;
  3239. } else {
  3240. resetView(cm);
  3241. }
  3242. }
  3243. var ext = display.externalMeasured;
  3244. if (ext) {
  3245. if (to < ext.lineN) {
  3246. ext.lineN += lendiff;
  3247. } else if (from < ext.lineN + ext.size) {
  3248. display.externalMeasured = null;
  3249. }
  3250. }
  3251. }
  3252. function regLineChange(cm, line, type) {
  3253. cm.curOp.viewChanged = true;
  3254. var display = cm.display, ext = cm.display.externalMeasured;
  3255. if (ext && line >= ext.lineN && line < ext.lineN + ext.size) {
  3256. display.externalMeasured = null;
  3257. }
  3258. if (line < display.viewFrom || line >= display.viewTo) {
  3259. return;
  3260. }
  3261. var lineView = display.view[findViewIndex(cm, line)];
  3262. if (lineView.node == null) {
  3263. return;
  3264. }
  3265. var arr = lineView.changes || (lineView.changes = []);
  3266. if (indexOf(arr, type) == -1) {
  3267. arr.push(type);
  3268. }
  3269. }
  3270. function resetView(cm) {
  3271. cm.display.viewFrom = cm.display.viewTo = cm.doc.first;
  3272. cm.display.view = [];
  3273. cm.display.viewOffset = 0;
  3274. }
  3275. function viewCuttingPoint(cm, oldN, newN, dir) {
  3276. var index = findViewIndex(cm, oldN), diff, view = cm.display.view;
  3277. if (!sawCollapsedSpans || newN == cm.doc.first + cm.doc.size) {
  3278. return { index, lineN: newN };
  3279. }
  3280. var n = cm.display.viewFrom;
  3281. for (var i2 = 0; i2 < index; i2++) {
  3282. n += view[i2].size;
  3283. }
  3284. if (n != oldN) {
  3285. if (dir > 0) {
  3286. if (index == view.length - 1) {
  3287. return null;
  3288. }
  3289. diff = n + view[index].size - oldN;
  3290. index++;
  3291. } else {
  3292. diff = n - oldN;
  3293. }
  3294. oldN += diff;
  3295. newN += diff;
  3296. }
  3297. while (visualLineNo(cm.doc, newN) != newN) {
  3298. if (index == (dir < 0 ? 0 : view.length - 1)) {
  3299. return null;
  3300. }
  3301. newN += dir * view[index - (dir < 0 ? 1 : 0)].size;
  3302. index += dir;
  3303. }
  3304. return { index, lineN: newN };
  3305. }
  3306. function adjustView(cm, from, to) {
  3307. var display = cm.display, view = display.view;
  3308. if (view.length == 0 || from >= display.viewTo || to <= display.viewFrom) {
  3309. display.view = buildViewArray(cm, from, to);
  3310. display.viewFrom = from;
  3311. } else {
  3312. if (display.viewFrom > from) {
  3313. display.view = buildViewArray(cm, from, display.viewFrom).concat(display.view);
  3314. } else if (display.viewFrom < from) {
  3315. display.view = display.view.slice(findViewIndex(cm, from));
  3316. }
  3317. display.viewFrom = from;
  3318. if (display.viewTo < to) {
  3319. display.view = display.view.concat(buildViewArray(cm, display.viewTo, to));
  3320. } else if (display.viewTo > to) {
  3321. display.view = display.view.slice(0, findViewIndex(cm, to));
  3322. }
  3323. }
  3324. display.viewTo = to;
  3325. }
  3326. function countDirtyView(cm) {
  3327. var view = cm.display.view, dirty = 0;
  3328. for (var i2 = 0; i2 < view.length; i2++) {
  3329. var lineView = view[i2];
  3330. if (!lineView.hidden && (!lineView.node || lineView.changes)) {
  3331. ++dirty;
  3332. }
  3333. }
  3334. return dirty;
  3335. }
  3336. function updateSelection(cm) {
  3337. cm.display.input.showSelection(cm.display.input.prepareSelection());
  3338. }
  3339. function prepareSelection(cm, primary) {
  3340. if (primary === void 0)
  3341. primary = true;
  3342. var doc2 = cm.doc, result = {};
  3343. var curFragment = result.cursors = document.createDocumentFragment();
  3344. var selFragment = result.selection = document.createDocumentFragment();
  3345. var customCursor = cm.options.$customCursor;
  3346. if (customCursor) {
  3347. primary = true;
  3348. }
  3349. for (var i2 = 0; i2 < doc2.sel.ranges.length; i2++) {
  3350. if (!primary && i2 == doc2.sel.primIndex) {
  3351. continue;
  3352. }
  3353. var range2 = doc2.sel.ranges[i2];
  3354. if (range2.from().line >= cm.display.viewTo || range2.to().line < cm.display.viewFrom) {
  3355. continue;
  3356. }
  3357. var collapsed = range2.empty();
  3358. if (customCursor) {
  3359. var head = customCursor(cm, range2);
  3360. if (head) {
  3361. drawSelectionCursor(cm, head, curFragment);
  3362. }
  3363. } else if (collapsed || cm.options.showCursorWhenSelecting) {
  3364. drawSelectionCursor(cm, range2.head, curFragment);
  3365. }
  3366. if (!collapsed) {
  3367. drawSelectionRange(cm, range2, selFragment);
  3368. }
  3369. }
  3370. return result;
  3371. }
  3372. function drawSelectionCursor(cm, head, output) {
  3373. var pos = cursorCoords(cm, head, "div", null, null, !cm.options.singleCursorHeightPerLine);
  3374. var cursor = output.appendChild(elt("div", " ", "CodeMirror-cursor"));
  3375. cursor.style.left = pos.left + "px";
  3376. cursor.style.top = pos.top + "px";
  3377. cursor.style.height = Math.max(0, pos.bottom - pos.top) * cm.options.cursorHeight + "px";
  3378. if (/\bcm-fat-cursor\b/.test(cm.getWrapperElement().className)) {
  3379. var charPos = charCoords(cm, head, "div", null, null);
  3380. var width = charPos.right - charPos.left;
  3381. cursor.style.width = (width > 0 ? width : cm.defaultCharWidth()) + "px";
  3382. }
  3383. if (pos.other) {
  3384. var otherCursor = output.appendChild(elt("div", " ", "CodeMirror-cursor CodeMirror-secondarycursor"));
  3385. otherCursor.style.display = "";
  3386. otherCursor.style.left = pos.other.left + "px";
  3387. otherCursor.style.top = pos.other.top + "px";
  3388. otherCursor.style.height = (pos.other.bottom - pos.other.top) * 0.85 + "px";
  3389. }
  3390. }
  3391. function cmpCoords(a, b) {
  3392. return a.top - b.top || a.left - b.left;
  3393. }
  3394. function drawSelectionRange(cm, range2, output) {
  3395. var display = cm.display, doc2 = cm.doc;
  3396. var fragment = document.createDocumentFragment();
  3397. var padding = paddingH(cm.display), leftSide = padding.left;
  3398. var rightSide = Math.max(display.sizerWidth, displayWidth(cm) - display.sizer.offsetLeft) - padding.right;
  3399. var docLTR = doc2.direction == "ltr";
  3400. function add(left, top, width, bottom) {
  3401. if (top < 0) {
  3402. top = 0;
  3403. }
  3404. top = Math.round(top);
  3405. bottom = Math.round(bottom);
  3406. fragment.appendChild(elt("div", null, "CodeMirror-selected", "position: absolute; left: " + left + "px;\n top: " + top + "px; width: " + (width == null ? rightSide - left : width) + "px;\n height: " + (bottom - top) + "px"));
  3407. }
  3408. function drawForLine(line, fromArg, toArg) {
  3409. var lineObj = getLine(doc2, line);
  3410. var lineLen = lineObj.text.length;
  3411. var start, end;
  3412. function coords(ch, bias) {
  3413. return charCoords(cm, Pos(line, ch), "div", lineObj, bias);
  3414. }
  3415. function wrapX(pos, dir, side) {
  3416. var extent = wrappedLineExtentChar(cm, lineObj, null, pos);
  3417. var prop2 = dir == "ltr" == (side == "after") ? "left" : "right";
  3418. var ch = side == "after" ? extent.begin : extent.end - (/\s/.test(lineObj.text.charAt(extent.end - 1)) ? 2 : 1);
  3419. return coords(ch, prop2)[prop2];
  3420. }
  3421. var order = getOrder(lineObj, doc2.direction);
  3422. iterateBidiSections(order, fromArg || 0, toArg == null ? lineLen : toArg, function(from, to, dir, i2) {
  3423. var ltr = dir == "ltr";
  3424. var fromPos = coords(from, ltr ? "left" : "right");
  3425. var toPos = coords(to - 1, ltr ? "right" : "left");
  3426. var openStart = fromArg == null && from == 0, openEnd = toArg == null && to == lineLen;
  3427. var first = i2 == 0, last = !order || i2 == order.length - 1;
  3428. if (toPos.top - fromPos.top <= 3) {
  3429. var openLeft = (docLTR ? openStart : openEnd) && first;
  3430. var openRight = (docLTR ? openEnd : openStart) && last;
  3431. var left = openLeft ? leftSide : (ltr ? fromPos : toPos).left;
  3432. var right = openRight ? rightSide : (ltr ? toPos : fromPos).right;
  3433. add(left, fromPos.top, right - left, fromPos.bottom);
  3434. } else {
  3435. var topLeft, topRight, botLeft, botRight;
  3436. if (ltr) {
  3437. topLeft = docLTR && openStart && first ? leftSide : fromPos.left;
  3438. topRight = docLTR ? rightSide : wrapX(from, dir, "before");
  3439. botLeft = docLTR ? leftSide : wrapX(to, dir, "after");
  3440. botRight = docLTR && openEnd && last ? rightSide : toPos.right;
  3441. } else {
  3442. topLeft = !docLTR ? leftSide : wrapX(from, dir, "before");
  3443. topRight = !docLTR && openStart && first ? rightSide : fromPos.right;
  3444. botLeft = !docLTR && openEnd && last ? leftSide : toPos.left;
  3445. botRight = !docLTR ? rightSide : wrapX(to, dir, "after");
  3446. }
  3447. add(topLeft, fromPos.top, topRight - topLeft, fromPos.bottom);
  3448. if (fromPos.bottom < toPos.top) {
  3449. add(leftSide, fromPos.bottom, null, toPos.top);
  3450. }
  3451. add(botLeft, toPos.top, botRight - botLeft, toPos.bottom);
  3452. }
  3453. if (!start || cmpCoords(fromPos, start) < 0) {
  3454. start = fromPos;
  3455. }
  3456. if (cmpCoords(toPos, start) < 0) {
  3457. start = toPos;
  3458. }
  3459. if (!end || cmpCoords(fromPos, end) < 0) {
  3460. end = fromPos;
  3461. }
  3462. if (cmpCoords(toPos, end) < 0) {
  3463. end = toPos;
  3464. }
  3465. });
  3466. return { start, end };
  3467. }
  3468. var sFrom = range2.from(), sTo = range2.to();
  3469. if (sFrom.line == sTo.line) {
  3470. drawForLine(sFrom.line, sFrom.ch, sTo.ch);
  3471. } else {
  3472. var fromLine = getLine(doc2, sFrom.line), toLine = getLine(doc2, sTo.line);
  3473. var singleVLine = visualLine(fromLine) == visualLine(toLine);
  3474. var leftEnd = drawForLine(sFrom.line, sFrom.ch, singleVLine ? fromLine.text.length + 1 : null).end;
  3475. var rightStart = drawForLine(sTo.line, singleVLine ? 0 : null, sTo.ch).start;
  3476. if (singleVLine) {
  3477. if (leftEnd.top < rightStart.top - 2) {
  3478. add(leftEnd.right, leftEnd.top, null, leftEnd.bottom);
  3479. add(leftSide, rightStart.top, rightStart.left, rightStart.bottom);
  3480. } else {
  3481. add(leftEnd.right, leftEnd.top, rightStart.left - leftEnd.right, leftEnd.bottom);
  3482. }
  3483. }
  3484. if (leftEnd.bottom < rightStart.top) {
  3485. add(leftSide, leftEnd.bottom, null, rightStart.top);
  3486. }
  3487. }
  3488. output.appendChild(fragment);
  3489. }
  3490. function restartBlink(cm) {
  3491. if (!cm.state.focused) {
  3492. return;
  3493. }
  3494. var display = cm.display;
  3495. clearInterval(display.blinker);
  3496. var on2 = true;
  3497. display.cursorDiv.style.visibility = "";
  3498. if (cm.options.cursorBlinkRate > 0) {
  3499. display.blinker = setInterval(function() {
  3500. if (!cm.hasFocus()) {
  3501. onBlur(cm);
  3502. }
  3503. display.cursorDiv.style.visibility = (on2 = !on2) ? "" : "hidden";
  3504. }, cm.options.cursorBlinkRate);
  3505. } else if (cm.options.cursorBlinkRate < 0) {
  3506. display.cursorDiv.style.visibility = "hidden";
  3507. }
  3508. }
  3509. function ensureFocus(cm) {
  3510. if (!cm.hasFocus()) {
  3511. cm.display.input.focus();
  3512. if (!cm.state.focused) {
  3513. onFocus(cm);
  3514. }
  3515. }
  3516. }
  3517. function delayBlurEvent(cm) {
  3518. cm.state.delayingBlurEvent = true;
  3519. setTimeout(function() {
  3520. if (cm.state.delayingBlurEvent) {
  3521. cm.state.delayingBlurEvent = false;
  3522. if (cm.state.focused) {
  3523. onBlur(cm);
  3524. }
  3525. }
  3526. }, 100);
  3527. }
  3528. function onFocus(cm, e) {
  3529. if (cm.state.delayingBlurEvent && !cm.state.draggingText) {
  3530. cm.state.delayingBlurEvent = false;
  3531. }
  3532. if (cm.options.readOnly == "nocursor") {
  3533. return;
  3534. }
  3535. if (!cm.state.focused) {
  3536. signal(cm, "focus", cm, e);
  3537. cm.state.focused = true;
  3538. addClass(cm.display.wrapper, "CodeMirror-focused");
  3539. if (!cm.curOp && cm.display.selForContextMenu != cm.doc.sel) {
  3540. cm.display.input.reset();
  3541. if (webkit) {
  3542. setTimeout(function() {
  3543. return cm.display.input.reset(true);
  3544. }, 20);
  3545. }
  3546. }
  3547. cm.display.input.receivedFocus();
  3548. }
  3549. restartBlink(cm);
  3550. }
  3551. function onBlur(cm, e) {
  3552. if (cm.state.delayingBlurEvent) {
  3553. return;
  3554. }
  3555. if (cm.state.focused) {
  3556. signal(cm, "blur", cm, e);
  3557. cm.state.focused = false;
  3558. rmClass(cm.display.wrapper, "CodeMirror-focused");
  3559. }
  3560. clearInterval(cm.display.blinker);
  3561. setTimeout(function() {
  3562. if (!cm.state.focused) {
  3563. cm.display.shift = false;
  3564. }
  3565. }, 150);
  3566. }
  3567. function updateHeightsInViewport(cm) {
  3568. var display = cm.display;
  3569. var prevBottom = display.lineDiv.offsetTop;
  3570. var viewTop = Math.max(0, display.scroller.getBoundingClientRect().top);
  3571. var oldHeight = display.lineDiv.getBoundingClientRect().top;
  3572. var mustScroll = 0;
  3573. for (var i2 = 0; i2 < display.view.length; i2++) {
  3574. var cur = display.view[i2], wrapping = cm.options.lineWrapping;
  3575. var height = void 0, width = 0;
  3576. if (cur.hidden) {
  3577. continue;
  3578. }
  3579. oldHeight += cur.line.height;
  3580. if (ie && ie_version < 8) {
  3581. var bot = cur.node.offsetTop + cur.node.offsetHeight;
  3582. height = bot - prevBottom;
  3583. prevBottom = bot;
  3584. } else {
  3585. var box = cur.node.getBoundingClientRect();
  3586. height = box.bottom - box.top;
  3587. if (!wrapping && cur.text.firstChild) {
  3588. width = cur.text.firstChild.getBoundingClientRect().right - box.left - 1;
  3589. }
  3590. }
  3591. var diff = cur.line.height - height;
  3592. if (diff > 5e-3 || diff < -5e-3) {
  3593. if (oldHeight < viewTop) {
  3594. mustScroll -= diff;
  3595. }
  3596. updateLineHeight(cur.line, height);
  3597. updateWidgetHeight(cur.line);
  3598. if (cur.rest) {
  3599. for (var j = 0; j < cur.rest.length; j++) {
  3600. updateWidgetHeight(cur.rest[j]);
  3601. }
  3602. }
  3603. }
  3604. if (width > cm.display.sizerWidth) {
  3605. var chWidth = Math.ceil(width / charWidth(cm.display));
  3606. if (chWidth > cm.display.maxLineLength) {
  3607. cm.display.maxLineLength = chWidth;
  3608. cm.display.maxLine = cur.line;
  3609. cm.display.maxLineChanged = true;
  3610. }
  3611. }
  3612. }
  3613. if (Math.abs(mustScroll) > 2) {
  3614. display.scroller.scrollTop += mustScroll;
  3615. }
  3616. }
  3617. function updateWidgetHeight(line) {
  3618. if (line.widgets) {
  3619. for (var i2 = 0; i2 < line.widgets.length; ++i2) {
  3620. var w = line.widgets[i2], parent = w.node.parentNode;
  3621. if (parent) {
  3622. w.height = parent.offsetHeight;
  3623. }
  3624. }
  3625. }
  3626. }
  3627. function visibleLines(display, doc2, viewport) {
  3628. var top = viewport && viewport.top != null ? Math.max(0, viewport.top) : display.scroller.scrollTop;
  3629. top = Math.floor(top - paddingTop(display));
  3630. var bottom = viewport && viewport.bottom != null ? viewport.bottom : top + display.wrapper.clientHeight;
  3631. var from = lineAtHeight(doc2, top), to = lineAtHeight(doc2, bottom);
  3632. if (viewport && viewport.ensure) {
  3633. var ensureFrom = viewport.ensure.from.line, ensureTo = viewport.ensure.to.line;
  3634. if (ensureFrom < from) {
  3635. from = ensureFrom;
  3636. to = lineAtHeight(doc2, heightAtLine(getLine(doc2, ensureFrom)) + display.wrapper.clientHeight);
  3637. } else if (Math.min(ensureTo, doc2.lastLine()) >= to) {
  3638. from = lineAtHeight(doc2, heightAtLine(getLine(doc2, ensureTo)) - display.wrapper.clientHeight);
  3639. to = ensureTo;
  3640. }
  3641. }
  3642. return { from, to: Math.max(to, from + 1) };
  3643. }
  3644. function maybeScrollWindow(cm, rect) {
  3645. if (signalDOMEvent(cm, "scrollCursorIntoView")) {
  3646. return;
  3647. }
  3648. var display = cm.display, box = display.sizer.getBoundingClientRect(), doScroll = null;
  3649. var doc2 = display.wrapper.ownerDocument;
  3650. if (rect.top + box.top < 0) {
  3651. doScroll = true;
  3652. } else if (rect.bottom + box.top > (doc2.defaultView.innerHeight || doc2.documentElement.clientHeight)) {
  3653. doScroll = false;
  3654. }
  3655. if (doScroll != null && !phantom) {
  3656. var scrollNode = elt("div", "​", null, "position: absolute;\n top: " + (rect.top - display.viewOffset - paddingTop(cm.display)) + "px;\n height: " + (rect.bottom - rect.top + scrollGap(cm) + display.barHeight) + "px;\n left: " + rect.left + "px; width: " + Math.max(2, rect.right - rect.left) + "px;");
  3657. cm.display.lineSpace.appendChild(scrollNode);
  3658. scrollNode.scrollIntoView(doScroll);
  3659. cm.display.lineSpace.removeChild(scrollNode);
  3660. }
  3661. }
  3662. function scrollPosIntoView(cm, pos, end, margin) {
  3663. if (margin == null) {
  3664. margin = 0;
  3665. }
  3666. var rect;
  3667. if (!cm.options.lineWrapping && pos == end) {
  3668. end = pos.sticky == "before" ? Pos(pos.line, pos.ch + 1, "before") : pos;
  3669. pos = pos.ch ? Pos(pos.line, pos.sticky == "before" ? pos.ch - 1 : pos.ch, "after") : pos;
  3670. }
  3671. for (var limit = 0; limit < 5; limit++) {
  3672. var changed = false;
  3673. var coords = cursorCoords(cm, pos);
  3674. var endCoords = !end || end == pos ? coords : cursorCoords(cm, end);
  3675. rect = {
  3676. left: Math.min(coords.left, endCoords.left),
  3677. top: Math.min(coords.top, endCoords.top) - margin,
  3678. right: Math.max(coords.left, endCoords.left),
  3679. bottom: Math.max(coords.bottom, endCoords.bottom) + margin
  3680. };
  3681. var scrollPos = calculateScrollPos(cm, rect);
  3682. var startTop = cm.doc.scrollTop, startLeft = cm.doc.scrollLeft;
  3683. if (scrollPos.scrollTop != null) {
  3684. updateScrollTop(cm, scrollPos.scrollTop);
  3685. if (Math.abs(cm.doc.scrollTop - startTop) > 1) {
  3686. changed = true;
  3687. }
  3688. }
  3689. if (scrollPos.scrollLeft != null) {
  3690. setScrollLeft(cm, scrollPos.scrollLeft);
  3691. if (Math.abs(cm.doc.scrollLeft - startLeft) > 1) {
  3692. changed = true;
  3693. }
  3694. }
  3695. if (!changed) {
  3696. break;
  3697. }
  3698. }
  3699. return rect;
  3700. }
  3701. function scrollIntoView(cm, rect) {
  3702. var scrollPos = calculateScrollPos(cm, rect);
  3703. if (scrollPos.scrollTop != null) {
  3704. updateScrollTop(cm, scrollPos.scrollTop);
  3705. }
  3706. if (scrollPos.scrollLeft != null) {
  3707. setScrollLeft(cm, scrollPos.scrollLeft);
  3708. }
  3709. }
  3710. function calculateScrollPos(cm, rect) {
  3711. var display = cm.display, snapMargin = textHeight(cm.display);
  3712. if (rect.top < 0) {
  3713. rect.top = 0;
  3714. }
  3715. var screentop = cm.curOp && cm.curOp.scrollTop != null ? cm.curOp.scrollTop : display.scroller.scrollTop;
  3716. var screen2 = displayHeight(cm), result = {};
  3717. if (rect.bottom - rect.top > screen2) {
  3718. rect.bottom = rect.top + screen2;
  3719. }
  3720. var docBottom = cm.doc.height + paddingVert(display);
  3721. var atTop = rect.top < snapMargin, atBottom = rect.bottom > docBottom - snapMargin;
  3722. if (rect.top < screentop) {
  3723. result.scrollTop = atTop ? 0 : rect.top;
  3724. } else if (rect.bottom > screentop + screen2) {
  3725. var newTop = Math.min(rect.top, (atBottom ? docBottom : rect.bottom) - screen2);
  3726. if (newTop != screentop) {
  3727. result.scrollTop = newTop;
  3728. }
  3729. }
  3730. var gutterSpace = cm.options.fixedGutter ? 0 : display.gutters.offsetWidth;
  3731. var screenleft = cm.curOp && cm.curOp.scrollLeft != null ? cm.curOp.scrollLeft : display.scroller.scrollLeft - gutterSpace;
  3732. var screenw = displayWidth(cm) - display.gutters.offsetWidth;
  3733. var tooWide = rect.right - rect.left > screenw;
  3734. if (tooWide) {
  3735. rect.right = rect.left + screenw;
  3736. }
  3737. if (rect.left < 10) {
  3738. result.scrollLeft = 0;
  3739. } else if (rect.left < screenleft) {
  3740. result.scrollLeft = Math.max(0, rect.left + gutterSpace - (tooWide ? 0 : 10));
  3741. } else if (rect.right > screenw + screenleft - 3) {
  3742. result.scrollLeft = rect.right + (tooWide ? 0 : 10) - screenw;
  3743. }
  3744. return result;
  3745. }
  3746. function addToScrollTop(cm, top) {
  3747. if (top == null) {
  3748. return;
  3749. }
  3750. resolveScrollToPos(cm);
  3751. cm.curOp.scrollTop = (cm.curOp.scrollTop == null ? cm.doc.scrollTop : cm.curOp.scrollTop) + top;
  3752. }
  3753. function ensureCursorVisible(cm) {
  3754. resolveScrollToPos(cm);
  3755. var cur = cm.getCursor();
  3756. cm.curOp.scrollToPos = { from: cur, to: cur, margin: cm.options.cursorScrollMargin };
  3757. }
  3758. function scrollToCoords(cm, x, y) {
  3759. if (x != null || y != null) {
  3760. resolveScrollToPos(cm);
  3761. }
  3762. if (x != null) {
  3763. cm.curOp.scrollLeft = x;
  3764. }
  3765. if (y != null) {
  3766. cm.curOp.scrollTop = y;
  3767. }
  3768. }
  3769. function scrollToRange(cm, range2) {
  3770. resolveScrollToPos(cm);
  3771. cm.curOp.scrollToPos = range2;
  3772. }
  3773. function resolveScrollToPos(cm) {
  3774. var range2 = cm.curOp.scrollToPos;
  3775. if (range2) {
  3776. cm.curOp.scrollToPos = null;
  3777. var from = estimateCoords(cm, range2.from), to = estimateCoords(cm, range2.to);
  3778. scrollToCoordsRange(cm, from, to, range2.margin);
  3779. }
  3780. }
  3781. function scrollToCoordsRange(cm, from, to, margin) {
  3782. var sPos = calculateScrollPos(cm, {
  3783. left: Math.min(from.left, to.left),
  3784. top: Math.min(from.top, to.top) - margin,
  3785. right: Math.max(from.right, to.right),
  3786. bottom: Math.max(from.bottom, to.bottom) + margin
  3787. });
  3788. scrollToCoords(cm, sPos.scrollLeft, sPos.scrollTop);
  3789. }
  3790. function updateScrollTop(cm, val) {
  3791. if (Math.abs(cm.doc.scrollTop - val) < 2) {
  3792. return;
  3793. }
  3794. if (!gecko) {
  3795. updateDisplaySimple(cm, { top: val });
  3796. }
  3797. setScrollTop(cm, val, true);
  3798. if (gecko) {
  3799. updateDisplaySimple(cm);
  3800. }
  3801. startWorker(cm, 100);
  3802. }
  3803. function setScrollTop(cm, val, forceScroll) {
  3804. val = Math.max(0, Math.min(cm.display.scroller.scrollHeight - cm.display.scroller.clientHeight, val));
  3805. if (cm.display.scroller.scrollTop == val && !forceScroll) {
  3806. return;
  3807. }
  3808. cm.doc.scrollTop = val;
  3809. cm.display.scrollbars.setScrollTop(val);
  3810. if (cm.display.scroller.scrollTop != val) {
  3811. cm.display.scroller.scrollTop = val;
  3812. }
  3813. }
  3814. function setScrollLeft(cm, val, isScroller, forceScroll) {
  3815. val = Math.max(0, Math.min(val, cm.display.scroller.scrollWidth - cm.display.scroller.clientWidth));
  3816. if ((isScroller ? val == cm.doc.scrollLeft : Math.abs(cm.doc.scrollLeft - val) < 2) && !forceScroll) {
  3817. return;
  3818. }
  3819. cm.doc.scrollLeft = val;
  3820. alignHorizontally(cm);
  3821. if (cm.display.scroller.scrollLeft != val) {
  3822. cm.display.scroller.scrollLeft = val;
  3823. }
  3824. cm.display.scrollbars.setScrollLeft(val);
  3825. }
  3826. function measureForScrollbars(cm) {
  3827. var d = cm.display, gutterW = d.gutters.offsetWidth;
  3828. var docH = Math.round(cm.doc.height + paddingVert(cm.display));
  3829. return {
  3830. clientHeight: d.scroller.clientHeight,
  3831. viewHeight: d.wrapper.clientHeight,
  3832. scrollWidth: d.scroller.scrollWidth,
  3833. clientWidth: d.scroller.clientWidth,
  3834. viewWidth: d.wrapper.clientWidth,
  3835. barLeft: cm.options.fixedGutter ? gutterW : 0,
  3836. docHeight: docH,
  3837. scrollHeight: docH + scrollGap(cm) + d.barHeight,
  3838. nativeBarWidth: d.nativeBarWidth,
  3839. gutterWidth: gutterW
  3840. };
  3841. }
  3842. var NativeScrollbars = function(place, scroll, cm) {
  3843. this.cm = cm;
  3844. var vert = this.vert = elt("div", [elt("div", null, null, "min-width: 1px")], "CodeMirror-vscrollbar");
  3845. var horiz = this.horiz = elt("div", [elt("div", null, null, "height: 100%; min-height: 1px")], "CodeMirror-hscrollbar");
  3846. vert.tabIndex = horiz.tabIndex = -1;
  3847. place(vert);
  3848. place(horiz);
  3849. on(vert, "scroll", function() {
  3850. if (vert.clientHeight) {
  3851. scroll(vert.scrollTop, "vertical");
  3852. }
  3853. });
  3854. on(horiz, "scroll", function() {
  3855. if (horiz.clientWidth) {
  3856. scroll(horiz.scrollLeft, "horizontal");
  3857. }
  3858. });
  3859. this.checkedZeroWidth = false;
  3860. if (ie && ie_version < 8) {
  3861. this.horiz.style.minHeight = this.vert.style.minWidth = "18px";
  3862. }
  3863. };
  3864. NativeScrollbars.prototype.update = function(measure) {
  3865. var needsH = measure.scrollWidth > measure.clientWidth + 1;
  3866. var needsV = measure.scrollHeight > measure.clientHeight + 1;
  3867. var sWidth = measure.nativeBarWidth;
  3868. if (needsV) {
  3869. this.vert.style.display = "block";
  3870. this.vert.style.bottom = needsH ? sWidth + "px" : "0";
  3871. var totalHeight = measure.viewHeight - (needsH ? sWidth : 0);
  3872. this.vert.firstChild.style.height = Math.max(0, measure.scrollHeight - measure.clientHeight + totalHeight) + "px";
  3873. } else {
  3874. this.vert.scrollTop = 0;
  3875. this.vert.style.display = "";
  3876. this.vert.firstChild.style.height = "0";
  3877. }
  3878. if (needsH) {
  3879. this.horiz.style.display = "block";
  3880. this.horiz.style.right = needsV ? sWidth + "px" : "0";
  3881. this.horiz.style.left = measure.barLeft + "px";
  3882. var totalWidth = measure.viewWidth - measure.barLeft - (needsV ? sWidth : 0);
  3883. this.horiz.firstChild.style.width = Math.max(0, measure.scrollWidth - measure.clientWidth + totalWidth) + "px";
  3884. } else {
  3885. this.horiz.style.display = "";
  3886. this.horiz.firstChild.style.width = "0";
  3887. }
  3888. if (!this.checkedZeroWidth && measure.clientHeight > 0) {
  3889. if (sWidth == 0) {
  3890. this.zeroWidthHack();
  3891. }
  3892. this.checkedZeroWidth = true;
  3893. }
  3894. return { right: needsV ? sWidth : 0, bottom: needsH ? sWidth : 0 };
  3895. };
  3896. NativeScrollbars.prototype.setScrollLeft = function(pos) {
  3897. if (this.horiz.scrollLeft != pos) {
  3898. this.horiz.scrollLeft = pos;
  3899. }
  3900. if (this.disableHoriz) {
  3901. this.enableZeroWidthBar(this.horiz, this.disableHoriz, "horiz");
  3902. }
  3903. };
  3904. NativeScrollbars.prototype.setScrollTop = function(pos) {
  3905. if (this.vert.scrollTop != pos) {
  3906. this.vert.scrollTop = pos;
  3907. }
  3908. if (this.disableVert) {
  3909. this.enableZeroWidthBar(this.vert, this.disableVert, "vert");
  3910. }
  3911. };
  3912. NativeScrollbars.prototype.zeroWidthHack = function() {
  3913. var w = mac && !mac_geMountainLion ? "12px" : "18px";
  3914. this.horiz.style.height = this.vert.style.width = w;
  3915. this.horiz.style.visibility = this.vert.style.visibility = "hidden";
  3916. this.disableHoriz = new Delayed();
  3917. this.disableVert = new Delayed();
  3918. };
  3919. NativeScrollbars.prototype.enableZeroWidthBar = function(bar, delay, type) {
  3920. bar.style.visibility = "";
  3921. function maybeDisable() {
  3922. var box = bar.getBoundingClientRect();
  3923. var elt2 = type == "vert" ? document.elementFromPoint(box.right - 1, (box.top + box.bottom) / 2) : document.elementFromPoint((box.right + box.left) / 2, box.bottom - 1);
  3924. if (elt2 != bar) {
  3925. bar.style.visibility = "hidden";
  3926. } else {
  3927. delay.set(1e3, maybeDisable);
  3928. }
  3929. }
  3930. delay.set(1e3, maybeDisable);
  3931. };
  3932. NativeScrollbars.prototype.clear = function() {
  3933. var parent = this.horiz.parentNode;
  3934. parent.removeChild(this.horiz);
  3935. parent.removeChild(this.vert);
  3936. };
  3937. var NullScrollbars = function() {
  3938. };
  3939. NullScrollbars.prototype.update = function() {
  3940. return { bottom: 0, right: 0 };
  3941. };
  3942. NullScrollbars.prototype.setScrollLeft = function() {
  3943. };
  3944. NullScrollbars.prototype.setScrollTop = function() {
  3945. };
  3946. NullScrollbars.prototype.clear = function() {
  3947. };
  3948. function updateScrollbars(cm, measure) {
  3949. if (!measure) {
  3950. measure = measureForScrollbars(cm);
  3951. }
  3952. var startWidth = cm.display.barWidth, startHeight = cm.display.barHeight;
  3953. updateScrollbarsInner(cm, measure);
  3954. for (var i2 = 0; i2 < 4 && startWidth != cm.display.barWidth || startHeight != cm.display.barHeight; i2++) {
  3955. if (startWidth != cm.display.barWidth && cm.options.lineWrapping) {
  3956. updateHeightsInViewport(cm);
  3957. }
  3958. updateScrollbarsInner(cm, measureForScrollbars(cm));
  3959. startWidth = cm.display.barWidth;
  3960. startHeight = cm.display.barHeight;
  3961. }
  3962. }
  3963. function updateScrollbarsInner(cm, measure) {
  3964. var d = cm.display;
  3965. var sizes = d.scrollbars.update(measure);
  3966. d.sizer.style.paddingRight = (d.barWidth = sizes.right) + "px";
  3967. d.sizer.style.paddingBottom = (d.barHeight = sizes.bottom) + "px";
  3968. d.heightForcer.style.borderBottom = sizes.bottom + "px solid transparent";
  3969. if (sizes.right && sizes.bottom) {
  3970. d.scrollbarFiller.style.display = "block";
  3971. d.scrollbarFiller.style.height = sizes.bottom + "px";
  3972. d.scrollbarFiller.style.width = sizes.right + "px";
  3973. } else {
  3974. d.scrollbarFiller.style.display = "";
  3975. }
  3976. if (sizes.bottom && cm.options.coverGutterNextToScrollbar && cm.options.fixedGutter) {
  3977. d.gutterFiller.style.display = "block";
  3978. d.gutterFiller.style.height = sizes.bottom + "px";
  3979. d.gutterFiller.style.width = measure.gutterWidth + "px";
  3980. } else {
  3981. d.gutterFiller.style.display = "";
  3982. }
  3983. }
  3984. var scrollbarModel = { "native": NativeScrollbars, "null": NullScrollbars };
  3985. function initScrollbars(cm) {
  3986. if (cm.display.scrollbars) {
  3987. cm.display.scrollbars.clear();
  3988. if (cm.display.scrollbars.addClass) {
  3989. rmClass(cm.display.wrapper, cm.display.scrollbars.addClass);
  3990. }
  3991. }
  3992. cm.display.scrollbars = new scrollbarModel[cm.options.scrollbarStyle](function(node) {
  3993. cm.display.wrapper.insertBefore(node, cm.display.scrollbarFiller);
  3994. on(node, "mousedown", function() {
  3995. if (cm.state.focused) {
  3996. setTimeout(function() {
  3997. return cm.display.input.focus();
  3998. }, 0);
  3999. }
  4000. });
  4001. node.setAttribute("cm-not-content", "true");
  4002. }, function(pos, axis) {
  4003. if (axis == "horizontal") {
  4004. setScrollLeft(cm, pos);
  4005. } else {
  4006. updateScrollTop(cm, pos);
  4007. }
  4008. }, cm);
  4009. if (cm.display.scrollbars.addClass) {
  4010. addClass(cm.display.wrapper, cm.display.scrollbars.addClass);
  4011. }
  4012. }
  4013. var nextOpId = 0;
  4014. function startOperation(cm) {
  4015. cm.curOp = {
  4016. cm,
  4017. viewChanged: false,
  4018. // Flag that indicates that lines might need to be redrawn
  4019. startHeight: cm.doc.height,
  4020. // Used to detect need to update scrollbar
  4021. forceUpdate: false,
  4022. // Used to force a redraw
  4023. updateInput: 0,
  4024. // Whether to reset the input textarea
  4025. typing: false,
  4026. // Whether this reset should be careful to leave existing text (for compositing)
  4027. changeObjs: null,
  4028. // Accumulated changes, for firing change events
  4029. cursorActivityHandlers: null,
  4030. // Set of handlers to fire cursorActivity on
  4031. cursorActivityCalled: 0,
  4032. // Tracks which cursorActivity handlers have been called already
  4033. selectionChanged: false,
  4034. // Whether the selection needs to be redrawn
  4035. updateMaxLine: false,
  4036. // Set when the widest line needs to be determined anew
  4037. scrollLeft: null,
  4038. scrollTop: null,
  4039. // Intermediate scroll position, not pushed to DOM yet
  4040. scrollToPos: null,
  4041. // Used to scroll to a specific position
  4042. focus: false,
  4043. id: ++nextOpId,
  4044. // Unique ID
  4045. markArrays: null
  4046. // Used by addMarkedSpan
  4047. };
  4048. pushOperation(cm.curOp);
  4049. }
  4050. function endOperation(cm) {
  4051. var op = cm.curOp;
  4052. if (op) {
  4053. finishOperation(op, function(group) {
  4054. for (var i2 = 0; i2 < group.ops.length; i2++) {
  4055. group.ops[i2].cm.curOp = null;
  4056. }
  4057. endOperations(group);
  4058. });
  4059. }
  4060. }
  4061. function endOperations(group) {
  4062. var ops = group.ops;
  4063. for (var i2 = 0; i2 < ops.length; i2++) {
  4064. endOperation_R1(ops[i2]);
  4065. }
  4066. for (var i$12 = 0; i$12 < ops.length; i$12++) {
  4067. endOperation_W1(ops[i$12]);
  4068. }
  4069. for (var i$22 = 0; i$22 < ops.length; i$22++) {
  4070. endOperation_R2(ops[i$22]);
  4071. }
  4072. for (var i$3 = 0; i$3 < ops.length; i$3++) {
  4073. endOperation_W2(ops[i$3]);
  4074. }
  4075. for (var i$4 = 0; i$4 < ops.length; i$4++) {
  4076. endOperation_finish(ops[i$4]);
  4077. }
  4078. }
  4079. function endOperation_R1(op) {
  4080. var cm = op.cm, display = cm.display;
  4081. maybeClipScrollbars(cm);
  4082. if (op.updateMaxLine) {
  4083. findMaxLine(cm);
  4084. }
  4085. op.mustUpdate = op.viewChanged || op.forceUpdate || op.scrollTop != null || op.scrollToPos && (op.scrollToPos.from.line < display.viewFrom || op.scrollToPos.to.line >= display.viewTo) || display.maxLineChanged && cm.options.lineWrapping;
  4086. op.update = op.mustUpdate && new DisplayUpdate(cm, op.mustUpdate && { top: op.scrollTop, ensure: op.scrollToPos }, op.forceUpdate);
  4087. }
  4088. function endOperation_W1(op) {
  4089. op.updatedDisplay = op.mustUpdate && updateDisplayIfNeeded(op.cm, op.update);
  4090. }
  4091. function endOperation_R2(op) {
  4092. var cm = op.cm, display = cm.display;
  4093. if (op.updatedDisplay) {
  4094. updateHeightsInViewport(cm);
  4095. }
  4096. op.barMeasure = measureForScrollbars(cm);
  4097. if (display.maxLineChanged && !cm.options.lineWrapping) {
  4098. op.adjustWidthTo = measureChar(cm, display.maxLine, display.maxLine.text.length).left + 3;
  4099. cm.display.sizerWidth = op.adjustWidthTo;
  4100. op.barMeasure.scrollWidth = Math.max(display.scroller.clientWidth, display.sizer.offsetLeft + op.adjustWidthTo + scrollGap(cm) + cm.display.barWidth);
  4101. op.maxScrollLeft = Math.max(0, display.sizer.offsetLeft + op.adjustWidthTo - displayWidth(cm));
  4102. }
  4103. if (op.updatedDisplay || op.selectionChanged) {
  4104. op.preparedSelection = display.input.prepareSelection();
  4105. }
  4106. }
  4107. function endOperation_W2(op) {
  4108. var cm = op.cm;
  4109. if (op.adjustWidthTo != null) {
  4110. cm.display.sizer.style.minWidth = op.adjustWidthTo + "px";
  4111. if (op.maxScrollLeft < cm.doc.scrollLeft) {
  4112. setScrollLeft(cm, Math.min(cm.display.scroller.scrollLeft, op.maxScrollLeft), true);
  4113. }
  4114. cm.display.maxLineChanged = false;
  4115. }
  4116. var takeFocus = op.focus && op.focus == activeElt(doc(cm));
  4117. if (op.preparedSelection) {
  4118. cm.display.input.showSelection(op.preparedSelection, takeFocus);
  4119. }
  4120. if (op.updatedDisplay || op.startHeight != cm.doc.height) {
  4121. updateScrollbars(cm, op.barMeasure);
  4122. }
  4123. if (op.updatedDisplay) {
  4124. setDocumentHeight(cm, op.barMeasure);
  4125. }
  4126. if (op.selectionChanged) {
  4127. restartBlink(cm);
  4128. }
  4129. if (cm.state.focused && op.updateInput) {
  4130. cm.display.input.reset(op.typing);
  4131. }
  4132. if (takeFocus) {
  4133. ensureFocus(op.cm);
  4134. }
  4135. }
  4136. function endOperation_finish(op) {
  4137. var cm = op.cm, display = cm.display, doc2 = cm.doc;
  4138. if (op.updatedDisplay) {
  4139. postUpdateDisplay(cm, op.update);
  4140. }
  4141. if (display.wheelStartX != null && (op.scrollTop != null || op.scrollLeft != null || op.scrollToPos)) {
  4142. display.wheelStartX = display.wheelStartY = null;
  4143. }
  4144. if (op.scrollTop != null) {
  4145. setScrollTop(cm, op.scrollTop, op.forceScroll);
  4146. }
  4147. if (op.scrollLeft != null) {
  4148. setScrollLeft(cm, op.scrollLeft, true, true);
  4149. }
  4150. if (op.scrollToPos) {
  4151. var rect = scrollPosIntoView(
  4152. cm,
  4153. clipPos(doc2, op.scrollToPos.from),
  4154. clipPos(doc2, op.scrollToPos.to),
  4155. op.scrollToPos.margin
  4156. );
  4157. maybeScrollWindow(cm, rect);
  4158. }
  4159. var hidden = op.maybeHiddenMarkers, unhidden = op.maybeUnhiddenMarkers;
  4160. if (hidden) {
  4161. for (var i2 = 0; i2 < hidden.length; ++i2) {
  4162. if (!hidden[i2].lines.length) {
  4163. signal(hidden[i2], "hide");
  4164. }
  4165. }
  4166. }
  4167. if (unhidden) {
  4168. for (var i$12 = 0; i$12 < unhidden.length; ++i$12) {
  4169. if (unhidden[i$12].lines.length) {
  4170. signal(unhidden[i$12], "unhide");
  4171. }
  4172. }
  4173. }
  4174. if (display.wrapper.offsetHeight) {
  4175. doc2.scrollTop = cm.display.scroller.scrollTop;
  4176. }
  4177. if (op.changeObjs) {
  4178. signal(cm, "changes", cm, op.changeObjs);
  4179. }
  4180. if (op.update) {
  4181. op.update.finish();
  4182. }
  4183. }
  4184. function runInOp(cm, f) {
  4185. if (cm.curOp) {
  4186. return f();
  4187. }
  4188. startOperation(cm);
  4189. try {
  4190. return f();
  4191. } finally {
  4192. endOperation(cm);
  4193. }
  4194. }
  4195. function operation(cm, f) {
  4196. return function() {
  4197. if (cm.curOp) {
  4198. return f.apply(cm, arguments);
  4199. }
  4200. startOperation(cm);
  4201. try {
  4202. return f.apply(cm, arguments);
  4203. } finally {
  4204. endOperation(cm);
  4205. }
  4206. };
  4207. }
  4208. function methodOp(f) {
  4209. return function() {
  4210. if (this.curOp) {
  4211. return f.apply(this, arguments);
  4212. }
  4213. startOperation(this);
  4214. try {
  4215. return f.apply(this, arguments);
  4216. } finally {
  4217. endOperation(this);
  4218. }
  4219. };
  4220. }
  4221. function docMethodOp(f) {
  4222. return function() {
  4223. var cm = this.cm;
  4224. if (!cm || cm.curOp) {
  4225. return f.apply(this, arguments);
  4226. }
  4227. startOperation(cm);
  4228. try {
  4229. return f.apply(this, arguments);
  4230. } finally {
  4231. endOperation(cm);
  4232. }
  4233. };
  4234. }
  4235. function startWorker(cm, time) {
  4236. if (cm.doc.highlightFrontier < cm.display.viewTo) {
  4237. cm.state.highlight.set(time, bind(highlightWorker, cm));
  4238. }
  4239. }
  4240. function highlightWorker(cm) {
  4241. var doc2 = cm.doc;
  4242. if (doc2.highlightFrontier >= cm.display.viewTo) {
  4243. return;
  4244. }
  4245. var end = +/* @__PURE__ */ new Date() + cm.options.workTime;
  4246. var context = getContextBefore(cm, doc2.highlightFrontier);
  4247. var changedLines = [];
  4248. doc2.iter(context.line, Math.min(doc2.first + doc2.size, cm.display.viewTo + 500), function(line) {
  4249. if (context.line >= cm.display.viewFrom) {
  4250. var oldStyles = line.styles;
  4251. var resetState = line.text.length > cm.options.maxHighlightLength ? copyState(doc2.mode, context.state) : null;
  4252. var highlighted = highlightLine(cm, line, context, true);
  4253. if (resetState) {
  4254. context.state = resetState;
  4255. }
  4256. line.styles = highlighted.styles;
  4257. var oldCls = line.styleClasses, newCls = highlighted.classes;
  4258. if (newCls) {
  4259. line.styleClasses = newCls;
  4260. } else if (oldCls) {
  4261. line.styleClasses = null;
  4262. }
  4263. var ischange = !oldStyles || oldStyles.length != line.styles.length || oldCls != newCls && (!oldCls || !newCls || oldCls.bgClass != newCls.bgClass || oldCls.textClass != newCls.textClass);
  4264. for (var i2 = 0; !ischange && i2 < oldStyles.length; ++i2) {
  4265. ischange = oldStyles[i2] != line.styles[i2];
  4266. }
  4267. if (ischange) {
  4268. changedLines.push(context.line);
  4269. }
  4270. line.stateAfter = context.save();
  4271. context.nextLine();
  4272. } else {
  4273. if (line.text.length <= cm.options.maxHighlightLength) {
  4274. processLine(cm, line.text, context);
  4275. }
  4276. line.stateAfter = context.line % 5 == 0 ? context.save() : null;
  4277. context.nextLine();
  4278. }
  4279. if (+/* @__PURE__ */ new Date() > end) {
  4280. startWorker(cm, cm.options.workDelay);
  4281. return true;
  4282. }
  4283. });
  4284. doc2.highlightFrontier = context.line;
  4285. doc2.modeFrontier = Math.max(doc2.modeFrontier, context.line);
  4286. if (changedLines.length) {
  4287. runInOp(cm, function() {
  4288. for (var i2 = 0; i2 < changedLines.length; i2++) {
  4289. regLineChange(cm, changedLines[i2], "text");
  4290. }
  4291. });
  4292. }
  4293. }
  4294. var DisplayUpdate = function(cm, viewport, force) {
  4295. var display = cm.display;
  4296. this.viewport = viewport;
  4297. this.visible = visibleLines(display, cm.doc, viewport);
  4298. this.editorIsHidden = !display.wrapper.offsetWidth;
  4299. this.wrapperHeight = display.wrapper.clientHeight;
  4300. this.wrapperWidth = display.wrapper.clientWidth;
  4301. this.oldDisplayWidth = displayWidth(cm);
  4302. this.force = force;
  4303. this.dims = getDimensions(cm);
  4304. this.events = [];
  4305. };
  4306. DisplayUpdate.prototype.signal = function(emitter, type) {
  4307. if (hasHandler(emitter, type)) {
  4308. this.events.push(arguments);
  4309. }
  4310. };
  4311. DisplayUpdate.prototype.finish = function() {
  4312. for (var i2 = 0; i2 < this.events.length; i2++) {
  4313. signal.apply(null, this.events[i2]);
  4314. }
  4315. };
  4316. function maybeClipScrollbars(cm) {
  4317. var display = cm.display;
  4318. if (!display.scrollbarsClipped && display.scroller.offsetWidth) {
  4319. display.nativeBarWidth = display.scroller.offsetWidth - display.scroller.clientWidth;
  4320. display.heightForcer.style.height = scrollGap(cm) + "px";
  4321. display.sizer.style.marginBottom = -display.nativeBarWidth + "px";
  4322. display.sizer.style.borderRightWidth = scrollGap(cm) + "px";
  4323. display.scrollbarsClipped = true;
  4324. }
  4325. }
  4326. function selectionSnapshot(cm) {
  4327. if (cm.hasFocus()) {
  4328. return null;
  4329. }
  4330. var active = activeElt(doc(cm));
  4331. if (!active || !contains(cm.display.lineDiv, active)) {
  4332. return null;
  4333. }
  4334. var result = { activeElt: active };
  4335. if (window.getSelection) {
  4336. var sel = win(cm).getSelection();
  4337. if (sel.anchorNode && sel.extend && contains(cm.display.lineDiv, sel.anchorNode)) {
  4338. result.anchorNode = sel.anchorNode;
  4339. result.anchorOffset = sel.anchorOffset;
  4340. result.focusNode = sel.focusNode;
  4341. result.focusOffset = sel.focusOffset;
  4342. }
  4343. }
  4344. return result;
  4345. }
  4346. function restoreSelection(snapshot) {
  4347. if (!snapshot || !snapshot.activeElt || snapshot.activeElt == activeElt(snapshot.activeElt.ownerDocument)) {
  4348. return;
  4349. }
  4350. snapshot.activeElt.focus();
  4351. if (!/^(INPUT|TEXTAREA)$/.test(snapshot.activeElt.nodeName) && snapshot.anchorNode && contains(document.body, snapshot.anchorNode) && contains(document.body, snapshot.focusNode)) {
  4352. var doc2 = snapshot.activeElt.ownerDocument;
  4353. var sel = doc2.defaultView.getSelection(), range2 = doc2.createRange();
  4354. range2.setEnd(snapshot.anchorNode, snapshot.anchorOffset);
  4355. range2.collapse(false);
  4356. sel.removeAllRanges();
  4357. sel.addRange(range2);
  4358. sel.extend(snapshot.focusNode, snapshot.focusOffset);
  4359. }
  4360. }
  4361. function updateDisplayIfNeeded(cm, update) {
  4362. var display = cm.display, doc2 = cm.doc;
  4363. if (update.editorIsHidden) {
  4364. resetView(cm);
  4365. return false;
  4366. }
  4367. if (!update.force && update.visible.from >= display.viewFrom && update.visible.to <= display.viewTo && (display.updateLineNumbers == null || display.updateLineNumbers >= display.viewTo) && display.renderedView == display.view && countDirtyView(cm) == 0) {
  4368. return false;
  4369. }
  4370. if (maybeUpdateLineNumberWidth(cm)) {
  4371. resetView(cm);
  4372. update.dims = getDimensions(cm);
  4373. }
  4374. var end = doc2.first + doc2.size;
  4375. var from = Math.max(update.visible.from - cm.options.viewportMargin, doc2.first);
  4376. var to = Math.min(end, update.visible.to + cm.options.viewportMargin);
  4377. if (display.viewFrom < from && from - display.viewFrom < 20) {
  4378. from = Math.max(doc2.first, display.viewFrom);
  4379. }
  4380. if (display.viewTo > to && display.viewTo - to < 20) {
  4381. to = Math.min(end, display.viewTo);
  4382. }
  4383. if (sawCollapsedSpans) {
  4384. from = visualLineNo(cm.doc, from);
  4385. to = visualLineEndNo(cm.doc, to);
  4386. }
  4387. var different = from != display.viewFrom || to != display.viewTo || display.lastWrapHeight != update.wrapperHeight || display.lastWrapWidth != update.wrapperWidth;
  4388. adjustView(cm, from, to);
  4389. display.viewOffset = heightAtLine(getLine(cm.doc, display.viewFrom));
  4390. cm.display.mover.style.top = display.viewOffset + "px";
  4391. var toUpdate = countDirtyView(cm);
  4392. if (!different && toUpdate == 0 && !update.force && display.renderedView == display.view && (display.updateLineNumbers == null || display.updateLineNumbers >= display.viewTo)) {
  4393. return false;
  4394. }
  4395. var selSnapshot = selectionSnapshot(cm);
  4396. if (toUpdate > 4) {
  4397. display.lineDiv.style.display = "none";
  4398. }
  4399. patchDisplay(cm, display.updateLineNumbers, update.dims);
  4400. if (toUpdate > 4) {
  4401. display.lineDiv.style.display = "";
  4402. }
  4403. display.renderedView = display.view;
  4404. restoreSelection(selSnapshot);
  4405. removeChildren(display.cursorDiv);
  4406. removeChildren(display.selectionDiv);
  4407. display.gutters.style.height = display.sizer.style.minHeight = 0;
  4408. if (different) {
  4409. display.lastWrapHeight = update.wrapperHeight;
  4410. display.lastWrapWidth = update.wrapperWidth;
  4411. startWorker(cm, 400);
  4412. }
  4413. display.updateLineNumbers = null;
  4414. return true;
  4415. }
  4416. function postUpdateDisplay(cm, update) {
  4417. var viewport = update.viewport;
  4418. for (var first = true; ; first = false) {
  4419. if (!first || !cm.options.lineWrapping || update.oldDisplayWidth == displayWidth(cm)) {
  4420. if (viewport && viewport.top != null) {
  4421. viewport = { top: Math.min(cm.doc.height + paddingVert(cm.display) - displayHeight(cm), viewport.top) };
  4422. }
  4423. update.visible = visibleLines(cm.display, cm.doc, viewport);
  4424. if (update.visible.from >= cm.display.viewFrom && update.visible.to <= cm.display.viewTo) {
  4425. break;
  4426. }
  4427. } else if (first) {
  4428. update.visible = visibleLines(cm.display, cm.doc, viewport);
  4429. }
  4430. if (!updateDisplayIfNeeded(cm, update)) {
  4431. break;
  4432. }
  4433. updateHeightsInViewport(cm);
  4434. var barMeasure = measureForScrollbars(cm);
  4435. updateSelection(cm);
  4436. updateScrollbars(cm, barMeasure);
  4437. setDocumentHeight(cm, barMeasure);
  4438. update.force = false;
  4439. }
  4440. update.signal(cm, "update", cm);
  4441. if (cm.display.viewFrom != cm.display.reportedViewFrom || cm.display.viewTo != cm.display.reportedViewTo) {
  4442. update.signal(cm, "viewportChange", cm, cm.display.viewFrom, cm.display.viewTo);
  4443. cm.display.reportedViewFrom = cm.display.viewFrom;
  4444. cm.display.reportedViewTo = cm.display.viewTo;
  4445. }
  4446. }
  4447. function updateDisplaySimple(cm, viewport) {
  4448. var update = new DisplayUpdate(cm, viewport);
  4449. if (updateDisplayIfNeeded(cm, update)) {
  4450. updateHeightsInViewport(cm);
  4451. postUpdateDisplay(cm, update);
  4452. var barMeasure = measureForScrollbars(cm);
  4453. updateSelection(cm);
  4454. updateScrollbars(cm, barMeasure);
  4455. setDocumentHeight(cm, barMeasure);
  4456. update.finish();
  4457. }
  4458. }
  4459. function patchDisplay(cm, updateNumbersFrom, dims) {
  4460. var display = cm.display, lineNumbers = cm.options.lineNumbers;
  4461. var container = display.lineDiv, cur = container.firstChild;
  4462. function rm(node2) {
  4463. var next = node2.nextSibling;
  4464. if (webkit && mac && cm.display.currentWheelTarget == node2) {
  4465. node2.style.display = "none";
  4466. } else {
  4467. node2.parentNode.removeChild(node2);
  4468. }
  4469. return next;
  4470. }
  4471. var view = display.view, lineN = display.viewFrom;
  4472. for (var i2 = 0; i2 < view.length; i2++) {
  4473. var lineView = view[i2];
  4474. if (lineView.hidden)
  4475. ;
  4476. else if (!lineView.node || lineView.node.parentNode != container) {
  4477. var node = buildLineElement(cm, lineView, lineN, dims);
  4478. container.insertBefore(node, cur);
  4479. } else {
  4480. while (cur != lineView.node) {
  4481. cur = rm(cur);
  4482. }
  4483. var updateNumber = lineNumbers && updateNumbersFrom != null && updateNumbersFrom <= lineN && lineView.lineNumber;
  4484. if (lineView.changes) {
  4485. if (indexOf(lineView.changes, "gutter") > -1) {
  4486. updateNumber = false;
  4487. }
  4488. updateLineForChanges(cm, lineView, lineN, dims);
  4489. }
  4490. if (updateNumber) {
  4491. removeChildren(lineView.lineNumber);
  4492. lineView.lineNumber.appendChild(document.createTextNode(lineNumberFor(cm.options, lineN)));
  4493. }
  4494. cur = lineView.node.nextSibling;
  4495. }
  4496. lineN += lineView.size;
  4497. }
  4498. while (cur) {
  4499. cur = rm(cur);
  4500. }
  4501. }
  4502. function updateGutterSpace(display) {
  4503. var width = display.gutters.offsetWidth;
  4504. display.sizer.style.marginLeft = width + "px";
  4505. signalLater(display, "gutterChanged", display);
  4506. }
  4507. function setDocumentHeight(cm, measure) {
  4508. cm.display.sizer.style.minHeight = measure.docHeight + "px";
  4509. cm.display.heightForcer.style.top = measure.docHeight + "px";
  4510. cm.display.gutters.style.height = measure.docHeight + cm.display.barHeight + scrollGap(cm) + "px";
  4511. }
  4512. function alignHorizontally(cm) {
  4513. var display = cm.display, view = display.view;
  4514. if (!display.alignWidgets && (!display.gutters.firstChild || !cm.options.fixedGutter)) {
  4515. return;
  4516. }
  4517. var comp = compensateForHScroll(display) - display.scroller.scrollLeft + cm.doc.scrollLeft;
  4518. var gutterW = display.gutters.offsetWidth, left = comp + "px";
  4519. for (var i2 = 0; i2 < view.length; i2++) {
  4520. if (!view[i2].hidden) {
  4521. if (cm.options.fixedGutter) {
  4522. if (view[i2].gutter) {
  4523. view[i2].gutter.style.left = left;
  4524. }
  4525. if (view[i2].gutterBackground) {
  4526. view[i2].gutterBackground.style.left = left;
  4527. }
  4528. }
  4529. var align = view[i2].alignable;
  4530. if (align) {
  4531. for (var j = 0; j < align.length; j++) {
  4532. align[j].style.left = left;
  4533. }
  4534. }
  4535. }
  4536. }
  4537. if (cm.options.fixedGutter) {
  4538. display.gutters.style.left = comp + gutterW + "px";
  4539. }
  4540. }
  4541. function maybeUpdateLineNumberWidth(cm) {
  4542. if (!cm.options.lineNumbers) {
  4543. return false;
  4544. }
  4545. var doc2 = cm.doc, last = lineNumberFor(cm.options, doc2.first + doc2.size - 1), display = cm.display;
  4546. if (last.length != display.lineNumChars) {
  4547. var test = display.measure.appendChild(elt(
  4548. "div",
  4549. [elt("div", last)],
  4550. "CodeMirror-linenumber CodeMirror-gutter-elt"
  4551. ));
  4552. var innerW = test.firstChild.offsetWidth, padding = test.offsetWidth - innerW;
  4553. display.lineGutter.style.width = "";
  4554. display.lineNumInnerWidth = Math.max(innerW, display.lineGutter.offsetWidth - padding) + 1;
  4555. display.lineNumWidth = display.lineNumInnerWidth + padding;
  4556. display.lineNumChars = display.lineNumInnerWidth ? last.length : -1;
  4557. display.lineGutter.style.width = display.lineNumWidth + "px";
  4558. updateGutterSpace(cm.display);
  4559. return true;
  4560. }
  4561. return false;
  4562. }
  4563. function getGutters(gutters, lineNumbers) {
  4564. var result = [], sawLineNumbers = false;
  4565. for (var i2 = 0; i2 < gutters.length; i2++) {
  4566. var name = gutters[i2], style = null;
  4567. if (typeof name != "string") {
  4568. style = name.style;
  4569. name = name.className;
  4570. }
  4571. if (name == "CodeMirror-linenumbers") {
  4572. if (!lineNumbers) {
  4573. continue;
  4574. } else {
  4575. sawLineNumbers = true;
  4576. }
  4577. }
  4578. result.push({ className: name, style });
  4579. }
  4580. if (lineNumbers && !sawLineNumbers) {
  4581. result.push({ className: "CodeMirror-linenumbers", style: null });
  4582. }
  4583. return result;
  4584. }
  4585. function renderGutters(display) {
  4586. var gutters = display.gutters, specs = display.gutterSpecs;
  4587. removeChildren(gutters);
  4588. display.lineGutter = null;
  4589. for (var i2 = 0; i2 < specs.length; ++i2) {
  4590. var ref = specs[i2];
  4591. var className = ref.className;
  4592. var style = ref.style;
  4593. var gElt = gutters.appendChild(elt("div", null, "CodeMirror-gutter " + className));
  4594. if (style) {
  4595. gElt.style.cssText = style;
  4596. }
  4597. if (className == "CodeMirror-linenumbers") {
  4598. display.lineGutter = gElt;
  4599. gElt.style.width = (display.lineNumWidth || 1) + "px";
  4600. }
  4601. }
  4602. gutters.style.display = specs.length ? "" : "none";
  4603. updateGutterSpace(display);
  4604. }
  4605. function updateGutters(cm) {
  4606. renderGutters(cm.display);
  4607. regChange(cm);
  4608. alignHorizontally(cm);
  4609. }
  4610. function Display(place, doc2, input, options) {
  4611. var d = this;
  4612. this.input = input;
  4613. d.scrollbarFiller = elt("div", null, "CodeMirror-scrollbar-filler");
  4614. d.scrollbarFiller.setAttribute("cm-not-content", "true");
  4615. d.gutterFiller = elt("div", null, "CodeMirror-gutter-filler");
  4616. d.gutterFiller.setAttribute("cm-not-content", "true");
  4617. d.lineDiv = eltP("div", null, "CodeMirror-code");
  4618. d.selectionDiv = elt("div", null, null, "position: relative; z-index: 1");
  4619. d.cursorDiv = elt("div", null, "CodeMirror-cursors");
  4620. d.measure = elt("div", null, "CodeMirror-measure");
  4621. d.lineMeasure = elt("div", null, "CodeMirror-measure");
  4622. d.lineSpace = eltP(
  4623. "div",
  4624. [d.measure, d.lineMeasure, d.selectionDiv, d.cursorDiv, d.lineDiv],
  4625. null,
  4626. "position: relative; outline: none"
  4627. );
  4628. var lines = eltP("div", [d.lineSpace], "CodeMirror-lines");
  4629. d.mover = elt("div", [lines], null, "position: relative");
  4630. d.sizer = elt("div", [d.mover], "CodeMirror-sizer");
  4631. d.sizerWidth = null;
  4632. d.heightForcer = elt("div", null, null, "position: absolute; height: " + scrollerGap + "px; width: 1px;");
  4633. d.gutters = elt("div", null, "CodeMirror-gutters");
  4634. d.lineGutter = null;
  4635. d.scroller = elt("div", [d.sizer, d.heightForcer, d.gutters], "CodeMirror-scroll");
  4636. d.scroller.setAttribute("tabIndex", "-1");
  4637. d.wrapper = elt("div", [d.scrollbarFiller, d.gutterFiller, d.scroller], "CodeMirror");
  4638. if (chrome && chrome_version >= 105) {
  4639. d.wrapper.style.clipPath = "inset(0px)";
  4640. }
  4641. d.wrapper.setAttribute("translate", "no");
  4642. if (ie && ie_version < 8) {
  4643. d.gutters.style.zIndex = -1;
  4644. d.scroller.style.paddingRight = 0;
  4645. }
  4646. if (!webkit && !(gecko && mobile)) {
  4647. d.scroller.draggable = true;
  4648. }
  4649. if (place) {
  4650. if (place.appendChild) {
  4651. place.appendChild(d.wrapper);
  4652. } else {
  4653. place(d.wrapper);
  4654. }
  4655. }
  4656. d.viewFrom = d.viewTo = doc2.first;
  4657. d.reportedViewFrom = d.reportedViewTo = doc2.first;
  4658. d.view = [];
  4659. d.renderedView = null;
  4660. d.externalMeasured = null;
  4661. d.viewOffset = 0;
  4662. d.lastWrapHeight = d.lastWrapWidth = 0;
  4663. d.updateLineNumbers = null;
  4664. d.nativeBarWidth = d.barHeight = d.barWidth = 0;
  4665. d.scrollbarsClipped = false;
  4666. d.lineNumWidth = d.lineNumInnerWidth = d.lineNumChars = null;
  4667. d.alignWidgets = false;
  4668. d.cachedCharWidth = d.cachedTextHeight = d.cachedPaddingH = null;
  4669. d.maxLine = null;
  4670. d.maxLineLength = 0;
  4671. d.maxLineChanged = false;
  4672. d.wheelDX = d.wheelDY = d.wheelStartX = d.wheelStartY = null;
  4673. d.shift = false;
  4674. d.selForContextMenu = null;
  4675. d.activeTouch = null;
  4676. d.gutterSpecs = getGutters(options.gutters, options.lineNumbers);
  4677. renderGutters(d);
  4678. input.init(d);
  4679. }
  4680. var wheelSamples = 0, wheelPixelsPerUnit = null;
  4681. if (ie) {
  4682. wheelPixelsPerUnit = -0.53;
  4683. } else if (gecko) {
  4684. wheelPixelsPerUnit = 15;
  4685. } else if (chrome) {
  4686. wheelPixelsPerUnit = -0.7;
  4687. } else if (safari) {
  4688. wheelPixelsPerUnit = -1 / 3;
  4689. }
  4690. function wheelEventDelta(e) {
  4691. var dx = e.wheelDeltaX, dy = e.wheelDeltaY;
  4692. if (dx == null && e.detail && e.axis == e.HORIZONTAL_AXIS) {
  4693. dx = e.detail;
  4694. }
  4695. if (dy == null && e.detail && e.axis == e.VERTICAL_AXIS) {
  4696. dy = e.detail;
  4697. } else if (dy == null) {
  4698. dy = e.wheelDelta;
  4699. }
  4700. return { x: dx, y: dy };
  4701. }
  4702. function wheelEventPixels(e) {
  4703. var delta = wheelEventDelta(e);
  4704. delta.x *= wheelPixelsPerUnit;
  4705. delta.y *= wheelPixelsPerUnit;
  4706. return delta;
  4707. }
  4708. function onScrollWheel(cm, e) {
  4709. if (chrome && chrome_version == 102) {
  4710. if (cm.display.chromeScrollHack == null) {
  4711. cm.display.sizer.style.pointerEvents = "none";
  4712. } else {
  4713. clearTimeout(cm.display.chromeScrollHack);
  4714. }
  4715. cm.display.chromeScrollHack = setTimeout(function() {
  4716. cm.display.chromeScrollHack = null;
  4717. cm.display.sizer.style.pointerEvents = "";
  4718. }, 100);
  4719. }
  4720. var delta = wheelEventDelta(e), dx = delta.x, dy = delta.y;
  4721. var pixelsPerUnit = wheelPixelsPerUnit;
  4722. if (e.deltaMode === 0) {
  4723. dx = e.deltaX;
  4724. dy = e.deltaY;
  4725. pixelsPerUnit = 1;
  4726. }
  4727. var display = cm.display, scroll = display.scroller;
  4728. var canScrollX = scroll.scrollWidth > scroll.clientWidth;
  4729. var canScrollY = scroll.scrollHeight > scroll.clientHeight;
  4730. if (!(dx && canScrollX || dy && canScrollY)) {
  4731. return;
  4732. }
  4733. if (dy && mac && webkit) {
  4734. outer:
  4735. for (var cur = e.target, view = display.view; cur != scroll; cur = cur.parentNode) {
  4736. for (var i2 = 0; i2 < view.length; i2++) {
  4737. if (view[i2].node == cur) {
  4738. cm.display.currentWheelTarget = cur;
  4739. break outer;
  4740. }
  4741. }
  4742. }
  4743. }
  4744. if (dx && !gecko && !presto && pixelsPerUnit != null) {
  4745. if (dy && canScrollY) {
  4746. updateScrollTop(cm, Math.max(0, scroll.scrollTop + dy * pixelsPerUnit));
  4747. }
  4748. setScrollLeft(cm, Math.max(0, scroll.scrollLeft + dx * pixelsPerUnit));
  4749. if (!dy || dy && canScrollY) {
  4750. e_preventDefault(e);
  4751. }
  4752. display.wheelStartX = null;
  4753. return;
  4754. }
  4755. if (dy && pixelsPerUnit != null) {
  4756. var pixels = dy * pixelsPerUnit;
  4757. var top = cm.doc.scrollTop, bot = top + display.wrapper.clientHeight;
  4758. if (pixels < 0) {
  4759. top = Math.max(0, top + pixels - 50);
  4760. } else {
  4761. bot = Math.min(cm.doc.height, bot + pixels + 50);
  4762. }
  4763. updateDisplaySimple(cm, { top, bottom: bot });
  4764. }
  4765. if (wheelSamples < 20 && e.deltaMode !== 0) {
  4766. if (display.wheelStartX == null) {
  4767. display.wheelStartX = scroll.scrollLeft;
  4768. display.wheelStartY = scroll.scrollTop;
  4769. display.wheelDX = dx;
  4770. display.wheelDY = dy;
  4771. setTimeout(function() {
  4772. if (display.wheelStartX == null) {
  4773. return;
  4774. }
  4775. var movedX = scroll.scrollLeft - display.wheelStartX;
  4776. var movedY = scroll.scrollTop - display.wheelStartY;
  4777. var sample = movedY && display.wheelDY && movedY / display.wheelDY || movedX && display.wheelDX && movedX / display.wheelDX;
  4778. display.wheelStartX = display.wheelStartY = null;
  4779. if (!sample) {
  4780. return;
  4781. }
  4782. wheelPixelsPerUnit = (wheelPixelsPerUnit * wheelSamples + sample) / (wheelSamples + 1);
  4783. ++wheelSamples;
  4784. }, 200);
  4785. } else {
  4786. display.wheelDX += dx;
  4787. display.wheelDY += dy;
  4788. }
  4789. }
  4790. }
  4791. var Selection = function(ranges, primIndex) {
  4792. this.ranges = ranges;
  4793. this.primIndex = primIndex;
  4794. };
  4795. Selection.prototype.primary = function() {
  4796. return this.ranges[this.primIndex];
  4797. };
  4798. Selection.prototype.equals = function(other) {
  4799. if (other == this) {
  4800. return true;
  4801. }
  4802. if (other.primIndex != this.primIndex || other.ranges.length != this.ranges.length) {
  4803. return false;
  4804. }
  4805. for (var i2 = 0; i2 < this.ranges.length; i2++) {
  4806. var here = this.ranges[i2], there = other.ranges[i2];
  4807. if (!equalCursorPos(here.anchor, there.anchor) || !equalCursorPos(here.head, there.head)) {
  4808. return false;
  4809. }
  4810. }
  4811. return true;
  4812. };
  4813. Selection.prototype.deepCopy = function() {
  4814. var out = [];
  4815. for (var i2 = 0; i2 < this.ranges.length; i2++) {
  4816. out[i2] = new Range(copyPos(this.ranges[i2].anchor), copyPos(this.ranges[i2].head));
  4817. }
  4818. return new Selection(out, this.primIndex);
  4819. };
  4820. Selection.prototype.somethingSelected = function() {
  4821. for (var i2 = 0; i2 < this.ranges.length; i2++) {
  4822. if (!this.ranges[i2].empty()) {
  4823. return true;
  4824. }
  4825. }
  4826. return false;
  4827. };
  4828. Selection.prototype.contains = function(pos, end) {
  4829. if (!end) {
  4830. end = pos;
  4831. }
  4832. for (var i2 = 0; i2 < this.ranges.length; i2++) {
  4833. var range2 = this.ranges[i2];
  4834. if (cmp(end, range2.from()) >= 0 && cmp(pos, range2.to()) <= 0) {
  4835. return i2;
  4836. }
  4837. }
  4838. return -1;
  4839. };
  4840. var Range = function(anchor, head) {
  4841. this.anchor = anchor;
  4842. this.head = head;
  4843. };
  4844. Range.prototype.from = function() {
  4845. return minPos(this.anchor, this.head);
  4846. };
  4847. Range.prototype.to = function() {
  4848. return maxPos(this.anchor, this.head);
  4849. };
  4850. Range.prototype.empty = function() {
  4851. return this.head.line == this.anchor.line && this.head.ch == this.anchor.ch;
  4852. };
  4853. function normalizeSelection(cm, ranges, primIndex) {
  4854. var mayTouch = cm && cm.options.selectionsMayTouch;
  4855. var prim = ranges[primIndex];
  4856. ranges.sort(function(a, b) {
  4857. return cmp(a.from(), b.from());
  4858. });
  4859. primIndex = indexOf(ranges, prim);
  4860. for (var i2 = 1; i2 < ranges.length; i2++) {
  4861. var cur = ranges[i2], prev = ranges[i2 - 1];
  4862. var diff = cmp(prev.to(), cur.from());
  4863. if (mayTouch && !cur.empty() ? diff > 0 : diff >= 0) {
  4864. var from = minPos(prev.from(), cur.from()), to = maxPos(prev.to(), cur.to());
  4865. var inv = prev.empty() ? cur.from() == cur.head : prev.from() == prev.head;
  4866. if (i2 <= primIndex) {
  4867. --primIndex;
  4868. }
  4869. ranges.splice(--i2, 2, new Range(inv ? to : from, inv ? from : to));
  4870. }
  4871. }
  4872. return new Selection(ranges, primIndex);
  4873. }
  4874. function simpleSelection(anchor, head) {
  4875. return new Selection([new Range(anchor, head || anchor)], 0);
  4876. }
  4877. function changeEnd(change) {
  4878. if (!change.text) {
  4879. return change.to;
  4880. }
  4881. return Pos(
  4882. change.from.line + change.text.length - 1,
  4883. lst(change.text).length + (change.text.length == 1 ? change.from.ch : 0)
  4884. );
  4885. }
  4886. function adjustForChange(pos, change) {
  4887. if (cmp(pos, change.from) < 0) {
  4888. return pos;
  4889. }
  4890. if (cmp(pos, change.to) <= 0) {
  4891. return changeEnd(change);
  4892. }
  4893. var line = pos.line + change.text.length - (change.to.line - change.from.line) - 1, ch = pos.ch;
  4894. if (pos.line == change.to.line) {
  4895. ch += changeEnd(change).ch - change.to.ch;
  4896. }
  4897. return Pos(line, ch);
  4898. }
  4899. function computeSelAfterChange(doc2, change) {
  4900. var out = [];
  4901. for (var i2 = 0; i2 < doc2.sel.ranges.length; i2++) {
  4902. var range2 = doc2.sel.ranges[i2];
  4903. out.push(new Range(
  4904. adjustForChange(range2.anchor, change),
  4905. adjustForChange(range2.head, change)
  4906. ));
  4907. }
  4908. return normalizeSelection(doc2.cm, out, doc2.sel.primIndex);
  4909. }
  4910. function offsetPos(pos, old, nw) {
  4911. if (pos.line == old.line) {
  4912. return Pos(nw.line, pos.ch - old.ch + nw.ch);
  4913. } else {
  4914. return Pos(nw.line + (pos.line - old.line), pos.ch);
  4915. }
  4916. }
  4917. function computeReplacedSel(doc2, changes, hint) {
  4918. var out = [];
  4919. var oldPrev = Pos(doc2.first, 0), newPrev = oldPrev;
  4920. for (var i2 = 0; i2 < changes.length; i2++) {
  4921. var change = changes[i2];
  4922. var from = offsetPos(change.from, oldPrev, newPrev);
  4923. var to = offsetPos(changeEnd(change), oldPrev, newPrev);
  4924. oldPrev = change.to;
  4925. newPrev = to;
  4926. if (hint == "around") {
  4927. var range2 = doc2.sel.ranges[i2], inv = cmp(range2.head, range2.anchor) < 0;
  4928. out[i2] = new Range(inv ? to : from, inv ? from : to);
  4929. } else {
  4930. out[i2] = new Range(from, from);
  4931. }
  4932. }
  4933. return new Selection(out, doc2.sel.primIndex);
  4934. }
  4935. function loadMode(cm) {
  4936. cm.doc.mode = getMode(cm.options, cm.doc.modeOption);
  4937. resetModeState(cm);
  4938. }
  4939. function resetModeState(cm) {
  4940. cm.doc.iter(function(line) {
  4941. if (line.stateAfter) {
  4942. line.stateAfter = null;
  4943. }
  4944. if (line.styles) {
  4945. line.styles = null;
  4946. }
  4947. });
  4948. cm.doc.modeFrontier = cm.doc.highlightFrontier = cm.doc.first;
  4949. startWorker(cm, 100);
  4950. cm.state.modeGen++;
  4951. if (cm.curOp) {
  4952. regChange(cm);
  4953. }
  4954. }
  4955. function isWholeLineUpdate(doc2, change) {
  4956. return change.from.ch == 0 && change.to.ch == 0 && lst(change.text) == "" && (!doc2.cm || doc2.cm.options.wholeLineUpdateBefore);
  4957. }
  4958. function updateDoc(doc2, change, markedSpans, estimateHeight2) {
  4959. function spansFor(n) {
  4960. return markedSpans ? markedSpans[n] : null;
  4961. }
  4962. function update(line, text2, spans) {
  4963. updateLine(line, text2, spans, estimateHeight2);
  4964. signalLater(line, "change", line, change);
  4965. }
  4966. function linesFor(start, end) {
  4967. var result = [];
  4968. for (var i2 = start; i2 < end; ++i2) {
  4969. result.push(new Line(text[i2], spansFor(i2), estimateHeight2));
  4970. }
  4971. return result;
  4972. }
  4973. var from = change.from, to = change.to, text = change.text;
  4974. var firstLine = getLine(doc2, from.line), lastLine = getLine(doc2, to.line);
  4975. var lastText = lst(text), lastSpans = spansFor(text.length - 1), nlines = to.line - from.line;
  4976. if (change.full) {
  4977. doc2.insert(0, linesFor(0, text.length));
  4978. doc2.remove(text.length, doc2.size - text.length);
  4979. } else if (isWholeLineUpdate(doc2, change)) {
  4980. var added = linesFor(0, text.length - 1);
  4981. update(lastLine, lastLine.text, lastSpans);
  4982. if (nlines) {
  4983. doc2.remove(from.line, nlines);
  4984. }
  4985. if (added.length) {
  4986. doc2.insert(from.line, added);
  4987. }
  4988. } else if (firstLine == lastLine) {
  4989. if (text.length == 1) {
  4990. update(firstLine, firstLine.text.slice(0, from.ch) + lastText + firstLine.text.slice(to.ch), lastSpans);
  4991. } else {
  4992. var added$1 = linesFor(1, text.length - 1);
  4993. added$1.push(new Line(lastText + firstLine.text.slice(to.ch), lastSpans, estimateHeight2));
  4994. update(firstLine, firstLine.text.slice(0, from.ch) + text[0], spansFor(0));
  4995. doc2.insert(from.line + 1, added$1);
  4996. }
  4997. } else if (text.length == 1) {
  4998. update(firstLine, firstLine.text.slice(0, from.ch) + text[0] + lastLine.text.slice(to.ch), spansFor(0));
  4999. doc2.remove(from.line + 1, nlines);
  5000. } else {
  5001. update(firstLine, firstLine.text.slice(0, from.ch) + text[0], spansFor(0));
  5002. update(lastLine, lastText + lastLine.text.slice(to.ch), lastSpans);
  5003. var added$2 = linesFor(1, text.length - 1);
  5004. if (nlines > 1) {
  5005. doc2.remove(from.line + 1, nlines - 1);
  5006. }
  5007. doc2.insert(from.line + 1, added$2);
  5008. }
  5009. signalLater(doc2, "change", doc2, change);
  5010. }
  5011. function linkedDocs(doc2, f, sharedHistOnly) {
  5012. function propagate(doc3, skip, sharedHist) {
  5013. if (doc3.linked) {
  5014. for (var i2 = 0; i2 < doc3.linked.length; ++i2) {
  5015. var rel = doc3.linked[i2];
  5016. if (rel.doc == skip) {
  5017. continue;
  5018. }
  5019. var shared = sharedHist && rel.sharedHist;
  5020. if (sharedHistOnly && !shared) {
  5021. continue;
  5022. }
  5023. f(rel.doc, shared);
  5024. propagate(rel.doc, doc3, shared);
  5025. }
  5026. }
  5027. }
  5028. propagate(doc2, null, true);
  5029. }
  5030. function attachDoc(cm, doc2) {
  5031. if (doc2.cm) {
  5032. throw new Error("This document is already in use.");
  5033. }
  5034. cm.doc = doc2;
  5035. doc2.cm = cm;
  5036. estimateLineHeights(cm);
  5037. loadMode(cm);
  5038. setDirectionClass(cm);
  5039. cm.options.direction = doc2.direction;
  5040. if (!cm.options.lineWrapping) {
  5041. findMaxLine(cm);
  5042. }
  5043. cm.options.mode = doc2.modeOption;
  5044. regChange(cm);
  5045. }
  5046. function setDirectionClass(cm) {
  5047. (cm.doc.direction == "rtl" ? addClass : rmClass)(cm.display.lineDiv, "CodeMirror-rtl");
  5048. }
  5049. function directionChanged(cm) {
  5050. runInOp(cm, function() {
  5051. setDirectionClass(cm);
  5052. regChange(cm);
  5053. });
  5054. }
  5055. function History(prev) {
  5056. this.done = [];
  5057. this.undone = [];
  5058. this.undoDepth = prev ? prev.undoDepth : Infinity;
  5059. this.lastModTime = this.lastSelTime = 0;
  5060. this.lastOp = this.lastSelOp = null;
  5061. this.lastOrigin = this.lastSelOrigin = null;
  5062. this.generation = this.maxGeneration = prev ? prev.maxGeneration : 1;
  5063. }
  5064. function historyChangeFromChange(doc2, change) {
  5065. var histChange = { from: copyPos(change.from), to: changeEnd(change), text: getBetween(doc2, change.from, change.to) };
  5066. attachLocalSpans(doc2, histChange, change.from.line, change.to.line + 1);
  5067. linkedDocs(doc2, function(doc3) {
  5068. return attachLocalSpans(doc3, histChange, change.from.line, change.to.line + 1);
  5069. }, true);
  5070. return histChange;
  5071. }
  5072. function clearSelectionEvents(array) {
  5073. while (array.length) {
  5074. var last = lst(array);
  5075. if (last.ranges) {
  5076. array.pop();
  5077. } else {
  5078. break;
  5079. }
  5080. }
  5081. }
  5082. function lastChangeEvent(hist, force) {
  5083. if (force) {
  5084. clearSelectionEvents(hist.done);
  5085. return lst(hist.done);
  5086. } else if (hist.done.length && !lst(hist.done).ranges) {
  5087. return lst(hist.done);
  5088. } else if (hist.done.length > 1 && !hist.done[hist.done.length - 2].ranges) {
  5089. hist.done.pop();
  5090. return lst(hist.done);
  5091. }
  5092. }
  5093. function addChangeToHistory(doc2, change, selAfter, opId) {
  5094. var hist = doc2.history;
  5095. hist.undone.length = 0;
  5096. var time = +/* @__PURE__ */ new Date(), cur;
  5097. var last;
  5098. if ((hist.lastOp == opId || hist.lastOrigin == change.origin && change.origin && (change.origin.charAt(0) == "+" && hist.lastModTime > time - (doc2.cm ? doc2.cm.options.historyEventDelay : 500) || change.origin.charAt(0) == "*")) && (cur = lastChangeEvent(hist, hist.lastOp == opId))) {
  5099. last = lst(cur.changes);
  5100. if (cmp(change.from, change.to) == 0 && cmp(change.from, last.to) == 0) {
  5101. last.to = changeEnd(change);
  5102. } else {
  5103. cur.changes.push(historyChangeFromChange(doc2, change));
  5104. }
  5105. } else {
  5106. var before = lst(hist.done);
  5107. if (!before || !before.ranges) {
  5108. pushSelectionToHistory(doc2.sel, hist.done);
  5109. }
  5110. cur = {
  5111. changes: [historyChangeFromChange(doc2, change)],
  5112. generation: hist.generation
  5113. };
  5114. hist.done.push(cur);
  5115. while (hist.done.length > hist.undoDepth) {
  5116. hist.done.shift();
  5117. if (!hist.done[0].ranges) {
  5118. hist.done.shift();
  5119. }
  5120. }
  5121. }
  5122. hist.done.push(selAfter);
  5123. hist.generation = ++hist.maxGeneration;
  5124. hist.lastModTime = hist.lastSelTime = time;
  5125. hist.lastOp = hist.lastSelOp = opId;
  5126. hist.lastOrigin = hist.lastSelOrigin = change.origin;
  5127. if (!last) {
  5128. signal(doc2, "historyAdded");
  5129. }
  5130. }
  5131. function selectionEventCanBeMerged(doc2, origin, prev, sel) {
  5132. var ch = origin.charAt(0);
  5133. return ch == "*" || ch == "+" && prev.ranges.length == sel.ranges.length && prev.somethingSelected() == sel.somethingSelected() && /* @__PURE__ */ new Date() - doc2.history.lastSelTime <= (doc2.cm ? doc2.cm.options.historyEventDelay : 500);
  5134. }
  5135. function addSelectionToHistory(doc2, sel, opId, options) {
  5136. var hist = doc2.history, origin = options && options.origin;
  5137. if (opId == hist.lastSelOp || origin && hist.lastSelOrigin == origin && (hist.lastModTime == hist.lastSelTime && hist.lastOrigin == origin || selectionEventCanBeMerged(doc2, origin, lst(hist.done), sel))) {
  5138. hist.done[hist.done.length - 1] = sel;
  5139. } else {
  5140. pushSelectionToHistory(sel, hist.done);
  5141. }
  5142. hist.lastSelTime = +/* @__PURE__ */ new Date();
  5143. hist.lastSelOrigin = origin;
  5144. hist.lastSelOp = opId;
  5145. if (options && options.clearRedo !== false) {
  5146. clearSelectionEvents(hist.undone);
  5147. }
  5148. }
  5149. function pushSelectionToHistory(sel, dest) {
  5150. var top = lst(dest);
  5151. if (!(top && top.ranges && top.equals(sel))) {
  5152. dest.push(sel);
  5153. }
  5154. }
  5155. function attachLocalSpans(doc2, change, from, to) {
  5156. var existing = change["spans_" + doc2.id], n = 0;
  5157. doc2.iter(Math.max(doc2.first, from), Math.min(doc2.first + doc2.size, to), function(line) {
  5158. if (line.markedSpans) {
  5159. (existing || (existing = change["spans_" + doc2.id] = {}))[n] = line.markedSpans;
  5160. }
  5161. ++n;
  5162. });
  5163. }
  5164. function removeClearedSpans(spans) {
  5165. if (!spans) {
  5166. return null;
  5167. }
  5168. var out;
  5169. for (var i2 = 0; i2 < spans.length; ++i2) {
  5170. if (spans[i2].marker.explicitlyCleared) {
  5171. if (!out) {
  5172. out = spans.slice(0, i2);
  5173. }
  5174. } else if (out) {
  5175. out.push(spans[i2]);
  5176. }
  5177. }
  5178. return !out ? spans : out.length ? out : null;
  5179. }
  5180. function getOldSpans(doc2, change) {
  5181. var found = change["spans_" + doc2.id];
  5182. if (!found) {
  5183. return null;
  5184. }
  5185. var nw = [];
  5186. for (var i2 = 0; i2 < change.text.length; ++i2) {
  5187. nw.push(removeClearedSpans(found[i2]));
  5188. }
  5189. return nw;
  5190. }
  5191. function mergeOldSpans(doc2, change) {
  5192. var old = getOldSpans(doc2, change);
  5193. var stretched = stretchSpansOverChange(doc2, change);
  5194. if (!old) {
  5195. return stretched;
  5196. }
  5197. if (!stretched) {
  5198. return old;
  5199. }
  5200. for (var i2 = 0; i2 < old.length; ++i2) {
  5201. var oldCur = old[i2], stretchCur = stretched[i2];
  5202. if (oldCur && stretchCur) {
  5203. spans:
  5204. for (var j = 0; j < stretchCur.length; ++j) {
  5205. var span = stretchCur[j];
  5206. for (var k = 0; k < oldCur.length; ++k) {
  5207. if (oldCur[k].marker == span.marker) {
  5208. continue spans;
  5209. }
  5210. }
  5211. oldCur.push(span);
  5212. }
  5213. } else if (stretchCur) {
  5214. old[i2] = stretchCur;
  5215. }
  5216. }
  5217. return old;
  5218. }
  5219. function copyHistoryArray(events, newGroup, instantiateSel) {
  5220. var copy = [];
  5221. for (var i2 = 0; i2 < events.length; ++i2) {
  5222. var event = events[i2];
  5223. if (event.ranges) {
  5224. copy.push(instantiateSel ? Selection.prototype.deepCopy.call(event) : event);
  5225. continue;
  5226. }
  5227. var changes = event.changes, newChanges = [];
  5228. copy.push({ changes: newChanges });
  5229. for (var j = 0; j < changes.length; ++j) {
  5230. var change = changes[j], m = void 0;
  5231. newChanges.push({ from: change.from, to: change.to, text: change.text });
  5232. if (newGroup) {
  5233. for (var prop2 in change) {
  5234. if (m = prop2.match(/^spans_(\d+)$/)) {
  5235. if (indexOf(newGroup, Number(m[1])) > -1) {
  5236. lst(newChanges)[prop2] = change[prop2];
  5237. delete change[prop2];
  5238. }
  5239. }
  5240. }
  5241. }
  5242. }
  5243. }
  5244. return copy;
  5245. }
  5246. function extendRange(range2, head, other, extend) {
  5247. if (extend) {
  5248. var anchor = range2.anchor;
  5249. if (other) {
  5250. var posBefore = cmp(head, anchor) < 0;
  5251. if (posBefore != cmp(other, anchor) < 0) {
  5252. anchor = head;
  5253. head = other;
  5254. } else if (posBefore != cmp(head, other) < 0) {
  5255. head = other;
  5256. }
  5257. }
  5258. return new Range(anchor, head);
  5259. } else {
  5260. return new Range(other || head, head);
  5261. }
  5262. }
  5263. function extendSelection(doc2, head, other, options, extend) {
  5264. if (extend == null) {
  5265. extend = doc2.cm && (doc2.cm.display.shift || doc2.extend);
  5266. }
  5267. setSelection(doc2, new Selection([extendRange(doc2.sel.primary(), head, other, extend)], 0), options);
  5268. }
  5269. function extendSelections(doc2, heads, options) {
  5270. var out = [];
  5271. var extend = doc2.cm && (doc2.cm.display.shift || doc2.extend);
  5272. for (var i2 = 0; i2 < doc2.sel.ranges.length; i2++) {
  5273. out[i2] = extendRange(doc2.sel.ranges[i2], heads[i2], null, extend);
  5274. }
  5275. var newSel = normalizeSelection(doc2.cm, out, doc2.sel.primIndex);
  5276. setSelection(doc2, newSel, options);
  5277. }
  5278. function replaceOneSelection(doc2, i2, range2, options) {
  5279. var ranges = doc2.sel.ranges.slice(0);
  5280. ranges[i2] = range2;
  5281. setSelection(doc2, normalizeSelection(doc2.cm, ranges, doc2.sel.primIndex), options);
  5282. }
  5283. function setSimpleSelection(doc2, anchor, head, options) {
  5284. setSelection(doc2, simpleSelection(anchor, head), options);
  5285. }
  5286. function filterSelectionChange(doc2, sel, options) {
  5287. var obj = {
  5288. ranges: sel.ranges,
  5289. update: function(ranges) {
  5290. this.ranges = [];
  5291. for (var i2 = 0; i2 < ranges.length; i2++) {
  5292. this.ranges[i2] = new Range(
  5293. clipPos(doc2, ranges[i2].anchor),
  5294. clipPos(doc2, ranges[i2].head)
  5295. );
  5296. }
  5297. },
  5298. origin: options && options.origin
  5299. };
  5300. signal(doc2, "beforeSelectionChange", doc2, obj);
  5301. if (doc2.cm) {
  5302. signal(doc2.cm, "beforeSelectionChange", doc2.cm, obj);
  5303. }
  5304. if (obj.ranges != sel.ranges) {
  5305. return normalizeSelection(doc2.cm, obj.ranges, obj.ranges.length - 1);
  5306. } else {
  5307. return sel;
  5308. }
  5309. }
  5310. function setSelectionReplaceHistory(doc2, sel, options) {
  5311. var done = doc2.history.done, last = lst(done);
  5312. if (last && last.ranges) {
  5313. done[done.length - 1] = sel;
  5314. setSelectionNoUndo(doc2, sel, options);
  5315. } else {
  5316. setSelection(doc2, sel, options);
  5317. }
  5318. }
  5319. function setSelection(doc2, sel, options) {
  5320. setSelectionNoUndo(doc2, sel, options);
  5321. addSelectionToHistory(doc2, doc2.sel, doc2.cm ? doc2.cm.curOp.id : NaN, options);
  5322. }
  5323. function setSelectionNoUndo(doc2, sel, options) {
  5324. if (hasHandler(doc2, "beforeSelectionChange") || doc2.cm && hasHandler(doc2.cm, "beforeSelectionChange")) {
  5325. sel = filterSelectionChange(doc2, sel, options);
  5326. }
  5327. var bias = options && options.bias || (cmp(sel.primary().head, doc2.sel.primary().head) < 0 ? -1 : 1);
  5328. setSelectionInner(doc2, skipAtomicInSelection(doc2, sel, bias, true));
  5329. if (!(options && options.scroll === false) && doc2.cm && doc2.cm.getOption("readOnly") != "nocursor") {
  5330. ensureCursorVisible(doc2.cm);
  5331. }
  5332. }
  5333. function setSelectionInner(doc2, sel) {
  5334. if (sel.equals(doc2.sel)) {
  5335. return;
  5336. }
  5337. doc2.sel = sel;
  5338. if (doc2.cm) {
  5339. doc2.cm.curOp.updateInput = 1;
  5340. doc2.cm.curOp.selectionChanged = true;
  5341. signalCursorActivity(doc2.cm);
  5342. }
  5343. signalLater(doc2, "cursorActivity", doc2);
  5344. }
  5345. function reCheckSelection(doc2) {
  5346. setSelectionInner(doc2, skipAtomicInSelection(doc2, doc2.sel, null, false));
  5347. }
  5348. function skipAtomicInSelection(doc2, sel, bias, mayClear) {
  5349. var out;
  5350. for (var i2 = 0; i2 < sel.ranges.length; i2++) {
  5351. var range2 = sel.ranges[i2];
  5352. var old = sel.ranges.length == doc2.sel.ranges.length && doc2.sel.ranges[i2];
  5353. var newAnchor = skipAtomic(doc2, range2.anchor, old && old.anchor, bias, mayClear);
  5354. var newHead = range2.head == range2.anchor ? newAnchor : skipAtomic(doc2, range2.head, old && old.head, bias, mayClear);
  5355. if (out || newAnchor != range2.anchor || newHead != range2.head) {
  5356. if (!out) {
  5357. out = sel.ranges.slice(0, i2);
  5358. }
  5359. out[i2] = new Range(newAnchor, newHead);
  5360. }
  5361. }
  5362. return out ? normalizeSelection(doc2.cm, out, sel.primIndex) : sel;
  5363. }
  5364. function skipAtomicInner(doc2, pos, oldPos, dir, mayClear) {
  5365. var line = getLine(doc2, pos.line);
  5366. if (line.markedSpans) {
  5367. for (var i2 = 0; i2 < line.markedSpans.length; ++i2) {
  5368. var sp = line.markedSpans[i2], m = sp.marker;
  5369. var preventCursorLeft = "selectLeft" in m ? !m.selectLeft : m.inclusiveLeft;
  5370. var preventCursorRight = "selectRight" in m ? !m.selectRight : m.inclusiveRight;
  5371. if ((sp.from == null || (preventCursorLeft ? sp.from <= pos.ch : sp.from < pos.ch)) && (sp.to == null || (preventCursorRight ? sp.to >= pos.ch : sp.to > pos.ch))) {
  5372. if (mayClear) {
  5373. signal(m, "beforeCursorEnter");
  5374. if (m.explicitlyCleared) {
  5375. if (!line.markedSpans) {
  5376. break;
  5377. } else {
  5378. --i2;
  5379. continue;
  5380. }
  5381. }
  5382. }
  5383. if (!m.atomic) {
  5384. continue;
  5385. }
  5386. if (oldPos) {
  5387. var near = m.find(dir < 0 ? 1 : -1), diff = void 0;
  5388. if (dir < 0 ? preventCursorRight : preventCursorLeft) {
  5389. near = movePos(doc2, near, -dir, near && near.line == pos.line ? line : null);
  5390. }
  5391. if (near && near.line == pos.line && (diff = cmp(near, oldPos)) && (dir < 0 ? diff < 0 : diff > 0)) {
  5392. return skipAtomicInner(doc2, near, pos, dir, mayClear);
  5393. }
  5394. }
  5395. var far = m.find(dir < 0 ? -1 : 1);
  5396. if (dir < 0 ? preventCursorLeft : preventCursorRight) {
  5397. far = movePos(doc2, far, dir, far.line == pos.line ? line : null);
  5398. }
  5399. return far ? skipAtomicInner(doc2, far, pos, dir, mayClear) : null;
  5400. }
  5401. }
  5402. }
  5403. return pos;
  5404. }
  5405. function skipAtomic(doc2, pos, oldPos, bias, mayClear) {
  5406. var dir = bias || 1;
  5407. var found = skipAtomicInner(doc2, pos, oldPos, dir, mayClear) || !mayClear && skipAtomicInner(doc2, pos, oldPos, dir, true) || skipAtomicInner(doc2, pos, oldPos, -dir, mayClear) || !mayClear && skipAtomicInner(doc2, pos, oldPos, -dir, true);
  5408. if (!found) {
  5409. doc2.cantEdit = true;
  5410. return Pos(doc2.first, 0);
  5411. }
  5412. return found;
  5413. }
  5414. function movePos(doc2, pos, dir, line) {
  5415. if (dir < 0 && pos.ch == 0) {
  5416. if (pos.line > doc2.first) {
  5417. return clipPos(doc2, Pos(pos.line - 1));
  5418. } else {
  5419. return null;
  5420. }
  5421. } else if (dir > 0 && pos.ch == (line || getLine(doc2, pos.line)).text.length) {
  5422. if (pos.line < doc2.first + doc2.size - 1) {
  5423. return Pos(pos.line + 1, 0);
  5424. } else {
  5425. return null;
  5426. }
  5427. } else {
  5428. return new Pos(pos.line, pos.ch + dir);
  5429. }
  5430. }
  5431. function selectAll(cm) {
  5432. cm.setSelection(Pos(cm.firstLine(), 0), Pos(cm.lastLine()), sel_dontScroll);
  5433. }
  5434. function filterChange(doc2, change, update) {
  5435. var obj = {
  5436. canceled: false,
  5437. from: change.from,
  5438. to: change.to,
  5439. text: change.text,
  5440. origin: change.origin,
  5441. cancel: function() {
  5442. return obj.canceled = true;
  5443. }
  5444. };
  5445. if (update) {
  5446. obj.update = function(from, to, text, origin) {
  5447. if (from) {
  5448. obj.from = clipPos(doc2, from);
  5449. }
  5450. if (to) {
  5451. obj.to = clipPos(doc2, to);
  5452. }
  5453. if (text) {
  5454. obj.text = text;
  5455. }
  5456. if (origin !== void 0) {
  5457. obj.origin = origin;
  5458. }
  5459. };
  5460. }
  5461. signal(doc2, "beforeChange", doc2, obj);
  5462. if (doc2.cm) {
  5463. signal(doc2.cm, "beforeChange", doc2.cm, obj);
  5464. }
  5465. if (obj.canceled) {
  5466. if (doc2.cm) {
  5467. doc2.cm.curOp.updateInput = 2;
  5468. }
  5469. return null;
  5470. }
  5471. return { from: obj.from, to: obj.to, text: obj.text, origin: obj.origin };
  5472. }
  5473. function makeChange(doc2, change, ignoreReadOnly) {
  5474. if (doc2.cm) {
  5475. if (!doc2.cm.curOp) {
  5476. return operation(doc2.cm, makeChange)(doc2, change, ignoreReadOnly);
  5477. }
  5478. if (doc2.cm.state.suppressEdits) {
  5479. return;
  5480. }
  5481. }
  5482. if (hasHandler(doc2, "beforeChange") || doc2.cm && hasHandler(doc2.cm, "beforeChange")) {
  5483. change = filterChange(doc2, change, true);
  5484. if (!change) {
  5485. return;
  5486. }
  5487. }
  5488. var split = sawReadOnlySpans && !ignoreReadOnly && removeReadOnlyRanges(doc2, change.from, change.to);
  5489. if (split) {
  5490. for (var i2 = split.length - 1; i2 >= 0; --i2) {
  5491. makeChangeInner(doc2, { from: split[i2].from, to: split[i2].to, text: i2 ? [""] : change.text, origin: change.origin });
  5492. }
  5493. } else {
  5494. makeChangeInner(doc2, change);
  5495. }
  5496. }
  5497. function makeChangeInner(doc2, change) {
  5498. if (change.text.length == 1 && change.text[0] == "" && cmp(change.from, change.to) == 0) {
  5499. return;
  5500. }
  5501. var selAfter = computeSelAfterChange(doc2, change);
  5502. addChangeToHistory(doc2, change, selAfter, doc2.cm ? doc2.cm.curOp.id : NaN);
  5503. makeChangeSingleDoc(doc2, change, selAfter, stretchSpansOverChange(doc2, change));
  5504. var rebased = [];
  5505. linkedDocs(doc2, function(doc3, sharedHist) {
  5506. if (!sharedHist && indexOf(rebased, doc3.history) == -1) {
  5507. rebaseHist(doc3.history, change);
  5508. rebased.push(doc3.history);
  5509. }
  5510. makeChangeSingleDoc(doc3, change, null, stretchSpansOverChange(doc3, change));
  5511. });
  5512. }
  5513. function makeChangeFromHistory(doc2, type, allowSelectionOnly) {
  5514. var suppress = doc2.cm && doc2.cm.state.suppressEdits;
  5515. if (suppress && !allowSelectionOnly) {
  5516. return;
  5517. }
  5518. var hist = doc2.history, event, selAfter = doc2.sel;
  5519. var source = type == "undo" ? hist.done : hist.undone, dest = type == "undo" ? hist.undone : hist.done;
  5520. var i2 = 0;
  5521. for (; i2 < source.length; i2++) {
  5522. event = source[i2];
  5523. if (allowSelectionOnly ? event.ranges && !event.equals(doc2.sel) : !event.ranges) {
  5524. break;
  5525. }
  5526. }
  5527. if (i2 == source.length) {
  5528. return;
  5529. }
  5530. hist.lastOrigin = hist.lastSelOrigin = null;
  5531. for (; ; ) {
  5532. event = source.pop();
  5533. if (event.ranges) {
  5534. pushSelectionToHistory(event, dest);
  5535. if (allowSelectionOnly && !event.equals(doc2.sel)) {
  5536. setSelection(doc2, event, { clearRedo: false });
  5537. return;
  5538. }
  5539. selAfter = event;
  5540. } else if (suppress) {
  5541. source.push(event);
  5542. return;
  5543. } else {
  5544. break;
  5545. }
  5546. }
  5547. var antiChanges = [];
  5548. pushSelectionToHistory(selAfter, dest);
  5549. dest.push({ changes: antiChanges, generation: hist.generation });
  5550. hist.generation = event.generation || ++hist.maxGeneration;
  5551. var filter = hasHandler(doc2, "beforeChange") || doc2.cm && hasHandler(doc2.cm, "beforeChange");
  5552. var loop = function(i3) {
  5553. var change = event.changes[i3];
  5554. change.origin = type;
  5555. if (filter && !filterChange(doc2, change, false)) {
  5556. source.length = 0;
  5557. return {};
  5558. }
  5559. antiChanges.push(historyChangeFromChange(doc2, change));
  5560. var after = i3 ? computeSelAfterChange(doc2, change) : lst(source);
  5561. makeChangeSingleDoc(doc2, change, after, mergeOldSpans(doc2, change));
  5562. if (!i3 && doc2.cm) {
  5563. doc2.cm.scrollIntoView({ from: change.from, to: changeEnd(change) });
  5564. }
  5565. var rebased = [];
  5566. linkedDocs(doc2, function(doc3, sharedHist) {
  5567. if (!sharedHist && indexOf(rebased, doc3.history) == -1) {
  5568. rebaseHist(doc3.history, change);
  5569. rebased.push(doc3.history);
  5570. }
  5571. makeChangeSingleDoc(doc3, change, null, mergeOldSpans(doc3, change));
  5572. });
  5573. };
  5574. for (var i$12 = event.changes.length - 1; i$12 >= 0; --i$12) {
  5575. var returned = loop(i$12);
  5576. if (returned)
  5577. return returned.v;
  5578. }
  5579. }
  5580. function shiftDoc(doc2, distance) {
  5581. if (distance == 0) {
  5582. return;
  5583. }
  5584. doc2.first += distance;
  5585. doc2.sel = new Selection(map(doc2.sel.ranges, function(range2) {
  5586. return new Range(
  5587. Pos(range2.anchor.line + distance, range2.anchor.ch),
  5588. Pos(range2.head.line + distance, range2.head.ch)
  5589. );
  5590. }), doc2.sel.primIndex);
  5591. if (doc2.cm) {
  5592. regChange(doc2.cm, doc2.first, doc2.first - distance, distance);
  5593. for (var d = doc2.cm.display, l = d.viewFrom; l < d.viewTo; l++) {
  5594. regLineChange(doc2.cm, l, "gutter");
  5595. }
  5596. }
  5597. }
  5598. function makeChangeSingleDoc(doc2, change, selAfter, spans) {
  5599. if (doc2.cm && !doc2.cm.curOp) {
  5600. return operation(doc2.cm, makeChangeSingleDoc)(doc2, change, selAfter, spans);
  5601. }
  5602. if (change.to.line < doc2.first) {
  5603. shiftDoc(doc2, change.text.length - 1 - (change.to.line - change.from.line));
  5604. return;
  5605. }
  5606. if (change.from.line > doc2.lastLine()) {
  5607. return;
  5608. }
  5609. if (change.from.line < doc2.first) {
  5610. var shift = change.text.length - 1 - (doc2.first - change.from.line);
  5611. shiftDoc(doc2, shift);
  5612. change = {
  5613. from: Pos(doc2.first, 0),
  5614. to: Pos(change.to.line + shift, change.to.ch),
  5615. text: [lst(change.text)],
  5616. origin: change.origin
  5617. };
  5618. }
  5619. var last = doc2.lastLine();
  5620. if (change.to.line > last) {
  5621. change = {
  5622. from: change.from,
  5623. to: Pos(last, getLine(doc2, last).text.length),
  5624. text: [change.text[0]],
  5625. origin: change.origin
  5626. };
  5627. }
  5628. change.removed = getBetween(doc2, change.from, change.to);
  5629. if (!selAfter) {
  5630. selAfter = computeSelAfterChange(doc2, change);
  5631. }
  5632. if (doc2.cm) {
  5633. makeChangeSingleDocInEditor(doc2.cm, change, spans);
  5634. } else {
  5635. updateDoc(doc2, change, spans);
  5636. }
  5637. setSelectionNoUndo(doc2, selAfter, sel_dontScroll);
  5638. if (doc2.cantEdit && skipAtomic(doc2, Pos(doc2.firstLine(), 0))) {
  5639. doc2.cantEdit = false;
  5640. }
  5641. }
  5642. function makeChangeSingleDocInEditor(cm, change, spans) {
  5643. var doc2 = cm.doc, display = cm.display, from = change.from, to = change.to;
  5644. var recomputeMaxLength = false, checkWidthStart = from.line;
  5645. if (!cm.options.lineWrapping) {
  5646. checkWidthStart = lineNo(visualLine(getLine(doc2, from.line)));
  5647. doc2.iter(checkWidthStart, to.line + 1, function(line) {
  5648. if (line == display.maxLine) {
  5649. recomputeMaxLength = true;
  5650. return true;
  5651. }
  5652. });
  5653. }
  5654. if (doc2.sel.contains(change.from, change.to) > -1) {
  5655. signalCursorActivity(cm);
  5656. }
  5657. updateDoc(doc2, change, spans, estimateHeight(cm));
  5658. if (!cm.options.lineWrapping) {
  5659. doc2.iter(checkWidthStart, from.line + change.text.length, function(line) {
  5660. var len = lineLength(line);
  5661. if (len > display.maxLineLength) {
  5662. display.maxLine = line;
  5663. display.maxLineLength = len;
  5664. display.maxLineChanged = true;
  5665. recomputeMaxLength = false;
  5666. }
  5667. });
  5668. if (recomputeMaxLength) {
  5669. cm.curOp.updateMaxLine = true;
  5670. }
  5671. }
  5672. retreatFrontier(doc2, from.line);
  5673. startWorker(cm, 400);
  5674. var lendiff = change.text.length - (to.line - from.line) - 1;
  5675. if (change.full) {
  5676. regChange(cm);
  5677. } else if (from.line == to.line && change.text.length == 1 && !isWholeLineUpdate(cm.doc, change)) {
  5678. regLineChange(cm, from.line, "text");
  5679. } else {
  5680. regChange(cm, from.line, to.line + 1, lendiff);
  5681. }
  5682. var changesHandler = hasHandler(cm, "changes"), changeHandler = hasHandler(cm, "change");
  5683. if (changeHandler || changesHandler) {
  5684. var obj = {
  5685. from,
  5686. to,
  5687. text: change.text,
  5688. removed: change.removed,
  5689. origin: change.origin
  5690. };
  5691. if (changeHandler) {
  5692. signalLater(cm, "change", cm, obj);
  5693. }
  5694. if (changesHandler) {
  5695. (cm.curOp.changeObjs || (cm.curOp.changeObjs = [])).push(obj);
  5696. }
  5697. }
  5698. cm.display.selForContextMenu = null;
  5699. }
  5700. function replaceRange(doc2, code, from, to, origin) {
  5701. var assign;
  5702. if (!to) {
  5703. to = from;
  5704. }
  5705. if (cmp(to, from) < 0) {
  5706. assign = [to, from], from = assign[0], to = assign[1];
  5707. }
  5708. if (typeof code == "string") {
  5709. code = doc2.splitLines(code);
  5710. }
  5711. makeChange(doc2, { from, to, text: code, origin });
  5712. }
  5713. function rebaseHistSelSingle(pos, from, to, diff) {
  5714. if (to < pos.line) {
  5715. pos.line += diff;
  5716. } else if (from < pos.line) {
  5717. pos.line = from;
  5718. pos.ch = 0;
  5719. }
  5720. }
  5721. function rebaseHistArray(array, from, to, diff) {
  5722. for (var i2 = 0; i2 < array.length; ++i2) {
  5723. var sub = array[i2], ok = true;
  5724. if (sub.ranges) {
  5725. if (!sub.copied) {
  5726. sub = array[i2] = sub.deepCopy();
  5727. sub.copied = true;
  5728. }
  5729. for (var j = 0; j < sub.ranges.length; j++) {
  5730. rebaseHistSelSingle(sub.ranges[j].anchor, from, to, diff);
  5731. rebaseHistSelSingle(sub.ranges[j].head, from, to, diff);
  5732. }
  5733. continue;
  5734. }
  5735. for (var j$1 = 0; j$1 < sub.changes.length; ++j$1) {
  5736. var cur = sub.changes[j$1];
  5737. if (to < cur.from.line) {
  5738. cur.from = Pos(cur.from.line + diff, cur.from.ch);
  5739. cur.to = Pos(cur.to.line + diff, cur.to.ch);
  5740. } else if (from <= cur.to.line) {
  5741. ok = false;
  5742. break;
  5743. }
  5744. }
  5745. if (!ok) {
  5746. array.splice(0, i2 + 1);
  5747. i2 = 0;
  5748. }
  5749. }
  5750. }
  5751. function rebaseHist(hist, change) {
  5752. var from = change.from.line, to = change.to.line, diff = change.text.length - (to - from) - 1;
  5753. rebaseHistArray(hist.done, from, to, diff);
  5754. rebaseHistArray(hist.undone, from, to, diff);
  5755. }
  5756. function changeLine(doc2, handle, changeType, op) {
  5757. var no = handle, line = handle;
  5758. if (typeof handle == "number") {
  5759. line = getLine(doc2, clipLine(doc2, handle));
  5760. } else {
  5761. no = lineNo(handle);
  5762. }
  5763. if (no == null) {
  5764. return null;
  5765. }
  5766. if (op(line, no) && doc2.cm) {
  5767. regLineChange(doc2.cm, no, changeType);
  5768. }
  5769. return line;
  5770. }
  5771. function LeafChunk(lines) {
  5772. this.lines = lines;
  5773. this.parent = null;
  5774. var height = 0;
  5775. for (var i2 = 0; i2 < lines.length; ++i2) {
  5776. lines[i2].parent = this;
  5777. height += lines[i2].height;
  5778. }
  5779. this.height = height;
  5780. }
  5781. LeafChunk.prototype = {
  5782. chunkSize: function() {
  5783. return this.lines.length;
  5784. },
  5785. // Remove the n lines at offset 'at'.
  5786. removeInner: function(at, n) {
  5787. for (var i2 = at, e = at + n; i2 < e; ++i2) {
  5788. var line = this.lines[i2];
  5789. this.height -= line.height;
  5790. cleanUpLine(line);
  5791. signalLater(line, "delete");
  5792. }
  5793. this.lines.splice(at, n);
  5794. },
  5795. // Helper used to collapse a small branch into a single leaf.
  5796. collapse: function(lines) {
  5797. lines.push.apply(lines, this.lines);
  5798. },
  5799. // Insert the given array of lines at offset 'at', count them as
  5800. // having the given height.
  5801. insertInner: function(at, lines, height) {
  5802. this.height += height;
  5803. this.lines = this.lines.slice(0, at).concat(lines).concat(this.lines.slice(at));
  5804. for (var i2 = 0; i2 < lines.length; ++i2) {
  5805. lines[i2].parent = this;
  5806. }
  5807. },
  5808. // Used to iterate over a part of the tree.
  5809. iterN: function(at, n, op) {
  5810. for (var e = at + n; at < e; ++at) {
  5811. if (op(this.lines[at])) {
  5812. return true;
  5813. }
  5814. }
  5815. }
  5816. };
  5817. function BranchChunk(children) {
  5818. this.children = children;
  5819. var size = 0, height = 0;
  5820. for (var i2 = 0; i2 < children.length; ++i2) {
  5821. var ch = children[i2];
  5822. size += ch.chunkSize();
  5823. height += ch.height;
  5824. ch.parent = this;
  5825. }
  5826. this.size = size;
  5827. this.height = height;
  5828. this.parent = null;
  5829. }
  5830. BranchChunk.prototype = {
  5831. chunkSize: function() {
  5832. return this.size;
  5833. },
  5834. removeInner: function(at, n) {
  5835. this.size -= n;
  5836. for (var i2 = 0; i2 < this.children.length; ++i2) {
  5837. var child = this.children[i2], sz = child.chunkSize();
  5838. if (at < sz) {
  5839. var rm = Math.min(n, sz - at), oldHeight = child.height;
  5840. child.removeInner(at, rm);
  5841. this.height -= oldHeight - child.height;
  5842. if (sz == rm) {
  5843. this.children.splice(i2--, 1);
  5844. child.parent = null;
  5845. }
  5846. if ((n -= rm) == 0) {
  5847. break;
  5848. }
  5849. at = 0;
  5850. } else {
  5851. at -= sz;
  5852. }
  5853. }
  5854. if (this.size - n < 25 && (this.children.length > 1 || !(this.children[0] instanceof LeafChunk))) {
  5855. var lines = [];
  5856. this.collapse(lines);
  5857. this.children = [new LeafChunk(lines)];
  5858. this.children[0].parent = this;
  5859. }
  5860. },
  5861. collapse: function(lines) {
  5862. for (var i2 = 0; i2 < this.children.length; ++i2) {
  5863. this.children[i2].collapse(lines);
  5864. }
  5865. },
  5866. insertInner: function(at, lines, height) {
  5867. this.size += lines.length;
  5868. this.height += height;
  5869. for (var i2 = 0; i2 < this.children.length; ++i2) {
  5870. var child = this.children[i2], sz = child.chunkSize();
  5871. if (at <= sz) {
  5872. child.insertInner(at, lines, height);
  5873. if (child.lines && child.lines.length > 50) {
  5874. var remaining = child.lines.length % 25 + 25;
  5875. for (var pos = remaining; pos < child.lines.length; ) {
  5876. var leaf = new LeafChunk(child.lines.slice(pos, pos += 25));
  5877. child.height -= leaf.height;
  5878. this.children.splice(++i2, 0, leaf);
  5879. leaf.parent = this;
  5880. }
  5881. child.lines = child.lines.slice(0, remaining);
  5882. this.maybeSpill();
  5883. }
  5884. break;
  5885. }
  5886. at -= sz;
  5887. }
  5888. },
  5889. // When a node has grown, check whether it should be split.
  5890. maybeSpill: function() {
  5891. if (this.children.length <= 10) {
  5892. return;
  5893. }
  5894. var me = this;
  5895. do {
  5896. var spilled = me.children.splice(me.children.length - 5, 5);
  5897. var sibling = new BranchChunk(spilled);
  5898. if (!me.parent) {
  5899. var copy = new BranchChunk(me.children);
  5900. copy.parent = me;
  5901. me.children = [copy, sibling];
  5902. me = copy;
  5903. } else {
  5904. me.size -= sibling.size;
  5905. me.height -= sibling.height;
  5906. var myIndex = indexOf(me.parent.children, me);
  5907. me.parent.children.splice(myIndex + 1, 0, sibling);
  5908. }
  5909. sibling.parent = me.parent;
  5910. } while (me.children.length > 10);
  5911. me.parent.maybeSpill();
  5912. },
  5913. iterN: function(at, n, op) {
  5914. for (var i2 = 0; i2 < this.children.length; ++i2) {
  5915. var child = this.children[i2], sz = child.chunkSize();
  5916. if (at < sz) {
  5917. var used = Math.min(n, sz - at);
  5918. if (child.iterN(at, used, op)) {
  5919. return true;
  5920. }
  5921. if ((n -= used) == 0) {
  5922. break;
  5923. }
  5924. at = 0;
  5925. } else {
  5926. at -= sz;
  5927. }
  5928. }
  5929. }
  5930. };
  5931. var LineWidget = function(doc2, node, options) {
  5932. if (options) {
  5933. for (var opt in options) {
  5934. if (options.hasOwnProperty(opt)) {
  5935. this[opt] = options[opt];
  5936. }
  5937. }
  5938. }
  5939. this.doc = doc2;
  5940. this.node = node;
  5941. };
  5942. LineWidget.prototype.clear = function() {
  5943. var cm = this.doc.cm, ws = this.line.widgets, line = this.line, no = lineNo(line);
  5944. if (no == null || !ws) {
  5945. return;
  5946. }
  5947. for (var i2 = 0; i2 < ws.length; ++i2) {
  5948. if (ws[i2] == this) {
  5949. ws.splice(i2--, 1);
  5950. }
  5951. }
  5952. if (!ws.length) {
  5953. line.widgets = null;
  5954. }
  5955. var height = widgetHeight(this);
  5956. updateLineHeight(line, Math.max(0, line.height - height));
  5957. if (cm) {
  5958. runInOp(cm, function() {
  5959. adjustScrollWhenAboveVisible(cm, line, -height);
  5960. regLineChange(cm, no, "widget");
  5961. });
  5962. signalLater(cm, "lineWidgetCleared", cm, this, no);
  5963. }
  5964. };
  5965. LineWidget.prototype.changed = function() {
  5966. var this$1 = this;
  5967. var oldH = this.height, cm = this.doc.cm, line = this.line;
  5968. this.height = null;
  5969. var diff = widgetHeight(this) - oldH;
  5970. if (!diff) {
  5971. return;
  5972. }
  5973. if (!lineIsHidden(this.doc, line)) {
  5974. updateLineHeight(line, line.height + diff);
  5975. }
  5976. if (cm) {
  5977. runInOp(cm, function() {
  5978. cm.curOp.forceUpdate = true;
  5979. adjustScrollWhenAboveVisible(cm, line, diff);
  5980. signalLater(cm, "lineWidgetChanged", cm, this$1, lineNo(line));
  5981. });
  5982. }
  5983. };
  5984. eventMixin(LineWidget);
  5985. function adjustScrollWhenAboveVisible(cm, line, diff) {
  5986. if (heightAtLine(line) < (cm.curOp && cm.curOp.scrollTop || cm.doc.scrollTop)) {
  5987. addToScrollTop(cm, diff);
  5988. }
  5989. }
  5990. function addLineWidget(doc2, handle, node, options) {
  5991. var widget = new LineWidget(doc2, node, options);
  5992. var cm = doc2.cm;
  5993. if (cm && widget.noHScroll) {
  5994. cm.display.alignWidgets = true;
  5995. }
  5996. changeLine(doc2, handle, "widget", function(line) {
  5997. var widgets = line.widgets || (line.widgets = []);
  5998. if (widget.insertAt == null) {
  5999. widgets.push(widget);
  6000. } else {
  6001. widgets.splice(Math.min(widgets.length, Math.max(0, widget.insertAt)), 0, widget);
  6002. }
  6003. widget.line = line;
  6004. if (cm && !lineIsHidden(doc2, line)) {
  6005. var aboveVisible = heightAtLine(line) < doc2.scrollTop;
  6006. updateLineHeight(line, line.height + widgetHeight(widget));
  6007. if (aboveVisible) {
  6008. addToScrollTop(cm, widget.height);
  6009. }
  6010. cm.curOp.forceUpdate = true;
  6011. }
  6012. return true;
  6013. });
  6014. if (cm) {
  6015. signalLater(cm, "lineWidgetAdded", cm, widget, typeof handle == "number" ? handle : lineNo(handle));
  6016. }
  6017. return widget;
  6018. }
  6019. var nextMarkerId = 0;
  6020. var TextMarker = function(doc2, type) {
  6021. this.lines = [];
  6022. this.type = type;
  6023. this.doc = doc2;
  6024. this.id = ++nextMarkerId;
  6025. };
  6026. TextMarker.prototype.clear = function() {
  6027. if (this.explicitlyCleared) {
  6028. return;
  6029. }
  6030. var cm = this.doc.cm, withOp = cm && !cm.curOp;
  6031. if (withOp) {
  6032. startOperation(cm);
  6033. }
  6034. if (hasHandler(this, "clear")) {
  6035. var found = this.find();
  6036. if (found) {
  6037. signalLater(this, "clear", found.from, found.to);
  6038. }
  6039. }
  6040. var min = null, max = null;
  6041. for (var i2 = 0; i2 < this.lines.length; ++i2) {
  6042. var line = this.lines[i2];
  6043. var span = getMarkedSpanFor(line.markedSpans, this);
  6044. if (cm && !this.collapsed) {
  6045. regLineChange(cm, lineNo(line), "text");
  6046. } else if (cm) {
  6047. if (span.to != null) {
  6048. max = lineNo(line);
  6049. }
  6050. if (span.from != null) {
  6051. min = lineNo(line);
  6052. }
  6053. }
  6054. line.markedSpans = removeMarkedSpan(line.markedSpans, span);
  6055. if (span.from == null && this.collapsed && !lineIsHidden(this.doc, line) && cm) {
  6056. updateLineHeight(line, textHeight(cm.display));
  6057. }
  6058. }
  6059. if (cm && this.collapsed && !cm.options.lineWrapping) {
  6060. for (var i$12 = 0; i$12 < this.lines.length; ++i$12) {
  6061. var visual = visualLine(this.lines[i$12]), len = lineLength(visual);
  6062. if (len > cm.display.maxLineLength) {
  6063. cm.display.maxLine = visual;
  6064. cm.display.maxLineLength = len;
  6065. cm.display.maxLineChanged = true;
  6066. }
  6067. }
  6068. }
  6069. if (min != null && cm && this.collapsed) {
  6070. regChange(cm, min, max + 1);
  6071. }
  6072. this.lines.length = 0;
  6073. this.explicitlyCleared = true;
  6074. if (this.atomic && this.doc.cantEdit) {
  6075. this.doc.cantEdit = false;
  6076. if (cm) {
  6077. reCheckSelection(cm.doc);
  6078. }
  6079. }
  6080. if (cm) {
  6081. signalLater(cm, "markerCleared", cm, this, min, max);
  6082. }
  6083. if (withOp) {
  6084. endOperation(cm);
  6085. }
  6086. if (this.parent) {
  6087. this.parent.clear();
  6088. }
  6089. };
  6090. TextMarker.prototype.find = function(side, lineObj) {
  6091. if (side == null && this.type == "bookmark") {
  6092. side = 1;
  6093. }
  6094. var from, to;
  6095. for (var i2 = 0; i2 < this.lines.length; ++i2) {
  6096. var line = this.lines[i2];
  6097. var span = getMarkedSpanFor(line.markedSpans, this);
  6098. if (span.from != null) {
  6099. from = Pos(lineObj ? line : lineNo(line), span.from);
  6100. if (side == -1) {
  6101. return from;
  6102. }
  6103. }
  6104. if (span.to != null) {
  6105. to = Pos(lineObj ? line : lineNo(line), span.to);
  6106. if (side == 1) {
  6107. return to;
  6108. }
  6109. }
  6110. }
  6111. return from && { from, to };
  6112. };
  6113. TextMarker.prototype.changed = function() {
  6114. var this$1 = this;
  6115. var pos = this.find(-1, true), widget = this, cm = this.doc.cm;
  6116. if (!pos || !cm) {
  6117. return;
  6118. }
  6119. runInOp(cm, function() {
  6120. var line = pos.line, lineN = lineNo(pos.line);
  6121. var view = findViewForLine(cm, lineN);
  6122. if (view) {
  6123. clearLineMeasurementCacheFor(view);
  6124. cm.curOp.selectionChanged = cm.curOp.forceUpdate = true;
  6125. }
  6126. cm.curOp.updateMaxLine = true;
  6127. if (!lineIsHidden(widget.doc, line) && widget.height != null) {
  6128. var oldHeight = widget.height;
  6129. widget.height = null;
  6130. var dHeight = widgetHeight(widget) - oldHeight;
  6131. if (dHeight) {
  6132. updateLineHeight(line, line.height + dHeight);
  6133. }
  6134. }
  6135. signalLater(cm, "markerChanged", cm, this$1);
  6136. });
  6137. };
  6138. TextMarker.prototype.attachLine = function(line) {
  6139. if (!this.lines.length && this.doc.cm) {
  6140. var op = this.doc.cm.curOp;
  6141. if (!op.maybeHiddenMarkers || indexOf(op.maybeHiddenMarkers, this) == -1) {
  6142. (op.maybeUnhiddenMarkers || (op.maybeUnhiddenMarkers = [])).push(this);
  6143. }
  6144. }
  6145. this.lines.push(line);
  6146. };
  6147. TextMarker.prototype.detachLine = function(line) {
  6148. this.lines.splice(indexOf(this.lines, line), 1);
  6149. if (!this.lines.length && this.doc.cm) {
  6150. var op = this.doc.cm.curOp;
  6151. (op.maybeHiddenMarkers || (op.maybeHiddenMarkers = [])).push(this);
  6152. }
  6153. };
  6154. eventMixin(TextMarker);
  6155. function markText(doc2, from, to, options, type) {
  6156. if (options && options.shared) {
  6157. return markTextShared(doc2, from, to, options, type);
  6158. }
  6159. if (doc2.cm && !doc2.cm.curOp) {
  6160. return operation(doc2.cm, markText)(doc2, from, to, options, type);
  6161. }
  6162. var marker = new TextMarker(doc2, type), diff = cmp(from, to);
  6163. if (options) {
  6164. copyObj(options, marker, false);
  6165. }
  6166. if (diff > 0 || diff == 0 && marker.clearWhenEmpty !== false) {
  6167. return marker;
  6168. }
  6169. if (marker.replacedWith) {
  6170. marker.collapsed = true;
  6171. marker.widgetNode = eltP("span", [marker.replacedWith], "CodeMirror-widget");
  6172. if (!options.handleMouseEvents) {
  6173. marker.widgetNode.setAttribute("cm-ignore-events", "true");
  6174. }
  6175. if (options.insertLeft) {
  6176. marker.widgetNode.insertLeft = true;
  6177. }
  6178. }
  6179. if (marker.collapsed) {
  6180. if (conflictingCollapsedRange(doc2, from.line, from, to, marker) || from.line != to.line && conflictingCollapsedRange(doc2, to.line, from, to, marker)) {
  6181. throw new Error("Inserting collapsed marker partially overlapping an existing one");
  6182. }
  6183. seeCollapsedSpans();
  6184. }
  6185. if (marker.addToHistory) {
  6186. addChangeToHistory(doc2, { from, to, origin: "markText" }, doc2.sel, NaN);
  6187. }
  6188. var curLine = from.line, cm = doc2.cm, updateMaxLine;
  6189. doc2.iter(curLine, to.line + 1, function(line) {
  6190. if (cm && marker.collapsed && !cm.options.lineWrapping && visualLine(line) == cm.display.maxLine) {
  6191. updateMaxLine = true;
  6192. }
  6193. if (marker.collapsed && curLine != from.line) {
  6194. updateLineHeight(line, 0);
  6195. }
  6196. addMarkedSpan(line, new MarkedSpan(
  6197. marker,
  6198. curLine == from.line ? from.ch : null,
  6199. curLine == to.line ? to.ch : null
  6200. ), doc2.cm && doc2.cm.curOp);
  6201. ++curLine;
  6202. });
  6203. if (marker.collapsed) {
  6204. doc2.iter(from.line, to.line + 1, function(line) {
  6205. if (lineIsHidden(doc2, line)) {
  6206. updateLineHeight(line, 0);
  6207. }
  6208. });
  6209. }
  6210. if (marker.clearOnEnter) {
  6211. on(marker, "beforeCursorEnter", function() {
  6212. return marker.clear();
  6213. });
  6214. }
  6215. if (marker.readOnly) {
  6216. seeReadOnlySpans();
  6217. if (doc2.history.done.length || doc2.history.undone.length) {
  6218. doc2.clearHistory();
  6219. }
  6220. }
  6221. if (marker.collapsed) {
  6222. marker.id = ++nextMarkerId;
  6223. marker.atomic = true;
  6224. }
  6225. if (cm) {
  6226. if (updateMaxLine) {
  6227. cm.curOp.updateMaxLine = true;
  6228. }
  6229. if (marker.collapsed) {
  6230. regChange(cm, from.line, to.line + 1);
  6231. } else if (marker.className || marker.startStyle || marker.endStyle || marker.css || marker.attributes || marker.title) {
  6232. for (var i2 = from.line; i2 <= to.line; i2++) {
  6233. regLineChange(cm, i2, "text");
  6234. }
  6235. }
  6236. if (marker.atomic) {
  6237. reCheckSelection(cm.doc);
  6238. }
  6239. signalLater(cm, "markerAdded", cm, marker);
  6240. }
  6241. return marker;
  6242. }
  6243. var SharedTextMarker = function(markers, primary) {
  6244. this.markers = markers;
  6245. this.primary = primary;
  6246. for (var i2 = 0; i2 < markers.length; ++i2) {
  6247. markers[i2].parent = this;
  6248. }
  6249. };
  6250. SharedTextMarker.prototype.clear = function() {
  6251. if (this.explicitlyCleared) {
  6252. return;
  6253. }
  6254. this.explicitlyCleared = true;
  6255. for (var i2 = 0; i2 < this.markers.length; ++i2) {
  6256. this.markers[i2].clear();
  6257. }
  6258. signalLater(this, "clear");
  6259. };
  6260. SharedTextMarker.prototype.find = function(side, lineObj) {
  6261. return this.primary.find(side, lineObj);
  6262. };
  6263. eventMixin(SharedTextMarker);
  6264. function markTextShared(doc2, from, to, options, type) {
  6265. options = copyObj(options);
  6266. options.shared = false;
  6267. var markers = [markText(doc2, from, to, options, type)], primary = markers[0];
  6268. var widget = options.widgetNode;
  6269. linkedDocs(doc2, function(doc3) {
  6270. if (widget) {
  6271. options.widgetNode = widget.cloneNode(true);
  6272. }
  6273. markers.push(markText(doc3, clipPos(doc3, from), clipPos(doc3, to), options, type));
  6274. for (var i2 = 0; i2 < doc3.linked.length; ++i2) {
  6275. if (doc3.linked[i2].isParent) {
  6276. return;
  6277. }
  6278. }
  6279. primary = lst(markers);
  6280. });
  6281. return new SharedTextMarker(markers, primary);
  6282. }
  6283. function findSharedMarkers(doc2) {
  6284. return doc2.findMarks(Pos(doc2.first, 0), doc2.clipPos(Pos(doc2.lastLine())), function(m) {
  6285. return m.parent;
  6286. });
  6287. }
  6288. function copySharedMarkers(doc2, markers) {
  6289. for (var i2 = 0; i2 < markers.length; i2++) {
  6290. var marker = markers[i2], pos = marker.find();
  6291. var mFrom = doc2.clipPos(pos.from), mTo = doc2.clipPos(pos.to);
  6292. if (cmp(mFrom, mTo)) {
  6293. var subMark = markText(doc2, mFrom, mTo, marker.primary, marker.primary.type);
  6294. marker.markers.push(subMark);
  6295. subMark.parent = marker;
  6296. }
  6297. }
  6298. }
  6299. function detachSharedMarkers(markers) {
  6300. var loop = function(i3) {
  6301. var marker = markers[i3], linked = [marker.primary.doc];
  6302. linkedDocs(marker.primary.doc, function(d) {
  6303. return linked.push(d);
  6304. });
  6305. for (var j = 0; j < marker.markers.length; j++) {
  6306. var subMarker = marker.markers[j];
  6307. if (indexOf(linked, subMarker.doc) == -1) {
  6308. subMarker.parent = null;
  6309. marker.markers.splice(j--, 1);
  6310. }
  6311. }
  6312. };
  6313. for (var i2 = 0; i2 < markers.length; i2++)
  6314. loop(i2);
  6315. }
  6316. var nextDocId = 0;
  6317. var Doc = function(text, mode, firstLine, lineSep, direction) {
  6318. if (!(this instanceof Doc)) {
  6319. return new Doc(text, mode, firstLine, lineSep, direction);
  6320. }
  6321. if (firstLine == null) {
  6322. firstLine = 0;
  6323. }
  6324. BranchChunk.call(this, [new LeafChunk([new Line("", null)])]);
  6325. this.first = firstLine;
  6326. this.scrollTop = this.scrollLeft = 0;
  6327. this.cantEdit = false;
  6328. this.cleanGeneration = 1;
  6329. this.modeFrontier = this.highlightFrontier = firstLine;
  6330. var start = Pos(firstLine, 0);
  6331. this.sel = simpleSelection(start);
  6332. this.history = new History(null);
  6333. this.id = ++nextDocId;
  6334. this.modeOption = mode;
  6335. this.lineSep = lineSep;
  6336. this.direction = direction == "rtl" ? "rtl" : "ltr";
  6337. this.extend = false;
  6338. if (typeof text == "string") {
  6339. text = this.splitLines(text);
  6340. }
  6341. updateDoc(this, { from: start, to: start, text });
  6342. setSelection(this, simpleSelection(start), sel_dontScroll);
  6343. };
  6344. Doc.prototype = createObj(BranchChunk.prototype, {
  6345. constructor: Doc,
  6346. // Iterate over the document. Supports two forms -- with only one
  6347. // argument, it calls that for each line in the document. With
  6348. // three, it iterates over the range given by the first two (with
  6349. // the second being non-inclusive).
  6350. iter: function(from, to, op) {
  6351. if (op) {
  6352. this.iterN(from - this.first, to - from, op);
  6353. } else {
  6354. this.iterN(this.first, this.first + this.size, from);
  6355. }
  6356. },
  6357. // Non-public interface for adding and removing lines.
  6358. insert: function(at, lines) {
  6359. var height = 0;
  6360. for (var i2 = 0; i2 < lines.length; ++i2) {
  6361. height += lines[i2].height;
  6362. }
  6363. this.insertInner(at - this.first, lines, height);
  6364. },
  6365. remove: function(at, n) {
  6366. this.removeInner(at - this.first, n);
  6367. },
  6368. // From here, the methods are part of the public interface. Most
  6369. // are also available from CodeMirror (editor) instances.
  6370. getValue: function(lineSep) {
  6371. var lines = getLines(this, this.first, this.first + this.size);
  6372. if (lineSep === false) {
  6373. return lines;
  6374. }
  6375. return lines.join(lineSep || this.lineSeparator());
  6376. },
  6377. setValue: docMethodOp(function(code) {
  6378. var top = Pos(this.first, 0), last = this.first + this.size - 1;
  6379. makeChange(this, {
  6380. from: top,
  6381. to: Pos(last, getLine(this, last).text.length),
  6382. text: this.splitLines(code),
  6383. origin: "setValue",
  6384. full: true
  6385. }, true);
  6386. if (this.cm) {
  6387. scrollToCoords(this.cm, 0, 0);
  6388. }
  6389. setSelection(this, simpleSelection(top), sel_dontScroll);
  6390. }),
  6391. replaceRange: function(code, from, to, origin) {
  6392. from = clipPos(this, from);
  6393. to = to ? clipPos(this, to) : from;
  6394. replaceRange(this, code, from, to, origin);
  6395. },
  6396. getRange: function(from, to, lineSep) {
  6397. var lines = getBetween(this, clipPos(this, from), clipPos(this, to));
  6398. if (lineSep === false) {
  6399. return lines;
  6400. }
  6401. if (lineSep === "") {
  6402. return lines.join("");
  6403. }
  6404. return lines.join(lineSep || this.lineSeparator());
  6405. },
  6406. getLine: function(line) {
  6407. var l = this.getLineHandle(line);
  6408. return l && l.text;
  6409. },
  6410. getLineHandle: function(line) {
  6411. if (isLine(this, line)) {
  6412. return getLine(this, line);
  6413. }
  6414. },
  6415. getLineNumber: function(line) {
  6416. return lineNo(line);
  6417. },
  6418. getLineHandleVisualStart: function(line) {
  6419. if (typeof line == "number") {
  6420. line = getLine(this, line);
  6421. }
  6422. return visualLine(line);
  6423. },
  6424. lineCount: function() {
  6425. return this.size;
  6426. },
  6427. firstLine: function() {
  6428. return this.first;
  6429. },
  6430. lastLine: function() {
  6431. return this.first + this.size - 1;
  6432. },
  6433. clipPos: function(pos) {
  6434. return clipPos(this, pos);
  6435. },
  6436. getCursor: function(start) {
  6437. var range2 = this.sel.primary(), pos;
  6438. if (start == null || start == "head") {
  6439. pos = range2.head;
  6440. } else if (start == "anchor") {
  6441. pos = range2.anchor;
  6442. } else if (start == "end" || start == "to" || start === false) {
  6443. pos = range2.to();
  6444. } else {
  6445. pos = range2.from();
  6446. }
  6447. return pos;
  6448. },
  6449. listSelections: function() {
  6450. return this.sel.ranges;
  6451. },
  6452. somethingSelected: function() {
  6453. return this.sel.somethingSelected();
  6454. },
  6455. setCursor: docMethodOp(function(line, ch, options) {
  6456. setSimpleSelection(this, clipPos(this, typeof line == "number" ? Pos(line, ch || 0) : line), null, options);
  6457. }),
  6458. setSelection: docMethodOp(function(anchor, head, options) {
  6459. setSimpleSelection(this, clipPos(this, anchor), clipPos(this, head || anchor), options);
  6460. }),
  6461. extendSelection: docMethodOp(function(head, other, options) {
  6462. extendSelection(this, clipPos(this, head), other && clipPos(this, other), options);
  6463. }),
  6464. extendSelections: docMethodOp(function(heads, options) {
  6465. extendSelections(this, clipPosArray(this, heads), options);
  6466. }),
  6467. extendSelectionsBy: docMethodOp(function(f, options) {
  6468. var heads = map(this.sel.ranges, f);
  6469. extendSelections(this, clipPosArray(this, heads), options);
  6470. }),
  6471. setSelections: docMethodOp(function(ranges, primary, options) {
  6472. if (!ranges.length) {
  6473. return;
  6474. }
  6475. var out = [];
  6476. for (var i2 = 0; i2 < ranges.length; i2++) {
  6477. out[i2] = new Range(
  6478. clipPos(this, ranges[i2].anchor),
  6479. clipPos(this, ranges[i2].head || ranges[i2].anchor)
  6480. );
  6481. }
  6482. if (primary == null) {
  6483. primary = Math.min(ranges.length - 1, this.sel.primIndex);
  6484. }
  6485. setSelection(this, normalizeSelection(this.cm, out, primary), options);
  6486. }),
  6487. addSelection: docMethodOp(function(anchor, head, options) {
  6488. var ranges = this.sel.ranges.slice(0);
  6489. ranges.push(new Range(clipPos(this, anchor), clipPos(this, head || anchor)));
  6490. setSelection(this, normalizeSelection(this.cm, ranges, ranges.length - 1), options);
  6491. }),
  6492. getSelection: function(lineSep) {
  6493. var ranges = this.sel.ranges, lines;
  6494. for (var i2 = 0; i2 < ranges.length; i2++) {
  6495. var sel = getBetween(this, ranges[i2].from(), ranges[i2].to());
  6496. lines = lines ? lines.concat(sel) : sel;
  6497. }
  6498. if (lineSep === false) {
  6499. return lines;
  6500. } else {
  6501. return lines.join(lineSep || this.lineSeparator());
  6502. }
  6503. },
  6504. getSelections: function(lineSep) {
  6505. var parts = [], ranges = this.sel.ranges;
  6506. for (var i2 = 0; i2 < ranges.length; i2++) {
  6507. var sel = getBetween(this, ranges[i2].from(), ranges[i2].to());
  6508. if (lineSep !== false) {
  6509. sel = sel.join(lineSep || this.lineSeparator());
  6510. }
  6511. parts[i2] = sel;
  6512. }
  6513. return parts;
  6514. },
  6515. replaceSelection: function(code, collapse, origin) {
  6516. var dup = [];
  6517. for (var i2 = 0; i2 < this.sel.ranges.length; i2++) {
  6518. dup[i2] = code;
  6519. }
  6520. this.replaceSelections(dup, collapse, origin || "+input");
  6521. },
  6522. replaceSelections: docMethodOp(function(code, collapse, origin) {
  6523. var changes = [], sel = this.sel;
  6524. for (var i2 = 0; i2 < sel.ranges.length; i2++) {
  6525. var range2 = sel.ranges[i2];
  6526. changes[i2] = { from: range2.from(), to: range2.to(), text: this.splitLines(code[i2]), origin };
  6527. }
  6528. var newSel = collapse && collapse != "end" && computeReplacedSel(this, changes, collapse);
  6529. for (var i$12 = changes.length - 1; i$12 >= 0; i$12--) {
  6530. makeChange(this, changes[i$12]);
  6531. }
  6532. if (newSel) {
  6533. setSelectionReplaceHistory(this, newSel);
  6534. } else if (this.cm) {
  6535. ensureCursorVisible(this.cm);
  6536. }
  6537. }),
  6538. undo: docMethodOp(function() {
  6539. makeChangeFromHistory(this, "undo");
  6540. }),
  6541. redo: docMethodOp(function() {
  6542. makeChangeFromHistory(this, "redo");
  6543. }),
  6544. undoSelection: docMethodOp(function() {
  6545. makeChangeFromHistory(this, "undo", true);
  6546. }),
  6547. redoSelection: docMethodOp(function() {
  6548. makeChangeFromHistory(this, "redo", true);
  6549. }),
  6550. setExtending: function(val) {
  6551. this.extend = val;
  6552. },
  6553. getExtending: function() {
  6554. return this.extend;
  6555. },
  6556. historySize: function() {
  6557. var hist = this.history, done = 0, undone = 0;
  6558. for (var i2 = 0; i2 < hist.done.length; i2++) {
  6559. if (!hist.done[i2].ranges) {
  6560. ++done;
  6561. }
  6562. }
  6563. for (var i$12 = 0; i$12 < hist.undone.length; i$12++) {
  6564. if (!hist.undone[i$12].ranges) {
  6565. ++undone;
  6566. }
  6567. }
  6568. return { undo: done, redo: undone };
  6569. },
  6570. clearHistory: function() {
  6571. var this$1 = this;
  6572. this.history = new History(this.history);
  6573. linkedDocs(this, function(doc2) {
  6574. return doc2.history = this$1.history;
  6575. }, true);
  6576. },
  6577. markClean: function() {
  6578. this.cleanGeneration = this.changeGeneration(true);
  6579. },
  6580. changeGeneration: function(forceSplit) {
  6581. if (forceSplit) {
  6582. this.history.lastOp = this.history.lastSelOp = this.history.lastOrigin = null;
  6583. }
  6584. return this.history.generation;
  6585. },
  6586. isClean: function(gen) {
  6587. return this.history.generation == (gen || this.cleanGeneration);
  6588. },
  6589. getHistory: function() {
  6590. return {
  6591. done: copyHistoryArray(this.history.done),
  6592. undone: copyHistoryArray(this.history.undone)
  6593. };
  6594. },
  6595. setHistory: function(histData) {
  6596. var hist = this.history = new History(this.history);
  6597. hist.done = copyHistoryArray(histData.done.slice(0), null, true);
  6598. hist.undone = copyHistoryArray(histData.undone.slice(0), null, true);
  6599. },
  6600. setGutterMarker: docMethodOp(function(line, gutterID, value) {
  6601. return changeLine(this, line, "gutter", function(line2) {
  6602. var markers = line2.gutterMarkers || (line2.gutterMarkers = {});
  6603. markers[gutterID] = value;
  6604. if (!value && isEmpty(markers)) {
  6605. line2.gutterMarkers = null;
  6606. }
  6607. return true;
  6608. });
  6609. }),
  6610. clearGutter: docMethodOp(function(gutterID) {
  6611. var this$1 = this;
  6612. this.iter(function(line) {
  6613. if (line.gutterMarkers && line.gutterMarkers[gutterID]) {
  6614. changeLine(this$1, line, "gutter", function() {
  6615. line.gutterMarkers[gutterID] = null;
  6616. if (isEmpty(line.gutterMarkers)) {
  6617. line.gutterMarkers = null;
  6618. }
  6619. return true;
  6620. });
  6621. }
  6622. });
  6623. }),
  6624. lineInfo: function(line) {
  6625. var n;
  6626. if (typeof line == "number") {
  6627. if (!isLine(this, line)) {
  6628. return null;
  6629. }
  6630. n = line;
  6631. line = getLine(this, line);
  6632. if (!line) {
  6633. return null;
  6634. }
  6635. } else {
  6636. n = lineNo(line);
  6637. if (n == null) {
  6638. return null;
  6639. }
  6640. }
  6641. return {
  6642. line: n,
  6643. handle: line,
  6644. text: line.text,
  6645. gutterMarkers: line.gutterMarkers,
  6646. textClass: line.textClass,
  6647. bgClass: line.bgClass,
  6648. wrapClass: line.wrapClass,
  6649. widgets: line.widgets
  6650. };
  6651. },
  6652. addLineClass: docMethodOp(function(handle, where, cls) {
  6653. return changeLine(this, handle, where == "gutter" ? "gutter" : "class", function(line) {
  6654. var prop2 = where == "text" ? "textClass" : where == "background" ? "bgClass" : where == "gutter" ? "gutterClass" : "wrapClass";
  6655. if (!line[prop2]) {
  6656. line[prop2] = cls;
  6657. } else if (classTest(cls).test(line[prop2])) {
  6658. return false;
  6659. } else {
  6660. line[prop2] += " " + cls;
  6661. }
  6662. return true;
  6663. });
  6664. }),
  6665. removeLineClass: docMethodOp(function(handle, where, cls) {
  6666. return changeLine(this, handle, where == "gutter" ? "gutter" : "class", function(line) {
  6667. var prop2 = where == "text" ? "textClass" : where == "background" ? "bgClass" : where == "gutter" ? "gutterClass" : "wrapClass";
  6668. var cur = line[prop2];
  6669. if (!cur) {
  6670. return false;
  6671. } else if (cls == null) {
  6672. line[prop2] = null;
  6673. } else {
  6674. var found = cur.match(classTest(cls));
  6675. if (!found) {
  6676. return false;
  6677. }
  6678. var end = found.index + found[0].length;
  6679. line[prop2] = cur.slice(0, found.index) + (!found.index || end == cur.length ? "" : " ") + cur.slice(end) || null;
  6680. }
  6681. return true;
  6682. });
  6683. }),
  6684. addLineWidget: docMethodOp(function(handle, node, options) {
  6685. return addLineWidget(this, handle, node, options);
  6686. }),
  6687. removeLineWidget: function(widget) {
  6688. widget.clear();
  6689. },
  6690. markText: function(from, to, options) {
  6691. return markText(this, clipPos(this, from), clipPos(this, to), options, options && options.type || "range");
  6692. },
  6693. setBookmark: function(pos, options) {
  6694. var realOpts = {
  6695. replacedWith: options && (options.nodeType == null ? options.widget : options),
  6696. insertLeft: options && options.insertLeft,
  6697. clearWhenEmpty: false,
  6698. shared: options && options.shared,
  6699. handleMouseEvents: options && options.handleMouseEvents
  6700. };
  6701. pos = clipPos(this, pos);
  6702. return markText(this, pos, pos, realOpts, "bookmark");
  6703. },
  6704. findMarksAt: function(pos) {
  6705. pos = clipPos(this, pos);
  6706. var markers = [], spans = getLine(this, pos.line).markedSpans;
  6707. if (spans) {
  6708. for (var i2 = 0; i2 < spans.length; ++i2) {
  6709. var span = spans[i2];
  6710. if ((span.from == null || span.from <= pos.ch) && (span.to == null || span.to >= pos.ch)) {
  6711. markers.push(span.marker.parent || span.marker);
  6712. }
  6713. }
  6714. }
  6715. return markers;
  6716. },
  6717. findMarks: function(from, to, filter) {
  6718. from = clipPos(this, from);
  6719. to = clipPos(this, to);
  6720. var found = [], lineNo2 = from.line;
  6721. this.iter(from.line, to.line + 1, function(line) {
  6722. var spans = line.markedSpans;
  6723. if (spans) {
  6724. for (var i2 = 0; i2 < spans.length; i2++) {
  6725. var span = spans[i2];
  6726. if (!(span.to != null && lineNo2 == from.line && from.ch >= span.to || span.from == null && lineNo2 != from.line || span.from != null && lineNo2 == to.line && span.from >= to.ch) && (!filter || filter(span.marker))) {
  6727. found.push(span.marker.parent || span.marker);
  6728. }
  6729. }
  6730. }
  6731. ++lineNo2;
  6732. });
  6733. return found;
  6734. },
  6735. getAllMarks: function() {
  6736. var markers = [];
  6737. this.iter(function(line) {
  6738. var sps = line.markedSpans;
  6739. if (sps) {
  6740. for (var i2 = 0; i2 < sps.length; ++i2) {
  6741. if (sps[i2].from != null) {
  6742. markers.push(sps[i2].marker);
  6743. }
  6744. }
  6745. }
  6746. });
  6747. return markers;
  6748. },
  6749. posFromIndex: function(off2) {
  6750. var ch, lineNo2 = this.first, sepSize = this.lineSeparator().length;
  6751. this.iter(function(line) {
  6752. var sz = line.text.length + sepSize;
  6753. if (sz > off2) {
  6754. ch = off2;
  6755. return true;
  6756. }
  6757. off2 -= sz;
  6758. ++lineNo2;
  6759. });
  6760. return clipPos(this, Pos(lineNo2, ch));
  6761. },
  6762. indexFromPos: function(coords) {
  6763. coords = clipPos(this, coords);
  6764. var index = coords.ch;
  6765. if (coords.line < this.first || coords.ch < 0) {
  6766. return 0;
  6767. }
  6768. var sepSize = this.lineSeparator().length;
  6769. this.iter(this.first, coords.line, function(line) {
  6770. index += line.text.length + sepSize;
  6771. });
  6772. return index;
  6773. },
  6774. copy: function(copyHistory) {
  6775. var doc2 = new Doc(
  6776. getLines(this, this.first, this.first + this.size),
  6777. this.modeOption,
  6778. this.first,
  6779. this.lineSep,
  6780. this.direction
  6781. );
  6782. doc2.scrollTop = this.scrollTop;
  6783. doc2.scrollLeft = this.scrollLeft;
  6784. doc2.sel = this.sel;
  6785. doc2.extend = false;
  6786. if (copyHistory) {
  6787. doc2.history.undoDepth = this.history.undoDepth;
  6788. doc2.setHistory(this.getHistory());
  6789. }
  6790. return doc2;
  6791. },
  6792. linkedDoc: function(options) {
  6793. if (!options) {
  6794. options = {};
  6795. }
  6796. var from = this.first, to = this.first + this.size;
  6797. if (options.from != null && options.from > from) {
  6798. from = options.from;
  6799. }
  6800. if (options.to != null && options.to < to) {
  6801. to = options.to;
  6802. }
  6803. var copy = new Doc(getLines(this, from, to), options.mode || this.modeOption, from, this.lineSep, this.direction);
  6804. if (options.sharedHist) {
  6805. copy.history = this.history;
  6806. }
  6807. (this.linked || (this.linked = [])).push({ doc: copy, sharedHist: options.sharedHist });
  6808. copy.linked = [{ doc: this, isParent: true, sharedHist: options.sharedHist }];
  6809. copySharedMarkers(copy, findSharedMarkers(this));
  6810. return copy;
  6811. },
  6812. unlinkDoc: function(other) {
  6813. if (other instanceof CodeMirror) {
  6814. other = other.doc;
  6815. }
  6816. if (this.linked) {
  6817. for (var i2 = 0; i2 < this.linked.length; ++i2) {
  6818. var link = this.linked[i2];
  6819. if (link.doc != other) {
  6820. continue;
  6821. }
  6822. this.linked.splice(i2, 1);
  6823. other.unlinkDoc(this);
  6824. detachSharedMarkers(findSharedMarkers(this));
  6825. break;
  6826. }
  6827. }
  6828. if (other.history == this.history) {
  6829. var splitIds = [other.id];
  6830. linkedDocs(other, function(doc2) {
  6831. return splitIds.push(doc2.id);
  6832. }, true);
  6833. other.history = new History(null);
  6834. other.history.done = copyHistoryArray(this.history.done, splitIds);
  6835. other.history.undone = copyHistoryArray(this.history.undone, splitIds);
  6836. }
  6837. },
  6838. iterLinkedDocs: function(f) {
  6839. linkedDocs(this, f);
  6840. },
  6841. getMode: function() {
  6842. return this.mode;
  6843. },
  6844. getEditor: function() {
  6845. return this.cm;
  6846. },
  6847. splitLines: function(str) {
  6848. if (this.lineSep) {
  6849. return str.split(this.lineSep);
  6850. }
  6851. return splitLinesAuto(str);
  6852. },
  6853. lineSeparator: function() {
  6854. return this.lineSep || "\n";
  6855. },
  6856. setDirection: docMethodOp(function(dir) {
  6857. if (dir != "rtl") {
  6858. dir = "ltr";
  6859. }
  6860. if (dir == this.direction) {
  6861. return;
  6862. }
  6863. this.direction = dir;
  6864. this.iter(function(line) {
  6865. return line.order = null;
  6866. });
  6867. if (this.cm) {
  6868. directionChanged(this.cm);
  6869. }
  6870. })
  6871. });
  6872. Doc.prototype.eachLine = Doc.prototype.iter;
  6873. var lastDrop = 0;
  6874. function onDrop(e) {
  6875. var cm = this;
  6876. clearDragCursor(cm);
  6877. if (signalDOMEvent(cm, e) || eventInWidget(cm.display, e)) {
  6878. return;
  6879. }
  6880. e_preventDefault(e);
  6881. if (ie) {
  6882. lastDrop = +/* @__PURE__ */ new Date();
  6883. }
  6884. var pos = posFromMouse(cm, e, true), files = e.dataTransfer.files;
  6885. if (!pos || cm.isReadOnly()) {
  6886. return;
  6887. }
  6888. if (files && files.length && window.FileReader && window.File) {
  6889. var n = files.length, text = Array(n), read = 0;
  6890. var markAsReadAndPasteIfAllFilesAreRead = function() {
  6891. if (++read == n) {
  6892. operation(cm, function() {
  6893. pos = clipPos(cm.doc, pos);
  6894. var change = {
  6895. from: pos,
  6896. to: pos,
  6897. text: cm.doc.splitLines(
  6898. text.filter(function(t) {
  6899. return t != null;
  6900. }).join(cm.doc.lineSeparator())
  6901. ),
  6902. origin: "paste"
  6903. };
  6904. makeChange(cm.doc, change);
  6905. setSelectionReplaceHistory(cm.doc, simpleSelection(clipPos(cm.doc, pos), clipPos(cm.doc, changeEnd(change))));
  6906. })();
  6907. }
  6908. };
  6909. var readTextFromFile = function(file, i3) {
  6910. if (cm.options.allowDropFileTypes && indexOf(cm.options.allowDropFileTypes, file.type) == -1) {
  6911. markAsReadAndPasteIfAllFilesAreRead();
  6912. return;
  6913. }
  6914. var reader = new FileReader();
  6915. reader.onerror = function() {
  6916. return markAsReadAndPasteIfAllFilesAreRead();
  6917. };
  6918. reader.onload = function() {
  6919. var content = reader.result;
  6920. if (/[\x00-\x08\x0e-\x1f]{2}/.test(content)) {
  6921. markAsReadAndPasteIfAllFilesAreRead();
  6922. return;
  6923. }
  6924. text[i3] = content;
  6925. markAsReadAndPasteIfAllFilesAreRead();
  6926. };
  6927. reader.readAsText(file);
  6928. };
  6929. for (var i2 = 0; i2 < files.length; i2++) {
  6930. readTextFromFile(files[i2], i2);
  6931. }
  6932. } else {
  6933. if (cm.state.draggingText && cm.doc.sel.contains(pos) > -1) {
  6934. cm.state.draggingText(e);
  6935. setTimeout(function() {
  6936. return cm.display.input.focus();
  6937. }, 20);
  6938. return;
  6939. }
  6940. try {
  6941. var text$1 = e.dataTransfer.getData("Text");
  6942. if (text$1) {
  6943. var selected;
  6944. if (cm.state.draggingText && !cm.state.draggingText.copy) {
  6945. selected = cm.listSelections();
  6946. }
  6947. setSelectionNoUndo(cm.doc, simpleSelection(pos, pos));
  6948. if (selected) {
  6949. for (var i$12 = 0; i$12 < selected.length; ++i$12) {
  6950. replaceRange(cm.doc, "", selected[i$12].anchor, selected[i$12].head, "drag");
  6951. }
  6952. }
  6953. cm.replaceSelection(text$1, "around", "paste");
  6954. cm.display.input.focus();
  6955. }
  6956. } catch (e$1) {
  6957. }
  6958. }
  6959. }
  6960. function onDragStart(cm, e) {
  6961. if (ie && (!cm.state.draggingText || +/* @__PURE__ */ new Date() - lastDrop < 100)) {
  6962. e_stop(e);
  6963. return;
  6964. }
  6965. if (signalDOMEvent(cm, e) || eventInWidget(cm.display, e)) {
  6966. return;
  6967. }
  6968. e.dataTransfer.setData("Text", cm.getSelection());
  6969. e.dataTransfer.effectAllowed = "copyMove";
  6970. if (e.dataTransfer.setDragImage && !safari) {
  6971. var img = elt("img", null, null, "position: fixed; left: 0; top: 0;");
  6972. img.src = "data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==";
  6973. if (presto) {
  6974. img.width = img.height = 1;
  6975. cm.display.wrapper.appendChild(img);
  6976. img._top = img.offsetTop;
  6977. }
  6978. e.dataTransfer.setDragImage(img, 0, 0);
  6979. if (presto) {
  6980. img.parentNode.removeChild(img);
  6981. }
  6982. }
  6983. }
  6984. function onDragOver(cm, e) {
  6985. var pos = posFromMouse(cm, e);
  6986. if (!pos) {
  6987. return;
  6988. }
  6989. var frag = document.createDocumentFragment();
  6990. drawSelectionCursor(cm, pos, frag);
  6991. if (!cm.display.dragCursor) {
  6992. cm.display.dragCursor = elt("div", null, "CodeMirror-cursors CodeMirror-dragcursors");
  6993. cm.display.lineSpace.insertBefore(cm.display.dragCursor, cm.display.cursorDiv);
  6994. }
  6995. removeChildrenAndAdd(cm.display.dragCursor, frag);
  6996. }
  6997. function clearDragCursor(cm) {
  6998. if (cm.display.dragCursor) {
  6999. cm.display.lineSpace.removeChild(cm.display.dragCursor);
  7000. cm.display.dragCursor = null;
  7001. }
  7002. }
  7003. function forEachCodeMirror(f) {
  7004. if (!document.getElementsByClassName) {
  7005. return;
  7006. }
  7007. var byClass = document.getElementsByClassName("CodeMirror"), editors = [];
  7008. for (var i2 = 0; i2 < byClass.length; i2++) {
  7009. var cm = byClass[i2].CodeMirror;
  7010. if (cm) {
  7011. editors.push(cm);
  7012. }
  7013. }
  7014. if (editors.length) {
  7015. editors[0].operation(function() {
  7016. for (var i3 = 0; i3 < editors.length; i3++) {
  7017. f(editors[i3]);
  7018. }
  7019. });
  7020. }
  7021. }
  7022. var globalsRegistered = false;
  7023. function ensureGlobalHandlers() {
  7024. if (globalsRegistered) {
  7025. return;
  7026. }
  7027. registerGlobalHandlers();
  7028. globalsRegistered = true;
  7029. }
  7030. function registerGlobalHandlers() {
  7031. var resizeTimer;
  7032. on(window, "resize", function() {
  7033. if (resizeTimer == null) {
  7034. resizeTimer = setTimeout(function() {
  7035. resizeTimer = null;
  7036. forEachCodeMirror(onResize);
  7037. }, 100);
  7038. }
  7039. });
  7040. on(window, "blur", function() {
  7041. return forEachCodeMirror(onBlur);
  7042. });
  7043. }
  7044. function onResize(cm) {
  7045. var d = cm.display;
  7046. d.cachedCharWidth = d.cachedTextHeight = d.cachedPaddingH = null;
  7047. d.scrollbarsClipped = false;
  7048. cm.setSize();
  7049. }
  7050. var keyNames = {
  7051. 3: "Pause",
  7052. 8: "Backspace",
  7053. 9: "Tab",
  7054. 13: "Enter",
  7055. 16: "Shift",
  7056. 17: "Ctrl",
  7057. 18: "Alt",
  7058. 19: "Pause",
  7059. 20: "CapsLock",
  7060. 27: "Esc",
  7061. 32: "Space",
  7062. 33: "PageUp",
  7063. 34: "PageDown",
  7064. 35: "End",
  7065. 36: "Home",
  7066. 37: "Left",
  7067. 38: "Up",
  7068. 39: "Right",
  7069. 40: "Down",
  7070. 44: "PrintScrn",
  7071. 45: "Insert",
  7072. 46: "Delete",
  7073. 59: ";",
  7074. 61: "=",
  7075. 91: "Mod",
  7076. 92: "Mod",
  7077. 93: "Mod",
  7078. 106: "*",
  7079. 107: "=",
  7080. 109: "-",
  7081. 110: ".",
  7082. 111: "/",
  7083. 145: "ScrollLock",
  7084. 173: "-",
  7085. 186: ";",
  7086. 187: "=",
  7087. 188: ",",
  7088. 189: "-",
  7089. 190: ".",
  7090. 191: "/",
  7091. 192: "`",
  7092. 219: "[",
  7093. 220: "\\",
  7094. 221: "]",
  7095. 222: "'",
  7096. 224: "Mod",
  7097. 63232: "Up",
  7098. 63233: "Down",
  7099. 63234: "Left",
  7100. 63235: "Right",
  7101. 63272: "Delete",
  7102. 63273: "Home",
  7103. 63275: "End",
  7104. 63276: "PageUp",
  7105. 63277: "PageDown",
  7106. 63302: "Insert"
  7107. };
  7108. for (var i = 0; i < 10; i++) {
  7109. keyNames[i + 48] = keyNames[i + 96] = String(i);
  7110. }
  7111. for (var i$1 = 65; i$1 <= 90; i$1++) {
  7112. keyNames[i$1] = String.fromCharCode(i$1);
  7113. }
  7114. for (var i$2 = 1; i$2 <= 12; i$2++) {
  7115. keyNames[i$2 + 111] = keyNames[i$2 + 63235] = "F" + i$2;
  7116. }
  7117. var keyMap = {};
  7118. keyMap.basic = {
  7119. "Left": "goCharLeft",
  7120. "Right": "goCharRight",
  7121. "Up": "goLineUp",
  7122. "Down": "goLineDown",
  7123. "End": "goLineEnd",
  7124. "Home": "goLineStartSmart",
  7125. "PageUp": "goPageUp",
  7126. "PageDown": "goPageDown",
  7127. "Delete": "delCharAfter",
  7128. "Backspace": "delCharBefore",
  7129. "Shift-Backspace": "delCharBefore",
  7130. "Tab": "defaultTab",
  7131. "Shift-Tab": "indentAuto",
  7132. "Enter": "newlineAndIndent",
  7133. "Insert": "toggleOverwrite",
  7134. "Esc": "singleSelection"
  7135. };
  7136. keyMap.pcDefault = {
  7137. "Ctrl-A": "selectAll",
  7138. "Ctrl-D": "deleteLine",
  7139. "Ctrl-Z": "undo",
  7140. "Shift-Ctrl-Z": "redo",
  7141. "Ctrl-Y": "redo",
  7142. "Ctrl-Home": "goDocStart",
  7143. "Ctrl-End": "goDocEnd",
  7144. "Ctrl-Up": "goLineUp",
  7145. "Ctrl-Down": "goLineDown",
  7146. "Ctrl-Left": "goGroupLeft",
  7147. "Ctrl-Right": "goGroupRight",
  7148. "Alt-Left": "goLineStart",
  7149. "Alt-Right": "goLineEnd",
  7150. "Ctrl-Backspace": "delGroupBefore",
  7151. "Ctrl-Delete": "delGroupAfter",
  7152. "Ctrl-S": "save",
  7153. "Ctrl-F": "find",
  7154. "Ctrl-G": "findNext",
  7155. "Shift-Ctrl-G": "findPrev",
  7156. "Shift-Ctrl-F": "replace",
  7157. "Shift-Ctrl-R": "replaceAll",
  7158. "Ctrl-[": "indentLess",
  7159. "Ctrl-]": "indentMore",
  7160. "Ctrl-U": "undoSelection",
  7161. "Shift-Ctrl-U": "redoSelection",
  7162. "Alt-U": "redoSelection",
  7163. "fallthrough": "basic"
  7164. };
  7165. keyMap.emacsy = {
  7166. "Ctrl-F": "goCharRight",
  7167. "Ctrl-B": "goCharLeft",
  7168. "Ctrl-P": "goLineUp",
  7169. "Ctrl-N": "goLineDown",
  7170. "Ctrl-A": "goLineStart",
  7171. "Ctrl-E": "goLineEnd",
  7172. "Ctrl-V": "goPageDown",
  7173. "Shift-Ctrl-V": "goPageUp",
  7174. "Ctrl-D": "delCharAfter",
  7175. "Ctrl-H": "delCharBefore",
  7176. "Alt-Backspace": "delWordBefore",
  7177. "Ctrl-K": "killLine",
  7178. "Ctrl-T": "transposeChars",
  7179. "Ctrl-O": "openLine"
  7180. };
  7181. keyMap.macDefault = {
  7182. "Cmd-A": "selectAll",
  7183. "Cmd-D": "deleteLine",
  7184. "Cmd-Z": "undo",
  7185. "Shift-Cmd-Z": "redo",
  7186. "Cmd-Y": "redo",
  7187. "Cmd-Home": "goDocStart",
  7188. "Cmd-Up": "goDocStart",
  7189. "Cmd-End": "goDocEnd",
  7190. "Cmd-Down": "goDocEnd",
  7191. "Alt-Left": "goGroupLeft",
  7192. "Alt-Right": "goGroupRight",
  7193. "Cmd-Left": "goLineLeft",
  7194. "Cmd-Right": "goLineRight",
  7195. "Alt-Backspace": "delGroupBefore",
  7196. "Ctrl-Alt-Backspace": "delGroupAfter",
  7197. "Alt-Delete": "delGroupAfter",
  7198. "Cmd-S": "save",
  7199. "Cmd-F": "find",
  7200. "Cmd-G": "findNext",
  7201. "Shift-Cmd-G": "findPrev",
  7202. "Cmd-Alt-F": "replace",
  7203. "Shift-Cmd-Alt-F": "replaceAll",
  7204. "Cmd-[": "indentLess",
  7205. "Cmd-]": "indentMore",
  7206. "Cmd-Backspace": "delWrappedLineLeft",
  7207. "Cmd-Delete": "delWrappedLineRight",
  7208. "Cmd-U": "undoSelection",
  7209. "Shift-Cmd-U": "redoSelection",
  7210. "Ctrl-Up": "goDocStart",
  7211. "Ctrl-Down": "goDocEnd",
  7212. "fallthrough": ["basic", "emacsy"]
  7213. };
  7214. keyMap["default"] = mac ? keyMap.macDefault : keyMap.pcDefault;
  7215. function normalizeKeyName(name) {
  7216. var parts = name.split(/-(?!$)/);
  7217. name = parts[parts.length - 1];
  7218. var alt, ctrl, shift, cmd;
  7219. for (var i2 = 0; i2 < parts.length - 1; i2++) {
  7220. var mod = parts[i2];
  7221. if (/^(cmd|meta|m)$/i.test(mod)) {
  7222. cmd = true;
  7223. } else if (/^a(lt)?$/i.test(mod)) {
  7224. alt = true;
  7225. } else if (/^(c|ctrl|control)$/i.test(mod)) {
  7226. ctrl = true;
  7227. } else if (/^s(hift)?$/i.test(mod)) {
  7228. shift = true;
  7229. } else {
  7230. throw new Error("Unrecognized modifier name: " + mod);
  7231. }
  7232. }
  7233. if (alt) {
  7234. name = "Alt-" + name;
  7235. }
  7236. if (ctrl) {
  7237. name = "Ctrl-" + name;
  7238. }
  7239. if (cmd) {
  7240. name = "Cmd-" + name;
  7241. }
  7242. if (shift) {
  7243. name = "Shift-" + name;
  7244. }
  7245. return name;
  7246. }
  7247. function normalizeKeyMap(keymap) {
  7248. var copy = {};
  7249. for (var keyname in keymap) {
  7250. if (keymap.hasOwnProperty(keyname)) {
  7251. var value = keymap[keyname];
  7252. if (/^(name|fallthrough|(de|at)tach)$/.test(keyname)) {
  7253. continue;
  7254. }
  7255. if (value == "...") {
  7256. delete keymap[keyname];
  7257. continue;
  7258. }
  7259. var keys = map(keyname.split(" "), normalizeKeyName);
  7260. for (var i2 = 0; i2 < keys.length; i2++) {
  7261. var val = void 0, name = void 0;
  7262. if (i2 == keys.length - 1) {
  7263. name = keys.join(" ");
  7264. val = value;
  7265. } else {
  7266. name = keys.slice(0, i2 + 1).join(" ");
  7267. val = "...";
  7268. }
  7269. var prev = copy[name];
  7270. if (!prev) {
  7271. copy[name] = val;
  7272. } else if (prev != val) {
  7273. throw new Error("Inconsistent bindings for " + name);
  7274. }
  7275. }
  7276. delete keymap[keyname];
  7277. }
  7278. }
  7279. for (var prop2 in copy) {
  7280. keymap[prop2] = copy[prop2];
  7281. }
  7282. return keymap;
  7283. }
  7284. function lookupKey(key, map2, handle, context) {
  7285. map2 = getKeyMap(map2);
  7286. var found = map2.call ? map2.call(key, context) : map2[key];
  7287. if (found === false) {
  7288. return "nothing";
  7289. }
  7290. if (found === "...") {
  7291. return "multi";
  7292. }
  7293. if (found != null && handle(found)) {
  7294. return "handled";
  7295. }
  7296. if (map2.fallthrough) {
  7297. if (Object.prototype.toString.call(map2.fallthrough) != "[object Array]") {
  7298. return lookupKey(key, map2.fallthrough, handle, context);
  7299. }
  7300. for (var i2 = 0; i2 < map2.fallthrough.length; i2++) {
  7301. var result = lookupKey(key, map2.fallthrough[i2], handle, context);
  7302. if (result) {
  7303. return result;
  7304. }
  7305. }
  7306. }
  7307. }
  7308. function isModifierKey(value) {
  7309. var name = typeof value == "string" ? value : keyNames[value.keyCode];
  7310. return name == "Ctrl" || name == "Alt" || name == "Shift" || name == "Mod";
  7311. }
  7312. function addModifierNames(name, event, noShift) {
  7313. var base = name;
  7314. if (event.altKey && base != "Alt") {
  7315. name = "Alt-" + name;
  7316. }
  7317. if ((flipCtrlCmd ? event.metaKey : event.ctrlKey) && base != "Ctrl") {
  7318. name = "Ctrl-" + name;
  7319. }
  7320. if ((flipCtrlCmd ? event.ctrlKey : event.metaKey) && base != "Mod") {
  7321. name = "Cmd-" + name;
  7322. }
  7323. if (!noShift && event.shiftKey && base != "Shift") {
  7324. name = "Shift-" + name;
  7325. }
  7326. return name;
  7327. }
  7328. function keyName(event, noShift) {
  7329. if (presto && event.keyCode == 34 && event["char"]) {
  7330. return false;
  7331. }
  7332. var name = keyNames[event.keyCode];
  7333. if (name == null || event.altGraphKey) {
  7334. return false;
  7335. }
  7336. if (event.keyCode == 3 && event.code) {
  7337. name = event.code;
  7338. }
  7339. return addModifierNames(name, event, noShift);
  7340. }
  7341. function getKeyMap(val) {
  7342. return typeof val == "string" ? keyMap[val] : val;
  7343. }
  7344. function deleteNearSelection(cm, compute) {
  7345. var ranges = cm.doc.sel.ranges, kill = [];
  7346. for (var i2 = 0; i2 < ranges.length; i2++) {
  7347. var toKill = compute(ranges[i2]);
  7348. while (kill.length && cmp(toKill.from, lst(kill).to) <= 0) {
  7349. var replaced = kill.pop();
  7350. if (cmp(replaced.from, toKill.from) < 0) {
  7351. toKill.from = replaced.from;
  7352. break;
  7353. }
  7354. }
  7355. kill.push(toKill);
  7356. }
  7357. runInOp(cm, function() {
  7358. for (var i3 = kill.length - 1; i3 >= 0; i3--) {
  7359. replaceRange(cm.doc, "", kill[i3].from, kill[i3].to, "+delete");
  7360. }
  7361. ensureCursorVisible(cm);
  7362. });
  7363. }
  7364. function moveCharLogically(line, ch, dir) {
  7365. var target = skipExtendingChars(line.text, ch + dir, dir);
  7366. return target < 0 || target > line.text.length ? null : target;
  7367. }
  7368. function moveLogically(line, start, dir) {
  7369. var ch = moveCharLogically(line, start.ch, dir);
  7370. return ch == null ? null : new Pos(start.line, ch, dir < 0 ? "after" : "before");
  7371. }
  7372. function endOfLine(visually, cm, lineObj, lineNo2, dir) {
  7373. if (visually) {
  7374. if (cm.doc.direction == "rtl") {
  7375. dir = -dir;
  7376. }
  7377. var order = getOrder(lineObj, cm.doc.direction);
  7378. if (order) {
  7379. var part = dir < 0 ? lst(order) : order[0];
  7380. var moveInStorageOrder = dir < 0 == (part.level == 1);
  7381. var sticky = moveInStorageOrder ? "after" : "before";
  7382. var ch;
  7383. if (part.level > 0 || cm.doc.direction == "rtl") {
  7384. var prep = prepareMeasureForLine(cm, lineObj);
  7385. ch = dir < 0 ? lineObj.text.length - 1 : 0;
  7386. var targetTop = measureCharPrepared(cm, prep, ch).top;
  7387. ch = findFirst(function(ch2) {
  7388. return measureCharPrepared(cm, prep, ch2).top == targetTop;
  7389. }, dir < 0 == (part.level == 1) ? part.from : part.to - 1, ch);
  7390. if (sticky == "before") {
  7391. ch = moveCharLogically(lineObj, ch, 1);
  7392. }
  7393. } else {
  7394. ch = dir < 0 ? part.to : part.from;
  7395. }
  7396. return new Pos(lineNo2, ch, sticky);
  7397. }
  7398. }
  7399. return new Pos(lineNo2, dir < 0 ? lineObj.text.length : 0, dir < 0 ? "before" : "after");
  7400. }
  7401. function moveVisually(cm, line, start, dir) {
  7402. var bidi = getOrder(line, cm.doc.direction);
  7403. if (!bidi) {
  7404. return moveLogically(line, start, dir);
  7405. }
  7406. if (start.ch >= line.text.length) {
  7407. start.ch = line.text.length;
  7408. start.sticky = "before";
  7409. } else if (start.ch <= 0) {
  7410. start.ch = 0;
  7411. start.sticky = "after";
  7412. }
  7413. var partPos = getBidiPartAt(bidi, start.ch, start.sticky), part = bidi[partPos];
  7414. if (cm.doc.direction == "ltr" && part.level % 2 == 0 && (dir > 0 ? part.to > start.ch : part.from < start.ch)) {
  7415. return moveLogically(line, start, dir);
  7416. }
  7417. var mv = function(pos, dir2) {
  7418. return moveCharLogically(line, pos instanceof Pos ? pos.ch : pos, dir2);
  7419. };
  7420. var prep;
  7421. var getWrappedLineExtent = function(ch2) {
  7422. if (!cm.options.lineWrapping) {
  7423. return { begin: 0, end: line.text.length };
  7424. }
  7425. prep = prep || prepareMeasureForLine(cm, line);
  7426. return wrappedLineExtentChar(cm, line, prep, ch2);
  7427. };
  7428. var wrappedLineExtent2 = getWrappedLineExtent(start.sticky == "before" ? mv(start, -1) : start.ch);
  7429. if (cm.doc.direction == "rtl" || part.level == 1) {
  7430. var moveInStorageOrder = part.level == 1 == dir < 0;
  7431. var ch = mv(start, moveInStorageOrder ? 1 : -1);
  7432. if (ch != null && (!moveInStorageOrder ? ch >= part.from && ch >= wrappedLineExtent2.begin : ch <= part.to && ch <= wrappedLineExtent2.end)) {
  7433. var sticky = moveInStorageOrder ? "before" : "after";
  7434. return new Pos(start.line, ch, sticky);
  7435. }
  7436. }
  7437. var searchInVisualLine = function(partPos2, dir2, wrappedLineExtent3) {
  7438. var getRes = function(ch3, moveInStorageOrder3) {
  7439. return moveInStorageOrder3 ? new Pos(start.line, mv(ch3, 1), "before") : new Pos(start.line, ch3, "after");
  7440. };
  7441. for (; partPos2 >= 0 && partPos2 < bidi.length; partPos2 += dir2) {
  7442. var part2 = bidi[partPos2];
  7443. var moveInStorageOrder2 = dir2 > 0 == (part2.level != 1);
  7444. var ch2 = moveInStorageOrder2 ? wrappedLineExtent3.begin : mv(wrappedLineExtent3.end, -1);
  7445. if (part2.from <= ch2 && ch2 < part2.to) {
  7446. return getRes(ch2, moveInStorageOrder2);
  7447. }
  7448. ch2 = moveInStorageOrder2 ? part2.from : mv(part2.to, -1);
  7449. if (wrappedLineExtent3.begin <= ch2 && ch2 < wrappedLineExtent3.end) {
  7450. return getRes(ch2, moveInStorageOrder2);
  7451. }
  7452. }
  7453. };
  7454. var res = searchInVisualLine(partPos + dir, dir, wrappedLineExtent2);
  7455. if (res) {
  7456. return res;
  7457. }
  7458. var nextCh = dir > 0 ? wrappedLineExtent2.end : mv(wrappedLineExtent2.begin, -1);
  7459. if (nextCh != null && !(dir > 0 && nextCh == line.text.length)) {
  7460. res = searchInVisualLine(dir > 0 ? 0 : bidi.length - 1, dir, getWrappedLineExtent(nextCh));
  7461. if (res) {
  7462. return res;
  7463. }
  7464. }
  7465. return null;
  7466. }
  7467. var commands = {
  7468. selectAll,
  7469. singleSelection: function(cm) {
  7470. return cm.setSelection(cm.getCursor("anchor"), cm.getCursor("head"), sel_dontScroll);
  7471. },
  7472. killLine: function(cm) {
  7473. return deleteNearSelection(cm, function(range2) {
  7474. if (range2.empty()) {
  7475. var len = getLine(cm.doc, range2.head.line).text.length;
  7476. if (range2.head.ch == len && range2.head.line < cm.lastLine()) {
  7477. return { from: range2.head, to: Pos(range2.head.line + 1, 0) };
  7478. } else {
  7479. return { from: range2.head, to: Pos(range2.head.line, len) };
  7480. }
  7481. } else {
  7482. return { from: range2.from(), to: range2.to() };
  7483. }
  7484. });
  7485. },
  7486. deleteLine: function(cm) {
  7487. return deleteNearSelection(cm, function(range2) {
  7488. return {
  7489. from: Pos(range2.from().line, 0),
  7490. to: clipPos(cm.doc, Pos(range2.to().line + 1, 0))
  7491. };
  7492. });
  7493. },
  7494. delLineLeft: function(cm) {
  7495. return deleteNearSelection(cm, function(range2) {
  7496. return {
  7497. from: Pos(range2.from().line, 0),
  7498. to: range2.from()
  7499. };
  7500. });
  7501. },
  7502. delWrappedLineLeft: function(cm) {
  7503. return deleteNearSelection(cm, function(range2) {
  7504. var top = cm.charCoords(range2.head, "div").top + 5;
  7505. var leftPos = cm.coordsChar({ left: 0, top }, "div");
  7506. return { from: leftPos, to: range2.from() };
  7507. });
  7508. },
  7509. delWrappedLineRight: function(cm) {
  7510. return deleteNearSelection(cm, function(range2) {
  7511. var top = cm.charCoords(range2.head, "div").top + 5;
  7512. var rightPos = cm.coordsChar({ left: cm.display.lineDiv.offsetWidth + 100, top }, "div");
  7513. return { from: range2.from(), to: rightPos };
  7514. });
  7515. },
  7516. undo: function(cm) {
  7517. return cm.undo();
  7518. },
  7519. redo: function(cm) {
  7520. return cm.redo();
  7521. },
  7522. undoSelection: function(cm) {
  7523. return cm.undoSelection();
  7524. },
  7525. redoSelection: function(cm) {
  7526. return cm.redoSelection();
  7527. },
  7528. goDocStart: function(cm) {
  7529. return cm.extendSelection(Pos(cm.firstLine(), 0));
  7530. },
  7531. goDocEnd: function(cm) {
  7532. return cm.extendSelection(Pos(cm.lastLine()));
  7533. },
  7534. goLineStart: function(cm) {
  7535. return cm.extendSelectionsBy(
  7536. function(range2) {
  7537. return lineStart(cm, range2.head.line);
  7538. },
  7539. { origin: "+move", bias: 1 }
  7540. );
  7541. },
  7542. goLineStartSmart: function(cm) {
  7543. return cm.extendSelectionsBy(
  7544. function(range2) {
  7545. return lineStartSmart(cm, range2.head);
  7546. },
  7547. { origin: "+move", bias: 1 }
  7548. );
  7549. },
  7550. goLineEnd: function(cm) {
  7551. return cm.extendSelectionsBy(
  7552. function(range2) {
  7553. return lineEnd(cm, range2.head.line);
  7554. },
  7555. { origin: "+move", bias: -1 }
  7556. );
  7557. },
  7558. goLineRight: function(cm) {
  7559. return cm.extendSelectionsBy(function(range2) {
  7560. var top = cm.cursorCoords(range2.head, "div").top + 5;
  7561. return cm.coordsChar({ left: cm.display.lineDiv.offsetWidth + 100, top }, "div");
  7562. }, sel_move);
  7563. },
  7564. goLineLeft: function(cm) {
  7565. return cm.extendSelectionsBy(function(range2) {
  7566. var top = cm.cursorCoords(range2.head, "div").top + 5;
  7567. return cm.coordsChar({ left: 0, top }, "div");
  7568. }, sel_move);
  7569. },
  7570. goLineLeftSmart: function(cm) {
  7571. return cm.extendSelectionsBy(function(range2) {
  7572. var top = cm.cursorCoords(range2.head, "div").top + 5;
  7573. var pos = cm.coordsChar({ left: 0, top }, "div");
  7574. if (pos.ch < cm.getLine(pos.line).search(/\S/)) {
  7575. return lineStartSmart(cm, range2.head);
  7576. }
  7577. return pos;
  7578. }, sel_move);
  7579. },
  7580. goLineUp: function(cm) {
  7581. return cm.moveV(-1, "line");
  7582. },
  7583. goLineDown: function(cm) {
  7584. return cm.moveV(1, "line");
  7585. },
  7586. goPageUp: function(cm) {
  7587. return cm.moveV(-1, "page");
  7588. },
  7589. goPageDown: function(cm) {
  7590. return cm.moveV(1, "page");
  7591. },
  7592. goCharLeft: function(cm) {
  7593. return cm.moveH(-1, "char");
  7594. },
  7595. goCharRight: function(cm) {
  7596. return cm.moveH(1, "char");
  7597. },
  7598. goColumnLeft: function(cm) {
  7599. return cm.moveH(-1, "column");
  7600. },
  7601. goColumnRight: function(cm) {
  7602. return cm.moveH(1, "column");
  7603. },
  7604. goWordLeft: function(cm) {
  7605. return cm.moveH(-1, "word");
  7606. },
  7607. goGroupRight: function(cm) {
  7608. return cm.moveH(1, "group");
  7609. },
  7610. goGroupLeft: function(cm) {
  7611. return cm.moveH(-1, "group");
  7612. },
  7613. goWordRight: function(cm) {
  7614. return cm.moveH(1, "word");
  7615. },
  7616. delCharBefore: function(cm) {
  7617. return cm.deleteH(-1, "codepoint");
  7618. },
  7619. delCharAfter: function(cm) {
  7620. return cm.deleteH(1, "char");
  7621. },
  7622. delWordBefore: function(cm) {
  7623. return cm.deleteH(-1, "word");
  7624. },
  7625. delWordAfter: function(cm) {
  7626. return cm.deleteH(1, "word");
  7627. },
  7628. delGroupBefore: function(cm) {
  7629. return cm.deleteH(-1, "group");
  7630. },
  7631. delGroupAfter: function(cm) {
  7632. return cm.deleteH(1, "group");
  7633. },
  7634. indentAuto: function(cm) {
  7635. return cm.indentSelection("smart");
  7636. },
  7637. indentMore: function(cm) {
  7638. return cm.indentSelection("add");
  7639. },
  7640. indentLess: function(cm) {
  7641. return cm.indentSelection("subtract");
  7642. },
  7643. insertTab: function(cm) {
  7644. return cm.replaceSelection(" ");
  7645. },
  7646. insertSoftTab: function(cm) {
  7647. var spaces = [], ranges = cm.listSelections(), tabSize = cm.options.tabSize;
  7648. for (var i2 = 0; i2 < ranges.length; i2++) {
  7649. var pos = ranges[i2].from();
  7650. var col = countColumn(cm.getLine(pos.line), pos.ch, tabSize);
  7651. spaces.push(spaceStr(tabSize - col % tabSize));
  7652. }
  7653. cm.replaceSelections(spaces);
  7654. },
  7655. defaultTab: function(cm) {
  7656. if (cm.somethingSelected()) {
  7657. cm.indentSelection("add");
  7658. } else {
  7659. cm.execCommand("insertTab");
  7660. }
  7661. },
  7662. // Swap the two chars left and right of each selection's head.
  7663. // Move cursor behind the two swapped characters afterwards.
  7664. //
  7665. // Doesn't consider line feeds a character.
  7666. // Doesn't scan more than one line above to find a character.
  7667. // Doesn't do anything on an empty line.
  7668. // Doesn't do anything with non-empty selections.
  7669. transposeChars: function(cm) {
  7670. return runInOp(cm, function() {
  7671. var ranges = cm.listSelections(), newSel = [];
  7672. for (var i2 = 0; i2 < ranges.length; i2++) {
  7673. if (!ranges[i2].empty()) {
  7674. continue;
  7675. }
  7676. var cur = ranges[i2].head, line = getLine(cm.doc, cur.line).text;
  7677. if (line) {
  7678. if (cur.ch == line.length) {
  7679. cur = new Pos(cur.line, cur.ch - 1);
  7680. }
  7681. if (cur.ch > 0) {
  7682. cur = new Pos(cur.line, cur.ch + 1);
  7683. cm.replaceRange(
  7684. line.charAt(cur.ch - 1) + line.charAt(cur.ch - 2),
  7685. Pos(cur.line, cur.ch - 2),
  7686. cur,
  7687. "+transpose"
  7688. );
  7689. } else if (cur.line > cm.doc.first) {
  7690. var prev = getLine(cm.doc, cur.line - 1).text;
  7691. if (prev) {
  7692. cur = new Pos(cur.line, 1);
  7693. cm.replaceRange(
  7694. line.charAt(0) + cm.doc.lineSeparator() + prev.charAt(prev.length - 1),
  7695. Pos(cur.line - 1, prev.length - 1),
  7696. cur,
  7697. "+transpose"
  7698. );
  7699. }
  7700. }
  7701. }
  7702. newSel.push(new Range(cur, cur));
  7703. }
  7704. cm.setSelections(newSel);
  7705. });
  7706. },
  7707. newlineAndIndent: function(cm) {
  7708. return runInOp(cm, function() {
  7709. var sels = cm.listSelections();
  7710. for (var i2 = sels.length - 1; i2 >= 0; i2--) {
  7711. cm.replaceRange(cm.doc.lineSeparator(), sels[i2].anchor, sels[i2].head, "+input");
  7712. }
  7713. sels = cm.listSelections();
  7714. for (var i$12 = 0; i$12 < sels.length; i$12++) {
  7715. cm.indentLine(sels[i$12].from().line, null, true);
  7716. }
  7717. ensureCursorVisible(cm);
  7718. });
  7719. },
  7720. openLine: function(cm) {
  7721. return cm.replaceSelection("\n", "start");
  7722. },
  7723. toggleOverwrite: function(cm) {
  7724. return cm.toggleOverwrite();
  7725. }
  7726. };
  7727. function lineStart(cm, lineN) {
  7728. var line = getLine(cm.doc, lineN);
  7729. var visual = visualLine(line);
  7730. if (visual != line) {
  7731. lineN = lineNo(visual);
  7732. }
  7733. return endOfLine(true, cm, visual, lineN, 1);
  7734. }
  7735. function lineEnd(cm, lineN) {
  7736. var line = getLine(cm.doc, lineN);
  7737. var visual = visualLineEnd(line);
  7738. if (visual != line) {
  7739. lineN = lineNo(visual);
  7740. }
  7741. return endOfLine(true, cm, line, lineN, -1);
  7742. }
  7743. function lineStartSmart(cm, pos) {
  7744. var start = lineStart(cm, pos.line);
  7745. var line = getLine(cm.doc, start.line);
  7746. var order = getOrder(line, cm.doc.direction);
  7747. if (!order || order[0].level == 0) {
  7748. var firstNonWS = Math.max(start.ch, line.text.search(/\S/));
  7749. var inWS = pos.line == start.line && pos.ch <= firstNonWS && pos.ch;
  7750. return Pos(start.line, inWS ? 0 : firstNonWS, start.sticky);
  7751. }
  7752. return start;
  7753. }
  7754. function doHandleBinding(cm, bound, dropShift) {
  7755. if (typeof bound == "string") {
  7756. bound = commands[bound];
  7757. if (!bound) {
  7758. return false;
  7759. }
  7760. }
  7761. cm.display.input.ensurePolled();
  7762. var prevShift = cm.display.shift, done = false;
  7763. try {
  7764. if (cm.isReadOnly()) {
  7765. cm.state.suppressEdits = true;
  7766. }
  7767. if (dropShift) {
  7768. cm.display.shift = false;
  7769. }
  7770. done = bound(cm) != Pass;
  7771. } finally {
  7772. cm.display.shift = prevShift;
  7773. cm.state.suppressEdits = false;
  7774. }
  7775. return done;
  7776. }
  7777. function lookupKeyForEditor(cm, name, handle) {
  7778. for (var i2 = 0; i2 < cm.state.keyMaps.length; i2++) {
  7779. var result = lookupKey(name, cm.state.keyMaps[i2], handle, cm);
  7780. if (result) {
  7781. return result;
  7782. }
  7783. }
  7784. return cm.options.extraKeys && lookupKey(name, cm.options.extraKeys, handle, cm) || lookupKey(name, cm.options.keyMap, handle, cm);
  7785. }
  7786. var stopSeq = new Delayed();
  7787. function dispatchKey(cm, name, e, handle) {
  7788. var seq = cm.state.keySeq;
  7789. if (seq) {
  7790. if (isModifierKey(name)) {
  7791. return "handled";
  7792. }
  7793. if (/\'$/.test(name)) {
  7794. cm.state.keySeq = null;
  7795. } else {
  7796. stopSeq.set(50, function() {
  7797. if (cm.state.keySeq == seq) {
  7798. cm.state.keySeq = null;
  7799. cm.display.input.reset();
  7800. }
  7801. });
  7802. }
  7803. if (dispatchKeyInner(cm, seq + " " + name, e, handle)) {
  7804. return true;
  7805. }
  7806. }
  7807. return dispatchKeyInner(cm, name, e, handle);
  7808. }
  7809. function dispatchKeyInner(cm, name, e, handle) {
  7810. var result = lookupKeyForEditor(cm, name, handle);
  7811. if (result == "multi") {
  7812. cm.state.keySeq = name;
  7813. }
  7814. if (result == "handled") {
  7815. signalLater(cm, "keyHandled", cm, name, e);
  7816. }
  7817. if (result == "handled" || result == "multi") {
  7818. e_preventDefault(e);
  7819. restartBlink(cm);
  7820. }
  7821. return !!result;
  7822. }
  7823. function handleKeyBinding(cm, e) {
  7824. var name = keyName(e, true);
  7825. if (!name) {
  7826. return false;
  7827. }
  7828. if (e.shiftKey && !cm.state.keySeq) {
  7829. return dispatchKey(cm, "Shift-" + name, e, function(b) {
  7830. return doHandleBinding(cm, b, true);
  7831. }) || dispatchKey(cm, name, e, function(b) {
  7832. if (typeof b == "string" ? /^go[A-Z]/.test(b) : b.motion) {
  7833. return doHandleBinding(cm, b);
  7834. }
  7835. });
  7836. } else {
  7837. return dispatchKey(cm, name, e, function(b) {
  7838. return doHandleBinding(cm, b);
  7839. });
  7840. }
  7841. }
  7842. function handleCharBinding(cm, e, ch) {
  7843. return dispatchKey(cm, "'" + ch + "'", e, function(b) {
  7844. return doHandleBinding(cm, b, true);
  7845. });
  7846. }
  7847. var lastStoppedKey = null;
  7848. function onKeyDown(e) {
  7849. var cm = this;
  7850. if (e.target && e.target != cm.display.input.getField()) {
  7851. return;
  7852. }
  7853. cm.curOp.focus = activeElt(doc(cm));
  7854. if (signalDOMEvent(cm, e)) {
  7855. return;
  7856. }
  7857. if (ie && ie_version < 11 && e.keyCode == 27) {
  7858. e.returnValue = false;
  7859. }
  7860. var code = e.keyCode;
  7861. cm.display.shift = code == 16 || e.shiftKey;
  7862. var handled = handleKeyBinding(cm, e);
  7863. if (presto) {
  7864. lastStoppedKey = handled ? code : null;
  7865. if (!handled && code == 88 && !hasCopyEvent && (mac ? e.metaKey : e.ctrlKey)) {
  7866. cm.replaceSelection("", null, "cut");
  7867. }
  7868. }
  7869. if (gecko && !mac && !handled && code == 46 && e.shiftKey && !e.ctrlKey && document.execCommand) {
  7870. document.execCommand("cut");
  7871. }
  7872. if (code == 18 && !/\bCodeMirror-crosshair\b/.test(cm.display.lineDiv.className)) {
  7873. showCrossHair(cm);
  7874. }
  7875. }
  7876. function showCrossHair(cm) {
  7877. var lineDiv = cm.display.lineDiv;
  7878. addClass(lineDiv, "CodeMirror-crosshair");
  7879. function up(e) {
  7880. if (e.keyCode == 18 || !e.altKey) {
  7881. rmClass(lineDiv, "CodeMirror-crosshair");
  7882. off(document, "keyup", up);
  7883. off(document, "mouseover", up);
  7884. }
  7885. }
  7886. on(document, "keyup", up);
  7887. on(document, "mouseover", up);
  7888. }
  7889. function onKeyUp(e) {
  7890. if (e.keyCode == 16) {
  7891. this.doc.sel.shift = false;
  7892. }
  7893. signalDOMEvent(this, e);
  7894. }
  7895. function onKeyPress(e) {
  7896. var cm = this;
  7897. if (e.target && e.target != cm.display.input.getField()) {
  7898. return;
  7899. }
  7900. if (eventInWidget(cm.display, e) || signalDOMEvent(cm, e) || e.ctrlKey && !e.altKey || mac && e.metaKey) {
  7901. return;
  7902. }
  7903. var keyCode = e.keyCode, charCode = e.charCode;
  7904. if (presto && keyCode == lastStoppedKey) {
  7905. lastStoppedKey = null;
  7906. e_preventDefault(e);
  7907. return;
  7908. }
  7909. if (presto && (!e.which || e.which < 10) && handleKeyBinding(cm, e)) {
  7910. return;
  7911. }
  7912. var ch = String.fromCharCode(charCode == null ? keyCode : charCode);
  7913. if (ch == "\b") {
  7914. return;
  7915. }
  7916. if (handleCharBinding(cm, e, ch)) {
  7917. return;
  7918. }
  7919. cm.display.input.onKeyPress(e);
  7920. }
  7921. var DOUBLECLICK_DELAY = 400;
  7922. var PastClick = function(time, pos, button) {
  7923. this.time = time;
  7924. this.pos = pos;
  7925. this.button = button;
  7926. };
  7927. PastClick.prototype.compare = function(time, pos, button) {
  7928. return this.time + DOUBLECLICK_DELAY > time && cmp(pos, this.pos) == 0 && button == this.button;
  7929. };
  7930. var lastClick, lastDoubleClick;
  7931. function clickRepeat(pos, button) {
  7932. var now = +/* @__PURE__ */ new Date();
  7933. if (lastDoubleClick && lastDoubleClick.compare(now, pos, button)) {
  7934. lastClick = lastDoubleClick = null;
  7935. return "triple";
  7936. } else if (lastClick && lastClick.compare(now, pos, button)) {
  7937. lastDoubleClick = new PastClick(now, pos, button);
  7938. lastClick = null;
  7939. return "double";
  7940. } else {
  7941. lastClick = new PastClick(now, pos, button);
  7942. lastDoubleClick = null;
  7943. return "single";
  7944. }
  7945. }
  7946. function onMouseDown(e) {
  7947. var cm = this, display = cm.display;
  7948. if (signalDOMEvent(cm, e) || display.activeTouch && display.input.supportsTouch()) {
  7949. return;
  7950. }
  7951. display.input.ensurePolled();
  7952. display.shift = e.shiftKey;
  7953. if (eventInWidget(display, e)) {
  7954. if (!webkit) {
  7955. display.scroller.draggable = false;
  7956. setTimeout(function() {
  7957. return display.scroller.draggable = true;
  7958. }, 100);
  7959. }
  7960. return;
  7961. }
  7962. if (clickInGutter(cm, e)) {
  7963. return;
  7964. }
  7965. var pos = posFromMouse(cm, e), button = e_button(e), repeat = pos ? clickRepeat(pos, button) : "single";
  7966. win(cm).focus();
  7967. if (button == 1 && cm.state.selectingText) {
  7968. cm.state.selectingText(e);
  7969. }
  7970. if (pos && handleMappedButton(cm, button, pos, repeat, e)) {
  7971. return;
  7972. }
  7973. if (button == 1) {
  7974. if (pos) {
  7975. leftButtonDown(cm, pos, repeat, e);
  7976. } else if (e_target(e) == display.scroller) {
  7977. e_preventDefault(e);
  7978. }
  7979. } else if (button == 2) {
  7980. if (pos) {
  7981. extendSelection(cm.doc, pos);
  7982. }
  7983. setTimeout(function() {
  7984. return display.input.focus();
  7985. }, 20);
  7986. } else if (button == 3) {
  7987. if (captureRightClick) {
  7988. cm.display.input.onContextMenu(e);
  7989. } else {
  7990. delayBlurEvent(cm);
  7991. }
  7992. }
  7993. }
  7994. function handleMappedButton(cm, button, pos, repeat, event) {
  7995. var name = "Click";
  7996. if (repeat == "double") {
  7997. name = "Double" + name;
  7998. } else if (repeat == "triple") {
  7999. name = "Triple" + name;
  8000. }
  8001. name = (button == 1 ? "Left" : button == 2 ? "Middle" : "Right") + name;
  8002. return dispatchKey(cm, addModifierNames(name, event), event, function(bound) {
  8003. if (typeof bound == "string") {
  8004. bound = commands[bound];
  8005. }
  8006. if (!bound) {
  8007. return false;
  8008. }
  8009. var done = false;
  8010. try {
  8011. if (cm.isReadOnly()) {
  8012. cm.state.suppressEdits = true;
  8013. }
  8014. done = bound(cm, pos) != Pass;
  8015. } finally {
  8016. cm.state.suppressEdits = false;
  8017. }
  8018. return done;
  8019. });
  8020. }
  8021. function configureMouse(cm, repeat, event) {
  8022. var option = cm.getOption("configureMouse");
  8023. var value = option ? option(cm, repeat, event) : {};
  8024. if (value.unit == null) {
  8025. var rect = chromeOS ? event.shiftKey && event.metaKey : event.altKey;
  8026. value.unit = rect ? "rectangle" : repeat == "single" ? "char" : repeat == "double" ? "word" : "line";
  8027. }
  8028. if (value.extend == null || cm.doc.extend) {
  8029. value.extend = cm.doc.extend || event.shiftKey;
  8030. }
  8031. if (value.addNew == null) {
  8032. value.addNew = mac ? event.metaKey : event.ctrlKey;
  8033. }
  8034. if (value.moveOnDrag == null) {
  8035. value.moveOnDrag = !(mac ? event.altKey : event.ctrlKey);
  8036. }
  8037. return value;
  8038. }
  8039. function leftButtonDown(cm, pos, repeat, event) {
  8040. if (ie) {
  8041. setTimeout(bind(ensureFocus, cm), 0);
  8042. } else {
  8043. cm.curOp.focus = activeElt(doc(cm));
  8044. }
  8045. var behavior = configureMouse(cm, repeat, event);
  8046. var sel = cm.doc.sel, contained;
  8047. if (cm.options.dragDrop && dragAndDrop && !cm.isReadOnly() && repeat == "single" && (contained = sel.contains(pos)) > -1 && (cmp((contained = sel.ranges[contained]).from(), pos) < 0 || pos.xRel > 0) && (cmp(contained.to(), pos) > 0 || pos.xRel < 0)) {
  8048. leftButtonStartDrag(cm, event, pos, behavior);
  8049. } else {
  8050. leftButtonSelect(cm, event, pos, behavior);
  8051. }
  8052. }
  8053. function leftButtonStartDrag(cm, event, pos, behavior) {
  8054. var display = cm.display, moved = false;
  8055. var dragEnd = operation(cm, function(e) {
  8056. if (webkit) {
  8057. display.scroller.draggable = false;
  8058. }
  8059. cm.state.draggingText = false;
  8060. if (cm.state.delayingBlurEvent) {
  8061. if (cm.hasFocus()) {
  8062. cm.state.delayingBlurEvent = false;
  8063. } else {
  8064. delayBlurEvent(cm);
  8065. }
  8066. }
  8067. off(display.wrapper.ownerDocument, "mouseup", dragEnd);
  8068. off(display.wrapper.ownerDocument, "mousemove", mouseMove);
  8069. off(display.scroller, "dragstart", dragStart);
  8070. off(display.scroller, "drop", dragEnd);
  8071. if (!moved) {
  8072. e_preventDefault(e);
  8073. if (!behavior.addNew) {
  8074. extendSelection(cm.doc, pos, null, null, behavior.extend);
  8075. }
  8076. if (webkit && !safari || ie && ie_version == 9) {
  8077. setTimeout(function() {
  8078. display.wrapper.ownerDocument.body.focus({ preventScroll: true });
  8079. display.input.focus();
  8080. }, 20);
  8081. } else {
  8082. display.input.focus();
  8083. }
  8084. }
  8085. });
  8086. var mouseMove = function(e2) {
  8087. moved = moved || Math.abs(event.clientX - e2.clientX) + Math.abs(event.clientY - e2.clientY) >= 10;
  8088. };
  8089. var dragStart = function() {
  8090. return moved = true;
  8091. };
  8092. if (webkit) {
  8093. display.scroller.draggable = true;
  8094. }
  8095. cm.state.draggingText = dragEnd;
  8096. dragEnd.copy = !behavior.moveOnDrag;
  8097. on(display.wrapper.ownerDocument, "mouseup", dragEnd);
  8098. on(display.wrapper.ownerDocument, "mousemove", mouseMove);
  8099. on(display.scroller, "dragstart", dragStart);
  8100. on(display.scroller, "drop", dragEnd);
  8101. cm.state.delayingBlurEvent = true;
  8102. setTimeout(function() {
  8103. return display.input.focus();
  8104. }, 20);
  8105. if (display.scroller.dragDrop) {
  8106. display.scroller.dragDrop();
  8107. }
  8108. }
  8109. function rangeForUnit(cm, pos, unit) {
  8110. if (unit == "char") {
  8111. return new Range(pos, pos);
  8112. }
  8113. if (unit == "word") {
  8114. return cm.findWordAt(pos);
  8115. }
  8116. if (unit == "line") {
  8117. return new Range(Pos(pos.line, 0), clipPos(cm.doc, Pos(pos.line + 1, 0)));
  8118. }
  8119. var result = unit(cm, pos);
  8120. return new Range(result.from, result.to);
  8121. }
  8122. function leftButtonSelect(cm, event, start, behavior) {
  8123. if (ie) {
  8124. delayBlurEvent(cm);
  8125. }
  8126. var display = cm.display, doc$1 = cm.doc;
  8127. e_preventDefault(event);
  8128. var ourRange, ourIndex, startSel = doc$1.sel, ranges = startSel.ranges;
  8129. if (behavior.addNew && !behavior.extend) {
  8130. ourIndex = doc$1.sel.contains(start);
  8131. if (ourIndex > -1) {
  8132. ourRange = ranges[ourIndex];
  8133. } else {
  8134. ourRange = new Range(start, start);
  8135. }
  8136. } else {
  8137. ourRange = doc$1.sel.primary();
  8138. ourIndex = doc$1.sel.primIndex;
  8139. }
  8140. if (behavior.unit == "rectangle") {
  8141. if (!behavior.addNew) {
  8142. ourRange = new Range(start, start);
  8143. }
  8144. start = posFromMouse(cm, event, true, true);
  8145. ourIndex = -1;
  8146. } else {
  8147. var range2 = rangeForUnit(cm, start, behavior.unit);
  8148. if (behavior.extend) {
  8149. ourRange = extendRange(ourRange, range2.anchor, range2.head, behavior.extend);
  8150. } else {
  8151. ourRange = range2;
  8152. }
  8153. }
  8154. if (!behavior.addNew) {
  8155. ourIndex = 0;
  8156. setSelection(doc$1, new Selection([ourRange], 0), sel_mouse);
  8157. startSel = doc$1.sel;
  8158. } else if (ourIndex == -1) {
  8159. ourIndex = ranges.length;
  8160. setSelection(
  8161. doc$1,
  8162. normalizeSelection(cm, ranges.concat([ourRange]), ourIndex),
  8163. { scroll: false, origin: "*mouse" }
  8164. );
  8165. } else if (ranges.length > 1 && ranges[ourIndex].empty() && behavior.unit == "char" && !behavior.extend) {
  8166. setSelection(
  8167. doc$1,
  8168. normalizeSelection(cm, ranges.slice(0, ourIndex).concat(ranges.slice(ourIndex + 1)), 0),
  8169. { scroll: false, origin: "*mouse" }
  8170. );
  8171. startSel = doc$1.sel;
  8172. } else {
  8173. replaceOneSelection(doc$1, ourIndex, ourRange, sel_mouse);
  8174. }
  8175. var lastPos = start;
  8176. function extendTo(pos) {
  8177. if (cmp(lastPos, pos) == 0) {
  8178. return;
  8179. }
  8180. lastPos = pos;
  8181. if (behavior.unit == "rectangle") {
  8182. var ranges2 = [], tabSize = cm.options.tabSize;
  8183. var startCol = countColumn(getLine(doc$1, start.line).text, start.ch, tabSize);
  8184. var posCol = countColumn(getLine(doc$1, pos.line).text, pos.ch, tabSize);
  8185. var left = Math.min(startCol, posCol), right = Math.max(startCol, posCol);
  8186. for (var line = Math.min(start.line, pos.line), end = Math.min(cm.lastLine(), Math.max(start.line, pos.line)); line <= end; line++) {
  8187. var text = getLine(doc$1, line).text, leftPos = findColumn(text, left, tabSize);
  8188. if (left == right) {
  8189. ranges2.push(new Range(Pos(line, leftPos), Pos(line, leftPos)));
  8190. } else if (text.length > leftPos) {
  8191. ranges2.push(new Range(Pos(line, leftPos), Pos(line, findColumn(text, right, tabSize))));
  8192. }
  8193. }
  8194. if (!ranges2.length) {
  8195. ranges2.push(new Range(start, start));
  8196. }
  8197. setSelection(
  8198. doc$1,
  8199. normalizeSelection(cm, startSel.ranges.slice(0, ourIndex).concat(ranges2), ourIndex),
  8200. { origin: "*mouse", scroll: false }
  8201. );
  8202. cm.scrollIntoView(pos);
  8203. } else {
  8204. var oldRange = ourRange;
  8205. var range3 = rangeForUnit(cm, pos, behavior.unit);
  8206. var anchor = oldRange.anchor, head;
  8207. if (cmp(range3.anchor, anchor) > 0) {
  8208. head = range3.head;
  8209. anchor = minPos(oldRange.from(), range3.anchor);
  8210. } else {
  8211. head = range3.anchor;
  8212. anchor = maxPos(oldRange.to(), range3.head);
  8213. }
  8214. var ranges$1 = startSel.ranges.slice(0);
  8215. ranges$1[ourIndex] = bidiSimplify(cm, new Range(clipPos(doc$1, anchor), head));
  8216. setSelection(doc$1, normalizeSelection(cm, ranges$1, ourIndex), sel_mouse);
  8217. }
  8218. }
  8219. var editorSize = display.wrapper.getBoundingClientRect();
  8220. var counter = 0;
  8221. function extend(e) {
  8222. var curCount = ++counter;
  8223. var cur = posFromMouse(cm, e, true, behavior.unit == "rectangle");
  8224. if (!cur) {
  8225. return;
  8226. }
  8227. if (cmp(cur, lastPos) != 0) {
  8228. cm.curOp.focus = activeElt(doc(cm));
  8229. extendTo(cur);
  8230. var visible = visibleLines(display, doc$1);
  8231. if (cur.line >= visible.to || cur.line < visible.from) {
  8232. setTimeout(operation(cm, function() {
  8233. if (counter == curCount) {
  8234. extend(e);
  8235. }
  8236. }), 150);
  8237. }
  8238. } else {
  8239. var outside = e.clientY < editorSize.top ? -20 : e.clientY > editorSize.bottom ? 20 : 0;
  8240. if (outside) {
  8241. setTimeout(operation(cm, function() {
  8242. if (counter != curCount) {
  8243. return;
  8244. }
  8245. display.scroller.scrollTop += outside;
  8246. extend(e);
  8247. }), 50);
  8248. }
  8249. }
  8250. }
  8251. function done(e) {
  8252. cm.state.selectingText = false;
  8253. counter = Infinity;
  8254. if (e) {
  8255. e_preventDefault(e);
  8256. display.input.focus();
  8257. }
  8258. off(display.wrapper.ownerDocument, "mousemove", move);
  8259. off(display.wrapper.ownerDocument, "mouseup", up);
  8260. doc$1.history.lastSelOrigin = null;
  8261. }
  8262. var move = operation(cm, function(e) {
  8263. if (e.buttons === 0 || !e_button(e)) {
  8264. done(e);
  8265. } else {
  8266. extend(e);
  8267. }
  8268. });
  8269. var up = operation(cm, done);
  8270. cm.state.selectingText = up;
  8271. on(display.wrapper.ownerDocument, "mousemove", move);
  8272. on(display.wrapper.ownerDocument, "mouseup", up);
  8273. }
  8274. function bidiSimplify(cm, range2) {
  8275. var anchor = range2.anchor;
  8276. var head = range2.head;
  8277. var anchorLine = getLine(cm.doc, anchor.line);
  8278. if (cmp(anchor, head) == 0 && anchor.sticky == head.sticky) {
  8279. return range2;
  8280. }
  8281. var order = getOrder(anchorLine);
  8282. if (!order) {
  8283. return range2;
  8284. }
  8285. var index = getBidiPartAt(order, anchor.ch, anchor.sticky), part = order[index];
  8286. if (part.from != anchor.ch && part.to != anchor.ch) {
  8287. return range2;
  8288. }
  8289. var boundary = index + (part.from == anchor.ch == (part.level != 1) ? 0 : 1);
  8290. if (boundary == 0 || boundary == order.length) {
  8291. return range2;
  8292. }
  8293. var leftSide;
  8294. if (head.line != anchor.line) {
  8295. leftSide = (head.line - anchor.line) * (cm.doc.direction == "ltr" ? 1 : -1) > 0;
  8296. } else {
  8297. var headIndex = getBidiPartAt(order, head.ch, head.sticky);
  8298. var dir = headIndex - index || (head.ch - anchor.ch) * (part.level == 1 ? -1 : 1);
  8299. if (headIndex == boundary - 1 || headIndex == boundary) {
  8300. leftSide = dir < 0;
  8301. } else {
  8302. leftSide = dir > 0;
  8303. }
  8304. }
  8305. var usePart = order[boundary + (leftSide ? -1 : 0)];
  8306. var from = leftSide == (usePart.level == 1);
  8307. var ch = from ? usePart.from : usePart.to, sticky = from ? "after" : "before";
  8308. return anchor.ch == ch && anchor.sticky == sticky ? range2 : new Range(new Pos(anchor.line, ch, sticky), head);
  8309. }
  8310. function gutterEvent(cm, e, type, prevent) {
  8311. var mX, mY;
  8312. if (e.touches) {
  8313. mX = e.touches[0].clientX;
  8314. mY = e.touches[0].clientY;
  8315. } else {
  8316. try {
  8317. mX = e.clientX;
  8318. mY = e.clientY;
  8319. } catch (e$1) {
  8320. return false;
  8321. }
  8322. }
  8323. if (mX >= Math.floor(cm.display.gutters.getBoundingClientRect().right)) {
  8324. return false;
  8325. }
  8326. if (prevent) {
  8327. e_preventDefault(e);
  8328. }
  8329. var display = cm.display;
  8330. var lineBox = display.lineDiv.getBoundingClientRect();
  8331. if (mY > lineBox.bottom || !hasHandler(cm, type)) {
  8332. return e_defaultPrevented(e);
  8333. }
  8334. mY -= lineBox.top - display.viewOffset;
  8335. for (var i2 = 0; i2 < cm.display.gutterSpecs.length; ++i2) {
  8336. var g = display.gutters.childNodes[i2];
  8337. if (g && g.getBoundingClientRect().right >= mX) {
  8338. var line = lineAtHeight(cm.doc, mY);
  8339. var gutter = cm.display.gutterSpecs[i2];
  8340. signal(cm, type, cm, line, gutter.className, e);
  8341. return e_defaultPrevented(e);
  8342. }
  8343. }
  8344. }
  8345. function clickInGutter(cm, e) {
  8346. return gutterEvent(cm, e, "gutterClick", true);
  8347. }
  8348. function onContextMenu(cm, e) {
  8349. if (eventInWidget(cm.display, e) || contextMenuInGutter(cm, e)) {
  8350. return;
  8351. }
  8352. if (signalDOMEvent(cm, e, "contextmenu")) {
  8353. return;
  8354. }
  8355. if (!captureRightClick) {
  8356. cm.display.input.onContextMenu(e);
  8357. }
  8358. }
  8359. function contextMenuInGutter(cm, e) {
  8360. if (!hasHandler(cm, "gutterContextMenu")) {
  8361. return false;
  8362. }
  8363. return gutterEvent(cm, e, "gutterContextMenu", false);
  8364. }
  8365. function themeChanged(cm) {
  8366. cm.display.wrapper.className = cm.display.wrapper.className.replace(/\s*cm-s-\S+/g, "") + cm.options.theme.replace(/(^|\s)\s*/g, " cm-s-");
  8367. clearCaches(cm);
  8368. }
  8369. var Init = { toString: function() {
  8370. return "CodeMirror.Init";
  8371. } };
  8372. var defaults = {};
  8373. var optionHandlers = {};
  8374. function defineOptions(CodeMirror2) {
  8375. var optionHandlers2 = CodeMirror2.optionHandlers;
  8376. function option(name, deflt, handle, notOnInit) {
  8377. CodeMirror2.defaults[name] = deflt;
  8378. if (handle) {
  8379. optionHandlers2[name] = notOnInit ? function(cm, val, old) {
  8380. if (old != Init) {
  8381. handle(cm, val, old);
  8382. }
  8383. } : handle;
  8384. }
  8385. }
  8386. CodeMirror2.defineOption = option;
  8387. CodeMirror2.Init = Init;
  8388. option("value", "", function(cm, val) {
  8389. return cm.setValue(val);
  8390. }, true);
  8391. option("mode", null, function(cm, val) {
  8392. cm.doc.modeOption = val;
  8393. loadMode(cm);
  8394. }, true);
  8395. option("indentUnit", 2, loadMode, true);
  8396. option("indentWithTabs", false);
  8397. option("smartIndent", true);
  8398. option("tabSize", 4, function(cm) {
  8399. resetModeState(cm);
  8400. clearCaches(cm);
  8401. regChange(cm);
  8402. }, true);
  8403. option("lineSeparator", null, function(cm, val) {
  8404. cm.doc.lineSep = val;
  8405. if (!val) {
  8406. return;
  8407. }
  8408. var newBreaks = [], lineNo2 = cm.doc.first;
  8409. cm.doc.iter(function(line) {
  8410. for (var pos = 0; ; ) {
  8411. var found = line.text.indexOf(val, pos);
  8412. if (found == -1) {
  8413. break;
  8414. }
  8415. pos = found + val.length;
  8416. newBreaks.push(Pos(lineNo2, found));
  8417. }
  8418. lineNo2++;
  8419. });
  8420. for (var i2 = newBreaks.length - 1; i2 >= 0; i2--) {
  8421. replaceRange(cm.doc, val, newBreaks[i2], Pos(newBreaks[i2].line, newBreaks[i2].ch + val.length));
  8422. }
  8423. });
  8424. option("specialChars", /[\u0000-\u001f\u007f-\u009f\u00ad\u061c\u200b\u200e\u200f\u2028\u2029\u202d\u202e\u2066\u2067\u2069\ufeff\ufff9-\ufffc]/g, function(cm, val, old) {
  8425. cm.state.specialChars = new RegExp(val.source + (val.test(" ") ? "" : "| "), "g");
  8426. if (old != Init) {
  8427. cm.refresh();
  8428. }
  8429. });
  8430. option("specialCharPlaceholder", defaultSpecialCharPlaceholder, function(cm) {
  8431. return cm.refresh();
  8432. }, true);
  8433. option("electricChars", true);
  8434. option("inputStyle", mobile ? "contenteditable" : "textarea", function() {
  8435. throw new Error("inputStyle can not (yet) be changed in a running editor");
  8436. }, true);
  8437. option("spellcheck", false, function(cm, val) {
  8438. return cm.getInputField().spellcheck = val;
  8439. }, true);
  8440. option("autocorrect", false, function(cm, val) {
  8441. return cm.getInputField().autocorrect = val;
  8442. }, true);
  8443. option("autocapitalize", false, function(cm, val) {
  8444. return cm.getInputField().autocapitalize = val;
  8445. }, true);
  8446. option("rtlMoveVisually", !windows);
  8447. option("wholeLineUpdateBefore", true);
  8448. option("theme", "default", function(cm) {
  8449. themeChanged(cm);
  8450. updateGutters(cm);
  8451. }, true);
  8452. option("keyMap", "default", function(cm, val, old) {
  8453. var next = getKeyMap(val);
  8454. var prev = old != Init && getKeyMap(old);
  8455. if (prev && prev.detach) {
  8456. prev.detach(cm, next);
  8457. }
  8458. if (next.attach) {
  8459. next.attach(cm, prev || null);
  8460. }
  8461. });
  8462. option("extraKeys", null);
  8463. option("configureMouse", null);
  8464. option("lineWrapping", false, wrappingChanged, true);
  8465. option("gutters", [], function(cm, val) {
  8466. cm.display.gutterSpecs = getGutters(val, cm.options.lineNumbers);
  8467. updateGutters(cm);
  8468. }, true);
  8469. option("fixedGutter", true, function(cm, val) {
  8470. cm.display.gutters.style.left = val ? compensateForHScroll(cm.display) + "px" : "0";
  8471. cm.refresh();
  8472. }, true);
  8473. option("coverGutterNextToScrollbar", false, function(cm) {
  8474. return updateScrollbars(cm);
  8475. }, true);
  8476. option("scrollbarStyle", "native", function(cm) {
  8477. initScrollbars(cm);
  8478. updateScrollbars(cm);
  8479. cm.display.scrollbars.setScrollTop(cm.doc.scrollTop);
  8480. cm.display.scrollbars.setScrollLeft(cm.doc.scrollLeft);
  8481. }, true);
  8482. option("lineNumbers", false, function(cm, val) {
  8483. cm.display.gutterSpecs = getGutters(cm.options.gutters, val);
  8484. updateGutters(cm);
  8485. }, true);
  8486. option("firstLineNumber", 1, updateGutters, true);
  8487. option("lineNumberFormatter", function(integer) {
  8488. return integer;
  8489. }, updateGutters, true);
  8490. option("showCursorWhenSelecting", false, updateSelection, true);
  8491. option("resetSelectionOnContextMenu", true);
  8492. option("lineWiseCopyCut", true);
  8493. option("pasteLinesPerSelection", true);
  8494. option("selectionsMayTouch", false);
  8495. option("readOnly", false, function(cm, val) {
  8496. if (val == "nocursor") {
  8497. onBlur(cm);
  8498. cm.display.input.blur();
  8499. }
  8500. cm.display.input.readOnlyChanged(val);
  8501. });
  8502. option("screenReaderLabel", null, function(cm, val) {
  8503. val = val === "" ? null : val;
  8504. cm.display.input.screenReaderLabelChanged(val);
  8505. });
  8506. option("disableInput", false, function(cm, val) {
  8507. if (!val) {
  8508. cm.display.input.reset();
  8509. }
  8510. }, true);
  8511. option("dragDrop", true, dragDropChanged);
  8512. option("allowDropFileTypes", null);
  8513. option("cursorBlinkRate", 530);
  8514. option("cursorScrollMargin", 0);
  8515. option("cursorHeight", 1, updateSelection, true);
  8516. option("singleCursorHeightPerLine", true, updateSelection, true);
  8517. option("workTime", 100);
  8518. option("workDelay", 100);
  8519. option("flattenSpans", true, resetModeState, true);
  8520. option("addModeClass", false, resetModeState, true);
  8521. option("pollInterval", 100);
  8522. option("undoDepth", 200, function(cm, val) {
  8523. return cm.doc.history.undoDepth = val;
  8524. });
  8525. option("historyEventDelay", 1250);
  8526. option("viewportMargin", 10, function(cm) {
  8527. return cm.refresh();
  8528. }, true);
  8529. option("maxHighlightLength", 1e4, resetModeState, true);
  8530. option("moveInputWithCursor", true, function(cm, val) {
  8531. if (!val) {
  8532. cm.display.input.resetPosition();
  8533. }
  8534. });
  8535. option("tabindex", null, function(cm, val) {
  8536. return cm.display.input.getField().tabIndex = val || "";
  8537. });
  8538. option("autofocus", null);
  8539. option("direction", "ltr", function(cm, val) {
  8540. return cm.doc.setDirection(val);
  8541. }, true);
  8542. option("phrases", null);
  8543. }
  8544. function dragDropChanged(cm, value, old) {
  8545. var wasOn = old && old != Init;
  8546. if (!value != !wasOn) {
  8547. var funcs = cm.display.dragFunctions;
  8548. var toggle = value ? on : off;
  8549. toggle(cm.display.scroller, "dragstart", funcs.start);
  8550. toggle(cm.display.scroller, "dragenter", funcs.enter);
  8551. toggle(cm.display.scroller, "dragover", funcs.over);
  8552. toggle(cm.display.scroller, "dragleave", funcs.leave);
  8553. toggle(cm.display.scroller, "drop", funcs.drop);
  8554. }
  8555. }
  8556. function wrappingChanged(cm) {
  8557. if (cm.options.lineWrapping) {
  8558. addClass(cm.display.wrapper, "CodeMirror-wrap");
  8559. cm.display.sizer.style.minWidth = "";
  8560. cm.display.sizerWidth = null;
  8561. } else {
  8562. rmClass(cm.display.wrapper, "CodeMirror-wrap");
  8563. findMaxLine(cm);
  8564. }
  8565. estimateLineHeights(cm);
  8566. regChange(cm);
  8567. clearCaches(cm);
  8568. setTimeout(function() {
  8569. return updateScrollbars(cm);
  8570. }, 100);
  8571. }
  8572. function CodeMirror(place, options) {
  8573. var this$1 = this;
  8574. if (!(this instanceof CodeMirror)) {
  8575. return new CodeMirror(place, options);
  8576. }
  8577. this.options = options = options ? copyObj(options) : {};
  8578. copyObj(defaults, options, false);
  8579. var doc2 = options.value;
  8580. if (typeof doc2 == "string") {
  8581. doc2 = new Doc(doc2, options.mode, null, options.lineSeparator, options.direction);
  8582. } else if (options.mode) {
  8583. doc2.modeOption = options.mode;
  8584. }
  8585. this.doc = doc2;
  8586. var input = new CodeMirror.inputStyles[options.inputStyle](this);
  8587. var display = this.display = new Display(place, doc2, input, options);
  8588. display.wrapper.CodeMirror = this;
  8589. themeChanged(this);
  8590. if (options.lineWrapping) {
  8591. this.display.wrapper.className += " CodeMirror-wrap";
  8592. }
  8593. initScrollbars(this);
  8594. this.state = {
  8595. keyMaps: [],
  8596. // stores maps added by addKeyMap
  8597. overlays: [],
  8598. // highlighting overlays, as added by addOverlay
  8599. modeGen: 0,
  8600. // bumped when mode/overlay changes, used to invalidate highlighting info
  8601. overwrite: false,
  8602. delayingBlurEvent: false,
  8603. focused: false,
  8604. suppressEdits: false,
  8605. // used to disable editing during key handlers when in readOnly mode
  8606. pasteIncoming: -1,
  8607. cutIncoming: -1,
  8608. // help recognize paste/cut edits in input.poll
  8609. selectingText: false,
  8610. draggingText: false,
  8611. highlight: new Delayed(),
  8612. // stores highlight worker timeout
  8613. keySeq: null,
  8614. // Unfinished key sequence
  8615. specialChars: null
  8616. };
  8617. if (options.autofocus && !mobile) {
  8618. display.input.focus();
  8619. }
  8620. if (ie && ie_version < 11) {
  8621. setTimeout(function() {
  8622. return this$1.display.input.reset(true);
  8623. }, 20);
  8624. }
  8625. registerEventHandlers(this);
  8626. ensureGlobalHandlers();
  8627. startOperation(this);
  8628. this.curOp.forceUpdate = true;
  8629. attachDoc(this, doc2);
  8630. if (options.autofocus && !mobile || this.hasFocus()) {
  8631. setTimeout(function() {
  8632. if (this$1.hasFocus() && !this$1.state.focused) {
  8633. onFocus(this$1);
  8634. }
  8635. }, 20);
  8636. } else {
  8637. onBlur(this);
  8638. }
  8639. for (var opt in optionHandlers) {
  8640. if (optionHandlers.hasOwnProperty(opt)) {
  8641. optionHandlers[opt](this, options[opt], Init);
  8642. }
  8643. }
  8644. maybeUpdateLineNumberWidth(this);
  8645. if (options.finishInit) {
  8646. options.finishInit(this);
  8647. }
  8648. for (var i2 = 0; i2 < initHooks.length; ++i2) {
  8649. initHooks[i2](this);
  8650. }
  8651. endOperation(this);
  8652. if (webkit && options.lineWrapping && getComputedStyle(display.lineDiv).textRendering == "optimizelegibility") {
  8653. display.lineDiv.style.textRendering = "auto";
  8654. }
  8655. }
  8656. CodeMirror.defaults = defaults;
  8657. CodeMirror.optionHandlers = optionHandlers;
  8658. function registerEventHandlers(cm) {
  8659. var d = cm.display;
  8660. on(d.scroller, "mousedown", operation(cm, onMouseDown));
  8661. if (ie && ie_version < 11) {
  8662. on(d.scroller, "dblclick", operation(cm, function(e) {
  8663. if (signalDOMEvent(cm, e)) {
  8664. return;
  8665. }
  8666. var pos = posFromMouse(cm, e);
  8667. if (!pos || clickInGutter(cm, e) || eventInWidget(cm.display, e)) {
  8668. return;
  8669. }
  8670. e_preventDefault(e);
  8671. var word = cm.findWordAt(pos);
  8672. extendSelection(cm.doc, word.anchor, word.head);
  8673. }));
  8674. } else {
  8675. on(d.scroller, "dblclick", function(e) {
  8676. return signalDOMEvent(cm, e) || e_preventDefault(e);
  8677. });
  8678. }
  8679. on(d.scroller, "contextmenu", function(e) {
  8680. return onContextMenu(cm, e);
  8681. });
  8682. on(d.input.getField(), "contextmenu", function(e) {
  8683. if (!d.scroller.contains(e.target)) {
  8684. onContextMenu(cm, e);
  8685. }
  8686. });
  8687. var touchFinished, prevTouch = { end: 0 };
  8688. function finishTouch() {
  8689. if (d.activeTouch) {
  8690. touchFinished = setTimeout(function() {
  8691. return d.activeTouch = null;
  8692. }, 1e3);
  8693. prevTouch = d.activeTouch;
  8694. prevTouch.end = +/* @__PURE__ */ new Date();
  8695. }
  8696. }
  8697. function isMouseLikeTouchEvent(e) {
  8698. if (e.touches.length != 1) {
  8699. return false;
  8700. }
  8701. var touch = e.touches[0];
  8702. return touch.radiusX <= 1 && touch.radiusY <= 1;
  8703. }
  8704. function farAway(touch, other) {
  8705. if (other.left == null) {
  8706. return true;
  8707. }
  8708. var dx = other.left - touch.left, dy = other.top - touch.top;
  8709. return dx * dx + dy * dy > 20 * 20;
  8710. }
  8711. on(d.scroller, "touchstart", function(e) {
  8712. if (!signalDOMEvent(cm, e) && !isMouseLikeTouchEvent(e) && !clickInGutter(cm, e)) {
  8713. d.input.ensurePolled();
  8714. clearTimeout(touchFinished);
  8715. var now = +/* @__PURE__ */ new Date();
  8716. d.activeTouch = {
  8717. start: now,
  8718. moved: false,
  8719. prev: now - prevTouch.end <= 300 ? prevTouch : null
  8720. };
  8721. if (e.touches.length == 1) {
  8722. d.activeTouch.left = e.touches[0].pageX;
  8723. d.activeTouch.top = e.touches[0].pageY;
  8724. }
  8725. }
  8726. });
  8727. on(d.scroller, "touchmove", function() {
  8728. if (d.activeTouch) {
  8729. d.activeTouch.moved = true;
  8730. }
  8731. });
  8732. on(d.scroller, "touchend", function(e) {
  8733. var touch = d.activeTouch;
  8734. if (touch && !eventInWidget(d, e) && touch.left != null && !touch.moved && /* @__PURE__ */ new Date() - touch.start < 300) {
  8735. var pos = cm.coordsChar(d.activeTouch, "page"), range2;
  8736. if (!touch.prev || farAway(touch, touch.prev)) {
  8737. range2 = new Range(pos, pos);
  8738. } else if (!touch.prev.prev || farAway(touch, touch.prev.prev)) {
  8739. range2 = cm.findWordAt(pos);
  8740. } else {
  8741. range2 = new Range(Pos(pos.line, 0), clipPos(cm.doc, Pos(pos.line + 1, 0)));
  8742. }
  8743. cm.setSelection(range2.anchor, range2.head);
  8744. cm.focus();
  8745. e_preventDefault(e);
  8746. }
  8747. finishTouch();
  8748. });
  8749. on(d.scroller, "touchcancel", finishTouch);
  8750. on(d.scroller, "scroll", function() {
  8751. if (d.scroller.clientHeight) {
  8752. updateScrollTop(cm, d.scroller.scrollTop);
  8753. setScrollLeft(cm, d.scroller.scrollLeft, true);
  8754. signal(cm, "scroll", cm);
  8755. }
  8756. });
  8757. on(d.scroller, "mousewheel", function(e) {
  8758. return onScrollWheel(cm, e);
  8759. });
  8760. on(d.scroller, "DOMMouseScroll", function(e) {
  8761. return onScrollWheel(cm, e);
  8762. });
  8763. on(d.wrapper, "scroll", function() {
  8764. return d.wrapper.scrollTop = d.wrapper.scrollLeft = 0;
  8765. });
  8766. d.dragFunctions = {
  8767. enter: function(e) {
  8768. if (!signalDOMEvent(cm, e)) {
  8769. e_stop(e);
  8770. }
  8771. },
  8772. over: function(e) {
  8773. if (!signalDOMEvent(cm, e)) {
  8774. onDragOver(cm, e);
  8775. e_stop(e);
  8776. }
  8777. },
  8778. start: function(e) {
  8779. return onDragStart(cm, e);
  8780. },
  8781. drop: operation(cm, onDrop),
  8782. leave: function(e) {
  8783. if (!signalDOMEvent(cm, e)) {
  8784. clearDragCursor(cm);
  8785. }
  8786. }
  8787. };
  8788. var inp = d.input.getField();
  8789. on(inp, "keyup", function(e) {
  8790. return onKeyUp.call(cm, e);
  8791. });
  8792. on(inp, "keydown", operation(cm, onKeyDown));
  8793. on(inp, "keypress", operation(cm, onKeyPress));
  8794. on(inp, "focus", function(e) {
  8795. return onFocus(cm, e);
  8796. });
  8797. on(inp, "blur", function(e) {
  8798. return onBlur(cm, e);
  8799. });
  8800. }
  8801. var initHooks = [];
  8802. CodeMirror.defineInitHook = function(f) {
  8803. return initHooks.push(f);
  8804. };
  8805. function indentLine(cm, n, how, aggressive) {
  8806. var doc2 = cm.doc, state;
  8807. if (how == null) {
  8808. how = "add";
  8809. }
  8810. if (how == "smart") {
  8811. if (!doc2.mode.indent) {
  8812. how = "prev";
  8813. } else {
  8814. state = getContextBefore(cm, n).state;
  8815. }
  8816. }
  8817. var tabSize = cm.options.tabSize;
  8818. var line = getLine(doc2, n), curSpace = countColumn(line.text, null, tabSize);
  8819. if (line.stateAfter) {
  8820. line.stateAfter = null;
  8821. }
  8822. var curSpaceString = line.text.match(/^\s*/)[0], indentation;
  8823. if (!aggressive && !/\S/.test(line.text)) {
  8824. indentation = 0;
  8825. how = "not";
  8826. } else if (how == "smart") {
  8827. indentation = doc2.mode.indent(state, line.text.slice(curSpaceString.length), line.text);
  8828. if (indentation == Pass || indentation > 150) {
  8829. if (!aggressive) {
  8830. return;
  8831. }
  8832. how = "prev";
  8833. }
  8834. }
  8835. if (how == "prev") {
  8836. if (n > doc2.first) {
  8837. indentation = countColumn(getLine(doc2, n - 1).text, null, tabSize);
  8838. } else {
  8839. indentation = 0;
  8840. }
  8841. } else if (how == "add") {
  8842. indentation = curSpace + cm.options.indentUnit;
  8843. } else if (how == "subtract") {
  8844. indentation = curSpace - cm.options.indentUnit;
  8845. } else if (typeof how == "number") {
  8846. indentation = curSpace + how;
  8847. }
  8848. indentation = Math.max(0, indentation);
  8849. var indentString = "", pos = 0;
  8850. if (cm.options.indentWithTabs) {
  8851. for (var i2 = Math.floor(indentation / tabSize); i2; --i2) {
  8852. pos += tabSize;
  8853. indentString += " ";
  8854. }
  8855. }
  8856. if (pos < indentation) {
  8857. indentString += spaceStr(indentation - pos);
  8858. }
  8859. if (indentString != curSpaceString) {
  8860. replaceRange(doc2, indentString, Pos(n, 0), Pos(n, curSpaceString.length), "+input");
  8861. line.stateAfter = null;
  8862. return true;
  8863. } else {
  8864. for (var i$12 = 0; i$12 < doc2.sel.ranges.length; i$12++) {
  8865. var range2 = doc2.sel.ranges[i$12];
  8866. if (range2.head.line == n && range2.head.ch < curSpaceString.length) {
  8867. var pos$1 = Pos(n, curSpaceString.length);
  8868. replaceOneSelection(doc2, i$12, new Range(pos$1, pos$1));
  8869. break;
  8870. }
  8871. }
  8872. }
  8873. }
  8874. var lastCopied = null;
  8875. function setLastCopied(newLastCopied) {
  8876. lastCopied = newLastCopied;
  8877. }
  8878. function applyTextInput(cm, inserted, deleted, sel, origin) {
  8879. var doc2 = cm.doc;
  8880. cm.display.shift = false;
  8881. if (!sel) {
  8882. sel = doc2.sel;
  8883. }
  8884. var recent = +/* @__PURE__ */ new Date() - 200;
  8885. var paste = origin == "paste" || cm.state.pasteIncoming > recent;
  8886. var textLines = splitLinesAuto(inserted), multiPaste = null;
  8887. if (paste && sel.ranges.length > 1) {
  8888. if (lastCopied && lastCopied.text.join("\n") == inserted) {
  8889. if (sel.ranges.length % lastCopied.text.length == 0) {
  8890. multiPaste = [];
  8891. for (var i2 = 0; i2 < lastCopied.text.length; i2++) {
  8892. multiPaste.push(doc2.splitLines(lastCopied.text[i2]));
  8893. }
  8894. }
  8895. } else if (textLines.length == sel.ranges.length && cm.options.pasteLinesPerSelection) {
  8896. multiPaste = map(textLines, function(l) {
  8897. return [l];
  8898. });
  8899. }
  8900. }
  8901. var updateInput = cm.curOp.updateInput;
  8902. for (var i$12 = sel.ranges.length - 1; i$12 >= 0; i$12--) {
  8903. var range2 = sel.ranges[i$12];
  8904. var from = range2.from(), to = range2.to();
  8905. if (range2.empty()) {
  8906. if (deleted && deleted > 0) {
  8907. from = Pos(from.line, from.ch - deleted);
  8908. } else if (cm.state.overwrite && !paste) {
  8909. to = Pos(to.line, Math.min(getLine(doc2, to.line).text.length, to.ch + lst(textLines).length));
  8910. } else if (paste && lastCopied && lastCopied.lineWise && lastCopied.text.join("\n") == textLines.join("\n")) {
  8911. from = to = Pos(from.line, 0);
  8912. }
  8913. }
  8914. var changeEvent = {
  8915. from,
  8916. to,
  8917. text: multiPaste ? multiPaste[i$12 % multiPaste.length] : textLines,
  8918. origin: origin || (paste ? "paste" : cm.state.cutIncoming > recent ? "cut" : "+input")
  8919. };
  8920. makeChange(cm.doc, changeEvent);
  8921. signalLater(cm, "inputRead", cm, changeEvent);
  8922. }
  8923. if (inserted && !paste) {
  8924. triggerElectric(cm, inserted);
  8925. }
  8926. ensureCursorVisible(cm);
  8927. if (cm.curOp.updateInput < 2) {
  8928. cm.curOp.updateInput = updateInput;
  8929. }
  8930. cm.curOp.typing = true;
  8931. cm.state.pasteIncoming = cm.state.cutIncoming = -1;
  8932. }
  8933. function handlePaste(e, cm) {
  8934. var pasted = e.clipboardData && e.clipboardData.getData("Text");
  8935. if (pasted) {
  8936. e.preventDefault();
  8937. if (!cm.isReadOnly() && !cm.options.disableInput && cm.hasFocus()) {
  8938. runInOp(cm, function() {
  8939. return applyTextInput(cm, pasted, 0, null, "paste");
  8940. });
  8941. }
  8942. return true;
  8943. }
  8944. }
  8945. function triggerElectric(cm, inserted) {
  8946. if (!cm.options.electricChars || !cm.options.smartIndent) {
  8947. return;
  8948. }
  8949. var sel = cm.doc.sel;
  8950. for (var i2 = sel.ranges.length - 1; i2 >= 0; i2--) {
  8951. var range2 = sel.ranges[i2];
  8952. if (range2.head.ch > 100 || i2 && sel.ranges[i2 - 1].head.line == range2.head.line) {
  8953. continue;
  8954. }
  8955. var mode = cm.getModeAt(range2.head);
  8956. var indented = false;
  8957. if (mode.electricChars) {
  8958. for (var j = 0; j < mode.electricChars.length; j++) {
  8959. if (inserted.indexOf(mode.electricChars.charAt(j)) > -1) {
  8960. indented = indentLine(cm, range2.head.line, "smart");
  8961. break;
  8962. }
  8963. }
  8964. } else if (mode.electricInput) {
  8965. if (mode.electricInput.test(getLine(cm.doc, range2.head.line).text.slice(0, range2.head.ch))) {
  8966. indented = indentLine(cm, range2.head.line, "smart");
  8967. }
  8968. }
  8969. if (indented) {
  8970. signalLater(cm, "electricInput", cm, range2.head.line);
  8971. }
  8972. }
  8973. }
  8974. function copyableRanges(cm) {
  8975. var text = [], ranges = [];
  8976. for (var i2 = 0; i2 < cm.doc.sel.ranges.length; i2++) {
  8977. var line = cm.doc.sel.ranges[i2].head.line;
  8978. var lineRange = { anchor: Pos(line, 0), head: Pos(line + 1, 0) };
  8979. ranges.push(lineRange);
  8980. text.push(cm.getRange(lineRange.anchor, lineRange.head));
  8981. }
  8982. return { text, ranges };
  8983. }
  8984. function disableBrowserMagic(field, spellcheck, autocorrect, autocapitalize) {
  8985. field.setAttribute("autocorrect", autocorrect ? "on" : "off");
  8986. field.setAttribute("autocapitalize", autocapitalize ? "on" : "off");
  8987. field.setAttribute("spellcheck", !!spellcheck);
  8988. }
  8989. function hiddenTextarea() {
  8990. var te = elt("textarea", null, null, "position: absolute; bottom: -1em; padding: 0; width: 1px; height: 1em; min-height: 1em; outline: none");
  8991. var div = elt("div", [te], null, "overflow: hidden; position: relative; width: 3px; height: 0px;");
  8992. if (webkit) {
  8993. te.style.width = "1000px";
  8994. } else {
  8995. te.setAttribute("wrap", "off");
  8996. }
  8997. if (ios) {
  8998. te.style.border = "1px solid black";
  8999. }
  9000. return div;
  9001. }
  9002. function addEditorMethods(CodeMirror2) {
  9003. var optionHandlers2 = CodeMirror2.optionHandlers;
  9004. var helpers = CodeMirror2.helpers = {};
  9005. CodeMirror2.prototype = {
  9006. constructor: CodeMirror2,
  9007. focus: function() {
  9008. win(this).focus();
  9009. this.display.input.focus();
  9010. },
  9011. setOption: function(option, value) {
  9012. var options = this.options, old = options[option];
  9013. if (options[option] == value && option != "mode") {
  9014. return;
  9015. }
  9016. options[option] = value;
  9017. if (optionHandlers2.hasOwnProperty(option)) {
  9018. operation(this, optionHandlers2[option])(this, value, old);
  9019. }
  9020. signal(this, "optionChange", this, option);
  9021. },
  9022. getOption: function(option) {
  9023. return this.options[option];
  9024. },
  9025. getDoc: function() {
  9026. return this.doc;
  9027. },
  9028. addKeyMap: function(map2, bottom) {
  9029. this.state.keyMaps[bottom ? "push" : "unshift"](getKeyMap(map2));
  9030. },
  9031. removeKeyMap: function(map2) {
  9032. var maps = this.state.keyMaps;
  9033. for (var i2 = 0; i2 < maps.length; ++i2) {
  9034. if (maps[i2] == map2 || maps[i2].name == map2) {
  9035. maps.splice(i2, 1);
  9036. return true;
  9037. }
  9038. }
  9039. },
  9040. addOverlay: methodOp(function(spec, options) {
  9041. var mode = spec.token ? spec : CodeMirror2.getMode(this.options, spec);
  9042. if (mode.startState) {
  9043. throw new Error("Overlays may not be stateful.");
  9044. }
  9045. insertSorted(
  9046. this.state.overlays,
  9047. {
  9048. mode,
  9049. modeSpec: spec,
  9050. opaque: options && options.opaque,
  9051. priority: options && options.priority || 0
  9052. },
  9053. function(overlay) {
  9054. return overlay.priority;
  9055. }
  9056. );
  9057. this.state.modeGen++;
  9058. regChange(this);
  9059. }),
  9060. removeOverlay: methodOp(function(spec) {
  9061. var overlays = this.state.overlays;
  9062. for (var i2 = 0; i2 < overlays.length; ++i2) {
  9063. var cur = overlays[i2].modeSpec;
  9064. if (cur == spec || typeof spec == "string" && cur.name == spec) {
  9065. overlays.splice(i2, 1);
  9066. this.state.modeGen++;
  9067. regChange(this);
  9068. return;
  9069. }
  9070. }
  9071. }),
  9072. indentLine: methodOp(function(n, dir, aggressive) {
  9073. if (typeof dir != "string" && typeof dir != "number") {
  9074. if (dir == null) {
  9075. dir = this.options.smartIndent ? "smart" : "prev";
  9076. } else {
  9077. dir = dir ? "add" : "subtract";
  9078. }
  9079. }
  9080. if (isLine(this.doc, n)) {
  9081. indentLine(this, n, dir, aggressive);
  9082. }
  9083. }),
  9084. indentSelection: methodOp(function(how) {
  9085. var ranges = this.doc.sel.ranges, end = -1;
  9086. for (var i2 = 0; i2 < ranges.length; i2++) {
  9087. var range2 = ranges[i2];
  9088. if (!range2.empty()) {
  9089. var from = range2.from(), to = range2.to();
  9090. var start = Math.max(end, from.line);
  9091. end = Math.min(this.lastLine(), to.line - (to.ch ? 0 : 1)) + 1;
  9092. for (var j = start; j < end; ++j) {
  9093. indentLine(this, j, how);
  9094. }
  9095. var newRanges = this.doc.sel.ranges;
  9096. if (from.ch == 0 && ranges.length == newRanges.length && newRanges[i2].from().ch > 0) {
  9097. replaceOneSelection(this.doc, i2, new Range(from, newRanges[i2].to()), sel_dontScroll);
  9098. }
  9099. } else if (range2.head.line > end) {
  9100. indentLine(this, range2.head.line, how, true);
  9101. end = range2.head.line;
  9102. if (i2 == this.doc.sel.primIndex) {
  9103. ensureCursorVisible(this);
  9104. }
  9105. }
  9106. }
  9107. }),
  9108. // Fetch the parser token for a given character. Useful for hacks
  9109. // that want to inspect the mode state (say, for completion).
  9110. getTokenAt: function(pos, precise) {
  9111. return takeToken(this, pos, precise);
  9112. },
  9113. getLineTokens: function(line, precise) {
  9114. return takeToken(this, Pos(line), precise, true);
  9115. },
  9116. getTokenTypeAt: function(pos) {
  9117. pos = clipPos(this.doc, pos);
  9118. var styles = getLineStyles(this, getLine(this.doc, pos.line));
  9119. var before = 0, after = (styles.length - 1) / 2, ch = pos.ch;
  9120. var type;
  9121. if (ch == 0) {
  9122. type = styles[2];
  9123. } else {
  9124. for (; ; ) {
  9125. var mid = before + after >> 1;
  9126. if ((mid ? styles[mid * 2 - 1] : 0) >= ch) {
  9127. after = mid;
  9128. } else if (styles[mid * 2 + 1] < ch) {
  9129. before = mid + 1;
  9130. } else {
  9131. type = styles[mid * 2 + 2];
  9132. break;
  9133. }
  9134. }
  9135. }
  9136. var cut = type ? type.indexOf("overlay ") : -1;
  9137. return cut < 0 ? type : cut == 0 ? null : type.slice(0, cut - 1);
  9138. },
  9139. getModeAt: function(pos) {
  9140. var mode = this.doc.mode;
  9141. if (!mode.innerMode) {
  9142. return mode;
  9143. }
  9144. return CodeMirror2.innerMode(mode, this.getTokenAt(pos).state).mode;
  9145. },
  9146. getHelper: function(pos, type) {
  9147. return this.getHelpers(pos, type)[0];
  9148. },
  9149. getHelpers: function(pos, type) {
  9150. var found = [];
  9151. if (!helpers.hasOwnProperty(type)) {
  9152. return found;
  9153. }
  9154. var help = helpers[type], mode = this.getModeAt(pos);
  9155. if (typeof mode[type] == "string") {
  9156. if (help[mode[type]]) {
  9157. found.push(help[mode[type]]);
  9158. }
  9159. } else if (mode[type]) {
  9160. for (var i2 = 0; i2 < mode[type].length; i2++) {
  9161. var val = help[mode[type][i2]];
  9162. if (val) {
  9163. found.push(val);
  9164. }
  9165. }
  9166. } else if (mode.helperType && help[mode.helperType]) {
  9167. found.push(help[mode.helperType]);
  9168. } else if (help[mode.name]) {
  9169. found.push(help[mode.name]);
  9170. }
  9171. for (var i$12 = 0; i$12 < help._global.length; i$12++) {
  9172. var cur = help._global[i$12];
  9173. if (cur.pred(mode, this) && indexOf(found, cur.val) == -1) {
  9174. found.push(cur.val);
  9175. }
  9176. }
  9177. return found;
  9178. },
  9179. getStateAfter: function(line, precise) {
  9180. var doc2 = this.doc;
  9181. line = clipLine(doc2, line == null ? doc2.first + doc2.size - 1 : line);
  9182. return getContextBefore(this, line + 1, precise).state;
  9183. },
  9184. cursorCoords: function(start, mode) {
  9185. var pos, range2 = this.doc.sel.primary();
  9186. if (start == null) {
  9187. pos = range2.head;
  9188. } else if (typeof start == "object") {
  9189. pos = clipPos(this.doc, start);
  9190. } else {
  9191. pos = start ? range2.from() : range2.to();
  9192. }
  9193. return cursorCoords(this, pos, mode || "page");
  9194. },
  9195. charCoords: function(pos, mode) {
  9196. return charCoords(this, clipPos(this.doc, pos), mode || "page");
  9197. },
  9198. coordsChar: function(coords, mode) {
  9199. coords = fromCoordSystem(this, coords, mode || "page");
  9200. return coordsChar(this, coords.left, coords.top);
  9201. },
  9202. lineAtHeight: function(height, mode) {
  9203. height = fromCoordSystem(this, { top: height, left: 0 }, mode || "page").top;
  9204. return lineAtHeight(this.doc, height + this.display.viewOffset);
  9205. },
  9206. heightAtLine: function(line, mode, includeWidgets) {
  9207. var end = false, lineObj;
  9208. if (typeof line == "number") {
  9209. var last = this.doc.first + this.doc.size - 1;
  9210. if (line < this.doc.first) {
  9211. line = this.doc.first;
  9212. } else if (line > last) {
  9213. line = last;
  9214. end = true;
  9215. }
  9216. lineObj = getLine(this.doc, line);
  9217. } else {
  9218. lineObj = line;
  9219. }
  9220. return intoCoordSystem(this, lineObj, { top: 0, left: 0 }, mode || "page", includeWidgets || end).top + (end ? this.doc.height - heightAtLine(lineObj) : 0);
  9221. },
  9222. defaultTextHeight: function() {
  9223. return textHeight(this.display);
  9224. },
  9225. defaultCharWidth: function() {
  9226. return charWidth(this.display);
  9227. },
  9228. getViewport: function() {
  9229. return { from: this.display.viewFrom, to: this.display.viewTo };
  9230. },
  9231. addWidget: function(pos, node, scroll, vert, horiz) {
  9232. var display = this.display;
  9233. pos = cursorCoords(this, clipPos(this.doc, pos));
  9234. var top = pos.bottom, left = pos.left;
  9235. node.style.position = "absolute";
  9236. node.setAttribute("cm-ignore-events", "true");
  9237. this.display.input.setUneditable(node);
  9238. display.sizer.appendChild(node);
  9239. if (vert == "over") {
  9240. top = pos.top;
  9241. } else if (vert == "above" || vert == "near") {
  9242. var vspace = Math.max(display.wrapper.clientHeight, this.doc.height), hspace = Math.max(display.sizer.clientWidth, display.lineSpace.clientWidth);
  9243. if ((vert == "above" || pos.bottom + node.offsetHeight > vspace) && pos.top > node.offsetHeight) {
  9244. top = pos.top - node.offsetHeight;
  9245. } else if (pos.bottom + node.offsetHeight <= vspace) {
  9246. top = pos.bottom;
  9247. }
  9248. if (left + node.offsetWidth > hspace) {
  9249. left = hspace - node.offsetWidth;
  9250. }
  9251. }
  9252. node.style.top = top + "px";
  9253. node.style.left = node.style.right = "";
  9254. if (horiz == "right") {
  9255. left = display.sizer.clientWidth - node.offsetWidth;
  9256. node.style.right = "0px";
  9257. } else {
  9258. if (horiz == "left") {
  9259. left = 0;
  9260. } else if (horiz == "middle") {
  9261. left = (display.sizer.clientWidth - node.offsetWidth) / 2;
  9262. }
  9263. node.style.left = left + "px";
  9264. }
  9265. if (scroll) {
  9266. scrollIntoView(this, { left, top, right: left + node.offsetWidth, bottom: top + node.offsetHeight });
  9267. }
  9268. },
  9269. triggerOnKeyDown: methodOp(onKeyDown),
  9270. triggerOnKeyPress: methodOp(onKeyPress),
  9271. triggerOnKeyUp: onKeyUp,
  9272. triggerOnMouseDown: methodOp(onMouseDown),
  9273. execCommand: function(cmd) {
  9274. if (commands.hasOwnProperty(cmd)) {
  9275. return commands[cmd].call(null, this);
  9276. }
  9277. },
  9278. triggerElectric: methodOp(function(text) {
  9279. triggerElectric(this, text);
  9280. }),
  9281. findPosH: function(from, amount, unit, visually) {
  9282. var dir = 1;
  9283. if (amount < 0) {
  9284. dir = -1;
  9285. amount = -amount;
  9286. }
  9287. var cur = clipPos(this.doc, from);
  9288. for (var i2 = 0; i2 < amount; ++i2) {
  9289. cur = findPosH(this.doc, cur, dir, unit, visually);
  9290. if (cur.hitSide) {
  9291. break;
  9292. }
  9293. }
  9294. return cur;
  9295. },
  9296. moveH: methodOp(function(dir, unit) {
  9297. var this$1 = this;
  9298. this.extendSelectionsBy(function(range2) {
  9299. if (this$1.display.shift || this$1.doc.extend || range2.empty()) {
  9300. return findPosH(this$1.doc, range2.head, dir, unit, this$1.options.rtlMoveVisually);
  9301. } else {
  9302. return dir < 0 ? range2.from() : range2.to();
  9303. }
  9304. }, sel_move);
  9305. }),
  9306. deleteH: methodOp(function(dir, unit) {
  9307. var sel = this.doc.sel, doc2 = this.doc;
  9308. if (sel.somethingSelected()) {
  9309. doc2.replaceSelection("", null, "+delete");
  9310. } else {
  9311. deleteNearSelection(this, function(range2) {
  9312. var other = findPosH(doc2, range2.head, dir, unit, false);
  9313. return dir < 0 ? { from: other, to: range2.head } : { from: range2.head, to: other };
  9314. });
  9315. }
  9316. }),
  9317. findPosV: function(from, amount, unit, goalColumn) {
  9318. var dir = 1, x = goalColumn;
  9319. if (amount < 0) {
  9320. dir = -1;
  9321. amount = -amount;
  9322. }
  9323. var cur = clipPos(this.doc, from);
  9324. for (var i2 = 0; i2 < amount; ++i2) {
  9325. var coords = cursorCoords(this, cur, "div");
  9326. if (x == null) {
  9327. x = coords.left;
  9328. } else {
  9329. coords.left = x;
  9330. }
  9331. cur = findPosV(this, coords, dir, unit);
  9332. if (cur.hitSide) {
  9333. break;
  9334. }
  9335. }
  9336. return cur;
  9337. },
  9338. moveV: methodOp(function(dir, unit) {
  9339. var this$1 = this;
  9340. var doc2 = this.doc, goals = [];
  9341. var collapse = !this.display.shift && !doc2.extend && doc2.sel.somethingSelected();
  9342. doc2.extendSelectionsBy(function(range2) {
  9343. if (collapse) {
  9344. return dir < 0 ? range2.from() : range2.to();
  9345. }
  9346. var headPos = cursorCoords(this$1, range2.head, "div");
  9347. if (range2.goalColumn != null) {
  9348. headPos.left = range2.goalColumn;
  9349. }
  9350. goals.push(headPos.left);
  9351. var pos = findPosV(this$1, headPos, dir, unit);
  9352. if (unit == "page" && range2 == doc2.sel.primary()) {
  9353. addToScrollTop(this$1, charCoords(this$1, pos, "div").top - headPos.top);
  9354. }
  9355. return pos;
  9356. }, sel_move);
  9357. if (goals.length) {
  9358. for (var i2 = 0; i2 < doc2.sel.ranges.length; i2++) {
  9359. doc2.sel.ranges[i2].goalColumn = goals[i2];
  9360. }
  9361. }
  9362. }),
  9363. // Find the word at the given position (as returned by coordsChar).
  9364. findWordAt: function(pos) {
  9365. var doc2 = this.doc, line = getLine(doc2, pos.line).text;
  9366. var start = pos.ch, end = pos.ch;
  9367. if (line) {
  9368. var helper = this.getHelper(pos, "wordChars");
  9369. if ((pos.sticky == "before" || end == line.length) && start) {
  9370. --start;
  9371. } else {
  9372. ++end;
  9373. }
  9374. var startChar = line.charAt(start);
  9375. var check = isWordChar(startChar, helper) ? function(ch) {
  9376. return isWordChar(ch, helper);
  9377. } : /\s/.test(startChar) ? function(ch) {
  9378. return /\s/.test(ch);
  9379. } : function(ch) {
  9380. return !/\s/.test(ch) && !isWordChar(ch);
  9381. };
  9382. while (start > 0 && check(line.charAt(start - 1))) {
  9383. --start;
  9384. }
  9385. while (end < line.length && check(line.charAt(end))) {
  9386. ++end;
  9387. }
  9388. }
  9389. return new Range(Pos(pos.line, start), Pos(pos.line, end));
  9390. },
  9391. toggleOverwrite: function(value) {
  9392. if (value != null && value == this.state.overwrite) {
  9393. return;
  9394. }
  9395. if (this.state.overwrite = !this.state.overwrite) {
  9396. addClass(this.display.cursorDiv, "CodeMirror-overwrite");
  9397. } else {
  9398. rmClass(this.display.cursorDiv, "CodeMirror-overwrite");
  9399. }
  9400. signal(this, "overwriteToggle", this, this.state.overwrite);
  9401. },
  9402. hasFocus: function() {
  9403. return this.display.input.getField() == activeElt(doc(this));
  9404. },
  9405. isReadOnly: function() {
  9406. return !!(this.options.readOnly || this.doc.cantEdit);
  9407. },
  9408. scrollTo: methodOp(function(x, y) {
  9409. scrollToCoords(this, x, y);
  9410. }),
  9411. getScrollInfo: function() {
  9412. var scroller = this.display.scroller;
  9413. return {
  9414. left: scroller.scrollLeft,
  9415. top: scroller.scrollTop,
  9416. height: scroller.scrollHeight - scrollGap(this) - this.display.barHeight,
  9417. width: scroller.scrollWidth - scrollGap(this) - this.display.barWidth,
  9418. clientHeight: displayHeight(this),
  9419. clientWidth: displayWidth(this)
  9420. };
  9421. },
  9422. scrollIntoView: methodOp(function(range2, margin) {
  9423. if (range2 == null) {
  9424. range2 = { from: this.doc.sel.primary().head, to: null };
  9425. if (margin == null) {
  9426. margin = this.options.cursorScrollMargin;
  9427. }
  9428. } else if (typeof range2 == "number") {
  9429. range2 = { from: Pos(range2, 0), to: null };
  9430. } else if (range2.from == null) {
  9431. range2 = { from: range2, to: null };
  9432. }
  9433. if (!range2.to) {
  9434. range2.to = range2.from;
  9435. }
  9436. range2.margin = margin || 0;
  9437. if (range2.from.line != null) {
  9438. scrollToRange(this, range2);
  9439. } else {
  9440. scrollToCoordsRange(this, range2.from, range2.to, range2.margin);
  9441. }
  9442. }),
  9443. setSize: methodOp(function(width, height) {
  9444. var this$1 = this;
  9445. var interpret = function(val) {
  9446. return typeof val == "number" || /^\d+$/.test(String(val)) ? val + "px" : val;
  9447. };
  9448. if (width != null) {
  9449. this.display.wrapper.style.width = interpret(width);
  9450. }
  9451. if (height != null) {
  9452. this.display.wrapper.style.height = interpret(height);
  9453. }
  9454. if (this.options.lineWrapping) {
  9455. clearLineMeasurementCache(this);
  9456. }
  9457. var lineNo2 = this.display.viewFrom;
  9458. this.doc.iter(lineNo2, this.display.viewTo, function(line) {
  9459. if (line.widgets) {
  9460. for (var i2 = 0; i2 < line.widgets.length; i2++) {
  9461. if (line.widgets[i2].noHScroll) {
  9462. regLineChange(this$1, lineNo2, "widget");
  9463. break;
  9464. }
  9465. }
  9466. }
  9467. ++lineNo2;
  9468. });
  9469. this.curOp.forceUpdate = true;
  9470. signal(this, "refresh", this);
  9471. }),
  9472. operation: function(f) {
  9473. return runInOp(this, f);
  9474. },
  9475. startOperation: function() {
  9476. return startOperation(this);
  9477. },
  9478. endOperation: function() {
  9479. return endOperation(this);
  9480. },
  9481. refresh: methodOp(function() {
  9482. var oldHeight = this.display.cachedTextHeight;
  9483. regChange(this);
  9484. this.curOp.forceUpdate = true;
  9485. clearCaches(this);
  9486. scrollToCoords(this, this.doc.scrollLeft, this.doc.scrollTop);
  9487. updateGutterSpace(this.display);
  9488. if (oldHeight == null || Math.abs(oldHeight - textHeight(this.display)) > 0.5 || this.options.lineWrapping) {
  9489. estimateLineHeights(this);
  9490. }
  9491. signal(this, "refresh", this);
  9492. }),
  9493. swapDoc: methodOp(function(doc2) {
  9494. var old = this.doc;
  9495. old.cm = null;
  9496. if (this.state.selectingText) {
  9497. this.state.selectingText();
  9498. }
  9499. attachDoc(this, doc2);
  9500. clearCaches(this);
  9501. this.display.input.reset();
  9502. scrollToCoords(this, doc2.scrollLeft, doc2.scrollTop);
  9503. this.curOp.forceScroll = true;
  9504. signalLater(this, "swapDoc", this, old);
  9505. return old;
  9506. }),
  9507. phrase: function(phraseText) {
  9508. var phrases = this.options.phrases;
  9509. return phrases && Object.prototype.hasOwnProperty.call(phrases, phraseText) ? phrases[phraseText] : phraseText;
  9510. },
  9511. getInputField: function() {
  9512. return this.display.input.getField();
  9513. },
  9514. getWrapperElement: function() {
  9515. return this.display.wrapper;
  9516. },
  9517. getScrollerElement: function() {
  9518. return this.display.scroller;
  9519. },
  9520. getGutterElement: function() {
  9521. return this.display.gutters;
  9522. }
  9523. };
  9524. eventMixin(CodeMirror2);
  9525. CodeMirror2.registerHelper = function(type, name, value) {
  9526. if (!helpers.hasOwnProperty(type)) {
  9527. helpers[type] = CodeMirror2[type] = { _global: [] };
  9528. }
  9529. helpers[type][name] = value;
  9530. };
  9531. CodeMirror2.registerGlobalHelper = function(type, name, predicate, value) {
  9532. CodeMirror2.registerHelper(type, name, value);
  9533. helpers[type]._global.push({ pred: predicate, val: value });
  9534. };
  9535. }
  9536. function findPosH(doc2, pos, dir, unit, visually) {
  9537. var oldPos = pos;
  9538. var origDir = dir;
  9539. var lineObj = getLine(doc2, pos.line);
  9540. var lineDir = visually && doc2.direction == "rtl" ? -dir : dir;
  9541. function findNextLine() {
  9542. var l = pos.line + lineDir;
  9543. if (l < doc2.first || l >= doc2.first + doc2.size) {
  9544. return false;
  9545. }
  9546. pos = new Pos(l, pos.ch, pos.sticky);
  9547. return lineObj = getLine(doc2, l);
  9548. }
  9549. function moveOnce(boundToLine) {
  9550. var next;
  9551. if (unit == "codepoint") {
  9552. var ch = lineObj.text.charCodeAt(pos.ch + (dir > 0 ? 0 : -1));
  9553. if (isNaN(ch)) {
  9554. next = null;
  9555. } else {
  9556. var astral = dir > 0 ? ch >= 55296 && ch < 56320 : ch >= 56320 && ch < 57343;
  9557. next = new Pos(pos.line, Math.max(0, Math.min(lineObj.text.length, pos.ch + dir * (astral ? 2 : 1))), -dir);
  9558. }
  9559. } else if (visually) {
  9560. next = moveVisually(doc2.cm, lineObj, pos, dir);
  9561. } else {
  9562. next = moveLogically(lineObj, pos, dir);
  9563. }
  9564. if (next == null) {
  9565. if (!boundToLine && findNextLine()) {
  9566. pos = endOfLine(visually, doc2.cm, lineObj, pos.line, lineDir);
  9567. } else {
  9568. return false;
  9569. }
  9570. } else {
  9571. pos = next;
  9572. }
  9573. return true;
  9574. }
  9575. if (unit == "char" || unit == "codepoint") {
  9576. moveOnce();
  9577. } else if (unit == "column") {
  9578. moveOnce(true);
  9579. } else if (unit == "word" || unit == "group") {
  9580. var sawType = null, group = unit == "group";
  9581. var helper = doc2.cm && doc2.cm.getHelper(pos, "wordChars");
  9582. for (var first = true; ; first = false) {
  9583. if (dir < 0 && !moveOnce(!first)) {
  9584. break;
  9585. }
  9586. var cur = lineObj.text.charAt(pos.ch) || "\n";
  9587. var type = isWordChar(cur, helper) ? "w" : group && cur == "\n" ? "n" : !group || /\s/.test(cur) ? null : "p";
  9588. if (group && !first && !type) {
  9589. type = "s";
  9590. }
  9591. if (sawType && sawType != type) {
  9592. if (dir < 0) {
  9593. dir = 1;
  9594. moveOnce();
  9595. pos.sticky = "after";
  9596. }
  9597. break;
  9598. }
  9599. if (type) {
  9600. sawType = type;
  9601. }
  9602. if (dir > 0 && !moveOnce(!first)) {
  9603. break;
  9604. }
  9605. }
  9606. }
  9607. var result = skipAtomic(doc2, pos, oldPos, origDir, true);
  9608. if (equalCursorPos(oldPos, result)) {
  9609. result.hitSide = true;
  9610. }
  9611. return result;
  9612. }
  9613. function findPosV(cm, pos, dir, unit) {
  9614. var doc2 = cm.doc, x = pos.left, y;
  9615. if (unit == "page") {
  9616. var pageSize = Math.min(cm.display.wrapper.clientHeight, win(cm).innerHeight || doc2(cm).documentElement.clientHeight);
  9617. var moveAmount = Math.max(pageSize - 0.5 * textHeight(cm.display), 3);
  9618. y = (dir > 0 ? pos.bottom : pos.top) + dir * moveAmount;
  9619. } else if (unit == "line") {
  9620. y = dir > 0 ? pos.bottom + 3 : pos.top - 3;
  9621. }
  9622. var target;
  9623. for (; ; ) {
  9624. target = coordsChar(cm, x, y);
  9625. if (!target.outside) {
  9626. break;
  9627. }
  9628. if (dir < 0 ? y <= 0 : y >= doc2.height) {
  9629. target.hitSide = true;
  9630. break;
  9631. }
  9632. y += dir * 5;
  9633. }
  9634. return target;
  9635. }
  9636. var ContentEditableInput = function(cm) {
  9637. this.cm = cm;
  9638. this.lastAnchorNode = this.lastAnchorOffset = this.lastFocusNode = this.lastFocusOffset = null;
  9639. this.polling = new Delayed();
  9640. this.composing = null;
  9641. this.gracePeriod = false;
  9642. this.readDOMTimeout = null;
  9643. };
  9644. ContentEditableInput.prototype.init = function(display) {
  9645. var this$1 = this;
  9646. var input = this, cm = input.cm;
  9647. var div = input.div = display.lineDiv;
  9648. div.contentEditable = true;
  9649. disableBrowserMagic(div, cm.options.spellcheck, cm.options.autocorrect, cm.options.autocapitalize);
  9650. function belongsToInput(e) {
  9651. for (var t = e.target; t; t = t.parentNode) {
  9652. if (t == div) {
  9653. return true;
  9654. }
  9655. if (/\bCodeMirror-(?:line)?widget\b/.test(t.className)) {
  9656. break;
  9657. }
  9658. }
  9659. return false;
  9660. }
  9661. on(div, "paste", function(e) {
  9662. if (!belongsToInput(e) || signalDOMEvent(cm, e) || handlePaste(e, cm)) {
  9663. return;
  9664. }
  9665. if (ie_version <= 11) {
  9666. setTimeout(operation(cm, function() {
  9667. return this$1.updateFromDOM();
  9668. }), 20);
  9669. }
  9670. });
  9671. on(div, "compositionstart", function(e) {
  9672. this$1.composing = { data: e.data, done: false };
  9673. });
  9674. on(div, "compositionupdate", function(e) {
  9675. if (!this$1.composing) {
  9676. this$1.composing = { data: e.data, done: false };
  9677. }
  9678. });
  9679. on(div, "compositionend", function(e) {
  9680. if (this$1.composing) {
  9681. if (e.data != this$1.composing.data) {
  9682. this$1.readFromDOMSoon();
  9683. }
  9684. this$1.composing.done = true;
  9685. }
  9686. });
  9687. on(div, "touchstart", function() {
  9688. return input.forceCompositionEnd();
  9689. });
  9690. on(div, "input", function() {
  9691. if (!this$1.composing) {
  9692. this$1.readFromDOMSoon();
  9693. }
  9694. });
  9695. function onCopyCut(e) {
  9696. if (!belongsToInput(e) || signalDOMEvent(cm, e)) {
  9697. return;
  9698. }
  9699. if (cm.somethingSelected()) {
  9700. setLastCopied({ lineWise: false, text: cm.getSelections() });
  9701. if (e.type == "cut") {
  9702. cm.replaceSelection("", null, "cut");
  9703. }
  9704. } else if (!cm.options.lineWiseCopyCut) {
  9705. return;
  9706. } else {
  9707. var ranges = copyableRanges(cm);
  9708. setLastCopied({ lineWise: true, text: ranges.text });
  9709. if (e.type == "cut") {
  9710. cm.operation(function() {
  9711. cm.setSelections(ranges.ranges, 0, sel_dontScroll);
  9712. cm.replaceSelection("", null, "cut");
  9713. });
  9714. }
  9715. }
  9716. if (e.clipboardData) {
  9717. e.clipboardData.clearData();
  9718. var content = lastCopied.text.join("\n");
  9719. e.clipboardData.setData("Text", content);
  9720. if (e.clipboardData.getData("Text") == content) {
  9721. e.preventDefault();
  9722. return;
  9723. }
  9724. }
  9725. var kludge = hiddenTextarea(), te = kludge.firstChild;
  9726. disableBrowserMagic(te);
  9727. cm.display.lineSpace.insertBefore(kludge, cm.display.lineSpace.firstChild);
  9728. te.value = lastCopied.text.join("\n");
  9729. var hadFocus = activeElt(div.ownerDocument);
  9730. selectInput(te);
  9731. setTimeout(function() {
  9732. cm.display.lineSpace.removeChild(kludge);
  9733. hadFocus.focus();
  9734. if (hadFocus == div) {
  9735. input.showPrimarySelection();
  9736. }
  9737. }, 50);
  9738. }
  9739. on(div, "copy", onCopyCut);
  9740. on(div, "cut", onCopyCut);
  9741. };
  9742. ContentEditableInput.prototype.screenReaderLabelChanged = function(label) {
  9743. if (label) {
  9744. this.div.setAttribute("aria-label", label);
  9745. } else {
  9746. this.div.removeAttribute("aria-label");
  9747. }
  9748. };
  9749. ContentEditableInput.prototype.prepareSelection = function() {
  9750. var result = prepareSelection(this.cm, false);
  9751. result.focus = activeElt(this.div.ownerDocument) == this.div;
  9752. return result;
  9753. };
  9754. ContentEditableInput.prototype.showSelection = function(info, takeFocus) {
  9755. if (!info || !this.cm.display.view.length) {
  9756. return;
  9757. }
  9758. if (info.focus || takeFocus) {
  9759. this.showPrimarySelection();
  9760. }
  9761. this.showMultipleSelections(info);
  9762. };
  9763. ContentEditableInput.prototype.getSelection = function() {
  9764. return this.cm.display.wrapper.ownerDocument.getSelection();
  9765. };
  9766. ContentEditableInput.prototype.showPrimarySelection = function() {
  9767. var sel = this.getSelection(), cm = this.cm, prim = cm.doc.sel.primary();
  9768. var from = prim.from(), to = prim.to();
  9769. if (cm.display.viewTo == cm.display.viewFrom || from.line >= cm.display.viewTo || to.line < cm.display.viewFrom) {
  9770. sel.removeAllRanges();
  9771. return;
  9772. }
  9773. var curAnchor = domToPos(cm, sel.anchorNode, sel.anchorOffset);
  9774. var curFocus = domToPos(cm, sel.focusNode, sel.focusOffset);
  9775. if (curAnchor && !curAnchor.bad && curFocus && !curFocus.bad && cmp(minPos(curAnchor, curFocus), from) == 0 && cmp(maxPos(curAnchor, curFocus), to) == 0) {
  9776. return;
  9777. }
  9778. var view = cm.display.view;
  9779. var start = from.line >= cm.display.viewFrom && posToDOM(cm, from) || { node: view[0].measure.map[2], offset: 0 };
  9780. var end = to.line < cm.display.viewTo && posToDOM(cm, to);
  9781. if (!end) {
  9782. var measure = view[view.length - 1].measure;
  9783. var map2 = measure.maps ? measure.maps[measure.maps.length - 1] : measure.map;
  9784. end = { node: map2[map2.length - 1], offset: map2[map2.length - 2] - map2[map2.length - 3] };
  9785. }
  9786. if (!start || !end) {
  9787. sel.removeAllRanges();
  9788. return;
  9789. }
  9790. var old = sel.rangeCount && sel.getRangeAt(0), rng;
  9791. try {
  9792. rng = range(start.node, start.offset, end.offset, end.node);
  9793. } catch (e) {
  9794. }
  9795. if (rng) {
  9796. if (!gecko && cm.state.focused) {
  9797. sel.collapse(start.node, start.offset);
  9798. if (!rng.collapsed) {
  9799. sel.removeAllRanges();
  9800. sel.addRange(rng);
  9801. }
  9802. } else {
  9803. sel.removeAllRanges();
  9804. sel.addRange(rng);
  9805. }
  9806. if (old && sel.anchorNode == null) {
  9807. sel.addRange(old);
  9808. } else if (gecko) {
  9809. this.startGracePeriod();
  9810. }
  9811. }
  9812. this.rememberSelection();
  9813. };
  9814. ContentEditableInput.prototype.startGracePeriod = function() {
  9815. var this$1 = this;
  9816. clearTimeout(this.gracePeriod);
  9817. this.gracePeriod = setTimeout(function() {
  9818. this$1.gracePeriod = false;
  9819. if (this$1.selectionChanged()) {
  9820. this$1.cm.operation(function() {
  9821. return this$1.cm.curOp.selectionChanged = true;
  9822. });
  9823. }
  9824. }, 20);
  9825. };
  9826. ContentEditableInput.prototype.showMultipleSelections = function(info) {
  9827. removeChildrenAndAdd(this.cm.display.cursorDiv, info.cursors);
  9828. removeChildrenAndAdd(this.cm.display.selectionDiv, info.selection);
  9829. };
  9830. ContentEditableInput.prototype.rememberSelection = function() {
  9831. var sel = this.getSelection();
  9832. this.lastAnchorNode = sel.anchorNode;
  9833. this.lastAnchorOffset = sel.anchorOffset;
  9834. this.lastFocusNode = sel.focusNode;
  9835. this.lastFocusOffset = sel.focusOffset;
  9836. };
  9837. ContentEditableInput.prototype.selectionInEditor = function() {
  9838. var sel = this.getSelection();
  9839. if (!sel.rangeCount) {
  9840. return false;
  9841. }
  9842. var node = sel.getRangeAt(0).commonAncestorContainer;
  9843. return contains(this.div, node);
  9844. };
  9845. ContentEditableInput.prototype.focus = function() {
  9846. if (this.cm.options.readOnly != "nocursor") {
  9847. if (!this.selectionInEditor() || activeElt(this.div.ownerDocument) != this.div) {
  9848. this.showSelection(this.prepareSelection(), true);
  9849. }
  9850. this.div.focus();
  9851. }
  9852. };
  9853. ContentEditableInput.prototype.blur = function() {
  9854. this.div.blur();
  9855. };
  9856. ContentEditableInput.prototype.getField = function() {
  9857. return this.div;
  9858. };
  9859. ContentEditableInput.prototype.supportsTouch = function() {
  9860. return true;
  9861. };
  9862. ContentEditableInput.prototype.receivedFocus = function() {
  9863. var this$1 = this;
  9864. var input = this;
  9865. if (this.selectionInEditor()) {
  9866. setTimeout(function() {
  9867. return this$1.pollSelection();
  9868. }, 20);
  9869. } else {
  9870. runInOp(this.cm, function() {
  9871. return input.cm.curOp.selectionChanged = true;
  9872. });
  9873. }
  9874. function poll() {
  9875. if (input.cm.state.focused) {
  9876. input.pollSelection();
  9877. input.polling.set(input.cm.options.pollInterval, poll);
  9878. }
  9879. }
  9880. this.polling.set(this.cm.options.pollInterval, poll);
  9881. };
  9882. ContentEditableInput.prototype.selectionChanged = function() {
  9883. var sel = this.getSelection();
  9884. return sel.anchorNode != this.lastAnchorNode || sel.anchorOffset != this.lastAnchorOffset || sel.focusNode != this.lastFocusNode || sel.focusOffset != this.lastFocusOffset;
  9885. };
  9886. ContentEditableInput.prototype.pollSelection = function() {
  9887. if (this.readDOMTimeout != null || this.gracePeriod || !this.selectionChanged()) {
  9888. return;
  9889. }
  9890. var sel = this.getSelection(), cm = this.cm;
  9891. if (android && chrome && this.cm.display.gutterSpecs.length && isInGutter(sel.anchorNode)) {
  9892. this.cm.triggerOnKeyDown({ type: "keydown", keyCode: 8, preventDefault: Math.abs });
  9893. this.blur();
  9894. this.focus();
  9895. return;
  9896. }
  9897. if (this.composing) {
  9898. return;
  9899. }
  9900. this.rememberSelection();
  9901. var anchor = domToPos(cm, sel.anchorNode, sel.anchorOffset);
  9902. var head = domToPos(cm, sel.focusNode, sel.focusOffset);
  9903. if (anchor && head) {
  9904. runInOp(cm, function() {
  9905. setSelection(cm.doc, simpleSelection(anchor, head), sel_dontScroll);
  9906. if (anchor.bad || head.bad) {
  9907. cm.curOp.selectionChanged = true;
  9908. }
  9909. });
  9910. }
  9911. };
  9912. ContentEditableInput.prototype.pollContent = function() {
  9913. if (this.readDOMTimeout != null) {
  9914. clearTimeout(this.readDOMTimeout);
  9915. this.readDOMTimeout = null;
  9916. }
  9917. var cm = this.cm, display = cm.display, sel = cm.doc.sel.primary();
  9918. var from = sel.from(), to = sel.to();
  9919. if (from.ch == 0 && from.line > cm.firstLine()) {
  9920. from = Pos(from.line - 1, getLine(cm.doc, from.line - 1).length);
  9921. }
  9922. if (to.ch == getLine(cm.doc, to.line).text.length && to.line < cm.lastLine()) {
  9923. to = Pos(to.line + 1, 0);
  9924. }
  9925. if (from.line < display.viewFrom || to.line > display.viewTo - 1) {
  9926. return false;
  9927. }
  9928. var fromIndex, fromLine, fromNode;
  9929. if (from.line == display.viewFrom || (fromIndex = findViewIndex(cm, from.line)) == 0) {
  9930. fromLine = lineNo(display.view[0].line);
  9931. fromNode = display.view[0].node;
  9932. } else {
  9933. fromLine = lineNo(display.view[fromIndex].line);
  9934. fromNode = display.view[fromIndex - 1].node.nextSibling;
  9935. }
  9936. var toIndex = findViewIndex(cm, to.line);
  9937. var toLine, toNode;
  9938. if (toIndex == display.view.length - 1) {
  9939. toLine = display.viewTo - 1;
  9940. toNode = display.lineDiv.lastChild;
  9941. } else {
  9942. toLine = lineNo(display.view[toIndex + 1].line) - 1;
  9943. toNode = display.view[toIndex + 1].node.previousSibling;
  9944. }
  9945. if (!fromNode) {
  9946. return false;
  9947. }
  9948. var newText = cm.doc.splitLines(domTextBetween(cm, fromNode, toNode, fromLine, toLine));
  9949. var oldText = getBetween(cm.doc, Pos(fromLine, 0), Pos(toLine, getLine(cm.doc, toLine).text.length));
  9950. while (newText.length > 1 && oldText.length > 1) {
  9951. if (lst(newText) == lst(oldText)) {
  9952. newText.pop();
  9953. oldText.pop();
  9954. toLine--;
  9955. } else if (newText[0] == oldText[0]) {
  9956. newText.shift();
  9957. oldText.shift();
  9958. fromLine++;
  9959. } else {
  9960. break;
  9961. }
  9962. }
  9963. var cutFront = 0, cutEnd = 0;
  9964. var newTop = newText[0], oldTop = oldText[0], maxCutFront = Math.min(newTop.length, oldTop.length);
  9965. while (cutFront < maxCutFront && newTop.charCodeAt(cutFront) == oldTop.charCodeAt(cutFront)) {
  9966. ++cutFront;
  9967. }
  9968. var newBot = lst(newText), oldBot = lst(oldText);
  9969. var maxCutEnd = Math.min(
  9970. newBot.length - (newText.length == 1 ? cutFront : 0),
  9971. oldBot.length - (oldText.length == 1 ? cutFront : 0)
  9972. );
  9973. while (cutEnd < maxCutEnd && newBot.charCodeAt(newBot.length - cutEnd - 1) == oldBot.charCodeAt(oldBot.length - cutEnd - 1)) {
  9974. ++cutEnd;
  9975. }
  9976. if (newText.length == 1 && oldText.length == 1 && fromLine == from.line) {
  9977. while (cutFront && cutFront > from.ch && newBot.charCodeAt(newBot.length - cutEnd - 1) == oldBot.charCodeAt(oldBot.length - cutEnd - 1)) {
  9978. cutFront--;
  9979. cutEnd++;
  9980. }
  9981. }
  9982. newText[newText.length - 1] = newBot.slice(0, newBot.length - cutEnd).replace(/^\u200b+/, "");
  9983. newText[0] = newText[0].slice(cutFront).replace(/\u200b+$/, "");
  9984. var chFrom = Pos(fromLine, cutFront);
  9985. var chTo = Pos(toLine, oldText.length ? lst(oldText).length - cutEnd : 0);
  9986. if (newText.length > 1 || newText[0] || cmp(chFrom, chTo)) {
  9987. replaceRange(cm.doc, newText, chFrom, chTo, "+input");
  9988. return true;
  9989. }
  9990. };
  9991. ContentEditableInput.prototype.ensurePolled = function() {
  9992. this.forceCompositionEnd();
  9993. };
  9994. ContentEditableInput.prototype.reset = function() {
  9995. this.forceCompositionEnd();
  9996. };
  9997. ContentEditableInput.prototype.forceCompositionEnd = function() {
  9998. if (!this.composing) {
  9999. return;
  10000. }
  10001. clearTimeout(this.readDOMTimeout);
  10002. this.composing = null;
  10003. this.updateFromDOM();
  10004. this.div.blur();
  10005. this.div.focus();
  10006. };
  10007. ContentEditableInput.prototype.readFromDOMSoon = function() {
  10008. var this$1 = this;
  10009. if (this.readDOMTimeout != null) {
  10010. return;
  10011. }
  10012. this.readDOMTimeout = setTimeout(function() {
  10013. this$1.readDOMTimeout = null;
  10014. if (this$1.composing) {
  10015. if (this$1.composing.done) {
  10016. this$1.composing = null;
  10017. } else {
  10018. return;
  10019. }
  10020. }
  10021. this$1.updateFromDOM();
  10022. }, 80);
  10023. };
  10024. ContentEditableInput.prototype.updateFromDOM = function() {
  10025. var this$1 = this;
  10026. if (this.cm.isReadOnly() || !this.pollContent()) {
  10027. runInOp(this.cm, function() {
  10028. return regChange(this$1.cm);
  10029. });
  10030. }
  10031. };
  10032. ContentEditableInput.prototype.setUneditable = function(node) {
  10033. node.contentEditable = "false";
  10034. };
  10035. ContentEditableInput.prototype.onKeyPress = function(e) {
  10036. if (e.charCode == 0 || this.composing) {
  10037. return;
  10038. }
  10039. e.preventDefault();
  10040. if (!this.cm.isReadOnly()) {
  10041. operation(this.cm, applyTextInput)(this.cm, String.fromCharCode(e.charCode == null ? e.keyCode : e.charCode), 0);
  10042. }
  10043. };
  10044. ContentEditableInput.prototype.readOnlyChanged = function(val) {
  10045. this.div.contentEditable = String(val != "nocursor");
  10046. };
  10047. ContentEditableInput.prototype.onContextMenu = function() {
  10048. };
  10049. ContentEditableInput.prototype.resetPosition = function() {
  10050. };
  10051. ContentEditableInput.prototype.needsContentAttribute = true;
  10052. function posToDOM(cm, pos) {
  10053. var view = findViewForLine(cm, pos.line);
  10054. if (!view || view.hidden) {
  10055. return null;
  10056. }
  10057. var line = getLine(cm.doc, pos.line);
  10058. var info = mapFromLineView(view, line, pos.line);
  10059. var order = getOrder(line, cm.doc.direction), side = "left";
  10060. if (order) {
  10061. var partPos = getBidiPartAt(order, pos.ch);
  10062. side = partPos % 2 ? "right" : "left";
  10063. }
  10064. var result = nodeAndOffsetInLineMap(info.map, pos.ch, side);
  10065. result.offset = result.collapse == "right" ? result.end : result.start;
  10066. return result;
  10067. }
  10068. function isInGutter(node) {
  10069. for (var scan = node; scan; scan = scan.parentNode) {
  10070. if (/CodeMirror-gutter-wrapper/.test(scan.className)) {
  10071. return true;
  10072. }
  10073. }
  10074. return false;
  10075. }
  10076. function badPos(pos, bad) {
  10077. if (bad) {
  10078. pos.bad = true;
  10079. }
  10080. return pos;
  10081. }
  10082. function domTextBetween(cm, from, to, fromLine, toLine) {
  10083. var text = "", closing = false, lineSep = cm.doc.lineSeparator(), extraLinebreak = false;
  10084. function recognizeMarker(id) {
  10085. return function(marker) {
  10086. return marker.id == id;
  10087. };
  10088. }
  10089. function close() {
  10090. if (closing) {
  10091. text += lineSep;
  10092. if (extraLinebreak) {
  10093. text += lineSep;
  10094. }
  10095. closing = extraLinebreak = false;
  10096. }
  10097. }
  10098. function addText(str) {
  10099. if (str) {
  10100. close();
  10101. text += str;
  10102. }
  10103. }
  10104. function walk(node) {
  10105. if (node.nodeType == 1) {
  10106. var cmText = node.getAttribute("cm-text");
  10107. if (cmText) {
  10108. addText(cmText);
  10109. return;
  10110. }
  10111. var markerID = node.getAttribute("cm-marker"), range2;
  10112. if (markerID) {
  10113. var found = cm.findMarks(Pos(fromLine, 0), Pos(toLine + 1, 0), recognizeMarker(+markerID));
  10114. if (found.length && (range2 = found[0].find(0))) {
  10115. addText(getBetween(cm.doc, range2.from, range2.to).join(lineSep));
  10116. }
  10117. return;
  10118. }
  10119. if (node.getAttribute("contenteditable") == "false") {
  10120. return;
  10121. }
  10122. var isBlock = /^(pre|div|p|li|table|br)$/i.test(node.nodeName);
  10123. if (!/^br$/i.test(node.nodeName) && node.textContent.length == 0) {
  10124. return;
  10125. }
  10126. if (isBlock) {
  10127. close();
  10128. }
  10129. for (var i2 = 0; i2 < node.childNodes.length; i2++) {
  10130. walk(node.childNodes[i2]);
  10131. }
  10132. if (/^(pre|p)$/i.test(node.nodeName)) {
  10133. extraLinebreak = true;
  10134. }
  10135. if (isBlock) {
  10136. closing = true;
  10137. }
  10138. } else if (node.nodeType == 3) {
  10139. addText(node.nodeValue.replace(/\u200b/g, "").replace(/\u00a0/g, " "));
  10140. }
  10141. }
  10142. for (; ; ) {
  10143. walk(from);
  10144. if (from == to) {
  10145. break;
  10146. }
  10147. from = from.nextSibling;
  10148. extraLinebreak = false;
  10149. }
  10150. return text;
  10151. }
  10152. function domToPos(cm, node, offset) {
  10153. var lineNode;
  10154. if (node == cm.display.lineDiv) {
  10155. lineNode = cm.display.lineDiv.childNodes[offset];
  10156. if (!lineNode) {
  10157. return badPos(cm.clipPos(Pos(cm.display.viewTo - 1)), true);
  10158. }
  10159. node = null;
  10160. offset = 0;
  10161. } else {
  10162. for (lineNode = node; ; lineNode = lineNode.parentNode) {
  10163. if (!lineNode || lineNode == cm.display.lineDiv) {
  10164. return null;
  10165. }
  10166. if (lineNode.parentNode && lineNode.parentNode == cm.display.lineDiv) {
  10167. break;
  10168. }
  10169. }
  10170. }
  10171. for (var i2 = 0; i2 < cm.display.view.length; i2++) {
  10172. var lineView = cm.display.view[i2];
  10173. if (lineView.node == lineNode) {
  10174. return locateNodeInLineView(lineView, node, offset);
  10175. }
  10176. }
  10177. }
  10178. function locateNodeInLineView(lineView, node, offset) {
  10179. var wrapper = lineView.text.firstChild, bad = false;
  10180. if (!node || !contains(wrapper, node)) {
  10181. return badPos(Pos(lineNo(lineView.line), 0), true);
  10182. }
  10183. if (node == wrapper) {
  10184. bad = true;
  10185. node = wrapper.childNodes[offset];
  10186. offset = 0;
  10187. if (!node) {
  10188. var line = lineView.rest ? lst(lineView.rest) : lineView.line;
  10189. return badPos(Pos(lineNo(line), line.text.length), bad);
  10190. }
  10191. }
  10192. var textNode = node.nodeType == 3 ? node : null, topNode = node;
  10193. if (!textNode && node.childNodes.length == 1 && node.firstChild.nodeType == 3) {
  10194. textNode = node.firstChild;
  10195. if (offset) {
  10196. offset = textNode.nodeValue.length;
  10197. }
  10198. }
  10199. while (topNode.parentNode != wrapper) {
  10200. topNode = topNode.parentNode;
  10201. }
  10202. var measure = lineView.measure, maps = measure.maps;
  10203. function find(textNode2, topNode2, offset2) {
  10204. for (var i2 = -1; i2 < (maps ? maps.length : 0); i2++) {
  10205. var map2 = i2 < 0 ? measure.map : maps[i2];
  10206. for (var j = 0; j < map2.length; j += 3) {
  10207. var curNode = map2[j + 2];
  10208. if (curNode == textNode2 || curNode == topNode2) {
  10209. var line2 = lineNo(i2 < 0 ? lineView.line : lineView.rest[i2]);
  10210. var ch = map2[j] + offset2;
  10211. if (offset2 < 0 || curNode != textNode2) {
  10212. ch = map2[j + (offset2 ? 1 : 0)];
  10213. }
  10214. return Pos(line2, ch);
  10215. }
  10216. }
  10217. }
  10218. }
  10219. var found = find(textNode, topNode, offset);
  10220. if (found) {
  10221. return badPos(found, bad);
  10222. }
  10223. for (var after = topNode.nextSibling, dist = textNode ? textNode.nodeValue.length - offset : 0; after; after = after.nextSibling) {
  10224. found = find(after, after.firstChild, 0);
  10225. if (found) {
  10226. return badPos(Pos(found.line, found.ch - dist), bad);
  10227. } else {
  10228. dist += after.textContent.length;
  10229. }
  10230. }
  10231. for (var before = topNode.previousSibling, dist$1 = offset; before; before = before.previousSibling) {
  10232. found = find(before, before.firstChild, -1);
  10233. if (found) {
  10234. return badPos(Pos(found.line, found.ch + dist$1), bad);
  10235. } else {
  10236. dist$1 += before.textContent.length;
  10237. }
  10238. }
  10239. }
  10240. var TextareaInput = function(cm) {
  10241. this.cm = cm;
  10242. this.prevInput = "";
  10243. this.pollingFast = false;
  10244. this.polling = new Delayed();
  10245. this.hasSelection = false;
  10246. this.composing = null;
  10247. this.resetting = false;
  10248. };
  10249. TextareaInput.prototype.init = function(display) {
  10250. var this$1 = this;
  10251. var input = this, cm = this.cm;
  10252. this.createField(display);
  10253. var te = this.textarea;
  10254. display.wrapper.insertBefore(this.wrapper, display.wrapper.firstChild);
  10255. if (ios) {
  10256. te.style.width = "0px";
  10257. }
  10258. on(te, "input", function() {
  10259. if (ie && ie_version >= 9 && this$1.hasSelection) {
  10260. this$1.hasSelection = null;
  10261. }
  10262. input.poll();
  10263. });
  10264. on(te, "paste", function(e) {
  10265. if (signalDOMEvent(cm, e) || handlePaste(e, cm)) {
  10266. return;
  10267. }
  10268. cm.state.pasteIncoming = +/* @__PURE__ */ new Date();
  10269. input.fastPoll();
  10270. });
  10271. function prepareCopyCut(e) {
  10272. if (signalDOMEvent(cm, e)) {
  10273. return;
  10274. }
  10275. if (cm.somethingSelected()) {
  10276. setLastCopied({ lineWise: false, text: cm.getSelections() });
  10277. } else if (!cm.options.lineWiseCopyCut) {
  10278. return;
  10279. } else {
  10280. var ranges = copyableRanges(cm);
  10281. setLastCopied({ lineWise: true, text: ranges.text });
  10282. if (e.type == "cut") {
  10283. cm.setSelections(ranges.ranges, null, sel_dontScroll);
  10284. } else {
  10285. input.prevInput = "";
  10286. te.value = ranges.text.join("\n");
  10287. selectInput(te);
  10288. }
  10289. }
  10290. if (e.type == "cut") {
  10291. cm.state.cutIncoming = +/* @__PURE__ */ new Date();
  10292. }
  10293. }
  10294. on(te, "cut", prepareCopyCut);
  10295. on(te, "copy", prepareCopyCut);
  10296. on(display.scroller, "paste", function(e) {
  10297. if (eventInWidget(display, e) || signalDOMEvent(cm, e)) {
  10298. return;
  10299. }
  10300. if (!te.dispatchEvent) {
  10301. cm.state.pasteIncoming = +/* @__PURE__ */ new Date();
  10302. input.focus();
  10303. return;
  10304. }
  10305. var event = new Event("paste");
  10306. event.clipboardData = e.clipboardData;
  10307. te.dispatchEvent(event);
  10308. });
  10309. on(display.lineSpace, "selectstart", function(e) {
  10310. if (!eventInWidget(display, e)) {
  10311. e_preventDefault(e);
  10312. }
  10313. });
  10314. on(te, "compositionstart", function() {
  10315. var start = cm.getCursor("from");
  10316. if (input.composing) {
  10317. input.composing.range.clear();
  10318. }
  10319. input.composing = {
  10320. start,
  10321. range: cm.markText(start, cm.getCursor("to"), { className: "CodeMirror-composing" })
  10322. };
  10323. });
  10324. on(te, "compositionend", function() {
  10325. if (input.composing) {
  10326. input.poll();
  10327. input.composing.range.clear();
  10328. input.composing = null;
  10329. }
  10330. });
  10331. };
  10332. TextareaInput.prototype.createField = function(_display) {
  10333. this.wrapper = hiddenTextarea();
  10334. this.textarea = this.wrapper.firstChild;
  10335. var opts = this.cm.options;
  10336. disableBrowserMagic(this.textarea, opts.spellcheck, opts.autocorrect, opts.autocapitalize);
  10337. };
  10338. TextareaInput.prototype.screenReaderLabelChanged = function(label) {
  10339. if (label) {
  10340. this.textarea.setAttribute("aria-label", label);
  10341. } else {
  10342. this.textarea.removeAttribute("aria-label");
  10343. }
  10344. };
  10345. TextareaInput.prototype.prepareSelection = function() {
  10346. var cm = this.cm, display = cm.display, doc2 = cm.doc;
  10347. var result = prepareSelection(cm);
  10348. if (cm.options.moveInputWithCursor) {
  10349. var headPos = cursorCoords(cm, doc2.sel.primary().head, "div");
  10350. var wrapOff = display.wrapper.getBoundingClientRect(), lineOff = display.lineDiv.getBoundingClientRect();
  10351. result.teTop = Math.max(0, Math.min(
  10352. display.wrapper.clientHeight - 10,
  10353. headPos.top + lineOff.top - wrapOff.top
  10354. ));
  10355. result.teLeft = Math.max(0, Math.min(
  10356. display.wrapper.clientWidth - 10,
  10357. headPos.left + lineOff.left - wrapOff.left
  10358. ));
  10359. }
  10360. return result;
  10361. };
  10362. TextareaInput.prototype.showSelection = function(drawn) {
  10363. var cm = this.cm, display = cm.display;
  10364. removeChildrenAndAdd(display.cursorDiv, drawn.cursors);
  10365. removeChildrenAndAdd(display.selectionDiv, drawn.selection);
  10366. if (drawn.teTop != null) {
  10367. this.wrapper.style.top = drawn.teTop + "px";
  10368. this.wrapper.style.left = drawn.teLeft + "px";
  10369. }
  10370. };
  10371. TextareaInput.prototype.reset = function(typing) {
  10372. if (this.contextMenuPending || this.composing && typing) {
  10373. return;
  10374. }
  10375. var cm = this.cm;
  10376. this.resetting = true;
  10377. if (cm.somethingSelected()) {
  10378. this.prevInput = "";
  10379. var content = cm.getSelection();
  10380. this.textarea.value = content;
  10381. if (cm.state.focused) {
  10382. selectInput(this.textarea);
  10383. }
  10384. if (ie && ie_version >= 9) {
  10385. this.hasSelection = content;
  10386. }
  10387. } else if (!typing) {
  10388. this.prevInput = this.textarea.value = "";
  10389. if (ie && ie_version >= 9) {
  10390. this.hasSelection = null;
  10391. }
  10392. }
  10393. this.resetting = false;
  10394. };
  10395. TextareaInput.prototype.getField = function() {
  10396. return this.textarea;
  10397. };
  10398. TextareaInput.prototype.supportsTouch = function() {
  10399. return false;
  10400. };
  10401. TextareaInput.prototype.focus = function() {
  10402. if (this.cm.options.readOnly != "nocursor" && (!mobile || activeElt(this.textarea.ownerDocument) != this.textarea)) {
  10403. try {
  10404. this.textarea.focus();
  10405. } catch (e) {
  10406. }
  10407. }
  10408. };
  10409. TextareaInput.prototype.blur = function() {
  10410. this.textarea.blur();
  10411. };
  10412. TextareaInput.prototype.resetPosition = function() {
  10413. this.wrapper.style.top = this.wrapper.style.left = 0;
  10414. };
  10415. TextareaInput.prototype.receivedFocus = function() {
  10416. this.slowPoll();
  10417. };
  10418. TextareaInput.prototype.slowPoll = function() {
  10419. var this$1 = this;
  10420. if (this.pollingFast) {
  10421. return;
  10422. }
  10423. this.polling.set(this.cm.options.pollInterval, function() {
  10424. this$1.poll();
  10425. if (this$1.cm.state.focused) {
  10426. this$1.slowPoll();
  10427. }
  10428. });
  10429. };
  10430. TextareaInput.prototype.fastPoll = function() {
  10431. var missed = false, input = this;
  10432. input.pollingFast = true;
  10433. function p() {
  10434. var changed = input.poll();
  10435. if (!changed && !missed) {
  10436. missed = true;
  10437. input.polling.set(60, p);
  10438. } else {
  10439. input.pollingFast = false;
  10440. input.slowPoll();
  10441. }
  10442. }
  10443. input.polling.set(20, p);
  10444. };
  10445. TextareaInput.prototype.poll = function() {
  10446. var this$1 = this;
  10447. var cm = this.cm, input = this.textarea, prevInput = this.prevInput;
  10448. if (this.contextMenuPending || this.resetting || !cm.state.focused || hasSelection(input) && !prevInput && !this.composing || cm.isReadOnly() || cm.options.disableInput || cm.state.keySeq) {
  10449. return false;
  10450. }
  10451. var text = input.value;
  10452. if (text == prevInput && !cm.somethingSelected()) {
  10453. return false;
  10454. }
  10455. if (ie && ie_version >= 9 && this.hasSelection === text || mac && /[\uf700-\uf7ff]/.test(text)) {
  10456. cm.display.input.reset();
  10457. return false;
  10458. }
  10459. if (cm.doc.sel == cm.display.selForContextMenu) {
  10460. var first = text.charCodeAt(0);
  10461. if (first == 8203 && !prevInput) {
  10462. prevInput = "​";
  10463. }
  10464. if (first == 8666) {
  10465. this.reset();
  10466. return this.cm.execCommand("undo");
  10467. }
  10468. }
  10469. var same = 0, l = Math.min(prevInput.length, text.length);
  10470. while (same < l && prevInput.charCodeAt(same) == text.charCodeAt(same)) {
  10471. ++same;
  10472. }
  10473. runInOp(cm, function() {
  10474. applyTextInput(
  10475. cm,
  10476. text.slice(same),
  10477. prevInput.length - same,
  10478. null,
  10479. this$1.composing ? "*compose" : null
  10480. );
  10481. if (text.length > 1e3 || text.indexOf("\n") > -1) {
  10482. input.value = this$1.prevInput = "";
  10483. } else {
  10484. this$1.prevInput = text;
  10485. }
  10486. if (this$1.composing) {
  10487. this$1.composing.range.clear();
  10488. this$1.composing.range = cm.markText(
  10489. this$1.composing.start,
  10490. cm.getCursor("to"),
  10491. { className: "CodeMirror-composing" }
  10492. );
  10493. }
  10494. });
  10495. return true;
  10496. };
  10497. TextareaInput.prototype.ensurePolled = function() {
  10498. if (this.pollingFast && this.poll()) {
  10499. this.pollingFast = false;
  10500. }
  10501. };
  10502. TextareaInput.prototype.onKeyPress = function() {
  10503. if (ie && ie_version >= 9) {
  10504. this.hasSelection = null;
  10505. }
  10506. this.fastPoll();
  10507. };
  10508. TextareaInput.prototype.onContextMenu = function(e) {
  10509. var input = this, cm = input.cm, display = cm.display, te = input.textarea;
  10510. if (input.contextMenuPending) {
  10511. input.contextMenuPending();
  10512. }
  10513. var pos = posFromMouse(cm, e), scrollPos = display.scroller.scrollTop;
  10514. if (!pos || presto) {
  10515. return;
  10516. }
  10517. var reset = cm.options.resetSelectionOnContextMenu;
  10518. if (reset && cm.doc.sel.contains(pos) == -1) {
  10519. operation(cm, setSelection)(cm.doc, simpleSelection(pos), sel_dontScroll);
  10520. }
  10521. var oldCSS = te.style.cssText, oldWrapperCSS = input.wrapper.style.cssText;
  10522. var wrapperBox = input.wrapper.offsetParent.getBoundingClientRect();
  10523. input.wrapper.style.cssText = "position: static";
  10524. te.style.cssText = "position: absolute; width: 30px; height: 30px;\n top: " + (e.clientY - wrapperBox.top - 5) + "px; left: " + (e.clientX - wrapperBox.left - 5) + "px;\n z-index: 1000; background: " + (ie ? "rgba(255, 255, 255, .05)" : "transparent") + ";\n outline: none; border-width: 0; outline: none; overflow: hidden; opacity: .05; filter: alpha(opacity=5);";
  10525. var oldScrollY;
  10526. if (webkit) {
  10527. oldScrollY = te.ownerDocument.defaultView.scrollY;
  10528. }
  10529. display.input.focus();
  10530. if (webkit) {
  10531. te.ownerDocument.defaultView.scrollTo(null, oldScrollY);
  10532. }
  10533. display.input.reset();
  10534. if (!cm.somethingSelected()) {
  10535. te.value = input.prevInput = " ";
  10536. }
  10537. input.contextMenuPending = rehide;
  10538. display.selForContextMenu = cm.doc.sel;
  10539. clearTimeout(display.detectingSelectAll);
  10540. function prepareSelectAllHack() {
  10541. if (te.selectionStart != null) {
  10542. var selected = cm.somethingSelected();
  10543. var extval = "​" + (selected ? te.value : "");
  10544. te.value = "⇚";
  10545. te.value = extval;
  10546. input.prevInput = selected ? "" : "​";
  10547. te.selectionStart = 1;
  10548. te.selectionEnd = extval.length;
  10549. display.selForContextMenu = cm.doc.sel;
  10550. }
  10551. }
  10552. function rehide() {
  10553. if (input.contextMenuPending != rehide) {
  10554. return;
  10555. }
  10556. input.contextMenuPending = false;
  10557. input.wrapper.style.cssText = oldWrapperCSS;
  10558. te.style.cssText = oldCSS;
  10559. if (ie && ie_version < 9) {
  10560. display.scrollbars.setScrollTop(display.scroller.scrollTop = scrollPos);
  10561. }
  10562. if (te.selectionStart != null) {
  10563. if (!ie || ie && ie_version < 9) {
  10564. prepareSelectAllHack();
  10565. }
  10566. var i2 = 0, poll = function() {
  10567. if (display.selForContextMenu == cm.doc.sel && te.selectionStart == 0 && te.selectionEnd > 0 && input.prevInput == "​") {
  10568. operation(cm, selectAll)(cm);
  10569. } else if (i2++ < 10) {
  10570. display.detectingSelectAll = setTimeout(poll, 500);
  10571. } else {
  10572. display.selForContextMenu = null;
  10573. display.input.reset();
  10574. }
  10575. };
  10576. display.detectingSelectAll = setTimeout(poll, 200);
  10577. }
  10578. }
  10579. if (ie && ie_version >= 9) {
  10580. prepareSelectAllHack();
  10581. }
  10582. if (captureRightClick) {
  10583. e_stop(e);
  10584. var mouseup = function() {
  10585. off(window, "mouseup", mouseup);
  10586. setTimeout(rehide, 20);
  10587. };
  10588. on(window, "mouseup", mouseup);
  10589. } else {
  10590. setTimeout(rehide, 50);
  10591. }
  10592. };
  10593. TextareaInput.prototype.readOnlyChanged = function(val) {
  10594. if (!val) {
  10595. this.reset();
  10596. }
  10597. this.textarea.disabled = val == "nocursor";
  10598. this.textarea.readOnly = !!val;
  10599. };
  10600. TextareaInput.prototype.setUneditable = function() {
  10601. };
  10602. TextareaInput.prototype.needsContentAttribute = false;
  10603. function fromTextArea(textarea, options) {
  10604. options = options ? copyObj(options) : {};
  10605. options.value = textarea.value;
  10606. if (!options.tabindex && textarea.tabIndex) {
  10607. options.tabindex = textarea.tabIndex;
  10608. }
  10609. if (!options.placeholder && textarea.placeholder) {
  10610. options.placeholder = textarea.placeholder;
  10611. }
  10612. if (options.autofocus == null) {
  10613. var hasFocus = activeElt(textarea.ownerDocument);
  10614. options.autofocus = hasFocus == textarea || textarea.getAttribute("autofocus") != null && hasFocus == document.body;
  10615. }
  10616. function save() {
  10617. textarea.value = cm.getValue();
  10618. }
  10619. var realSubmit;
  10620. if (textarea.form) {
  10621. on(textarea.form, "submit", save);
  10622. if (!options.leaveSubmitMethodAlone) {
  10623. var form = textarea.form;
  10624. realSubmit = form.submit;
  10625. try {
  10626. var wrappedSubmit = form.submit = function() {
  10627. save();
  10628. form.submit = realSubmit;
  10629. form.submit();
  10630. form.submit = wrappedSubmit;
  10631. };
  10632. } catch (e) {
  10633. }
  10634. }
  10635. }
  10636. options.finishInit = function(cm2) {
  10637. cm2.save = save;
  10638. cm2.getTextArea = function() {
  10639. return textarea;
  10640. };
  10641. cm2.toTextArea = function() {
  10642. cm2.toTextArea = isNaN;
  10643. save();
  10644. textarea.parentNode.removeChild(cm2.getWrapperElement());
  10645. textarea.style.display = "";
  10646. if (textarea.form) {
  10647. off(textarea.form, "submit", save);
  10648. if (!options.leaveSubmitMethodAlone && typeof textarea.form.submit == "function") {
  10649. textarea.form.submit = realSubmit;
  10650. }
  10651. }
  10652. };
  10653. };
  10654. textarea.style.display = "none";
  10655. var cm = CodeMirror(
  10656. function(node) {
  10657. return textarea.parentNode.insertBefore(node, textarea.nextSibling);
  10658. },
  10659. options
  10660. );
  10661. return cm;
  10662. }
  10663. function addLegacyProps(CodeMirror2) {
  10664. CodeMirror2.off = off;
  10665. CodeMirror2.on = on;
  10666. CodeMirror2.wheelEventPixels = wheelEventPixels;
  10667. CodeMirror2.Doc = Doc;
  10668. CodeMirror2.splitLines = splitLinesAuto;
  10669. CodeMirror2.countColumn = countColumn;
  10670. CodeMirror2.findColumn = findColumn;
  10671. CodeMirror2.isWordChar = isWordCharBasic;
  10672. CodeMirror2.Pass = Pass;
  10673. CodeMirror2.signal = signal;
  10674. CodeMirror2.Line = Line;
  10675. CodeMirror2.changeEnd = changeEnd;
  10676. CodeMirror2.scrollbarModel = scrollbarModel;
  10677. CodeMirror2.Pos = Pos;
  10678. CodeMirror2.cmpPos = cmp;
  10679. CodeMirror2.modes = modes;
  10680. CodeMirror2.mimeModes = mimeModes;
  10681. CodeMirror2.resolveMode = resolveMode;
  10682. CodeMirror2.getMode = getMode;
  10683. CodeMirror2.modeExtensions = modeExtensions;
  10684. CodeMirror2.extendMode = extendMode;
  10685. CodeMirror2.copyState = copyState;
  10686. CodeMirror2.startState = startState;
  10687. CodeMirror2.innerMode = innerMode;
  10688. CodeMirror2.commands = commands;
  10689. CodeMirror2.keyMap = keyMap;
  10690. CodeMirror2.keyName = keyName;
  10691. CodeMirror2.isModifierKey = isModifierKey;
  10692. CodeMirror2.lookupKey = lookupKey;
  10693. CodeMirror2.normalizeKeyMap = normalizeKeyMap;
  10694. CodeMirror2.StringStream = StringStream;
  10695. CodeMirror2.SharedTextMarker = SharedTextMarker;
  10696. CodeMirror2.TextMarker = TextMarker;
  10697. CodeMirror2.LineWidget = LineWidget;
  10698. CodeMirror2.e_preventDefault = e_preventDefault;
  10699. CodeMirror2.e_stopPropagation = e_stopPropagation;
  10700. CodeMirror2.e_stop = e_stop;
  10701. CodeMirror2.addClass = addClass;
  10702. CodeMirror2.contains = contains;
  10703. CodeMirror2.rmClass = rmClass;
  10704. CodeMirror2.keyNames = keyNames;
  10705. }
  10706. defineOptions(CodeMirror);
  10707. addEditorMethods(CodeMirror);
  10708. var dontDelegate = "iter insert remove copy getEditor constructor".split(" ");
  10709. for (var prop in Doc.prototype) {
  10710. if (Doc.prototype.hasOwnProperty(prop) && indexOf(dontDelegate, prop) < 0) {
  10711. CodeMirror.prototype[prop] = function(method) {
  10712. return function() {
  10713. return method.apply(this.doc, arguments);
  10714. };
  10715. }(Doc.prototype[prop]);
  10716. }
  10717. }
  10718. eventMixin(Doc);
  10719. CodeMirror.inputStyles = { "textarea": TextareaInput, "contenteditable": ContentEditableInput };
  10720. CodeMirror.defineMode = function(name) {
  10721. if (!CodeMirror.defaults.mode && name != "null") {
  10722. CodeMirror.defaults.mode = name;
  10723. }
  10724. defineMode.apply(this, arguments);
  10725. };
  10726. CodeMirror.defineMIME = defineMIME;
  10727. CodeMirror.defineMode("null", function() {
  10728. return { token: function(stream) {
  10729. return stream.skipToEnd();
  10730. } };
  10731. });
  10732. CodeMirror.defineMIME("text/plain", "null");
  10733. CodeMirror.defineExtension = function(name, func) {
  10734. CodeMirror.prototype[name] = func;
  10735. };
  10736. CodeMirror.defineDocExtension = function(name, func) {
  10737. Doc.prototype[name] = func;
  10738. };
  10739. CodeMirror.fromTextArea = fromTextArea;
  10740. addLegacyProps(CodeMirror);
  10741. CodeMirror.version = "5.65.12";
  10742. return CodeMirror;
  10743. });
  10744. }
  10745. });
  10746. export {
  10747. require_codemirror
  10748. };
  10749. //# sourceMappingURL=chunk-SPLH5WDX.js.map