ace.js 662 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737137381373913740137411374213743137441374513746137471374813749137501375113752137531375413755137561375713758137591376013761137621376313764137651376613767137681376913770137711377213773137741377513776137771377813779137801378113782137831378413785137861378713788137891379013791137921379313794137951379613797137981379913800138011380213803138041380513806138071380813809138101381113812138131381413815138161381713818138191382013821138221382313824138251382613827138281382913830138311383213833138341383513836138371383813839138401384113842138431384413845138461384713848138491385013851138521385313854138551385613857138581385913860138611386213863138641386513866138671386813869138701387113872138731387413875138761387713878138791388013881138821388313884138851388613887138881388913890138911389213893138941389513896138971389813899139001390113902139031390413905139061390713908139091391013911139121391313914139151391613917139181391913920139211392213923139241392513926139271392813929139301393113932139331393413935139361393713938139391394013941139421394313944139451394613947139481394913950139511395213953139541395513956139571395813959139601396113962139631396413965139661396713968139691397013971139721397313974139751397613977139781397913980139811398213983139841398513986139871398813989139901399113992139931399413995139961399713998139991400014001140021400314004140051400614007140081400914010140111401214013140141401514016140171401814019140201402114022140231402414025140261402714028140291403014031140321403314034140351403614037140381403914040140411404214043140441404514046140471404814049140501405114052140531405414055140561405714058140591406014061140621406314064140651406614067140681406914070140711407214073140741407514076140771407814079140801408114082140831408414085140861408714088140891409014091140921409314094140951409614097140981409914100141011410214103141041410514106141071410814109141101411114112141131411414115141161411714118141191412014121141221412314124141251412614127141281412914130141311413214133141341413514136141371413814139141401414114142141431414414145141461414714148141491415014151141521415314154141551415614157141581415914160141611416214163141641416514166141671416814169141701417114172141731417414175141761417714178141791418014181141821418314184141851418614187141881418914190141911419214193141941419514196141971419814199142001420114202142031420414205142061420714208142091421014211142121421314214142151421614217142181421914220142211422214223142241422514226142271422814229142301423114232142331423414235142361423714238142391424014241142421424314244142451424614247142481424914250142511425214253142541425514256142571425814259142601426114262142631426414265142661426714268142691427014271142721427314274142751427614277142781427914280142811428214283142841428514286142871428814289142901429114292142931429414295142961429714298142991430014301143021430314304143051430614307143081430914310143111431214313143141431514316143171431814319143201432114322143231432414325143261432714328143291433014331143321433314334143351433614337143381433914340143411434214343143441434514346143471434814349143501435114352143531435414355143561435714358143591436014361143621436314364143651436614367143681436914370143711437214373143741437514376143771437814379143801438114382143831438414385143861438714388143891439014391143921439314394143951439614397143981439914400144011440214403144041440514406144071440814409144101441114412144131441414415144161441714418144191442014421144221442314424144251442614427144281442914430144311443214433144341443514436144371443814439144401444114442144431444414445144461444714448144491445014451144521445314454144551445614457144581445914460144611446214463144641446514466144671446814469144701447114472144731447414475144761447714478144791448014481144821448314484144851448614487144881448914490144911449214493144941449514496144971449814499145001450114502145031450414505145061450714508145091451014511145121451314514145151451614517145181451914520145211452214523145241452514526145271452814529145301453114532145331453414535145361453714538145391454014541145421454314544145451454614547145481454914550145511455214553145541455514556145571455814559145601456114562145631456414565145661456714568145691457014571145721457314574145751457614577145781457914580145811458214583145841458514586145871458814589145901459114592145931459414595145961459714598145991460014601146021460314604146051460614607146081460914610146111461214613146141461514616146171461814619146201462114622146231462414625146261462714628146291463014631146321463314634146351463614637146381463914640146411464214643146441464514646146471464814649146501465114652146531465414655146561465714658146591466014661146621466314664146651466614667146681466914670146711467214673146741467514676146771467814679146801468114682146831468414685146861468714688146891469014691146921469314694146951469614697146981469914700147011470214703147041470514706147071470814709147101471114712147131471414715147161471714718147191472014721147221472314724147251472614727147281472914730147311473214733147341473514736147371473814739147401474114742147431474414745147461474714748147491475014751147521475314754147551475614757147581475914760147611476214763147641476514766147671476814769147701477114772147731477414775147761477714778147791478014781147821478314784147851478614787147881478914790147911479214793147941479514796147971479814799148001480114802148031480414805148061480714808148091481014811148121481314814148151481614817148181481914820148211482214823148241482514826148271482814829148301483114832148331483414835148361483714838148391484014841148421484314844148451484614847148481484914850148511485214853148541485514856148571485814859148601486114862148631486414865148661486714868148691487014871148721487314874148751487614877148781487914880148811488214883148841488514886148871488814889148901489114892148931489414895148961489714898148991490014901149021490314904149051490614907149081490914910149111491214913149141491514916149171491814919149201492114922149231492414925149261492714928149291493014931149321493314934149351493614937149381493914940149411494214943149441494514946149471494814949149501495114952149531495414955149561495714958149591496014961149621496314964149651496614967149681496914970149711497214973149741497514976149771497814979149801498114982149831498414985149861498714988149891499014991149921499314994149951499614997149981499915000150011500215003150041500515006150071500815009150101501115012150131501415015150161501715018150191502015021150221502315024150251502615027150281502915030150311503215033150341503515036150371503815039150401504115042150431504415045150461504715048150491505015051150521505315054150551505615057150581505915060150611506215063150641506515066150671506815069150701507115072150731507415075150761507715078150791508015081150821508315084150851508615087150881508915090150911509215093150941509515096150971509815099151001510115102151031510415105151061510715108151091511015111151121511315114151151511615117151181511915120151211512215123151241512515126151271512815129151301513115132151331513415135151361513715138151391514015141151421514315144151451514615147151481514915150151511515215153151541515515156151571515815159151601516115162151631516415165151661516715168151691517015171151721517315174151751517615177151781517915180151811518215183151841518515186151871518815189151901519115192151931519415195151961519715198151991520015201152021520315204152051520615207152081520915210152111521215213152141521515216152171521815219152201522115222152231522415225152261522715228152291523015231152321523315234152351523615237152381523915240152411524215243152441524515246152471524815249152501525115252152531525415255152561525715258152591526015261152621526315264152651526615267152681526915270152711527215273152741527515276152771527815279152801528115282152831528415285152861528715288152891529015291152921529315294152951529615297152981529915300153011530215303153041530515306153071530815309153101531115312153131531415315153161531715318153191532015321153221532315324153251532615327153281532915330153311533215333153341533515336153371533815339153401534115342153431534415345153461534715348153491535015351153521535315354153551535615357153581535915360153611536215363153641536515366153671536815369153701537115372153731537415375153761537715378153791538015381153821538315384153851538615387153881538915390153911539215393153941539515396153971539815399154001540115402154031540415405154061540715408154091541015411154121541315414154151541615417154181541915420154211542215423154241542515426154271542815429154301543115432154331543415435154361543715438154391544015441154421544315444154451544615447154481544915450154511545215453154541545515456154571545815459154601546115462154631546415465154661546715468154691547015471154721547315474154751547615477154781547915480154811548215483154841548515486154871548815489154901549115492154931549415495154961549715498154991550015501155021550315504155051550615507155081550915510155111551215513155141551515516155171551815519155201552115522155231552415525155261552715528155291553015531155321553315534155351553615537155381553915540155411554215543155441554515546155471554815549155501555115552155531555415555155561555715558155591556015561155621556315564155651556615567155681556915570155711557215573155741557515576155771557815579155801558115582155831558415585155861558715588155891559015591155921559315594155951559615597155981559915600156011560215603156041560515606156071560815609156101561115612156131561415615156161561715618156191562015621156221562315624156251562615627156281562915630156311563215633156341563515636156371563815639156401564115642156431564415645156461564715648156491565015651156521565315654156551565615657156581565915660156611566215663156641566515666156671566815669156701567115672156731567415675156761567715678156791568015681156821568315684156851568615687156881568915690156911569215693156941569515696156971569815699157001570115702157031570415705157061570715708157091571015711157121571315714157151571615717157181571915720157211572215723157241572515726157271572815729157301573115732157331573415735157361573715738157391574015741157421574315744157451574615747157481574915750157511575215753157541575515756157571575815759157601576115762157631576415765157661576715768157691577015771157721577315774157751577615777157781577915780157811578215783157841578515786157871578815789157901579115792157931579415795157961579715798157991580015801158021580315804158051580615807158081580915810158111581215813158141581515816158171581815819158201582115822158231582415825158261582715828158291583015831158321583315834158351583615837158381583915840158411584215843158441584515846158471584815849158501585115852158531585415855158561585715858158591586015861158621586315864158651586615867158681586915870158711587215873158741587515876158771587815879158801588115882158831588415885158861588715888158891589015891158921589315894158951589615897158981589915900159011590215903159041590515906159071590815909159101591115912159131591415915159161591715918159191592015921159221592315924159251592615927159281592915930159311593215933159341593515936159371593815939159401594115942159431594415945159461594715948159491595015951159521595315954159551595615957159581595915960159611596215963159641596515966159671596815969159701597115972159731597415975159761597715978159791598015981159821598315984159851598615987159881598915990159911599215993159941599515996159971599815999160001600116002160031600416005160061600716008160091601016011160121601316014160151601616017160181601916020160211602216023160241602516026160271602816029160301603116032160331603416035160361603716038160391604016041160421604316044160451604616047160481604916050160511605216053160541605516056160571605816059160601606116062160631606416065160661606716068160691607016071160721607316074160751607616077160781607916080160811608216083160841608516086160871608816089160901609116092160931609416095160961609716098160991610016101161021610316104161051610616107161081610916110161111611216113161141611516116161171611816119161201612116122161231612416125161261612716128161291613016131161321613316134161351613616137161381613916140161411614216143161441614516146161471614816149161501615116152161531615416155161561615716158161591616016161161621616316164161651616616167161681616916170161711617216173161741617516176161771617816179161801618116182161831618416185161861618716188161891619016191161921619316194161951619616197161981619916200162011620216203162041620516206162071620816209162101621116212162131621416215162161621716218162191622016221162221622316224162251622616227162281622916230162311623216233162341623516236162371623816239162401624116242162431624416245162461624716248162491625016251162521625316254162551625616257162581625916260162611626216263162641626516266162671626816269162701627116272162731627416275162761627716278162791628016281162821628316284162851628616287162881628916290162911629216293162941629516296162971629816299163001630116302163031630416305163061630716308163091631016311163121631316314163151631616317163181631916320163211632216323163241632516326163271632816329163301633116332163331633416335163361633716338163391634016341163421634316344163451634616347163481634916350163511635216353163541635516356163571635816359163601636116362163631636416365163661636716368163691637016371163721637316374163751637616377163781637916380163811638216383163841638516386163871638816389163901639116392163931639416395163961639716398163991640016401164021640316404164051640616407164081640916410164111641216413164141641516416164171641816419164201642116422164231642416425164261642716428164291643016431164321643316434164351643616437164381643916440164411644216443164441644516446164471644816449164501645116452164531645416455164561645716458164591646016461164621646316464164651646616467164681646916470164711647216473164741647516476164771647816479164801648116482164831648416485164861648716488164891649016491164921649316494164951649616497164981649916500165011650216503165041650516506165071650816509165101651116512165131651416515165161651716518165191652016521165221652316524165251652616527165281652916530165311653216533165341653516536165371653816539165401654116542165431654416545165461654716548165491655016551165521655316554165551655616557165581655916560165611656216563165641656516566165671656816569165701657116572165731657416575165761657716578165791658016581165821658316584165851658616587165881658916590165911659216593165941659516596165971659816599166001660116602166031660416605166061660716608166091661016611166121661316614166151661616617166181661916620166211662216623166241662516626166271662816629166301663116632166331663416635166361663716638166391664016641166421664316644166451664616647166481664916650166511665216653166541665516656166571665816659166601666116662166631666416665166661666716668166691667016671166721667316674166751667616677166781667916680166811668216683166841668516686166871668816689166901669116692166931669416695166961669716698166991670016701167021670316704167051670616707167081670916710167111671216713167141671516716167171671816719167201672116722167231672416725167261672716728167291673016731167321673316734167351673616737167381673916740167411674216743167441674516746167471674816749167501675116752167531675416755167561675716758167591676016761167621676316764167651676616767167681676916770167711677216773167741677516776167771677816779167801678116782167831678416785167861678716788167891679016791167921679316794167951679616797167981679916800168011680216803168041680516806168071680816809168101681116812168131681416815168161681716818168191682016821168221682316824168251682616827168281682916830168311683216833168341683516836168371683816839168401684116842168431684416845168461684716848168491685016851168521685316854168551685616857168581685916860168611686216863168641686516866168671686816869168701687116872168731687416875168761687716878168791688016881168821688316884168851688616887168881688916890168911689216893168941689516896168971689816899169001690116902169031690416905169061690716908169091691016911169121691316914169151691616917169181691916920169211692216923169241692516926169271692816929169301693116932169331693416935169361693716938169391694016941169421694316944169451694616947169481694916950169511695216953169541695516956169571695816959169601696116962169631696416965169661696716968169691697016971169721697316974169751697616977169781697916980169811698216983169841698516986169871698816989169901699116992169931699416995169961699716998169991700017001170021700317004170051700617007170081700917010170111701217013170141701517016170171701817019170201702117022170231702417025170261702717028170291703017031170321703317034170351703617037170381703917040170411704217043170441704517046170471704817049170501705117052170531705417055170561705717058170591706017061170621706317064170651706617067170681706917070170711707217073170741707517076170771707817079170801708117082170831708417085170861708717088170891709017091170921709317094170951709617097170981709917100171011710217103171041710517106171071710817109171101711117112171131711417115171161711717118171191712017121171221712317124171251712617127171281712917130171311713217133171341713517136171371713817139171401714117142171431714417145171461714717148171491715017151171521715317154171551715617157171581715917160171611716217163171641716517166171671716817169171701717117172171731717417175171761717717178171791718017181171821718317184171851718617187171881718917190171911719217193171941719517196171971719817199172001720117202172031720417205172061720717208172091721017211172121721317214172151721617217172181721917220172211722217223172241722517226172271722817229172301723117232172331723417235172361723717238172391724017241172421724317244172451724617247172481724917250172511725217253172541725517256172571725817259172601726117262172631726417265172661726717268172691727017271172721727317274172751727617277172781727917280172811728217283172841728517286172871728817289172901729117292172931729417295172961729717298172991730017301173021730317304173051730617307173081730917310173111731217313173141731517316173171731817319173201732117322173231732417325173261732717328173291733017331173321733317334173351733617337173381733917340173411734217343173441734517346173471734817349173501735117352173531735417355173561735717358173591736017361173621736317364173651736617367173681736917370173711737217373173741737517376173771737817379173801738117382173831738417385173861738717388173891739017391173921739317394173951739617397173981739917400174011740217403174041740517406174071740817409174101741117412174131741417415174161741717418174191742017421174221742317424174251742617427174281742917430174311743217433174341743517436174371743817439174401744117442174431744417445174461744717448174491745017451174521745317454174551745617457174581745917460174611746217463174641746517466174671746817469174701747117472174731747417475174761747717478174791748017481174821748317484174851748617487174881748917490174911749217493174941749517496174971749817499175001750117502175031750417505175061750717508175091751017511175121751317514175151751617517175181751917520175211752217523175241752517526175271752817529175301753117532175331753417535175361753717538175391754017541175421754317544175451754617547175481754917550175511755217553175541755517556175571755817559175601756117562175631756417565175661756717568175691757017571175721757317574175751757617577175781757917580175811758217583175841758517586175871758817589175901759117592175931759417595175961759717598175991760017601176021760317604176051760617607176081760917610176111761217613176141761517616176171761817619176201762117622176231762417625176261762717628176291763017631176321763317634176351763617637176381763917640176411764217643176441764517646176471764817649176501765117652176531765417655176561765717658176591766017661176621766317664176651766617667176681766917670176711767217673176741767517676176771767817679176801768117682176831768417685176861768717688176891769017691176921769317694176951769617697176981769917700177011770217703177041770517706177071770817709177101771117712177131771417715177161771717718177191772017721177221772317724177251772617727177281772917730177311773217733177341773517736177371773817739177401774117742177431774417745177461774717748177491775017751177521775317754177551775617757177581775917760177611776217763177641776517766177671776817769177701777117772177731777417775177761777717778177791778017781177821778317784177851778617787177881778917790177911779217793177941779517796177971779817799178001780117802178031780417805178061780717808178091781017811178121781317814178151781617817178181781917820178211782217823178241782517826178271782817829178301783117832178331783417835178361783717838178391784017841178421784317844178451784617847178481784917850178511785217853178541785517856178571785817859178601786117862178631786417865178661786717868178691787017871178721787317874178751787617877178781787917880178811788217883178841788517886178871788817889178901789117892178931789417895178961789717898178991790017901179021790317904179051790617907179081790917910179111791217913179141791517916179171791817919179201792117922179231792417925179261792717928179291793017931179321793317934179351793617937179381793917940179411794217943179441794517946179471794817949179501795117952179531795417955179561795717958179591796017961179621796317964179651796617967179681796917970179711797217973179741797517976179771797817979179801798117982179831798417985179861798717988179891799017991179921799317994179951799617997179981799918000180011800218003180041800518006180071800818009180101801118012180131801418015180161801718018180191802018021180221802318024180251802618027180281802918030180311803218033180341803518036180371803818039180401804118042180431804418045180461804718048180491805018051180521805318054180551805618057180581805918060180611806218063180641806518066180671806818069180701807118072180731807418075180761807718078180791808018081180821808318084180851808618087180881808918090180911809218093180941809518096180971809818099181001810118102181031810418105181061810718108181091811018111181121811318114181151811618117181181811918120181211812218123181241812518126181271812818129181301813118132181331813418135181361813718138181391814018141181421814318144181451814618147181481814918150181511815218153181541815518156181571815818159181601816118162181631816418165181661816718168181691817018171181721817318174181751817618177181781817918180181811818218183181841818518186181871818818189181901819118192181931819418195181961819718198181991820018201182021820318204182051820618207182081820918210182111821218213182141821518216182171821818219182201822118222182231822418225182261822718228182291823018231182321823318234182351823618237182381823918240182411824218243182441824518246182471824818249182501825118252182531825418255182561825718258182591826018261182621826318264182651826618267182681826918270182711827218273182741827518276182771827818279182801828118282182831828418285182861828718288182891829018291182921829318294182951829618297182981829918300183011830218303183041830518306183071830818309183101831118312183131831418315183161831718318183191832018321183221832318324183251832618327183281832918330183311833218333183341833518336183371833818339183401834118342183431834418345183461834718348183491835018351183521835318354183551835618357183581835918360183611836218363183641836518366183671836818369183701837118372183731837418375183761837718378183791838018381183821838318384183851838618387183881838918390183911839218393183941839518396183971839818399184001840118402184031840418405184061840718408184091841018411184121841318414184151841618417184181841918420184211842218423184241842518426184271842818429184301843118432184331843418435184361843718438184391844018441184421844318444184451844618447184481844918450184511845218453184541845518456184571845818459184601846118462184631846418465184661846718468184691847018471184721847318474184751847618477184781847918480184811848218483184841848518486184871848818489184901849118492184931849418495184961849718498184991850018501185021850318504185051850618507185081850918510185111851218513185141851518516185171851818519185201852118522185231852418525185261852718528185291853018531185321853318534185351853618537185381853918540185411854218543185441854518546185471854818549185501855118552185531855418555185561855718558185591856018561185621856318564185651856618567185681856918570185711857218573185741857518576185771857818579185801858118582185831858418585185861858718588185891859018591185921859318594185951859618597185981859918600186011860218603186041860518606186071860818609186101861118612186131861418615186161861718618186191862018621186221862318624186251862618627186281862918630186311863218633186341863518636186371863818639186401864118642186431864418645186461864718648186491865018651186521865318654186551865618657186581865918660186611866218663186641866518666186671866818669186701867118672186731867418675186761867718678186791868018681186821868318684186851868618687186881868918690186911869218693186941869518696186971869818699187001870118702187031870418705187061870718708187091871018711187121871318714187151871618717187181871918720187211872218723187241872518726187271872818729187301873118732187331873418735187361873718738187391874018741187421874318744187451874618747187481874918750187511875218753187541875518756187571875818759187601876118762187631876418765187661876718768187691877018771187721877318774187751877618777187781877918780187811878218783187841878518786187871878818789187901879118792187931879418795187961879718798187991880018801188021880318804188051880618807188081880918810188111881218813188141881518816188171881818819188201882118822188231882418825188261882718828188291883018831188321883318834188351883618837188381883918840188411884218843188441884518846188471884818849188501885118852188531885418855188561885718858188591886018861188621886318864188651886618867188681886918870188711887218873188741887518876188771887818879188801888118882188831888418885188861888718888188891889018891188921889318894188951889618897188981889918900189011890218903189041890518906189071890818909189101891118912189131891418915189161891718918189191892018921189221892318924189251892618927189281892918930189311893218933189341893518936189371893818939189401894118942189431894418945189461894718948189491895018951189521895318954189551895618957189581895918960189611896218963189641896518966189671896818969189701897118972189731897418975189761897718978189791898018981189821898318984189851898618987189881898918990189911899218993189941899518996189971899818999190001900119002190031900419005190061900719008190091901019011190121901319014190151901619017190181901919020190211902219023190241902519026190271902819029190301903119032190331903419035190361903719038190391904019041190421904319044190451904619047190481904919050190511905219053190541905519056190571905819059190601906119062190631906419065190661906719068190691907019071190721907319074190751907619077190781907919080190811908219083190841908519086190871908819089190901909119092190931909419095190961909719098190991910019101191021910319104191051910619107191081910919110191111911219113191141911519116191171911819119191201912119122191231912419125191261912719128191291913019131191321913319134191351913619137191381913919140191411914219143191441914519146191471914819149191501915119152191531915419155191561915719158191591916019161191621916319164191651916619167191681916919170191711917219173191741917519176191771917819179191801918119182191831918419185191861918719188191891919019191191921919319194191951919619197191981919919200192011920219203192041920519206192071920819209192101921119212192131921419215192161921719218192191922019221192221922319224192251922619227192281922919230192311923219233192341923519236192371923819239192401924119242192431924419245192461924719248192491925019251192521925319254192551925619257192581925919260192611926219263192641926519266192671926819269192701927119272192731927419275192761927719278192791928019281192821928319284192851928619287192881928919290192911929219293192941929519296192971929819299193001930119302193031930419305193061930719308193091931019311193121931319314193151931619317193181931919320193211932219323193241932519326193271932819329193301933119332193331933419335193361933719338193391934019341193421934319344193451934619347193481934919350193511935219353193541935519356193571935819359193601936119362193631936419365193661936719368193691937019371193721937319374193751937619377193781937919380193811938219383193841938519386193871938819389193901939119392193931939419395193961939719398193991940019401194021940319404194051940619407194081940919410194111941219413194141941519416194171941819419194201942119422194231942419425194261942719428194291943019431194321943319434194351943619437194381943919440194411944219443194441944519446194471944819449194501945119452194531945419455194561945719458194591946019461194621946319464194651946619467194681946919470194711947219473194741947519476194771947819479194801948119482194831948419485194861948719488194891949019491194921949319494194951949619497194981949919500195011950219503195041950519506195071950819509195101951119512195131951419515195161951719518195191952019521195221952319524195251952619527195281952919530195311953219533195341953519536195371953819539195401954119542195431954419545195461954719548195491955019551195521955319554195551955619557195581955919560
  1. /* ***** BEGIN LICENSE BLOCK *****
  2. * Distributed under the BSD license:
  3. *
  4. * Copyright (c) 2010, Ajax.org B.V.
  5. * All rights reserved.
  6. *
  7. * Redistribution and use in source and binary forms, with or without
  8. * modification, are permitted provided that the following conditions are met:
  9. * * Redistributions of source code must retain the above copyright
  10. * notice, this list of conditions and the following disclaimer.
  11. * * Redistributions in binary form must reproduce the above copyright
  12. * notice, this list of conditions and the following disclaimer in the
  13. * documentation and/or other materials provided with the distribution.
  14. * * Neither the name of Ajax.org B.V. nor the
  15. * names of its contributors may be used to endorse or promote products
  16. * derived from this software without specific prior written permission.
  17. *
  18. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
  19. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  20. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  21. * DISCLAIMED. IN NO EVENT SHALL AJAX.ORG B.V. BE LIABLE FOR ANY
  22. * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  23. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  24. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  25. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  26. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  27. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  28. *
  29. * ***** END LICENSE BLOCK ***** */
  30. /**
  31. * Define a module along with a payload
  32. * @param module a name for the payload
  33. * @param payload a function to call with (require, exports, module) params
  34. */
  35. (function() {
  36. var ACE_NAMESPACE = "";
  37. var global = (function() { return this; })();
  38. if (!global && typeof window != "undefined") global = window; // strict mode
  39. if (!ACE_NAMESPACE && typeof requirejs !== "undefined")
  40. return;
  41. var define = function(module, deps, payload) {
  42. if (typeof module !== "string") {
  43. if (define.original)
  44. define.original.apply(this, arguments);
  45. else {
  46. console.error("dropping module because define wasn\'t a string.");
  47. console.trace();
  48. }
  49. return;
  50. }
  51. if (arguments.length == 2)
  52. payload = deps;
  53. if (!define.modules[module]) {
  54. define.payloads[module] = payload;
  55. define.modules[module] = null;
  56. }
  57. };
  58. define.modules = {};
  59. define.payloads = {};
  60. /**
  61. * Get at functionality define()ed using the function above
  62. */
  63. var _require = function(parentId, module, callback) {
  64. if (typeof module === "string") {
  65. var payload = lookup(parentId, module);
  66. if (payload != undefined) {
  67. callback && callback();
  68. return payload;
  69. }
  70. } else if (Object.prototype.toString.call(module) === "[object Array]") {
  71. var params = [];
  72. for (var i = 0, l = module.length; i < l; ++i) {
  73. var dep = lookup(parentId, module[i]);
  74. if (dep == undefined && require.original)
  75. return;
  76. params.push(dep);
  77. }
  78. return callback && callback.apply(null, params) || true;
  79. }
  80. };
  81. var require = function(module, callback) {
  82. var packagedModule = _require("", module, callback);
  83. if (packagedModule == undefined && require.original)
  84. return require.original.apply(this, arguments);
  85. return packagedModule;
  86. };
  87. var normalizeModule = function(parentId, moduleName) {
  88. // normalize plugin requires
  89. if (moduleName.indexOf("!") !== -1) {
  90. var chunks = moduleName.split("!");
  91. return normalizeModule(parentId, chunks[0]) + "!" + normalizeModule(parentId, chunks[1]);
  92. }
  93. // normalize relative requires
  94. if (moduleName.charAt(0) == ".") {
  95. var base = parentId.split("/").slice(0, -1).join("/");
  96. moduleName = base + "/" + moduleName;
  97. while(moduleName.indexOf(".") !== -1 && previous != moduleName) {
  98. var previous = moduleName;
  99. moduleName = moduleName.replace(/\/\.\//, "/").replace(/[^\/]+\/\.\.\//, "");
  100. }
  101. }
  102. return moduleName;
  103. };
  104. /**
  105. * Internal function to lookup moduleNames and resolve them by calling the
  106. * definition function if needed.
  107. */
  108. var lookup = function(parentId, moduleName) {
  109. moduleName = normalizeModule(parentId, moduleName);
  110. var module = define.modules[moduleName];
  111. if (!module) {
  112. module = define.payloads[moduleName];
  113. if (typeof module === 'function') {
  114. var exports = {};
  115. var mod = {
  116. id: moduleName,
  117. uri: '',
  118. exports: exports,
  119. packaged: true
  120. };
  121. var req = function(module, callback) {
  122. return _require(moduleName, module, callback);
  123. };
  124. var returnValue = module(req, exports, mod);
  125. exports = returnValue || mod.exports;
  126. define.modules[moduleName] = exports;
  127. delete define.payloads[moduleName];
  128. }
  129. module = define.modules[moduleName] = exports || module;
  130. }
  131. return module;
  132. };
  133. function exportAce(ns) {
  134. var root = global;
  135. if (ns) {
  136. if (!global[ns])
  137. global[ns] = {};
  138. root = global[ns];
  139. }
  140. if (!root.define || !root.define.packaged) {
  141. define.original = root.define;
  142. root.define = define;
  143. root.define.packaged = true;
  144. }
  145. if (!root.require || !root.require.packaged) {
  146. require.original = root.require;
  147. root.require = require;
  148. root.require.packaged = true;
  149. }
  150. }
  151. exportAce(ACE_NAMESPACE);
  152. })();
  153. define("ace/lib/regexp",["require","exports","module"], function(require, exports, module) {
  154. "use strict";
  155. var real = {
  156. exec: RegExp.prototype.exec,
  157. test: RegExp.prototype.test,
  158. match: String.prototype.match,
  159. replace: String.prototype.replace,
  160. split: String.prototype.split
  161. },
  162. compliantExecNpcg = real.exec.call(/()??/, "")[1] === undefined, // check `exec` handling of nonparticipating capturing groups
  163. compliantLastIndexIncrement = function () {
  164. var x = /^/g;
  165. real.test.call(x, "");
  166. return !x.lastIndex;
  167. }();
  168. if (compliantLastIndexIncrement && compliantExecNpcg)
  169. return;
  170. RegExp.prototype.exec = function (str) {
  171. var match = real.exec.apply(this, arguments),
  172. name, r2;
  173. if ( typeof(str) == 'string' && match) {
  174. if (!compliantExecNpcg && match.length > 1 && indexOf(match, "") > -1) {
  175. r2 = RegExp(this.source, real.replace.call(getNativeFlags(this), "g", ""));
  176. real.replace.call(str.slice(match.index), r2, function () {
  177. for (var i = 1; i < arguments.length - 2; i++) {
  178. if (arguments[i] === undefined)
  179. match[i] = undefined;
  180. }
  181. });
  182. }
  183. if (this._xregexp && this._xregexp.captureNames) {
  184. for (var i = 1; i < match.length; i++) {
  185. name = this._xregexp.captureNames[i - 1];
  186. if (name)
  187. match[name] = match[i];
  188. }
  189. }
  190. if (!compliantLastIndexIncrement && this.global && !match[0].length && (this.lastIndex > match.index))
  191. this.lastIndex--;
  192. }
  193. return match;
  194. };
  195. if (!compliantLastIndexIncrement) {
  196. RegExp.prototype.test = function (str) {
  197. var match = real.exec.call(this, str);
  198. if (match && this.global && !match[0].length && (this.lastIndex > match.index))
  199. this.lastIndex--;
  200. return !!match;
  201. };
  202. }
  203. function getNativeFlags (regex) {
  204. return (regex.global ? "g" : "") +
  205. (regex.ignoreCase ? "i" : "") +
  206. (regex.multiline ? "m" : "") +
  207. (regex.extended ? "x" : "") + // Proposed for ES4; included in AS3
  208. (regex.sticky ? "y" : "");
  209. }
  210. function indexOf (array, item, from) {
  211. if (Array.prototype.indexOf) // Use the native array method if available
  212. return array.indexOf(item, from);
  213. for (var i = from || 0; i < array.length; i++) {
  214. if (array[i] === item)
  215. return i;
  216. }
  217. return -1;
  218. }
  219. });
  220. define("ace/lib/es5-shim",["require","exports","module"], function(require, exports, module) {
  221. function Empty() {}
  222. if (!Function.prototype.bind) {
  223. Function.prototype.bind = function bind(that) { // .length is 1
  224. var target = this;
  225. if (typeof target != "function") {
  226. throw new TypeError("Function.prototype.bind called on incompatible " + target);
  227. }
  228. var args = slice.call(arguments, 1); // for normal call
  229. var bound = function () {
  230. if (this instanceof bound) {
  231. var result = target.apply(
  232. this,
  233. args.concat(slice.call(arguments))
  234. );
  235. if (Object(result) === result) {
  236. return result;
  237. }
  238. return this;
  239. } else {
  240. return target.apply(
  241. that,
  242. args.concat(slice.call(arguments))
  243. );
  244. }
  245. };
  246. if(target.prototype) {
  247. Empty.prototype = target.prototype;
  248. bound.prototype = new Empty();
  249. Empty.prototype = null;
  250. }
  251. return bound;
  252. };
  253. }
  254. var call = Function.prototype.call;
  255. var prototypeOfArray = Array.prototype;
  256. var prototypeOfObject = Object.prototype;
  257. var slice = prototypeOfArray.slice;
  258. var _toString = call.bind(prototypeOfObject.toString);
  259. var owns = call.bind(prototypeOfObject.hasOwnProperty);
  260. var defineGetter;
  261. var defineSetter;
  262. var lookupGetter;
  263. var lookupSetter;
  264. var supportsAccessors;
  265. if ((supportsAccessors = owns(prototypeOfObject, "__defineGetter__"))) {
  266. defineGetter = call.bind(prototypeOfObject.__defineGetter__);
  267. defineSetter = call.bind(prototypeOfObject.__defineSetter__);
  268. lookupGetter = call.bind(prototypeOfObject.__lookupGetter__);
  269. lookupSetter = call.bind(prototypeOfObject.__lookupSetter__);
  270. }
  271. if ([1,2].splice(0).length != 2) {
  272. if(function() { // test IE < 9 to splice bug - see issue #138
  273. function makeArray(l) {
  274. var a = new Array(l+2);
  275. a[0] = a[1] = 0;
  276. return a;
  277. }
  278. var array = [], lengthBefore;
  279. array.splice.apply(array, makeArray(20));
  280. array.splice.apply(array, makeArray(26));
  281. lengthBefore = array.length; //46
  282. array.splice(5, 0, "XXX"); // add one element
  283. lengthBefore + 1 == array.length
  284. if (lengthBefore + 1 == array.length) {
  285. return true;// has right splice implementation without bugs
  286. }
  287. }()) {//IE 6/7
  288. var array_splice = Array.prototype.splice;
  289. Array.prototype.splice = function(start, deleteCount) {
  290. if (!arguments.length) {
  291. return [];
  292. } else {
  293. return array_splice.apply(this, [
  294. start === void 0 ? 0 : start,
  295. deleteCount === void 0 ? (this.length - start) : deleteCount
  296. ].concat(slice.call(arguments, 2)))
  297. }
  298. };
  299. } else {//IE8
  300. Array.prototype.splice = function(pos, removeCount){
  301. var length = this.length;
  302. if (pos > 0) {
  303. if (pos > length)
  304. pos = length;
  305. } else if (pos == void 0) {
  306. pos = 0;
  307. } else if (pos < 0) {
  308. pos = Math.max(length + pos, 0);
  309. }
  310. if (!(pos+removeCount < length))
  311. removeCount = length - pos;
  312. var removed = this.slice(pos, pos+removeCount);
  313. var insert = slice.call(arguments, 2);
  314. var add = insert.length;
  315. if (pos === length) {
  316. if (add) {
  317. this.push.apply(this, insert);
  318. }
  319. } else {
  320. var remove = Math.min(removeCount, length - pos);
  321. var tailOldPos = pos + remove;
  322. var tailNewPos = tailOldPos + add - remove;
  323. var tailCount = length - tailOldPos;
  324. var lengthAfterRemove = length - remove;
  325. if (tailNewPos < tailOldPos) { // case A
  326. for (var i = 0; i < tailCount; ++i) {
  327. this[tailNewPos+i] = this[tailOldPos+i];
  328. }
  329. } else if (tailNewPos > tailOldPos) { // case B
  330. for (i = tailCount; i--; ) {
  331. this[tailNewPos+i] = this[tailOldPos+i];
  332. }
  333. } // else, add == remove (nothing to do)
  334. if (add && pos === lengthAfterRemove) {
  335. this.length = lengthAfterRemove; // truncate array
  336. this.push.apply(this, insert);
  337. } else {
  338. this.length = lengthAfterRemove + add; // reserves space
  339. for (i = 0; i < add; ++i) {
  340. this[pos+i] = insert[i];
  341. }
  342. }
  343. }
  344. return removed;
  345. };
  346. }
  347. }
  348. if (!Array.isArray) {
  349. Array.isArray = function isArray(obj) {
  350. return _toString(obj) == "[object Array]";
  351. };
  352. }
  353. var boxedString = Object("a"),
  354. splitString = boxedString[0] != "a" || !(0 in boxedString);
  355. if (!Array.prototype.forEach) {
  356. Array.prototype.forEach = function forEach(fun /*, thisp*/) {
  357. var object = toObject(this),
  358. self = splitString && _toString(this) == "[object String]" ?
  359. this.split("") :
  360. object,
  361. thisp = arguments[1],
  362. i = -1,
  363. length = self.length >>> 0;
  364. if (_toString(fun) != "[object Function]") {
  365. throw new TypeError(); // TODO message
  366. }
  367. while (++i < length) {
  368. if (i in self) {
  369. fun.call(thisp, self[i], i, object);
  370. }
  371. }
  372. };
  373. }
  374. if (!Array.prototype.map) {
  375. Array.prototype.map = function map(fun /*, thisp*/) {
  376. var object = toObject(this),
  377. self = splitString && _toString(this) == "[object String]" ?
  378. this.split("") :
  379. object,
  380. length = self.length >>> 0,
  381. result = Array(length),
  382. thisp = arguments[1];
  383. if (_toString(fun) != "[object Function]") {
  384. throw new TypeError(fun + " is not a function");
  385. }
  386. for (var i = 0; i < length; i++) {
  387. if (i in self)
  388. result[i] = fun.call(thisp, self[i], i, object);
  389. }
  390. return result;
  391. };
  392. }
  393. if (!Array.prototype.filter) {
  394. Array.prototype.filter = function filter(fun /*, thisp */) {
  395. var object = toObject(this),
  396. self = splitString && _toString(this) == "[object String]" ?
  397. this.split("") :
  398. object,
  399. length = self.length >>> 0,
  400. result = [],
  401. value,
  402. thisp = arguments[1];
  403. if (_toString(fun) != "[object Function]") {
  404. throw new TypeError(fun + " is not a function");
  405. }
  406. for (var i = 0; i < length; i++) {
  407. if (i in self) {
  408. value = self[i];
  409. if (fun.call(thisp, value, i, object)) {
  410. result.push(value);
  411. }
  412. }
  413. }
  414. return result;
  415. };
  416. }
  417. if (!Array.prototype.every) {
  418. Array.prototype.every = function every(fun /*, thisp */) {
  419. var object = toObject(this),
  420. self = splitString && _toString(this) == "[object String]" ?
  421. this.split("") :
  422. object,
  423. length = self.length >>> 0,
  424. thisp = arguments[1];
  425. if (_toString(fun) != "[object Function]") {
  426. throw new TypeError(fun + " is not a function");
  427. }
  428. for (var i = 0; i < length; i++) {
  429. if (i in self && !fun.call(thisp, self[i], i, object)) {
  430. return false;
  431. }
  432. }
  433. return true;
  434. };
  435. }
  436. if (!Array.prototype.some) {
  437. Array.prototype.some = function some(fun /*, thisp */) {
  438. var object = toObject(this),
  439. self = splitString && _toString(this) == "[object String]" ?
  440. this.split("") :
  441. object,
  442. length = self.length >>> 0,
  443. thisp = arguments[1];
  444. if (_toString(fun) != "[object Function]") {
  445. throw new TypeError(fun + " is not a function");
  446. }
  447. for (var i = 0; i < length; i++) {
  448. if (i in self && fun.call(thisp, self[i], i, object)) {
  449. return true;
  450. }
  451. }
  452. return false;
  453. };
  454. }
  455. if (!Array.prototype.reduce) {
  456. Array.prototype.reduce = function reduce(fun /*, initial*/) {
  457. var object = toObject(this),
  458. self = splitString && _toString(this) == "[object String]" ?
  459. this.split("") :
  460. object,
  461. length = self.length >>> 0;
  462. if (_toString(fun) != "[object Function]") {
  463. throw new TypeError(fun + " is not a function");
  464. }
  465. if (!length && arguments.length == 1) {
  466. throw new TypeError("reduce of empty array with no initial value");
  467. }
  468. var i = 0;
  469. var result;
  470. if (arguments.length >= 2) {
  471. result = arguments[1];
  472. } else {
  473. do {
  474. if (i in self) {
  475. result = self[i++];
  476. break;
  477. }
  478. if (++i >= length) {
  479. throw new TypeError("reduce of empty array with no initial value");
  480. }
  481. } while (true);
  482. }
  483. for (; i < length; i++) {
  484. if (i in self) {
  485. result = fun.call(void 0, result, self[i], i, object);
  486. }
  487. }
  488. return result;
  489. };
  490. }
  491. if (!Array.prototype.reduceRight) {
  492. Array.prototype.reduceRight = function reduceRight(fun /*, initial*/) {
  493. var object = toObject(this),
  494. self = splitString && _toString(this) == "[object String]" ?
  495. this.split("") :
  496. object,
  497. length = self.length >>> 0;
  498. if (_toString(fun) != "[object Function]") {
  499. throw new TypeError(fun + " is not a function");
  500. }
  501. if (!length && arguments.length == 1) {
  502. throw new TypeError("reduceRight of empty array with no initial value");
  503. }
  504. var result, i = length - 1;
  505. if (arguments.length >= 2) {
  506. result = arguments[1];
  507. } else {
  508. do {
  509. if (i in self) {
  510. result = self[i--];
  511. break;
  512. }
  513. if (--i < 0) {
  514. throw new TypeError("reduceRight of empty array with no initial value");
  515. }
  516. } while (true);
  517. }
  518. do {
  519. if (i in this) {
  520. result = fun.call(void 0, result, self[i], i, object);
  521. }
  522. } while (i--);
  523. return result;
  524. };
  525. }
  526. if (!Array.prototype.indexOf || ([0, 1].indexOf(1, 2) != -1)) {
  527. Array.prototype.indexOf = function indexOf(sought /*, fromIndex */ ) {
  528. var self = splitString && _toString(this) == "[object String]" ?
  529. this.split("") :
  530. toObject(this),
  531. length = self.length >>> 0;
  532. if (!length) {
  533. return -1;
  534. }
  535. var i = 0;
  536. if (arguments.length > 1) {
  537. i = toInteger(arguments[1]);
  538. }
  539. i = i >= 0 ? i : Math.max(0, length + i);
  540. for (; i < length; i++) {
  541. if (i in self && self[i] === sought) {
  542. return i;
  543. }
  544. }
  545. return -1;
  546. };
  547. }
  548. if (!Array.prototype.lastIndexOf || ([0, 1].lastIndexOf(0, -3) != -1)) {
  549. Array.prototype.lastIndexOf = function lastIndexOf(sought /*, fromIndex */) {
  550. var self = splitString && _toString(this) == "[object String]" ?
  551. this.split("") :
  552. toObject(this),
  553. length = self.length >>> 0;
  554. if (!length) {
  555. return -1;
  556. }
  557. var i = length - 1;
  558. if (arguments.length > 1) {
  559. i = Math.min(i, toInteger(arguments[1]));
  560. }
  561. i = i >= 0 ? i : length - Math.abs(i);
  562. for (; i >= 0; i--) {
  563. if (i in self && sought === self[i]) {
  564. return i;
  565. }
  566. }
  567. return -1;
  568. };
  569. }
  570. if (!Object.getPrototypeOf) {
  571. Object.getPrototypeOf = function getPrototypeOf(object) {
  572. return object.__proto__ || (
  573. object.constructor ?
  574. object.constructor.prototype :
  575. prototypeOfObject
  576. );
  577. };
  578. }
  579. if (!Object.getOwnPropertyDescriptor) {
  580. var ERR_NON_OBJECT = "Object.getOwnPropertyDescriptor called on a " +
  581. "non-object: ";
  582. Object.getOwnPropertyDescriptor = function getOwnPropertyDescriptor(object, property) {
  583. if ((typeof object != "object" && typeof object != "function") || object === null)
  584. throw new TypeError(ERR_NON_OBJECT + object);
  585. if (!owns(object, property))
  586. return;
  587. var descriptor, getter, setter;
  588. descriptor = { enumerable: true, configurable: true };
  589. if (supportsAccessors) {
  590. var prototype = object.__proto__;
  591. object.__proto__ = prototypeOfObject;
  592. var getter = lookupGetter(object, property);
  593. var setter = lookupSetter(object, property);
  594. object.__proto__ = prototype;
  595. if (getter || setter) {
  596. if (getter) descriptor.get = getter;
  597. if (setter) descriptor.set = setter;
  598. return descriptor;
  599. }
  600. }
  601. descriptor.value = object[property];
  602. return descriptor;
  603. };
  604. }
  605. if (!Object.getOwnPropertyNames) {
  606. Object.getOwnPropertyNames = function getOwnPropertyNames(object) {
  607. return Object.keys(object);
  608. };
  609. }
  610. if (!Object.create) {
  611. var createEmpty;
  612. if (Object.prototype.__proto__ === null) {
  613. createEmpty = function () {
  614. return { "__proto__": null };
  615. };
  616. } else {
  617. createEmpty = function () {
  618. var empty = {};
  619. for (var i in empty)
  620. empty[i] = null;
  621. empty.constructor =
  622. empty.hasOwnProperty =
  623. empty.propertyIsEnumerable =
  624. empty.isPrototypeOf =
  625. empty.toLocaleString =
  626. empty.toString =
  627. empty.valueOf =
  628. empty.__proto__ = null;
  629. return empty;
  630. }
  631. }
  632. Object.create = function create(prototype, properties) {
  633. var object;
  634. if (prototype === null) {
  635. object = createEmpty();
  636. } else {
  637. if (typeof prototype != "object")
  638. throw new TypeError("typeof prototype["+(typeof prototype)+"] != 'object'");
  639. var Type = function () {};
  640. Type.prototype = prototype;
  641. object = new Type();
  642. object.__proto__ = prototype;
  643. }
  644. if (properties !== void 0)
  645. Object.defineProperties(object, properties);
  646. return object;
  647. };
  648. }
  649. function doesDefinePropertyWork(object) {
  650. try {
  651. Object.defineProperty(object, "sentinel", {});
  652. return "sentinel" in object;
  653. } catch (exception) {
  654. }
  655. }
  656. if (Object.defineProperty) {
  657. var definePropertyWorksOnObject = doesDefinePropertyWork({});
  658. var definePropertyWorksOnDom = typeof document == "undefined" ||
  659. doesDefinePropertyWork(document.createElement("div"));
  660. if (!definePropertyWorksOnObject || !definePropertyWorksOnDom) {
  661. var definePropertyFallback = Object.defineProperty;
  662. }
  663. }
  664. if (!Object.defineProperty || definePropertyFallback) {
  665. var ERR_NON_OBJECT_DESCRIPTOR = "Property description must be an object: ";
  666. var ERR_NON_OBJECT_TARGET = "Object.defineProperty called on non-object: "
  667. var ERR_ACCESSORS_NOT_SUPPORTED = "getters & setters can not be defined " +
  668. "on this javascript engine";
  669. Object.defineProperty = function defineProperty(object, property, descriptor) {
  670. if ((typeof object != "object" && typeof object != "function") || object === null)
  671. throw new TypeError(ERR_NON_OBJECT_TARGET + object);
  672. if ((typeof descriptor != "object" && typeof descriptor != "function") || descriptor === null)
  673. throw new TypeError(ERR_NON_OBJECT_DESCRIPTOR + descriptor);
  674. if (definePropertyFallback) {
  675. try {
  676. return definePropertyFallback.call(Object, object, property, descriptor);
  677. } catch (exception) {
  678. }
  679. }
  680. if (owns(descriptor, "value")) {
  681. if (supportsAccessors && (lookupGetter(object, property) ||
  682. lookupSetter(object, property)))
  683. {
  684. var prototype = object.__proto__;
  685. object.__proto__ = prototypeOfObject;
  686. delete object[property];
  687. object[property] = descriptor.value;
  688. object.__proto__ = prototype;
  689. } else {
  690. object[property] = descriptor.value;
  691. }
  692. } else {
  693. if (!supportsAccessors)
  694. throw new TypeError(ERR_ACCESSORS_NOT_SUPPORTED);
  695. if (owns(descriptor, "get"))
  696. defineGetter(object, property, descriptor.get);
  697. if (owns(descriptor, "set"))
  698. defineSetter(object, property, descriptor.set);
  699. }
  700. return object;
  701. };
  702. }
  703. if (!Object.defineProperties) {
  704. Object.defineProperties = function defineProperties(object, properties) {
  705. for (var property in properties) {
  706. if (owns(properties, property))
  707. Object.defineProperty(object, property, properties[property]);
  708. }
  709. return object;
  710. };
  711. }
  712. if (!Object.seal) {
  713. Object.seal = function seal(object) {
  714. return object;
  715. };
  716. }
  717. if (!Object.freeze) {
  718. Object.freeze = function freeze(object) {
  719. return object;
  720. };
  721. }
  722. try {
  723. Object.freeze(function () {});
  724. } catch (exception) {
  725. Object.freeze = (function freeze(freezeObject) {
  726. return function freeze(object) {
  727. if (typeof object == "function") {
  728. return object;
  729. } else {
  730. return freezeObject(object);
  731. }
  732. };
  733. })(Object.freeze);
  734. }
  735. if (!Object.preventExtensions) {
  736. Object.preventExtensions = function preventExtensions(object) {
  737. return object;
  738. };
  739. }
  740. if (!Object.isSealed) {
  741. Object.isSealed = function isSealed(object) {
  742. return false;
  743. };
  744. }
  745. if (!Object.isFrozen) {
  746. Object.isFrozen = function isFrozen(object) {
  747. return false;
  748. };
  749. }
  750. if (!Object.isExtensible) {
  751. Object.isExtensible = function isExtensible(object) {
  752. if (Object(object) === object) {
  753. throw new TypeError(); // TODO message
  754. }
  755. var name = '';
  756. while (owns(object, name)) {
  757. name += '?';
  758. }
  759. object[name] = true;
  760. var returnValue = owns(object, name);
  761. delete object[name];
  762. return returnValue;
  763. };
  764. }
  765. if (!Object.keys) {
  766. var hasDontEnumBug = true,
  767. dontEnums = [
  768. "toString",
  769. "toLocaleString",
  770. "valueOf",
  771. "hasOwnProperty",
  772. "isPrototypeOf",
  773. "propertyIsEnumerable",
  774. "constructor"
  775. ],
  776. dontEnumsLength = dontEnums.length;
  777. for (var key in {"toString": null}) {
  778. hasDontEnumBug = false;
  779. }
  780. Object.keys = function keys(object) {
  781. if (
  782. (typeof object != "object" && typeof object != "function") ||
  783. object === null
  784. ) {
  785. throw new TypeError("Object.keys called on a non-object");
  786. }
  787. var keys = [];
  788. for (var name in object) {
  789. if (owns(object, name)) {
  790. keys.push(name);
  791. }
  792. }
  793. if (hasDontEnumBug) {
  794. for (var i = 0, ii = dontEnumsLength; i < ii; i++) {
  795. var dontEnum = dontEnums[i];
  796. if (owns(object, dontEnum)) {
  797. keys.push(dontEnum);
  798. }
  799. }
  800. }
  801. return keys;
  802. };
  803. }
  804. if (!Date.now) {
  805. Date.now = function now() {
  806. return new Date().getTime();
  807. };
  808. }
  809. var ws = "\x09\x0A\x0B\x0C\x0D\x20\xA0\u1680\u180E\u2000\u2001\u2002\u2003" +
  810. "\u2004\u2005\u2006\u2007\u2008\u2009\u200A\u202F\u205F\u3000\u2028" +
  811. "\u2029\uFEFF";
  812. if (!String.prototype.trim || ws.trim()) {
  813. ws = "[" + ws + "]";
  814. var trimBeginRegexp = new RegExp("^" + ws + ws + "*"),
  815. trimEndRegexp = new RegExp(ws + ws + "*$");
  816. String.prototype.trim = function trim() {
  817. return String(this).replace(trimBeginRegexp, "").replace(trimEndRegexp, "");
  818. };
  819. }
  820. function toInteger(n) {
  821. n = +n;
  822. if (n !== n) { // isNaN
  823. n = 0;
  824. } else if (n !== 0 && n !== (1/0) && n !== -(1/0)) {
  825. n = (n > 0 || -1) * Math.floor(Math.abs(n));
  826. }
  827. return n;
  828. }
  829. function isPrimitive(input) {
  830. var type = typeof input;
  831. return (
  832. input === null ||
  833. type === "undefined" ||
  834. type === "boolean" ||
  835. type === "number" ||
  836. type === "string"
  837. );
  838. }
  839. function toPrimitive(input) {
  840. var val, valueOf, toString;
  841. if (isPrimitive(input)) {
  842. return input;
  843. }
  844. valueOf = input.valueOf;
  845. if (typeof valueOf === "function") {
  846. val = valueOf.call(input);
  847. if (isPrimitive(val)) {
  848. return val;
  849. }
  850. }
  851. toString = input.toString;
  852. if (typeof toString === "function") {
  853. val = toString.call(input);
  854. if (isPrimitive(val)) {
  855. return val;
  856. }
  857. }
  858. throw new TypeError();
  859. }
  860. var toObject = function (o) {
  861. if (o == null) { // this matches both null and undefined
  862. throw new TypeError("can't convert "+o+" to object");
  863. }
  864. return Object(o);
  865. };
  866. });
  867. define("ace/lib/fixoldbrowsers",["require","exports","module","ace/lib/regexp","ace/lib/es5-shim"], function(require, exports, module) {
  868. "use strict";
  869. require("./regexp");
  870. require("./es5-shim");
  871. });
  872. define("ace/lib/dom",["require","exports","module"], function(require, exports, module) {
  873. "use strict";
  874. var XHTML_NS = "http://www.w3.org/1999/xhtml";
  875. exports.getDocumentHead = function(doc) {
  876. if (!doc)
  877. doc = document;
  878. return doc.head || doc.getElementsByTagName("head")[0] || doc.documentElement;
  879. }
  880. exports.createElement = function(tag, ns) {
  881. return document.createElementNS ?
  882. document.createElementNS(ns || XHTML_NS, tag) :
  883. document.createElement(tag);
  884. };
  885. exports.hasCssClass = function(el, name) {
  886. var classes = (el.className + "").split(/\s+/g);
  887. return classes.indexOf(name) !== -1;
  888. };
  889. exports.addCssClass = function(el, name) {
  890. if (!exports.hasCssClass(el, name)) {
  891. el.className += " " + name;
  892. }
  893. };
  894. exports.removeCssClass = function(el, name) {
  895. var classes = el.className.split(/\s+/g);
  896. while (true) {
  897. var index = classes.indexOf(name);
  898. if (index == -1) {
  899. break;
  900. }
  901. classes.splice(index, 1);
  902. }
  903. el.className = classes.join(" ");
  904. };
  905. exports.toggleCssClass = function(el, name) {
  906. var classes = el.className.split(/\s+/g), add = true;
  907. while (true) {
  908. var index = classes.indexOf(name);
  909. if (index == -1) {
  910. break;
  911. }
  912. add = false;
  913. classes.splice(index, 1);
  914. }
  915. if (add)
  916. classes.push(name);
  917. el.className = classes.join(" ");
  918. return add;
  919. };
  920. exports.setCssClass = function(node, className, include) {
  921. if (include) {
  922. exports.addCssClass(node, className);
  923. } else {
  924. exports.removeCssClass(node, className);
  925. }
  926. };
  927. exports.hasCssString = function(id, doc) {
  928. var index = 0, sheets;
  929. doc = doc || document;
  930. if (doc.createStyleSheet && (sheets = doc.styleSheets)) {
  931. while (index < sheets.length)
  932. if (sheets[index++].owningElement.id === id) return true;
  933. } else if ((sheets = doc.getElementsByTagName("style"))) {
  934. while (index < sheets.length)
  935. if (sheets[index++].id === id) return true;
  936. }
  937. return false;
  938. };
  939. exports.importCssString = function importCssString(cssText, id, doc) {
  940. doc = doc || document;
  941. if (id && exports.hasCssString(id, doc))
  942. return null;
  943. var style;
  944. if (id)
  945. cssText += "\n/*# sourceURL=ace/css/" + id + " */";
  946. if (doc.createStyleSheet) {
  947. style = doc.createStyleSheet();
  948. style.cssText = cssText;
  949. if (id)
  950. style.owningElement.id = id;
  951. } else {
  952. style = exports.createElement("style");
  953. style.appendChild(doc.createTextNode(cssText));
  954. if (id)
  955. style.id = id;
  956. exports.getDocumentHead(doc).appendChild(style);
  957. }
  958. };
  959. exports.importCssStylsheet = function(uri, doc) {
  960. if (doc.createStyleSheet) {
  961. doc.createStyleSheet(uri);
  962. } else {
  963. var link = exports.createElement('link');
  964. link.rel = 'stylesheet';
  965. link.href = uri;
  966. exports.getDocumentHead(doc).appendChild(link);
  967. }
  968. };
  969. exports.getInnerWidth = function(element) {
  970. return (
  971. parseInt(exports.computedStyle(element, "paddingLeft"), 10) +
  972. parseInt(exports.computedStyle(element, "paddingRight"), 10) +
  973. element.clientWidth
  974. );
  975. };
  976. exports.getInnerHeight = function(element) {
  977. return (
  978. parseInt(exports.computedStyle(element, "paddingTop"), 10) +
  979. parseInt(exports.computedStyle(element, "paddingBottom"), 10) +
  980. element.clientHeight
  981. );
  982. };
  983. exports.scrollbarWidth = function(document) {
  984. var inner = exports.createElement("ace_inner");
  985. inner.style.width = "100%";
  986. inner.style.minWidth = "0px";
  987. inner.style.height = "200px";
  988. inner.style.display = "block";
  989. var outer = exports.createElement("ace_outer");
  990. var style = outer.style;
  991. style.position = "absolute";
  992. style.left = "-10000px";
  993. style.overflow = "hidden";
  994. style.width = "200px";
  995. style.minWidth = "0px";
  996. style.height = "150px";
  997. style.display = "block";
  998. outer.appendChild(inner);
  999. var body = document.documentElement;
  1000. body.appendChild(outer);
  1001. var noScrollbar = inner.offsetWidth;
  1002. style.overflow = "scroll";
  1003. var withScrollbar = inner.offsetWidth;
  1004. if (noScrollbar == withScrollbar) {
  1005. withScrollbar = outer.clientWidth;
  1006. }
  1007. body.removeChild(outer);
  1008. return noScrollbar-withScrollbar;
  1009. };
  1010. if (typeof document == "undefined") {
  1011. exports.importCssString = function() {};
  1012. return;
  1013. }
  1014. if (window.pageYOffset !== undefined) {
  1015. exports.getPageScrollTop = function() {
  1016. return window.pageYOffset;
  1017. };
  1018. exports.getPageScrollLeft = function() {
  1019. return window.pageXOffset;
  1020. };
  1021. }
  1022. else {
  1023. exports.getPageScrollTop = function() {
  1024. return document.body.scrollTop;
  1025. };
  1026. exports.getPageScrollLeft = function() {
  1027. return document.body.scrollLeft;
  1028. };
  1029. }
  1030. if (window.getComputedStyle)
  1031. exports.computedStyle = function(element, style) {
  1032. if (style)
  1033. return (window.getComputedStyle(element, "") || {})[style] || "";
  1034. return window.getComputedStyle(element, "") || {};
  1035. };
  1036. else
  1037. exports.computedStyle = function(element, style) {
  1038. if (style)
  1039. return element.currentStyle[style];
  1040. return element.currentStyle;
  1041. };
  1042. exports.setInnerHtml = function(el, innerHtml) {
  1043. var element = el.cloneNode(false);//document.createElement("div");
  1044. element.innerHTML = innerHtml;
  1045. el.parentNode.replaceChild(element, el);
  1046. return element;
  1047. };
  1048. if ("textContent" in document.documentElement) {
  1049. exports.setInnerText = function(el, innerText) {
  1050. el.textContent = innerText;
  1051. };
  1052. exports.getInnerText = function(el) {
  1053. return el.textContent;
  1054. };
  1055. }
  1056. else {
  1057. exports.setInnerText = function(el, innerText) {
  1058. el.innerText = innerText;
  1059. };
  1060. exports.getInnerText = function(el) {
  1061. return el.innerText;
  1062. };
  1063. }
  1064. exports.getParentWindow = function(document) {
  1065. return document.defaultView || document.parentWindow;
  1066. };
  1067. });
  1068. define("ace/lib/oop",["require","exports","module"], function(require, exports, module) {
  1069. "use strict";
  1070. exports.inherits = function(ctor, superCtor) {
  1071. ctor.super_ = superCtor;
  1072. ctor.prototype = Object.create(superCtor.prototype, {
  1073. constructor: {
  1074. value: ctor,
  1075. enumerable: false,
  1076. writable: true,
  1077. configurable: true
  1078. }
  1079. });
  1080. };
  1081. exports.mixin = function(obj, mixin) {
  1082. for (var key in mixin) {
  1083. obj[key] = mixin[key];
  1084. }
  1085. return obj;
  1086. };
  1087. exports.implement = function(proto, mixin) {
  1088. exports.mixin(proto, mixin);
  1089. };
  1090. });
  1091. define("ace/lib/keys",["require","exports","module","ace/lib/fixoldbrowsers","ace/lib/oop"], function(require, exports, module) {
  1092. "use strict";
  1093. require("./fixoldbrowsers");
  1094. var oop = require("./oop");
  1095. var Keys = (function() {
  1096. var ret = {
  1097. MODIFIER_KEYS: {
  1098. 16: 'Shift', 17: 'Ctrl', 18: 'Alt', 224: 'Meta'
  1099. },
  1100. KEY_MODS: {
  1101. "ctrl": 1, "alt": 2, "option" : 2, "shift": 4,
  1102. "super": 8, "meta": 8, "command": 8, "cmd": 8
  1103. },
  1104. FUNCTION_KEYS : {
  1105. 8 : "Backspace",
  1106. 9 : "Tab",
  1107. 13 : "Return",
  1108. 19 : "Pause",
  1109. 27 : "Esc",
  1110. 32 : "Space",
  1111. 33 : "PageUp",
  1112. 34 : "PageDown",
  1113. 35 : "End",
  1114. 36 : "Home",
  1115. 37 : "Left",
  1116. 38 : "Up",
  1117. 39 : "Right",
  1118. 40 : "Down",
  1119. 44 : "Print",
  1120. 45 : "Insert",
  1121. 46 : "Delete",
  1122. 96 : "Numpad0",
  1123. 97 : "Numpad1",
  1124. 98 : "Numpad2",
  1125. 99 : "Numpad3",
  1126. 100: "Numpad4",
  1127. 101: "Numpad5",
  1128. 102: "Numpad6",
  1129. 103: "Numpad7",
  1130. 104: "Numpad8",
  1131. 105: "Numpad9",
  1132. '-13': "NumpadEnter",
  1133. 112: "F1",
  1134. 113: "F2",
  1135. 114: "F3",
  1136. 115: "F4",
  1137. 116: "F5",
  1138. 117: "F6",
  1139. 118: "F7",
  1140. 119: "F8",
  1141. 120: "F9",
  1142. 121: "F10",
  1143. 122: "F11",
  1144. 123: "F12",
  1145. 144: "Numlock",
  1146. 145: "Scrolllock"
  1147. },
  1148. PRINTABLE_KEYS: {
  1149. 32: ' ', 48: '0', 49: '1', 50: '2', 51: '3', 52: '4', 53: '5',
  1150. 54: '6', 55: '7', 56: '8', 57: '9', 59: ';', 61: '=', 65: 'a',
  1151. 66: 'b', 67: 'c', 68: 'd', 69: 'e', 70: 'f', 71: 'g', 72: 'h',
  1152. 73: 'i', 74: 'j', 75: 'k', 76: 'l', 77: 'm', 78: 'n', 79: 'o',
  1153. 80: 'p', 81: 'q', 82: 'r', 83: 's', 84: 't', 85: 'u', 86: 'v',
  1154. 87: 'w', 88: 'x', 89: 'y', 90: 'z', 107: '+', 109: '-', 110: '.',
  1155. 186: ';', 187: '=', 188: ',', 189: '-', 190: '.', 191: '/', 192: '`',
  1156. 219: '[', 220: '\\',221: ']', 222: "'", 111: '/', 106: '*'
  1157. }
  1158. };
  1159. var name, i;
  1160. for (i in ret.FUNCTION_KEYS) {
  1161. name = ret.FUNCTION_KEYS[i].toLowerCase();
  1162. ret[name] = parseInt(i, 10);
  1163. }
  1164. for (i in ret.PRINTABLE_KEYS) {
  1165. name = ret.PRINTABLE_KEYS[i].toLowerCase();
  1166. ret[name] = parseInt(i, 10);
  1167. }
  1168. oop.mixin(ret, ret.MODIFIER_KEYS);
  1169. oop.mixin(ret, ret.PRINTABLE_KEYS);
  1170. oop.mixin(ret, ret.FUNCTION_KEYS);
  1171. ret.enter = ret["return"];
  1172. ret.escape = ret.esc;
  1173. ret.del = ret["delete"];
  1174. ret[173] = '-';
  1175. (function() {
  1176. var mods = ["cmd", "ctrl", "alt", "shift"];
  1177. for (var i = Math.pow(2, mods.length); i--;) {
  1178. ret.KEY_MODS[i] = mods.filter(function(x) {
  1179. return i & ret.KEY_MODS[x];
  1180. }).join("-") + "-";
  1181. }
  1182. })();
  1183. ret.KEY_MODS[0] = "";
  1184. ret.KEY_MODS[-1] = "input-";
  1185. return ret;
  1186. })();
  1187. oop.mixin(exports, Keys);
  1188. exports.keyCodeToString = function(keyCode) {
  1189. var keyString = Keys[keyCode];
  1190. if (typeof keyString != "string")
  1191. keyString = String.fromCharCode(keyCode);
  1192. return keyString.toLowerCase();
  1193. };
  1194. });
  1195. define("ace/lib/useragent",["require","exports","module"], function(require, exports, module) {
  1196. "use strict";
  1197. exports.OS = {
  1198. LINUX: "LINUX",
  1199. MAC: "MAC",
  1200. WINDOWS: "WINDOWS"
  1201. };
  1202. exports.getOS = function() {
  1203. if (exports.isMac) {
  1204. return exports.OS.MAC;
  1205. } else if (exports.isLinux) {
  1206. return exports.OS.LINUX;
  1207. } else {
  1208. return exports.OS.WINDOWS;
  1209. }
  1210. };
  1211. if (typeof navigator != "object")
  1212. return;
  1213. var os = (navigator.platform.match(/mac|win|linux/i) || ["other"])[0].toLowerCase();
  1214. var ua = navigator.userAgent;
  1215. exports.isWin = (os == "win");
  1216. exports.isMac = (os == "mac");
  1217. exports.isLinux = (os == "linux");
  1218. exports.isIE =
  1219. (navigator.appName == "Microsoft Internet Explorer" || navigator.appName.indexOf("MSAppHost") >= 0)
  1220. ? parseFloat((ua.match(/(?:MSIE |Trident\/[0-9]+[\.0-9]+;.*rv:)([0-9]+[\.0-9]+)/)||[])[1])
  1221. : parseFloat((ua.match(/(?:Trident\/[0-9]+[\.0-9]+;.*rv:)([0-9]+[\.0-9]+)/)||[])[1]); // for ie
  1222. exports.isOldIE = exports.isIE && exports.isIE < 9;
  1223. exports.isGecko = exports.isMozilla = (window.Controllers || window.controllers) && window.navigator.product === "Gecko";
  1224. exports.isOldGecko = exports.isGecko && parseInt((ua.match(/rv:(\d+)/)||[])[1], 10) < 4;
  1225. exports.isOpera = window.opera && Object.prototype.toString.call(window.opera) == "[object Opera]";
  1226. exports.isWebKit = parseFloat(ua.split("WebKit/")[1]) || undefined;
  1227. exports.isChrome = parseFloat(ua.split(" Chrome/")[1]) || undefined;
  1228. exports.isAIR = ua.indexOf("AdobeAIR") >= 0;
  1229. exports.isIPad = ua.indexOf("iPad") >= 0;
  1230. exports.isChromeOS = ua.indexOf(" CrOS ") >= 0;
  1231. exports.isIOS = /iPad|iPhone|iPod/.test(ua) && !window.MSStream;
  1232. if (exports.isIOS) exports.isMac = true;
  1233. });
  1234. define("ace/lib/event",["require","exports","module","ace/lib/keys","ace/lib/useragent"], function(require, exports, module) {
  1235. "use strict";
  1236. var keys = require("./keys");
  1237. var useragent = require("./useragent");
  1238. var pressedKeys = null;
  1239. var ts = 0;
  1240. exports.addListener = function(elem, type, callback) {
  1241. if (elem.addEventListener) {
  1242. return elem.addEventListener(type, callback, false);
  1243. }
  1244. if (elem.attachEvent) {
  1245. var wrapper = function() {
  1246. callback.call(elem, window.event);
  1247. };
  1248. callback._wrapper = wrapper;
  1249. elem.attachEvent("on" + type, wrapper);
  1250. }
  1251. };
  1252. exports.removeListener = function(elem, type, callback) {
  1253. if (elem.removeEventListener) {
  1254. return elem.removeEventListener(type, callback, false);
  1255. }
  1256. if (elem.detachEvent) {
  1257. elem.detachEvent("on" + type, callback._wrapper || callback);
  1258. }
  1259. };
  1260. exports.stopEvent = function(e) {
  1261. exports.stopPropagation(e);
  1262. exports.preventDefault(e);
  1263. return false;
  1264. };
  1265. exports.stopPropagation = function(e) {
  1266. if (e.stopPropagation)
  1267. e.stopPropagation();
  1268. else
  1269. e.cancelBubble = true;
  1270. };
  1271. exports.preventDefault = function(e) {
  1272. if (e.preventDefault)
  1273. e.preventDefault();
  1274. else
  1275. e.returnValue = false;
  1276. };
  1277. exports.getButton = function(e) {
  1278. if (e.type == "dblclick")
  1279. return 0;
  1280. if (e.type == "contextmenu" || (useragent.isMac && (e.ctrlKey && !e.altKey && !e.shiftKey)))
  1281. return 2;
  1282. if (e.preventDefault) {
  1283. return e.button;
  1284. }
  1285. else {
  1286. return {1:0, 2:2, 4:1}[e.button];
  1287. }
  1288. };
  1289. exports.capture = function(el, eventHandler, releaseCaptureHandler) {
  1290. function onMouseUp(e) {
  1291. eventHandler && eventHandler(e);
  1292. releaseCaptureHandler && releaseCaptureHandler(e);
  1293. exports.removeListener(document, "mousemove", eventHandler, true);
  1294. exports.removeListener(document, "mouseup", onMouseUp, true);
  1295. exports.removeListener(document, "dragstart", onMouseUp, true);
  1296. }
  1297. exports.addListener(document, "mousemove", eventHandler, true);
  1298. exports.addListener(document, "mouseup", onMouseUp, true);
  1299. exports.addListener(document, "dragstart", onMouseUp, true);
  1300. return onMouseUp;
  1301. };
  1302. exports.addTouchMoveListener = function (el, callback) {
  1303. if ("ontouchmove" in el) {
  1304. var startx, starty;
  1305. exports.addListener(el, "touchstart", function (e) {
  1306. var touchObj = e.changedTouches[0];
  1307. startx = touchObj.clientX;
  1308. starty = touchObj.clientY;
  1309. });
  1310. exports.addListener(el, "touchmove", function (e) {
  1311. var factor = 1,
  1312. touchObj = e.changedTouches[0];
  1313. e.wheelX = -(touchObj.clientX - startx) / factor;
  1314. e.wheelY = -(touchObj.clientY - starty) / factor;
  1315. startx = touchObj.clientX;
  1316. starty = touchObj.clientY;
  1317. callback(e);
  1318. });
  1319. }
  1320. };
  1321. exports.addMouseWheelListener = function(el, callback) {
  1322. if ("onmousewheel" in el) {
  1323. exports.addListener(el, "mousewheel", function(e) {
  1324. var factor = 8;
  1325. if (e.wheelDeltaX !== undefined) {
  1326. e.wheelX = -e.wheelDeltaX / factor;
  1327. e.wheelY = -e.wheelDeltaY / factor;
  1328. } else {
  1329. e.wheelX = 0;
  1330. e.wheelY = -e.wheelDelta / factor;
  1331. }
  1332. callback(e);
  1333. });
  1334. } else if ("onwheel" in el) {
  1335. exports.addListener(el, "wheel", function(e) {
  1336. var factor = 0.35;
  1337. switch (e.deltaMode) {
  1338. case e.DOM_DELTA_PIXEL:
  1339. e.wheelX = e.deltaX * factor || 0;
  1340. e.wheelY = e.deltaY * factor || 0;
  1341. break;
  1342. case e.DOM_DELTA_LINE:
  1343. case e.DOM_DELTA_PAGE:
  1344. e.wheelX = (e.deltaX || 0) * 5;
  1345. e.wheelY = (e.deltaY || 0) * 5;
  1346. break;
  1347. }
  1348. callback(e);
  1349. });
  1350. } else {
  1351. exports.addListener(el, "DOMMouseScroll", function(e) {
  1352. if (e.axis && e.axis == e.HORIZONTAL_AXIS) {
  1353. e.wheelX = (e.detail || 0) * 5;
  1354. e.wheelY = 0;
  1355. } else {
  1356. e.wheelX = 0;
  1357. e.wheelY = (e.detail || 0) * 5;
  1358. }
  1359. callback(e);
  1360. });
  1361. }
  1362. };
  1363. exports.addMultiMouseDownListener = function(elements, timeouts, eventHandler, callbackName) {
  1364. var clicks = 0;
  1365. var startX, startY, timer;
  1366. var eventNames = {
  1367. 2: "dblclick",
  1368. 3: "tripleclick",
  1369. 4: "quadclick"
  1370. };
  1371. function onMousedown(e) {
  1372. if (exports.getButton(e) !== 0) {
  1373. clicks = 0;
  1374. } else if (e.detail > 1) {
  1375. clicks++;
  1376. if (clicks > 4)
  1377. clicks = 1;
  1378. } else {
  1379. clicks = 1;
  1380. }
  1381. if (useragent.isIE) {
  1382. var isNewClick = Math.abs(e.clientX - startX) > 5 || Math.abs(e.clientY - startY) > 5;
  1383. if (!timer || isNewClick)
  1384. clicks = 1;
  1385. if (timer)
  1386. clearTimeout(timer);
  1387. timer = setTimeout(function() {timer = null}, timeouts[clicks - 1] || 600);
  1388. if (clicks == 1) {
  1389. startX = e.clientX;
  1390. startY = e.clientY;
  1391. }
  1392. }
  1393. e._clicks = clicks;
  1394. eventHandler[callbackName]("mousedown", e);
  1395. if (clicks > 4)
  1396. clicks = 0;
  1397. else if (clicks > 1)
  1398. return eventHandler[callbackName](eventNames[clicks], e);
  1399. }
  1400. function onDblclick(e) {
  1401. clicks = 2;
  1402. if (timer)
  1403. clearTimeout(timer);
  1404. timer = setTimeout(function() {timer = null}, timeouts[clicks - 1] || 600);
  1405. eventHandler[callbackName]("mousedown", e);
  1406. eventHandler[callbackName](eventNames[clicks], e);
  1407. }
  1408. if (!Array.isArray(elements))
  1409. elements = [elements];
  1410. elements.forEach(function(el) {
  1411. exports.addListener(el, "mousedown", onMousedown);
  1412. if (useragent.isOldIE)
  1413. exports.addListener(el, "dblclick", onDblclick);
  1414. });
  1415. };
  1416. var getModifierHash = useragent.isMac && useragent.isOpera && !("KeyboardEvent" in window)
  1417. ? function(e) {
  1418. return 0 | (e.metaKey ? 1 : 0) | (e.altKey ? 2 : 0) | (e.shiftKey ? 4 : 0) | (e.ctrlKey ? 8 : 0);
  1419. }
  1420. : function(e) {
  1421. return 0 | (e.ctrlKey ? 1 : 0) | (e.altKey ? 2 : 0) | (e.shiftKey ? 4 : 0) | (e.metaKey ? 8 : 0);
  1422. };
  1423. exports.getModifierString = function(e) {
  1424. return keys.KEY_MODS[getModifierHash(e)];
  1425. };
  1426. function normalizeCommandKeys(callback, e, keyCode) {
  1427. var hashId = getModifierHash(e);
  1428. if (!useragent.isMac && pressedKeys) {
  1429. if (e.getModifierState && (e.getModifierState("OS") || e.getModifierState("Win")))
  1430. hashId |= 8;
  1431. if (pressedKeys.altGr) {
  1432. if ((3 & hashId) != 3)
  1433. pressedKeys.altGr = 0;
  1434. else
  1435. return;
  1436. }
  1437. if (keyCode === 18 || keyCode === 17) {
  1438. var location = "location" in e ? e.location : e.keyLocation;
  1439. if (keyCode === 17 && location === 1) {
  1440. if (pressedKeys[keyCode] == 1)
  1441. ts = e.timeStamp;
  1442. } else if (keyCode === 18 && hashId === 3 && location === 2) {
  1443. var dt = e.timeStamp - ts;
  1444. if (dt < 50)
  1445. pressedKeys.altGr = true;
  1446. }
  1447. }
  1448. }
  1449. if (keyCode in keys.MODIFIER_KEYS) {
  1450. keyCode = -1;
  1451. }
  1452. if (hashId & 8 && (keyCode >= 91 && keyCode <= 93)) {
  1453. keyCode = -1;
  1454. }
  1455. if (!hashId && keyCode === 13) {
  1456. var location = "location" in e ? e.location : e.keyLocation;
  1457. if (location === 3) {
  1458. callback(e, hashId, -keyCode);
  1459. if (e.defaultPrevented)
  1460. return;
  1461. }
  1462. }
  1463. if (useragent.isChromeOS && hashId & 8) {
  1464. callback(e, hashId, keyCode);
  1465. if (e.defaultPrevented)
  1466. return;
  1467. else
  1468. hashId &= ~8;
  1469. }
  1470. if (!hashId && !(keyCode in keys.FUNCTION_KEYS) && !(keyCode in keys.PRINTABLE_KEYS)) {
  1471. return false;
  1472. }
  1473. return callback(e, hashId, keyCode);
  1474. }
  1475. exports.addCommandKeyListener = function(el, callback) {
  1476. var addListener = exports.addListener;
  1477. if (useragent.isOldGecko || (useragent.isOpera && !("KeyboardEvent" in window))) {
  1478. var lastKeyDownKeyCode = null;
  1479. addListener(el, "keydown", function(e) {
  1480. lastKeyDownKeyCode = e.keyCode;
  1481. });
  1482. addListener(el, "keypress", function(e) {
  1483. return normalizeCommandKeys(callback, e, lastKeyDownKeyCode);
  1484. });
  1485. } else {
  1486. var lastDefaultPrevented = null;
  1487. addListener(el, "keydown", function(e) {
  1488. pressedKeys[e.keyCode] = (pressedKeys[e.keyCode] || 0) + 1;
  1489. var result = normalizeCommandKeys(callback, e, e.keyCode);
  1490. lastDefaultPrevented = e.defaultPrevented;
  1491. return result;
  1492. });
  1493. addListener(el, "keypress", function(e) {
  1494. if (lastDefaultPrevented && (e.ctrlKey || e.altKey || e.shiftKey || e.metaKey)) {
  1495. exports.stopEvent(e);
  1496. lastDefaultPrevented = null;
  1497. }
  1498. });
  1499. addListener(el, "keyup", function(e) {
  1500. pressedKeys[e.keyCode] = null;
  1501. });
  1502. if (!pressedKeys) {
  1503. resetPressedKeys();
  1504. addListener(window, "focus", resetPressedKeys);
  1505. }
  1506. }
  1507. };
  1508. function resetPressedKeys() {
  1509. pressedKeys = Object.create(null);
  1510. }
  1511. if (typeof window == "object" && window.postMessage && !useragent.isOldIE) {
  1512. var postMessageId = 1;
  1513. exports.nextTick = function(callback, win) {
  1514. win = win || window;
  1515. var messageName = "zero-timeout-message-" + postMessageId;
  1516. exports.addListener(win, "message", function listener(e) {
  1517. if (e.data == messageName) {
  1518. exports.stopPropagation(e);
  1519. exports.removeListener(win, "message", listener);
  1520. callback();
  1521. }
  1522. });
  1523. win.postMessage(messageName, "*");
  1524. };
  1525. }
  1526. exports.nextFrame = typeof window == "object" && (window.requestAnimationFrame
  1527. || window.mozRequestAnimationFrame
  1528. || window.webkitRequestAnimationFrame
  1529. || window.msRequestAnimationFrame
  1530. || window.oRequestAnimationFrame);
  1531. if (exports.nextFrame)
  1532. exports.nextFrame = exports.nextFrame.bind(window);
  1533. else
  1534. exports.nextFrame = function(callback) {
  1535. setTimeout(callback, 17);
  1536. };
  1537. });
  1538. define("ace/lib/lang",["require","exports","module"], function(require, exports, module) {
  1539. "use strict";
  1540. exports.last = function(a) {
  1541. return a[a.length - 1];
  1542. };
  1543. exports.stringReverse = function(string) {
  1544. return string.split("").reverse().join("");
  1545. };
  1546. exports.stringRepeat = function (string, count) {
  1547. var result = '';
  1548. while (count > 0) {
  1549. if (count & 1)
  1550. result += string;
  1551. if (count >>= 1)
  1552. string += string;
  1553. }
  1554. return result;
  1555. };
  1556. var trimBeginRegexp = /^\s\s*/;
  1557. var trimEndRegexp = /\s\s*$/;
  1558. exports.stringTrimLeft = function (string) {
  1559. return string.replace(trimBeginRegexp, '');
  1560. };
  1561. exports.stringTrimRight = function (string) {
  1562. return string.replace(trimEndRegexp, '');
  1563. };
  1564. exports.copyObject = function(obj) {
  1565. var copy = {};
  1566. for (var key in obj) {
  1567. copy[key] = obj[key];
  1568. }
  1569. return copy;
  1570. };
  1571. exports.copyArray = function(array){
  1572. var copy = [];
  1573. for (var i=0, l=array.length; i<l; i++) {
  1574. if (array[i] && typeof array[i] == "object")
  1575. copy[i] = this.copyObject(array[i]);
  1576. else
  1577. copy[i] = array[i];
  1578. }
  1579. return copy;
  1580. };
  1581. exports.deepCopy = function deepCopy(obj) {
  1582. if (typeof obj !== "object" || !obj)
  1583. return obj;
  1584. var copy;
  1585. if (Array.isArray(obj)) {
  1586. copy = [];
  1587. for (var key = 0; key < obj.length; key++) {
  1588. copy[key] = deepCopy(obj[key]);
  1589. }
  1590. return copy;
  1591. }
  1592. if (Object.prototype.toString.call(obj) !== "[object Object]")
  1593. return obj;
  1594. copy = {};
  1595. for (var key in obj)
  1596. copy[key] = deepCopy(obj[key]);
  1597. return copy;
  1598. };
  1599. exports.arrayToMap = function(arr) {
  1600. var map = {};
  1601. for (var i=0; i<arr.length; i++) {
  1602. map[arr[i]] = 1;
  1603. }
  1604. return map;
  1605. };
  1606. exports.createMap = function(props) {
  1607. var map = Object.create(null);
  1608. for (var i in props) {
  1609. map[i] = props[i];
  1610. }
  1611. return map;
  1612. };
  1613. exports.arrayRemove = function(array, value) {
  1614. for (var i = 0; i <= array.length; i++) {
  1615. if (value === array[i]) {
  1616. array.splice(i, 1);
  1617. }
  1618. }
  1619. };
  1620. exports.escapeRegExp = function(str) {
  1621. return str.replace(/([.*+?^${}()|[\]\/\\])/g, '\\$1');
  1622. };
  1623. exports.escapeHTML = function(str) {
  1624. return str.replace(/&/g, "&#38;").replace(/"/g, "&#34;").replace(/'/g, "&#39;").replace(/</g, "&#60;");
  1625. };
  1626. exports.getMatchOffsets = function(string, regExp) {
  1627. var matches = [];
  1628. string.replace(regExp, function(str) {
  1629. matches.push({
  1630. offset: arguments[arguments.length-2],
  1631. length: str.length
  1632. });
  1633. });
  1634. return matches;
  1635. };
  1636. exports.deferredCall = function(fcn) {
  1637. var timer = null;
  1638. var callback = function() {
  1639. timer = null;
  1640. fcn();
  1641. };
  1642. var deferred = function(timeout) {
  1643. deferred.cancel();
  1644. timer = setTimeout(callback, timeout || 0);
  1645. return deferred;
  1646. };
  1647. deferred.schedule = deferred;
  1648. deferred.call = function() {
  1649. this.cancel();
  1650. fcn();
  1651. return deferred;
  1652. };
  1653. deferred.cancel = function() {
  1654. clearTimeout(timer);
  1655. timer = null;
  1656. return deferred;
  1657. };
  1658. deferred.isPending = function() {
  1659. return timer;
  1660. };
  1661. return deferred;
  1662. };
  1663. exports.delayedCall = function(fcn, defaultTimeout) {
  1664. var timer = null;
  1665. var callback = function() {
  1666. timer = null;
  1667. fcn();
  1668. };
  1669. var _self = function(timeout) {
  1670. if (timer == null)
  1671. timer = setTimeout(callback, timeout || defaultTimeout);
  1672. };
  1673. _self.delay = function(timeout) {
  1674. timer && clearTimeout(timer);
  1675. timer = setTimeout(callback, timeout || defaultTimeout);
  1676. };
  1677. _self.schedule = _self;
  1678. _self.call = function() {
  1679. this.cancel();
  1680. fcn();
  1681. };
  1682. _self.cancel = function() {
  1683. timer && clearTimeout(timer);
  1684. timer = null;
  1685. };
  1686. _self.isPending = function() {
  1687. return timer;
  1688. };
  1689. return _self;
  1690. };
  1691. });
  1692. define("ace/keyboard/textinput_ios",["require","exports","module","ace/lib/event","ace/lib/useragent","ace/lib/dom","ace/lib/lang","ace/lib/keys"], function(require, exports, module) {
  1693. "use strict";
  1694. var event = require("../lib/event");
  1695. var useragent = require("../lib/useragent");
  1696. var dom = require("../lib/dom");
  1697. var lang = require("../lib/lang");
  1698. var KEYS = require("../lib/keys");
  1699. var MODS = KEYS.KEY_MODS;
  1700. var BROKEN_SETDATA = useragent.isChrome < 18;
  1701. var USE_IE_MIME_TYPE = useragent.isIE;
  1702. var TextInput = function(parentNode, host) {
  1703. var self = this;
  1704. var text = dom.createElement("textarea");
  1705. text.className = useragent.isIOS ? "ace_text-input ace_text-input-ios" : "ace_text-input";
  1706. if (useragent.isTouchPad)
  1707. text.setAttribute("x-palm-disable-auto-cap", true);
  1708. text.setAttribute("wrap", "off");
  1709. text.setAttribute("autocorrect", "off");
  1710. text.setAttribute("autocapitalize", "off");
  1711. text.setAttribute("spellcheck", false);
  1712. text.style.opacity = "0";
  1713. parentNode.insertBefore(text, parentNode.firstChild);
  1714. var PLACEHOLDER = "\n aaaa a\n";
  1715. var copied = false;
  1716. var cut = false;
  1717. var pasted = false;
  1718. var inComposition = false;
  1719. var tempStyle = '';
  1720. var isSelectionEmpty = true;
  1721. try { var isFocused = document.activeElement === text; } catch(e) {}
  1722. event.addListener(text, "blur", function(e) {
  1723. host.onBlur(e);
  1724. isFocused = false;
  1725. });
  1726. event.addListener(text, "focus", function(e) {
  1727. isFocused = true;
  1728. host.onFocus(e);
  1729. resetSelection();
  1730. });
  1731. this.focus = function() {
  1732. if (tempStyle) return text.focus();
  1733. text.style.position = "fixed";
  1734. text.focus();
  1735. };
  1736. this.blur = function() {
  1737. text.blur();
  1738. };
  1739. this.isFocused = function() {
  1740. return isFocused;
  1741. };
  1742. var syncSelection = lang.delayedCall(function() {
  1743. isFocused && resetSelection(isSelectionEmpty);
  1744. });
  1745. var syncValue = lang.delayedCall(function() {
  1746. if (!inComposition) {
  1747. text.value = PLACEHOLDER;
  1748. isFocused && resetSelection();
  1749. }
  1750. });
  1751. function resetSelection(isEmpty) {
  1752. if (inComposition)
  1753. return;
  1754. inComposition = true;
  1755. if (inputHandler) {
  1756. selectionStart = 0;
  1757. selectionEnd = isEmpty ? 0 : text.value.length - 1;
  1758. } else {
  1759. var selectionStart = 4;
  1760. var selectionEnd = 5;
  1761. }
  1762. try {
  1763. text.setSelectionRange(selectionStart, selectionEnd);
  1764. } catch(e) {}
  1765. inComposition = false;
  1766. }
  1767. function resetValue() {
  1768. if (inComposition)
  1769. return;
  1770. text.value = PLACEHOLDER;
  1771. if (useragent.isWebKit)
  1772. syncValue.schedule();
  1773. }
  1774. useragent.isWebKit || host.addEventListener('changeSelection', function() {
  1775. if (host.selection.isEmpty() != isSelectionEmpty) {
  1776. isSelectionEmpty = !isSelectionEmpty;
  1777. syncSelection.schedule();
  1778. }
  1779. });
  1780. resetValue();
  1781. if (isFocused)
  1782. host.onFocus();
  1783. var isAllSelected = function(text) {
  1784. return text.selectionStart === 0 && text.selectionEnd === text.value.length;
  1785. };
  1786. var onSelect = function(e) {
  1787. if (isAllSelected(text)) {
  1788. host.selectAll();
  1789. resetSelection();
  1790. } else if (inputHandler) {
  1791. resetSelection(host.selection.isEmpty());
  1792. }
  1793. };
  1794. var inputHandler = null;
  1795. this.setInputHandler = function(cb) {inputHandler = cb};
  1796. this.getInputHandler = function() {return inputHandler};
  1797. var afterContextMenu = false;
  1798. var sendText = function(data) {
  1799. if (text.selectionStart === 4 && text.selectionEnd === 5) {
  1800. return;
  1801. }
  1802. if (inputHandler) {
  1803. data = inputHandler(data);
  1804. inputHandler = null;
  1805. }
  1806. if (pasted) {
  1807. resetSelection();
  1808. if (data)
  1809. host.onPaste(data);
  1810. pasted = false;
  1811. } else if (data == PLACEHOLDER.substr(0) && text.selectionStart === 4) {
  1812. if (afterContextMenu)
  1813. host.execCommand("del", {source: "ace"});
  1814. else // some versions of android do not fire keydown when pressing backspace
  1815. host.execCommand("backspace", {source: "ace"});
  1816. } else if (!copied) {
  1817. if (data.substring(0, 9) == PLACEHOLDER && data.length > PLACEHOLDER.length)
  1818. data = data.substr(9);
  1819. else if (data.substr(0, 4) == PLACEHOLDER.substr(0, 4))
  1820. data = data.substr(4, data.length - PLACEHOLDER.length + 1);
  1821. else if (data.charAt(data.length - 1) == PLACEHOLDER.charAt(0))
  1822. data = data.slice(0, -1);
  1823. if (data == PLACEHOLDER.charAt(0)) {
  1824. } else if (data.charAt(data.length - 1) == PLACEHOLDER.charAt(0))
  1825. data = data.slice(0, -1);
  1826. if (data)
  1827. host.onTextInput(data);
  1828. }
  1829. if (copied) {
  1830. copied = false;
  1831. }
  1832. if (afterContextMenu)
  1833. afterContextMenu = false;
  1834. };
  1835. var onInput = function(e) {
  1836. if (inComposition)
  1837. return;
  1838. var data = text.value;
  1839. sendText(data);
  1840. resetValue();
  1841. };
  1842. var handleClipboardData = function(e, data, forceIEMime) {
  1843. var clipboardData = e.clipboardData || window.clipboardData;
  1844. if (!clipboardData || BROKEN_SETDATA)
  1845. return;
  1846. var mime = USE_IE_MIME_TYPE || forceIEMime ? "Text" : "text/plain";
  1847. try {
  1848. if (data) {
  1849. return clipboardData.setData(mime, data) !== false;
  1850. } else {
  1851. return clipboardData.getData(mime);
  1852. }
  1853. } catch(e) {
  1854. if (!forceIEMime)
  1855. return handleClipboardData(e, data, true);
  1856. }
  1857. };
  1858. var doCopy = function(e, isCut) {
  1859. var data = host.getCopyText();
  1860. if (!data)
  1861. return event.preventDefault(e);
  1862. if (handleClipboardData(e, data)) {
  1863. if (useragent.isIOS) {
  1864. cut = isCut;
  1865. text.value = "\n aa" + data + "a a\n";
  1866. text.setSelectionRange(4, 4 + data.length);
  1867. copied = {
  1868. value: data
  1869. };
  1870. }
  1871. isCut ? host.onCut() : host.onCopy();
  1872. if (!useragent.isIOS) event.preventDefault(e);
  1873. } else {
  1874. copied = true;
  1875. text.value = data;
  1876. text.select();
  1877. setTimeout(function(){
  1878. copied = false;
  1879. resetValue();
  1880. resetSelection();
  1881. isCut ? host.onCut() : host.onCopy();
  1882. });
  1883. }
  1884. };
  1885. var onCut = function(e) {
  1886. doCopy(e, true);
  1887. };
  1888. var onCopy = function(e) {
  1889. doCopy(e, false);
  1890. };
  1891. var onPaste = function(e) {
  1892. var data = handleClipboardData(e);
  1893. if (typeof data == "string") {
  1894. if (data)
  1895. host.onPaste(data, e);
  1896. if (useragent.isIE)
  1897. setTimeout(resetSelection);
  1898. event.preventDefault(e);
  1899. }
  1900. else {
  1901. text.value = "";
  1902. pasted = true;
  1903. }
  1904. };
  1905. event.addCommandKeyListener(text, host.onCommandKey.bind(host));
  1906. event.addListener(text, "select", onSelect);
  1907. event.addListener(text, "input", onInput);
  1908. event.addListener(text, "cut", onCut);
  1909. event.addListener(text, "copy", onCopy);
  1910. event.addListener(text, "paste", onPaste);
  1911. var onCompositionStart = function(e) {
  1912. if (inComposition || !host.onCompositionStart || host.$readOnly)
  1913. return;
  1914. inComposition = {};
  1915. inComposition.canUndo = host.session.$undoManager;
  1916. host.onCompositionStart();
  1917. setTimeout(onCompositionUpdate, 0);
  1918. host.on("mousedown", onCompositionEnd);
  1919. if (inComposition.canUndo && !host.selection.isEmpty()) {
  1920. host.insert("");
  1921. host.session.markUndoGroup();
  1922. host.selection.clearSelection();
  1923. }
  1924. host.session.markUndoGroup();
  1925. };
  1926. var onCompositionUpdate = function() {
  1927. if (!inComposition || !host.onCompositionUpdate || host.$readOnly)
  1928. return;
  1929. var val = text.value.replace(/\x01/g, "");
  1930. if (inComposition.lastValue === val) return;
  1931. host.onCompositionUpdate(val);
  1932. if (inComposition.lastValue)
  1933. host.undo();
  1934. if (inComposition.canUndo)
  1935. inComposition.lastValue = val;
  1936. if (inComposition.lastValue) {
  1937. var r = host.selection.getRange();
  1938. host.insert(inComposition.lastValue);
  1939. host.session.markUndoGroup();
  1940. inComposition.range = host.selection.getRange();
  1941. host.selection.setRange(r);
  1942. host.selection.clearSelection();
  1943. }
  1944. };
  1945. var onCompositionEnd = function(e) {
  1946. if (!host.onCompositionEnd || host.$readOnly) return;
  1947. var c = inComposition;
  1948. inComposition = false;
  1949. var timer = setTimeout(function() {
  1950. timer = null;
  1951. var str = text.value.replace(/\x01/g, "");
  1952. if (inComposition)
  1953. return;
  1954. else if (str == c.lastValue)
  1955. resetValue();
  1956. else if (!c.lastValue && str) {
  1957. resetValue();
  1958. sendText(str);
  1959. }
  1960. });
  1961. inputHandler = function compositionInputHandler(str) {
  1962. if (timer)
  1963. clearTimeout(timer);
  1964. str = str.replace(/\x01/g, "");
  1965. if (str == c.lastValue)
  1966. return "";
  1967. if (c.lastValue && timer)
  1968. host.undo();
  1969. return str;
  1970. };
  1971. host.onCompositionEnd();
  1972. host.removeListener("mousedown", onCompositionEnd);
  1973. if (e.type == "compositionend" && c.range) {
  1974. host.selection.setRange(c.range);
  1975. }
  1976. var needsOnInput =
  1977. (!!useragent.isChrome && useragent.isChrome >= 53) ||
  1978. (!!useragent.isWebKit && useragent.isWebKit >= 603);
  1979. if (needsOnInput) {
  1980. onInput();
  1981. }
  1982. };
  1983. var syncComposition = lang.delayedCall(onCompositionUpdate, 50);
  1984. event.addListener(text, "compositionstart", onCompositionStart);
  1985. if (useragent.isGecko) {
  1986. event.addListener(text, "text", function(){syncComposition.schedule()});
  1987. } else {
  1988. event.addListener(text, "keyup", function(){syncComposition.schedule()});
  1989. event.addListener(text, "keydown", function(){syncComposition.schedule()});
  1990. }
  1991. event.addListener(text, "compositionend", onCompositionEnd);
  1992. this.getElement = function() {
  1993. return text;
  1994. };
  1995. this.setReadOnly = function(readOnly) {
  1996. text.readOnly = readOnly;
  1997. };
  1998. this.onContextMenu = function(e) {
  1999. afterContextMenu = true;
  2000. resetSelection(host.selection.isEmpty());
  2001. host._emit("nativecontextmenu", {target: host, domEvent: e});
  2002. this.moveToMouse(e, true);
  2003. };
  2004. this.moveToMouse = function(e, bringToFront) {
  2005. if (!tempStyle)
  2006. tempStyle = text.style.cssText;
  2007. text.style.cssText = (bringToFront ? "z-index:100000;" : "")
  2008. + "height:" + text.style.height + ";"
  2009. + (useragent.isIE ? "opacity:0.1;" : "");
  2010. var rect = host.container.getBoundingClientRect();
  2011. var style = dom.computedStyle(host.container);
  2012. var top = rect.top + (parseInt(style.borderTopWidth) || 0);
  2013. var left = rect.left + (parseInt(rect.borderLeftWidth) || 0);
  2014. var maxTop = rect.bottom - top - text.clientHeight -2;
  2015. var move = function(e) {
  2016. text.style.left = e.clientX - left - 2 + "px";
  2017. text.style.top = Math.min(e.clientY - top - 2, maxTop) + "px";
  2018. };
  2019. move(e);
  2020. if (e.type != "mousedown")
  2021. return;
  2022. if (host.renderer.$keepTextAreaAtCursor)
  2023. host.renderer.$keepTextAreaAtCursor = null;
  2024. clearTimeout(closeTimeout);
  2025. if (useragent.isWin)
  2026. event.capture(host.container, move, onContextMenuClose);
  2027. };
  2028. this.onContextMenuClose = onContextMenuClose;
  2029. var closeTimeout;
  2030. function onContextMenuClose() {
  2031. clearTimeout(closeTimeout);
  2032. closeTimeout = setTimeout(function () {
  2033. if (tempStyle) {
  2034. text.style.cssText = tempStyle;
  2035. tempStyle = '';
  2036. }
  2037. if (host.renderer.$keepTextAreaAtCursor == null) {
  2038. host.renderer.$keepTextAreaAtCursor = true;
  2039. host.renderer.$moveTextAreaToCursor();
  2040. }
  2041. }, 0);
  2042. }
  2043. var onContextMenu = function(e) {
  2044. host.textInput.onContextMenu(e);
  2045. onContextMenuClose();
  2046. };
  2047. event.addListener(text, "mouseup", onContextMenu);
  2048. event.addListener(text, "mousedown", function(e) {
  2049. e.preventDefault();
  2050. onContextMenuClose();
  2051. });
  2052. event.addListener(host.renderer.scroller, "contextmenu", onContextMenu);
  2053. event.addListener(text, "contextmenu", onContextMenu);
  2054. if (useragent.isIOS) {
  2055. var typingResetTimeout = null;
  2056. var typing = false;
  2057. parentNode.addEventListener("keydown", function (e) {
  2058. if (typingResetTimeout) clearTimeout(typingResetTimeout);
  2059. typing = true;
  2060. });
  2061. parentNode.addEventListener("keyup", function (e) {
  2062. typingResetTimeout = setTimeout(function () {
  2063. typing = false;
  2064. }, 100);
  2065. });
  2066. var detectArrowKeys = function(e) {
  2067. if (document.activeElement !== text) return;
  2068. if (typing) return;
  2069. if (cut) {
  2070. return setTimeout(function () {
  2071. cut = false;
  2072. }, 100);
  2073. }
  2074. var selectionStart = text.selectionStart;
  2075. var selectionEnd = text.selectionEnd;
  2076. text.setSelectionRange(4, 5);
  2077. if (selectionStart == selectionEnd) {
  2078. switch (selectionStart) {
  2079. case 0: host.onCommandKey(null, 0, KEYS.up); break;
  2080. case 1: host.onCommandKey(null, 0, KEYS.home); break;
  2081. case 2: host.onCommandKey(null, MODS.option, KEYS.left); break;
  2082. case 4: host.onCommandKey(null, 0, KEYS.left); break;
  2083. case 5: host.onCommandKey(null, 0, KEYS.right); break;
  2084. case 7: host.onCommandKey(null, MODS.option, KEYS.right); break;
  2085. case 8: host.onCommandKey(null, 0, KEYS.end); break;
  2086. case 9: host.onCommandKey(null, 0, KEYS.down); break;
  2087. }
  2088. } else {
  2089. switch (selectionEnd) {
  2090. case 6: host.onCommandKey(null, MODS.shift, KEYS.right); break;
  2091. case 7: host.onCommandKey(null, MODS.shift | MODS.option, KEYS.right); break;
  2092. case 8: host.onCommandKey(null, MODS.shift, KEYS.end); break;
  2093. case 9: host.onCommandKey(null, MODS.shift, KEYS.down); break;
  2094. }
  2095. switch (selectionStart) {
  2096. case 0: host.onCommandKey(null, MODS.shift, KEYS.up); break;
  2097. case 1: host.onCommandKey(null, MODS.shift, KEYS.home); break;
  2098. case 2: host.onCommandKey(null, MODS.shift | MODS.option, KEYS.left); break;
  2099. case 3: host.onCommandKey(null, MODS.shift, KEYS.left); break;
  2100. }
  2101. }
  2102. }
  2103. document.addEventListener("selectionchange", detectArrowKeys);
  2104. host.on("destroy", function() {
  2105. document.removeEventListener("selectionchange", detectArrowKeys);
  2106. })
  2107. }
  2108. };
  2109. exports.TextInput = TextInput;
  2110. });
  2111. define("ace/keyboard/textinput",["require","exports","module","ace/lib/event","ace/lib/useragent","ace/lib/dom","ace/lib/lang","ace/keyboard/textinput_ios"], function(require, exports, module) {
  2112. "use strict";
  2113. var event = require("../lib/event");
  2114. var useragent = require("../lib/useragent");
  2115. var dom = require("../lib/dom");
  2116. var lang = require("../lib/lang");
  2117. var BROKEN_SETDATA = useragent.isChrome < 18;
  2118. var USE_IE_MIME_TYPE = useragent.isIE;
  2119. var TextInputIOS = require("./textinput_ios").TextInput
  2120. var TextInput = function(parentNode, host) {
  2121. if (useragent.isIOS)
  2122. return TextInputIOS.call(this, parentNode, host);
  2123. var text = dom.createElement("textarea");
  2124. text.className = "ace_text-input";
  2125. text.setAttribute("wrap", "off");
  2126. text.setAttribute("autocorrect", "off");
  2127. text.setAttribute("autocapitalize", "off");
  2128. text.setAttribute("spellcheck", false);
  2129. text.style.opacity = "0";
  2130. parentNode.insertBefore(text, parentNode.firstChild);
  2131. var PLACEHOLDER = "\u2028\u2028";
  2132. var copied = false;
  2133. var pasted = false;
  2134. var inComposition = false;
  2135. var tempStyle = '';
  2136. var isSelectionEmpty = true;
  2137. try { var isFocused = document.activeElement === text; } catch(e) {}
  2138. event.addListener(text, "blur", function(e) {
  2139. host.onBlur(e);
  2140. isFocused = false;
  2141. });
  2142. event.addListener(text, "focus", function(e) {
  2143. isFocused = true;
  2144. host.onFocus(e);
  2145. resetSelection();
  2146. });
  2147. this.focus = function() {
  2148. if (tempStyle) return text.focus();
  2149. var top = text.style.top;
  2150. text.style.position = "fixed";
  2151. text.style.top = "0px";
  2152. text.focus();
  2153. setTimeout(function() {
  2154. text.style.position = "";
  2155. if (text.style.top == "0px")
  2156. text.style.top = top;
  2157. }, 0);
  2158. };
  2159. this.blur = function() {
  2160. text.blur();
  2161. };
  2162. this.isFocused = function() {
  2163. return isFocused;
  2164. };
  2165. var syncSelection = lang.delayedCall(function() {
  2166. isFocused && resetSelection(isSelectionEmpty);
  2167. });
  2168. var syncValue = lang.delayedCall(function() {
  2169. if (!inComposition) {
  2170. text.value = PLACEHOLDER;
  2171. isFocused && resetSelection();
  2172. }
  2173. });
  2174. function resetSelection(isEmpty) {
  2175. if (inComposition)
  2176. return;
  2177. inComposition = true;
  2178. if (inputHandler) {
  2179. selectionStart = 0;
  2180. selectionEnd = isEmpty ? 0 : text.value.length - 1;
  2181. } else {
  2182. var selectionStart = isEmpty ? 2 : 1;
  2183. var selectionEnd = 2;
  2184. }
  2185. try {
  2186. text.setSelectionRange(selectionStart, selectionEnd);
  2187. } catch(e){}
  2188. inComposition = false;
  2189. }
  2190. function resetValue() {
  2191. if (inComposition)
  2192. return;
  2193. text.value = PLACEHOLDER;
  2194. if (useragent.isWebKit)
  2195. syncValue.schedule();
  2196. }
  2197. useragent.isWebKit || host.addEventListener('changeSelection', function() {
  2198. if (host.selection.isEmpty() != isSelectionEmpty) {
  2199. isSelectionEmpty = !isSelectionEmpty;
  2200. syncSelection.schedule();
  2201. }
  2202. });
  2203. resetValue();
  2204. if (isFocused)
  2205. host.onFocus();
  2206. var isAllSelected = function(text) {
  2207. return text.selectionStart === 0 && text.selectionEnd === text.value.length;
  2208. };
  2209. var onSelect = function(e) {
  2210. if (copied) {
  2211. copied = false;
  2212. } else if (isAllSelected(text)) {
  2213. host.selectAll();
  2214. resetSelection();
  2215. } else if (inputHandler) {
  2216. resetSelection(host.selection.isEmpty());
  2217. }
  2218. };
  2219. var inputHandler = null;
  2220. this.setInputHandler = function(cb) {inputHandler = cb};
  2221. this.getInputHandler = function() {return inputHandler};
  2222. var afterContextMenu = false;
  2223. var sendText = function(data) {
  2224. if (inputHandler) {
  2225. data = inputHandler(data);
  2226. inputHandler = null;
  2227. }
  2228. if (pasted) {
  2229. resetSelection();
  2230. if (data)
  2231. host.onPaste(data);
  2232. pasted = false;
  2233. } else if (data == PLACEHOLDER.charAt(0)) {
  2234. if (afterContextMenu)
  2235. host.execCommand("del", {source: "ace"});
  2236. else // some versions of android do not fire keydown when pressing backspace
  2237. host.execCommand("backspace", {source: "ace"});
  2238. } else {
  2239. if (data.substring(0, 2) == PLACEHOLDER)
  2240. data = data.substr(2);
  2241. else if (data.charAt(0) == PLACEHOLDER.charAt(0))
  2242. data = data.substr(1);
  2243. else if (data.charAt(data.length - 1) == PLACEHOLDER.charAt(0))
  2244. data = data.slice(0, -1);
  2245. if (data.charAt(data.length - 1) == PLACEHOLDER.charAt(0))
  2246. data = data.slice(0, -1);
  2247. if (data)
  2248. host.onTextInput(data);
  2249. }
  2250. if (afterContextMenu)
  2251. afterContextMenu = false;
  2252. };
  2253. var onInput = function(e) {
  2254. if (inComposition)
  2255. return;
  2256. var data = text.value;
  2257. sendText(data);
  2258. resetValue();
  2259. };
  2260. var handleClipboardData = function(e, data, forceIEMime) {
  2261. var clipboardData = e.clipboardData || window.clipboardData;
  2262. if (!clipboardData || BROKEN_SETDATA)
  2263. return;
  2264. var mime = USE_IE_MIME_TYPE || forceIEMime ? "Text" : "text/plain";
  2265. try {
  2266. if (data) {
  2267. return clipboardData.setData(mime, data) !== false;
  2268. } else {
  2269. return clipboardData.getData(mime);
  2270. }
  2271. } catch(e) {
  2272. if (!forceIEMime)
  2273. return handleClipboardData(e, data, true);
  2274. }
  2275. };
  2276. var doCopy = function(e, isCut) {
  2277. var data = host.getCopyText();
  2278. if (!data)
  2279. return event.preventDefault(e);
  2280. if (handleClipboardData(e, data)) {
  2281. isCut ? host.onCut() : host.onCopy();
  2282. event.preventDefault(e);
  2283. } else {
  2284. copied = true;
  2285. text.value = data;
  2286. text.select();
  2287. setTimeout(function(){
  2288. copied = false;
  2289. resetValue();
  2290. resetSelection();
  2291. isCut ? host.onCut() : host.onCopy();
  2292. });
  2293. }
  2294. };
  2295. var onCut = function(e) {
  2296. doCopy(e, true);
  2297. };
  2298. var onCopy = function(e) {
  2299. doCopy(e, false);
  2300. };
  2301. var onPaste = function(e) {
  2302. var data = handleClipboardData(e);
  2303. if (typeof data == "string") {
  2304. if (data)
  2305. host.onPaste(data, e);
  2306. if (useragent.isIE)
  2307. setTimeout(resetSelection);
  2308. event.preventDefault(e);
  2309. }
  2310. else {
  2311. text.value = "";
  2312. pasted = true;
  2313. }
  2314. };
  2315. event.addCommandKeyListener(text, host.onCommandKey.bind(host));
  2316. event.addListener(text, "select", onSelect);
  2317. event.addListener(text, "input", onInput);
  2318. event.addListener(text, "cut", onCut);
  2319. event.addListener(text, "copy", onCopy);
  2320. event.addListener(text, "paste", onPaste);
  2321. if (!('oncut' in text) || !('oncopy' in text) || !('onpaste' in text)) {
  2322. event.addListener(parentNode, "keydown", function(e) {
  2323. if ((useragent.isMac && !e.metaKey) || !e.ctrlKey)
  2324. return;
  2325. switch (e.keyCode) {
  2326. case 67:
  2327. onCopy(e);
  2328. break;
  2329. case 86:
  2330. onPaste(e);
  2331. break;
  2332. case 88:
  2333. onCut(e);
  2334. break;
  2335. }
  2336. });
  2337. }
  2338. var onCompositionStart = function(e) {
  2339. if (inComposition || !host.onCompositionStart || host.$readOnly)
  2340. return;
  2341. inComposition = {};
  2342. inComposition.canUndo = host.session.$undoManager;
  2343. host.onCompositionStart();
  2344. setTimeout(onCompositionUpdate, 0);
  2345. host.on("mousedown", onCompositionEnd);
  2346. if (inComposition.canUndo && !host.selection.isEmpty()) {
  2347. host.insert("");
  2348. host.session.markUndoGroup();
  2349. host.selection.clearSelection();
  2350. }
  2351. host.session.markUndoGroup();
  2352. };
  2353. var onCompositionUpdate = function() {
  2354. if (!inComposition || !host.onCompositionUpdate || host.$readOnly)
  2355. return;
  2356. var val = text.value.replace(/\u2028/g, "");
  2357. if (inComposition.lastValue === val) return;
  2358. host.onCompositionUpdate(val);
  2359. if (inComposition.lastValue)
  2360. host.undo();
  2361. if (inComposition.canUndo)
  2362. inComposition.lastValue = val;
  2363. if (inComposition.lastValue) {
  2364. var r = host.selection.getRange();
  2365. host.insert(inComposition.lastValue);
  2366. host.session.markUndoGroup();
  2367. inComposition.range = host.selection.getRange();
  2368. host.selection.setRange(r);
  2369. host.selection.clearSelection();
  2370. }
  2371. };
  2372. var onCompositionEnd = function(e) {
  2373. if (!host.onCompositionEnd || host.$readOnly) return;
  2374. var c = inComposition;
  2375. inComposition = false;
  2376. var timer = setTimeout(function() {
  2377. timer = null;
  2378. var str = text.value.replace(/\u2028/g, "");
  2379. if (inComposition)
  2380. return;
  2381. else if (str == c.lastValue)
  2382. resetValue();
  2383. else if (!c.lastValue && str) {
  2384. resetValue();
  2385. sendText(str);
  2386. }
  2387. });
  2388. inputHandler = function compositionInputHandler(str) {
  2389. if (timer)
  2390. clearTimeout(timer);
  2391. str = str.replace(/\u2028/g, "");
  2392. if (str == c.lastValue)
  2393. return "";
  2394. if (c.lastValue && timer)
  2395. host.undo();
  2396. return str;
  2397. };
  2398. host.onCompositionEnd();
  2399. host.removeListener("mousedown", onCompositionEnd);
  2400. if (e.type == "compositionend" && c.range) {
  2401. host.selection.setRange(c.range);
  2402. }
  2403. var needsOnInput =
  2404. (!!useragent.isChrome && useragent.isChrome >= 53) ||
  2405. (!!useragent.isWebKit && useragent.isWebKit >= 603);
  2406. if (needsOnInput) {
  2407. onInput();
  2408. }
  2409. };
  2410. var syncComposition = lang.delayedCall(onCompositionUpdate, 50);
  2411. event.addListener(text, "compositionstart", onCompositionStart);
  2412. if (useragent.isGecko) {
  2413. event.addListener(text, "text", function(){syncComposition.schedule()});
  2414. } else {
  2415. event.addListener(text, "keyup", function(){syncComposition.schedule()});
  2416. event.addListener(text, "keydown", function(){syncComposition.schedule()});
  2417. }
  2418. event.addListener(text, "compositionend", onCompositionEnd);
  2419. this.getElement = function() {
  2420. return text;
  2421. };
  2422. this.setReadOnly = function(readOnly) {
  2423. text.readOnly = readOnly;
  2424. };
  2425. this.onContextMenu = function(e) {
  2426. afterContextMenu = true;
  2427. resetSelection(host.selection.isEmpty());
  2428. host._emit("nativecontextmenu", {target: host, domEvent: e});
  2429. this.moveToMouse(e, true);
  2430. };
  2431. this.moveToMouse = function(e, bringToFront) {
  2432. if (!tempStyle)
  2433. tempStyle = text.style.cssText;
  2434. text.style.cssText = (bringToFront ? "z-index:100000;" : "")
  2435. + "height:" + text.style.height + ";"
  2436. + (useragent.isIE ? "opacity:0.1;" : "");
  2437. var rect = host.container.getBoundingClientRect();
  2438. var style = dom.computedStyle(host.container);
  2439. var top = rect.top + (parseInt(style.borderTopWidth) || 0);
  2440. var left = rect.left + (parseInt(rect.borderLeftWidth) || 0);
  2441. var maxTop = rect.bottom - top - text.clientHeight -2;
  2442. var move = function(e) {
  2443. text.style.left = e.clientX - left - 2 + "px";
  2444. text.style.top = Math.min(e.clientY - top - 2, maxTop) + "px";
  2445. };
  2446. move(e);
  2447. if (e.type != "mousedown")
  2448. return;
  2449. if (host.renderer.$keepTextAreaAtCursor)
  2450. host.renderer.$keepTextAreaAtCursor = null;
  2451. clearTimeout(closeTimeout);
  2452. if (useragent.isWin)
  2453. event.capture(host.container, move, onContextMenuClose);
  2454. };
  2455. this.onContextMenuClose = onContextMenuClose;
  2456. var closeTimeout;
  2457. function onContextMenuClose() {
  2458. clearTimeout(closeTimeout);
  2459. closeTimeout = setTimeout(function () {
  2460. if (tempStyle) {
  2461. text.style.cssText = tempStyle;
  2462. tempStyle = '';
  2463. }
  2464. if (host.renderer.$keepTextAreaAtCursor == null) {
  2465. host.renderer.$keepTextAreaAtCursor = true;
  2466. host.renderer.$moveTextAreaToCursor();
  2467. }
  2468. }, 0);
  2469. }
  2470. var onContextMenu = function(e) {
  2471. host.textInput.onContextMenu(e);
  2472. onContextMenuClose();
  2473. };
  2474. event.addListener(text, "mouseup", onContextMenu);
  2475. event.addListener(text, "mousedown", function(e) {
  2476. e.preventDefault();
  2477. onContextMenuClose();
  2478. });
  2479. event.addListener(host.renderer.scroller, "contextmenu", onContextMenu);
  2480. event.addListener(text, "contextmenu", onContextMenu);
  2481. };
  2482. exports.TextInput = TextInput;
  2483. });
  2484. define("ace/mouse/default_handlers",["require","exports","module","ace/lib/dom","ace/lib/event","ace/lib/useragent"], function(require, exports, module) {
  2485. "use strict";
  2486. var dom = require("../lib/dom");
  2487. var event = require("../lib/event");
  2488. var useragent = require("../lib/useragent");
  2489. var DRAG_OFFSET = 0; // pixels
  2490. function DefaultHandlers(mouseHandler) {
  2491. mouseHandler.$clickSelection = null;
  2492. var editor = mouseHandler.editor;
  2493. editor.setDefaultHandler("mousedown", this.onMouseDown.bind(mouseHandler));
  2494. editor.setDefaultHandler("dblclick", this.onDoubleClick.bind(mouseHandler));
  2495. editor.setDefaultHandler("tripleclick", this.onTripleClick.bind(mouseHandler));
  2496. editor.setDefaultHandler("quadclick", this.onQuadClick.bind(mouseHandler));
  2497. editor.setDefaultHandler("mousewheel", this.onMouseWheel.bind(mouseHandler));
  2498. editor.setDefaultHandler("touchmove", this.onTouchMove.bind(mouseHandler));
  2499. var exports = ["select", "startSelect", "selectEnd", "selectAllEnd", "selectByWordsEnd",
  2500. "selectByLinesEnd", "dragWait", "dragWaitEnd", "focusWait"];
  2501. exports.forEach(function(x) {
  2502. mouseHandler[x] = this[x];
  2503. }, this);
  2504. mouseHandler.selectByLines = this.extendSelectionBy.bind(mouseHandler, "getLineRange");
  2505. mouseHandler.selectByWords = this.extendSelectionBy.bind(mouseHandler, "getWordRange");
  2506. }
  2507. (function() {
  2508. this.onMouseDown = function(ev) {
  2509. var inSelection = ev.inSelection();
  2510. var pos = ev.getDocumentPosition();
  2511. this.mousedownEvent = ev;
  2512. var editor = this.editor;
  2513. var button = ev.getButton();
  2514. if (button !== 0) {
  2515. var selectionRange = editor.getSelectionRange();
  2516. var selectionEmpty = selectionRange.isEmpty();
  2517. editor.$blockScrolling++;
  2518. if (selectionEmpty || button == 1)
  2519. editor.selection.moveToPosition(pos);
  2520. editor.$blockScrolling--;
  2521. if (button == 2) {
  2522. editor.textInput.onContextMenu(ev.domEvent);
  2523. if (!useragent.isMozilla)
  2524. ev.preventDefault();
  2525. }
  2526. return;
  2527. }
  2528. this.mousedownEvent.time = Date.now();
  2529. if (inSelection && !editor.isFocused()) {
  2530. editor.focus();
  2531. if (this.$focusTimout && !this.$clickSelection && !editor.inMultiSelectMode) {
  2532. this.setState("focusWait");
  2533. this.captureMouse(ev);
  2534. return;
  2535. }
  2536. }
  2537. this.captureMouse(ev);
  2538. this.startSelect(pos, ev.domEvent._clicks > 1);
  2539. return ev.preventDefault();
  2540. };
  2541. this.startSelect = function(pos, waitForClickSelection) {
  2542. pos = pos || this.editor.renderer.screenToTextCoordinates(this.x, this.y);
  2543. var editor = this.editor;
  2544. editor.$blockScrolling++;
  2545. if (this.mousedownEvent.getShiftKey())
  2546. editor.selection.selectToPosition(pos);
  2547. else if (!waitForClickSelection)
  2548. editor.selection.moveToPosition(pos);
  2549. if (!waitForClickSelection)
  2550. this.select();
  2551. if (editor.renderer.scroller.setCapture) {
  2552. editor.renderer.scroller.setCapture();
  2553. }
  2554. editor.setStyle("ace_selecting");
  2555. this.setState("select");
  2556. editor.$blockScrolling--;
  2557. };
  2558. this.select = function() {
  2559. var anchor, editor = this.editor;
  2560. var cursor = editor.renderer.screenToTextCoordinates(this.x, this.y);
  2561. editor.$blockScrolling++;
  2562. if (this.$clickSelection) {
  2563. var cmp = this.$clickSelection.comparePoint(cursor);
  2564. if (cmp == -1) {
  2565. anchor = this.$clickSelection.end;
  2566. } else if (cmp == 1) {
  2567. anchor = this.$clickSelection.start;
  2568. } else {
  2569. var orientedRange = calcRangeOrientation(this.$clickSelection, cursor);
  2570. cursor = orientedRange.cursor;
  2571. anchor = orientedRange.anchor;
  2572. }
  2573. editor.selection.setSelectionAnchor(anchor.row, anchor.column);
  2574. }
  2575. editor.selection.selectToPosition(cursor);
  2576. editor.$blockScrolling--;
  2577. editor.renderer.scrollCursorIntoView();
  2578. };
  2579. this.extendSelectionBy = function(unitName) {
  2580. var anchor, editor = this.editor;
  2581. var cursor = editor.renderer.screenToTextCoordinates(this.x, this.y);
  2582. var range = editor.selection[unitName](cursor.row, cursor.column);
  2583. editor.$blockScrolling++;
  2584. if (this.$clickSelection) {
  2585. var cmpStart = this.$clickSelection.comparePoint(range.start);
  2586. var cmpEnd = this.$clickSelection.comparePoint(range.end);
  2587. if (cmpStart == -1 && cmpEnd <= 0) {
  2588. anchor = this.$clickSelection.end;
  2589. if (range.end.row != cursor.row || range.end.column != cursor.column)
  2590. cursor = range.start;
  2591. } else if (cmpEnd == 1 && cmpStart >= 0) {
  2592. anchor = this.$clickSelection.start;
  2593. if (range.start.row != cursor.row || range.start.column != cursor.column)
  2594. cursor = range.end;
  2595. } else if (cmpStart == -1 && cmpEnd == 1) {
  2596. cursor = range.end;
  2597. anchor = range.start;
  2598. } else {
  2599. var orientedRange = calcRangeOrientation(this.$clickSelection, cursor);
  2600. cursor = orientedRange.cursor;
  2601. anchor = orientedRange.anchor;
  2602. }
  2603. editor.selection.setSelectionAnchor(anchor.row, anchor.column);
  2604. }
  2605. editor.selection.selectToPosition(cursor);
  2606. editor.$blockScrolling--;
  2607. editor.renderer.scrollCursorIntoView();
  2608. };
  2609. this.selectEnd =
  2610. this.selectAllEnd =
  2611. this.selectByWordsEnd =
  2612. this.selectByLinesEnd = function() {
  2613. this.$clickSelection = null;
  2614. this.editor.unsetStyle("ace_selecting");
  2615. if (this.editor.renderer.scroller.releaseCapture) {
  2616. this.editor.renderer.scroller.releaseCapture();
  2617. }
  2618. };
  2619. this.focusWait = function() {
  2620. var distance = calcDistance(this.mousedownEvent.x, this.mousedownEvent.y, this.x, this.y);
  2621. var time = Date.now();
  2622. if (distance > DRAG_OFFSET || time - this.mousedownEvent.time > this.$focusTimout)
  2623. this.startSelect(this.mousedownEvent.getDocumentPosition());
  2624. };
  2625. this.onDoubleClick = function(ev) {
  2626. var pos = ev.getDocumentPosition();
  2627. var editor = this.editor;
  2628. var session = editor.session;
  2629. var range = session.getBracketRange(pos);
  2630. if (range) {
  2631. if (range.isEmpty()) {
  2632. range.start.column--;
  2633. range.end.column++;
  2634. }
  2635. this.setState("select");
  2636. } else {
  2637. range = editor.selection.getWordRange(pos.row, pos.column);
  2638. this.setState("selectByWords");
  2639. }
  2640. this.$clickSelection = range;
  2641. this.select();
  2642. };
  2643. this.onTripleClick = function(ev) {
  2644. var pos = ev.getDocumentPosition();
  2645. var editor = this.editor;
  2646. this.setState("selectByLines");
  2647. var range = editor.getSelectionRange();
  2648. if (range.isMultiLine() && range.contains(pos.row, pos.column)) {
  2649. this.$clickSelection = editor.selection.getLineRange(range.start.row);
  2650. this.$clickSelection.end = editor.selection.getLineRange(range.end.row).end;
  2651. } else {
  2652. this.$clickSelection = editor.selection.getLineRange(pos.row);
  2653. }
  2654. this.select();
  2655. };
  2656. this.onQuadClick = function(ev) {
  2657. var editor = this.editor;
  2658. editor.selectAll();
  2659. this.$clickSelection = editor.getSelectionRange();
  2660. this.setState("selectAll");
  2661. };
  2662. this.onMouseWheel = function(ev) {
  2663. if (ev.getAccelKey())
  2664. return;
  2665. if (ev.getShiftKey() && ev.wheelY && !ev.wheelX) {
  2666. ev.wheelX = ev.wheelY;
  2667. ev.wheelY = 0;
  2668. }
  2669. var t = ev.domEvent.timeStamp;
  2670. var dt = t - (this.$lastScrollTime||0);
  2671. var editor = this.editor;
  2672. var isScrolable = editor.renderer.isScrollableBy(ev.wheelX * ev.speed, ev.wheelY * ev.speed);
  2673. if (isScrolable || dt < 200) {
  2674. this.$lastScrollTime = t;
  2675. editor.renderer.scrollBy(ev.wheelX * ev.speed, ev.wheelY * ev.speed);
  2676. return ev.stop();
  2677. }
  2678. };
  2679. this.onTouchMove = function (ev) {
  2680. var t = ev.domEvent.timeStamp;
  2681. var dt = t - (this.$lastScrollTime || 0);
  2682. var editor = this.editor;
  2683. var isScrolable = editor.renderer.isScrollableBy(ev.wheelX * ev.speed, ev.wheelY * ev.speed);
  2684. if (isScrolable || dt < 200) {
  2685. this.$lastScrollTime = t;
  2686. editor.renderer.scrollBy(ev.wheelX * ev.speed, ev.wheelY * ev.speed);
  2687. return ev.stop();
  2688. }
  2689. };
  2690. }).call(DefaultHandlers.prototype);
  2691. exports.DefaultHandlers = DefaultHandlers;
  2692. function calcDistance(ax, ay, bx, by) {
  2693. return Math.sqrt(Math.pow(bx - ax, 2) + Math.pow(by - ay, 2));
  2694. }
  2695. function calcRangeOrientation(range, cursor) {
  2696. if (range.start.row == range.end.row)
  2697. var cmp = 2 * cursor.column - range.start.column - range.end.column;
  2698. else if (range.start.row == range.end.row - 1 && !range.start.column && !range.end.column)
  2699. var cmp = cursor.column - 4;
  2700. else
  2701. var cmp = 2 * cursor.row - range.start.row - range.end.row;
  2702. if (cmp < 0)
  2703. return {cursor: range.start, anchor: range.end};
  2704. else
  2705. return {cursor: range.end, anchor: range.start};
  2706. }
  2707. });
  2708. define("ace/tooltip",["require","exports","module","ace/lib/oop","ace/lib/dom"], function(require, exports, module) {
  2709. "use strict";
  2710. var oop = require("./lib/oop");
  2711. var dom = require("./lib/dom");
  2712. function Tooltip (parentNode) {
  2713. this.isOpen = false;
  2714. this.$element = null;
  2715. this.$parentNode = parentNode;
  2716. }
  2717. (function() {
  2718. this.$init = function() {
  2719. this.$element = dom.createElement("div");
  2720. this.$element.className = "ace_tooltip";
  2721. this.$element.style.display = "none";
  2722. this.$parentNode.appendChild(this.$element);
  2723. return this.$element;
  2724. };
  2725. this.getElement = function() {
  2726. return this.$element || this.$init();
  2727. };
  2728. this.setText = function(text) {
  2729. dom.setInnerText(this.getElement(), text);
  2730. };
  2731. this.setHtml = function(html) {
  2732. this.getElement().innerHTML = html;
  2733. };
  2734. this.setPosition = function(x, y) {
  2735. this.getElement().style.left = x + "px";
  2736. this.getElement().style.top = y + "px";
  2737. };
  2738. this.setClassName = function(className) {
  2739. dom.addCssClass(this.getElement(), className);
  2740. };
  2741. this.show = function(text, x, y) {
  2742. if (text != null)
  2743. this.setText(text);
  2744. if (x != null && y != null)
  2745. this.setPosition(x, y);
  2746. if (!this.isOpen) {
  2747. this.getElement().style.display = "block";
  2748. this.isOpen = true;
  2749. }
  2750. };
  2751. this.hide = function() {
  2752. if (this.isOpen) {
  2753. this.getElement().style.display = "none";
  2754. this.isOpen = false;
  2755. }
  2756. };
  2757. this.getHeight = function() {
  2758. return this.getElement().offsetHeight;
  2759. };
  2760. this.getWidth = function() {
  2761. return this.getElement().offsetWidth;
  2762. };
  2763. this.destroy = function() {
  2764. this.isOpen = false;
  2765. if (this.$element && this.$element.parentNode) {
  2766. this.$element.parentNode.removeChild(this.$element);
  2767. }
  2768. };
  2769. }).call(Tooltip.prototype);
  2770. exports.Tooltip = Tooltip;
  2771. });
  2772. define("ace/mouse/default_gutter_handler",["require","exports","module","ace/lib/dom","ace/lib/oop","ace/lib/event","ace/tooltip"], function(require, exports, module) {
  2773. "use strict";
  2774. var dom = require("../lib/dom");
  2775. var oop = require("../lib/oop");
  2776. var event = require("../lib/event");
  2777. var Tooltip = require("../tooltip").Tooltip;
  2778. function GutterHandler(mouseHandler) {
  2779. var editor = mouseHandler.editor;
  2780. var gutter = editor.renderer.$gutterLayer;
  2781. var tooltip = new GutterTooltip(editor.container);
  2782. mouseHandler.editor.setDefaultHandler("guttermousedown", function(e) {
  2783. if (!editor.isFocused() || e.getButton() != 0)
  2784. return;
  2785. var gutterRegion = gutter.getRegion(e);
  2786. if (gutterRegion == "foldWidgets")
  2787. return;
  2788. var row = e.getDocumentPosition().row;
  2789. var selection = editor.session.selection;
  2790. if (e.getShiftKey())
  2791. selection.selectTo(row, 0);
  2792. else {
  2793. if (e.domEvent.detail == 2) {
  2794. editor.selectAll();
  2795. return e.preventDefault();
  2796. }
  2797. mouseHandler.$clickSelection = editor.selection.getLineRange(row);
  2798. }
  2799. mouseHandler.setState("selectByLines");
  2800. mouseHandler.captureMouse(e);
  2801. return e.preventDefault();
  2802. });
  2803. var tooltipTimeout, mouseEvent, tooltipAnnotation;
  2804. function showTooltip() {
  2805. var row = mouseEvent.getDocumentPosition().row;
  2806. var annotation = gutter.$annotations[row];
  2807. if (!annotation)
  2808. return hideTooltip();
  2809. var maxRow = editor.session.getLength();
  2810. if (row == maxRow) {
  2811. var screenRow = editor.renderer.pixelToScreenCoordinates(0, mouseEvent.y).row;
  2812. var pos = mouseEvent.$pos;
  2813. if (screenRow > editor.session.documentToScreenRow(pos.row, pos.column))
  2814. return hideTooltip();
  2815. }
  2816. if (tooltipAnnotation == annotation)
  2817. return;
  2818. tooltipAnnotation = annotation.text.join("<br/>");
  2819. tooltip.setHtml(tooltipAnnotation);
  2820. tooltip.show();
  2821. editor._signal("showGutterTooltip", tooltip);
  2822. editor.on("mousewheel", hideTooltip);
  2823. if (mouseHandler.$tooltipFollowsMouse) {
  2824. moveTooltip(mouseEvent);
  2825. } else {
  2826. var gutterElement = mouseEvent.domEvent.target;
  2827. var rect = gutterElement.getBoundingClientRect();
  2828. var style = tooltip.getElement().style;
  2829. style.left = rect.right + "px";
  2830. style.top = rect.bottom + "px";
  2831. }
  2832. }
  2833. function hideTooltip() {
  2834. if (tooltipTimeout)
  2835. tooltipTimeout = clearTimeout(tooltipTimeout);
  2836. if (tooltipAnnotation) {
  2837. tooltip.hide();
  2838. tooltipAnnotation = null;
  2839. editor._signal("hideGutterTooltip", tooltip);
  2840. editor.removeEventListener("mousewheel", hideTooltip);
  2841. }
  2842. }
  2843. function moveTooltip(e) {
  2844. tooltip.setPosition(e.x, e.y);
  2845. }
  2846. mouseHandler.editor.setDefaultHandler("guttermousemove", function(e) {
  2847. var target = e.domEvent.target || e.domEvent.srcElement;
  2848. if (dom.hasCssClass(target, "ace_fold-widget"))
  2849. return hideTooltip();
  2850. if (tooltipAnnotation && mouseHandler.$tooltipFollowsMouse)
  2851. moveTooltip(e);
  2852. mouseEvent = e;
  2853. if (tooltipTimeout)
  2854. return;
  2855. tooltipTimeout = setTimeout(function() {
  2856. tooltipTimeout = null;
  2857. if (mouseEvent && !mouseHandler.isMousePressed)
  2858. showTooltip();
  2859. else
  2860. hideTooltip();
  2861. }, 50);
  2862. });
  2863. event.addListener(editor.renderer.$gutter, "mouseout", function(e) {
  2864. mouseEvent = null;
  2865. if (!tooltipAnnotation || tooltipTimeout)
  2866. return;
  2867. tooltipTimeout = setTimeout(function() {
  2868. tooltipTimeout = null;
  2869. hideTooltip();
  2870. }, 50);
  2871. });
  2872. editor.on("changeSession", hideTooltip);
  2873. }
  2874. function GutterTooltip(parentNode) {
  2875. Tooltip.call(this, parentNode);
  2876. }
  2877. oop.inherits(GutterTooltip, Tooltip);
  2878. (function(){
  2879. this.setPosition = function(x, y) {
  2880. var windowWidth = window.innerWidth || document.documentElement.clientWidth;
  2881. var windowHeight = window.innerHeight || document.documentElement.clientHeight;
  2882. var width = this.getWidth();
  2883. var height = this.getHeight();
  2884. x += 15;
  2885. y += 15;
  2886. if (x + width > windowWidth) {
  2887. x -= (x + width) - windowWidth;
  2888. }
  2889. if (y + height > windowHeight) {
  2890. y -= 20 + height;
  2891. }
  2892. Tooltip.prototype.setPosition.call(this, x, y);
  2893. };
  2894. }).call(GutterTooltip.prototype);
  2895. exports.GutterHandler = GutterHandler;
  2896. });
  2897. define("ace/mouse/mouse_event",["require","exports","module","ace/lib/event","ace/lib/useragent"], function(require, exports, module) {
  2898. "use strict";
  2899. var event = require("../lib/event");
  2900. var useragent = require("../lib/useragent");
  2901. var MouseEvent = exports.MouseEvent = function(domEvent, editor) {
  2902. this.domEvent = domEvent;
  2903. this.editor = editor;
  2904. this.x = this.clientX = domEvent.clientX;
  2905. this.y = this.clientY = domEvent.clientY;
  2906. this.$pos = null;
  2907. this.$inSelection = null;
  2908. this.propagationStopped = false;
  2909. this.defaultPrevented = false;
  2910. };
  2911. (function() {
  2912. this.stopPropagation = function() {
  2913. event.stopPropagation(this.domEvent);
  2914. this.propagationStopped = true;
  2915. };
  2916. this.preventDefault = function() {
  2917. event.preventDefault(this.domEvent);
  2918. this.defaultPrevented = true;
  2919. };
  2920. this.stop = function() {
  2921. this.stopPropagation();
  2922. this.preventDefault();
  2923. };
  2924. this.getDocumentPosition = function() {
  2925. if (this.$pos)
  2926. return this.$pos;
  2927. this.$pos = this.editor.renderer.screenToTextCoordinates(this.clientX, this.clientY);
  2928. return this.$pos;
  2929. };
  2930. this.inSelection = function() {
  2931. if (this.$inSelection !== null)
  2932. return this.$inSelection;
  2933. var editor = this.editor;
  2934. var selectionRange = editor.getSelectionRange();
  2935. if (selectionRange.isEmpty())
  2936. this.$inSelection = false;
  2937. else {
  2938. var pos = this.getDocumentPosition();
  2939. this.$inSelection = selectionRange.contains(pos.row, pos.column);
  2940. }
  2941. return this.$inSelection;
  2942. };
  2943. this.getButton = function() {
  2944. return event.getButton(this.domEvent);
  2945. };
  2946. this.getShiftKey = function() {
  2947. return this.domEvent.shiftKey;
  2948. };
  2949. this.getAccelKey = useragent.isMac
  2950. ? function() { return this.domEvent.metaKey; }
  2951. : function() { return this.domEvent.ctrlKey; };
  2952. }).call(MouseEvent.prototype);
  2953. });
  2954. define("ace/mouse/dragdrop_handler",["require","exports","module","ace/lib/dom","ace/lib/event","ace/lib/useragent"], function(require, exports, module) {
  2955. "use strict";
  2956. var dom = require("../lib/dom");
  2957. var event = require("../lib/event");
  2958. var useragent = require("../lib/useragent");
  2959. var AUTOSCROLL_DELAY = 200;
  2960. var SCROLL_CURSOR_DELAY = 200;
  2961. var SCROLL_CURSOR_HYSTERESIS = 5;
  2962. function DragdropHandler(mouseHandler) {
  2963. var editor = mouseHandler.editor;
  2964. var blankImage = dom.createElement("img");
  2965. blankImage.src = "data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==";
  2966. if (useragent.isOpera)
  2967. blankImage.style.cssText = "width:1px;height:1px;position:fixed;top:0;left:0;z-index:2147483647;opacity:0;";
  2968. var exports = ["dragWait", "dragWaitEnd", "startDrag", "dragReadyEnd", "onMouseDrag"];
  2969. exports.forEach(function(x) {
  2970. mouseHandler[x] = this[x];
  2971. }, this);
  2972. editor.addEventListener("mousedown", this.onMouseDown.bind(mouseHandler));
  2973. var mouseTarget = editor.container;
  2974. var dragSelectionMarker, x, y;
  2975. var timerId, range;
  2976. var dragCursor, counter = 0;
  2977. var dragOperation;
  2978. var isInternal;
  2979. var autoScrollStartTime;
  2980. var cursorMovedTime;
  2981. var cursorPointOnCaretMoved;
  2982. this.onDragStart = function(e) {
  2983. if (this.cancelDrag || !mouseTarget.draggable) {
  2984. var self = this;
  2985. setTimeout(function(){
  2986. self.startSelect();
  2987. self.captureMouse(e);
  2988. }, 0);
  2989. return e.preventDefault();
  2990. }
  2991. range = editor.getSelectionRange();
  2992. var dataTransfer = e.dataTransfer;
  2993. dataTransfer.effectAllowed = editor.getReadOnly() ? "copy" : "copyMove";
  2994. if (useragent.isOpera) {
  2995. editor.container.appendChild(blankImage);
  2996. blankImage.scrollTop = 0;
  2997. }
  2998. dataTransfer.setDragImage && dataTransfer.setDragImage(blankImage, 0, 0);
  2999. if (useragent.isOpera) {
  3000. editor.container.removeChild(blankImage);
  3001. }
  3002. dataTransfer.clearData();
  3003. dataTransfer.setData("Text", editor.session.getTextRange());
  3004. isInternal = true;
  3005. this.setState("drag");
  3006. };
  3007. this.onDragEnd = function(e) {
  3008. mouseTarget.draggable = false;
  3009. isInternal = false;
  3010. this.setState(null);
  3011. if (!editor.getReadOnly()) {
  3012. var dropEffect = e.dataTransfer.dropEffect;
  3013. if (!dragOperation && dropEffect == "move")
  3014. editor.session.remove(editor.getSelectionRange());
  3015. editor.renderer.$cursorLayer.setBlinking(true);
  3016. }
  3017. this.editor.unsetStyle("ace_dragging");
  3018. this.editor.renderer.setCursorStyle("");
  3019. };
  3020. this.onDragEnter = function(e) {
  3021. if (editor.getReadOnly() || !canAccept(e.dataTransfer))
  3022. return;
  3023. x = e.clientX;
  3024. y = e.clientY;
  3025. if (!dragSelectionMarker)
  3026. addDragMarker();
  3027. counter++;
  3028. e.dataTransfer.dropEffect = dragOperation = getDropEffect(e);
  3029. return event.preventDefault(e);
  3030. };
  3031. this.onDragOver = function(e) {
  3032. if (editor.getReadOnly() || !canAccept(e.dataTransfer))
  3033. return;
  3034. x = e.clientX;
  3035. y = e.clientY;
  3036. if (!dragSelectionMarker) {
  3037. addDragMarker();
  3038. counter++;
  3039. }
  3040. if (onMouseMoveTimer !== null)
  3041. onMouseMoveTimer = null;
  3042. e.dataTransfer.dropEffect = dragOperation = getDropEffect(e);
  3043. return event.preventDefault(e);
  3044. };
  3045. this.onDragLeave = function(e) {
  3046. counter--;
  3047. if (counter <= 0 && dragSelectionMarker) {
  3048. clearDragMarker();
  3049. dragOperation = null;
  3050. return event.preventDefault(e);
  3051. }
  3052. };
  3053. this.onDrop = function(e) {
  3054. if (!dragCursor)
  3055. return;
  3056. var dataTransfer = e.dataTransfer;
  3057. if (isInternal) {
  3058. switch (dragOperation) {
  3059. case "move":
  3060. if (range.contains(dragCursor.row, dragCursor.column)) {
  3061. range = {
  3062. start: dragCursor,
  3063. end: dragCursor
  3064. };
  3065. } else {
  3066. range = editor.moveText(range, dragCursor);
  3067. }
  3068. break;
  3069. case "copy":
  3070. range = editor.moveText(range, dragCursor, true);
  3071. break;
  3072. }
  3073. } else {
  3074. var dropData = dataTransfer.getData('Text');
  3075. range = {
  3076. start: dragCursor,
  3077. end: editor.session.insert(dragCursor, dropData)
  3078. };
  3079. editor.focus();
  3080. dragOperation = null;
  3081. }
  3082. clearDragMarker();
  3083. return event.preventDefault(e);
  3084. };
  3085. event.addListener(mouseTarget, "dragstart", this.onDragStart.bind(mouseHandler));
  3086. event.addListener(mouseTarget, "dragend", this.onDragEnd.bind(mouseHandler));
  3087. event.addListener(mouseTarget, "dragenter", this.onDragEnter.bind(mouseHandler));
  3088. event.addListener(mouseTarget, "dragover", this.onDragOver.bind(mouseHandler));
  3089. event.addListener(mouseTarget, "dragleave", this.onDragLeave.bind(mouseHandler));
  3090. event.addListener(mouseTarget, "drop", this.onDrop.bind(mouseHandler));
  3091. function scrollCursorIntoView(cursor, prevCursor) {
  3092. var now = Date.now();
  3093. var vMovement = !prevCursor || cursor.row != prevCursor.row;
  3094. var hMovement = !prevCursor || cursor.column != prevCursor.column;
  3095. if (!cursorMovedTime || vMovement || hMovement) {
  3096. editor.$blockScrolling += 1;
  3097. editor.moveCursorToPosition(cursor);
  3098. editor.$blockScrolling -= 1;
  3099. cursorMovedTime = now;
  3100. cursorPointOnCaretMoved = {x: x, y: y};
  3101. } else {
  3102. var distance = calcDistance(cursorPointOnCaretMoved.x, cursorPointOnCaretMoved.y, x, y);
  3103. if (distance > SCROLL_CURSOR_HYSTERESIS) {
  3104. cursorMovedTime = null;
  3105. } else if (now - cursorMovedTime >= SCROLL_CURSOR_DELAY) {
  3106. editor.renderer.scrollCursorIntoView();
  3107. cursorMovedTime = null;
  3108. }
  3109. }
  3110. }
  3111. function autoScroll(cursor, prevCursor) {
  3112. var now = Date.now();
  3113. var lineHeight = editor.renderer.layerConfig.lineHeight;
  3114. var characterWidth = editor.renderer.layerConfig.characterWidth;
  3115. var editorRect = editor.renderer.scroller.getBoundingClientRect();
  3116. var offsets = {
  3117. x: {
  3118. left: x - editorRect.left,
  3119. right: editorRect.right - x
  3120. },
  3121. y: {
  3122. top: y - editorRect.top,
  3123. bottom: editorRect.bottom - y
  3124. }
  3125. };
  3126. var nearestXOffset = Math.min(offsets.x.left, offsets.x.right);
  3127. var nearestYOffset = Math.min(offsets.y.top, offsets.y.bottom);
  3128. var scrollCursor = {row: cursor.row, column: cursor.column};
  3129. if (nearestXOffset / characterWidth <= 2) {
  3130. scrollCursor.column += (offsets.x.left < offsets.x.right ? -3 : +2);
  3131. }
  3132. if (nearestYOffset / lineHeight <= 1) {
  3133. scrollCursor.row += (offsets.y.top < offsets.y.bottom ? -1 : +1);
  3134. }
  3135. var vScroll = cursor.row != scrollCursor.row;
  3136. var hScroll = cursor.column != scrollCursor.column;
  3137. var vMovement = !prevCursor || cursor.row != prevCursor.row;
  3138. if (vScroll || (hScroll && !vMovement)) {
  3139. if (!autoScrollStartTime)
  3140. autoScrollStartTime = now;
  3141. else if (now - autoScrollStartTime >= AUTOSCROLL_DELAY)
  3142. editor.renderer.scrollCursorIntoView(scrollCursor);
  3143. } else {
  3144. autoScrollStartTime = null;
  3145. }
  3146. }
  3147. function onDragInterval() {
  3148. var prevCursor = dragCursor;
  3149. dragCursor = editor.renderer.screenToTextCoordinates(x, y);
  3150. scrollCursorIntoView(dragCursor, prevCursor);
  3151. autoScroll(dragCursor, prevCursor);
  3152. }
  3153. function addDragMarker() {
  3154. range = editor.selection.toOrientedRange();
  3155. dragSelectionMarker = editor.session.addMarker(range, "ace_selection", editor.getSelectionStyle());
  3156. editor.clearSelection();
  3157. if (editor.isFocused())
  3158. editor.renderer.$cursorLayer.setBlinking(false);
  3159. clearInterval(timerId);
  3160. onDragInterval();
  3161. timerId = setInterval(onDragInterval, 20);
  3162. counter = 0;
  3163. event.addListener(document, "mousemove", onMouseMove);
  3164. }
  3165. function clearDragMarker() {
  3166. clearInterval(timerId);
  3167. editor.session.removeMarker(dragSelectionMarker);
  3168. dragSelectionMarker = null;
  3169. editor.$blockScrolling += 1;
  3170. editor.selection.fromOrientedRange(range);
  3171. editor.$blockScrolling -= 1;
  3172. if (editor.isFocused() && !isInternal)
  3173. editor.renderer.$cursorLayer.setBlinking(!editor.getReadOnly());
  3174. range = null;
  3175. dragCursor = null;
  3176. counter = 0;
  3177. autoScrollStartTime = null;
  3178. cursorMovedTime = null;
  3179. event.removeListener(document, "mousemove", onMouseMove);
  3180. }
  3181. var onMouseMoveTimer = null;
  3182. function onMouseMove() {
  3183. if (onMouseMoveTimer == null) {
  3184. onMouseMoveTimer = setTimeout(function() {
  3185. if (onMouseMoveTimer != null && dragSelectionMarker)
  3186. clearDragMarker();
  3187. }, 20);
  3188. }
  3189. }
  3190. function canAccept(dataTransfer) {
  3191. var types = dataTransfer.types;
  3192. return !types || Array.prototype.some.call(types, function(type) {
  3193. return type == 'text/plain' || type == 'Text';
  3194. });
  3195. }
  3196. function getDropEffect(e) {
  3197. var copyAllowed = ['copy', 'copymove', 'all', 'uninitialized'];
  3198. var moveAllowed = ['move', 'copymove', 'linkmove', 'all', 'uninitialized'];
  3199. var copyModifierState = useragent.isMac ? e.altKey : e.ctrlKey;
  3200. var effectAllowed = "uninitialized";
  3201. try {
  3202. effectAllowed = e.dataTransfer.effectAllowed.toLowerCase();
  3203. } catch (e) {}
  3204. var dropEffect = "none";
  3205. if (copyModifierState && copyAllowed.indexOf(effectAllowed) >= 0)
  3206. dropEffect = "copy";
  3207. else if (moveAllowed.indexOf(effectAllowed) >= 0)
  3208. dropEffect = "move";
  3209. else if (copyAllowed.indexOf(effectAllowed) >= 0)
  3210. dropEffect = "copy";
  3211. return dropEffect;
  3212. }
  3213. }
  3214. (function() {
  3215. this.dragWait = function() {
  3216. var interval = Date.now() - this.mousedownEvent.time;
  3217. if (interval > this.editor.getDragDelay())
  3218. this.startDrag();
  3219. };
  3220. this.dragWaitEnd = function() {
  3221. var target = this.editor.container;
  3222. target.draggable = false;
  3223. this.startSelect(this.mousedownEvent.getDocumentPosition());
  3224. this.selectEnd();
  3225. };
  3226. this.dragReadyEnd = function(e) {
  3227. this.editor.renderer.$cursorLayer.setBlinking(!this.editor.getReadOnly());
  3228. this.editor.unsetStyle("ace_dragging");
  3229. this.editor.renderer.setCursorStyle("");
  3230. this.dragWaitEnd();
  3231. };
  3232. this.startDrag = function(){
  3233. this.cancelDrag = false;
  3234. var editor = this.editor;
  3235. var target = editor.container;
  3236. target.draggable = true;
  3237. editor.renderer.$cursorLayer.setBlinking(false);
  3238. editor.setStyle("ace_dragging");
  3239. var cursorStyle = useragent.isWin ? "default" : "move";
  3240. editor.renderer.setCursorStyle(cursorStyle);
  3241. this.setState("dragReady");
  3242. };
  3243. this.onMouseDrag = function(e) {
  3244. var target = this.editor.container;
  3245. if (useragent.isIE && this.state == "dragReady") {
  3246. var distance = calcDistance(this.mousedownEvent.x, this.mousedownEvent.y, this.x, this.y);
  3247. if (distance > 3)
  3248. target.dragDrop();
  3249. }
  3250. if (this.state === "dragWait") {
  3251. var distance = calcDistance(this.mousedownEvent.x, this.mousedownEvent.y, this.x, this.y);
  3252. if (distance > 0) {
  3253. target.draggable = false;
  3254. this.startSelect(this.mousedownEvent.getDocumentPosition());
  3255. }
  3256. }
  3257. };
  3258. this.onMouseDown = function(e) {
  3259. if (!this.$dragEnabled)
  3260. return;
  3261. this.mousedownEvent = e;
  3262. var editor = this.editor;
  3263. var inSelection = e.inSelection();
  3264. var button = e.getButton();
  3265. var clickCount = e.domEvent.detail || 1;
  3266. if (clickCount === 1 && button === 0 && inSelection) {
  3267. if (e.editor.inMultiSelectMode && (e.getAccelKey() || e.getShiftKey()))
  3268. return;
  3269. this.mousedownEvent.time = Date.now();
  3270. var eventTarget = e.domEvent.target || e.domEvent.srcElement;
  3271. if ("unselectable" in eventTarget)
  3272. eventTarget.unselectable = "on";
  3273. if (editor.getDragDelay()) {
  3274. if (useragent.isWebKit) {
  3275. this.cancelDrag = true;
  3276. var mouseTarget = editor.container;
  3277. mouseTarget.draggable = true;
  3278. }
  3279. this.setState("dragWait");
  3280. } else {
  3281. this.startDrag();
  3282. }
  3283. this.captureMouse(e, this.onMouseDrag.bind(this));
  3284. e.defaultPrevented = true;
  3285. }
  3286. };
  3287. }).call(DragdropHandler.prototype);
  3288. function calcDistance(ax, ay, bx, by) {
  3289. return Math.sqrt(Math.pow(bx - ax, 2) + Math.pow(by - ay, 2));
  3290. }
  3291. exports.DragdropHandler = DragdropHandler;
  3292. });
  3293. define("ace/lib/net",["require","exports","module","ace/lib/dom"], function(require, exports, module) {
  3294. "use strict";
  3295. var dom = require("./dom");
  3296. exports.get = function (url, callback) {
  3297. var xhr = new XMLHttpRequest();
  3298. xhr.open('GET', url, true);
  3299. xhr.onreadystatechange = function () {
  3300. if (xhr.readyState === 4) {
  3301. callback(xhr.responseText);
  3302. }
  3303. };
  3304. xhr.send(null);
  3305. };
  3306. exports.loadScript = function(path, callback) {
  3307. var head = dom.getDocumentHead();
  3308. var s = document.createElement('script');
  3309. s.src = path;
  3310. head.appendChild(s);
  3311. s.onload = s.onreadystatechange = function(_, isAbort) {
  3312. if (isAbort || !s.readyState || s.readyState == "loaded" || s.readyState == "complete") {
  3313. s = s.onload = s.onreadystatechange = null;
  3314. if (!isAbort)
  3315. callback();
  3316. }
  3317. };
  3318. };
  3319. exports.qualifyURL = function(url) {
  3320. var a = document.createElement('a');
  3321. a.href = url;
  3322. return a.href;
  3323. }
  3324. });
  3325. define("ace/lib/event_emitter",["require","exports","module"], function(require, exports, module) {
  3326. "use strict";
  3327. var EventEmitter = {};
  3328. var stopPropagation = function() { this.propagationStopped = true; };
  3329. var preventDefault = function() { this.defaultPrevented = true; };
  3330. EventEmitter._emit =
  3331. EventEmitter._dispatchEvent = function(eventName, e) {
  3332. this._eventRegistry || (this._eventRegistry = {});
  3333. this._defaultHandlers || (this._defaultHandlers = {});
  3334. var listeners = this._eventRegistry[eventName] || [];
  3335. var defaultHandler = this._defaultHandlers[eventName];
  3336. if (!listeners.length && !defaultHandler)
  3337. return;
  3338. if (typeof e != "object" || !e)
  3339. e = {};
  3340. if (!e.type)
  3341. e.type = eventName;
  3342. if (!e.stopPropagation)
  3343. e.stopPropagation = stopPropagation;
  3344. if (!e.preventDefault)
  3345. e.preventDefault = preventDefault;
  3346. listeners = listeners.slice();
  3347. for (var i=0; i<listeners.length; i++) {
  3348. listeners[i](e, this);
  3349. if (e.propagationStopped)
  3350. break;
  3351. }
  3352. if (defaultHandler && !e.defaultPrevented)
  3353. return defaultHandler(e, this);
  3354. };
  3355. EventEmitter._signal = function(eventName, e) {
  3356. var listeners = (this._eventRegistry || {})[eventName];
  3357. if (!listeners)
  3358. return;
  3359. listeners = listeners.slice();
  3360. for (var i=0; i<listeners.length; i++)
  3361. listeners[i](e, this);
  3362. };
  3363. EventEmitter.once = function(eventName, callback) {
  3364. var _self = this;
  3365. callback && this.addEventListener(eventName, function newCallback() {
  3366. _self.removeEventListener(eventName, newCallback);
  3367. callback.apply(null, arguments);
  3368. });
  3369. };
  3370. EventEmitter.setDefaultHandler = function(eventName, callback) {
  3371. var handlers = this._defaultHandlers
  3372. if (!handlers)
  3373. handlers = this._defaultHandlers = {_disabled_: {}};
  3374. if (handlers[eventName]) {
  3375. var old = handlers[eventName];
  3376. var disabled = handlers._disabled_[eventName];
  3377. if (!disabled)
  3378. handlers._disabled_[eventName] = disabled = [];
  3379. disabled.push(old);
  3380. var i = disabled.indexOf(callback);
  3381. if (i != -1)
  3382. disabled.splice(i, 1);
  3383. }
  3384. handlers[eventName] = callback;
  3385. };
  3386. EventEmitter.removeDefaultHandler = function(eventName, callback) {
  3387. var handlers = this._defaultHandlers
  3388. if (!handlers)
  3389. return;
  3390. var disabled = handlers._disabled_[eventName];
  3391. if (handlers[eventName] == callback) {
  3392. var old = handlers[eventName];
  3393. if (disabled)
  3394. this.setDefaultHandler(eventName, disabled.pop());
  3395. } else if (disabled) {
  3396. var i = disabled.indexOf(callback);
  3397. if (i != -1)
  3398. disabled.splice(i, 1);
  3399. }
  3400. };
  3401. EventEmitter.on =
  3402. EventEmitter.addEventListener = function(eventName, callback, capturing) {
  3403. this._eventRegistry = this._eventRegistry || {};
  3404. var listeners = this._eventRegistry[eventName];
  3405. if (!listeners)
  3406. listeners = this._eventRegistry[eventName] = [];
  3407. if (listeners.indexOf(callback) == -1)
  3408. listeners[capturing ? "unshift" : "push"](callback);
  3409. return callback;
  3410. };
  3411. EventEmitter.off =
  3412. EventEmitter.removeListener =
  3413. EventEmitter.removeEventListener = function(eventName, callback) {
  3414. this._eventRegistry = this._eventRegistry || {};
  3415. var listeners = this._eventRegistry[eventName];
  3416. if (!listeners)
  3417. return;
  3418. var index = listeners.indexOf(callback);
  3419. if (index !== -1)
  3420. listeners.splice(index, 1);
  3421. };
  3422. EventEmitter.removeAllListeners = function(eventName) {
  3423. if (this._eventRegistry) this._eventRegistry[eventName] = [];
  3424. };
  3425. exports.EventEmitter = EventEmitter;
  3426. });
  3427. define("ace/lib/app_config",["require","exports","module","ace/lib/oop","ace/lib/event_emitter"], function(require, exports, module) {
  3428. "no use strict";
  3429. var oop = require("./oop");
  3430. var EventEmitter = require("./event_emitter").EventEmitter;
  3431. var optionsProvider = {
  3432. setOptions: function(optList) {
  3433. Object.keys(optList).forEach(function(key) {
  3434. this.setOption(key, optList[key]);
  3435. }, this);
  3436. },
  3437. getOptions: function(optionNames) {
  3438. var result = {};
  3439. if (!optionNames) {
  3440. optionNames = Object.keys(this.$options);
  3441. } else if (!Array.isArray(optionNames)) {
  3442. result = optionNames;
  3443. optionNames = Object.keys(result);
  3444. }
  3445. optionNames.forEach(function(key) {
  3446. result[key] = this.getOption(key);
  3447. }, this);
  3448. return result;
  3449. },
  3450. setOption: function(name, value) {
  3451. if (this["$" + name] === value)
  3452. return;
  3453. var opt = this.$options[name];
  3454. if (!opt) {
  3455. return warn('misspelled option "' + name + '"');
  3456. }
  3457. if (opt.forwardTo)
  3458. return this[opt.forwardTo] && this[opt.forwardTo].setOption(name, value);
  3459. if (!opt.handlesSet)
  3460. this["$" + name] = value;
  3461. if (opt && opt.set)
  3462. opt.set.call(this, value);
  3463. },
  3464. getOption: function(name) {
  3465. var opt = this.$options[name];
  3466. if (!opt) {
  3467. return warn('misspelled option "' + name + '"');
  3468. }
  3469. if (opt.forwardTo)
  3470. return this[opt.forwardTo] && this[opt.forwardTo].getOption(name);
  3471. return opt && opt.get ? opt.get.call(this) : this["$" + name];
  3472. }
  3473. };
  3474. function warn(message) {
  3475. if (typeof console != "undefined" && console.warn)
  3476. console.warn.apply(console, arguments);
  3477. }
  3478. function reportError(msg, data) {
  3479. var e = new Error(msg);
  3480. e.data = data;
  3481. if (typeof console == "object" && console.error)
  3482. console.error(e);
  3483. setTimeout(function() { throw e; });
  3484. }
  3485. var AppConfig = function() {
  3486. this.$defaultOptions = {};
  3487. };
  3488. (function() {
  3489. oop.implement(this, EventEmitter);
  3490. this.defineOptions = function(obj, path, options) {
  3491. if (!obj.$options)
  3492. this.$defaultOptions[path] = obj.$options = {};
  3493. Object.keys(options).forEach(function(key) {
  3494. var opt = options[key];
  3495. if (typeof opt == "string")
  3496. opt = {forwardTo: opt};
  3497. opt.name || (opt.name = key);
  3498. obj.$options[opt.name] = opt;
  3499. if ("initialValue" in opt)
  3500. obj["$" + opt.name] = opt.initialValue;
  3501. });
  3502. oop.implement(obj, optionsProvider);
  3503. return this;
  3504. };
  3505. this.resetOptions = function(obj) {
  3506. Object.keys(obj.$options).forEach(function(key) {
  3507. var opt = obj.$options[key];
  3508. if ("value" in opt)
  3509. obj.setOption(key, opt.value);
  3510. });
  3511. };
  3512. this.setDefaultValue = function(path, name, value) {
  3513. var opts = this.$defaultOptions[path] || (this.$defaultOptions[path] = {});
  3514. if (opts[name]) {
  3515. if (opts.forwardTo)
  3516. this.setDefaultValue(opts.forwardTo, name, value);
  3517. else
  3518. opts[name].value = value;
  3519. }
  3520. };
  3521. this.setDefaultValues = function(path, optionHash) {
  3522. Object.keys(optionHash).forEach(function(key) {
  3523. this.setDefaultValue(path, key, optionHash[key]);
  3524. }, this);
  3525. };
  3526. this.warn = warn;
  3527. this.reportError = reportError;
  3528. }).call(AppConfig.prototype);
  3529. exports.AppConfig = AppConfig;
  3530. });
  3531. define("ace/config",["require","exports","module","ace/lib/lang","ace/lib/oop","ace/lib/net","ace/lib/app_config"], function(require, exports, module) {
  3532. "no use strict";
  3533. var lang = require("./lib/lang");
  3534. var oop = require("./lib/oop");
  3535. var net = require("./lib/net");
  3536. var AppConfig = require("./lib/app_config").AppConfig;
  3537. module.exports = exports = new AppConfig();
  3538. var global = (function() {
  3539. return this || typeof window != "undefined" && window;
  3540. })();
  3541. var options = {
  3542. packaged: false,
  3543. workerPath: null,
  3544. modePath: null,
  3545. themePath: null,
  3546. basePath: "",
  3547. suffix: ".js",
  3548. $moduleUrls: {}
  3549. };
  3550. exports.get = function(key) {
  3551. if (!options.hasOwnProperty(key))
  3552. throw new Error("Unknown config key: " + key);
  3553. return options[key];
  3554. };
  3555. exports.set = function(key, value) {
  3556. if (!options.hasOwnProperty(key))
  3557. throw new Error("Unknown config key: " + key);
  3558. options[key] = value;
  3559. };
  3560. exports.all = function() {
  3561. return lang.copyObject(options);
  3562. };
  3563. exports.moduleUrl = function(name, component) {
  3564. if (options.$moduleUrls[name])
  3565. return options.$moduleUrls[name];
  3566. var parts = name.split("/");
  3567. component = component || parts[parts.length - 2] || "";
  3568. var sep = component == "snippets" ? "/" : "-";
  3569. var base = parts[parts.length - 1];
  3570. if (component == "worker" && sep == "-") {
  3571. var re = new RegExp("^" + component + "[\\-_]|[\\-_]" + component + "$", "g");
  3572. base = base.replace(re, "");
  3573. }
  3574. if ((!base || base == component) && parts.length > 1)
  3575. base = parts[parts.length - 2];
  3576. var path = options[component + "Path"];
  3577. if (path == null) {
  3578. path = options.basePath;
  3579. } else if (sep == "/") {
  3580. component = sep = "";
  3581. }
  3582. if (path && path.slice(-1) != "/")
  3583. path += "/";
  3584. return path + component + sep + base + this.get("suffix");
  3585. };
  3586. exports.setModuleUrl = function(name, subst) {
  3587. return options.$moduleUrls[name] = subst;
  3588. };
  3589. exports.$loading = {};
  3590. exports.loadModule = function(moduleName, onLoad) {
  3591. var module, moduleType;
  3592. if (Array.isArray(moduleName)) {
  3593. moduleType = moduleName[0];
  3594. moduleName = moduleName[1];
  3595. }
  3596. try {
  3597. module = require(moduleName);
  3598. } catch (e) {}
  3599. if (module && !exports.$loading[moduleName])
  3600. return onLoad && onLoad(module);
  3601. if (!exports.$loading[moduleName])
  3602. exports.$loading[moduleName] = [];
  3603. exports.$loading[moduleName].push(onLoad);
  3604. if (exports.$loading[moduleName].length > 1)
  3605. return;
  3606. var afterLoad = function() {
  3607. require([moduleName], function(module) {
  3608. exports._emit("load.module", {name: moduleName, module: module});
  3609. var listeners = exports.$loading[moduleName];
  3610. exports.$loading[moduleName] = null;
  3611. listeners.forEach(function(onLoad) {
  3612. onLoad && onLoad(module);
  3613. });
  3614. });
  3615. };
  3616. if (!exports.get("packaged"))
  3617. return afterLoad();
  3618. net.loadScript(exports.moduleUrl(moduleName, moduleType), afterLoad);
  3619. };
  3620. init(true);function init(packaged) {
  3621. if (!global || !global.document)
  3622. return;
  3623. options.packaged = packaged || require.packaged || module.packaged || (global.define && define.packaged);
  3624. var scriptOptions = {};
  3625. var scriptUrl = "";
  3626. var currentScript = (document.currentScript || document._currentScript ); // native or polyfill
  3627. var currentDocument = currentScript && currentScript.ownerDocument || document;
  3628. var scripts = currentDocument.getElementsByTagName("script");
  3629. for (var i=0; i<scripts.length; i++) {
  3630. var script = scripts[i];
  3631. var src = script.src || script.getAttribute("src");
  3632. if (!src)
  3633. continue;
  3634. var attributes = script.attributes;
  3635. for (var j=0, l=attributes.length; j < l; j++) {
  3636. var attr = attributes[j];
  3637. if (attr.name.indexOf("data-ace-") === 0) {
  3638. scriptOptions[deHyphenate(attr.name.replace(/^data-ace-/, ""))] = attr.value;
  3639. }
  3640. }
  3641. var m = src.match(/^(.*)\/ace(\-\w+)?\.js(\?|$)/);
  3642. if (m)
  3643. scriptUrl = m[1];
  3644. }
  3645. if (scriptUrl) {
  3646. scriptOptions.base = scriptOptions.base || scriptUrl;
  3647. scriptOptions.packaged = true;
  3648. }
  3649. scriptOptions.basePath = scriptOptions.base;
  3650. scriptOptions.workerPath = scriptOptions.workerPath || scriptOptions.base;
  3651. scriptOptions.modePath = scriptOptions.modePath || scriptOptions.base;
  3652. scriptOptions.themePath = scriptOptions.themePath || scriptOptions.base;
  3653. delete scriptOptions.base;
  3654. for (var key in scriptOptions)
  3655. if (typeof scriptOptions[key] !== "undefined")
  3656. exports.set(key, scriptOptions[key]);
  3657. }
  3658. exports.init = init;
  3659. function deHyphenate(str) {
  3660. return str.replace(/-(.)/g, function(m, m1) { return m1.toUpperCase(); });
  3661. }
  3662. });
  3663. define("ace/mouse/mouse_handler",["require","exports","module","ace/lib/event","ace/lib/useragent","ace/mouse/default_handlers","ace/mouse/default_gutter_handler","ace/mouse/mouse_event","ace/mouse/dragdrop_handler","ace/config"], function(require, exports, module) {
  3664. "use strict";
  3665. var event = require("../lib/event");
  3666. var useragent = require("../lib/useragent");
  3667. var DefaultHandlers = require("./default_handlers").DefaultHandlers;
  3668. var DefaultGutterHandler = require("./default_gutter_handler").GutterHandler;
  3669. var MouseEvent = require("./mouse_event").MouseEvent;
  3670. var DragdropHandler = require("./dragdrop_handler").DragdropHandler;
  3671. var config = require("../config");
  3672. var MouseHandler = function(editor) {
  3673. var _self = this;
  3674. this.editor = editor;
  3675. new DefaultHandlers(this);
  3676. new DefaultGutterHandler(this);
  3677. new DragdropHandler(this);
  3678. var focusEditor = function(e) {
  3679. var windowBlurred = !document.hasFocus || !document.hasFocus()
  3680. || !editor.isFocused() && document.activeElement == (editor.textInput && editor.textInput.getElement())
  3681. if (windowBlurred)
  3682. window.focus();
  3683. editor.focus();
  3684. };
  3685. var mouseTarget = editor.renderer.getMouseEventTarget();
  3686. event.addListener(mouseTarget, "click", this.onMouseEvent.bind(this, "click"));
  3687. event.addListener(mouseTarget, "mousemove", this.onMouseMove.bind(this, "mousemove"));
  3688. event.addMultiMouseDownListener([
  3689. mouseTarget,
  3690. editor.renderer.scrollBarV && editor.renderer.scrollBarV.inner,
  3691. editor.renderer.scrollBarH && editor.renderer.scrollBarH.inner,
  3692. editor.textInput && editor.textInput.getElement()
  3693. ].filter(Boolean), [400, 300, 250], this, "onMouseEvent");
  3694. event.addMouseWheelListener(editor.container, this.onMouseWheel.bind(this, "mousewheel"));
  3695. event.addTouchMoveListener(editor.container, this.onTouchMove.bind(this, "touchmove"));
  3696. var gutterEl = editor.renderer.$gutter;
  3697. event.addListener(gutterEl, "mousedown", this.onMouseEvent.bind(this, "guttermousedown"));
  3698. event.addListener(gutterEl, "click", this.onMouseEvent.bind(this, "gutterclick"));
  3699. event.addListener(gutterEl, "dblclick", this.onMouseEvent.bind(this, "gutterdblclick"));
  3700. event.addListener(gutterEl, "mousemove", this.onMouseEvent.bind(this, "guttermousemove"));
  3701. event.addListener(mouseTarget, "mousedown", focusEditor);
  3702. event.addListener(gutterEl, "mousedown", focusEditor);
  3703. if (useragent.isIE && editor.renderer.scrollBarV) {
  3704. event.addListener(editor.renderer.scrollBarV.element, "mousedown", focusEditor);
  3705. event.addListener(editor.renderer.scrollBarH.element, "mousedown", focusEditor);
  3706. }
  3707. editor.on("mousemove", function(e){
  3708. if (_self.state || _self.$dragDelay || !_self.$dragEnabled)
  3709. return;
  3710. var character = editor.renderer.screenToTextCoordinates(e.x, e.y);
  3711. var range = editor.session.selection.getRange();
  3712. var renderer = editor.renderer;
  3713. if (!range.isEmpty() && range.insideStart(character.row, character.column)) {
  3714. renderer.setCursorStyle("default");
  3715. } else {
  3716. renderer.setCursorStyle("");
  3717. }
  3718. });
  3719. };
  3720. (function() {
  3721. this.onMouseEvent = function(name, e) {
  3722. this.editor._emit(name, new MouseEvent(e, this.editor));
  3723. };
  3724. this.onMouseMove = function(name, e) {
  3725. var listeners = this.editor._eventRegistry && this.editor._eventRegistry.mousemove;
  3726. if (!listeners || !listeners.length)
  3727. return;
  3728. this.editor._emit(name, new MouseEvent(e, this.editor));
  3729. };
  3730. this.onMouseWheel = function(name, e) {
  3731. var mouseEvent = new MouseEvent(e, this.editor);
  3732. mouseEvent.speed = this.$scrollSpeed * 2;
  3733. mouseEvent.wheelX = e.wheelX;
  3734. mouseEvent.wheelY = e.wheelY;
  3735. this.editor._emit(name, mouseEvent);
  3736. };
  3737. this.onTouchMove = function (name, e) {
  3738. var mouseEvent = new MouseEvent(e, this.editor);
  3739. mouseEvent.speed = 1;//this.$scrollSpeed * 2;
  3740. mouseEvent.wheelX = e.wheelX;
  3741. mouseEvent.wheelY = e.wheelY;
  3742. this.editor._emit(name, mouseEvent);
  3743. };
  3744. this.setState = function(state) {
  3745. this.state = state;
  3746. };
  3747. this.captureMouse = function(ev, mouseMoveHandler) {
  3748. this.x = ev.x;
  3749. this.y = ev.y;
  3750. this.isMousePressed = true;
  3751. var renderer = this.editor.renderer;
  3752. if (renderer.$keepTextAreaAtCursor)
  3753. renderer.$keepTextAreaAtCursor = null;
  3754. var self = this;
  3755. var onMouseMove = function(e) {
  3756. if (!e) return;
  3757. if (useragent.isWebKit && !e.which && self.releaseMouse)
  3758. return self.releaseMouse();
  3759. self.x = e.clientX;
  3760. self.y = e.clientY;
  3761. mouseMoveHandler && mouseMoveHandler(e);
  3762. self.mouseEvent = new MouseEvent(e, self.editor);
  3763. self.$mouseMoved = true;
  3764. };
  3765. var onCaptureEnd = function(e) {
  3766. clearInterval(timerId);
  3767. onCaptureInterval();
  3768. self[self.state + "End"] && self[self.state + "End"](e);
  3769. self.state = "";
  3770. if (renderer.$keepTextAreaAtCursor == null) {
  3771. renderer.$keepTextAreaAtCursor = true;
  3772. renderer.$moveTextAreaToCursor();
  3773. }
  3774. self.isMousePressed = false;
  3775. self.$onCaptureMouseMove = self.releaseMouse = null;
  3776. e && self.onMouseEvent("mouseup", e);
  3777. };
  3778. var onCaptureInterval = function() {
  3779. self[self.state] && self[self.state]();
  3780. self.$mouseMoved = false;
  3781. };
  3782. if (useragent.isOldIE && ev.domEvent.type == "dblclick") {
  3783. return setTimeout(function() {onCaptureEnd(ev);});
  3784. }
  3785. self.$onCaptureMouseMove = onMouseMove;
  3786. self.releaseMouse = event.capture(this.editor.container, onMouseMove, onCaptureEnd);
  3787. var timerId = setInterval(onCaptureInterval, 20);
  3788. };
  3789. this.releaseMouse = null;
  3790. this.cancelContextMenu = function() {
  3791. var stop = function(e) {
  3792. if (e && e.domEvent && e.domEvent.type != "contextmenu")
  3793. return;
  3794. this.editor.off("nativecontextmenu", stop);
  3795. if (e && e.domEvent)
  3796. event.stopEvent(e.domEvent);
  3797. }.bind(this);
  3798. setTimeout(stop, 10);
  3799. this.editor.on("nativecontextmenu", stop);
  3800. };
  3801. }).call(MouseHandler.prototype);
  3802. config.defineOptions(MouseHandler.prototype, "mouseHandler", {
  3803. scrollSpeed: {initialValue: 2},
  3804. dragDelay: {initialValue: (useragent.isMac ? 150 : 0)},
  3805. dragEnabled: {initialValue: true},
  3806. focusTimout: {initialValue: 0},
  3807. tooltipFollowsMouse: {initialValue: true}
  3808. });
  3809. exports.MouseHandler = MouseHandler;
  3810. });
  3811. define("ace/mouse/fold_handler",["require","exports","module"], function(require, exports, module) {
  3812. "use strict";
  3813. function FoldHandler(editor) {
  3814. editor.on("click", function(e) {
  3815. var position = e.getDocumentPosition();
  3816. var session = editor.session;
  3817. var fold = session.getFoldAt(position.row, position.column, 1);
  3818. if (fold) {
  3819. if (e.getAccelKey())
  3820. session.removeFold(fold);
  3821. else
  3822. session.expandFold(fold);
  3823. e.stop();
  3824. }
  3825. });
  3826. editor.on("gutterclick", function(e) {
  3827. var gutterRegion = editor.renderer.$gutterLayer.getRegion(e);
  3828. if (gutterRegion == "foldWidgets") {
  3829. var row = e.getDocumentPosition().row;
  3830. var session = editor.session;
  3831. if (session.foldWidgets && session.foldWidgets[row])
  3832. editor.session.onFoldWidgetClick(row, e);
  3833. if (!editor.isFocused())
  3834. editor.focus();
  3835. e.stop();
  3836. }
  3837. });
  3838. editor.on("gutterdblclick", function(e) {
  3839. var gutterRegion = editor.renderer.$gutterLayer.getRegion(e);
  3840. if (gutterRegion == "foldWidgets") {
  3841. var row = e.getDocumentPosition().row;
  3842. var session = editor.session;
  3843. var data = session.getParentFoldRangeData(row, true);
  3844. var range = data.range || data.firstRange;
  3845. if (range) {
  3846. row = range.start.row;
  3847. var fold = session.getFoldAt(row, session.getLine(row).length, 1);
  3848. if (fold) {
  3849. session.removeFold(fold);
  3850. } else {
  3851. session.addFold("...", range);
  3852. editor.renderer.scrollCursorIntoView({row: range.start.row, column: 0});
  3853. }
  3854. }
  3855. e.stop();
  3856. }
  3857. });
  3858. }
  3859. exports.FoldHandler = FoldHandler;
  3860. });
  3861. define("ace/keyboard/keybinding",["require","exports","module","ace/lib/keys","ace/lib/event"], function(require, exports, module) {
  3862. "use strict";
  3863. var keyUtil = require("../lib/keys");
  3864. var event = require("../lib/event");
  3865. var KeyBinding = function(editor) {
  3866. this.$editor = editor;
  3867. this.$data = {editor: editor};
  3868. this.$handlers = [];
  3869. this.setDefaultHandler(editor.commands);
  3870. };
  3871. (function() {
  3872. this.setDefaultHandler = function(kb) {
  3873. this.removeKeyboardHandler(this.$defaultHandler);
  3874. this.$defaultHandler = kb;
  3875. this.addKeyboardHandler(kb, 0);
  3876. };
  3877. this.setKeyboardHandler = function(kb) {
  3878. var h = this.$handlers;
  3879. if (h[h.length - 1] == kb)
  3880. return;
  3881. while (h[h.length - 1] && h[h.length - 1] != this.$defaultHandler)
  3882. this.removeKeyboardHandler(h[h.length - 1]);
  3883. this.addKeyboardHandler(kb, 1);
  3884. };
  3885. this.addKeyboardHandler = function(kb, pos) {
  3886. if (!kb)
  3887. return;
  3888. if (typeof kb == "function" && !kb.handleKeyboard)
  3889. kb.handleKeyboard = kb;
  3890. var i = this.$handlers.indexOf(kb);
  3891. if (i != -1)
  3892. this.$handlers.splice(i, 1);
  3893. if (pos == undefined)
  3894. this.$handlers.push(kb);
  3895. else
  3896. this.$handlers.splice(pos, 0, kb);
  3897. if (i == -1 && kb.attach)
  3898. kb.attach(this.$editor);
  3899. };
  3900. this.removeKeyboardHandler = function(kb) {
  3901. var i = this.$handlers.indexOf(kb);
  3902. if (i == -1)
  3903. return false;
  3904. this.$handlers.splice(i, 1);
  3905. kb.detach && kb.detach(this.$editor);
  3906. return true;
  3907. };
  3908. this.getKeyboardHandler = function() {
  3909. return this.$handlers[this.$handlers.length - 1];
  3910. };
  3911. this.getStatusText = function() {
  3912. var data = this.$data;
  3913. var editor = data.editor;
  3914. return this.$handlers.map(function(h) {
  3915. return h.getStatusText && h.getStatusText(editor, data) || "";
  3916. }).filter(Boolean).join(" ");
  3917. };
  3918. this.$callKeyboardHandlers = function(hashId, keyString, keyCode, e) {
  3919. var toExecute;
  3920. var success = false;
  3921. var commands = this.$editor.commands;
  3922. for (var i = this.$handlers.length; i--;) {
  3923. toExecute = this.$handlers[i].handleKeyboard(
  3924. this.$data, hashId, keyString, keyCode, e
  3925. );
  3926. if (!toExecute || !toExecute.command)
  3927. continue;
  3928. if (toExecute.command == "null") {
  3929. success = true;
  3930. } else {
  3931. success = commands.exec(toExecute.command, this.$editor, toExecute.args, e);
  3932. }
  3933. if (success && e && hashId != -1 &&
  3934. toExecute.passEvent != true && toExecute.command.passEvent != true
  3935. ) {
  3936. event.stopEvent(e);
  3937. }
  3938. if (success)
  3939. break;
  3940. }
  3941. if (!success && hashId == -1) {
  3942. toExecute = {command: "insertstring"};
  3943. success = commands.exec("insertstring", this.$editor, keyString);
  3944. }
  3945. if (success && this.$editor._signal)
  3946. this.$editor._signal("keyboardActivity", toExecute);
  3947. return success;
  3948. };
  3949. this.onCommandKey = function(e, hashId, keyCode) {
  3950. var keyString = keyUtil.keyCodeToString(keyCode);
  3951. this.$callKeyboardHandlers(hashId, keyString, keyCode, e);
  3952. };
  3953. this.onTextInput = function(text) {
  3954. this.$callKeyboardHandlers(-1, text);
  3955. };
  3956. }).call(KeyBinding.prototype);
  3957. exports.KeyBinding = KeyBinding;
  3958. });
  3959. define("ace/range",["require","exports","module"], function(require, exports, module) {
  3960. "use strict";
  3961. var comparePoints = function(p1, p2) {
  3962. return p1.row - p2.row || p1.column - p2.column;
  3963. };
  3964. var Range = function(startRow, startColumn, endRow, endColumn) {
  3965. this.start = {
  3966. row: startRow,
  3967. column: startColumn
  3968. };
  3969. this.end = {
  3970. row: endRow,
  3971. column: endColumn
  3972. };
  3973. };
  3974. (function() {
  3975. this.isEqual = function(range) {
  3976. return this.start.row === range.start.row &&
  3977. this.end.row === range.end.row &&
  3978. this.start.column === range.start.column &&
  3979. this.end.column === range.end.column;
  3980. };
  3981. this.toString = function() {
  3982. return ("Range: [" + this.start.row + "/" + this.start.column +
  3983. "] -> [" + this.end.row + "/" + this.end.column + "]");
  3984. };
  3985. this.contains = function(row, column) {
  3986. return this.compare(row, column) == 0;
  3987. };
  3988. this.compareRange = function(range) {
  3989. var cmp,
  3990. end = range.end,
  3991. start = range.start;
  3992. cmp = this.compare(end.row, end.column);
  3993. if (cmp == 1) {
  3994. cmp = this.compare(start.row, start.column);
  3995. if (cmp == 1) {
  3996. return 2;
  3997. } else if (cmp == 0) {
  3998. return 1;
  3999. } else {
  4000. return 0;
  4001. }
  4002. } else if (cmp == -1) {
  4003. return -2;
  4004. } else {
  4005. cmp = this.compare(start.row, start.column);
  4006. if (cmp == -1) {
  4007. return -1;
  4008. } else if (cmp == 1) {
  4009. return 42;
  4010. } else {
  4011. return 0;
  4012. }
  4013. }
  4014. };
  4015. this.comparePoint = function(p) {
  4016. return this.compare(p.row, p.column);
  4017. };
  4018. this.containsRange = function(range) {
  4019. return this.comparePoint(range.start) == 0 && this.comparePoint(range.end) == 0;
  4020. };
  4021. this.intersects = function(range) {
  4022. var cmp = this.compareRange(range);
  4023. return (cmp == -1 || cmp == 0 || cmp == 1);
  4024. };
  4025. this.isEnd = function(row, column) {
  4026. return this.end.row == row && this.end.column == column;
  4027. };
  4028. this.isStart = function(row, column) {
  4029. return this.start.row == row && this.start.column == column;
  4030. };
  4031. this.setStart = function(row, column) {
  4032. if (typeof row == "object") {
  4033. this.start.column = row.column;
  4034. this.start.row = row.row;
  4035. } else {
  4036. this.start.row = row;
  4037. this.start.column = column;
  4038. }
  4039. };
  4040. this.setEnd = function(row, column) {
  4041. if (typeof row == "object") {
  4042. this.end.column = row.column;
  4043. this.end.row = row.row;
  4044. } else {
  4045. this.end.row = row;
  4046. this.end.column = column;
  4047. }
  4048. };
  4049. this.inside = function(row, column) {
  4050. if (this.compare(row, column) == 0) {
  4051. if (this.isEnd(row, column) || this.isStart(row, column)) {
  4052. return false;
  4053. } else {
  4054. return true;
  4055. }
  4056. }
  4057. return false;
  4058. };
  4059. this.insideStart = function(row, column) {
  4060. if (this.compare(row, column) == 0) {
  4061. if (this.isEnd(row, column)) {
  4062. return false;
  4063. } else {
  4064. return true;
  4065. }
  4066. }
  4067. return false;
  4068. };
  4069. this.insideEnd = function(row, column) {
  4070. if (this.compare(row, column) == 0) {
  4071. if (this.isStart(row, column)) {
  4072. return false;
  4073. } else {
  4074. return true;
  4075. }
  4076. }
  4077. return false;
  4078. };
  4079. this.compare = function(row, column) {
  4080. if (!this.isMultiLine()) {
  4081. if (row === this.start.row) {
  4082. return column < this.start.column ? -1 : (column > this.end.column ? 1 : 0);
  4083. }
  4084. }
  4085. if (row < this.start.row)
  4086. return -1;
  4087. if (row > this.end.row)
  4088. return 1;
  4089. if (this.start.row === row)
  4090. return column >= this.start.column ? 0 : -1;
  4091. if (this.end.row === row)
  4092. return column <= this.end.column ? 0 : 1;
  4093. return 0;
  4094. };
  4095. this.compareStart = function(row, column) {
  4096. if (this.start.row == row && this.start.column == column) {
  4097. return -1;
  4098. } else {
  4099. return this.compare(row, column);
  4100. }
  4101. };
  4102. this.compareEnd = function(row, column) {
  4103. if (this.end.row == row && this.end.column == column) {
  4104. return 1;
  4105. } else {
  4106. return this.compare(row, column);
  4107. }
  4108. };
  4109. this.compareInside = function(row, column) {
  4110. if (this.end.row == row && this.end.column == column) {
  4111. return 1;
  4112. } else if (this.start.row == row && this.start.column == column) {
  4113. return -1;
  4114. } else {
  4115. return this.compare(row, column);
  4116. }
  4117. };
  4118. this.clipRows = function(firstRow, lastRow) {
  4119. if (this.end.row > lastRow)
  4120. var end = {row: lastRow + 1, column: 0};
  4121. else if (this.end.row < firstRow)
  4122. var end = {row: firstRow, column: 0};
  4123. if (this.start.row > lastRow)
  4124. var start = {row: lastRow + 1, column: 0};
  4125. else if (this.start.row < firstRow)
  4126. var start = {row: firstRow, column: 0};
  4127. return Range.fromPoints(start || this.start, end || this.end);
  4128. };
  4129. this.extend = function(row, column) {
  4130. var cmp = this.compare(row, column);
  4131. if (cmp == 0)
  4132. return this;
  4133. else if (cmp == -1)
  4134. var start = {row: row, column: column};
  4135. else
  4136. var end = {row: row, column: column};
  4137. return Range.fromPoints(start || this.start, end || this.end);
  4138. };
  4139. this.isEmpty = function() {
  4140. return (this.start.row === this.end.row && this.start.column === this.end.column);
  4141. };
  4142. this.isMultiLine = function() {
  4143. return (this.start.row !== this.end.row);
  4144. };
  4145. this.clone = function() {
  4146. return Range.fromPoints(this.start, this.end);
  4147. };
  4148. this.collapseRows = function() {
  4149. if (this.end.column == 0)
  4150. return new Range(this.start.row, 0, Math.max(this.start.row, this.end.row-1), 0)
  4151. else
  4152. return new Range(this.start.row, 0, this.end.row, 0)
  4153. };
  4154. this.toScreenRange = function(session) {
  4155. var screenPosStart = session.documentToScreenPosition(this.start);
  4156. var screenPosEnd = session.documentToScreenPosition(this.end);
  4157. return new Range(
  4158. screenPosStart.row, screenPosStart.column,
  4159. screenPosEnd.row, screenPosEnd.column
  4160. );
  4161. };
  4162. this.moveBy = function(row, column) {
  4163. this.start.row += row;
  4164. this.start.column += column;
  4165. this.end.row += row;
  4166. this.end.column += column;
  4167. };
  4168. }).call(Range.prototype);
  4169. Range.fromPoints = function(start, end) {
  4170. return new Range(start.row, start.column, end.row, end.column);
  4171. };
  4172. Range.comparePoints = comparePoints;
  4173. Range.comparePoints = function(p1, p2) {
  4174. return p1.row - p2.row || p1.column - p2.column;
  4175. };
  4176. exports.Range = Range;
  4177. });
  4178. define("ace/selection",["require","exports","module","ace/lib/oop","ace/lib/lang","ace/lib/event_emitter","ace/range"], function(require, exports, module) {
  4179. "use strict";
  4180. var oop = require("./lib/oop");
  4181. var lang = require("./lib/lang");
  4182. var EventEmitter = require("./lib/event_emitter").EventEmitter;
  4183. var Range = require("./range").Range;
  4184. var Selection = function(session) {
  4185. this.session = session;
  4186. this.doc = session.getDocument();
  4187. this.clearSelection();
  4188. this.lead = this.selectionLead = this.doc.createAnchor(0, 0);
  4189. this.anchor = this.selectionAnchor = this.doc.createAnchor(0, 0);
  4190. var self = this;
  4191. this.lead.on("change", function(e) {
  4192. self._emit("changeCursor");
  4193. if (!self.$isEmpty)
  4194. self._emit("changeSelection");
  4195. if (!self.$keepDesiredColumnOnChange && e.old.column != e.value.column)
  4196. self.$desiredColumn = null;
  4197. });
  4198. this.selectionAnchor.on("change", function() {
  4199. if (!self.$isEmpty)
  4200. self._emit("changeSelection");
  4201. });
  4202. };
  4203. (function() {
  4204. oop.implement(this, EventEmitter);
  4205. this.isEmpty = function() {
  4206. return (this.$isEmpty || (
  4207. this.anchor.row == this.lead.row &&
  4208. this.anchor.column == this.lead.column
  4209. ));
  4210. };
  4211. this.isMultiLine = function() {
  4212. if (this.isEmpty()) {
  4213. return false;
  4214. }
  4215. return this.getRange().isMultiLine();
  4216. };
  4217. this.getCursor = function() {
  4218. return this.lead.getPosition();
  4219. };
  4220. this.setSelectionAnchor = function(row, column) {
  4221. this.anchor.setPosition(row, column);
  4222. if (this.$isEmpty) {
  4223. this.$isEmpty = false;
  4224. this._emit("changeSelection");
  4225. }
  4226. };
  4227. this.getSelectionAnchor = function() {
  4228. if (this.$isEmpty)
  4229. return this.getSelectionLead();
  4230. else
  4231. return this.anchor.getPosition();
  4232. };
  4233. this.getSelectionLead = function() {
  4234. return this.lead.getPosition();
  4235. };
  4236. this.shiftSelection = function(columns) {
  4237. if (this.$isEmpty) {
  4238. this.moveCursorTo(this.lead.row, this.lead.column + columns);
  4239. return;
  4240. }
  4241. var anchor = this.getSelectionAnchor();
  4242. var lead = this.getSelectionLead();
  4243. var isBackwards = this.isBackwards();
  4244. if (!isBackwards || anchor.column !== 0)
  4245. this.setSelectionAnchor(anchor.row, anchor.column + columns);
  4246. if (isBackwards || lead.column !== 0) {
  4247. this.$moveSelection(function() {
  4248. this.moveCursorTo(lead.row, lead.column + columns);
  4249. });
  4250. }
  4251. };
  4252. this.isBackwards = function() {
  4253. var anchor = this.anchor;
  4254. var lead = this.lead;
  4255. return (anchor.row > lead.row || (anchor.row == lead.row && anchor.column > lead.column));
  4256. };
  4257. this.getRange = function() {
  4258. var anchor = this.anchor;
  4259. var lead = this.lead;
  4260. if (this.isEmpty())
  4261. return Range.fromPoints(lead, lead);
  4262. if (this.isBackwards()) {
  4263. return Range.fromPoints(lead, anchor);
  4264. }
  4265. else {
  4266. return Range.fromPoints(anchor, lead);
  4267. }
  4268. };
  4269. this.clearSelection = function() {
  4270. if (!this.$isEmpty) {
  4271. this.$isEmpty = true;
  4272. this._emit("changeSelection");
  4273. }
  4274. };
  4275. this.selectAll = function() {
  4276. var lastRow = this.doc.getLength() - 1;
  4277. this.setSelectionAnchor(0, 0);
  4278. this.moveCursorTo(lastRow, this.doc.getLine(lastRow).length);
  4279. };
  4280. this.setRange =
  4281. this.setSelectionRange = function(range, reverse) {
  4282. if (reverse) {
  4283. this.setSelectionAnchor(range.end.row, range.end.column);
  4284. this.selectTo(range.start.row, range.start.column);
  4285. } else {
  4286. this.setSelectionAnchor(range.start.row, range.start.column);
  4287. this.selectTo(range.end.row, range.end.column);
  4288. }
  4289. if (this.getRange().isEmpty())
  4290. this.$isEmpty = true;
  4291. this.$desiredColumn = null;
  4292. };
  4293. this.$moveSelection = function(mover) {
  4294. var lead = this.lead;
  4295. if (this.$isEmpty)
  4296. this.setSelectionAnchor(lead.row, lead.column);
  4297. mover.call(this);
  4298. };
  4299. this.selectTo = function(row, column) {
  4300. this.$moveSelection(function() {
  4301. this.moveCursorTo(row, column);
  4302. });
  4303. };
  4304. this.selectToPosition = function(pos) {
  4305. this.$moveSelection(function() {
  4306. this.moveCursorToPosition(pos);
  4307. });
  4308. };
  4309. this.moveTo = function(row, column) {
  4310. this.clearSelection();
  4311. this.moveCursorTo(row, column);
  4312. };
  4313. this.moveToPosition = function(pos) {
  4314. this.clearSelection();
  4315. this.moveCursorToPosition(pos);
  4316. };
  4317. this.selectUp = function() {
  4318. this.$moveSelection(this.moveCursorUp);
  4319. };
  4320. this.selectDown = function() {
  4321. this.$moveSelection(this.moveCursorDown);
  4322. };
  4323. this.selectRight = function() {
  4324. this.$moveSelection(this.moveCursorRight);
  4325. };
  4326. this.selectLeft = function() {
  4327. this.$moveSelection(this.moveCursorLeft);
  4328. };
  4329. this.selectLineStart = function() {
  4330. this.$moveSelection(this.moveCursorLineStart);
  4331. };
  4332. this.selectLineEnd = function() {
  4333. this.$moveSelection(this.moveCursorLineEnd);
  4334. };
  4335. this.selectFileEnd = function() {
  4336. this.$moveSelection(this.moveCursorFileEnd);
  4337. };
  4338. this.selectFileStart = function() {
  4339. this.$moveSelection(this.moveCursorFileStart);
  4340. };
  4341. this.selectWordRight = function() {
  4342. this.$moveSelection(this.moveCursorWordRight);
  4343. };
  4344. this.selectWordLeft = function() {
  4345. this.$moveSelection(this.moveCursorWordLeft);
  4346. };
  4347. this.getWordRange = function(row, column) {
  4348. if (typeof column == "undefined") {
  4349. var cursor = row || this.lead;
  4350. row = cursor.row;
  4351. column = cursor.column;
  4352. }
  4353. return this.session.getWordRange(row, column);
  4354. };
  4355. this.selectWord = function() {
  4356. this.setSelectionRange(this.getWordRange());
  4357. };
  4358. this.selectAWord = function() {
  4359. var cursor = this.getCursor();
  4360. var range = this.session.getAWordRange(cursor.row, cursor.column);
  4361. this.setSelectionRange(range);
  4362. };
  4363. this.getLineRange = function(row, excludeLastChar) {
  4364. var rowStart = typeof row == "number" ? row : this.lead.row;
  4365. var rowEnd;
  4366. var foldLine = this.session.getFoldLine(rowStart);
  4367. if (foldLine) {
  4368. rowStart = foldLine.start.row;
  4369. rowEnd = foldLine.end.row;
  4370. } else {
  4371. rowEnd = rowStart;
  4372. }
  4373. if (excludeLastChar === true)
  4374. return new Range(rowStart, 0, rowEnd, this.session.getLine(rowEnd).length);
  4375. else
  4376. return new Range(rowStart, 0, rowEnd + 1, 0);
  4377. };
  4378. this.selectLine = function() {
  4379. this.setSelectionRange(this.getLineRange());
  4380. };
  4381. this.moveCursorUp = function() {
  4382. this.moveCursorBy(-1, 0);
  4383. };
  4384. this.moveCursorDown = function() {
  4385. this.moveCursorBy(1, 0);
  4386. };
  4387. this.wouldMoveIntoSoftTab = function(cursor, tabSize, direction) {
  4388. var start = cursor.column;
  4389. var end = cursor.column + tabSize;
  4390. if (direction < 0) {
  4391. start = cursor.column - tabSize;
  4392. end = cursor.column;
  4393. }
  4394. return this.session.isTabStop(cursor) && this.doc.getLine(cursor.row).slice(start, end).split(" ").length-1 == tabSize
  4395. }
  4396. this.moveCursorLeft = function() {
  4397. var cursor = this.lead.getPosition(),
  4398. fold;
  4399. if (fold = this.session.getFoldAt(cursor.row, cursor.column, -1)) {
  4400. this.moveCursorTo(fold.start.row, fold.start.column);
  4401. } else if (cursor.column === 0) {
  4402. if (cursor.row > 0) {
  4403. this.moveCursorTo(cursor.row - 1, this.doc.getLine(cursor.row - 1).length);
  4404. }
  4405. }
  4406. else {
  4407. var tabSize = this.session.getTabSize();
  4408. if (this.wouldMoveIntoSoftTab(cursor, tabSize, -1) && !this.session.getNavigateWithinSoftTabs()) {
  4409. this.moveCursorBy(0, -tabSize);
  4410. } else {
  4411. this.moveCursorBy(0, -1);
  4412. }
  4413. }
  4414. };
  4415. this.moveCursorRight = function() {
  4416. var cursor = this.lead.getPosition(),
  4417. fold;
  4418. if (fold = this.session.getFoldAt(cursor.row, cursor.column, 1)) {
  4419. this.moveCursorTo(fold.end.row, fold.end.column);
  4420. }
  4421. else if (this.lead.column == this.doc.getLine(this.lead.row).length) {
  4422. if (this.lead.row < this.doc.getLength() - 1) {
  4423. this.moveCursorTo(this.lead.row + 1, 0);
  4424. }
  4425. }
  4426. else {
  4427. var tabSize = this.session.getTabSize();
  4428. var cursor = this.lead;
  4429. if (this.wouldMoveIntoSoftTab(cursor, tabSize, 1) && !this.session.getNavigateWithinSoftTabs()) {
  4430. this.moveCursorBy(0, tabSize);
  4431. } else {
  4432. this.moveCursorBy(0, 1);
  4433. }
  4434. }
  4435. };
  4436. this.moveCursorLineStart = function() {
  4437. var row = this.lead.row;
  4438. var column = this.lead.column;
  4439. var screenRow = this.session.documentToScreenRow(row, column);
  4440. var firstColumnPosition = this.session.screenToDocumentPosition(screenRow, 0);
  4441. var beforeCursor = this.session.getDisplayLine(
  4442. row, null, firstColumnPosition.row,
  4443. firstColumnPosition.column
  4444. );
  4445. var leadingSpace = beforeCursor.match(/^\s*/);
  4446. if (leadingSpace[0].length != column && !this.session.$useEmacsStyleLineStart)
  4447. firstColumnPosition.column += leadingSpace[0].length;
  4448. this.moveCursorToPosition(firstColumnPosition);
  4449. };
  4450. this.moveCursorLineEnd = function() {
  4451. var lead = this.lead;
  4452. var lineEnd = this.session.getDocumentLastRowColumnPosition(lead.row, lead.column);
  4453. if (this.lead.column == lineEnd.column) {
  4454. var line = this.session.getLine(lineEnd.row);
  4455. if (lineEnd.column == line.length) {
  4456. var textEnd = line.search(/\s+$/);
  4457. if (textEnd > 0)
  4458. lineEnd.column = textEnd;
  4459. }
  4460. }
  4461. this.moveCursorTo(lineEnd.row, lineEnd.column);
  4462. };
  4463. this.moveCursorFileEnd = function() {
  4464. var row = this.doc.getLength() - 1;
  4465. var column = this.doc.getLine(row).length;
  4466. this.moveCursorTo(row, column);
  4467. };
  4468. this.moveCursorFileStart = function() {
  4469. this.moveCursorTo(0, 0);
  4470. };
  4471. this.moveCursorLongWordRight = function() {
  4472. var row = this.lead.row;
  4473. var column = this.lead.column;
  4474. var line = this.doc.getLine(row);
  4475. var rightOfCursor = line.substring(column);
  4476. var match;
  4477. this.session.nonTokenRe.lastIndex = 0;
  4478. this.session.tokenRe.lastIndex = 0;
  4479. var fold = this.session.getFoldAt(row, column, 1);
  4480. if (fold) {
  4481. this.moveCursorTo(fold.end.row, fold.end.column);
  4482. return;
  4483. }
  4484. if (match = this.session.nonTokenRe.exec(rightOfCursor)) {
  4485. column += this.session.nonTokenRe.lastIndex;
  4486. this.session.nonTokenRe.lastIndex = 0;
  4487. rightOfCursor = line.substring(column);
  4488. }
  4489. if (column >= line.length) {
  4490. this.moveCursorTo(row, line.length);
  4491. this.moveCursorRight();
  4492. if (row < this.doc.getLength() - 1)
  4493. this.moveCursorWordRight();
  4494. return;
  4495. }
  4496. if (match = this.session.tokenRe.exec(rightOfCursor)) {
  4497. column += this.session.tokenRe.lastIndex;
  4498. this.session.tokenRe.lastIndex = 0;
  4499. }
  4500. this.moveCursorTo(row, column);
  4501. };
  4502. this.moveCursorLongWordLeft = function() {
  4503. var row = this.lead.row;
  4504. var column = this.lead.column;
  4505. var fold;
  4506. if (fold = this.session.getFoldAt(row, column, -1)) {
  4507. this.moveCursorTo(fold.start.row, fold.start.column);
  4508. return;
  4509. }
  4510. var str = this.session.getFoldStringAt(row, column, -1);
  4511. if (str == null) {
  4512. str = this.doc.getLine(row).substring(0, column);
  4513. }
  4514. var leftOfCursor = lang.stringReverse(str);
  4515. var match;
  4516. this.session.nonTokenRe.lastIndex = 0;
  4517. this.session.tokenRe.lastIndex = 0;
  4518. if (match = this.session.nonTokenRe.exec(leftOfCursor)) {
  4519. column -= this.session.nonTokenRe.lastIndex;
  4520. leftOfCursor = leftOfCursor.slice(this.session.nonTokenRe.lastIndex);
  4521. this.session.nonTokenRe.lastIndex = 0;
  4522. }
  4523. if (column <= 0) {
  4524. this.moveCursorTo(row, 0);
  4525. this.moveCursorLeft();
  4526. if (row > 0)
  4527. this.moveCursorWordLeft();
  4528. return;
  4529. }
  4530. if (match = this.session.tokenRe.exec(leftOfCursor)) {
  4531. column -= this.session.tokenRe.lastIndex;
  4532. this.session.tokenRe.lastIndex = 0;
  4533. }
  4534. this.moveCursorTo(row, column);
  4535. };
  4536. this.$shortWordEndIndex = function(rightOfCursor) {
  4537. var match, index = 0, ch;
  4538. var whitespaceRe = /\s/;
  4539. var tokenRe = this.session.tokenRe;
  4540. tokenRe.lastIndex = 0;
  4541. if (match = this.session.tokenRe.exec(rightOfCursor)) {
  4542. index = this.session.tokenRe.lastIndex;
  4543. } else {
  4544. while ((ch = rightOfCursor[index]) && whitespaceRe.test(ch))
  4545. index ++;
  4546. if (index < 1) {
  4547. tokenRe.lastIndex = 0;
  4548. while ((ch = rightOfCursor[index]) && !tokenRe.test(ch)) {
  4549. tokenRe.lastIndex = 0;
  4550. index ++;
  4551. if (whitespaceRe.test(ch)) {
  4552. if (index > 2) {
  4553. index--;
  4554. break;
  4555. } else {
  4556. while ((ch = rightOfCursor[index]) && whitespaceRe.test(ch))
  4557. index ++;
  4558. if (index > 2)
  4559. break;
  4560. }
  4561. }
  4562. }
  4563. }
  4564. }
  4565. tokenRe.lastIndex = 0;
  4566. return index;
  4567. };
  4568. this.moveCursorShortWordRight = function() {
  4569. var row = this.lead.row;
  4570. var column = this.lead.column;
  4571. var line = this.doc.getLine(row);
  4572. var rightOfCursor = line.substring(column);
  4573. var fold = this.session.getFoldAt(row, column, 1);
  4574. if (fold)
  4575. return this.moveCursorTo(fold.end.row, fold.end.column);
  4576. if (column == line.length) {
  4577. var l = this.doc.getLength();
  4578. do {
  4579. row++;
  4580. rightOfCursor = this.doc.getLine(row);
  4581. } while (row < l && /^\s*$/.test(rightOfCursor));
  4582. if (!/^\s+/.test(rightOfCursor))
  4583. rightOfCursor = "";
  4584. column = 0;
  4585. }
  4586. var index = this.$shortWordEndIndex(rightOfCursor);
  4587. this.moveCursorTo(row, column + index);
  4588. };
  4589. this.moveCursorShortWordLeft = function() {
  4590. var row = this.lead.row;
  4591. var column = this.lead.column;
  4592. var fold;
  4593. if (fold = this.session.getFoldAt(row, column, -1))
  4594. return this.moveCursorTo(fold.start.row, fold.start.column);
  4595. var line = this.session.getLine(row).substring(0, column);
  4596. if (column === 0) {
  4597. do {
  4598. row--;
  4599. line = this.doc.getLine(row);
  4600. } while (row > 0 && /^\s*$/.test(line));
  4601. column = line.length;
  4602. if (!/\s+$/.test(line))
  4603. line = "";
  4604. }
  4605. var leftOfCursor = lang.stringReverse(line);
  4606. var index = this.$shortWordEndIndex(leftOfCursor);
  4607. return this.moveCursorTo(row, column - index);
  4608. };
  4609. this.moveCursorWordRight = function() {
  4610. if (this.session.$selectLongWords)
  4611. this.moveCursorLongWordRight();
  4612. else
  4613. this.moveCursorShortWordRight();
  4614. };
  4615. this.moveCursorWordLeft = function() {
  4616. if (this.session.$selectLongWords)
  4617. this.moveCursorLongWordLeft();
  4618. else
  4619. this.moveCursorShortWordLeft();
  4620. };
  4621. this.moveCursorBy = function(rows, chars) {
  4622. var screenPos = this.session.documentToScreenPosition(
  4623. this.lead.row,
  4624. this.lead.column
  4625. );
  4626. if (chars === 0) {
  4627. if (this.$desiredColumn)
  4628. screenPos.column = this.$desiredColumn;
  4629. else
  4630. this.$desiredColumn = screenPos.column;
  4631. }
  4632. var docPos = this.session.screenToDocumentPosition(screenPos.row + rows, screenPos.column);
  4633. if (rows !== 0 && chars === 0 && docPos.row === this.lead.row && docPos.column === this.lead.column) {
  4634. if (this.session.lineWidgets && this.session.lineWidgets[docPos.row]) {
  4635. if (docPos.row > 0 || rows > 0)
  4636. docPos.row++;
  4637. }
  4638. }
  4639. this.moveCursorTo(docPos.row, docPos.column + chars, chars === 0);
  4640. };
  4641. this.moveCursorToPosition = function(position) {
  4642. this.moveCursorTo(position.row, position.column);
  4643. };
  4644. this.moveCursorTo = function(row, column, keepDesiredColumn) {
  4645. var fold = this.session.getFoldAt(row, column, 1);
  4646. if (fold) {
  4647. row = fold.start.row;
  4648. column = fold.start.column;
  4649. }
  4650. this.$keepDesiredColumnOnChange = true;
  4651. this.lead.setPosition(row, column);
  4652. this.$keepDesiredColumnOnChange = false;
  4653. if (!keepDesiredColumn)
  4654. this.$desiredColumn = null;
  4655. };
  4656. this.moveCursorToScreen = function(row, column, keepDesiredColumn) {
  4657. var pos = this.session.screenToDocumentPosition(row, column);
  4658. this.moveCursorTo(pos.row, pos.column, keepDesiredColumn);
  4659. };
  4660. this.detach = function() {
  4661. this.lead.detach();
  4662. this.anchor.detach();
  4663. this.session = this.doc = null;
  4664. };
  4665. this.fromOrientedRange = function(range) {
  4666. this.setSelectionRange(range, range.cursor == range.start);
  4667. this.$desiredColumn = range.desiredColumn || this.$desiredColumn;
  4668. };
  4669. this.toOrientedRange = function(range) {
  4670. var r = this.getRange();
  4671. if (range) {
  4672. range.start.column = r.start.column;
  4673. range.start.row = r.start.row;
  4674. range.end.column = r.end.column;
  4675. range.end.row = r.end.row;
  4676. } else {
  4677. range = r;
  4678. }
  4679. range.cursor = this.isBackwards() ? range.start : range.end;
  4680. range.desiredColumn = this.$desiredColumn;
  4681. return range;
  4682. };
  4683. this.getRangeOfMovements = function(func) {
  4684. var start = this.getCursor();
  4685. try {
  4686. func(this);
  4687. var end = this.getCursor();
  4688. return Range.fromPoints(start,end);
  4689. } catch(e) {
  4690. return Range.fromPoints(start,start);
  4691. } finally {
  4692. this.moveCursorToPosition(start);
  4693. }
  4694. };
  4695. this.toJSON = function() {
  4696. if (this.rangeCount) {
  4697. var data = this.ranges.map(function(r) {
  4698. var r1 = r.clone();
  4699. r1.isBackwards = r.cursor == r.start;
  4700. return r1;
  4701. });
  4702. } else {
  4703. var data = this.getRange();
  4704. data.isBackwards = this.isBackwards();
  4705. }
  4706. return data;
  4707. };
  4708. this.fromJSON = function(data) {
  4709. if (data.start == undefined) {
  4710. if (this.rangeList) {
  4711. this.toSingleRange(data[0]);
  4712. for (var i = data.length; i--; ) {
  4713. var r = Range.fromPoints(data[i].start, data[i].end);
  4714. if (data[i].isBackwards)
  4715. r.cursor = r.start;
  4716. this.addRange(r, true);
  4717. }
  4718. return;
  4719. } else
  4720. data = data[0];
  4721. }
  4722. if (this.rangeList)
  4723. this.toSingleRange(data);
  4724. this.setSelectionRange(data, data.isBackwards);
  4725. };
  4726. this.isEqual = function(data) {
  4727. if ((data.length || this.rangeCount) && data.length != this.rangeCount)
  4728. return false;
  4729. if (!data.length || !this.ranges)
  4730. return this.getRange().isEqual(data);
  4731. for (var i = this.ranges.length; i--; ) {
  4732. if (!this.ranges[i].isEqual(data[i]))
  4733. return false;
  4734. }
  4735. return true;
  4736. };
  4737. }).call(Selection.prototype);
  4738. exports.Selection = Selection;
  4739. });
  4740. define("ace/tokenizer",["require","exports","module","ace/config"], function(require, exports, module) {
  4741. "use strict";
  4742. var config = require("./config");
  4743. var MAX_TOKEN_COUNT = 2000;
  4744. var Tokenizer = function(rules) {
  4745. this.states = rules;
  4746. this.regExps = {};
  4747. this.matchMappings = {};
  4748. for (var key in this.states) {
  4749. var state = this.states[key];
  4750. var ruleRegExps = [];
  4751. var matchTotal = 0;
  4752. var mapping = this.matchMappings[key] = {defaultToken: "text"};
  4753. var flag = "g";
  4754. var splitterRurles = [];
  4755. for (var i = 0; i < state.length; i++) {
  4756. var rule = state[i];
  4757. if (rule.defaultToken)
  4758. mapping.defaultToken = rule.defaultToken;
  4759. if (rule.caseInsensitive)
  4760. flag = "gi";
  4761. if (rule.regex == null)
  4762. continue;
  4763. if (rule.regex instanceof RegExp)
  4764. rule.regex = rule.regex.toString().slice(1, -1);
  4765. var adjustedregex = rule.regex;
  4766. var matchcount = new RegExp("(?:(" + adjustedregex + ")|(.))").exec("a").length - 2;
  4767. if (Array.isArray(rule.token)) {
  4768. if (rule.token.length == 1 || matchcount == 1) {
  4769. rule.token = rule.token[0];
  4770. } else if (matchcount - 1 != rule.token.length) {
  4771. this.reportError("number of classes and regexp groups doesn't match", {
  4772. rule: rule,
  4773. groupCount: matchcount - 1
  4774. });
  4775. rule.token = rule.token[0];
  4776. } else {
  4777. rule.tokenArray = rule.token;
  4778. rule.token = null;
  4779. rule.onMatch = this.$arrayTokens;
  4780. }
  4781. } else if (typeof rule.token == "function" && !rule.onMatch) {
  4782. if (matchcount > 1)
  4783. rule.onMatch = this.$applyToken;
  4784. else
  4785. rule.onMatch = rule.token;
  4786. }
  4787. if (matchcount > 1) {
  4788. if (/\\\d/.test(rule.regex)) {
  4789. adjustedregex = rule.regex.replace(/\\([0-9]+)/g, function(match, digit) {
  4790. return "\\" + (parseInt(digit, 10) + matchTotal + 1);
  4791. });
  4792. } else {
  4793. matchcount = 1;
  4794. adjustedregex = this.removeCapturingGroups(rule.regex);
  4795. }
  4796. if (!rule.splitRegex && typeof rule.token != "string")
  4797. splitterRurles.push(rule); // flag will be known only at the very end
  4798. }
  4799. mapping[matchTotal] = i;
  4800. matchTotal += matchcount;
  4801. ruleRegExps.push(adjustedregex);
  4802. if (!rule.onMatch)
  4803. rule.onMatch = null;
  4804. }
  4805. if (!ruleRegExps.length) {
  4806. mapping[0] = 0;
  4807. ruleRegExps.push("$");
  4808. }
  4809. splitterRurles.forEach(function(rule) {
  4810. rule.splitRegex = this.createSplitterRegexp(rule.regex, flag);
  4811. }, this);
  4812. this.regExps[key] = new RegExp("(" + ruleRegExps.join(")|(") + ")|($)", flag);
  4813. }
  4814. };
  4815. (function() {
  4816. this.$setMaxTokenCount = function(m) {
  4817. MAX_TOKEN_COUNT = m | 0;
  4818. };
  4819. this.$applyToken = function(str) {
  4820. var values = this.splitRegex.exec(str).slice(1);
  4821. var types = this.token.apply(this, values);
  4822. if (typeof types === "string")
  4823. return [{type: types, value: str}];
  4824. var tokens = [];
  4825. for (var i = 0, l = types.length; i < l; i++) {
  4826. if (values[i])
  4827. tokens[tokens.length] = {
  4828. type: types[i],
  4829. value: values[i]
  4830. };
  4831. }
  4832. return tokens;
  4833. };
  4834. this.$arrayTokens = function(str) {
  4835. if (!str)
  4836. return [];
  4837. var values = this.splitRegex.exec(str);
  4838. if (!values)
  4839. return "text";
  4840. var tokens = [];
  4841. var types = this.tokenArray;
  4842. for (var i = 0, l = types.length; i < l; i++) {
  4843. if (values[i + 1])
  4844. tokens[tokens.length] = {
  4845. type: types[i],
  4846. value: values[i + 1]
  4847. };
  4848. }
  4849. return tokens;
  4850. };
  4851. this.removeCapturingGroups = function(src) {
  4852. var r = src.replace(
  4853. /\[(?:\\.|[^\]])*?\]|\\.|\(\?[:=!]|(\()/g,
  4854. function(x, y) {return y ? "(?:" : x;}
  4855. );
  4856. return r;
  4857. };
  4858. this.createSplitterRegexp = function(src, flag) {
  4859. if (src.indexOf("(?=") != -1) {
  4860. var stack = 0;
  4861. var inChClass = false;
  4862. var lastCapture = {};
  4863. src.replace(/(\\.)|(\((?:\?[=!])?)|(\))|([\[\]])/g, function(
  4864. m, esc, parenOpen, parenClose, square, index
  4865. ) {
  4866. if (inChClass) {
  4867. inChClass = square != "]";
  4868. } else if (square) {
  4869. inChClass = true;
  4870. } else if (parenClose) {
  4871. if (stack == lastCapture.stack) {
  4872. lastCapture.end = index+1;
  4873. lastCapture.stack = -1;
  4874. }
  4875. stack--;
  4876. } else if (parenOpen) {
  4877. stack++;
  4878. if (parenOpen.length != 1) {
  4879. lastCapture.stack = stack
  4880. lastCapture.start = index;
  4881. }
  4882. }
  4883. return m;
  4884. });
  4885. if (lastCapture.end != null && /^\)*$/.test(src.substr(lastCapture.end)))
  4886. src = src.substring(0, lastCapture.start) + src.substr(lastCapture.end);
  4887. }
  4888. if (src.charAt(0) != "^") src = "^" + src;
  4889. if (src.charAt(src.length - 1) != "$") src += "$";
  4890. return new RegExp(src, (flag||"").replace("g", ""));
  4891. };
  4892. this.getLineTokens = function(line, startState) {
  4893. if (startState && typeof startState != "string") {
  4894. var stack = startState.slice(0);
  4895. startState = stack[0];
  4896. if (startState === "#tmp") {
  4897. stack.shift()
  4898. startState = stack.shift()
  4899. }
  4900. } else
  4901. var stack = [];
  4902. var currentState = startState || "start";
  4903. var state = this.states[currentState];
  4904. if (!state) {
  4905. currentState = "start";
  4906. state = this.states[currentState];
  4907. }
  4908. var mapping = this.matchMappings[currentState];
  4909. var re = this.regExps[currentState];
  4910. re.lastIndex = 0;
  4911. var match, tokens = [];
  4912. var lastIndex = 0;
  4913. var matchAttempts = 0;
  4914. var token = {type: null, value: ""};
  4915. while (match = re.exec(line)) {
  4916. var type = mapping.defaultToken;
  4917. var rule = null;
  4918. var value = match[0];
  4919. var index = re.lastIndex;
  4920. if (index - value.length > lastIndex) {
  4921. var skipped = line.substring(lastIndex, index - value.length);
  4922. if (token.type == type) {
  4923. token.value += skipped;
  4924. } else {
  4925. if (token.type)
  4926. tokens.push(token);
  4927. token = {type: type, value: skipped};
  4928. }
  4929. }
  4930. for (var i = 0; i < match.length-2; i++) {
  4931. if (match[i + 1] === undefined)
  4932. continue;
  4933. rule = state[mapping[i]];
  4934. if (rule.onMatch)
  4935. type = rule.onMatch(value, currentState, stack, line);
  4936. else
  4937. type = rule.token;
  4938. if (rule.next) {
  4939. if (typeof rule.next == "string") {
  4940. currentState = rule.next;
  4941. } else {
  4942. currentState = rule.next(currentState, stack);
  4943. }
  4944. state = this.states[currentState];
  4945. if (!state) {
  4946. this.reportError("state doesn't exist", currentState);
  4947. currentState = "start";
  4948. state = this.states[currentState];
  4949. }
  4950. mapping = this.matchMappings[currentState];
  4951. lastIndex = index;
  4952. re = this.regExps[currentState];
  4953. re.lastIndex = index;
  4954. }
  4955. if (rule.consumeLineEnd)
  4956. lastIndex = index;
  4957. break;
  4958. }
  4959. if (value) {
  4960. if (typeof type === "string") {
  4961. if ((!rule || rule.merge !== false) && token.type === type) {
  4962. token.value += value;
  4963. } else {
  4964. if (token.type)
  4965. tokens.push(token);
  4966. token = {type: type, value: value};
  4967. }
  4968. } else if (type) {
  4969. if (token.type)
  4970. tokens.push(token);
  4971. token = {type: null, value: ""};
  4972. for (var i = 0; i < type.length; i++)
  4973. tokens.push(type[i]);
  4974. }
  4975. }
  4976. if (lastIndex == line.length)
  4977. break;
  4978. lastIndex = index;
  4979. if (matchAttempts++ > MAX_TOKEN_COUNT) {
  4980. if (matchAttempts > 2 * line.length) {
  4981. this.reportError("infinite loop with in ace tokenizer", {
  4982. startState: startState,
  4983. line: line
  4984. });
  4985. }
  4986. while (lastIndex < line.length) {
  4987. if (token.type)
  4988. tokens.push(token);
  4989. token = {
  4990. value: line.substring(lastIndex, lastIndex += 2000),
  4991. type: "overflow"
  4992. };
  4993. }
  4994. currentState = "start";
  4995. stack = [];
  4996. break;
  4997. }
  4998. }
  4999. if (token.type)
  5000. tokens.push(token);
  5001. if (stack.length > 1) {
  5002. if (stack[0] !== currentState)
  5003. stack.unshift("#tmp", currentState);
  5004. }
  5005. return {
  5006. tokens : tokens,
  5007. state : stack.length ? stack : currentState
  5008. };
  5009. };
  5010. this.reportError = config.reportError;
  5011. }).call(Tokenizer.prototype);
  5012. exports.Tokenizer = Tokenizer;
  5013. });
  5014. define("ace/mode/text_highlight_rules",["require","exports","module","ace/lib/lang"], function(require, exports, module) {
  5015. "use strict";
  5016. var lang = require("../lib/lang");
  5017. var TextHighlightRules = function() {
  5018. this.$rules = {
  5019. "start" : [{
  5020. token : "empty_line",
  5021. regex : '^$'
  5022. }, {
  5023. defaultToken : "text"
  5024. }]
  5025. };
  5026. };
  5027. (function() {
  5028. this.addRules = function(rules, prefix) {
  5029. if (!prefix) {
  5030. for (var key in rules)
  5031. this.$rules[key] = rules[key];
  5032. return;
  5033. }
  5034. for (var key in rules) {
  5035. var state = rules[key];
  5036. for (var i = 0; i < state.length; i++) {
  5037. var rule = state[i];
  5038. if (rule.next || rule.onMatch) {
  5039. if (typeof rule.next == "string") {
  5040. if (rule.next.indexOf(prefix) !== 0)
  5041. rule.next = prefix + rule.next;
  5042. }
  5043. if (rule.nextState && rule.nextState.indexOf(prefix) !== 0)
  5044. rule.nextState = prefix + rule.nextState;
  5045. }
  5046. }
  5047. this.$rules[prefix + key] = state;
  5048. }
  5049. };
  5050. this.getRules = function() {
  5051. return this.$rules;
  5052. };
  5053. this.embedRules = function (HighlightRules, prefix, escapeRules, states, append) {
  5054. var embedRules = typeof HighlightRules == "function"
  5055. ? new HighlightRules().getRules()
  5056. : HighlightRules;
  5057. if (states) {
  5058. for (var i = 0; i < states.length; i++)
  5059. states[i] = prefix + states[i];
  5060. } else {
  5061. states = [];
  5062. for (var key in embedRules)
  5063. states.push(prefix + key);
  5064. }
  5065. this.addRules(embedRules, prefix);
  5066. if (escapeRules) {
  5067. var addRules = Array.prototype[append ? "push" : "unshift"];
  5068. for (var i = 0; i < states.length; i++)
  5069. addRules.apply(this.$rules[states[i]], lang.deepCopy(escapeRules));
  5070. }
  5071. if (!this.$embeds)
  5072. this.$embeds = [];
  5073. this.$embeds.push(prefix);
  5074. };
  5075. this.getEmbeds = function() {
  5076. return this.$embeds;
  5077. };
  5078. var pushState = function(currentState, stack) {
  5079. if (currentState != "start" || stack.length)
  5080. stack.unshift(this.nextState, currentState);
  5081. return this.nextState;
  5082. };
  5083. var popState = function(currentState, stack) {
  5084. stack.shift();
  5085. return stack.shift() || "start";
  5086. };
  5087. this.normalizeRules = function() {
  5088. var id = 0;
  5089. var rules = this.$rules;
  5090. function processState(key) {
  5091. var state = rules[key];
  5092. state.processed = true;
  5093. for (var i = 0; i < state.length; i++) {
  5094. var rule = state[i];
  5095. var toInsert = null;
  5096. if (Array.isArray(rule)) {
  5097. toInsert = rule;
  5098. rule = {};
  5099. }
  5100. if (!rule.regex && rule.start) {
  5101. rule.regex = rule.start;
  5102. if (!rule.next)
  5103. rule.next = [];
  5104. rule.next.push({
  5105. defaultToken: rule.token
  5106. }, {
  5107. token: rule.token + ".end",
  5108. regex: rule.end || rule.start,
  5109. next: "pop"
  5110. });
  5111. rule.token = rule.token + ".start";
  5112. rule.push = true;
  5113. }
  5114. var next = rule.next || rule.push;
  5115. if (next && Array.isArray(next)) {
  5116. var stateName = rule.stateName;
  5117. if (!stateName) {
  5118. stateName = rule.token;
  5119. if (typeof stateName != "string")
  5120. stateName = stateName[0] || "";
  5121. if (rules[stateName])
  5122. stateName += id++;
  5123. }
  5124. rules[stateName] = next;
  5125. rule.next = stateName;
  5126. processState(stateName);
  5127. } else if (next == "pop") {
  5128. rule.next = popState;
  5129. }
  5130. if (rule.push) {
  5131. rule.nextState = rule.next || rule.push;
  5132. rule.next = pushState;
  5133. delete rule.push;
  5134. }
  5135. if (rule.rules) {
  5136. for (var r in rule.rules) {
  5137. if (rules[r]) {
  5138. if (rules[r].push)
  5139. rules[r].push.apply(rules[r], rule.rules[r]);
  5140. } else {
  5141. rules[r] = rule.rules[r];
  5142. }
  5143. }
  5144. }
  5145. var includeName = typeof rule == "string" ? rule : rule.include;
  5146. if (includeName) {
  5147. if (Array.isArray(includeName))
  5148. toInsert = includeName.map(function(x) { return rules[x]; });
  5149. else
  5150. toInsert = rules[includeName];
  5151. }
  5152. if (toInsert) {
  5153. var args = [i, 1].concat(toInsert);
  5154. if (rule.noEscape)
  5155. args = args.filter(function(x) {return !x.next;});
  5156. state.splice.apply(state, args);
  5157. i--;
  5158. }
  5159. if (rule.keywordMap) {
  5160. rule.token = this.createKeywordMapper(
  5161. rule.keywordMap, rule.defaultToken || "text", rule.caseInsensitive
  5162. );
  5163. delete rule.defaultToken;
  5164. }
  5165. }
  5166. }
  5167. Object.keys(rules).forEach(processState, this);
  5168. };
  5169. this.createKeywordMapper = function(map, defaultToken, ignoreCase, splitChar) {
  5170. var keywords = Object.create(null);
  5171. Object.keys(map).forEach(function(className) {
  5172. var a = map[className];
  5173. if (ignoreCase)
  5174. a = a.toLowerCase();
  5175. var list = a.split(splitChar || "|");
  5176. for (var i = list.length; i--; )
  5177. keywords[list[i]] = className;
  5178. });
  5179. if (Object.getPrototypeOf(keywords)) {
  5180. keywords.__proto__ = null;
  5181. }
  5182. this.$keywordList = Object.keys(keywords);
  5183. map = null;
  5184. return ignoreCase
  5185. ? function(value) {return keywords[value.toLowerCase()] || defaultToken }
  5186. : function(value) {return keywords[value] || defaultToken };
  5187. };
  5188. this.getKeywords = function() {
  5189. return this.$keywords;
  5190. };
  5191. }).call(TextHighlightRules.prototype);
  5192. exports.TextHighlightRules = TextHighlightRules;
  5193. });
  5194. define("ace/mode/behaviour",["require","exports","module"], function(require, exports, module) {
  5195. "use strict";
  5196. var Behaviour = function() {
  5197. this.$behaviours = {};
  5198. };
  5199. (function () {
  5200. this.add = function (name, action, callback) {
  5201. switch (undefined) {
  5202. case this.$behaviours:
  5203. this.$behaviours = {};
  5204. case this.$behaviours[name]:
  5205. this.$behaviours[name] = {};
  5206. }
  5207. this.$behaviours[name][action] = callback;
  5208. }
  5209. this.addBehaviours = function (behaviours) {
  5210. for (var key in behaviours) {
  5211. for (var action in behaviours[key]) {
  5212. this.add(key, action, behaviours[key][action]);
  5213. }
  5214. }
  5215. }
  5216. this.remove = function (name) {
  5217. if (this.$behaviours && this.$behaviours[name]) {
  5218. delete this.$behaviours[name];
  5219. }
  5220. }
  5221. this.inherit = function (mode, filter) {
  5222. if (typeof mode === "function") {
  5223. var behaviours = new mode().getBehaviours(filter);
  5224. } else {
  5225. var behaviours = mode.getBehaviours(filter);
  5226. }
  5227. this.addBehaviours(behaviours);
  5228. }
  5229. this.getBehaviours = function (filter) {
  5230. if (!filter) {
  5231. return this.$behaviours;
  5232. } else {
  5233. var ret = {}
  5234. for (var i = 0; i < filter.length; i++) {
  5235. if (this.$behaviours[filter[i]]) {
  5236. ret[filter[i]] = this.$behaviours[filter[i]];
  5237. }
  5238. }
  5239. return ret;
  5240. }
  5241. }
  5242. }).call(Behaviour.prototype);
  5243. exports.Behaviour = Behaviour;
  5244. });
  5245. define("ace/token_iterator",["require","exports","module"], function(require, exports, module) {
  5246. "use strict";
  5247. var TokenIterator = function(session, initialRow, initialColumn) {
  5248. this.$session = session;
  5249. this.$row = initialRow;
  5250. this.$rowTokens = session.getTokens(initialRow);
  5251. var token = session.getTokenAt(initialRow, initialColumn);
  5252. this.$tokenIndex = token ? token.index : -1;
  5253. };
  5254. (function() {
  5255. this.stepBackward = function() {
  5256. this.$tokenIndex -= 1;
  5257. while (this.$tokenIndex < 0) {
  5258. this.$row -= 1;
  5259. if (this.$row < 0) {
  5260. this.$row = 0;
  5261. return null;
  5262. }
  5263. this.$rowTokens = this.$session.getTokens(this.$row);
  5264. this.$tokenIndex = this.$rowTokens.length - 1;
  5265. }
  5266. return this.$rowTokens[this.$tokenIndex];
  5267. };
  5268. this.stepForward = function() {
  5269. this.$tokenIndex += 1;
  5270. var rowCount;
  5271. while (this.$tokenIndex >= this.$rowTokens.length) {
  5272. this.$row += 1;
  5273. if (!rowCount)
  5274. rowCount = this.$session.getLength();
  5275. if (this.$row >= rowCount) {
  5276. this.$row = rowCount - 1;
  5277. return null;
  5278. }
  5279. this.$rowTokens = this.$session.getTokens(this.$row);
  5280. this.$tokenIndex = 0;
  5281. }
  5282. return this.$rowTokens[this.$tokenIndex];
  5283. };
  5284. this.getCurrentToken = function () {
  5285. return this.$rowTokens[this.$tokenIndex];
  5286. };
  5287. this.getCurrentTokenRow = function () {
  5288. return this.$row;
  5289. };
  5290. this.getCurrentTokenColumn = function() {
  5291. var rowTokens = this.$rowTokens;
  5292. var tokenIndex = this.$tokenIndex;
  5293. var column = rowTokens[tokenIndex].start;
  5294. if (column !== undefined)
  5295. return column;
  5296. column = 0;
  5297. while (tokenIndex > 0) {
  5298. tokenIndex -= 1;
  5299. column += rowTokens[tokenIndex].value.length;
  5300. }
  5301. return column;
  5302. };
  5303. this.getCurrentTokenPosition = function() {
  5304. return {row: this.$row, column: this.getCurrentTokenColumn()};
  5305. };
  5306. }).call(TokenIterator.prototype);
  5307. exports.TokenIterator = TokenIterator;
  5308. });
  5309. define("ace/mode/behaviour/cstyle",["require","exports","module","ace/lib/oop","ace/mode/behaviour","ace/token_iterator","ace/lib/lang"], function(require, exports, module) {
  5310. "use strict";
  5311. var oop = require("../../lib/oop");
  5312. var Behaviour = require("../behaviour").Behaviour;
  5313. var TokenIterator = require("../../token_iterator").TokenIterator;
  5314. var lang = require("../../lib/lang");
  5315. var SAFE_INSERT_IN_TOKENS =
  5316. ["text", "paren.rparen", "punctuation.operator"];
  5317. var SAFE_INSERT_BEFORE_TOKENS =
  5318. ["text", "paren.rparen", "punctuation.operator", "comment"];
  5319. var context;
  5320. var contextCache = {};
  5321. var defaultQuotes = {'"' : '"', "'" : "'"};
  5322. var initContext = function(editor) {
  5323. var id = -1;
  5324. if (editor.multiSelect) {
  5325. id = editor.selection.index;
  5326. if (contextCache.rangeCount != editor.multiSelect.rangeCount)
  5327. contextCache = {rangeCount: editor.multiSelect.rangeCount};
  5328. }
  5329. if (contextCache[id])
  5330. return context = contextCache[id];
  5331. context = contextCache[id] = {
  5332. autoInsertedBrackets: 0,
  5333. autoInsertedRow: -1,
  5334. autoInsertedLineEnd: "",
  5335. maybeInsertedBrackets: 0,
  5336. maybeInsertedRow: -1,
  5337. maybeInsertedLineStart: "",
  5338. maybeInsertedLineEnd: ""
  5339. };
  5340. };
  5341. var getWrapped = function(selection, selected, opening, closing) {
  5342. var rowDiff = selection.end.row - selection.start.row;
  5343. return {
  5344. text: opening + selected + closing,
  5345. selection: [
  5346. 0,
  5347. selection.start.column + 1,
  5348. rowDiff,
  5349. selection.end.column + (rowDiff ? 0 : 1)
  5350. ]
  5351. };
  5352. };
  5353. var CstyleBehaviour = function(options) {
  5354. this.add("braces", "insertion", function(state, action, editor, session, text) {
  5355. var cursor = editor.getCursorPosition();
  5356. var line = session.doc.getLine(cursor.row);
  5357. if (text == '{') {
  5358. initContext(editor);
  5359. var selection = editor.getSelectionRange();
  5360. var selected = session.doc.getTextRange(selection);
  5361. if (selected !== "" && selected !== "{" && editor.getWrapBehavioursEnabled()) {
  5362. return getWrapped(selection, selected, '{', '}');
  5363. } else if (CstyleBehaviour.isSaneInsertion(editor, session)) {
  5364. if (/[\]\}\)]/.test(line[cursor.column]) || editor.inMultiSelectMode || options && options.braces) {
  5365. CstyleBehaviour.recordAutoInsert(editor, session, "}");
  5366. return {
  5367. text: '{}',
  5368. selection: [1, 1]
  5369. };
  5370. } else {
  5371. CstyleBehaviour.recordMaybeInsert(editor, session, "{");
  5372. return {
  5373. text: '{',
  5374. selection: [1, 1]
  5375. };
  5376. }
  5377. }
  5378. } else if (text == '}') {
  5379. initContext(editor);
  5380. var rightChar = line.substring(cursor.column, cursor.column + 1);
  5381. if (rightChar == '}') {
  5382. var matching = session.$findOpeningBracket('}', {column: cursor.column + 1, row: cursor.row});
  5383. if (matching !== null && CstyleBehaviour.isAutoInsertedClosing(cursor, line, text)) {
  5384. CstyleBehaviour.popAutoInsertedClosing();
  5385. return {
  5386. text: '',
  5387. selection: [1, 1]
  5388. };
  5389. }
  5390. }
  5391. } else if (text == "\n" || text == "\r\n") {
  5392. initContext(editor);
  5393. var closing = "";
  5394. if (CstyleBehaviour.isMaybeInsertedClosing(cursor, line)) {
  5395. closing = lang.stringRepeat("}", context.maybeInsertedBrackets);
  5396. CstyleBehaviour.clearMaybeInsertedClosing();
  5397. }
  5398. var rightChar = line.substring(cursor.column, cursor.column + 1);
  5399. if (rightChar === '}') {
  5400. var openBracePos = session.findMatchingBracket({row: cursor.row, column: cursor.column+1}, '}');
  5401. if (!openBracePos)
  5402. return null;
  5403. var next_indent = this.$getIndent(session.getLine(openBracePos.row));
  5404. } else if (closing) {
  5405. var next_indent = this.$getIndent(line);
  5406. } else {
  5407. CstyleBehaviour.clearMaybeInsertedClosing();
  5408. return;
  5409. }
  5410. var indent = next_indent + session.getTabString();
  5411. return {
  5412. text: '\n' + indent + '\n' + next_indent + closing,
  5413. selection: [1, indent.length, 1, indent.length]
  5414. };
  5415. } else {
  5416. CstyleBehaviour.clearMaybeInsertedClosing();
  5417. }
  5418. });
  5419. this.add("braces", "deletion", function(state, action, editor, session, range) {
  5420. var selected = session.doc.getTextRange(range);
  5421. if (!range.isMultiLine() && selected == '{') {
  5422. initContext(editor);
  5423. var line = session.doc.getLine(range.start.row);
  5424. var rightChar = line.substring(range.end.column, range.end.column + 1);
  5425. if (rightChar == '}') {
  5426. range.end.column++;
  5427. return range;
  5428. } else {
  5429. context.maybeInsertedBrackets--;
  5430. }
  5431. }
  5432. });
  5433. this.add("parens", "insertion", function(state, action, editor, session, text) {
  5434. if (text == '(') {
  5435. initContext(editor);
  5436. var selection = editor.getSelectionRange();
  5437. var selected = session.doc.getTextRange(selection);
  5438. if (selected !== "" && editor.getWrapBehavioursEnabled()) {
  5439. return getWrapped(selection, selected, '(', ')');
  5440. } else if (CstyleBehaviour.isSaneInsertion(editor, session)) {
  5441. CstyleBehaviour.recordAutoInsert(editor, session, ")");
  5442. return {
  5443. text: '()',
  5444. selection: [1, 1]
  5445. };
  5446. }
  5447. } else if (text == ')') {
  5448. initContext(editor);
  5449. var cursor = editor.getCursorPosition();
  5450. var line = session.doc.getLine(cursor.row);
  5451. var rightChar = line.substring(cursor.column, cursor.column + 1);
  5452. if (rightChar == ')') {
  5453. var matching = session.$findOpeningBracket(')', {column: cursor.column + 1, row: cursor.row});
  5454. if (matching !== null && CstyleBehaviour.isAutoInsertedClosing(cursor, line, text)) {
  5455. CstyleBehaviour.popAutoInsertedClosing();
  5456. return {
  5457. text: '',
  5458. selection: [1, 1]
  5459. };
  5460. }
  5461. }
  5462. }
  5463. });
  5464. this.add("parens", "deletion", function(state, action, editor, session, range) {
  5465. var selected = session.doc.getTextRange(range);
  5466. if (!range.isMultiLine() && selected == '(') {
  5467. initContext(editor);
  5468. var line = session.doc.getLine(range.start.row);
  5469. var rightChar = line.substring(range.start.column + 1, range.start.column + 2);
  5470. if (rightChar == ')') {
  5471. range.end.column++;
  5472. return range;
  5473. }
  5474. }
  5475. });
  5476. this.add("brackets", "insertion", function(state, action, editor, session, text) {
  5477. if (text == '[') {
  5478. initContext(editor);
  5479. var selection = editor.getSelectionRange();
  5480. var selected = session.doc.getTextRange(selection);
  5481. if (selected !== "" && editor.getWrapBehavioursEnabled()) {
  5482. return getWrapped(selection, selected, '[', ']');
  5483. } else if (CstyleBehaviour.isSaneInsertion(editor, session)) {
  5484. CstyleBehaviour.recordAutoInsert(editor, session, "]");
  5485. return {
  5486. text: '[]',
  5487. selection: [1, 1]
  5488. };
  5489. }
  5490. } else if (text == ']') {
  5491. initContext(editor);
  5492. var cursor = editor.getCursorPosition();
  5493. var line = session.doc.getLine(cursor.row);
  5494. var rightChar = line.substring(cursor.column, cursor.column + 1);
  5495. if (rightChar == ']') {
  5496. var matching = session.$findOpeningBracket(']', {column: cursor.column + 1, row: cursor.row});
  5497. if (matching !== null && CstyleBehaviour.isAutoInsertedClosing(cursor, line, text)) {
  5498. CstyleBehaviour.popAutoInsertedClosing();
  5499. return {
  5500. text: '',
  5501. selection: [1, 1]
  5502. };
  5503. }
  5504. }
  5505. }
  5506. });
  5507. this.add("brackets", "deletion", function(state, action, editor, session, range) {
  5508. var selected = session.doc.getTextRange(range);
  5509. if (!range.isMultiLine() && selected == '[') {
  5510. initContext(editor);
  5511. var line = session.doc.getLine(range.start.row);
  5512. var rightChar = line.substring(range.start.column + 1, range.start.column + 2);
  5513. if (rightChar == ']') {
  5514. range.end.column++;
  5515. return range;
  5516. }
  5517. }
  5518. });
  5519. this.add("string_dquotes", "insertion", function(state, action, editor, session, text) {
  5520. var quotes = session.$mode.$quotes || defaultQuotes;
  5521. if (text.length == 1 && quotes[text]) {
  5522. if (this.lineCommentStart && this.lineCommentStart.indexOf(text) != -1)
  5523. return;
  5524. initContext(editor);
  5525. var quote = text;
  5526. var selection = editor.getSelectionRange();
  5527. var selected = session.doc.getTextRange(selection);
  5528. if (selected !== "" && (selected.length != 1 || !quotes[selected]) && editor.getWrapBehavioursEnabled()) {
  5529. return getWrapped(selection, selected, quote, quote);
  5530. } else if (!selected) {
  5531. var cursor = editor.getCursorPosition();
  5532. var line = session.doc.getLine(cursor.row);
  5533. var leftChar = line.substring(cursor.column-1, cursor.column);
  5534. var rightChar = line.substring(cursor.column, cursor.column + 1);
  5535. var token = session.getTokenAt(cursor.row, cursor.column);
  5536. var rightToken = session.getTokenAt(cursor.row, cursor.column + 1);
  5537. if (leftChar == "\\" && token && /escape/.test(token.type))
  5538. return null;
  5539. var stringBefore = token && /string|escape/.test(token.type);
  5540. var stringAfter = !rightToken || /string|escape/.test(rightToken.type);
  5541. var pair;
  5542. if (rightChar == quote) {
  5543. pair = stringBefore !== stringAfter;
  5544. if (pair && /string\.end/.test(rightToken.type))
  5545. pair = false;
  5546. } else {
  5547. if (stringBefore && !stringAfter)
  5548. return null; // wrap string with different quote
  5549. if (stringBefore && stringAfter)
  5550. return null; // do not pair quotes inside strings
  5551. var wordRe = session.$mode.tokenRe;
  5552. wordRe.lastIndex = 0;
  5553. var isWordBefore = wordRe.test(leftChar);
  5554. wordRe.lastIndex = 0;
  5555. var isWordAfter = wordRe.test(leftChar);
  5556. if (isWordBefore || isWordAfter)
  5557. return null; // before or after alphanumeric
  5558. if (rightChar && !/[\s;,.})\]\\]/.test(rightChar))
  5559. return null; // there is rightChar and it isn't closing
  5560. pair = true;
  5561. }
  5562. return {
  5563. text: pair ? quote + quote : "",
  5564. selection: [1,1]
  5565. };
  5566. }
  5567. }
  5568. });
  5569. this.add("string_dquotes", "deletion", function(state, action, editor, session, range) {
  5570. var selected = session.doc.getTextRange(range);
  5571. if (!range.isMultiLine() && (selected == '"' || selected == "'")) {
  5572. initContext(editor);
  5573. var line = session.doc.getLine(range.start.row);
  5574. var rightChar = line.substring(range.start.column + 1, range.start.column + 2);
  5575. if (rightChar == selected) {
  5576. range.end.column++;
  5577. return range;
  5578. }
  5579. }
  5580. });
  5581. };
  5582. CstyleBehaviour.isSaneInsertion = function(editor, session) {
  5583. var cursor = editor.getCursorPosition();
  5584. var iterator = new TokenIterator(session, cursor.row, cursor.column);
  5585. if (!this.$matchTokenType(iterator.getCurrentToken() || "text", SAFE_INSERT_IN_TOKENS)) {
  5586. var iterator2 = new TokenIterator(session, cursor.row, cursor.column + 1);
  5587. if (!this.$matchTokenType(iterator2.getCurrentToken() || "text", SAFE_INSERT_IN_TOKENS))
  5588. return false;
  5589. }
  5590. iterator.stepForward();
  5591. return iterator.getCurrentTokenRow() !== cursor.row ||
  5592. this.$matchTokenType(iterator.getCurrentToken() || "text", SAFE_INSERT_BEFORE_TOKENS);
  5593. };
  5594. CstyleBehaviour.$matchTokenType = function(token, types) {
  5595. return types.indexOf(token.type || token) > -1;
  5596. };
  5597. CstyleBehaviour.recordAutoInsert = function(editor, session, bracket) {
  5598. var cursor = editor.getCursorPosition();
  5599. var line = session.doc.getLine(cursor.row);
  5600. if (!this.isAutoInsertedClosing(cursor, line, context.autoInsertedLineEnd[0]))
  5601. context.autoInsertedBrackets = 0;
  5602. context.autoInsertedRow = cursor.row;
  5603. context.autoInsertedLineEnd = bracket + line.substr(cursor.column);
  5604. context.autoInsertedBrackets++;
  5605. };
  5606. CstyleBehaviour.recordMaybeInsert = function(editor, session, bracket) {
  5607. var cursor = editor.getCursorPosition();
  5608. var line = session.doc.getLine(cursor.row);
  5609. if (!this.isMaybeInsertedClosing(cursor, line))
  5610. context.maybeInsertedBrackets = 0;
  5611. context.maybeInsertedRow = cursor.row;
  5612. context.maybeInsertedLineStart = line.substr(0, cursor.column) + bracket;
  5613. context.maybeInsertedLineEnd = line.substr(cursor.column);
  5614. context.maybeInsertedBrackets++;
  5615. };
  5616. CstyleBehaviour.isAutoInsertedClosing = function(cursor, line, bracket) {
  5617. return context.autoInsertedBrackets > 0 &&
  5618. cursor.row === context.autoInsertedRow &&
  5619. bracket === context.autoInsertedLineEnd[0] &&
  5620. line.substr(cursor.column) === context.autoInsertedLineEnd;
  5621. };
  5622. CstyleBehaviour.isMaybeInsertedClosing = function(cursor, line) {
  5623. return context.maybeInsertedBrackets > 0 &&
  5624. cursor.row === context.maybeInsertedRow &&
  5625. line.substr(cursor.column) === context.maybeInsertedLineEnd &&
  5626. line.substr(0, cursor.column) == context.maybeInsertedLineStart;
  5627. };
  5628. CstyleBehaviour.popAutoInsertedClosing = function() {
  5629. context.autoInsertedLineEnd = context.autoInsertedLineEnd.substr(1);
  5630. context.autoInsertedBrackets--;
  5631. };
  5632. CstyleBehaviour.clearMaybeInsertedClosing = function() {
  5633. if (context) {
  5634. context.maybeInsertedBrackets = 0;
  5635. context.maybeInsertedRow = -1;
  5636. }
  5637. };
  5638. oop.inherits(CstyleBehaviour, Behaviour);
  5639. exports.CstyleBehaviour = CstyleBehaviour;
  5640. });
  5641. define("ace/unicode",["require","exports","module"], function(require, exports, module) {
  5642. "use strict";
  5643. exports.packages = {};
  5644. addUnicodePackage({
  5645. L: "0041-005A0061-007A00AA00B500BA00C0-00D600D8-00F600F8-02C102C6-02D102E0-02E402EC02EE0370-037403760377037A-037D03860388-038A038C038E-03A103A3-03F503F7-0481048A-05250531-055605590561-058705D0-05EA05F0-05F20621-064A066E066F0671-06D306D506E506E606EE06EF06FA-06FC06FF07100712-072F074D-07A507B107CA-07EA07F407F507FA0800-0815081A082408280904-0939093D09500958-0961097109720979-097F0985-098C098F09900993-09A809AA-09B009B209B6-09B909BD09CE09DC09DD09DF-09E109F009F10A05-0A0A0A0F0A100A13-0A280A2A-0A300A320A330A350A360A380A390A59-0A5C0A5E0A72-0A740A85-0A8D0A8F-0A910A93-0AA80AAA-0AB00AB20AB30AB5-0AB90ABD0AD00AE00AE10B05-0B0C0B0F0B100B13-0B280B2A-0B300B320B330B35-0B390B3D0B5C0B5D0B5F-0B610B710B830B85-0B8A0B8E-0B900B92-0B950B990B9A0B9C0B9E0B9F0BA30BA40BA8-0BAA0BAE-0BB90BD00C05-0C0C0C0E-0C100C12-0C280C2A-0C330C35-0C390C3D0C580C590C600C610C85-0C8C0C8E-0C900C92-0CA80CAA-0CB30CB5-0CB90CBD0CDE0CE00CE10D05-0D0C0D0E-0D100D12-0D280D2A-0D390D3D0D600D610D7A-0D7F0D85-0D960D9A-0DB10DB3-0DBB0DBD0DC0-0DC60E01-0E300E320E330E40-0E460E810E820E840E870E880E8A0E8D0E94-0E970E99-0E9F0EA1-0EA30EA50EA70EAA0EAB0EAD-0EB00EB20EB30EBD0EC0-0EC40EC60EDC0EDD0F000F40-0F470F49-0F6C0F88-0F8B1000-102A103F1050-1055105A-105D106110651066106E-10701075-1081108E10A0-10C510D0-10FA10FC1100-1248124A-124D1250-12561258125A-125D1260-1288128A-128D1290-12B012B2-12B512B8-12BE12C012C2-12C512C8-12D612D8-13101312-13151318-135A1380-138F13A0-13F41401-166C166F-167F1681-169A16A0-16EA1700-170C170E-17111720-17311740-17511760-176C176E-17701780-17B317D717DC1820-18771880-18A818AA18B0-18F51900-191C1950-196D1970-19741980-19AB19C1-19C71A00-1A161A20-1A541AA71B05-1B331B45-1B4B1B83-1BA01BAE1BAF1C00-1C231C4D-1C4F1C5A-1C7D1CE9-1CEC1CEE-1CF11D00-1DBF1E00-1F151F18-1F1D1F20-1F451F48-1F4D1F50-1F571F591F5B1F5D1F5F-1F7D1F80-1FB41FB6-1FBC1FBE1FC2-1FC41FC6-1FCC1FD0-1FD31FD6-1FDB1FE0-1FEC1FF2-1FF41FF6-1FFC2071207F2090-209421022107210A-211321152119-211D212421262128212A-212D212F-2139213C-213F2145-2149214E218321842C00-2C2E2C30-2C5E2C60-2CE42CEB-2CEE2D00-2D252D30-2D652D6F2D80-2D962DA0-2DA62DA8-2DAE2DB0-2DB62DB8-2DBE2DC0-2DC62DC8-2DCE2DD0-2DD62DD8-2DDE2E2F300530063031-3035303B303C3041-3096309D-309F30A1-30FA30FC-30FF3105-312D3131-318E31A0-31B731F0-31FF3400-4DB54E00-9FCBA000-A48CA4D0-A4FDA500-A60CA610-A61FA62AA62BA640-A65FA662-A66EA67F-A697A6A0-A6E5A717-A71FA722-A788A78BA78CA7FB-A801A803-A805A807-A80AA80C-A822A840-A873A882-A8B3A8F2-A8F7A8FBA90A-A925A930-A946A960-A97CA984-A9B2A9CFAA00-AA28AA40-AA42AA44-AA4BAA60-AA76AA7AAA80-AAAFAAB1AAB5AAB6AAB9-AABDAAC0AAC2AADB-AADDABC0-ABE2AC00-D7A3D7B0-D7C6D7CB-D7FBF900-FA2DFA30-FA6DFA70-FAD9FB00-FB06FB13-FB17FB1DFB1F-FB28FB2A-FB36FB38-FB3CFB3EFB40FB41FB43FB44FB46-FBB1FBD3-FD3DFD50-FD8FFD92-FDC7FDF0-FDFBFE70-FE74FE76-FEFCFF21-FF3AFF41-FF5AFF66-FFBEFFC2-FFC7FFCA-FFCFFFD2-FFD7FFDA-FFDC",
  5646. Ll: "0061-007A00AA00B500BA00DF-00F600F8-00FF01010103010501070109010B010D010F01110113011501170119011B011D011F01210123012501270129012B012D012F01310133013501370138013A013C013E014001420144014601480149014B014D014F01510153015501570159015B015D015F01610163016501670169016B016D016F0171017301750177017A017C017E-0180018301850188018C018D019201950199-019B019E01A101A301A501A801AA01AB01AD01B001B401B601B901BA01BD-01BF01C601C901CC01CE01D001D201D401D601D801DA01DC01DD01DF01E101E301E501E701E901EB01ED01EF01F001F301F501F901FB01FD01FF02010203020502070209020B020D020F02110213021502170219021B021D021F02210223022502270229022B022D022F02310233-0239023C023F0240024202470249024B024D024F-02930295-02AF037103730377037B-037D039003AC-03CE03D003D103D5-03D703D903DB03DD03DF03E103E303E503E703E903EB03ED03EF-03F303F503F803FB03FC0430-045F04610463046504670469046B046D046F04710473047504770479047B047D047F0481048B048D048F04910493049504970499049B049D049F04A104A304A504A704A904AB04AD04AF04B104B304B504B704B904BB04BD04BF04C204C404C604C804CA04CC04CE04CF04D104D304D504D704D904DB04DD04DF04E104E304E504E704E904EB04ED04EF04F104F304F504F704F904FB04FD04FF05010503050505070509050B050D050F05110513051505170519051B051D051F0521052305250561-05871D00-1D2B1D62-1D771D79-1D9A1E011E031E051E071E091E0B1E0D1E0F1E111E131E151E171E191E1B1E1D1E1F1E211E231E251E271E291E2B1E2D1E2F1E311E331E351E371E391E3B1E3D1E3F1E411E431E451E471E491E4B1E4D1E4F1E511E531E551E571E591E5B1E5D1E5F1E611E631E651E671E691E6B1E6D1E6F1E711E731E751E771E791E7B1E7D1E7F1E811E831E851E871E891E8B1E8D1E8F1E911E931E95-1E9D1E9F1EA11EA31EA51EA71EA91EAB1EAD1EAF1EB11EB31EB51EB71EB91EBB1EBD1EBF1EC11EC31EC51EC71EC91ECB1ECD1ECF1ED11ED31ED51ED71ED91EDB1EDD1EDF1EE11EE31EE51EE71EE91EEB1EED1EEF1EF11EF31EF51EF71EF91EFB1EFD1EFF-1F071F10-1F151F20-1F271F30-1F371F40-1F451F50-1F571F60-1F671F70-1F7D1F80-1F871F90-1F971FA0-1FA71FB0-1FB41FB61FB71FBE1FC2-1FC41FC61FC71FD0-1FD31FD61FD71FE0-1FE71FF2-1FF41FF61FF7210A210E210F2113212F21342139213C213D2146-2149214E21842C30-2C5E2C612C652C662C682C6A2C6C2C712C732C742C76-2C7C2C812C832C852C872C892C8B2C8D2C8F2C912C932C952C972C992C9B2C9D2C9F2CA12CA32CA52CA72CA92CAB2CAD2CAF2CB12CB32CB52CB72CB92CBB2CBD2CBF2CC12CC32CC52CC72CC92CCB2CCD2CCF2CD12CD32CD52CD72CD92CDB2CDD2CDF2CE12CE32CE42CEC2CEE2D00-2D25A641A643A645A647A649A64BA64DA64FA651A653A655A657A659A65BA65DA65FA663A665A667A669A66BA66DA681A683A685A687A689A68BA68DA68FA691A693A695A697A723A725A727A729A72BA72DA72F-A731A733A735A737A739A73BA73DA73FA741A743A745A747A749A74BA74DA74FA751A753A755A757A759A75BA75DA75FA761A763A765A767A769A76BA76DA76FA771-A778A77AA77CA77FA781A783A785A787A78CFB00-FB06FB13-FB17FF41-FF5A",
  5647. Lu: "0041-005A00C0-00D600D8-00DE01000102010401060108010A010C010E01100112011401160118011A011C011E01200122012401260128012A012C012E01300132013401360139013B013D013F0141014301450147014A014C014E01500152015401560158015A015C015E01600162016401660168016A016C016E017001720174017601780179017B017D018101820184018601870189-018B018E-0191019301940196-0198019C019D019F01A001A201A401A601A701A901AC01AE01AF01B1-01B301B501B701B801BC01C401C701CA01CD01CF01D101D301D501D701D901DB01DE01E001E201E401E601E801EA01EC01EE01F101F401F6-01F801FA01FC01FE02000202020402060208020A020C020E02100212021402160218021A021C021E02200222022402260228022A022C022E02300232023A023B023D023E02410243-02460248024A024C024E03700372037603860388-038A038C038E038F0391-03A103A3-03AB03CF03D2-03D403D803DA03DC03DE03E003E203E403E603E803EA03EC03EE03F403F703F903FA03FD-042F04600462046404660468046A046C046E04700472047404760478047A047C047E0480048A048C048E04900492049404960498049A049C049E04A004A204A404A604A804AA04AC04AE04B004B204B404B604B804BA04BC04BE04C004C104C304C504C704C904CB04CD04D004D204D404D604D804DA04DC04DE04E004E204E404E604E804EA04EC04EE04F004F204F404F604F804FA04FC04FE05000502050405060508050A050C050E05100512051405160518051A051C051E0520052205240531-055610A0-10C51E001E021E041E061E081E0A1E0C1E0E1E101E121E141E161E181E1A1E1C1E1E1E201E221E241E261E281E2A1E2C1E2E1E301E321E341E361E381E3A1E3C1E3E1E401E421E441E461E481E4A1E4C1E4E1E501E521E541E561E581E5A1E5C1E5E1E601E621E641E661E681E6A1E6C1E6E1E701E721E741E761E781E7A1E7C1E7E1E801E821E841E861E881E8A1E8C1E8E1E901E921E941E9E1EA01EA21EA41EA61EA81EAA1EAC1EAE1EB01EB21EB41EB61EB81EBA1EBC1EBE1EC01EC21EC41EC61EC81ECA1ECC1ECE1ED01ED21ED41ED61ED81EDA1EDC1EDE1EE01EE21EE41EE61EE81EEA1EEC1EEE1EF01EF21EF41EF61EF81EFA1EFC1EFE1F08-1F0F1F18-1F1D1F28-1F2F1F38-1F3F1F48-1F4D1F591F5B1F5D1F5F1F68-1F6F1FB8-1FBB1FC8-1FCB1FD8-1FDB1FE8-1FEC1FF8-1FFB21022107210B-210D2110-211221152119-211D212421262128212A-212D2130-2133213E213F214521832C00-2C2E2C602C62-2C642C672C692C6B2C6D-2C702C722C752C7E-2C802C822C842C862C882C8A2C8C2C8E2C902C922C942C962C982C9A2C9C2C9E2CA02CA22CA42CA62CA82CAA2CAC2CAE2CB02CB22CB42CB62CB82CBA2CBC2CBE2CC02CC22CC42CC62CC82CCA2CCC2CCE2CD02CD22CD42CD62CD82CDA2CDC2CDE2CE02CE22CEB2CEDA640A642A644A646A648A64AA64CA64EA650A652A654A656A658A65AA65CA65EA662A664A666A668A66AA66CA680A682A684A686A688A68AA68CA68EA690A692A694A696A722A724A726A728A72AA72CA72EA732A734A736A738A73AA73CA73EA740A742A744A746A748A74AA74CA74EA750A752A754A756A758A75AA75CA75EA760A762A764A766A768A76AA76CA76EA779A77BA77DA77EA780A782A784A786A78BFF21-FF3A",
  5648. Lt: "01C501C801CB01F21F88-1F8F1F98-1F9F1FA8-1FAF1FBC1FCC1FFC",
  5649. Lm: "02B0-02C102C6-02D102E0-02E402EC02EE0374037A0559064006E506E607F407F507FA081A0824082809710E460EC610FC17D718431AA71C78-1C7D1D2C-1D611D781D9B-1DBF2071207F2090-20942C7D2D6F2E2F30053031-3035303B309D309E30FC-30FEA015A4F8-A4FDA60CA67FA717-A71FA770A788A9CFAA70AADDFF70FF9EFF9F",
  5650. Lo: "01BB01C0-01C3029405D0-05EA05F0-05F20621-063F0641-064A066E066F0671-06D306D506EE06EF06FA-06FC06FF07100712-072F074D-07A507B107CA-07EA0800-08150904-0939093D09500958-096109720979-097F0985-098C098F09900993-09A809AA-09B009B209B6-09B909BD09CE09DC09DD09DF-09E109F009F10A05-0A0A0A0F0A100A13-0A280A2A-0A300A320A330A350A360A380A390A59-0A5C0A5E0A72-0A740A85-0A8D0A8F-0A910A93-0AA80AAA-0AB00AB20AB30AB5-0AB90ABD0AD00AE00AE10B05-0B0C0B0F0B100B13-0B280B2A-0B300B320B330B35-0B390B3D0B5C0B5D0B5F-0B610B710B830B85-0B8A0B8E-0B900B92-0B950B990B9A0B9C0B9E0B9F0BA30BA40BA8-0BAA0BAE-0BB90BD00C05-0C0C0C0E-0C100C12-0C280C2A-0C330C35-0C390C3D0C580C590C600C610C85-0C8C0C8E-0C900C92-0CA80CAA-0CB30CB5-0CB90CBD0CDE0CE00CE10D05-0D0C0D0E-0D100D12-0D280D2A-0D390D3D0D600D610D7A-0D7F0D85-0D960D9A-0DB10DB3-0DBB0DBD0DC0-0DC60E01-0E300E320E330E40-0E450E810E820E840E870E880E8A0E8D0E94-0E970E99-0E9F0EA1-0EA30EA50EA70EAA0EAB0EAD-0EB00EB20EB30EBD0EC0-0EC40EDC0EDD0F000F40-0F470F49-0F6C0F88-0F8B1000-102A103F1050-1055105A-105D106110651066106E-10701075-1081108E10D0-10FA1100-1248124A-124D1250-12561258125A-125D1260-1288128A-128D1290-12B012B2-12B512B8-12BE12C012C2-12C512C8-12D612D8-13101312-13151318-135A1380-138F13A0-13F41401-166C166F-167F1681-169A16A0-16EA1700-170C170E-17111720-17311740-17511760-176C176E-17701780-17B317DC1820-18421844-18771880-18A818AA18B0-18F51900-191C1950-196D1970-19741980-19AB19C1-19C71A00-1A161A20-1A541B05-1B331B45-1B4B1B83-1BA01BAE1BAF1C00-1C231C4D-1C4F1C5A-1C771CE9-1CEC1CEE-1CF12135-21382D30-2D652D80-2D962DA0-2DA62DA8-2DAE2DB0-2DB62DB8-2DBE2DC0-2DC62DC8-2DCE2DD0-2DD62DD8-2DDE3006303C3041-3096309F30A1-30FA30FF3105-312D3131-318E31A0-31B731F0-31FF3400-4DB54E00-9FCBA000-A014A016-A48CA4D0-A4F7A500-A60BA610-A61FA62AA62BA66EA6A0-A6E5A7FB-A801A803-A805A807-A80AA80C-A822A840-A873A882-A8B3A8F2-A8F7A8FBA90A-A925A930-A946A960-A97CA984-A9B2AA00-AA28AA40-AA42AA44-AA4BAA60-AA6FAA71-AA76AA7AAA80-AAAFAAB1AAB5AAB6AAB9-AABDAAC0AAC2AADBAADCABC0-ABE2AC00-D7A3D7B0-D7C6D7CB-D7FBF900-FA2DFA30-FA6DFA70-FAD9FB1DFB1F-FB28FB2A-FB36FB38-FB3CFB3EFB40FB41FB43FB44FB46-FBB1FBD3-FD3DFD50-FD8FFD92-FDC7FDF0-FDFBFE70-FE74FE76-FEFCFF66-FF6FFF71-FF9DFFA0-FFBEFFC2-FFC7FFCA-FFCFFFD2-FFD7FFDA-FFDC",
  5651. M: "0300-036F0483-04890591-05BD05BF05C105C205C405C505C70610-061A064B-065E067006D6-06DC06DE-06E406E706E806EA-06ED07110730-074A07A6-07B007EB-07F30816-0819081B-08230825-08270829-082D0900-0903093C093E-094E0951-0955096209630981-098309BC09BE-09C409C709C809CB-09CD09D709E209E30A01-0A030A3C0A3E-0A420A470A480A4B-0A4D0A510A700A710A750A81-0A830ABC0ABE-0AC50AC7-0AC90ACB-0ACD0AE20AE30B01-0B030B3C0B3E-0B440B470B480B4B-0B4D0B560B570B620B630B820BBE-0BC20BC6-0BC80BCA-0BCD0BD70C01-0C030C3E-0C440C46-0C480C4A-0C4D0C550C560C620C630C820C830CBC0CBE-0CC40CC6-0CC80CCA-0CCD0CD50CD60CE20CE30D020D030D3E-0D440D46-0D480D4A-0D4D0D570D620D630D820D830DCA0DCF-0DD40DD60DD8-0DDF0DF20DF30E310E34-0E3A0E47-0E4E0EB10EB4-0EB90EBB0EBC0EC8-0ECD0F180F190F350F370F390F3E0F3F0F71-0F840F860F870F90-0F970F99-0FBC0FC6102B-103E1056-1059105E-10601062-10641067-106D1071-10741082-108D108F109A-109D135F1712-17141732-1734175217531772177317B6-17D317DD180B-180D18A91920-192B1930-193B19B0-19C019C819C91A17-1A1B1A55-1A5E1A60-1A7C1A7F1B00-1B041B34-1B441B6B-1B731B80-1B821BA1-1BAA1C24-1C371CD0-1CD21CD4-1CE81CED1CF21DC0-1DE61DFD-1DFF20D0-20F02CEF-2CF12DE0-2DFF302A-302F3099309AA66F-A672A67CA67DA6F0A6F1A802A806A80BA823-A827A880A881A8B4-A8C4A8E0-A8F1A926-A92DA947-A953A980-A983A9B3-A9C0AA29-AA36AA43AA4CAA4DAA7BAAB0AAB2-AAB4AAB7AAB8AABEAABFAAC1ABE3-ABEAABECABEDFB1EFE00-FE0FFE20-FE26",
  5652. Mn: "0300-036F0483-04870591-05BD05BF05C105C205C405C505C70610-061A064B-065E067006D6-06DC06DF-06E406E706E806EA-06ED07110730-074A07A6-07B007EB-07F30816-0819081B-08230825-08270829-082D0900-0902093C0941-0948094D0951-095509620963098109BC09C1-09C409CD09E209E30A010A020A3C0A410A420A470A480A4B-0A4D0A510A700A710A750A810A820ABC0AC1-0AC50AC70AC80ACD0AE20AE30B010B3C0B3F0B41-0B440B4D0B560B620B630B820BC00BCD0C3E-0C400C46-0C480C4A-0C4D0C550C560C620C630CBC0CBF0CC60CCC0CCD0CE20CE30D41-0D440D4D0D620D630DCA0DD2-0DD40DD60E310E34-0E3A0E47-0E4E0EB10EB4-0EB90EBB0EBC0EC8-0ECD0F180F190F350F370F390F71-0F7E0F80-0F840F860F870F90-0F970F99-0FBC0FC6102D-10301032-10371039103A103D103E10581059105E-10601071-1074108210851086108D109D135F1712-17141732-1734175217531772177317B7-17BD17C617C9-17D317DD180B-180D18A91920-19221927192819321939-193B1A171A181A561A58-1A5E1A601A621A65-1A6C1A73-1A7C1A7F1B00-1B031B341B36-1B3A1B3C1B421B6B-1B731B801B811BA2-1BA51BA81BA91C2C-1C331C361C371CD0-1CD21CD4-1CE01CE2-1CE81CED1DC0-1DE61DFD-1DFF20D0-20DC20E120E5-20F02CEF-2CF12DE0-2DFF302A-302F3099309AA66FA67CA67DA6F0A6F1A802A806A80BA825A826A8C4A8E0-A8F1A926-A92DA947-A951A980-A982A9B3A9B6-A9B9A9BCAA29-AA2EAA31AA32AA35AA36AA43AA4CAAB0AAB2-AAB4AAB7AAB8AABEAABFAAC1ABE5ABE8ABEDFB1EFE00-FE0FFE20-FE26",
  5653. Mc: "0903093E-09400949-094C094E0982098309BE-09C009C709C809CB09CC09D70A030A3E-0A400A830ABE-0AC00AC90ACB0ACC0B020B030B3E0B400B470B480B4B0B4C0B570BBE0BBF0BC10BC20BC6-0BC80BCA-0BCC0BD70C01-0C030C41-0C440C820C830CBE0CC0-0CC40CC70CC80CCA0CCB0CD50CD60D020D030D3E-0D400D46-0D480D4A-0D4C0D570D820D830DCF-0DD10DD8-0DDF0DF20DF30F3E0F3F0F7F102B102C10311038103B103C105610571062-10641067-106D108310841087-108C108F109A-109C17B617BE-17C517C717C81923-19261929-192B193019311933-193819B0-19C019C819C91A19-1A1B1A551A571A611A631A641A6D-1A721B041B351B3B1B3D-1B411B431B441B821BA11BA61BA71BAA1C24-1C2B1C341C351CE11CF2A823A824A827A880A881A8B4-A8C3A952A953A983A9B4A9B5A9BAA9BBA9BD-A9C0AA2FAA30AA33AA34AA4DAA7BABE3ABE4ABE6ABE7ABE9ABEAABEC",
  5654. Me: "0488048906DE20DD-20E020E2-20E4A670-A672",
  5655. N: "0030-003900B200B300B900BC-00BE0660-066906F0-06F907C0-07C90966-096F09E6-09EF09F4-09F90A66-0A6F0AE6-0AEF0B66-0B6F0BE6-0BF20C66-0C6F0C78-0C7E0CE6-0CEF0D66-0D750E50-0E590ED0-0ED90F20-0F331040-10491090-10991369-137C16EE-16F017E0-17E917F0-17F91810-18191946-194F19D0-19DA1A80-1A891A90-1A991B50-1B591BB0-1BB91C40-1C491C50-1C5920702074-20792080-20892150-21822185-21892460-249B24EA-24FF2776-27932CFD30073021-30293038-303A3192-31953220-32293251-325F3280-328932B1-32BFA620-A629A6E6-A6EFA830-A835A8D0-A8D9A900-A909A9D0-A9D9AA50-AA59ABF0-ABF9FF10-FF19",
  5656. Nd: "0030-00390660-066906F0-06F907C0-07C90966-096F09E6-09EF0A66-0A6F0AE6-0AEF0B66-0B6F0BE6-0BEF0C66-0C6F0CE6-0CEF0D66-0D6F0E50-0E590ED0-0ED90F20-0F291040-10491090-109917E0-17E91810-18191946-194F19D0-19DA1A80-1A891A90-1A991B50-1B591BB0-1BB91C40-1C491C50-1C59A620-A629A8D0-A8D9A900-A909A9D0-A9D9AA50-AA59ABF0-ABF9FF10-FF19",
  5657. Nl: "16EE-16F02160-21822185-218830073021-30293038-303AA6E6-A6EF",
  5658. No: "00B200B300B900BC-00BE09F4-09F90BF0-0BF20C78-0C7E0D70-0D750F2A-0F331369-137C17F0-17F920702074-20792080-20892150-215F21892460-249B24EA-24FF2776-27932CFD3192-31953220-32293251-325F3280-328932B1-32BFA830-A835",
  5659. P: "0021-00230025-002A002C-002F003A003B003F0040005B-005D005F007B007D00A100AB00B700BB00BF037E0387055A-055F0589058A05BE05C005C305C605F305F40609060A060C060D061B061E061F066A-066D06D40700-070D07F7-07F90830-083E0964096509700DF40E4F0E5A0E5B0F04-0F120F3A-0F3D0F850FD0-0FD4104A-104F10FB1361-13681400166D166E169B169C16EB-16ED1735173617D4-17D617D8-17DA1800-180A1944194519DE19DF1A1E1A1F1AA0-1AA61AA8-1AAD1B5A-1B601C3B-1C3F1C7E1C7F1CD32010-20272030-20432045-20512053-205E207D207E208D208E2329232A2768-277527C527C627E6-27EF2983-299829D8-29DB29FC29FD2CF9-2CFC2CFE2CFF2E00-2E2E2E302E313001-30033008-30113014-301F3030303D30A030FBA4FEA4FFA60D-A60FA673A67EA6F2-A6F7A874-A877A8CEA8CFA8F8-A8FAA92EA92FA95FA9C1-A9CDA9DEA9DFAA5C-AA5FAADEAADFABEBFD3EFD3FFE10-FE19FE30-FE52FE54-FE61FE63FE68FE6AFE6BFF01-FF03FF05-FF0AFF0C-FF0FFF1AFF1BFF1FFF20FF3B-FF3DFF3FFF5BFF5DFF5F-FF65",
  5660. Pd: "002D058A05BE140018062010-20152E172E1A301C303030A0FE31FE32FE58FE63FF0D",
  5661. Ps: "0028005B007B0F3A0F3C169B201A201E2045207D208D23292768276A276C276E27702772277427C527E627E827EA27EC27EE2983298529872989298B298D298F299129932995299729D829DA29FC2E222E242E262E283008300A300C300E3010301430163018301A301DFD3EFE17FE35FE37FE39FE3BFE3DFE3FFE41FE43FE47FE59FE5BFE5DFF08FF3BFF5BFF5FFF62",
  5662. Pe: "0029005D007D0F3B0F3D169C2046207E208E232A2769276B276D276F27712773277527C627E727E927EB27ED27EF298429862988298A298C298E2990299229942996299829D929DB29FD2E232E252E272E293009300B300D300F3011301530173019301B301E301FFD3FFE18FE36FE38FE3AFE3CFE3EFE40FE42FE44FE48FE5AFE5CFE5EFF09FF3DFF5DFF60FF63",
  5663. Pi: "00AB2018201B201C201F20392E022E042E092E0C2E1C2E20",
  5664. Pf: "00BB2019201D203A2E032E052E0A2E0D2E1D2E21",
  5665. Pc: "005F203F20402054FE33FE34FE4D-FE4FFF3F",
  5666. Po: "0021-00230025-0027002A002C002E002F003A003B003F0040005C00A100B700BF037E0387055A-055F058905C005C305C605F305F40609060A060C060D061B061E061F066A-066D06D40700-070D07F7-07F90830-083E0964096509700DF40E4F0E5A0E5B0F04-0F120F850FD0-0FD4104A-104F10FB1361-1368166D166E16EB-16ED1735173617D4-17D617D8-17DA1800-18051807-180A1944194519DE19DF1A1E1A1F1AA0-1AA61AA8-1AAD1B5A-1B601C3B-1C3F1C7E1C7F1CD3201620172020-20272030-2038203B-203E2041-20432047-205120532055-205E2CF9-2CFC2CFE2CFF2E002E012E06-2E082E0B2E0E-2E162E182E192E1B2E1E2E1F2E2A-2E2E2E302E313001-3003303D30FBA4FEA4FFA60D-A60FA673A67EA6F2-A6F7A874-A877A8CEA8CFA8F8-A8FAA92EA92FA95FA9C1-A9CDA9DEA9DFAA5C-AA5FAADEAADFABEBFE10-FE16FE19FE30FE45FE46FE49-FE4CFE50-FE52FE54-FE57FE5F-FE61FE68FE6AFE6BFF01-FF03FF05-FF07FF0AFF0CFF0EFF0FFF1AFF1BFF1FFF20FF3CFF61FF64FF65",
  5667. S: "0024002B003C-003E005E0060007C007E00A2-00A900AC00AE-00B100B400B600B800D700F702C2-02C502D2-02DF02E5-02EB02ED02EF-02FF03750384038503F604820606-0608060B060E060F06E906FD06FE07F609F209F309FA09FB0AF10B700BF3-0BFA0C7F0CF10CF20D790E3F0F01-0F030F13-0F170F1A-0F1F0F340F360F380FBE-0FC50FC7-0FCC0FCE0FCF0FD5-0FD8109E109F13601390-139917DB194019E0-19FF1B61-1B6A1B74-1B7C1FBD1FBF-1FC11FCD-1FCF1FDD-1FDF1FED-1FEF1FFD1FFE20442052207A-207C208A-208C20A0-20B8210021012103-21062108210921142116-2118211E-2123212521272129212E213A213B2140-2144214A-214D214F2190-2328232B-23E82400-24262440-244A249C-24E92500-26CD26CF-26E126E326E8-26FF2701-27042706-2709270C-27272729-274B274D274F-27522756-275E2761-276727942798-27AF27B1-27BE27C0-27C427C7-27CA27CC27D0-27E527F0-29822999-29D729DC-29FB29FE-2B4C2B50-2B592CE5-2CEA2E80-2E992E9B-2EF32F00-2FD52FF0-2FFB300430123013302030363037303E303F309B309C319031913196-319F31C0-31E33200-321E322A-32503260-327F328A-32B032C0-32FE3300-33FF4DC0-4DFFA490-A4C6A700-A716A720A721A789A78AA828-A82BA836-A839AA77-AA79FB29FDFCFDFDFE62FE64-FE66FE69FF04FF0BFF1C-FF1EFF3EFF40FF5CFF5EFFE0-FFE6FFE8-FFEEFFFCFFFD",
  5668. Sm: "002B003C-003E007C007E00AC00B100D700F703F60606-060820442052207A-207C208A-208C2140-2144214B2190-2194219A219B21A021A321A621AE21CE21CF21D221D421F4-22FF2308-230B23202321237C239B-23B323DC-23E125B725C125F8-25FF266F27C0-27C427C7-27CA27CC27D0-27E527F0-27FF2900-29822999-29D729DC-29FB29FE-2AFF2B30-2B442B47-2B4CFB29FE62FE64-FE66FF0BFF1C-FF1EFF5CFF5EFFE2FFE9-FFEC",
  5669. Sc: "002400A2-00A5060B09F209F309FB0AF10BF90E3F17DB20A0-20B8A838FDFCFE69FF04FFE0FFE1FFE5FFE6",
  5670. Sk: "005E006000A800AF00B400B802C2-02C502D2-02DF02E5-02EB02ED02EF-02FF0375038403851FBD1FBF-1FC11FCD-1FCF1FDD-1FDF1FED-1FEF1FFD1FFE309B309CA700-A716A720A721A789A78AFF3EFF40FFE3",
  5671. So: "00A600A700A900AE00B000B60482060E060F06E906FD06FE07F609FA0B700BF3-0BF80BFA0C7F0CF10CF20D790F01-0F030F13-0F170F1A-0F1F0F340F360F380FBE-0FC50FC7-0FCC0FCE0FCF0FD5-0FD8109E109F13601390-1399194019E0-19FF1B61-1B6A1B74-1B7C210021012103-21062108210921142116-2118211E-2123212521272129212E213A213B214A214C214D214F2195-2199219C-219F21A121A221A421A521A7-21AD21AF-21CD21D021D121D321D5-21F32300-2307230C-231F2322-2328232B-237B237D-239A23B4-23DB23E2-23E82400-24262440-244A249C-24E92500-25B625B8-25C025C2-25F72600-266E2670-26CD26CF-26E126E326E8-26FF2701-27042706-2709270C-27272729-274B274D274F-27522756-275E2761-276727942798-27AF27B1-27BE2800-28FF2B00-2B2F2B452B462B50-2B592CE5-2CEA2E80-2E992E9B-2EF32F00-2FD52FF0-2FFB300430123013302030363037303E303F319031913196-319F31C0-31E33200-321E322A-32503260-327F328A-32B032C0-32FE3300-33FF4DC0-4DFFA490-A4C6A828-A82BA836A837A839AA77-AA79FDFDFFE4FFE8FFEDFFEEFFFCFFFD",
  5672. Z: "002000A01680180E2000-200A20282029202F205F3000",
  5673. Zs: "002000A01680180E2000-200A202F205F3000",
  5674. Zl: "2028",
  5675. Zp: "2029",
  5676. C: "0000-001F007F-009F00AD03780379037F-0383038B038D03A20526-05300557055805600588058B-059005C8-05CF05EB-05EF05F5-0605061C061D0620065F06DD070E070F074B074C07B2-07BF07FB-07FF082E082F083F-08FF093A093B094F095609570973-097809800984098D098E0991099209A909B109B3-09B509BA09BB09C509C609C909CA09CF-09D609D8-09DB09DE09E409E509FC-0A000A040A0B-0A0E0A110A120A290A310A340A370A3A0A3B0A3D0A43-0A460A490A4A0A4E-0A500A52-0A580A5D0A5F-0A650A76-0A800A840A8E0A920AA90AB10AB40ABA0ABB0AC60ACA0ACE0ACF0AD1-0ADF0AE40AE50AF00AF2-0B000B040B0D0B0E0B110B120B290B310B340B3A0B3B0B450B460B490B4A0B4E-0B550B58-0B5B0B5E0B640B650B72-0B810B840B8B-0B8D0B910B96-0B980B9B0B9D0BA0-0BA20BA5-0BA70BAB-0BAD0BBA-0BBD0BC3-0BC50BC90BCE0BCF0BD1-0BD60BD8-0BE50BFB-0C000C040C0D0C110C290C340C3A-0C3C0C450C490C4E-0C540C570C5A-0C5F0C640C650C70-0C770C800C810C840C8D0C910CA90CB40CBA0CBB0CC50CC90CCE-0CD40CD7-0CDD0CDF0CE40CE50CF00CF3-0D010D040D0D0D110D290D3A-0D3C0D450D490D4E-0D560D58-0D5F0D640D650D76-0D780D800D810D840D97-0D990DB20DBC0DBE0DBF0DC7-0DC90DCB-0DCE0DD50DD70DE0-0DF10DF5-0E000E3B-0E3E0E5C-0E800E830E850E860E890E8B0E8C0E8E-0E930E980EA00EA40EA60EA80EA90EAC0EBA0EBE0EBF0EC50EC70ECE0ECF0EDA0EDB0EDE-0EFF0F480F6D-0F700F8C-0F8F0F980FBD0FCD0FD9-0FFF10C6-10CF10FD-10FF1249124E124F12571259125E125F1289128E128F12B112B612B712BF12C112C612C712D7131113161317135B-135E137D-137F139A-139F13F5-13FF169D-169F16F1-16FF170D1715-171F1737-173F1754-175F176D17711774-177F17B417B517DE17DF17EA-17EF17FA-17FF180F181A-181F1878-187F18AB-18AF18F6-18FF191D-191F192C-192F193C-193F1941-1943196E196F1975-197F19AC-19AF19CA-19CF19DB-19DD1A1C1A1D1A5F1A7D1A7E1A8A-1A8F1A9A-1A9F1AAE-1AFF1B4C-1B4F1B7D-1B7F1BAB-1BAD1BBA-1BFF1C38-1C3A1C4A-1C4C1C80-1CCF1CF3-1CFF1DE7-1DFC1F161F171F1E1F1F1F461F471F4E1F4F1F581F5A1F5C1F5E1F7E1F7F1FB51FC51FD41FD51FDC1FF01FF11FF51FFF200B-200F202A-202E2060-206F20722073208F2095-209F20B9-20CF20F1-20FF218A-218F23E9-23FF2427-243F244B-245F26CE26E226E4-26E727002705270A270B2728274C274E2753-2755275F27602795-279727B027BF27CB27CD-27CF2B4D-2B4F2B5A-2BFF2C2F2C5F2CF2-2CF82D26-2D2F2D66-2D6E2D70-2D7F2D97-2D9F2DA72DAF2DB72DBF2DC72DCF2DD72DDF2E32-2E7F2E9A2EF4-2EFF2FD6-2FEF2FFC-2FFF3040309730983100-3104312E-3130318F31B8-31BF31E4-31EF321F32FF4DB6-4DBF9FCC-9FFFA48D-A48FA4C7-A4CFA62C-A63FA660A661A674-A67BA698-A69FA6F8-A6FFA78D-A7FAA82C-A82FA83A-A83FA878-A87FA8C5-A8CDA8DA-A8DFA8FC-A8FFA954-A95EA97D-A97FA9CEA9DA-A9DDA9E0-A9FFAA37-AA3FAA4EAA4FAA5AAA5BAA7C-AA7FAAC3-AADAAAE0-ABBFABEEABEFABFA-ABFFD7A4-D7AFD7C7-D7CAD7FC-F8FFFA2EFA2FFA6EFA6FFADA-FAFFFB07-FB12FB18-FB1CFB37FB3DFB3FFB42FB45FBB2-FBD2FD40-FD4FFD90FD91FDC8-FDEFFDFEFDFFFE1A-FE1FFE27-FE2FFE53FE67FE6C-FE6FFE75FEFD-FF00FFBF-FFC1FFC8FFC9FFD0FFD1FFD8FFD9FFDD-FFDFFFE7FFEF-FFFBFFFEFFFF",
  5677. Cc: "0000-001F007F-009F",
  5678. Cf: "00AD0600-060306DD070F17B417B5200B-200F202A-202E2060-2064206A-206FFEFFFFF9-FFFB",
  5679. Co: "E000-F8FF",
  5680. Cs: "D800-DFFF",
  5681. Cn: "03780379037F-0383038B038D03A20526-05300557055805600588058B-059005C8-05CF05EB-05EF05F5-05FF06040605061C061D0620065F070E074B074C07B2-07BF07FB-07FF082E082F083F-08FF093A093B094F095609570973-097809800984098D098E0991099209A909B109B3-09B509BA09BB09C509C609C909CA09CF-09D609D8-09DB09DE09E409E509FC-0A000A040A0B-0A0E0A110A120A290A310A340A370A3A0A3B0A3D0A43-0A460A490A4A0A4E-0A500A52-0A580A5D0A5F-0A650A76-0A800A840A8E0A920AA90AB10AB40ABA0ABB0AC60ACA0ACE0ACF0AD1-0ADF0AE40AE50AF00AF2-0B000B040B0D0B0E0B110B120B290B310B340B3A0B3B0B450B460B490B4A0B4E-0B550B58-0B5B0B5E0B640B650B72-0B810B840B8B-0B8D0B910B96-0B980B9B0B9D0BA0-0BA20BA5-0BA70BAB-0BAD0BBA-0BBD0BC3-0BC50BC90BCE0BCF0BD1-0BD60BD8-0BE50BFB-0C000C040C0D0C110C290C340C3A-0C3C0C450C490C4E-0C540C570C5A-0C5F0C640C650C70-0C770C800C810C840C8D0C910CA90CB40CBA0CBB0CC50CC90CCE-0CD40CD7-0CDD0CDF0CE40CE50CF00CF3-0D010D040D0D0D110D290D3A-0D3C0D450D490D4E-0D560D58-0D5F0D640D650D76-0D780D800D810D840D97-0D990DB20DBC0DBE0DBF0DC7-0DC90DCB-0DCE0DD50DD70DE0-0DF10DF5-0E000E3B-0E3E0E5C-0E800E830E850E860E890E8B0E8C0E8E-0E930E980EA00EA40EA60EA80EA90EAC0EBA0EBE0EBF0EC50EC70ECE0ECF0EDA0EDB0EDE-0EFF0F480F6D-0F700F8C-0F8F0F980FBD0FCD0FD9-0FFF10C6-10CF10FD-10FF1249124E124F12571259125E125F1289128E128F12B112B612B712BF12C112C612C712D7131113161317135B-135E137D-137F139A-139F13F5-13FF169D-169F16F1-16FF170D1715-171F1737-173F1754-175F176D17711774-177F17DE17DF17EA-17EF17FA-17FF180F181A-181F1878-187F18AB-18AF18F6-18FF191D-191F192C-192F193C-193F1941-1943196E196F1975-197F19AC-19AF19CA-19CF19DB-19DD1A1C1A1D1A5F1A7D1A7E1A8A-1A8F1A9A-1A9F1AAE-1AFF1B4C-1B4F1B7D-1B7F1BAB-1BAD1BBA-1BFF1C38-1C3A1C4A-1C4C1C80-1CCF1CF3-1CFF1DE7-1DFC1F161F171F1E1F1F1F461F471F4E1F4F1F581F5A1F5C1F5E1F7E1F7F1FB51FC51FD41FD51FDC1FF01FF11FF51FFF2065-206920722073208F2095-209F20B9-20CF20F1-20FF218A-218F23E9-23FF2427-243F244B-245F26CE26E226E4-26E727002705270A270B2728274C274E2753-2755275F27602795-279727B027BF27CB27CD-27CF2B4D-2B4F2B5A-2BFF2C2F2C5F2CF2-2CF82D26-2D2F2D66-2D6E2D70-2D7F2D97-2D9F2DA72DAF2DB72DBF2DC72DCF2DD72DDF2E32-2E7F2E9A2EF4-2EFF2FD6-2FEF2FFC-2FFF3040309730983100-3104312E-3130318F31B8-31BF31E4-31EF321F32FF4DB6-4DBF9FCC-9FFFA48D-A48FA4C7-A4CFA62C-A63FA660A661A674-A67BA698-A69FA6F8-A6FFA78D-A7FAA82C-A82FA83A-A83FA878-A87FA8C5-A8CDA8DA-A8DFA8FC-A8FFA954-A95EA97D-A97FA9CEA9DA-A9DDA9E0-A9FFAA37-AA3FAA4EAA4FAA5AAA5BAA7C-AA7FAAC3-AADAAAE0-ABBFABEEABEFABFA-ABFFD7A4-D7AFD7C7-D7CAD7FC-D7FFFA2EFA2FFA6EFA6FFADA-FAFFFB07-FB12FB18-FB1CFB37FB3DFB3FFB42FB45FBB2-FBD2FD40-FD4FFD90FD91FDC8-FDEFFDFEFDFFFE1A-FE1FFE27-FE2FFE53FE67FE6C-FE6FFE75FEFDFEFEFF00FFBF-FFC1FFC8FFC9FFD0FFD1FFD8FFD9FFDD-FFDFFFE7FFEF-FFF8FFFEFFFF"
  5682. });
  5683. function addUnicodePackage (pack) {
  5684. var codePoint = /\w{4}/g;
  5685. for (var name in pack)
  5686. exports.packages[name] = pack[name].replace(codePoint, "\\u$&");
  5687. }
  5688. });
  5689. define("ace/mode/text",["require","exports","module","ace/tokenizer","ace/mode/text_highlight_rules","ace/mode/behaviour/cstyle","ace/unicode","ace/lib/lang","ace/token_iterator","ace/range"], function(require, exports, module) {
  5690. "use strict";
  5691. var Tokenizer = require("../tokenizer").Tokenizer;
  5692. var TextHighlightRules = require("./text_highlight_rules").TextHighlightRules;
  5693. var CstyleBehaviour = require("./behaviour/cstyle").CstyleBehaviour;
  5694. var unicode = require("../unicode");
  5695. var lang = require("../lib/lang");
  5696. var TokenIterator = require("../token_iterator").TokenIterator;
  5697. var Range = require("../range").Range;
  5698. var Mode = function() {
  5699. this.HighlightRules = TextHighlightRules;
  5700. };
  5701. (function() {
  5702. this.$defaultBehaviour = new CstyleBehaviour();
  5703. this.tokenRe = new RegExp("^["
  5704. + unicode.packages.L
  5705. + unicode.packages.Mn + unicode.packages.Mc
  5706. + unicode.packages.Nd
  5707. + unicode.packages.Pc + "\\$_]+", "g"
  5708. );
  5709. this.nonTokenRe = new RegExp("^(?:[^"
  5710. + unicode.packages.L
  5711. + unicode.packages.Mn + unicode.packages.Mc
  5712. + unicode.packages.Nd
  5713. + unicode.packages.Pc + "\\$_]|\\s])+", "g"
  5714. );
  5715. this.getTokenizer = function() {
  5716. if (!this.$tokenizer) {
  5717. this.$highlightRules = this.$highlightRules || new this.HighlightRules(this.$highlightRuleConfig);
  5718. this.$tokenizer = new Tokenizer(this.$highlightRules.getRules());
  5719. }
  5720. return this.$tokenizer;
  5721. };
  5722. this.lineCommentStart = "";
  5723. this.blockComment = "";
  5724. this.toggleCommentLines = function(state, session, startRow, endRow) {
  5725. var doc = session.doc;
  5726. var ignoreBlankLines = true;
  5727. var shouldRemove = true;
  5728. var minIndent = Infinity;
  5729. var tabSize = session.getTabSize();
  5730. var insertAtTabStop = false;
  5731. if (!this.lineCommentStart) {
  5732. if (!this.blockComment)
  5733. return false;
  5734. var lineCommentStart = this.blockComment.start;
  5735. var lineCommentEnd = this.blockComment.end;
  5736. var regexpStart = new RegExp("^(\\s*)(?:" + lang.escapeRegExp(lineCommentStart) + ")");
  5737. var regexpEnd = new RegExp("(?:" + lang.escapeRegExp(lineCommentEnd) + ")\\s*$");
  5738. var comment = function(line, i) {
  5739. if (testRemove(line, i))
  5740. return;
  5741. if (!ignoreBlankLines || /\S/.test(line)) {
  5742. doc.insertInLine({row: i, column: line.length}, lineCommentEnd);
  5743. doc.insertInLine({row: i, column: minIndent}, lineCommentStart);
  5744. }
  5745. };
  5746. var uncomment = function(line, i) {
  5747. var m;
  5748. if (m = line.match(regexpEnd))
  5749. doc.removeInLine(i, line.length - m[0].length, line.length);
  5750. if (m = line.match(regexpStart))
  5751. doc.removeInLine(i, m[1].length, m[0].length);
  5752. };
  5753. var testRemove = function(line, row) {
  5754. if (regexpStart.test(line))
  5755. return true;
  5756. var tokens = session.getTokens(row);
  5757. for (var i = 0; i < tokens.length; i++) {
  5758. if (tokens[i].type === "comment")
  5759. return true;
  5760. }
  5761. };
  5762. } else {
  5763. if (Array.isArray(this.lineCommentStart)) {
  5764. var regexpStart = this.lineCommentStart.map(lang.escapeRegExp).join("|");
  5765. var lineCommentStart = this.lineCommentStart[0];
  5766. } else {
  5767. var regexpStart = lang.escapeRegExp(this.lineCommentStart);
  5768. var lineCommentStart = this.lineCommentStart;
  5769. }
  5770. regexpStart = new RegExp("^(\\s*)(?:" + regexpStart + ") ?");
  5771. insertAtTabStop = session.getUseSoftTabs();
  5772. var uncomment = function(line, i) {
  5773. var m = line.match(regexpStart);
  5774. if (!m) return;
  5775. var start = m[1].length, end = m[0].length;
  5776. if (!shouldInsertSpace(line, start, end) && m[0][end - 1] == " ")
  5777. end--;
  5778. doc.removeInLine(i, start, end);
  5779. };
  5780. var commentWithSpace = lineCommentStart + " ";
  5781. var comment = function(line, i) {
  5782. if (!ignoreBlankLines || /\S/.test(line)) {
  5783. if (shouldInsertSpace(line, minIndent, minIndent))
  5784. doc.insertInLine({row: i, column: minIndent}, commentWithSpace);
  5785. else
  5786. doc.insertInLine({row: i, column: minIndent}, lineCommentStart);
  5787. }
  5788. };
  5789. var testRemove = function(line, i) {
  5790. return regexpStart.test(line);
  5791. };
  5792. var shouldInsertSpace = function(line, before, after) {
  5793. var spaces = 0;
  5794. while (before-- && line.charAt(before) == " ")
  5795. spaces++;
  5796. if (spaces % tabSize != 0)
  5797. return false;
  5798. var spaces = 0;
  5799. while (line.charAt(after++) == " ")
  5800. spaces++;
  5801. if (tabSize > 2)
  5802. return spaces % tabSize != tabSize - 1;
  5803. else
  5804. return spaces % tabSize == 0;
  5805. return true;
  5806. };
  5807. }
  5808. function iter(fun) {
  5809. for (var i = startRow; i <= endRow; i++)
  5810. fun(doc.getLine(i), i);
  5811. }
  5812. var minEmptyLength = Infinity;
  5813. iter(function(line, i) {
  5814. var indent = line.search(/\S/);
  5815. if (indent !== -1) {
  5816. if (indent < minIndent)
  5817. minIndent = indent;
  5818. if (shouldRemove && !testRemove(line, i))
  5819. shouldRemove = false;
  5820. } else if (minEmptyLength > line.length) {
  5821. minEmptyLength = line.length;
  5822. }
  5823. });
  5824. if (minIndent == Infinity) {
  5825. minIndent = minEmptyLength;
  5826. ignoreBlankLines = false;
  5827. shouldRemove = false;
  5828. }
  5829. if (insertAtTabStop && minIndent % tabSize != 0)
  5830. minIndent = Math.floor(minIndent / tabSize) * tabSize;
  5831. iter(shouldRemove ? uncomment : comment);
  5832. };
  5833. this.toggleBlockComment = function(state, session, range, cursor) {
  5834. var comment = this.blockComment;
  5835. if (!comment)
  5836. return;
  5837. if (!comment.start && comment[0])
  5838. comment = comment[0];
  5839. var iterator = new TokenIterator(session, cursor.row, cursor.column);
  5840. var token = iterator.getCurrentToken();
  5841. var sel = session.selection;
  5842. var initialRange = session.selection.toOrientedRange();
  5843. var startRow, colDiff;
  5844. if (token && /comment/.test(token.type)) {
  5845. var startRange, endRange;
  5846. while (token && /comment/.test(token.type)) {
  5847. var i = token.value.indexOf(comment.start);
  5848. if (i != -1) {
  5849. var row = iterator.getCurrentTokenRow();
  5850. var column = iterator.getCurrentTokenColumn() + i;
  5851. startRange = new Range(row, column, row, column + comment.start.length);
  5852. break;
  5853. }
  5854. token = iterator.stepBackward();
  5855. }
  5856. var iterator = new TokenIterator(session, cursor.row, cursor.column);
  5857. var token = iterator.getCurrentToken();
  5858. while (token && /comment/.test(token.type)) {
  5859. var i = token.value.indexOf(comment.end);
  5860. if (i != -1) {
  5861. var row = iterator.getCurrentTokenRow();
  5862. var column = iterator.getCurrentTokenColumn() + i;
  5863. endRange = new Range(row, column, row, column + comment.end.length);
  5864. break;
  5865. }
  5866. token = iterator.stepForward();
  5867. }
  5868. if (endRange)
  5869. session.remove(endRange);
  5870. if (startRange) {
  5871. session.remove(startRange);
  5872. startRow = startRange.start.row;
  5873. colDiff = -comment.start.length;
  5874. }
  5875. } else {
  5876. colDiff = comment.start.length;
  5877. startRow = range.start.row;
  5878. session.insert(range.end, comment.end);
  5879. session.insert(range.start, comment.start);
  5880. }
  5881. if (initialRange.start.row == startRow)
  5882. initialRange.start.column += colDiff;
  5883. if (initialRange.end.row == startRow)
  5884. initialRange.end.column += colDiff;
  5885. session.selection.fromOrientedRange(initialRange);
  5886. };
  5887. this.getNextLineIndent = function(state, line, tab) {
  5888. return this.$getIndent(line);
  5889. };
  5890. this.checkOutdent = function(state, line, input) {
  5891. return false;
  5892. };
  5893. this.autoOutdent = function(state, doc, row) {
  5894. };
  5895. this.$getIndent = function(line) {
  5896. return line.match(/^\s*/)[0];
  5897. };
  5898. this.createWorker = function(session) {
  5899. return null;
  5900. };
  5901. this.createModeDelegates = function (mapping) {
  5902. this.$embeds = [];
  5903. this.$modes = {};
  5904. for (var i in mapping) {
  5905. if (mapping[i]) {
  5906. this.$embeds.push(i);
  5907. this.$modes[i] = new mapping[i]();
  5908. }
  5909. }
  5910. var delegations = ["toggleBlockComment", "toggleCommentLines", "getNextLineIndent",
  5911. "checkOutdent", "autoOutdent", "transformAction", "getCompletions"];
  5912. for (var i = 0; i < delegations.length; i++) {
  5913. (function(scope) {
  5914. var functionName = delegations[i];
  5915. var defaultHandler = scope[functionName];
  5916. scope[delegations[i]] = function() {
  5917. return this.$delegator(functionName, arguments, defaultHandler);
  5918. };
  5919. }(this));
  5920. }
  5921. };
  5922. this.$delegator = function(method, args, defaultHandler) {
  5923. var state = args[0];
  5924. if (typeof state != "string")
  5925. state = state[0];
  5926. for (var i = 0; i < this.$embeds.length; i++) {
  5927. if (!this.$modes[this.$embeds[i]]) continue;
  5928. var split = state.split(this.$embeds[i]);
  5929. if (!split[0] && split[1]) {
  5930. args[0] = split[1];
  5931. var mode = this.$modes[this.$embeds[i]];
  5932. return mode[method].apply(mode, args);
  5933. }
  5934. }
  5935. var ret = defaultHandler.apply(this, args);
  5936. return defaultHandler ? ret : undefined;
  5937. };
  5938. this.transformAction = function(state, action, editor, session, param) {
  5939. if (this.$behaviour) {
  5940. var behaviours = this.$behaviour.getBehaviours();
  5941. for (var key in behaviours) {
  5942. if (behaviours[key][action]) {
  5943. var ret = behaviours[key][action].apply(this, arguments);
  5944. if (ret) {
  5945. return ret;
  5946. }
  5947. }
  5948. }
  5949. }
  5950. };
  5951. this.getKeywords = function(append) {
  5952. if (!this.completionKeywords) {
  5953. var rules = this.$tokenizer.rules;
  5954. var completionKeywords = [];
  5955. for (var rule in rules) {
  5956. var ruleItr = rules[rule];
  5957. for (var r = 0, l = ruleItr.length; r < l; r++) {
  5958. if (typeof ruleItr[r].token === "string") {
  5959. if (/keyword|support|storage/.test(ruleItr[r].token))
  5960. completionKeywords.push(ruleItr[r].regex);
  5961. }
  5962. else if (typeof ruleItr[r].token === "object") {
  5963. for (var a = 0, aLength = ruleItr[r].token.length; a < aLength; a++) {
  5964. if (/keyword|support|storage/.test(ruleItr[r].token[a])) {
  5965. var rule = ruleItr[r].regex.match(/\(.+?\)/g)[a];
  5966. completionKeywords.push(rule.substr(1, rule.length - 2));
  5967. }
  5968. }
  5969. }
  5970. }
  5971. }
  5972. this.completionKeywords = completionKeywords;
  5973. }
  5974. if (!append)
  5975. return this.$keywordList;
  5976. return completionKeywords.concat(this.$keywordList || []);
  5977. };
  5978. this.$createKeywordList = function() {
  5979. if (!this.$highlightRules)
  5980. this.getTokenizer();
  5981. return this.$keywordList = this.$highlightRules.$keywordList || [];
  5982. };
  5983. this.getCompletions = function(state, session, pos, prefix) {
  5984. var keywords = this.$keywordList || this.$createKeywordList();
  5985. return keywords.map(function(word) {
  5986. return {
  5987. name: word,
  5988. value: word,
  5989. score: 0,
  5990. meta: "keyword"
  5991. };
  5992. });
  5993. };
  5994. this.$id = "ace/mode/text";
  5995. }).call(Mode.prototype);
  5996. exports.Mode = Mode;
  5997. });
  5998. define("ace/apply_delta",["require","exports","module"], function(require, exports, module) {
  5999. "use strict";
  6000. function throwDeltaError(delta, errorText){
  6001. console.log("Invalid Delta:", delta);
  6002. throw "Invalid Delta: " + errorText;
  6003. }
  6004. function positionInDocument(docLines, position) {
  6005. return position.row >= 0 && position.row < docLines.length &&
  6006. position.column >= 0 && position.column <= docLines[position.row].length;
  6007. }
  6008. function validateDelta(docLines, delta) {
  6009. if (delta.action != "insert" && delta.action != "remove")
  6010. throwDeltaError(delta, "delta.action must be 'insert' or 'remove'");
  6011. if (!(delta.lines instanceof Array))
  6012. throwDeltaError(delta, "delta.lines must be an Array");
  6013. if (!delta.start || !delta.end)
  6014. throwDeltaError(delta, "delta.start/end must be an present");
  6015. var start = delta.start;
  6016. if (!positionInDocument(docLines, delta.start))
  6017. throwDeltaError(delta, "delta.start must be contained in document");
  6018. var end = delta.end;
  6019. if (delta.action == "remove" && !positionInDocument(docLines, end))
  6020. throwDeltaError(delta, "delta.end must contained in document for 'remove' actions");
  6021. var numRangeRows = end.row - start.row;
  6022. var numRangeLastLineChars = (end.column - (numRangeRows == 0 ? start.column : 0));
  6023. if (numRangeRows != delta.lines.length - 1 || delta.lines[numRangeRows].length != numRangeLastLineChars)
  6024. throwDeltaError(delta, "delta.range must match delta lines");
  6025. }
  6026. exports.applyDelta = function(docLines, delta, doNotValidate) {
  6027. var row = delta.start.row;
  6028. var startColumn = delta.start.column;
  6029. var line = docLines[row] || "";
  6030. switch (delta.action) {
  6031. case "insert":
  6032. var lines = delta.lines;
  6033. if (lines.length === 1) {
  6034. docLines[row] = line.substring(0, startColumn) + delta.lines[0] + line.substring(startColumn);
  6035. } else {
  6036. var args = [row, 1].concat(delta.lines);
  6037. docLines.splice.apply(docLines, args);
  6038. docLines[row] = line.substring(0, startColumn) + docLines[row];
  6039. docLines[row + delta.lines.length - 1] += line.substring(startColumn);
  6040. }
  6041. break;
  6042. case "remove":
  6043. var endColumn = delta.end.column;
  6044. var endRow = delta.end.row;
  6045. if (row === endRow) {
  6046. docLines[row] = line.substring(0, startColumn) + line.substring(endColumn);
  6047. } else {
  6048. docLines.splice(
  6049. row, endRow - row + 1,
  6050. line.substring(0, startColumn) + docLines[endRow].substring(endColumn)
  6051. );
  6052. }
  6053. break;
  6054. }
  6055. }
  6056. });
  6057. define("ace/anchor",["require","exports","module","ace/lib/oop","ace/lib/event_emitter"], function(require, exports, module) {
  6058. "use strict";
  6059. var oop = require("./lib/oop");
  6060. var EventEmitter = require("./lib/event_emitter").EventEmitter;
  6061. var Anchor = exports.Anchor = function(doc, row, column) {
  6062. this.$onChange = this.onChange.bind(this);
  6063. this.attach(doc);
  6064. if (typeof column == "undefined")
  6065. this.setPosition(row.row, row.column);
  6066. else
  6067. this.setPosition(row, column);
  6068. };
  6069. (function() {
  6070. oop.implement(this, EventEmitter);
  6071. this.getPosition = function() {
  6072. return this.$clipPositionToDocument(this.row, this.column);
  6073. };
  6074. this.getDocument = function() {
  6075. return this.document;
  6076. };
  6077. this.$insertRight = false;
  6078. this.onChange = function(delta) {
  6079. if (delta.start.row == delta.end.row && delta.start.row != this.row)
  6080. return;
  6081. if (delta.start.row > this.row)
  6082. return;
  6083. var point = $getTransformedPoint(delta, {row: this.row, column: this.column}, this.$insertRight);
  6084. this.setPosition(point.row, point.column, true);
  6085. };
  6086. function $pointsInOrder(point1, point2, equalPointsInOrder) {
  6087. var bColIsAfter = equalPointsInOrder ? point1.column <= point2.column : point1.column < point2.column;
  6088. return (point1.row < point2.row) || (point1.row == point2.row && bColIsAfter);
  6089. }
  6090. function $getTransformedPoint(delta, point, moveIfEqual) {
  6091. var deltaIsInsert = delta.action == "insert";
  6092. var deltaRowShift = (deltaIsInsert ? 1 : -1) * (delta.end.row - delta.start.row);
  6093. var deltaColShift = (deltaIsInsert ? 1 : -1) * (delta.end.column - delta.start.column);
  6094. var deltaStart = delta.start;
  6095. var deltaEnd = deltaIsInsert ? deltaStart : delta.end; // Collapse insert range.
  6096. if ($pointsInOrder(point, deltaStart, moveIfEqual)) {
  6097. return {
  6098. row: point.row,
  6099. column: point.column
  6100. };
  6101. }
  6102. if ($pointsInOrder(deltaEnd, point, !moveIfEqual)) {
  6103. return {
  6104. row: point.row + deltaRowShift,
  6105. column: point.column + (point.row == deltaEnd.row ? deltaColShift : 0)
  6106. };
  6107. }
  6108. return {
  6109. row: deltaStart.row,
  6110. column: deltaStart.column
  6111. };
  6112. }
  6113. this.setPosition = function(row, column, noClip) {
  6114. var pos;
  6115. if (noClip) {
  6116. pos = {
  6117. row: row,
  6118. column: column
  6119. };
  6120. } else {
  6121. pos = this.$clipPositionToDocument(row, column);
  6122. }
  6123. if (this.row == pos.row && this.column == pos.column)
  6124. return;
  6125. var old = {
  6126. row: this.row,
  6127. column: this.column
  6128. };
  6129. this.row = pos.row;
  6130. this.column = pos.column;
  6131. this._signal("change", {
  6132. old: old,
  6133. value: pos
  6134. });
  6135. };
  6136. this.detach = function() {
  6137. this.document.removeEventListener("change", this.$onChange);
  6138. };
  6139. this.attach = function(doc) {
  6140. this.document = doc || this.document;
  6141. this.document.on("change", this.$onChange);
  6142. };
  6143. this.$clipPositionToDocument = function(row, column) {
  6144. var pos = {};
  6145. if (row >= this.document.getLength()) {
  6146. pos.row = Math.max(0, this.document.getLength() - 1);
  6147. pos.column = this.document.getLine(pos.row).length;
  6148. }
  6149. else if (row < 0) {
  6150. pos.row = 0;
  6151. pos.column = 0;
  6152. }
  6153. else {
  6154. pos.row = row;
  6155. pos.column = Math.min(this.document.getLine(pos.row).length, Math.max(0, column));
  6156. }
  6157. if (column < 0)
  6158. pos.column = 0;
  6159. return pos;
  6160. };
  6161. }).call(Anchor.prototype);
  6162. });
  6163. define("ace/document",["require","exports","module","ace/lib/oop","ace/apply_delta","ace/lib/event_emitter","ace/range","ace/anchor"], function(require, exports, module) {
  6164. "use strict";
  6165. var oop = require("./lib/oop");
  6166. var applyDelta = require("./apply_delta").applyDelta;
  6167. var EventEmitter = require("./lib/event_emitter").EventEmitter;
  6168. var Range = require("./range").Range;
  6169. var Anchor = require("./anchor").Anchor;
  6170. var Document = function(textOrLines) {
  6171. this.$lines = [""];
  6172. if (textOrLines.length === 0) {
  6173. this.$lines = [""];
  6174. } else if (Array.isArray(textOrLines)) {
  6175. this.insertMergedLines({row: 0, column: 0}, textOrLines);
  6176. } else {
  6177. this.insert({row: 0, column:0}, textOrLines);
  6178. }
  6179. };
  6180. (function() {
  6181. oop.implement(this, EventEmitter);
  6182. this.setValue = function(text) {
  6183. var len = this.getLength() - 1;
  6184. this.remove(new Range(0, 0, len, this.getLine(len).length));
  6185. this.insert({row: 0, column: 0}, text);
  6186. };
  6187. this.getValue = function() {
  6188. return this.getAllLines().join(this.getNewLineCharacter());
  6189. };
  6190. this.createAnchor = function(row, column) {
  6191. return new Anchor(this, row, column);
  6192. };
  6193. if ("aaa".split(/a/).length === 0) {
  6194. this.$split = function(text) {
  6195. return text.replace(/\r\n|\r/g, "\n").split("\n");
  6196. };
  6197. } else {
  6198. this.$split = function(text) {
  6199. return text.split(/\r\n|\r|\n/);
  6200. };
  6201. }
  6202. this.$detectNewLine = function(text) {
  6203. var match = text.match(/^.*?(\r\n|\r|\n)/m);
  6204. this.$autoNewLine = match ? match[1] : "\n";
  6205. this._signal("changeNewLineMode");
  6206. };
  6207. this.getNewLineCharacter = function() {
  6208. switch (this.$newLineMode) {
  6209. case "windows":
  6210. return "\r\n";
  6211. case "unix":
  6212. return "\n";
  6213. default:
  6214. return this.$autoNewLine || "\n";
  6215. }
  6216. };
  6217. this.$autoNewLine = "";
  6218. this.$newLineMode = "auto";
  6219. this.setNewLineMode = function(newLineMode) {
  6220. if (this.$newLineMode === newLineMode)
  6221. return;
  6222. this.$newLineMode = newLineMode;
  6223. this._signal("changeNewLineMode");
  6224. };
  6225. this.getNewLineMode = function() {
  6226. return this.$newLineMode;
  6227. };
  6228. this.isNewLine = function(text) {
  6229. return (text == "\r\n" || text == "\r" || text == "\n");
  6230. };
  6231. this.getLine = function(row) {
  6232. return this.$lines[row] || "";
  6233. };
  6234. this.getLines = function(firstRow, lastRow) {
  6235. return this.$lines.slice(firstRow, lastRow + 1);
  6236. };
  6237. this.getAllLines = function() {
  6238. return this.getLines(0, this.getLength());
  6239. };
  6240. this.getLength = function() {
  6241. return this.$lines.length;
  6242. };
  6243. this.getTextRange = function(range) {
  6244. return this.getLinesForRange(range).join(this.getNewLineCharacter());
  6245. };
  6246. this.getLinesForRange = function(range) {
  6247. var lines;
  6248. if (range.start.row === range.end.row) {
  6249. lines = [this.getLine(range.start.row).substring(range.start.column, range.end.column)];
  6250. } else {
  6251. lines = this.getLines(range.start.row, range.end.row);
  6252. lines[0] = (lines[0] || "").substring(range.start.column);
  6253. var l = lines.length - 1;
  6254. if (range.end.row - range.start.row == l)
  6255. lines[l] = lines[l].substring(0, range.end.column);
  6256. }
  6257. return lines;
  6258. };
  6259. this.insertLines = function(row, lines) {
  6260. console.warn("Use of document.insertLines is deprecated. Use the insertFullLines method instead.");
  6261. return this.insertFullLines(row, lines);
  6262. };
  6263. this.removeLines = function(firstRow, lastRow) {
  6264. console.warn("Use of document.removeLines is deprecated. Use the removeFullLines method instead.");
  6265. return this.removeFullLines(firstRow, lastRow);
  6266. };
  6267. this.insertNewLine = function(position) {
  6268. console.warn("Use of document.insertNewLine is deprecated. Use insertMergedLines(position, ['', '']) instead.");
  6269. return this.insertMergedLines(position, ["", ""]);
  6270. };
  6271. this.insert = function(position, text) {
  6272. if (this.getLength() <= 1)
  6273. this.$detectNewLine(text);
  6274. return this.insertMergedLines(position, this.$split(text));
  6275. };
  6276. this.insertInLine = function(position, text) {
  6277. var start = this.clippedPos(position.row, position.column);
  6278. var end = this.pos(position.row, position.column + text.length);
  6279. this.applyDelta({
  6280. start: start,
  6281. end: end,
  6282. action: "insert",
  6283. lines: [text]
  6284. }, true);
  6285. return this.clonePos(end);
  6286. };
  6287. this.clippedPos = function(row, column) {
  6288. var length = this.getLength();
  6289. if (row === undefined) {
  6290. row = length;
  6291. } else if (row < 0) {
  6292. row = 0;
  6293. } else if (row >= length) {
  6294. row = length - 1;
  6295. column = undefined;
  6296. }
  6297. var line = this.getLine(row);
  6298. if (column == undefined)
  6299. column = line.length;
  6300. column = Math.min(Math.max(column, 0), line.length);
  6301. return {row: row, column: column};
  6302. };
  6303. this.clonePos = function(pos) {
  6304. return {row: pos.row, column: pos.column};
  6305. };
  6306. this.pos = function(row, column) {
  6307. return {row: row, column: column};
  6308. };
  6309. this.$clipPosition = function(position) {
  6310. var length = this.getLength();
  6311. if (position.row >= length) {
  6312. position.row = Math.max(0, length - 1);
  6313. position.column = this.getLine(length - 1).length;
  6314. } else {
  6315. position.row = Math.max(0, position.row);
  6316. position.column = Math.min(Math.max(position.column, 0), this.getLine(position.row).length);
  6317. }
  6318. return position;
  6319. };
  6320. this.insertFullLines = function(row, lines) {
  6321. row = Math.min(Math.max(row, 0), this.getLength());
  6322. var column = 0;
  6323. if (row < this.getLength()) {
  6324. lines = lines.concat([""]);
  6325. column = 0;
  6326. } else {
  6327. lines = [""].concat(lines);
  6328. row--;
  6329. column = this.$lines[row].length;
  6330. }
  6331. this.insertMergedLines({row: row, column: column}, lines);
  6332. };
  6333. this.insertMergedLines = function(position, lines) {
  6334. var start = this.clippedPos(position.row, position.column);
  6335. var end = {
  6336. row: start.row + lines.length - 1,
  6337. column: (lines.length == 1 ? start.column : 0) + lines[lines.length - 1].length
  6338. };
  6339. this.applyDelta({
  6340. start: start,
  6341. end: end,
  6342. action: "insert",
  6343. lines: lines
  6344. });
  6345. return this.clonePos(end);
  6346. };
  6347. this.remove = function(range) {
  6348. var start = this.clippedPos(range.start.row, range.start.column);
  6349. var end = this.clippedPos(range.end.row, range.end.column);
  6350. this.applyDelta({
  6351. start: start,
  6352. end: end,
  6353. action: "remove",
  6354. lines: this.getLinesForRange({start: start, end: end})
  6355. });
  6356. return this.clonePos(start);
  6357. };
  6358. this.removeInLine = function(row, startColumn, endColumn) {
  6359. var start = this.clippedPos(row, startColumn);
  6360. var end = this.clippedPos(row, endColumn);
  6361. this.applyDelta({
  6362. start: start,
  6363. end: end,
  6364. action: "remove",
  6365. lines: this.getLinesForRange({start: start, end: end})
  6366. }, true);
  6367. return this.clonePos(start);
  6368. };
  6369. this.removeFullLines = function(firstRow, lastRow) {
  6370. firstRow = Math.min(Math.max(0, firstRow), this.getLength() - 1);
  6371. lastRow = Math.min(Math.max(0, lastRow ), this.getLength() - 1);
  6372. var deleteFirstNewLine = lastRow == this.getLength() - 1 && firstRow > 0;
  6373. var deleteLastNewLine = lastRow < this.getLength() - 1;
  6374. var startRow = ( deleteFirstNewLine ? firstRow - 1 : firstRow );
  6375. var startCol = ( deleteFirstNewLine ? this.getLine(startRow).length : 0 );
  6376. var endRow = ( deleteLastNewLine ? lastRow + 1 : lastRow );
  6377. var endCol = ( deleteLastNewLine ? 0 : this.getLine(endRow).length );
  6378. var range = new Range(startRow, startCol, endRow, endCol);
  6379. var deletedLines = this.$lines.slice(firstRow, lastRow + 1);
  6380. this.applyDelta({
  6381. start: range.start,
  6382. end: range.end,
  6383. action: "remove",
  6384. lines: this.getLinesForRange(range)
  6385. });
  6386. return deletedLines;
  6387. };
  6388. this.removeNewLine = function(row) {
  6389. if (row < this.getLength() - 1 && row >= 0) {
  6390. this.applyDelta({
  6391. start: this.pos(row, this.getLine(row).length),
  6392. end: this.pos(row + 1, 0),
  6393. action: "remove",
  6394. lines: ["", ""]
  6395. });
  6396. }
  6397. };
  6398. this.replace = function(range, text) {
  6399. if (!(range instanceof Range))
  6400. range = Range.fromPoints(range.start, range.end);
  6401. if (text.length === 0 && range.isEmpty())
  6402. return range.start;
  6403. if (text == this.getTextRange(range))
  6404. return range.end;
  6405. this.remove(range);
  6406. var end;
  6407. if (text) {
  6408. end = this.insert(range.start, text);
  6409. }
  6410. else {
  6411. end = range.start;
  6412. }
  6413. return end;
  6414. };
  6415. this.applyDeltas = function(deltas) {
  6416. for (var i=0; i<deltas.length; i++) {
  6417. this.applyDelta(deltas[i]);
  6418. }
  6419. };
  6420. this.revertDeltas = function(deltas) {
  6421. for (var i=deltas.length-1; i>=0; i--) {
  6422. this.revertDelta(deltas[i]);
  6423. }
  6424. };
  6425. this.applyDelta = function(delta, doNotValidate) {
  6426. var isInsert = delta.action == "insert";
  6427. if (isInsert ? delta.lines.length <= 1 && !delta.lines[0]
  6428. : !Range.comparePoints(delta.start, delta.end)) {
  6429. return;
  6430. }
  6431. if (isInsert && delta.lines.length > 20000)
  6432. this.$splitAndapplyLargeDelta(delta, 20000);
  6433. applyDelta(this.$lines, delta, doNotValidate);
  6434. this._signal("change", delta);
  6435. };
  6436. this.$splitAndapplyLargeDelta = function(delta, MAX) {
  6437. var lines = delta.lines;
  6438. var l = lines.length;
  6439. var row = delta.start.row;
  6440. var column = delta.start.column;
  6441. var from = 0, to = 0;
  6442. do {
  6443. from = to;
  6444. to += MAX - 1;
  6445. var chunk = lines.slice(from, to);
  6446. if (to > l) {
  6447. delta.lines = chunk;
  6448. delta.start.row = row + from;
  6449. delta.start.column = column;
  6450. break;
  6451. }
  6452. chunk.push("");
  6453. this.applyDelta({
  6454. start: this.pos(row + from, column),
  6455. end: this.pos(row + to, column = 0),
  6456. action: delta.action,
  6457. lines: chunk
  6458. }, true);
  6459. } while(true);
  6460. };
  6461. this.revertDelta = function(delta) {
  6462. this.applyDelta({
  6463. start: this.clonePos(delta.start),
  6464. end: this.clonePos(delta.end),
  6465. action: (delta.action == "insert" ? "remove" : "insert"),
  6466. lines: delta.lines.slice()
  6467. });
  6468. };
  6469. this.indexToPosition = function(index, startRow) {
  6470. var lines = this.$lines || this.getAllLines();
  6471. var newlineLength = this.getNewLineCharacter().length;
  6472. for (var i = startRow || 0, l = lines.length; i < l; i++) {
  6473. index -= lines[i].length + newlineLength;
  6474. if (index < 0)
  6475. return {row: i, column: index + lines[i].length + newlineLength};
  6476. }
  6477. return {row: l-1, column: lines[l-1].length};
  6478. };
  6479. this.positionToIndex = function(pos, startRow) {
  6480. var lines = this.$lines || this.getAllLines();
  6481. var newlineLength = this.getNewLineCharacter().length;
  6482. var index = 0;
  6483. var row = Math.min(pos.row, lines.length);
  6484. for (var i = startRow || 0; i < row; ++i)
  6485. index += lines[i].length + newlineLength;
  6486. return index + pos.column;
  6487. };
  6488. }).call(Document.prototype);
  6489. exports.Document = Document;
  6490. });
  6491. define("ace/background_tokenizer",["require","exports","module","ace/lib/oop","ace/lib/event_emitter"], function(require, exports, module) {
  6492. "use strict";
  6493. var oop = require("./lib/oop");
  6494. var EventEmitter = require("./lib/event_emitter").EventEmitter;
  6495. var BackgroundTokenizer = function(tokenizer, editor) {
  6496. this.running = false;
  6497. this.lines = [];
  6498. this.states = [];
  6499. this.currentLine = 0;
  6500. this.tokenizer = tokenizer;
  6501. var self = this;
  6502. this.$worker = function() {
  6503. if (!self.running) { return; }
  6504. var workerStart = new Date();
  6505. var currentLine = self.currentLine;
  6506. var endLine = -1;
  6507. var doc = self.doc;
  6508. var startLine = currentLine;
  6509. while (self.lines[currentLine])
  6510. currentLine++;
  6511. var len = doc.getLength();
  6512. var processedLines = 0;
  6513. self.running = false;
  6514. while (currentLine < len) {
  6515. self.$tokenizeRow(currentLine);
  6516. endLine = currentLine;
  6517. do {
  6518. currentLine++;
  6519. } while (self.lines[currentLine]);
  6520. processedLines ++;
  6521. if ((processedLines % 5 === 0) && (new Date() - workerStart) > 20) {
  6522. self.running = setTimeout(self.$worker, 20);
  6523. break;
  6524. }
  6525. }
  6526. self.currentLine = currentLine;
  6527. if (endLine == -1)
  6528. endLine = currentLine;
  6529. if (startLine <= endLine)
  6530. self.fireUpdateEvent(startLine, endLine);
  6531. };
  6532. };
  6533. (function(){
  6534. oop.implement(this, EventEmitter);
  6535. this.setTokenizer = function(tokenizer) {
  6536. this.tokenizer = tokenizer;
  6537. this.lines = [];
  6538. this.states = [];
  6539. this.start(0);
  6540. };
  6541. this.setDocument = function(doc) {
  6542. this.doc = doc;
  6543. this.lines = [];
  6544. this.states = [];
  6545. this.stop();
  6546. };
  6547. this.fireUpdateEvent = function(firstRow, lastRow) {
  6548. var data = {
  6549. first: firstRow,
  6550. last: lastRow
  6551. };
  6552. this._signal("update", {data: data});
  6553. };
  6554. this.start = function(startRow) {
  6555. this.currentLine = Math.min(startRow || 0, this.currentLine, this.doc.getLength());
  6556. this.lines.splice(this.currentLine, this.lines.length);
  6557. this.states.splice(this.currentLine, this.states.length);
  6558. this.stop();
  6559. this.running = setTimeout(this.$worker, 700);
  6560. };
  6561. this.scheduleStart = function() {
  6562. if (!this.running)
  6563. this.running = setTimeout(this.$worker, 700);
  6564. }
  6565. this.$updateOnChange = function(delta) {
  6566. var startRow = delta.start.row;
  6567. var len = delta.end.row - startRow;
  6568. if (len === 0) {
  6569. this.lines[startRow] = null;
  6570. } else if (delta.action == "remove") {
  6571. this.lines.splice(startRow, len + 1, null);
  6572. this.states.splice(startRow, len + 1, null);
  6573. } else {
  6574. var args = Array(len + 1);
  6575. args.unshift(startRow, 1);
  6576. this.lines.splice.apply(this.lines, args);
  6577. this.states.splice.apply(this.states, args);
  6578. }
  6579. this.currentLine = Math.min(startRow, this.currentLine, this.doc.getLength());
  6580. this.stop();
  6581. };
  6582. this.stop = function() {
  6583. if (this.running)
  6584. clearTimeout(this.running);
  6585. this.running = false;
  6586. };
  6587. this.getTokens = function(row) {
  6588. return this.lines[row] || this.$tokenizeRow(row);
  6589. };
  6590. this.getState = function(row) {
  6591. if (this.currentLine == row)
  6592. this.$tokenizeRow(row);
  6593. return this.states[row] || "start";
  6594. };
  6595. this.$tokenizeRow = function(row) {
  6596. var line = this.doc.getLine(row);
  6597. var state = this.states[row - 1];
  6598. var data = this.tokenizer.getLineTokens(line, state, row);
  6599. if (this.states[row] + "" !== data.state + "") {
  6600. this.states[row] = data.state;
  6601. this.lines[row + 1] = null;
  6602. if (this.currentLine > row + 1)
  6603. this.currentLine = row + 1;
  6604. } else if (this.currentLine == row) {
  6605. this.currentLine = row + 1;
  6606. }
  6607. return this.lines[row] = data.tokens;
  6608. };
  6609. }).call(BackgroundTokenizer.prototype);
  6610. exports.BackgroundTokenizer = BackgroundTokenizer;
  6611. });
  6612. define("ace/search_highlight",["require","exports","module","ace/lib/lang","ace/lib/oop","ace/range"], function(require, exports, module) {
  6613. "use strict";
  6614. var lang = require("./lib/lang");
  6615. var oop = require("./lib/oop");
  6616. var Range = require("./range").Range;
  6617. var SearchHighlight = function(regExp, clazz, type) {
  6618. this.setRegexp(regExp);
  6619. this.clazz = clazz;
  6620. this.type = type || "text";
  6621. };
  6622. (function() {
  6623. this.MAX_RANGES = 500;
  6624. this.setRegexp = function(regExp) {
  6625. if (this.regExp+"" == regExp+"")
  6626. return;
  6627. this.regExp = regExp;
  6628. this.cache = [];
  6629. };
  6630. this.update = function(html, markerLayer, session, config) {
  6631. if (!this.regExp)
  6632. return;
  6633. var start = config.firstRow, end = config.lastRow;
  6634. for (var i = start; i <= end; i++) {
  6635. var ranges = this.cache[i];
  6636. if (ranges == null) {
  6637. ranges = lang.getMatchOffsets(session.getLine(i), this.regExp);
  6638. if (ranges.length > this.MAX_RANGES)
  6639. ranges = ranges.slice(0, this.MAX_RANGES);
  6640. ranges = ranges.map(function(match) {
  6641. return new Range(i, match.offset, i, match.offset + match.length);
  6642. });
  6643. this.cache[i] = ranges.length ? ranges : "";
  6644. }
  6645. for (var j = ranges.length; j --; ) {
  6646. markerLayer.drawSingleLineMarker(
  6647. html, ranges[j].toScreenRange(session), this.clazz, config);
  6648. }
  6649. }
  6650. };
  6651. }).call(SearchHighlight.prototype);
  6652. exports.SearchHighlight = SearchHighlight;
  6653. });
  6654. define("ace/edit_session/fold_line",["require","exports","module","ace/range"], function(require, exports, module) {
  6655. "use strict";
  6656. var Range = require("../range").Range;
  6657. function FoldLine(foldData, folds) {
  6658. this.foldData = foldData;
  6659. if (Array.isArray(folds)) {
  6660. this.folds = folds;
  6661. } else {
  6662. folds = this.folds = [ folds ];
  6663. }
  6664. var last = folds[folds.length - 1];
  6665. this.range = new Range(folds[0].start.row, folds[0].start.column,
  6666. last.end.row, last.end.column);
  6667. this.start = this.range.start;
  6668. this.end = this.range.end;
  6669. this.folds.forEach(function(fold) {
  6670. fold.setFoldLine(this);
  6671. }, this);
  6672. }
  6673. (function() {
  6674. this.shiftRow = function(shift) {
  6675. this.start.row += shift;
  6676. this.end.row += shift;
  6677. this.folds.forEach(function(fold) {
  6678. fold.start.row += shift;
  6679. fold.end.row += shift;
  6680. });
  6681. };
  6682. this.addFold = function(fold) {
  6683. if (fold.sameRow) {
  6684. if (fold.start.row < this.startRow || fold.endRow > this.endRow) {
  6685. throw new Error("Can't add a fold to this FoldLine as it has no connection");
  6686. }
  6687. this.folds.push(fold);
  6688. this.folds.sort(function(a, b) {
  6689. return -a.range.compareEnd(b.start.row, b.start.column);
  6690. });
  6691. if (this.range.compareEnd(fold.start.row, fold.start.column) > 0) {
  6692. this.end.row = fold.end.row;
  6693. this.end.column = fold.end.column;
  6694. } else if (this.range.compareStart(fold.end.row, fold.end.column) < 0) {
  6695. this.start.row = fold.start.row;
  6696. this.start.column = fold.start.column;
  6697. }
  6698. } else if (fold.start.row == this.end.row) {
  6699. this.folds.push(fold);
  6700. this.end.row = fold.end.row;
  6701. this.end.column = fold.end.column;
  6702. } else if (fold.end.row == this.start.row) {
  6703. this.folds.unshift(fold);
  6704. this.start.row = fold.start.row;
  6705. this.start.column = fold.start.column;
  6706. } else {
  6707. throw new Error("Trying to add fold to FoldRow that doesn't have a matching row");
  6708. }
  6709. fold.foldLine = this;
  6710. };
  6711. this.containsRow = function(row) {
  6712. return row >= this.start.row && row <= this.end.row;
  6713. };
  6714. this.walk = function(callback, endRow, endColumn) {
  6715. var lastEnd = 0,
  6716. folds = this.folds,
  6717. fold,
  6718. cmp, stop, isNewRow = true;
  6719. if (endRow == null) {
  6720. endRow = this.end.row;
  6721. endColumn = this.end.column;
  6722. }
  6723. for (var i = 0; i < folds.length; i++) {
  6724. fold = folds[i];
  6725. cmp = fold.range.compareStart(endRow, endColumn);
  6726. if (cmp == -1) {
  6727. callback(null, endRow, endColumn, lastEnd, isNewRow);
  6728. return;
  6729. }
  6730. stop = callback(null, fold.start.row, fold.start.column, lastEnd, isNewRow);
  6731. stop = !stop && callback(fold.placeholder, fold.start.row, fold.start.column, lastEnd);
  6732. if (stop || cmp === 0) {
  6733. return;
  6734. }
  6735. isNewRow = !fold.sameRow;
  6736. lastEnd = fold.end.column;
  6737. }
  6738. callback(null, endRow, endColumn, lastEnd, isNewRow);
  6739. };
  6740. this.getNextFoldTo = function(row, column) {
  6741. var fold, cmp;
  6742. for (var i = 0; i < this.folds.length; i++) {
  6743. fold = this.folds[i];
  6744. cmp = fold.range.compareEnd(row, column);
  6745. if (cmp == -1) {
  6746. return {
  6747. fold: fold,
  6748. kind: "after"
  6749. };
  6750. } else if (cmp === 0) {
  6751. return {
  6752. fold: fold,
  6753. kind: "inside"
  6754. };
  6755. }
  6756. }
  6757. return null;
  6758. };
  6759. this.addRemoveChars = function(row, column, len) {
  6760. var ret = this.getNextFoldTo(row, column),
  6761. fold, folds;
  6762. if (ret) {
  6763. fold = ret.fold;
  6764. if (ret.kind == "inside"
  6765. && fold.start.column != column
  6766. && fold.start.row != row)
  6767. {
  6768. window.console && window.console.log(row, column, fold);
  6769. } else if (fold.start.row == row) {
  6770. folds = this.folds;
  6771. var i = folds.indexOf(fold);
  6772. if (i === 0) {
  6773. this.start.column += len;
  6774. }
  6775. for (i; i < folds.length; i++) {
  6776. fold = folds[i];
  6777. fold.start.column += len;
  6778. if (!fold.sameRow) {
  6779. return;
  6780. }
  6781. fold.end.column += len;
  6782. }
  6783. this.end.column += len;
  6784. }
  6785. }
  6786. };
  6787. this.split = function(row, column) {
  6788. var pos = this.getNextFoldTo(row, column);
  6789. if (!pos || pos.kind == "inside")
  6790. return null;
  6791. var fold = pos.fold;
  6792. var folds = this.folds;
  6793. var foldData = this.foldData;
  6794. var i = folds.indexOf(fold);
  6795. var foldBefore = folds[i - 1];
  6796. this.end.row = foldBefore.end.row;
  6797. this.end.column = foldBefore.end.column;
  6798. folds = folds.splice(i, folds.length - i);
  6799. var newFoldLine = new FoldLine(foldData, folds);
  6800. foldData.splice(foldData.indexOf(this) + 1, 0, newFoldLine);
  6801. return newFoldLine;
  6802. };
  6803. this.merge = function(foldLineNext) {
  6804. var folds = foldLineNext.folds;
  6805. for (var i = 0; i < folds.length; i++) {
  6806. this.addFold(folds[i]);
  6807. }
  6808. var foldData = this.foldData;
  6809. foldData.splice(foldData.indexOf(foldLineNext), 1);
  6810. };
  6811. this.toString = function() {
  6812. var ret = [this.range.toString() + ": [" ];
  6813. this.folds.forEach(function(fold) {
  6814. ret.push(" " + fold.toString());
  6815. });
  6816. ret.push("]");
  6817. return ret.join("\n");
  6818. };
  6819. this.idxToPosition = function(idx) {
  6820. var lastFoldEndColumn = 0;
  6821. for (var i = 0; i < this.folds.length; i++) {
  6822. var fold = this.folds[i];
  6823. idx -= fold.start.column - lastFoldEndColumn;
  6824. if (idx < 0) {
  6825. return {
  6826. row: fold.start.row,
  6827. column: fold.start.column + idx
  6828. };
  6829. }
  6830. idx -= fold.placeholder.length;
  6831. if (idx < 0) {
  6832. return fold.start;
  6833. }
  6834. lastFoldEndColumn = fold.end.column;
  6835. }
  6836. return {
  6837. row: this.end.row,
  6838. column: this.end.column + idx
  6839. };
  6840. };
  6841. }).call(FoldLine.prototype);
  6842. exports.FoldLine = FoldLine;
  6843. });
  6844. define("ace/range_list",["require","exports","module","ace/range"], function(require, exports, module) {
  6845. "use strict";
  6846. var Range = require("./range").Range;
  6847. var comparePoints = Range.comparePoints;
  6848. var RangeList = function() {
  6849. this.ranges = [];
  6850. };
  6851. (function() {
  6852. this.comparePoints = comparePoints;
  6853. this.pointIndex = function(pos, excludeEdges, startIndex) {
  6854. var list = this.ranges;
  6855. for (var i = startIndex || 0; i < list.length; i++) {
  6856. var range = list[i];
  6857. var cmpEnd = comparePoints(pos, range.end);
  6858. if (cmpEnd > 0)
  6859. continue;
  6860. var cmpStart = comparePoints(pos, range.start);
  6861. if (cmpEnd === 0)
  6862. return excludeEdges && cmpStart !== 0 ? -i-2 : i;
  6863. if (cmpStart > 0 || (cmpStart === 0 && !excludeEdges))
  6864. return i;
  6865. return -i-1;
  6866. }
  6867. return -i - 1;
  6868. };
  6869. this.add = function(range) {
  6870. var excludeEdges = !range.isEmpty();
  6871. var startIndex = this.pointIndex(range.start, excludeEdges);
  6872. if (startIndex < 0)
  6873. startIndex = -startIndex - 1;
  6874. var endIndex = this.pointIndex(range.end, excludeEdges, startIndex);
  6875. if (endIndex < 0)
  6876. endIndex = -endIndex - 1;
  6877. else
  6878. endIndex++;
  6879. return this.ranges.splice(startIndex, endIndex - startIndex, range);
  6880. };
  6881. this.addList = function(list) {
  6882. var removed = [];
  6883. for (var i = list.length; i--; ) {
  6884. removed.push.apply(removed, this.add(list[i]));
  6885. }
  6886. return removed;
  6887. };
  6888. this.substractPoint = function(pos) {
  6889. var i = this.pointIndex(pos);
  6890. if (i >= 0)
  6891. return this.ranges.splice(i, 1);
  6892. };
  6893. this.merge = function() {
  6894. var removed = [];
  6895. var list = this.ranges;
  6896. list = list.sort(function(a, b) {
  6897. return comparePoints(a.start, b.start);
  6898. });
  6899. var next = list[0], range;
  6900. for (var i = 1; i < list.length; i++) {
  6901. range = next;
  6902. next = list[i];
  6903. var cmp = comparePoints(range.end, next.start);
  6904. if (cmp < 0)
  6905. continue;
  6906. if (cmp == 0 && !range.isEmpty() && !next.isEmpty())
  6907. continue;
  6908. if (comparePoints(range.end, next.end) < 0) {
  6909. range.end.row = next.end.row;
  6910. range.end.column = next.end.column;
  6911. }
  6912. list.splice(i, 1);
  6913. removed.push(next);
  6914. next = range;
  6915. i--;
  6916. }
  6917. this.ranges = list;
  6918. return removed;
  6919. };
  6920. this.contains = function(row, column) {
  6921. return this.pointIndex({row: row, column: column}) >= 0;
  6922. };
  6923. this.containsPoint = function(pos) {
  6924. return this.pointIndex(pos) >= 0;
  6925. };
  6926. this.rangeAtPoint = function(pos) {
  6927. var i = this.pointIndex(pos);
  6928. if (i >= 0)
  6929. return this.ranges[i];
  6930. };
  6931. this.clipRows = function(startRow, endRow) {
  6932. var list = this.ranges;
  6933. if (list[0].start.row > endRow || list[list.length - 1].start.row < startRow)
  6934. return [];
  6935. var startIndex = this.pointIndex({row: startRow, column: 0});
  6936. if (startIndex < 0)
  6937. startIndex = -startIndex - 1;
  6938. var endIndex = this.pointIndex({row: endRow, column: 0}, startIndex);
  6939. if (endIndex < 0)
  6940. endIndex = -endIndex - 1;
  6941. var clipped = [];
  6942. for (var i = startIndex; i < endIndex; i++) {
  6943. clipped.push(list[i]);
  6944. }
  6945. return clipped;
  6946. };
  6947. this.removeAll = function() {
  6948. return this.ranges.splice(0, this.ranges.length);
  6949. };
  6950. this.attach = function(session) {
  6951. if (this.session)
  6952. this.detach();
  6953. this.session = session;
  6954. this.onChange = this.$onChange.bind(this);
  6955. this.session.on('change', this.onChange);
  6956. };
  6957. this.detach = function() {
  6958. if (!this.session)
  6959. return;
  6960. this.session.removeListener('change', this.onChange);
  6961. this.session = null;
  6962. };
  6963. this.$onChange = function(delta) {
  6964. if (delta.action == "insert"){
  6965. var start = delta.start;
  6966. var end = delta.end;
  6967. } else {
  6968. var end = delta.start;
  6969. var start = delta.end;
  6970. }
  6971. var startRow = start.row;
  6972. var endRow = end.row;
  6973. var lineDif = endRow - startRow;
  6974. var colDiff = -start.column + end.column;
  6975. var ranges = this.ranges;
  6976. for (var i = 0, n = ranges.length; i < n; i++) {
  6977. var r = ranges[i];
  6978. if (r.end.row < startRow)
  6979. continue;
  6980. if (r.start.row > startRow)
  6981. break;
  6982. if (r.start.row == startRow && r.start.column >= start.column ) {
  6983. if (r.start.column == start.column && this.$insertRight) {
  6984. } else {
  6985. r.start.column += colDiff;
  6986. r.start.row += lineDif;
  6987. }
  6988. }
  6989. if (r.end.row == startRow && r.end.column >= start.column) {
  6990. if (r.end.column == start.column && this.$insertRight) {
  6991. continue;
  6992. }
  6993. if (r.end.column == start.column && colDiff > 0 && i < n - 1) {
  6994. if (r.end.column > r.start.column && r.end.column == ranges[i+1].start.column)
  6995. r.end.column -= colDiff;
  6996. }
  6997. r.end.column += colDiff;
  6998. r.end.row += lineDif;
  6999. }
  7000. }
  7001. if (lineDif != 0 && i < n) {
  7002. for (; i < n; i++) {
  7003. var r = ranges[i];
  7004. r.start.row += lineDif;
  7005. r.end.row += lineDif;
  7006. }
  7007. }
  7008. };
  7009. }).call(RangeList.prototype);
  7010. exports.RangeList = RangeList;
  7011. });
  7012. define("ace/edit_session/fold",["require","exports","module","ace/range","ace/range_list","ace/lib/oop"], function(require, exports, module) {
  7013. "use strict";
  7014. var Range = require("../range").Range;
  7015. var RangeList = require("../range_list").RangeList;
  7016. var oop = require("../lib/oop")
  7017. var Fold = exports.Fold = function(range, placeholder) {
  7018. this.foldLine = null;
  7019. this.placeholder = placeholder;
  7020. this.range = range;
  7021. this.start = range.start;
  7022. this.end = range.end;
  7023. this.sameRow = range.start.row == range.end.row;
  7024. this.subFolds = this.ranges = [];
  7025. };
  7026. oop.inherits(Fold, RangeList);
  7027. (function() {
  7028. this.toString = function() {
  7029. return '"' + this.placeholder + '" ' + this.range.toString();
  7030. };
  7031. this.setFoldLine = function(foldLine) {
  7032. this.foldLine = foldLine;
  7033. this.subFolds.forEach(function(fold) {
  7034. fold.setFoldLine(foldLine);
  7035. });
  7036. };
  7037. this.clone = function() {
  7038. var range = this.range.clone();
  7039. var fold = new Fold(range, this.placeholder);
  7040. this.subFolds.forEach(function(subFold) {
  7041. fold.subFolds.push(subFold.clone());
  7042. });
  7043. fold.collapseChildren = this.collapseChildren;
  7044. return fold;
  7045. };
  7046. this.addSubFold = function(fold) {
  7047. if (this.range.isEqual(fold))
  7048. return;
  7049. if (!this.range.containsRange(fold))
  7050. throw new Error("A fold can't intersect already existing fold" + fold.range + this.range);
  7051. consumeRange(fold, this.start);
  7052. var row = fold.start.row, column = fold.start.column;
  7053. for (var i = 0, cmp = -1; i < this.subFolds.length; i++) {
  7054. cmp = this.subFolds[i].range.compare(row, column);
  7055. if (cmp != 1)
  7056. break;
  7057. }
  7058. var afterStart = this.subFolds[i];
  7059. if (cmp == 0)
  7060. return afterStart.addSubFold(fold);
  7061. var row = fold.range.end.row, column = fold.range.end.column;
  7062. for (var j = i, cmp = -1; j < this.subFolds.length; j++) {
  7063. cmp = this.subFolds[j].range.compare(row, column);
  7064. if (cmp != 1)
  7065. break;
  7066. }
  7067. var afterEnd = this.subFolds[j];
  7068. if (cmp == 0)
  7069. throw new Error("A fold can't intersect already existing fold" + fold.range + this.range);
  7070. var consumedFolds = this.subFolds.splice(i, j - i, fold);
  7071. fold.setFoldLine(this.foldLine);
  7072. return fold;
  7073. };
  7074. this.restoreRange = function(range) {
  7075. return restoreRange(range, this.start);
  7076. };
  7077. }).call(Fold.prototype);
  7078. function consumePoint(point, anchor) {
  7079. point.row -= anchor.row;
  7080. if (point.row == 0)
  7081. point.column -= anchor.column;
  7082. }
  7083. function consumeRange(range, anchor) {
  7084. consumePoint(range.start, anchor);
  7085. consumePoint(range.end, anchor);
  7086. }
  7087. function restorePoint(point, anchor) {
  7088. if (point.row == 0)
  7089. point.column += anchor.column;
  7090. point.row += anchor.row;
  7091. }
  7092. function restoreRange(range, anchor) {
  7093. restorePoint(range.start, anchor);
  7094. restorePoint(range.end, anchor);
  7095. }
  7096. });
  7097. define("ace/edit_session/folding",["require","exports","module","ace/range","ace/edit_session/fold_line","ace/edit_session/fold","ace/token_iterator"], function(require, exports, module) {
  7098. "use strict";
  7099. var Range = require("../range").Range;
  7100. var FoldLine = require("./fold_line").FoldLine;
  7101. var Fold = require("./fold").Fold;
  7102. var TokenIterator = require("../token_iterator").TokenIterator;
  7103. function Folding() {
  7104. this.getFoldAt = function(row, column, side) {
  7105. var foldLine = this.getFoldLine(row);
  7106. if (!foldLine)
  7107. return null;
  7108. var folds = foldLine.folds;
  7109. for (var i = 0; i < folds.length; i++) {
  7110. var fold = folds[i];
  7111. if (fold.range.contains(row, column)) {
  7112. if (side == 1 && fold.range.isEnd(row, column)) {
  7113. continue;
  7114. } else if (side == -1 && fold.range.isStart(row, column)) {
  7115. continue;
  7116. }
  7117. return fold;
  7118. }
  7119. }
  7120. };
  7121. this.getFoldsInRange = function(range) {
  7122. var start = range.start;
  7123. var end = range.end;
  7124. var foldLines = this.$foldData;
  7125. var foundFolds = [];
  7126. start.column += 1;
  7127. end.column -= 1;
  7128. for (var i = 0; i < foldLines.length; i++) {
  7129. var cmp = foldLines[i].range.compareRange(range);
  7130. if (cmp == 2) {
  7131. continue;
  7132. }
  7133. else if (cmp == -2) {
  7134. break;
  7135. }
  7136. var folds = foldLines[i].folds;
  7137. for (var j = 0; j < folds.length; j++) {
  7138. var fold = folds[j];
  7139. cmp = fold.range.compareRange(range);
  7140. if (cmp == -2) {
  7141. break;
  7142. } else if (cmp == 2) {
  7143. continue;
  7144. } else
  7145. if (cmp == 42) {
  7146. break;
  7147. }
  7148. foundFolds.push(fold);
  7149. }
  7150. }
  7151. start.column -= 1;
  7152. end.column += 1;
  7153. return foundFolds;
  7154. };
  7155. this.getFoldsInRangeList = function(ranges) {
  7156. if (Array.isArray(ranges)) {
  7157. var folds = [];
  7158. ranges.forEach(function(range) {
  7159. folds = folds.concat(this.getFoldsInRange(range));
  7160. }, this);
  7161. } else {
  7162. var folds = this.getFoldsInRange(ranges);
  7163. }
  7164. return folds;
  7165. };
  7166. this.getAllFolds = function() {
  7167. var folds = [];
  7168. var foldLines = this.$foldData;
  7169. for (var i = 0; i < foldLines.length; i++)
  7170. for (var j = 0; j < foldLines[i].folds.length; j++)
  7171. folds.push(foldLines[i].folds[j]);
  7172. return folds;
  7173. };
  7174. this.getFoldStringAt = function(row, column, trim, foldLine) {
  7175. foldLine = foldLine || this.getFoldLine(row);
  7176. if (!foldLine)
  7177. return null;
  7178. var lastFold = {
  7179. end: { column: 0 }
  7180. };
  7181. var str, fold;
  7182. for (var i = 0; i < foldLine.folds.length; i++) {
  7183. fold = foldLine.folds[i];
  7184. var cmp = fold.range.compareEnd(row, column);
  7185. if (cmp == -1) {
  7186. str = this
  7187. .getLine(fold.start.row)
  7188. .substring(lastFold.end.column, fold.start.column);
  7189. break;
  7190. }
  7191. else if (cmp === 0) {
  7192. return null;
  7193. }
  7194. lastFold = fold;
  7195. }
  7196. if (!str)
  7197. str = this.getLine(fold.start.row).substring(lastFold.end.column);
  7198. if (trim == -1)
  7199. return str.substring(0, column - lastFold.end.column);
  7200. else if (trim == 1)
  7201. return str.substring(column - lastFold.end.column);
  7202. else
  7203. return str;
  7204. };
  7205. this.getFoldLine = function(docRow, startFoldLine) {
  7206. var foldData = this.$foldData;
  7207. var i = 0;
  7208. if (startFoldLine)
  7209. i = foldData.indexOf(startFoldLine);
  7210. if (i == -1)
  7211. i = 0;
  7212. for (i; i < foldData.length; i++) {
  7213. var foldLine = foldData[i];
  7214. if (foldLine.start.row <= docRow && foldLine.end.row >= docRow) {
  7215. return foldLine;
  7216. } else if (foldLine.end.row > docRow) {
  7217. return null;
  7218. }
  7219. }
  7220. return null;
  7221. };
  7222. this.getNextFoldLine = function(docRow, startFoldLine) {
  7223. var foldData = this.$foldData;
  7224. var i = 0;
  7225. if (startFoldLine)
  7226. i = foldData.indexOf(startFoldLine);
  7227. if (i == -1)
  7228. i = 0;
  7229. for (i; i < foldData.length; i++) {
  7230. var foldLine = foldData[i];
  7231. if (foldLine.end.row >= docRow) {
  7232. return foldLine;
  7233. }
  7234. }
  7235. return null;
  7236. };
  7237. this.getFoldedRowCount = function(first, last) {
  7238. var foldData = this.$foldData, rowCount = last-first+1;
  7239. for (var i = 0; i < foldData.length; i++) {
  7240. var foldLine = foldData[i],
  7241. end = foldLine.end.row,
  7242. start = foldLine.start.row;
  7243. if (end >= last) {
  7244. if (start < last) {
  7245. if (start >= first)
  7246. rowCount -= last-start;
  7247. else
  7248. rowCount = 0; // in one fold
  7249. }
  7250. break;
  7251. } else if (end >= first){
  7252. if (start >= first) // fold inside range
  7253. rowCount -= end-start;
  7254. else
  7255. rowCount -= end-first+1;
  7256. }
  7257. }
  7258. return rowCount;
  7259. };
  7260. this.$addFoldLine = function(foldLine) {
  7261. this.$foldData.push(foldLine);
  7262. this.$foldData.sort(function(a, b) {
  7263. return a.start.row - b.start.row;
  7264. });
  7265. return foldLine;
  7266. };
  7267. this.addFold = function(placeholder, range) {
  7268. var foldData = this.$foldData;
  7269. var added = false;
  7270. var fold;
  7271. if (placeholder instanceof Fold)
  7272. fold = placeholder;
  7273. else {
  7274. fold = new Fold(range, placeholder);
  7275. fold.collapseChildren = range.collapseChildren;
  7276. }
  7277. this.$clipRangeToDocument(fold.range);
  7278. var startRow = fold.start.row;
  7279. var startColumn = fold.start.column;
  7280. var endRow = fold.end.row;
  7281. var endColumn = fold.end.column;
  7282. if (!(startRow < endRow ||
  7283. startRow == endRow && startColumn <= endColumn - 2))
  7284. throw new Error("The range has to be at least 2 characters width");
  7285. var startFold = this.getFoldAt(startRow, startColumn, 1);
  7286. var endFold = this.getFoldAt(endRow, endColumn, -1);
  7287. if (startFold && endFold == startFold)
  7288. return startFold.addSubFold(fold);
  7289. if (startFold && !startFold.range.isStart(startRow, startColumn))
  7290. this.removeFold(startFold);
  7291. if (endFold && !endFold.range.isEnd(endRow, endColumn))
  7292. this.removeFold(endFold);
  7293. var folds = this.getFoldsInRange(fold.range);
  7294. if (folds.length > 0) {
  7295. this.removeFolds(folds);
  7296. folds.forEach(function(subFold) {
  7297. fold.addSubFold(subFold);
  7298. });
  7299. }
  7300. for (var i = 0; i < foldData.length; i++) {
  7301. var foldLine = foldData[i];
  7302. if (endRow == foldLine.start.row) {
  7303. foldLine.addFold(fold);
  7304. added = true;
  7305. break;
  7306. } else if (startRow == foldLine.end.row) {
  7307. foldLine.addFold(fold);
  7308. added = true;
  7309. if (!fold.sameRow) {
  7310. var foldLineNext = foldData[i + 1];
  7311. if (foldLineNext && foldLineNext.start.row == endRow) {
  7312. foldLine.merge(foldLineNext);
  7313. break;
  7314. }
  7315. }
  7316. break;
  7317. } else if (endRow <= foldLine.start.row) {
  7318. break;
  7319. }
  7320. }
  7321. if (!added)
  7322. foldLine = this.$addFoldLine(new FoldLine(this.$foldData, fold));
  7323. if (this.$useWrapMode)
  7324. this.$updateWrapData(foldLine.start.row, foldLine.start.row);
  7325. else
  7326. this.$updateRowLengthCache(foldLine.start.row, foldLine.start.row);
  7327. this.$modified = true;
  7328. this._signal("changeFold", { data: fold, action: "add" });
  7329. return fold;
  7330. };
  7331. this.addFolds = function(folds) {
  7332. folds.forEach(function(fold) {
  7333. this.addFold(fold);
  7334. }, this);
  7335. };
  7336. this.removeFold = function(fold) {
  7337. var foldLine = fold.foldLine;
  7338. var startRow = foldLine.start.row;
  7339. var endRow = foldLine.end.row;
  7340. var foldLines = this.$foldData;
  7341. var folds = foldLine.folds;
  7342. if (folds.length == 1) {
  7343. foldLines.splice(foldLines.indexOf(foldLine), 1);
  7344. } else
  7345. if (foldLine.range.isEnd(fold.end.row, fold.end.column)) {
  7346. folds.pop();
  7347. foldLine.end.row = folds[folds.length - 1].end.row;
  7348. foldLine.end.column = folds[folds.length - 1].end.column;
  7349. } else
  7350. if (foldLine.range.isStart(fold.start.row, fold.start.column)) {
  7351. folds.shift();
  7352. foldLine.start.row = folds[0].start.row;
  7353. foldLine.start.column = folds[0].start.column;
  7354. } else
  7355. if (fold.sameRow) {
  7356. folds.splice(folds.indexOf(fold), 1);
  7357. } else
  7358. {
  7359. var newFoldLine = foldLine.split(fold.start.row, fold.start.column);
  7360. folds = newFoldLine.folds;
  7361. folds.shift();
  7362. newFoldLine.start.row = folds[0].start.row;
  7363. newFoldLine.start.column = folds[0].start.column;
  7364. }
  7365. if (!this.$updating) {
  7366. if (this.$useWrapMode)
  7367. this.$updateWrapData(startRow, endRow);
  7368. else
  7369. this.$updateRowLengthCache(startRow, endRow);
  7370. }
  7371. this.$modified = true;
  7372. this._signal("changeFold", { data: fold, action: "remove" });
  7373. };
  7374. this.removeFolds = function(folds) {
  7375. var cloneFolds = [];
  7376. for (var i = 0; i < folds.length; i++) {
  7377. cloneFolds.push(folds[i]);
  7378. }
  7379. cloneFolds.forEach(function(fold) {
  7380. this.removeFold(fold);
  7381. }, this);
  7382. this.$modified = true;
  7383. };
  7384. this.expandFold = function(fold) {
  7385. this.removeFold(fold);
  7386. fold.subFolds.forEach(function(subFold) {
  7387. fold.restoreRange(subFold);
  7388. this.addFold(subFold);
  7389. }, this);
  7390. if (fold.collapseChildren > 0) {
  7391. this.foldAll(fold.start.row+1, fold.end.row, fold.collapseChildren-1);
  7392. }
  7393. fold.subFolds = [];
  7394. };
  7395. this.expandFolds = function(folds) {
  7396. folds.forEach(function(fold) {
  7397. this.expandFold(fold);
  7398. }, this);
  7399. };
  7400. this.unfold = function(location, expandInner) {
  7401. var range, folds;
  7402. if (location == null) {
  7403. range = new Range(0, 0, this.getLength(), 0);
  7404. expandInner = true;
  7405. } else if (typeof location == "number")
  7406. range = new Range(location, 0, location, this.getLine(location).length);
  7407. else if ("row" in location)
  7408. range = Range.fromPoints(location, location);
  7409. else
  7410. range = location;
  7411. folds = this.getFoldsInRangeList(range);
  7412. if (expandInner) {
  7413. this.removeFolds(folds);
  7414. } else {
  7415. var subFolds = folds;
  7416. while (subFolds.length) {
  7417. this.expandFolds(subFolds);
  7418. subFolds = this.getFoldsInRangeList(range);
  7419. }
  7420. }
  7421. if (folds.length)
  7422. return folds;
  7423. };
  7424. this.isRowFolded = function(docRow, startFoldRow) {
  7425. return !!this.getFoldLine(docRow, startFoldRow);
  7426. };
  7427. this.getRowFoldEnd = function(docRow, startFoldRow) {
  7428. var foldLine = this.getFoldLine(docRow, startFoldRow);
  7429. return foldLine ? foldLine.end.row : docRow;
  7430. };
  7431. this.getRowFoldStart = function(docRow, startFoldRow) {
  7432. var foldLine = this.getFoldLine(docRow, startFoldRow);
  7433. return foldLine ? foldLine.start.row : docRow;
  7434. };
  7435. this.getFoldDisplayLine = function(foldLine, endRow, endColumn, startRow, startColumn) {
  7436. if (startRow == null)
  7437. startRow = foldLine.start.row;
  7438. if (startColumn == null)
  7439. startColumn = 0;
  7440. if (endRow == null)
  7441. endRow = foldLine.end.row;
  7442. if (endColumn == null)
  7443. endColumn = this.getLine(endRow).length;
  7444. var doc = this.doc;
  7445. var textLine = "";
  7446. foldLine.walk(function(placeholder, row, column, lastColumn) {
  7447. if (row < startRow)
  7448. return;
  7449. if (row == startRow) {
  7450. if (column < startColumn)
  7451. return;
  7452. lastColumn = Math.max(startColumn, lastColumn);
  7453. }
  7454. if (placeholder != null) {
  7455. textLine += placeholder;
  7456. } else {
  7457. textLine += doc.getLine(row).substring(lastColumn, column);
  7458. }
  7459. }, endRow, endColumn);
  7460. return textLine;
  7461. };
  7462. this.getDisplayLine = function(row, endColumn, startRow, startColumn) {
  7463. var foldLine = this.getFoldLine(row);
  7464. if (!foldLine) {
  7465. var line;
  7466. line = this.doc.getLine(row);
  7467. return line.substring(startColumn || 0, endColumn || line.length);
  7468. } else {
  7469. return this.getFoldDisplayLine(
  7470. foldLine, row, endColumn, startRow, startColumn);
  7471. }
  7472. };
  7473. this.$cloneFoldData = function() {
  7474. var fd = [];
  7475. fd = this.$foldData.map(function(foldLine) {
  7476. var folds = foldLine.folds.map(function(fold) {
  7477. return fold.clone();
  7478. });
  7479. return new FoldLine(fd, folds);
  7480. });
  7481. return fd;
  7482. };
  7483. this.toggleFold = function(tryToUnfold) {
  7484. var selection = this.selection;
  7485. var range = selection.getRange();
  7486. var fold;
  7487. var bracketPos;
  7488. if (range.isEmpty()) {
  7489. var cursor = range.start;
  7490. fold = this.getFoldAt(cursor.row, cursor.column);
  7491. if (fold) {
  7492. this.expandFold(fold);
  7493. return;
  7494. } else if (bracketPos = this.findMatchingBracket(cursor)) {
  7495. if (range.comparePoint(bracketPos) == 1) {
  7496. range.end = bracketPos;
  7497. } else {
  7498. range.start = bracketPos;
  7499. range.start.column++;
  7500. range.end.column--;
  7501. }
  7502. } else if (bracketPos = this.findMatchingBracket({row: cursor.row, column: cursor.column + 1})) {
  7503. if (range.comparePoint(bracketPos) == 1)
  7504. range.end = bracketPos;
  7505. else
  7506. range.start = bracketPos;
  7507. range.start.column++;
  7508. } else {
  7509. range = this.getCommentFoldRange(cursor.row, cursor.column) || range;
  7510. }
  7511. } else {
  7512. var folds = this.getFoldsInRange(range);
  7513. if (tryToUnfold && folds.length) {
  7514. this.expandFolds(folds);
  7515. return;
  7516. } else if (folds.length == 1 ) {
  7517. fold = folds[0];
  7518. }
  7519. }
  7520. if (!fold)
  7521. fold = this.getFoldAt(range.start.row, range.start.column);
  7522. if (fold && fold.range.toString() == range.toString()) {
  7523. this.expandFold(fold);
  7524. return;
  7525. }
  7526. var placeholder = "...";
  7527. if (!range.isMultiLine()) {
  7528. placeholder = this.getTextRange(range);
  7529. if (placeholder.length < 4)
  7530. return;
  7531. placeholder = placeholder.trim().substring(0, 2) + "..";
  7532. }
  7533. this.addFold(placeholder, range);
  7534. };
  7535. this.getCommentFoldRange = function(row, column, dir) {
  7536. var iterator = new TokenIterator(this, row, column);
  7537. var token = iterator.getCurrentToken();
  7538. var type = token.type;
  7539. if (token && /^comment|string/.test(type)) {
  7540. type = type.match(/comment|string/)[0];
  7541. if (type == "comment")
  7542. type += "|doc-start";
  7543. var re = new RegExp(type);
  7544. var range = new Range();
  7545. if (dir != 1) {
  7546. do {
  7547. token = iterator.stepBackward();
  7548. } while (token && re.test(token.type));
  7549. iterator.stepForward();
  7550. }
  7551. range.start.row = iterator.getCurrentTokenRow();
  7552. range.start.column = iterator.getCurrentTokenColumn() + 2;
  7553. iterator = new TokenIterator(this, row, column);
  7554. if (dir != -1) {
  7555. var lastRow = -1;
  7556. do {
  7557. token = iterator.stepForward();
  7558. if (lastRow == -1) {
  7559. var state = this.getState(iterator.$row);
  7560. if (!re.test(state))
  7561. lastRow = iterator.$row;
  7562. } else if (iterator.$row > lastRow) {
  7563. break;
  7564. }
  7565. } while (token && re.test(token.type));
  7566. token = iterator.stepBackward();
  7567. } else
  7568. token = iterator.getCurrentToken();
  7569. range.end.row = iterator.getCurrentTokenRow();
  7570. range.end.column = iterator.getCurrentTokenColumn() + token.value.length - 2;
  7571. return range;
  7572. }
  7573. };
  7574. this.foldAll = function(startRow, endRow, depth) {
  7575. if (depth == undefined)
  7576. depth = 100000; // JSON.stringify doesn't hanle Infinity
  7577. var foldWidgets = this.foldWidgets;
  7578. if (!foldWidgets)
  7579. return; // mode doesn't support folding
  7580. endRow = endRow || this.getLength();
  7581. startRow = startRow || 0;
  7582. for (var row = startRow; row < endRow; row++) {
  7583. if (foldWidgets[row] == null)
  7584. foldWidgets[row] = this.getFoldWidget(row);
  7585. if (foldWidgets[row] != "start")
  7586. continue;
  7587. var range = this.getFoldWidgetRange(row);
  7588. if (range && range.isMultiLine()
  7589. && range.end.row <= endRow
  7590. && range.start.row >= startRow
  7591. ) {
  7592. row = range.end.row;
  7593. try {
  7594. var fold = this.addFold("...", range);
  7595. if (fold)
  7596. fold.collapseChildren = depth;
  7597. } catch(e) {}
  7598. }
  7599. }
  7600. };
  7601. this.$foldStyles = {
  7602. "manual": 1,
  7603. "markbegin": 1,
  7604. "markbeginend": 1
  7605. };
  7606. this.$foldStyle = "markbegin";
  7607. this.setFoldStyle = function(style) {
  7608. if (!this.$foldStyles[style])
  7609. throw new Error("invalid fold style: " + style + "[" + Object.keys(this.$foldStyles).join(", ") + "]");
  7610. if (this.$foldStyle == style)
  7611. return;
  7612. this.$foldStyle = style;
  7613. if (style == "manual")
  7614. this.unfold();
  7615. var mode = this.$foldMode;
  7616. this.$setFolding(null);
  7617. this.$setFolding(mode);
  7618. };
  7619. this.$setFolding = function(foldMode) {
  7620. if (this.$foldMode == foldMode)
  7621. return;
  7622. this.$foldMode = foldMode;
  7623. this.off('change', this.$updateFoldWidgets);
  7624. this.off('tokenizerUpdate', this.$tokenizerUpdateFoldWidgets);
  7625. this._signal("changeAnnotation");
  7626. if (!foldMode || this.$foldStyle == "manual") {
  7627. this.foldWidgets = null;
  7628. return;
  7629. }
  7630. this.foldWidgets = [];
  7631. this.getFoldWidget = foldMode.getFoldWidget.bind(foldMode, this, this.$foldStyle);
  7632. this.getFoldWidgetRange = foldMode.getFoldWidgetRange.bind(foldMode, this, this.$foldStyle);
  7633. this.$updateFoldWidgets = this.updateFoldWidgets.bind(this);
  7634. this.$tokenizerUpdateFoldWidgets = this.tokenizerUpdateFoldWidgets.bind(this);
  7635. this.on('change', this.$updateFoldWidgets);
  7636. this.on('tokenizerUpdate', this.$tokenizerUpdateFoldWidgets);
  7637. };
  7638. this.getParentFoldRangeData = function (row, ignoreCurrent) {
  7639. var fw = this.foldWidgets;
  7640. if (!fw || (ignoreCurrent && fw[row]))
  7641. return {};
  7642. var i = row - 1, firstRange;
  7643. while (i >= 0) {
  7644. var c = fw[i];
  7645. if (c == null)
  7646. c = fw[i] = this.getFoldWidget(i);
  7647. if (c == "start") {
  7648. var range = this.getFoldWidgetRange(i);
  7649. if (!firstRange)
  7650. firstRange = range;
  7651. if (range && range.end.row >= row)
  7652. break;
  7653. }
  7654. i--;
  7655. }
  7656. return {
  7657. range: i !== -1 && range,
  7658. firstRange: firstRange
  7659. };
  7660. };
  7661. this.onFoldWidgetClick = function(row, e) {
  7662. e = e.domEvent;
  7663. var options = {
  7664. children: e.shiftKey,
  7665. all: e.ctrlKey || e.metaKey,
  7666. siblings: e.altKey
  7667. };
  7668. var range = this.$toggleFoldWidget(row, options);
  7669. if (!range) {
  7670. var el = (e.target || e.srcElement);
  7671. if (el && /ace_fold-widget/.test(el.className))
  7672. el.className += " ace_invalid";
  7673. }
  7674. };
  7675. this.$toggleFoldWidget = function(row, options) {
  7676. if (!this.getFoldWidget)
  7677. return;
  7678. var type = this.getFoldWidget(row);
  7679. var line = this.getLine(row);
  7680. var dir = type === "end" ? -1 : 1;
  7681. var fold = this.getFoldAt(row, dir === -1 ? 0 : line.length, dir);
  7682. if (fold) {
  7683. if (options.children || options.all)
  7684. this.removeFold(fold);
  7685. else
  7686. this.expandFold(fold);
  7687. return fold;
  7688. }
  7689. var range = this.getFoldWidgetRange(row, true);
  7690. if (range && !range.isMultiLine()) {
  7691. fold = this.getFoldAt(range.start.row, range.start.column, 1);
  7692. if (fold && range.isEqual(fold.range)) {
  7693. this.removeFold(fold);
  7694. return fold;
  7695. }
  7696. }
  7697. if (options.siblings) {
  7698. var data = this.getParentFoldRangeData(row);
  7699. if (data.range) {
  7700. var startRow = data.range.start.row + 1;
  7701. var endRow = data.range.end.row;
  7702. }
  7703. this.foldAll(startRow, endRow, options.all ? 10000 : 0);
  7704. } else if (options.children) {
  7705. endRow = range ? range.end.row : this.getLength();
  7706. this.foldAll(row + 1, endRow, options.all ? 10000 : 0);
  7707. } else if (range) {
  7708. if (options.all)
  7709. range.collapseChildren = 10000;
  7710. this.addFold("...", range);
  7711. }
  7712. return range;
  7713. };
  7714. this.toggleFoldWidget = function(toggleParent) {
  7715. var row = this.selection.getCursor().row;
  7716. row = this.getRowFoldStart(row);
  7717. var range = this.$toggleFoldWidget(row, {});
  7718. if (range)
  7719. return;
  7720. var data = this.getParentFoldRangeData(row, true);
  7721. range = data.range || data.firstRange;
  7722. if (range) {
  7723. row = range.start.row;
  7724. var fold = this.getFoldAt(row, this.getLine(row).length, 1);
  7725. if (fold) {
  7726. this.removeFold(fold);
  7727. } else {
  7728. this.addFold("...", range);
  7729. }
  7730. }
  7731. };
  7732. this.updateFoldWidgets = function(delta) {
  7733. var firstRow = delta.start.row;
  7734. var len = delta.end.row - firstRow;
  7735. if (len === 0) {
  7736. this.foldWidgets[firstRow] = null;
  7737. } else if (delta.action == 'remove') {
  7738. this.foldWidgets.splice(firstRow, len + 1, null);
  7739. } else {
  7740. var args = Array(len + 1);
  7741. args.unshift(firstRow, 1);
  7742. this.foldWidgets.splice.apply(this.foldWidgets, args);
  7743. }
  7744. };
  7745. this.tokenizerUpdateFoldWidgets = function(e) {
  7746. var rows = e.data;
  7747. if (rows.first != rows.last) {
  7748. if (this.foldWidgets.length > rows.first)
  7749. this.foldWidgets.splice(rows.first, this.foldWidgets.length);
  7750. }
  7751. };
  7752. }
  7753. exports.Folding = Folding;
  7754. });
  7755. define("ace/edit_session/bracket_match",["require","exports","module","ace/token_iterator","ace/range"], function(require, exports, module) {
  7756. "use strict";
  7757. var TokenIterator = require("../token_iterator").TokenIterator;
  7758. var Range = require("../range").Range;
  7759. function BracketMatch() {
  7760. this.findMatchingBracket = function(position, chr) {
  7761. if (position.column == 0) return null;
  7762. var charBeforeCursor = chr || this.getLine(position.row).charAt(position.column-1);
  7763. if (charBeforeCursor == "") return null;
  7764. var match = charBeforeCursor.match(/([\(\[\{])|([\)\]\}])/);
  7765. if (!match)
  7766. return null;
  7767. if (match[1])
  7768. return this.$findClosingBracket(match[1], position);
  7769. else
  7770. return this.$findOpeningBracket(match[2], position);
  7771. };
  7772. this.getBracketRange = function(pos) {
  7773. var line = this.getLine(pos.row);
  7774. var before = true, range;
  7775. var chr = line.charAt(pos.column-1);
  7776. var match = chr && chr.match(/([\(\[\{])|([\)\]\}])/);
  7777. if (!match) {
  7778. chr = line.charAt(pos.column);
  7779. pos = {row: pos.row, column: pos.column + 1};
  7780. match = chr && chr.match(/([\(\[\{])|([\)\]\}])/);
  7781. before = false;
  7782. }
  7783. if (!match)
  7784. return null;
  7785. if (match[1]) {
  7786. var bracketPos = this.$findClosingBracket(match[1], pos);
  7787. if (!bracketPos)
  7788. return null;
  7789. range = Range.fromPoints(pos, bracketPos);
  7790. if (!before) {
  7791. range.end.column++;
  7792. range.start.column--;
  7793. }
  7794. range.cursor = range.end;
  7795. } else {
  7796. var bracketPos = this.$findOpeningBracket(match[2], pos);
  7797. if (!bracketPos)
  7798. return null;
  7799. range = Range.fromPoints(bracketPos, pos);
  7800. if (!before) {
  7801. range.start.column++;
  7802. range.end.column--;
  7803. }
  7804. range.cursor = range.start;
  7805. }
  7806. return range;
  7807. };
  7808. this.$brackets = {
  7809. ")": "(",
  7810. "(": ")",
  7811. "]": "[",
  7812. "[": "]",
  7813. "{": "}",
  7814. "}": "{"
  7815. };
  7816. this.$findOpeningBracket = function(bracket, position, typeRe) {
  7817. var openBracket = this.$brackets[bracket];
  7818. var depth = 1;
  7819. var iterator = new TokenIterator(this, position.row, position.column);
  7820. var token = iterator.getCurrentToken();
  7821. if (!token)
  7822. token = iterator.stepForward();
  7823. if (!token)
  7824. return;
  7825. if (!typeRe){
  7826. typeRe = new RegExp(
  7827. "(\\.?" +
  7828. token.type.replace(".", "\\.").replace("rparen", ".paren")
  7829. .replace(/\b(?:end)\b/, "(?:start|begin|end)")
  7830. + ")+"
  7831. );
  7832. }
  7833. var valueIndex = position.column - iterator.getCurrentTokenColumn() - 2;
  7834. var value = token.value;
  7835. while (true) {
  7836. while (valueIndex >= 0) {
  7837. var chr = value.charAt(valueIndex);
  7838. if (chr == openBracket) {
  7839. depth -= 1;
  7840. if (depth == 0) {
  7841. return {row: iterator.getCurrentTokenRow(),
  7842. column: valueIndex + iterator.getCurrentTokenColumn()};
  7843. }
  7844. }
  7845. else if (chr == bracket) {
  7846. depth += 1;
  7847. }
  7848. valueIndex -= 1;
  7849. }
  7850. do {
  7851. token = iterator.stepBackward();
  7852. } while (token && !typeRe.test(token.type));
  7853. if (token == null)
  7854. break;
  7855. value = token.value;
  7856. valueIndex = value.length - 1;
  7857. }
  7858. return null;
  7859. };
  7860. this.$findClosingBracket = function(bracket, position, typeRe) {
  7861. var closingBracket = this.$brackets[bracket];
  7862. var depth = 1;
  7863. var iterator = new TokenIterator(this, position.row, position.column);
  7864. var token = iterator.getCurrentToken();
  7865. if (!token)
  7866. token = iterator.stepForward();
  7867. if (!token)
  7868. return;
  7869. if (!typeRe){
  7870. typeRe = new RegExp(
  7871. "(\\.?" +
  7872. token.type.replace(".", "\\.").replace("lparen", ".paren")
  7873. .replace(/\b(?:start|begin)\b/, "(?:start|begin|end)")
  7874. + ")+"
  7875. );
  7876. }
  7877. var valueIndex = position.column - iterator.getCurrentTokenColumn();
  7878. while (true) {
  7879. var value = token.value;
  7880. var valueLength = value.length;
  7881. while (valueIndex < valueLength) {
  7882. var chr = value.charAt(valueIndex);
  7883. if (chr == closingBracket) {
  7884. depth -= 1;
  7885. if (depth == 0) {
  7886. return {row: iterator.getCurrentTokenRow(),
  7887. column: valueIndex + iterator.getCurrentTokenColumn()};
  7888. }
  7889. }
  7890. else if (chr == bracket) {
  7891. depth += 1;
  7892. }
  7893. valueIndex += 1;
  7894. }
  7895. do {
  7896. token = iterator.stepForward();
  7897. } while (token && !typeRe.test(token.type));
  7898. if (token == null)
  7899. break;
  7900. valueIndex = 0;
  7901. }
  7902. return null;
  7903. };
  7904. }
  7905. exports.BracketMatch = BracketMatch;
  7906. });
  7907. define("ace/edit_session",["require","exports","module","ace/lib/oop","ace/lib/lang","ace/config","ace/lib/event_emitter","ace/selection","ace/mode/text","ace/range","ace/document","ace/background_tokenizer","ace/search_highlight","ace/edit_session/folding","ace/edit_session/bracket_match"], function(require, exports, module) {
  7908. "use strict";
  7909. var oop = require("./lib/oop");
  7910. var lang = require("./lib/lang");
  7911. var config = require("./config");
  7912. var EventEmitter = require("./lib/event_emitter").EventEmitter;
  7913. var Selection = require("./selection").Selection;
  7914. var TextMode = require("./mode/text").Mode;
  7915. var Range = require("./range").Range;
  7916. var Document = require("./document").Document;
  7917. var BackgroundTokenizer = require("./background_tokenizer").BackgroundTokenizer;
  7918. var SearchHighlight = require("./search_highlight").SearchHighlight;
  7919. var EditSession = function(text, mode) {
  7920. this.$breakpoints = [];
  7921. this.$decorations = [];
  7922. this.$frontMarkers = {};
  7923. this.$backMarkers = {};
  7924. this.$markerId = 1;
  7925. this.$undoSelect = true;
  7926. this.$foldData = [];
  7927. this.id = "session" + (++EditSession.$uid);
  7928. this.$foldData.toString = function() {
  7929. return this.join("\n");
  7930. };
  7931. this.on("changeFold", this.onChangeFold.bind(this));
  7932. this.$onChange = this.onChange.bind(this);
  7933. if (typeof text != "object" || !text.getLine)
  7934. text = new Document(text);
  7935. this.setDocument(text);
  7936. this.selection = new Selection(this);
  7937. config.resetOptions(this);
  7938. this.setMode(mode);
  7939. config._signal("session", this);
  7940. };
  7941. EditSession.$uid = 0;
  7942. (function() {
  7943. oop.implement(this, EventEmitter);
  7944. this.setDocument = function(doc) {
  7945. if (this.doc)
  7946. this.doc.removeListener("change", this.$onChange);
  7947. this.doc = doc;
  7948. doc.on("change", this.$onChange);
  7949. if (this.bgTokenizer)
  7950. this.bgTokenizer.setDocument(this.getDocument());
  7951. this.resetCaches();
  7952. };
  7953. this.getDocument = function() {
  7954. return this.doc;
  7955. };
  7956. this.$resetRowCache = function(docRow) {
  7957. if (!docRow) {
  7958. this.$docRowCache = [];
  7959. this.$screenRowCache = [];
  7960. return;
  7961. }
  7962. var l = this.$docRowCache.length;
  7963. var i = this.$getRowCacheIndex(this.$docRowCache, docRow) + 1;
  7964. if (l > i) {
  7965. this.$docRowCache.splice(i, l);
  7966. this.$screenRowCache.splice(i, l);
  7967. }
  7968. };
  7969. this.$getRowCacheIndex = function(cacheArray, val) {
  7970. var low = 0;
  7971. var hi = cacheArray.length - 1;
  7972. while (low <= hi) {
  7973. var mid = (low + hi) >> 1;
  7974. var c = cacheArray[mid];
  7975. if (val > c)
  7976. low = mid + 1;
  7977. else if (val < c)
  7978. hi = mid - 1;
  7979. else
  7980. return mid;
  7981. }
  7982. return low -1;
  7983. };
  7984. this.resetCaches = function() {
  7985. this.$modified = true;
  7986. this.$wrapData = [];
  7987. this.$rowLengthCache = [];
  7988. this.$resetRowCache(0);
  7989. if (this.bgTokenizer)
  7990. this.bgTokenizer.start(0);
  7991. };
  7992. this.onChangeFold = function(e) {
  7993. var fold = e.data;
  7994. this.$resetRowCache(fold.start.row);
  7995. };
  7996. this.onChange = function(delta) {
  7997. this.$modified = true;
  7998. this.$resetRowCache(delta.start.row);
  7999. var removedFolds = this.$updateInternalDataOnChange(delta);
  8000. if (!this.$fromUndo && this.$undoManager && !delta.ignore) {
  8001. this.$deltasDoc.push(delta);
  8002. if (removedFolds && removedFolds.length != 0) {
  8003. this.$deltasFold.push({
  8004. action: "removeFolds",
  8005. folds: removedFolds
  8006. });
  8007. }
  8008. this.$informUndoManager.schedule();
  8009. }
  8010. this.bgTokenizer && this.bgTokenizer.$updateOnChange(delta);
  8011. this._signal("change", delta);
  8012. };
  8013. this.setValue = function(text) {
  8014. this.doc.setValue(text);
  8015. this.selection.moveTo(0, 0);
  8016. this.$resetRowCache(0);
  8017. this.$deltas = [];
  8018. this.$deltasDoc = [];
  8019. this.$deltasFold = [];
  8020. this.setUndoManager(this.$undoManager);
  8021. this.getUndoManager().reset();
  8022. };
  8023. this.getValue =
  8024. this.toString = function() {
  8025. return this.doc.getValue();
  8026. };
  8027. this.getSelection = function() {
  8028. return this.selection;
  8029. };
  8030. this.getState = function(row) {
  8031. return this.bgTokenizer.getState(row);
  8032. };
  8033. this.getTokens = function(row) {
  8034. return this.bgTokenizer.getTokens(row);
  8035. };
  8036. this.getTokenAt = function(row, column) {
  8037. var tokens = this.bgTokenizer.getTokens(row);
  8038. var token, c = 0;
  8039. if (column == null) {
  8040. i = tokens.length - 1;
  8041. c = this.getLine(row).length;
  8042. } else {
  8043. for (var i = 0; i < tokens.length; i++) {
  8044. c += tokens[i].value.length;
  8045. if (c >= column)
  8046. break;
  8047. }
  8048. }
  8049. token = tokens[i];
  8050. if (!token)
  8051. return null;
  8052. token.index = i;
  8053. token.start = c - token.value.length;
  8054. return token;
  8055. };
  8056. this.setUndoManager = function(undoManager) {
  8057. this.$undoManager = undoManager;
  8058. this.$deltas = [];
  8059. this.$deltasDoc = [];
  8060. this.$deltasFold = [];
  8061. if (this.$informUndoManager)
  8062. this.$informUndoManager.cancel();
  8063. if (undoManager) {
  8064. var self = this;
  8065. this.$syncInformUndoManager = function() {
  8066. self.$informUndoManager.cancel();
  8067. if (self.$deltasFold.length) {
  8068. self.$deltas.push({
  8069. group: "fold",
  8070. deltas: self.$deltasFold
  8071. });
  8072. self.$deltasFold = [];
  8073. }
  8074. if (self.$deltasDoc.length) {
  8075. self.$deltas.push({
  8076. group: "doc",
  8077. deltas: self.$deltasDoc
  8078. });
  8079. self.$deltasDoc = [];
  8080. }
  8081. if (self.$deltas.length > 0) {
  8082. undoManager.execute({
  8083. action: "aceupdate",
  8084. args: [self.$deltas, self],
  8085. merge: self.mergeUndoDeltas
  8086. });
  8087. }
  8088. self.mergeUndoDeltas = false;
  8089. self.$deltas = [];
  8090. };
  8091. this.$informUndoManager = lang.delayedCall(this.$syncInformUndoManager);
  8092. }
  8093. };
  8094. this.markUndoGroup = function() {
  8095. if (this.$syncInformUndoManager)
  8096. this.$syncInformUndoManager();
  8097. };
  8098. this.$defaultUndoManager = {
  8099. undo: function() {},
  8100. redo: function() {},
  8101. reset: function() {}
  8102. };
  8103. this.getUndoManager = function() {
  8104. return this.$undoManager || this.$defaultUndoManager;
  8105. };
  8106. this.getTabString = function() {
  8107. if (this.getUseSoftTabs()) {
  8108. return lang.stringRepeat(" ", this.getTabSize());
  8109. } else {
  8110. return "\t";
  8111. }
  8112. };
  8113. this.setUseSoftTabs = function(val) {
  8114. this.setOption("useSoftTabs", val);
  8115. };
  8116. this.getUseSoftTabs = function() {
  8117. return this.$useSoftTabs && !this.$mode.$indentWithTabs;
  8118. };
  8119. this.setTabSize = function(tabSize) {
  8120. this.setOption("tabSize", tabSize);
  8121. };
  8122. this.getTabSize = function() {
  8123. return this.$tabSize;
  8124. };
  8125. this.isTabStop = function(position) {
  8126. return this.$useSoftTabs && (position.column % this.$tabSize === 0);
  8127. };
  8128. this.setNavigateWithinSoftTabs = function (navigateWithinSoftTabs) {
  8129. this.setOption("navigateWithinSoftTabs", navigateWithinSoftTabs)
  8130. }
  8131. this.getNavigateWithinSoftTabs = function() {
  8132. return this.$navigateWithinSoftTabs;
  8133. }
  8134. this.$overwrite = false;
  8135. this.setOverwrite = function(overwrite) {
  8136. this.setOption("overwrite", overwrite);
  8137. };
  8138. this.getOverwrite = function() {
  8139. return this.$overwrite;
  8140. };
  8141. this.toggleOverwrite = function() {
  8142. this.setOverwrite(!this.$overwrite);
  8143. };
  8144. this.addGutterDecoration = function(row, className) {
  8145. if (!this.$decorations[row])
  8146. this.$decorations[row] = "";
  8147. this.$decorations[row] += " " + className;
  8148. this._signal("changeBreakpoint", {});
  8149. };
  8150. this.removeGutterDecoration = function(row, className) {
  8151. this.$decorations[row] = (this.$decorations[row] || "").replace(" " + className, "");
  8152. this._signal("changeBreakpoint", {});
  8153. };
  8154. this.getBreakpoints = function() {
  8155. return this.$breakpoints;
  8156. };
  8157. this.setBreakpoints = function(rows) {
  8158. this.$breakpoints = [];
  8159. for (var i=0; i<rows.length; i++) {
  8160. this.$breakpoints[rows[i]] = "ace_breakpoint";
  8161. }
  8162. this._signal("changeBreakpoint", {});
  8163. };
  8164. this.clearBreakpoints = function() {
  8165. this.$breakpoints = [];
  8166. this._signal("changeBreakpoint", {});
  8167. };
  8168. this.setBreakpoint = function(row, className) {
  8169. if (className === undefined)
  8170. className = "ace_breakpoint";
  8171. if (className)
  8172. this.$breakpoints[row] = className;
  8173. else
  8174. delete this.$breakpoints[row];
  8175. this._signal("changeBreakpoint", {});
  8176. };
  8177. this.clearBreakpoint = function(row) {
  8178. delete this.$breakpoints[row];
  8179. this._signal("changeBreakpoint", {});
  8180. };
  8181. this.addMarker = function(range, clazz, type, inFront) {
  8182. var id = this.$markerId++;
  8183. var marker = {
  8184. range : range,
  8185. type : type || "line",
  8186. renderer: typeof type == "function" ? type : null,
  8187. clazz : clazz,
  8188. inFront: !!inFront,
  8189. id: id
  8190. };
  8191. if (inFront) {
  8192. this.$frontMarkers[id] = marker;
  8193. this._signal("changeFrontMarker");
  8194. } else {
  8195. this.$backMarkers[id] = marker;
  8196. this._signal("changeBackMarker");
  8197. }
  8198. return id;
  8199. };
  8200. this.addDynamicMarker = function(marker, inFront) {
  8201. if (!marker.update)
  8202. return;
  8203. var id = this.$markerId++;
  8204. marker.id = id;
  8205. marker.inFront = !!inFront;
  8206. if (inFront) {
  8207. this.$frontMarkers[id] = marker;
  8208. this._signal("changeFrontMarker");
  8209. } else {
  8210. this.$backMarkers[id] = marker;
  8211. this._signal("changeBackMarker");
  8212. }
  8213. return marker;
  8214. };
  8215. this.removeMarker = function(markerId) {
  8216. var marker = this.$frontMarkers[markerId] || this.$backMarkers[markerId];
  8217. if (!marker)
  8218. return;
  8219. var markers = marker.inFront ? this.$frontMarkers : this.$backMarkers;
  8220. if (marker) {
  8221. delete (markers[markerId]);
  8222. this._signal(marker.inFront ? "changeFrontMarker" : "changeBackMarker");
  8223. }
  8224. };
  8225. this.getMarkers = function(inFront) {
  8226. return inFront ? this.$frontMarkers : this.$backMarkers;
  8227. };
  8228. this.highlight = function(re) {
  8229. if (!this.$searchHighlight) {
  8230. var highlight = new SearchHighlight(null, "ace_selected-word", "text");
  8231. this.$searchHighlight = this.addDynamicMarker(highlight);
  8232. }
  8233. this.$searchHighlight.setRegexp(re);
  8234. };
  8235. this.highlightLines = function(startRow, endRow, clazz, inFront) {
  8236. if (typeof endRow != "number") {
  8237. clazz = endRow;
  8238. endRow = startRow;
  8239. }
  8240. if (!clazz)
  8241. clazz = "ace_step";
  8242. var range = new Range(startRow, 0, endRow, Infinity);
  8243. range.id = this.addMarker(range, clazz, "fullLine", inFront);
  8244. return range;
  8245. };
  8246. this.setAnnotations = function(annotations) {
  8247. this.$annotations = annotations;
  8248. this._signal("changeAnnotation", {});
  8249. };
  8250. this.getAnnotations = function() {
  8251. return this.$annotations || [];
  8252. };
  8253. this.clearAnnotations = function() {
  8254. this.setAnnotations([]);
  8255. };
  8256. this.$detectNewLine = function(text) {
  8257. var match = text.match(/^.*?(\r?\n)/m);
  8258. if (match) {
  8259. this.$autoNewLine = match[1];
  8260. } else {
  8261. this.$autoNewLine = "\n";
  8262. }
  8263. };
  8264. this.getWordRange = function(row, column) {
  8265. var line = this.getLine(row);
  8266. var inToken = false;
  8267. if (column > 0)
  8268. inToken = !!line.charAt(column - 1).match(this.tokenRe);
  8269. if (!inToken)
  8270. inToken = !!line.charAt(column).match(this.tokenRe);
  8271. if (inToken)
  8272. var re = this.tokenRe;
  8273. else if (/^\s+$/.test(line.slice(column-1, column+1)))
  8274. var re = /\s/;
  8275. else
  8276. var re = this.nonTokenRe;
  8277. var start = column;
  8278. if (start > 0) {
  8279. do {
  8280. start--;
  8281. }
  8282. while (start >= 0 && line.charAt(start).match(re));
  8283. start++;
  8284. }
  8285. var end = column;
  8286. while (end < line.length && line.charAt(end).match(re)) {
  8287. end++;
  8288. }
  8289. return new Range(row, start, row, end);
  8290. };
  8291. this.getAWordRange = function(row, column) {
  8292. var wordRange = this.getWordRange(row, column);
  8293. var line = this.getLine(wordRange.end.row);
  8294. while (line.charAt(wordRange.end.column).match(/[ \t]/)) {
  8295. wordRange.end.column += 1;
  8296. }
  8297. return wordRange;
  8298. };
  8299. this.setNewLineMode = function(newLineMode) {
  8300. this.doc.setNewLineMode(newLineMode);
  8301. };
  8302. this.getNewLineMode = function() {
  8303. return this.doc.getNewLineMode();
  8304. };
  8305. this.setUseWorker = function(useWorker) { this.setOption("useWorker", useWorker); };
  8306. this.getUseWorker = function() { return this.$useWorker; };
  8307. this.onReloadTokenizer = function(e) {
  8308. var rows = e.data;
  8309. this.bgTokenizer.start(rows.first);
  8310. this._signal("tokenizerUpdate", e);
  8311. };
  8312. this.$modes = {};
  8313. this.$mode = null;
  8314. this.$modeId = null;
  8315. this.setMode = function(mode, cb) {
  8316. if (mode && typeof mode === "object") {
  8317. if (mode.getTokenizer)
  8318. return this.$onChangeMode(mode);
  8319. var options = mode;
  8320. var path = options.path;
  8321. } else {
  8322. path = mode || "ace/mode/text";
  8323. }
  8324. if (!this.$modes["ace/mode/text"])
  8325. this.$modes["ace/mode/text"] = new TextMode();
  8326. if (this.$modes[path] && !options) {
  8327. this.$onChangeMode(this.$modes[path]);
  8328. cb && cb();
  8329. return;
  8330. }
  8331. this.$modeId = path;
  8332. config.loadModule(["mode", path], function(m) {
  8333. if (this.$modeId !== path)
  8334. return cb && cb();
  8335. if (this.$modes[path] && !options) {
  8336. this.$onChangeMode(this.$modes[path]);
  8337. } else if (m && m.Mode) {
  8338. m = new m.Mode(options);
  8339. if (!options) {
  8340. this.$modes[path] = m;
  8341. m.$id = path;
  8342. }
  8343. this.$onChangeMode(m);
  8344. }
  8345. cb && cb();
  8346. }.bind(this));
  8347. if (!this.$mode)
  8348. this.$onChangeMode(this.$modes["ace/mode/text"], true);
  8349. };
  8350. this.$onChangeMode = function(mode, $isPlaceholder) {
  8351. if (!$isPlaceholder)
  8352. this.$modeId = mode.$id;
  8353. if (this.$mode === mode)
  8354. return;
  8355. this.$mode = mode;
  8356. this.$stopWorker();
  8357. if (this.$useWorker)
  8358. this.$startWorker();
  8359. var tokenizer = mode.getTokenizer();
  8360. if(tokenizer.addEventListener !== undefined) {
  8361. var onReloadTokenizer = this.onReloadTokenizer.bind(this);
  8362. tokenizer.addEventListener("update", onReloadTokenizer);
  8363. }
  8364. if (!this.bgTokenizer) {
  8365. this.bgTokenizer = new BackgroundTokenizer(tokenizer);
  8366. var _self = this;
  8367. this.bgTokenizer.addEventListener("update", function(e) {
  8368. _self._signal("tokenizerUpdate", e);
  8369. });
  8370. } else {
  8371. this.bgTokenizer.setTokenizer(tokenizer);
  8372. }
  8373. this.bgTokenizer.setDocument(this.getDocument());
  8374. this.tokenRe = mode.tokenRe;
  8375. this.nonTokenRe = mode.nonTokenRe;
  8376. if (!$isPlaceholder) {
  8377. if (mode.attachToSession)
  8378. mode.attachToSession(this);
  8379. this.$options.wrapMethod.set.call(this, this.$wrapMethod);
  8380. this.$setFolding(mode.foldingRules);
  8381. this.bgTokenizer.start(0);
  8382. this._emit("changeMode");
  8383. }
  8384. };
  8385. this.$stopWorker = function() {
  8386. if (this.$worker) {
  8387. this.$worker.terminate();
  8388. this.$worker = null;
  8389. }
  8390. };
  8391. this.$startWorker = function() {
  8392. try {
  8393. this.$worker = this.$mode.createWorker(this);
  8394. } catch (e) {
  8395. config.warn("Could not load worker", e);
  8396. this.$worker = null;
  8397. }
  8398. };
  8399. this.getMode = function() {
  8400. return this.$mode;
  8401. };
  8402. this.$scrollTop = 0;
  8403. this.setScrollTop = function(scrollTop) {
  8404. if (this.$scrollTop === scrollTop || isNaN(scrollTop))
  8405. return;
  8406. this.$scrollTop = scrollTop;
  8407. this._signal("changeScrollTop", scrollTop);
  8408. };
  8409. this.getScrollTop = function() {
  8410. return this.$scrollTop;
  8411. };
  8412. this.$scrollLeft = 0;
  8413. this.setScrollLeft = function(scrollLeft) {
  8414. if (this.$scrollLeft === scrollLeft || isNaN(scrollLeft))
  8415. return;
  8416. this.$scrollLeft = scrollLeft;
  8417. this._signal("changeScrollLeft", scrollLeft);
  8418. };
  8419. this.getScrollLeft = function() {
  8420. return this.$scrollLeft;
  8421. };
  8422. this.getScreenWidth = function() {
  8423. this.$computeWidth();
  8424. if (this.lineWidgets)
  8425. return Math.max(this.getLineWidgetMaxWidth(), this.screenWidth);
  8426. return this.screenWidth;
  8427. };
  8428. this.getLineWidgetMaxWidth = function() {
  8429. if (this.lineWidgetsWidth != null) return this.lineWidgetsWidth;
  8430. var width = 0;
  8431. this.lineWidgets.forEach(function(w) {
  8432. if (w && w.screenWidth > width)
  8433. width = w.screenWidth;
  8434. });
  8435. return this.lineWidgetWidth = width;
  8436. };
  8437. this.$computeWidth = function(force) {
  8438. if (this.$modified || force) {
  8439. this.$modified = false;
  8440. if (this.$useWrapMode)
  8441. return this.screenWidth = this.$wrapLimit;
  8442. var lines = this.doc.getAllLines();
  8443. var cache = this.$rowLengthCache;
  8444. var longestScreenLine = 0;
  8445. var foldIndex = 0;
  8446. var foldLine = this.$foldData[foldIndex];
  8447. var foldStart = foldLine ? foldLine.start.row : Infinity;
  8448. var len = lines.length;
  8449. for (var i = 0; i < len; i++) {
  8450. if (i > foldStart) {
  8451. i = foldLine.end.row + 1;
  8452. if (i >= len)
  8453. break;
  8454. foldLine = this.$foldData[foldIndex++];
  8455. foldStart = foldLine ? foldLine.start.row : Infinity;
  8456. }
  8457. if (cache[i] == null)
  8458. cache[i] = this.$getStringScreenWidth(lines[i])[0];
  8459. if (cache[i] > longestScreenLine)
  8460. longestScreenLine = cache[i];
  8461. }
  8462. this.screenWidth = longestScreenLine;
  8463. }
  8464. };
  8465. this.getLine = function(row) {
  8466. return this.doc.getLine(row);
  8467. };
  8468. this.getLines = function(firstRow, lastRow) {
  8469. return this.doc.getLines(firstRow, lastRow);
  8470. };
  8471. this.getLength = function() {
  8472. return this.doc.getLength();
  8473. };
  8474. this.getTextRange = function(range) {
  8475. return this.doc.getTextRange(range || this.selection.getRange());
  8476. };
  8477. this.insert = function(position, text) {
  8478. return this.doc.insert(position, text);
  8479. };
  8480. this.remove = function(range) {
  8481. return this.doc.remove(range);
  8482. };
  8483. this.removeFullLines = function(firstRow, lastRow){
  8484. return this.doc.removeFullLines(firstRow, lastRow);
  8485. };
  8486. this.undoChanges = function(deltas, dontSelect) {
  8487. if (!deltas.length)
  8488. return;
  8489. this.$fromUndo = true;
  8490. var lastUndoRange = null;
  8491. for (var i = deltas.length - 1; i != -1; i--) {
  8492. var delta = deltas[i];
  8493. if (delta.group == "doc") {
  8494. this.doc.revertDeltas(delta.deltas);
  8495. lastUndoRange =
  8496. this.$getUndoSelection(delta.deltas, true, lastUndoRange);
  8497. } else {
  8498. delta.deltas.forEach(function(foldDelta) {
  8499. this.addFolds(foldDelta.folds);
  8500. }, this);
  8501. }
  8502. }
  8503. this.$fromUndo = false;
  8504. lastUndoRange &&
  8505. this.$undoSelect &&
  8506. !dontSelect &&
  8507. this.selection.setSelectionRange(lastUndoRange);
  8508. return lastUndoRange;
  8509. };
  8510. this.redoChanges = function(deltas, dontSelect) {
  8511. if (!deltas.length)
  8512. return;
  8513. this.$fromUndo = true;
  8514. var lastUndoRange = null;
  8515. for (var i = 0; i < deltas.length; i++) {
  8516. var delta = deltas[i];
  8517. if (delta.group == "doc") {
  8518. this.doc.applyDeltas(delta.deltas);
  8519. lastUndoRange =
  8520. this.$getUndoSelection(delta.deltas, false, lastUndoRange);
  8521. }
  8522. }
  8523. this.$fromUndo = false;
  8524. lastUndoRange &&
  8525. this.$undoSelect &&
  8526. !dontSelect &&
  8527. this.selection.setSelectionRange(lastUndoRange);
  8528. return lastUndoRange;
  8529. };
  8530. this.setUndoSelect = function(enable) {
  8531. this.$undoSelect = enable;
  8532. };
  8533. this.$getUndoSelection = function(deltas, isUndo, lastUndoRange) {
  8534. function isInsert(delta) {
  8535. return isUndo ? delta.action !== "insert" : delta.action === "insert";
  8536. }
  8537. var delta = deltas[0];
  8538. var range, point;
  8539. var lastDeltaIsInsert = false;
  8540. if (isInsert(delta)) {
  8541. range = Range.fromPoints(delta.start, delta.end);
  8542. lastDeltaIsInsert = true;
  8543. } else {
  8544. range = Range.fromPoints(delta.start, delta.start);
  8545. lastDeltaIsInsert = false;
  8546. }
  8547. for (var i = 1; i < deltas.length; i++) {
  8548. delta = deltas[i];
  8549. if (isInsert(delta)) {
  8550. point = delta.start;
  8551. if (range.compare(point.row, point.column) == -1) {
  8552. range.setStart(point);
  8553. }
  8554. point = delta.end;
  8555. if (range.compare(point.row, point.column) == 1) {
  8556. range.setEnd(point);
  8557. }
  8558. lastDeltaIsInsert = true;
  8559. } else {
  8560. point = delta.start;
  8561. if (range.compare(point.row, point.column) == -1) {
  8562. range = Range.fromPoints(delta.start, delta.start);
  8563. }
  8564. lastDeltaIsInsert = false;
  8565. }
  8566. }
  8567. if (lastUndoRange != null) {
  8568. if (Range.comparePoints(lastUndoRange.start, range.start) === 0) {
  8569. lastUndoRange.start.column += range.end.column - range.start.column;
  8570. lastUndoRange.end.column += range.end.column - range.start.column;
  8571. }
  8572. var cmp = lastUndoRange.compareRange(range);
  8573. if (cmp == 1) {
  8574. range.setStart(lastUndoRange.start);
  8575. } else if (cmp == -1) {
  8576. range.setEnd(lastUndoRange.end);
  8577. }
  8578. }
  8579. return range;
  8580. };
  8581. this.replace = function(range, text) {
  8582. return this.doc.replace(range, text);
  8583. };
  8584. this.moveText = function(fromRange, toPosition, copy) {
  8585. var text = this.getTextRange(fromRange);
  8586. var folds = this.getFoldsInRange(fromRange);
  8587. var toRange = Range.fromPoints(toPosition, toPosition);
  8588. if (!copy) {
  8589. this.remove(fromRange);
  8590. var rowDiff = fromRange.start.row - fromRange.end.row;
  8591. var collDiff = rowDiff ? -fromRange.end.column : fromRange.start.column - fromRange.end.column;
  8592. if (collDiff) {
  8593. if (toRange.start.row == fromRange.end.row && toRange.start.column > fromRange.end.column)
  8594. toRange.start.column += collDiff;
  8595. if (toRange.end.row == fromRange.end.row && toRange.end.column > fromRange.end.column)
  8596. toRange.end.column += collDiff;
  8597. }
  8598. if (rowDiff && toRange.start.row >= fromRange.end.row) {
  8599. toRange.start.row += rowDiff;
  8600. toRange.end.row += rowDiff;
  8601. }
  8602. }
  8603. toRange.end = this.insert(toRange.start, text);
  8604. if (folds.length) {
  8605. var oldStart = fromRange.start;
  8606. var newStart = toRange.start;
  8607. var rowDiff = newStart.row - oldStart.row;
  8608. var collDiff = newStart.column - oldStart.column;
  8609. this.addFolds(folds.map(function(x) {
  8610. x = x.clone();
  8611. if (x.start.row == oldStart.row)
  8612. x.start.column += collDiff;
  8613. if (x.end.row == oldStart.row)
  8614. x.end.column += collDiff;
  8615. x.start.row += rowDiff;
  8616. x.end.row += rowDiff;
  8617. return x;
  8618. }));
  8619. }
  8620. return toRange;
  8621. };
  8622. this.indentRows = function(startRow, endRow, indentString) {
  8623. indentString = indentString.replace(/\t/g, this.getTabString());
  8624. for (var row=startRow; row<=endRow; row++)
  8625. this.doc.insertInLine({row: row, column: 0}, indentString);
  8626. };
  8627. this.outdentRows = function (range) {
  8628. var rowRange = range.collapseRows();
  8629. var deleteRange = new Range(0, 0, 0, 0);
  8630. var size = this.getTabSize();
  8631. for (var i = rowRange.start.row; i <= rowRange.end.row; ++i) {
  8632. var line = this.getLine(i);
  8633. deleteRange.start.row = i;
  8634. deleteRange.end.row = i;
  8635. for (var j = 0; j < size; ++j)
  8636. if (line.charAt(j) != ' ')
  8637. break;
  8638. if (j < size && line.charAt(j) == '\t') {
  8639. deleteRange.start.column = j;
  8640. deleteRange.end.column = j + 1;
  8641. } else {
  8642. deleteRange.start.column = 0;
  8643. deleteRange.end.column = j;
  8644. }
  8645. this.remove(deleteRange);
  8646. }
  8647. };
  8648. this.$moveLines = function(firstRow, lastRow, dir) {
  8649. firstRow = this.getRowFoldStart(firstRow);
  8650. lastRow = this.getRowFoldEnd(lastRow);
  8651. if (dir < 0) {
  8652. var row = this.getRowFoldStart(firstRow + dir);
  8653. if (row < 0) return 0;
  8654. var diff = row-firstRow;
  8655. } else if (dir > 0) {
  8656. var row = this.getRowFoldEnd(lastRow + dir);
  8657. if (row > this.doc.getLength()-1) return 0;
  8658. var diff = row-lastRow;
  8659. } else {
  8660. firstRow = this.$clipRowToDocument(firstRow);
  8661. lastRow = this.$clipRowToDocument(lastRow);
  8662. var diff = lastRow - firstRow + 1;
  8663. }
  8664. var range = new Range(firstRow, 0, lastRow, Number.MAX_VALUE);
  8665. var folds = this.getFoldsInRange(range).map(function(x){
  8666. x = x.clone();
  8667. x.start.row += diff;
  8668. x.end.row += diff;
  8669. return x;
  8670. });
  8671. var lines = dir == 0
  8672. ? this.doc.getLines(firstRow, lastRow)
  8673. : this.doc.removeFullLines(firstRow, lastRow);
  8674. this.doc.insertFullLines(firstRow+diff, lines);
  8675. folds.length && this.addFolds(folds);
  8676. return diff;
  8677. };
  8678. this.moveLinesUp = function(firstRow, lastRow) {
  8679. return this.$moveLines(firstRow, lastRow, -1);
  8680. };
  8681. this.moveLinesDown = function(firstRow, lastRow) {
  8682. return this.$moveLines(firstRow, lastRow, 1);
  8683. };
  8684. this.duplicateLines = function(firstRow, lastRow) {
  8685. return this.$moveLines(firstRow, lastRow, 0);
  8686. };
  8687. this.$clipRowToDocument = function(row) {
  8688. return Math.max(0, Math.min(row, this.doc.getLength()-1));
  8689. };
  8690. this.$clipColumnToRow = function(row, column) {
  8691. if (column < 0)
  8692. return 0;
  8693. return Math.min(this.doc.getLine(row).length, column);
  8694. };
  8695. this.$clipPositionToDocument = function(row, column) {
  8696. column = Math.max(0, column);
  8697. if (row < 0) {
  8698. row = 0;
  8699. column = 0;
  8700. } else {
  8701. var len = this.doc.getLength();
  8702. if (row >= len) {
  8703. row = len - 1;
  8704. column = this.doc.getLine(len-1).length;
  8705. } else {
  8706. column = Math.min(this.doc.getLine(row).length, column);
  8707. }
  8708. }
  8709. return {
  8710. row: row,
  8711. column: column
  8712. };
  8713. };
  8714. this.$clipRangeToDocument = function(range) {
  8715. if (range.start.row < 0) {
  8716. range.start.row = 0;
  8717. range.start.column = 0;
  8718. } else {
  8719. range.start.column = this.$clipColumnToRow(
  8720. range.start.row,
  8721. range.start.column
  8722. );
  8723. }
  8724. var len = this.doc.getLength() - 1;
  8725. if (range.end.row > len) {
  8726. range.end.row = len;
  8727. range.end.column = this.doc.getLine(len).length;
  8728. } else {
  8729. range.end.column = this.$clipColumnToRow(
  8730. range.end.row,
  8731. range.end.column
  8732. );
  8733. }
  8734. return range;
  8735. };
  8736. this.$wrapLimit = 80;
  8737. this.$useWrapMode = false;
  8738. this.$wrapLimitRange = {
  8739. min : null,
  8740. max : null
  8741. };
  8742. this.setUseWrapMode = function(useWrapMode) {
  8743. if (useWrapMode != this.$useWrapMode) {
  8744. this.$useWrapMode = useWrapMode;
  8745. this.$modified = true;
  8746. this.$resetRowCache(0);
  8747. if (useWrapMode) {
  8748. var len = this.getLength();
  8749. this.$wrapData = Array(len);
  8750. this.$updateWrapData(0, len - 1);
  8751. }
  8752. this._signal("changeWrapMode");
  8753. }
  8754. };
  8755. this.getUseWrapMode = function() {
  8756. return this.$useWrapMode;
  8757. };
  8758. this.setWrapLimitRange = function(min, max) {
  8759. if (this.$wrapLimitRange.min !== min || this.$wrapLimitRange.max !== max) {
  8760. this.$wrapLimitRange = { min: min, max: max };
  8761. this.$modified = true;
  8762. if (this.$useWrapMode)
  8763. this._signal("changeWrapMode");
  8764. }
  8765. };
  8766. this.adjustWrapLimit = function(desiredLimit, $printMargin) {
  8767. var limits = this.$wrapLimitRange;
  8768. if (limits.max < 0)
  8769. limits = {min: $printMargin, max: $printMargin};
  8770. var wrapLimit = this.$constrainWrapLimit(desiredLimit, limits.min, limits.max);
  8771. if (wrapLimit != this.$wrapLimit && wrapLimit > 1) {
  8772. this.$wrapLimit = wrapLimit;
  8773. this.$modified = true;
  8774. if (this.$useWrapMode) {
  8775. this.$updateWrapData(0, this.getLength() - 1);
  8776. this.$resetRowCache(0);
  8777. this._signal("changeWrapLimit");
  8778. }
  8779. return true;
  8780. }
  8781. return false;
  8782. };
  8783. this.$constrainWrapLimit = function(wrapLimit, min, max) {
  8784. if (min)
  8785. wrapLimit = Math.max(min, wrapLimit);
  8786. if (max)
  8787. wrapLimit = Math.min(max, wrapLimit);
  8788. return wrapLimit;
  8789. };
  8790. this.getWrapLimit = function() {
  8791. return this.$wrapLimit;
  8792. };
  8793. this.setWrapLimit = function (limit) {
  8794. this.setWrapLimitRange(limit, limit);
  8795. };
  8796. this.getWrapLimitRange = function() {
  8797. return {
  8798. min : this.$wrapLimitRange.min,
  8799. max : this.$wrapLimitRange.max
  8800. };
  8801. };
  8802. this.$updateInternalDataOnChange = function(delta) {
  8803. var useWrapMode = this.$useWrapMode;
  8804. var action = delta.action;
  8805. var start = delta.start;
  8806. var end = delta.end;
  8807. var firstRow = start.row;
  8808. var lastRow = end.row;
  8809. var len = lastRow - firstRow;
  8810. var removedFolds = null;
  8811. this.$updating = true;
  8812. if (len != 0) {
  8813. if (action === "remove") {
  8814. this[useWrapMode ? "$wrapData" : "$rowLengthCache"].splice(firstRow, len);
  8815. var foldLines = this.$foldData;
  8816. removedFolds = this.getFoldsInRange(delta);
  8817. this.removeFolds(removedFolds);
  8818. var foldLine = this.getFoldLine(end.row);
  8819. var idx = 0;
  8820. if (foldLine) {
  8821. foldLine.addRemoveChars(end.row, end.column, start.column - end.column);
  8822. foldLine.shiftRow(-len);
  8823. var foldLineBefore = this.getFoldLine(firstRow);
  8824. if (foldLineBefore && foldLineBefore !== foldLine) {
  8825. foldLineBefore.merge(foldLine);
  8826. foldLine = foldLineBefore;
  8827. }
  8828. idx = foldLines.indexOf(foldLine) + 1;
  8829. }
  8830. for (idx; idx < foldLines.length; idx++) {
  8831. var foldLine = foldLines[idx];
  8832. if (foldLine.start.row >= end.row) {
  8833. foldLine.shiftRow(-len);
  8834. }
  8835. }
  8836. lastRow = firstRow;
  8837. } else {
  8838. var args = Array(len);
  8839. args.unshift(firstRow, 0);
  8840. var arr = useWrapMode ? this.$wrapData : this.$rowLengthCache
  8841. arr.splice.apply(arr, args);
  8842. var foldLines = this.$foldData;
  8843. var foldLine = this.getFoldLine(firstRow);
  8844. var idx = 0;
  8845. if (foldLine) {
  8846. var cmp = foldLine.range.compareInside(start.row, start.column);
  8847. if (cmp == 0) {
  8848. foldLine = foldLine.split(start.row, start.column);
  8849. if (foldLine) {
  8850. foldLine.shiftRow(len);
  8851. foldLine.addRemoveChars(lastRow, 0, end.column - start.column);
  8852. }
  8853. } else
  8854. if (cmp == -1) {
  8855. foldLine.addRemoveChars(firstRow, 0, end.column - start.column);
  8856. foldLine.shiftRow(len);
  8857. }
  8858. idx = foldLines.indexOf(foldLine) + 1;
  8859. }
  8860. for (idx; idx < foldLines.length; idx++) {
  8861. var foldLine = foldLines[idx];
  8862. if (foldLine.start.row >= firstRow) {
  8863. foldLine.shiftRow(len);
  8864. }
  8865. }
  8866. }
  8867. } else {
  8868. len = Math.abs(delta.start.column - delta.end.column);
  8869. if (action === "remove") {
  8870. removedFolds = this.getFoldsInRange(delta);
  8871. this.removeFolds(removedFolds);
  8872. len = -len;
  8873. }
  8874. var foldLine = this.getFoldLine(firstRow);
  8875. if (foldLine) {
  8876. foldLine.addRemoveChars(firstRow, start.column, len);
  8877. }
  8878. }
  8879. if (useWrapMode && this.$wrapData.length != this.doc.getLength()) {
  8880. console.error("doc.getLength() and $wrapData.length have to be the same!");
  8881. }
  8882. this.$updating = false;
  8883. if (useWrapMode)
  8884. this.$updateWrapData(firstRow, lastRow);
  8885. else
  8886. this.$updateRowLengthCache(firstRow, lastRow);
  8887. return removedFolds;
  8888. };
  8889. this.$updateRowLengthCache = function(firstRow, lastRow, b) {
  8890. this.$rowLengthCache[firstRow] = null;
  8891. this.$rowLengthCache[lastRow] = null;
  8892. };
  8893. this.$updateWrapData = function(firstRow, lastRow) {
  8894. var lines = this.doc.getAllLines();
  8895. var tabSize = this.getTabSize();
  8896. var wrapData = this.$wrapData;
  8897. var wrapLimit = this.$wrapLimit;
  8898. var tokens;
  8899. var foldLine;
  8900. var row = firstRow;
  8901. lastRow = Math.min(lastRow, lines.length - 1);
  8902. while (row <= lastRow) {
  8903. foldLine = this.getFoldLine(row, foldLine);
  8904. if (!foldLine) {
  8905. tokens = this.$getDisplayTokens(lines[row]);
  8906. wrapData[row] = this.$computeWrapSplits(tokens, wrapLimit, tabSize);
  8907. row ++;
  8908. } else {
  8909. tokens = [];
  8910. foldLine.walk(function(placeholder, row, column, lastColumn) {
  8911. var walkTokens;
  8912. if (placeholder != null) {
  8913. walkTokens = this.$getDisplayTokens(
  8914. placeholder, tokens.length);
  8915. walkTokens[0] = PLACEHOLDER_START;
  8916. for (var i = 1; i < walkTokens.length; i++) {
  8917. walkTokens[i] = PLACEHOLDER_BODY;
  8918. }
  8919. } else {
  8920. walkTokens = this.$getDisplayTokens(
  8921. lines[row].substring(lastColumn, column),
  8922. tokens.length);
  8923. }
  8924. tokens = tokens.concat(walkTokens);
  8925. }.bind(this),
  8926. foldLine.end.row,
  8927. lines[foldLine.end.row].length + 1
  8928. );
  8929. wrapData[foldLine.start.row] = this.$computeWrapSplits(tokens, wrapLimit, tabSize);
  8930. row = foldLine.end.row + 1;
  8931. }
  8932. }
  8933. };
  8934. var CHAR = 1,
  8935. CHAR_EXT = 2,
  8936. PLACEHOLDER_START = 3,
  8937. PLACEHOLDER_BODY = 4,
  8938. PUNCTUATION = 9,
  8939. SPACE = 10,
  8940. TAB = 11,
  8941. TAB_SPACE = 12;
  8942. this.$computeWrapSplits = function(tokens, wrapLimit, tabSize) {
  8943. if (tokens.length == 0) {
  8944. return [];
  8945. }
  8946. var splits = [];
  8947. var displayLength = tokens.length;
  8948. var lastSplit = 0, lastDocSplit = 0;
  8949. var isCode = this.$wrapAsCode;
  8950. var indentedSoftWrap = this.$indentedSoftWrap;
  8951. var maxIndent = wrapLimit <= Math.max(2 * tabSize, 8)
  8952. || indentedSoftWrap === false ? 0 : Math.floor(wrapLimit / 2);
  8953. function getWrapIndent() {
  8954. var indentation = 0;
  8955. if (maxIndent === 0)
  8956. return indentation;
  8957. if (indentedSoftWrap) {
  8958. for (var i = 0; i < tokens.length; i++) {
  8959. var token = tokens[i];
  8960. if (token == SPACE)
  8961. indentation += 1;
  8962. else if (token == TAB)
  8963. indentation += tabSize;
  8964. else if (token == TAB_SPACE)
  8965. continue;
  8966. else
  8967. break;
  8968. }
  8969. }
  8970. if (isCode && indentedSoftWrap !== false)
  8971. indentation += tabSize;
  8972. return Math.min(indentation, maxIndent);
  8973. }
  8974. function addSplit(screenPos) {
  8975. var displayed = tokens.slice(lastSplit, screenPos);
  8976. var len = displayed.length;
  8977. displayed.join("")
  8978. .replace(/12/g, function() {
  8979. len -= 1;
  8980. })
  8981. .replace(/2/g, function() {
  8982. len -= 1;
  8983. });
  8984. if (!splits.length) {
  8985. indent = getWrapIndent();
  8986. splits.indent = indent;
  8987. }
  8988. lastDocSplit += len;
  8989. splits.push(lastDocSplit);
  8990. lastSplit = screenPos;
  8991. }
  8992. var indent = 0;
  8993. while (displayLength - lastSplit > wrapLimit - indent) {
  8994. var split = lastSplit + wrapLimit - indent;
  8995. if (tokens[split - 1] >= SPACE && tokens[split] >= SPACE) {
  8996. addSplit(split);
  8997. continue;
  8998. }
  8999. if (tokens[split] == PLACEHOLDER_START || tokens[split] == PLACEHOLDER_BODY) {
  9000. for (split; split != lastSplit - 1; split--) {
  9001. if (tokens[split] == PLACEHOLDER_START) {
  9002. break;
  9003. }
  9004. }
  9005. if (split > lastSplit) {
  9006. addSplit(split);
  9007. continue;
  9008. }
  9009. split = lastSplit + wrapLimit;
  9010. for (split; split < tokens.length; split++) {
  9011. if (tokens[split] != PLACEHOLDER_BODY) {
  9012. break;
  9013. }
  9014. }
  9015. if (split == tokens.length) {
  9016. break; // Breaks the while-loop.
  9017. }
  9018. addSplit(split);
  9019. continue;
  9020. }
  9021. var minSplit = Math.max(split - (wrapLimit -(wrapLimit>>2)), lastSplit - 1);
  9022. while (split > minSplit && tokens[split] < PLACEHOLDER_START) {
  9023. split --;
  9024. }
  9025. if (isCode) {
  9026. while (split > minSplit && tokens[split] < PLACEHOLDER_START) {
  9027. split --;
  9028. }
  9029. while (split > minSplit && tokens[split] == PUNCTUATION) {
  9030. split --;
  9031. }
  9032. } else {
  9033. while (split > minSplit && tokens[split] < SPACE) {
  9034. split --;
  9035. }
  9036. }
  9037. if (split > minSplit) {
  9038. addSplit(++split);
  9039. continue;
  9040. }
  9041. split = lastSplit + wrapLimit;
  9042. if (tokens[split] == CHAR_EXT)
  9043. split--;
  9044. addSplit(split - indent);
  9045. }
  9046. return splits;
  9047. };
  9048. this.$getDisplayTokens = function(str, offset) {
  9049. var arr = [];
  9050. var tabSize;
  9051. offset = offset || 0;
  9052. for (var i = 0; i < str.length; i++) {
  9053. var c = str.charCodeAt(i);
  9054. if (c == 9) {
  9055. tabSize = this.getScreenTabSize(arr.length + offset);
  9056. arr.push(TAB);
  9057. for (var n = 1; n < tabSize; n++) {
  9058. arr.push(TAB_SPACE);
  9059. }
  9060. }
  9061. else if (c == 32) {
  9062. arr.push(SPACE);
  9063. } else if((c > 39 && c < 48) || (c > 57 && c < 64)) {
  9064. arr.push(PUNCTUATION);
  9065. }
  9066. else if (c >= 0x1100 && isFullWidth(c)) {
  9067. arr.push(CHAR, CHAR_EXT);
  9068. } else {
  9069. arr.push(CHAR);
  9070. }
  9071. }
  9072. return arr;
  9073. };
  9074. this.$getStringScreenWidth = function(str, maxScreenColumn, screenColumn) {
  9075. if (maxScreenColumn == 0)
  9076. return [0, 0];
  9077. if (maxScreenColumn == null)
  9078. maxScreenColumn = Infinity;
  9079. screenColumn = screenColumn || 0;
  9080. var c, column;
  9081. for (column = 0; column < str.length; column++) {
  9082. c = str.charCodeAt(column);
  9083. if (c == 9) {
  9084. screenColumn += this.getScreenTabSize(screenColumn);
  9085. }
  9086. else if (c >= 0x1100 && isFullWidth(c)) {
  9087. screenColumn += 2;
  9088. } else {
  9089. screenColumn += 1;
  9090. }
  9091. if (screenColumn > maxScreenColumn) {
  9092. break;
  9093. }
  9094. }
  9095. return [screenColumn, column];
  9096. };
  9097. this.lineWidgets = null;
  9098. this.getRowLength = function(row) {
  9099. if (this.lineWidgets)
  9100. var h = this.lineWidgets[row] && this.lineWidgets[row].rowCount || 0;
  9101. else
  9102. h = 0
  9103. if (!this.$useWrapMode || !this.$wrapData[row]) {
  9104. return 1 + h;
  9105. } else {
  9106. return this.$wrapData[row].length + 1 + h;
  9107. }
  9108. };
  9109. this.getRowLineCount = function(row) {
  9110. if (!this.$useWrapMode || !this.$wrapData[row]) {
  9111. return 1;
  9112. } else {
  9113. return this.$wrapData[row].length + 1;
  9114. }
  9115. };
  9116. this.getRowWrapIndent = function(screenRow) {
  9117. if (this.$useWrapMode) {
  9118. var pos = this.screenToDocumentPosition(screenRow, Number.MAX_VALUE);
  9119. var splits = this.$wrapData[pos.row];
  9120. return splits.length && splits[0] < pos.column ? splits.indent : 0;
  9121. } else {
  9122. return 0;
  9123. }
  9124. }
  9125. this.getScreenLastRowColumn = function(screenRow) {
  9126. var pos = this.screenToDocumentPosition(screenRow, Number.MAX_VALUE);
  9127. return this.documentToScreenColumn(pos.row, pos.column);
  9128. };
  9129. this.getDocumentLastRowColumn = function(docRow, docColumn) {
  9130. var screenRow = this.documentToScreenRow(docRow, docColumn);
  9131. return this.getScreenLastRowColumn(screenRow);
  9132. };
  9133. this.getDocumentLastRowColumnPosition = function(docRow, docColumn) {
  9134. var screenRow = this.documentToScreenRow(docRow, docColumn);
  9135. return this.screenToDocumentPosition(screenRow, Number.MAX_VALUE / 10);
  9136. };
  9137. this.getRowSplitData = function(row) {
  9138. if (!this.$useWrapMode) {
  9139. return undefined;
  9140. } else {
  9141. return this.$wrapData[row];
  9142. }
  9143. };
  9144. this.getScreenTabSize = function(screenColumn) {
  9145. return this.$tabSize - screenColumn % this.$tabSize;
  9146. };
  9147. this.screenToDocumentRow = function(screenRow, screenColumn) {
  9148. return this.screenToDocumentPosition(screenRow, screenColumn).row;
  9149. };
  9150. this.screenToDocumentColumn = function(screenRow, screenColumn) {
  9151. return this.screenToDocumentPosition(screenRow, screenColumn).column;
  9152. };
  9153. this.screenToDocumentPosition = function(screenRow, screenColumn) {
  9154. if (screenRow < 0)
  9155. return {row: 0, column: 0};
  9156. var line;
  9157. var docRow = 0;
  9158. var docColumn = 0;
  9159. var column;
  9160. var row = 0;
  9161. var rowLength = 0;
  9162. var rowCache = this.$screenRowCache;
  9163. var i = this.$getRowCacheIndex(rowCache, screenRow);
  9164. var l = rowCache.length;
  9165. if (l && i >= 0) {
  9166. var row = rowCache[i];
  9167. var docRow = this.$docRowCache[i];
  9168. var doCache = screenRow > rowCache[l - 1];
  9169. } else {
  9170. var doCache = !l;
  9171. }
  9172. var maxRow = this.getLength() - 1;
  9173. var foldLine = this.getNextFoldLine(docRow);
  9174. var foldStart = foldLine ? foldLine.start.row : Infinity;
  9175. while (row <= screenRow) {
  9176. rowLength = this.getRowLength(docRow);
  9177. if (row + rowLength > screenRow || docRow >= maxRow) {
  9178. break;
  9179. } else {
  9180. row += rowLength;
  9181. docRow++;
  9182. if (docRow > foldStart) {
  9183. docRow = foldLine.end.row+1;
  9184. foldLine = this.getNextFoldLine(docRow, foldLine);
  9185. foldStart = foldLine ? foldLine.start.row : Infinity;
  9186. }
  9187. }
  9188. if (doCache) {
  9189. this.$docRowCache.push(docRow);
  9190. this.$screenRowCache.push(row);
  9191. }
  9192. }
  9193. if (foldLine && foldLine.start.row <= docRow) {
  9194. line = this.getFoldDisplayLine(foldLine);
  9195. docRow = foldLine.start.row;
  9196. } else if (row + rowLength <= screenRow || docRow > maxRow) {
  9197. return {
  9198. row: maxRow,
  9199. column: this.getLine(maxRow).length
  9200. };
  9201. } else {
  9202. line = this.getLine(docRow);
  9203. foldLine = null;
  9204. }
  9205. var wrapIndent = 0;
  9206. if (this.$useWrapMode) {
  9207. var splits = this.$wrapData[docRow];
  9208. if (splits) {
  9209. var splitIndex = Math.floor(screenRow - row);
  9210. column = splits[splitIndex];
  9211. if(splitIndex > 0 && splits.length) {
  9212. wrapIndent = splits.indent;
  9213. docColumn = splits[splitIndex - 1] || splits[splits.length - 1];
  9214. line = line.substring(docColumn);
  9215. }
  9216. }
  9217. }
  9218. docColumn += this.$getStringScreenWidth(line, screenColumn - wrapIndent)[1];
  9219. if (this.$useWrapMode && docColumn >= column)
  9220. docColumn = column - 1;
  9221. if (foldLine)
  9222. return foldLine.idxToPosition(docColumn);
  9223. return {row: docRow, column: docColumn};
  9224. };
  9225. this.documentToScreenPosition = function(docRow, docColumn) {
  9226. if (typeof docColumn === "undefined")
  9227. var pos = this.$clipPositionToDocument(docRow.row, docRow.column);
  9228. else
  9229. pos = this.$clipPositionToDocument(docRow, docColumn);
  9230. docRow = pos.row;
  9231. docColumn = pos.column;
  9232. var screenRow = 0;
  9233. var foldStartRow = null;
  9234. var fold = null;
  9235. fold = this.getFoldAt(docRow, docColumn, 1);
  9236. if (fold) {
  9237. docRow = fold.start.row;
  9238. docColumn = fold.start.column;
  9239. }
  9240. var rowEnd, row = 0;
  9241. var rowCache = this.$docRowCache;
  9242. var i = this.$getRowCacheIndex(rowCache, docRow);
  9243. var l = rowCache.length;
  9244. if (l && i >= 0) {
  9245. var row = rowCache[i];
  9246. var screenRow = this.$screenRowCache[i];
  9247. var doCache = docRow > rowCache[l - 1];
  9248. } else {
  9249. var doCache = !l;
  9250. }
  9251. var foldLine = this.getNextFoldLine(row);
  9252. var foldStart = foldLine ?foldLine.start.row :Infinity;
  9253. while (row < docRow) {
  9254. if (row >= foldStart) {
  9255. rowEnd = foldLine.end.row + 1;
  9256. if (rowEnd > docRow)
  9257. break;
  9258. foldLine = this.getNextFoldLine(rowEnd, foldLine);
  9259. foldStart = foldLine ?foldLine.start.row :Infinity;
  9260. }
  9261. else {
  9262. rowEnd = row + 1;
  9263. }
  9264. screenRow += this.getRowLength(row);
  9265. row = rowEnd;
  9266. if (doCache) {
  9267. this.$docRowCache.push(row);
  9268. this.$screenRowCache.push(screenRow);
  9269. }
  9270. }
  9271. var textLine = "";
  9272. if (foldLine && row >= foldStart) {
  9273. textLine = this.getFoldDisplayLine(foldLine, docRow, docColumn);
  9274. foldStartRow = foldLine.start.row;
  9275. } else {
  9276. textLine = this.getLine(docRow).substring(0, docColumn);
  9277. foldStartRow = docRow;
  9278. }
  9279. var wrapIndent = 0;
  9280. if (this.$useWrapMode) {
  9281. var wrapRow = this.$wrapData[foldStartRow];
  9282. if (wrapRow) {
  9283. var screenRowOffset = 0;
  9284. while (textLine.length >= wrapRow[screenRowOffset]) {
  9285. screenRow ++;
  9286. screenRowOffset++;
  9287. }
  9288. textLine = textLine.substring(
  9289. wrapRow[screenRowOffset - 1] || 0, textLine.length
  9290. );
  9291. wrapIndent = screenRowOffset > 0 ? wrapRow.indent : 0;
  9292. }
  9293. }
  9294. return {
  9295. row: screenRow,
  9296. column: wrapIndent + this.$getStringScreenWidth(textLine)[0]
  9297. };
  9298. };
  9299. this.documentToScreenColumn = function(row, docColumn) {
  9300. return this.documentToScreenPosition(row, docColumn).column;
  9301. };
  9302. this.documentToScreenRow = function(docRow, docColumn) {
  9303. return this.documentToScreenPosition(docRow, docColumn).row;
  9304. };
  9305. this.getScreenLength = function() {
  9306. var screenRows = 0;
  9307. var fold = null;
  9308. if (!this.$useWrapMode) {
  9309. screenRows = this.getLength();
  9310. var foldData = this.$foldData;
  9311. for (var i = 0; i < foldData.length; i++) {
  9312. fold = foldData[i];
  9313. screenRows -= fold.end.row - fold.start.row;
  9314. }
  9315. } else {
  9316. var lastRow = this.$wrapData.length;
  9317. var row = 0, i = 0;
  9318. var fold = this.$foldData[i++];
  9319. var foldStart = fold ? fold.start.row :Infinity;
  9320. while (row < lastRow) {
  9321. var splits = this.$wrapData[row];
  9322. screenRows += splits ? splits.length + 1 : 1;
  9323. row ++;
  9324. if (row > foldStart) {
  9325. row = fold.end.row+1;
  9326. fold = this.$foldData[i++];
  9327. foldStart = fold ?fold.start.row :Infinity;
  9328. }
  9329. }
  9330. }
  9331. if (this.lineWidgets)
  9332. screenRows += this.$getWidgetScreenLength();
  9333. return screenRows;
  9334. };
  9335. this.$setFontMetrics = function(fm) {
  9336. if (!this.$enableVarChar) return;
  9337. this.$getStringScreenWidth = function(str, maxScreenColumn, screenColumn) {
  9338. if (maxScreenColumn === 0)
  9339. return [0, 0];
  9340. if (!maxScreenColumn)
  9341. maxScreenColumn = Infinity;
  9342. screenColumn = screenColumn || 0;
  9343. var c, column;
  9344. for (column = 0; column < str.length; column++) {
  9345. c = str.charAt(column);
  9346. if (c === "\t") {
  9347. screenColumn += this.getScreenTabSize(screenColumn);
  9348. } else {
  9349. screenColumn += fm.getCharacterWidth(c);
  9350. }
  9351. if (screenColumn > maxScreenColumn) {
  9352. break;
  9353. }
  9354. }
  9355. return [screenColumn, column];
  9356. };
  9357. };
  9358. this.destroy = function() {
  9359. if (this.bgTokenizer) {
  9360. this.bgTokenizer.setDocument(null);
  9361. this.bgTokenizer = null;
  9362. }
  9363. this.$stopWorker();
  9364. };
  9365. function isFullWidth(c) {
  9366. if (c < 0x1100)
  9367. return false;
  9368. return c >= 0x1100 && c <= 0x115F ||
  9369. c >= 0x11A3 && c <= 0x11A7 ||
  9370. c >= 0x11FA && c <= 0x11FF ||
  9371. c >= 0x2329 && c <= 0x232A ||
  9372. c >= 0x2E80 && c <= 0x2E99 ||
  9373. c >= 0x2E9B && c <= 0x2EF3 ||
  9374. c >= 0x2F00 && c <= 0x2FD5 ||
  9375. c >= 0x2FF0 && c <= 0x2FFB ||
  9376. c >= 0x3000 && c <= 0x303E ||
  9377. c >= 0x3041 && c <= 0x3096 ||
  9378. c >= 0x3099 && c <= 0x30FF ||
  9379. c >= 0x3105 && c <= 0x312D ||
  9380. c >= 0x3131 && c <= 0x318E ||
  9381. c >= 0x3190 && c <= 0x31BA ||
  9382. c >= 0x31C0 && c <= 0x31E3 ||
  9383. c >= 0x31F0 && c <= 0x321E ||
  9384. c >= 0x3220 && c <= 0x3247 ||
  9385. c >= 0x3250 && c <= 0x32FE ||
  9386. c >= 0x3300 && c <= 0x4DBF ||
  9387. c >= 0x4E00 && c <= 0xA48C ||
  9388. c >= 0xA490 && c <= 0xA4C6 ||
  9389. c >= 0xA960 && c <= 0xA97C ||
  9390. c >= 0xAC00 && c <= 0xD7A3 ||
  9391. c >= 0xD7B0 && c <= 0xD7C6 ||
  9392. c >= 0xD7CB && c <= 0xD7FB ||
  9393. c >= 0xF900 && c <= 0xFAFF ||
  9394. c >= 0xFE10 && c <= 0xFE19 ||
  9395. c >= 0xFE30 && c <= 0xFE52 ||
  9396. c >= 0xFE54 && c <= 0xFE66 ||
  9397. c >= 0xFE68 && c <= 0xFE6B ||
  9398. c >= 0xFF01 && c <= 0xFF60 ||
  9399. c >= 0xFFE0 && c <= 0xFFE6;
  9400. }
  9401. }).call(EditSession.prototype);
  9402. require("./edit_session/folding").Folding.call(EditSession.prototype);
  9403. require("./edit_session/bracket_match").BracketMatch.call(EditSession.prototype);
  9404. config.defineOptions(EditSession.prototype, "session", {
  9405. wrap: {
  9406. set: function(value) {
  9407. if (!value || value == "off")
  9408. value = false;
  9409. else if (value == "free")
  9410. value = true;
  9411. else if (value == "printMargin")
  9412. value = -1;
  9413. else if (typeof value == "string")
  9414. value = parseInt(value, 10) || false;
  9415. if (this.$wrap == value)
  9416. return;
  9417. this.$wrap = value;
  9418. if (!value) {
  9419. this.setUseWrapMode(false);
  9420. } else {
  9421. var col = typeof value == "number" ? value : null;
  9422. this.setWrapLimitRange(col, col);
  9423. this.setUseWrapMode(true);
  9424. }
  9425. },
  9426. get: function() {
  9427. if (this.getUseWrapMode()) {
  9428. if (this.$wrap == -1)
  9429. return "printMargin";
  9430. if (!this.getWrapLimitRange().min)
  9431. return "free";
  9432. return this.$wrap;
  9433. }
  9434. return "off";
  9435. },
  9436. handlesSet: true
  9437. },
  9438. wrapMethod: {
  9439. set: function(val) {
  9440. val = val == "auto"
  9441. ? this.$mode.type != "text"
  9442. : val != "text";
  9443. if (val != this.$wrapAsCode) {
  9444. this.$wrapAsCode = val;
  9445. if (this.$useWrapMode) {
  9446. this.$modified = true;
  9447. this.$resetRowCache(0);
  9448. this.$updateWrapData(0, this.getLength() - 1);
  9449. }
  9450. }
  9451. },
  9452. initialValue: "auto"
  9453. },
  9454. indentedSoftWrap: { initialValue: true },
  9455. firstLineNumber: {
  9456. set: function() {this._signal("changeBreakpoint");},
  9457. initialValue: 1
  9458. },
  9459. useWorker: {
  9460. set: function(useWorker) {
  9461. this.$useWorker = useWorker;
  9462. this.$stopWorker();
  9463. if (useWorker)
  9464. this.$startWorker();
  9465. },
  9466. initialValue: true
  9467. },
  9468. useSoftTabs: {initialValue: true},
  9469. tabSize: {
  9470. set: function(tabSize) {
  9471. if (isNaN(tabSize) || this.$tabSize === tabSize) return;
  9472. this.$modified = true;
  9473. this.$rowLengthCache = [];
  9474. this.$tabSize = tabSize;
  9475. this._signal("changeTabSize");
  9476. },
  9477. initialValue: 4,
  9478. handlesSet: true
  9479. },
  9480. navigateWithinSoftTabs: {initialValue: false},
  9481. overwrite: {
  9482. set: function(val) {this._signal("changeOverwrite");},
  9483. initialValue: false
  9484. },
  9485. newLineMode: {
  9486. set: function(val) {this.doc.setNewLineMode(val)},
  9487. get: function() {return this.doc.getNewLineMode()},
  9488. handlesSet: true
  9489. },
  9490. mode: {
  9491. set: function(val) { this.setMode(val) },
  9492. get: function() { return this.$modeId }
  9493. }
  9494. });
  9495. exports.EditSession = EditSession;
  9496. });
  9497. define("ace/search",["require","exports","module","ace/lib/lang","ace/lib/oop","ace/range"], function(require, exports, module) {
  9498. "use strict";
  9499. var lang = require("./lib/lang");
  9500. var oop = require("./lib/oop");
  9501. var Range = require("./range").Range;
  9502. var Search = function() {
  9503. this.$options = {};
  9504. };
  9505. (function() {
  9506. this.set = function(options) {
  9507. oop.mixin(this.$options, options);
  9508. return this;
  9509. };
  9510. this.getOptions = function() {
  9511. return lang.copyObject(this.$options);
  9512. };
  9513. this.setOptions = function(options) {
  9514. this.$options = options;
  9515. };
  9516. this.find = function(session) {
  9517. var options = this.$options;
  9518. var iterator = this.$matchIterator(session, options);
  9519. if (!iterator)
  9520. return false;
  9521. var firstRange = null;
  9522. iterator.forEach(function(sr, sc, er, ec) {
  9523. firstRange = new Range(sr, sc, er, ec);
  9524. if (sc == ec && options.start && options.start.start
  9525. && options.skipCurrent != false && firstRange.isEqual(options.start)
  9526. ) {
  9527. firstRange = null;
  9528. return false;
  9529. }
  9530. return true;
  9531. });
  9532. return firstRange;
  9533. };
  9534. this.findAll = function(session) {
  9535. var options = this.$options;
  9536. if (!options.needle)
  9537. return [];
  9538. this.$assembleRegExp(options);
  9539. var range = options.range;
  9540. var lines = range
  9541. ? session.getLines(range.start.row, range.end.row)
  9542. : session.doc.getAllLines();
  9543. var ranges = [];
  9544. var re = options.re;
  9545. if (options.$isMultiLine) {
  9546. var len = re.length;
  9547. var maxRow = lines.length - len;
  9548. var prevRange;
  9549. outer: for (var row = re.offset || 0; row <= maxRow; row++) {
  9550. for (var j = 0; j < len; j++)
  9551. if (lines[row + j].search(re[j]) == -1)
  9552. continue outer;
  9553. var startLine = lines[row];
  9554. var line = lines[row + len - 1];
  9555. var startIndex = startLine.length - startLine.match(re[0])[0].length;
  9556. var endIndex = line.match(re[len - 1])[0].length;
  9557. if (prevRange && prevRange.end.row === row &&
  9558. prevRange.end.column > startIndex
  9559. ) {
  9560. continue;
  9561. }
  9562. ranges.push(prevRange = new Range(
  9563. row, startIndex, row + len - 1, endIndex
  9564. ));
  9565. if (len > 2)
  9566. row = row + len - 2;
  9567. }
  9568. } else {
  9569. for (var i = 0; i < lines.length; i++) {
  9570. var matches = lang.getMatchOffsets(lines[i], re);
  9571. for (var j = 0; j < matches.length; j++) {
  9572. var match = matches[j];
  9573. ranges.push(new Range(i, match.offset, i, match.offset + match.length));
  9574. }
  9575. }
  9576. }
  9577. if (range) {
  9578. var startColumn = range.start.column;
  9579. var endColumn = range.start.column;
  9580. var i = 0, j = ranges.length - 1;
  9581. while (i < j && ranges[i].start.column < startColumn && ranges[i].start.row == range.start.row)
  9582. i++;
  9583. while (i < j && ranges[j].end.column > endColumn && ranges[j].end.row == range.end.row)
  9584. j--;
  9585. ranges = ranges.slice(i, j + 1);
  9586. for (i = 0, j = ranges.length; i < j; i++) {
  9587. ranges[i].start.row += range.start.row;
  9588. ranges[i].end.row += range.start.row;
  9589. }
  9590. }
  9591. return ranges;
  9592. };
  9593. this.replace = function(input, replacement) {
  9594. var options = this.$options;
  9595. var re = this.$assembleRegExp(options);
  9596. if (options.$isMultiLine)
  9597. return replacement;
  9598. if (!re)
  9599. return;
  9600. var match = re.exec(input);
  9601. if (!match || match[0].length != input.length)
  9602. return null;
  9603. replacement = input.replace(re, replacement);
  9604. if (options.preserveCase) {
  9605. replacement = replacement.split("");
  9606. for (var i = Math.min(input.length, input.length); i--; ) {
  9607. var ch = input[i];
  9608. if (ch && ch.toLowerCase() != ch)
  9609. replacement[i] = replacement[i].toUpperCase();
  9610. else
  9611. replacement[i] = replacement[i].toLowerCase();
  9612. }
  9613. replacement = replacement.join("");
  9614. }
  9615. return replacement;
  9616. };
  9617. this.$assembleRegExp = function(options, $disableFakeMultiline) {
  9618. if (options.needle instanceof RegExp)
  9619. return options.re = options.needle;
  9620. var needle = options.needle;
  9621. if (!options.needle)
  9622. return options.re = false;
  9623. if (!options.regExp)
  9624. needle = lang.escapeRegExp(needle);
  9625. if (options.wholeWord)
  9626. needle = addWordBoundary(needle, options);
  9627. var modifier = options.caseSensitive ? "gm" : "gmi";
  9628. options.$isMultiLine = !$disableFakeMultiline && /[\n\r]/.test(needle);
  9629. if (options.$isMultiLine)
  9630. return options.re = this.$assembleMultilineRegExp(needle, modifier);
  9631. try {
  9632. var re = new RegExp(needle, modifier);
  9633. } catch(e) {
  9634. re = false;
  9635. }
  9636. return options.re = re;
  9637. };
  9638. this.$assembleMultilineRegExp = function(needle, modifier) {
  9639. var parts = needle.replace(/\r\n|\r|\n/g, "$\n^").split("\n");
  9640. var re = [];
  9641. for (var i = 0; i < parts.length; i++) try {
  9642. re.push(new RegExp(parts[i], modifier));
  9643. } catch(e) {
  9644. return false;
  9645. }
  9646. return re;
  9647. };
  9648. this.$matchIterator = function(session, options) {
  9649. var re = this.$assembleRegExp(options);
  9650. if (!re)
  9651. return false;
  9652. var backwards = options.backwards == true;
  9653. var skipCurrent = options.skipCurrent != false;
  9654. var range = options.range;
  9655. var start = options.start;
  9656. if (!start)
  9657. start = range ? range[backwards ? "end" : "start"] : session.selection.getRange();
  9658. if (start.start)
  9659. start = start[skipCurrent != backwards ? "end" : "start"];
  9660. var firstRow = range ? range.start.row : 0;
  9661. var lastRow = range ? range.end.row : session.getLength() - 1;
  9662. if (backwards) {
  9663. var forEach = function(callback) {
  9664. var row = start.row;
  9665. if (forEachInLine(row, start.column, callback))
  9666. return;
  9667. for (row--; row >= firstRow; row--)
  9668. if (forEachInLine(row, Number.MAX_VALUE, callback))
  9669. return;
  9670. if (options.wrap == false)
  9671. return;
  9672. for (row = lastRow, firstRow = start.row; row >= firstRow; row--)
  9673. if (forEachInLine(row, Number.MAX_VALUE, callback))
  9674. return;
  9675. };
  9676. }
  9677. else {
  9678. var forEach = function(callback) {
  9679. var row = start.row;
  9680. if (forEachInLine(row, start.column, callback))
  9681. return;
  9682. for (row = row + 1; row <= lastRow; row++)
  9683. if (forEachInLine(row, 0, callback))
  9684. return;
  9685. if (options.wrap == false)
  9686. return;
  9687. for (row = firstRow, lastRow = start.row; row <= lastRow; row++)
  9688. if (forEachInLine(row, 0, callback))
  9689. return;
  9690. };
  9691. }
  9692. if (options.$isMultiLine) {
  9693. var len = re.length;
  9694. var forEachInLine = function(row, offset, callback) {
  9695. var startRow = backwards ? row - len + 1 : row;
  9696. if (startRow < 0) return;
  9697. var line = session.getLine(startRow);
  9698. var startIndex = line.search(re[0])
  9699. if (!backwards && startIndex < offset || startIndex === -1) return;
  9700. for (var i = 1; i < len; i++) {
  9701. line = session.getLine(startRow + i);
  9702. if (line.search(re[i]) == -1)
  9703. return;
  9704. }
  9705. var endIndex = line.match(re[len - 1])[0].length;
  9706. if (backwards && endIndex > offset) return;
  9707. if (callback(startRow, startIndex, startRow + len - 1, endIndex))
  9708. return true;
  9709. };
  9710. }
  9711. else if (backwards) {
  9712. var forEachInLine = function(row, endIndex, callback) {
  9713. var line = session.getLine(row);
  9714. var matches = [];
  9715. var m, last = 0;
  9716. re.lastIndex = 0;
  9717. while((m = re.exec(line))) {
  9718. var length = m[0].length;
  9719. last = m.index;
  9720. if (!length) {
  9721. if (last >= line.length) break;
  9722. re.lastIndex = last += 1;
  9723. }
  9724. if (m.index + length > endIndex)
  9725. break;
  9726. matches.push(m.index, length)
  9727. }
  9728. for (var i = matches.length - 1; i >= 0; i -= 2) {
  9729. var column = matches[i - 1];
  9730. var length = matches[i];
  9731. if (callback(row, column, row, column + length))
  9732. return true;
  9733. }
  9734. };
  9735. }
  9736. else {
  9737. var forEachInLine = function(row, startIndex, callback) {
  9738. var line = session.getLine(row);
  9739. var m;
  9740. var last = startIndex;
  9741. re.lastIndex = startIndex;
  9742. while((m = re.exec(line))) {
  9743. var length = m[0].length;
  9744. last = m.index;
  9745. if (callback(row, last, row,last + length))
  9746. return true;
  9747. if (!length) {
  9748. re.lastIndex = last += 1;
  9749. if (last >= line.length) return false;
  9750. }
  9751. }
  9752. };
  9753. }
  9754. return {forEach: forEach};
  9755. };
  9756. }).call(Search.prototype);
  9757. function addWordBoundary(needle, options) {
  9758. function wordBoundary(c) {
  9759. if (/\w/.test(c) || options.regExp) return "\\b";
  9760. return "";
  9761. }
  9762. return wordBoundary(needle[0]) + needle
  9763. + wordBoundary(needle[needle.length - 1]);
  9764. }
  9765. exports.Search = Search;
  9766. });
  9767. define("ace/keyboard/hash_handler",["require","exports","module","ace/lib/keys","ace/lib/useragent"], function(require, exports, module) {
  9768. "use strict";
  9769. var keyUtil = require("../lib/keys");
  9770. var useragent = require("../lib/useragent");
  9771. var KEY_MODS = keyUtil.KEY_MODS;
  9772. function HashHandler(config, platform) {
  9773. this.platform = platform || (useragent.isMac ? "mac" : "win");
  9774. this.commands = {};
  9775. this.commandKeyBinding = {};
  9776. this.addCommands(config);
  9777. this.$singleCommand = true;
  9778. }
  9779. function MultiHashHandler(config, platform) {
  9780. HashHandler.call(this, config, platform);
  9781. this.$singleCommand = false;
  9782. }
  9783. MultiHashHandler.prototype = HashHandler.prototype;
  9784. (function() {
  9785. this.addCommand = function(command) {
  9786. if (this.commands[command.name])
  9787. this.removeCommand(command);
  9788. this.commands[command.name] = command;
  9789. if (command.bindKey)
  9790. this._buildKeyHash(command);
  9791. };
  9792. this.removeCommand = function(command, keepCommand) {
  9793. var name = command && (typeof command === 'string' ? command : command.name);
  9794. command = this.commands[name];
  9795. if (!keepCommand)
  9796. delete this.commands[name];
  9797. var ckb = this.commandKeyBinding;
  9798. for (var keyId in ckb) {
  9799. var cmdGroup = ckb[keyId];
  9800. if (cmdGroup == command) {
  9801. delete ckb[keyId];
  9802. } else if (Array.isArray(cmdGroup)) {
  9803. var i = cmdGroup.indexOf(command);
  9804. if (i != -1) {
  9805. cmdGroup.splice(i, 1);
  9806. if (cmdGroup.length == 1)
  9807. ckb[keyId] = cmdGroup[0];
  9808. }
  9809. }
  9810. }
  9811. };
  9812. this.bindKey = function(key, command, position) {
  9813. if (typeof key == "object" && key) {
  9814. if (position == undefined)
  9815. position = key.position;
  9816. key = key[this.platform];
  9817. }
  9818. if (!key)
  9819. return;
  9820. if (typeof command == "function")
  9821. return this.addCommand({exec: command, bindKey: key, name: command.name || key});
  9822. key.split("|").forEach(function(keyPart) {
  9823. var chain = "";
  9824. if (keyPart.indexOf(" ") != -1) {
  9825. var parts = keyPart.split(/\s+/);
  9826. keyPart = parts.pop();
  9827. parts.forEach(function(keyPart) {
  9828. var binding = this.parseKeys(keyPart);
  9829. var id = KEY_MODS[binding.hashId] + binding.key;
  9830. chain += (chain ? " " : "") + id;
  9831. this._addCommandToBinding(chain, "chainKeys");
  9832. }, this);
  9833. chain += " ";
  9834. }
  9835. var binding = this.parseKeys(keyPart);
  9836. var id = KEY_MODS[binding.hashId] + binding.key;
  9837. this._addCommandToBinding(chain + id, command, position);
  9838. }, this);
  9839. };
  9840. function getPosition(command) {
  9841. return typeof command == "object" && command.bindKey
  9842. && command.bindKey.position
  9843. || (command.isDefault ? -100 : 0);
  9844. }
  9845. this._addCommandToBinding = function(keyId, command, position) {
  9846. var ckb = this.commandKeyBinding, i;
  9847. if (!command) {
  9848. delete ckb[keyId];
  9849. } else if (!ckb[keyId] || this.$singleCommand) {
  9850. ckb[keyId] = command;
  9851. } else {
  9852. if (!Array.isArray(ckb[keyId])) {
  9853. ckb[keyId] = [ckb[keyId]];
  9854. } else if ((i = ckb[keyId].indexOf(command)) != -1) {
  9855. ckb[keyId].splice(i, 1);
  9856. }
  9857. if (typeof position != "number") {
  9858. position = getPosition(command);
  9859. }
  9860. var commands = ckb[keyId];
  9861. for (i = 0; i < commands.length; i++) {
  9862. var other = commands[i];
  9863. var otherPos = getPosition(other);
  9864. if (otherPos > position)
  9865. break;
  9866. }
  9867. commands.splice(i, 0, command);
  9868. }
  9869. };
  9870. this.addCommands = function(commands) {
  9871. commands && Object.keys(commands).forEach(function(name) {
  9872. var command = commands[name];
  9873. if (!command)
  9874. return;
  9875. if (typeof command === "string")
  9876. return this.bindKey(command, name);
  9877. if (typeof command === "function")
  9878. command = { exec: command };
  9879. if (typeof command !== "object")
  9880. return;
  9881. if (!command.name)
  9882. command.name = name;
  9883. this.addCommand(command);
  9884. }, this);
  9885. };
  9886. this.removeCommands = function(commands) {
  9887. Object.keys(commands).forEach(function(name) {
  9888. this.removeCommand(commands[name]);
  9889. }, this);
  9890. };
  9891. this.bindKeys = function(keyList) {
  9892. Object.keys(keyList).forEach(function(key) {
  9893. this.bindKey(key, keyList[key]);
  9894. }, this);
  9895. };
  9896. this._buildKeyHash = function(command) {
  9897. this.bindKey(command.bindKey, command);
  9898. };
  9899. this.parseKeys = function(keys) {
  9900. var parts = keys.toLowerCase().split(/[\-\+]([\-\+])?/).filter(function(x){return x});
  9901. var key = parts.pop();
  9902. var keyCode = keyUtil[key];
  9903. if (keyUtil.FUNCTION_KEYS[keyCode])
  9904. key = keyUtil.FUNCTION_KEYS[keyCode].toLowerCase();
  9905. else if (!parts.length)
  9906. return {key: key, hashId: -1};
  9907. else if (parts.length == 1 && parts[0] == "shift")
  9908. return {key: key.toUpperCase(), hashId: -1};
  9909. var hashId = 0;
  9910. for (var i = parts.length; i--;) {
  9911. var modifier = keyUtil.KEY_MODS[parts[i]];
  9912. if (modifier == null) {
  9913. if (typeof console != "undefined")
  9914. console.error("invalid modifier " + parts[i] + " in " + keys);
  9915. return false;
  9916. }
  9917. hashId |= modifier;
  9918. }
  9919. return {key: key, hashId: hashId};
  9920. };
  9921. this.findKeyCommand = function findKeyCommand(hashId, keyString) {
  9922. var key = KEY_MODS[hashId] + keyString;
  9923. return this.commandKeyBinding[key];
  9924. };
  9925. this.handleKeyboard = function(data, hashId, keyString, keyCode) {
  9926. if (keyCode < 0) return;
  9927. var key = KEY_MODS[hashId] + keyString;
  9928. var command = this.commandKeyBinding[key];
  9929. if (data.$keyChain) {
  9930. data.$keyChain += " " + key;
  9931. command = this.commandKeyBinding[data.$keyChain] || command;
  9932. }
  9933. if (command) {
  9934. if (command == "chainKeys" || command[command.length - 1] == "chainKeys") {
  9935. data.$keyChain = data.$keyChain || key;
  9936. return {command: "null"};
  9937. }
  9938. }
  9939. if (data.$keyChain) {
  9940. if ((!hashId || hashId == 4) && keyString.length == 1)
  9941. data.$keyChain = data.$keyChain.slice(0, -key.length - 1); // wait for input
  9942. else if (hashId == -1 || keyCode > 0)
  9943. data.$keyChain = ""; // reset keyChain
  9944. }
  9945. return {command: command};
  9946. };
  9947. this.getStatusText = function(editor, data) {
  9948. return data.$keyChain || "";
  9949. };
  9950. }).call(HashHandler.prototype);
  9951. exports.HashHandler = HashHandler;
  9952. exports.MultiHashHandler = MultiHashHandler;
  9953. });
  9954. define("ace/commands/command_manager",["require","exports","module","ace/lib/oop","ace/keyboard/hash_handler","ace/lib/event_emitter"], function(require, exports, module) {
  9955. "use strict";
  9956. var oop = require("../lib/oop");
  9957. var MultiHashHandler = require("../keyboard/hash_handler").MultiHashHandler;
  9958. var EventEmitter = require("../lib/event_emitter").EventEmitter;
  9959. var CommandManager = function(platform, commands) {
  9960. MultiHashHandler.call(this, commands, platform);
  9961. this.byName = this.commands;
  9962. this.setDefaultHandler("exec", function(e) {
  9963. return e.command.exec(e.editor, e.args || {});
  9964. });
  9965. };
  9966. oop.inherits(CommandManager, MultiHashHandler);
  9967. (function() {
  9968. oop.implement(this, EventEmitter);
  9969. this.exec = function(command, editor, args) {
  9970. if (Array.isArray(command)) {
  9971. for (var i = command.length; i--; ) {
  9972. if (this.exec(command[i], editor, args)) return true;
  9973. }
  9974. return false;
  9975. }
  9976. if (typeof command === "string")
  9977. command = this.commands[command];
  9978. if (!command)
  9979. return false;
  9980. if (editor && editor.$readOnly && !command.readOnly)
  9981. return false;
  9982. if (command.isAvailable && !command.isAvailable(editor))
  9983. return false;
  9984. var e = {editor: editor, command: command, args: args};
  9985. e.returnValue = this._emit("exec", e);
  9986. this._signal("afterExec", e);
  9987. return e.returnValue === false ? false : true;
  9988. };
  9989. this.toggleRecording = function(editor) {
  9990. if (this.$inReplay)
  9991. return;
  9992. editor && editor._emit("changeStatus");
  9993. if (this.recording) {
  9994. this.macro.pop();
  9995. this.removeEventListener("exec", this.$addCommandToMacro);
  9996. if (!this.macro.length)
  9997. this.macro = this.oldMacro;
  9998. return this.recording = false;
  9999. }
  10000. if (!this.$addCommandToMacro) {
  10001. this.$addCommandToMacro = function(e) {
  10002. this.macro.push([e.command, e.args]);
  10003. }.bind(this);
  10004. }
  10005. this.oldMacro = this.macro;
  10006. this.macro = [];
  10007. this.on("exec", this.$addCommandToMacro);
  10008. return this.recording = true;
  10009. };
  10010. this.replay = function(editor) {
  10011. if (this.$inReplay || !this.macro)
  10012. return;
  10013. if (this.recording)
  10014. return this.toggleRecording(editor);
  10015. try {
  10016. this.$inReplay = true;
  10017. this.macro.forEach(function(x) {
  10018. if (typeof x == "string")
  10019. this.exec(x, editor);
  10020. else
  10021. this.exec(x[0], editor, x[1]);
  10022. }, this);
  10023. } finally {
  10024. this.$inReplay = false;
  10025. }
  10026. };
  10027. this.trimMacro = function(m) {
  10028. return m.map(function(x){
  10029. if (typeof x[0] != "string")
  10030. x[0] = x[0].name;
  10031. if (!x[1])
  10032. x = x[0];
  10033. return x;
  10034. });
  10035. };
  10036. }).call(CommandManager.prototype);
  10037. exports.CommandManager = CommandManager;
  10038. });
  10039. define("ace/commands/default_commands",["require","exports","module","ace/lib/lang","ace/config","ace/range"], function(require, exports, module) {
  10040. "use strict";
  10041. var lang = require("../lib/lang");
  10042. var config = require("../config");
  10043. var Range = require("../range").Range;
  10044. function bindKey(win, mac) {
  10045. return {win: win, mac: mac};
  10046. }
  10047. exports.commands = [{
  10048. name: "showSettingsMenu",
  10049. bindKey: bindKey("Ctrl-,", "Command-,"),
  10050. exec: function(editor) {
  10051. config.loadModule("ace/ext/settings_menu", function(module) {
  10052. module.init(editor);
  10053. editor.showSettingsMenu();
  10054. });
  10055. },
  10056. readOnly: true
  10057. }, {
  10058. name: "goToNextError",
  10059. bindKey: bindKey("Alt-E", "F4"),
  10060. exec: function(editor) {
  10061. config.loadModule("ace/ext/error_marker", function(module) {
  10062. module.showErrorMarker(editor, 1);
  10063. });
  10064. },
  10065. scrollIntoView: "animate",
  10066. readOnly: true
  10067. }, {
  10068. name: "goToPreviousError",
  10069. bindKey: bindKey("Alt-Shift-E", "Shift-F4"),
  10070. exec: function(editor) {
  10071. config.loadModule("ace/ext/error_marker", function(module) {
  10072. module.showErrorMarker(editor, -1);
  10073. });
  10074. },
  10075. scrollIntoView: "animate",
  10076. readOnly: true
  10077. }, {
  10078. name: "selectall",
  10079. bindKey: bindKey("Ctrl-A", "Command-A"),
  10080. exec: function(editor) { editor.selectAll(); },
  10081. readOnly: true
  10082. }, {
  10083. name: "centerselection",
  10084. bindKey: bindKey(null, "Ctrl-L"),
  10085. exec: function(editor) { editor.centerSelection(); },
  10086. readOnly: true
  10087. }, {
  10088. name: "gotoline",
  10089. bindKey: bindKey("Ctrl-L", "Command-L"),
  10090. exec: function(editor) {
  10091. var line = parseInt(prompt("Enter line number:"), 10);
  10092. if (!isNaN(line)) {
  10093. editor.gotoLine(line);
  10094. }
  10095. },
  10096. readOnly: true
  10097. }, {
  10098. name: "fold",
  10099. bindKey: bindKey("Alt-L|Ctrl-F1", "Command-Alt-L|Command-F1"),
  10100. exec: function(editor) { editor.session.toggleFold(false); },
  10101. multiSelectAction: "forEach",
  10102. scrollIntoView: "center",
  10103. readOnly: true
  10104. }, {
  10105. name: "unfold",
  10106. bindKey: bindKey("Alt-Shift-L|Ctrl-Shift-F1", "Command-Alt-Shift-L|Command-Shift-F1"),
  10107. exec: function(editor) { editor.session.toggleFold(true); },
  10108. multiSelectAction: "forEach",
  10109. scrollIntoView: "center",
  10110. readOnly: true
  10111. }, {
  10112. name: "toggleFoldWidget",
  10113. bindKey: bindKey("F2", "F2"),
  10114. exec: function(editor) { editor.session.toggleFoldWidget(); },
  10115. multiSelectAction: "forEach",
  10116. scrollIntoView: "center",
  10117. readOnly: true
  10118. }, {
  10119. name: "toggleParentFoldWidget",
  10120. bindKey: bindKey("Alt-F2", "Alt-F2"),
  10121. exec: function(editor) { editor.session.toggleFoldWidget(true); },
  10122. multiSelectAction: "forEach",
  10123. scrollIntoView: "center",
  10124. readOnly: true
  10125. }, {
  10126. name: "foldall",
  10127. bindKey: bindKey(null, "Ctrl-Command-Option-0"),
  10128. exec: function(editor) { editor.session.foldAll(); },
  10129. scrollIntoView: "center",
  10130. readOnly: true
  10131. }, {
  10132. name: "foldOther",
  10133. bindKey: bindKey("Alt-0", "Command-Option-0"),
  10134. exec: function(editor) {
  10135. editor.session.foldAll();
  10136. editor.session.unfold(editor.selection.getAllRanges());
  10137. },
  10138. scrollIntoView: "center",
  10139. readOnly: true
  10140. }, {
  10141. name: "unfoldall",
  10142. bindKey: bindKey("Alt-Shift-0", "Command-Option-Shift-0"),
  10143. exec: function(editor) { editor.session.unfold(); },
  10144. scrollIntoView: "center",
  10145. readOnly: true
  10146. }, {
  10147. name: "findnext",
  10148. bindKey: bindKey("Ctrl-K", "Command-G"),
  10149. exec: function(editor) { editor.findNext(); },
  10150. multiSelectAction: "forEach",
  10151. scrollIntoView: "center",
  10152. readOnly: true
  10153. }, {
  10154. name: "findprevious",
  10155. bindKey: bindKey("Ctrl-Shift-K", "Command-Shift-G"),
  10156. exec: function(editor) { editor.findPrevious(); },
  10157. multiSelectAction: "forEach",
  10158. scrollIntoView: "center",
  10159. readOnly: true
  10160. }, {
  10161. name: "selectOrFindNext",
  10162. bindKey: bindKey("Alt-K", "Ctrl-G"),
  10163. exec: function(editor) {
  10164. if (editor.selection.isEmpty())
  10165. editor.selection.selectWord();
  10166. else
  10167. editor.findNext();
  10168. },
  10169. readOnly: true
  10170. }, {
  10171. name: "selectOrFindPrevious",
  10172. bindKey: bindKey("Alt-Shift-K", "Ctrl-Shift-G"),
  10173. exec: function(editor) {
  10174. if (editor.selection.isEmpty())
  10175. editor.selection.selectWord();
  10176. else
  10177. editor.findPrevious();
  10178. },
  10179. readOnly: true
  10180. }, {
  10181. name: "find",
  10182. bindKey: bindKey("Ctrl-F", "Command-F"),
  10183. exec: function(editor) {
  10184. config.loadModule("ace/ext/searchbox", function(e) {e.Search(editor)});
  10185. },
  10186. readOnly: true
  10187. }, {
  10188. name: "overwrite",
  10189. bindKey: "Insert",
  10190. exec: function(editor) { editor.toggleOverwrite(); },
  10191. readOnly: true
  10192. }, {
  10193. name: "selecttostart",
  10194. bindKey: bindKey("Ctrl-Shift-Home", "Command-Shift-Home|Command-Shift-Up"),
  10195. exec: function(editor) { editor.getSelection().selectFileStart(); },
  10196. multiSelectAction: "forEach",
  10197. readOnly: true,
  10198. scrollIntoView: "animate",
  10199. aceCommandGroup: "fileJump"
  10200. }, {
  10201. name: "gotostart",
  10202. bindKey: bindKey("Ctrl-Home", "Command-Home|Command-Up"),
  10203. exec: function(editor) { editor.navigateFileStart(); },
  10204. multiSelectAction: "forEach",
  10205. readOnly: true,
  10206. scrollIntoView: "animate",
  10207. aceCommandGroup: "fileJump"
  10208. }, {
  10209. name: "selectup",
  10210. bindKey: bindKey("Shift-Up", "Shift-Up|Ctrl-Shift-P"),
  10211. exec: function(editor) { editor.getSelection().selectUp(); },
  10212. multiSelectAction: "forEach",
  10213. scrollIntoView: "cursor",
  10214. readOnly: true
  10215. }, {
  10216. name: "golineup",
  10217. bindKey: bindKey("Up", "Up|Ctrl-P"),
  10218. exec: function(editor, args) { editor.navigateUp(args.times); },
  10219. multiSelectAction: "forEach",
  10220. scrollIntoView: "cursor",
  10221. readOnly: true
  10222. }, {
  10223. name: "selecttoend",
  10224. bindKey: bindKey("Ctrl-Shift-End", "Command-Shift-End|Command-Shift-Down"),
  10225. exec: function(editor) { editor.getSelection().selectFileEnd(); },
  10226. multiSelectAction: "forEach",
  10227. readOnly: true,
  10228. scrollIntoView: "animate",
  10229. aceCommandGroup: "fileJump"
  10230. }, {
  10231. name: "gotoend",
  10232. bindKey: bindKey("Ctrl-End", "Command-End|Command-Down"),
  10233. exec: function(editor) { editor.navigateFileEnd(); },
  10234. multiSelectAction: "forEach",
  10235. readOnly: true,
  10236. scrollIntoView: "animate",
  10237. aceCommandGroup: "fileJump"
  10238. }, {
  10239. name: "selectdown",
  10240. bindKey: bindKey("Shift-Down", "Shift-Down|Ctrl-Shift-N"),
  10241. exec: function(editor) { editor.getSelection().selectDown(); },
  10242. multiSelectAction: "forEach",
  10243. scrollIntoView: "cursor",
  10244. readOnly: true
  10245. }, {
  10246. name: "golinedown",
  10247. bindKey: bindKey("Down", "Down|Ctrl-N"),
  10248. exec: function(editor, args) { editor.navigateDown(args.times); },
  10249. multiSelectAction: "forEach",
  10250. scrollIntoView: "cursor",
  10251. readOnly: true
  10252. }, {
  10253. name: "selectwordleft",
  10254. bindKey: bindKey("Ctrl-Shift-Left", "Option-Shift-Left"),
  10255. exec: function(editor) { editor.getSelection().selectWordLeft(); },
  10256. multiSelectAction: "forEach",
  10257. scrollIntoView: "cursor",
  10258. readOnly: true
  10259. }, {
  10260. name: "gotowordleft",
  10261. bindKey: bindKey("Ctrl-Left", "Option-Left"),
  10262. exec: function(editor) { editor.navigateWordLeft(); },
  10263. multiSelectAction: "forEach",
  10264. scrollIntoView: "cursor",
  10265. readOnly: true
  10266. }, {
  10267. name: "selecttolinestart",
  10268. bindKey: bindKey("Alt-Shift-Left", "Command-Shift-Left|Ctrl-Shift-A"),
  10269. exec: function(editor) { editor.getSelection().selectLineStart(); },
  10270. multiSelectAction: "forEach",
  10271. scrollIntoView: "cursor",
  10272. readOnly: true
  10273. }, {
  10274. name: "gotolinestart",
  10275. bindKey: bindKey("Alt-Left|Home", "Command-Left|Home|Ctrl-A"),
  10276. exec: function(editor) { editor.navigateLineStart(); },
  10277. multiSelectAction: "forEach",
  10278. scrollIntoView: "cursor",
  10279. readOnly: true
  10280. }, {
  10281. name: "selectleft",
  10282. bindKey: bindKey("Shift-Left", "Shift-Left|Ctrl-Shift-B"),
  10283. exec: function(editor) { editor.getSelection().selectLeft(); },
  10284. multiSelectAction: "forEach",
  10285. scrollIntoView: "cursor",
  10286. readOnly: true
  10287. }, {
  10288. name: "gotoleft",
  10289. bindKey: bindKey("Left", "Left|Ctrl-B"),
  10290. exec: function(editor, args) { editor.navigateLeft(args.times); },
  10291. multiSelectAction: "forEach",
  10292. scrollIntoView: "cursor",
  10293. readOnly: true
  10294. }, {
  10295. name: "selectwordright",
  10296. bindKey: bindKey("Ctrl-Shift-Right", "Option-Shift-Right"),
  10297. exec: function(editor) { editor.getSelection().selectWordRight(); },
  10298. multiSelectAction: "forEach",
  10299. scrollIntoView: "cursor",
  10300. readOnly: true
  10301. }, {
  10302. name: "gotowordright",
  10303. bindKey: bindKey("Ctrl-Right", "Option-Right"),
  10304. exec: function(editor) { editor.navigateWordRight(); },
  10305. multiSelectAction: "forEach",
  10306. scrollIntoView: "cursor",
  10307. readOnly: true
  10308. }, {
  10309. name: "selecttolineend",
  10310. bindKey: bindKey("Alt-Shift-Right", "Command-Shift-Right|Shift-End|Ctrl-Shift-E"),
  10311. exec: function(editor) { editor.getSelection().selectLineEnd(); },
  10312. multiSelectAction: "forEach",
  10313. scrollIntoView: "cursor",
  10314. readOnly: true
  10315. }, {
  10316. name: "gotolineend",
  10317. bindKey: bindKey("Alt-Right|End", "Command-Right|End|Ctrl-E"),
  10318. exec: function(editor) { editor.navigateLineEnd(); },
  10319. multiSelectAction: "forEach",
  10320. scrollIntoView: "cursor",
  10321. readOnly: true
  10322. }, {
  10323. name: "selectright",
  10324. bindKey: bindKey("Shift-Right", "Shift-Right"),
  10325. exec: function(editor) { editor.getSelection().selectRight(); },
  10326. multiSelectAction: "forEach",
  10327. scrollIntoView: "cursor",
  10328. readOnly: true
  10329. }, {
  10330. name: "gotoright",
  10331. bindKey: bindKey("Right", "Right|Ctrl-F"),
  10332. exec: function(editor, args) { editor.navigateRight(args.times); },
  10333. multiSelectAction: "forEach",
  10334. scrollIntoView: "cursor",
  10335. readOnly: true
  10336. }, {
  10337. name: "selectpagedown",
  10338. bindKey: "Shift-PageDown",
  10339. exec: function(editor) { editor.selectPageDown(); },
  10340. readOnly: true
  10341. }, {
  10342. name: "pagedown",
  10343. bindKey: bindKey(null, "Option-PageDown"),
  10344. exec: function(editor) { editor.scrollPageDown(); },
  10345. readOnly: true
  10346. }, {
  10347. name: "gotopagedown",
  10348. bindKey: bindKey("PageDown", "PageDown|Ctrl-V"),
  10349. exec: function(editor) { editor.gotoPageDown(); },
  10350. readOnly: true
  10351. }, {
  10352. name: "selectpageup",
  10353. bindKey: "Shift-PageUp",
  10354. exec: function(editor) { editor.selectPageUp(); },
  10355. readOnly: true
  10356. }, {
  10357. name: "pageup",
  10358. bindKey: bindKey(null, "Option-PageUp"),
  10359. exec: function(editor) { editor.scrollPageUp(); },
  10360. readOnly: true
  10361. }, {
  10362. name: "gotopageup",
  10363. bindKey: "PageUp",
  10364. exec: function(editor) { editor.gotoPageUp(); },
  10365. readOnly: true
  10366. }, {
  10367. name: "scrollup",
  10368. bindKey: bindKey("Ctrl-Up", null),
  10369. exec: function(e) { e.renderer.scrollBy(0, -2 * e.renderer.layerConfig.lineHeight); },
  10370. readOnly: true
  10371. }, {
  10372. name: "scrolldown",
  10373. bindKey: bindKey("Ctrl-Down", null),
  10374. exec: function(e) { e.renderer.scrollBy(0, 2 * e.renderer.layerConfig.lineHeight); },
  10375. readOnly: true
  10376. }, {
  10377. name: "selectlinestart",
  10378. bindKey: "Shift-Home",
  10379. exec: function(editor) { editor.getSelection().selectLineStart(); },
  10380. multiSelectAction: "forEach",
  10381. scrollIntoView: "cursor",
  10382. readOnly: true
  10383. }, {
  10384. name: "selectlineend",
  10385. bindKey: "Shift-End",
  10386. exec: function(editor) { editor.getSelection().selectLineEnd(); },
  10387. multiSelectAction: "forEach",
  10388. scrollIntoView: "cursor",
  10389. readOnly: true
  10390. }, {
  10391. name: "togglerecording",
  10392. bindKey: bindKey("Ctrl-Alt-E", "Command-Option-E"),
  10393. exec: function(editor) { editor.commands.toggleRecording(editor); },
  10394. readOnly: true
  10395. }, {
  10396. name: "replaymacro",
  10397. bindKey: bindKey("Ctrl-Shift-E", "Command-Shift-E"),
  10398. exec: function(editor) { editor.commands.replay(editor); },
  10399. readOnly: true
  10400. }, {
  10401. name: "jumptomatching",
  10402. bindKey: bindKey("Ctrl-P", "Ctrl-P"),
  10403. exec: function(editor) { editor.jumpToMatching(); },
  10404. multiSelectAction: "forEach",
  10405. scrollIntoView: "animate",
  10406. readOnly: true
  10407. }, {
  10408. name: "selecttomatching",
  10409. bindKey: bindKey("Ctrl-Shift-P", "Ctrl-Shift-P"),
  10410. exec: function(editor) { editor.jumpToMatching(true); },
  10411. multiSelectAction: "forEach",
  10412. scrollIntoView: "animate",
  10413. readOnly: true
  10414. }, {
  10415. name: "expandToMatching",
  10416. bindKey: bindKey("Ctrl-Shift-M", "Ctrl-Shift-M"),
  10417. exec: function(editor) { editor.jumpToMatching(true, true); },
  10418. multiSelectAction: "forEach",
  10419. scrollIntoView: "animate",
  10420. readOnly: true
  10421. }, {
  10422. name: "passKeysToBrowser",
  10423. bindKey: bindKey(null, null),
  10424. exec: function() {},
  10425. passEvent: true,
  10426. readOnly: true
  10427. }, {
  10428. name: "copy",
  10429. exec: function(editor) {
  10430. },
  10431. readOnly: true
  10432. },
  10433. {
  10434. name: "cut",
  10435. exec: function(editor) {
  10436. var range = editor.getSelectionRange();
  10437. editor._emit("cut", range);
  10438. if (!editor.selection.isEmpty()) {
  10439. editor.session.remove(range);
  10440. editor.clearSelection();
  10441. }
  10442. },
  10443. scrollIntoView: "cursor",
  10444. multiSelectAction: "forEach"
  10445. }, {
  10446. name: "paste",
  10447. exec: function(editor, args) {
  10448. editor.$handlePaste(args);
  10449. },
  10450. scrollIntoView: "cursor"
  10451. }, {
  10452. name: "removeline",
  10453. bindKey: bindKey("Ctrl-D", "Command-D"),
  10454. exec: function(editor) { editor.removeLines(); },
  10455. scrollIntoView: "cursor",
  10456. multiSelectAction: "forEachLine"
  10457. }, {
  10458. name: "duplicateSelection",
  10459. bindKey: bindKey("Ctrl-Shift-D", "Command-Shift-D"),
  10460. exec: function(editor) { editor.duplicateSelection(); },
  10461. scrollIntoView: "cursor",
  10462. multiSelectAction: "forEach"
  10463. }, {
  10464. name: "sortlines",
  10465. bindKey: bindKey("Ctrl-Alt-S", "Command-Alt-S"),
  10466. exec: function(editor) { editor.sortLines(); },
  10467. scrollIntoView: "selection",
  10468. multiSelectAction: "forEachLine"
  10469. }, {
  10470. name: "togglecomment",
  10471. bindKey: bindKey("Ctrl-/", "Command-/"),
  10472. exec: function(editor) { editor.toggleCommentLines(); },
  10473. multiSelectAction: "forEachLine",
  10474. scrollIntoView: "selectionPart"
  10475. }, {
  10476. name: "toggleBlockComment",
  10477. bindKey: bindKey("Ctrl-Shift-/", "Command-Shift-/"),
  10478. exec: function(editor) { editor.toggleBlockComment(); },
  10479. multiSelectAction: "forEach",
  10480. scrollIntoView: "selectionPart"
  10481. }, {
  10482. name: "modifyNumberUp",
  10483. bindKey: bindKey("Ctrl-Shift-Up", "Alt-Shift-Up"),
  10484. exec: function(editor) { editor.modifyNumber(1); },
  10485. scrollIntoView: "cursor",
  10486. multiSelectAction: "forEach"
  10487. }, {
  10488. name: "modifyNumberDown",
  10489. bindKey: bindKey("Ctrl-Shift-Down", "Alt-Shift-Down"),
  10490. exec: function(editor) { editor.modifyNumber(-1); },
  10491. scrollIntoView: "cursor",
  10492. multiSelectAction: "forEach"
  10493. }, {
  10494. name: "replace",
  10495. bindKey: bindKey("Ctrl-H", "Command-Option-F"),
  10496. exec: function(editor) {
  10497. config.loadModule("ace/ext/searchbox", function(e) {e.Search(editor, true)});
  10498. }
  10499. }, {
  10500. name: "undo",
  10501. bindKey: bindKey("Ctrl-Z", "Command-Z"),
  10502. exec: function(editor) { editor.undo(); }
  10503. }, {
  10504. name: "redo",
  10505. bindKey: bindKey("Ctrl-Shift-Z|Ctrl-Y", "Command-Shift-Z|Command-Y"),
  10506. exec: function(editor) { editor.redo(); }
  10507. }, {
  10508. name: "copylinesup",
  10509. bindKey: bindKey("Alt-Shift-Up", "Command-Option-Up"),
  10510. exec: function(editor) { editor.copyLinesUp(); },
  10511. scrollIntoView: "cursor"
  10512. }, {
  10513. name: "movelinesup",
  10514. bindKey: bindKey("Alt-Up", "Option-Up"),
  10515. exec: function(editor) { editor.moveLinesUp(); },
  10516. scrollIntoView: "cursor"
  10517. }, {
  10518. name: "copylinesdown",
  10519. bindKey: bindKey("Alt-Shift-Down", "Command-Option-Down"),
  10520. exec: function(editor) { editor.copyLinesDown(); },
  10521. scrollIntoView: "cursor"
  10522. }, {
  10523. name: "movelinesdown",
  10524. bindKey: bindKey("Alt-Down", "Option-Down"),
  10525. exec: function(editor) { editor.moveLinesDown(); },
  10526. scrollIntoView: "cursor"
  10527. }, {
  10528. name: "del",
  10529. bindKey: bindKey("Delete", "Delete|Ctrl-D|Shift-Delete"),
  10530. exec: function(editor) { editor.remove("right"); },
  10531. multiSelectAction: "forEach",
  10532. scrollIntoView: "cursor"
  10533. }, {
  10534. name: "backspace",
  10535. bindKey: bindKey(
  10536. "Shift-Backspace|Backspace",
  10537. "Ctrl-Backspace|Shift-Backspace|Backspace|Ctrl-H"
  10538. ),
  10539. exec: function(editor) { editor.remove("left"); },
  10540. multiSelectAction: "forEach",
  10541. scrollIntoView: "cursor"
  10542. }, {
  10543. name: "cut_or_delete",
  10544. bindKey: bindKey("Shift-Delete", null),
  10545. exec: function(editor) {
  10546. if (editor.selection.isEmpty()) {
  10547. editor.remove("left");
  10548. } else {
  10549. return false;
  10550. }
  10551. },
  10552. multiSelectAction: "forEach",
  10553. scrollIntoView: "cursor"
  10554. }, {
  10555. name: "removetolinestart",
  10556. bindKey: bindKey("Alt-Backspace", "Command-Backspace"),
  10557. exec: function(editor) { editor.removeToLineStart(); },
  10558. multiSelectAction: "forEach",
  10559. scrollIntoView: "cursor"
  10560. }, {
  10561. name: "removetolineend",
  10562. bindKey: bindKey("Alt-Delete", "Ctrl-K"),
  10563. exec: function(editor) { editor.removeToLineEnd(); },
  10564. multiSelectAction: "forEach",
  10565. scrollIntoView: "cursor"
  10566. }, {
  10567. name: "removewordleft",
  10568. bindKey: bindKey("Ctrl-Backspace", "Alt-Backspace|Ctrl-Alt-Backspace"),
  10569. exec: function(editor) { editor.removeWordLeft(); },
  10570. multiSelectAction: "forEach",
  10571. scrollIntoView: "cursor"
  10572. }, {
  10573. name: "removewordright",
  10574. bindKey: bindKey("Ctrl-Delete", "Alt-Delete"),
  10575. exec: function(editor) { editor.removeWordRight(); },
  10576. multiSelectAction: "forEach",
  10577. scrollIntoView: "cursor"
  10578. }, {
  10579. name: "outdent",
  10580. bindKey: bindKey("Shift-Tab", "Shift-Tab"),
  10581. exec: function(editor) { editor.blockOutdent(); },
  10582. multiSelectAction: "forEach",
  10583. scrollIntoView: "selectionPart"
  10584. }, {
  10585. name: "indent",
  10586. bindKey: bindKey("Tab", "Tab"),
  10587. exec: function(editor) { editor.indent(); },
  10588. multiSelectAction: "forEach",
  10589. scrollIntoView: "selectionPart"
  10590. }, {
  10591. name: "blockoutdent",
  10592. bindKey: bindKey("Ctrl-[", "Ctrl-["),
  10593. exec: function(editor) { editor.blockOutdent(); },
  10594. multiSelectAction: "forEachLine",
  10595. scrollIntoView: "selectionPart"
  10596. }, {
  10597. name: "blockindent",
  10598. bindKey: bindKey("Ctrl-]", "Ctrl-]"),
  10599. exec: function(editor) { editor.blockIndent(); },
  10600. multiSelectAction: "forEachLine",
  10601. scrollIntoView: "selectionPart"
  10602. }, {
  10603. name: "insertstring",
  10604. exec: function(editor, str) { editor.insert(str); },
  10605. multiSelectAction: "forEach",
  10606. scrollIntoView: "cursor"
  10607. }, {
  10608. name: "inserttext",
  10609. exec: function(editor, args) {
  10610. editor.insert(lang.stringRepeat(args.text || "", args.times || 1));
  10611. },
  10612. multiSelectAction: "forEach",
  10613. scrollIntoView: "cursor"
  10614. }, {
  10615. name: "splitline",
  10616. bindKey: bindKey(null, "Ctrl-O"),
  10617. exec: function(editor) { editor.splitLine(); },
  10618. multiSelectAction: "forEach",
  10619. scrollIntoView: "cursor"
  10620. }, {
  10621. name: "transposeletters",
  10622. bindKey: bindKey("Alt-Shift-X", "Ctrl-T"),
  10623. exec: function(editor) { editor.transposeLetters(); },
  10624. multiSelectAction: function(editor) {editor.transposeSelections(1); },
  10625. scrollIntoView: "cursor"
  10626. }, {
  10627. name: "touppercase",
  10628. bindKey: bindKey("Ctrl-U", "Ctrl-U"),
  10629. exec: function(editor) { editor.toUpperCase(); },
  10630. multiSelectAction: "forEach",
  10631. scrollIntoView: "cursor"
  10632. }, {
  10633. name: "tolowercase",
  10634. bindKey: bindKey("Ctrl-Shift-U", "Ctrl-Shift-U"),
  10635. exec: function(editor) { editor.toLowerCase(); },
  10636. multiSelectAction: "forEach",
  10637. scrollIntoView: "cursor"
  10638. }, {
  10639. name: "expandtoline",
  10640. bindKey: bindKey("Ctrl-Shift-L", "Command-Shift-L"),
  10641. exec: function(editor) {
  10642. var range = editor.selection.getRange();
  10643. range.start.column = range.end.column = 0;
  10644. range.end.row++;
  10645. editor.selection.setRange(range, false);
  10646. },
  10647. multiSelectAction: "forEach",
  10648. scrollIntoView: "cursor",
  10649. readOnly: true
  10650. }, {
  10651. name: "joinlines",
  10652. bindKey: bindKey(null, null),
  10653. exec: function(editor) {
  10654. var isBackwards = editor.selection.isBackwards();
  10655. var selectionStart = isBackwards ? editor.selection.getSelectionLead() : editor.selection.getSelectionAnchor();
  10656. var selectionEnd = isBackwards ? editor.selection.getSelectionAnchor() : editor.selection.getSelectionLead();
  10657. var firstLineEndCol = editor.session.doc.getLine(selectionStart.row).length;
  10658. var selectedText = editor.session.doc.getTextRange(editor.selection.getRange());
  10659. var selectedCount = selectedText.replace(/\n\s*/, " ").length;
  10660. var insertLine = editor.session.doc.getLine(selectionStart.row);
  10661. for (var i = selectionStart.row + 1; i <= selectionEnd.row + 1; i++) {
  10662. var curLine = lang.stringTrimLeft(lang.stringTrimRight(editor.session.doc.getLine(i)));
  10663. if (curLine.length !== 0) {
  10664. curLine = " " + curLine;
  10665. }
  10666. insertLine += curLine;
  10667. }
  10668. if (selectionEnd.row + 1 < (editor.session.doc.getLength() - 1)) {
  10669. insertLine += editor.session.doc.getNewLineCharacter();
  10670. }
  10671. editor.clearSelection();
  10672. editor.session.doc.replace(new Range(selectionStart.row, 0, selectionEnd.row + 2, 0), insertLine);
  10673. if (selectedCount > 0) {
  10674. editor.selection.moveCursorTo(selectionStart.row, selectionStart.column);
  10675. editor.selection.selectTo(selectionStart.row, selectionStart.column + selectedCount);
  10676. } else {
  10677. firstLineEndCol = editor.session.doc.getLine(selectionStart.row).length > firstLineEndCol ? (firstLineEndCol + 1) : firstLineEndCol;
  10678. editor.selection.moveCursorTo(selectionStart.row, firstLineEndCol);
  10679. }
  10680. },
  10681. multiSelectAction: "forEach",
  10682. readOnly: true
  10683. }, {
  10684. name: "invertSelection",
  10685. bindKey: bindKey(null, null),
  10686. exec: function(editor) {
  10687. var endRow = editor.session.doc.getLength() - 1;
  10688. var endCol = editor.session.doc.getLine(endRow).length;
  10689. var ranges = editor.selection.rangeList.ranges;
  10690. var newRanges = [];
  10691. if (ranges.length < 1) {
  10692. ranges = [editor.selection.getRange()];
  10693. }
  10694. for (var i = 0; i < ranges.length; i++) {
  10695. if (i == (ranges.length - 1)) {
  10696. if (!(ranges[i].end.row === endRow && ranges[i].end.column === endCol)) {
  10697. newRanges.push(new Range(ranges[i].end.row, ranges[i].end.column, endRow, endCol));
  10698. }
  10699. }
  10700. if (i === 0) {
  10701. if (!(ranges[i].start.row === 0 && ranges[i].start.column === 0)) {
  10702. newRanges.push(new Range(0, 0, ranges[i].start.row, ranges[i].start.column));
  10703. }
  10704. } else {
  10705. newRanges.push(new Range(ranges[i-1].end.row, ranges[i-1].end.column, ranges[i].start.row, ranges[i].start.column));
  10706. }
  10707. }
  10708. editor.exitMultiSelectMode();
  10709. editor.clearSelection();
  10710. for(var i = 0; i < newRanges.length; i++) {
  10711. editor.selection.addRange(newRanges[i], false);
  10712. }
  10713. },
  10714. readOnly: true,
  10715. scrollIntoView: "none"
  10716. }];
  10717. });
  10718. define("ace/editor",["require","exports","module","ace/lib/fixoldbrowsers","ace/lib/oop","ace/lib/dom","ace/lib/lang","ace/lib/useragent","ace/keyboard/textinput","ace/mouse/mouse_handler","ace/mouse/fold_handler","ace/keyboard/keybinding","ace/edit_session","ace/search","ace/range","ace/lib/event_emitter","ace/commands/command_manager","ace/commands/default_commands","ace/config","ace/token_iterator"], function(require, exports, module) {
  10719. "use strict";
  10720. require("./lib/fixoldbrowsers");
  10721. var oop = require("./lib/oop");
  10722. var dom = require("./lib/dom");
  10723. var lang = require("./lib/lang");
  10724. var useragent = require("./lib/useragent");
  10725. var TextInput = require("./keyboard/textinput").TextInput;
  10726. var MouseHandler = require("./mouse/mouse_handler").MouseHandler;
  10727. var FoldHandler = require("./mouse/fold_handler").FoldHandler;
  10728. var KeyBinding = require("./keyboard/keybinding").KeyBinding;
  10729. var EditSession = require("./edit_session").EditSession;
  10730. var Search = require("./search").Search;
  10731. var Range = require("./range").Range;
  10732. var EventEmitter = require("./lib/event_emitter").EventEmitter;
  10733. var CommandManager = require("./commands/command_manager").CommandManager;
  10734. var defaultCommands = require("./commands/default_commands").commands;
  10735. var config = require("./config");
  10736. var TokenIterator = require("./token_iterator").TokenIterator;
  10737. var Editor = function(renderer, session) {
  10738. var container = renderer.getContainerElement();
  10739. this.container = container;
  10740. this.renderer = renderer;
  10741. this.id = "editor" + (++Editor.$uid);
  10742. this.commands = new CommandManager(useragent.isMac ? "mac" : "win", defaultCommands);
  10743. if (typeof document == "object") {
  10744. this.textInput = new TextInput(renderer.getTextAreaContainer(), this);
  10745. this.renderer.textarea = this.textInput.getElement();
  10746. this.$mouseHandler = new MouseHandler(this);
  10747. new FoldHandler(this);
  10748. }
  10749. this.keyBinding = new KeyBinding(this);
  10750. this.$blockScrolling = 0;
  10751. this.$search = new Search().set({
  10752. wrap: true
  10753. });
  10754. this.$historyTracker = this.$historyTracker.bind(this);
  10755. this.commands.on("exec", this.$historyTracker);
  10756. this.$initOperationListeners();
  10757. this._$emitInputEvent = lang.delayedCall(function() {
  10758. this._signal("input", {});
  10759. if (this.session && this.session.bgTokenizer)
  10760. this.session.bgTokenizer.scheduleStart();
  10761. }.bind(this));
  10762. this.on("change", function(_, _self) {
  10763. _self._$emitInputEvent.schedule(31);
  10764. });
  10765. this.setSession(session || new EditSession(""));
  10766. config.resetOptions(this);
  10767. config._signal("editor", this);
  10768. };
  10769. Editor.$uid = 0;
  10770. (function(){
  10771. oop.implement(this, EventEmitter);
  10772. this.$initOperationListeners = function() {
  10773. function last(a) {return a[a.length - 1]}
  10774. this.selections = [];
  10775. this.commands.on("exec", this.startOperation.bind(this), true);
  10776. this.commands.on("afterExec", this.endOperation.bind(this), true);
  10777. this.$opResetTimer = lang.delayedCall(this.endOperation.bind(this));
  10778. this.on("change", function() {
  10779. this.curOp || this.startOperation();
  10780. this.curOp.docChanged = true;
  10781. }.bind(this), true);
  10782. this.on("changeSelection", function() {
  10783. this.curOp || this.startOperation();
  10784. this.curOp.selectionChanged = true;
  10785. }.bind(this), true);
  10786. };
  10787. this.curOp = null;
  10788. this.prevOp = {};
  10789. this.startOperation = function(commadEvent) {
  10790. if (this.curOp) {
  10791. if (!commadEvent || this.curOp.command)
  10792. return;
  10793. this.prevOp = this.curOp;
  10794. }
  10795. if (!commadEvent) {
  10796. this.previousCommand = null;
  10797. commadEvent = {};
  10798. }
  10799. this.$opResetTimer.schedule();
  10800. this.curOp = {
  10801. command: commadEvent.command || {},
  10802. args: commadEvent.args,
  10803. scrollTop: this.renderer.scrollTop
  10804. };
  10805. if (this.curOp.command.name && this.curOp.command.scrollIntoView !== undefined)
  10806. this.$blockScrolling++;
  10807. };
  10808. this.endOperation = function(e) {
  10809. if (this.curOp) {
  10810. if (e && e.returnValue === false)
  10811. return this.curOp = null;
  10812. this._signal("beforeEndOperation");
  10813. var command = this.curOp.command;
  10814. if (command.name && this.$blockScrolling > 0)
  10815. this.$blockScrolling--;
  10816. var scrollIntoView = command && command.scrollIntoView;
  10817. if (scrollIntoView) {
  10818. switch (scrollIntoView) {
  10819. case "center-animate":
  10820. scrollIntoView = "animate";
  10821. case "center":
  10822. this.renderer.scrollCursorIntoView(null, 0.5);
  10823. break;
  10824. case "animate":
  10825. case "cursor":
  10826. this.renderer.scrollCursorIntoView();
  10827. break;
  10828. case "selectionPart":
  10829. var range = this.selection.getRange();
  10830. var config = this.renderer.layerConfig;
  10831. if (range.start.row >= config.lastRow || range.end.row <= config.firstRow) {
  10832. this.renderer.scrollSelectionIntoView(this.selection.anchor, this.selection.lead);
  10833. }
  10834. break;
  10835. default:
  10836. break;
  10837. }
  10838. if (scrollIntoView == "animate")
  10839. this.renderer.animateScrolling(this.curOp.scrollTop);
  10840. }
  10841. this.prevOp = this.curOp;
  10842. this.curOp = null;
  10843. }
  10844. };
  10845. this.$mergeableCommands = ["backspace", "del", "insertstring"];
  10846. this.$historyTracker = function(e) {
  10847. if (!this.$mergeUndoDeltas)
  10848. return;
  10849. var prev = this.prevOp;
  10850. var mergeableCommands = this.$mergeableCommands;
  10851. var shouldMerge = prev.command && (e.command.name == prev.command.name);
  10852. if (e.command.name == "insertstring") {
  10853. var text = e.args;
  10854. if (this.mergeNextCommand === undefined)
  10855. this.mergeNextCommand = true;
  10856. shouldMerge = shouldMerge
  10857. && this.mergeNextCommand // previous command allows to coalesce with
  10858. && (!/\s/.test(text) || /\s/.test(prev.args)); // previous insertion was of same type
  10859. this.mergeNextCommand = true;
  10860. } else {
  10861. shouldMerge = shouldMerge
  10862. && mergeableCommands.indexOf(e.command.name) !== -1; // the command is mergeable
  10863. }
  10864. if (
  10865. this.$mergeUndoDeltas != "always"
  10866. && Date.now() - this.sequenceStartTime > 2000
  10867. ) {
  10868. shouldMerge = false; // the sequence is too long
  10869. }
  10870. if (shouldMerge)
  10871. this.session.mergeUndoDeltas = true;
  10872. else if (mergeableCommands.indexOf(e.command.name) !== -1)
  10873. this.sequenceStartTime = Date.now();
  10874. };
  10875. this.setKeyboardHandler = function(keyboardHandler, cb) {
  10876. if (keyboardHandler && typeof keyboardHandler === "string") {
  10877. this.$keybindingId = keyboardHandler;
  10878. var _self = this;
  10879. config.loadModule(["keybinding", keyboardHandler], function(module) {
  10880. if (_self.$keybindingId == keyboardHandler)
  10881. _self.keyBinding.setKeyboardHandler(module && module.handler);
  10882. cb && cb();
  10883. });
  10884. } else {
  10885. this.$keybindingId = null;
  10886. this.keyBinding.setKeyboardHandler(keyboardHandler);
  10887. cb && cb();
  10888. }
  10889. };
  10890. this.getKeyboardHandler = function() {
  10891. return this.keyBinding.getKeyboardHandler();
  10892. };
  10893. this.setSession = function(session) {
  10894. if (this.session == session)
  10895. return;
  10896. if (this.curOp) this.endOperation();
  10897. this.curOp = {};
  10898. var oldSession = this.session;
  10899. if (oldSession) {
  10900. this.session.off("change", this.$onDocumentChange);
  10901. this.session.off("changeMode", this.$onChangeMode);
  10902. this.session.off("tokenizerUpdate", this.$onTokenizerUpdate);
  10903. this.session.off("changeTabSize", this.$onChangeTabSize);
  10904. this.session.off("changeWrapLimit", this.$onChangeWrapLimit);
  10905. this.session.off("changeWrapMode", this.$onChangeWrapMode);
  10906. this.session.off("changeFold", this.$onChangeFold);
  10907. this.session.off("changeFrontMarker", this.$onChangeFrontMarker);
  10908. this.session.off("changeBackMarker", this.$onChangeBackMarker);
  10909. this.session.off("changeBreakpoint", this.$onChangeBreakpoint);
  10910. this.session.off("changeAnnotation", this.$onChangeAnnotation);
  10911. this.session.off("changeOverwrite", this.$onCursorChange);
  10912. this.session.off("changeScrollTop", this.$onScrollTopChange);
  10913. this.session.off("changeScrollLeft", this.$onScrollLeftChange);
  10914. var selection = this.session.getSelection();
  10915. selection.off("changeCursor", this.$onCursorChange);
  10916. selection.off("changeSelection", this.$onSelectionChange);
  10917. }
  10918. this.session = session;
  10919. if (session) {
  10920. this.$onDocumentChange = this.onDocumentChange.bind(this);
  10921. session.on("change", this.$onDocumentChange);
  10922. this.renderer.setSession(session);
  10923. this.$onChangeMode = this.onChangeMode.bind(this);
  10924. session.on("changeMode", this.$onChangeMode);
  10925. this.$onTokenizerUpdate = this.onTokenizerUpdate.bind(this);
  10926. session.on("tokenizerUpdate", this.$onTokenizerUpdate);
  10927. this.$onChangeTabSize = this.renderer.onChangeTabSize.bind(this.renderer);
  10928. session.on("changeTabSize", this.$onChangeTabSize);
  10929. this.$onChangeWrapLimit = this.onChangeWrapLimit.bind(this);
  10930. session.on("changeWrapLimit", this.$onChangeWrapLimit);
  10931. this.$onChangeWrapMode = this.onChangeWrapMode.bind(this);
  10932. session.on("changeWrapMode", this.$onChangeWrapMode);
  10933. this.$onChangeFold = this.onChangeFold.bind(this);
  10934. session.on("changeFold", this.$onChangeFold);
  10935. this.$onChangeFrontMarker = this.onChangeFrontMarker.bind(this);
  10936. this.session.on("changeFrontMarker", this.$onChangeFrontMarker);
  10937. this.$onChangeBackMarker = this.onChangeBackMarker.bind(this);
  10938. this.session.on("changeBackMarker", this.$onChangeBackMarker);
  10939. this.$onChangeBreakpoint = this.onChangeBreakpoint.bind(this);
  10940. this.session.on("changeBreakpoint", this.$onChangeBreakpoint);
  10941. this.$onChangeAnnotation = this.onChangeAnnotation.bind(this);
  10942. this.session.on("changeAnnotation", this.$onChangeAnnotation);
  10943. this.$onCursorChange = this.onCursorChange.bind(this);
  10944. this.session.on("changeOverwrite", this.$onCursorChange);
  10945. this.$onScrollTopChange = this.onScrollTopChange.bind(this);
  10946. this.session.on("changeScrollTop", this.$onScrollTopChange);
  10947. this.$onScrollLeftChange = this.onScrollLeftChange.bind(this);
  10948. this.session.on("changeScrollLeft", this.$onScrollLeftChange);
  10949. this.selection = session.getSelection();
  10950. this.selection.on("changeCursor", this.$onCursorChange);
  10951. this.$onSelectionChange = this.onSelectionChange.bind(this);
  10952. this.selection.on("changeSelection", this.$onSelectionChange);
  10953. this.onChangeMode();
  10954. this.$blockScrolling += 1;
  10955. this.onCursorChange();
  10956. this.$blockScrolling -= 1;
  10957. this.onScrollTopChange();
  10958. this.onScrollLeftChange();
  10959. this.onSelectionChange();
  10960. this.onChangeFrontMarker();
  10961. this.onChangeBackMarker();
  10962. this.onChangeBreakpoint();
  10963. this.onChangeAnnotation();
  10964. this.session.getUseWrapMode() && this.renderer.adjustWrapLimit();
  10965. this.renderer.updateFull();
  10966. } else {
  10967. this.selection = null;
  10968. this.renderer.setSession(session);
  10969. }
  10970. this._signal("changeSession", {
  10971. session: session,
  10972. oldSession: oldSession
  10973. });
  10974. this.curOp = null;
  10975. oldSession && oldSession._signal("changeEditor", {oldEditor: this});
  10976. session && session._signal("changeEditor", {editor: this});
  10977. if (session && session.bgTokenizer)
  10978. session.bgTokenizer.scheduleStart();
  10979. };
  10980. this.getSession = function() {
  10981. return this.session;
  10982. };
  10983. this.setValue = function(val, cursorPos) {
  10984. this.session.doc.setValue(val);
  10985. if (!cursorPos)
  10986. this.selectAll();
  10987. else if (cursorPos == 1)
  10988. this.navigateFileEnd();
  10989. else if (cursorPos == -1)
  10990. this.navigateFileStart();
  10991. return val;
  10992. };
  10993. this.getValue = function() {
  10994. return this.session.getValue();
  10995. };
  10996. this.getSelection = function() {
  10997. return this.selection;
  10998. };
  10999. this.resize = function(force) {
  11000. this.renderer.onResize(force);
  11001. };
  11002. this.setTheme = function(theme, cb) {
  11003. this.renderer.setTheme(theme, cb);
  11004. };
  11005. this.getTheme = function() {
  11006. return this.renderer.getTheme();
  11007. };
  11008. this.setStyle = function(style) {
  11009. this.renderer.setStyle(style);
  11010. };
  11011. this.unsetStyle = function(style) {
  11012. this.renderer.unsetStyle(style);
  11013. };
  11014. this.getFontSize = function () {
  11015. return this.getOption("fontSize") ||
  11016. dom.computedStyle(this.container, "fontSize");
  11017. };
  11018. this.setFontSize = function(size) {
  11019. this.setOption("fontSize", size);
  11020. };
  11021. this.$highlightBrackets = function() {
  11022. if (this.session.$bracketHighlight) {
  11023. this.session.removeMarker(this.session.$bracketHighlight);
  11024. this.session.$bracketHighlight = null;
  11025. }
  11026. if (this.$highlightPending) {
  11027. return;
  11028. }
  11029. var self = this;
  11030. this.$highlightPending = true;
  11031. setTimeout(function() {
  11032. self.$highlightPending = false;
  11033. var session = self.session;
  11034. if (!session || !session.bgTokenizer) return;
  11035. var pos = session.findMatchingBracket(self.getCursorPosition());
  11036. if (pos) {
  11037. var range = new Range(pos.row, pos.column, pos.row, pos.column + 1);
  11038. } else if (session.$mode.getMatching) {
  11039. var range = session.$mode.getMatching(self.session);
  11040. }
  11041. if (range)
  11042. session.$bracketHighlight = session.addMarker(range, "ace_bracket", "text");
  11043. }, 50);
  11044. };
  11045. this.$highlightTags = function() {
  11046. if (this.$highlightTagPending)
  11047. return;
  11048. var self = this;
  11049. this.$highlightTagPending = true;
  11050. setTimeout(function() {
  11051. self.$highlightTagPending = false;
  11052. var session = self.session;
  11053. if (!session || !session.bgTokenizer) return;
  11054. var pos = self.getCursorPosition();
  11055. var iterator = new TokenIterator(self.session, pos.row, pos.column);
  11056. var token = iterator.getCurrentToken();
  11057. if (!token || !/\b(?:tag-open|tag-name)/.test(token.type)) {
  11058. session.removeMarker(session.$tagHighlight);
  11059. session.$tagHighlight = null;
  11060. return;
  11061. }
  11062. if (token.type.indexOf("tag-open") != -1) {
  11063. token = iterator.stepForward();
  11064. if (!token)
  11065. return;
  11066. }
  11067. var tag = token.value;
  11068. var depth = 0;
  11069. var prevToken = iterator.stepBackward();
  11070. if (prevToken.value == '<'){
  11071. do {
  11072. prevToken = token;
  11073. token = iterator.stepForward();
  11074. if (token && token.value === tag && token.type.indexOf('tag-name') !== -1) {
  11075. if (prevToken.value === '<'){
  11076. depth++;
  11077. } else if (prevToken.value === '</'){
  11078. depth--;
  11079. }
  11080. }
  11081. } while (token && depth >= 0);
  11082. } else {
  11083. do {
  11084. token = prevToken;
  11085. prevToken = iterator.stepBackward();
  11086. if (token && token.value === tag && token.type.indexOf('tag-name') !== -1) {
  11087. if (prevToken.value === '<') {
  11088. depth++;
  11089. } else if (prevToken.value === '</') {
  11090. depth--;
  11091. }
  11092. }
  11093. } while (prevToken && depth <= 0);
  11094. iterator.stepForward();
  11095. }
  11096. if (!token) {
  11097. session.removeMarker(session.$tagHighlight);
  11098. session.$tagHighlight = null;
  11099. return;
  11100. }
  11101. var row = iterator.getCurrentTokenRow();
  11102. var column = iterator.getCurrentTokenColumn();
  11103. var range = new Range(row, column, row, column+token.value.length);
  11104. var sbm = session.$backMarkers[session.$tagHighlight];
  11105. if (session.$tagHighlight && sbm != undefined && range.compareRange(sbm.range) !== 0) {
  11106. session.removeMarker(session.$tagHighlight);
  11107. session.$tagHighlight = null;
  11108. }
  11109. if (range && !session.$tagHighlight)
  11110. session.$tagHighlight = session.addMarker(range, "ace_bracket", "text");
  11111. }, 50);
  11112. };
  11113. this.focus = function() {
  11114. var _self = this;
  11115. setTimeout(function() {
  11116. _self.textInput.focus();
  11117. });
  11118. this.textInput.focus();
  11119. };
  11120. this.isFocused = function() {
  11121. return this.textInput.isFocused();
  11122. };
  11123. this.blur = function() {
  11124. this.textInput.blur();
  11125. };
  11126. this.onFocus = function(e) {
  11127. if (this.$isFocused)
  11128. return;
  11129. this.$isFocused = true;
  11130. this.renderer.showCursor();
  11131. this.renderer.visualizeFocus();
  11132. this._emit("focus", e);
  11133. };
  11134. this.onBlur = function(e) {
  11135. if (!this.$isFocused)
  11136. return;
  11137. this.$isFocused = false;
  11138. this.renderer.hideCursor();
  11139. this.renderer.visualizeBlur();
  11140. this._emit("blur", e);
  11141. };
  11142. this.$cursorChange = function() {
  11143. this.renderer.updateCursor();
  11144. };
  11145. this.onDocumentChange = function(delta) {
  11146. var wrap = this.session.$useWrapMode;
  11147. var lastRow = (delta.start.row == delta.end.row ? delta.end.row : Infinity);
  11148. this.renderer.updateLines(delta.start.row, lastRow, wrap);
  11149. this._signal("change", delta);
  11150. this.$cursorChange();
  11151. this.$updateHighlightActiveLine();
  11152. };
  11153. this.onTokenizerUpdate = function(e) {
  11154. var rows = e.data;
  11155. this.renderer.updateLines(rows.first, rows.last);
  11156. };
  11157. this.onScrollTopChange = function() {
  11158. this.renderer.scrollToY(this.session.getScrollTop());
  11159. };
  11160. this.onScrollLeftChange = function() {
  11161. this.renderer.scrollToX(this.session.getScrollLeft());
  11162. };
  11163. this.onCursorChange = function() {
  11164. this.$cursorChange();
  11165. if (!this.$blockScrolling) {
  11166. config.warn("Automatically scrolling cursor into view after selection change",
  11167. "this will be disabled in the next version",
  11168. "set editor.$blockScrolling = Infinity to disable this message"
  11169. );
  11170. this.renderer.scrollCursorIntoView();
  11171. }
  11172. this.$highlightBrackets();
  11173. this.$highlightTags();
  11174. this.$updateHighlightActiveLine();
  11175. this._signal("changeSelection");
  11176. };
  11177. this.$updateHighlightActiveLine = function() {
  11178. var session = this.getSession();
  11179. var highlight;
  11180. if (this.$highlightActiveLine) {
  11181. if ((this.$selectionStyle != "line" || !this.selection.isMultiLine()))
  11182. highlight = this.getCursorPosition();
  11183. if (this.renderer.$maxLines && this.session.getLength() === 1 && !(this.renderer.$minLines > 1))
  11184. highlight = false;
  11185. }
  11186. if (session.$highlightLineMarker && !highlight) {
  11187. session.removeMarker(session.$highlightLineMarker.id);
  11188. session.$highlightLineMarker = null;
  11189. } else if (!session.$highlightLineMarker && highlight) {
  11190. var range = new Range(highlight.row, highlight.column, highlight.row, Infinity);
  11191. range.id = session.addMarker(range, "ace_active-line", "screenLine");
  11192. session.$highlightLineMarker = range;
  11193. } else if (highlight) {
  11194. session.$highlightLineMarker.start.row = highlight.row;
  11195. session.$highlightLineMarker.end.row = highlight.row;
  11196. session.$highlightLineMarker.start.column = highlight.column;
  11197. session._signal("changeBackMarker");
  11198. }
  11199. };
  11200. this.onSelectionChange = function(e) {
  11201. var session = this.session;
  11202. if (session.$selectionMarker) {
  11203. session.removeMarker(session.$selectionMarker);
  11204. }
  11205. session.$selectionMarker = null;
  11206. if (!this.selection.isEmpty()) {
  11207. var range = this.selection.getRange();
  11208. var style = this.getSelectionStyle();
  11209. session.$selectionMarker = session.addMarker(range, "ace_selection", style);
  11210. } else {
  11211. this.$updateHighlightActiveLine();
  11212. }
  11213. var re = this.$highlightSelectedWord && this.$getSelectionHighLightRegexp();
  11214. this.session.highlight(re);
  11215. this._signal("changeSelection");
  11216. };
  11217. this.$getSelectionHighLightRegexp = function() {
  11218. var session = this.session;
  11219. var selection = this.getSelectionRange();
  11220. if (selection.isEmpty() || selection.isMultiLine())
  11221. return;
  11222. var startOuter = selection.start.column - 1;
  11223. var endOuter = selection.end.column + 1;
  11224. var line = session.getLine(selection.start.row);
  11225. var lineCols = line.length;
  11226. var needle = line.substring(Math.max(startOuter, 0),
  11227. Math.min(endOuter, lineCols));
  11228. if ((startOuter >= 0 && /^[\w\d]/.test(needle)) ||
  11229. (endOuter <= lineCols && /[\w\d]$/.test(needle)))
  11230. return;
  11231. needle = line.substring(selection.start.column, selection.end.column);
  11232. if (!/^[\w\d]+$/.test(needle))
  11233. return;
  11234. var re = this.$search.$assembleRegExp({
  11235. wholeWord: true,
  11236. caseSensitive: true,
  11237. needle: needle
  11238. });
  11239. return re;
  11240. };
  11241. this.onChangeFrontMarker = function() {
  11242. this.renderer.updateFrontMarkers();
  11243. };
  11244. this.onChangeBackMarker = function() {
  11245. this.renderer.updateBackMarkers();
  11246. };
  11247. this.onChangeBreakpoint = function() {
  11248. this.renderer.updateBreakpoints();
  11249. };
  11250. this.onChangeAnnotation = function() {
  11251. this.renderer.setAnnotations(this.session.getAnnotations());
  11252. };
  11253. this.onChangeMode = function(e) {
  11254. this.renderer.updateText();
  11255. this._emit("changeMode", e);
  11256. };
  11257. this.onChangeWrapLimit = function() {
  11258. this.renderer.updateFull();
  11259. };
  11260. this.onChangeWrapMode = function() {
  11261. this.renderer.onResize(true);
  11262. };
  11263. this.onChangeFold = function() {
  11264. this.$updateHighlightActiveLine();
  11265. this.renderer.updateFull();
  11266. };
  11267. this.getSelectedText = function() {
  11268. return this.session.getTextRange(this.getSelectionRange());
  11269. };
  11270. this.getCopyText = function() {
  11271. var text = this.getSelectedText();
  11272. this._signal("copy", text);
  11273. return text;
  11274. };
  11275. this.onCopy = function() {
  11276. this.commands.exec("copy", this);
  11277. };
  11278. this.onCut = function() {
  11279. this.commands.exec("cut", this);
  11280. };
  11281. this.onPaste = function(text, event) {
  11282. var e = {text: text, event: event};
  11283. this.commands.exec("paste", this, e);
  11284. };
  11285. this.$handlePaste = function(e) {
  11286. if (typeof e == "string")
  11287. e = {text: e};
  11288. this._signal("paste", e);
  11289. var text = e.text;
  11290. if (!this.inMultiSelectMode || this.inVirtualSelectionMode) {
  11291. this.insert(text);
  11292. } else {
  11293. var lines = text.split(/\r\n|\r|\n/);
  11294. var ranges = this.selection.rangeList.ranges;
  11295. if (lines.length > ranges.length || lines.length < 2 || !lines[1])
  11296. return this.commands.exec("insertstring", this, text);
  11297. for (var i = ranges.length; i--;) {
  11298. var range = ranges[i];
  11299. if (!range.isEmpty())
  11300. this.session.remove(range);
  11301. this.session.insert(range.start, lines[i]);
  11302. }
  11303. }
  11304. };
  11305. this.execCommand = function(command, args) {
  11306. return this.commands.exec(command, this, args);
  11307. };
  11308. this.insert = function(text, pasted) {
  11309. var session = this.session;
  11310. var mode = session.getMode();
  11311. var cursor = this.getCursorPosition();
  11312. if (this.getBehavioursEnabled() && !pasted) {
  11313. var transform = mode.transformAction(session.getState(cursor.row), 'insertion', this, session, text);
  11314. if (transform) {
  11315. if (text !== transform.text) {
  11316. this.session.mergeUndoDeltas = false;
  11317. this.$mergeNextCommand = false;
  11318. }
  11319. text = transform.text;
  11320. }
  11321. }
  11322. if (text == "\t")
  11323. text = this.session.getTabString();
  11324. if (!this.selection.isEmpty()) {
  11325. var range = this.getSelectionRange();
  11326. cursor = this.session.remove(range);
  11327. this.clearSelection();
  11328. }
  11329. else if (this.session.getOverwrite() && text.indexOf("\n") == -1) {
  11330. var range = new Range.fromPoints(cursor, cursor);
  11331. range.end.column += text.length;
  11332. this.session.remove(range);
  11333. }
  11334. if (text == "\n" || text == "\r\n") {
  11335. var line = session.getLine(cursor.row);
  11336. if (cursor.column > line.search(/\S|$/)) {
  11337. var d = line.substr(cursor.column).search(/\S|$/);
  11338. session.doc.removeInLine(cursor.row, cursor.column, cursor.column + d);
  11339. }
  11340. }
  11341. this.clearSelection();
  11342. var start = cursor.column;
  11343. var lineState = session.getState(cursor.row);
  11344. var line = session.getLine(cursor.row);
  11345. var shouldOutdent = mode.checkOutdent(lineState, line, text);
  11346. var end = session.insert(cursor, text);
  11347. if (transform && transform.selection) {
  11348. if (transform.selection.length == 2) { // Transform relative to the current column
  11349. this.selection.setSelectionRange(
  11350. new Range(cursor.row, start + transform.selection[0],
  11351. cursor.row, start + transform.selection[1]));
  11352. } else { // Transform relative to the current row.
  11353. this.selection.setSelectionRange(
  11354. new Range(cursor.row + transform.selection[0],
  11355. transform.selection[1],
  11356. cursor.row + transform.selection[2],
  11357. transform.selection[3]));
  11358. }
  11359. }
  11360. if (session.getDocument().isNewLine(text)) {
  11361. var lineIndent = mode.getNextLineIndent(lineState, line.slice(0, cursor.column), session.getTabString());
  11362. session.insert({row: cursor.row+1, column: 0}, lineIndent);
  11363. }
  11364. if (shouldOutdent)
  11365. mode.autoOutdent(lineState, session, cursor.row);
  11366. };
  11367. this.onTextInput = function(text) {
  11368. this.keyBinding.onTextInput(text);
  11369. };
  11370. this.onCommandKey = function(e, hashId, keyCode) {
  11371. this.keyBinding.onCommandKey(e, hashId, keyCode);
  11372. };
  11373. this.setOverwrite = function(overwrite) {
  11374. this.session.setOverwrite(overwrite);
  11375. };
  11376. this.getOverwrite = function() {
  11377. return this.session.getOverwrite();
  11378. };
  11379. this.toggleOverwrite = function() {
  11380. this.session.toggleOverwrite();
  11381. };
  11382. this.setScrollSpeed = function(speed) {
  11383. this.setOption("scrollSpeed", speed);
  11384. };
  11385. this.getScrollSpeed = function() {
  11386. return this.getOption("scrollSpeed");
  11387. };
  11388. this.setDragDelay = function(dragDelay) {
  11389. this.setOption("dragDelay", dragDelay);
  11390. };
  11391. this.getDragDelay = function() {
  11392. return this.getOption("dragDelay");
  11393. };
  11394. this.setSelectionStyle = function(val) {
  11395. this.setOption("selectionStyle", val);
  11396. };
  11397. this.getSelectionStyle = function() {
  11398. return this.getOption("selectionStyle");
  11399. };
  11400. this.setHighlightActiveLine = function(shouldHighlight) {
  11401. this.setOption("highlightActiveLine", shouldHighlight);
  11402. };
  11403. this.getHighlightActiveLine = function() {
  11404. return this.getOption("highlightActiveLine");
  11405. };
  11406. this.setHighlightGutterLine = function(shouldHighlight) {
  11407. this.setOption("highlightGutterLine", shouldHighlight);
  11408. };
  11409. this.getHighlightGutterLine = function() {
  11410. return this.getOption("highlightGutterLine");
  11411. };
  11412. this.setHighlightSelectedWord = function(shouldHighlight) {
  11413. this.setOption("highlightSelectedWord", shouldHighlight);
  11414. };
  11415. this.getHighlightSelectedWord = function() {
  11416. return this.$highlightSelectedWord;
  11417. };
  11418. this.setAnimatedScroll = function(shouldAnimate){
  11419. this.renderer.setAnimatedScroll(shouldAnimate);
  11420. };
  11421. this.getAnimatedScroll = function(){
  11422. return this.renderer.getAnimatedScroll();
  11423. };
  11424. this.setShowInvisibles = function(showInvisibles) {
  11425. this.renderer.setShowInvisibles(showInvisibles);
  11426. };
  11427. this.getShowInvisibles = function() {
  11428. return this.renderer.getShowInvisibles();
  11429. };
  11430. this.setDisplayIndentGuides = function(display) {
  11431. this.renderer.setDisplayIndentGuides(display);
  11432. };
  11433. this.getDisplayIndentGuides = function() {
  11434. return this.renderer.getDisplayIndentGuides();
  11435. };
  11436. this.setShowPrintMargin = function(showPrintMargin) {
  11437. this.renderer.setShowPrintMargin(showPrintMargin);
  11438. };
  11439. this.getShowPrintMargin = function() {
  11440. return this.renderer.getShowPrintMargin();
  11441. };
  11442. this.setPrintMarginColumn = function(showPrintMargin) {
  11443. this.renderer.setPrintMarginColumn(showPrintMargin);
  11444. };
  11445. this.getPrintMarginColumn = function() {
  11446. return this.renderer.getPrintMarginColumn();
  11447. };
  11448. this.setReadOnly = function(readOnly) {
  11449. this.setOption("readOnly", readOnly);
  11450. };
  11451. this.getReadOnly = function() {
  11452. return this.getOption("readOnly");
  11453. };
  11454. this.setBehavioursEnabled = function (enabled) {
  11455. this.setOption("behavioursEnabled", enabled);
  11456. };
  11457. this.getBehavioursEnabled = function () {
  11458. return this.getOption("behavioursEnabled");
  11459. };
  11460. this.setWrapBehavioursEnabled = function (enabled) {
  11461. this.setOption("wrapBehavioursEnabled", enabled);
  11462. };
  11463. this.getWrapBehavioursEnabled = function () {
  11464. return this.getOption("wrapBehavioursEnabled");
  11465. };
  11466. this.setShowFoldWidgets = function(show) {
  11467. this.setOption("showFoldWidgets", show);
  11468. };
  11469. this.getShowFoldWidgets = function() {
  11470. return this.getOption("showFoldWidgets");
  11471. };
  11472. this.setFadeFoldWidgets = function(fade) {
  11473. this.setOption("fadeFoldWidgets", fade);
  11474. };
  11475. this.getFadeFoldWidgets = function() {
  11476. return this.getOption("fadeFoldWidgets");
  11477. };
  11478. this.remove = function(dir) {
  11479. if (this.selection.isEmpty()){
  11480. if (dir == "left")
  11481. this.selection.selectLeft();
  11482. else
  11483. this.selection.selectRight();
  11484. }
  11485. var range = this.getSelectionRange();
  11486. if (this.getBehavioursEnabled()) {
  11487. var session = this.session;
  11488. var state = session.getState(range.start.row);
  11489. var new_range = session.getMode().transformAction(state, 'deletion', this, session, range);
  11490. if (range.end.column === 0) {
  11491. var text = session.getTextRange(range);
  11492. if (text[text.length - 1] == "\n") {
  11493. var line = session.getLine(range.end.row);
  11494. if (/^\s+$/.test(line)) {
  11495. range.end.column = line.length;
  11496. }
  11497. }
  11498. }
  11499. if (new_range)
  11500. range = new_range;
  11501. }
  11502. this.session.remove(range);
  11503. this.clearSelection();
  11504. };
  11505. this.removeWordRight = function() {
  11506. if (this.selection.isEmpty())
  11507. this.selection.selectWordRight();
  11508. this.session.remove(this.getSelectionRange());
  11509. this.clearSelection();
  11510. };
  11511. this.removeWordLeft = function() {
  11512. if (this.selection.isEmpty())
  11513. this.selection.selectWordLeft();
  11514. this.session.remove(this.getSelectionRange());
  11515. this.clearSelection();
  11516. };
  11517. this.removeToLineStart = function() {
  11518. if (this.selection.isEmpty())
  11519. this.selection.selectLineStart();
  11520. this.session.remove(this.getSelectionRange());
  11521. this.clearSelection();
  11522. };
  11523. this.removeToLineEnd = function() {
  11524. if (this.selection.isEmpty())
  11525. this.selection.selectLineEnd();
  11526. var range = this.getSelectionRange();
  11527. if (range.start.column == range.end.column && range.start.row == range.end.row) {
  11528. range.end.column = 0;
  11529. range.end.row++;
  11530. }
  11531. this.session.remove(range);
  11532. this.clearSelection();
  11533. };
  11534. this.splitLine = function() {
  11535. if (!this.selection.isEmpty()) {
  11536. this.session.remove(this.getSelectionRange());
  11537. this.clearSelection();
  11538. }
  11539. var cursor = this.getCursorPosition();
  11540. this.insert("\n");
  11541. this.moveCursorToPosition(cursor);
  11542. };
  11543. this.transposeLetters = function() {
  11544. if (!this.selection.isEmpty()) {
  11545. return;
  11546. }
  11547. var cursor = this.getCursorPosition();
  11548. var column = cursor.column;
  11549. if (column === 0)
  11550. return;
  11551. var line = this.session.getLine(cursor.row);
  11552. var swap, range;
  11553. if (column < line.length) {
  11554. swap = line.charAt(column) + line.charAt(column-1);
  11555. range = new Range(cursor.row, column-1, cursor.row, column+1);
  11556. }
  11557. else {
  11558. swap = line.charAt(column-1) + line.charAt(column-2);
  11559. range = new Range(cursor.row, column-2, cursor.row, column);
  11560. }
  11561. this.session.replace(range, swap);
  11562. this.session.selection.moveToPosition(range.end);
  11563. };
  11564. this.toLowerCase = function() {
  11565. var originalRange = this.getSelectionRange();
  11566. if (this.selection.isEmpty()) {
  11567. this.selection.selectWord();
  11568. }
  11569. var range = this.getSelectionRange();
  11570. var text = this.session.getTextRange(range);
  11571. this.session.replace(range, text.toLowerCase());
  11572. this.selection.setSelectionRange(originalRange);
  11573. };
  11574. this.toUpperCase = function() {
  11575. var originalRange = this.getSelectionRange();
  11576. if (this.selection.isEmpty()) {
  11577. this.selection.selectWord();
  11578. }
  11579. var range = this.getSelectionRange();
  11580. var text = this.session.getTextRange(range);
  11581. this.session.replace(range, text.toUpperCase());
  11582. this.selection.setSelectionRange(originalRange);
  11583. };
  11584. this.indent = function() {
  11585. var session = this.session;
  11586. var range = this.getSelectionRange();
  11587. if (range.start.row < range.end.row) {
  11588. var rows = this.$getSelectedRows();
  11589. session.indentRows(rows.first, rows.last, "\t");
  11590. return;
  11591. } else if (range.start.column < range.end.column) {
  11592. var text = session.getTextRange(range);
  11593. if (!/^\s+$/.test(text)) {
  11594. var rows = this.$getSelectedRows();
  11595. session.indentRows(rows.first, rows.last, "\t");
  11596. return;
  11597. }
  11598. }
  11599. var line = session.getLine(range.start.row);
  11600. var position = range.start;
  11601. var size = session.getTabSize();
  11602. var column = session.documentToScreenColumn(position.row, position.column);
  11603. if (this.session.getUseSoftTabs()) {
  11604. var count = (size - column % size);
  11605. var indentString = lang.stringRepeat(" ", count);
  11606. } else {
  11607. var count = column % size;
  11608. while (line[range.start.column - 1] == " " && count) {
  11609. range.start.column--;
  11610. count--;
  11611. }
  11612. this.selection.setSelectionRange(range);
  11613. indentString = "\t";
  11614. }
  11615. return this.insert(indentString);
  11616. };
  11617. this.blockIndent = function() {
  11618. var rows = this.$getSelectedRows();
  11619. this.session.indentRows(rows.first, rows.last, "\t");
  11620. };
  11621. this.blockOutdent = function() {
  11622. var selection = this.session.getSelection();
  11623. this.session.outdentRows(selection.getRange());
  11624. };
  11625. this.sortLines = function() {
  11626. var rows = this.$getSelectedRows();
  11627. var session = this.session;
  11628. var lines = [];
  11629. for (i = rows.first; i <= rows.last; i++)
  11630. lines.push(session.getLine(i));
  11631. lines.sort(function(a, b) {
  11632. if (a.toLowerCase() < b.toLowerCase()) return -1;
  11633. if (a.toLowerCase() > b.toLowerCase()) return 1;
  11634. return 0;
  11635. });
  11636. var deleteRange = new Range(0, 0, 0, 0);
  11637. for (var i = rows.first; i <= rows.last; i++) {
  11638. var line = session.getLine(i);
  11639. deleteRange.start.row = i;
  11640. deleteRange.end.row = i;
  11641. deleteRange.end.column = line.length;
  11642. session.replace(deleteRange, lines[i-rows.first]);
  11643. }
  11644. };
  11645. this.toggleCommentLines = function() {
  11646. var state = this.session.getState(this.getCursorPosition().row);
  11647. var rows = this.$getSelectedRows();
  11648. this.session.getMode().toggleCommentLines(state, this.session, rows.first, rows.last);
  11649. };
  11650. this.toggleBlockComment = function() {
  11651. var cursor = this.getCursorPosition();
  11652. var state = this.session.getState(cursor.row);
  11653. var range = this.getSelectionRange();
  11654. this.session.getMode().toggleBlockComment(state, this.session, range, cursor);
  11655. };
  11656. this.getNumberAt = function(row, column) {
  11657. var _numberRx = /[\-]?[0-9]+(?:\.[0-9]+)?/g;
  11658. _numberRx.lastIndex = 0;
  11659. var s = this.session.getLine(row);
  11660. while (_numberRx.lastIndex < column) {
  11661. var m = _numberRx.exec(s);
  11662. if(m.index <= column && m.index+m[0].length >= column){
  11663. var number = {
  11664. value: m[0],
  11665. start: m.index,
  11666. end: m.index+m[0].length
  11667. };
  11668. return number;
  11669. }
  11670. }
  11671. return null;
  11672. };
  11673. this.modifyNumber = function(amount) {
  11674. var row = this.selection.getCursor().row;
  11675. var column = this.selection.getCursor().column;
  11676. var charRange = new Range(row, column-1, row, column);
  11677. var c = this.session.getTextRange(charRange);
  11678. if (!isNaN(parseFloat(c)) && isFinite(c)) {
  11679. var nr = this.getNumberAt(row, column);
  11680. if (nr) {
  11681. var fp = nr.value.indexOf(".") >= 0 ? nr.start + nr.value.indexOf(".") + 1 : nr.end;
  11682. var decimals = nr.start + nr.value.length - fp;
  11683. var t = parseFloat(nr.value);
  11684. t *= Math.pow(10, decimals);
  11685. if(fp !== nr.end && column < fp){
  11686. amount *= Math.pow(10, nr.end - column - 1);
  11687. } else {
  11688. amount *= Math.pow(10, nr.end - column);
  11689. }
  11690. t += amount;
  11691. t /= Math.pow(10, decimals);
  11692. var nnr = t.toFixed(decimals);
  11693. var replaceRange = new Range(row, nr.start, row, nr.end);
  11694. this.session.replace(replaceRange, nnr);
  11695. this.moveCursorTo(row, Math.max(nr.start +1, column + nnr.length - nr.value.length));
  11696. }
  11697. }
  11698. };
  11699. this.removeLines = function() {
  11700. var rows = this.$getSelectedRows();
  11701. this.session.removeFullLines(rows.first, rows.last);
  11702. this.clearSelection();
  11703. };
  11704. this.duplicateSelection = function() {
  11705. var sel = this.selection;
  11706. var doc = this.session;
  11707. var range = sel.getRange();
  11708. var reverse = sel.isBackwards();
  11709. if (range.isEmpty()) {
  11710. var row = range.start.row;
  11711. doc.duplicateLines(row, row);
  11712. } else {
  11713. var point = reverse ? range.start : range.end;
  11714. var endPoint = doc.insert(point, doc.getTextRange(range), false);
  11715. range.start = point;
  11716. range.end = endPoint;
  11717. sel.setSelectionRange(range, reverse);
  11718. }
  11719. };
  11720. this.moveLinesDown = function() {
  11721. this.$moveLines(1, false);
  11722. };
  11723. this.moveLinesUp = function() {
  11724. this.$moveLines(-1, false);
  11725. };
  11726. this.moveText = function(range, toPosition, copy) {
  11727. return this.session.moveText(range, toPosition, copy);
  11728. };
  11729. this.copyLinesUp = function() {
  11730. this.$moveLines(-1, true);
  11731. };
  11732. this.copyLinesDown = function() {
  11733. this.$moveLines(1, true);
  11734. };
  11735. this.$moveLines = function(dir, copy) {
  11736. var rows, moved;
  11737. var selection = this.selection;
  11738. if (!selection.inMultiSelectMode || this.inVirtualSelectionMode) {
  11739. var range = selection.toOrientedRange();
  11740. rows = this.$getSelectedRows(range);
  11741. moved = this.session.$moveLines(rows.first, rows.last, copy ? 0 : dir);
  11742. if (copy && dir == -1) moved = 0;
  11743. range.moveBy(moved, 0);
  11744. selection.fromOrientedRange(range);
  11745. } else {
  11746. var ranges = selection.rangeList.ranges;
  11747. selection.rangeList.detach(this.session);
  11748. this.inVirtualSelectionMode = true;
  11749. var diff = 0;
  11750. var totalDiff = 0;
  11751. var l = ranges.length;
  11752. for (var i = 0; i < l; i++) {
  11753. var rangeIndex = i;
  11754. ranges[i].moveBy(diff, 0);
  11755. rows = this.$getSelectedRows(ranges[i]);
  11756. var first = rows.first;
  11757. var last = rows.last;
  11758. while (++i < l) {
  11759. if (totalDiff) ranges[i].moveBy(totalDiff, 0);
  11760. var subRows = this.$getSelectedRows(ranges[i]);
  11761. if (copy && subRows.first != last)
  11762. break;
  11763. else if (!copy && subRows.first > last + 1)
  11764. break;
  11765. last = subRows.last;
  11766. }
  11767. i--;
  11768. diff = this.session.$moveLines(first, last, copy ? 0 : dir);
  11769. if (copy && dir == -1) rangeIndex = i + 1;
  11770. while (rangeIndex <= i) {
  11771. ranges[rangeIndex].moveBy(diff, 0);
  11772. rangeIndex++;
  11773. }
  11774. if (!copy) diff = 0;
  11775. totalDiff += diff;
  11776. }
  11777. selection.fromOrientedRange(selection.ranges[0]);
  11778. selection.rangeList.attach(this.session);
  11779. this.inVirtualSelectionMode = false;
  11780. }
  11781. };
  11782. this.$getSelectedRows = function(range) {
  11783. range = (range || this.getSelectionRange()).collapseRows();
  11784. return {
  11785. first: this.session.getRowFoldStart(range.start.row),
  11786. last: this.session.getRowFoldEnd(range.end.row)
  11787. };
  11788. };
  11789. this.onCompositionStart = function(text) {
  11790. this.renderer.showComposition(this.getCursorPosition());
  11791. };
  11792. this.onCompositionUpdate = function(text) {
  11793. this.renderer.setCompositionText(text);
  11794. };
  11795. this.onCompositionEnd = function() {
  11796. this.renderer.hideComposition();
  11797. };
  11798. this.getFirstVisibleRow = function() {
  11799. return this.renderer.getFirstVisibleRow();
  11800. };
  11801. this.getLastVisibleRow = function() {
  11802. return this.renderer.getLastVisibleRow();
  11803. };
  11804. this.isRowVisible = function(row) {
  11805. return (row >= this.getFirstVisibleRow() && row <= this.getLastVisibleRow());
  11806. };
  11807. this.isRowFullyVisible = function(row) {
  11808. return (row >= this.renderer.getFirstFullyVisibleRow() && row <= this.renderer.getLastFullyVisibleRow());
  11809. };
  11810. this.$getVisibleRowCount = function() {
  11811. return this.renderer.getScrollBottomRow() - this.renderer.getScrollTopRow() + 1;
  11812. };
  11813. this.$moveByPage = function(dir, select) {
  11814. var renderer = this.renderer;
  11815. var config = this.renderer.layerConfig;
  11816. var rows = dir * Math.floor(config.height / config.lineHeight);
  11817. this.$blockScrolling++;
  11818. if (select === true) {
  11819. this.selection.$moveSelection(function(){
  11820. this.moveCursorBy(rows, 0);
  11821. });
  11822. } else if (select === false) {
  11823. this.selection.moveCursorBy(rows, 0);
  11824. this.selection.clearSelection();
  11825. }
  11826. this.$blockScrolling--;
  11827. var scrollTop = renderer.scrollTop;
  11828. renderer.scrollBy(0, rows * config.lineHeight);
  11829. if (select != null)
  11830. renderer.scrollCursorIntoView(null, 0.5);
  11831. renderer.animateScrolling(scrollTop);
  11832. };
  11833. this.selectPageDown = function() {
  11834. this.$moveByPage(1, true);
  11835. };
  11836. this.selectPageUp = function() {
  11837. this.$moveByPage(-1, true);
  11838. };
  11839. this.gotoPageDown = function() {
  11840. this.$moveByPage(1, false);
  11841. };
  11842. this.gotoPageUp = function() {
  11843. this.$moveByPage(-1, false);
  11844. };
  11845. this.scrollPageDown = function() {
  11846. this.$moveByPage(1);
  11847. };
  11848. this.scrollPageUp = function() {
  11849. this.$moveByPage(-1);
  11850. };
  11851. this.scrollToRow = function(row) {
  11852. this.renderer.scrollToRow(row);
  11853. };
  11854. this.scrollToLine = function(line, center, animate, callback) {
  11855. this.renderer.scrollToLine(line, center, animate, callback);
  11856. };
  11857. this.centerSelection = function() {
  11858. var range = this.getSelectionRange();
  11859. var pos = {
  11860. row: Math.floor(range.start.row + (range.end.row - range.start.row) / 2),
  11861. column: Math.floor(range.start.column + (range.end.column - range.start.column) / 2)
  11862. };
  11863. this.renderer.alignCursor(pos, 0.5);
  11864. };
  11865. this.getCursorPosition = function() {
  11866. return this.selection.getCursor();
  11867. };
  11868. this.getCursorPositionScreen = function() {
  11869. return this.session.documentToScreenPosition(this.getCursorPosition());
  11870. };
  11871. this.getSelectionRange = function() {
  11872. return this.selection.getRange();
  11873. };
  11874. this.selectAll = function() {
  11875. this.$blockScrolling += 1;
  11876. this.selection.selectAll();
  11877. this.$blockScrolling -= 1;
  11878. };
  11879. this.clearSelection = function() {
  11880. this.selection.clearSelection();
  11881. };
  11882. this.moveCursorTo = function(row, column) {
  11883. this.selection.moveCursorTo(row, column);
  11884. };
  11885. this.moveCursorToPosition = function(pos) {
  11886. this.selection.moveCursorToPosition(pos);
  11887. };
  11888. this.jumpToMatching = function(select, expand) {
  11889. var cursor = this.getCursorPosition();
  11890. var iterator = new TokenIterator(this.session, cursor.row, cursor.column);
  11891. var prevToken = iterator.getCurrentToken();
  11892. var token = prevToken || iterator.stepForward();
  11893. if (!token) return;
  11894. var matchType;
  11895. var found = false;
  11896. var depth = {};
  11897. var i = cursor.column - token.start;
  11898. var bracketType;
  11899. var brackets = {
  11900. ")": "(",
  11901. "(": "(",
  11902. "]": "[",
  11903. "[": "[",
  11904. "{": "{",
  11905. "}": "{"
  11906. };
  11907. do {
  11908. if (token.value.match(/[{}()\[\]]/g)) {
  11909. for (; i < token.value.length && !found; i++) {
  11910. if (!brackets[token.value[i]]) {
  11911. continue;
  11912. }
  11913. bracketType = brackets[token.value[i]] + '.' + token.type.replace("rparen", "lparen");
  11914. if (isNaN(depth[bracketType])) {
  11915. depth[bracketType] = 0;
  11916. }
  11917. switch (token.value[i]) {
  11918. case '(':
  11919. case '[':
  11920. case '{':
  11921. depth[bracketType]++;
  11922. break;
  11923. case ')':
  11924. case ']':
  11925. case '}':
  11926. depth[bracketType]--;
  11927. if (depth[bracketType] === -1) {
  11928. matchType = 'bracket';
  11929. found = true;
  11930. }
  11931. break;
  11932. }
  11933. }
  11934. }
  11935. else if (token && token.type.indexOf('tag-name') !== -1) {
  11936. if (isNaN(depth[token.value])) {
  11937. depth[token.value] = 0;
  11938. }
  11939. if (prevToken.value === '<') {
  11940. depth[token.value]++;
  11941. }
  11942. else if (prevToken.value === '</') {
  11943. depth[token.value]--;
  11944. }
  11945. if (depth[token.value] === -1) {
  11946. matchType = 'tag';
  11947. found = true;
  11948. }
  11949. }
  11950. if (!found) {
  11951. prevToken = token;
  11952. token = iterator.stepForward();
  11953. i = 0;
  11954. }
  11955. } while (token && !found);
  11956. if (!matchType)
  11957. return;
  11958. var range, pos;
  11959. if (matchType === 'bracket') {
  11960. range = this.session.getBracketRange(cursor);
  11961. if (!range) {
  11962. range = new Range(
  11963. iterator.getCurrentTokenRow(),
  11964. iterator.getCurrentTokenColumn() + i - 1,
  11965. iterator.getCurrentTokenRow(),
  11966. iterator.getCurrentTokenColumn() + i - 1
  11967. );
  11968. pos = range.start;
  11969. if (expand || pos.row === cursor.row && Math.abs(pos.column - cursor.column) < 2)
  11970. range = this.session.getBracketRange(pos);
  11971. }
  11972. }
  11973. else if (matchType === 'tag') {
  11974. if (token && token.type.indexOf('tag-name') !== -1)
  11975. var tag = token.value;
  11976. else
  11977. return;
  11978. range = new Range(
  11979. iterator.getCurrentTokenRow(),
  11980. iterator.getCurrentTokenColumn() - 2,
  11981. iterator.getCurrentTokenRow(),
  11982. iterator.getCurrentTokenColumn() - 2
  11983. );
  11984. if (range.compare(cursor.row, cursor.column) === 0) {
  11985. found = false;
  11986. do {
  11987. token = prevToken;
  11988. prevToken = iterator.stepBackward();
  11989. if (prevToken) {
  11990. if (prevToken.type.indexOf('tag-close') !== -1) {
  11991. range.setEnd(iterator.getCurrentTokenRow(), iterator.getCurrentTokenColumn() + 1);
  11992. }
  11993. if (token.value === tag && token.type.indexOf('tag-name') !== -1) {
  11994. if (prevToken.value === '<') {
  11995. depth[tag]++;
  11996. }
  11997. else if (prevToken.value === '</') {
  11998. depth[tag]--;
  11999. }
  12000. if (depth[tag] === 0)
  12001. found = true;
  12002. }
  12003. }
  12004. } while (prevToken && !found);
  12005. }
  12006. if (token && token.type.indexOf('tag-name')) {
  12007. pos = range.start;
  12008. if (pos.row == cursor.row && Math.abs(pos.column - cursor.column) < 2)
  12009. pos = range.end;
  12010. }
  12011. }
  12012. pos = range && range.cursor || pos;
  12013. if (pos) {
  12014. if (select) {
  12015. if (range && expand) {
  12016. this.selection.setRange(range);
  12017. } else if (range && range.isEqual(this.getSelectionRange())) {
  12018. this.clearSelection();
  12019. } else {
  12020. this.selection.selectTo(pos.row, pos.column);
  12021. }
  12022. } else {
  12023. this.selection.moveTo(pos.row, pos.column);
  12024. }
  12025. }
  12026. };
  12027. this.gotoLine = function(lineNumber, column, animate) {
  12028. this.selection.clearSelection();
  12029. this.session.unfold({row: lineNumber - 1, column: column || 0});
  12030. this.$blockScrolling += 1;
  12031. this.exitMultiSelectMode && this.exitMultiSelectMode();
  12032. this.moveCursorTo(lineNumber - 1, column || 0);
  12033. this.$blockScrolling -= 1;
  12034. if (!this.isRowFullyVisible(lineNumber - 1))
  12035. this.scrollToLine(lineNumber - 1, true, animate);
  12036. };
  12037. this.navigateTo = function(row, column) {
  12038. this.selection.moveTo(row, column);
  12039. };
  12040. this.navigateUp = function(times) {
  12041. if (this.selection.isMultiLine() && !this.selection.isBackwards()) {
  12042. var selectionStart = this.selection.anchor.getPosition();
  12043. return this.moveCursorToPosition(selectionStart);
  12044. }
  12045. this.selection.clearSelection();
  12046. this.selection.moveCursorBy(-times || -1, 0);
  12047. };
  12048. this.navigateDown = function(times) {
  12049. if (this.selection.isMultiLine() && this.selection.isBackwards()) {
  12050. var selectionEnd = this.selection.anchor.getPosition();
  12051. return this.moveCursorToPosition(selectionEnd);
  12052. }
  12053. this.selection.clearSelection();
  12054. this.selection.moveCursorBy(times || 1, 0);
  12055. };
  12056. this.navigateLeft = function(times) {
  12057. if (!this.selection.isEmpty()) {
  12058. var selectionStart = this.getSelectionRange().start;
  12059. this.moveCursorToPosition(selectionStart);
  12060. }
  12061. else {
  12062. times = times || 1;
  12063. while (times--) {
  12064. this.selection.moveCursorLeft();
  12065. }
  12066. }
  12067. this.clearSelection();
  12068. };
  12069. this.navigateRight = function(times) {
  12070. if (!this.selection.isEmpty()) {
  12071. var selectionEnd = this.getSelectionRange().end;
  12072. this.moveCursorToPosition(selectionEnd);
  12073. }
  12074. else {
  12075. times = times || 1;
  12076. while (times--) {
  12077. this.selection.moveCursorRight();
  12078. }
  12079. }
  12080. this.clearSelection();
  12081. };
  12082. this.navigateLineStart = function() {
  12083. this.selection.moveCursorLineStart();
  12084. this.clearSelection();
  12085. };
  12086. this.navigateLineEnd = function() {
  12087. this.selection.moveCursorLineEnd();
  12088. this.clearSelection();
  12089. };
  12090. this.navigateFileEnd = function() {
  12091. this.selection.moveCursorFileEnd();
  12092. this.clearSelection();
  12093. };
  12094. this.navigateFileStart = function() {
  12095. this.selection.moveCursorFileStart();
  12096. this.clearSelection();
  12097. };
  12098. this.navigateWordRight = function() {
  12099. this.selection.moveCursorWordRight();
  12100. this.clearSelection();
  12101. };
  12102. this.navigateWordLeft = function() {
  12103. this.selection.moveCursorWordLeft();
  12104. this.clearSelection();
  12105. };
  12106. this.replace = function(replacement, options) {
  12107. if (options)
  12108. this.$search.set(options);
  12109. var range = this.$search.find(this.session);
  12110. var replaced = 0;
  12111. if (!range)
  12112. return replaced;
  12113. if (this.$tryReplace(range, replacement)) {
  12114. replaced = 1;
  12115. }
  12116. if (range !== null) {
  12117. this.selection.setSelectionRange(range);
  12118. this.renderer.scrollSelectionIntoView(range.start, range.end);
  12119. }
  12120. return replaced;
  12121. };
  12122. this.replaceAll = function(replacement, options) {
  12123. if (options) {
  12124. this.$search.set(options);
  12125. }
  12126. var ranges = this.$search.findAll(this.session);
  12127. var replaced = 0;
  12128. if (!ranges.length)
  12129. return replaced;
  12130. this.$blockScrolling += 1;
  12131. var selection = this.getSelectionRange();
  12132. this.selection.moveTo(0, 0);
  12133. for (var i = ranges.length - 1; i >= 0; --i) {
  12134. if(this.$tryReplace(ranges[i], replacement)) {
  12135. replaced++;
  12136. }
  12137. }
  12138. this.selection.setSelectionRange(selection);
  12139. this.$blockScrolling -= 1;
  12140. return replaced;
  12141. };
  12142. this.$tryReplace = function(range, replacement) {
  12143. var input = this.session.getTextRange(range);
  12144. replacement = this.$search.replace(input, replacement);
  12145. if (replacement !== null) {
  12146. range.end = this.session.replace(range, replacement);
  12147. return range;
  12148. } else {
  12149. return null;
  12150. }
  12151. };
  12152. this.getLastSearchOptions = function() {
  12153. return this.$search.getOptions();
  12154. };
  12155. this.find = function(needle, options, animate) {
  12156. if (!options)
  12157. options = {};
  12158. if (typeof needle == "string" || needle instanceof RegExp)
  12159. options.needle = needle;
  12160. else if (typeof needle == "object")
  12161. oop.mixin(options, needle);
  12162. var range = this.selection.getRange();
  12163. if (options.needle == null) {
  12164. needle = this.session.getTextRange(range)
  12165. || this.$search.$options.needle;
  12166. if (!needle) {
  12167. range = this.session.getWordRange(range.start.row, range.start.column);
  12168. needle = this.session.getTextRange(range);
  12169. }
  12170. this.$search.set({needle: needle});
  12171. }
  12172. this.$search.set(options);
  12173. if (!options.start)
  12174. this.$search.set({start: range});
  12175. var newRange = this.$search.find(this.session);
  12176. if (options.preventScroll)
  12177. return newRange;
  12178. if (newRange) {
  12179. this.revealRange(newRange, animate);
  12180. return newRange;
  12181. }
  12182. if (options.backwards)
  12183. range.start = range.end;
  12184. else
  12185. range.end = range.start;
  12186. this.selection.setRange(range);
  12187. };
  12188. this.findNext = function(options, animate) {
  12189. this.find({skipCurrent: true, backwards: false}, options, animate);
  12190. };
  12191. this.findPrevious = function(options, animate) {
  12192. this.find(options, {skipCurrent: true, backwards: true}, animate);
  12193. };
  12194. this.revealRange = function(range, animate) {
  12195. this.$blockScrolling += 1;
  12196. this.session.unfold(range);
  12197. this.selection.setSelectionRange(range);
  12198. this.$blockScrolling -= 1;
  12199. var scrollTop = this.renderer.scrollTop;
  12200. this.renderer.scrollSelectionIntoView(range.start, range.end, 0.5);
  12201. if (animate !== false)
  12202. this.renderer.animateScrolling(scrollTop);
  12203. };
  12204. this.undo = function() {
  12205. this.$blockScrolling++;
  12206. this.session.getUndoManager().undo();
  12207. this.$blockScrolling--;
  12208. this.renderer.scrollCursorIntoView(null, 0.5);
  12209. };
  12210. this.redo = function() {
  12211. this.$blockScrolling++;
  12212. this.session.getUndoManager().redo();
  12213. this.$blockScrolling--;
  12214. this.renderer.scrollCursorIntoView(null, 0.5);
  12215. };
  12216. this.destroy = function() {
  12217. this.renderer.destroy();
  12218. this._signal("destroy", this);
  12219. if (this.session) {
  12220. this.session.destroy();
  12221. }
  12222. };
  12223. this.setAutoScrollEditorIntoView = function(enable) {
  12224. if (!enable)
  12225. return;
  12226. var rect;
  12227. var self = this;
  12228. var shouldScroll = false;
  12229. if (!this.$scrollAnchor)
  12230. this.$scrollAnchor = document.createElement("div");
  12231. var scrollAnchor = this.$scrollAnchor;
  12232. scrollAnchor.style.cssText = "position:absolute";
  12233. this.container.insertBefore(scrollAnchor, this.container.firstChild);
  12234. var onChangeSelection = this.on("changeSelection", function() {
  12235. shouldScroll = true;
  12236. });
  12237. var onBeforeRender = this.renderer.on("beforeRender", function() {
  12238. if (shouldScroll)
  12239. rect = self.renderer.container.getBoundingClientRect();
  12240. });
  12241. var onAfterRender = this.renderer.on("afterRender", function() {
  12242. if (shouldScroll && rect && (self.isFocused()
  12243. || self.searchBox && self.searchBox.isFocused())
  12244. ) {
  12245. var renderer = self.renderer;
  12246. var pos = renderer.$cursorLayer.$pixelPos;
  12247. var config = renderer.layerConfig;
  12248. var top = pos.top - config.offset;
  12249. if (pos.top >= 0 && top + rect.top < 0) {
  12250. shouldScroll = true;
  12251. } else if (pos.top < config.height &&
  12252. pos.top + rect.top + config.lineHeight > window.innerHeight) {
  12253. shouldScroll = false;
  12254. } else {
  12255. shouldScroll = null;
  12256. }
  12257. if (shouldScroll != null) {
  12258. scrollAnchor.style.top = top + "px";
  12259. scrollAnchor.style.left = pos.left + "px";
  12260. scrollAnchor.style.height = config.lineHeight + "px";
  12261. scrollAnchor.scrollIntoView(shouldScroll);
  12262. }
  12263. shouldScroll = rect = null;
  12264. }
  12265. });
  12266. this.setAutoScrollEditorIntoView = function(enable) {
  12267. if (enable)
  12268. return;
  12269. delete this.setAutoScrollEditorIntoView;
  12270. this.off("changeSelection", onChangeSelection);
  12271. this.renderer.off("afterRender", onAfterRender);
  12272. this.renderer.off("beforeRender", onBeforeRender);
  12273. };
  12274. };
  12275. this.$resetCursorStyle = function() {
  12276. var style = this.$cursorStyle || "ace";
  12277. var cursorLayer = this.renderer.$cursorLayer;
  12278. if (!cursorLayer)
  12279. return;
  12280. cursorLayer.setSmoothBlinking(/smooth/.test(style));
  12281. cursorLayer.isBlinking = !this.$readOnly && style != "wide";
  12282. dom.setCssClass(cursorLayer.element, "ace_slim-cursors", /slim/.test(style));
  12283. };
  12284. }).call(Editor.prototype);
  12285. config.defineOptions(Editor.prototype, "editor", {
  12286. selectionStyle: {
  12287. set: function(style) {
  12288. this.onSelectionChange();
  12289. this._signal("changeSelectionStyle", {data: style});
  12290. },
  12291. initialValue: "line"
  12292. },
  12293. highlightActiveLine: {
  12294. set: function() {this.$updateHighlightActiveLine();},
  12295. initialValue: true
  12296. },
  12297. highlightSelectedWord: {
  12298. set: function(shouldHighlight) {this.$onSelectionChange();},
  12299. initialValue: true
  12300. },
  12301. readOnly: {
  12302. set: function(readOnly) {
  12303. this.$resetCursorStyle();
  12304. },
  12305. initialValue: false
  12306. },
  12307. cursorStyle: {
  12308. set: function(val) { this.$resetCursorStyle(); },
  12309. values: ["ace", "slim", "smooth", "wide"],
  12310. initialValue: "ace"
  12311. },
  12312. mergeUndoDeltas: {
  12313. values: [false, true, "always"],
  12314. initialValue: true
  12315. },
  12316. behavioursEnabled: {initialValue: true},
  12317. wrapBehavioursEnabled: {initialValue: true},
  12318. autoScrollEditorIntoView: {
  12319. set: function(val) {this.setAutoScrollEditorIntoView(val)}
  12320. },
  12321. keyboardHandler: {
  12322. set: function(val) { this.setKeyboardHandler(val); },
  12323. get: function() { return this.keybindingId; },
  12324. handlesSet: true
  12325. },
  12326. hScrollBarAlwaysVisible: "renderer",
  12327. vScrollBarAlwaysVisible: "renderer",
  12328. highlightGutterLine: "renderer",
  12329. animatedScroll: "renderer",
  12330. showInvisibles: "renderer",
  12331. showPrintMargin: "renderer",
  12332. printMarginColumn: "renderer",
  12333. printMargin: "renderer",
  12334. fadeFoldWidgets: "renderer",
  12335. showFoldWidgets: "renderer",
  12336. showLineNumbers: "renderer",
  12337. showGutter: "renderer",
  12338. displayIndentGuides: "renderer",
  12339. fontSize: "renderer",
  12340. fontFamily: "renderer",
  12341. maxLines: "renderer",
  12342. minLines: "renderer",
  12343. scrollPastEnd: "renderer",
  12344. fixedWidthGutter: "renderer",
  12345. theme: "renderer",
  12346. scrollSpeed: "$mouseHandler",
  12347. dragDelay: "$mouseHandler",
  12348. dragEnabled: "$mouseHandler",
  12349. focusTimout: "$mouseHandler",
  12350. tooltipFollowsMouse: "$mouseHandler",
  12351. firstLineNumber: "session",
  12352. overwrite: "session",
  12353. newLineMode: "session",
  12354. useWorker: "session",
  12355. useSoftTabs: "session",
  12356. tabSize: "session",
  12357. wrap: "session",
  12358. indentedSoftWrap: "session",
  12359. foldStyle: "session",
  12360. mode: "session"
  12361. });
  12362. exports.Editor = Editor;
  12363. });
  12364. define("ace/undomanager",["require","exports","module"], function(require, exports, module) {
  12365. "use strict";
  12366. var UndoManager = function() {
  12367. this.reset();
  12368. };
  12369. (function() {
  12370. this.execute = function(options) {
  12371. var deltaSets = options.args[0];
  12372. this.$doc = options.args[1];
  12373. if (options.merge && this.hasUndo()){
  12374. this.dirtyCounter--;
  12375. deltaSets = this.$undoStack.pop().concat(deltaSets);
  12376. }
  12377. this.$undoStack.push(deltaSets);
  12378. this.$redoStack = [];
  12379. if (this.dirtyCounter < 0) {
  12380. this.dirtyCounter = NaN;
  12381. }
  12382. this.dirtyCounter++;
  12383. };
  12384. this.undo = function(dontSelect) {
  12385. var deltaSets = this.$undoStack.pop();
  12386. var undoSelectionRange = null;
  12387. if (deltaSets) {
  12388. undoSelectionRange = this.$doc.undoChanges(deltaSets, dontSelect);
  12389. this.$redoStack.push(deltaSets);
  12390. this.dirtyCounter--;
  12391. }
  12392. return undoSelectionRange;
  12393. };
  12394. this.redo = function(dontSelect) {
  12395. var deltaSets = this.$redoStack.pop();
  12396. var redoSelectionRange = null;
  12397. if (deltaSets) {
  12398. redoSelectionRange =
  12399. this.$doc.redoChanges(this.$deserializeDeltas(deltaSets), dontSelect);
  12400. this.$undoStack.push(deltaSets);
  12401. this.dirtyCounter++;
  12402. }
  12403. return redoSelectionRange;
  12404. };
  12405. this.reset = function() {
  12406. this.$undoStack = [];
  12407. this.$redoStack = [];
  12408. this.dirtyCounter = 0;
  12409. };
  12410. this.hasUndo = function() {
  12411. return this.$undoStack.length > 0;
  12412. };
  12413. this.hasRedo = function() {
  12414. return this.$redoStack.length > 0;
  12415. };
  12416. this.markClean = function() {
  12417. this.dirtyCounter = 0;
  12418. };
  12419. this.isClean = function() {
  12420. return this.dirtyCounter === 0;
  12421. };
  12422. this.$serializeDeltas = function(deltaSets) {
  12423. return cloneDeltaSetsObj(deltaSets, $serializeDelta);
  12424. };
  12425. this.$deserializeDeltas = function(deltaSets) {
  12426. return cloneDeltaSetsObj(deltaSets, $deserializeDelta);
  12427. };
  12428. function $serializeDelta(delta){
  12429. return {
  12430. action: delta.action,
  12431. start: delta.start,
  12432. end: delta.end,
  12433. lines: delta.lines.length == 1 ? null : delta.lines,
  12434. text: delta.lines.length == 1 ? delta.lines[0] : null
  12435. };
  12436. }
  12437. function $deserializeDelta(delta) {
  12438. return {
  12439. action: delta.action,
  12440. start: delta.start,
  12441. end: delta.end,
  12442. lines: delta.lines || [delta.text]
  12443. };
  12444. }
  12445. function cloneDeltaSetsObj(deltaSets_old, fnGetModifiedDelta) {
  12446. var deltaSets_new = new Array(deltaSets_old.length);
  12447. for (var i = 0; i < deltaSets_old.length; i++) {
  12448. var deltaSet_old = deltaSets_old[i];
  12449. var deltaSet_new = { group: deltaSet_old.group, deltas: new Array(deltaSet_old.length)};
  12450. for (var j = 0; j < deltaSet_old.deltas.length; j++) {
  12451. var delta_old = deltaSet_old.deltas[j];
  12452. deltaSet_new.deltas[j] = fnGetModifiedDelta(delta_old);
  12453. }
  12454. deltaSets_new[i] = deltaSet_new;
  12455. }
  12456. return deltaSets_new;
  12457. }
  12458. }).call(UndoManager.prototype);
  12459. exports.UndoManager = UndoManager;
  12460. });
  12461. define("ace/layer/gutter",["require","exports","module","ace/lib/dom","ace/lib/oop","ace/lib/lang","ace/lib/event_emitter"], function(require, exports, module) {
  12462. "use strict";
  12463. var dom = require("../lib/dom");
  12464. var oop = require("../lib/oop");
  12465. var lang = require("../lib/lang");
  12466. var EventEmitter = require("../lib/event_emitter").EventEmitter;
  12467. var Gutter = function(parentEl) {
  12468. this.element = dom.createElement("div");
  12469. this.element.className = "ace_layer ace_gutter-layer";
  12470. parentEl.appendChild(this.element);
  12471. this.setShowFoldWidgets(this.$showFoldWidgets);
  12472. this.gutterWidth = 0;
  12473. this.$annotations = [];
  12474. this.$updateAnnotations = this.$updateAnnotations.bind(this);
  12475. this.$cells = [];
  12476. };
  12477. (function() {
  12478. oop.implement(this, EventEmitter);
  12479. this.setSession = function(session) {
  12480. if (this.session)
  12481. this.session.removeEventListener("change", this.$updateAnnotations);
  12482. this.session = session;
  12483. if (session)
  12484. session.on("change", this.$updateAnnotations);
  12485. };
  12486. this.addGutterDecoration = function(row, className){
  12487. if (window.console)
  12488. console.warn && console.warn("deprecated use session.addGutterDecoration");
  12489. this.session.addGutterDecoration(row, className);
  12490. };
  12491. this.removeGutterDecoration = function(row, className){
  12492. if (window.console)
  12493. console.warn && console.warn("deprecated use session.removeGutterDecoration");
  12494. this.session.removeGutterDecoration(row, className);
  12495. };
  12496. this.setAnnotations = function(annotations) {
  12497. this.$annotations = [];
  12498. for (var i = 0; i < annotations.length; i++) {
  12499. var annotation = annotations[i];
  12500. var row = annotation.row;
  12501. var rowInfo = this.$annotations[row];
  12502. if (!rowInfo)
  12503. rowInfo = this.$annotations[row] = {text: []};
  12504. var annoText = annotation.text;
  12505. annoText = annoText ? lang.escapeHTML(annoText) : annotation.html || "";
  12506. if (rowInfo.text.indexOf(annoText) === -1)
  12507. rowInfo.text.push(annoText);
  12508. var type = annotation.type;
  12509. if (type == "error")
  12510. rowInfo.className = " ace_error";
  12511. else if (type == "warning" && rowInfo.className != " ace_error")
  12512. rowInfo.className = " ace_warning";
  12513. else if (type == "info" && (!rowInfo.className))
  12514. rowInfo.className = " ace_info";
  12515. }
  12516. };
  12517. this.$updateAnnotations = function (delta) {
  12518. if (!this.$annotations.length)
  12519. return;
  12520. var firstRow = delta.start.row;
  12521. var len = delta.end.row - firstRow;
  12522. if (len === 0) {
  12523. } else if (delta.action == 'remove') {
  12524. this.$annotations.splice(firstRow, len + 1, null);
  12525. } else {
  12526. var args = new Array(len + 1);
  12527. args.unshift(firstRow, 1);
  12528. this.$annotations.splice.apply(this.$annotations, args);
  12529. }
  12530. };
  12531. this.update = function(config) {
  12532. var session = this.session;
  12533. var firstRow = config.firstRow;
  12534. var lastRow = Math.min(config.lastRow + config.gutterOffset, // needed to compensate for hor scollbar
  12535. session.getLength() - 1);
  12536. var fold = session.getNextFoldLine(firstRow);
  12537. var foldStart = fold ? fold.start.row : Infinity;
  12538. var foldWidgets = this.$showFoldWidgets && session.foldWidgets;
  12539. var breakpoints = session.$breakpoints;
  12540. var decorations = session.$decorations;
  12541. var firstLineNumber = session.$firstLineNumber;
  12542. var lastLineNumber = 0;
  12543. var gutterRenderer = session.gutterRenderer || this.$renderer;
  12544. var cell = null;
  12545. var index = -1;
  12546. var row = firstRow;
  12547. while (true) {
  12548. if (row > foldStart) {
  12549. row = fold.end.row + 1;
  12550. fold = session.getNextFoldLine(row, fold);
  12551. foldStart = fold ? fold.start.row : Infinity;
  12552. }
  12553. if (row > lastRow) {
  12554. while (this.$cells.length > index + 1) {
  12555. cell = this.$cells.pop();
  12556. this.element.removeChild(cell.element);
  12557. }
  12558. break;
  12559. }
  12560. cell = this.$cells[++index];
  12561. if (!cell) {
  12562. cell = {element: null, textNode: null, foldWidget: null};
  12563. cell.element = dom.createElement("div");
  12564. cell.textNode = document.createTextNode('');
  12565. cell.element.appendChild(cell.textNode);
  12566. this.element.appendChild(cell.element);
  12567. this.$cells[index] = cell;
  12568. }
  12569. var className = "ace_gutter-cell ";
  12570. if (breakpoints[row])
  12571. className += breakpoints[row];
  12572. if (decorations[row])
  12573. className += decorations[row];
  12574. if (this.$annotations[row])
  12575. className += this.$annotations[row].className;
  12576. if (cell.element.className != className)
  12577. cell.element.className = className;
  12578. var height = session.getRowLength(row) * config.lineHeight + "px";
  12579. if (height != cell.element.style.height)
  12580. cell.element.style.height = height;
  12581. if (foldWidgets) {
  12582. var c = foldWidgets[row];
  12583. if (c == null)
  12584. c = foldWidgets[row] = session.getFoldWidget(row);
  12585. }
  12586. if (c) {
  12587. if (!cell.foldWidget) {
  12588. cell.foldWidget = dom.createElement("span");
  12589. cell.element.appendChild(cell.foldWidget);
  12590. }
  12591. var className = "ace_fold-widget ace_" + c;
  12592. if (c == "start" && row == foldStart && row < fold.end.row)
  12593. className += " ace_closed";
  12594. else
  12595. className += " ace_open";
  12596. if (cell.foldWidget.className != className)
  12597. cell.foldWidget.className = className;
  12598. var height = config.lineHeight + "px";
  12599. if (cell.foldWidget.style.height != height)
  12600. cell.foldWidget.style.height = height;
  12601. } else {
  12602. if (cell.foldWidget) {
  12603. cell.element.removeChild(cell.foldWidget);
  12604. cell.foldWidget = null;
  12605. }
  12606. }
  12607. var text = lastLineNumber = gutterRenderer
  12608. ? gutterRenderer.getText(session, row)
  12609. : row + firstLineNumber;
  12610. if (text !== cell.textNode.data)
  12611. cell.textNode.data = text;
  12612. row++;
  12613. }
  12614. this.element.style.height = config.minHeight + "px";
  12615. if (this.$fixedWidth || session.$useWrapMode)
  12616. lastLineNumber = session.getLength() + firstLineNumber;
  12617. var gutterWidth = gutterRenderer
  12618. ? gutterRenderer.getWidth(session, lastLineNumber, config)
  12619. : lastLineNumber.toString().length * config.characterWidth;
  12620. var padding = this.$padding || this.$computePadding();
  12621. gutterWidth += padding.left + padding.right;
  12622. if (gutterWidth !== this.gutterWidth && !isNaN(gutterWidth)) {
  12623. this.gutterWidth = gutterWidth;
  12624. this.element.style.width = Math.ceil(this.gutterWidth) + "px";
  12625. this._emit("changeGutterWidth", gutterWidth);
  12626. }
  12627. };
  12628. this.$fixedWidth = false;
  12629. this.$showLineNumbers = true;
  12630. this.$renderer = "";
  12631. this.setShowLineNumbers = function(show) {
  12632. this.$renderer = !show && {
  12633. getWidth: function() {return ""},
  12634. getText: function() {return ""}
  12635. };
  12636. };
  12637. this.getShowLineNumbers = function() {
  12638. return this.$showLineNumbers;
  12639. };
  12640. this.$showFoldWidgets = true;
  12641. this.setShowFoldWidgets = function(show) {
  12642. if (show)
  12643. dom.addCssClass(this.element, "ace_folding-enabled");
  12644. else
  12645. dom.removeCssClass(this.element, "ace_folding-enabled");
  12646. this.$showFoldWidgets = show;
  12647. this.$padding = null;
  12648. };
  12649. this.getShowFoldWidgets = function() {
  12650. return this.$showFoldWidgets;
  12651. };
  12652. this.$computePadding = function() {
  12653. if (!this.element.firstChild)
  12654. return {left: 0, right: 0};
  12655. var style = dom.computedStyle(this.element.firstChild);
  12656. this.$padding = {};
  12657. this.$padding.left = parseInt(style.paddingLeft) + 1 || 0;
  12658. this.$padding.right = parseInt(style.paddingRight) || 0;
  12659. return this.$padding;
  12660. };
  12661. this.getRegion = function(point) {
  12662. var padding = this.$padding || this.$computePadding();
  12663. var rect = this.element.getBoundingClientRect();
  12664. if (point.x < padding.left + rect.left)
  12665. return "markers";
  12666. if (this.$showFoldWidgets && point.x > rect.right - padding.right)
  12667. return "foldWidgets";
  12668. };
  12669. }).call(Gutter.prototype);
  12670. exports.Gutter = Gutter;
  12671. });
  12672. define("ace/layer/marker",["require","exports","module","ace/range","ace/lib/dom"], function(require, exports, module) {
  12673. "use strict";
  12674. var Range = require("../range").Range;
  12675. var dom = require("../lib/dom");
  12676. var Marker = function(parentEl) {
  12677. this.element = dom.createElement("div");
  12678. this.element.className = "ace_layer ace_marker-layer";
  12679. parentEl.appendChild(this.element);
  12680. };
  12681. (function() {
  12682. this.$padding = 0;
  12683. this.setPadding = function(padding) {
  12684. this.$padding = padding;
  12685. };
  12686. this.setSession = function(session) {
  12687. this.session = session;
  12688. };
  12689. this.setMarkers = function(markers) {
  12690. this.markers = markers;
  12691. };
  12692. this.update = function(config) {
  12693. if (!config) return;
  12694. this.config = config;
  12695. var html = [];
  12696. for (var key in this.markers) {
  12697. var marker = this.markers[key];
  12698. if (!marker.range) {
  12699. marker.update(html, this, this.session, config);
  12700. continue;
  12701. }
  12702. var range = marker.range.clipRows(config.firstRow, config.lastRow);
  12703. if (range.isEmpty()) continue;
  12704. range = range.toScreenRange(this.session);
  12705. if (marker.renderer) {
  12706. var top = this.$getTop(range.start.row, config);
  12707. var left = this.$padding + range.start.column * config.characterWidth;
  12708. marker.renderer(html, range, left, top, config);
  12709. } else if (marker.type == "fullLine") {
  12710. this.drawFullLineMarker(html, range, marker.clazz, config);
  12711. } else if (marker.type == "screenLine") {
  12712. this.drawScreenLineMarker(html, range, marker.clazz, config);
  12713. } else if (range.isMultiLine()) {
  12714. if (marker.type == "text")
  12715. this.drawTextMarker(html, range, marker.clazz, config);
  12716. else
  12717. this.drawMultiLineMarker(html, range, marker.clazz, config);
  12718. } else {
  12719. this.drawSingleLineMarker(html, range, marker.clazz + " ace_start" + " ace_br15", config);
  12720. }
  12721. }
  12722. this.element.innerHTML = html.join("");
  12723. };
  12724. this.$getTop = function(row, layerConfig) {
  12725. return (row - layerConfig.firstRowScreen) * layerConfig.lineHeight;
  12726. };
  12727. function getBorderClass(tl, tr, br, bl) {
  12728. return (tl ? 1 : 0) | (tr ? 2 : 0) | (br ? 4 : 0) | (bl ? 8 : 0);
  12729. }
  12730. this.drawTextMarker = function(stringBuilder, range, clazz, layerConfig, extraStyle) {
  12731. var session = this.session;
  12732. var start = range.start.row;
  12733. var end = range.end.row;
  12734. var row = start;
  12735. var prev = 0;
  12736. var curr = 0;
  12737. var next = session.getScreenLastRowColumn(row);
  12738. var lineRange = new Range(row, range.start.column, row, curr);
  12739. for (; row <= end; row++) {
  12740. lineRange.start.row = lineRange.end.row = row;
  12741. lineRange.start.column = row == start ? range.start.column : session.getRowWrapIndent(row);
  12742. lineRange.end.column = next;
  12743. prev = curr;
  12744. curr = next;
  12745. next = row + 1 < end ? session.getScreenLastRowColumn(row + 1) : row == end ? 0 : range.end.column;
  12746. this.drawSingleLineMarker(stringBuilder, lineRange,
  12747. clazz + (row == start ? " ace_start" : "") + " ace_br"
  12748. + getBorderClass(row == start || row == start + 1 && range.start.column, prev < curr, curr > next, row == end),
  12749. layerConfig, row == end ? 0 : 1, extraStyle);
  12750. }
  12751. };
  12752. this.drawMultiLineMarker = function(stringBuilder, range, clazz, config, extraStyle) {
  12753. var padding = this.$padding;
  12754. var height = config.lineHeight;
  12755. var top = this.$getTop(range.start.row, config);
  12756. var left = padding + range.start.column * config.characterWidth;
  12757. extraStyle = extraStyle || "";
  12758. stringBuilder.push(
  12759. "<div class='", clazz, " ace_br1 ace_start' style='",
  12760. "height:", height, "px;",
  12761. "right:0;",
  12762. "top:", top, "px;",
  12763. "left:", left, "px;", extraStyle, "'></div>"
  12764. );
  12765. top = this.$getTop(range.end.row, config);
  12766. var width = range.end.column * config.characterWidth;
  12767. stringBuilder.push(
  12768. "<div class='", clazz, " ace_br12' style='",
  12769. "height:", height, "px;",
  12770. "width:", width, "px;",
  12771. "top:", top, "px;",
  12772. "left:", padding, "px;", extraStyle, "'></div>"
  12773. );
  12774. height = (range.end.row - range.start.row - 1) * config.lineHeight;
  12775. if (height <= 0)
  12776. return;
  12777. top = this.$getTop(range.start.row + 1, config);
  12778. var radiusClass = (range.start.column ? 1 : 0) | (range.end.column ? 0 : 8);
  12779. stringBuilder.push(
  12780. "<div class='", clazz, (radiusClass ? " ace_br" + radiusClass : ""), "' style='",
  12781. "height:", height, "px;",
  12782. "right:0;",
  12783. "top:", top, "px;",
  12784. "left:", padding, "px;", extraStyle, "'></div>"
  12785. );
  12786. };
  12787. this.drawSingleLineMarker = function(stringBuilder, range, clazz, config, extraLength, extraStyle) {
  12788. var height = config.lineHeight;
  12789. var width = (range.end.column + (extraLength || 0) - range.start.column) * config.characterWidth;
  12790. var top = this.$getTop(range.start.row, config);
  12791. var left = this.$padding + range.start.column * config.characterWidth;
  12792. stringBuilder.push(
  12793. "<div class='", clazz, "' style='",
  12794. "height:", height, "px;",
  12795. "width:", width, "px;",
  12796. "top:", top, "px;",
  12797. "left:", left, "px;", extraStyle || "", "'></div>"
  12798. );
  12799. };
  12800. this.drawFullLineMarker = function(stringBuilder, range, clazz, config, extraStyle) {
  12801. var top = this.$getTop(range.start.row, config);
  12802. var height = config.lineHeight;
  12803. if (range.start.row != range.end.row)
  12804. height += this.$getTop(range.end.row, config) - top;
  12805. stringBuilder.push(
  12806. "<div class='", clazz, "' style='",
  12807. "height:", height, "px;",
  12808. "top:", top, "px;",
  12809. "left:0;right:0;", extraStyle || "", "'></div>"
  12810. );
  12811. };
  12812. this.drawScreenLineMarker = function(stringBuilder, range, clazz, config, extraStyle) {
  12813. var top = this.$getTop(range.start.row, config);
  12814. var height = config.lineHeight;
  12815. stringBuilder.push(
  12816. "<div class='", clazz, "' style='",
  12817. "height:", height, "px;",
  12818. "top:", top, "px;",
  12819. "left:0;right:0;", extraStyle || "", "'></div>"
  12820. );
  12821. };
  12822. }).call(Marker.prototype);
  12823. exports.Marker = Marker;
  12824. });
  12825. define("ace/layer/text",["require","exports","module","ace/lib/oop","ace/lib/dom","ace/lib/lang","ace/lib/useragent","ace/lib/event_emitter"], function(require, exports, module) {
  12826. "use strict";
  12827. var oop = require("../lib/oop");
  12828. var dom = require("../lib/dom");
  12829. var lang = require("../lib/lang");
  12830. var useragent = require("../lib/useragent");
  12831. var EventEmitter = require("../lib/event_emitter").EventEmitter;
  12832. var Text = function(parentEl) {
  12833. this.element = dom.createElement("div");
  12834. this.element.className = "ace_layer ace_text-layer";
  12835. parentEl.appendChild(this.element);
  12836. this.$updateEolChar = this.$updateEolChar.bind(this);
  12837. };
  12838. (function() {
  12839. oop.implement(this, EventEmitter);
  12840. this.EOF_CHAR = "\xB6";
  12841. this.EOL_CHAR_LF = "\xAC";
  12842. this.EOL_CHAR_CRLF = "\xa4";
  12843. this.EOL_CHAR = this.EOL_CHAR_LF;
  12844. this.TAB_CHAR = "\u2014"; //"\u21E5";
  12845. this.SPACE_CHAR = "\xB7";
  12846. this.$padding = 0;
  12847. this.$updateEolChar = function() {
  12848. var EOL_CHAR = this.session.doc.getNewLineCharacter() == "\n"
  12849. ? this.EOL_CHAR_LF
  12850. : this.EOL_CHAR_CRLF;
  12851. if (this.EOL_CHAR != EOL_CHAR) {
  12852. this.EOL_CHAR = EOL_CHAR;
  12853. return true;
  12854. }
  12855. }
  12856. this.setPadding = function(padding) {
  12857. this.$padding = padding;
  12858. this.element.style.padding = "0 " + padding + "px";
  12859. };
  12860. this.getLineHeight = function() {
  12861. return this.$fontMetrics.$characterSize.height || 0;
  12862. };
  12863. this.getCharacterWidth = function() {
  12864. return this.$fontMetrics.$characterSize.width || 0;
  12865. };
  12866. this.$setFontMetrics = function(measure) {
  12867. this.$fontMetrics = measure;
  12868. this.$fontMetrics.on("changeCharacterSize", function(e) {
  12869. this._signal("changeCharacterSize", e);
  12870. }.bind(this));
  12871. this.$pollSizeChanges();
  12872. }
  12873. this.checkForSizeChanges = function() {
  12874. this.$fontMetrics.checkForSizeChanges();
  12875. };
  12876. this.$pollSizeChanges = function() {
  12877. return this.$pollSizeChangesTimer = this.$fontMetrics.$pollSizeChanges();
  12878. };
  12879. this.setSession = function(session) {
  12880. this.session = session;
  12881. if (session)
  12882. this.$computeTabString();
  12883. };
  12884. this.showInvisibles = false;
  12885. this.setShowInvisibles = function(showInvisibles) {
  12886. if (this.showInvisibles == showInvisibles)
  12887. return false;
  12888. this.showInvisibles = showInvisibles;
  12889. this.$computeTabString();
  12890. return true;
  12891. };
  12892. this.displayIndentGuides = true;
  12893. this.setDisplayIndentGuides = function(display) {
  12894. if (this.displayIndentGuides == display)
  12895. return false;
  12896. this.displayIndentGuides = display;
  12897. this.$computeTabString();
  12898. return true;
  12899. };
  12900. this.$tabStrings = [];
  12901. this.onChangeTabSize =
  12902. this.$computeTabString = function() {
  12903. var tabSize = this.session.getTabSize();
  12904. this.tabSize = tabSize;
  12905. var tabStr = this.$tabStrings = [0];
  12906. for (var i = 1; i < tabSize + 1; i++) {
  12907. if (this.showInvisibles) {
  12908. tabStr.push("<span class='ace_invisible ace_invisible_tab'>"
  12909. + lang.stringRepeat(this.TAB_CHAR, i)
  12910. + "</span>");
  12911. } else {
  12912. tabStr.push(lang.stringRepeat(" ", i));
  12913. }
  12914. }
  12915. if (this.displayIndentGuides) {
  12916. this.$indentGuideRe = /\s\S| \t|\t |\s$/;
  12917. var className = "ace_indent-guide";
  12918. var spaceClass = "";
  12919. var tabClass = "";
  12920. if (this.showInvisibles) {
  12921. className += " ace_invisible";
  12922. spaceClass = " ace_invisible_space";
  12923. tabClass = " ace_invisible_tab";
  12924. var spaceContent = lang.stringRepeat(this.SPACE_CHAR, this.tabSize);
  12925. var tabContent = lang.stringRepeat(this.TAB_CHAR, this.tabSize);
  12926. } else{
  12927. var spaceContent = lang.stringRepeat(" ", this.tabSize);
  12928. var tabContent = spaceContent;
  12929. }
  12930. this.$tabStrings[" "] = "<span class='" + className + spaceClass + "'>" + spaceContent + "</span>";
  12931. this.$tabStrings["\t"] = "<span class='" + className + tabClass + "'>" + tabContent + "</span>";
  12932. }
  12933. };
  12934. this.updateLines = function(config, firstRow, lastRow) {
  12935. if (this.config.lastRow != config.lastRow ||
  12936. this.config.firstRow != config.firstRow) {
  12937. this.scrollLines(config);
  12938. }
  12939. this.config = config;
  12940. var first = Math.max(firstRow, config.firstRow);
  12941. var last = Math.min(lastRow, config.lastRow);
  12942. var lineElements = this.element.childNodes;
  12943. var lineElementsIdx = 0;
  12944. for (var row = config.firstRow; row < first; row++) {
  12945. var foldLine = this.session.getFoldLine(row);
  12946. if (foldLine) {
  12947. if (foldLine.containsRow(first)) {
  12948. first = foldLine.start.row;
  12949. break;
  12950. } else {
  12951. row = foldLine.end.row;
  12952. }
  12953. }
  12954. lineElementsIdx ++;
  12955. }
  12956. var row = first;
  12957. var foldLine = this.session.getNextFoldLine(row);
  12958. var foldStart = foldLine ? foldLine.start.row : Infinity;
  12959. while (true) {
  12960. if (row > foldStart) {
  12961. row = foldLine.end.row+1;
  12962. foldLine = this.session.getNextFoldLine(row, foldLine);
  12963. foldStart = foldLine ? foldLine.start.row :Infinity;
  12964. }
  12965. if (row > last)
  12966. break;
  12967. var lineElement = lineElements[lineElementsIdx++];
  12968. if (lineElement) {
  12969. var html = [];
  12970. this.$renderLine(
  12971. html, row, !this.$useLineGroups(), row == foldStart ? foldLine : false
  12972. );
  12973. lineElement.style.height = config.lineHeight * this.session.getRowLength(row) + "px";
  12974. lineElement.innerHTML = html.join("");
  12975. }
  12976. row++;
  12977. }
  12978. };
  12979. this.scrollLines = function(config) {
  12980. var oldConfig = this.config;
  12981. this.config = config;
  12982. if (!oldConfig || oldConfig.lastRow < config.firstRow)
  12983. return this.update(config);
  12984. if (config.lastRow < oldConfig.firstRow)
  12985. return this.update(config);
  12986. var el = this.element;
  12987. if (oldConfig.firstRow < config.firstRow)
  12988. for (var row=this.session.getFoldedRowCount(oldConfig.firstRow, config.firstRow - 1); row>0; row--)
  12989. el.removeChild(el.firstChild);
  12990. if (oldConfig.lastRow > config.lastRow)
  12991. for (var row=this.session.getFoldedRowCount(config.lastRow + 1, oldConfig.lastRow); row>0; row--)
  12992. el.removeChild(el.lastChild);
  12993. if (config.firstRow < oldConfig.firstRow) {
  12994. var fragment = this.$renderLinesFragment(config, config.firstRow, oldConfig.firstRow - 1);
  12995. if (el.firstChild)
  12996. el.insertBefore(fragment, el.firstChild);
  12997. else
  12998. el.appendChild(fragment);
  12999. }
  13000. if (config.lastRow > oldConfig.lastRow) {
  13001. var fragment = this.$renderLinesFragment(config, oldConfig.lastRow + 1, config.lastRow);
  13002. el.appendChild(fragment);
  13003. }
  13004. };
  13005. this.$renderLinesFragment = function(config, firstRow, lastRow) {
  13006. var fragment = this.element.ownerDocument.createDocumentFragment();
  13007. var row = firstRow;
  13008. var foldLine = this.session.getNextFoldLine(row);
  13009. var foldStart = foldLine ? foldLine.start.row : Infinity;
  13010. while (true) {
  13011. if (row > foldStart) {
  13012. row = foldLine.end.row+1;
  13013. foldLine = this.session.getNextFoldLine(row, foldLine);
  13014. foldStart = foldLine ? foldLine.start.row : Infinity;
  13015. }
  13016. if (row > lastRow)
  13017. break;
  13018. var container = dom.createElement("div");
  13019. var html = [];
  13020. this.$renderLine(html, row, false, row == foldStart ? foldLine : false);
  13021. container.innerHTML = html.join("");
  13022. if (this.$useLineGroups()) {
  13023. container.className = 'ace_line_group';
  13024. fragment.appendChild(container);
  13025. container.style.height = config.lineHeight * this.session.getRowLength(row) + "px";
  13026. } else {
  13027. while(container.firstChild)
  13028. fragment.appendChild(container.firstChild);
  13029. }
  13030. row++;
  13031. }
  13032. return fragment;
  13033. };
  13034. this.update = function(config) {
  13035. this.config = config;
  13036. var html = [];
  13037. var firstRow = config.firstRow, lastRow = config.lastRow;
  13038. var row = firstRow;
  13039. var foldLine = this.session.getNextFoldLine(row);
  13040. var foldStart = foldLine ? foldLine.start.row : Infinity;
  13041. while (true) {
  13042. if (row > foldStart) {
  13043. row = foldLine.end.row+1;
  13044. foldLine = this.session.getNextFoldLine(row, foldLine);
  13045. foldStart = foldLine ? foldLine.start.row :Infinity;
  13046. }
  13047. if (row > lastRow)
  13048. break;
  13049. if (this.$useLineGroups())
  13050. html.push("<div class='ace_line_group' style='height:", config.lineHeight*this.session.getRowLength(row), "px'>")
  13051. this.$renderLine(html, row, false, row == foldStart ? foldLine : false);
  13052. if (this.$useLineGroups())
  13053. html.push("</div>"); // end the line group
  13054. row++;
  13055. }
  13056. this.element.innerHTML = html.join("");
  13057. };
  13058. this.$textToken = {
  13059. "text": true,
  13060. "rparen": true,
  13061. "lparen": true
  13062. };
  13063. this.$renderToken = function(stringBuilder, screenColumn, token, value) {
  13064. var self = this;
  13065. var replaceReg = /\t|&|<|>|( +)|([\x00-\x1f\x80-\xa0\xad\u1680\u180E\u2000-\u200f\u2028\u2029\u202F\u205F\u3000\uFEFF\uFFF9-\uFFFC])|[\u1100-\u115F\u11A3-\u11A7\u11FA-\u11FF\u2329-\u232A\u2E80-\u2E99\u2E9B-\u2EF3\u2F00-\u2FD5\u2FF0-\u2FFB\u3000-\u303E\u3041-\u3096\u3099-\u30FF\u3105-\u312D\u3131-\u318E\u3190-\u31BA\u31C0-\u31E3\u31F0-\u321E\u3220-\u3247\u3250-\u32FE\u3300-\u4DBF\u4E00-\uA48C\uA490-\uA4C6\uA960-\uA97C\uAC00-\uD7A3\uD7B0-\uD7C6\uD7CB-\uD7FB\uF900-\uFAFF\uFE10-\uFE19\uFE30-\uFE52\uFE54-\uFE66\uFE68-\uFE6B\uFF01-\uFF60\uFFE0-\uFFE6]/g;
  13066. var replaceFunc = function(c, a, b, tabIdx, idx4) {
  13067. if (a) {
  13068. return self.showInvisibles
  13069. ? "<span class='ace_invisible ace_invisible_space'>" + lang.stringRepeat(self.SPACE_CHAR, c.length) + "</span>"
  13070. : c;
  13071. } else if (c == "&") {
  13072. return "&#38;";
  13073. } else if (c == "<") {
  13074. return "&#60;";
  13075. } else if (c == ">") {
  13076. return "&#62;";
  13077. } else if (c == "\t") {
  13078. var tabSize = self.session.getScreenTabSize(screenColumn + tabIdx);
  13079. screenColumn += tabSize - 1;
  13080. return self.$tabStrings[tabSize];
  13081. } else if (c == "\u3000") {
  13082. var classToUse = self.showInvisibles ? "ace_cjk ace_invisible ace_invisible_space" : "ace_cjk";
  13083. var space = self.showInvisibles ? self.SPACE_CHAR : "";
  13084. screenColumn += 1;
  13085. return "<span class='" + classToUse + "' style='width:" +
  13086. (self.config.characterWidth * 2) +
  13087. "px'>" + space + "</span>";
  13088. } else if (b) {
  13089. return "<span class='ace_invisible ace_invisible_space ace_invalid'>" + self.SPACE_CHAR + "</span>";
  13090. } else {
  13091. screenColumn += 1;
  13092. return "<span class='ace_cjk' style='width:" +
  13093. (self.config.characterWidth * 2) +
  13094. "px'>" + c + "</span>";
  13095. }
  13096. };
  13097. var output = value.replace(replaceReg, replaceFunc);
  13098. if (!this.$textToken[token.type]) {
  13099. var classes = "ace_" + token.type.replace(/\./g, " ace_");
  13100. var style = "";
  13101. if (token.type == "fold")
  13102. style = " style='width:" + (token.value.length * this.config.characterWidth) + "px;' ";
  13103. stringBuilder.push("<span class='", classes, "'", style, ">", output, "</span>");
  13104. }
  13105. else {
  13106. stringBuilder.push(output);
  13107. }
  13108. return screenColumn + value.length;
  13109. };
  13110. this.renderIndentGuide = function(stringBuilder, value, max) {
  13111. var cols = value.search(this.$indentGuideRe);
  13112. if (cols <= 0 || cols >= max)
  13113. return value;
  13114. if (value[0] == " ") {
  13115. cols -= cols % this.tabSize;
  13116. stringBuilder.push(lang.stringRepeat(this.$tabStrings[" "], cols/this.tabSize));
  13117. return value.substr(cols);
  13118. } else if (value[0] == "\t") {
  13119. stringBuilder.push(lang.stringRepeat(this.$tabStrings["\t"], cols));
  13120. return value.substr(cols);
  13121. }
  13122. return value;
  13123. };
  13124. this.$renderWrappedLine = function(stringBuilder, tokens, splits, onlyContents) {
  13125. var chars = 0;
  13126. var split = 0;
  13127. var splitChars = splits[0];
  13128. var screenColumn = 0;
  13129. for (var i = 0; i < tokens.length; i++) {
  13130. var token = tokens[i];
  13131. var value = token.value;
  13132. if (i == 0 && this.displayIndentGuides) {
  13133. chars = value.length;
  13134. value = this.renderIndentGuide(stringBuilder, value, splitChars);
  13135. if (!value)
  13136. continue;
  13137. chars -= value.length;
  13138. }
  13139. if (chars + value.length < splitChars) {
  13140. screenColumn = this.$renderToken(stringBuilder, screenColumn, token, value);
  13141. chars += value.length;
  13142. } else {
  13143. while (chars + value.length >= splitChars) {
  13144. screenColumn = this.$renderToken(
  13145. stringBuilder, screenColumn,
  13146. token, value.substring(0, splitChars - chars)
  13147. );
  13148. value = value.substring(splitChars - chars);
  13149. chars = splitChars;
  13150. if (!onlyContents) {
  13151. stringBuilder.push("</div>",
  13152. "<div class='ace_line' style='height:",
  13153. this.config.lineHeight, "px'>"
  13154. );
  13155. }
  13156. stringBuilder.push(lang.stringRepeat("\xa0", splits.indent));
  13157. split ++;
  13158. screenColumn = 0;
  13159. splitChars = splits[split] || Number.MAX_VALUE;
  13160. }
  13161. if (value.length != 0) {
  13162. chars += value.length;
  13163. screenColumn = this.$renderToken(
  13164. stringBuilder, screenColumn, token, value
  13165. );
  13166. }
  13167. }
  13168. }
  13169. };
  13170. this.$renderSimpleLine = function(stringBuilder, tokens) {
  13171. var screenColumn = 0;
  13172. var token = tokens[0];
  13173. var value = token.value;
  13174. if (this.displayIndentGuides)
  13175. value = this.renderIndentGuide(stringBuilder, value);
  13176. if (value)
  13177. screenColumn = this.$renderToken(stringBuilder, screenColumn, token, value);
  13178. for (var i = 1; i < tokens.length; i++) {
  13179. token = tokens[i];
  13180. value = token.value;
  13181. screenColumn = this.$renderToken(stringBuilder, screenColumn, token, value);
  13182. }
  13183. };
  13184. this.$renderLine = function(stringBuilder, row, onlyContents, foldLine) {
  13185. if (!foldLine && foldLine != false)
  13186. foldLine = this.session.getFoldLine(row);
  13187. if (foldLine)
  13188. var tokens = this.$getFoldLineTokens(row, foldLine);
  13189. else
  13190. var tokens = this.session.getTokens(row);
  13191. if (!onlyContents) {
  13192. stringBuilder.push(
  13193. "<div class='ace_line' style='height:",
  13194. this.config.lineHeight * (
  13195. this.$useLineGroups() ? 1 :this.session.getRowLength(row)
  13196. ), "px'>"
  13197. );
  13198. }
  13199. if (tokens.length) {
  13200. var splits = this.session.getRowSplitData(row);
  13201. if (splits && splits.length)
  13202. this.$renderWrappedLine(stringBuilder, tokens, splits, onlyContents);
  13203. else
  13204. this.$renderSimpleLine(stringBuilder, tokens);
  13205. }
  13206. if (this.showInvisibles) {
  13207. if (foldLine)
  13208. row = foldLine.end.row
  13209. stringBuilder.push(
  13210. "<span class='ace_invisible ace_invisible_eol'>",
  13211. row == this.session.getLength() - 1 ? this.EOF_CHAR : this.EOL_CHAR,
  13212. "</span>"
  13213. );
  13214. }
  13215. if (!onlyContents)
  13216. stringBuilder.push("</div>");
  13217. };
  13218. this.$getFoldLineTokens = function(row, foldLine) {
  13219. var session = this.session;
  13220. var renderTokens = [];
  13221. function addTokens(tokens, from, to) {
  13222. var idx = 0, col = 0;
  13223. while ((col + tokens[idx].value.length) < from) {
  13224. col += tokens[idx].value.length;
  13225. idx++;
  13226. if (idx == tokens.length)
  13227. return;
  13228. }
  13229. if (col != from) {
  13230. var value = tokens[idx].value.substring(from - col);
  13231. if (value.length > (to - from))
  13232. value = value.substring(0, to - from);
  13233. renderTokens.push({
  13234. type: tokens[idx].type,
  13235. value: value
  13236. });
  13237. col = from + value.length;
  13238. idx += 1;
  13239. }
  13240. while (col < to && idx < tokens.length) {
  13241. var value = tokens[idx].value;
  13242. if (value.length + col > to) {
  13243. renderTokens.push({
  13244. type: tokens[idx].type,
  13245. value: value.substring(0, to - col)
  13246. });
  13247. } else
  13248. renderTokens.push(tokens[idx]);
  13249. col += value.length;
  13250. idx += 1;
  13251. }
  13252. }
  13253. var tokens = session.getTokens(row);
  13254. foldLine.walk(function(placeholder, row, column, lastColumn, isNewRow) {
  13255. if (placeholder != null) {
  13256. renderTokens.push({
  13257. type: "fold",
  13258. value: placeholder
  13259. });
  13260. } else {
  13261. if (isNewRow)
  13262. tokens = session.getTokens(row);
  13263. if (tokens.length)
  13264. addTokens(tokens, lastColumn, column);
  13265. }
  13266. }, foldLine.end.row, this.session.getLine(foldLine.end.row).length);
  13267. return renderTokens;
  13268. };
  13269. this.$useLineGroups = function() {
  13270. return this.session.getUseWrapMode();
  13271. };
  13272. this.destroy = function() {
  13273. clearInterval(this.$pollSizeChangesTimer);
  13274. if (this.$measureNode)
  13275. this.$measureNode.parentNode.removeChild(this.$measureNode);
  13276. delete this.$measureNode;
  13277. };
  13278. }).call(Text.prototype);
  13279. exports.Text = Text;
  13280. });
  13281. define("ace/layer/cursor",["require","exports","module","ace/lib/dom"], function(require, exports, module) {
  13282. "use strict";
  13283. var dom = require("../lib/dom");
  13284. var isIE8;
  13285. var Cursor = function(parentEl) {
  13286. this.element = dom.createElement("div");
  13287. this.element.className = "ace_layer ace_cursor-layer";
  13288. parentEl.appendChild(this.element);
  13289. if (isIE8 === undefined)
  13290. isIE8 = !("opacity" in this.element.style);
  13291. this.isVisible = false;
  13292. this.isBlinking = true;
  13293. this.blinkInterval = 1000;
  13294. this.smoothBlinking = false;
  13295. this.cursors = [];
  13296. this.cursor = this.addCursor();
  13297. dom.addCssClass(this.element, "ace_hidden-cursors");
  13298. this.$updateCursors = (isIE8
  13299. ? this.$updateVisibility
  13300. : this.$updateOpacity).bind(this);
  13301. };
  13302. (function() {
  13303. this.$updateVisibility = function(val) {
  13304. var cursors = this.cursors;
  13305. for (var i = cursors.length; i--; )
  13306. cursors[i].style.visibility = val ? "" : "hidden";
  13307. };
  13308. this.$updateOpacity = function(val) {
  13309. var cursors = this.cursors;
  13310. for (var i = cursors.length; i--; )
  13311. cursors[i].style.opacity = val ? "" : "0";
  13312. };
  13313. this.$padding = 0;
  13314. this.setPadding = function(padding) {
  13315. this.$padding = padding;
  13316. };
  13317. this.setSession = function(session) {
  13318. this.session = session;
  13319. };
  13320. this.setBlinking = function(blinking) {
  13321. if (blinking != this.isBlinking){
  13322. this.isBlinking = blinking;
  13323. this.restartTimer();
  13324. }
  13325. };
  13326. this.setBlinkInterval = function(blinkInterval) {
  13327. if (blinkInterval != this.blinkInterval){
  13328. this.blinkInterval = blinkInterval;
  13329. this.restartTimer();
  13330. }
  13331. };
  13332. this.setSmoothBlinking = function(smoothBlinking) {
  13333. if (smoothBlinking != this.smoothBlinking && !isIE8) {
  13334. this.smoothBlinking = smoothBlinking;
  13335. dom.setCssClass(this.element, "ace_smooth-blinking", smoothBlinking);
  13336. this.$updateCursors(true);
  13337. this.$updateCursors = (this.$updateOpacity).bind(this);
  13338. this.restartTimer();
  13339. }
  13340. };
  13341. this.addCursor = function() {
  13342. var el = dom.createElement("div");
  13343. el.className = "ace_cursor";
  13344. this.element.appendChild(el);
  13345. this.cursors.push(el);
  13346. return el;
  13347. };
  13348. this.removeCursor = function() {
  13349. if (this.cursors.length > 1) {
  13350. var el = this.cursors.pop();
  13351. el.parentNode.removeChild(el);
  13352. return el;
  13353. }
  13354. };
  13355. this.hideCursor = function() {
  13356. this.isVisible = false;
  13357. dom.addCssClass(this.element, "ace_hidden-cursors");
  13358. this.restartTimer();
  13359. };
  13360. this.showCursor = function() {
  13361. this.isVisible = true;
  13362. dom.removeCssClass(this.element, "ace_hidden-cursors");
  13363. this.restartTimer();
  13364. };
  13365. this.restartTimer = function() {
  13366. var update = this.$updateCursors;
  13367. clearInterval(this.intervalId);
  13368. clearTimeout(this.timeoutId);
  13369. if (this.smoothBlinking) {
  13370. dom.removeCssClass(this.element, "ace_smooth-blinking");
  13371. }
  13372. update(true);
  13373. if (!this.isBlinking || !this.blinkInterval || !this.isVisible)
  13374. return;
  13375. if (this.smoothBlinking) {
  13376. setTimeout(function(){
  13377. dom.addCssClass(this.element, "ace_smooth-blinking");
  13378. }.bind(this));
  13379. }
  13380. var blink = function(){
  13381. this.timeoutId = setTimeout(function() {
  13382. update(false);
  13383. }, 0.6 * this.blinkInterval);
  13384. }.bind(this);
  13385. this.intervalId = setInterval(function() {
  13386. update(true);
  13387. blink();
  13388. }, this.blinkInterval);
  13389. blink();
  13390. };
  13391. this.getPixelPosition = function(position, onScreen) {
  13392. if (!this.config || !this.session)
  13393. return {left : 0, top : 0};
  13394. if (!position)
  13395. position = this.session.selection.getCursor();
  13396. var pos = this.session.documentToScreenPosition(position);
  13397. var cursorLeft = this.$padding + pos.column * this.config.characterWidth;
  13398. var cursorTop = (pos.row - (onScreen ? this.config.firstRowScreen : 0)) *
  13399. this.config.lineHeight;
  13400. return {left : cursorLeft, top : cursorTop};
  13401. };
  13402. this.update = function(config) {
  13403. this.config = config;
  13404. var selections = this.session.$selectionMarkers;
  13405. var i = 0, cursorIndex = 0;
  13406. if (selections === undefined || selections.length === 0){
  13407. selections = [{cursor: null}];
  13408. }
  13409. for (var i = 0, n = selections.length; i < n; i++) {
  13410. var pixelPos = this.getPixelPosition(selections[i].cursor, true);
  13411. if ((pixelPos.top > config.height + config.offset ||
  13412. pixelPos.top < 0) && i > 1) {
  13413. continue;
  13414. }
  13415. var style = (this.cursors[cursorIndex++] || this.addCursor()).style;
  13416. if (!this.drawCursor) {
  13417. style.left = pixelPos.left + "px";
  13418. style.top = pixelPos.top + "px";
  13419. style.width = config.characterWidth + "px";
  13420. style.height = config.lineHeight + "px";
  13421. } else {
  13422. this.drawCursor(style, pixelPos, config, selections[i], this.session);
  13423. }
  13424. }
  13425. while (this.cursors.length > cursorIndex)
  13426. this.removeCursor();
  13427. var overwrite = this.session.getOverwrite();
  13428. this.$setOverwrite(overwrite);
  13429. this.$pixelPos = pixelPos;
  13430. this.restartTimer();
  13431. };
  13432. this.drawCursor = null;
  13433. this.$setOverwrite = function(overwrite) {
  13434. if (overwrite != this.overwrite) {
  13435. this.overwrite = overwrite;
  13436. if (overwrite)
  13437. dom.addCssClass(this.element, "ace_overwrite-cursors");
  13438. else
  13439. dom.removeCssClass(this.element, "ace_overwrite-cursors");
  13440. }
  13441. };
  13442. this.destroy = function() {
  13443. clearInterval(this.intervalId);
  13444. clearTimeout(this.timeoutId);
  13445. };
  13446. }).call(Cursor.prototype);
  13447. exports.Cursor = Cursor;
  13448. });
  13449. define("ace/scrollbar",["require","exports","module","ace/lib/oop","ace/lib/dom","ace/lib/event","ace/lib/event_emitter"], function(require, exports, module) {
  13450. "use strict";
  13451. var oop = require("./lib/oop");
  13452. var dom = require("./lib/dom");
  13453. var event = require("./lib/event");
  13454. var EventEmitter = require("./lib/event_emitter").EventEmitter;
  13455. var MAX_SCROLL_H = 0x8000;
  13456. var ScrollBar = function(parent) {
  13457. this.element = dom.createElement("div");
  13458. this.element.className = "ace_scrollbar ace_scrollbar" + this.classSuffix;
  13459. this.inner = dom.createElement("div");
  13460. this.inner.className = "ace_scrollbar-inner";
  13461. this.element.appendChild(this.inner);
  13462. parent.appendChild(this.element);
  13463. this.setVisible(false);
  13464. this.skipEvent = false;
  13465. event.addListener(this.element, "scroll", this.onScroll.bind(this));
  13466. event.addListener(this.element, "mousedown", event.preventDefault);
  13467. };
  13468. (function() {
  13469. oop.implement(this, EventEmitter);
  13470. this.setVisible = function(isVisible) {
  13471. this.element.style.display = isVisible ? "" : "none";
  13472. this.isVisible = isVisible;
  13473. this.coeff = 1;
  13474. };
  13475. }).call(ScrollBar.prototype);
  13476. var VScrollBar = function(parent, renderer) {
  13477. ScrollBar.call(this, parent);
  13478. this.scrollTop = 0;
  13479. this.scrollHeight = 0;
  13480. renderer.$scrollbarWidth =
  13481. this.width = dom.scrollbarWidth(parent.ownerDocument);
  13482. this.inner.style.width =
  13483. this.element.style.width = (this.width || 15) + 5 + "px";
  13484. this.$minWidth = 0;
  13485. };
  13486. oop.inherits(VScrollBar, ScrollBar);
  13487. (function() {
  13488. this.classSuffix = '-v';
  13489. this.onScroll = function() {
  13490. if (!this.skipEvent) {
  13491. this.scrollTop = this.element.scrollTop;
  13492. if (this.coeff != 1) {
  13493. var h = this.element.clientHeight / this.scrollHeight;
  13494. this.scrollTop = this.scrollTop * (1 - h) / (this.coeff - h);
  13495. }
  13496. this._emit("scroll", {data: this.scrollTop});
  13497. }
  13498. this.skipEvent = false;
  13499. };
  13500. this.getWidth = function() {
  13501. return Math.max(this.isVisible ? this.width : 0, this.$minWidth || 0);
  13502. };
  13503. this.setHeight = function(height) {
  13504. this.element.style.height = height + "px";
  13505. };
  13506. this.setInnerHeight =
  13507. this.setScrollHeight = function(height) {
  13508. this.scrollHeight = height;
  13509. if (height > MAX_SCROLL_H) {
  13510. this.coeff = MAX_SCROLL_H / height;
  13511. height = MAX_SCROLL_H;
  13512. } else if (this.coeff != 1) {
  13513. this.coeff = 1
  13514. }
  13515. this.inner.style.height = height + "px";
  13516. };
  13517. this.setScrollTop = function(scrollTop) {
  13518. if (this.scrollTop != scrollTop) {
  13519. this.skipEvent = true;
  13520. this.scrollTop = scrollTop;
  13521. this.element.scrollTop = scrollTop * this.coeff;
  13522. }
  13523. };
  13524. }).call(VScrollBar.prototype);
  13525. var HScrollBar = function(parent, renderer) {
  13526. ScrollBar.call(this, parent);
  13527. this.scrollLeft = 0;
  13528. this.height = renderer.$scrollbarWidth;
  13529. this.inner.style.height =
  13530. this.element.style.height = (this.height || 15) + 5 + "px";
  13531. };
  13532. oop.inherits(HScrollBar, ScrollBar);
  13533. (function() {
  13534. this.classSuffix = '-h';
  13535. this.onScroll = function() {
  13536. if (!this.skipEvent) {
  13537. this.scrollLeft = this.element.scrollLeft;
  13538. this._emit("scroll", {data: this.scrollLeft});
  13539. }
  13540. this.skipEvent = false;
  13541. };
  13542. this.getHeight = function() {
  13543. return this.isVisible ? this.height : 0;
  13544. };
  13545. this.setWidth = function(width) {
  13546. this.element.style.width = width + "px";
  13547. };
  13548. this.setInnerWidth = function(width) {
  13549. this.inner.style.width = width + "px";
  13550. };
  13551. this.setScrollWidth = function(width) {
  13552. this.inner.style.width = width + "px";
  13553. };
  13554. this.setScrollLeft = function(scrollLeft) {
  13555. if (this.scrollLeft != scrollLeft) {
  13556. this.skipEvent = true;
  13557. this.scrollLeft = this.element.scrollLeft = scrollLeft;
  13558. }
  13559. };
  13560. }).call(HScrollBar.prototype);
  13561. exports.ScrollBar = VScrollBar; // backward compatibility
  13562. exports.ScrollBarV = VScrollBar; // backward compatibility
  13563. exports.ScrollBarH = HScrollBar; // backward compatibility
  13564. exports.VScrollBar = VScrollBar;
  13565. exports.HScrollBar = HScrollBar;
  13566. });
  13567. define("ace/renderloop",["require","exports","module","ace/lib/event"], function(require, exports, module) {
  13568. "use strict";
  13569. var event = require("./lib/event");
  13570. var RenderLoop = function(onRender, win) {
  13571. this.onRender = onRender;
  13572. this.pending = false;
  13573. this.changes = 0;
  13574. this.window = win || window;
  13575. };
  13576. (function() {
  13577. this.schedule = function(change) {
  13578. this.changes = this.changes | change;
  13579. if (!this.pending && this.changes) {
  13580. this.pending = true;
  13581. var _self = this;
  13582. event.nextFrame(function() {
  13583. _self.pending = false;
  13584. var changes;
  13585. while (changes = _self.changes) {
  13586. _self.changes = 0;
  13587. _self.onRender(changes);
  13588. }
  13589. }, this.window);
  13590. }
  13591. };
  13592. }).call(RenderLoop.prototype);
  13593. exports.RenderLoop = RenderLoop;
  13594. });
  13595. define("ace/layer/font_metrics",["require","exports","module","ace/lib/oop","ace/lib/dom","ace/lib/lang","ace/lib/useragent","ace/lib/event_emitter"], function(require, exports, module) {
  13596. var oop = require("../lib/oop");
  13597. var dom = require("../lib/dom");
  13598. var lang = require("../lib/lang");
  13599. var useragent = require("../lib/useragent");
  13600. var EventEmitter = require("../lib/event_emitter").EventEmitter;
  13601. var CHAR_COUNT = 0;
  13602. var FontMetrics = exports.FontMetrics = function(parentEl) {
  13603. this.el = dom.createElement("div");
  13604. this.$setMeasureNodeStyles(this.el.style, true);
  13605. this.$main = dom.createElement("div");
  13606. this.$setMeasureNodeStyles(this.$main.style);
  13607. this.$measureNode = dom.createElement("div");
  13608. this.$setMeasureNodeStyles(this.$measureNode.style);
  13609. this.el.appendChild(this.$main);
  13610. this.el.appendChild(this.$measureNode);
  13611. parentEl.appendChild(this.el);
  13612. if (!CHAR_COUNT)
  13613. this.$testFractionalRect();
  13614. this.$measureNode.innerHTML = lang.stringRepeat("X", CHAR_COUNT);
  13615. this.$characterSize = {width: 0, height: 0};
  13616. this.checkForSizeChanges();
  13617. };
  13618. (function() {
  13619. oop.implement(this, EventEmitter);
  13620. this.$characterSize = {width: 0, height: 0};
  13621. this.$testFractionalRect = function() {
  13622. var el = dom.createElement("div");
  13623. this.$setMeasureNodeStyles(el.style);
  13624. el.style.width = "0.2px";
  13625. document.documentElement.appendChild(el);
  13626. var w = el.getBoundingClientRect().width;
  13627. if (w > 0 && w < 1)
  13628. CHAR_COUNT = 50;
  13629. else
  13630. CHAR_COUNT = 100;
  13631. el.parentNode.removeChild(el);
  13632. };
  13633. this.$setMeasureNodeStyles = function(style, isRoot) {
  13634. style.width = style.height = "auto";
  13635. style.left = style.top = "0px";
  13636. style.visibility = "hidden";
  13637. style.position = "absolute";
  13638. style.whiteSpace = "pre";
  13639. if (useragent.isIE < 8) {
  13640. style["font-family"] = "inherit";
  13641. } else {
  13642. style.font = "inherit";
  13643. }
  13644. style.overflow = isRoot ? "hidden" : "visible";
  13645. };
  13646. this.checkForSizeChanges = function() {
  13647. var size = this.$measureSizes();
  13648. if (size && (this.$characterSize.width !== size.width || this.$characterSize.height !== size.height)) {
  13649. this.$measureNode.style.fontWeight = "bold";
  13650. var boldSize = this.$measureSizes();
  13651. this.$measureNode.style.fontWeight = "";
  13652. this.$characterSize = size;
  13653. this.charSizes = Object.create(null);
  13654. this.allowBoldFonts = boldSize && boldSize.width === size.width && boldSize.height === size.height;
  13655. this._emit("changeCharacterSize", {data: size});
  13656. }
  13657. };
  13658. this.$pollSizeChanges = function() {
  13659. if (this.$pollSizeChangesTimer)
  13660. return this.$pollSizeChangesTimer;
  13661. var self = this;
  13662. return this.$pollSizeChangesTimer = setInterval(function() {
  13663. self.checkForSizeChanges();
  13664. }, 500);
  13665. };
  13666. this.setPolling = function(val) {
  13667. if (val) {
  13668. this.$pollSizeChanges();
  13669. } else if (this.$pollSizeChangesTimer) {
  13670. clearInterval(this.$pollSizeChangesTimer);
  13671. this.$pollSizeChangesTimer = 0;
  13672. }
  13673. };
  13674. this.$measureSizes = function() {
  13675. if (CHAR_COUNT === 50) {
  13676. var rect = null;
  13677. try {
  13678. rect = this.$measureNode.getBoundingClientRect();
  13679. } catch(e) {
  13680. rect = {width: 0, height:0 };
  13681. }
  13682. var size = {
  13683. height: rect.height,
  13684. width: rect.width / CHAR_COUNT
  13685. };
  13686. } else {
  13687. var size = {
  13688. height: this.$measureNode.clientHeight,
  13689. width: this.$measureNode.clientWidth / CHAR_COUNT
  13690. };
  13691. }
  13692. if (size.width === 0 || size.height === 0)
  13693. return null;
  13694. return size;
  13695. };
  13696. this.$measureCharWidth = function(ch) {
  13697. this.$main.innerHTML = lang.stringRepeat(ch, CHAR_COUNT);
  13698. var rect = this.$main.getBoundingClientRect();
  13699. return rect.width / CHAR_COUNT;
  13700. };
  13701. this.getCharacterWidth = function(ch) {
  13702. var w = this.charSizes[ch];
  13703. if (w === undefined) {
  13704. w = this.charSizes[ch] = this.$measureCharWidth(ch) / this.$characterSize.width;
  13705. }
  13706. return w;
  13707. };
  13708. this.destroy = function() {
  13709. clearInterval(this.$pollSizeChangesTimer);
  13710. if (this.el && this.el.parentNode)
  13711. this.el.parentNode.removeChild(this.el);
  13712. };
  13713. }).call(FontMetrics.prototype);
  13714. });
  13715. define("ace/virtual_renderer",["require","exports","module","ace/lib/oop","ace/lib/dom","ace/config","ace/lib/useragent","ace/layer/gutter","ace/layer/marker","ace/layer/text","ace/layer/cursor","ace/scrollbar","ace/scrollbar","ace/renderloop","ace/layer/font_metrics","ace/lib/event_emitter"], function(require, exports, module) {
  13716. "use strict";
  13717. var oop = require("./lib/oop");
  13718. var dom = require("./lib/dom");
  13719. var config = require("./config");
  13720. var useragent = require("./lib/useragent");
  13721. var GutterLayer = require("./layer/gutter").Gutter;
  13722. var MarkerLayer = require("./layer/marker").Marker;
  13723. var TextLayer = require("./layer/text").Text;
  13724. var CursorLayer = require("./layer/cursor").Cursor;
  13725. var HScrollBar = require("./scrollbar").HScrollBar;
  13726. var VScrollBar = require("./scrollbar").VScrollBar;
  13727. var RenderLoop = require("./renderloop").RenderLoop;
  13728. var FontMetrics = require("./layer/font_metrics").FontMetrics;
  13729. var EventEmitter = require("./lib/event_emitter").EventEmitter;
  13730. var editorCss = ".ace_editor {\
  13731. position: relative;\
  13732. overflow: hidden;\
  13733. font: 12px/normal 'Monaco', 'Menlo', 'Ubuntu Mono', 'Consolas', 'source-code-pro', monospace;\
  13734. direction: ltr;\
  13735. text-align: left;\
  13736. -webkit-tap-highlight-color: rgba(0, 0, 0, 0);\
  13737. }\
  13738. .ace_scroller {\
  13739. position: absolute;\
  13740. overflow: hidden;\
  13741. top: 0;\
  13742. bottom: 0;\
  13743. background-color: inherit;\
  13744. -ms-user-select: none;\
  13745. -moz-user-select: none;\
  13746. -webkit-user-select: none;\
  13747. user-select: none;\
  13748. cursor: text;\
  13749. }\
  13750. .ace_content {\
  13751. position: absolute;\
  13752. -moz-box-sizing: border-box;\
  13753. -webkit-box-sizing: border-box;\
  13754. box-sizing: border-box;\
  13755. min-width: 100%;\
  13756. }\
  13757. .ace_dragging .ace_scroller:before{\
  13758. position: absolute;\
  13759. top: 0;\
  13760. left: 0;\
  13761. right: 0;\
  13762. bottom: 0;\
  13763. content: '';\
  13764. background: rgba(250, 250, 250, 0.01);\
  13765. z-index: 1000;\
  13766. }\
  13767. .ace_dragging.ace_dark .ace_scroller:before{\
  13768. background: rgba(0, 0, 0, 0.01);\
  13769. }\
  13770. .ace_selecting, .ace_selecting * {\
  13771. cursor: text !important;\
  13772. }\
  13773. .ace_gutter {\
  13774. position: absolute;\
  13775. overflow : hidden;\
  13776. width: auto;\
  13777. top: 0;\
  13778. bottom: 0;\
  13779. left: 0;\
  13780. cursor: default;\
  13781. z-index: 4;\
  13782. -ms-user-select: none;\
  13783. -moz-user-select: none;\
  13784. -webkit-user-select: none;\
  13785. user-select: none;\
  13786. }\
  13787. .ace_gutter-active-line {\
  13788. position: absolute;\
  13789. left: 0;\
  13790. right: 0;\
  13791. }\
  13792. .ace_scroller.ace_scroll-left {\
  13793. box-shadow: 17px 0 16px -16px rgba(0, 0, 0, 0.4) inset;\
  13794. }\
  13795. .ace_gutter-cell {\
  13796. padding-left: 19px;\
  13797. padding-right: 6px;\
  13798. background-repeat: no-repeat;\
  13799. }\
  13800. .ace_gutter-cell.ace_error {\
  13801. background-image: url(\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAMAAAAoLQ9TAAABOFBMVEX/////////QRswFAb/Ui4wFAYwFAYwFAaWGAfDRymzOSH/PxswFAb/SiUwFAYwFAbUPRvjQiDllog5HhHdRybsTi3/Tyv9Tir+Syj/UC3////XurebMBIwFAb/RSHbPx/gUzfdwL3kzMivKBAwFAbbvbnhPx66NhowFAYwFAaZJg8wFAaxKBDZurf/RB6mMxb/SCMwFAYwFAbxQB3+RB4wFAb/Qhy4Oh+4QifbNRcwFAYwFAYwFAb/QRzdNhgwFAYwFAbav7v/Uy7oaE68MBK5LxLewr/r2NXewLswFAaxJw4wFAbkPRy2PyYwFAaxKhLm1tMwFAazPiQwFAaUGAb/QBrfOx3bvrv/VC/maE4wFAbRPBq6MRO8Qynew8Dp2tjfwb0wFAbx6eju5+by6uns4uH9/f36+vr/GkHjAAAAYnRSTlMAGt+64rnWu/bo8eAA4InH3+DwoN7j4eLi4xP99Nfg4+b+/u9B/eDs1MD1mO7+4PHg2MXa347g7vDizMLN4eG+Pv7i5evs/v79yu7S3/DV7/498Yv24eH+4ufQ3Ozu/v7+y13sRqwAAADLSURBVHjaZc/XDsFgGIBhtDrshlitmk2IrbHFqL2pvXf/+78DPokj7+Fz9qpU/9UXJIlhmPaTaQ6QPaz0mm+5gwkgovcV6GZzd5JtCQwgsxoHOvJO15kleRLAnMgHFIESUEPmawB9ngmelTtipwwfASilxOLyiV5UVUyVAfbG0cCPHig+GBkzAENHS0AstVF6bacZIOzgLmxsHbt2OecNgJC83JERmePUYq8ARGkJx6XtFsdddBQgZE2nPR6CICZhawjA4Fb/chv+399kfR+MMMDGOQAAAABJRU5ErkJggg==\");\
  13802. background-repeat: no-repeat;\
  13803. background-position: 2px center;\
  13804. }\
  13805. .ace_gutter-cell.ace_warning {\
  13806. background-image: url(\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAMAAAAoLQ9TAAAAmVBMVEX///8AAAD///8AAAAAAABPSzb/5sAAAAB/blH/73z/ulkAAAAAAAD85pkAAAAAAAACAgP/vGz/rkDerGbGrV7/pkQICAf////e0IsAAAD/oED/qTvhrnUAAAD/yHD/njcAAADuv2r/nz//oTj/p064oGf/zHAAAAA9Nir/tFIAAAD/tlTiuWf/tkIAAACynXEAAAAAAAAtIRW7zBpBAAAAM3RSTlMAABR1m7RXO8Ln31Z36zT+neXe5OzooRDfn+TZ4p3h2hTf4t3k3ucyrN1K5+Xaks52Sfs9CXgrAAAAjklEQVR42o3PbQ+CIBQFYEwboPhSYgoYunIqqLn6/z8uYdH8Vmdnu9vz4WwXgN/xTPRD2+sgOcZjsge/whXZgUaYYvT8QnuJaUrjrHUQreGczuEafQCO/SJTufTbroWsPgsllVhq3wJEk2jUSzX3CUEDJC84707djRc5MTAQxoLgupWRwW6UB5fS++NV8AbOZgnsC7BpEAAAAABJRU5ErkJggg==\");\
  13807. background-position: 2px center;\
  13808. }\
  13809. .ace_gutter-cell.ace_info {\
  13810. background-image: url(\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAAAAAA6mKC9AAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAAJ0Uk5TAAB2k804AAAAPklEQVQY02NgIB68QuO3tiLznjAwpKTgNyDbMegwisCHZUETUZV0ZqOquBpXj2rtnpSJT1AEnnRmL2OgGgAAIKkRQap2htgAAAAASUVORK5CYII=\");\
  13811. background-position: 2px center;\
  13812. }\
  13813. .ace_dark .ace_gutter-cell.ace_info {\
  13814. background-image: url(\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQBAMAAADt3eJSAAAAJFBMVEUAAAChoaGAgIAqKiq+vr6tra1ZWVmUlJSbm5s8PDxubm56enrdgzg3AAAAAXRSTlMAQObYZgAAAClJREFUeNpjYMAPdsMYHegyJZFQBlsUlMFVCWUYKkAZMxZAGdxlDMQBAG+TBP4B6RyJAAAAAElFTkSuQmCC\");\
  13815. }\
  13816. .ace_scrollbar {\
  13817. position: absolute;\
  13818. right: 0;\
  13819. bottom: 0;\
  13820. z-index: 6;\
  13821. }\
  13822. .ace_scrollbar-inner {\
  13823. position: absolute;\
  13824. cursor: text;\
  13825. left: 0;\
  13826. top: 0;\
  13827. }\
  13828. .ace_scrollbar-v{\
  13829. overflow-x: hidden;\
  13830. overflow-y: scroll;\
  13831. top: 0;\
  13832. }\
  13833. .ace_scrollbar-h {\
  13834. overflow-x: scroll;\
  13835. overflow-y: hidden;\
  13836. left: 0;\
  13837. }\
  13838. .ace_print-margin {\
  13839. position: absolute;\
  13840. height: 100%;\
  13841. }\
  13842. .ace_text-input {\
  13843. position: absolute;\
  13844. z-index: 0;\
  13845. width: 0.5em;\
  13846. height: 1em;\
  13847. opacity: 0;\
  13848. background: transparent;\
  13849. -moz-appearance: none;\
  13850. appearance: none;\
  13851. border: none;\
  13852. resize: none;\
  13853. outline: none;\
  13854. overflow: hidden;\
  13855. font: inherit;\
  13856. padding: 0 1px;\
  13857. margin: 0 -1px;\
  13858. text-indent: -1em;\
  13859. -ms-user-select: text;\
  13860. -moz-user-select: text;\
  13861. -webkit-user-select: text;\
  13862. user-select: text;\
  13863. white-space: pre!important;\
  13864. }\
  13865. .ace_text-input.ace_composition {\
  13866. background: inherit;\
  13867. color: inherit;\
  13868. z-index: 1000;\
  13869. opacity: 1;\
  13870. text-indent: 0;\
  13871. }\
  13872. .ace_layer {\
  13873. z-index: 1;\
  13874. position: absolute;\
  13875. overflow: hidden;\
  13876. word-wrap: normal;\
  13877. white-space: pre;\
  13878. height: 100%;\
  13879. width: 100%;\
  13880. -moz-box-sizing: border-box;\
  13881. -webkit-box-sizing: border-box;\
  13882. box-sizing: border-box;\
  13883. pointer-events: none;\
  13884. }\
  13885. .ace_gutter-layer {\
  13886. position: relative;\
  13887. width: auto;\
  13888. text-align: right;\
  13889. pointer-events: auto;\
  13890. }\
  13891. .ace_text-layer {\
  13892. font: inherit !important;\
  13893. }\
  13894. .ace_cjk {\
  13895. display: inline-block;\
  13896. text-align: center;\
  13897. }\
  13898. .ace_cursor-layer {\
  13899. z-index: 4;\
  13900. }\
  13901. .ace_cursor {\
  13902. z-index: 4;\
  13903. position: absolute;\
  13904. -moz-box-sizing: border-box;\
  13905. -webkit-box-sizing: border-box;\
  13906. box-sizing: border-box;\
  13907. border-left: 2px solid;\
  13908. transform: translatez(0);\
  13909. }\
  13910. .ace_multiselect .ace_cursor {\
  13911. border-left-width: 1px;\
  13912. }\
  13913. .ace_slim-cursors .ace_cursor {\
  13914. border-left-width: 1px;\
  13915. }\
  13916. .ace_overwrite-cursors .ace_cursor {\
  13917. border-left-width: 0;\
  13918. border-bottom: 1px solid;\
  13919. }\
  13920. .ace_hidden-cursors .ace_cursor {\
  13921. opacity: 0.2;\
  13922. }\
  13923. .ace_smooth-blinking .ace_cursor {\
  13924. -webkit-transition: opacity 0.18s;\
  13925. transition: opacity 0.18s;\
  13926. }\
  13927. .ace_marker-layer .ace_step, .ace_marker-layer .ace_stack {\
  13928. position: absolute;\
  13929. z-index: 3;\
  13930. }\
  13931. .ace_marker-layer .ace_selection {\
  13932. position: absolute;\
  13933. z-index: 5;\
  13934. }\
  13935. .ace_marker-layer .ace_bracket {\
  13936. position: absolute;\
  13937. z-index: 6;\
  13938. }\
  13939. .ace_marker-layer .ace_active-line {\
  13940. position: absolute;\
  13941. z-index: 2;\
  13942. }\
  13943. .ace_marker-layer .ace_selected-word {\
  13944. position: absolute;\
  13945. z-index: 4;\
  13946. -moz-box-sizing: border-box;\
  13947. -webkit-box-sizing: border-box;\
  13948. box-sizing: border-box;\
  13949. }\
  13950. .ace_line .ace_fold {\
  13951. -moz-box-sizing: border-box;\
  13952. -webkit-box-sizing: border-box;\
  13953. box-sizing: border-box;\
  13954. display: inline-block;\
  13955. height: 11px;\
  13956. margin-top: -2px;\
  13957. vertical-align: middle;\
  13958. background-image:\
  13959. url(\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABEAAAAJCAYAAADU6McMAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAJpJREFUeNpi/P//PwOlgAXGYGRklAVSokD8GmjwY1wasKljQpYACtpCFeADcHVQfQyMQAwzwAZI3wJKvCLkfKBaMSClBlR7BOQikCFGQEErIH0VqkabiGCAqwUadAzZJRxQr/0gwiXIal8zQQPnNVTgJ1TdawL0T5gBIP1MUJNhBv2HKoQHHjqNrA4WO4zY0glyNKLT2KIfIMAAQsdgGiXvgnYAAAAASUVORK5CYII=\"),\
  13960. url(\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAA3CAYAAADNNiA5AAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAACJJREFUeNpi+P//fxgTAwPDBxDxD078RSX+YeEyDFMCIMAAI3INmXiwf2YAAAAASUVORK5CYII=\");\
  13961. background-repeat: no-repeat, repeat-x;\
  13962. background-position: center center, top left;\
  13963. color: transparent;\
  13964. border: 1px solid black;\
  13965. border-radius: 2px;\
  13966. cursor: pointer;\
  13967. pointer-events: auto;\
  13968. }\
  13969. .ace_dark .ace_fold {\
  13970. }\
  13971. .ace_fold:hover{\
  13972. background-image:\
  13973. url(\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABEAAAAJCAYAAADU6McMAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAJpJREFUeNpi/P//PwOlgAXGYGRklAVSokD8GmjwY1wasKljQpYACtpCFeADcHVQfQyMQAwzwAZI3wJKvCLkfKBaMSClBlR7BOQikCFGQEErIH0VqkabiGCAqwUadAzZJRxQr/0gwiXIal8zQQPnNVTgJ1TdawL0T5gBIP1MUJNhBv2HKoQHHjqNrA4WO4zY0glyNKLT2KIfIMAAQsdgGiXvgnYAAAAASUVORK5CYII=\"),\
  13974. url(\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAA3CAYAAADNNiA5AAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAACBJREFUeNpi+P//fz4TAwPDZxDxD5X4i5fLMEwJgAADAEPVDbjNw87ZAAAAAElFTkSuQmCC\");\
  13975. }\
  13976. .ace_tooltip {\
  13977. background-color: #FFF;\
  13978. background-image: -webkit-linear-gradient(top, transparent, rgba(0, 0, 0, 0.1));\
  13979. background-image: linear-gradient(to bottom, transparent, rgba(0, 0, 0, 0.1));\
  13980. border: 1px solid gray;\
  13981. border-radius: 1px;\
  13982. box-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);\
  13983. color: black;\
  13984. max-width: 100%;\
  13985. padding: 3px 4px;\
  13986. position: fixed;\
  13987. z-index: 999999;\
  13988. -moz-box-sizing: border-box;\
  13989. -webkit-box-sizing: border-box;\
  13990. box-sizing: border-box;\
  13991. cursor: default;\
  13992. white-space: pre;\
  13993. word-wrap: break-word;\
  13994. line-height: normal;\
  13995. font-style: normal;\
  13996. font-weight: normal;\
  13997. letter-spacing: normal;\
  13998. pointer-events: none;\
  13999. }\
  14000. .ace_folding-enabled > .ace_gutter-cell {\
  14001. padding-right: 13px;\
  14002. }\
  14003. .ace_fold-widget {\
  14004. -moz-box-sizing: border-box;\
  14005. -webkit-box-sizing: border-box;\
  14006. box-sizing: border-box;\
  14007. margin: 0 -12px 0 1px;\
  14008. display: none;\
  14009. width: 11px;\
  14010. vertical-align: top;\
  14011. background-image: url(\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAANElEQVR42mWKsQ0AMAzC8ixLlrzQjzmBiEjp0A6WwBCSPgKAXoLkqSot7nN3yMwR7pZ32NzpKkVoDBUxKAAAAABJRU5ErkJggg==\");\
  14012. background-repeat: no-repeat;\
  14013. background-position: center;\
  14014. border-radius: 3px;\
  14015. border: 1px solid transparent;\
  14016. cursor: pointer;\
  14017. }\
  14018. .ace_folding-enabled .ace_fold-widget {\
  14019. display: inline-block; \
  14020. }\
  14021. .ace_fold-widget.ace_end {\
  14022. background-image: url(\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAANElEQVR42m3HwQkAMAhD0YzsRchFKI7sAikeWkrxwScEB0nh5e7KTPWimZki4tYfVbX+MNl4pyZXejUO1QAAAABJRU5ErkJggg==\");\
  14023. }\
  14024. .ace_fold-widget.ace_closed {\
  14025. background-image: url(\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAMAAAAGCAYAAAAG5SQMAAAAOUlEQVR42jXKwQkAMAgDwKwqKD4EwQ26sSOkVWjgIIHAzPiCgaqiqnJHZnKICBERHN194O5b9vbLuAVRL+l0YWnZAAAAAElFTkSuQmCCXA==\");\
  14026. }\
  14027. .ace_fold-widget:hover {\
  14028. border: 1px solid rgba(0, 0, 0, 0.3);\
  14029. background-color: rgba(255, 255, 255, 0.2);\
  14030. box-shadow: 0 1px 1px rgba(255, 255, 255, 0.7);\
  14031. }\
  14032. .ace_fold-widget:active {\
  14033. border: 1px solid rgba(0, 0, 0, 0.4);\
  14034. background-color: rgba(0, 0, 0, 0.05);\
  14035. box-shadow: 0 1px 1px rgba(255, 255, 255, 0.8);\
  14036. }\
  14037. .ace_dark .ace_fold-widget {\
  14038. background-image: url(\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAHklEQVQIW2P4//8/AzoGEQ7oGCaLLAhWiSwB146BAQCSTPYocqT0AAAAAElFTkSuQmCC\");\
  14039. }\
  14040. .ace_dark .ace_fold-widget.ace_end {\
  14041. background-image: url(\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAH0lEQVQIW2P4//8/AxQ7wNjIAjDMgC4AxjCVKBirIAAF0kz2rlhxpAAAAABJRU5ErkJggg==\");\
  14042. }\
  14043. .ace_dark .ace_fold-widget.ace_closed {\
  14044. background-image: url(\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAMAAAAFCAYAAACAcVaiAAAAHElEQVQIW2P4//+/AxAzgDADlOOAznHAKgPWAwARji8UIDTfQQAAAABJRU5ErkJggg==\");\
  14045. }\
  14046. .ace_dark .ace_fold-widget:hover {\
  14047. box-shadow: 0 1px 1px rgba(255, 255, 255, 0.2);\
  14048. background-color: rgba(255, 255, 255, 0.1);\
  14049. }\
  14050. .ace_dark .ace_fold-widget:active {\
  14051. box-shadow: 0 1px 1px rgba(255, 255, 255, 0.2);\
  14052. }\
  14053. .ace_fold-widget.ace_invalid {\
  14054. background-color: #FFB4B4;\
  14055. border-color: #DE5555;\
  14056. }\
  14057. .ace_fade-fold-widgets .ace_fold-widget {\
  14058. -webkit-transition: opacity 0.4s ease 0.05s;\
  14059. transition: opacity 0.4s ease 0.05s;\
  14060. opacity: 0;\
  14061. }\
  14062. .ace_fade-fold-widgets:hover .ace_fold-widget {\
  14063. -webkit-transition: opacity 0.05s ease 0.05s;\
  14064. transition: opacity 0.05s ease 0.05s;\
  14065. opacity:1;\
  14066. }\
  14067. .ace_underline {\
  14068. text-decoration: underline;\
  14069. }\
  14070. .ace_bold {\
  14071. font-weight: bold;\
  14072. }\
  14073. .ace_nobold .ace_bold {\
  14074. font-weight: normal;\
  14075. }\
  14076. .ace_italic {\
  14077. font-style: italic;\
  14078. }\
  14079. .ace_error-marker {\
  14080. background-color: rgba(255, 0, 0,0.2);\
  14081. position: absolute;\
  14082. z-index: 9;\
  14083. }\
  14084. .ace_highlight-marker {\
  14085. background-color: rgba(255, 255, 0,0.2);\
  14086. position: absolute;\
  14087. z-index: 8;\
  14088. }\
  14089. .ace_br1 {border-top-left-radius : 3px;}\
  14090. .ace_br2 {border-top-right-radius : 3px;}\
  14091. .ace_br3 {border-top-left-radius : 3px; border-top-right-radius: 3px;}\
  14092. .ace_br4 {border-bottom-right-radius: 3px;}\
  14093. .ace_br5 {border-top-left-radius : 3px; border-bottom-right-radius: 3px;}\
  14094. .ace_br6 {border-top-right-radius : 3px; border-bottom-right-radius: 3px;}\
  14095. .ace_br7 {border-top-left-radius : 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px;}\
  14096. .ace_br8 {border-bottom-left-radius : 3px;}\
  14097. .ace_br9 {border-top-left-radius : 3px; border-bottom-left-radius: 3px;}\
  14098. .ace_br10{border-top-right-radius : 3px; border-bottom-left-radius: 3px;}\
  14099. .ace_br11{border-top-left-radius : 3px; border-top-right-radius: 3px; border-bottom-left-radius: 3px;}\
  14100. .ace_br12{border-bottom-right-radius: 3px; border-bottom-left-radius: 3px;}\
  14101. .ace_br13{border-top-left-radius : 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px;}\
  14102. .ace_br14{border-top-right-radius : 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px;}\
  14103. .ace_br15{border-top-left-radius : 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px;}\
  14104. .ace_text-input-ios {\
  14105. position: absolute !important;\
  14106. top: -100000px !important;\
  14107. left: -100000px !important;\
  14108. }\
  14109. ";
  14110. dom.importCssString(editorCss, "ace_editor.css");
  14111. var VirtualRenderer = function(container, theme) {
  14112. var _self = this;
  14113. this.container = container || dom.createElement("div");
  14114. this.$keepTextAreaAtCursor = !useragent.isOldIE;
  14115. dom.addCssClass(this.container, "ace_editor");
  14116. this.setTheme(theme);
  14117. this.$gutter = dom.createElement("div");
  14118. this.$gutter.className = "ace_gutter";
  14119. this.container.appendChild(this.$gutter);
  14120. this.scroller = dom.createElement("div");
  14121. this.scroller.className = "ace_scroller";
  14122. this.container.appendChild(this.scroller);
  14123. this.content = dom.createElement("div");
  14124. this.content.className = "ace_content";
  14125. this.scroller.appendChild(this.content);
  14126. this.$gutterLayer = new GutterLayer(this.$gutter);
  14127. this.$gutterLayer.on("changeGutterWidth", this.onGutterResize.bind(this));
  14128. this.$markerBack = new MarkerLayer(this.content);
  14129. var textLayer = this.$textLayer = new TextLayer(this.content);
  14130. this.canvas = textLayer.element;
  14131. this.$markerFront = new MarkerLayer(this.content);
  14132. this.$cursorLayer = new CursorLayer(this.content);
  14133. this.$horizScroll = false;
  14134. this.$vScroll = false;
  14135. this.scrollBar =
  14136. this.scrollBarV = new VScrollBar(this.container, this);
  14137. this.scrollBarH = new HScrollBar(this.container, this);
  14138. this.scrollBarV.addEventListener("scroll", function(e) {
  14139. if (!_self.$scrollAnimation)
  14140. _self.session.setScrollTop(e.data - _self.scrollMargin.top);
  14141. });
  14142. this.scrollBarH.addEventListener("scroll", function(e) {
  14143. if (!_self.$scrollAnimation)
  14144. _self.session.setScrollLeft(e.data - _self.scrollMargin.left);
  14145. });
  14146. this.scrollTop = 0;
  14147. this.scrollLeft = 0;
  14148. this.cursorPos = {
  14149. row : 0,
  14150. column : 0
  14151. };
  14152. this.$fontMetrics = new FontMetrics(this.container);
  14153. this.$textLayer.$setFontMetrics(this.$fontMetrics);
  14154. this.$textLayer.addEventListener("changeCharacterSize", function(e) {
  14155. _self.updateCharacterSize();
  14156. _self.onResize(true, _self.gutterWidth, _self.$size.width, _self.$size.height);
  14157. _self._signal("changeCharacterSize", e);
  14158. });
  14159. this.$size = {
  14160. width: 0,
  14161. height: 0,
  14162. scrollerHeight: 0,
  14163. scrollerWidth: 0,
  14164. $dirty: true
  14165. };
  14166. this.layerConfig = {
  14167. width : 1,
  14168. padding : 0,
  14169. firstRow : 0,
  14170. firstRowScreen: 0,
  14171. lastRow : 0,
  14172. lineHeight : 0,
  14173. characterWidth : 0,
  14174. minHeight : 1,
  14175. maxHeight : 1,
  14176. offset : 0,
  14177. height : 1,
  14178. gutterOffset: 1
  14179. };
  14180. this.scrollMargin = {
  14181. left: 0,
  14182. right: 0,
  14183. top: 0,
  14184. bottom: 0,
  14185. v: 0,
  14186. h: 0
  14187. };
  14188. this.$loop = new RenderLoop(
  14189. this.$renderChanges.bind(this),
  14190. this.container.ownerDocument.defaultView
  14191. );
  14192. this.$loop.schedule(this.CHANGE_FULL);
  14193. this.updateCharacterSize();
  14194. this.setPadding(4);
  14195. config.resetOptions(this);
  14196. config._emit("renderer", this);
  14197. };
  14198. (function() {
  14199. this.CHANGE_CURSOR = 1;
  14200. this.CHANGE_MARKER = 2;
  14201. this.CHANGE_GUTTER = 4;
  14202. this.CHANGE_SCROLL = 8;
  14203. this.CHANGE_LINES = 16;
  14204. this.CHANGE_TEXT = 32;
  14205. this.CHANGE_SIZE = 64;
  14206. this.CHANGE_MARKER_BACK = 128;
  14207. this.CHANGE_MARKER_FRONT = 256;
  14208. this.CHANGE_FULL = 512;
  14209. this.CHANGE_H_SCROLL = 1024;
  14210. oop.implement(this, EventEmitter);
  14211. this.updateCharacterSize = function() {
  14212. if (this.$textLayer.allowBoldFonts != this.$allowBoldFonts) {
  14213. this.$allowBoldFonts = this.$textLayer.allowBoldFonts;
  14214. this.setStyle("ace_nobold", !this.$allowBoldFonts);
  14215. }
  14216. this.layerConfig.characterWidth =
  14217. this.characterWidth = this.$textLayer.getCharacterWidth();
  14218. this.layerConfig.lineHeight =
  14219. this.lineHeight = this.$textLayer.getLineHeight();
  14220. this.$updatePrintMargin();
  14221. };
  14222. this.setSession = function(session) {
  14223. if (this.session)
  14224. this.session.doc.off("changeNewLineMode", this.onChangeNewLineMode);
  14225. this.session = session;
  14226. if (session && this.scrollMargin.top && session.getScrollTop() <= 0)
  14227. session.setScrollTop(-this.scrollMargin.top);
  14228. this.$cursorLayer.setSession(session);
  14229. this.$markerBack.setSession(session);
  14230. this.$markerFront.setSession(session);
  14231. this.$gutterLayer.setSession(session);
  14232. this.$textLayer.setSession(session);
  14233. if (!session)
  14234. return;
  14235. this.$loop.schedule(this.CHANGE_FULL);
  14236. this.session.$setFontMetrics(this.$fontMetrics);
  14237. this.scrollBarH.scrollLeft = this.scrollBarV.scrollTop = null;
  14238. this.onChangeNewLineMode = this.onChangeNewLineMode.bind(this);
  14239. this.onChangeNewLineMode()
  14240. this.session.doc.on("changeNewLineMode", this.onChangeNewLineMode);
  14241. };
  14242. this.updateLines = function(firstRow, lastRow, force) {
  14243. if (lastRow === undefined)
  14244. lastRow = Infinity;
  14245. if (!this.$changedLines) {
  14246. this.$changedLines = {
  14247. firstRow: firstRow,
  14248. lastRow: lastRow
  14249. };
  14250. }
  14251. else {
  14252. if (this.$changedLines.firstRow > firstRow)
  14253. this.$changedLines.firstRow = firstRow;
  14254. if (this.$changedLines.lastRow < lastRow)
  14255. this.$changedLines.lastRow = lastRow;
  14256. }
  14257. if (this.$changedLines.lastRow < this.layerConfig.firstRow) {
  14258. if (force)
  14259. this.$changedLines.lastRow = this.layerConfig.lastRow;
  14260. else
  14261. return;
  14262. }
  14263. if (this.$changedLines.firstRow > this.layerConfig.lastRow)
  14264. return;
  14265. this.$loop.schedule(this.CHANGE_LINES);
  14266. };
  14267. this.onChangeNewLineMode = function() {
  14268. this.$loop.schedule(this.CHANGE_TEXT);
  14269. this.$textLayer.$updateEolChar();
  14270. };
  14271. this.onChangeTabSize = function() {
  14272. this.$loop.schedule(this.CHANGE_TEXT | this.CHANGE_MARKER);
  14273. this.$textLayer.onChangeTabSize();
  14274. };
  14275. this.updateText = function() {
  14276. this.$loop.schedule(this.CHANGE_TEXT);
  14277. };
  14278. this.updateFull = function(force) {
  14279. if (force)
  14280. this.$renderChanges(this.CHANGE_FULL, true);
  14281. else
  14282. this.$loop.schedule(this.CHANGE_FULL);
  14283. };
  14284. this.updateFontSize = function() {
  14285. this.$textLayer.checkForSizeChanges();
  14286. };
  14287. this.$changes = 0;
  14288. this.$updateSizeAsync = function() {
  14289. if (this.$loop.pending)
  14290. this.$size.$dirty = true;
  14291. else
  14292. this.onResize();
  14293. };
  14294. this.onResize = function(force, gutterWidth, width, height) {
  14295. if (this.resizing > 2)
  14296. return;
  14297. else if (this.resizing > 0)
  14298. this.resizing++;
  14299. else
  14300. this.resizing = force ? 1 : 0;
  14301. var el = this.container;
  14302. if (!height)
  14303. height = el.clientHeight || el.scrollHeight;
  14304. if (!width)
  14305. width = el.clientWidth || el.scrollWidth;
  14306. var changes = this.$updateCachedSize(force, gutterWidth, width, height);
  14307. if (!this.$size.scrollerHeight || (!width && !height))
  14308. return this.resizing = 0;
  14309. if (force)
  14310. this.$gutterLayer.$padding = null;
  14311. if (force)
  14312. this.$renderChanges(changes | this.$changes, true);
  14313. else
  14314. this.$loop.schedule(changes | this.$changes);
  14315. if (this.resizing)
  14316. this.resizing = 0;
  14317. this.scrollBarV.scrollLeft = this.scrollBarV.scrollTop = null;
  14318. };
  14319. this.$updateCachedSize = function(force, gutterWidth, width, height) {
  14320. height -= (this.$extraHeight || 0);
  14321. var changes = 0;
  14322. var size = this.$size;
  14323. var oldSize = {
  14324. width: size.width,
  14325. height: size.height,
  14326. scrollerHeight: size.scrollerHeight,
  14327. scrollerWidth: size.scrollerWidth
  14328. };
  14329. if (height && (force || size.height != height)) {
  14330. size.height = height;
  14331. changes |= this.CHANGE_SIZE;
  14332. size.scrollerHeight = size.height;
  14333. if (this.$horizScroll)
  14334. size.scrollerHeight -= this.scrollBarH.getHeight();
  14335. this.scrollBarV.element.style.bottom = this.scrollBarH.getHeight() + "px";
  14336. changes = changes | this.CHANGE_SCROLL;
  14337. }
  14338. if (width && (force || size.width != width)) {
  14339. changes |= this.CHANGE_SIZE;
  14340. size.width = width;
  14341. if (gutterWidth == null)
  14342. gutterWidth = this.$showGutter ? this.$gutter.offsetWidth : 0;
  14343. this.gutterWidth = gutterWidth;
  14344. this.scrollBarH.element.style.left =
  14345. this.scroller.style.left = gutterWidth + "px";
  14346. size.scrollerWidth = Math.max(0, width - gutterWidth - this.scrollBarV.getWidth());
  14347. this.scrollBarH.element.style.right =
  14348. this.scroller.style.right = this.scrollBarV.getWidth() + "px";
  14349. this.scroller.style.bottom = this.scrollBarH.getHeight() + "px";
  14350. if (this.session && this.session.getUseWrapMode() && this.adjustWrapLimit() || force)
  14351. changes |= this.CHANGE_FULL;
  14352. }
  14353. size.$dirty = !width || !height;
  14354. if (changes)
  14355. this._signal("resize", oldSize);
  14356. return changes;
  14357. };
  14358. this.onGutterResize = function() {
  14359. var gutterWidth = this.$showGutter ? this.$gutter.offsetWidth : 0;
  14360. if (gutterWidth != this.gutterWidth)
  14361. this.$changes |= this.$updateCachedSize(true, gutterWidth, this.$size.width, this.$size.height);
  14362. if (this.session.getUseWrapMode() && this.adjustWrapLimit()) {
  14363. this.$loop.schedule(this.CHANGE_FULL);
  14364. } else if (this.$size.$dirty) {
  14365. this.$loop.schedule(this.CHANGE_FULL);
  14366. } else {
  14367. this.$computeLayerConfig();
  14368. this.$loop.schedule(this.CHANGE_MARKER);
  14369. }
  14370. };
  14371. this.adjustWrapLimit = function() {
  14372. var availableWidth = this.$size.scrollerWidth - this.$padding * 2;
  14373. var limit = Math.floor(availableWidth / this.characterWidth);
  14374. return this.session.adjustWrapLimit(limit, this.$showPrintMargin && this.$printMarginColumn);
  14375. };
  14376. this.setAnimatedScroll = function(shouldAnimate){
  14377. this.setOption("animatedScroll", shouldAnimate);
  14378. };
  14379. this.getAnimatedScroll = function() {
  14380. return this.$animatedScroll;
  14381. };
  14382. this.setShowInvisibles = function(showInvisibles) {
  14383. this.setOption("showInvisibles", showInvisibles);
  14384. };
  14385. this.getShowInvisibles = function() {
  14386. return this.getOption("showInvisibles");
  14387. };
  14388. this.getDisplayIndentGuides = function() {
  14389. return this.getOption("displayIndentGuides");
  14390. };
  14391. this.setDisplayIndentGuides = function(display) {
  14392. this.setOption("displayIndentGuides", display);
  14393. };
  14394. this.setShowPrintMargin = function(showPrintMargin) {
  14395. this.setOption("showPrintMargin", showPrintMargin);
  14396. };
  14397. this.getShowPrintMargin = function() {
  14398. return this.getOption("showPrintMargin");
  14399. };
  14400. this.setPrintMarginColumn = function(showPrintMargin) {
  14401. this.setOption("printMarginColumn", showPrintMargin);
  14402. };
  14403. this.getPrintMarginColumn = function() {
  14404. return this.getOption("printMarginColumn");
  14405. };
  14406. this.getShowGutter = function(){
  14407. return this.getOption("showGutter");
  14408. };
  14409. this.setShowGutter = function(show){
  14410. return this.setOption("showGutter", show);
  14411. };
  14412. this.getFadeFoldWidgets = function(){
  14413. return this.getOption("fadeFoldWidgets")
  14414. };
  14415. this.setFadeFoldWidgets = function(show) {
  14416. this.setOption("fadeFoldWidgets", show);
  14417. };
  14418. this.setHighlightGutterLine = function(shouldHighlight) {
  14419. this.setOption("highlightGutterLine", shouldHighlight);
  14420. };
  14421. this.getHighlightGutterLine = function() {
  14422. return this.getOption("highlightGutterLine");
  14423. };
  14424. this.$updateGutterLineHighlight = function() {
  14425. var pos = this.$cursorLayer.$pixelPos;
  14426. var height = this.layerConfig.lineHeight;
  14427. if (this.session.getUseWrapMode()) {
  14428. var cursor = this.session.selection.getCursor();
  14429. cursor.column = 0;
  14430. pos = this.$cursorLayer.getPixelPosition(cursor, true);
  14431. height *= this.session.getRowLength(cursor.row);
  14432. }
  14433. this.$gutterLineHighlight.style.top = pos.top - this.layerConfig.offset + "px";
  14434. this.$gutterLineHighlight.style.height = height + "px";
  14435. };
  14436. this.$updatePrintMargin = function() {
  14437. if (!this.$showPrintMargin && !this.$printMarginEl)
  14438. return;
  14439. if (!this.$printMarginEl) {
  14440. var containerEl = dom.createElement("div");
  14441. containerEl.className = "ace_layer ace_print-margin-layer";
  14442. this.$printMarginEl = dom.createElement("div");
  14443. this.$printMarginEl.className = "ace_print-margin";
  14444. containerEl.appendChild(this.$printMarginEl);
  14445. this.content.insertBefore(containerEl, this.content.firstChild);
  14446. }
  14447. var style = this.$printMarginEl.style;
  14448. style.left = ((this.characterWidth * this.$printMarginColumn) + this.$padding) + "px";
  14449. style.visibility = this.$showPrintMargin ? "visible" : "hidden";
  14450. if (this.session && this.session.$wrap == -1)
  14451. this.adjustWrapLimit();
  14452. };
  14453. this.getContainerElement = function() {
  14454. return this.container;
  14455. };
  14456. this.getMouseEventTarget = function() {
  14457. return this.scroller;
  14458. };
  14459. this.getTextAreaContainer = function() {
  14460. return this.container;
  14461. };
  14462. this.$moveTextAreaToCursor = function() {
  14463. if (!this.$keepTextAreaAtCursor)
  14464. return;
  14465. var config = this.layerConfig;
  14466. var posTop = this.$cursorLayer.$pixelPos.top;
  14467. var posLeft = this.$cursorLayer.$pixelPos.left;
  14468. posTop -= config.offset;
  14469. var style = this.textarea.style;
  14470. var h = this.lineHeight;
  14471. if (posTop < 0 || posTop > config.height - h) {
  14472. style.top = style.left = "0";
  14473. return;
  14474. }
  14475. var w = this.characterWidth;
  14476. if (this.$composition) {
  14477. var val = this.textarea.value.replace(/^\x01+/, "");
  14478. w *= (this.session.$getStringScreenWidth(val)[0]+2);
  14479. h += 2;
  14480. }
  14481. posLeft -= this.scrollLeft;
  14482. if (posLeft > this.$size.scrollerWidth - w)
  14483. posLeft = this.$size.scrollerWidth - w;
  14484. posLeft += this.gutterWidth;
  14485. style.height = h + "px";
  14486. style.width = w + "px";
  14487. style.left = Math.min(posLeft, this.$size.scrollerWidth - w) + "px";
  14488. style.top = Math.min(posTop, this.$size.height - h) + "px";
  14489. };
  14490. this.getFirstVisibleRow = function() {
  14491. return this.layerConfig.firstRow;
  14492. };
  14493. this.getFirstFullyVisibleRow = function() {
  14494. return this.layerConfig.firstRow + (this.layerConfig.offset === 0 ? 0 : 1);
  14495. };
  14496. this.getLastFullyVisibleRow = function() {
  14497. var config = this.layerConfig;
  14498. var lastRow = config.lastRow
  14499. var top = this.session.documentToScreenRow(lastRow, 0) * config.lineHeight;
  14500. if (top - this.session.getScrollTop() > config.height - config.lineHeight)
  14501. return lastRow - 1;
  14502. return lastRow;
  14503. };
  14504. this.getLastVisibleRow = function() {
  14505. return this.layerConfig.lastRow;
  14506. };
  14507. this.$padding = null;
  14508. this.setPadding = function(padding) {
  14509. this.$padding = padding;
  14510. this.$textLayer.setPadding(padding);
  14511. this.$cursorLayer.setPadding(padding);
  14512. this.$markerFront.setPadding(padding);
  14513. this.$markerBack.setPadding(padding);
  14514. this.$loop.schedule(this.CHANGE_FULL);
  14515. this.$updatePrintMargin();
  14516. };
  14517. this.setScrollMargin = function(top, bottom, left, right) {
  14518. var sm = this.scrollMargin;
  14519. sm.top = top|0;
  14520. sm.bottom = bottom|0;
  14521. sm.right = right|0;
  14522. sm.left = left|0;
  14523. sm.v = sm.top + sm.bottom;
  14524. sm.h = sm.left + sm.right;
  14525. if (sm.top && this.scrollTop <= 0 && this.session)
  14526. this.session.setScrollTop(-sm.top);
  14527. this.updateFull();
  14528. };
  14529. this.getHScrollBarAlwaysVisible = function() {
  14530. return this.$hScrollBarAlwaysVisible;
  14531. };
  14532. this.setHScrollBarAlwaysVisible = function(alwaysVisible) {
  14533. this.setOption("hScrollBarAlwaysVisible", alwaysVisible);
  14534. };
  14535. this.getVScrollBarAlwaysVisible = function() {
  14536. return this.$vScrollBarAlwaysVisible;
  14537. };
  14538. this.setVScrollBarAlwaysVisible = function(alwaysVisible) {
  14539. this.setOption("vScrollBarAlwaysVisible", alwaysVisible);
  14540. };
  14541. this.$updateScrollBarV = function() {
  14542. var scrollHeight = this.layerConfig.maxHeight;
  14543. var scrollerHeight = this.$size.scrollerHeight;
  14544. if (!this.$maxLines && this.$scrollPastEnd) {
  14545. scrollHeight -= (scrollerHeight - this.lineHeight) * this.$scrollPastEnd;
  14546. if (this.scrollTop > scrollHeight - scrollerHeight) {
  14547. scrollHeight = this.scrollTop + scrollerHeight;
  14548. this.scrollBarV.scrollTop = null;
  14549. }
  14550. }
  14551. this.scrollBarV.setScrollHeight(scrollHeight + this.scrollMargin.v);
  14552. this.scrollBarV.setScrollTop(this.scrollTop + this.scrollMargin.top);
  14553. };
  14554. this.$updateScrollBarH = function() {
  14555. this.scrollBarH.setScrollWidth(this.layerConfig.width + 2 * this.$padding + this.scrollMargin.h);
  14556. this.scrollBarH.setScrollLeft(this.scrollLeft + this.scrollMargin.left);
  14557. };
  14558. this.$frozen = false;
  14559. this.freeze = function() {
  14560. this.$frozen = true;
  14561. };
  14562. this.unfreeze = function() {
  14563. this.$frozen = false;
  14564. };
  14565. this.$renderChanges = function(changes, force) {
  14566. if (this.$changes) {
  14567. changes |= this.$changes;
  14568. this.$changes = 0;
  14569. }
  14570. if ((!this.session || !this.container.offsetWidth || this.$frozen) || (!changes && !force)) {
  14571. this.$changes |= changes;
  14572. return;
  14573. }
  14574. if (this.$size.$dirty) {
  14575. this.$changes |= changes;
  14576. return this.onResize(true);
  14577. }
  14578. if (!this.lineHeight) {
  14579. this.$textLayer.checkForSizeChanges();
  14580. }
  14581. this._signal("beforeRender");
  14582. var config = this.layerConfig;
  14583. if (changes & this.CHANGE_FULL ||
  14584. changes & this.CHANGE_SIZE ||
  14585. changes & this.CHANGE_TEXT ||
  14586. changes & this.CHANGE_LINES ||
  14587. changes & this.CHANGE_SCROLL ||
  14588. changes & this.CHANGE_H_SCROLL
  14589. ) {
  14590. changes |= this.$computeLayerConfig();
  14591. if (config.firstRow != this.layerConfig.firstRow && config.firstRowScreen == this.layerConfig.firstRowScreen) {
  14592. var st = this.scrollTop + (config.firstRow - this.layerConfig.firstRow) * this.lineHeight;
  14593. if (st > 0) {
  14594. this.scrollTop = st;
  14595. changes = changes | this.CHANGE_SCROLL;
  14596. changes |= this.$computeLayerConfig();
  14597. }
  14598. }
  14599. config = this.layerConfig;
  14600. this.$updateScrollBarV();
  14601. if (changes & this.CHANGE_H_SCROLL)
  14602. this.$updateScrollBarH();
  14603. this.$gutterLayer.element.style.marginTop = (-config.offset) + "px";
  14604. this.content.style.marginTop = (-config.offset) + "px";
  14605. this.content.style.width = config.width + 2 * this.$padding + "px";
  14606. this.content.style.height = config.minHeight + "px";
  14607. }
  14608. if (changes & this.CHANGE_H_SCROLL) {
  14609. this.content.style.marginLeft = -this.scrollLeft + "px";
  14610. this.scroller.className = this.scrollLeft <= 0 ? "ace_scroller" : "ace_scroller ace_scroll-left";
  14611. }
  14612. if (changes & this.CHANGE_FULL) {
  14613. this.$textLayer.update(config);
  14614. if (this.$showGutter)
  14615. this.$gutterLayer.update(config);
  14616. this.$markerBack.update(config);
  14617. this.$markerFront.update(config);
  14618. this.$cursorLayer.update(config);
  14619. this.$moveTextAreaToCursor();
  14620. this.$highlightGutterLine && this.$updateGutterLineHighlight();
  14621. this._signal("afterRender");
  14622. return;
  14623. }
  14624. if (changes & this.CHANGE_SCROLL) {
  14625. if (changes & this.CHANGE_TEXT || changes & this.CHANGE_LINES)
  14626. this.$textLayer.update(config);
  14627. else
  14628. this.$textLayer.scrollLines(config);
  14629. if (this.$showGutter)
  14630. this.$gutterLayer.update(config);
  14631. this.$markerBack.update(config);
  14632. this.$markerFront.update(config);
  14633. this.$cursorLayer.update(config);
  14634. this.$highlightGutterLine && this.$updateGutterLineHighlight();
  14635. this.$moveTextAreaToCursor();
  14636. this._signal("afterRender");
  14637. return;
  14638. }
  14639. if (changes & this.CHANGE_TEXT) {
  14640. this.$textLayer.update(config);
  14641. if (this.$showGutter)
  14642. this.$gutterLayer.update(config);
  14643. }
  14644. else if (changes & this.CHANGE_LINES) {
  14645. if (this.$updateLines() || (changes & this.CHANGE_GUTTER) && this.$showGutter)
  14646. this.$gutterLayer.update(config);
  14647. }
  14648. else if (changes & this.CHANGE_TEXT || changes & this.CHANGE_GUTTER) {
  14649. if (this.$showGutter)
  14650. this.$gutterLayer.update(config);
  14651. }
  14652. if (changes & this.CHANGE_CURSOR) {
  14653. this.$cursorLayer.update(config);
  14654. this.$moveTextAreaToCursor();
  14655. this.$highlightGutterLine && this.$updateGutterLineHighlight();
  14656. }
  14657. if (changes & (this.CHANGE_MARKER | this.CHANGE_MARKER_FRONT)) {
  14658. this.$markerFront.update(config);
  14659. }
  14660. if (changes & (this.CHANGE_MARKER | this.CHANGE_MARKER_BACK)) {
  14661. this.$markerBack.update(config);
  14662. }
  14663. this._signal("afterRender");
  14664. };
  14665. this.$autosize = function() {
  14666. var height = this.session.getScreenLength() * this.lineHeight;
  14667. var maxHeight = this.$maxLines * this.lineHeight;
  14668. var desiredHeight = Math.min(maxHeight,
  14669. Math.max((this.$minLines || 1) * this.lineHeight, height)
  14670. ) + this.scrollMargin.v + (this.$extraHeight || 0);
  14671. if (this.$horizScroll)
  14672. desiredHeight += this.scrollBarH.getHeight();
  14673. if (this.$maxPixelHeight && desiredHeight > this.$maxPixelHeight)
  14674. desiredHeight = this.$maxPixelHeight;
  14675. var vScroll = height > maxHeight;
  14676. if (desiredHeight != this.desiredHeight ||
  14677. this.$size.height != this.desiredHeight || vScroll != this.$vScroll) {
  14678. if (vScroll != this.$vScroll) {
  14679. this.$vScroll = vScroll;
  14680. this.scrollBarV.setVisible(vScroll);
  14681. }
  14682. var w = this.container.clientWidth;
  14683. this.container.style.height = desiredHeight + "px";
  14684. this.$updateCachedSize(true, this.$gutterWidth, w, desiredHeight);
  14685. this.desiredHeight = desiredHeight;
  14686. this._signal("autosize");
  14687. }
  14688. };
  14689. this.$computeLayerConfig = function() {
  14690. var session = this.session;
  14691. var size = this.$size;
  14692. var hideScrollbars = size.height <= 2 * this.lineHeight;
  14693. var screenLines = this.session.getScreenLength();
  14694. var maxHeight = screenLines * this.lineHeight;
  14695. var longestLine = this.$getLongestLine();
  14696. var horizScroll = !hideScrollbars && (this.$hScrollBarAlwaysVisible ||
  14697. size.scrollerWidth - longestLine - 2 * this.$padding < 0);
  14698. var hScrollChanged = this.$horizScroll !== horizScroll;
  14699. if (hScrollChanged) {
  14700. this.$horizScroll = horizScroll;
  14701. this.scrollBarH.setVisible(horizScroll);
  14702. }
  14703. var vScrollBefore = this.$vScroll; // autosize can change vscroll value in which case we need to update longestLine
  14704. if (this.$maxLines && this.lineHeight > 1)
  14705. this.$autosize();
  14706. var offset = this.scrollTop % this.lineHeight;
  14707. var minHeight = size.scrollerHeight + this.lineHeight;
  14708. var scrollPastEnd = !this.$maxLines && this.$scrollPastEnd
  14709. ? (size.scrollerHeight - this.lineHeight) * this.$scrollPastEnd
  14710. : 0;
  14711. maxHeight += scrollPastEnd;
  14712. var sm = this.scrollMargin;
  14713. this.session.setScrollTop(Math.max(-sm.top,
  14714. Math.min(this.scrollTop, maxHeight - size.scrollerHeight + sm.bottom)));
  14715. this.session.setScrollLeft(Math.max(-sm.left, Math.min(this.scrollLeft,
  14716. longestLine + 2 * this.$padding - size.scrollerWidth + sm.right)));
  14717. var vScroll = !hideScrollbars && (this.$vScrollBarAlwaysVisible ||
  14718. size.scrollerHeight - maxHeight + scrollPastEnd < 0 || this.scrollTop > sm.top);
  14719. var vScrollChanged = vScrollBefore !== vScroll;
  14720. if (vScrollChanged) {
  14721. this.$vScroll = vScroll;
  14722. this.scrollBarV.setVisible(vScroll);
  14723. }
  14724. var lineCount = Math.ceil(minHeight / this.lineHeight) - 1;
  14725. var firstRow = Math.max(0, Math.round((this.scrollTop - offset) / this.lineHeight));
  14726. var lastRow = firstRow + lineCount;
  14727. var firstRowScreen, firstRowHeight;
  14728. var lineHeight = this.lineHeight;
  14729. firstRow = session.screenToDocumentRow(firstRow, 0);
  14730. var foldLine = session.getFoldLine(firstRow);
  14731. if (foldLine) {
  14732. firstRow = foldLine.start.row;
  14733. }
  14734. firstRowScreen = session.documentToScreenRow(firstRow, 0);
  14735. firstRowHeight = session.getRowLength(firstRow) * lineHeight;
  14736. lastRow = Math.min(session.screenToDocumentRow(lastRow, 0), session.getLength() - 1);
  14737. minHeight = size.scrollerHeight + session.getRowLength(lastRow) * lineHeight +
  14738. firstRowHeight;
  14739. offset = this.scrollTop - firstRowScreen * lineHeight;
  14740. var changes = 0;
  14741. if (this.layerConfig.width != longestLine)
  14742. changes = this.CHANGE_H_SCROLL;
  14743. if (hScrollChanged || vScrollChanged) {
  14744. changes = this.$updateCachedSize(true, this.gutterWidth, size.width, size.height);
  14745. this._signal("scrollbarVisibilityChanged");
  14746. if (vScrollChanged)
  14747. longestLine = this.$getLongestLine();
  14748. }
  14749. this.layerConfig = {
  14750. width : longestLine,
  14751. padding : this.$padding,
  14752. firstRow : firstRow,
  14753. firstRowScreen: firstRowScreen,
  14754. lastRow : lastRow,
  14755. lineHeight : lineHeight,
  14756. characterWidth : this.characterWidth,
  14757. minHeight : minHeight,
  14758. maxHeight : maxHeight,
  14759. offset : offset,
  14760. gutterOffset : lineHeight ? Math.max(0, Math.ceil((offset + size.height - size.scrollerHeight) / lineHeight)) : 0,
  14761. height : this.$size.scrollerHeight
  14762. };
  14763. return changes;
  14764. };
  14765. this.$updateLines = function() {
  14766. if (!this.$changedLines) return;
  14767. var firstRow = this.$changedLines.firstRow;
  14768. var lastRow = this.$changedLines.lastRow;
  14769. this.$changedLines = null;
  14770. var layerConfig = this.layerConfig;
  14771. if (firstRow > layerConfig.lastRow + 1) { return; }
  14772. if (lastRow < layerConfig.firstRow) { return; }
  14773. if (lastRow === Infinity) {
  14774. if (this.$showGutter)
  14775. this.$gutterLayer.update(layerConfig);
  14776. this.$textLayer.update(layerConfig);
  14777. return;
  14778. }
  14779. this.$textLayer.updateLines(layerConfig, firstRow, lastRow);
  14780. return true;
  14781. };
  14782. this.$getLongestLine = function() {
  14783. var charCount = this.session.getScreenWidth();
  14784. if (this.showInvisibles && !this.session.$useWrapMode)
  14785. charCount += 1;
  14786. return Math.max(this.$size.scrollerWidth - 2 * this.$padding, Math.round(charCount * this.characterWidth));
  14787. };
  14788. this.updateFrontMarkers = function() {
  14789. this.$markerFront.setMarkers(this.session.getMarkers(true));
  14790. this.$loop.schedule(this.CHANGE_MARKER_FRONT);
  14791. };
  14792. this.updateBackMarkers = function() {
  14793. this.$markerBack.setMarkers(this.session.getMarkers());
  14794. this.$loop.schedule(this.CHANGE_MARKER_BACK);
  14795. };
  14796. this.addGutterDecoration = function(row, className){
  14797. this.$gutterLayer.addGutterDecoration(row, className);
  14798. };
  14799. this.removeGutterDecoration = function(row, className){
  14800. this.$gutterLayer.removeGutterDecoration(row, className);
  14801. };
  14802. this.updateBreakpoints = function(rows) {
  14803. this.$loop.schedule(this.CHANGE_GUTTER);
  14804. };
  14805. this.setAnnotations = function(annotations) {
  14806. this.$gutterLayer.setAnnotations(annotations);
  14807. this.$loop.schedule(this.CHANGE_GUTTER);
  14808. };
  14809. this.updateCursor = function() {
  14810. this.$loop.schedule(this.CHANGE_CURSOR);
  14811. };
  14812. this.hideCursor = function() {
  14813. this.$cursorLayer.hideCursor();
  14814. };
  14815. this.showCursor = function() {
  14816. this.$cursorLayer.showCursor();
  14817. };
  14818. this.scrollSelectionIntoView = function(anchor, lead, offset) {
  14819. this.scrollCursorIntoView(anchor, offset);
  14820. this.scrollCursorIntoView(lead, offset);
  14821. };
  14822. this.scrollCursorIntoView = function(cursor, offset, $viewMargin) {
  14823. if (this.$size.scrollerHeight === 0)
  14824. return;
  14825. var pos = this.$cursorLayer.getPixelPosition(cursor);
  14826. var left = pos.left;
  14827. var top = pos.top;
  14828. var topMargin = $viewMargin && $viewMargin.top || 0;
  14829. var bottomMargin = $viewMargin && $viewMargin.bottom || 0;
  14830. var scrollTop = this.$scrollAnimation ? this.session.getScrollTop() : this.scrollTop;
  14831. if (scrollTop + topMargin > top) {
  14832. if (offset && scrollTop + topMargin > top + this.lineHeight)
  14833. top -= offset * this.$size.scrollerHeight;
  14834. if (top === 0)
  14835. top = -this.scrollMargin.top;
  14836. this.session.setScrollTop(top);
  14837. } else if (scrollTop + this.$size.scrollerHeight - bottomMargin < top + this.lineHeight) {
  14838. if (offset && scrollTop + this.$size.scrollerHeight - bottomMargin < top - this.lineHeight)
  14839. top += offset * this.$size.scrollerHeight;
  14840. this.session.setScrollTop(top + this.lineHeight - this.$size.scrollerHeight);
  14841. }
  14842. var scrollLeft = this.scrollLeft;
  14843. if (scrollLeft > left) {
  14844. if (left < this.$padding + 2 * this.layerConfig.characterWidth)
  14845. left = -this.scrollMargin.left;
  14846. this.session.setScrollLeft(left);
  14847. } else if (scrollLeft + this.$size.scrollerWidth < left + this.characterWidth) {
  14848. this.session.setScrollLeft(Math.round(left + this.characterWidth - this.$size.scrollerWidth));
  14849. } else if (scrollLeft <= this.$padding && left - scrollLeft < this.characterWidth) {
  14850. this.session.setScrollLeft(0);
  14851. }
  14852. };
  14853. this.getScrollTop = function() {
  14854. return this.session.getScrollTop();
  14855. };
  14856. this.getScrollLeft = function() {
  14857. return this.session.getScrollLeft();
  14858. };
  14859. this.getScrollTopRow = function() {
  14860. return this.scrollTop / this.lineHeight;
  14861. };
  14862. this.getScrollBottomRow = function() {
  14863. return Math.max(0, Math.floor((this.scrollTop + this.$size.scrollerHeight) / this.lineHeight) - 1);
  14864. };
  14865. this.scrollToRow = function(row) {
  14866. this.session.setScrollTop(row * this.lineHeight);
  14867. };
  14868. this.alignCursor = function(cursor, alignment) {
  14869. if (typeof cursor == "number")
  14870. cursor = {row: cursor, column: 0};
  14871. var pos = this.$cursorLayer.getPixelPosition(cursor);
  14872. var h = this.$size.scrollerHeight - this.lineHeight;
  14873. var offset = pos.top - h * (alignment || 0);
  14874. this.session.setScrollTop(offset);
  14875. return offset;
  14876. };
  14877. this.STEPS = 8;
  14878. this.$calcSteps = function(fromValue, toValue){
  14879. var i = 0;
  14880. var l = this.STEPS;
  14881. var steps = [];
  14882. var func = function(t, x_min, dx) {
  14883. return dx * (Math.pow(t - 1, 3) + 1) + x_min;
  14884. };
  14885. for (i = 0; i < l; ++i)
  14886. steps.push(func(i / this.STEPS, fromValue, toValue - fromValue));
  14887. return steps;
  14888. };
  14889. this.scrollToLine = function(line, center, animate, callback) {
  14890. var pos = this.$cursorLayer.getPixelPosition({row: line, column: 0});
  14891. var offset = pos.top;
  14892. if (center)
  14893. offset -= this.$size.scrollerHeight / 2;
  14894. var initialScroll = this.scrollTop;
  14895. this.session.setScrollTop(offset);
  14896. if (animate !== false)
  14897. this.animateScrolling(initialScroll, callback);
  14898. };
  14899. this.animateScrolling = function(fromValue, callback) {
  14900. var toValue = this.scrollTop;
  14901. if (!this.$animatedScroll)
  14902. return;
  14903. var _self = this;
  14904. if (fromValue == toValue)
  14905. return;
  14906. if (this.$scrollAnimation) {
  14907. var oldSteps = this.$scrollAnimation.steps;
  14908. if (oldSteps.length) {
  14909. fromValue = oldSteps[0];
  14910. if (fromValue == toValue)
  14911. return;
  14912. }
  14913. }
  14914. var steps = _self.$calcSteps(fromValue, toValue);
  14915. this.$scrollAnimation = {from: fromValue, to: toValue, steps: steps};
  14916. clearInterval(this.$timer);
  14917. _self.session.setScrollTop(steps.shift());
  14918. _self.session.$scrollTop = toValue;
  14919. this.$timer = setInterval(function() {
  14920. if (steps.length) {
  14921. _self.session.setScrollTop(steps.shift());
  14922. _self.session.$scrollTop = toValue;
  14923. } else if (toValue != null) {
  14924. _self.session.$scrollTop = -1;
  14925. _self.session.setScrollTop(toValue);
  14926. toValue = null;
  14927. } else {
  14928. _self.$timer = clearInterval(_self.$timer);
  14929. _self.$scrollAnimation = null;
  14930. callback && callback();
  14931. }
  14932. }, 10);
  14933. };
  14934. this.scrollToY = function(scrollTop) {
  14935. if (this.scrollTop !== scrollTop) {
  14936. this.$loop.schedule(this.CHANGE_SCROLL);
  14937. this.scrollTop = scrollTop;
  14938. }
  14939. };
  14940. this.scrollToX = function(scrollLeft) {
  14941. if (this.scrollLeft !== scrollLeft)
  14942. this.scrollLeft = scrollLeft;
  14943. this.$loop.schedule(this.CHANGE_H_SCROLL);
  14944. };
  14945. this.scrollTo = function(x, y) {
  14946. this.session.setScrollTop(y);
  14947. this.session.setScrollLeft(y);
  14948. };
  14949. this.scrollBy = function(deltaX, deltaY) {
  14950. deltaY && this.session.setScrollTop(this.session.getScrollTop() + deltaY);
  14951. deltaX && this.session.setScrollLeft(this.session.getScrollLeft() + deltaX);
  14952. };
  14953. this.isScrollableBy = function(deltaX, deltaY) {
  14954. if (deltaY < 0 && this.session.getScrollTop() >= 1 - this.scrollMargin.top)
  14955. return true;
  14956. if (deltaY > 0 && this.session.getScrollTop() + this.$size.scrollerHeight
  14957. - this.layerConfig.maxHeight < -1 + this.scrollMargin.bottom)
  14958. return true;
  14959. if (deltaX < 0 && this.session.getScrollLeft() >= 1 - this.scrollMargin.left)
  14960. return true;
  14961. if (deltaX > 0 && this.session.getScrollLeft() + this.$size.scrollerWidth
  14962. - this.layerConfig.width < -1 + this.scrollMargin.right)
  14963. return true;
  14964. };
  14965. this.pixelToScreenCoordinates = function(x, y) {
  14966. var canvasPos = this.scroller.getBoundingClientRect();
  14967. var offset = (x + this.scrollLeft - canvasPos.left - this.$padding) / this.characterWidth;
  14968. var row = Math.floor((y + this.scrollTop - canvasPos.top) / this.lineHeight);
  14969. var col = Math.round(offset);
  14970. return {row: row, column: col, side: offset - col > 0 ? 1 : -1};
  14971. };
  14972. this.screenToTextCoordinates = function(x, y) {
  14973. var canvasPos = this.scroller.getBoundingClientRect();
  14974. var col = Math.round(
  14975. (x + this.scrollLeft - canvasPos.left - this.$padding) / this.characterWidth
  14976. );
  14977. var row = (y + this.scrollTop - canvasPos.top) / this.lineHeight;
  14978. return this.session.screenToDocumentPosition(row, Math.max(col, 0));
  14979. };
  14980. this.textToScreenCoordinates = function(row, column) {
  14981. var canvasPos = this.scroller.getBoundingClientRect();
  14982. var pos = this.session.documentToScreenPosition(row, column);
  14983. var x = this.$padding + Math.round(pos.column * this.characterWidth);
  14984. var y = pos.row * this.lineHeight;
  14985. return {
  14986. pageX: canvasPos.left + x - this.scrollLeft,
  14987. pageY: canvasPos.top + y - this.scrollTop
  14988. };
  14989. };
  14990. this.visualizeFocus = function() {
  14991. dom.addCssClass(this.container, "ace_focus");
  14992. };
  14993. this.visualizeBlur = function() {
  14994. dom.removeCssClass(this.container, "ace_focus");
  14995. };
  14996. this.showComposition = function(position) {
  14997. if (!this.$composition)
  14998. this.$composition = {
  14999. keepTextAreaAtCursor: this.$keepTextAreaAtCursor,
  15000. cssText: this.textarea.style.cssText
  15001. };
  15002. this.$keepTextAreaAtCursor = true;
  15003. dom.addCssClass(this.textarea, "ace_composition");
  15004. this.textarea.style.cssText = "";
  15005. this.$moveTextAreaToCursor();
  15006. };
  15007. this.setCompositionText = function(text) {
  15008. this.$moveTextAreaToCursor();
  15009. };
  15010. this.hideComposition = function() {
  15011. if (!this.$composition)
  15012. return;
  15013. dom.removeCssClass(this.textarea, "ace_composition");
  15014. this.$keepTextAreaAtCursor = this.$composition.keepTextAreaAtCursor;
  15015. this.textarea.style.cssText = this.$composition.cssText;
  15016. this.$composition = null;
  15017. };
  15018. this.setTheme = function(theme, cb) {
  15019. var _self = this;
  15020. this.$themeId = theme;
  15021. _self._dispatchEvent('themeChange',{theme:theme});
  15022. if (!theme || typeof theme == "string") {
  15023. var moduleName = theme || this.$options.theme.initialValue;
  15024. config.loadModule(["theme", moduleName], afterLoad);
  15025. } else {
  15026. afterLoad(theme);
  15027. }
  15028. function afterLoad(module) {
  15029. if (_self.$themeId != theme)
  15030. return cb && cb();
  15031. if (!module || !module.cssClass)
  15032. throw new Error("couldn't load module " + theme + " or it didn't call define");
  15033. dom.importCssString(
  15034. module.cssText,
  15035. module.cssClass,
  15036. _self.container.ownerDocument
  15037. );
  15038. if (_self.theme)
  15039. dom.removeCssClass(_self.container, _self.theme.cssClass);
  15040. var padding = "padding" in module ? module.padding
  15041. : "padding" in (_self.theme || {}) ? 4 : _self.$padding;
  15042. if (_self.$padding && padding != _self.$padding)
  15043. _self.setPadding(padding);
  15044. _self.$theme = module.cssClass;
  15045. _self.theme = module;
  15046. dom.addCssClass(_self.container, module.cssClass);
  15047. dom.setCssClass(_self.container, "ace_dark", module.isDark);
  15048. if (_self.$size) {
  15049. _self.$size.width = 0;
  15050. _self.$updateSizeAsync();
  15051. }
  15052. _self._dispatchEvent('themeLoaded', {theme:module});
  15053. cb && cb();
  15054. }
  15055. };
  15056. this.getTheme = function() {
  15057. return this.$themeId;
  15058. };
  15059. this.setStyle = function(style, include) {
  15060. dom.setCssClass(this.container, style, include !== false);
  15061. };
  15062. this.unsetStyle = function(style) {
  15063. dom.removeCssClass(this.container, style);
  15064. };
  15065. this.setCursorStyle = function(style) {
  15066. if (this.scroller.style.cursor != style)
  15067. this.scroller.style.cursor = style;
  15068. };
  15069. this.setMouseCursor = function(cursorStyle) {
  15070. this.scroller.style.cursor = cursorStyle;
  15071. };
  15072. this.destroy = function() {
  15073. this.$textLayer.destroy();
  15074. this.$cursorLayer.destroy();
  15075. };
  15076. }).call(VirtualRenderer.prototype);
  15077. config.defineOptions(VirtualRenderer.prototype, "renderer", {
  15078. animatedScroll: {initialValue: false},
  15079. showInvisibles: {
  15080. set: function(value) {
  15081. if (this.$textLayer.setShowInvisibles(value))
  15082. this.$loop.schedule(this.CHANGE_TEXT);
  15083. },
  15084. initialValue: false
  15085. },
  15086. showPrintMargin: {
  15087. set: function() { this.$updatePrintMargin(); },
  15088. initialValue: true
  15089. },
  15090. printMarginColumn: {
  15091. set: function() { this.$updatePrintMargin(); },
  15092. initialValue: 80
  15093. },
  15094. printMargin: {
  15095. set: function(val) {
  15096. if (typeof val == "number")
  15097. this.$printMarginColumn = val;
  15098. this.$showPrintMargin = !!val;
  15099. this.$updatePrintMargin();
  15100. },
  15101. get: function() {
  15102. return this.$showPrintMargin && this.$printMarginColumn;
  15103. }
  15104. },
  15105. showGutter: {
  15106. set: function(show){
  15107. this.$gutter.style.display = show ? "block" : "none";
  15108. this.$loop.schedule(this.CHANGE_FULL);
  15109. this.onGutterResize();
  15110. },
  15111. initialValue: true
  15112. },
  15113. fadeFoldWidgets: {
  15114. set: function(show) {
  15115. dom.setCssClass(this.$gutter, "ace_fade-fold-widgets", show);
  15116. },
  15117. initialValue: false
  15118. },
  15119. showFoldWidgets: {
  15120. set: function(show) {this.$gutterLayer.setShowFoldWidgets(show)},
  15121. initialValue: true
  15122. },
  15123. showLineNumbers: {
  15124. set: function(show) {
  15125. this.$gutterLayer.setShowLineNumbers(show);
  15126. this.$loop.schedule(this.CHANGE_GUTTER);
  15127. },
  15128. initialValue: true
  15129. },
  15130. displayIndentGuides: {
  15131. set: function(show) {
  15132. if (this.$textLayer.setDisplayIndentGuides(show))
  15133. this.$loop.schedule(this.CHANGE_TEXT);
  15134. },
  15135. initialValue: true
  15136. },
  15137. highlightGutterLine: {
  15138. set: function(shouldHighlight) {
  15139. if (!this.$gutterLineHighlight) {
  15140. this.$gutterLineHighlight = dom.createElement("div");
  15141. this.$gutterLineHighlight.className = "ace_gutter-active-line";
  15142. this.$gutter.appendChild(this.$gutterLineHighlight);
  15143. return;
  15144. }
  15145. this.$gutterLineHighlight.style.display = shouldHighlight ? "" : "none";
  15146. if (this.$cursorLayer.$pixelPos)
  15147. this.$updateGutterLineHighlight();
  15148. },
  15149. initialValue: false,
  15150. value: true
  15151. },
  15152. hScrollBarAlwaysVisible: {
  15153. set: function(val) {
  15154. if (!this.$hScrollBarAlwaysVisible || !this.$horizScroll)
  15155. this.$loop.schedule(this.CHANGE_SCROLL);
  15156. },
  15157. initialValue: false
  15158. },
  15159. vScrollBarAlwaysVisible: {
  15160. set: function(val) {
  15161. if (!this.$vScrollBarAlwaysVisible || !this.$vScroll)
  15162. this.$loop.schedule(this.CHANGE_SCROLL);
  15163. },
  15164. initialValue: false
  15165. },
  15166. fontSize: {
  15167. set: function(size) {
  15168. if (typeof size == "number")
  15169. size = size + "px";
  15170. this.container.style.fontSize = size;
  15171. this.updateFontSize();
  15172. },
  15173. initialValue: 12
  15174. },
  15175. fontFamily: {
  15176. set: function(name) {
  15177. this.container.style.fontFamily = name;
  15178. this.updateFontSize();
  15179. }
  15180. },
  15181. maxLines: {
  15182. set: function(val) {
  15183. this.updateFull();
  15184. }
  15185. },
  15186. minLines: {
  15187. set: function(val) {
  15188. this.updateFull();
  15189. }
  15190. },
  15191. maxPixelHeight: {
  15192. set: function(val) {
  15193. this.updateFull();
  15194. },
  15195. initialValue: 0
  15196. },
  15197. scrollPastEnd: {
  15198. set: function(val) {
  15199. val = +val || 0;
  15200. if (this.$scrollPastEnd == val)
  15201. return;
  15202. this.$scrollPastEnd = val;
  15203. this.$loop.schedule(this.CHANGE_SCROLL);
  15204. },
  15205. initialValue: 0,
  15206. handlesSet: true
  15207. },
  15208. fixedWidthGutter: {
  15209. set: function(val) {
  15210. this.$gutterLayer.$fixedWidth = !!val;
  15211. this.$loop.schedule(this.CHANGE_GUTTER);
  15212. }
  15213. },
  15214. theme: {
  15215. set: function(val) { this.setTheme(val) },
  15216. get: function() { return this.$themeId || this.theme; },
  15217. initialValue: "./theme/textmate",
  15218. handlesSet: true
  15219. }
  15220. });
  15221. exports.VirtualRenderer = VirtualRenderer;
  15222. });
  15223. define("ace/worker/worker_client",["require","exports","module","ace/lib/oop","ace/lib/net","ace/lib/event_emitter","ace/config"], function(require, exports, module) {
  15224. "use strict";
  15225. var oop = require("../lib/oop");
  15226. var net = require("../lib/net");
  15227. var EventEmitter = require("../lib/event_emitter").EventEmitter;
  15228. var config = require("../config");
  15229. function $workerBlob(workerUrl) {
  15230. var script = "importScripts('" + net.qualifyURL(workerUrl) + "');";
  15231. try {
  15232. return new Blob([script], {"type": "application/javascript"});
  15233. } catch (e) { // Backwards-compatibility
  15234. var BlobBuilder = window.BlobBuilder || window.WebKitBlobBuilder || window.MozBlobBuilder;
  15235. var blobBuilder = new BlobBuilder();
  15236. blobBuilder.append(script);
  15237. return blobBuilder.getBlob("application/javascript");
  15238. }
  15239. }
  15240. function createWorker(workerUrl) {
  15241. var blob = $workerBlob(workerUrl);
  15242. var URL = window.URL || window.webkitURL;
  15243. var blobURL = URL.createObjectURL(blob);
  15244. return new Worker(blobURL);
  15245. }
  15246. var WorkerClient = function(topLevelNamespaces, mod, classname, workerUrl, importScripts) {
  15247. this.$sendDeltaQueue = this.$sendDeltaQueue.bind(this);
  15248. this.changeListener = this.changeListener.bind(this);
  15249. this.onMessage = this.onMessage.bind(this);
  15250. if (require.nameToUrl && !require.toUrl)
  15251. require.toUrl = require.nameToUrl;
  15252. if (config.get("packaged") || !require.toUrl) {
  15253. workerUrl = workerUrl || config.moduleUrl(mod, "worker");
  15254. } else {
  15255. var normalizePath = this.$normalizePath;
  15256. workerUrl = workerUrl || normalizePath(require.toUrl("ace/worker/worker.js", null, "_"));
  15257. var tlns = {};
  15258. topLevelNamespaces.forEach(function(ns) {
  15259. tlns[ns] = normalizePath(require.toUrl(ns, null, "_").replace(/(\.js)?(\?.*)?$/, ""));
  15260. });
  15261. }
  15262. this.$worker = createWorker(workerUrl);
  15263. if (importScripts) {
  15264. this.send("importScripts", importScripts);
  15265. }
  15266. this.$worker.postMessage({
  15267. init : true,
  15268. tlns : tlns,
  15269. module : mod,
  15270. classname : classname
  15271. });
  15272. this.callbackId = 1;
  15273. this.callbacks = {};
  15274. this.$worker.onmessage = this.onMessage;
  15275. };
  15276. (function(){
  15277. oop.implement(this, EventEmitter);
  15278. this.onMessage = function(e) {
  15279. var msg = e.data;
  15280. switch (msg.type) {
  15281. case "event":
  15282. this._signal(msg.name, {data: msg.data});
  15283. break;
  15284. case "call":
  15285. var callback = this.callbacks[msg.id];
  15286. if (callback) {
  15287. callback(msg.data);
  15288. delete this.callbacks[msg.id];
  15289. }
  15290. break;
  15291. case "error":
  15292. this.reportError(msg.data);
  15293. break;
  15294. case "log":
  15295. window.console && console.log && console.log.apply(console, msg.data);
  15296. break;
  15297. }
  15298. };
  15299. this.reportError = function(err) {
  15300. window.console && console.error && console.error(err);
  15301. };
  15302. this.$normalizePath = function(path) {
  15303. return net.qualifyURL(path);
  15304. };
  15305. this.terminate = function() {
  15306. this._signal("terminate", {});
  15307. this.deltaQueue = null;
  15308. this.$worker.terminate();
  15309. this.$worker = null;
  15310. if (this.$doc)
  15311. this.$doc.off("change", this.changeListener);
  15312. this.$doc = null;
  15313. };
  15314. this.send = function(cmd, args) {
  15315. this.$worker.postMessage({command: cmd, args: args});
  15316. };
  15317. this.call = function(cmd, args, callback) {
  15318. if (callback) {
  15319. var id = this.callbackId++;
  15320. this.callbacks[id] = callback;
  15321. args.push(id);
  15322. }
  15323. this.send(cmd, args);
  15324. };
  15325. this.emit = function(event, data) {
  15326. try {
  15327. this.$worker.postMessage({event: event, data: {data: data.data}});
  15328. }
  15329. catch(ex) {
  15330. console.error(ex.stack);
  15331. }
  15332. };
  15333. this.attachToDocument = function(doc) {
  15334. if (this.$doc)
  15335. this.terminate();
  15336. this.$doc = doc;
  15337. this.call("setValue", [doc.getValue()]);
  15338. doc.on("change", this.changeListener);
  15339. };
  15340. this.changeListener = function(delta) {
  15341. if (!this.deltaQueue) {
  15342. this.deltaQueue = [];
  15343. setTimeout(this.$sendDeltaQueue, 0);
  15344. }
  15345. if (delta.action == "insert")
  15346. this.deltaQueue.push(delta.start, delta.lines);
  15347. else
  15348. this.deltaQueue.push(delta.start, delta.end);
  15349. };
  15350. this.$sendDeltaQueue = function() {
  15351. var q = this.deltaQueue;
  15352. if (!q) return;
  15353. this.deltaQueue = null;
  15354. if (q.length > 50 && q.length > this.$doc.getLength() >> 1) {
  15355. this.call("setValue", [this.$doc.getValue()]);
  15356. } else
  15357. this.emit("change", {data: q});
  15358. };
  15359. }).call(WorkerClient.prototype);
  15360. var UIWorkerClient = function(topLevelNamespaces, mod, classname) {
  15361. this.$sendDeltaQueue = this.$sendDeltaQueue.bind(this);
  15362. this.changeListener = this.changeListener.bind(this);
  15363. this.callbackId = 1;
  15364. this.callbacks = {};
  15365. this.messageBuffer = [];
  15366. var main = null;
  15367. var emitSync = false;
  15368. var sender = Object.create(EventEmitter);
  15369. var _self = this;
  15370. this.$worker = {};
  15371. this.$worker.terminate = function() {};
  15372. this.$worker.postMessage = function(e) {
  15373. _self.messageBuffer.push(e);
  15374. if (main) {
  15375. if (emitSync)
  15376. setTimeout(processNext);
  15377. else
  15378. processNext();
  15379. }
  15380. };
  15381. this.setEmitSync = function(val) { emitSync = val };
  15382. var processNext = function() {
  15383. var msg = _self.messageBuffer.shift();
  15384. if (msg.command)
  15385. main[msg.command].apply(main, msg.args);
  15386. else if (msg.event)
  15387. sender._signal(msg.event, msg.data);
  15388. };
  15389. sender.postMessage = function(msg) {
  15390. _self.onMessage({data: msg});
  15391. };
  15392. sender.callback = function(data, callbackId) {
  15393. this.postMessage({type: "call", id: callbackId, data: data});
  15394. };
  15395. sender.emit = function(name, data) {
  15396. this.postMessage({type: "event", name: name, data: data});
  15397. };
  15398. config.loadModule(["worker", mod], function(Main) {
  15399. main = new Main[classname](sender);
  15400. while (_self.messageBuffer.length)
  15401. processNext();
  15402. });
  15403. };
  15404. UIWorkerClient.prototype = WorkerClient.prototype;
  15405. exports.UIWorkerClient = UIWorkerClient;
  15406. exports.WorkerClient = WorkerClient;
  15407. exports.createWorker = createWorker;
  15408. });
  15409. define("ace/placeholder",["require","exports","module","ace/range","ace/lib/event_emitter","ace/lib/oop"], function(require, exports, module) {
  15410. "use strict";
  15411. var Range = require("./range").Range;
  15412. var EventEmitter = require("./lib/event_emitter").EventEmitter;
  15413. var oop = require("./lib/oop");
  15414. var PlaceHolder = function(session, length, pos, others, mainClass, othersClass) {
  15415. var _self = this;
  15416. this.length = length;
  15417. this.session = session;
  15418. this.doc = session.getDocument();
  15419. this.mainClass = mainClass;
  15420. this.othersClass = othersClass;
  15421. this.$onUpdate = this.onUpdate.bind(this);
  15422. this.doc.on("change", this.$onUpdate);
  15423. this.$others = others;
  15424. this.$onCursorChange = function() {
  15425. setTimeout(function() {
  15426. _self.onCursorChange();
  15427. });
  15428. };
  15429. this.$pos = pos;
  15430. var undoStack = session.getUndoManager().$undoStack || session.getUndoManager().$undostack || {length: -1};
  15431. this.$undoStackDepth = undoStack.length;
  15432. this.setup();
  15433. session.selection.on("changeCursor", this.$onCursorChange);
  15434. };
  15435. (function() {
  15436. oop.implement(this, EventEmitter);
  15437. this.setup = function() {
  15438. var _self = this;
  15439. var doc = this.doc;
  15440. var session = this.session;
  15441. this.selectionBefore = session.selection.toJSON();
  15442. if (session.selection.inMultiSelectMode)
  15443. session.selection.toSingleRange();
  15444. this.pos = doc.createAnchor(this.$pos.row, this.$pos.column);
  15445. var pos = this.pos;
  15446. pos.$insertRight = true;
  15447. pos.detach();
  15448. pos.markerId = session.addMarker(new Range(pos.row, pos.column, pos.row, pos.column + this.length), this.mainClass, null, false);
  15449. this.others = [];
  15450. this.$others.forEach(function(other) {
  15451. var anchor = doc.createAnchor(other.row, other.column);
  15452. anchor.$insertRight = true;
  15453. anchor.detach();
  15454. _self.others.push(anchor);
  15455. });
  15456. session.setUndoSelect(false);
  15457. };
  15458. this.showOtherMarkers = function() {
  15459. if (this.othersActive) return;
  15460. var session = this.session;
  15461. var _self = this;
  15462. this.othersActive = true;
  15463. this.others.forEach(function(anchor) {
  15464. anchor.markerId = session.addMarker(new Range(anchor.row, anchor.column, anchor.row, anchor.column+_self.length), _self.othersClass, null, false);
  15465. });
  15466. };
  15467. this.hideOtherMarkers = function() {
  15468. if (!this.othersActive) return;
  15469. this.othersActive = false;
  15470. for (var i = 0; i < this.others.length; i++) {
  15471. this.session.removeMarker(this.others[i].markerId);
  15472. }
  15473. };
  15474. this.onUpdate = function(delta) {
  15475. if (this.$updating)
  15476. return this.updateAnchors(delta);
  15477. var range = delta;
  15478. if (range.start.row !== range.end.row) return;
  15479. if (range.start.row !== this.pos.row) return;
  15480. this.$updating = true;
  15481. var lengthDiff = delta.action === "insert" ? range.end.column - range.start.column : range.start.column - range.end.column;
  15482. var inMainRange = range.start.column >= this.pos.column && range.start.column <= this.pos.column + this.length + 1;
  15483. var distanceFromStart = range.start.column - this.pos.column;
  15484. this.updateAnchors(delta);
  15485. if (inMainRange)
  15486. this.length += lengthDiff;
  15487. if (inMainRange && !this.session.$fromUndo) {
  15488. if (delta.action === 'insert') {
  15489. for (var i = this.others.length - 1; i >= 0; i--) {
  15490. var otherPos = this.others[i];
  15491. var newPos = {row: otherPos.row, column: otherPos.column + distanceFromStart};
  15492. this.doc.insertMergedLines(newPos, delta.lines);
  15493. }
  15494. } else if (delta.action === 'remove') {
  15495. for (var i = this.others.length - 1; i >= 0; i--) {
  15496. var otherPos = this.others[i];
  15497. var newPos = {row: otherPos.row, column: otherPos.column + distanceFromStart};
  15498. this.doc.remove(new Range(newPos.row, newPos.column, newPos.row, newPos.column - lengthDiff));
  15499. }
  15500. }
  15501. }
  15502. this.$updating = false;
  15503. this.updateMarkers();
  15504. };
  15505. this.updateAnchors = function(delta) {
  15506. this.pos.onChange(delta);
  15507. for (var i = this.others.length; i--;)
  15508. this.others[i].onChange(delta);
  15509. this.updateMarkers();
  15510. };
  15511. this.updateMarkers = function() {
  15512. if (this.$updating)
  15513. return;
  15514. var _self = this;
  15515. var session = this.session;
  15516. var updateMarker = function(pos, className) {
  15517. session.removeMarker(pos.markerId);
  15518. pos.markerId = session.addMarker(new Range(pos.row, pos.column, pos.row, pos.column+_self.length), className, null, false);
  15519. };
  15520. updateMarker(this.pos, this.mainClass);
  15521. for (var i = this.others.length; i--;)
  15522. updateMarker(this.others[i], this.othersClass);
  15523. };
  15524. this.onCursorChange = function(event) {
  15525. if (this.$updating || !this.session) return;
  15526. var pos = this.session.selection.getCursor();
  15527. if (pos.row === this.pos.row && pos.column >= this.pos.column && pos.column <= this.pos.column + this.length) {
  15528. this.showOtherMarkers();
  15529. this._emit("cursorEnter", event);
  15530. } else {
  15531. this.hideOtherMarkers();
  15532. this._emit("cursorLeave", event);
  15533. }
  15534. };
  15535. this.detach = function() {
  15536. this.session.removeMarker(this.pos && this.pos.markerId);
  15537. this.hideOtherMarkers();
  15538. this.doc.removeEventListener("change", this.$onUpdate);
  15539. this.session.selection.removeEventListener("changeCursor", this.$onCursorChange);
  15540. this.session.setUndoSelect(true);
  15541. this.session = null;
  15542. };
  15543. this.cancel = function() {
  15544. if (this.$undoStackDepth === -1)
  15545. return;
  15546. var undoManager = this.session.getUndoManager();
  15547. var undosRequired = (undoManager.$undoStack || undoManager.$undostack).length - this.$undoStackDepth;
  15548. for (var i = 0; i < undosRequired; i++) {
  15549. undoManager.undo(true);
  15550. }
  15551. if (this.selectionBefore)
  15552. this.session.selection.fromJSON(this.selectionBefore);
  15553. };
  15554. }).call(PlaceHolder.prototype);
  15555. exports.PlaceHolder = PlaceHolder;
  15556. });
  15557. define("ace/mouse/multi_select_handler",["require","exports","module","ace/lib/event","ace/lib/useragent"], function(require, exports, module) {
  15558. var event = require("../lib/event");
  15559. var useragent = require("../lib/useragent");
  15560. function isSamePoint(p1, p2) {
  15561. return p1.row == p2.row && p1.column == p2.column;
  15562. }
  15563. function onMouseDown(e) {
  15564. var ev = e.domEvent;
  15565. var alt = ev.altKey;
  15566. var shift = ev.shiftKey;
  15567. var ctrl = ev.ctrlKey;
  15568. var accel = e.getAccelKey();
  15569. var button = e.getButton();
  15570. if (ctrl && useragent.isMac)
  15571. button = ev.button;
  15572. if (e.editor.inMultiSelectMode && button == 2) {
  15573. e.editor.textInput.onContextMenu(e.domEvent);
  15574. return;
  15575. }
  15576. if (!ctrl && !alt && !accel) {
  15577. if (button === 0 && e.editor.inMultiSelectMode)
  15578. e.editor.exitMultiSelectMode();
  15579. return;
  15580. }
  15581. if (button !== 0)
  15582. return;
  15583. var editor = e.editor;
  15584. var selection = editor.selection;
  15585. var isMultiSelect = editor.inMultiSelectMode;
  15586. var pos = e.getDocumentPosition();
  15587. var cursor = selection.getCursor();
  15588. var inSelection = e.inSelection() || (selection.isEmpty() && isSamePoint(pos, cursor));
  15589. var mouseX = e.x, mouseY = e.y;
  15590. var onMouseSelection = function(e) {
  15591. mouseX = e.clientX;
  15592. mouseY = e.clientY;
  15593. };
  15594. var session = editor.session;
  15595. var screenAnchor = editor.renderer.pixelToScreenCoordinates(mouseX, mouseY);
  15596. var screenCursor = screenAnchor;
  15597. var selectionMode;
  15598. if (editor.$mouseHandler.$enableJumpToDef) {
  15599. if (ctrl && alt || accel && alt)
  15600. selectionMode = shift ? "block" : "add";
  15601. else if (alt && editor.$blockSelectEnabled)
  15602. selectionMode = "block";
  15603. } else {
  15604. if (accel && !alt) {
  15605. selectionMode = "add";
  15606. if (!isMultiSelect && shift)
  15607. return;
  15608. } else if (alt && editor.$blockSelectEnabled) {
  15609. selectionMode = "block";
  15610. }
  15611. }
  15612. if (selectionMode && useragent.isMac && ev.ctrlKey) {
  15613. editor.$mouseHandler.cancelContextMenu();
  15614. }
  15615. if (selectionMode == "add") {
  15616. if (!isMultiSelect && inSelection)
  15617. return; // dragging
  15618. if (!isMultiSelect) {
  15619. var range = selection.toOrientedRange();
  15620. editor.addSelectionMarker(range);
  15621. }
  15622. var oldRange = selection.rangeList.rangeAtPoint(pos);
  15623. editor.$blockScrolling++;
  15624. editor.inVirtualSelectionMode = true;
  15625. if (shift) {
  15626. oldRange = null;
  15627. range = selection.ranges[0] || range;
  15628. editor.removeSelectionMarker(range);
  15629. }
  15630. editor.once("mouseup", function() {
  15631. var tmpSel = selection.toOrientedRange();
  15632. if (oldRange && tmpSel.isEmpty() && isSamePoint(oldRange.cursor, tmpSel.cursor))
  15633. selection.substractPoint(tmpSel.cursor);
  15634. else {
  15635. if (shift) {
  15636. selection.substractPoint(range.cursor);
  15637. } else if (range) {
  15638. editor.removeSelectionMarker(range);
  15639. selection.addRange(range);
  15640. }
  15641. selection.addRange(tmpSel);
  15642. }
  15643. editor.$blockScrolling--;
  15644. editor.inVirtualSelectionMode = false;
  15645. });
  15646. } else if (selectionMode == "block") {
  15647. e.stop();
  15648. editor.inVirtualSelectionMode = true;
  15649. var initialRange;
  15650. var rectSel = [];
  15651. var blockSelect = function() {
  15652. var newCursor = editor.renderer.pixelToScreenCoordinates(mouseX, mouseY);
  15653. var cursor = session.screenToDocumentPosition(newCursor.row, newCursor.column);
  15654. if (isSamePoint(screenCursor, newCursor) && isSamePoint(cursor, selection.lead))
  15655. return;
  15656. screenCursor = newCursor;
  15657. editor.$blockScrolling++;
  15658. editor.selection.moveToPosition(cursor);
  15659. editor.renderer.scrollCursorIntoView();
  15660. editor.removeSelectionMarkers(rectSel);
  15661. rectSel = selection.rectangularRangeBlock(screenCursor, screenAnchor);
  15662. if (editor.$mouseHandler.$clickSelection && rectSel.length == 1 && rectSel[0].isEmpty())
  15663. rectSel[0] = editor.$mouseHandler.$clickSelection.clone();
  15664. rectSel.forEach(editor.addSelectionMarker, editor);
  15665. editor.updateSelectionMarkers();
  15666. editor.$blockScrolling--;
  15667. };
  15668. editor.$blockScrolling++;
  15669. if (isMultiSelect && !accel) {
  15670. selection.toSingleRange();
  15671. } else if (!isMultiSelect && accel) {
  15672. initialRange = selection.toOrientedRange();
  15673. editor.addSelectionMarker(initialRange);
  15674. }
  15675. if (shift)
  15676. screenAnchor = session.documentToScreenPosition(selection.lead);
  15677. else
  15678. selection.moveToPosition(pos);
  15679. editor.$blockScrolling--;
  15680. screenCursor = {row: -1, column: -1};
  15681. var onMouseSelectionEnd = function(e) {
  15682. clearInterval(timerId);
  15683. editor.removeSelectionMarkers(rectSel);
  15684. if (!rectSel.length)
  15685. rectSel = [selection.toOrientedRange()];
  15686. editor.$blockScrolling++;
  15687. if (initialRange) {
  15688. editor.removeSelectionMarker(initialRange);
  15689. selection.toSingleRange(initialRange);
  15690. }
  15691. for (var i = 0; i < rectSel.length; i++)
  15692. selection.addRange(rectSel[i]);
  15693. editor.inVirtualSelectionMode = false;
  15694. editor.$mouseHandler.$clickSelection = null;
  15695. editor.$blockScrolling--;
  15696. };
  15697. var onSelectionInterval = blockSelect;
  15698. event.capture(editor.container, onMouseSelection, onMouseSelectionEnd);
  15699. var timerId = setInterval(function() {onSelectionInterval();}, 20);
  15700. return e.preventDefault();
  15701. }
  15702. }
  15703. exports.onMouseDown = onMouseDown;
  15704. });
  15705. define("ace/commands/multi_select_commands",["require","exports","module","ace/keyboard/hash_handler"], function(require, exports, module) {
  15706. exports.defaultCommands = [{
  15707. name: "addCursorAbove",
  15708. exec: function(editor) { editor.selectMoreLines(-1); },
  15709. bindKey: {win: "Ctrl-Alt-Up", mac: "Ctrl-Alt-Up"},
  15710. scrollIntoView: "cursor",
  15711. readOnly: true
  15712. }, {
  15713. name: "addCursorBelow",
  15714. exec: function(editor) { editor.selectMoreLines(1); },
  15715. bindKey: {win: "Ctrl-Alt-Down", mac: "Ctrl-Alt-Down"},
  15716. scrollIntoView: "cursor",
  15717. readOnly: true
  15718. }, {
  15719. name: "addCursorAboveSkipCurrent",
  15720. exec: function(editor) { editor.selectMoreLines(-1, true); },
  15721. bindKey: {win: "Ctrl-Alt-Shift-Up", mac: "Ctrl-Alt-Shift-Up"},
  15722. scrollIntoView: "cursor",
  15723. readOnly: true
  15724. }, {
  15725. name: "addCursorBelowSkipCurrent",
  15726. exec: function(editor) { editor.selectMoreLines(1, true); },
  15727. bindKey: {win: "Ctrl-Alt-Shift-Down", mac: "Ctrl-Alt-Shift-Down"},
  15728. scrollIntoView: "cursor",
  15729. readOnly: true
  15730. }, {
  15731. name: "selectMoreBefore",
  15732. exec: function(editor) { editor.selectMore(-1); },
  15733. bindKey: {win: "Ctrl-Alt-Left", mac: "Ctrl-Alt-Left"},
  15734. scrollIntoView: "cursor",
  15735. readOnly: true
  15736. }, {
  15737. name: "selectMoreAfter",
  15738. exec: function(editor) { editor.selectMore(1); },
  15739. bindKey: {win: "Ctrl-Alt-Right", mac: "Ctrl-Alt-Right"},
  15740. scrollIntoView: "cursor",
  15741. readOnly: true
  15742. }, {
  15743. name: "selectNextBefore",
  15744. exec: function(editor) { editor.selectMore(-1, true); },
  15745. bindKey: {win: "Ctrl-Alt-Shift-Left", mac: "Ctrl-Alt-Shift-Left"},
  15746. scrollIntoView: "cursor",
  15747. readOnly: true
  15748. }, {
  15749. name: "selectNextAfter",
  15750. exec: function(editor) { editor.selectMore(1, true); },
  15751. bindKey: {win: "Ctrl-Alt-Shift-Right", mac: "Ctrl-Alt-Shift-Right"},
  15752. scrollIntoView: "cursor",
  15753. readOnly: true
  15754. }, {
  15755. name: "splitIntoLines",
  15756. exec: function(editor) { editor.multiSelect.splitIntoLines(); },
  15757. bindKey: {win: "Ctrl-Alt-L", mac: "Ctrl-Alt-L"},
  15758. readOnly: true
  15759. }, {
  15760. name: "alignCursors",
  15761. exec: function(editor) { editor.alignCursors(); },
  15762. bindKey: {win: "Ctrl-Alt-A", mac: "Ctrl-Alt-A"},
  15763. scrollIntoView: "cursor"
  15764. }, {
  15765. name: "findAll",
  15766. exec: function(editor) { editor.findAll(); },
  15767. bindKey: {win: "Ctrl-Alt-K", mac: "Ctrl-Alt-G"},
  15768. scrollIntoView: "cursor",
  15769. readOnly: true
  15770. }];
  15771. exports.multiSelectCommands = [{
  15772. name: "singleSelection",
  15773. bindKey: "esc",
  15774. exec: function(editor) { editor.exitMultiSelectMode(); },
  15775. scrollIntoView: "cursor",
  15776. readOnly: true,
  15777. isAvailable: function(editor) {return editor && editor.inMultiSelectMode}
  15778. }];
  15779. var HashHandler = require("../keyboard/hash_handler").HashHandler;
  15780. exports.keyboardHandler = new HashHandler(exports.multiSelectCommands);
  15781. });
  15782. define("ace/multi_select",["require","exports","module","ace/range_list","ace/range","ace/selection","ace/mouse/multi_select_handler","ace/lib/event","ace/lib/lang","ace/commands/multi_select_commands","ace/search","ace/edit_session","ace/editor","ace/config"], function(require, exports, module) {
  15783. var RangeList = require("./range_list").RangeList;
  15784. var Range = require("./range").Range;
  15785. var Selection = require("./selection").Selection;
  15786. var onMouseDown = require("./mouse/multi_select_handler").onMouseDown;
  15787. var event = require("./lib/event");
  15788. var lang = require("./lib/lang");
  15789. var commands = require("./commands/multi_select_commands");
  15790. exports.commands = commands.defaultCommands.concat(commands.multiSelectCommands);
  15791. var Search = require("./search").Search;
  15792. var search = new Search();
  15793. function find(session, needle, dir) {
  15794. search.$options.wrap = true;
  15795. search.$options.needle = needle;
  15796. search.$options.backwards = dir == -1;
  15797. return search.find(session);
  15798. }
  15799. var EditSession = require("./edit_session").EditSession;
  15800. (function() {
  15801. this.getSelectionMarkers = function() {
  15802. return this.$selectionMarkers;
  15803. };
  15804. }).call(EditSession.prototype);
  15805. (function() {
  15806. this.ranges = null;
  15807. this.rangeList = null;
  15808. this.addRange = function(range, $blockChangeEvents) {
  15809. if (!range)
  15810. return;
  15811. if (!this.inMultiSelectMode && this.rangeCount === 0) {
  15812. var oldRange = this.toOrientedRange();
  15813. this.rangeList.add(oldRange);
  15814. this.rangeList.add(range);
  15815. if (this.rangeList.ranges.length != 2) {
  15816. this.rangeList.removeAll();
  15817. return $blockChangeEvents || this.fromOrientedRange(range);
  15818. }
  15819. this.rangeList.removeAll();
  15820. this.rangeList.add(oldRange);
  15821. this.$onAddRange(oldRange);
  15822. }
  15823. if (!range.cursor)
  15824. range.cursor = range.end;
  15825. var removed = this.rangeList.add(range);
  15826. this.$onAddRange(range);
  15827. if (removed.length)
  15828. this.$onRemoveRange(removed);
  15829. if (this.rangeCount > 1 && !this.inMultiSelectMode) {
  15830. this._signal("multiSelect");
  15831. this.inMultiSelectMode = true;
  15832. this.session.$undoSelect = false;
  15833. this.rangeList.attach(this.session);
  15834. }
  15835. return $blockChangeEvents || this.fromOrientedRange(range);
  15836. };
  15837. this.toSingleRange = function(range) {
  15838. range = range || this.ranges[0];
  15839. var removed = this.rangeList.removeAll();
  15840. if (removed.length)
  15841. this.$onRemoveRange(removed);
  15842. range && this.fromOrientedRange(range);
  15843. };
  15844. this.substractPoint = function(pos) {
  15845. var removed = this.rangeList.substractPoint(pos);
  15846. if (removed) {
  15847. this.$onRemoveRange(removed);
  15848. return removed[0];
  15849. }
  15850. };
  15851. this.mergeOverlappingRanges = function() {
  15852. var removed = this.rangeList.merge();
  15853. if (removed.length)
  15854. this.$onRemoveRange(removed);
  15855. else if(this.ranges[0])
  15856. this.fromOrientedRange(this.ranges[0]);
  15857. };
  15858. this.$onAddRange = function(range) {
  15859. this.rangeCount = this.rangeList.ranges.length;
  15860. this.ranges.unshift(range);
  15861. this._signal("addRange", {range: range});
  15862. };
  15863. this.$onRemoveRange = function(removed) {
  15864. this.rangeCount = this.rangeList.ranges.length;
  15865. if (this.rangeCount == 1 && this.inMultiSelectMode) {
  15866. var lastRange = this.rangeList.ranges.pop();
  15867. removed.push(lastRange);
  15868. this.rangeCount = 0;
  15869. }
  15870. for (var i = removed.length; i--; ) {
  15871. var index = this.ranges.indexOf(removed[i]);
  15872. this.ranges.splice(index, 1);
  15873. }
  15874. this._signal("removeRange", {ranges: removed});
  15875. if (this.rangeCount === 0 && this.inMultiSelectMode) {
  15876. this.inMultiSelectMode = false;
  15877. this._signal("singleSelect");
  15878. this.session.$undoSelect = true;
  15879. this.rangeList.detach(this.session);
  15880. }
  15881. lastRange = lastRange || this.ranges[0];
  15882. if (lastRange && !lastRange.isEqual(this.getRange()))
  15883. this.fromOrientedRange(lastRange);
  15884. };
  15885. this.$initRangeList = function() {
  15886. if (this.rangeList)
  15887. return;
  15888. this.rangeList = new RangeList();
  15889. this.ranges = [];
  15890. this.rangeCount = 0;
  15891. };
  15892. this.getAllRanges = function() {
  15893. return this.rangeCount ? this.rangeList.ranges.concat() : [this.getRange()];
  15894. };
  15895. this.splitIntoLines = function () {
  15896. if (this.rangeCount > 1) {
  15897. var ranges = this.rangeList.ranges;
  15898. var lastRange = ranges[ranges.length - 1];
  15899. var range = Range.fromPoints(ranges[0].start, lastRange.end);
  15900. this.toSingleRange();
  15901. this.setSelectionRange(range, lastRange.cursor == lastRange.start);
  15902. } else {
  15903. var range = this.getRange();
  15904. var isBackwards = this.isBackwards();
  15905. var startRow = range.start.row;
  15906. var endRow = range.end.row;
  15907. if (startRow == endRow) {
  15908. if (isBackwards)
  15909. var start = range.end, end = range.start;
  15910. else
  15911. var start = range.start, end = range.end;
  15912. this.addRange(Range.fromPoints(end, end));
  15913. this.addRange(Range.fromPoints(start, start));
  15914. return;
  15915. }
  15916. var rectSel = [];
  15917. var r = this.getLineRange(startRow, true);
  15918. r.start.column = range.start.column;
  15919. rectSel.push(r);
  15920. for (var i = startRow + 1; i < endRow; i++)
  15921. rectSel.push(this.getLineRange(i, true));
  15922. r = this.getLineRange(endRow, true);
  15923. r.end.column = range.end.column;
  15924. rectSel.push(r);
  15925. rectSel.forEach(this.addRange, this);
  15926. }
  15927. };
  15928. this.toggleBlockSelection = function () {
  15929. if (this.rangeCount > 1) {
  15930. var ranges = this.rangeList.ranges;
  15931. var lastRange = ranges[ranges.length - 1];
  15932. var range = Range.fromPoints(ranges[0].start, lastRange.end);
  15933. this.toSingleRange();
  15934. this.setSelectionRange(range, lastRange.cursor == lastRange.start);
  15935. } else {
  15936. var cursor = this.session.documentToScreenPosition(this.selectionLead);
  15937. var anchor = this.session.documentToScreenPosition(this.selectionAnchor);
  15938. var rectSel = this.rectangularRangeBlock(cursor, anchor);
  15939. rectSel.forEach(this.addRange, this);
  15940. }
  15941. };
  15942. this.rectangularRangeBlock = function(screenCursor, screenAnchor, includeEmptyLines) {
  15943. var rectSel = [];
  15944. var xBackwards = screenCursor.column < screenAnchor.column;
  15945. if (xBackwards) {
  15946. var startColumn = screenCursor.column;
  15947. var endColumn = screenAnchor.column;
  15948. } else {
  15949. var startColumn = screenAnchor.column;
  15950. var endColumn = screenCursor.column;
  15951. }
  15952. var yBackwards = screenCursor.row < screenAnchor.row;
  15953. if (yBackwards) {
  15954. var startRow = screenCursor.row;
  15955. var endRow = screenAnchor.row;
  15956. } else {
  15957. var startRow = screenAnchor.row;
  15958. var endRow = screenCursor.row;
  15959. }
  15960. if (startColumn < 0)
  15961. startColumn = 0;
  15962. if (startRow < 0)
  15963. startRow = 0;
  15964. if (startRow == endRow)
  15965. includeEmptyLines = true;
  15966. for (var row = startRow; row <= endRow; row++) {
  15967. var range = Range.fromPoints(
  15968. this.session.screenToDocumentPosition(row, startColumn),
  15969. this.session.screenToDocumentPosition(row, endColumn)
  15970. );
  15971. if (range.isEmpty()) {
  15972. if (docEnd && isSamePoint(range.end, docEnd))
  15973. break;
  15974. var docEnd = range.end;
  15975. }
  15976. range.cursor = xBackwards ? range.start : range.end;
  15977. rectSel.push(range);
  15978. }
  15979. if (yBackwards)
  15980. rectSel.reverse();
  15981. if (!includeEmptyLines) {
  15982. var end = rectSel.length - 1;
  15983. while (rectSel[end].isEmpty() && end > 0)
  15984. end--;
  15985. if (end > 0) {
  15986. var start = 0;
  15987. while (rectSel[start].isEmpty())
  15988. start++;
  15989. }
  15990. for (var i = end; i >= start; i--) {
  15991. if (rectSel[i].isEmpty())
  15992. rectSel.splice(i, 1);
  15993. }
  15994. }
  15995. return rectSel;
  15996. };
  15997. }).call(Selection.prototype);
  15998. var Editor = require("./editor").Editor;
  15999. (function() {
  16000. this.updateSelectionMarkers = function() {
  16001. this.renderer.updateCursor();
  16002. this.renderer.updateBackMarkers();
  16003. };
  16004. this.addSelectionMarker = function(orientedRange) {
  16005. if (!orientedRange.cursor)
  16006. orientedRange.cursor = orientedRange.end;
  16007. var style = this.getSelectionStyle();
  16008. orientedRange.marker = this.session.addMarker(orientedRange, "ace_selection", style);
  16009. this.session.$selectionMarkers.push(orientedRange);
  16010. this.session.selectionMarkerCount = this.session.$selectionMarkers.length;
  16011. return orientedRange;
  16012. };
  16013. this.removeSelectionMarker = function(range) {
  16014. if (!range.marker)
  16015. return;
  16016. this.session.removeMarker(range.marker);
  16017. var index = this.session.$selectionMarkers.indexOf(range);
  16018. if (index != -1)
  16019. this.session.$selectionMarkers.splice(index, 1);
  16020. this.session.selectionMarkerCount = this.session.$selectionMarkers.length;
  16021. };
  16022. this.removeSelectionMarkers = function(ranges) {
  16023. var markerList = this.session.$selectionMarkers;
  16024. for (var i = ranges.length; i--; ) {
  16025. var range = ranges[i];
  16026. if (!range.marker)
  16027. continue;
  16028. this.session.removeMarker(range.marker);
  16029. var index = markerList.indexOf(range);
  16030. if (index != -1)
  16031. markerList.splice(index, 1);
  16032. }
  16033. this.session.selectionMarkerCount = markerList.length;
  16034. };
  16035. this.$onAddRange = function(e) {
  16036. this.addSelectionMarker(e.range);
  16037. this.renderer.updateCursor();
  16038. this.renderer.updateBackMarkers();
  16039. };
  16040. this.$onRemoveRange = function(e) {
  16041. this.removeSelectionMarkers(e.ranges);
  16042. this.renderer.updateCursor();
  16043. this.renderer.updateBackMarkers();
  16044. };
  16045. this.$onMultiSelect = function(e) {
  16046. if (this.inMultiSelectMode)
  16047. return;
  16048. this.inMultiSelectMode = true;
  16049. this.setStyle("ace_multiselect");
  16050. this.keyBinding.addKeyboardHandler(commands.keyboardHandler);
  16051. this.commands.setDefaultHandler("exec", this.$onMultiSelectExec);
  16052. this.renderer.updateCursor();
  16053. this.renderer.updateBackMarkers();
  16054. };
  16055. this.$onSingleSelect = function(e) {
  16056. if (this.session.multiSelect.inVirtualMode)
  16057. return;
  16058. this.inMultiSelectMode = false;
  16059. this.unsetStyle("ace_multiselect");
  16060. this.keyBinding.removeKeyboardHandler(commands.keyboardHandler);
  16061. this.commands.removeDefaultHandler("exec", this.$onMultiSelectExec);
  16062. this.renderer.updateCursor();
  16063. this.renderer.updateBackMarkers();
  16064. this._emit("changeSelection");
  16065. };
  16066. this.$onMultiSelectExec = function(e) {
  16067. var command = e.command;
  16068. var editor = e.editor;
  16069. if (!editor.multiSelect)
  16070. return;
  16071. if (!command.multiSelectAction) {
  16072. var result = command.exec(editor, e.args || {});
  16073. editor.multiSelect.addRange(editor.multiSelect.toOrientedRange());
  16074. editor.multiSelect.mergeOverlappingRanges();
  16075. } else if (command.multiSelectAction == "forEach") {
  16076. result = editor.forEachSelection(command, e.args);
  16077. } else if (command.multiSelectAction == "forEachLine") {
  16078. result = editor.forEachSelection(command, e.args, true);
  16079. } else if (command.multiSelectAction == "single") {
  16080. editor.exitMultiSelectMode();
  16081. result = command.exec(editor, e.args || {});
  16082. } else {
  16083. result = command.multiSelectAction(editor, e.args || {});
  16084. }
  16085. return result;
  16086. };
  16087. this.forEachSelection = function(cmd, args, options) {
  16088. if (this.inVirtualSelectionMode)
  16089. return;
  16090. var keepOrder = options && options.keepOrder;
  16091. var $byLines = options == true || options && options.$byLines
  16092. var session = this.session;
  16093. var selection = this.selection;
  16094. var rangeList = selection.rangeList;
  16095. var ranges = (keepOrder ? selection : rangeList).ranges;
  16096. var result;
  16097. if (!ranges.length)
  16098. return cmd.exec ? cmd.exec(this, args || {}) : cmd(this, args || {});
  16099. var reg = selection._eventRegistry;
  16100. selection._eventRegistry = {};
  16101. var tmpSel = new Selection(session);
  16102. this.inVirtualSelectionMode = true;
  16103. for (var i = ranges.length; i--;) {
  16104. if ($byLines) {
  16105. while (i > 0 && ranges[i].start.row == ranges[i - 1].end.row)
  16106. i--;
  16107. }
  16108. tmpSel.fromOrientedRange(ranges[i]);
  16109. tmpSel.index = i;
  16110. this.selection = session.selection = tmpSel;
  16111. var cmdResult = cmd.exec ? cmd.exec(this, args || {}) : cmd(this, args || {});
  16112. if (!result && cmdResult !== undefined)
  16113. result = cmdResult;
  16114. tmpSel.toOrientedRange(ranges[i]);
  16115. }
  16116. tmpSel.detach();
  16117. this.selection = session.selection = selection;
  16118. this.inVirtualSelectionMode = false;
  16119. selection._eventRegistry = reg;
  16120. selection.mergeOverlappingRanges();
  16121. var anim = this.renderer.$scrollAnimation;
  16122. this.onCursorChange();
  16123. this.onSelectionChange();
  16124. if (anim && anim.from == anim.to)
  16125. this.renderer.animateScrolling(anim.from);
  16126. return result;
  16127. };
  16128. this.exitMultiSelectMode = function() {
  16129. if (!this.inMultiSelectMode || this.inVirtualSelectionMode)
  16130. return;
  16131. this.multiSelect.toSingleRange();
  16132. };
  16133. this.getSelectedText = function() {
  16134. var text = "";
  16135. if (this.inMultiSelectMode && !this.inVirtualSelectionMode) {
  16136. var ranges = this.multiSelect.rangeList.ranges;
  16137. var buf = [];
  16138. for (var i = 0; i < ranges.length; i++) {
  16139. buf.push(this.session.getTextRange(ranges[i]));
  16140. }
  16141. var nl = this.session.getDocument().getNewLineCharacter();
  16142. text = buf.join(nl);
  16143. if (text.length == (buf.length - 1) * nl.length)
  16144. text = "";
  16145. } else if (!this.selection.isEmpty()) {
  16146. text = this.session.getTextRange(this.getSelectionRange());
  16147. }
  16148. return text;
  16149. };
  16150. this.$checkMultiselectChange = function(e, anchor) {
  16151. if (this.inMultiSelectMode && !this.inVirtualSelectionMode) {
  16152. var range = this.multiSelect.ranges[0];
  16153. if (this.multiSelect.isEmpty() && anchor == this.multiSelect.anchor)
  16154. return;
  16155. var pos = anchor == this.multiSelect.anchor
  16156. ? range.cursor == range.start ? range.end : range.start
  16157. : range.cursor;
  16158. if (pos.row != anchor.row
  16159. || this.session.$clipPositionToDocument(pos.row, pos.column).column != anchor.column)
  16160. this.multiSelect.toSingleRange(this.multiSelect.toOrientedRange());
  16161. }
  16162. };
  16163. this.findAll = function(needle, options, additive) {
  16164. options = options || {};
  16165. options.needle = needle || options.needle;
  16166. if (options.needle == undefined) {
  16167. var range = this.selection.isEmpty()
  16168. ? this.selection.getWordRange()
  16169. : this.selection.getRange();
  16170. options.needle = this.session.getTextRange(range);
  16171. }
  16172. this.$search.set(options);
  16173. var ranges = this.$search.findAll(this.session);
  16174. if (!ranges.length)
  16175. return 0;
  16176. this.$blockScrolling += 1;
  16177. var selection = this.multiSelect;
  16178. if (!additive)
  16179. selection.toSingleRange(ranges[0]);
  16180. for (var i = ranges.length; i--; )
  16181. selection.addRange(ranges[i], true);
  16182. if (range && selection.rangeList.rangeAtPoint(range.start))
  16183. selection.addRange(range, true);
  16184. this.$blockScrolling -= 1;
  16185. return ranges.length;
  16186. };
  16187. this.selectMoreLines = function(dir, skip) {
  16188. var range = this.selection.toOrientedRange();
  16189. var isBackwards = range.cursor == range.end;
  16190. var screenLead = this.session.documentToScreenPosition(range.cursor);
  16191. if (this.selection.$desiredColumn)
  16192. screenLead.column = this.selection.$desiredColumn;
  16193. var lead = this.session.screenToDocumentPosition(screenLead.row + dir, screenLead.column);
  16194. if (!range.isEmpty()) {
  16195. var screenAnchor = this.session.documentToScreenPosition(isBackwards ? range.end : range.start);
  16196. var anchor = this.session.screenToDocumentPosition(screenAnchor.row + dir, screenAnchor.column);
  16197. } else {
  16198. var anchor = lead;
  16199. }
  16200. if (isBackwards) {
  16201. var newRange = Range.fromPoints(lead, anchor);
  16202. newRange.cursor = newRange.start;
  16203. } else {
  16204. var newRange = Range.fromPoints(anchor, lead);
  16205. newRange.cursor = newRange.end;
  16206. }
  16207. newRange.desiredColumn = screenLead.column;
  16208. if (!this.selection.inMultiSelectMode) {
  16209. this.selection.addRange(range);
  16210. } else {
  16211. if (skip)
  16212. var toRemove = range.cursor;
  16213. }
  16214. this.selection.addRange(newRange);
  16215. if (toRemove)
  16216. this.selection.substractPoint(toRemove);
  16217. };
  16218. this.transposeSelections = function(dir) {
  16219. var session = this.session;
  16220. var sel = session.multiSelect;
  16221. var all = sel.ranges;
  16222. for (var i = all.length; i--; ) {
  16223. var range = all[i];
  16224. if (range.isEmpty()) {
  16225. var tmp = session.getWordRange(range.start.row, range.start.column);
  16226. range.start.row = tmp.start.row;
  16227. range.start.column = tmp.start.column;
  16228. range.end.row = tmp.end.row;
  16229. range.end.column = tmp.end.column;
  16230. }
  16231. }
  16232. sel.mergeOverlappingRanges();
  16233. var words = [];
  16234. for (var i = all.length; i--; ) {
  16235. var range = all[i];
  16236. words.unshift(session.getTextRange(range));
  16237. }
  16238. if (dir < 0)
  16239. words.unshift(words.pop());
  16240. else
  16241. words.push(words.shift());
  16242. for (var i = all.length; i--; ) {
  16243. var range = all[i];
  16244. var tmp = range.clone();
  16245. session.replace(range, words[i]);
  16246. range.start.row = tmp.start.row;
  16247. range.start.column = tmp.start.column;
  16248. }
  16249. };
  16250. this.selectMore = function(dir, skip, stopAtFirst) {
  16251. var session = this.session;
  16252. var sel = session.multiSelect;
  16253. var range = sel.toOrientedRange();
  16254. if (range.isEmpty()) {
  16255. range = session.getWordRange(range.start.row, range.start.column);
  16256. range.cursor = dir == -1 ? range.start : range.end;
  16257. this.multiSelect.addRange(range);
  16258. if (stopAtFirst)
  16259. return;
  16260. }
  16261. var needle = session.getTextRange(range);
  16262. var newRange = find(session, needle, dir);
  16263. if (newRange) {
  16264. newRange.cursor = dir == -1 ? newRange.start : newRange.end;
  16265. this.$blockScrolling += 1;
  16266. this.session.unfold(newRange);
  16267. this.multiSelect.addRange(newRange);
  16268. this.$blockScrolling -= 1;
  16269. this.renderer.scrollCursorIntoView(null, 0.5);
  16270. }
  16271. if (skip)
  16272. this.multiSelect.substractPoint(range.cursor);
  16273. };
  16274. this.alignCursors = function() {
  16275. var session = this.session;
  16276. var sel = session.multiSelect;
  16277. var ranges = sel.ranges;
  16278. var row = -1;
  16279. var sameRowRanges = ranges.filter(function(r) {
  16280. if (r.cursor.row == row)
  16281. return true;
  16282. row = r.cursor.row;
  16283. });
  16284. if (!ranges.length || sameRowRanges.length == ranges.length - 1) {
  16285. var range = this.selection.getRange();
  16286. var fr = range.start.row, lr = range.end.row;
  16287. var guessRange = fr == lr;
  16288. if (guessRange) {
  16289. var max = this.session.getLength();
  16290. var line;
  16291. do {
  16292. line = this.session.getLine(lr);
  16293. } while (/[=:]/.test(line) && ++lr < max);
  16294. do {
  16295. line = this.session.getLine(fr);
  16296. } while (/[=:]/.test(line) && --fr > 0);
  16297. if (fr < 0) fr = 0;
  16298. if (lr >= max) lr = max - 1;
  16299. }
  16300. var lines = this.session.removeFullLines(fr, lr);
  16301. lines = this.$reAlignText(lines, guessRange);
  16302. this.session.insert({row: fr, column: 0}, lines.join("\n") + "\n");
  16303. if (!guessRange) {
  16304. range.start.column = 0;
  16305. range.end.column = lines[lines.length - 1].length;
  16306. }
  16307. this.selection.setRange(range);
  16308. } else {
  16309. sameRowRanges.forEach(function(r) {
  16310. sel.substractPoint(r.cursor);
  16311. });
  16312. var maxCol = 0;
  16313. var minSpace = Infinity;
  16314. var spaceOffsets = ranges.map(function(r) {
  16315. var p = r.cursor;
  16316. var line = session.getLine(p.row);
  16317. var spaceOffset = line.substr(p.column).search(/\S/g);
  16318. if (spaceOffset == -1)
  16319. spaceOffset = 0;
  16320. if (p.column > maxCol)
  16321. maxCol = p.column;
  16322. if (spaceOffset < minSpace)
  16323. minSpace = spaceOffset;
  16324. return spaceOffset;
  16325. });
  16326. ranges.forEach(function(r, i) {
  16327. var p = r.cursor;
  16328. var l = maxCol - p.column;
  16329. var d = spaceOffsets[i] - minSpace;
  16330. if (l > d)
  16331. session.insert(p, lang.stringRepeat(" ", l - d));
  16332. else
  16333. session.remove(new Range(p.row, p.column, p.row, p.column - l + d));
  16334. r.start.column = r.end.column = maxCol;
  16335. r.start.row = r.end.row = p.row;
  16336. r.cursor = r.end;
  16337. });
  16338. sel.fromOrientedRange(ranges[0]);
  16339. this.renderer.updateCursor();
  16340. this.renderer.updateBackMarkers();
  16341. }
  16342. };
  16343. this.$reAlignText = function(lines, forceLeft) {
  16344. var isLeftAligned = true, isRightAligned = true;
  16345. var startW, textW, endW;
  16346. return lines.map(function(line) {
  16347. var m = line.match(/(\s*)(.*?)(\s*)([=:].*)/);
  16348. if (!m)
  16349. return [line];
  16350. if (startW == null) {
  16351. startW = m[1].length;
  16352. textW = m[2].length;
  16353. endW = m[3].length;
  16354. return m;
  16355. }
  16356. if (startW + textW + endW != m[1].length + m[2].length + m[3].length)
  16357. isRightAligned = false;
  16358. if (startW != m[1].length)
  16359. isLeftAligned = false;
  16360. if (startW > m[1].length)
  16361. startW = m[1].length;
  16362. if (textW < m[2].length)
  16363. textW = m[2].length;
  16364. if (endW > m[3].length)
  16365. endW = m[3].length;
  16366. return m;
  16367. }).map(forceLeft ? alignLeft :
  16368. isLeftAligned ? isRightAligned ? alignRight : alignLeft : unAlign);
  16369. function spaces(n) {
  16370. return lang.stringRepeat(" ", n);
  16371. }
  16372. function alignLeft(m) {
  16373. return !m[2] ? m[0] : spaces(startW) + m[2]
  16374. + spaces(textW - m[2].length + endW)
  16375. + m[4].replace(/^([=:])\s+/, "$1 ");
  16376. }
  16377. function alignRight(m) {
  16378. return !m[2] ? m[0] : spaces(startW + textW - m[2].length) + m[2]
  16379. + spaces(endW, " ")
  16380. + m[4].replace(/^([=:])\s+/, "$1 ");
  16381. }
  16382. function unAlign(m) {
  16383. return !m[2] ? m[0] : spaces(startW) + m[2]
  16384. + spaces(endW)
  16385. + m[4].replace(/^([=:])\s+/, "$1 ");
  16386. }
  16387. };
  16388. }).call(Editor.prototype);
  16389. function isSamePoint(p1, p2) {
  16390. return p1.row == p2.row && p1.column == p2.column;
  16391. }
  16392. exports.onSessionChange = function(e) {
  16393. var session = e.session;
  16394. if (session && !session.multiSelect) {
  16395. session.$selectionMarkers = [];
  16396. session.selection.$initRangeList();
  16397. session.multiSelect = session.selection;
  16398. }
  16399. this.multiSelect = session && session.multiSelect;
  16400. var oldSession = e.oldSession;
  16401. if (oldSession) {
  16402. oldSession.multiSelect.off("addRange", this.$onAddRange);
  16403. oldSession.multiSelect.off("removeRange", this.$onRemoveRange);
  16404. oldSession.multiSelect.off("multiSelect", this.$onMultiSelect);
  16405. oldSession.multiSelect.off("singleSelect", this.$onSingleSelect);
  16406. oldSession.multiSelect.lead.off("change", this.$checkMultiselectChange);
  16407. oldSession.multiSelect.anchor.off("change", this.$checkMultiselectChange);
  16408. }
  16409. if (session) {
  16410. session.multiSelect.on("addRange", this.$onAddRange);
  16411. session.multiSelect.on("removeRange", this.$onRemoveRange);
  16412. session.multiSelect.on("multiSelect", this.$onMultiSelect);
  16413. session.multiSelect.on("singleSelect", this.$onSingleSelect);
  16414. session.multiSelect.lead.on("change", this.$checkMultiselectChange);
  16415. session.multiSelect.anchor.on("change", this.$checkMultiselectChange);
  16416. }
  16417. if (session && this.inMultiSelectMode != session.selection.inMultiSelectMode) {
  16418. if (session.selection.inMultiSelectMode)
  16419. this.$onMultiSelect();
  16420. else
  16421. this.$onSingleSelect();
  16422. }
  16423. };
  16424. function MultiSelect(editor) {
  16425. if (editor.$multiselectOnSessionChange)
  16426. return;
  16427. editor.$onAddRange = editor.$onAddRange.bind(editor);
  16428. editor.$onRemoveRange = editor.$onRemoveRange.bind(editor);
  16429. editor.$onMultiSelect = editor.$onMultiSelect.bind(editor);
  16430. editor.$onSingleSelect = editor.$onSingleSelect.bind(editor);
  16431. editor.$multiselectOnSessionChange = exports.onSessionChange.bind(editor);
  16432. editor.$checkMultiselectChange = editor.$checkMultiselectChange.bind(editor);
  16433. editor.$multiselectOnSessionChange(editor);
  16434. editor.on("changeSession", editor.$multiselectOnSessionChange);
  16435. editor.on("mousedown", onMouseDown);
  16436. editor.commands.addCommands(commands.defaultCommands);
  16437. addAltCursorListeners(editor);
  16438. }
  16439. function addAltCursorListeners(editor){
  16440. var el = editor.textInput.getElement();
  16441. var altCursor = false;
  16442. event.addListener(el, "keydown", function(e) {
  16443. var altDown = e.keyCode == 18 && !(e.ctrlKey || e.shiftKey || e.metaKey);
  16444. if (editor.$blockSelectEnabled && altDown) {
  16445. if (!altCursor) {
  16446. editor.renderer.setMouseCursor("crosshair");
  16447. altCursor = true;
  16448. }
  16449. } else if (altCursor) {
  16450. reset();
  16451. }
  16452. });
  16453. event.addListener(el, "keyup", reset);
  16454. event.addListener(el, "blur", reset);
  16455. function reset(e) {
  16456. if (altCursor) {
  16457. editor.renderer.setMouseCursor("");
  16458. altCursor = false;
  16459. }
  16460. }
  16461. }
  16462. exports.MultiSelect = MultiSelect;
  16463. require("./config").defineOptions(Editor.prototype, "editor", {
  16464. enableMultiselect: {
  16465. set: function(val) {
  16466. MultiSelect(this);
  16467. if (val) {
  16468. this.on("changeSession", this.$multiselectOnSessionChange);
  16469. this.on("mousedown", onMouseDown);
  16470. } else {
  16471. this.off("changeSession", this.$multiselectOnSessionChange);
  16472. this.off("mousedown", onMouseDown);
  16473. }
  16474. },
  16475. value: true
  16476. },
  16477. enableBlockSelect: {
  16478. set: function(val) {
  16479. this.$blockSelectEnabled = val;
  16480. },
  16481. value: true
  16482. }
  16483. });
  16484. });
  16485. define("ace/mode/folding/fold_mode",["require","exports","module","ace/range"], function(require, exports, module) {
  16486. "use strict";
  16487. var Range = require("../../range").Range;
  16488. var FoldMode = exports.FoldMode = function() {};
  16489. (function() {
  16490. this.foldingStartMarker = null;
  16491. this.foldingStopMarker = null;
  16492. this.getFoldWidget = function(session, foldStyle, row) {
  16493. var line = session.getLine(row);
  16494. if (this.foldingStartMarker.test(line))
  16495. return "start";
  16496. if (foldStyle == "markbeginend"
  16497. && this.foldingStopMarker
  16498. && this.foldingStopMarker.test(line))
  16499. return "end";
  16500. return "";
  16501. };
  16502. this.getFoldWidgetRange = function(session, foldStyle, row) {
  16503. return null;
  16504. };
  16505. this.indentationBlock = function(session, row, column) {
  16506. var re = /\S/;
  16507. var line = session.getLine(row);
  16508. var startLevel = line.search(re);
  16509. if (startLevel == -1)
  16510. return;
  16511. var startColumn = column || line.length;
  16512. var maxRow = session.getLength();
  16513. var startRow = row;
  16514. var endRow = row;
  16515. while (++row < maxRow) {
  16516. var level = session.getLine(row).search(re);
  16517. if (level == -1)
  16518. continue;
  16519. if (level <= startLevel)
  16520. break;
  16521. endRow = row;
  16522. }
  16523. if (endRow > startRow) {
  16524. var endColumn = session.getLine(endRow).length;
  16525. return new Range(startRow, startColumn, endRow, endColumn);
  16526. }
  16527. };
  16528. this.openingBracketBlock = function(session, bracket, row, column, typeRe) {
  16529. var start = {row: row, column: column + 1};
  16530. var end = session.$findClosingBracket(bracket, start, typeRe);
  16531. if (!end)
  16532. return;
  16533. var fw = session.foldWidgets[end.row];
  16534. if (fw == null)
  16535. fw = session.getFoldWidget(end.row);
  16536. if (fw == "start" && end.row > start.row) {
  16537. end.row --;
  16538. end.column = session.getLine(end.row).length;
  16539. }
  16540. return Range.fromPoints(start, end);
  16541. };
  16542. this.closingBracketBlock = function(session, bracket, row, column, typeRe) {
  16543. var end = {row: row, column: column};
  16544. var start = session.$findOpeningBracket(bracket, end);
  16545. if (!start)
  16546. return;
  16547. start.column++;
  16548. end.column--;
  16549. return Range.fromPoints(start, end);
  16550. };
  16551. }).call(FoldMode.prototype);
  16552. });
  16553. define("ace/theme/textmate",["require","exports","module","ace/lib/dom"], function(require, exports, module) {
  16554. "use strict";
  16555. exports.isDark = false;
  16556. exports.cssClass = "ace-tm";
  16557. exports.cssText = ".ace-tm .ace_gutter {\
  16558. background: #f0f0f0;\
  16559. color: #333;\
  16560. }\
  16561. .ace-tm .ace_print-margin {\
  16562. width: 1px;\
  16563. background: #e8e8e8;\
  16564. }\
  16565. .ace-tm .ace_fold {\
  16566. background-color: #6B72E6;\
  16567. }\
  16568. .ace-tm {\
  16569. background-color: #FFFFFF;\
  16570. color: black;\
  16571. }\
  16572. .ace-tm .ace_cursor {\
  16573. color: black;\
  16574. }\
  16575. .ace-tm .ace_invisible {\
  16576. color: rgb(191, 191, 191);\
  16577. }\
  16578. .ace-tm .ace_storage,\
  16579. .ace-tm .ace_keyword {\
  16580. color: blue;\
  16581. }\
  16582. .ace-tm .ace_constant {\
  16583. color: rgb(197, 6, 11);\
  16584. }\
  16585. .ace-tm .ace_constant.ace_buildin {\
  16586. color: rgb(88, 72, 246);\
  16587. }\
  16588. .ace-tm .ace_constant.ace_language {\
  16589. color: rgb(88, 92, 246);\
  16590. }\
  16591. .ace-tm .ace_constant.ace_library {\
  16592. color: rgb(6, 150, 14);\
  16593. }\
  16594. .ace-tm .ace_invalid {\
  16595. background-color: rgba(255, 0, 0, 0.1);\
  16596. color: red;\
  16597. }\
  16598. .ace-tm .ace_support.ace_function {\
  16599. color: rgb(60, 76, 114);\
  16600. }\
  16601. .ace-tm .ace_support.ace_constant {\
  16602. color: rgb(6, 150, 14);\
  16603. }\
  16604. .ace-tm .ace_support.ace_type,\
  16605. .ace-tm .ace_support.ace_class {\
  16606. color: rgb(109, 121, 222);\
  16607. }\
  16608. .ace-tm .ace_keyword.ace_operator {\
  16609. color: rgb(104, 118, 135);\
  16610. }\
  16611. .ace-tm .ace_string {\
  16612. color: rgb(3, 106, 7);\
  16613. }\
  16614. .ace-tm .ace_comment {\
  16615. color: rgb(76, 136, 107);\
  16616. }\
  16617. .ace-tm .ace_comment.ace_doc {\
  16618. color: rgb(0, 102, 255);\
  16619. }\
  16620. .ace-tm .ace_comment.ace_doc.ace_tag {\
  16621. color: rgb(128, 159, 191);\
  16622. }\
  16623. .ace-tm .ace_constant.ace_numeric {\
  16624. color: rgb(0, 0, 205);\
  16625. }\
  16626. .ace-tm .ace_variable {\
  16627. color: rgb(49, 132, 149);\
  16628. }\
  16629. .ace-tm .ace_xml-pe {\
  16630. color: rgb(104, 104, 91);\
  16631. }\
  16632. .ace-tm .ace_entity.ace_name.ace_function {\
  16633. color: #0000A2;\
  16634. }\
  16635. .ace-tm .ace_heading {\
  16636. color: rgb(12, 7, 255);\
  16637. }\
  16638. .ace-tm .ace_list {\
  16639. color:rgb(185, 6, 144);\
  16640. }\
  16641. .ace-tm .ace_meta.ace_tag {\
  16642. color:rgb(0, 22, 142);\
  16643. }\
  16644. .ace-tm .ace_string.ace_regex {\
  16645. color: rgb(255, 0, 0)\
  16646. }\
  16647. .ace-tm .ace_marker-layer .ace_selection {\
  16648. background: rgb(181, 213, 255);\
  16649. }\
  16650. .ace-tm.ace_multiselect .ace_selection.ace_start {\
  16651. box-shadow: 0 0 3px 0px white;\
  16652. }\
  16653. .ace-tm .ace_marker-layer .ace_step {\
  16654. background: rgb(252, 255, 0);\
  16655. }\
  16656. .ace-tm .ace_marker-layer .ace_stack {\
  16657. background: rgb(164, 229, 101);\
  16658. }\
  16659. .ace-tm .ace_marker-layer .ace_bracket {\
  16660. margin: -1px 0 0 -1px;\
  16661. border: 1px solid rgb(192, 192, 192);\
  16662. }\
  16663. .ace-tm .ace_marker-layer .ace_active-line {\
  16664. background: rgba(0, 0, 0, 0.07);\
  16665. }\
  16666. .ace-tm .ace_gutter-active-line {\
  16667. background-color : #dcdcdc;\
  16668. }\
  16669. .ace-tm .ace_marker-layer .ace_selected-word {\
  16670. background: rgb(250, 250, 255);\
  16671. border: 1px solid rgb(200, 200, 250);\
  16672. }\
  16673. .ace-tm .ace_indent-guide {\
  16674. background: url(\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAACCAYAAACZgbYnAAAAE0lEQVQImWP4////f4bLly//BwAmVgd1/w11/gAAAABJRU5ErkJggg==\") right repeat-y;\
  16675. }\
  16676. ";
  16677. var dom = require("../lib/dom");
  16678. dom.importCssString(exports.cssText, exports.cssClass);
  16679. });
  16680. define("ace/line_widgets",["require","exports","module","ace/lib/oop","ace/lib/dom","ace/range"], function(require, exports, module) {
  16681. "use strict";
  16682. var oop = require("./lib/oop");
  16683. var dom = require("./lib/dom");
  16684. var Range = require("./range").Range;
  16685. function LineWidgets(session) {
  16686. this.session = session;
  16687. this.session.widgetManager = this;
  16688. this.session.getRowLength = this.getRowLength;
  16689. this.session.$getWidgetScreenLength = this.$getWidgetScreenLength;
  16690. this.updateOnChange = this.updateOnChange.bind(this);
  16691. this.renderWidgets = this.renderWidgets.bind(this);
  16692. this.measureWidgets = this.measureWidgets.bind(this);
  16693. this.session._changedWidgets = [];
  16694. this.$onChangeEditor = this.$onChangeEditor.bind(this);
  16695. this.session.on("change", this.updateOnChange);
  16696. this.session.on("changeFold", this.updateOnFold);
  16697. this.session.on("changeEditor", this.$onChangeEditor);
  16698. }
  16699. (function() {
  16700. this.getRowLength = function(row) {
  16701. var h;
  16702. if (this.lineWidgets)
  16703. h = this.lineWidgets[row] && this.lineWidgets[row].rowCount || 0;
  16704. else
  16705. h = 0;
  16706. if (!this.$useWrapMode || !this.$wrapData[row]) {
  16707. return 1 + h;
  16708. } else {
  16709. return this.$wrapData[row].length + 1 + h;
  16710. }
  16711. };
  16712. this.$getWidgetScreenLength = function() {
  16713. var screenRows = 0;
  16714. this.lineWidgets.forEach(function(w){
  16715. if (w && w.rowCount && !w.hidden)
  16716. screenRows += w.rowCount;
  16717. });
  16718. return screenRows;
  16719. };
  16720. this.$onChangeEditor = function(e) {
  16721. this.attach(e.editor);
  16722. };
  16723. this.attach = function(editor) {
  16724. if (editor && editor.widgetManager && editor.widgetManager != this)
  16725. editor.widgetManager.detach();
  16726. if (this.editor == editor)
  16727. return;
  16728. this.detach();
  16729. this.editor = editor;
  16730. if (editor) {
  16731. editor.widgetManager = this;
  16732. editor.renderer.on("beforeRender", this.measureWidgets);
  16733. editor.renderer.on("afterRender", this.renderWidgets);
  16734. }
  16735. };
  16736. this.detach = function(e) {
  16737. var editor = this.editor;
  16738. if (!editor)
  16739. return;
  16740. this.editor = null;
  16741. editor.widgetManager = null;
  16742. editor.renderer.off("beforeRender", this.measureWidgets);
  16743. editor.renderer.off("afterRender", this.renderWidgets);
  16744. var lineWidgets = this.session.lineWidgets;
  16745. lineWidgets && lineWidgets.forEach(function(w) {
  16746. if (w && w.el && w.el.parentNode) {
  16747. w._inDocument = false;
  16748. w.el.parentNode.removeChild(w.el);
  16749. }
  16750. });
  16751. };
  16752. this.updateOnFold = function(e, session) {
  16753. var lineWidgets = session.lineWidgets;
  16754. if (!lineWidgets || !e.action)
  16755. return;
  16756. var fold = e.data;
  16757. var start = fold.start.row;
  16758. var end = fold.end.row;
  16759. var hide = e.action == "add";
  16760. for (var i = start + 1; i < end; i++) {
  16761. if (lineWidgets[i])
  16762. lineWidgets[i].hidden = hide;
  16763. }
  16764. if (lineWidgets[end]) {
  16765. if (hide) {
  16766. if (!lineWidgets[start])
  16767. lineWidgets[start] = lineWidgets[end];
  16768. else
  16769. lineWidgets[end].hidden = hide;
  16770. } else {
  16771. if (lineWidgets[start] == lineWidgets[end])
  16772. lineWidgets[start] = undefined;
  16773. lineWidgets[end].hidden = hide;
  16774. }
  16775. }
  16776. };
  16777. this.updateOnChange = function(delta) {
  16778. var lineWidgets = this.session.lineWidgets;
  16779. if (!lineWidgets) return;
  16780. var startRow = delta.start.row;
  16781. var len = delta.end.row - startRow;
  16782. if (len === 0) {
  16783. } else if (delta.action == 'remove') {
  16784. var removed = lineWidgets.splice(startRow + 1, len);
  16785. removed.forEach(function(w) {
  16786. w && this.removeLineWidget(w);
  16787. }, this);
  16788. this.$updateRows();
  16789. } else {
  16790. var args = new Array(len);
  16791. args.unshift(startRow, 0);
  16792. lineWidgets.splice.apply(lineWidgets, args);
  16793. this.$updateRows();
  16794. }
  16795. };
  16796. this.$updateRows = function() {
  16797. var lineWidgets = this.session.lineWidgets;
  16798. if (!lineWidgets) return;
  16799. var noWidgets = true;
  16800. lineWidgets.forEach(function(w, i) {
  16801. if (w) {
  16802. noWidgets = false;
  16803. w.row = i;
  16804. while (w.$oldWidget) {
  16805. w.$oldWidget.row = i;
  16806. w = w.$oldWidget;
  16807. }
  16808. }
  16809. });
  16810. if (noWidgets)
  16811. this.session.lineWidgets = null;
  16812. };
  16813. this.addLineWidget = function(w) {
  16814. if (!this.session.lineWidgets)
  16815. this.session.lineWidgets = new Array(this.session.getLength());
  16816. var old = this.session.lineWidgets[w.row];
  16817. if (old) {
  16818. w.$oldWidget = old;
  16819. if (old.el && old.el.parentNode) {
  16820. old.el.parentNode.removeChild(old.el);
  16821. old._inDocument = false;
  16822. }
  16823. }
  16824. this.session.lineWidgets[w.row] = w;
  16825. w.session = this.session;
  16826. var renderer = this.editor.renderer;
  16827. if (w.html && !w.el) {
  16828. w.el = dom.createElement("div");
  16829. w.el.innerHTML = w.html;
  16830. }
  16831. if (w.el) {
  16832. dom.addCssClass(w.el, "ace_lineWidgetContainer");
  16833. w.el.style.position = "absolute";
  16834. w.el.style.zIndex = 5;
  16835. renderer.container.appendChild(w.el);
  16836. w._inDocument = true;
  16837. }
  16838. if (!w.coverGutter) {
  16839. w.el.style.zIndex = 3;
  16840. }
  16841. if (w.pixelHeight == null) {
  16842. w.pixelHeight = w.el.offsetHeight;
  16843. }
  16844. if (w.rowCount == null) {
  16845. w.rowCount = w.pixelHeight / renderer.layerConfig.lineHeight;
  16846. }
  16847. var fold = this.session.getFoldAt(w.row, 0);
  16848. w.$fold = fold;
  16849. if (fold) {
  16850. var lineWidgets = this.session.lineWidgets;
  16851. if (w.row == fold.end.row && !lineWidgets[fold.start.row])
  16852. lineWidgets[fold.start.row] = w;
  16853. else
  16854. w.hidden = true;
  16855. }
  16856. this.session._emit("changeFold", {data:{start:{row: w.row}}});
  16857. this.$updateRows();
  16858. this.renderWidgets(null, renderer);
  16859. this.onWidgetChanged(w);
  16860. return w;
  16861. };
  16862. this.removeLineWidget = function(w) {
  16863. w._inDocument = false;
  16864. w.session = null;
  16865. if (w.el && w.el.parentNode)
  16866. w.el.parentNode.removeChild(w.el);
  16867. if (w.editor && w.editor.destroy) try {
  16868. w.editor.destroy();
  16869. } catch(e){}
  16870. if (this.session.lineWidgets) {
  16871. var w1 = this.session.lineWidgets[w.row]
  16872. if (w1 == w) {
  16873. this.session.lineWidgets[w.row] = w.$oldWidget;
  16874. if (w.$oldWidget)
  16875. this.onWidgetChanged(w.$oldWidget);
  16876. } else {
  16877. while (w1) {
  16878. if (w1.$oldWidget == w) {
  16879. w1.$oldWidget = w.$oldWidget;
  16880. break;
  16881. }
  16882. w1 = w1.$oldWidget;
  16883. }
  16884. }
  16885. }
  16886. this.session._emit("changeFold", {data:{start:{row: w.row}}});
  16887. this.$updateRows();
  16888. };
  16889. this.getWidgetsAtRow = function(row) {
  16890. var lineWidgets = this.session.lineWidgets;
  16891. var w = lineWidgets && lineWidgets[row];
  16892. var list = [];
  16893. while (w) {
  16894. list.push(w);
  16895. w = w.$oldWidget;
  16896. }
  16897. return list;
  16898. };
  16899. this.onWidgetChanged = function(w) {
  16900. this.session._changedWidgets.push(w);
  16901. this.editor && this.editor.renderer.updateFull();
  16902. };
  16903. this.measureWidgets = function(e, renderer) {
  16904. var changedWidgets = this.session._changedWidgets;
  16905. var config = renderer.layerConfig;
  16906. if (!changedWidgets || !changedWidgets.length) return;
  16907. var min = Infinity;
  16908. for (var i = 0; i < changedWidgets.length; i++) {
  16909. var w = changedWidgets[i];
  16910. if (!w || !w.el) continue;
  16911. if (w.session != this.session) continue;
  16912. if (!w._inDocument) {
  16913. if (this.session.lineWidgets[w.row] != w)
  16914. continue;
  16915. w._inDocument = true;
  16916. renderer.container.appendChild(w.el);
  16917. }
  16918. w.h = w.el.offsetHeight;
  16919. if (!w.fixedWidth) {
  16920. w.w = w.el.offsetWidth;
  16921. w.screenWidth = Math.ceil(w.w / config.characterWidth);
  16922. }
  16923. var rowCount = w.h / config.lineHeight;
  16924. if (w.coverLine) {
  16925. rowCount -= this.session.getRowLineCount(w.row);
  16926. if (rowCount < 0)
  16927. rowCount = 0;
  16928. }
  16929. if (w.rowCount != rowCount) {
  16930. w.rowCount = rowCount;
  16931. if (w.row < min)
  16932. min = w.row;
  16933. }
  16934. }
  16935. if (min != Infinity) {
  16936. this.session._emit("changeFold", {data:{start:{row: min}}});
  16937. this.session.lineWidgetWidth = null;
  16938. }
  16939. this.session._changedWidgets = [];
  16940. };
  16941. this.renderWidgets = function(e, renderer) {
  16942. var config = renderer.layerConfig;
  16943. var lineWidgets = this.session.lineWidgets;
  16944. if (!lineWidgets)
  16945. return;
  16946. var first = Math.min(this.firstRow, config.firstRow);
  16947. var last = Math.max(this.lastRow, config.lastRow, lineWidgets.length);
  16948. while (first > 0 && !lineWidgets[first])
  16949. first--;
  16950. this.firstRow = config.firstRow;
  16951. this.lastRow = config.lastRow;
  16952. renderer.$cursorLayer.config = config;
  16953. for (var i = first; i <= last; i++) {
  16954. var w = lineWidgets[i];
  16955. if (!w || !w.el) continue;
  16956. if (w.hidden) {
  16957. w.el.style.top = -100 - (w.pixelHeight || 0) + "px";
  16958. continue;
  16959. }
  16960. if (!w._inDocument) {
  16961. w._inDocument = true;
  16962. renderer.container.appendChild(w.el);
  16963. }
  16964. var top = renderer.$cursorLayer.getPixelPosition({row: i, column:0}, true).top;
  16965. if (!w.coverLine)
  16966. top += config.lineHeight * this.session.getRowLineCount(w.row);
  16967. w.el.style.top = top - config.offset + "px";
  16968. var left = w.coverGutter ? 0 : renderer.gutterWidth;
  16969. if (!w.fixedWidth)
  16970. left -= renderer.scrollLeft;
  16971. w.el.style.left = left + "px";
  16972. if (w.fullWidth && w.screenWidth) {
  16973. w.el.style.minWidth = config.width + 2 * config.padding + "px";
  16974. }
  16975. if (w.fixedWidth) {
  16976. w.el.style.right = renderer.scrollBar.getWidth() + "px";
  16977. } else {
  16978. w.el.style.right = "";
  16979. }
  16980. }
  16981. };
  16982. }).call(LineWidgets.prototype);
  16983. exports.LineWidgets = LineWidgets;
  16984. });
  16985. define("ace/ext/error_marker",["require","exports","module","ace/line_widgets","ace/lib/dom","ace/range"], function(require, exports, module) {
  16986. "use strict";
  16987. var LineWidgets = require("../line_widgets").LineWidgets;
  16988. var dom = require("../lib/dom");
  16989. var Range = require("../range").Range;
  16990. function binarySearch(array, needle, comparator) {
  16991. var first = 0;
  16992. var last = array.length - 1;
  16993. while (first <= last) {
  16994. var mid = (first + last) >> 1;
  16995. var c = comparator(needle, array[mid]);
  16996. if (c > 0)
  16997. first = mid + 1;
  16998. else if (c < 0)
  16999. last = mid - 1;
  17000. else
  17001. return mid;
  17002. }
  17003. return -(first + 1);
  17004. }
  17005. function findAnnotations(session, row, dir) {
  17006. var annotations = session.getAnnotations().sort(Range.comparePoints);
  17007. if (!annotations.length)
  17008. return;
  17009. var i = binarySearch(annotations, {row: row, column: -1}, Range.comparePoints);
  17010. if (i < 0)
  17011. i = -i - 1;
  17012. if (i >= annotations.length)
  17013. i = dir > 0 ? 0 : annotations.length - 1;
  17014. else if (i === 0 && dir < 0)
  17015. i = annotations.length - 1;
  17016. var annotation = annotations[i];
  17017. if (!annotation || !dir)
  17018. return;
  17019. if (annotation.row === row) {
  17020. do {
  17021. annotation = annotations[i += dir];
  17022. } while (annotation && annotation.row === row);
  17023. if (!annotation)
  17024. return annotations.slice();
  17025. }
  17026. var matched = [];
  17027. row = annotation.row;
  17028. do {
  17029. matched[dir < 0 ? "unshift" : "push"](annotation);
  17030. annotation = annotations[i += dir];
  17031. } while (annotation && annotation.row == row);
  17032. return matched.length && matched;
  17033. }
  17034. exports.showErrorMarker = function(editor, dir) {
  17035. var session = editor.session;
  17036. if (!session.widgetManager) {
  17037. session.widgetManager = new LineWidgets(session);
  17038. session.widgetManager.attach(editor);
  17039. }
  17040. var pos = editor.getCursorPosition();
  17041. var row = pos.row;
  17042. var oldWidget = session.widgetManager.getWidgetsAtRow(row).filter(function(w) {
  17043. return w.type == "errorMarker";
  17044. })[0];
  17045. if (oldWidget) {
  17046. oldWidget.destroy();
  17047. } else {
  17048. row -= dir;
  17049. }
  17050. var annotations = findAnnotations(session, row, dir);
  17051. var gutterAnno;
  17052. if (annotations) {
  17053. var annotation = annotations[0];
  17054. pos.column = (annotation.pos && typeof annotation.column != "number"
  17055. ? annotation.pos.sc
  17056. : annotation.column) || 0;
  17057. pos.row = annotation.row;
  17058. gutterAnno = editor.renderer.$gutterLayer.$annotations[pos.row];
  17059. } else if (oldWidget) {
  17060. return;
  17061. } else {
  17062. gutterAnno = {
  17063. text: ["Looks good!"],
  17064. className: "ace_ok"
  17065. };
  17066. }
  17067. editor.session.unfold(pos.row);
  17068. editor.selection.moveToPosition(pos);
  17069. var w = {
  17070. row: pos.row,
  17071. fixedWidth: true,
  17072. coverGutter: true,
  17073. el: dom.createElement("div"),
  17074. type: "errorMarker"
  17075. };
  17076. var el = w.el.appendChild(dom.createElement("div"));
  17077. var arrow = w.el.appendChild(dom.createElement("div"));
  17078. arrow.className = "error_widget_arrow " + gutterAnno.className;
  17079. var left = editor.renderer.$cursorLayer
  17080. .getPixelPosition(pos).left;
  17081. arrow.style.left = left + editor.renderer.gutterWidth - 5 + "px";
  17082. w.el.className = "error_widget_wrapper";
  17083. el.className = "error_widget " + gutterAnno.className;
  17084. el.innerHTML = gutterAnno.text.join("<br>");
  17085. el.appendChild(dom.createElement("div"));
  17086. var kb = function(_, hashId, keyString) {
  17087. if (hashId === 0 && (keyString === "esc" || keyString === "return")) {
  17088. w.destroy();
  17089. return {command: "null"};
  17090. }
  17091. };
  17092. w.destroy = function() {
  17093. if (editor.$mouseHandler.isMousePressed)
  17094. return;
  17095. editor.keyBinding.removeKeyboardHandler(kb);
  17096. session.widgetManager.removeLineWidget(w);
  17097. editor.off("changeSelection", w.destroy);
  17098. editor.off("changeSession", w.destroy);
  17099. editor.off("mouseup", w.destroy);
  17100. editor.off("change", w.destroy);
  17101. };
  17102. editor.keyBinding.addKeyboardHandler(kb);
  17103. editor.on("changeSelection", w.destroy);
  17104. editor.on("changeSession", w.destroy);
  17105. editor.on("mouseup", w.destroy);
  17106. editor.on("change", w.destroy);
  17107. editor.session.widgetManager.addLineWidget(w);
  17108. w.el.onmousedown = editor.focus.bind(editor);
  17109. editor.renderer.scrollCursorIntoView(null, 0.5, {bottom: w.el.offsetHeight});
  17110. };
  17111. dom.importCssString("\
  17112. .error_widget_wrapper {\
  17113. background: inherit;\
  17114. color: inherit;\
  17115. border:none\
  17116. }\
  17117. .error_widget {\
  17118. border-top: solid 2px;\
  17119. border-bottom: solid 2px;\
  17120. margin: 5px 0;\
  17121. padding: 10px 40px;\
  17122. white-space: pre-wrap;\
  17123. }\
  17124. .error_widget.ace_error, .error_widget_arrow.ace_error{\
  17125. border-color: #ff5a5a\
  17126. }\
  17127. .error_widget.ace_warning, .error_widget_arrow.ace_warning{\
  17128. border-color: #F1D817\
  17129. }\
  17130. .error_widget.ace_info, .error_widget_arrow.ace_info{\
  17131. border-color: #5a5a5a\
  17132. }\
  17133. .error_widget.ace_ok, .error_widget_arrow.ace_ok{\
  17134. border-color: #5aaa5a\
  17135. }\
  17136. .error_widget_arrow {\
  17137. position: absolute;\
  17138. border: solid 5px;\
  17139. border-top-color: transparent!important;\
  17140. border-right-color: transparent!important;\
  17141. border-left-color: transparent!important;\
  17142. top: -5px;\
  17143. }\
  17144. ", "");
  17145. });
  17146. define("ace/ace",["require","exports","module","ace/lib/fixoldbrowsers","ace/lib/dom","ace/lib/event","ace/editor","ace/edit_session","ace/undomanager","ace/virtual_renderer","ace/worker/worker_client","ace/keyboard/hash_handler","ace/placeholder","ace/multi_select","ace/mode/folding/fold_mode","ace/theme/textmate","ace/ext/error_marker","ace/config"], function(require, exports, module) {
  17147. "use strict";
  17148. require("./lib/fixoldbrowsers");
  17149. var dom = require("./lib/dom");
  17150. var event = require("./lib/event");
  17151. var Editor = require("./editor").Editor;
  17152. var EditSession = require("./edit_session").EditSession;
  17153. var UndoManager = require("./undomanager").UndoManager;
  17154. var Renderer = require("./virtual_renderer").VirtualRenderer;
  17155. require("./worker/worker_client");
  17156. require("./keyboard/hash_handler");
  17157. require("./placeholder");
  17158. require("./multi_select");
  17159. require("./mode/folding/fold_mode");
  17160. require("./theme/textmate");
  17161. require("./ext/error_marker");
  17162. exports.config = require("./config");
  17163. exports.require = require;
  17164. if (typeof define === "function")
  17165. exports.define = define;
  17166. exports.edit = function(el) {
  17167. if (typeof el == "string") {
  17168. var _id = el;
  17169. el = document.getElementById(_id);
  17170. if (!el)
  17171. throw new Error("ace.edit can't find div #" + _id);
  17172. }
  17173. if (el && el.env && el.env.editor instanceof Editor)
  17174. return el.env.editor;
  17175. var value = "";
  17176. if (el && /input|textarea/i.test(el.tagName)) {
  17177. var oldNode = el;
  17178. value = oldNode.value;
  17179. el = dom.createElement("pre");
  17180. oldNode.parentNode.replaceChild(el, oldNode);
  17181. } else if (el) {
  17182. value = dom.getInnerText(el);
  17183. el.innerHTML = "";
  17184. }
  17185. var doc = exports.createEditSession(value);
  17186. var editor = new Editor(new Renderer(el));
  17187. editor.setSession(doc);
  17188. var env = {
  17189. document: doc,
  17190. editor: editor,
  17191. onResize: editor.resize.bind(editor, null)
  17192. };
  17193. if (oldNode) env.textarea = oldNode;
  17194. event.addListener(window, "resize", env.onResize);
  17195. editor.on("destroy", function() {
  17196. event.removeListener(window, "resize", env.onResize);
  17197. env.editor.container.env = null; // prevent memory leak on old ie
  17198. });
  17199. editor.container.env = editor.env = env;
  17200. return editor;
  17201. };
  17202. exports.createEditSession = function(text, mode) {
  17203. var doc = new EditSession(text, mode);
  17204. doc.setUndoManager(new UndoManager());
  17205. return doc;
  17206. }
  17207. exports.EditSession = EditSession;
  17208. exports.UndoManager = UndoManager;
  17209. exports.version = "1.2.8";
  17210. });
  17211. (function() {
  17212. window.require(["ace/ace"], function(a) {
  17213. if (a) {
  17214. a.config.init(true);
  17215. a.define = window.define;
  17216. }
  17217. if (!window.ace)
  17218. window.ace = a;
  17219. for (var key in a) if (a.hasOwnProperty(key))
  17220. window.ace[key] = a[key];
  17221. });
  17222. })();